Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sabrenman94 · Sep 14, 2016 at 03:23 AM · meshdynamicvertices

Dynamically Generate Plane Mesh in App from Vertices

Hi,

I am trying to generate a plane mesh in the app from 4 user defined vertices. This is for a hololens application, and I am getting the vertices from the cursor position. I have the following script attached to an empty game object with a material, a mesh filter, and a mesh renderer component. currently my application recognizes the 4 vertices inputted by the user, but no visual mesh seems to be created. Can anyone please tell me what I need to do differently? Thanks.

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class EditPlane : MonoBehaviour {

 public TempStateManager stateManager;
 public TextMesh debug;
 private List<Vector3> vertexHolder;
 private Vector3 firstVertex;
 public GameObject cursor;
 private int input;
 // Use this for initialization
 void Start() {
     vertexHolder = new List<Vector3>();
     input = 0;
 }


 void OnSelect()
 {
     if (stateManager.state == "setVertices")
     {

         if (input < 4)
         {
             if (input == 0)//first time
             {
                 firstVertex = cursor.transform.position;//save first y position
                 //add first vertex (vertex 0)
                 vertexHolder.Add(firstVertex);
                 Debug.Log("added first vertex");
                 debug.text = "added first vertex";
             }
             else 
             {
                 Vector3 newVertex = new Vector3(cursor.transform.position.x, firstVertex.y, cursor.transform.position.z);
                 //add vertices 1, 2, and 3
                 vertexHolder.Add(newVertex);
                 Debug.Log("added subsequent vertex");
                 debug.text = "added subsequent vertex";
                 if(input ==3)//last input
                 {
                     debug.text = "last vertex";

                     //triangles
                     int[] tri = new int[6];
                     tri[0] = 0;
                     tri[1] = 2;
                     tri[2] = 1;

                     tri[3] = 2;
                     tri[4] = 3;
                     tri[5] = 1;

                     //normals
                     Vector3[] normals = new Vector3[4];
                     normals[0] = Vector3.up;
                     normals[1] = Vector3.up;
                     normals[2] = Vector3.up;
                     normals[3] = Vector3.up;

                     Mesh mesh = new Mesh();
                     GetComponent<MeshFilter>().mesh = mesh;
                     mesh.SetVertices(vertexHolder);
                     mesh.triangles = tri;
                     mesh.normals = normals;
                     debug.text = "set mesh";
                 }
             }
             input++;
         }
     }

 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aditya · Sep 14, 2016 at 05:14 AM

you can try my below suggestions :

  • Apply the new generated mesh to meshfilter after applying its vertices and normals etc

  • Where are the UVs ?

  • Try this triangle sequence 0,2,1,0,3,2

  • You are setting Vector3.Up as the normales, make sure that your camera is looking from correct diection

  • You are setting the positions of vertices according to the position of gameobject cursor, make sure this gameobject is changing its position otherwise all your vertices are going to be placed on exact same position and you won't be able to see the mesh

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Manipulating vertices through colliders 1 Answer

Best way to transition one mesh to another with the option to change the target mesh 0 Answers

how to add multiple vertices in a mesh at runtime 0 Answers

Alternative Ways of Finding Vertices 2 Answers

Multiple MeshFilters for a GameObject 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges