Hi, im following some examples on making meshes by script, almost all examples available out there work great.
However, the problem starts when it’s segmented, giving an example below on the order of addition to the array, it doesn’t display it on the final result.
So the question is, what is the correct order following the example, should it be, based on it, starting instead, on t3, t4, t1, t2, t7, t8, t5 and then on…?
It really does not care at all about the vertex order, as Praetor says.
Each vertex is projected to whatever view you’re looking at, and once they’re all projected, the triangle triplet just says “make a triangle between these three screen dots.”
Unity is left-hand-rule, so clockwise winding to face your camera.
If you’re missing triangles that you think you should see, press Pause and go look in the scene from the opposite side. If the triangle is backwards, fix the ordering. If there simply is no triangle, then you probably have it wound with zero area, such as with using the same point (or point in space) for two or more corners. A vanishingly thin triangle will NOT draw a line. It will be invisible.
I have a bunch of procgen examples in my MakeGeo package:
The vertex order you described in this first sentence seems fine to me. Can you explain what you mean by “not working” in this context? What is going wrong?
You haven’t shown your code how you generate your triangles array. Since you have a simply 2d grid it’s just a matter of iterating through your grid in a 2d way. You usually would use two nested for loops, one for the x direction and one for the y direction. So the outer “x” loop goes from 0 to 4 (since you only have 5 cells in the x direction) and the inner y loop goes from 0 to 1. You get the vertex indices for one quad cell like this
int i0 = y*h + x;
int i1 = y*h + x + 1;
int i2 = y*h + x + h;
int i3 = y*h + x + h +1;
Note that “h” is the vertical vertex count, in your example case it’s 3 (or the y quad grid size of 2 + 1).
Now you just need to construct 2 triangles with those indices. Since you want them like you have shown in your image it would be something like i0, i1, i3, i0, i3, i2 for each quad cell.