Browse Source

Bind MeshShape

Lucien Greathouse 4 months ago
parent
commit
30ba0f1b3f
2 changed files with 66 additions and 1 deletions
  1. 21 0
      JoltC/Functions.h
  2. 45 1
      JoltCImpl/JoltC.cpp

+ 21 - 0
JoltC/Functions.h

@@ -781,6 +781,27 @@ typedef struct JPC_TriangleShapeSettings {
 JPC_API void JPC_TriangleShapeSettings_default(JPC_TriangleShapeSettings* object);
 JPC_API bool JPC_TriangleShapeSettings_Create(const JPC_TriangleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
 
+////////////////////////////////////////////////////////////////////////////////
+// MeshShapeSettings -> ShapeSettings
+
+typedef struct JPC_MeshShapeSettings {
+	// ShapeSettings
+	uint64_t UserData;
+
+	// MeshShapeSettings
+	JPC_Float3* TriangleVertices;
+	size_t TriangleVerticesLen;
+	JPC_IndexedTriangle* IndexedTriangles;
+	size_t IndexedTrianglesLen;
+	// PhysicsMaterialList				mMaterials;
+	// uint							mMaxTrianglesPerLeaf = 8;
+	// float							mActiveEdgeCosThresholdAngle = 0.996195f;
+	// bool							mPerTriangleUserData = false;
+} JPC_MeshShapeSettings;
+
+JPC_API void JPC_MeshShapeSettings_default(JPC_MeshShapeSettings* object);
+JPC_API bool JPC_MeshShapeSettings_Create(const JPC_MeshShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
+
 ////////////////////////////////////////////////////////////////////////////////
 // BoxShapeSettings -> ConvexShapeSettings -> ShapeSettings
 

+ 45 - 1
JoltCImpl/JoltC.cpp

@@ -16,15 +16,16 @@
 #include <Jolt/Physics/Collision/Shape/CompoundShape.h>
 #include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
 #include <Jolt/Physics/Collision/Shape/CylinderShape.h>
+#include <Jolt/Physics/Collision/Shape/MeshShape.h>
 #include <Jolt/Physics/Collision/Shape/MutableCompoundShape.h>
 #include <Jolt/Physics/Collision/Shape/SphereShape.h>
 #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/Constraints/ConstraintPart/SwingTwistConstraintPart.h>
 #include <Jolt/Physics/Constraints/FixedConstraint.h>
 #include <Jolt/Physics/Constraints/SixDOFConstraint.h>
-#include <Jolt/Physics/Constraints/ConstraintPart/SwingTwistConstraintPart.h>
 #include <Jolt/Physics/PhysicsSettings.h>
 #include <Jolt/Physics/PhysicsSystem.h>
 #include <Jolt/RegisterTypes.h>
@@ -1267,6 +1268,49 @@ JPC_API bool JPC_TriangleShapeSettings_Create(const JPC_TriangleShapeSettings* s
 	return HandleShapeResult(settings.Create(), outShape, outError);
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// MeshShapeSettings
+
+JPC_IMPL void JPC_MeshShapeSettings_to_jpc_borrowed(
+	JPC_MeshShapeSettings* outJpc,
+	const JPH::MeshShapeSettings* inJph)
+{
+	outJpc->TriangleVertices = (JPC_Float3*)inJph->mTriangleVertices.data();
+	outJpc->TriangleVerticesLen = inJph->mTriangleVertices.size();
+	outJpc->IndexedTriangles = (JPC_IndexedTriangle*)inJph->mIndexedTriangles.data();
+	outJpc->IndexedTrianglesLen = inJph->mIndexedTriangles.size();
+}
+
+JPC_IMPL void JPC_MeshShapeSettings_to_jph(
+	const JPC_MeshShapeSettings* inJpc,
+	JPH::MeshShapeSettings* outJph)
+{
+	auto triangleVertices = (const JPH::Float3*)inJpc->TriangleVertices;
+	outJph->mTriangleVertices = JPH::VertexList(triangleVertices, triangleVertices + inJpc->TriangleVerticesLen);
+
+	auto indexedTriangles = (const JPH::IndexedTriangle*)inJpc->IndexedTriangles;
+	outJph->mIndexedTriangles = JPH::IndexedTriangleList(indexedTriangles, indexedTriangles + inJpc->IndexedTrianglesLen);
+}
+
+JPC_API void JPC_MeshShapeSettings_default(JPC_MeshShapeSettings* object) {
+	JPH::MeshShapeSettings settings;
+	JPC_MeshShapeSettings_to_jpc_borrowed(object, &settings);
+
+	// Overwrite all pointers and lengths so that the default value doesn't
+	// contain pointers to freed memory.
+	object->TriangleVertices = nullptr;
+	object->TriangleVerticesLen = 0;
+	object->IndexedTriangles = nullptr;
+	object->IndexedTrianglesLen = 0;
+}
+
+JPC_API bool JPC_MeshShapeSettings_Create(const JPC_MeshShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
+	JPH::MeshShapeSettings settings;
+	JPC_MeshShapeSettings_to_jph(self, &settings);
+
+	return HandleShapeResult(settings.Create(), outShape, outError);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // BoxShapeSettings