- Home /
How can I ADD vertices and faces to a mesh?
I want to make my own mesh manipulation scripts, but I can't find anywhere how to simply, for example, create a vertex at the midpoint of the edge connecting vertex A and vertex B, or, for building upon this idea, how to make a vertex 40% distance from A to B, to 5 units away from B on y axis, etc. I'm good at coding, I just don't know what to reference. I look at the API, go to Mesh, look at methods, but find nothing helpful. Please help.
Answer by Graham-Dunnett · May 30, 2015 at 05:29 PM
The Mesh
documentation tells you how you can create a new mesh. If you are changing the number of vertices, or how triangles are formed from the verts then you'll need to create a new one.
If you need a new vertex C midway between A and B, then just add them together and divide by two. If C is 40% between them, make a direction vector between A and B, and add 40% of this to A. I guess your problem is the maths to do the vertex creation or edits.
http://docs.unity3d.com/ScriptReference/$$anonymous$$esh.html
I've read the doc. It basically just tells us how to create a copy mesh, or gives example code with no values, and since I've read Unity stores vertices in arrays in no particular order, how can I know which vertices to connect if I can't reference them?