Answers for "Procedurally Generated mesh not rendering all triangles,Procedurally generated mesh isn't rendering all triangles?"
http://answers.unity.com/questions/1885156/procedurally-generated-mesh-not-rendering-all-tria-1.html
The latest answers for the question "Procedurally Generated mesh not rendering all triangles,Procedurally generated mesh isn't rendering all triangles?"Answer by amabone
http://answers.unity.com/answers/1885219/view.html
Ok, Mr. you start from a 0 indexing vertex list, u grow up of maxX (resolution) for each y, that for the entire first row is 0.
for (y = 1; y <= resolution; y++)
{
for (x = 1; x <= resolution; x++)
{
....
you start here for 1 while doing calculation. resulting in index 0 never being mentioned, and thats what i would do (i did).
you take count of the whole square while triangulating. so u need to check only for the square
in a
> resolution-1 * resolution-1 grid
those are the number of square in a grid of resolution*resolution vertices
so u do
for (y = 0; y <= resolution-1; y++)
{
for (x = 0; x <= resolution-1; x++)
{
and then when selecting the corresponding vertex index u start from the point 0, 0 of the grid and count from there
x---------x+1
| |
x+X------x+X+1
entering the indexing like this
triangles[i2] = x;
triangles[i2+1] = x+1;
triangles[i2+2] = x+resolution;
triangles[i2+3] = x+resolution;
triangles[i2+4] = x+1;
triangles[i2+5] = x+resolution+1;
i2=i2+6;
im actually not sure by the orther, but u can figure it out i hope. Good Luck!
edit:
i re-read the answer that i posted and pointed out that x, must be accessed linearly so,
u can add another counter, like int index, and then when the last x occur u can call index++
triangles[i2] = index;
triangles[i2+1] = index+1;
triangles[i2+2] = index+resolution;
triangles[i2+3] = index+resolution;
triangles[i2+4] = index+1;
triangles[i2+5] = (index++)+resolution+1
i2=i2+6;
u can rewrite the whole thing as a single for loop int i = 0; i<((resolution-1)*(resolution-1));i++
the y would be i divided / by resolution
removing i2 at all
stepping i for 6 like this
for(int i = 0 ;i<((resolution-1)*(resolution-1));i++){
int triangle_index = i*6;
int y = i / resolution;
//triangle[triangle_index+0] = i;//i+1,i+resolution
//blabla...
//i2 no more
}Fri, 04 Feb 2022 10:04:14 GMTamabone