Using the Skybox example, I tried to change the value of the subdivision, to check the results. Unfortunately, whenever the value is different from 100, the method getHeightAtCoordinates from the ground sometimes returns NaN values.
Apparently when you call getHeightAtCoordinates before the terrain geometry has been created, it doesn’t initialize properly, so you should wait for the scene to be ready, or you can call updateCoordinateHeights before calling getHeightAtCoordinates
Yes, I’m assuring that the ground is loaded, I’m doing this inside the ground.onReady = function () {}.
I find a temporal solution, but I do not fully understand the consequences.
In the ground.onReady = function () {} I call getHeightAtCoordinates before I call the ground.optimize(). It was my first line before following the online example.
Solution: Call the optimization function only after you use no longer need getHeightAtCoordinates.
I think I found the problem: the optimize function changes the ground’s _subdivisionsX and _subdivisionsY to the provided chunksCount parameter, which is the number of submeshes to create — while those variables actually represent the number of quads the ground is subdivided into.
Could you try if setting _subdivisionsX and _subdivisionsY to their original value after you called the optimize function solved your problem?
Just to clarify, with getHeightAtCoordinates I’m looking for the Y coordinate at a point (x,z) so the mesh I want to place is over the ground.
Then, you want me to set up _subdivisionsX and _subdivisionsY to their original value. Initially, this is only one value: subdivisions. Originally is: subdivitionsValue^-2? or I should get it to save it and set it up back?
@Gijs
Unfortunately, this solution is not working. I don’t know if this make sense to you, but when added the code you suggested, the ground was no visible anymore. although the other elements were placed correctly. So maybe it recalculates the surface??