HungryProton / scatter

Godot engine addon to randomly fill an area with props or other scenes
MIT License
2.07k stars 94 forks source link

"Baked" meshes with colliders #155

Open LoipesMas opened 1 year ago

LoipesMas commented 1 year ago

I would like to have working colliders and pre-bake my multi-mesh instances.

Current situation

Currently (with the version from AssetLib), with the following settings:

there are no colliders in-game. If I enable force rebuild on load, the colliders are created, but then there is a long load time (I have a big map with lots of props). I can also use Create copies render mode, but that has obvious performance impact.

Expected result

Colliders are either also pre-baked, or created on load time (assuming that generating just the colliders would take less time than full rebuild)


I hope that this is technically feasible. Maybe going through the pre-baked multi-mesh instances on load, extracting data from them and creating colliders based on that? Or maybe pre-baking intermediate CollisionShape3D nodes and on load adding them directly to the PhysicsServer?

It's probably related to #111

PS: Thanks for the great addon! :heart:

HungryProton commented 1 year ago

Oh right, because the colliders are added through the physics server when the transforms are generated, they're not saved in the scene.

The easiest way to fix this is to disable Show output on tree (keep the other settings as is) and add a ScatterCache node to the scene instead.

(Also, make sure you manually create the cache folder in res://addons/proton_scatter/cache if you're using the asset lib version, that's something I fixed this morning, so it's only on the GitHub version for now)

LoipesMas commented 1 year ago

Thanks for the quick response!

The easiest way to fix this is to disable Show output on tree (keep the other settings as is) and add a ScatterCache node to the scene instead.

This technically works, but sadly it is as slow as Force rebuild on load without the cache. Both of them take ~8 seconds to fully load my scene. Pre-baked (i.e., Show output on tree enabled) is pretty much instant. This would suggest that the multi-mesh generation is the slow part. Also Create copies and Use particles render modes load faster than instancing, which supports that claim. I would test that hypothesis, but I don't know how to profile that (built-in Godot profiler has failed me).

LoipesMas commented 1 year ago

Turns out the slow part was LOD Generation. If I disable it (in the ScatterItem node), the scene loads fast! About as fast as the pre-baked setup.

Would it be possible to keep the pre-baked meshes (with their already generated LODs), but re-generate colliders, using the ScatterCache? Otherwise I'll have to work around the lack of LOD generation or accept the long load times.

HungryProton commented 1 year ago

I can probably store it on the cache too. I'll look into it.