Vertices return to original position after toggling between terrain and path making functions

Hi there
I’m trying to create a terrain generator in this pg Babylon.js Playground
I don’t know what causes the vertices to return to original position
The steps to reproduce this issue is as follows
1-Right-click and press on the ground mesh to increase the height of the vertices
2-After this, click on the “draw path” button. Then left-click on the ground mesh and drag it to create a path on the hill you created.
3-repeat step 2
The vertices that were modified end up returning to step 1

I’m not sure I can reproduce the problem, but we can’t really see what’s going on without proper normals for the modified mesh.

So, I updated your PG to recalculate the normals and use a directional light, so that we can better see the changes we make:

You should probably first fix the error we can see in the console log of the browser when we draw a path:

image

I fixed the pg errors: https://playground.babylonjs.com/#B0ES4F#2

Here is the video showing the issue

You forgot to update the height coordinates when you raise the summits I think.

mesh.updateCoordinateHeights();

See line 133 :

And maybe also increase the land subdivisions to 150 or 200.

It didn’t work. The vertices retuned to the original state
I also tried with the computeWolrdMatrix(true) but nothing worked

You are missing something in your code to save the state of your first modification, otherwise the following modifications overwrite the first.

I also have tried to clean the vertices position arrays after all steps.

Your PathsControl class must also update the VerticesManipulator.meshes[mesh].vertices array, because it is this array which is modified by VerticesManipulator.selectVertices and set to the mesh in VerticesManipulator.updateVertices.

Your code would probably be simpler if you used a pattern like this each time you modify a set of vertices:

const positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind)
// do your modification in the positions array
mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions);

That way, you would always work with the latest updates of the vertices.

Is it possible to modify the previous pg so that I can see better what I am missing?

You can do something like that:

1 Like