In my project, I am utilizing threeJS along with a Simplex noise algorithm to create a tile system consisting of 50x50 planes. Currently, I am iterating through x+y and adding each plane. The Simplex noise algorithm is then used to calculate the z position of the four vertices of the plane.
The current x/y values are being used as the top left vertice [0], and the remaining process can be seen in the function that initializes the tiles below:
PerlinSimplex.noiseDetail(4,0.5);
x=0;
y=0;
while (x<32) {
while (y<32) {
l=(x*tilesize)+(tilesize/2);
t=(y*tilesize)+(tilesize/2);
fScl= 1;
xx=x*fScl;
yy=y*fScl;
tl=Math.floor((PerlinSimplex.noise(xx,yy))*100);
bl=Math.floor((PerlinSimplex.noise(xx,yy-1))*100);
br=Math.floor((PerlinSimplex.noise(xx+1,yy-1))*100);
tr=Math.floor((PerlinSimplex.noise(xx+1,yy))*100);
addTile(t,l,tl,tr,bl,br);
y++;
}
y=0;
x++;
}
Next is the 'addTile' function:
function addTile(x,y,tl,tr,bl,br) {
var geo=new THREE.PlaneGeometry(tilesize, tilesize);
geo.dynamic = true;
geos.push(geo);
var plane = new THREE.Mesh(geo, col);
plane.overdraw = true;
plane.geometry.vertices[0].z=tl;
plane.geometry.vertices[1].z=tr;
plane.geometry.vertices[2].z=bl;
plane.geometry.vertices[3].z=br;
plane.geometry.computeFaceNormals();
plane.geometry.computeVertexNormals();
plane.geometry.__dirtyNormals = true;
plane.position.x=x;
plane.position.y=y;
plane.position.z=0;
scene.add(plane);
planes.push(plane);
plane.geometry.verticesNeedUpdate = true;
plane.geometry.normalsNeedUpdate = true;
}
I have noticed that having a new geometry for each plane might not be necessary for my implementation.
Here is the outcome so far: https://i.sstatic.net/as7hb.jpg
It seems that the vertices are not aligning properly. Despite trying various approaches, I am unable to figure out why the vertices are not lining up correctly. If you spot the issue, your insights would be greatly appreciated!
Thank you :) Jack