Skip to content

@bendyline/molen-physics-rapier ​

Molen opt-in Rapier rigid-body physics: body<->ECS mirroring, hybrid snapshot.

ts
import { /* … */ } from '@bendyline/molen-physics-rapier';

Interfaces ​

Collider3DData ​

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

density? ​
ts
optional density?: number;
events? ​
ts
optional events?: boolean;

Opt into collision start/end events for this collider.

friction? ​
ts
optional friction?: number;
layer? ​
ts
optional layer?: number;
mask? ​
ts
optional mask?: number;
offset? ​
ts
optional offset?: Vec3;

Local offset from the entity transform.

restitution? ​
ts
optional restitution?: number;
rotOffset? ​
ts
optional rotOffset?: [number, number, number, number];
sensor? ​
ts
optional sensor?: boolean;

Sensor colliders detect overlaps without a physical response.

shape ​
ts
shape: Shape3D;

ForceData ​

Continuous force/torque applied every tick while the component is present.

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

linear? ​
ts
optional linear?: Vec3;
torque? ​
ts
optional torque?: Vec3;

HeightfieldGeometry ​

Heightfield geometry: heights is an nrows x ncols SAMPLE matrix (nrows*ncols entries) in column-major order (heights[col * nrows + row]). Columns run along local +x (column j sits at (-0.5 + j/(ncols-1)) * scale.x), rows along local +z; scale is the local x/z extent and the y multiplier. The shape is centered on its local origin unless center is given, which becomes the collider's local translation when the authored collider has no offset of its own. (Rapier's own API counts cells; the plugin converts.)

Properties ​

center? ​
ts
optional center?: Vec3;
heights ​
ts
heights: Float32Array;
ncols ​
ts
ncols: number;
nrows ​
ts
nrows: number;
scale ​
ts
scale: Vec3;

ImpulseData ​

One-shot impulse; consumed the tick it is applied.

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

torque? ​
ts
optional torque?: Vec3;
v? ​
ts
optional v?: Vec3;

JointData ​

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

anchor1 ​
ts
anchor1: Vec3;
anchor2 ​
ts
anchor2: Vec3;
axis? ​
ts
optional axis?: Vec3;

revolute/prismatic axis.

limits? ​
ts
optional limits?: [number, number];
motor? ​
ts
optional motor?: object;
maxForce ​
ts
maxForce: number;
targetVel ​
ts
targetVel: number;
other ​
ts
other: string;

Entity id of the OTHER body (this entity is body 2).

type ​
ts
type: "fixed" | "revolute" | "spherical" | "prismatic";

QueryFilter ​

Collider filter shared by the spatial queries.

Extended by ​

Properties ​

exclude? ​
ts
optional exclude?: string[];

Entities whose colliders are skipped.

mask? ​
ts
optional mask?: number;

Only colliders whose layer bits intersect this mask are considered.


RapierCharacterOptions ​

Properties ​

autostep? ​
ts
optional autostep?: object;
maxHeight ​
ts
maxHeight: number;
minWidth ​
ts
minWidth: number;
maxSlopeClimbAngle? ​
ts
optional maxSlopeClimbAngle?: number;
offset? ​
ts
optional offset?: number;

Controller skin offset (default 0.02).

snapToGround? ​
ts
optional snapToGround?: number;

RapierHandle ​

Properties ​

world ​
ts
readonly world: World;

The live Rapier world (escape hatch).

Methods ​

dispose() ​
ts
dispose(): void;

Free the Rapier world, event queue, and character-controller WASM resources, and detach the system + snapshot provider from the world. Queries throw afterwards.

Returns ​

void

overlapSphere() ​
ts
overlapSphere(
   center, 
   radius, 
   opts?
): string[];
Parameters ​
center ​

Vec3

radius ​

number

opts? ​

QueryFilter

Returns ​

string[]

raycast() ​
ts
raycast(
   origin, 
   dir, 
   maxDist, 
   opts?
): RayHit3D | null;

A boolean opts keeps the older solid meaning.

Parameters ​
origin ​

Vec3

dir ​

Vec3

maxDist ​

number

opts? ​

boolean | RaycastOptions

Returns ​

RayHit3D | null

velocityOf() ​
ts
velocityOf(id): 
  | {
  angular: Vec3;
  linear: Vec3;
}
  | undefined;

Live velocity read (not serialized; use the velocity component for mirrored state).

Parameters ​
id ​

string

Returns ​

| { angular: Vec3; linear: Vec3; } | undefined


RapierOptions ​

Properties ​

character? ​
ts
optional character?: RapierCharacterOptions;
gravity? ​
ts
optional gravity?: Vec3;
resolvers? ​
ts
optional resolvers?: ShapeResolvers;

RaycastOptions ​

Collider filter shared by the spatial queries.

Extends ​

