Zylann / godot_voxel

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

How can I create custom mesher? #215

Open slapin opened 3 years ago

slapin commented 3 years ago

Hi! I need to access the generated geometry to do some post-processing on it (i.e. grow plants on surface / other geometry) so I found that creating custom mesher using Transvoxel mesher code would be better way than hacking VoxelLodTerrain itself, so I wonder is it possible to do that without modification of main module code. Any ideas?

Zylann commented 3 years ago

It currently isn't possible to add a custom mesher using the script API. It has to be done in the module. The main reason is that scripts often don't have enough speed to tackle this. Threading is also involved (and it's painful to get it working safely in editor already for generators), and it's a process that could be better served with composition of features. I thought about making meshers a resource at some point but I havent figured out a proper design yet. In fact, if the use case is only to spawn stuff on top of the mesh, you would not need a custom mesher, but a component of some sort on it. Reimplementing just to add something doesnt sound good IMO. At some point I think an API to do this will be added.

slapin commented 3 years ago

I'm fine with module way but so I can do it in isolated way (like generators added) so kind or register mesher with server... The main reason for this is to have additional or extra mesher to interpret voxel data and do something a standard one can't do... The component way is good too, would be nice to see your ideas so my implementation would be in compliant direction.

On Sun, Nov 29, 2020 at 10:28 PM Marc notifications@github.com wrote:

It currently isn't possible to add a custom mesher using the script API. It has to be done in the module. The main reason is that scripts often don't have enough speed to tackle this, and it's a process that could be better served with composition of features. I thought about making meshers a resource at some point but I havent figured out a proper design yet. In fact, if the use case is only to spawn stuff on top of the mesh, you would not need a custom mesher, but a component of some sort on it. Reimplementing just to add something doesnt sound good IMO. At some point I think an API to do this will be added.

— 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/215#issuecomment-735442244, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABPU6I3QH5BEXXTX4UXN3SSKOFRANCNFSM4UF7OJEQ .

Zylann commented 3 years ago

Since this recent change: https://github.com/Zylann/godot_voxel/issues/220 It should now be easier to implement a custom mesher. You still need to do it in the module, but it's no longer hardcoded like it used to be. I recommend reading the details because threading is important to consider when implementing one.