godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Allow creating colliders from multiple meshes at once #508

Open aaronfranke opened 4 years ago

aaronfranke commented 4 years ago

Describe the project you are working on:

I recently bought an asset pack with hundreds of meshes. I would like to create collisions for all of them, so that I can have a character moving around a level built with the meshes.

Describe the problem or limitation you are having in your project:

In Godot, we can use this menu to create collisions when a MeshInstance is selected:

Untitled

The limitation that I am facing is that there is no way to do this in bulk through the editor. If you select multiple MeshInstance nodes, you can't open this menu.

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

The feature would be that the button would show up when you have multiple MeshInstance nodes selected, allowing you to create colliders for all of them at once.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

I took a look at the existing code in mesh_instance_editor_plugin.cpp. It appears to be hard-coded to work with exactly one object. This would require a significant rewrite of this code.

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

Yes, it can. However, this is supposed to be an editor feature, so it isn't ideal to do so.

https://godotengine.org/asset-library/asset/603

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

Because it's an expansion of an existing editor feature, to make it work with multiple nodes.

Okxa commented 9 months ago

On 4.2 the menu shows up and it is possible to create some colliders, however it's not perfect.

Now it is possible to use "Create Trimesh Static Body" if you have multiple MeshInstances selected. That results in each MeshInstance getting its own staticbody child:

image

The other options generate the colliders only for the first selected node. Here is result of "Create Trimesh Collision Sibling"

image

As for workarounds, with editor plugins it is possible to get selection with EditorInterface.get_selection().get_selected_nodes() and check if there are any MeshInstance3D nodes, and then generate collision with MeshInstance3D or Mesh functions.

MeshInstance3D helper functions like MeshInstance3D.create_trimesh_collision() seem to only create child nodes, not siblings.

Mesh however has functions to only create shapes, such as Mesh.create_trimesh_shape(), but then you must create the CollisionShape3D node manually.