Runtime Mesh Generation - Messed up!

I have tried diffrent solutions for the past 3 days.
Any ideas ?

for (int j = 0, k = 0; j < verticesArray.Length; k++)
                {
                  ;
                    GeoWithCords data = EntityManager.GetComponentData<GeoWithCords>(iterator[k]);

                    Vector2 v2a = new Vector2(data.cords0.x, data.cords0.y);
                    Vector2 v2b = new Vector2(data.cords1.x, data.cords0.y);
                    Vector2 v2c = new Vector2(data.cords2.x, data.cords0.y);
                    Vector2 v2d = new Vector2(data.cords3.x, data.cords0.y);

                    verticesArray[j] = p.transform.InverseTransformPoint(new Vector3(layerDepth, v2a.y, v2a.x));
                    verticesArray[j + 1] = p.transform.InverseTransformPoint(new Vector3(layerDepth, v2b.y, v2b.x));
                    verticesArray[j + 2] = p.transform.InverseTransformPoint(new Vector3(layerDepth, v2c.y, v2c.x));
                    verticesArray[j + 3] = p.transform.InverseTransformPoint(new Vector3(layerDepth, v2d.y, v2d.x));
                    j += 4;
                  

                }
            
                for (int v = 0; v < iteratorLength; v++)
                {
                                      
                    triangles[t] = v; 
                    triangles[t + 1] = 2 + v; 
                    triangles[t + 2] = 1 + v;

                    triangles[t + 3] = 3 + v; 
                    triangles[t + 4] = 1 + v;   
                    triangles[t + 5] = 2 + v; 

                    
                    t += 6;

                }

                mesh.vertices = verticesArray;
                mesh.triangles = triangles;
                mesh.RecalculateNormals();

It is unclear what you are trying to do. Can you simplify it down to a single triangle (three vertices and three integer offsets) and get that to go through correctly?

Iam trying to combine all the vertices and triangels into one mesh.

If i draw every triangle as a seperate mesh it works. But it is slow :confused:

Why not this?

1 Like