@threenative/physics 0.1.0 → 0.2.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/dist/Area3D-CvwDbfU6.d.ts +577 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +614 -72
- package/dist/native/index.d.ts +1 -1
- package/dist/native/index.js +533 -49
- package/dist/navigation/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/Area3D-B8LJ2C4S.d.ts +0 -403
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import { Mesh, Object3D, Vector3 } from 'three';
|
|
2
|
+
import { IGamePluginHooks } from '@threenative/core';
|
|
3
|
+
import { CrowdAgent, NavMesh, NavMeshQuery, Crowd } from 'recast-navigation';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Portable handle for a backend-owned physics object.
|
|
7
|
+
*
|
|
8
|
+
* `raw` is deliberately backend-specific: it is a Rapier object on web and an opaque
|
|
9
|
+
* native handle on device. Code that reads it is not portable across build targets.
|
|
10
|
+
*/
|
|
11
|
+
interface IPhysicsHandle {
|
|
12
|
+
readonly raw: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface IPhysicsBodyHandle extends IPhysicsHandle {
|
|
15
|
+
readonly id: number;
|
|
16
|
+
readonly entity?: string;
|
|
17
|
+
}
|
|
18
|
+
interface IPhysicsColliderHandle extends IPhysicsHandle {
|
|
19
|
+
readonly id: number;
|
|
20
|
+
}
|
|
21
|
+
interface IPhysicsWorldHandle extends IPhysicsHandle {
|
|
22
|
+
/** The selected backend, kept beside `raw` so shared nodes do not inspect it. */
|
|
23
|
+
readonly simulation?: unknown;
|
|
24
|
+
}
|
|
25
|
+
declare function physicsHandle(raw: unknown): IPhysicsHandle;
|
|
26
|
+
declare function physicsWorldHandle(raw: unknown, simulation: unknown): IPhysicsWorldHandle;
|
|
27
|
+
|
|
28
|
+
/** One record is logical body id, xyz position, and xyzw rotation. */
|
|
29
|
+
declare const PHYSICS_TRANSFORM_STRIDE = 8;
|
|
30
|
+
declare const PHYSICS_COLLISION_EVENT_STRIDE = 4;
|
|
31
|
+
/** Caps native query buffers while remaining exactly representable by the native ABI. */
|
|
32
|
+
declare const MAX_PHYSICS_QUERY_RESULTS = 1024;
|
|
33
|
+
type PhysicsShapeKind = "box" | "sphere" | "capsule" | "trimesh" | "convexHull" | "heightfield";
|
|
34
|
+
/** Portable shape data. Backend-specific objects are created only by a simulation adapter. */
|
|
35
|
+
interface IPhysicsShapeDescriptor {
|
|
36
|
+
readonly kind: PhysicsShapeKind;
|
|
37
|
+
readonly x: number;
|
|
38
|
+
readonly y: number;
|
|
39
|
+
readonly z: number;
|
|
40
|
+
readonly vertices?: Float32Array;
|
|
41
|
+
readonly indices?: Uint32Array;
|
|
42
|
+
readonly rows?: number;
|
|
43
|
+
readonly columns?: number;
|
|
44
|
+
readonly heights?: Float32Array;
|
|
45
|
+
readonly scale?: {
|
|
46
|
+
readonly x: number;
|
|
47
|
+
readonly y: number;
|
|
48
|
+
readonly z: number;
|
|
49
|
+
};
|
|
50
|
+
readonly shape?: unknown;
|
|
51
|
+
collisionLayer: number;
|
|
52
|
+
collisionMask: number;
|
|
53
|
+
sensor: boolean;
|
|
54
|
+
}
|
|
55
|
+
type PhysicsBodyType = "character" | "dynamic" | "fixed" | "kinematic";
|
|
56
|
+
interface IPhysicsBodyCreateOptions {
|
|
57
|
+
readonly type: PhysicsBodyType;
|
|
58
|
+
readonly shape: IPhysicsShapeDescriptor;
|
|
59
|
+
readonly entity?: string;
|
|
60
|
+
readonly position: {
|
|
61
|
+
readonly x: number;
|
|
62
|
+
readonly y: number;
|
|
63
|
+
readonly z: number;
|
|
64
|
+
};
|
|
65
|
+
readonly rotation: {
|
|
66
|
+
readonly x: number;
|
|
67
|
+
readonly y: number;
|
|
68
|
+
readonly z: number;
|
|
69
|
+
readonly w: number;
|
|
70
|
+
};
|
|
71
|
+
readonly mass: number;
|
|
72
|
+
/** Must match `shape.sensor`; conflicting values are rejected during body creation. */
|
|
73
|
+
readonly sensor: boolean;
|
|
74
|
+
}
|
|
75
|
+
interface IPhysicsVector3 {
|
|
76
|
+
readonly x: number;
|
|
77
|
+
readonly y: number;
|
|
78
|
+
readonly z: number;
|
|
79
|
+
}
|
|
80
|
+
interface IPhysicsRotation {
|
|
81
|
+
readonly x: number;
|
|
82
|
+
readonly y: number;
|
|
83
|
+
readonly z: number;
|
|
84
|
+
readonly w: number;
|
|
85
|
+
}
|
|
86
|
+
interface IPhysicsRayQuery {
|
|
87
|
+
readonly from: IPhysicsVector3;
|
|
88
|
+
readonly to: IPhysicsVector3;
|
|
89
|
+
readonly collisionMask: number;
|
|
90
|
+
}
|
|
91
|
+
interface IPhysicsShapeQuery {
|
|
92
|
+
readonly shape: IPhysicsShapeDescriptor;
|
|
93
|
+
readonly position: IPhysicsVector3;
|
|
94
|
+
readonly rotation: IPhysicsRotation;
|
|
95
|
+
readonly collisionMask: number;
|
|
96
|
+
readonly maxResults: number;
|
|
97
|
+
}
|
|
98
|
+
interface IPhysicsPointQuery {
|
|
99
|
+
readonly position: IPhysicsVector3;
|
|
100
|
+
readonly collisionMask: number;
|
|
101
|
+
readonly maxResults: number;
|
|
102
|
+
}
|
|
103
|
+
interface IPhysicsQueryHit {
|
|
104
|
+
readonly body: IPhysicsBodyHandle;
|
|
105
|
+
readonly entity?: string;
|
|
106
|
+
readonly position: IPhysicsVector3;
|
|
107
|
+
}
|
|
108
|
+
interface IPhysicsRayHit extends IPhysicsQueryHit {
|
|
109
|
+
readonly normal: IPhysicsVector3;
|
|
110
|
+
readonly distance: number;
|
|
111
|
+
}
|
|
112
|
+
interface IPhysicsBodyRegistration {
|
|
113
|
+
readonly body: IPhysicsBodyHandle;
|
|
114
|
+
readonly collider: IPhysicsColliderHandle;
|
|
115
|
+
readonly controller?: IPhysicsHandle;
|
|
116
|
+
/** The backend shape object to expose through `CollisionShape3D.raw`. */
|
|
117
|
+
readonly rawShape: unknown;
|
|
118
|
+
}
|
|
119
|
+
interface IPhysicsCharacterOptions {
|
|
120
|
+
readonly offset: number;
|
|
121
|
+
readonly maxSlopeClimbAngle: number;
|
|
122
|
+
readonly autostep?: {
|
|
123
|
+
readonly maxHeight: number;
|
|
124
|
+
readonly minWidth: number;
|
|
125
|
+
readonly includeDynamicBodies: boolean;
|
|
126
|
+
};
|
|
127
|
+
readonly snapToGround?: number;
|
|
128
|
+
readonly oneWayLayers: number;
|
|
129
|
+
/** Let the character shove dynamic bodies it collides with, instead of sliding past them. */
|
|
130
|
+
readonly pushesDynamicBodies?: boolean;
|
|
131
|
+
}
|
|
132
|
+
interface IPhysicsCharacterState {
|
|
133
|
+
readonly grounded: boolean;
|
|
134
|
+
readonly groundCollider?: number;
|
|
135
|
+
}
|
|
136
|
+
interface IPhysicsInputSnapshot {
|
|
137
|
+
/** One eight-float record per kinematic body. The buffer is caller-owned and reusable. */
|
|
138
|
+
readonly kinematicTransforms: Readonly<Float32Array>;
|
|
139
|
+
readonly kinematicCount: number;
|
|
140
|
+
}
|
|
141
|
+
/** The backend seam used by all shared physics nodes. */
|
|
142
|
+
interface IPhysicsSimulation {
|
|
143
|
+
createBody(options: IPhysicsBodyCreateOptions): IPhysicsBodyRegistration;
|
|
144
|
+
configureCharacter(id: number, options: IPhysicsCharacterOptions): void;
|
|
145
|
+
removeBody(id: number): void;
|
|
146
|
+
/** Cold-path repositioning for teleport/setup. Per-frame kinematics use `step()` input. */
|
|
147
|
+
setBodyTransform(id: number, position: {
|
|
148
|
+
readonly x: number;
|
|
149
|
+
readonly y: number;
|
|
150
|
+
readonly z: number;
|
|
151
|
+
}): void;
|
|
152
|
+
/**
|
|
153
|
+
* Dynamic-body actuation. Without these a game cannot move a dynamic body at all: a transform
|
|
154
|
+
* write is overwritten by the next step, so `setBodyTransform` is genuinely cold-path only.
|
|
155
|
+
*/
|
|
156
|
+
applyBodyImpulse(id: number, impulse: IPhysicsVector3): void;
|
|
157
|
+
applyBodyForce(id: number, force: IPhysicsVector3): void;
|
|
158
|
+
setBodyLinearVelocity(id: number, velocity: IPhysicsVector3): void;
|
|
159
|
+
readBodyLinearVelocity(id: number): IPhysicsVector3;
|
|
160
|
+
step(deltaTime: number, inputSnapshot?: IPhysicsInputSnapshot): void;
|
|
161
|
+
readVisibleTransforms(renderBuffer: Float32Array): number;
|
|
162
|
+
readBodySleepStates(buffer: Float32Array): number;
|
|
163
|
+
intersectRay(query: IPhysicsRayQuery): IPhysicsRayHit | undefined;
|
|
164
|
+
intersectShape(query: IPhysicsShapeQuery): readonly IPhysicsQueryHit[];
|
|
165
|
+
intersectPoint(query: IPhysicsPointQuery): readonly IPhysicsQueryHit[];
|
|
166
|
+
readBodyTransform?(id: number): {
|
|
167
|
+
readonly position: {
|
|
168
|
+
readonly x: number;
|
|
169
|
+
readonly y: number;
|
|
170
|
+
readonly z: number;
|
|
171
|
+
};
|
|
172
|
+
readonly rotation: {
|
|
173
|
+
readonly x: number;
|
|
174
|
+
readonly y: number;
|
|
175
|
+
readonly z: number;
|
|
176
|
+
readonly w: number;
|
|
177
|
+
};
|
|
178
|
+
} | undefined;
|
|
179
|
+
/** Reflects the most recently completed step, independent of visible-transform reads. */
|
|
180
|
+
readCharacterState?(id: number): IPhysicsCharacterState | undefined;
|
|
181
|
+
/** Reflects the most recently completed step, independent of visible-transform reads. */
|
|
182
|
+
areaIntersections?(id: number): ReadonlySet<number>;
|
|
183
|
+
drainCollisionEvents(buffer: Uint32Array): number;
|
|
184
|
+
dispose(): void;
|
|
185
|
+
}
|
|
186
|
+
/** Runtime metadata needed to expose backend-specific escape hatches without leaking them. */
|
|
187
|
+
interface IPhysicsRuntimeSimulation extends IPhysicsSimulation {
|
|
188
|
+
readonly version: string;
|
|
189
|
+
readonly rawWorld: unknown;
|
|
190
|
+
readonly rawEventQueue: unknown;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type CollisionShapeKind = PhysicsShapeKind;
|
|
194
|
+
/** A backend-specific escape hatch: Rapier on web, opaque on native. */
|
|
195
|
+
interface ICollisionShapeHandle {
|
|
196
|
+
readonly raw: unknown;
|
|
197
|
+
}
|
|
198
|
+
declare class CollisionShape3D {
|
|
199
|
+
#private;
|
|
200
|
+
private constructor();
|
|
201
|
+
/** Backend-neutral data consumed by the selected IPhysicsSimulation adapter. */
|
|
202
|
+
get descriptor(): IPhysicsShapeDescriptor;
|
|
203
|
+
/** Backend-specific escape hatch: Rapier's descriptor on web, or an opaque native handle. */
|
|
204
|
+
get raw(): unknown;
|
|
205
|
+
/** Internal seam: the backend binds its own descriptor when the body is created. */
|
|
206
|
+
bindRaw(raw: unknown): void;
|
|
207
|
+
static box(width: number, height: number, depth: number): CollisionShape3D;
|
|
208
|
+
static sphere(radius: number): CollisionShape3D;
|
|
209
|
+
/**
|
|
210
|
+
* A capsule of total height `2 * (halfHeight + radius)`, **centred on the body's origin** like
|
|
211
|
+
* every other shape here — `halfHeight` is the straight section's half-length, measured from
|
|
212
|
+
* that centre, and the hemispherical cap adds `radius` beyond it.
|
|
213
|
+
*
|
|
214
|
+
* So the body origin sits at the character's waist, not at its feet. A visual rig modelled
|
|
215
|
+
* standing on its own origin, parented straight onto the body object, therefore floats exactly
|
|
216
|
+
* `halfHeight + radius` above every surface it lands on. Offset the rig down by that amount:
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* const shape = CollisionShape3D.capsule(0.26, 0.28);
|
|
220
|
+
* rig.position.y = -(0.26 + 0.28); // feet reach the capsule's bottom cap
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
static capsule(halfHeight: number, radius: number): CollisionShape3D;
|
|
224
|
+
static heightfield(rows: number, columns: number, heights: Float32Array, scale: {
|
|
225
|
+
x: number;
|
|
226
|
+
y: number;
|
|
227
|
+
z: number;
|
|
228
|
+
}): CollisionShape3D;
|
|
229
|
+
static fromMesh(mesh: Mesh, kind?: CollisionShapeKind): CollisionShape3D;
|
|
230
|
+
setCollisionGroups(groups: number): this;
|
|
231
|
+
setSensor(sensor: boolean): this;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
interface ICharacterBody3DOptions {
|
|
235
|
+
readonly object: Object3D;
|
|
236
|
+
readonly entity?: string;
|
|
237
|
+
readonly physics?: IPhysicsContext;
|
|
238
|
+
/** @deprecated Prefer `physics`; a raw web world is backend-specific. */
|
|
239
|
+
readonly world?: IPhysicsWorldHandle | unknown;
|
|
240
|
+
readonly shape: CollisionShape3D;
|
|
241
|
+
readonly offset?: number;
|
|
242
|
+
readonly maxSlopeClimbAngle?: number;
|
|
243
|
+
readonly autostep?: {
|
|
244
|
+
readonly maxHeight: number;
|
|
245
|
+
readonly minWidth: number;
|
|
246
|
+
readonly includeDynamicBodies?: boolean;
|
|
247
|
+
};
|
|
248
|
+
readonly snapToGround?: number;
|
|
249
|
+
/**
|
|
250
|
+
* Vertical acceleration in m/s², added to `velocity.y` every `moveAndSlide(dt)`. It is a
|
|
251
|
+
* signed component of a velocity, not a strength: **down is negative**. `-9.81` is earth,
|
|
252
|
+
* `-24` a snappy platformer, `0` a planar top-down game that must not fall, and a positive
|
|
253
|
+
* value accelerates the character upward.
|
|
254
|
+
*
|
|
255
|
+
* Passing the magnitude — `gravity: 24` — makes the character fly, which on screen is
|
|
256
|
+
* indistinguishable from a broken collider. Default `-9.81`.
|
|
257
|
+
*/
|
|
258
|
+
readonly gravity?: number;
|
|
259
|
+
/** Terminal downward speed in m/s, as a positive magnitude. Default 50. */
|
|
260
|
+
readonly maxFallSpeed?: number;
|
|
261
|
+
/** Godot's collision_layer — which layers this body occupies. Default 1. */
|
|
262
|
+
readonly collisionLayer?: number;
|
|
263
|
+
/** Godot's collision_mask — which layers this body scans. Default 0xffff. */
|
|
264
|
+
readonly collisionMask?: number;
|
|
265
|
+
/** Collider layer bits to ignore while moving upward. */
|
|
266
|
+
readonly oneWayLayers?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Shove dynamic bodies the character walks into, instead of sliding past them. Default false,
|
|
269
|
+
* matching Rapier. Without it a character collides with a crate and the crate never moves,
|
|
270
|
+
* which reads as a physics bug rather than a default.
|
|
271
|
+
*/
|
|
272
|
+
readonly pushesDynamicBodies?: boolean;
|
|
273
|
+
}
|
|
274
|
+
declare class CharacterBody3D {
|
|
275
|
+
#private;
|
|
276
|
+
readonly body: IPhysicsBodyHandle;
|
|
277
|
+
readonly collider: IPhysicsColliderHandle;
|
|
278
|
+
readonly controller: IPhysicsHandle;
|
|
279
|
+
readonly object: Object3D;
|
|
280
|
+
readonly velocity: Vector3;
|
|
281
|
+
/** Signed vertical acceleration; see `ICharacterBody3DOptions.gravity`. Down is negative. */
|
|
282
|
+
gravity: number;
|
|
283
|
+
maxFallSpeed: number;
|
|
284
|
+
readonly oneWayLayers: number;
|
|
285
|
+
grounded: boolean;
|
|
286
|
+
constructor(options: ICharacterBody3DOptions);
|
|
287
|
+
move(desiredTranslation: Pick<Vector3, "x" | "y" | "z">): void;
|
|
288
|
+
moveAndSlide(dt: number): void;
|
|
289
|
+
/** Called by the shared plugin before a bulk step. */
|
|
290
|
+
writeKinematic(buffer: Float32Array, offset: number): void;
|
|
291
|
+
syncToPhysics(): void;
|
|
292
|
+
step(): void;
|
|
293
|
+
teleport(position: Pick<Vector3, "x" | "y" | "z">): void;
|
|
294
|
+
applyTransform(values: Readonly<Float32Array>, offset: number): void;
|
|
295
|
+
syncFromPhysics(): void;
|
|
296
|
+
dispose(): void;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
type PhysicsQueryVector3 = IPhysicsVector3;
|
|
300
|
+
interface IIntersectRayOptions {
|
|
301
|
+
readonly from: PhysicsQueryVector3;
|
|
302
|
+
readonly to: PhysicsQueryVector3;
|
|
303
|
+
readonly collisionMask?: number;
|
|
304
|
+
}
|
|
305
|
+
interface IIntersectShapeOptions {
|
|
306
|
+
readonly shape: CollisionShape3D;
|
|
307
|
+
readonly position: PhysicsQueryVector3;
|
|
308
|
+
readonly rotation?: {
|
|
309
|
+
readonly x: number;
|
|
310
|
+
readonly y: number;
|
|
311
|
+
readonly z: number;
|
|
312
|
+
readonly w: number;
|
|
313
|
+
};
|
|
314
|
+
readonly collisionMask?: number;
|
|
315
|
+
readonly maxResults?: number;
|
|
316
|
+
}
|
|
317
|
+
interface IIntersectPointOptions {
|
|
318
|
+
readonly position: PhysicsQueryVector3;
|
|
319
|
+
readonly collisionMask?: number;
|
|
320
|
+
readonly maxResults?: number;
|
|
321
|
+
}
|
|
322
|
+
interface IRayHit extends IPhysicsRayHit {
|
|
323
|
+
readonly body: IPhysicsBodyHandle;
|
|
324
|
+
}
|
|
325
|
+
type IShapeHit = IPhysicsQueryHit;
|
|
326
|
+
type IPointHit = IPhysicsQueryHit;
|
|
327
|
+
/** Godot-shaped point-in-time queries over the selected physics simulation. */
|
|
328
|
+
declare class PhysicsDirectSpaceState3D {
|
|
329
|
+
#private;
|
|
330
|
+
constructor(simulation: IPhysicsSimulation);
|
|
331
|
+
intersectRay(options: IIntersectRayOptions): IRayHit | undefined;
|
|
332
|
+
intersectShape(options: IIntersectShapeOptions): readonly IShapeHit[];
|
|
333
|
+
intersectPoint(options: IIntersectPointOptions): readonly IPointHit[];
|
|
334
|
+
}
|
|
335
|
+
|
|
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
|
+
type NavigationAgentEvent = "targetReached" | "navigationFinished" | "pathChanged";
|
|
402
|
+
type NavigationAgentHandler = () => void;
|
|
403
|
+
interface INavigationAgent3DOptions {
|
|
404
|
+
readonly navigation: INavigationContext;
|
|
405
|
+
readonly object: Object3D;
|
|
406
|
+
readonly radius?: number;
|
|
407
|
+
readonly height?: number;
|
|
408
|
+
readonly maxSpeed?: number;
|
|
409
|
+
readonly pathDesiredDistance?: number;
|
|
410
|
+
readonly targetDesiredDistance?: number;
|
|
411
|
+
readonly avoidanceEnabled?: boolean;
|
|
412
|
+
}
|
|
413
|
+
declare class NavigationAgent3D {
|
|
414
|
+
#private;
|
|
415
|
+
readonly navigation: INavigationContext;
|
|
416
|
+
readonly object: Object3D;
|
|
417
|
+
readonly radius: number;
|
|
418
|
+
readonly height: number;
|
|
419
|
+
readonly maxSpeed: number;
|
|
420
|
+
readonly pathDesiredDistance: number;
|
|
421
|
+
readonly targetDesiredDistance: number;
|
|
422
|
+
constructor(options: INavigationAgent3DOptions);
|
|
423
|
+
get crowdAgent(): CrowdAgent | undefined;
|
|
424
|
+
get avoidanceEnabled(): boolean;
|
|
425
|
+
set avoidanceEnabled(value: boolean);
|
|
426
|
+
on(event: NavigationAgentEvent, handler: NavigationAgentHandler): () => void;
|
|
427
|
+
setTargetPosition(position: Pick<Vector3, "x" | "y" | "z">): void;
|
|
428
|
+
getNextPathPosition(): Vector3;
|
|
429
|
+
isNavigationFinished(): boolean;
|
|
430
|
+
isTargetReachable(position?: Pick<Vector3, "x" | "y" | "z">): boolean;
|
|
431
|
+
getFinalPosition(): Vector3;
|
|
432
|
+
distanceToTarget(): number;
|
|
433
|
+
syncCrowd(): void;
|
|
434
|
+
advance(): void;
|
|
435
|
+
dispose(): void;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
interface INavigationObstacle3DOptions {
|
|
439
|
+
readonly navigation: INavigationContext;
|
|
440
|
+
readonly object: Object3D;
|
|
441
|
+
readonly radius?: number;
|
|
442
|
+
readonly height?: number;
|
|
443
|
+
readonly avoidanceEnabled?: boolean;
|
|
444
|
+
}
|
|
445
|
+
declare class NavigationObstacle3D {
|
|
446
|
+
#private;
|
|
447
|
+
readonly navigation: INavigationContext;
|
|
448
|
+
readonly object: Object3D;
|
|
449
|
+
readonly radius: number;
|
|
450
|
+
readonly height: number;
|
|
451
|
+
crowdAgent: CrowdAgent | undefined;
|
|
452
|
+
constructor(options: INavigationObstacle3DOptions);
|
|
453
|
+
get avoidanceEnabled(): boolean;
|
|
454
|
+
set avoidanceEnabled(value: boolean);
|
|
455
|
+
syncCrowd(): void;
|
|
456
|
+
dispose(): void;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
interface INavigationRegion3DOptions {
|
|
460
|
+
readonly navigation: INavigationContext;
|
|
461
|
+
readonly meshes: readonly Object3D[];
|
|
462
|
+
readonly cellSize?: number;
|
|
463
|
+
readonly cellHeight?: number;
|
|
464
|
+
readonly agentRadius?: number;
|
|
465
|
+
readonly agentHeight?: number;
|
|
466
|
+
readonly agentMaxClimb?: number;
|
|
467
|
+
readonly agentMaxSlope?: number;
|
|
468
|
+
}
|
|
469
|
+
declare class NavigationRegion3D {
|
|
470
|
+
#private;
|
|
471
|
+
readonly navigation: INavigationContext;
|
|
472
|
+
readonly meshes: readonly Object3D[];
|
|
473
|
+
navigationMesh: NavMesh;
|
|
474
|
+
constructor(options: INavigationRegion3DOptions);
|
|
475
|
+
get enabled(): boolean;
|
|
476
|
+
set enabled(value: boolean);
|
|
477
|
+
bakeNavigationMesh(): NavMesh;
|
|
478
|
+
dispose(): void;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
interface INavigationContext {
|
|
482
|
+
navMesh: NavMesh;
|
|
483
|
+
query: NavMeshQuery;
|
|
484
|
+
readonly regions: Set<NavigationRegion3D>;
|
|
485
|
+
readonly agents: Set<NavigationAgent3D>;
|
|
486
|
+
readonly obstacles: Set<NavigationObstacle3D>;
|
|
487
|
+
crowd?: Crowd;
|
|
488
|
+
}
|
|
489
|
+
type NavigationPlugin = IGamePluginHooks<Record<string, unknown>, IPhysicsContext>;
|
|
490
|
+
declare function recast(): NavigationPlugin;
|
|
491
|
+
|
|
492
|
+
interface IPhysicsOptions {
|
|
493
|
+
readonly gravity?: {
|
|
494
|
+
readonly x: number;
|
|
495
|
+
readonly y: number;
|
|
496
|
+
readonly z: number;
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Give each scene a pristine simulation, so restarting a scene reproduces its predecessor
|
|
500
|
+
* exactly. Default false.
|
|
501
|
+
*
|
|
502
|
+
* Disposing the bodies is not enough on its own: the solver, island manager and broad phase
|
|
503
|
+
* carry state from everything that has already happened, so an identical authored layout
|
|
504
|
+
* settles differently in a reused world. A sandbox build measured settle hashes `a2f87bad`
|
|
505
|
+
* versus `658eb6f8` at 240 versus 266 ticks, diverging during the initial drop before any
|
|
506
|
+
* input, and had no way to fix it from game code.
|
|
507
|
+
*
|
|
508
|
+
* Opt-in because it frees the backend world at scene exit. Anything still holding a
|
|
509
|
+
* `body.raw`, `collider.raw` or `world.raw` from the previous scene is reading freed memory
|
|
510
|
+
* afterwards. Those references are already documented as non-portable, and a scene that has
|
|
511
|
+
* exited has disposed its bodies, but the failure mode is a hard backend fault rather than a
|
|
512
|
+
* quiet `false` — so a game asks for this rather than inheriting it.
|
|
513
|
+
*/
|
|
514
|
+
readonly deterministicRestart?: boolean;
|
|
515
|
+
}
|
|
516
|
+
type PhysicsBody3D = RigidBody3D | CharacterBody3D;
|
|
517
|
+
interface IPhysicsContext {
|
|
518
|
+
readonly world: ReturnType<typeof physicsWorldHandle>;
|
|
519
|
+
readonly eventQueue: ReturnType<typeof physicsHandle>;
|
|
520
|
+
readonly simulation: IPhysicsSimulation;
|
|
521
|
+
readonly directSpaceState: PhysicsDirectSpaceState3D;
|
|
522
|
+
navigation?: INavigationContext;
|
|
523
|
+
add(body: PhysicsBody3D): void;
|
|
524
|
+
numBodies(): number;
|
|
525
|
+
kinematicMotion?(colliderHandle: number): {
|
|
526
|
+
readonly x: number;
|
|
527
|
+
readonly y: number;
|
|
528
|
+
readonly z: number;
|
|
529
|
+
} | undefined;
|
|
530
|
+
remove(body: PhysicsBody3D): void;
|
|
531
|
+
addArea(area: Area3D): void;
|
|
532
|
+
removeArea(area: Area3D): void;
|
|
533
|
+
}
|
|
534
|
+
type PhysicsPlugin = IGamePluginHooks<Record<string, unknown>, IPhysicsContext>;
|
|
535
|
+
declare function rapier(options?: IPhysicsOptions): PhysicsPlugin;
|
|
536
|
+
|
|
537
|
+
type AreaEvent = "bodyEntered" | "bodyExited";
|
|
538
|
+
type AreaHandler = (body: PhysicsBody3D) => void;
|
|
539
|
+
interface IAreaContact {
|
|
540
|
+
readonly area: Area3D;
|
|
541
|
+
readonly body: PhysicsBody3D;
|
|
542
|
+
readonly entity?: string;
|
|
543
|
+
readonly started: boolean;
|
|
544
|
+
}
|
|
545
|
+
interface IArea3DOptions {
|
|
546
|
+
readonly entity?: string;
|
|
547
|
+
readonly physics?: IPhysicsContext;
|
|
548
|
+
/** @deprecated Prefer `physics`; a raw web world is backend-specific. */
|
|
549
|
+
readonly world?: IPhysicsWorldHandle | unknown;
|
|
550
|
+
readonly shape: CollisionShape3D;
|
|
551
|
+
readonly position?: Pick<Vector3, "x" | "y" | "z">;
|
|
552
|
+
/** Godot's collision_layer — which layers this area occupies. Default 1. */
|
|
553
|
+
readonly collisionLayer?: number;
|
|
554
|
+
/** Godot's collision_mask — which layers this area scans. Default 0xffff. */
|
|
555
|
+
readonly collisionMask?: number;
|
|
556
|
+
}
|
|
557
|
+
declare class Area3D {
|
|
558
|
+
#private;
|
|
559
|
+
readonly entity: string | undefined;
|
|
560
|
+
readonly body: IPhysicsBodyHandle;
|
|
561
|
+
readonly collider: IPhysicsColliderHandle;
|
|
562
|
+
constructor(options: IArea3DOptions);
|
|
563
|
+
on(event: AreaEvent, handler: AreaHandler): () => void;
|
|
564
|
+
/** Mirrors Godot's Area3D.monitoring. When false the area reports no contacts. */
|
|
565
|
+
get monitoring(): boolean;
|
|
566
|
+
set monitoring(value: boolean);
|
|
567
|
+
setPosition(position: Pick<Vector3, "x" | "y" | "z">): void;
|
|
568
|
+
/** Called by the shared plugin before a bulk step. */
|
|
569
|
+
writeKinematic(buffer: Float32Array, offset: number): void;
|
|
570
|
+
applyTransform(values: Readonly<Float32Array>, offset: number): void;
|
|
571
|
+
handleCollision(body: PhysicsBody3D, started: boolean): void;
|
|
572
|
+
drainContacts(): IAreaContact[];
|
|
573
|
+
reconcileIntersections(current: ReadonlyMap<number, PhysicsBody3D>): void;
|
|
574
|
+
dispose(): void;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export { type NavigationAgentHandler as $, Area3D as A, type PhysicsBody3D as B, CharacterBody3D as C, PhysicsDirectSpaceState3D as D, type PhysicsQueryVector3 as E, type PhysicsShapeKind as F, rapier as G, type AreaEvent as H, type ICollisionShapeHandle as I, type AreaHandler as J, type CollisionShapeKind as K, type IArea3DOptions as L, MAX_PHYSICS_QUERY_RESULTS as M, type IAreaContact as N, type ICharacterBody3DOptions as O, PHYSICS_COLLISION_EVENT_STRIDE as P, type IPhysicsOptions as Q, RigidBody3D as R, type IRigidBody3DOptions as S, type PhysicsPlugin as T, type RigidBodyType as U, type INavigationAgent3DOptions as V, type INavigationContext as W, type INavigationObstacle3DOptions as X, type INavigationRegion3DOptions as Y, NavigationAgent3D as Z, type NavigationAgentEvent as _, CollisionShape3D as a, NavigationObstacle3D as a0, type NavigationPlugin as a1, NavigationRegion3D as a2, recast as a3, type IIntersectPointOptions as b, type IIntersectRayOptions as c, type IIntersectShapeOptions as d, type IPhysicsBodyCreateOptions as e, type IPhysicsBodyHandle as f, type IPhysicsCharacterOptions as g, type IPhysicsColliderHandle as h, type IPhysicsContext as i, type IPhysicsHandle as j, type IPhysicsInputSnapshot as k, type IPhysicsPointQuery as l, type IPhysicsQueryHit as m, type IPhysicsRayHit as n, type IPhysicsRayQuery as o, type IPhysicsRotation as p, type IPhysicsRuntimeSimulation as q, type IPhysicsShapeDescriptor as r, type IPhysicsShapeQuery as s, type IPhysicsSimulation as t, type IPhysicsVector3 as u, type IPhysicsWorldHandle as v, type IPointHit as w, type IRayHit as x, type IShapeHit as y, PHYSICS_TRANSFORM_STRIDE as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as Area3D, a as
|
|
1
|
+
export { A as Area3D, C as CharacterBody3D, a as CollisionShape3D, I as ICollisionShapeHandle, b as IIntersectPointOptions, c as IIntersectRayOptions, d as IIntersectShapeOptions, e as IPhysicsBodyCreateOptions, f as IPhysicsBodyHandle, g as IPhysicsCharacterOptions, h as IPhysicsColliderHandle, i as IPhysicsContext, j as IPhysicsHandle, k as IPhysicsInputSnapshot, l as IPhysicsPointQuery, m as IPhysicsQueryHit, n as IPhysicsRayHit, o as IPhysicsRayQuery, p as IPhysicsRotation, q as IPhysicsRuntimeSimulation, r as IPhysicsShapeDescriptor, s as IPhysicsShapeQuery, t as IPhysicsSimulation, u as IPhysicsVector3, v as IPhysicsWorldHandle, w as IPointHit, x as IRayHit, y as IShapeHit, M as MAX_PHYSICS_QUERY_RESULTS, P as PHYSICS_COLLISION_EVENT_STRIDE, z as PHYSICS_TRANSFORM_STRIDE, B as PhysicsBody3D, D as PhysicsDirectSpaceState3D, E as PhysicsQueryVector3, F as PhysicsShapeKind, R as RigidBody3D, G as rapier } from './Area3D-CvwDbfU6.js';
|
|
2
2
|
import 'three';
|
|
3
3
|
import '@threenative/core';
|
|
4
4
|
import 'recast-navigation';
|