I am generating my own procedural mesh. I use a 3 dimensional array that represents coordinates, and each coordinate is a vertex for the mesh. Then I draw triangles from vertex to vertex. Its pretty simple.
The problem is, I want to change out the triangles I draw with another combination of triangles. I can easily add more triangles in, but the original triangles will still be there.
I have tried to delete the original triangles like this:
function Update () {
if (Input.GetKeyDown ("q"))
{
var verts = mesh.vertices;
var tris = mesh.triangles;
mesh.Clear();
tris = removeTriangle(7, tris);
mesh.vertices = verts;
mesh.triangles = tris;
}
}
function removeTriangle(triangle : int, tris : int[]) : int[]{
for (var i = triangle*3; i < tris.Length-3; ++i) {
if (tris[i] == -1) break;
tris[i] = tris[i+3];
}
return tris;
}
In the above example, The code would delete the 7th triangle. Seems easy, right? Unfortunately, the array that represents the mesh's triangles changes all the values above 7 down one, making a new "7th" triangle. Because of this, I have no way of controlling my triangles.
So my question is, does anyone else have a method to control the mesh.triangles array so that when I create a triangle, I can easily delete it at will. Or, if you know how, do you have a different method of deleting triangles?
↧