jerome

Dynamic Terrain

Recommended Posts

Well, here's the first working prototype of this new feature : http://jerome.bousquie.fr/BJS/test/terrainSP.html

Demo description :

- the wireframe is the visualization of the map, the logical pool of data describing the relief. Normally, it's not rendered and can be far bigger.

- the textured square is the terrain. It's dynamically morphed to the map data when moving according to the camera position. I didn't activate any LOD or camera elevation correction. Just move the cam and zoom in/out.

- the red sphere is the World origin and the red box shows the north, those are just tags in the space.

=> Another logical pool is added beside the map : a Solid Particle Map (SPMap). It's simply a bunch of data describing where some solid particles are in the World. The solid particles in this map have a type (a shape model), a set of coordinates, a set of rotation values and a set of scaling values. So 9 successive float values per particle of a given type.

So the SPMap is simply an array of arrays.

SPMap[particleType1] = [posx1, posy1, posz1, rotx1, rotx1, rotz1, sclx1, scly1, sclz1, posx2, posy2, posz2, etc ...]   <= list of successive values of particle of type1

SPMap[particleType2] = [posx1, posy1, posz1, rotx1, rotx1, rotz1, sclx1, scly1, sclz1, posx2, posy2, posz2, etc ...]  <= list of successive values of particle of type2

SPMap[ etc ]

In this example type1 is a box, type2 a sphere and type3 a tetrahadron. I randomy populate the SPMap with particle values. There could be dozen thousands or millions objects in the map. There are just set at a fixed location, rotation and scaling.

The SPMap feature of the DynamicTerrain allows to render dynamically only the SPMap objects visible on the terrain with a SPS. This SPS can then be quite little (according to the object density in the map actually).

In this example, I just declared a SPS with 100 boxes, 100 spheres and 100 tetrahedrons what is quite few (less than 300 visible objects is easy to manage for the SPS engine; maybe I could have done it even tinier, didn't test) and I passed this SPS with the SPMap to the DynamicTerrain. And that's all.

The DynamicTerrain will update the SPS for you by recycling automatically the particles per type in order to use and show only the needed ones in the terrain according to the current position and obviously to the SPMap data.

Still a little buggy on the edges : from the terrain perspective the map is infinitely repeated and tiled, but not the SPMap for now. [EDITED] fixed !

Doc coming soon with better examples...

 

What is this for ?

This allows for instance to declare where some objects are located on a map (houses, trees, bridge, buildings... or clouds) and then to render these objects on the terrain with the best possible performance : a small SPS, recycling quickly a light pool of particles.

.

 

Share this post


Link to post
Share on other sites

Please have a look at this better demo : http://jerome.bousquie.fr/BJS/test/terrainSP2.html

- map : 1000 x 1000 points map

- 66511 random particles fixed in the SPMap (well more than 66K)

- terrain : 100 x 100

- sps : 2000 boxes, 2000 spheres, 2000 tetra (it can works with 500 of each if we don't get in altitude to see in the distance), so 6K real particles maximum

So we can manage 66K objects from the map with only 6K (or less, if no LOD) real objects automatically recycled.

 

not sure the LOD is really accurate with the particles ... (edit : I'm sure it's wrong actually)

Share this post


Link to post
Share on other sites

New feature for the DynamicTerrain : per object color and texture.
The previous feature added the ability to set objects in an object map, as many as wanted, by setting their positions, rotations and scalings in the map.
A SPS was used to render these objects in the terrain with a reduced pool of recycled solid particles.

This new feature allows now to pass also to the terrain data about object colors and textures (uvs actually) in the same way than object settings.
Example of randomly population of objects in the map with random colors and uvs :

            if (Math.random() > 0.8) {
               let xp = x;
               let yp = y;
               let zp = z;
               
               let ry = Math.random() * 3.6;
               let sx = 0.5 + Math.random();
               let sy = 0.5 + Math.random();
               let sz = 0.5 + Math.random();

               let r = Math.abs(xp) / mapSubX + 0.5;
               let g = Math.abs(zp) / mapSubZ + 0.5;
               let b = Math.abs(yp) / elevationScale + 0.1;

               let u = 0.9 * Math.random();
               let v = 0.9 * Math.random();
               
               let type = index % 3;
               SPmapData[type].push(xp, yp, zp, 0, ry, 0, sx, sy, sz);
               SPcolorData[type].push(r, g, b, 1.0); 
               SPuvData[type].push(u, v, u + 0.1, v + 0.1);
           }

then the terrain creation  with the new parameters SPcolorData and SPuvData :

    var terrainSub = 100;        // terrain subdivisions
    var terrainOptions = {
        terrainSub: terrainSub, 
        mapData: mapData, mapSubX: mapSubX, mapSubZ: mapSubZ, 
        mapColors: mapColors, 
        SPmapData: SPmapData,
        sps: sps,
        SPcolorData: SPcolorData,
        SPuvData: SPuvData
    };
    var terrain = new BABYLON.DynamicTerrain("dt", terrainOptions, scene);
    terrain.mesh.material = terrainMaterial;

That's all ... now each recycled solid particle will be ever given the right settings, colors and uvs when rendering the related object in the terrain.

Documentation to come.

 

Live example : http://jerome.bousquie.fr/BJS/test/terrainSP.html

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.