godotengine / godotengine/godot
gltf convex shapes are "incorrect" sometimes (importing with gltf physics extensions)
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
4.3 stable, 4.2.2 stable
### System information
win 10
### Issue description
I'm working with a small community of 3D godot friends, on an open source level editor made for Godot (and others), in Blender as an addon.
Part of this addon covers the godot core implementation of GLTFPhysicsShape and GLTFPhysicsBody for creating level geometry from blender and exporting the gltf with the physics extensions built in. The extensions are `OMI_physics_body` and `OMI_physics_shape`.
Here is an example of this gltf file imported into godot:

I tested trimesh shapes, works fine as far as I know. I made sure that the meshes where correct and simplified (cube-like) and generally had 8 vertexes each to test convex shapes.
However I have run into an issue with using convex shapes from blender meshes, and I'm trying to find out why _sometimes_ the convex shapes seem to be adding an extra vertex incorrectly. For example, with a box mesh in blender, you can export it and it will make a collision shape and node using that mesh.. HOWEVER, in godot's collision shape, on one face it will make a triangle, therefore adding an extra vertex. imagine a box with a diagonal strike on one face to make 2 triangle faces. If a character body collides with this shape, it phases through that face. Sometimes it adds more than one "strike". Sometimes the vertexes are ordered in a strange way.
So, a box is struggling sometimes but i don't know how to trigger that. Then, if you subdivide the shape in blender, it totally breaks the convex collision shape generated by godot, it adds all kinds of vectors everywhere.
From what I've been told a bit by @aaronfranke it calls the Godot implementation and is not something related to the gltf implementation:
https://github.com/godotengine/godot/blob/1bd740d18d714f815486b04bf4c6154ef6c355d9/modules/gltf/extensions/physics/gltf_physics_shape.cpp#L255
What I'm thinking is, Blender's meshes might not be suitable for godot's convex shapes, as they might use a different system for counting vertexes or something like that.
### Steps to reproduce
This another problem. The implementation is too specific to what I'm doing that it would be very difficult to reproduce this easily without using Blender and this very specific (almost hidden) implementation of gltf. It was just added recently to 4.3 core, but not many people know how to implement this so I'm trying to indirectly contribute to godot from the outside - so I think it is worthwhile to at least make an issue.
It could be a problem with how blenders shapes directly become a godot convex shape. But it could be something else I don't know about related to physics.
I _can_ give some example .gltf files (but how to test them? it would just be to inpsect the incorrect shapes.), and I can share some videos and images of what is happening. I can also share an MRP.
### Minimal reproduction project (MRP)
I will post one over the next few days. I want to provide the most minimal MRP I can thats readable and not confusing
Contributor guide
Research direction
Start with modules/gltf/extensions/physics/gltf_physics_shape.cpp around line 255 and inspect how the convex shape is created from imported glTF physics data. Reproduce the issue using the promised minimal reproduction project or supplied .gltf files, comparing Blender meshes with Godot's generated collision shapes. Done means identifying and fixing the cause of incorrect or extra vertices, with a reproducible test case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- blender, cpp
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100