THREE.Terrain
THREE.Terrain copied to clipboard
Implement Optimizations
I’m interested in implementing optimizations, I see you’ve started naming them, and I have interest in using GEOCLIPMAP, and even try to combine it to also use POLYGONREDUCTION.
Are you planning to release optimizations?
I could try implementing it myself too, where could I add it? Any recommendations?
I haven't actively worked on this project, other than occasional maintenance to keep it compatible with Three.js updates, in many years. So unfortunately I do not have any optimizations stored away waiting to be released 🙂 The references you see to things like GEOCLIPMAP are a sign of the unfulfilled ambitions I had for this library.
Thanks for your interest in contributing. I would certainly accept contributions, though I might not be able to review them super quickly.
where could I add it? Any recommendations?
-
POLYGONREDUCTION
is a relatively simple pass over the geometry. The main issue is that once it happens, the vertices are no longer in a grid, so some of the math of the various filters/generators/etc. no longer work. So, it would need to be applied insideTHREE.Terrain.Normalize
insrc/core.js
, before theafter
callback. (Note that some things that use theafter
callback would need to be aware of this, like scattering meshes on the surface of the terrain randomly per face.) - The easiest way to do
GEOMIPMAP
is to generate the high detail mesh as usual, but then after theNormalize
step, generate a bunch of new meshes at varying levels of detail for different sections of the terrain. Add those all to the scene returned byTHREE.Terrain()
, then the caller would be responsible for showing/hiding the relevant meshes based on the camera position (for example usingTHREE.LOD()
) or you could add a helpful wrapper. Note that there are some tricky details with seams between different LODs. You also need to be careful about meshes placed on the surface of the terrain suddenly not being on the surface once the meshes are switched out for a different LOD. -
GEOCLIPMAP
is relatively hard because you have to morph the geometry as the camera moves. You can do this by generating different LODs like with mipmapping (though you don't need to split the terrain into sections) and then writing a shader to interpolate the terrain heights based on the camera position. The TriggerRally example linked in the code is still there, and that's how it works. There is some literature on more advanced methods, where for example you can compress the high detail terrain (along the lines ofPOLYGONREDUCTION
) and then interpolate higher detail on demand.