Browse Source

Update to Jolt Physics master, bind SimShapeFilter

The size of JPH::IndexedTriangle changed due to addition of a 32-bit UserData field
Lucien Greathouse 9 months ago
parent
commit
52d0447345
3 changed files with 56 additions and 3 deletions
  1. 19 2
      JoltC/Functions.h
  2. 36 0
      JoltC/JoltC.cpp
  3. 1 1
      JoltPhysics

+ 19 - 2
JoltC/Functions.h

@@ -140,6 +140,7 @@ ENSURE_SIZE_ALIGN(JPC_IndexedTriangleNoMaterial, JPH::IndexedTriangleNoMaterial)
 typedef struct JPC_IndexedTriangle {
 	uint32_t idx[3];
 	uint32_t materialIndex;
+	uint32_t userData;
 } JPC_IndexedTriangle;
 
 ENSURE_SIZE_ALIGN(JPC_IndexedTriangle, JPH::IndexedTriangle)
@@ -312,8 +313,6 @@ JPC_API void JPC_BodyFilter_delete(JPC_BodyFilter* object);
 
 typedef struct JPC_ShapeFilterFns {
 	bool (*ShouldCollide)(const void *self, const JPC_Shape *inShape2, JPC_SubShapeID inSubShapeIDOfShape2);
-
-	// virtual bool			ShouldCollide([[maybe_unused]] const Shape *inShape1, [[maybe_unused]] const SubShapeID &inSubShapeIDOfShape1, [[maybe_unused]] const Shape *inShape2, [[maybe_unused]] const SubShapeID &inSubShapeIDOfShape2) const
 } JPC_ShapeFilterFns;
 
 typedef struct JPC_ShapeFilter JPC_ShapeFilter;
@@ -324,6 +323,24 @@ JPC_API JPC_ShapeFilter* JPC_ShapeFilter_new(
 
 JPC_API void JPC_ShapeFilter_delete(JPC_ShapeFilter* object);
 
+////////////////////////////////////////////////////////////////////////////////
+// SimShapeFilter
+
+typedef struct JPC_SimShapeFilterFns {
+	bool (*ShouldCollide)(
+		const void *self,
+		const JPC_Body *inBody1, const JPC_Shape *inShape1, JPC_SubShapeID inSubShapeIDOfShape1,
+		const JPC_Body *inBody2, const JPC_Shape *inShape2, JPC_SubShapeID inSubShapeIDOfShape2);
+} JPC_SimShapeFilterFns;
+
+typedef struct JPC_SimShapeFilter JPC_SimShapeFilter;
+
+JPC_API JPC_SimShapeFilter* JPC_SimShapeFilter_new(
+	const void *self,
+	JPC_SimShapeFilterFns fns);
+
+JPC_API void JPC_SimShapeFilter_delete(JPC_ShapeFilter* object);
+
 ////////////////////////////////////////////////////////////////////////////////
 // ObjectVsBroadPhaseLayerFilter
 

+ 36 - 0
JoltC/JoltC.cpp

@@ -20,6 +20,7 @@
 #include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
 #include <Jolt/Physics/Collision/Shape/TriangleShape.h>
 #include <Jolt/Physics/Collision/ShapeCast.h>
+#include <Jolt/Physics/Collision/SimShapeFilter.h>
 #include <Jolt/Physics/PhysicsSettings.h>
 #include <Jolt/Physics/PhysicsSystem.h>
 #include <Jolt/RegisterTypes.h>
@@ -501,6 +502,41 @@ JPC_API JPC_ShapeFilter* JPC_ShapeFilter_new(
 	return to_jpc(new JPC_ShapeFilterBridge(self, fns));
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// SimShapeFilter
+
+class JPC_SimShapeFilterBridge final : public JPH::SimShapeFilter {
+public:
+	explicit JPC_SimShapeFilterBridge(const void *self, JPC_SimShapeFilterFns fns) : self(self), fns(fns) {}
+
+	virtual bool ShouldCollide(
+		const JPH::Body &inBody1, const JPH::Shape *inShape1, const JPH::SubShapeID &inSubShapeIDOfShape1,
+		const JPH::Body &inBody2, const JPH::Shape *inShape2, const JPH::SubShapeID &inSubShapeIDOfShape2) const override
+	{
+		if (fns.ShouldCollide == nullptr) {
+			return true;
+		}
+
+		return fns.ShouldCollide(self,
+			to_jpc(&inBody1), to_jpc(inShape1), to_jpc(inSubShapeIDOfShape1),
+			to_jpc(&inBody2), to_jpc(inShape2), to_jpc(inSubShapeIDOfShape2));
+	}
+
+private:
+	const void* self;
+	JPC_SimShapeFilterFns fns;
+};
+
+OPAQUE_WRAPPER(JPC_SimShapeFilter, JPC_SimShapeFilterBridge)
+DESTRUCTOR(JPC_SimShapeFilter)
+
+JPC_API JPC_SimShapeFilter* JPC_SimShapeFilter_new(
+	const void *self,
+	JPC_SimShapeFilterFns fns)
+{
+	return to_jpc(new JPC_SimShapeFilterBridge(self, fns));
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // JPC_ObjectLayerPairFilter
 

+ 1 - 1
JoltPhysics

@@ -1 +1 @@
-Subproject commit cede24d2733a4a473c6d486650ca9b6d0481681a
+Subproject commit e071001ba15836f98e3d883ee9e7fad5bff27ce4