BabylonJS / Extensions

Extensions for Babylon.js
178 stars 157 forks source link

added LODOnlyPositiveX and Z + fix + doc #145

Closed jbousquie closed 6 years ago

jbousquie commented 6 years ago

Actually we can set the camera at any wanted position. The terrain is hooked to the camera and will follow it as the camera moves.
By default, the camera is linked to the terrain center what can be useful when the camera spins around so the terrain keeps visible in any direction. This is also useful in the case where the camera gets some altitude and looks at the terrain below.
However we could want sometimes to hook the camera to a different location on the terrain : let's imagine that our camera will, for instance, move mainly along the Z World axis always looking straight ahead. In this case, the quads behind the terrain center would be computed but never visible. Just CPU waste. So setting the camera near the terrain lower edge would allow to see all the computed quads and even to expand the visible area far away.
This is possible by using the property .shiftFromCamera that is a Vector2-like object, set by default to {x:0, z:0}.
Note : it's not a real Vector2 because its member are x and z (not y).
This can be set and changed at any time.

terrain.shiftFromCamera.z = 100.0;  // shifts the terrain +100 in front of the camera
terrain.shiftFromCamera.x = 100.0;  // shifts the terrain +100 right to the camera

If some perimetric LOD was defined, we probably don't want to see bigger quads in the first plan. So we can also force the computation the LOD only for terrain upper (positiveZ) or right (positiveX) edges only.
The boolean properties .LODOnlyPositiveX and .LODOnlyPositiveZ will allow/prevent to compute the perimetric LOD on right and upper edges. They can be set at any time (default false).

terrain.LODOnlyPositiveX = true; // stops the perimetric LOD computation on the terrain right edge
terrain.LODOnlyPositiveZ = true; // stops the perimetric LOD computation on the terrain upper edge