Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve collision generation usability in the new 3D scene import workflow #3155

Open
AndreaCatania opened this issue Aug 18, 2021 · 17 comments

Comments

@AndreaCatania
Copy link

Describe the project you are working on

A first person game, that has many maps with a lot of colliding meshes (Dynamic and Static).

Describe the problem or limitation you are having in your project

Right now it's difficult to generate the collisions for an imported mesh, so that the model can be drag and drop immediately inside the map.

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

The idea is to enhance the Advanced Editor Import Window, so it's more effective generate collisions for a Mesh.
Screenshot from 2021-08-18 11-54-14

We already have support for generating the colliders, it uses the VHACD lib but we don't have control over it. Also, the editor doesn't show the generated collider either, so it's difficult to handle it.

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

This is a short video that should give an idea on what to expect: https://user-images.githubusercontent.com/8342599/129878371-add60334-513d-43ed-bf07-441d65a0a599.mp4

The new UI will allow to select the collider types using the property generate/physics, and you can select:

  • Disabled (Doesn't generate any collider)
  • Collider (Generated the collider)
  • Collider Only (Generates the collider without importing the mesh) [This option is probably useless now, I'm including it for legacy, but I would be glad to remove it.]

Once the Collider is selected a new set of properties appear:

  • Body type you can specify the body nature Static, a Dynamic, Area.
  • Shape you can select the method how to generate the actual collider shape.

The property Shape allow to select between:

  • Generated Convex: Uses the VHACD algorithm to generate one or more convex shapes, depending on the Mesh.
  • Trimesh: Generates one trimesh shape, following the mesh silhouette.
  • Box: Add a box shape
  • Sphere: Add a shpere shape
  • Cylinder: Add a cylinder shape

Per each of these Shapes, we will have a set of properties that we can use to tweak the generated shape. For example, selecting Generated Convex, the editor will show the VHACD settings, or selecting the Box, we will be able to change the shape position and box sizing.

Notice that the editor will show immediately the generated shape, directly on the Advanced Import Window, so that we can see immediately the final generated shape, and we can more effectively tweak the available settings of the chosen shape.

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

This is an Editor enhancement.

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

This is an Editor enhancement.

@bodamat
Copy link

bodamat commented Aug 18, 2021

In some point generating more than 1 simple collisions per mesh would be also useful

@AndreaCatania
Copy link
Author

Do you have an example? Withe VHACD we should cover more or less all the cases.

@bodamat
Copy link

bodamat commented Aug 18, 2021

Unfortunately, I don't have examples. I'm not expert with VHACD. I imagine this like in Unreal when open mesh editor. There I can create simple collisions and change position, size.

Edit: V-HACD should support custom collision, which can be created in modelling program like Blender. Just need specials letters at the start of object name

@AndreaCatania
Copy link
Author

I imagine this like in Unreal when open mesh editor. There I can create simple collisions and change position, size.

Yup, that's how I imagine it too.

Edit: V-HACD should support custom collision, which can be created in modelling program like Blender. Just need specials letters at the start of object name

We already support custom collision imported via blender, and this one will not change.

@Calinou Calinou changed the title Collision generation on model import Improve collision generation usability in the new 3D scene import workflow Aug 18, 2021
@pouleyKetchoupp
Copy link

pouleyKetchoupp commented Aug 18, 2021

Great idea! It would be useful to have such options.

I have some comments and suggestions:

  • About collider only:

Collider Only (Generates the collider without importing the mesh) [This option is probably useless now, I'm including it for legacy, but I would be glad to remove it.]

Why is it useless now? Is there a different way to disable importing the visual mesh?

  • As already mentioned in the chat, I think capsule could be useful too, since it's faster than cylinder and might fit the shape better in some cases.

  • For generated convex:

Generated Convex: Uses the VHACD algorithm to generate one or more convex shapes, depending on the Mesh.

It would be great to have different modes, because VHACD is a lossy algorithm and in some cases you just want to generate a basic convex hull. It could be another drop-down list in the convex settings to set the generation mode:
-Basic: Keep the exact same geometry, just remove duplicate vertices.
-Simplify: Use VHACD to generate just one convex hull with less vertices, while modifying the geometry a little bit.
-Decompose: Use VHACD to generate multiple convex hulls (current mode, would be the default)
(see godotengine/godot#50262 for the editor options and an example)

Simplify and Decompose would have more settings for VHACD (as you mentioned), and maybe they could be just one option, with a max number of convex hulls to set (so 1 would just simplify).

@AndreaCatania
Copy link
Author

About collider only.

Originally this feature was added to insert meshes that was supposed to be converted to collisions. So in your GLTF you had two meshes, the main one and the collision only one (with postfix -colonly). It still make sense to have that feature has flag (-colonly), but not as part of the UI. Indeed is unlikely that you need to create the RigidBody, with just a collision shape by importing a glft, if you really need a RigidBody, you can just create it using the editor.

Considering this, the best would be to just hide that option from that DD, but still leave the flag -colonly working as usual. What do you think?

As already mentioned in the chat, I think capsule could be useful too, since it's faster than cylinder and might fit the shape better in some cases.

Ok, I'll add that.

For generated convex: [...]

The idea is to expose all the settings that VHACD has, it's definitely useful to know that each mode has a different set of settings, I'll add those! :)

@pouleyKetchoupp
Copy link

Considering this, the best would be to just hide that option from that DD, but still leave the flag -colonly working as usual. What do you think?

Ok, makes sense to remove the option in the UI then.

@AndreaCatania
Copy link
Author

@pouleyKetchoupp now that I've checked how VHACD works, I've few questions on the modes you proposed.

-Basic: Keep the exact same geometry, just remove duplicate vertices.
-Simplify: Use VHACD to generate just one convex hull with less vertices, while modifying the geometry a little bit.
-Decompose: Use VHACD to generate multiple convex hulls (current mode, would be the default)

As you mention, I'll collapse Simplify and Decompose into one. I guess, it made sense differentiate those two modes since it was the only tweaking we could do. Now we can, so have just one option seems the most clean way.

Regarding Basic, it seems like generating a convex shape using all the vertices of the mesh, but however VHACD does the same thing but in a better way, so I wonder what's the benefit of having it at all? If the benefit is just marginal, I think we can just avoid such option, so to keep the UI clean and easy to use.

@AndreaCatania
Copy link
Author

ezgif com-gif-maker(9)

@pouleyKetchoupp
Copy link

Regarding Basic, it seems like generating a convex shape using all the vertices of the mesh, but however VHACD does the same thing but in a better way, so I wonder what's the benefit of having it at all? If the benefit is just marginal, I think we can just avoid such option, so to keep the UI clean and easy to use.

Since VHACD can modify the geometry, Basic is useful because it's the only way to ensure the original vertices are preserved. The only changes it does is removing duplicates. It can be used for example in cases where users just want to keep the exact geometry from a mesh that's already convex.

@AndreaCatania
Copy link
Author

ok make sense, I'll add that too.

@AndreaCatania
Copy link
Author

PR: godotengine/godot#51985

@Shatur
Copy link

Shatur commented Sep 5, 2021

The new workflow is awesome!

I have a suggestion. For now there is a limitation with collision generation for each mesh. Let's imagine I want to create a physics-enabled object. I have two options:

  1. Use the "Dynamic" type for "Body type" in the import menu. In this case I will need to force my artist to merge all meshes into one, because the object will just fall apart if each mesh will has a separate RigidBody3D. Also root node will be Node3D by default, and I will have to create a custom class that exposes the selected RigidBody3D child to apply a force or to get the real translation (because the translation of the parent Node3D will be incorrect).
  2. Make the root scene a RigidBody3D type, do not use the collision settings from the import dialog, and create a post-import script that will generate only CollishionShape3Ds for each mesh and make them children of the root scene.

Both workflows above are inconvenient.
Therefore, I propose to add an additional "Body type" called "Root". In this case, the generated collision will be added as children to the root scene. This way users will be able to use generated collision for the root scene, the type of which they can select in the import settings (this functionality already available since 3.x).

This approach should be better in general, so I proposing to use "Root" for "Body type" by default. In this case your root scene will represent the actual type and it will be convenient to interact with it (for example, apply force or take coordinates) and you will also have less objects:

Before
изображение
After
изображение

What do you think about it?

@Shatur
Copy link

Shatur commented Sep 26, 2021

Opened a proposal about my message above: #3355
Need your feedback / opinions. If the idea is approved, I can send a PR.

@andyp123
Copy link

andyp123 commented Dec 29, 2021

It is possible right now to use post import script to generate collision for your meshes, but generating collisions on import is such a useful feature it should be included as standard in the editor. However, I think it is a good idea to allow users to manually specify meshes to use for collision, as it's possible to make much cleaner convex meshes than vhacd, as well as boxes, capsules and spheres and assign multiple colliders to a single object.

I made a post import script for Godot 3.4 to import collision meshes from a gltf file based on object naming conventions. This workflow is currently broken in Godot 4.0 because the option to import objects in a single file as separate scenes is missing, but I found it very helpful for importing asset pack objects for static level geometry, as I could just drag the scenes from the file tree into the 3d viewport and have collision, and there was no additional manual setup of collision meshes outside of Blender.

Here is an image showing an asset and File Tree view for a game jam game I made. The file RoadParts.glb contained all the various road related assets I was using, and when imported, a scene for each object was generated, each with collision meshes set up exactly how it was in Blender. I really hope we can set up a simple pipeline/workflow for this kind of ease of importing (and reimporting!)

godot_importer-example

The scene hierarchy is shown here, but using the post import script you can arrange it differently (i.e. flat hierarchy, or put the static body as root).

godot_imported-scene

You can see the script here in case you are interested.

Another thing that may be worth mentioning is that generated LODs could potentially be used for collision meshes in cases where a convex decomposition is unsatisfactory, although I'm not so sure how fast or robust non-convex collision is in Godot. Unreal allows this, and it works pretty well for static geometry. I'm mentioning this because Godot got new LOD generation features recently.

@aaronfranke
Copy link
Member

See also godotengine/godot#39924 and the discussion within for ideas on how to improve this workflow.

@aaronfranke
Copy link
Member

As of Godot 4.1, you will be able to specify the collision information inside of the GLTF file. This means that you can set up physics before importing and no configuration in the import dialog will be necessary.

Currently the only way to generate GLTF files with physics information is by exporting from Godot 4.1+, but in the future you will be able to export physics information from Blender.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants