Generating a planet mesh

MirceaKitsuneMirceaKitsune Posts: 43Member
in 3D

I'm trying to create a planet, using either the builtin sphere mesh or generating my mesh on the fly if that's better. I want it to contain real valleys and mountains, for which I'm planning to use the Open Simplex module to generate a noise map. Stuff like player navigation / orientation should be fairly easy to script, Godot seems to make spider physics easy... I am however stuck on three aspects I need your help with for starters:

  1. How do I offset the vertices of the sphere toward or away from its center? With a plane this is easier as you can just go from start to end across the X and Z directions... in this case however the noise must be mapped to the body of a sphere. I don't mind doing it with either GDScript or a shader (whichever is better) though it mustn't break #2:
  2. Once 1 is working, how do I make the deformed shape of the sphere collide so physical items interact with the terrain?
  3. For the material, how would I blend different textures based on height so each height level has its own ground, and ideally blend one based on slope so the more vertical a part is the more rocky it looks? I'm assuming I can use the heightmap noise as a splatmap too, but have no idea how to blend different textures or materials with it. Note that each texture will have albedo, roughness, depth (parallax), normal map... and ideally also an alpha channel to be used for realistic blending.

I know this is all a bit complicated but doable, but I need some script pointers to start with. I can offer a little hint to my own question: It is mathematically possible to pack a flat plane into a sphere... I could use this to generate the terrain as a plane more easily, but doing it this way may cause ugly seams so maybe I use a sphere from the start.


Tags :

Best Answers

  • MegalomaniakMegalomaniak Posts: 2,658
    Accepted Answer

    Codat has some videos on youtube that might interest you.
    https://www.youtube.com/channel/UCSWBKqm0Rxxi-yZa0zyvDjA/videos

  • cyberealitycybereality Posts: 927
    Accepted Answer

    You can use MeshDataTool to modify vertices loaded in from a model.
    https://docs.godotengine.org/en/3.2/tutorials/content/procedural_geometry/meshdatatool.html

    So import a high poly sphere and use MeshDataTool to iterate through the vertices and adjust them based on the height map. I don't think a shader will work because you need to generate a collision shape as well (assuming the world will have collision).

    In Blender (or your DCC tool) make the sphere center zero and make sure to apply all transforms. This way, each vertex is a vector coming off the origin. So to scale the vector by a scalar value you will essentially be moving it forward and away from the center. For example, multiplying the vertex by 0.5 will make it half the size aka halfway in-between it's original position and the center. 2.0 would make it twice as high.

    You can use ConcavePolygonShape to create the collision mesh used with a StaticBody.
    https://docs.godotengine.org/en/3.2/classes/class_concavepolygonshape.html

    You can use vertex colors to set the transition to different textures. MeshDataTool can set vertex colors. I think you want to use one Material, though, and blend the textures in a shader.

    Never tried this in Godot, but I believe that would work (or set you in the right direction at least).

Answers

  • MegalomaniakMegalomaniak Posts: 2,658Admin
    Accepted Answer

    Codat has some videos on youtube that might interest you.
    https://www.youtube.com/channel/UCSWBKqm0Rxxi-yZa0zyvDjA/videos

  • cyberealitycybereality Posts: 927Moderator
    Accepted Answer

    You can use MeshDataTool to modify vertices loaded in from a model.
    https://docs.godotengine.org/en/3.2/tutorials/content/procedural_geometry/meshdatatool.html

    So import a high poly sphere and use MeshDataTool to iterate through the vertices and adjust them based on the height map. I don't think a shader will work because you need to generate a collision shape as well (assuming the world will have collision).

    In Blender (or your DCC tool) make the sphere center zero and make sure to apply all transforms. This way, each vertex is a vector coming off the origin. So to scale the vector by a scalar value you will essentially be moving it forward and away from the center. For example, multiplying the vertex by 0.5 will make it half the size aka halfway in-between it's original position and the center. 2.0 would make it twice as high.

    You can use ConcavePolygonShape to create the collision mesh used with a StaticBody.
    https://docs.godotengine.org/en/3.2/classes/class_concavepolygonshape.html

    You can use vertex colors to set the transition to different textures. MeshDataTool can set vertex colors. I think you want to use one Material, though, and blend the textures in a shader.

    Never tried this in Godot, but I believe that would work (or set you in the right direction at least).

  • MirceaKitsuneMirceaKitsune Posts: 43Member

    @Megalomaniak said:
    Codat has some videos on youtube that might interest you.
    https://www.youtube.com/channel/UCSWBKqm0Rxxi-yZa0zyvDjA/videos

    Thank you, his tutorials actually helped a lot! I think I got the base concept down including working player collisions, still need to adjust it but the basis is there. Only need to figure out the shader now... one of his tutorials includes that bit, if I run into issues I'll ask.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file