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

When importing a mesh, allow the user to simplify the created physics TriMesh with mesh optimizer. #82649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

basicer
Copy link
Contributor

@basicer basicer commented Oct 1, 2023

Adds a new simplification option to the model importer when the trimesh physics mesh mode is selected similar to how the options for convex decomposition are presented.

Also adds GDScript exports to generate a convex shapes and trimesh shapes (both simplified and simplified) to ImportMesh match Mesh.

Closes godotengine/godot-proposals#3603, tested with the example project posted there.

@basicer basicer requested review from a team as code owners October 1, 2023 23:59
@basicer
Copy link
Contributor Author

basicer commented Oct 2, 2023

This is my first patch for godot!

I considered also implementing the simplification method on Mesh, but was a bit thrown off by how much code is duplicated between Mesh and ImporterMesh.

@basicer
Copy link
Contributor Author

basicer commented Oct 2, 2023

image

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected. The default parameters seem to generate a collision shape close to the original, but with fewer vertices.

@JoNax97
Copy link
Contributor

JoNax97 commented Oct 2, 2023

I think some of the options can be streamlined. For collision shapes, do we really care about topology? That is to say, do we need to have the 'sloppy' toggle?

@clayjohn
Copy link
Member

clayjohn commented Oct 2, 2023

I think some of the options can be streamlined. For collision shapes, do we really care about topology? That is to say, do we need to have the 'sloppy' toggle?

I agree. These options should be as simple as possible. Ideally just a slider for simplification amount.

@basicer
Copy link
Contributor Author

basicer commented Oct 2, 2023

I thought about a few options to cut down on the number of tweakable but nothing really came out of it. Sometimes the mesh you get from sloppy is closer to the "idea" mesh, sometimes the non-sloppy one is better, it seems to just depend on the model.

As far as trying to combine the target number or vertices and the target error into a single slider, I'm not sure how what sort of formula you would use to translate simplification amount into those two values.

@basicer basicer force-pushed the simplify-trimesh branch 2 times, most recently from ea03473 to 4b2a6e6 Compare October 3, 2023 01:18
@basicer basicer requested a review from Calinou October 3, 2023 17:12
@fire
Copy link
Member

fire commented Oct 5, 2023

As far as trying to combine the target number or vertices and the target error into a single slider, I'm not sure how what sort of formula you would use to translate simplification amount into those two values.

Godot uses the error metric to distance in autolod. Maybe there's something there you can remix.

@basicer basicer force-pushed the simplify-trimesh branch 2 times, most recently from 22950fc to 7ef13cc Compare October 8, 2023 00:03
@basicer
Copy link
Contributor Author

basicer commented Oct 8, 2023

image

I scrapped the slider as it was too laggy with doing the simplification calculation and simplified the whole thing down two three simplification levels. This option only appears when the shape type is Trimesh.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally (rebased on top of master 4a01602), it mostly works as expected.

The single setting with 3 options makes the configuration much easier now.

However, the 3D preview doesn't always update after you change the simplification setting in the Advanced Import Settings dialog. It only seems to be consistently updated when you change the physics type from something else to Trimesh.

Testing project: test_collision_shape_simplify_on_import.zip

Off Low (Conservative)
Screenshot_20240420_233601 png webp Screenshot_20240420_233817 png webp
Medium (Balanced) High (Aggressive)
Screenshot_20240420_233831 png webp Screenshot_20240420_233845 png webp

@basicer
Copy link
Contributor Author

basicer commented Apr 26, 2024

However, the 3D preview doesn't always update after you change the simplification setting in the Advanced Import Settings dialog. It only seems to be consistently updated when you change the physics type from something else to Trimesh.

I rebased this on top of 11d3768 and couldn't reproduce this problem, however I do vaguely remember having it at some point while developing. Does this trigger consistently for you?

@Calinou
Copy link
Member

Calinou commented Apr 26, 2024

Does this trigger consistently for you?

No, it's quite random and unpredictable 🙁

… TriMesh with mesh optimizer.

Adds a new simplification option to the model importer when the trimesh
physics mesh mode is selected similar to how the options for convex
decomposition are presented.

Also adds GDScript exports to generate a convex shapes and trimesh shapes
(both simplified and simplified) to ImportMesh match Mesh.

Closes godotengine/godot-proposals#3603, tested with the example project posted there.

Update doc/classes/MeshSimplificationSettings.xml
Update doc/classes/MeshSimplificationSettings.xml

Co-authored-by: Hugo Locurcio <[email protected]>

Update editor/import/3d/resource_importer_scene.cpp

Co-authored-by: Hugo Locurcio <[email protected]>
@basicer
Copy link
Contributor Author

basicer commented Oct 5, 2024

Alright @Calinou , finally figured out whats going on here. The bug fixed in #97837 masked what was going on here, but should be fixed now :).

@basicer basicer requested a review from Calinou October 5, 2024 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a mesh simplification option for TriMesh collision shape generation in the advanced import settings
5 participants