Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.59k stars 244 forks source link

Can you use your own meshes as VoxelLodTerrain? #541

Open andzejsp opened 1 year ago

andzejsp commented 1 year ago

Thanks for all the work you have done. Great job!

As i was playing around, i understand that you use some kind of noise input to generate voxel terrain mesh wich later you can like dig down or add more hill etx using the voxel tool/ terrain tool.

But my question is can i for example craft a 3D model in blender and then set it to behave like voxel? So that i can add or subtract mesh data from it. Like if you would import house mesh and shoot it and make a hole in it?

Im a complete noob, just starting with godot and in general with game development, so i might not understand the concepts of all these tools, just asking direct questions.

The idea what i had in mind was to maybe use this noise to generate like overall cave structure but as i read more, and more, its not that easy to get precisely what you want , like intricate details.

So the next move would be to model like tilemap assets in blender and use some sort of random walker to stitch them together but have them be destructable voxels, so that you could dig around the parts etc..

Zylann commented 1 year ago

can i for example craft a 3D model in blender and then set it to behave like voxel? So that i can add or subtract mesh data from it. Like if you would import house mesh and shoot it and make a hole in it?

You can do it, but to a limited extent.

First, the mesh has to be baked into a distance field first using the VoxelMeshSDF resource. That distance field is stored into a 3D voxel grid (so the mesh is no longer used after that). The bigger the resolution, the more details are retained, but the more memory it uses and the more expensive it is to bake. Not all meshes are fit for SDF baking. Ideally, it should be a watertight, closed shape. So for example a flat/deformed plane or a model with very thin details will likely not work well.

To place that SDF on the terrain, there are two ways:

The engine uses Transvoxel for polygonizing voxels, so sharp features are not supported and meshes will look blobby. If you have sharp corners, they will look beveled. More expensive polygonization like dual contouring could improve that, but there is currently no plan to work on it, as Transvoxel is already plenty sufficient for terrains, so it's very low priority.

So the next move would be to model like tilemap assets in blender and use some sort of random walker to stitch them together but have them be destructable voxels, so that you could dig around the parts etc..

VoxelLodTerrain does not work at all like a tilemap. It looks like it would be more like VoxelMesherBlocky and VoxelTerrain, which are used to create terrains composed of simple blocks similar to Minecraft, but that might also not be what you're looking for. There are many ways to do voxel-based terrains and very often if the case isn't common then it involves writing a custom mesher or terrain.

andzejsp commented 1 year ago

Thank you for detailed explanation.