Hello i having been searching about Triangles on mesh but i have found “0” things about them there is no tutorial for triangles for mesh in Unity, so i have some code below and if you can tell me how it works, that would be helpful.
So i have this Triangle code from here
int ti = 0;
for( int i = 0; i < segments; i++ ) {
int offset = i * vertsInShape;
for ( int l = 0; l < lines.Length; l += 2 ) {
int a = offset + lines[l] + vertsInShape;
int b = offset + lines[l];
int c = offset + lines[l+1];
int d = offset + lines[l+1] + vertsInShape;
triangleIndices[ti] = a; ti++;
triangleIndices[ti] = b; ti++;
triangleIndices[ti] = c; ti++;
triangleIndices[ti] = c; ti++;
triangleIndices[ti] = d; ti++;
triangleIndices[ti] = a; ti++;
}
}
And i am trying to change it to this, but obviously it does not work
int ti = 0;
for (int i = 0; i < segments; i++)
{
int offset = i * vertsInShape;
for (int l = 0; l < origVerts.Length; l += 6)
{
int a = offset + (stretch * l) + vertsInShape;
int b = offset + (stretch * l);
int c = offset + (stretch * l + 1);
int d = offset + (stretch * l + 1) + vertsInShape;
triangleIndices[ti] = c; ti++;
triangleIndices[ti] = b; ti++;
triangleIndices[ti] = a; ti++;
triangleIndices[ti] = a; ti++;
triangleIndices[ti] = d; ti++;
triangleIndices[ti] = c; ti++;
}
}
And this is the error i get with my code.
“Failed setting triangles. Some indices are referencing out of bounds vertices. IndexCount: 48, VertexCount: 20
UnityEngine.Mesh:set_triangles(Int32[])
Extruder:Generate() (at Assets/Extruder.cs:73)
Extruder:Start() (at Assets/Extruder.cs:23)”
But if you need the full code to know what i am doing with the code just comment below.