Properties ​

exclude? ​
ts
optional exclude?: string[];

Entities whose colliders are skipped.

Inherited from ​

QueryFilter.exclude

mask? ​
ts
optional mask?: number;

Only colliders whose layer bits intersect this mask are considered.

Inherited from ​

QueryFilter.mask

solid? ​
ts
optional solid?: boolean;

false treats shapes as hollow (a ray starting inside still hits the boundary). Default true.


RayHit3D ​

Properties ​

distance ​
ts
distance: number;
id ​
ts
id: string;
normal ​
ts
normal: Vec3;

Surface normal at the hit point.

point ​
ts
point: Vec3;

RigidBodyData ​

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

angularDamping? ​
ts
optional angularDamping?: number;
body ​
ts
body: "fixed" | "dynamic" | "kinematicPosition";
ccd? ​
ts
optional ccd?: boolean;

Continuous collision detection for fast movers.

gravityScale? ​
ts
optional gravityScale?: number;
linearDamping? ​
ts
optional linearDamping?: number;
lockRot? ​
ts
optional lockRot?: boolean;

Lock all rotation (upright characters, HUD-ish bodies).


SetVelocityData ​

One-shot velocity set; consumed the tick it is applied.

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

angular? ​
ts
optional angular?: Vec3;
linear? ​
ts
optional linear?: Vec3;

ShapeResolvers ​

How asset/heightfield shapes resolve to geometry (wired by tooling/apps; fs-free here).

Methods ​

asset()? ​
ts
optional asset(
   assetId, 
   kind, 
   index?
): 
  | {
  points: Float32Array;
}
  | {
  indices: Uint32Array;
  vertices: Float32Array;
}
  | undefined;
Parameters ​
assetId ​

string

kind ​

"trimesh" | "hull"

index? ​

number

Returns ​

| { points: Float32Array; } | { indices: Uint32Array; vertices: Float32Array; } | undefined

heightfield()? ​
ts
optional heightfield(ref): HeightfieldGeometry | undefined;
Parameters ​
ref ​

string

Returns ​

HeightfieldGeometry | undefined


VelocityData ​

Opt-in per-tick velocity mirror (presence = subscription; plugin-written).

Extends ​

  • JsonObject

Indexable ​

ts
[key: string]: JsonValue | undefined

Properties ​

angular ​
ts
angular: Vec3;
linear ​
ts
linear: Vec3;

Type Aliases ​

Shape3D ​

ts
type Shape3D = 
  | {
  radius: number;
  type: "ball";
}
  | {
  hx: number;
  hy: number;
  hz: number;
  type: "cuboid";
}
  | {
  halfHeight: number;
  radius: number;
  type: "capsule";
}
  | {
  points: number[];
  type: "convexHull";
}
  | {
  indices: number[];
  type: "trimesh";
  vertices: number[];
}
  | {
  assetId: string;
  collision?: "hull" | "trimesh";
  index?: number;
  type: "asset";
}
  | {
  ref: string;
  type: "heightfield";
};

Variables ​

Collider3D ​

ts
const Collider3D: ComponentType<Collider3DData>;

Force ​

ts
const Force: ComponentType<ForceData>;

Impulse ​

ts
const Impulse: ComponentType<ImpulseData>;

Joint ​

ts
const Joint: ComponentType<JointData>;

Rigidbody ​

ts
const Rigidbody: ComponentType<RigidBodyData>;

SetVelocity ​

ts
const SetVelocity: ComponentType<SetVelocityData>;

Velocity ​

ts
const Velocity: ComponentType<VelocityData>;

Functions ​

initRapier() ​

ts
function initRapier(): Promise<void>;

Initialize the Rapier WASM runtime once. Must be awaited before installRapier.

Returns ​

Promise&lt;void&gt;


installRapier() ​

ts
function installRapier(world, opts?): RapierHandle;

Install the Rapier physics system + snapshot provider. Requires initRapier() first.

Parameters ​

world ​

World

opts? ​

RapierOptions

Returns ​

RapierHandle


installScenePhysics() ​

ts
function installScenePhysics(
   world, 
   manifest, 
   resolvers?
): RapierHandle | undefined;

Install physics per the scene's physics block (engine "rapier"). Returns the handle, or undefined when the scene doesn't ask for rapier. Requires initRapier() first.

Parameters ​

world ​

World

manifest ​

SceneManifest

resolvers? ​

ShapeResolvers

Returns ​

RapierHandle | undefined


rapierScriptApi() ​

ts
function rapierScriptApi(handle): object;

The script-sandbox extension namespace: pass as extensions: { physics: rapierScriptApi(h) }.

Parameters ​

handle ​

RapierHandle

Returns ​

object

37 guides · 36 schema formats · 41 API entry points · 10 samples. API, CLI and schema pages are generated from the shipped build.