Skip to content

Expose JPH::PlaneShape via JPC_PlaneShapeSettings#25

Merged
LPGhatguy merged 1 commit into
SecondHalfGames:mainfrom
Solidor777:plane-shape
May 14, 2026
Merged

Expose JPH::PlaneShape via JPC_PlaneShapeSettings#25
LPGhatguy merged 1 commit into
SecondHalfGames:mainfrom
Solidor777:plane-shape

Conversation

@Solidor777

Copy link
Copy Markdown
Contributor

Problem

JoltC does not expose JPH::PlaneShape (the infinite-half-space collider; "negative half space is solid"). Downstream consumers that want a real halfspace primitive — for example mapping a Halfspace { normal } shape from a higher-level physics abstraction — have no choice but to approximate with a thin static box, which loses the authored normal direction and forces an arbitrary thickness offset.

Fix

Add JPC_PlaneShapeSettings + matching _default / _Create exports following the same pattern as JPC_BoxShapeSettings, JPC_SphereShapeSettings, etc.

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);

The C-side struct carries Normal + Constant rather than a JPC_Plane wrapper to avoid introducing a new binding type for a single use site; the C++ side constructs the JPH::Plane via its Plane(Vec3 normal, float constant) ctor. Material is stubbed with a TODO comment, consistent with every other *ShapeSettings in the codebase.

HalfExtent defaults to JPH::PlaneShapeSettings::cDefaultHalfExtent (1000.0f), matching JPH's own default.

Constraint

PlaneShape MUST be static or kinematic per JPH (PlaneShape::MustBeStatic() == true). Caller's responsibility, same contract as JoltPhysics/Samples/Tests/Shapes/PlaneShapeTest.cpp upstream.

Validation

Downstream verification: Titan engine's titan-jolt-3d plugin uses this binding to back its BodyShape::Halfspace { normal }. New integration test (halfspace_authors_non_y_normal) raycasts a non-+Y halfspace and asserts:

  • ray distance lands on the authored plane (5 m for a 5-m offset along the plane normal)
  • hit normal returned by Jolt's raycast matches the authored normal (dot product > 0.95 with the expected direction)

The same test against the prior thin-box approximation returned axis-aligned normals on the box faces, never the authored plane normal — concrete evidence that the new path actually exercises PlaneShape::GetSurfaceNormal.

Test plan

  • Builds against current main on Windows host (msvc).
  • JPC_PlaneShapeSettings_Create returns a valid JPC_Shape* for a +Y normal at the origin.
  • Downstream raycast against the resulting body returns the authored normal.
  • Material parameter — out of scope for this PR (left as TODO like every other shape).

Solidor777 added a commit to Solidor777/Titan that referenced this pull request May 8, 2026
m34-a-ii shipped Halfspace as a 100×0.05×100 thin static box because
JoltC didn't expose JPH's PlaneShape. The authored normal was ignored;
raycasts returned axis-aligned box-face normals; rotated halfspaces
silently used the ground approximation.

Bumps the Solidor777/JoltC submodule to 3eddf05, which adds a TITAN
PATCH exposing `JPC_PlaneShapeSettings` + `_default` + `_Create`
following the existing BoxShape/SphereShape pattern. Companion one-line
patch on `crates/third_party/joltc-sys/src/lib.rs` adds the new shape
to the `ffi_default!` list so `JPC_PlaneShapeSettings::default()` works
from rust.

`titan-jolt-3d`'s `BodyShape::Halfspace { normal }` arm now constructs
a real `PlaneShape` with the authored normal as the plane's outward
direction and `Constant = 0` (plane through body-local origin). Module
docs updated.

New regression test `halfspace_authors_non_y_normal` raycasts a +X-
normal halfspace and asserts:
- ray distance lands on the plane (5 m for a 5 m offset along the
  authored normal)
- raycast surface normal returned by Jolt matches the authored normal
  (dot with +X > 0.95). The thin-box approx returned (0, ±1, 0) here.

Existing `dynamic_body_rests_on_static_ground` updated: the ball now
settles at y ≈ radius (0.4..0.6) instead of radius + box-half-extent
(0.4..0.7) since the plane is exactly at y=0.

508 tests pass (was 507). Smoke-launched: editor reaches `boot
complete` cleanly.

