@orillusion/physics-rapier 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -0
- package/dist/Physics.d.ts +114 -0
- package/dist/character/CharacterController.d.ts +54 -0
- package/dist/debug/PhysicsDebugDrawer.d.ts +38 -0
- package/dist/index.d.ts +19 -0
- package/dist/joint/ConstraintBase.d.ts +26 -0
- package/dist/joint/FixedJoint.d.ts +14 -0
- package/dist/joint/GenericJoint.d.ts +31 -0
- package/dist/joint/HingeJoint.d.ts +28 -0
- package/dist/joint/RopeJoint.d.ts +13 -0
- package/dist/joint/SliderJoint.d.ts +19 -0
- package/dist/joint/SphericalJoint.d.ts +14 -0
- package/dist/joint/SpringJoint.d.ts +15 -0
- package/dist/physics-rapier.es.js +6353 -0
- package/dist/physics-rapier.umd.js +2 -0
- package/dist/query/PhysicsQuery.d.ts +55 -0
- package/dist/rigidbody/Rigidbody.d.ts +118 -0
- package/dist/rigidbody/RigidbodyEnum.d.ts +13 -0
- package/dist/shape/CollisionShapeUtil.d.ts +95 -0
- package/dist/utils/PhysicsDragger.d.ts +33 -0
- package/dist/utils/TempPhyMath.d.ts +65 -0
- package/dist/vehicle/VehicleController.d.ts +60 -0
- package/package.json +29 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Vector3, Quaternion } from '@orillusion/core';
|
|
2
|
+
import RAPIER from '@dimforge/rapier3d-compat';
|
|
3
|
+
import { Rigidbody } from '../rigidbody/Rigidbody';
|
|
4
|
+
export interface QueryFilter {
|
|
5
|
+
/** Maximum hit distance / time-of-impact. Default Infinity-ish (1e6). */
|
|
6
|
+
maxDistance?: number;
|
|
7
|
+
/** Whether the ray treats colliders as solid (hits start-inside as t=0). */
|
|
8
|
+
solid?: boolean;
|
|
9
|
+
/** Skip a specific Rigidbody (e.g. the caster). */
|
|
10
|
+
excludeRigidbody?: Rigidbody;
|
|
11
|
+
/** Skip a specific Rapier collider. */
|
|
12
|
+
excludeCollider?: RAPIER.Collider;
|
|
13
|
+
/** Ignore sensors. */
|
|
14
|
+
excludeSensors?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface RaycastHit {
|
|
17
|
+
rigidbody: Rigidbody | null;
|
|
18
|
+
collider: RAPIER.Collider;
|
|
19
|
+
/** World-space hit point. */
|
|
20
|
+
point: Vector3;
|
|
21
|
+
/** World-space surface normal at the hit. */
|
|
22
|
+
normal: Vector3;
|
|
23
|
+
/** Time-of-impact along the ray (= distance for unit-length direction). */
|
|
24
|
+
toi: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ShapeHit {
|
|
27
|
+
rigidbody: Rigidbody | null;
|
|
28
|
+
collider: RAPIER.Collider;
|
|
29
|
+
point: Vector3;
|
|
30
|
+
normal1: Vector3;
|
|
31
|
+
normal2: Vector3;
|
|
32
|
+
toi: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Static physics queries — Rapier-backed.
|
|
36
|
+
*
|
|
37
|
+
* Replaces the missing public query API in `@orillusion/physics`.
|
|
38
|
+
*/
|
|
39
|
+
export declare class PhysicsQuery {
|
|
40
|
+
/** Cast a ray and return the closest hit, or `null`. */
|
|
41
|
+
static raycast(origin: Vector3, direction: Vector3, filter?: QueryFilter): RaycastHit | null;
|
|
42
|
+
/** Collect every collider intersected by the ray, up to `maxDistance`. */
|
|
43
|
+
static raycastAll(origin: Vector3, direction: Vector3, filter?: QueryFilter): RaycastHit[];
|
|
44
|
+
/** Sweep a shape along `velocity` for `maxDistance`, return first hit or null. */
|
|
45
|
+
static sweep(shape: RAPIER.ColliderDesc, position: Vector3, rotation: Quaternion, velocity: Vector3, filter?: QueryFilter): ShapeHit | null;
|
|
46
|
+
/** Return every collider whose AABB intersects the given shape's AABB. */
|
|
47
|
+
static overlap(shape: RAPIER.ColliderDesc, position: Vector3, rotation: Quaternion, filter?: QueryFilter): Rigidbody[];
|
|
48
|
+
/** Project a point onto the closest collider; returns `null` if none. */
|
|
49
|
+
static closestPoint(point: Vector3, filter?: QueryFilter): {
|
|
50
|
+
rigidbody: Rigidbody | null;
|
|
51
|
+
collider: RAPIER.Collider;
|
|
52
|
+
point: Vector3;
|
|
53
|
+
isInside: boolean;
|
|
54
|
+
} | null;
|
|
55
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ComponentBase, Vector3, Quaternion } from '@orillusion/core';
|
|
2
|
+
import RAPIER from '@dimforge/rapier3d-compat';
|
|
3
|
+
import { BodyType } from './RigidbodyEnum';
|
|
4
|
+
import { ChildShape } from '../shape/CollisionShapeUtil';
|
|
5
|
+
export type ContactCallback = (other: Rigidbody) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Rigidbody Component (Rapier backend).
|
|
8
|
+
*
|
|
9
|
+
* Public API mirrors `@orillusion/physics`'s `Rigidbody` where semantics line
|
|
10
|
+
* up. Rapier-only switches (`lockTranslations`, `enableCcd`) replace ammo's
|
|
11
|
+
* matrix-style `setLinearFactor / setCcdMotionThreshold + sweptSphereRadius`.
|
|
12
|
+
*
|
|
13
|
+
* @group Components
|
|
14
|
+
*/
|
|
15
|
+
export declare class Rigidbody extends ComponentBase {
|
|
16
|
+
private _initResolve;
|
|
17
|
+
private _initializationPromise;
|
|
18
|
+
private _bodyInited;
|
|
19
|
+
private _body;
|
|
20
|
+
private _colliders;
|
|
21
|
+
private _shapes;
|
|
22
|
+
private _bodyType;
|
|
23
|
+
private _mass;
|
|
24
|
+
private _restitution;
|
|
25
|
+
private _friction;
|
|
26
|
+
private _linearDamping;
|
|
27
|
+
private _angularDamping;
|
|
28
|
+
private _gravityScale;
|
|
29
|
+
private _ccd;
|
|
30
|
+
private _userIndex;
|
|
31
|
+
/**
|
|
32
|
+
* Whether this body is a sensor (no contact response, fires triggerEnter/Exit).
|
|
33
|
+
* Must be set BEFORE `start()`.
|
|
34
|
+
*/
|
|
35
|
+
isSensor: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether contact / trigger events are emitted. Must be set BEFORE
|
|
38
|
+
* `start()`. Off by default for performance.
|
|
39
|
+
*/
|
|
40
|
+
enableEvents: boolean;
|
|
41
|
+
/** Fires once when contact between two non-sensor bodies begins. */
|
|
42
|
+
onContactBegin?: ContactCallback;
|
|
43
|
+
/** Fires every frame while contact persists (after `onContactBegin`). */
|
|
44
|
+
onContactStay?: ContactCallback;
|
|
45
|
+
/** Fires once when contact ends. */
|
|
46
|
+
onContactEnd?: ContactCallback;
|
|
47
|
+
/** Fires once when a non-sensor body enters this sensor. */
|
|
48
|
+
onTriggerEnter?: ContactCallback;
|
|
49
|
+
/** Fires once when a non-sensor body leaves this sensor. */
|
|
50
|
+
onTriggerExit?: ContactCallback;
|
|
51
|
+
/** @internal */
|
|
52
|
+
_activeContacts: Set<Rigidbody>;
|
|
53
|
+
start(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Pull body pose into the owner Object3D. Called by `Physics.update` AFTER
|
|
56
|
+
* `world.step` so the transform reflects the post-step pose in the SAME
|
|
57
|
+
* frame's render. Doing this in `onUpdate` (which runs BEFORE the render-
|
|
58
|
+
* loop callback) would render the pre-step pose and lag visuals one frame
|
|
59
|
+
* behind physics — visible during kinematic drag where the body chases
|
|
60
|
+
* mouse-set `setNextKinematicTranslation` targets every frame.
|
|
61
|
+
*/
|
|
62
|
+
_syncTransformFromBody(force?: boolean): void;
|
|
63
|
+
onUpdate(): void;
|
|
64
|
+
destroy(force?: boolean): void;
|
|
65
|
+
/**
|
|
66
|
+
* @internal Swap in fresh body/collider wrappers after `Physics.restore()`
|
|
67
|
+
* rebuilds the world. Handles are preserved across snapshots, so the new
|
|
68
|
+
* wrappers describe the same logical entities — only their JS proxies
|
|
69
|
+
* needed refreshing.
|
|
70
|
+
*/
|
|
71
|
+
_rebind(body: RAPIER.RigidBody, colliders: RAPIER.Collider[]): void;
|
|
72
|
+
/** @internal Detach this component from the physics world (used when restore drops the body). */
|
|
73
|
+
_detach(): void;
|
|
74
|
+
wait(): Promise<RAPIER.RigidBody>;
|
|
75
|
+
get bodyInited(): boolean;
|
|
76
|
+
/** Escape hatch to the native Rapier RigidBody. Opts out of cross-backend portability. */
|
|
77
|
+
get native(): RAPIER.RigidBody;
|
|
78
|
+
get colliders(): RAPIER.Collider[];
|
|
79
|
+
/**
|
|
80
|
+
* Collider descriptor used to build the body. Accepts a single shape, a
|
|
81
|
+
* compound (`ChildShape[]`) or a flat array of `ColliderDesc`.
|
|
82
|
+
* Set BEFORE `start()`.
|
|
83
|
+
*/
|
|
84
|
+
get shape(): RAPIER.ColliderDesc | RAPIER.ColliderDesc[];
|
|
85
|
+
set shape(value: RAPIER.ColliderDesc | RAPIER.ColliderDesc[] | ChildShape[]);
|
|
86
|
+
get bodyType(): BodyType;
|
|
87
|
+
set bodyType(value: BodyType);
|
|
88
|
+
get mass(): number;
|
|
89
|
+
set mass(value: number);
|
|
90
|
+
get restitution(): number;
|
|
91
|
+
set restitution(value: number);
|
|
92
|
+
get friction(): number;
|
|
93
|
+
set friction(value: number);
|
|
94
|
+
get linearDamping(): number;
|
|
95
|
+
set linearDamping(value: number);
|
|
96
|
+
get angularDamping(): number;
|
|
97
|
+
set angularDamping(value: number);
|
|
98
|
+
get gravityScale(): number;
|
|
99
|
+
set gravityScale(value: number);
|
|
100
|
+
get userIndex(): number;
|
|
101
|
+
set userIndex(value: number);
|
|
102
|
+
get linearVelocity(): Vector3;
|
|
103
|
+
set linearVelocity(value: Vector3);
|
|
104
|
+
get angularVelocity(): Vector3;
|
|
105
|
+
set angularVelocity(value: Vector3);
|
|
106
|
+
/** Continuous Collision Detection. Replaces ammo's two-knob CCD API. */
|
|
107
|
+
enableCcd(value: boolean): void;
|
|
108
|
+
/** Lock translation axes. `true` locks the axis. (Rapier-only) */
|
|
109
|
+
lockTranslations(x: boolean, y: boolean, z: boolean): void;
|
|
110
|
+
/** Lock rotation axes. `true` locks the axis. (Rapier-only) */
|
|
111
|
+
lockRotations(x: boolean, y: boolean, z: boolean): void;
|
|
112
|
+
applyImpulse(impulse: Vector3, point?: Vector3): void;
|
|
113
|
+
applyTorqueImpulse(torque: Vector3): void;
|
|
114
|
+
applyForce(force: Vector3, point?: Vector3): void;
|
|
115
|
+
clearForcesAndVelocities(): void;
|
|
116
|
+
/** Force pose; mirrors ammo plugin's `Rigidbody.updateTransform`. */
|
|
117
|
+
updateTransform(position?: Vector3, rotation?: Vector3 | Quaternion, clearFV?: boolean): void;
|
|
118
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rigid body kind. Mirrors Rapier's RigidBodyType but exposes a simpler enum.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum BodyType {
|
|
5
|
+
/** Affected by forces and collisions. */
|
|
6
|
+
Dynamic = 0,
|
|
7
|
+
/** Immovable. Equivalent to ammo plugin's `mass = 0`. */
|
|
8
|
+
Static = 1,
|
|
9
|
+
/** Driven by user-set transform; velocity is auto-computed from delta. */
|
|
10
|
+
KinematicPosition = 2,
|
|
11
|
+
/** Driven by user-set velocity. */
|
|
12
|
+
KinematicVelocity = 3
|
|
13
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Object3D, Vector3, Quaternion } from '@orillusion/core';
|
|
2
|
+
import RAPIER from '@dimforge/rapier3d-compat';
|
|
3
|
+
/**
|
|
4
|
+
* One child entry of a "compound" shape. Rapier has no monolithic compound
|
|
5
|
+
* primitive — every entry becomes its own collider attached to the same body
|
|
6
|
+
* with the given offset.
|
|
7
|
+
*/
|
|
8
|
+
export interface ChildShape {
|
|
9
|
+
shape: RAPIER.ColliderDesc;
|
|
10
|
+
position: Vector3;
|
|
11
|
+
rotation: Quaternion;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Collider descriptor factories.
|
|
15
|
+
*
|
|
16
|
+
* Public method names mirror `@orillusion/physics`'s `CollisionShapeUtil`
|
|
17
|
+
* one-to-one where semantics line up. Some return types deviate where
|
|
18
|
+
* Rapier and Bullet model things differently:
|
|
19
|
+
*
|
|
20
|
+
* - `createCompoundShape*` returns `ChildShape[]` (Rapier has no monolithic
|
|
21
|
+
* compound primitive — multiple colliders attach to one body).
|
|
22
|
+
* - `createConvexHullShape` may return `null` if the points are degenerate
|
|
23
|
+
* (Rapier surfaces this; ammo silently constructs an invalid hull).
|
|
24
|
+
*/
|
|
25
|
+
export declare class CollisionShapeUtil {
|
|
26
|
+
/**
|
|
27
|
+
* Box shape. Falls back to mesh-bounds size when `size` omitted.
|
|
28
|
+
*/
|
|
29
|
+
static createBoxShape(object3D: Object3D, size?: Vector3): RAPIER.ColliderDesc;
|
|
30
|
+
/**
|
|
31
|
+
* Sphere shape. Falls back to mesh-bounds extents.x for radius.
|
|
32
|
+
*/
|
|
33
|
+
static createSphereShape(object3D: Object3D, radius?: number): RAPIER.ColliderDesc;
|
|
34
|
+
/**
|
|
35
|
+
* Capsule shape. NOTE: Rapier's capsule takes `halfHeight` (the half
|
|
36
|
+
* length of the cylindrical mid-section, NOT including the caps). The
|
|
37
|
+
* ammo plugin's `createCapsuleShape(obj, radius, height)` uses the full
|
|
38
|
+
* mid-section height; pass `height / 2` here.
|
|
39
|
+
*/
|
|
40
|
+
static createCapsuleShape(object3D: Object3D, radius?: number, halfHeight?: number): RAPIER.ColliderDesc;
|
|
41
|
+
/**
|
|
42
|
+
* Cylinder shape. NOTE: takes `halfHeight`, not full height.
|
|
43
|
+
*/
|
|
44
|
+
static createCylinderShape(object3D: Object3D, radius?: number, halfHeight?: number): RAPIER.ColliderDesc;
|
|
45
|
+
/**
|
|
46
|
+
* Cone shape. NOTE: takes `halfHeight`, not full height.
|
|
47
|
+
*/
|
|
48
|
+
static createConeShape(object3D: Object3D, radius?: number, halfHeight?: number): RAPIER.ColliderDesc;
|
|
49
|
+
/**
|
|
50
|
+
* Static plane stand-in. Rapier has no `staticPlane`; uses a wide thin
|
|
51
|
+
* cuboid so behavior matches the ammo plugin's typical floor pattern.
|
|
52
|
+
*/
|
|
53
|
+
static createPlaneShape(extent?: number, thickness?: number): RAPIER.ColliderDesc;
|
|
54
|
+
/**
|
|
55
|
+
* Compound shape. Returns an array of child descriptors — pass to
|
|
56
|
+
* `Rigidbody.shape = [...]` and each entry becomes its own collider.
|
|
57
|
+
*/
|
|
58
|
+
static createCompoundShape(childShapes: ChildShape[]): ChildShape[];
|
|
59
|
+
/**
|
|
60
|
+
* Build a compound from an Object3D's mesh hierarchy. Each child
|
|
61
|
+
* MeshRenderer contributes one collider, transformed into the parent's
|
|
62
|
+
* local space.
|
|
63
|
+
*/
|
|
64
|
+
static createCompoundShapeFromObject(object3D: Object3D, includeParent?: boolean): ChildShape[];
|
|
65
|
+
/**
|
|
66
|
+
* Pick the best primitive shape for a single Object3D, falling back to
|
|
67
|
+
* `convexHull` for arbitrary meshes. Mirrors the ammo plugin's
|
|
68
|
+
* `createShapeFromObject`.
|
|
69
|
+
*/
|
|
70
|
+
static createShapeFromObject(object3D: Object3D): RAPIER.ColliderDesc | null;
|
|
71
|
+
/**
|
|
72
|
+
* Convex-hull shape from raw vertices or an Object3D's mesh.
|
|
73
|
+
*/
|
|
74
|
+
static createConvexHullShape(object3D: Object3D, modelVertices?: Float32Array): RAPIER.ColliderDesc | null;
|
|
75
|
+
/**
|
|
76
|
+
* Triangle-mesh shape from Object3D's mesh. Suitable for static geometry.
|
|
77
|
+
* For dynamic bodies prefer `createConvexHullShape` or compounds.
|
|
78
|
+
*/
|
|
79
|
+
static createTrimeshShape(object3D: Object3D, modelVertices?: Float32Array, modelIndices?: Uint32Array): RAPIER.ColliderDesc;
|
|
80
|
+
/**
|
|
81
|
+
* Heightfield from a `PlaneGeometry`'s vertex Y values. Mirrors the ammo
|
|
82
|
+
* plugin's `createHeightfieldTerrainShape`.
|
|
83
|
+
*/
|
|
84
|
+
static createHeightfieldShape(object3D: Object3D): RAPIER.ColliderDesc;
|
|
85
|
+
/**
|
|
86
|
+
* Get a flat (verts, indices) representation of an Object3D's meshes.
|
|
87
|
+
* Mirrors the ammo plugin's helper, but widens indices to `Uint32Array`
|
|
88
|
+
* (Rapier requires u32; engine geometry uses u16 typically).
|
|
89
|
+
*/
|
|
90
|
+
static getAllMeshVerticesAndIndices(object3D: Object3D, isTransformChildren?: boolean): {
|
|
91
|
+
vertices: Float32Array<ArrayBufferLike>;
|
|
92
|
+
indices: Uint32Array<ArrayBufferLike>;
|
|
93
|
+
};
|
|
94
|
+
private static calculateLocalBoundingBox;
|
|
95
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { View3D } from '@orillusion/core';
|
|
2
|
+
/**
|
|
3
|
+
* Mouse-driven rigid-body dragger.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors `@orillusion/physics`'s `PhysicsDragger`. Implementation differs
|
|
6
|
+
* from the ammo version: rather than juggling collision flags, it switches
|
|
7
|
+
* the body to KinematicPositionBased while dragging, then restores the
|
|
8
|
+
* original type on release.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PhysicsDragger {
|
|
11
|
+
private _view;
|
|
12
|
+
private _enable;
|
|
13
|
+
private _interactionDepth;
|
|
14
|
+
private _hitPoint;
|
|
15
|
+
private _offset;
|
|
16
|
+
private _isDragging;
|
|
17
|
+
private _draggedBody;
|
|
18
|
+
private _originalBodyType;
|
|
19
|
+
private _registered;
|
|
20
|
+
filterStatic: boolean;
|
|
21
|
+
constructor(view: View3D);
|
|
22
|
+
set enable(value: boolean);
|
|
23
|
+
get enable(): boolean;
|
|
24
|
+
private get _input();
|
|
25
|
+
private _registerEvents;
|
|
26
|
+
private _unregisterEvents;
|
|
27
|
+
private _onMouseDown;
|
|
28
|
+
private _onMouseMove;
|
|
29
|
+
private _onMouseUp;
|
|
30
|
+
private _onMouseWheel;
|
|
31
|
+
private _updateBody;
|
|
32
|
+
private _resetState;
|
|
33
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Vector3, Quaternion } from '@orillusion/core';
|
|
2
|
+
/**
|
|
3
|
+
* Rapier Vec3 (POJO) — does not require destroy.
|
|
4
|
+
*/
|
|
5
|
+
export interface RVec3 {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Rapier Quat (POJO) — does not require destroy.
|
|
12
|
+
*/
|
|
13
|
+
export interface RQuat {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
z: number;
|
|
17
|
+
w: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Math conversion helpers between engine `Vector3 / Quaternion` and Rapier
|
|
21
|
+
* plain `{x, y, z, [w]}` objects. Provides reusable scratch objects.
|
|
22
|
+
*
|
|
23
|
+
* Unlike the ammo plugin's `TempPhyMath`, Rapier values are POJOs and do
|
|
24
|
+
* NOT need to be destroyed manually.
|
|
25
|
+
*/
|
|
26
|
+
export declare class TempPhyMath {
|
|
27
|
+
static readonly tmpVecA: RVec3;
|
|
28
|
+
static readonly tmpVecB: RVec3;
|
|
29
|
+
static readonly tmpVecC: RVec3;
|
|
30
|
+
static readonly tmpVecD: RVec3;
|
|
31
|
+
static readonly tmpQuaA: RQuat;
|
|
32
|
+
static readonly tmpQuaB: RQuat;
|
|
33
|
+
/**
|
|
34
|
+
* Vector3 → Rapier Vec3.
|
|
35
|
+
*/
|
|
36
|
+
static toRVec(vec: Vector3, target?: RVec3): RVec3;
|
|
37
|
+
/**
|
|
38
|
+
* Quaternion → Rapier Quat.
|
|
39
|
+
*/
|
|
40
|
+
static toRQuat(qua: Quaternion, target?: RQuat): RQuat;
|
|
41
|
+
/**
|
|
42
|
+
* Set Rapier Vec3 from raw scalars.
|
|
43
|
+
*/
|
|
44
|
+
static setRVec(x: number, y: number, z: number, target?: RVec3): RVec3;
|
|
45
|
+
/**
|
|
46
|
+
* Set Rapier Quat from raw scalars.
|
|
47
|
+
*/
|
|
48
|
+
static setRQuat(x: number, y: number, z: number, w: number, target?: RQuat): RQuat;
|
|
49
|
+
/**
|
|
50
|
+
* Rapier Vec3 → Vector3.
|
|
51
|
+
*/
|
|
52
|
+
static fromRVec(rv: RVec3, vec?: Vector3): Vector3;
|
|
53
|
+
/**
|
|
54
|
+
* Rapier Quat → Quaternion.
|
|
55
|
+
*/
|
|
56
|
+
static fromRQuat(rq: RQuat, qua?: Quaternion): Quaternion;
|
|
57
|
+
/**
|
|
58
|
+
* Sets the given Rapier Vec3 to (0, 0, 0).
|
|
59
|
+
*/
|
|
60
|
+
static zeroRVec(target?: RVec3): RVec3;
|
|
61
|
+
/**
|
|
62
|
+
* Sets the given Rapier Quat to (0, 0, 0, 1).
|
|
63
|
+
*/
|
|
64
|
+
static resetRQuat(target?: RQuat): RQuat;
|
|
65
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ComponentBase, Vector3 } from '@orillusion/core';
|
|
2
|
+
import RAPIER from '@dimforge/rapier3d-compat';
|
|
3
|
+
export interface WheelOptions {
|
|
4
|
+
/** Wheel attach point on chassis (chassis-local). */
|
|
5
|
+
chassisConnection: Vector3;
|
|
6
|
+
/** Suspension direction in chassis-local space. Typically -Y (down). */
|
|
7
|
+
suspensionDirection?: Vector3;
|
|
8
|
+
/** Wheel rolling axle direction in chassis-local space. Typically +X. */
|
|
9
|
+
axleDirection?: Vector3;
|
|
10
|
+
/** Resting suspension length. */
|
|
11
|
+
suspensionRestLength: number;
|
|
12
|
+
/** Wheel radius. */
|
|
13
|
+
radius: number;
|
|
14
|
+
/** Suspension stiffness coefficient. Default 30. */
|
|
15
|
+
stiffness?: number;
|
|
16
|
+
/** Damping when compressing the suspension. Default 0.83. */
|
|
17
|
+
dampingCompression?: number;
|
|
18
|
+
/** Damping when relaxing the suspension. Default 0.88. */
|
|
19
|
+
dampingRelaxation?: number;
|
|
20
|
+
/** Tire friction coefficient (longitudinal). Default 1000. */
|
|
21
|
+
frictionSlip?: number;
|
|
22
|
+
/** Side-slip friction stiffness. Default 1. */
|
|
23
|
+
sideFrictionStiffness?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Vehicle controller — Rapier-only. Replaces the bare `btRaycastVehicle`
|
|
27
|
+
* usage in the ammo plugin's car sample.
|
|
28
|
+
*
|
|
29
|
+
* This component must be added to the same Object3D as a `Rigidbody`
|
|
30
|
+
* (the chassis); it auto-discovers the chassis body via `wait()`.
|
|
31
|
+
*
|
|
32
|
+
* @group Components
|
|
33
|
+
*/
|
|
34
|
+
export declare class VehicleController extends ComponentBase {
|
|
35
|
+
private _initResolve;
|
|
36
|
+
private _initializationPromise;
|
|
37
|
+
private _controller;
|
|
38
|
+
private _vehicleInited;
|
|
39
|
+
private _pendingWheels;
|
|
40
|
+
/** Up axis index (0=X, 1=Y, 2=Z). Default 1 (+Y). */
|
|
41
|
+
indexUpAxis: number;
|
|
42
|
+
/** Forward axis index (0=X, 1=Y, 2=Z). Default 2 (+Z). */
|
|
43
|
+
indexForwardAxis: number;
|
|
44
|
+
start(): Promise<void>;
|
|
45
|
+
destroy(force?: boolean): void;
|
|
46
|
+
private _preStep;
|
|
47
|
+
/** Append a wheel. Can be called pre- or post-start. */
|
|
48
|
+
addWheel(opts: WheelOptions): void;
|
|
49
|
+
private _addWheelInternal;
|
|
50
|
+
setEngineForce(force: number, wheelIdx: number): void;
|
|
51
|
+
setBrake(brake: number, wheelIdx: number): void;
|
|
52
|
+
setSteering(angle: number, wheelIdx: number): void;
|
|
53
|
+
numWheels(): number;
|
|
54
|
+
wheelInContact(i: number): boolean;
|
|
55
|
+
wheelChassisConnectionPoint(i: number): Vector3 | null;
|
|
56
|
+
/** Current vehicle speed in km/h. Mirrors ammo's `getCurrentSpeedKmHour`. */
|
|
57
|
+
currentSpeedKmHour(): number;
|
|
58
|
+
wait(): Promise<void>;
|
|
59
|
+
get native(): RAPIER.DynamicRayCastVehicleController;
|
|
60
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orillusion/physics-rapier",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "Orillusion",
|
|
5
|
+
"description": "Orillusion Physics Plugin, Powered by Rapier (Rust → WASM).",
|
|
6
|
+
"main": "./dist/physics-rapier.umd.js",
|
|
7
|
+
"module": "./dist/physics-rapier.es.js",
|
|
8
|
+
"module:dev": "./index.ts",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": ["dist"],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "vite build && npm run build:types && npm run build:clean",
|
|
13
|
+
"build:types": "tsc --emitDeclarationOnly --experimentalDecorators -p tsconfig.json",
|
|
14
|
+
"build:clean": "mv dist/packages/physics-rapier/* dist && rm -rf dist/src && rm -rf dist/packages",
|
|
15
|
+
"docs": "npm run docs:typedoc ../../docs/physics-rapier index.ts",
|
|
16
|
+
"docs:typedoc": "npx typedoc --plugin typedoc-plugin-markdown --tsconfig tsconfig.json --gitRevision main --hideBreadcrumbs --router member --readme none --excludeInternal --excludePrivate --excludeProtected --excludeExternals --sort source-order --out"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Orillusion/orillusion.git"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@dimforge/rapier3d-compat": "^0.14.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@orillusion/core": ">=0.9.0"
|
|
28
|
+
}
|
|
29
|
+
}
|