Answers for "How to find triangles using variables"
http://answers.unity.com/questions/45121/how-to-find-triangles-using-variables.html
The latest answers for the question "How to find triangles using variables"Answer by Bunny83
http://answers.unity.com/answers/45129/view.html
<p>I guess you don't understand what a vertexbuffer and a indexbuffer is?<br>
A Mesh in Unity consists of triangles. Every triangle is made up of 3 vertices. I guess you already know that part. Now the important part. Mesh.vertices is the vertexbuffer and Mesh.triangles is the indexbuffer. The indexbuffer is also an array but it contains indices related to the vertexbuffer. Each number (int) in the indexbuffer is a index into the vertexbuffer. Always 3 indices made up a triangle. The indexbuffer just tell you which vertices you need.</p>
<p>A simple example for a plane:</p>
<pre><code>var vertices : Vector3[] = new Vector3[4];
vertices[0] = Vector3(-1,-1,0);
vertices[1] = Vector3(-1, 1,0);
vertices[2] = Vector3( 1, 1,0);
vertices[3] = Vector3( 1,-1,0);
var indices : int[] = new int[6];
// triangle 1
indices[0] = 0; // first vertex
indices[1] = 1; // second vertex
indices[2] = 2; // third vertex
// triangle 2
indices[3] = 2; // third vertex
indices[4] = 3; // forth vertex
indices[5] = 0; // first vertex
mesh.vertices = vertices;
mesh.triangles = indices;
</code></pre>
<p>Look carefully at the example of the indices. The first and the third vertex is shared between both triangled.</p>
<p>If you want remove some triangles you have to remove the 3 corresponding indices that made up the triangle. The resulting indices array will be smaller in the end. That's tricky because you can't change the size of builtin arrays dynamically. If you want to remove vertices somewhere in the middle of the vertices array it gets really difficult because the indices would be pointing to the wrong vertices.</p>
<p>I still don't know exactly what you want to do. I'll hope you understand everything i explained here. Maybe you can specify you question a bit and tell us what you want to archive.</p>
<p>I guess you've tried something similar in this <a href="http://answers.unity3d.com/questions/36084/correct-form-to-use-vertices-uv-and-triangles-create" rel="nofollow">post</a>, right?</p>
<hr>
<p>Ok, i still don't understand what exactly you want to archive :D<br>
Do you want to remove some triangles completely or just move them outwards. If you want to move them outward you just need to shift the vertices like you've done already but it depends on how the mesh is built up. If there are shared vertex points you have to duplicate the vertex points to make them unique. That would require to build up a complete new vertex and index array.</p>
<p>You said how to "find" a triangle. The loop where you increment your "j", it already goes through all triangles. "j" is the current triangle and (j*3), (j*3+1) and (j*3+2) are the 3 points that define this triangle. </p>
<p>If you want to remove a single triangle you have to copy all triangle indices into a new array except those you don't want. You can't change the size of a builtin array. The new arraysize have to be reduced by 3.</p>Sat, 29 Jan 2011 05:00:48 GMTBunny83