godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

Allow baking of GPUParticlesCollisionSDF3D at runtime #6468

Open m4nu3lf opened 1 year ago

m4nu3lf commented 1 year ago

Describe the project you are working on

A top-down shooter with GridMap based maps.

Describe the problem or limitation you are having in your project

If the map is procedurally generated at runtime, there is no easy and efficient way to add particle collisions.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

By baking the GPUParticlesCollisionSDF3D when the level is generated.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I'm not sure why this feature is absent. I think it shouldn't be hard to expose it at runtime.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It would require a script that manually places particle collision shapes to approximate the shapes of the Gridmap. However, I don't think this would be efficient given the high number of collision shapes.

Is there a reason why this should be core and not an add-on in the asset library?

Baking is already provided in the editor, but there is no way to trigger it at runtime.

Calinou commented 1 year ago

This is the bake function, which is currently not exposed to scripting: https://github.com/godotengine/godot/blob/c1128e911ccd6f1e8c35646df804d894652a58f1/scene/3d/gpu_particles_collision_3d.cpp#L391

It makes sense to expose it to scripting, as VoxelGI can also be baked at run-time (including from a project exported in release mode). The baking code is fairly similar between both if I'm not mistaken.

See how VoxelGI's bake() function is exposed: https://github.com/godotengine/godot/blob/c1128e911ccd6f1e8c35646df804d894652a58f1/scene/3d/voxel_gi.cpp#L516

m4nu3lf commented 1 year ago

I created this PR https://github.com/godotengine/godot/pull/74685