Jump to content

Dynamic Terrain


jerome
 Share

Recommended Posts

Hi folks,

Maybe some of you followed this topic for while :

Well, now I'm proud to announce the fully documented first release of the Dynamic Terrain Extension : https://github.com/BabylonJS/Extensions/tree/master/DynamicTerrain

Its documentation is one the same repo : https://github.com/BabylonJS/Extensions/blob/master/DynamicTerrain/documentation/dynamicTerrainDocumentation.md

Have fun

Some more demos and features to come ;)

Link to comment
Share on other sites

I'll probably try it one day. it sounds cool, but it also seems complex at first. But I intend when I would look over, to add this to my terrain editor.

Great work on this land dynamic.

I have a question, the vertexes can be dynamically raise ? (as on my terrain editor)

We can add a dynamic texture for the paint?

Thanks

Link to comment
Share on other sites

  • 1 month later...
1 hour ago, jerome said:

Oh, great, my bad for not looking more thoroughly :) 

Sorry, another question (last I hope), does DynamicTerrain support something like .dataFromHeightMap (possibly with an offset option so a different portion of the image could be used when the player walks around)?

Link to comment
Share on other sites

New internal improvement :

Now when you set a data map to the terrain, all the map normals are pre-computed once and stored internally. This is a heavy operation, but done only once.

Then the terrain mesh uses now by default all these pre-computed normals instead of recomputing its own ones each time it's updated. If the terrain is very large, its normal re-computation can be an intensive process what impacts the FPS.

So, unless you request it explicitly with

terrain.computeNormals = true; // now false by default

the mesh normal computation is now skipped.

Documentation updated : https://github.com/BabylonJS/Extensions/blob/master/DynamicTerrain/documentation/dynamicTerrainDocumentation.md#normal-map

In brief, you don't need to care any longer about the normal optimizations with large terrains.

Link to comment
Share on other sites

No change in the API but some internal changes to ease and speed up the Dynamic Terrain

Added the ability to pre-compute statically many normal maps before assigning some new data maps to the terrain :

var map1 = someFloat32Array;
var map2 = someOtherFloat32Array;
var map3 = someOtherFloat32Array;
var normal1 = new Float32Array(map1.length);
var normal2 = new Float32Array(map2.length);
var normal3 = new Float32Array(map3.length);
// let's precompute the normals of all the maps
DynamicTerrain.ComputeNormalsFromMapToRef(map1, subX1, subY1, normal1);
DynamicTerrain.ComputeNormalsFromMapToRef(map2, subX2, subY2, normal2);
DynamicTerrain.ComputeNormalsFromMapToRef(map3, subX3, subY3, normal3);

So now the change of data map on the fly can be associated with the change of normal map (so no interleave normal computation)

var map2 = someOtherFloat32Array;
var normal2 = new Float32Array(map2.length);
DynamicTerrain.ComputeNormalsFromMapToRef(map2, subX2, subY2, normal2);

// then, later in the code ...
if (cond) {
    terrain.mapData = map2;
    terrain.mapNormals = normals2;
}

The map normals are precomputed automatically only at terrain construction time. If we want this automatic computation goes on for any new map assignment to the terrain, we can force it with

terrain.precomputeNormalsFromMap = true;

 

Added also the property .isAlwaysVisible to force the mesh direct selection in the culling process when we know the terrain is always in the camera fov.

 

Documentation updated as well : https://github.com/BabylonJS/Extensions/blob/master/DynamicTerrain/documentation/dynamicTerrainDocumentation.md

Link to comment
Share on other sites

@jerome looking *really* good!
Any chance of an example of a game-style terrain? Something with a first person character running around on grassy hills with a far view distance + fog so we can see how it performs in a more real-world use case.

 

 

Link to comment
Share on other sites

First clean and commented example : http://www.babylonjs-playground.com/#FJNR5#129

You should start flying initially from the Sahara towards the Europe if I'm not wrong.

I generated a big map, sized 10000 x 10000 units in the World. This map holds 1 million of points (1000 x 1000). It's generated from a symetric image so we can fly endlessly around the world in all the directions : earthDouble.png

The terrain is 150 x 150 quads. I just added a little LOD in the distance.

Then everything is quite optimized : the terrain is set as always visible (no culling), the map normals are precomputed, as well for the map UV.

 

So, ladies and gentlemen, welcome on board. The crew wishes to you an excellent flight in our skies. The meteological conditions may be good during your trip. We expect to NEVER land, nor crash and fly forever at the cruise speed of 60 FPS :D

 

Same link without editor : http://www.babylonjs-playground.com/frame.html#FJNR5#129

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...