Upstream PRs: [SecondHalfGames/JoltC#25](SecondHalfGames/JoltC#25)
+ [SecondHalfGames/jolt-rust#14](SecondHalfGames/jolt-rust#14).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@LPGhatguy

Copy link
Copy Markdown
Member

Hello and thank you!

Can you remove the titan comments from the code? Then it's good to merge!

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).
@Solidor777

Copy link
Copy Markdown
Contributor Author

Done — removed both TITAN PATCH comment blocks; section headers now match the rest of the file.

@LPGhatguy LPGhatguy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merci beaucoup!

@LPGhatguy LPGhatguy merged commit 2982004 into SecondHalfGames:main May 14, 2026
9 checks passed
Solidor777 added a commit to Solidor777/Titan that referenced this pull request May 17, 2026
m34-a-ii shipped Halfspace as a 100×0.05×100 thin static box because
JoltC didn't expose JPH's PlaneShape. The authored normal was ignored;
raycasts returned axis-aligned box-face normals; rotated halfspaces
silently used the ground approximation.

Bumps the Solidor777/JoltC submodule to 3eddf05, which adds a TITAN
PATCH exposing `JPC_PlaneShapeSettings` + `_default` + `_Create`
following the existing BoxShape/SphereShape pattern. Companion one-line
patch on `crates/third_party/joltc-sys/src/lib.rs` adds the new shape
to the `ffi_default!` list so `JPC_PlaneShapeSettings::default()` works
from rust.

`titan-jolt-3d`'s `BodyShape::Halfspace { normal }` arm now constructs
a real `PlaneShape` with the authored normal as the plane's outward
direction and `Constant = 0` (plane through body-local origin). Module
docs updated.

New regression test `halfspace_authors_non_y_normal` raycasts a +X-
normal halfspace and asserts:
- ray distance lands on the plane (5 m for a 5 m offset along the
  authored normal)
- raycast surface normal returned by Jolt matches the authored normal
  (dot with +X > 0.95). The thin-box approx returned (0, ±1, 0) here.

Existing `dynamic_body_rests_on_static_ground` updated: the ball now
settles at y ≈ radius (0.4..0.6) instead of radius + box-half-extent
(0.4..0.7) since the plane is exactly at y=0.

508 tests pass (was 507). Smoke-launched: editor reaches `boot
complete` cleanly.

Upstream PRs: [SecondHalfGames/JoltC#25](SecondHalfGames/JoltC#25)
+ [SecondHalfGames/jolt-rust#14](SecondHalfGames/jolt-rust#14).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Solidor777 added a commit to Solidor777/Titan that referenced this pull request Jun 4, 2026
m34-a-ii shipped Halfspace as a 100×0.05×100 thin static box because
JoltC didn't expose JPH's PlaneShape. The authored normal was ignored;
raycasts returned axis-aligned box-face normals; rotated halfspaces
silently used the ground approximation.

Bumps the Solidor777/JoltC submodule to 3eddf05, which adds a TITAN
PATCH exposing `JPC_PlaneShapeSettings` + `_default` + `_Create`
following the existing BoxShape/SphereShape pattern. Companion one-line
patch on `crates/third_party/joltc-sys/src/lib.rs` adds the new shape
to the `ffi_default!` list so `JPC_PlaneShapeSettings::default()` works
from rust.

`titan-jolt-3d`'s `BodyShape::Halfspace { normal }` arm now constructs
a real `PlaneShape` with the authored normal as the plane's outward
direction and `Constant = 0` (plane through body-local origin). Module
docs updated.

New regression test `halfspace_authors_non_y_normal` raycasts a +X-
normal halfspace and asserts:
- ray distance lands on the plane (5 m for a 5 m offset along the
  authored normal)
- raycast surface normal returned by Jolt matches the authored normal
  (dot with +X > 0.95). The thin-box approx returned (0, ±1, 0) here.

Existing `dynamic_body_rests_on_static_ground` updated: the ball now
settles at y ≈ radius (0.4..0.6) instead of radius + box-half-extent
(0.4..0.7) since the plane is exactly at y=0.

508 tests pass (was 507). Smoke-launched: editor reaches `boot
complete` cleanly.

Upstream PRs: [SecondHalfGames/JoltC#25](SecondHalfGames/JoltC#25)
+ [SecondHalfGames/jolt-rust#14](SecondHalfGames/jolt-rust#14).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants