Hi,
I generate a mesh with many triangles.
I want to delete 2 triangles if i click them.
It works the first time, but if i try to hit the next triangle… the raycast triangleindex give me some wrong values.
- i select a triangle, detect the triangle to get the quad and i remove it.
http://www.terabyte-unlimited.com/help1.png
I remove the triangles from the Mesh an safe ist
public static void RemoveFace(GameObject ga, int tIndex)
{
Mesh tmpMesh = ga.GetComponent<MeshFilter>().mesh;
MeshCollider tmpCol = ga.GetComponent<MeshCollider>();
Vector3[] vertices = tmpMesh.vertices;
Vector2[] uv = tmpMesh.uv;
int[] triangles = tmpMesh.triangles;
Vector3[] nVertices = new Vector3[vertices.Length - 4];
Vector2[] nUV = new Vector2[nVertices.Length];
int[] nTriangles = new int[triangles.Length - 6];
int iC = 0;
int[] TriIndex = new int[6];
/*
TriIndex[0] = triangles[tIndex * 3 + 0];
TriIndex[1] = triangles[tIndex * 3 + 1];
TriIndex[2] = triangles[tIndex * 3 + 2];
if ((float)tIndex / 2.0f - Mathf.Floor((float)tIndex / 2.0f) > 0.0f)
{
TriIndex[3] = triangles[(tIndex - 1) * 3 + 0];
TriIndex[4] = triangles[(tIndex - 1) * 3 + 1];
TriIndex[5] = triangles[(tIndex - 1) * 3 + 2];
}
else
{
TriIndex[3] = triangles[(tIndex + 1) * 3 + 0];
TriIndex[4] = triangles[(tIndex + 1) * 3 + 1];
TriIndex[5] = triangles[(tIndex + 1) * 3 + 2];
}
for (int i = 0; i < vertices.Length; i++)
{
if (!TriIndex.Contains<int>(i))
{
nVertices[iC] = vertices*;*
nUV[iC] = uv*;*
iC++;
}
}
* */
TriIndex[0] = tIndex * 3 + 0;
TriIndex[1] = tIndex * 3 + 1;
TriIndex[2] = tIndex * 3 + 2;
if ((float)tIndex / 2.0f - Mathf.Floor((float)tIndex / 2.0f) > 0.0f)
{
TriIndex[3] = (tIndex - 1) * 3 + 0;
TriIndex[4] = (tIndex - 1) * 3 + 1;
TriIndex[5] = (tIndex - 1) * 3 + 2;
}
else
{
TriIndex[3] = (tIndex + 1) * 3 + 0;
TriIndex[4] = (tIndex + 1) * 3 + 1;
TriIndex[5] = (tIndex + 1) * 3 + 2;
}
iC = 0;
for (int i = 0; i < triangles.Length; i++)
{
if (!TriIndex.Contains(i))
{
nTriangles[iC] = triangles*;*
iC++;
}
}
tmpMesh.Clear();
tmpMesh.vertices = vertices;
tmpMesh.triangles = nTriangles;
tmpMesh.uv = uv;
tmpMesh.Optimize();
tmpMesh.RecalculateNormals();
tmpCol.sharedMesh = tmpMesh;
}
The two triangles are vanish… all fine…
*http://www.terabyte-unlimited.com/help2.png*_
If i try to raycast the next triangle, then i get some wrong triangleindex From the cast.
*http://www.terabyte-unlimited.com/help3.png*_
What can i do to get the right Triangle?
Something wrong with the mesh? Or with my Raycast?