-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Pass indices to trimesh collision shapes; optimize CSG collision #72868
base: master
Are you sure you want to change the base?
Conversation
5c021e6
to
9883c78
Compare
It may be desirable to keep the index data the same as in the original mesh, so I could remove the automatic optimization and add a warning for degenerate triangles instead, as suggested in #47214 (review). |
We could also make indices optional; that would be less compatibility-breaking. Edit: But this requires distinguishing "no indices" from "no triangles" somehow, which seems annoying, considering the ordering of setter calls (e.g. when loading resources). If you set the vertices, should it start creating faces assuming there are no indices? That would be a waste of work if there are indices that will be set shortly after. The alternative of requiring to set indices first would be a weird API. |
This will help implement godotengine/godot-proposals#3603 🙂 meshoptimizer is available in exported projects if I'm not mistaken, so this should be exposable as a function you can call at runtime too. |
9883c78
to
775a285
Compare
I've removed the calls to The internal trimesh collision shape generated for CSG shapes is still optimized using |
270fb17
to
6eff10c
Compare
6eff10c
to
52037dd
Compare
@mihe @fabriceci Could you comment on this API for trimesh collision shapes? In the current version I have the indices always being saved (e.g. to disk), even if they are |
By "this API" I assume you're referring to the notion of using indexed triangles for If so, I'm all for it. This is something Jolt more or less requires for its |
Is there any way for this to maintain compatibility? Or at least provide an intuitive error for users? Perhaps the returned dictionary could provide a faces key, but hidden behind a |
@mihe I was referring more to the implementation detail mentioned in the second half of my comment. I'd really like to avoid saving It is interesting that Godot-Jolt does automatic deduplication and welding of vertices. It's definitely good for performance, and can prevent bugs in some physics algorithms (at least in Godot Physics). In Godot itself this could be done in @clayjohn For compatibility (for those users using |
Judging by your list of indices and the name of Assuming I'm not misunderstand this, and you're willing to consider triangle lists instead, then any notion of optimizing away the indices becomes moot I guess, since triangle lists would be much less predictable in anything but the simplest of cases. Although, would it even have made sense with triangle strips? Would the meshes really be a single continuous strip? I must admit I haven't used triangle strips much ever.
Through what mechanism would you toggle such a setting? Things like the "Create Trimesh Static Body" menu option don't seem to offer much in terms of configuration. I guess the |
Thinking about it some more, I guess converting from strips to lists would be fairly straight-forward, and strips would lead to more space-efficient indices. You'd likely need to marshal the indices/vertices over to whatever third-party engine one-by-one anyway, due to potential differences in size or winding order, so doing a slight conversion along with it isn't all that bad I guess. I'm assuming then that this optimization for the case of |
In Godot Physics the trimesh collision shape (
ConcavePolygonShape3D
) always had the ability to store triangles by storing vertices and (triples of) indices (into the list of vertices), but this ability was only ever used like this:godot/servers/physics_3d/godot_shape_3d.cpp
Lines 1631 to 1633 in a05670c
By adding the ability to pass custom indices, we also gain the ability to run the mesh optimizer (via the static method
SurfaceTool::strip_mesh_arrays
) in the editor (on import, or when generating a collision shape from a mesh). This has the positive effect of eliminating degenerate triangles, which are known to cause collision issues, see e.g. #47214 (comment). This PR applies that optimization to CSG collision shapes; it could also be exposed (as an option) to meshes and the mesh importer.This also paves the way to fixing #69683 (for
ConcavePolygonShape3D
) via the algorithm described in Contact generation for meshes by Pierre Terdiman.Breaks compatibility very slightly, only on the physics server level: the format of
shape_get_data
/shape_set_data
changed from a dictionary with a"faces"
key (PackedVector3Array
value) to a dictionary with a"vertices"
key (PackedVector3Array
value) and an"indices"
key (PackedInt32Array
value).Supersedes #47214.
Production edit: closes godotengine/internal-team-priorities#54