Documentation
    Preparing search index...

    Interface RapierBodyAccess

    Per-handle access to a Rapier body — the seam §37's two sync* methods leave open (see the module header).

    PhysicsSolverAdapter deliberately says nothing about reading or writing an individual body: §37's contract is about the step, and the transform exchange with the scene is @fourjs/physics's business. That leaves the physics package needing an interface it can call per body per step, which is this one. It is declared here, in the adapter package, rather than added to @fourjs/physics — the plan reserves that as an allowed extension point, and a WP-5.1 amendment can promote it later once the 3D adapter (WP-5.5) has confirmed the shape is dimension-independent.

    Every method takes handles minted by the same adapter and throws a FourError for a foreign or destroyed handle. Reading methods take out parameters and write into them (§7b, D7); the only allocations left are the { x, y } objects Rapier's own bindings return, which no caller can avoid at 0.19.3.

    Angles, torques, and angular velocities are the §21 planar scalars: a number is about +Z, and a Vector3 must lie on the Z axis.

    interface RapierBodyAccess {
        applyAngularImpulse(
            handle: PhysicsBodyHandle,
            angularImpulse: AngularVelocityInput,
        ): void;
        applyForce(handle: PhysicsBodyHandle, force: Vector3Input): void;
        applyForceAtPoint(
            handle: PhysicsBodyHandle,
            force: Vector3Input,
            worldPoint: Vector3Input,
        ): void;
        applyImpulse(handle: PhysicsBodyHandle, impulse: Vector3Input): void;
        applyImpulseAtPoint(
            handle: PhysicsBodyHandle,
            impulse: Vector3Input,
            worldPoint: Vector3Input,
        ): void;
        applyTorque(handle: PhysicsBodyHandle, torque: AngularVelocityInput): void;
        forEachBody(visit: (handle: PhysicsBodyHandle, id: number) => void): void;
        forEachCollider(
            visit: (handle: PhysicsColliderHandle, id: number) => void,
        ): void;
        getBodyCcdMode(handle: PhysicsBodyHandle): CCDMode;
        getBodyCenterOfMass(handle: PhysicsBodyHandle, out: Vector3): void;
        getBodyId(handle: PhysicsBodyHandle): number;
        getBodyMass(handle: PhysicsBodyHandle): number;
        getBodyTransform(
            handle: PhysicsBodyHandle,
            outPosition: Vector3,
            outRotation: Quaternion,
        ): void;
        getBodyVelocities(
            handle: PhysicsBodyHandle,
            outLinear: Vector3,
            outAngular: Vector3,
        ): void;
        getColliderBody(handle: PhysicsColliderHandle): PhysicsBodyHandle;
        getColliderId(handle: PhysicsColliderHandle): number;
        isBodySleeping(handle: PhysicsBodyHandle): boolean;
        resetForces(handle: PhysicsBodyHandle): void;
        setBodyTransform(
            handle: PhysicsBodyHandle,
            position: Vector3Input,
            rotation: RotationInput,
            wake?: boolean,
        ): void;
        setBodyType(
            handle: PhysicsBodyHandle,
            type: BodyType,
            wake?: boolean,
        ): void;
        setBodyVelocities(
            handle: PhysicsBodyHandle,
            linear: Vector3Input,
            angular: AngularVelocityInput,
            wake?: boolean,
        ): void;
        setNextKinematicTransform(
            handle: PhysicsBodyHandle,
            position: Vector3Input,
            rotation?: RotationInput,
        ): void;
        sleepBody(handle: PhysicsBodyHandle): void;
        wakeBody(handle: PhysicsBodyHandle): void;
    }

    Implemented by

    Index
    • Visits every live body in creation order, which is ascending RapierBodyAccess.getBodyId because ids are monotonic and never reused. This is the iteration §33 requires: destroying a body removes it from the sequence and creating one appends, so no destruction can permute the order a checksum is taken in.

      Parameters

      Returns void

    • Visits every live collider in creation order.

      Parameters

      Returns void

    • The §31 CCD mode the solver is actually running for this body — read back from Rapier rather than remembered, so it reports what the solver does and not what the descriptor asked for.

      Parameters

      Returns CCDMode

    • World-space centre of mass into out (§25); out.z is 0 in this planar build. Served by Rapier's RigidBody.worldCom().

      Parameters

      Returns void

    • The monotonic id §33's checksum orders by.

      Parameters

      Returns number

    • The body's mass in kilograms, as the solver computed it (§23, §25).

      Parameters

      Returns number

    • Reads a body's world transform (§42's "physics" authority reads this). outRotation receives the pure Z quaternion for Rapier's scalar angle.

      Parameters

      Returns void

    • Reads linear (m/s) and angular (rad/s) velocity into out parameters.

      Parameters

      Returns void

    • §32 sleep state. The transitions are also reported as drainEvents events.

      Parameters

      Returns boolean

    • Clears the accumulated forces and torques (not impulses, which are applied immediately). Rapier keeps user forces across steps until reset.

      Parameters

      Returns void

    • Re-types a live body in place (§22, plan P7-3) — Rapier's own RigidBody.setBodyType, which keeps the body's handle, its colliders, its pose, and its mass properties.

      wake defaults to true, like RapierBodyAccess.setBodyTransform's.

      Parameters

      Returns void

    • Sets a "kinematic-position" body's target pose for the next step (§22). Rapier derives an artificial velocity from it so dynamic bodies react.

      Parameters

      Returns void

    • §32's explicit sleep command.

      Parameters

      Returns void

    • §32's explicit wake command.

      Parameters

      Returns void