3D Terrain in Defold?

Its possible to make terrain script on Lua (or C++)? and terrain generation by heightmap for 3D game?

No, generating models at runtime is not possible yet.

@sven started looking into this again. No promises yet though…

2 Likes

You can generate the terrain patches (as collada files) and collection files offline, and load them in as necessary.

I can include native extension (in this case its C++ and OpenGL ES 2.0 TOGETHER) for generating terrain? Or vertex program?

You can use native extension to generate terrain, but it would be hard to make Defold interact with it. All you can do is render your terrain from C++ into a render target. Defold objects would be rendered on top of that texture.

What you can do is have terrain meshes (by that I mean a flat mesh with enough faces to show the geometry in as much detail as you want) of the size you want already created in your project. Then you can generate the terrain texture(s) at runtime and set that texture on the mesh / read the texture x,y data to know how to position stuff. You need to prepare multiple meshes and textures in advance if you want to have multiple terrain patches (as @Mathias_Westerdahl mentions) being used at a time, they have to be unique files. Reading / generating the terrain data would be faster with a native extension but you can do it all on the Lua side too.

Here is a version with prepared in advance terrain texture, but that texture data can be changed at runtime.

Features like caves are possible too although until we have a proper way to modify meshes at runtime it’s something you have to prepare in advance on unique meshes.

It’s been a while since I messed with this, I think I was trying to make a seamless world with multiple meshes and there were some serious problems though with multiple meshes and textures at once which I couldn’t solve. Try it out yourself!

okay, but can i edit model in runtime with lua?

You modify the vertex position in a shader based on the heightmap. Then you use that same texture for knowing how to position things / do collision on the terrain.

1 Like