@threenative/physics 0.2.1 → 0.3.1
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/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/{Area3D-CvwDbfU6.d.ts → Area3D-BQDiAwQb.d.ts} +211 -69
- package/dist/index.d.ts +73 -4
- package/dist/index.js +886 -175
- package/dist/native/index.d.ts +2 -2
- package/dist/native/index.js +832 -136
- package/dist/navigation/index.d.ts +1 -1
- package/dist/navigation/index.js +201 -4678
- package/package.json +26 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Furtado
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -5,10 +5,10 @@ Godot-shaped physics nodes backed by Rapier: `RigidBody3D`, `Area3D`,
|
|
|
5
5
|
|
|
6
6
|
## Backend portability
|
|
7
7
|
|
|
8
|
-
Browser
|
|
8
|
+
Browser builds use Rapier WASM `0.19.3`. Native desktop, Android, and iOS builds select the
|
|
9
9
|
ThreeNative runtime's native Rapier `0.30.0` adapter through the `threenative-native` export
|
|
10
10
|
condition. Physics replays and snapshots are repeatable only within the exact pinned runtime
|
|
11
|
-
that recorded them; they are not portable between web
|
|
11
|
+
that recorded them; they are not portable between web and native builds,
|
|
12
12
|
Rapier versions, operating systems, or architectures.
|
|
13
13
|
|
|
14
14
|
`world.raw`, `body.raw`, `collider.raw`, and `CollisionShape3D.raw` are backend-specific.
|
|
@@ -71,6 +71,8 @@ interface IPhysicsBodyCreateOptions {
|
|
|
71
71
|
readonly mass: number;
|
|
72
72
|
/** Must match `shape.sensor`; conflicting values are rejected during body creation. */
|
|
73
73
|
readonly sensor: boolean;
|
|
74
|
+
/** Enable continuous collision for fast-moving dynamic bodies. Defaults true for dynamic bodies and is always false for non-dynamic bodies. */
|
|
75
|
+
readonly continuousCollision?: boolean;
|
|
74
76
|
}
|
|
75
77
|
interface IPhysicsVector3 {
|
|
76
78
|
readonly x: number;
|
|
@@ -83,6 +85,23 @@ interface IPhysicsRotation {
|
|
|
83
85
|
readonly z: number;
|
|
84
86
|
readonly w: number;
|
|
85
87
|
}
|
|
88
|
+
type PhysicsJointKind = "pin" | "hinge" | "fixed";
|
|
89
|
+
interface IPhysicsJointLimit {
|
|
90
|
+
readonly lower: number;
|
|
91
|
+
readonly upper: number;
|
|
92
|
+
}
|
|
93
|
+
/** Backend-neutral data for a cold-path joint creation call. Anchors and frames are local-space. */
|
|
94
|
+
interface IPhysicsJointCreateOptions {
|
|
95
|
+
readonly type: PhysicsJointKind;
|
|
96
|
+
readonly bodyA: number;
|
|
97
|
+
readonly bodyB: number;
|
|
98
|
+
readonly anchorA: IPhysicsVector3;
|
|
99
|
+
readonly anchorB: IPhysicsVector3;
|
|
100
|
+
readonly axis?: IPhysicsVector3;
|
|
101
|
+
readonly limit?: IPhysicsJointLimit;
|
|
102
|
+
readonly frameA?: IPhysicsRotation;
|
|
103
|
+
readonly frameB?: IPhysicsRotation;
|
|
104
|
+
}
|
|
86
105
|
interface IPhysicsRayQuery {
|
|
87
106
|
readonly from: IPhysicsVector3;
|
|
88
107
|
readonly to: IPhysicsVector3;
|
|
@@ -131,7 +150,9 @@ interface IPhysicsCharacterOptions {
|
|
|
131
150
|
}
|
|
132
151
|
interface IPhysicsCharacterState {
|
|
133
152
|
readonly grounded: boolean;
|
|
153
|
+
readonly groundBody?: IPhysicsBodyHandle;
|
|
134
154
|
readonly groundCollider?: number;
|
|
155
|
+
readonly groundNormal?: IPhysicsVector3;
|
|
135
156
|
}
|
|
136
157
|
interface IPhysicsInputSnapshot {
|
|
137
158
|
/** One eight-float record per kinematic body. The buffer is caller-owned and reusable. */
|
|
@@ -141,8 +162,10 @@ interface IPhysicsInputSnapshot {
|
|
|
141
162
|
/** The backend seam used by all shared physics nodes. */
|
|
142
163
|
interface IPhysicsSimulation {
|
|
143
164
|
createBody(options: IPhysicsBodyCreateOptions): IPhysicsBodyRegistration;
|
|
165
|
+
createJoint(options: IPhysicsJointCreateOptions): number;
|
|
144
166
|
configureCharacter(id: number, options: IPhysicsCharacterOptions): void;
|
|
145
167
|
removeBody(id: number): void;
|
|
168
|
+
removeJoint(id: number): void;
|
|
146
169
|
/** Cold-path repositioning for teleport/setup. Per-frame kinematics use `step()` input. */
|
|
147
170
|
setBodyTransform(id: number, position: {
|
|
148
171
|
readonly x: number;
|
|
@@ -155,6 +178,7 @@ interface IPhysicsSimulation {
|
|
|
155
178
|
*/
|
|
156
179
|
applyBodyImpulse(id: number, impulse: IPhysicsVector3): void;
|
|
157
180
|
applyBodyForce(id: number, force: IPhysicsVector3): void;
|
|
181
|
+
applyBodyForceAtPoint(id: number, force: IPhysicsVector3, point: IPhysicsVector3): void;
|
|
158
182
|
setBodyLinearVelocity(id: number, velocity: IPhysicsVector3): void;
|
|
159
183
|
readBodyLinearVelocity(id: number): IPhysicsVector3;
|
|
160
184
|
step(deltaTime: number, inputSnapshot?: IPhysicsInputSnapshot): void;
|
|
@@ -176,9 +200,19 @@ interface IPhysicsSimulation {
|
|
|
176
200
|
readonly w: number;
|
|
177
201
|
};
|
|
178
202
|
} | undefined;
|
|
179
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* Reflects the most recently completed step, independent of visible-transform reads.
|
|
205
|
+
*
|
|
206
|
+
* This reuses one record per character, so the next call overwrites the object it returned.
|
|
207
|
+
* Read it in the same tick, or copy the fields out before the step advances.
|
|
208
|
+
*/
|
|
180
209
|
readCharacterState?(id: number): IPhysicsCharacterState | undefined;
|
|
181
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* Reflects the most recently completed step, independent of visible-transform reads.
|
|
212
|
+
*
|
|
213
|
+
* This reuses one set per area, so the next call overwrites the set it returned. Read it in
|
|
214
|
+
* the same tick, or copy the fields out before the step advances.
|
|
215
|
+
*/
|
|
182
216
|
areaIntersections?(id: number): ReadonlySet<number>;
|
|
183
217
|
drainCollisionEvents(buffer: Uint32Array): number;
|
|
184
218
|
dispose(): void;
|
|
@@ -231,6 +265,153 @@ declare class CollisionShape3D {
|
|
|
231
265
|
setSensor(sensor: boolean): this;
|
|
232
266
|
}
|
|
233
267
|
|
|
268
|
+
type RigidBodyType = "dynamic" | "fixed" | "kinematic";
|
|
269
|
+
interface IRigidBody3DOptions {
|
|
270
|
+
/** The transform this body drives. Omit for a fixed collider with no visual; supply `position`. */
|
|
271
|
+
readonly object?: Object3D;
|
|
272
|
+
/** Initial world position. Only for a fixed body with no `object`. */
|
|
273
|
+
readonly position?: Pick<Vector3, "x" | "y" | "z">;
|
|
274
|
+
readonly entity?: string;
|
|
275
|
+
readonly physics?: IPhysicsContext;
|
|
276
|
+
/** @deprecated Prefer `physics`; a raw web world is backend-specific. */
|
|
277
|
+
readonly world?: IPhysicsWorldHandle | unknown;
|
|
278
|
+
readonly shape: CollisionShape3D;
|
|
279
|
+
readonly mass?: number;
|
|
280
|
+
readonly type?: RigidBodyType;
|
|
281
|
+
/** Godot's collision_layer — which layers this body occupies. Default 1. */
|
|
282
|
+
readonly collisionLayer?: number;
|
|
283
|
+
/** Godot's collision_mask — which layers this body scans. Default 0xffff. */
|
|
284
|
+
readonly collisionMask?: number;
|
|
285
|
+
/** Enable continuous collision for fast-moving dynamic bodies. Dynamic defaults true; fixed and kinematic bodies are always disabled. */
|
|
286
|
+
readonly continuousCollision?: boolean;
|
|
287
|
+
}
|
|
288
|
+
declare class RigidBody3D {
|
|
289
|
+
#private;
|
|
290
|
+
readonly body: IPhysicsBodyHandle;
|
|
291
|
+
readonly collider: IPhysicsColliderHandle;
|
|
292
|
+
/** The supplied transform; position-only fixed bodies have no runtime object. */
|
|
293
|
+
readonly object: Object3D | undefined;
|
|
294
|
+
readonly shape: CollisionShape3D;
|
|
295
|
+
readonly type: RigidBodyType;
|
|
296
|
+
readonly mass: number;
|
|
297
|
+
/** The effective continuous-collision setting; dynamic defaults true, fixed and kinematic are always false. */
|
|
298
|
+
readonly continuousCollision: boolean;
|
|
299
|
+
buoyancy: Buoyancy3D | undefined;
|
|
300
|
+
constructor(options: IRigidBody3DOptions);
|
|
301
|
+
get physics(): IPhysicsContext | undefined;
|
|
302
|
+
/** Called by the shared plugin before a bulk step. */
|
|
303
|
+
writeKinematic(buffer: Float32Array, offset: number): void;
|
|
304
|
+
/** Displacement since the last backend transform, used for moving-platform carry. */
|
|
305
|
+
kinematicMotion(): {
|
|
306
|
+
readonly x: number;
|
|
307
|
+
readonly y: number;
|
|
308
|
+
readonly z: number;
|
|
309
|
+
};
|
|
310
|
+
syncToPhysics(): void;
|
|
311
|
+
/**
|
|
312
|
+
* Godot's `apply_impulse`. The one-shot shove: a thrown crate, a jump pad, a hit reaction.
|
|
313
|
+
*
|
|
314
|
+
* These four members exist because there is otherwise no portable way to move a dynamic body
|
|
315
|
+
* at all. `body.raw` is a Rapier object on web and opaque on native, so reaching through it
|
|
316
|
+
* forks the game by platform, and a transform write is discarded by the next step.
|
|
317
|
+
*/
|
|
318
|
+
applyImpulse(impulse: {
|
|
319
|
+
readonly x: number;
|
|
320
|
+
readonly y: number;
|
|
321
|
+
readonly z: number;
|
|
322
|
+
}): void;
|
|
323
|
+
/** Godot's `apply_force`. Continuous push; cleared by the backend each step. */
|
|
324
|
+
applyForce(force: {
|
|
325
|
+
readonly x: number;
|
|
326
|
+
readonly y: number;
|
|
327
|
+
readonly z: number;
|
|
328
|
+
}): void;
|
|
329
|
+
/** Godot's force-at-position equivalent. Continuous push in world space; cleared each step. */
|
|
330
|
+
applyForceAtPoint(force: {
|
|
331
|
+
readonly x: number;
|
|
332
|
+
readonly y: number;
|
|
333
|
+
readonly z: number;
|
|
334
|
+
}, point: {
|
|
335
|
+
readonly x: number;
|
|
336
|
+
readonly y: number;
|
|
337
|
+
readonly z: number;
|
|
338
|
+
}): void;
|
|
339
|
+
/** Godot's `linear_velocity`. */
|
|
340
|
+
get linearVelocity(): {
|
|
341
|
+
readonly x: number;
|
|
342
|
+
readonly y: number;
|
|
343
|
+
readonly z: number;
|
|
344
|
+
};
|
|
345
|
+
set linearVelocity(velocity: {
|
|
346
|
+
readonly x: number;
|
|
347
|
+
readonly y: number;
|
|
348
|
+
readonly z: number;
|
|
349
|
+
});
|
|
350
|
+
syncFromPhysics(): void;
|
|
351
|
+
applyTransform(values: Readonly<Float32Array>, offset: number): void;
|
|
352
|
+
dispose(): void;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
interface IBuoyancySurfaceSample {
|
|
356
|
+
readonly height: number;
|
|
357
|
+
readonly normal?: {
|
|
358
|
+
readonly x: number;
|
|
359
|
+
readonly y: number;
|
|
360
|
+
readonly z: number;
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
interface IBuoyancySurface {
|
|
364
|
+
sample(x: number, z: number, time: number): IBuoyancySurfaceSample;
|
|
365
|
+
}
|
|
366
|
+
type BuoyancyPointPosition = readonly [number, number, number] | {
|
|
367
|
+
readonly x: number;
|
|
368
|
+
readonly y: number;
|
|
369
|
+
readonly z: number;
|
|
370
|
+
};
|
|
371
|
+
interface IBuoyancyHullPoint {
|
|
372
|
+
readonly position: BuoyancyPointPosition;
|
|
373
|
+
readonly volume?: number;
|
|
374
|
+
readonly spacing?: number;
|
|
375
|
+
}
|
|
376
|
+
interface IBuoyancy3DOptions {
|
|
377
|
+
readonly body: RigidBody3D;
|
|
378
|
+
readonly hullPoints: readonly IBuoyancyHullPoint[];
|
|
379
|
+
readonly surface?: IBuoyancySurface;
|
|
380
|
+
readonly heightSource?: IBuoyancySurface;
|
|
381
|
+
readonly field?: IBuoyancySurface;
|
|
382
|
+
readonly physics?: IPhysicsContext;
|
|
383
|
+
/** Fluid density in the same units as the body's mass and world gravity. */
|
|
384
|
+
readonly density?: number;
|
|
385
|
+
/** Total displaced volume when points do not carry individual volumes. */
|
|
386
|
+
readonly volume?: number;
|
|
387
|
+
/** Vertical sample span used to turn a hull point into a partial volume. */
|
|
388
|
+
readonly pointSpacing?: number;
|
|
389
|
+
/** Continuous velocity drag for the submerged volume. */
|
|
390
|
+
readonly drag?: number;
|
|
391
|
+
readonly gravity?: number;
|
|
392
|
+
/** Convention switch. Measurement continues when false. */
|
|
393
|
+
readonly buoyancy?: boolean;
|
|
394
|
+
}
|
|
395
|
+
/** Applies game-authored displaced-volume forces before the shared physics step. */
|
|
396
|
+
declare class Buoyancy3D {
|
|
397
|
+
#private;
|
|
398
|
+
readonly body: RigidBody3D;
|
|
399
|
+
readonly hullPoints: readonly IBuoyancyHullPoint[];
|
|
400
|
+
readonly density: number;
|
|
401
|
+
readonly drag: number;
|
|
402
|
+
readonly gravity: number;
|
|
403
|
+
constructor(options: IBuoyancy3DOptions);
|
|
404
|
+
get enabled(): boolean;
|
|
405
|
+
set enabled(value: boolean);
|
|
406
|
+
get buoyancy(): boolean;
|
|
407
|
+
set buoyancy(value: boolean);
|
|
408
|
+
get submergedFraction(): number;
|
|
409
|
+
get time(): number;
|
|
410
|
+
/** Called by `rapier()` immediately before its fixed-step backend call. */
|
|
411
|
+
apply(deltaTime: number): void;
|
|
412
|
+
dispose(): void;
|
|
413
|
+
}
|
|
414
|
+
|
|
234
415
|
interface ICharacterBody3DOptions {
|
|
235
416
|
readonly object: Object3D;
|
|
236
417
|
readonly entity?: string;
|
|
@@ -283,8 +464,25 @@ declare class CharacterBody3D {
|
|
|
283
464
|
maxFallSpeed: number;
|
|
284
465
|
readonly oneWayLayers: number;
|
|
285
466
|
grounded: boolean;
|
|
467
|
+
/** Contact normal from the completed physics step; reset to +Y while airborne. */
|
|
468
|
+
readonly groundNormal: Vector3;
|
|
469
|
+
/** Portable handle for the body currently supporting this character. */
|
|
470
|
+
groundBody: IPhysicsBodyHandle | undefined;
|
|
471
|
+
/** Radians between `groundNormal` and world up (+Y). */
|
|
472
|
+
slopeAngle: number;
|
|
286
473
|
constructor(options: ICharacterBody3DOptions);
|
|
287
474
|
move(desiredTranslation: Pick<Vector3, "x" | "y" | "z">): void;
|
|
475
|
+
/**
|
|
476
|
+
* Queue velocity-based motion for the shared bulk physics step.
|
|
477
|
+
*
|
|
478
|
+
* @remarks
|
|
479
|
+
* This does not move `object` synchronously. The solver writes the transform after the step, so
|
|
480
|
+
* reading `object.position` immediately after this call still observes the previous transform.
|
|
481
|
+
* Three.js `Vector3` instances are mutable, so do not retain `object.position` itself as the
|
|
482
|
+
* snapshot: use `const before = object.position.clone()` (or copy its `x`, `y`, and `z` scalars).
|
|
483
|
+
* Compare that snapshot with `object.position` only after the deferred bulk physics step,
|
|
484
|
+
* typically on the next frame, to measure the motion that the solver applied.
|
|
485
|
+
*/
|
|
288
486
|
moveAndSlide(dt: number): void;
|
|
289
487
|
/** Called by the shared plugin before a bulk step. */
|
|
290
488
|
writeKinematic(buffer: Float32Array, offset: number): void;
|
|
@@ -333,71 +531,6 @@ declare class PhysicsDirectSpaceState3D {
|
|
|
333
531
|
intersectPoint(options: IIntersectPointOptions): readonly IPointHit[];
|
|
334
532
|
}
|
|
335
533
|
|
|
336
|
-
type RigidBodyType = "dynamic" | "fixed" | "kinematic";
|
|
337
|
-
interface IRigidBody3DOptions {
|
|
338
|
-
readonly object: Object3D;
|
|
339
|
-
readonly entity?: string;
|
|
340
|
-
readonly physics?: IPhysicsContext;
|
|
341
|
-
/** @deprecated Prefer `physics`; a raw web world is backend-specific. */
|
|
342
|
-
readonly world?: IPhysicsWorldHandle | unknown;
|
|
343
|
-
readonly shape: CollisionShape3D;
|
|
344
|
-
readonly mass?: number;
|
|
345
|
-
readonly type?: RigidBodyType;
|
|
346
|
-
/** Godot's collision_layer — which layers this body occupies. Default 1. */
|
|
347
|
-
readonly collisionLayer?: number;
|
|
348
|
-
/** Godot's collision_mask — which layers this body scans. Default 0xffff. */
|
|
349
|
-
readonly collisionMask?: number;
|
|
350
|
-
}
|
|
351
|
-
declare class RigidBody3D {
|
|
352
|
-
#private;
|
|
353
|
-
readonly body: IPhysicsBodyHandle;
|
|
354
|
-
readonly collider: IPhysicsColliderHandle;
|
|
355
|
-
readonly object: Object3D;
|
|
356
|
-
readonly type: RigidBodyType;
|
|
357
|
-
constructor(options: IRigidBody3DOptions);
|
|
358
|
-
/** Called by the shared plugin before a bulk step. */
|
|
359
|
-
writeKinematic(buffer: Float32Array, offset: number): void;
|
|
360
|
-
/** Displacement since the last backend transform, used for moving-platform carry. */
|
|
361
|
-
kinematicMotion(): {
|
|
362
|
-
readonly x: number;
|
|
363
|
-
readonly y: number;
|
|
364
|
-
readonly z: number;
|
|
365
|
-
};
|
|
366
|
-
syncToPhysics(): void;
|
|
367
|
-
/**
|
|
368
|
-
* Godot's `apply_impulse`. The one-shot shove: a thrown crate, a jump pad, a hit reaction.
|
|
369
|
-
*
|
|
370
|
-
* These four members exist because there is otherwise no portable way to move a dynamic body
|
|
371
|
-
* at all. `body.raw` is a Rapier object on web and opaque on native, so reaching through it
|
|
372
|
-
* forks the game by platform, and a transform write is discarded by the next step.
|
|
373
|
-
*/
|
|
374
|
-
applyImpulse(impulse: {
|
|
375
|
-
readonly x: number;
|
|
376
|
-
readonly y: number;
|
|
377
|
-
readonly z: number;
|
|
378
|
-
}): void;
|
|
379
|
-
/** Godot's `apply_force`. Continuous push; cleared by the backend each step. */
|
|
380
|
-
applyForce(force: {
|
|
381
|
-
readonly x: number;
|
|
382
|
-
readonly y: number;
|
|
383
|
-
readonly z: number;
|
|
384
|
-
}): void;
|
|
385
|
-
/** Godot's `linear_velocity`. */
|
|
386
|
-
get linearVelocity(): {
|
|
387
|
-
readonly x: number;
|
|
388
|
-
readonly y: number;
|
|
389
|
-
readonly z: number;
|
|
390
|
-
};
|
|
391
|
-
set linearVelocity(velocity: {
|
|
392
|
-
readonly x: number;
|
|
393
|
-
readonly y: number;
|
|
394
|
-
readonly z: number;
|
|
395
|
-
});
|
|
396
|
-
syncFromPhysics(): void;
|
|
397
|
-
applyTransform(values: Readonly<Float32Array>, offset: number): void;
|
|
398
|
-
dispose(): void;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
534
|
type NavigationAgentEvent = "targetReached" | "navigationFinished" | "pathChanged";
|
|
402
535
|
type NavigationAgentHandler = () => void;
|
|
403
536
|
interface INavigationAgent3DOptions {
|
|
@@ -425,7 +558,7 @@ declare class NavigationAgent3D {
|
|
|
425
558
|
set avoidanceEnabled(value: boolean);
|
|
426
559
|
on(event: NavigationAgentEvent, handler: NavigationAgentHandler): () => void;
|
|
427
560
|
setTargetPosition(position: Pick<Vector3, "x" | "y" | "z">): void;
|
|
428
|
-
getNextPathPosition(): Vector3;
|
|
561
|
+
getNextPathPosition(target?: Vector3): Vector3;
|
|
429
562
|
isNavigationFinished(): boolean;
|
|
430
563
|
isTargetReachable(position?: Pick<Vector3, "x" | "y" | "z">): boolean;
|
|
431
564
|
getFinalPosition(): Vector3;
|
|
@@ -487,6 +620,13 @@ interface INavigationContext {
|
|
|
487
620
|
crowd?: Crowd;
|
|
488
621
|
}
|
|
489
622
|
type NavigationPlugin = IGamePluginHooks<Record<string, unknown>, IPhysicsContext>;
|
|
623
|
+
/**
|
|
624
|
+
* Install navmesh pathfinding and crowd avoidance.
|
|
625
|
+
* @situation enemy walks around a wall
|
|
626
|
+
* @situation NPC patrols a level and chases a player
|
|
627
|
+
* @constraint requires rapier() earlier in the plugins array
|
|
628
|
+
* @example const game = defineGame({ plugins: [rapier(), recast()] });
|
|
629
|
+
*/
|
|
490
630
|
declare function recast(): NavigationPlugin;
|
|
491
631
|
|
|
492
632
|
interface IPhysicsOptions {
|
|
@@ -530,6 +670,8 @@ interface IPhysicsContext {
|
|
|
530
670
|
remove(body: PhysicsBody3D): void;
|
|
531
671
|
addArea(area: Area3D): void;
|
|
532
672
|
removeArea(area: Area3D): void;
|
|
673
|
+
addBuoyancy(buoyancy: Buoyancy3D): void;
|
|
674
|
+
removeBuoyancy(buoyancy: Buoyancy3D): void;
|
|
533
675
|
}
|
|
534
676
|
type PhysicsPlugin = IGamePluginHooks<Record<string, unknown>, IPhysicsContext>;
|
|
535
677
|
declare function rapier(options?: IPhysicsOptions): PhysicsPlugin;
|
|
@@ -574,4 +716,4 @@ declare class Area3D {
|
|
|
574
716
|
dispose(): void;
|
|
575
717
|
}
|
|
576
718
|
|
|
577
|
-
export { type
|
|
719
|
+
export { type ICharacterBody3DOptions as $, Area3D as A, Buoyancy3D as B, CharacterBody3D as C, type IPhysicsShapeDescriptor as D, type IPhysicsShapeQuery as E, type IPhysicsSimulation as F, type IPointHit as G, type IRayHit as H, type IPhysicsContext as I, type IRigidBody3DOptions as J, type IShapeHit as K, PHYSICS_TRANSFORM_STRIDE as L, MAX_PHYSICS_QUERY_RESULTS as M, type PhysicsBody3D as N, PhysicsDirectSpaceState3D as O, PHYSICS_COLLISION_EVENT_STRIDE as P, type PhysicsJointKind as Q, RigidBody3D as R, type PhysicsQueryVector3 as S, type PhysicsShapeKind as T, type RigidBodyType as U, rapier as V, type AreaEvent as W, type AreaHandler as X, type CollisionShapeKind as Y, type IArea3DOptions as Z, type IAreaContact as _, type IPhysicsWorldHandle as a, type IPhysicsOptions as a0, type PhysicsPlugin as a1, type INavigationAgent3DOptions as a2, type INavigationContext as a3, type INavigationObstacle3DOptions as a4, type INavigationRegion3DOptions as a5, NavigationAgent3D as a6, type NavigationAgentEvent as a7, type NavigationAgentHandler as a8, NavigationObstacle3D as a9, type NavigationPlugin as aa, NavigationRegion3D as ab, recast as ac, type IPhysicsBodyHandle as b, type IPhysicsVector3 as c, type IPhysicsRotation as d, type IPhysicsJointLimit as e, type BuoyancyPointPosition as f, CollisionShape3D as g, type IBuoyancy3DOptions as h, type IBuoyancyHullPoint as i, type IBuoyancySurface as j, type IBuoyancySurfaceSample as k, type ICollisionShapeHandle as l, type IIntersectPointOptions as m, type IIntersectRayOptions as n, type IIntersectShapeOptions as o, type IPhysicsBodyCreateOptions as p, type IPhysicsCharacterOptions as q, type IPhysicsColliderHandle as r, type IPhysicsHandle as s, type IPhysicsInputSnapshot as t, type IPhysicsJointCreateOptions as u, type IPhysicsPointQuery as v, type IPhysicsQueryHit as w, type IPhysicsRayHit as x, type IPhysicsRayQuery as y, type IPhysicsRuntimeSimulation as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import '
|
|
1
|
+
import { I as IPhysicsContext, a as IPhysicsWorldHandle, b as IPhysicsBodyHandle, c as IPhysicsVector3, d as IPhysicsRotation, e as IPhysicsJointLimit, R as RigidBody3D } from './Area3D-BQDiAwQb.js';
|
|
2
|
+
export { A as Area3D, B as Buoyancy3D, f as BuoyancyPointPosition, C as CharacterBody3D, g as CollisionShape3D, h as IBuoyancy3DOptions, i as IBuoyancyHullPoint, j as IBuoyancySurface, k as IBuoyancySurfaceSample, l as ICollisionShapeHandle, m as IIntersectPointOptions, n as IIntersectRayOptions, o as IIntersectShapeOptions, p as IPhysicsBodyCreateOptions, q as IPhysicsCharacterOptions, r as IPhysicsColliderHandle, s as IPhysicsHandle, t as IPhysicsInputSnapshot, u as IPhysicsJointCreateOptions, v as IPhysicsPointQuery, w as IPhysicsQueryHit, x as IPhysicsRayHit, y as IPhysicsRayQuery, z as IPhysicsRuntimeSimulation, D as IPhysicsShapeDescriptor, E as IPhysicsShapeQuery, F as IPhysicsSimulation, G as IPointHit, H as IRayHit, J as IRigidBody3DOptions, K as IShapeHit, M as MAX_PHYSICS_QUERY_RESULTS, P as PHYSICS_COLLISION_EVENT_STRIDE, L as PHYSICS_TRANSFORM_STRIDE, N as PhysicsBody3D, O as PhysicsDirectSpaceState3D, Q as PhysicsJointKind, S as PhysicsQueryVector3, T as PhysicsShapeKind, U as RigidBodyType, V as rapier } from './Area3D-BQDiAwQb.js';
|
|
3
|
+
import { Object3D } from 'three';
|
|
4
|
+
import { ISoftBodyCollision } from '@threenative/core';
|
|
4
5
|
import 'recast-navigation';
|
|
5
6
|
|
|
7
|
+
/** A body handle or a shared physics node exposing one. */
|
|
8
|
+
type PhysicsJointBody = IPhysicsBodyHandle | {
|
|
9
|
+
readonly body: IPhysicsBodyHandle;
|
|
10
|
+
};
|
|
11
|
+
interface IJoint3DOptions {
|
|
12
|
+
readonly physics?: IPhysicsContext;
|
|
13
|
+
/** @deprecated Prefer `physics`; a raw backend world is backend-specific. */
|
|
14
|
+
readonly world?: IPhysicsWorldHandle | unknown;
|
|
15
|
+
readonly bodyA: PhysicsJointBody;
|
|
16
|
+
readonly bodyB: PhysicsJointBody;
|
|
17
|
+
/** Local-space anchor on body A. Defaults to the body origin. */
|
|
18
|
+
readonly anchorA?: IPhysicsVector3;
|
|
19
|
+
/** Local-space anchor on body B. Defaults to the body origin. */
|
|
20
|
+
readonly anchorB?: IPhysicsVector3;
|
|
21
|
+
}
|
|
22
|
+
interface IPinJoint3DOptions extends IJoint3DOptions {
|
|
23
|
+
}
|
|
24
|
+
interface IHingeJoint3DOptions extends IJoint3DOptions {
|
|
25
|
+
/** Local-space axis on both bodies. Defaults to the local X axis. */
|
|
26
|
+
readonly axis?: IPhysicsVector3;
|
|
27
|
+
/** Optional lower and upper angular limits, in radians. */
|
|
28
|
+
readonly limit?: IPhysicsJointLimit;
|
|
29
|
+
}
|
|
30
|
+
interface IFixedJoint3DOptions extends IJoint3DOptions {
|
|
31
|
+
/** Optional local reference frames. Identity frames preserve equal initial orientations. */
|
|
32
|
+
readonly frameA?: IPhysicsRotation;
|
|
33
|
+
readonly frameB?: IPhysicsRotation;
|
|
34
|
+
}
|
|
35
|
+
declare class Joint3D {
|
|
36
|
+
#private;
|
|
37
|
+
readonly id: number;
|
|
38
|
+
private constructor();
|
|
39
|
+
static pin(options: IPinJoint3DOptions): Joint3D;
|
|
40
|
+
static hinge(options: IHingeJoint3DOptions): Joint3D;
|
|
41
|
+
static fixed(options: IFixedJoint3DOptions): Joint3D;
|
|
42
|
+
dispose(): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type StaticColliderPredicate = (object: Object3D) => boolean;
|
|
46
|
+
interface IStaticColliderContext {
|
|
47
|
+
readonly physics: IPhysicsContext;
|
|
48
|
+
}
|
|
49
|
+
interface IBuildStaticCollidersOptions {
|
|
50
|
+
/** Game-owned filter for decorative or otherwise non-colliding meshes. */
|
|
51
|
+
readonly predicate?: StaticColliderPredicate;
|
|
52
|
+
/** Alias for predicate when the call site wants the intent to read explicitly. */
|
|
53
|
+
readonly shouldCollide?: StaticColliderPredicate;
|
|
54
|
+
/** Meshes whose lowest point is at or above this height are outside the reachable world. */
|
|
55
|
+
readonly reachableCeiling?: number;
|
|
56
|
+
/** Collision layer occupied by the generated fixed bodies. */
|
|
57
|
+
readonly collisionLayer?: number;
|
|
58
|
+
/** Collision mask scanned by the generated fixed bodies. */
|
|
59
|
+
readonly collisionMask?: number;
|
|
60
|
+
}
|
|
61
|
+
type StaticColliderFilter = StaticColliderPredicate | IBuildStaticCollidersOptions;
|
|
62
|
+
/**
|
|
63
|
+
* Turn selected meshes under an authored scene root into fixed trimesh bodies.
|
|
64
|
+
*
|
|
65
|
+
* The root and predicate belong to the game; this helper owns the reusable walk, reachability
|
|
66
|
+
* cull, exact pierced-mesh shape and world-space instance carrier. It returns every generated
|
|
67
|
+
* body so the game can dispose or inspect the cold-path registrations, and throws when the filter
|
|
68
|
+
* produces no colliders rather than letting a level silently become non-solid.
|
|
69
|
+
*/
|
|
70
|
+
declare function buildStaticColliders(context: IStaticColliderContext, root: Object3D, filter?: StaticColliderFilter): readonly RigidBody3D[];
|
|
71
|
+
|
|
72
|
+
/** Adapt existing physics bodies into `SoftBody3D` collision input without a second shape API. */
|
|
73
|
+
declare function softBodyCollision(...bodies: readonly RigidBody3D[]): ISoftBodyCollision;
|
|
74
|
+
|
|
6
75
|
/** Rapier packs membership in the high 16 bits and the filter in the low 16. */
|
|
7
76
|
declare function interactionGroups(layer: number, mask: number): number;
|
|
8
77
|
|
|
9
|
-
export { interactionGroups };
|
|
78
|
+
export { type IBuildStaticCollidersOptions, type IFixedJoint3DOptions, type IHingeJoint3DOptions, type IJoint3DOptions, IPhysicsBodyHandle, IPhysicsContext, IPhysicsJointLimit, IPhysicsRotation, IPhysicsVector3, IPhysicsWorldHandle, type IPinJoint3DOptions, type IStaticColliderContext, Joint3D, type PhysicsJointBody, RigidBody3D, type StaticColliderPredicate, buildStaticColliders, interactionGroups, softBodyCollision };
|