Trying to transition code from openFrameworks to THREE.JS for generating a landscape with Perlin noise. The approach involves creating a static index array first, followed by positioning vertices in a square grid, each offset by a specific distance. This setup allows for shifting vertices within the array (up, down, left, right) to update the landscape based on camera movement.
Each vertex has 6 indices in the array, referencing two adjacent triangles to avoid duplicating vertices for each triangle.
For instance:
v12 v11 v10
*----*----*
|\ |\ |
| \ | \ |
| \ | \ |
| \| \|
*----*----*
v02 v01 v00
For vertex v00, indices {v00, v10, v11} and {v00, v11, v01} are added, and so forth.
The code runs smoothly in openFrameworks, but faces issues in THREE.js when the vertex count is increased. Triangles start connecting randomly, and chunks of vertices are skipped. Everything is fine up to a grid size of 256*256, but artifacts occur beyond that.
It's suspected to be an offsetting problem, which others have addressed by defining indices sequentially and using 3 vertices for each triangle. However, replicating the setup proves challenging.
Any insights? Code is provided below, highlighting areas where offsetting is attempted.
...