Skip to content

Commit fc827bb

Browse files
committed
Merge pull request godotengine#104310 from mihe/jolt/back-face-collision
Fix `ConcavePolygonShape3D` always enabling `backface_collision` when using Jolt Physics
2 parents 777ad0b + 3603a5a commit fc827bb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

modules/jolt_physics/shapes/jolt_custom_double_sided_shape.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ void collide_double_sided_vs_shape(const JPH::Shape *p_shape1, const JPH::Shape
4949
const JoltCustomDoubleSidedShape *shape1 = static_cast<const JoltCustomDoubleSidedShape *>(p_shape1);
5050

5151
JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;
52-
new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;
52+
if (shape1->should_collide_with_back_faces()) {
53+
new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;
54+
}
5355

5456
JPH::CollisionDispatch::sCollideShapeVsShape(shape1->GetInnerShape(), p_shape2, p_scale1, p_scale2, p_center_of_mass_transform1, p_center_of_mass_transform2, p_sub_shape_id_creator1, p_sub_shape_id_creator2, new_collide_shape_settings, p_collector, p_shape_filter);
5557
}
@@ -60,7 +62,9 @@ void collide_shape_vs_double_sided(const JPH::Shape *p_shape1, const JPH::Shape
6062
const JoltCustomDoubleSidedShape *shape2 = static_cast<const JoltCustomDoubleSidedShape *>(p_shape2);
6163

6264
JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;
63-
new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;
65+
if (shape2->should_collide_with_back_faces()) {
66+
new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;
67+
}
6468

6569
JPH::CollisionDispatch::sCollideShapeVsShape(p_shape1, shape2->GetInnerShape(), p_scale1, p_scale2, p_center_of_mass_transform1, p_center_of_mass_transform2, p_sub_shape_id_creator1, p_sub_shape_id_creator2, new_collide_shape_settings, p_collector, p_shape_filter);
6670
}
@@ -71,7 +75,9 @@ void cast_shape_vs_double_sided(const JPH::ShapeCast &p_shape_cast, const JPH::S
7175
const JoltCustomDoubleSidedShape *shape = static_cast<const JoltCustomDoubleSidedShape *>(p_shape);
7276

7377
JPH::ShapeCastSettings new_shape_cast_settings = p_shape_cast_settings;
74-
new_shape_cast_settings.mBackFaceModeTriangles = JPH::EBackFaceMode::CollideWithBackFaces;
78+
if (shape->should_collide_with_back_faces()) {
79+
new_shape_cast_settings.mBackFaceModeTriangles = JPH::EBackFaceMode::CollideWithBackFaces;
80+
}
7581

7682
JPH::CollisionDispatch::sCastShapeVsShapeLocalSpace(p_shape_cast, new_shape_cast_settings, shape->GetInnerShape(), p_scale, p_shape_filter, p_center_of_mass_transform2, p_sub_shape_id_creator1, p_sub_shape_id_creator2, p_collector);
7783
}
@@ -104,8 +110,7 @@ void JoltCustomDoubleSidedShape::register_type() {
104110

105111
void JoltCustomDoubleSidedShape::CastRay(const JPH::RayCast &p_ray, const JPH::RayCastSettings &p_ray_cast_settings, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::CastRayCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) const {
106112
JPH::RayCastSettings new_ray_cast_settings = p_ray_cast_settings;
107-
108-
if (!back_face_collision) {
113+
if (!should_collide_with_back_faces()) {
109114
new_ray_cast_settings.SetBackFaceMode(JPH::EBackFaceMode::IgnoreBackFaces);
110115
}
111116

modules/jolt_physics/shapes/jolt_custom_double_sided_shape.h

+2
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ class JoltCustomDoubleSidedShape final : public JoltCustomDecoratedShape {
6868
JoltCustomDecoratedShape(JoltCustomShapeSubType::DOUBLE_SIDED, p_inner_shape), back_face_collision(p_back_face_collision) {}
6969

7070
virtual void CastRay(const JPH::RayCast &p_ray, const JPH::RayCastSettings &p_ray_cast_settings, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::CastRayCollector &p_collector, const JPH::ShapeFilter &p_shape_filter = JPH::ShapeFilter()) const override;
71+
72+
bool should_collide_with_back_faces() const { return back_face_collision; }
7173
};

0 commit comments

Comments
 (0)