@frsource/babylon-box3d 1.0.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.
@@ -0,0 +1,782 @@
1
+ /**
2
+ * box3d-wasm ships no bundled TypeScript types (see
3
+ * https://github.com/monteslu/box3d-wasm). This is a hand-written surface
4
+ * covering exactly the embind API consumed by {@link Box3DPlugin}, derived
5
+ * from the wrapper's glue code (csrc/glue.cpp) and README.
6
+ */
7
+ declare module 'box3d-wasm' {
8
+ export interface Vec3 {
9
+ x: number;
10
+ y: number;
11
+ z: number;
12
+ }
13
+
14
+ export interface Quat {
15
+ x: number;
16
+ y: number;
17
+ z: number;
18
+ w: number;
19
+ }
20
+
21
+ export interface Box3DTransform {
22
+ position?: Vec3;
23
+ rotation?: Quat;
24
+ }
25
+
26
+ export interface Filter {
27
+ categoryBits?: number;
28
+ maskBits?: number;
29
+ groupIndex?: number;
30
+ }
31
+
32
+ export interface ShapeMaterialOptions {
33
+ density?: number;
34
+ friction?: number;
35
+ restitution?: number;
36
+ rollingResistance?: number;
37
+ tangentVelocity?: Vec3;
38
+ userMaterialId?: number;
39
+ isSensor?: boolean;
40
+ enableSensorEvents?: boolean;
41
+ enableContactEvents?: boolean;
42
+ enableHitEvents?: boolean;
43
+ invokeContactCreation?: boolean;
44
+ updateBodyMass?: boolean;
45
+ filter?: Filter;
46
+ userData?: number;
47
+ }
48
+
49
+ export interface BoxShapeOptions extends ShapeMaterialOptions {
50
+ halfExtents?: Vec3;
51
+ hx?: number;
52
+ hy?: number;
53
+ hz?: number;
54
+ offset?: Vec3;
55
+ rotation?: Quat;
56
+ }
57
+
58
+ export interface SphereShapeOptions extends ShapeMaterialOptions {
59
+ center?: Vec3;
60
+ radius?: number;
61
+ }
62
+
63
+ export interface CapsuleShapeOptions extends ShapeMaterialOptions {
64
+ radius?: number;
65
+ height?: number;
66
+ center1?: Vec3;
67
+ center2?: Vec3;
68
+ }
69
+
70
+ export interface HullShapeOptions extends ShapeMaterialOptions {
71
+ points: Vec3[];
72
+ maxVertices?: number;
73
+ }
74
+
75
+ export interface AABB {
76
+ lowerBound: Vec3;
77
+ upperBound: Vec3;
78
+ }
79
+
80
+ export interface ShapeRayCastResult {
81
+ hit: boolean;
82
+ point?: Vec3;
83
+ normal?: Vec3;
84
+ fraction?: number;
85
+ }
86
+
87
+ export type Box3DShapeType =
88
+ | 'sphere'
89
+ | 'capsule'
90
+ | 'hull'
91
+ | 'mesh'
92
+ | 'heightField'
93
+ | 'compound'
94
+ | 'unknown';
95
+
96
+ export class Shape {
97
+ isValid(): boolean;
98
+ destroy(updateBodyMass: boolean): void;
99
+ getType(): Box3DShapeType;
100
+ getUserData(): number;
101
+ setUserData(tag: number): void;
102
+ getFriction(): number;
103
+ setFriction(friction: number): void;
104
+ getRestitution(): number;
105
+ setRestitution(restitution: number): void;
106
+ getDensity(): number;
107
+ setDensity(density: number, updateBodyMass: boolean): void;
108
+ isSensor(): boolean;
109
+ enableSensorEvents(flag: boolean): void;
110
+ enableContactEvents(flag: boolean): void;
111
+ enableHitEvents(flag: boolean): void;
112
+ getFilter(): Required<Filter>;
113
+ setFilter(filter: Filter): void;
114
+ getAABB(): AABB;
115
+ rayCast(origin: Vec3, translation: Vec3): ShapeRayCastResult;
116
+ }
117
+
118
+ export interface JointBaseOptions {
119
+ localFrameA?: Box3DTransform;
120
+ localFrameB?: Box3DTransform;
121
+ anchorA?: Vec3;
122
+ anchorB?: Vec3;
123
+ collideConnected?: boolean;
124
+ forceThreshold?: number;
125
+ torqueThreshold?: number;
126
+ }
127
+
128
+ export class Joint {
129
+ isValid(): boolean;
130
+ destroy(wakeAttached: boolean): void;
131
+ getType(): string;
132
+ wakeBodies(): void;
133
+ getCollideConnected(): boolean;
134
+ setCollideConnected(flag: boolean): void;
135
+ getLocalFrameA(): Required<Box3DTransform>;
136
+ getLocalFrameB(): Required<Box3DTransform>;
137
+ getConstraintForce(): Vec3;
138
+ getConstraintTorque(): Vec3;
139
+ }
140
+
141
+ export interface DistanceJointOptions extends JointBaseOptions {
142
+ length?: number;
143
+ enableSpring?: boolean;
144
+ hertz?: number;
145
+ dampingRatio?: number;
146
+ lowerSpringForce?: number;
147
+ upperSpringForce?: number;
148
+ enableLimit?: boolean;
149
+ minLength?: number;
150
+ maxLength?: number;
151
+ enableMotor?: boolean;
152
+ maxMotorForce?: number;
153
+ motorSpeed?: number;
154
+ }
155
+
156
+ export class DistanceJoint extends Joint {
157
+ setLength(length: number): void;
158
+ getLength(): number;
159
+ getCurrentLength(): number;
160
+ enableSpring(flag: boolean): void;
161
+ setSpringHertz(hertz: number): void;
162
+ setSpringDampingRatio(ratio: number): void;
163
+ enableLimit(flag: boolean): void;
164
+ setLengthRange(min: number, max: number): void;
165
+ enableMotor(flag: boolean): void;
166
+ setMotorSpeed(speed: number): void;
167
+ setMaxMotorForce(force: number): void;
168
+ }
169
+
170
+ export interface RevoluteJointOptions extends JointBaseOptions {
171
+ targetAngle?: number;
172
+ enableSpring?: boolean;
173
+ hertz?: number;
174
+ dampingRatio?: number;
175
+ enableLimit?: boolean;
176
+ lowerAngle?: number;
177
+ upperAngle?: number;
178
+ enableMotor?: boolean;
179
+ maxMotorTorque?: number;
180
+ motorSpeed?: number;
181
+ }
182
+
183
+ export class RevoluteJoint extends Joint {
184
+ getAngle(): number;
185
+ enableSpring(flag: boolean): void;
186
+ setSpringHertz(hertz: number): void;
187
+ setSpringDampingRatio(ratio: number): void;
188
+ setTargetAngle(angle: number): void;
189
+ enableLimit(flag: boolean): void;
190
+ setLimits(lower: number, upper: number): void;
191
+ enableMotor(flag: boolean): void;
192
+ setMotorSpeed(speed: number): void;
193
+ setMaxMotorTorque(torque: number): void;
194
+ getMotorTorque(): number;
195
+ }
196
+
197
+ export interface SphericalJointOptions extends JointBaseOptions {
198
+ enableSpring?: boolean;
199
+ hertz?: number;
200
+ dampingRatio?: number;
201
+ targetRotation?: Quat;
202
+ enableConeLimit?: boolean;
203
+ coneAngle?: number;
204
+ enableTwistLimit?: boolean;
205
+ lowerTwistAngle?: number;
206
+ upperTwistAngle?: number;
207
+ enableMotor?: boolean;
208
+ maxMotorTorque?: number;
209
+ motorVelocity?: Vec3;
210
+ }
211
+
212
+ export class SphericalJoint extends Joint {
213
+ enableConeLimit(flag: boolean): void;
214
+ setConeLimit(angle: number): void;
215
+ getConeAngle(): number;
216
+ enableTwistLimit(flag: boolean): void;
217
+ setTwistLimits(lower: number, upper: number): void;
218
+ getTwistAngle(): number;
219
+ enableSpring(flag: boolean): void;
220
+ setSpringHertz(hertz: number): void;
221
+ setSpringDampingRatio(ratio: number): void;
222
+ setTargetRotation(rotation: Quat): void;
223
+ enableMotor(flag: boolean): void;
224
+ setMotorVelocity(velocity: Vec3): void;
225
+ setMaxMotorTorque(torque: number): void;
226
+ }
227
+
228
+ export interface PrismaticJointOptions extends JointBaseOptions {
229
+ enableSpring?: boolean;
230
+ hertz?: number;
231
+ dampingRatio?: number;
232
+ targetTranslation?: number;
233
+ enableLimit?: boolean;
234
+ lowerTranslation?: number;
235
+ upperTranslation?: number;
236
+ enableMotor?: boolean;
237
+ maxMotorForce?: number;
238
+ motorSpeed?: number;
239
+ }
240
+
241
+ export class PrismaticJoint extends Joint {
242
+ getTranslation(): number;
243
+ getSpeed(): number;
244
+ enableSpring(flag: boolean): void;
245
+ setSpringHertz(hertz: number): void;
246
+ setSpringDampingRatio(ratio: number): void;
247
+ setTargetTranslation(translation: number): void;
248
+ enableLimit(flag: boolean): void;
249
+ setLimits(lower: number, upper: number): void;
250
+ enableMotor(flag: boolean): void;
251
+ setMotorSpeed(speed: number): void;
252
+ setMaxMotorForce(force: number): void;
253
+ }
254
+
255
+ export interface WeldJointOptions extends JointBaseOptions {
256
+ linearHertz?: number;
257
+ angularHertz?: number;
258
+ linearDampingRatio?: number;
259
+ angularDampingRatio?: number;
260
+ }
261
+
262
+ export class WeldJoint extends Joint {
263
+ setLinearHertz(hertz: number): void;
264
+ setLinearDampingRatio(ratio: number): void;
265
+ setAngularHertz(hertz: number): void;
266
+ setAngularDampingRatio(ratio: number): void;
267
+ }
268
+
269
+ export interface MotorJointOptions extends JointBaseOptions {
270
+ linearVelocity?: Vec3;
271
+ maxVelocityForce?: number;
272
+ angularVelocity?: Vec3;
273
+ maxVelocityTorque?: number;
274
+ linearHertz?: number;
275
+ linearDampingRatio?: number;
276
+ maxSpringForce?: number;
277
+ angularHertz?: number;
278
+ angularDampingRatio?: number;
279
+ maxSpringTorque?: number;
280
+ }
281
+
282
+ export class MotorJoint extends Joint {
283
+ setLinearVelocity(velocity: Vec3): void;
284
+ setAngularVelocity(velocity: Vec3): void;
285
+ setMaxVelocityForce(force: number): void;
286
+ setMaxVelocityTorque(torque: number): void;
287
+ setLinearHertz(hertz: number): void;
288
+ setLinearDampingRatio(ratio: number): void;
289
+ setAngularHertz(hertz: number): void;
290
+ setAngularDampingRatio(ratio: number): void;
291
+ setMaxSpringForce(force: number): void;
292
+ setMaxSpringTorque(torque: number): void;
293
+ }
294
+
295
+ export interface MotionLocks {
296
+ linearX?: boolean;
297
+ linearY?: boolean;
298
+ linearZ?: boolean;
299
+ angularX?: boolean;
300
+ angularY?: boolean;
301
+ angularZ?: boolean;
302
+ }
303
+
304
+ export type Box3DBodyType = 'static' | 'kinematic' | 'dynamic';
305
+
306
+ export interface BodyOptions {
307
+ type?: Box3DBodyType;
308
+ position?: Vec3;
309
+ rotation?: Quat;
310
+ linearVelocity?: Vec3;
311
+ angularVelocity?: Vec3;
312
+ linearDamping?: number;
313
+ angularDamping?: number;
314
+ gravityScale?: number;
315
+ sleepThreshold?: number;
316
+ enableSleep?: boolean;
317
+ isAwake?: boolean;
318
+ isBullet?: boolean;
319
+ isEnabled?: boolean;
320
+ allowFastRotation?: boolean;
321
+ enableContactRecycling?: boolean;
322
+ motionLocks?: MotionLocks;
323
+ userData?: number;
324
+ name?: string;
325
+ }
326
+
327
+ export class Body {
328
+ isValid(): boolean;
329
+ destroy(): void;
330
+ getType(): Box3DBodyType;
331
+ setType(type: Box3DBodyType): void;
332
+ getName(): string;
333
+ setName(name: string): void;
334
+ getUserData(): number;
335
+ setUserData(tag: number): void;
336
+ getPosition(): Vec3;
337
+ getRotation(): Quat;
338
+ getTransform(): Required<Box3DTransform>;
339
+ setTransform(position: Vec3, rotation: Quat): void;
340
+ setTargetTransform(
341
+ target: Box3DTransform,
342
+ timeStep: number,
343
+ wake: boolean,
344
+ ): void;
345
+ getLinearVelocity(): Vec3;
346
+ setLinearVelocity(velocity: Vec3): void;
347
+ getAngularVelocity(): Vec3;
348
+ setAngularVelocity(velocity: Vec3): void;
349
+ applyForce(force: Vec3, point: Vec3, wake: boolean): void;
350
+ applyForceToCenter(force: Vec3, wake: boolean): void;
351
+ applyTorque(torque: Vec3, wake: boolean): void;
352
+ applyLinearImpulse(impulse: Vec3, point: Vec3, wake: boolean): void;
353
+ applyLinearImpulseToCenter(impulse: Vec3, wake: boolean): void;
354
+ applyAngularImpulse(impulse: Vec3, wake: boolean): void;
355
+ getMass(): number;
356
+ applyMassFromShapes(): void;
357
+ getLocalCenterOfMass(): Vec3;
358
+ getWorldCenterOfMass(): Vec3;
359
+ getLocalPoint(worldPoint: Vec3): Vec3;
360
+ getWorldPoint(localPoint: Vec3): Vec3;
361
+ getLinearDamping(): number;
362
+ setLinearDamping(damping: number): void;
363
+ getAngularDamping(): number;
364
+ setAngularDamping(damping: number): void;
365
+ getGravityScale(): number;
366
+ setGravityScale(scale: number): void;
367
+ isAwake(): boolean;
368
+ setAwake(awake: boolean): void;
369
+ enableSleep(flag: boolean): void;
370
+ isEnabled(): boolean;
371
+ setEnabled(flag: boolean): void;
372
+ isBullet(): boolean;
373
+ setBullet(flag: boolean): void;
374
+ setMotionLocks(locks: MotionLocks): void;
375
+ getMotionLocks(): Required<MotionLocks>;
376
+ getShapeCount(): number;
377
+ computeAABB(): AABB;
378
+ createSphere(options: SphereShapeOptions): Shape;
379
+ createCapsule(options: CapsuleShapeOptions): Shape;
380
+ createBox(options: BoxShapeOptions): Shape;
381
+ createHull(options: HullShapeOptions): Shape;
382
+ }
383
+
384
+ export interface WorldOptions {
385
+ gravity?: Vec3;
386
+ restitutionThreshold?: number;
387
+ hitEventThreshold?: number;
388
+ contactHertz?: number;
389
+ contactDampingRatio?: number;
390
+ contactSpeed?: number;
391
+ maximumLinearSpeed?: number;
392
+ enableSleep?: boolean;
393
+ enableContinuous?: boolean;
394
+ /** Only honored by the `deluxe` (threaded) flavour. */
395
+ workerCount?: number;
396
+ }
397
+
398
+ export interface RayCastResult {
399
+ hit: boolean;
400
+ point?: Vec3;
401
+ normal?: Vec3;
402
+ fraction?: number;
403
+ shapeUserData?: number;
404
+ bodyUserData?: number;
405
+ shape?: Shape;
406
+ }
407
+
408
+ export interface QueryFilter {
409
+ categoryBits?: number;
410
+ maskBits?: number;
411
+ }
412
+
413
+ export interface ExplosionOptions {
414
+ position?: Vec3;
415
+ radius?: number;
416
+ falloff?: number;
417
+ impulsePerArea?: number;
418
+ maskBits?: number;
419
+ }
420
+
421
+ export interface BodyMoveEvent {
422
+ userData: number;
423
+ position: Vec3;
424
+ rotation: Quat;
425
+ fellAsleep: boolean;
426
+ }
427
+
428
+ export interface ContactBeginEvent {
429
+ shapeUserDataA: number;
430
+ shapeUserDataB: number;
431
+ }
432
+
433
+ export interface ContactEndEvent {
434
+ shapeUserDataA: number | null;
435
+ shapeUserDataB: number | null;
436
+ }
437
+
438
+ export interface ContactHitEvent {
439
+ shapeUserDataA: number;
440
+ shapeUserDataB: number;
441
+ point: Vec3;
442
+ normal: Vec3;
443
+ approachSpeed: number;
444
+ }
445
+
446
+ export interface ContactEvents {
447
+ begin: ContactBeginEvent[];
448
+ end: ContactEndEvent[];
449
+ hit: ContactHitEvent[];
450
+ }
451
+
452
+ export interface SensorBeginEvent {
453
+ sensorUserData: number;
454
+ visitorUserData: number;
455
+ }
456
+
457
+ export interface SensorEndEvent {
458
+ sensorUserData: number | null;
459
+ visitorUserData: number | null;
460
+ }
461
+
462
+ export interface SensorEvents {
463
+ begin: SensorBeginEvent[];
464
+ end: SensorEndEvent[];
465
+ }
466
+
467
+ export interface Profile {
468
+ step: number;
469
+ pairs: number;
470
+ collide: number;
471
+ solve: number;
472
+ }
473
+
474
+ export class World {
475
+ constructor(options?: WorldOptions);
476
+ isValid(): boolean;
477
+ destroy(): void;
478
+ step(timeStep: number, subStepCount: number): void;
479
+ getGravity(): Vec3;
480
+ setGravity(gravity: Vec3): void;
481
+ enableSleeping(flag: boolean): void;
482
+ enableContinuous(flag: boolean): void;
483
+ getAwakeBodyCount(): number;
484
+ getWorkerCount(): number;
485
+ createBody(options?: BodyOptions): Body;
486
+ createDistanceJoint(
487
+ bodyA: Body,
488
+ bodyB: Body,
489
+ options?: DistanceJointOptions,
490
+ ): DistanceJoint;
491
+ createRevoluteJoint(
492
+ bodyA: Body,
493
+ bodyB: Body,
494
+ options?: RevoluteJointOptions,
495
+ ): RevoluteJoint;
496
+ createSphericalJoint(
497
+ bodyA: Body,
498
+ bodyB: Body,
499
+ options?: SphericalJointOptions,
500
+ ): SphericalJoint;
501
+ createPrismaticJoint(
502
+ bodyA: Body,
503
+ bodyB: Body,
504
+ options?: PrismaticJointOptions,
505
+ ): PrismaticJoint;
506
+ createWeldJoint(
507
+ bodyA: Body,
508
+ bodyB: Body,
509
+ options?: WeldJointOptions,
510
+ ): WeldJoint;
511
+ createMotorJoint(
512
+ bodyA: Body,
513
+ bodyB: Body,
514
+ options?: MotorJointOptions,
515
+ ): MotorJoint;
516
+ castRayClosest(
517
+ origin: Vec3,
518
+ translation: Vec3,
519
+ filter?: QueryFilter,
520
+ ): RayCastResult;
521
+ explode(options: ExplosionOptions): void;
522
+ getBodyEvents(): BodyMoveEvent[];
523
+ getContactEvents(): ContactEvents;
524
+ getSensorEvents(): SensorEvents;
525
+ getProfile(): Profile;
526
+ }
527
+
528
+ export interface Box3DModule {
529
+ World: typeof World;
530
+ /** Whether this flavour of the module has wasm threads enabled. */
531
+ threaded: boolean;
532
+ /** Upper bound accepted by `WorldOptions.workerCount`. */
533
+ maxWorkers: number;
534
+ }
535
+
536
+ export interface Box3DFactoryOptions {
537
+ locateFile?: (path: string, prefix: string) => string;
538
+ [key: string]: unknown;
539
+ }
540
+
541
+ export default function Box3D(
542
+ options?: Box3DFactoryOptions,
543
+ ): Promise<Box3DModule>;
544
+ }
545
+
546
+ declare module 'box3d-wasm/standard' {
547
+ export { default } from 'box3d-wasm';
548
+ }
549
+
550
+ declare module 'box3d-wasm/deluxe' {
551
+ export { default } from 'box3d-wasm';
552
+ }
553
+
554
+ /**
555
+ * Joint types box3d-wasm's compiled binary exposes (wheel joint: car
556
+ * suspension + steering + drive in a single joint; filter joint: pure
557
+ * collision-filtering between two bodies; parallel joint: constrains a body's
558
+ * rotation to match another's, e.g. for parallel linkages) that aren't used
559
+ * by `Box3DPlugin` -- Babylon's V2 physics API has no equivalent constraint
560
+ * type to wrap any of them in, so they're absent from `box3d-wasm.d.ts`.
561
+ * Consumers that want them access box3d directly through
562
+ * `Box3DPlugin.world` (bypassing the `IPhysicsEnginePluginV2` abstraction)
563
+ * and this augments the base declaration with the missing surface.
564
+ * Verified present by instantiating the compiled `box3d-wasm@0.2.0` binary
565
+ * and inspecting the live prototypes (`Object.getOwnPropertyNames`) --
566
+ * upstream ships no types at all, so nothing here is derived from a
567
+ * declaration file that could be stale.
568
+ */
569
+ declare module 'box3d-wasm' {
570
+ export interface WheelJointOptions extends JointBaseOptions {
571
+ enableSuspensionSpring?: boolean;
572
+ suspensionHertz?: number;
573
+ suspensionDampingRatio?: number;
574
+ enableSuspensionLimit?: boolean;
575
+ lowerSuspensionLimit?: number;
576
+ upperSuspensionLimit?: number;
577
+ enableSpinMotor?: boolean;
578
+ maxSpinTorque?: number;
579
+ spinMotorSpeed?: number;
580
+ enableSteering?: boolean;
581
+ steeringHertz?: number;
582
+ steeringDampingRatio?: number;
583
+ maxSteeringTorque?: number;
584
+ enableSteeringLimit?: boolean;
585
+ lowerSteeringLimit?: number;
586
+ upperSteeringLimit?: number;
587
+ targetSteeringAngle?: number;
588
+ }
589
+
590
+ export class WheelJoint extends Joint {
591
+ getSpinSpeed(): number;
592
+ enableSpinMotor(flag: boolean): void;
593
+ setSpinMotorSpeed(speed: number): void;
594
+ setMaxSpinTorque(torque: number): void;
595
+ getSteeringAngle(): number;
596
+ enableSteering(flag: boolean): void;
597
+ setTargetSteeringAngle(angle: number): void;
598
+ enableSteeringLimit(flag: boolean): void;
599
+ setSteeringLimits(lower: number, upper: number): void;
600
+ setMaxSteeringTorque(torque: number): void;
601
+ setSteeringHertz(hertz: number): void;
602
+ setSteeringDampingRatio(ratio: number): void;
603
+ enableSuspension(flag: boolean): void;
604
+ enableSuspensionLimit(flag: boolean): void;
605
+ setSuspensionLimits(lower: number, upper: number): void;
606
+ setSuspensionHertz(hertz: number): void;
607
+ setSuspensionDampingRatio(ratio: number): void;
608
+ }
609
+
610
+ export type FilterJointOptions = JointBaseOptions;
611
+
612
+ export class FilterJoint extends Joint {}
613
+
614
+ export interface ParallelJointOptions extends JointBaseOptions {
615
+ enableSpring?: boolean;
616
+ hertz?: number;
617
+ dampingRatio?: number;
618
+ maxTorque?: number;
619
+ }
620
+
621
+ export class ParallelJoint extends Joint {
622
+ setMaxTorque(torque: number): void;
623
+ setSpringHertz(hertz: number): void;
624
+ setSpringDampingRatio(ratio: number): void;
625
+ }
626
+
627
+ export interface World {
628
+ createWheelJoint(
629
+ bodyA: Body,
630
+ bodyB: Body,
631
+ options?: WheelJointOptions,
632
+ ): WheelJoint;
633
+ createFilterJoint(
634
+ bodyA: Body,
635
+ bodyB: Body,
636
+ options?: FilterJointOptions,
637
+ ): FilterJoint;
638
+ createParallelJoint(
639
+ bodyA: Body,
640
+ bodyB: Body,
641
+ options?: ParallelJointOptions,
642
+ ): ParallelJoint;
643
+ }
644
+ }
645
+
646
+ import { IPhysicsEnginePluginV2, Observable, IPhysicsCollisionEvent, IBasePhysicsCollisionEvent, Vector3, PhysicsBody, PhysicsMotionType, Quaternion, Mesh, TransformNode, Nullable, PhysicsShape, PhysicsShapeType, PhysicsMassProperties, PhysicsConstraint, PhysicsShapeParameters, PhysicsMaterial, BoundingBox, PhysicsConstraintAxis, PhysicsConstraintAxisLimitMode, PhysicsConstraintMotorType, ConstrainedBodyPair, PhysicsRaycastResult, IRaycastQuery } from '@babylonjs/core';
647
+ import { World, Box3DModule } from 'box3d-wasm';
648
+
649
+ /**
650
+ * Babylon.js Physics V2 plugin backed by {@link https://github.com/monteslu/box3d-wasm | box3d-wasm}.
651
+ *
652
+ * Modeled after `@babylonjs/core`'s `HavokPlugin` (same file layout as
653
+ * `Physics/v2/Plugins/havokPlugin.ts`), adapted to the narrower API surface
654
+ * that box3d-wasm's embind bindings expose. See the package README for a
655
+ * summary of what isn't (fully) supported.
656
+ */
657
+ declare class Box3DPlugin implements IPhysicsEnginePluginV2 {
658
+ world: World;
659
+ name: string;
660
+ onCollisionObservable: Observable<IPhysicsCollisionEvent>;
661
+ onCollisionEndedObservable: Observable<IBasePhysicsCollisionEvent>;
662
+ onTriggerCollisionObservable: Observable<IBasePhysicsCollisionEvent>;
663
+ private _timeStep;
664
+ private _subStepCount;
665
+ private _maxLinearVelocity;
666
+ private _maxAngularVelocity;
667
+ private readonly _bodies;
668
+ private readonly _shapeOwners;
669
+ private _warnedAboutInstancing;
670
+ /**
671
+ * @param box3d - The resolved box3d-wasm module, e.g. `await Box3D()`.
672
+ * @param worldOptions - Forwarded to box3d-wasm's `World` constructor (gravity, sleep, continuous collision, thread count, ...).
673
+ */
674
+ constructor(box3d: Box3DModule, worldOptions?: ConstructorParameters<Box3DModule['World']>[0]);
675
+ setGravity(gravity: Vector3): void;
676
+ setTimeStep(timeStep: number): void;
677
+ getTimeStep(): number;
678
+ /** Number of box3d solver sub-steps per `executeStep` call. Defaults to 4, matching box3d's own samples. */
679
+ setSubStepCount(subStepCount: number): void;
680
+ getPluginVersion(): number;
681
+ setVelocityLimits(maxLinearVelocity: number, maxAngularVelocity: number): void;
682
+ getMaxLinearVelocity(): number;
683
+ getMaxAngularVelocity(): number;
684
+ executeStep(delta: number, bodies: Array<PhysicsBody>): void;
685
+ private _clampLinearVelocities;
686
+ /** Pushes kinematic/animated transform-node motion into box3d before stepping. Dynamic bodies are driven by the solver and skip this. */
687
+ private _prestep;
688
+ initBody(body: PhysicsBody, motionType: PhysicsMotionType, position: Vector3, orientation: Quaternion): void;
689
+ initBodyInstances(body: PhysicsBody, motionType: PhysicsMotionType, mesh: Mesh): void;
690
+ updateBodyInstances(_body: PhysicsBody, _mesh: Mesh): void;
691
+ removeBody(body: PhysicsBody): void;
692
+ sync(body: PhysicsBody): void;
693
+ syncTransform(body: PhysicsBody, transformNode: TransformNode): void;
694
+ setShape(body: PhysicsBody, shape: Nullable<PhysicsShape>): void;
695
+ getShape(body: PhysicsBody): Nullable<PhysicsShape>;
696
+ getShapeType(shape: PhysicsShape): PhysicsShapeType;
697
+ setEventMask(body: PhysicsBody, eventMask: number): void;
698
+ getEventMask(body: PhysicsBody): number;
699
+ setMotionType(body: PhysicsBody, motionType: PhysicsMotionType): void;
700
+ getMotionType(body: PhysicsBody): PhysicsMotionType;
701
+ computeMassProperties(body: PhysicsBody): PhysicsMassProperties;
702
+ setMassProperties(body: PhysicsBody, massProps: PhysicsMassProperties): void;
703
+ getMassProperties(body: PhysicsBody): PhysicsMassProperties;
704
+ setLinearDamping(body: PhysicsBody, damping: number): void;
705
+ getLinearDamping(body: PhysicsBody): number;
706
+ setAngularDamping(body: PhysicsBody, damping: number): void;
707
+ getAngularDamping(body: PhysicsBody): number;
708
+ setLinearVelocity(body: PhysicsBody, linVel: Vector3): void;
709
+ getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3): void;
710
+ applyImpulse(body: PhysicsBody, impulse: Vector3, location: Vector3): void;
711
+ applyAngularImpulse(body: PhysicsBody, angularImpulse: Vector3): void;
712
+ applyForce(body: PhysicsBody, force: Vector3, location: Vector3): void;
713
+ applyTorque(body: PhysicsBody, torque: Vector3): void;
714
+ setAngularVelocity(body: PhysicsBody, angVel: Vector3): void;
715
+ getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;
716
+ getBodyGeometry(_body: PhysicsBody): object;
717
+ disposeBody(body: PhysicsBody): void;
718
+ setCollisionCallbackEnabled(body: PhysicsBody, enabled: boolean): void;
719
+ setCollisionEndedCallbackEnabled(body: PhysicsBody, enabled: boolean): void;
720
+ addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;
721
+ getCollisionObservable(body: PhysicsBody): Observable<IPhysicsCollisionEvent>;
722
+ getCollisionEndedObservable(body: PhysicsBody): Observable<IBasePhysicsCollisionEvent>;
723
+ setGravityFactor(body: PhysicsBody, factor: number): void;
724
+ getGravityFactor(body: PhysicsBody): number;
725
+ setTargetTransform(body: PhysicsBody, position: Vector3, rotation: Quaternion): void;
726
+ private _getPluginData;
727
+ private _destroyAttachments;
728
+ initShape(shape: PhysicsShape, type: PhysicsShapeType, options: PhysicsShapeParameters): void;
729
+ setShapeFilterMembershipMask(shape: PhysicsShape, membershipMask: number): void;
730
+ getShapeFilterMembershipMask(shape: PhysicsShape): number;
731
+ setShapeFilterCollideMask(shape: PhysicsShape, collideMask: number): void;
732
+ getShapeFilterCollideMask(shape: PhysicsShape): number;
733
+ setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void;
734
+ getMaterial(shape: PhysicsShape): PhysicsMaterial;
735
+ setDensity(shape: PhysicsShape, density: number): void;
736
+ getDensity(shape: PhysicsShape): number;
737
+ addChild(shape: PhysicsShape, newChild: PhysicsShape, translation?: Vector3, rotation?: Quaternion, scale?: Vector3): void;
738
+ removeChild(shape: PhysicsShape, childIndex: number): void;
739
+ getNumChildren(shape: PhysicsShape): number;
740
+ getBoundingBox(shape: PhysicsShape): BoundingBox;
741
+ getBodyBoundingBox(body: PhysicsBody): BoundingBox;
742
+ disposeShape(shape: PhysicsShape): void;
743
+ setTrigger(shape: PhysicsShape, isTrigger: boolean): void;
744
+ private _getShapeData;
745
+ private _nativeShapesOf;
746
+ private _ownersOfShape;
747
+ /** Re-creates every body's attachment tree that (transitively) references `shape`, e.g. after `addChild`/`removeChild`/`setTrigger`. */
748
+ private _reattachOwners;
749
+ private _refreshShapeFilters;
750
+ /** Recursively creates native box3d shapes for `shape` (and, for CONTAINER shapes, its children) on `bodyData.native`, composing local transforms along the way. */
751
+ private _attachShape;
752
+ initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;
753
+ setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
754
+ getEnabled(constraint: PhysicsConstraint): boolean;
755
+ setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
756
+ getCollisionsEnabled(constraint: PhysicsConstraint): boolean;
757
+ setAxisFriction(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, friction: number): void;
758
+ getAxisFriction(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<number>;
759
+ setAxisMode(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, limitMode: PhysicsConstraintAxisLimitMode): void;
760
+ getAxisMode(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<PhysicsConstraintAxisLimitMode>;
761
+ setAxisMinLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, minLimit: number): void;
762
+ getAxisMinLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<number>;
763
+ setAxisMaxLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, limit: number): void;
764
+ getAxisMaxLimit(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<number>;
765
+ setAxisMotorType(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, motorType: PhysicsConstraintMotorType): void;
766
+ getAxisMotorType(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<PhysicsConstraintMotorType>;
767
+ setAxisMotorTarget(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, target: number): void;
768
+ getAxisMotorTarget(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<number>;
769
+ setAxisMotorMaxForce(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis, maxForce: number): void;
770
+ getAxisMotorMaxForce(constraint: PhysicsConstraint, axis: PhysicsConstraintAxis): Nullable<number>;
771
+ disposeConstraint(constraint: PhysicsConstraint): void;
772
+ getBodiesUsingConstraint(constraint: PhysicsConstraint): ConstrainedBodyPair[];
773
+ private _getConstraintData;
774
+ raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult | Array<PhysicsRaycastResult>, query?: IRaycastQuery): void;
775
+ dispose(): void;
776
+ private _dispatchEvents;
777
+ private _notifyCollision;
778
+ private _notifyCollisionEnded;
779
+ private _notifyTrigger;
780
+ }
781
+
782
+ export { Box3DPlugin };