Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.48k stars 233 forks source link

What is easiest way to access block geometry? #187

Open slapin opened 3 years ago

slapin commented 3 years ago

Hi,

I generate terrain geometry via class inheriting from VoxelStream and get some nice results. Thanks a lot for the great work! But to turn it into usable terrain I need to populate it with additional objects.

I need to access block geometry most efficiently for

  1. Navmesh. I need to generate navigation mesh for AIs to go around terrain.

  2. Object placement. I need to place objects like buildings, grass, trees on top of voxel terrain.

Is there any solution about getting access to generated geometry? The best would be to avoid unnecessary geometry, but for now anything would be nice.

Thanks!

Zylann commented 3 years ago

Block meshes belonging to a terrain are currently unavailable, but they may be in the future. For now, raycasting is the only way to query geometry surface. Note, even if access to the mesh is provided, it still won't be the best way to spawn things on top because Mesh is for rendering so it might not give best performance to query vertices.

Currently one way is to use the voxels themselves within the block_loaded signal callback, although for smooth terrain it may not be practical since you have to iterate through the gradient and find the zero-cross. If your goal is to spawn things on top you could try using a raycast as well, or use custom data from your generator passed using block metadata (i.e if your world is mostly based on a heightmap with modifiers, you know more or less where you would place props on it). I still have to write documentation about the metadata system tho.

Navmesh sounds extremely annoying to generate in a voxel world. I'm really suspicious about the efficiency of making one from the mesh, because not only again mesh is a rendering data structure (while vertices could be made available in plain from the polygonizer), but a navmesh needs to be seamless across streamed blocks, offset from the mesh somehow to let agents cruise on it, and not be hanging upside down. I dunno what you planned to do, but I was thinking of on-the-fly techniques using voxels directly or dynamic point clouds instead (never tried yet, just random ideas). You could theoretically bake a navmesh using Godot tools, but only if the voxel terrain is finite and static (and baking takes a bunch).

slapin commented 3 years ago

Well, tiled navmesh from Detour (recastnavigation suite) is quite capable to do this at runtime and can have various inputs. Also I doubt that what works for collision generation won't work for navmesh, it definitely should. Anyway my current priority is object placement. But navmesh might help with this task too via polygon filtering and marking... But I still need planB and higher lods still need foliage...

The goal is to get all vertices with normals looking up enough for a tree and grass patch to stay. Also limited by height. Maybe this can be helped a lot my mesher directly by providing vertex index list for all good vertices.

On Tue, Aug 25, 2020 at 6:33 PM Marc notifications@github.com wrote:

Block meshes belonging to a terrain are currently unavailable, but they may be in the future. Note, even if access to the mesh is provided, it still won't be the best way to spawn things on top because Mesh is for rendering so it might not give best performance to query vertices.

Currently one way is to use the voxels themselves within the block_loaded signal callback, although for smooth terrain it may not be practical since you have to iterate through the gradient and find the zero-cross. If your goal is to spawn things on top you could try using a raycast as well.

Navmesh sounds extremely annoying to generate in a voxel world. I'm really suspicious about the efficiency of making one from the mesh, because not only again mesh is a rendering data structure (while vertices could be made available in plain from the polygonizer), but a navmesh needs to be seamless and offset from the mesh somehow to let agents cruise on it. I dunno what you planned to do, but I was thinking of different techniques using voxels directly or dynamic point clouds (never tried yet, just random ideas).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Zylann/godot_voxel/issues/187#issuecomment-680099698, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABPU3C5VNXFFR5MX2VQSTSCPKT5ANCNFSM4QKRIPKQ .

slapin commented 3 years ago

I did direct geometry-based approach. It works.

Toupoc commented 5 months ago

I did direct geometry-based approach. It works.

I know this is an old conversation but I'm having trouble finding a solution for navigation on Zylann's voxel terrains. Can you elaborate a little on the solution you found?

slapin commented 5 months ago

That really depends on your task. As my terrain is mostly static with only a few things changed, I just added Detour for navigation (because current Godot navmesh is too slow to get. using my editor I create heightmap (which is used to create terrain) and placement mask (which marks some parts unpassable). Because I have quite low-detailed terrain and need no precise motion, both are 512x512 bitmaps (can be stored as pngs).

If you really need meshes, you can modify the code to get you all chunk meshes from your world instead of heightmap approach.

Then I produce recast/detour tiled navmesh from this data using code from detour demo (I generate geometry from heightmap and mask and supply that to detour removeing geometry for large holes in mask and marking as unpassable leter for smaller things. The mesh is chunked so saved/loaded on demand by parts in runtime w/o delays in threads. Look at recastnavigation demo for examples of everything. If you do something with roads make sure to produce simple but precise geometry for that so that vehicles/characters do not shortcut your corners. Also always query navmesh in background threads for big world.

In game I just load parts of navmesh on demand. I also make lowres version of navmesh to contain whole world for queries outside player's view. There are a lot of options possible for some better performance, like using hierarchical navigation, but that is out of scope I guess.

On Sun, Feb 4, 2024 at 4:42 AM Toupoc @.***> wrote:

I did direct geometry-based approach. It works.

I know this is an old conversation but I'm having trouble finding a solution for navigation on Zylann's voxel terrains. Can you elaborate a little on the solution you found?

— Reply to this email directly, view it on GitHub https://github.com/Zylann/godot_voxel/issues/187#issuecomment-1925530659, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABPUZPHABQA65FVK7T4RLYR3RP3AVCNFSM4QKRIPK2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJSGU2TGMBWGU4Q . You are receiving this because you authored the thread.Message ID: @.***>