- Home /
problem with loop and mesh values
Trying to delete n colored uvs and vertices from a mesh, but after 4 loops, it sais the index is out of range, even though it is counting down from top to bottom. i dont understand.
var vtxlist = new List.<Vector3>(); var vtx2 = mesh2.vertices; vtxlist = vtx2.ToList();
var nmlist = new List.<Vector3>(); var norms2 = mesh2.normals; nmlist = norms2.ToList();
var uvlist = new List.<Vector2>(); var uvv2 = mesh2.uv; uvlist = uvv2.ToList();
var trilist = new List.<int>(); var tris2 = mesh2.triangles; trilist = tris2.ToList();
print( trilist.Count + " yahhahyfuhsu " + tris2.length);
for ( var i = tris2.length-1; i >= 0 ; i -- )
{
if(uvv2[tris2[i]] == p0)
{
print( " deleted mesh vales at index number " + i );
if (vtxlist[tris2[i]] !=null)vtxlist.RemoveAt(tris2[i] );
if (nmlist[tris2[i]] !=null)nmlist.RemoveAt(tris2[i] );
if (uvlist[tris2[i]] !=null)uvlist.RemoveAt(tris2[i] );
if (tris2[i] !=null)trilist.RemoveAt(i );
}
}
mesh2.triangles = trilist.ToArray();
mesh2.normals = nmlist.ToArray();
mesh2.uv = uvlist.ToArray();
mesh2.vertices = vtxlist.ToArray();
meshval.png
(17.4 kB)
Comment
At first: your null-comparisons are useless, because int and vector3 are value-types, which means they can not be null. Can you tell us, at which line you get the error?