ShiVa Developer Forum • View topic - Runtime terrain creation
 

Runtime terrain creation

Shaders, Level design, Sound design, Special effects

Runtime terrain creation

Postby javlik » 2017-01-02 00:24

Hi,
is there a way to create a terrain programmatically in Shiva? I mean I am looking for a set of functions which enable me to:

- Create a new heightmap (e.g. with help of the perline noise alg.)
- Generate a new terrain from this heightmap with all the great terrain capabilities inbuilt in ShiVa (vegetation, collision detection for each chunk)

Is something like this possible in ShiVa? If yes, how?
Thanks
javlik
Fresh Boarder
Fresh Boarder
 
Posts: 14
Joined: 2014-10-07 21:50

Re: Runtime terrain creation

Postby broozar » 2017-01-02 02:02

hi,

not as "terrain" (with texutre layers, vegetation, terrain api functions etc.), no. however you can create meshes at runtime, which act like models. there is no built-in functionality to read a greyscale texture and modify mesh points, so you would have to write that yourself.

you are essentially asking for a runtime version of the terrain creator module (read heightmap, create mesh chunks, create/assign/render textures, ...) which is possible, but also a lot of work, if you were to do it yourself.

in short: it's not impossible, but the functionality is not included right now.
User avatar
broozar
Administrator
Administrator
 
Posts: 4172
Joined: 2007-09-16 10:22
Location: Berlin - Germany

Re: Runtime terrain creation

Postby Fraser » 2017-01-02 15:06

To expand on what @broozar says:

pixelmap.getPixel and setPixel could be used to read/create a heightmap.

Then a chunked terrain model could be made by simply creating a tessalated XZ plane model and runtime modifying the meshes vertex heights and normals. For more code control you could stitch whole chunks at runtime.

Basic runtime stitching code:
Code: Select all
    ----------------------------------------------------------------------------------------------------
    --  STITCH MESH

    -- At this point hObject is just any simple model using the material you require, we will replace its existing mesh with a new one:

    local hMesh = shape.createRuntimeMesh ( hObject )
    mesh.addSubset ( hMesh )
    mesh.createSubsetVertexBuffer ( hMesh, 0, 4 )
    mesh.createSubsetIndexBuffer ( hMesh, 0, 0, 6 )
    mesh.lockSubsetVertexBuffer ( hMesh, 0, mesh.kLockModeWrite )
    mesh.lockSubsetIndexBuffer ( hMesh, 0, 0, mesh.kLockModeWrite )
   
    --  SET VERTEX
    --  2 3
    --  0 1
    mesh.setSubsetVertexPosition ( hMesh, 0, 0, nSizeX*-0.5, nSizeY*-0.5, 0 )
    mesh.setSubsetVertexPosition ( hMesh, 0, 1, nSizeX* 0.5, nSizeY*-0.5, 0 )
    mesh.setSubsetVertexPosition ( hMesh, 0, 2, nSizeX*-0.5, nSizeY* 0.5, 0 )
    mesh.setSubsetVertexPosition ( hMesh, 0, 3, nSizeX* 0.5, nSizeY* 0.5, 0 )
   
    mesh.setSubsetVertexNormal ( hMesh, 0, 0, 0, 0, 1 )
    mesh.setSubsetVertexNormal ( hMesh, 0, 1, 0, 0, 1 )
    mesh.setSubsetVertexNormal ( hMesh, 0, 2, 0, 0, 1 )
    mesh.setSubsetVertexNormal ( hMesh, 0, 3, 0, 0, 1 )
   
    mesh.setSubsetVertexTexCoord ( hMesh, 0, 0, 0, nU, nV )
    mesh.setSubsetVertexTexCoord ( hMesh, 0, 1, 0, nU+nSpanU, nV )
    mesh.setSubsetVertexTexCoord ( hMesh, 0, 2, 0, nU, nV+nSpanV )
    mesh.setSubsetVertexTexCoord ( hMesh, 0, 3, 0, nU+nSpanU, nV+nSpanV )
    --  SET INDEX
    mesh.setSubsetIndexValue ( hMesh, 0, 0, 0, 0 )
    mesh.setSubsetIndexValue ( hMesh, 0, 0, 1, 1 )
    mesh.setSubsetIndexValue ( hMesh, 0, 0, 2, 3 )
    mesh.setSubsetIndexValue ( hMesh, 0, 0, 3, 0 )
    mesh.setSubsetIndexValue ( hMesh, 0, 0, 4, 3 )
    mesh.setSubsetIndexValue ( hMesh, 0, 0, 5, 2 )
    --  DONE
    mesh.unlockSubsetVertexBuffer ( hMesh, 0 )
    mesh.unlockSubsetIndexBuffer ( hMesh, 0, 0 )
    mesh.updateBoundingVolumes ( hMesh )


RE Runtime mesh creation: Yes it can take some time to implement, but for me worth it; For example to manage the model assets of 180 golf holes using conventional 3D modelling tools would require lots of work, and then say you wanted to quickly change something common to all 180 models, maybe change the curved edge break angles, ouch, RSI city!

But after making a stitcher that turns ASCII course maps into meshes such an adjustment is easy, just a single variable in the code.
https://twitter.com/SiliconDroid/status ... 9136175108
https://twitter.com/SiliconDroid/status ... 4445499392
It also opens the door for user generated courses, which is nice.
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1324
Joined: 2012-02-05 19:28
Location: Europe

Re: Runtime terrain creation

Postby javlik » 2017-01-03 21:26

Well,
I am going to do some tests and then, according to the results, I will choose the most appropriate solution for my project.
Anyway, your replies are very appreciated.
Thanks to both of you guys.
javlik
Fresh Boarder
Fresh Boarder
 
Posts: 14
Joined: 2014-10-07 21:50


Return to Creation

Who is online

Users browsing this forum: No registered users and 0 guests

cron