From 0848d775896c6b17e653edd75f5cb70929e425d8 Mon Sep 17 00:00:00 2001 From: "SOLIDOR\\emper" Date: Fri, 8 May 2026 14:31:40 -0700 Subject: [PATCH] Expose JPH::PlaneShape via JPC_PlaneShapeSettings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JPH ships PlaneShape (an infinite-half-space collider; "negative half space is solid") but JoltC did not expose it via the C API. Downstream backends that want a real halfspace primitive — e.g. Titan's `titan-jolt-3d` mapping its `BodyShape::Halfspace { normal }` — had to approximate with a thin static box, which loses the authored normal + forces an arbitrary thickness offset. Add `JPC_PlaneShapeSettings { UserData, Normal, Constant, HalfExtent }` + `_default` + `_Create`. The C-side struct carries Normal + Constant rather than a Plane wrapper to avoid introducing a new JPC_Plane binding for a single use site; the implementation constructs the JPH::Plane via its `Plane(Vec3 normal, float constant)` ctor. Material is stubbed (`TODO: Material`) consistent with every other `*ShapeSettings` in the codebase. PlaneShape MUST be static or kinematic per JPH; that constraint is the caller's responsibility (matches the existing PlaneShape usage in the JoltPhysics samples). --- JoltC/Functions.h | 17 +++++++++++++++++ JoltCImpl/JoltC.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/JoltC/Functions.h b/JoltC/Functions.h index 500106d..2090ac0 100644 --- a/JoltC/Functions.h +++ b/JoltC/Functions.h @@ -1159,6 +1159,23 @@ typedef struct JPC_CylinderShapeSettings { JPC_API void JPC_CylinderShapeSettings_default(JPC_CylinderShapeSettings* object); JPC_API bool JPC_CylinderShapeSettings_Create(const JPC_CylinderShapeSettings* self, JPC_Shape** outShape, JPC_String** outError); +//////////////////////////////////////////////////////////////////////////////// +// PlaneShapeSettings -> ShapeSettings + +typedef struct JPC_PlaneShapeSettings { + // ShapeSettings + uint64_t UserData; + + // PlaneShapeSettings + // TODO: Material + JPC_Vec3 Normal; + float Constant; + float HalfExtent; +} JPC_PlaneShapeSettings; + +JPC_API void JPC_PlaneShapeSettings_default(JPC_PlaneShapeSettings* object); +JPC_API bool JPC_PlaneShapeSettings_Create(const JPC_PlaneShapeSettings* self, JPC_Shape** outShape, JPC_String** outError); + //////////////////////////////////////////////////////////////////////////////// // ConvexHullShapeSettings -> ConvexShapeSettings -> ShapeSettings diff --git a/JoltCImpl/JoltC.cpp b/JoltCImpl/JoltC.cpp index e5be33a..025bcc5 100644 --- a/JoltCImpl/JoltC.cpp +++ b/JoltCImpl/JoltC.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1907,6 +1908,33 @@ JPC_API bool JPC_CylinderShapeSettings_Create(const JPC_CylinderShapeSettings* s return HandleShapeResult(settings.Create(), outShape, outError); } +//////////////////////////////////////////////////////////////////////////////// +// PlaneShapeSettings + +static void to_jph(const JPC_PlaneShapeSettings* input, JPH::PlaneShapeSettings* output) { + output->mUserData = input->UserData; + + // TODO: Material + output->mPlane = JPH::Plane(to_jph(input->Normal), input->Constant); + output->mHalfExtent = input->HalfExtent; +} + +JPC_API void JPC_PlaneShapeSettings_default(JPC_PlaneShapeSettings* object) { + object->UserData = 0; + + // TODO: Material + object->Normal = JPC_Vec3{0, 1, 0, 1}; + object->Constant = 0.0; + object->HalfExtent = JPH::PlaneShapeSettings::cDefaultHalfExtent; +} + +JPC_API bool JPC_PlaneShapeSettings_Create(const JPC_PlaneShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) { + JPH::PlaneShapeSettings settings; + to_jph(self, &settings); + + return HandleShapeResult(settings.Create(), outShape, outError); +} + //////////////////////////////////////////////////////////////////////////////// // ConvexHullShapeSettings