Godot Engine – Multi-platform 2D and 3D game engine
Consolidate Jolt decorator shapes into one and make it a leaf shape
Mikael Hermansson62cd25492d8a
diff --git a/modules/jolt_physics/jolt_globals.cpp b/modules/jolt_physics/jolt_globals.cppindex fb9b4d780a0..36b2d776421 100644--- a/modules/jolt_physics/jolt_globals.cpp+++ b/modules/jolt_physics/jolt_globals.cpp@@ -31,9 +31,8 @@#include "jolt_globals.h"#include "objects/jolt_group_filter.h"-#include "shapes/jolt_custom_double_sided_shape.h"+#include "shapes/jolt_custom_instance_overrides_shape.h"#include "shapes/jolt_custom_ray_shape.h"-#include "shapes/jolt_custom_user_data_shape.h"#include "core/os/memory.h"@@ -109,8 +108,7 @@ void jolt_initialize() {JPH::RegisterTypes();JoltCustomRayShape::register_type();- JoltCustomUserDataShape::register_type();- JoltCustomDoubleSidedShape::register_type();+ JoltCustomInstanceOverridesShape::register_type();JoltGroupFilter::instance = new JoltGroupFilter();JoltGroupFilter::instance->SetEmbedded();diff --git a/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp b/modules/jolt_physics/objects/jolt_shaped_object_3d.cppindex f5e2e4a278c..a367500ad52 100644--- a/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp+++ b/modules/jolt_physics/objects/jolt_shaped_object_3d.cpp@@ -45,10 +45,11 @@ bool JoltShapedObject3D::_is_big() const {}JPH::ShapeRefC JoltShapedObject3D::_try_build_shape(bool p_optimize_compound) {+ bool has_back_face_collision = is_area();int built_shapes = 0;for (JoltShapeInstance3D &shape : shapes) {- if (shape.is_enabled() && shape.try_build()) {+ if (shape.is_enabled() && shape.try_build(has_back_face_collision)) {built_shapes += 1;}}@@ -72,10 +73,6 @@ JPH::ShapeRefC JoltShapedObject3D::_try_build_shape(bool p_optimize_compound) {result = JoltShape3D::with_scale(result, actual_scale);}- if (is_area()) {- result = JoltShape3D::with_double_sided(result, true);- }-return result;}diff --git a/modules/jolt_physics/shapes/jolt_box_shape_3d.h b/modules/jolt_physics/shapes/jolt_box_shape_3d.hindex 476099853e2..2cae6e98961 100644--- a/modules/jolt_physics/shapes/jolt_box_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_box_shape_3d.h@@ -41,6 +41,7 @@ class JoltBoxShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_BOX; }virtual bool is_convex() const override { return true; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_capsule_shape_3d.h b/modules/jolt_physics/shapes/jolt_capsule_shape_3d.hindex 69fae6e54db..5eb5a938f81 100644--- a/modules/jolt_physics/shapes/jolt_capsule_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_capsule_shape_3d.h@@ -41,6 +41,7 @@ class JoltCapsuleShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_CAPSULE; }virtual bool is_convex() const override { return true; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.cpp b/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.cppindex e2a2c1efbe0..0f1e932046d 100644--- a/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.cpp+++ b/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.cpp@@ -75,7 +75,7 @@ JPH::ShapeRefC JoltConcavePolygonShape3D::_build() const {const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to build Jolt Physics concave polygon shape with %s. It returned the following error: '%s'. This shape belongs to %s.", to_string(), to_godot(shape_result.GetError()), _owners_to_string()));- return JoltShape3D::with_double_sided(shape_result.Get(), back_face_collision);+ return shape_result.Get();}AABB JoltConcavePolygonShape3D::_calculate_aabb() const {diff --git a/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.h b/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.hindex 68b33a0adfd..a6f22dcb659 100644--- a/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_concave_polygon_shape_3d.h@@ -44,6 +44,7 @@ class JoltConcavePolygonShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_CONCAVE_POLYGON; }virtual bool is_convex() const override { return false; }+ virtual bool has_back_face_collision() const override { return back_face_collision; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_convex_polygon_shape_3d.h b/modules/jolt_physics/shapes/jolt_convex_polygon_shape_3d.hindex b75424d53af..316a0706f34 100644--- a/modules/jolt_physics/shapes/jolt_convex_polygon_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_convex_polygon_shape_3d.h@@ -44,6 +44,7 @@ class JoltConvexPolygonShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_CONVEX_POLYGON; }virtual bool is_convex() const override { return true; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_custom_double_sided_shape.cpp b/modules/jolt_physics/shapes/jolt_custom_double_sided_shape.cppdeleted file mode 100644index 56eae37a407..00000000000--- a/modules/jolt_physics/shapes/jolt_custom_double_sided_shape.cpp+++ /dev/null@@ -1,116 +0,0 @@-/**************************************************************************/-/* jolt_custom_double_sided_shape.cpp */-/**************************************************************************/-/* This file is part of: */-/* GODOT ENGINE */-/* https://godotengine.org */-/**************************************************************************/-/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */-/* */-/* Permission is hereby granted, free of charge, to any person obtaining */-/* a copy of this software and associated documentation files (the */-/* "Software"), to deal in the Software without restriction, including */-/* without limitation the rights to use, copy, modify, merge, publish, */-/* distribute, sublicense, and/or sell copies of the Software, and to */-/* permit persons to whom the Software is furnished to do so, subject to */-/* the following conditions: */-/* */-/* The above copyright notice and this permission notice shall be */-/* included in all copies or substantial portions of the Software. */-/* */-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */-/**************************************************************************/--#include "jolt_custom_double_sided_shape.h"--#include "core/error/error_macros.h"--#include <Jolt/Physics/Collision/CollisionDispatch.h>-#include <Jolt/Physics/Collision/RayCast.h>--namespace {--JPH::Shape *construct_double_sided() {- return new JoltCustomDoubleSidedShape();-}--void collide_double_sided_vs_shape(const JPH::Shape *p_shape1, const JPH::Shape *p_shape2, JPH::Vec3Arg p_scale1, JPH::Vec3Arg p_scale2, JPH::Mat44Arg p_center_of_mass_transform1, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, const JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {- ERR_FAIL_COND(p_shape1->GetSubType() != JoltCustomShapeSubType::DOUBLE_SIDED);-- const JoltCustomDoubleSidedShape *shape1 = static_cast<const JoltCustomDoubleSidedShape *>(p_shape1);-- JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;- if (shape1->should_collide_with_back_faces()) {- new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;- }-- 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);-}--void collide_shape_vs_double_sided(const JPH::Shape *p_shape1, const JPH::Shape *p_shape2, JPH::Vec3Arg p_scale1, JPH::Vec3Arg p_scale2, JPH::Mat44Arg p_center_of_mass_transform1, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, const JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {- ERR_FAIL_COND(p_shape2->GetSubType() != JoltCustomShapeSubType::DOUBLE_SIDED);-- const JoltCustomDoubleSidedShape *shape2 = static_cast<const JoltCustomDoubleSidedShape *>(p_shape2);-- JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;- if (shape2->should_collide_with_back_faces()) {- new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;- }-- 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);-}--void cast_shape_vs_double_sided(const JPH::ShapeCast &p_shape_cast, const JPH::ShapeCastSettings &p_shape_cast_settings, const JPH::Shape *p_shape, JPH::Vec3Arg p_scale, const JPH::ShapeFilter &p_shape_filter, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, JPH::CastShapeCollector &p_collector) {- ERR_FAIL_COND(p_shape->GetSubType() != JoltCustomShapeSubType::DOUBLE_SIDED);-- const JoltCustomDoubleSidedShape *shape = static_cast<const JoltCustomDoubleSidedShape *>(p_shape);-- JPH::ShapeCastSettings new_shape_cast_settings = p_shape_cast_settings;- if (shape->should_collide_with_back_faces()) {- new_shape_cast_settings.mBackFaceModeTriangles = JPH::EBackFaceMode::CollideWithBackFaces;- }-- 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);-}--} // namespace--JPH::ShapeSettings::ShapeResult JoltCustomDoubleSidedShapeSettings::Create() const {- if (mCachedResult.IsEmpty()) {- new JoltCustomDoubleSidedShape(*this, mCachedResult);- }-- return mCachedResult;-}--void JoltCustomDoubleSidedShape::register_type() {- JPH::ShapeFunctions &shape_functions = JPH::ShapeFunctions::sGet(JoltCustomShapeSubType::DOUBLE_SIDED);-- shape_functions.mConstruct = construct_double_sided;- shape_functions.mColor = JPH::Color::sPurple;-- for (const JPH::EShapeSubType sub_type : JPH::sAllSubShapeTypes) {- JPH::CollisionDispatch::sRegisterCollideShape(JoltCustomShapeSubType::DOUBLE_SIDED, sub_type, collide_double_sided_vs_shape);- JPH::CollisionDispatch::sRegisterCollideShape(sub_type, JoltCustomShapeSubType::DOUBLE_SIDED, collide_shape_vs_double_sided);- }-- for (const JPH::EShapeSubType sub_type : JPH::sConvexSubShapeTypes) {- JPH::CollisionDispatch::sRegisterCastShape(sub_type, JoltCustomShapeSubType::DOUBLE_SIDED, cast_shape_vs_double_sided);- }-}--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 {- JPH::RayCastSettings new_ray_cast_settings = p_ray_cast_settings;- if (!should_collide_with_back_faces()) {- new_ray_cast_settings.SetBackFaceMode(JPH::EBackFaceMode::IgnoreBackFaces);- }-- return mInnerShape->CastRay(p_ray, new_ray_cast_settings, p_sub_shape_id_creator, p_collector, p_shape_filter);-}diff --git a/modules/jolt_physics/shapes/jolt_custom_double_sided_shape.h b/modules/jolt_physics/shapes/jolt_custom_double_sided_shape.hdeleted file mode 100644index 962d2261428..00000000000--- a/modules/jolt_physics/shapes/jolt_custom_double_sided_shape.h+++ /dev/null@@ -1,73 +0,0 @@-/**************************************************************************/-/* jolt_custom_double_sided_shape.h */-/**************************************************************************/-/* This file is part of: */-/* GODOT ENGINE */-/* https://godotengine.org */-/**************************************************************************/-/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */-/* */-/* Permission is hereby granted, free of charge, to any person obtaining */-/* a copy of this software and associated documentation files (the */-/* "Software"), to deal in the Software without restriction, including */-/* without limitation the rights to use, copy, modify, merge, publish, */-/* distribute, sublicense, and/or sell copies of the Software, and to */-/* permit persons to whom the Software is furnished to do so, subject to */-/* the following conditions: */-/* */-/* The above copyright notice and this permission notice shall be */-/* included in all copies or substantial portions of the Software. */-/* */-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */-/**************************************************************************/--#pragma once--#include "jolt_custom_decorated_shape.h"-#include "jolt_custom_shape_type.h"--class JoltCustomDoubleSidedShapeSettings final : public JoltCustomDecoratedShapeSettings {-public:- bool back_face_collision = false;-- JoltCustomDoubleSidedShapeSettings() = default;-- JoltCustomDoubleSidedShapeSettings(const ShapeSettings *p_inner_settings, bool p_back_face_collision) :- JoltCustomDecoratedShapeSettings(p_inner_settings), back_face_collision(p_back_face_collision) {}-- JoltCustomDoubleSidedShapeSettings(const JPH::Shape *p_inner_shape, bool p_back_face_collision) :- JoltCustomDecoratedShapeSettings(p_inner_shape), back_face_collision(p_back_face_collision) {}-- virtual JPH::Shape::ShapeResult Create() const override;-};--class JoltCustomDoubleSidedShape final : public JoltCustomDecoratedShape {- bool back_face_collision = false;--public:- static void register_type();-- JoltCustomDoubleSidedShape() :- JoltCustomDecoratedShape(JoltCustomShapeSubType::DOUBLE_SIDED) {}-- JoltCustomDoubleSidedShape(const JoltCustomDoubleSidedShapeSettings &p_settings, JPH::Shape::ShapeResult &p_result) :- JoltCustomDecoratedShape(JoltCustomShapeSubType::DOUBLE_SIDED, p_settings, p_result), back_face_collision(p_settings.back_face_collision) {- if (!p_result.HasError()) {- p_result.Set(this);- }- }-- JoltCustomDoubleSidedShape(const JPH::Shape *p_inner_shape, bool p_back_face_collision) :- JoltCustomDecoratedShape(JoltCustomShapeSubType::DOUBLE_SIDED, p_inner_shape), back_face_collision(p_back_face_collision) {}-- 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;-- bool should_collide_with_back_faces() const { return back_face_collision; }-};diff --git a/modules/jolt_physics/shapes/jolt_custom_user_data_shape.cpp b/modules/jolt_physics/shapes/jolt_custom_instance_overrides_shape.cppsimilarity index 60%rename from modules/jolt_physics/shapes/jolt_custom_user_data_shape.cpprename to modules/jolt_physics/shapes/jolt_custom_instance_overrides_shape.cppindex c7ce6f30e63..8b41df7e3bc 100644--- a/modules/jolt_physics/shapes/jolt_custom_user_data_shape.cpp+++ b/modules/jolt_physics/shapes/jolt_custom_instance_overrides_shape.cpp@@ -1,5 +1,5 @@/**************************************************************************/-/* jolt_custom_user_data_shape.cpp */+/* jolt_custom_instance_overrides_shape.cpp *//**************************************************************************//* This file is part of: *//* GODOT ENGINE */@@ -28,72 +28,98 @@/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//**************************************************************************/-#include "jolt_custom_user_data_shape.h"+#include "jolt_custom_instance_overrides_shape.h"#include "core/error/error_macros.h"#include <Jolt/Physics/Collision/CollisionDispatch.h>+#include <Jolt/Physics/Collision/RayCast.h>#include <Jolt/Physics/Collision/ShapeCast.h>namespace {-JPH::Shape *construct_override_user_data() {- return new JoltCustomUserDataShape();+JPH::Shape *construct_instance_overrides_shape() {+ return new JoltCustomInstanceOverridesShape();}-void collide_override_user_data_vs_shape(const JPH::Shape *p_shape1, const JPH::Shape *p_shape2, JPH::Vec3Arg p_scale1, JPH::Vec3Arg p_scale2, JPH::Mat44Arg p_center_of_mass_transform1, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, const JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {- ERR_FAIL_COND(p_shape1->GetSubType() != JoltCustomShapeSubType::OVERRIDE_USER_DATA);+void collide_instance_overrides_vs_shape(const JPH::Shape *p_shape1, const JPH::Shape *p_shape2, JPH::Vec3Arg p_scale1, JPH::Vec3Arg p_scale2, JPH::Mat44Arg p_center_of_mass_transform1, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, const JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {+ ERR_FAIL_COND(p_shape1->GetSubType() != JoltCustomShapeSubType::INSTANCE_OVERRIDES);- const JoltCustomUserDataShape *shape1 = static_cast<const JoltCustomUserDataShape *>(p_shape1);+ const JoltCustomInstanceOverridesShape *shape1 = static_cast<const JoltCustomInstanceOverridesShape *>(p_shape1);- 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, p_collide_shape_settings, p_collector, p_shape_filter);+ JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;+ if (shape1->object_has_back_face_collision() || shape1->shape_has_back_face_collision()) {+ new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;+ }++ 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);}-void collide_shape_vs_override_user_data(const JPH::Shape *p_shape1, const JPH::Shape *p_shape2, JPH::Vec3Arg p_scale1, JPH::Vec3Arg p_scale2, JPH::Mat44Arg p_center_of_mass_transform1, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, const JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {- ERR_FAIL_COND(p_shape2->GetSubType() != JoltCustomShapeSubType::OVERRIDE_USER_DATA);+void collide_shape_vs_instance_overrides(const JPH::Shape *p_shape1, const JPH::Shape *p_shape2, JPH::Vec3Arg p_scale1, JPH::Vec3Arg p_scale2, JPH::Mat44Arg p_center_of_mass_transform1, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, const JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {+ ERR_FAIL_COND(p_shape2->GetSubType() != JoltCustomShapeSubType::INSTANCE_OVERRIDES);- const JoltCustomUserDataShape *shape2 = static_cast<const JoltCustomUserDataShape *>(p_shape2);+ const JoltCustomInstanceOverridesShape *shape2 = static_cast<const JoltCustomInstanceOverridesShape *>(p_shape2);- 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, p_collide_shape_settings, p_collector, p_shape_filter);+ JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;+ if (shape2->object_has_back_face_collision() || shape2->shape_has_back_face_collision()) {+ new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;+ }++ 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);}-void cast_override_user_data_vs_shape(const JPH::ShapeCast &p_shape_cast, const JPH::ShapeCastSettings &p_shape_cast_settings, const JPH::Shape *p_shape, JPH::Vec3Arg p_scale, const JPH::ShapeFilter &p_shape_filter, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, JPH::CastShapeCollector &p_collector) {- ERR_FAIL_COND(p_shape_cast.mShape->GetSubType() != JoltCustomShapeSubType::OVERRIDE_USER_DATA);+void cast_instance_overrides_vs_shape(const JPH::ShapeCast &p_shape_cast, const JPH::ShapeCastSettings &p_shape_cast_settings, const JPH::Shape *p_shape, JPH::Vec3Arg p_scale, const JPH::ShapeFilter &p_shape_filter, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, JPH::CastShapeCollector &p_collector) {+ ERR_FAIL_COND(p_shape_cast.mShape->GetSubType() != JoltCustomShapeSubType::INSTANCE_OVERRIDES);- const JoltCustomUserDataShape *shape = static_cast<const JoltCustomUserDataShape *>(p_shape_cast.mShape);+ const JoltCustomInstanceOverridesShape *shape = static_cast<const JoltCustomInstanceOverridesShape *>(p_shape_cast.mShape);const JPH::ShapeCast shape_cast(shape->GetInnerShape(), p_shape_cast.mScale, p_shape_cast.mCenterOfMassStart, p_shape_cast.mDirection);JPH::CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, p_shape_cast_settings, p_shape, p_scale, p_shape_filter, p_center_of_mass_transform2, p_sub_shape_id_creator1, p_sub_shape_id_creator2, p_collector);}-void cast_shape_vs_override_user_data(const JPH::ShapeCast &p_shape_cast, const JPH::ShapeCastSettings &p_shape_cast_settings, const JPH::Shape *p_shape, JPH::Vec3Arg p_scale, const JPH::ShapeFilter &p_shape_filter, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, JPH::CastShapeCollector &p_collector) {- ERR_FAIL_COND(p_shape->GetSubType() != JoltCustomShapeSubType::OVERRIDE_USER_DATA);+void cast_shape_vs_instance_overrides(const JPH::ShapeCast &p_shape_cast, const JPH::ShapeCastSettings &p_shape_cast_settings, const JPH::Shape *p_shape, JPH::Vec3Arg p_scale, const JPH::ShapeFilter &p_shape_filter, JPH::Mat44Arg p_center_of_mass_transform2, const JPH::SubShapeIDCreator &p_sub_shape_id_creator1, const JPH::SubShapeIDCreator &p_sub_shape_id_creator2, JPH::CastShapeCollector &p_collector) {+ ERR_FAIL_COND(p_shape->GetSubType() != JoltCustomShapeSubType::INSTANCE_OVERRIDES);++ const JoltCustomInstanceOverridesShape *shape = static_cast<const JoltCustomInstanceOverridesShape *>(p_shape);- const JoltCustomUserDataShape *shape = static_cast<const JoltCustomUserDataShape *>(p_shape);+ JPH::ShapeCastSettings new_shape_cast_settings = p_shape_cast_settings;+ if (shape->object_has_back_face_collision() || shape->shape_has_back_face_collision()) {+ new_shape_cast_settings.mBackFaceModeTriangles = JPH::EBackFaceMode::CollideWithBackFaces;+ }- JPH::CollisionDispatch::sCastShapeVsShapeLocalSpace(p_shape_cast, p_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);+ 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);}} // namespace-JPH::ShapeSettings::ShapeResult JoltCustomUserDataShapeSettings::Create() const {+JPH::ShapeSettings::ShapeResult JoltCustomInstanceOverridesShapeSettings::Create() const {if (mCachedResult.IsEmpty()) {- new JoltCustomUserDataShape(*this, mCachedResult);+ new JoltCustomInstanceOverridesShape(*this, mCachedResult);}return mCachedResult;}-void JoltCustomUserDataShape::register_type() {- JPH::ShapeFunctions &shape_functions = JPH::ShapeFunctions::sGet(JoltCustomShapeSubType::OVERRIDE_USER_DATA);+void JoltCustomInstanceOverridesShape::register_type() {+ JPH::ShapeFunctions &shape_functions = JPH::ShapeFunctions::sGet(JoltCustomShapeSubType::INSTANCE_OVERRIDES);- shape_functions.mConstruct = construct_override_user_data;+ shape_functions.mConstruct = construct_instance_overrides_shape;shape_functions.mColor = JPH::Color::sCyan;for (const JPH::EShapeSubType sub_type : JPH::sAllSubShapeTypes) {- JPH::CollisionDispatch::sRegisterCollideShape(JoltCustomShapeSubType::OVERRIDE_USER_DATA, sub_type, collide_override_user_data_vs_shape);- JPH::CollisionDispatch::sRegisterCollideShape(sub_type, JoltCustomShapeSubType::OVERRIDE_USER_DATA, collide_shape_vs_override_user_data);- JPH::CollisionDispatch::sRegisterCastShape(JoltCustomShapeSubType::OVERRIDE_USER_DATA, sub_type, cast_override_user_data_vs_shape);- JPH::CollisionDispatch::sRegisterCastShape(sub_type, JoltCustomShapeSubType::OVERRIDE_USER_DATA, cast_shape_vs_override_user_data);+ JPH::CollisionDispatch::sRegisterCollideShape(JoltCustomShapeSubType::INSTANCE_OVERRIDES, sub_type, collide_instance_overrides_vs_shape);+ JPH::CollisionDispatch::sRegisterCollideShape(sub_type, JoltCustomShapeSubType::INSTANCE_OVERRIDES, collide_shape_vs_instance_overrides);+ JPH::CollisionDispatch::sRegisterCastShape(JoltCustomShapeSubType::INSTANCE_OVERRIDES, sub_type, cast_instance_overrides_vs_shape);+ JPH::CollisionDispatch::sRegisterCastShape(sub_type, JoltCustomShapeSubType::INSTANCE_OVERRIDES, cast_shape_vs_instance_overrides);}}++void JoltCustomInstanceOverridesShape::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 {+ JPH::RayCastSettings new_ray_cast_settings = p_ray_cast_settings;+ if (!shape_has_back_face_collision()) {+ // While ray-casts in Godot can be configured to hit back-faces, it's only allowed to do so if the `backface_collision` property of the shape is enabled as well.+ new_ray_cast_settings.mBackFaceModeTriangles = JPH::EBackFaceMode::IgnoreBackFaces;+ }++ mInnerShape->CastRay(p_ray, new_ray_cast_settings, p_sub_shape_id_creator, p_collector, p_shape_filter);+}diff --git a/modules/jolt_physics/shapes/jolt_custom_decorated_shape.h b/modules/jolt_physics/shapes/jolt_custom_instance_overrides_shape.hsimilarity index 84%rename from modules/jolt_physics/shapes/jolt_custom_decorated_shape.hrename to modules/jolt_physics/shapes/jolt_custom_instance_overrides_shape.hindex ad29418e3bb..a62afff1afa 100644--- a/modules/jolt_physics/shapes/jolt_custom_decorated_shape.h+++ b/modules/jolt_physics/shapes/jolt_custom_instance_overrides_shape.h@@ -1,5 +1,5 @@/**************************************************************************/-/* jolt_custom_decorated_shape.h */+/* jolt_custom_instance_overrides_shape.h *//**************************************************************************//* This file is part of: *//* GODOT ENGINE */@@ -30,19 +30,44 @@#pragma once+#include "jolt_custom_shape_type.h"+#include <Jolt/Jolt.h>#include <Jolt/Physics/Collision/Shape/DecoratedShape.h>#include <Jolt/Physics/Collision/TransformedShape.h>-class JoltCustomDecoratedShapeSettings : public JPH::DecoratedShapeSettings {+class JoltCustomInstanceOverridesShapeSettings final : public JPH::DecoratedShapeSettings {public:+ bool object_back_face_collision = false;+ bool shape_back_face_collision = false;+using JPH::DecoratedShapeSettings::DecoratedShapeSettings;++ virtual ShapeResult Create() const override;};-class JoltCustomDecoratedShape : public JPH::DecoratedShape {+class JoltCustomInstanceOverridesShape final : public JPH::DecoratedShape {+ bool object_back_face_collision = false;+ bool shape_back_face_collision = false;+public:- using JPH::DecoratedShape::DecoratedShape;+ static void register_type();++ JoltCustomInstanceOverridesShape() : JPH::DecoratedShape(JoltCustomShapeSubType::INSTANCE_OVERRIDES) {}++ JoltCustomInstanceOverridesShape(const JoltCustomInstanceOverridesShapeSettings &p_settings, JPH::Shape::ShapeResult &p_result) :+ JPH::DecoratedShape(JoltCustomShapeSubType::INSTANCE_OVERRIDES, p_settings, p_result),+ object_back_face_collision(p_settings.object_back_face_collision),+ shape_back_face_collision(p_settings.shape_back_face_collision) {+ if (!p_result.HasError()) {+ p_result.Set(this);+ }+ }++ bool object_has_back_face_collision() const { return object_back_face_collision; }++ bool shape_has_back_face_collision() const { return shape_back_face_collision; }virtual JPH::AABox GetLocalBounds() const override { return mInnerShape->GetLocalBounds(); }@@ -54,7 +79,7 @@ public:virtual JPH::Vec3 GetSurfaceNormal(const JPH::SubShapeID &p_sub_shape_id, JPH::Vec3Arg p_local_surface_position) const override { return mInnerShape->GetSurfaceNormal(p_sub_shape_id, p_local_surface_position); }- virtual JPH::uint64 GetSubShapeUserData(const JPH::SubShapeID &p_sub_shape_id) const override { return mInnerShape->GetSubShapeUserData(p_sub_shape_id); }+ virtual JPH::uint64 GetSubShapeUserData(const JPH::SubShapeID &p_sub_shape_id) const override { return GetUserData(); }virtual JPH::TransformedShape GetSubShapeTransformedShape(const JPH::SubShapeID &p_sub_shape_id, JPH::Vec3Arg p_position_com, JPH::QuatArg p_rotation, JPH::Vec3Arg p_scale, JPH::SubShapeID &p_remainder) const override { return mInnerShape->GetSubShapeTransformedShape(p_sub_shape_id, p_position_com, p_rotation, p_scale, p_remainder); }@@ -70,14 +95,12 @@ public:virtual bool CastRay(const JPH::RayCast &p_ray, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::RayCastResult &p_hit) const override { return mInnerShape->CastRay(p_ray, p_sub_shape_id_creator, p_hit); }- 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 { return mInnerShape->CastRay(p_ray, p_ray_cast_settings, p_sub_shape_id_creator, p_collector, p_shape_filter); }+ 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;virtual void CollidePoint(JPH::Vec3Arg p_point, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::CollidePointCollector &p_collector, const JPH::ShapeFilter &p_shape_filter = JPH::ShapeFilter()) const override { mInnerShape->CollidePoint(p_point, p_sub_shape_id_creator, p_collector, p_shape_filter); }virtual void CollideSoftBodyVertices(JPH::Mat44Arg p_center_of_mass_transform, JPH::Vec3Arg p_scale, const JPH::CollideSoftBodyVertexIterator &p_vertices, JPH::uint p_num_vertices, int p_colliding_shape_index) const override { mInnerShape->CollideSoftBodyVertices(p_center_of_mass_transform, p_scale, p_vertices, p_num_vertices, p_colliding_shape_index); }- virtual void CollectTransformedShapes(const JPH::AABox &p_box, JPH::Vec3Arg p_position_com, JPH::QuatArg p_rotation, JPH::Vec3Arg p_scale, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::TransformedShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter = JPH::ShapeFilter()) const override { mInnerShape->CollectTransformedShapes(p_box, p_position_com, p_rotation, p_scale, p_sub_shape_id_creator, p_collector, p_shape_filter); }-virtual void TransformShape(JPH::Mat44Arg p_center_of_mass_transform, JPH::TransformedShapeCollector &p_collector) const override { mInnerShape->TransformShape(p_center_of_mass_transform, p_collector); }virtual void GetTrianglesStart(JPH::Shape::GetTrianglesContext &p_context, const JPH::AABox &p_box, JPH::Vec3Arg p_position_com, JPH::QuatArg p_rotation, JPH::Vec3Arg p_scale) const override { mInnerShape->GetTrianglesStart(p_context, p_box, p_position_com, p_rotation, p_scale); }diff --git a/modules/jolt_physics/shapes/jolt_custom_shape_type.h b/modules/jolt_physics/shapes/jolt_custom_shape_type.hindex 973f2b1ea73..a0edd2df5d9 100644--- a/modules/jolt_physics/shapes/jolt_custom_shape_type.h+++ b/modules/jolt_physics/shapes/jolt_custom_shape_type.h@@ -36,8 +36,7 @@namespace JoltCustomShapeSubType {-constexpr JPH::EShapeSubType OVERRIDE_USER_DATA = JPH::EShapeSubType::User1;-constexpr JPH::EShapeSubType DOUBLE_SIDED = JPH::EShapeSubType::User2;+constexpr JPH::EShapeSubType INSTANCE_OVERRIDES = JPH::EShapeSubType::User1;constexpr JPH::EShapeSubType RAY = JPH::EShapeSubType::UserConvex1;constexpr JPH::EShapeSubType MOTION = JPH::EShapeSubType::UserConvex2;diff --git a/modules/jolt_physics/shapes/jolt_custom_user_data_shape.h b/modules/jolt_physics/shapes/jolt_custom_user_data_shape.hdeleted file mode 100644index ed72909c403..00000000000--- a/modules/jolt_physics/shapes/jolt_custom_user_data_shape.h+++ /dev/null@@ -1,58 +0,0 @@-/**************************************************************************/-/* jolt_custom_user_data_shape.h */-/**************************************************************************/-/* This file is part of: */-/* GODOT ENGINE */-/* https://godotengine.org */-/**************************************************************************/-/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */-/* */-/* Permission is hereby granted, free of charge, to any person obtaining */-/* a copy of this software and associated documentation files (the */-/* "Software"), to deal in the Software without restriction, including */-/* without limitation the rights to use, copy, modify, merge, publish, */-/* distribute, sublicense, and/or sell copies of the Software, and to */-/* permit persons to whom the Software is furnished to do so, subject to */-/* the following conditions: */-/* */-/* The above copyright notice and this permission notice shall be */-/* included in all copies or substantial portions of the Software. */-/* */-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */-/**************************************************************************/--#pragma once--#include "jolt_custom_decorated_shape.h"-#include "jolt_custom_shape_type.h"--class JoltCustomUserDataShapeSettings final : public JoltCustomDecoratedShapeSettings {-public:- using JoltCustomDecoratedShapeSettings::JoltCustomDecoratedShapeSettings;-- virtual ShapeResult Create() const override;-};--class JoltCustomUserDataShape final : public JoltCustomDecoratedShape {-public:- static void register_type();-- JoltCustomUserDataShape() :- JoltCustomDecoratedShape(JoltCustomShapeSubType::OVERRIDE_USER_DATA) {}-- JoltCustomUserDataShape(const JoltCustomUserDataShapeSettings &p_settings, ShapeResult &p_result) :- JoltCustomDecoratedShape(JoltCustomShapeSubType::OVERRIDE_USER_DATA, p_settings, p_result) {- if (!p_result.HasError()) {- p_result.Set(this);- }- }-- virtual JPH::uint64 GetSubShapeUserData(const JPH::SubShapeID &p_sub_shape_id) const override { return GetUserData(); }-};diff --git a/modules/jolt_physics/shapes/jolt_cylinder_shape_3d.h b/modules/jolt_physics/shapes/jolt_cylinder_shape_3d.hindex d825fcc8d69..be089878233 100644--- a/modules/jolt_physics/shapes/jolt_cylinder_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_cylinder_shape_3d.h@@ -42,6 +42,7 @@ class JoltCylinderShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_CYLINDER; }virtual bool is_convex() const override { return true; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_height_map_shape_3d.cpp b/modules/jolt_physics/shapes/jolt_height_map_shape_3d.cppindex ec7a9998cfe..8f1322b3359 100644--- a/modules/jolt_physics/shapes/jolt_height_map_shape_3d.cpp+++ b/modules/jolt_physics/shapes/jolt_height_map_shape_3d.cpp@@ -59,17 +59,17 @@ JPH::ShapeRefC JoltHeightMapShape3D::_build() const {ERR_FAIL_COND_V_MSG(width < 2 || depth < 2, nullptr, vformat("Failed to build Jolt Physics height map shape with %s. The height map must be at least 2x2. This shape belongs to %s.", to_string(), _owners_to_string()));if (width != depth) {- return JoltShape3D::with_double_sided(_build_mesh(), true);+ return _build_mesh();}const int block_size = 2; // Default of JPH::HeightFieldShapeSettings::mBlockSizeconst int block_count = width / block_size;if (block_count < 2) {- return JoltShape3D::with_double_sided(_build_mesh(), true);+ return _build_mesh();}- return JoltShape3D::with_double_sided(_build_height_field(), true);+ return _build_height_field();}JPH::ShapeRefC JoltHeightMapShape3D::_build_height_field() const {diff --git a/modules/jolt_physics/shapes/jolt_height_map_shape_3d.h b/modules/jolt_physics/shapes/jolt_height_map_shape_3d.hindex 0b9471d9bae..cd3dba4cab6 100644--- a/modules/jolt_physics/shapes/jolt_height_map_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_height_map_shape_3d.h@@ -53,6 +53,7 @@ class JoltHeightMapShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_HEIGHTMAP; }virtual bool is_convex() const override { return false; }+ virtual bool has_back_face_collision() const override { return true; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_separation_ray_shape_3d.h b/modules/jolt_physics/shapes/jolt_separation_ray_shape_3d.hindex b69ae27056f..e76f268e52a 100644--- a/modules/jolt_physics/shapes/jolt_separation_ray_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_separation_ray_shape_3d.h@@ -41,6 +41,7 @@ class JoltSeparationRayShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_SEPARATION_RAY; }virtual bool is_convex() const override { return true; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_shape_3d.cpp b/modules/jolt_physics/shapes/jolt_shape_3d.cppindex fe9b2bad0fa..1b3ec743adc 100644--- a/modules/jolt_physics/shapes/jolt_shape_3d.cpp+++ b/modules/jolt_physics/shapes/jolt_shape_3d.cpp@@ -32,8 +32,7 @@#include "../misc/jolt_type_conversions.h"#include "../objects/jolt_shaped_object_3d.h"-#include "jolt_custom_double_sided_shape.h"-#include "jolt_custom_user_data_shape.h"+#include "jolt_custom_instance_overrides_shape.h"#include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>#include <Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h>@@ -158,22 +157,16 @@ JPH::ShapeRefC JoltShape3D::with_center_of_mass(const JPH::Shape *p_shape, constreturn with_center_of_mass_offset(p_shape, center_of_mass_offset);}-JPH::ShapeRefC JoltShape3D::with_user_data(const JPH::Shape *p_shape, uint64_t p_user_data) {- JoltCustomUserDataShapeSettings shape_settings(p_shape);- shape_settings.mUserData = (JPH::uint64)p_user_data;-- const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();- ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to override user data. It returned the following error: '%s'.", to_godot(shape_result.GetError())));-- return shape_result.Get();-}--JPH::ShapeRefC JoltShape3D::with_double_sided(const JPH::Shape *p_shape, bool p_back_face_collision) {+JPH::ShapeRefC JoltShape3D::with_instance_overrides(const JPH::Shape *p_shape, uint64_t p_user_data, bool p_object_has_back_face_collision, bool p_shape_has_back_face_collision) {ERR_FAIL_NULL_V(p_shape, nullptr);- const JoltCustomDoubleSidedShapeSettings shape_settings(p_shape, p_back_face_collision);+ JoltCustomInstanceOverridesShapeSettings shape_settings(p_shape);+ shape_settings.mUserData = (JPH::uint64)p_user_data;+ shape_settings.object_back_face_collision = p_object_has_back_face_collision;+ shape_settings.shape_back_face_collision = p_shape_has_back_face_collision;+const JPH::ShapeSettings::ShapeResult shape_result = shape_settings.Create();- ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to make shape double-sided. It returned the following error: '%s'.", to_godot(shape_result.GetError())));+ ERR_FAIL_COND_V_MSG(shape_result.HasError(), nullptr, vformat("Failed to set instance overrides on shape. It returned the following error: '%s'.", to_godot(shape_result.GetError())));return shape_result.Get();}@@ -186,8 +179,7 @@ JPH::ShapeRefC JoltShape3D::without_custom_shapes(const JPH::Shape *p_shape) {return new JPH::SphereShape(0.1f);}- case JoltCustomShapeSubType::OVERRIDE_USER_DATA:- case JoltCustomShapeSubType::DOUBLE_SIDED: {+ case JoltCustomShapeSubType::INSTANCE_OVERRIDES: {const JPH::DecoratedShape *shape = static_cast<const JPH::DecoratedShape *>(p_shape);// Replace unsupported decorator shapes with the inner shape.diff --git a/modules/jolt_physics/shapes/jolt_shape_3d.h b/modules/jolt_physics/shapes/jolt_shape_3d.hindex 8a6d9fb5606..4758b427be5 100644--- a/modules/jolt_physics/shapes/jolt_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_shape_3d.h@@ -68,6 +68,7 @@ public:virtual ShapeType get_type() const = 0;virtual bool is_convex() const = 0;+ virtual bool has_back_face_collision() const = 0;virtual Variant get_data() const = 0;virtual void set_data(const Variant &p_data) = 0;@@ -90,8 +91,7 @@ public:static JPH::ShapeRefC with_basis_origin(const JPH::Shape *p_shape, const Basis &p_basis, const Vector3 &p_origin);static JPH::ShapeRefC with_center_of_mass_offset(const JPH::Shape *p_shape, const Vector3 &p_offset);static JPH::ShapeRefC with_center_of_mass(const JPH::Shape *p_shape, const Vector3 &p_center_of_mass);- static JPH::ShapeRefC with_user_data(const JPH::Shape *p_shape, uint64_t p_user_data);- static JPH::ShapeRefC with_double_sided(const JPH::Shape *p_shape, bool p_back_face_collision);+ static JPH::ShapeRefC with_instance_overrides(const JPH::Shape *p_shape, uint64_t p_user_data, bool p_object_has_back_face_collision, bool p_shape_has_back_face_collision);static JPH::ShapeRefC without_custom_shapes(const JPH::Shape *p_shape);static Vector3 make_scale_valid(const JPH::Shape *p_shape, const Vector3 &p_scale);diff --git a/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp b/modules/jolt_physics/shapes/jolt_shape_instance_3d.cppindex 0878d89704a..9ba8d005022 100644--- a/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp+++ b/modules/jolt_physics/shapes/jolt_shape_instance_3d.cpp@@ -75,7 +75,7 @@ AABB JoltShapeInstance3D::get_aabb() const {return get_transform_scaled().xform(shape->get_aabb());}-bool JoltShapeInstance3D::try_build() {+bool JoltShapeInstance3D::try_build(bool p_object_has_back_face_collision) {ERR_FAIL_COND_V(is_disabled(), false);const JPH::ShapeRefC maybe_new_shape = shape->try_build();@@ -93,7 +93,7 @@ bool JoltShapeInstance3D::try_build() {}}- jolt_ref = JoltShape3D::with_user_data(maybe_new_shape, (uint64_t)id);+ jolt_ref = JoltShape3D::with_instance_overrides(maybe_new_shape, (uint64_t)id, p_object_has_back_face_collision, shape->has_back_face_collision());return true;}diff --git a/modules/jolt_physics/shapes/jolt_shape_instance_3d.h b/modules/jolt_physics/shapes/jolt_shape_instance_3d.hindex cc5eaf36eb9..5bf87b9a3b7 100644--- a/modules/jolt_physics/shapes/jolt_shape_instance_3d.h+++ b/modules/jolt_physics/shapes/jolt_shape_instance_3d.h@@ -95,5 +95,5 @@ public:void enable() { disabled = false; }void disable() { disabled = true; }- bool try_build();+ bool try_build(bool p_object_has_back_face_collision);};diff --git a/modules/jolt_physics/shapes/jolt_sphere_shape_3d.h b/modules/jolt_physics/shapes/jolt_sphere_shape_3d.hindex 7ff159d97ba..fb49c0e0bda 100644--- a/modules/jolt_physics/shapes/jolt_sphere_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_sphere_shape_3d.h@@ -40,6 +40,7 @@ class JoltSphereShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_SPHERE; }virtual bool is_convex() const override { return true; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/shapes/jolt_world_boundary_shape_3d.h b/modules/jolt_physics/shapes/jolt_world_boundary_shape_3d.hindex ebe1138513d..ad2324945c4 100644--- a/modules/jolt_physics/shapes/jolt_world_boundary_shape_3d.h+++ b/modules/jolt_physics/shapes/jolt_world_boundary_shape_3d.h@@ -40,6 +40,7 @@ class JoltWorldBoundaryShape3D final : public JoltShape3D {public:virtual ShapeType get_type() const override { return ShapeType::SHAPE_WORLD_BOUNDARY; }virtual bool is_convex() const override { return false; }+ virtual bool has_back_face_collision() const override { return false; }virtual Variant get_data() const override;virtual void set_data(const Variant &p_data) override;diff --git a/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp b/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cppindex 9ac06cfb133..a6af833433a 100644--- a/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp+++ b/modules/jolt_physics/spaces/jolt_physics_direct_space_state_3d.cpp@@ -37,6 +37,7 @@#include "../objects/jolt_area_3d.h"#include "../objects/jolt_body_3d.h"#include "../objects/jolt_object_3d.h"+#include "../shapes/jolt_custom_instance_overrides_shape.h"#include "../shapes/jolt_custom_motion_shape.h"#include "../shapes/jolt_shape_3d.h"#include "jolt_motion_filter_3d.h"@@ -815,21 +816,25 @@ Vector3 JoltPhysicsDirectSpaceState3D::get_closest_point_to_object_volume(RID p_for (int i = 0; i < collector.get_hit_count(); ++i) {const JPH::TransformedShape &shape_transformed = collector.get_hit(i);- const JPH::Shape &shape = *shape_transformed.mShape;+ const JPH::Shape *shape = shape_transformed.mShape;+ if (unlikely(shape->GetSubType() != JoltCustomShapeSubType::INSTANCE_OVERRIDES)) {+ continue;+ }- if (shape.GetType() != JPH::EShapeType::Convex) {+ shape = static_cast<const JoltCustomInstanceOverridesShape *>(shape)->GetInnerShape();+ if (shape->GetType() != JPH::EShapeType::Convex) {continue;}- const JPH::ConvexShape &shape_convex = static_cast<const JPH::ConvexShape &>(shape);+ const JPH::ConvexShape *shape_convex = static_cast<const JPH::ConvexShape *>(shape);JPH::GJKClosestPoint gjk;JPH::ConvexShape::SupportBuffer shape_support_buffer;- const JPH::ConvexShape::Support *shape_support = shape_convex.GetSupportFunction(JPH::ConvexShape::ESupportMode::IncludeConvexRadius, shape_support_buffer, shape_transformed.GetShapeScale());+ const JPH::ConvexShape::Support *shape_support = shape_convex->GetSupportFunction(JPH::ConvexShape::ESupportMode::IncludeConvexRadius, shape_support_buffer, shape_transformed.GetShapeScale());const JPH::RMat44 shape_rotation = JPH::RMat44::sRotation(shape_transformed.mShapeRotation);- const JPH::Vec3 shape_com = shape_rotation.Multiply3x3(shape.GetCenterOfMass());+ const JPH::Vec3 shape_com = shape_rotation.Multiply3x3(shape->GetCenterOfMass());const JPH::RVec3 shape_pos = shape_transformed.mShapePositionCOM - JPH::RVec3(shape_com);const JPH::RMat44 shape_xform = shape_rotation.PostTranslated(shape_pos);const JPH::RMat44 shape_xform_inv = shape_xform.InversedRotationTranslation();diff --git a/modules/jolt_physics/spaces/jolt_space_3d.cpp b/modules/jolt_physics/spaces/jolt_space_3d.cppindex 4242161bf9d..09c5c91193c 100644--- a/modules/jolt_physics/spaces/jolt_space_3d.cpp+++ b/modules/jolt_physics/spaces/jolt_space_3d.cpp@@ -141,11 +141,8 @@ JoltSpace3D::JoltSpace3D(JPH::JobSystem *p_job_system, JPH::TempAllocator *p_temphysics_system->SetSimCollideBodyVsBody([](const JPH::Body &p_body1, const JPH::Body &p_body2, JPH::Mat44Arg p_transform_com1, JPH::Mat44Arg p_transform_com2, JPH::CollideShapeSettings &p_collide_shape_settings, JPH::CollideShapeCollector &p_collector, const JPH::ShapeFilter &p_shape_filter) {if (p_body1.IsSensor() || p_body2.IsSensor()) {- JPH::CollideShapeSettings new_collide_shape_settings = p_collide_shape_settings;- // Since we're breaking the sensor down into leaf shapes we'll end up stripping away our `JoltCustomDoubleSidedShape` decorator shape and thus any back-face collision, so we simply force-enable it like this rather than going through the trouble of reapplying the decorator.- new_collide_shape_settings.mBackFaceMode = JPH::EBackFaceMode::CollideWithBackFaces;JPH::SubShapeIDCreator part1, part2;- JPH::CollideShapeVsShapePerLeaf<JPH::AnyHitCollisionCollector<JPH::CollideShapeCollector>>(p_body1.GetShape(), p_body2.GetShape(), JPH::Vec3::sOne(), JPH::Vec3::sOne(), p_transform_com1, p_transform_com2, part1, part2, new_collide_shape_settings, p_collector, p_shape_filter);+ JPH::CollideShapeVsShapePerLeaf<JPH::AnyHitCollisionCollector<JPH::CollideShapeCollector>>(p_body1.GetShape(), p_body2.GetShape(), JPH::Vec3::sOne(), JPH::Vec3::sOne(), p_transform_com1, p_transform_com2, part1, part2, p_collide_shape_settings, p_collector, p_shape_filter);} else {JPH::PhysicsSystem::sDefaultSimCollideBodyVsBody(p_body1, p_body2, p_transform_com1, p_transform_com2, p_collide_shape_settings, p_collector, p_shape_filter);}