@codexo/exojs-physics 0.19.1 → 0.20.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 +8 -73
- package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
- package/debug.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +17 -23
- package/dist/esm/Aabb.d.ts +0 -10
- package/dist/esm/Aabb.d.ts.map +0 -1
- package/dist/esm/Aabb.js +0 -16
- package/dist/esm/Aabb.js.map +0 -1
- package/dist/esm/Collider.d.ts +0 -107
- package/dist/esm/Collider.d.ts.map +0 -1
- package/dist/esm/Collider.js +0 -284
- package/dist/esm/Collider.js.map +0 -1
- package/dist/esm/ContactGraph.d.ts +0 -154
- package/dist/esm/ContactGraph.d.ts.map +0 -1
- package/dist/esm/ContactGraph.js +0 -383
- package/dist/esm/ContactGraph.js.map +0 -1
- package/dist/esm/ContactModifier.d.ts +0 -62
- package/dist/esm/ContactModifier.d.ts.map +0 -1
- package/dist/esm/ContactModifier.js +0 -49
- package/dist/esm/ContactModifier.js.map +0 -1
- package/dist/esm/PhysicsBody.d.ts +0 -186
- package/dist/esm/PhysicsBody.d.ts.map +0 -1
- package/dist/esm/PhysicsBody.js +0 -526
- package/dist/esm/PhysicsBody.js.map +0 -1
- package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
- package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
- package/dist/esm/PhysicsBodyComponent.js +0 -77
- package/dist/esm/PhysicsBodyComponent.js.map +0 -1
- package/dist/esm/PhysicsWorld.d.ts +0 -567
- package/dist/esm/PhysicsWorld.d.ts.map +0 -1
- package/dist/esm/PhysicsWorld.js +0 -1096
- package/dist/esm/PhysicsWorld.js.map +0 -1
- package/dist/esm/TimeStepper.d.ts +0 -40
- package/dist/esm/TimeStepper.d.ts.map +0 -1
- package/dist/esm/TimeStepper.js +0 -59
- package/dist/esm/TimeStepper.js.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
- package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
- package/dist/esm/backend/NativePhysicsBackend.js +0 -52
- package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
- package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
- package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.d.ts +0 -48
- package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
- package/dist/esm/binding/BindingRegistry.js +0 -81
- package/dist/esm/binding/BindingRegistry.js.map +0 -1
- package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
- package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
- package/dist/esm/binding/PhysicsBinding.js +0 -54
- package/dist/esm/binding/PhysicsBinding.js.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
- package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
- package/dist/esm/binding/nodeWorldTransform.js +0 -41
- package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
- package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
- package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
- package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
- package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
- package/dist/esm/broadphase/index.d.ts +0 -3
- package/dist/esm/broadphase/index.d.ts.map +0 -1
- package/dist/esm/collision/CollisionProxy.d.ts +0 -15
- package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.d.ts +0 -34
- package/dist/esm/collision/Manifold.d.ts.map +0 -1
- package/dist/esm/collision/Manifold.js +0 -37
- package/dist/esm/collision/Manifold.js.map +0 -1
- package/dist/esm/collision/chainAdjacency.d.ts +0 -2
- package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
- package/dist/esm/collision/chainAdjacency.js +0 -44
- package/dist/esm/collision/chainAdjacency.js.map +0 -1
- package/dist/esm/collision/dispatch.d.ts +0 -35
- package/dist/esm/collision/dispatch.d.ts.map +0 -1
- package/dist/esm/collision/dispatch.js +0 -58
- package/dist/esm/collision/dispatch.js.map +0 -1
- package/dist/esm/collision/index.d.ts +0 -5
- package/dist/esm/collision/index.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.d.ts +0 -17
- package/dist/esm/collision/narrowphase.d.ts.map +0 -1
- package/dist/esm/collision/narrowphase.js +0 -555
- package/dist/esm/collision/narrowphase.js.map +0 -1
- package/dist/esm/collision/segments.d.ts +0 -19
- package/dist/esm/collision/segments.d.ts.map +0 -1
- package/dist/esm/collision/segments.js +0 -36
- package/dist/esm/collision/segments.js.map +0 -1
- package/dist/esm/collision/sweep.d.ts +0 -35
- package/dist/esm/collision/sweep.d.ts.map +0 -1
- package/dist/esm/collision/sweep.js +0 -437
- package/dist/esm/collision/sweep.js.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
- package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
- package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
- package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
- package/dist/esm/debug/index.d.ts.map +0 -1
- package/dist/esm/debug/index.js +0 -3
- package/dist/esm/events.d.ts +0 -36
- package/dist/esm/events.d.ts.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -25
- package/dist/esm/joints/DistanceJoint.d.ts +0 -70
- package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
- package/dist/esm/joints/DistanceJoint.js +0 -167
- package/dist/esm/joints/DistanceJoint.js.map +0 -1
- package/dist/esm/joints/Joint.d.ts +0 -76
- package/dist/esm/joints/Joint.d.ts.map +0 -1
- package/dist/esm/joints/Joint.js +0 -62
- package/dist/esm/joints/Joint.js.map +0 -1
- package/dist/esm/joints/MouseJoint.d.ts +0 -55
- package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
- package/dist/esm/joints/MouseJoint.js +0 -139
- package/dist/esm/joints/MouseJoint.js.map +0 -1
- package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
- package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
- package/dist/esm/joints/PrismaticJoint.js +0 -218
- package/dist/esm/joints/PrismaticJoint.js.map +0 -1
- package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
- package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
- package/dist/esm/joints/RevoluteJoint.js +0 -204
- package/dist/esm/joints/RevoluteJoint.js.map +0 -1
- package/dist/esm/joints/WeldJoint.d.ts +0 -60
- package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
- package/dist/esm/joints/WeldJoint.js +0 -166
- package/dist/esm/joints/WeldJoint.js.map +0 -1
- package/dist/esm/joints/WheelJoint.d.ts +0 -91
- package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
- package/dist/esm/joints/WheelJoint.js +0 -235
- package/dist/esm/joints/WheelJoint.js.map +0 -1
- package/dist/esm/math.d.ts +0 -29
- package/dist/esm/math.d.ts.map +0 -1
- package/dist/esm/math.js +0 -60
- package/dist/esm/math.js.map +0 -1
- package/dist/esm/physicsBuildInfo.d.ts +0 -16
- package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
- package/dist/esm/physicsBuildInfo.js +0 -10
- package/dist/esm/physicsBuildInfo.js.map +0 -1
- package/dist/esm/public.d.ts +0 -34
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.d.ts +0 -95
- package/dist/esm/query/QueryEngine.d.ts.map +0 -1
- package/dist/esm/query/QueryEngine.js +0 -512
- package/dist/esm/query/QueryEngine.js.map +0 -1
- package/dist/esm/query/SpatialIndex.d.ts +0 -34
- package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
- package/dist/esm/shapes/AnyShape.d.ts +0 -14
- package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.d.ts +0 -12
- package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
- package/dist/esm/shapes/BoxShape.js +0 -41
- package/dist/esm/shapes/BoxShape.js.map +0 -1
- package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
- package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CapsuleShape.js +0 -88
- package/dist/esm/shapes/CapsuleShape.js.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
- package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainEdgeShape.js +0 -66
- package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
- package/dist/esm/shapes/ChainShape.d.ts +0 -46
- package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
- package/dist/esm/shapes/ChainShape.js +0 -85
- package/dist/esm/shapes/ChainShape.js.map +0 -1
- package/dist/esm/shapes/CircleShape.d.ts +0 -14
- package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
- package/dist/esm/shapes/CircleShape.js +0 -31
- package/dist/esm/shapes/CircleShape.js.map +0 -1
- package/dist/esm/shapes/PolygonShape.d.ts +0 -24
- package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
- package/dist/esm/shapes/PolygonShape.js +0 -153
- package/dist/esm/shapes/PolygonShape.js.map +0 -1
- package/dist/esm/shapes/SegmentShape.d.ts +0 -31
- package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
- package/dist/esm/shapes/SegmentShape.js +0 -62
- package/dist/esm/shapes/SegmentShape.js.map +0 -1
- package/dist/esm/shapes/Shape.d.ts +0 -37
- package/dist/esm/shapes/Shape.d.ts.map +0 -1
- package/dist/esm/shapes/Shape.js +0 -15
- package/dist/esm/shapes/Shape.js.map +0 -1
- package/dist/esm/shapes/convexParts.d.ts +0 -21
- package/dist/esm/shapes/convexParts.d.ts.map +0 -1
- package/dist/esm/shapes/convexParts.js +0 -26
- package/dist/esm/shapes/convexParts.js.map +0 -1
- package/dist/esm/shapes/decompose.d.ts +0 -2
- package/dist/esm/shapes/decompose.d.ts.map +0 -1
- package/dist/esm/shapes/decompose.js +0 -272
- package/dist/esm/shapes/decompose.js.map +0 -1
- package/dist/esm/shapes/index.d.ts +0 -9
- package/dist/esm/shapes/index.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.d.ts +0 -94
- package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
- package/dist/esm/solver/ContactSolver.js +0 -457
- package/dist/esm/solver/ContactSolver.js.map +0 -1
- package/dist/esm/solver/tolerances.d.ts +0 -2
- package/dist/esm/solver/tolerances.d.ts.map +0 -1
- package/dist/esm/solver/tolerances.js +0 -36
- package/dist/esm/solver/tolerances.js.map +0 -1
- package/dist/esm/sort.d.ts +0 -2
- package/dist/esm/sort.d.ts.map +0 -1
- package/dist/esm/sort.js +0 -44
- package/dist/esm/sort.js.map +0 -1
- package/dist/esm/types.d.ts +0 -35
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -26
- package/dist/esm/types.js.map +0 -1
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { PhysicsBody } from "./PhysicsBody.js";
|
|
2
|
-
import { nodeWorldAngle, nodeWorldPosition } from "./binding/nodeWorldTransform.js";
|
|
3
|
-
import { Component } from "@codexo/exojs";
|
|
4
|
-
|
|
5
|
-
//#region src/PhysicsBodyComponent.ts
|
|
6
|
-
/**
|
|
7
|
-
* Gives a scene node a {@link PhysicsBody} whose world membership follows the
|
|
8
|
-
* component's lifecycle. While the component is active the body is in
|
|
9
|
-
* {@link world} and drives the node. Whenever the component is disabled -
|
|
10
|
-
* switched off, its node removed or reparented, its scene retained or ended -
|
|
11
|
-
* the body leaves the world with its state kept, and the next activation puts
|
|
12
|
-
* the same body back. Destroying the component, or its node, destroys the
|
|
13
|
-
* body. Pausing the scene changes nothing here: a world registered as that
|
|
14
|
-
* scene's system stops stepping with it, a world owned elsewhere keeps going.
|
|
15
|
-
*
|
|
16
|
-
* The body exists from construction, so {@link body} can be configured before
|
|
17
|
-
* the node enters a scene. Unless `options.position` or `options.angle` is
|
|
18
|
-
* given, the first activation places the body at the node's current world
|
|
19
|
-
* position or rotation. The node must be world-space-rooted, as for
|
|
20
|
-
* {@link PhysicsWorld.bind}.
|
|
21
|
-
*
|
|
22
|
-
* The world is never inferred: a node moved into a scene that steps another
|
|
23
|
-
* world keeps this component's body in the world it was given. A
|
|
24
|
-
* component-managed body cannot be constrained by a joint, and
|
|
25
|
-
* {@link PhysicsWorld.addJoint} rejects it; use a manually managed
|
|
26
|
-
* {@link PhysicsBody} for jointed bodies.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const physics = ball.addComponent(new PhysicsBodyComponent(world, { colliders: [{ shape: new CircleShape(12) }] }));
|
|
31
|
-
*
|
|
32
|
-
* physics.body.applyImpulse(0, -300);
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
var PhysicsBodyComponent = class extends Component {
|
|
36
|
-
/** The world the body joins while the component is active. */
|
|
37
|
-
world;
|
|
38
|
-
/** The body this component owns. Leave its world membership to the component. */
|
|
39
|
-
body;
|
|
40
|
-
_adoptNodePosition;
|
|
41
|
-
_adoptNodeAngle;
|
|
42
|
-
constructor(world, options = {}) {
|
|
43
|
-
super();
|
|
44
|
-
this.world = world;
|
|
45
|
-
this.body = new PhysicsBody(options);
|
|
46
|
-
this.body._componentManaged = true;
|
|
47
|
-
this._adoptNodePosition = options.position === void 0;
|
|
48
|
-
this._adoptNodeAngle = options.angle === void 0;
|
|
49
|
-
}
|
|
50
|
-
onEnable() {
|
|
51
|
-
const body = this.body;
|
|
52
|
-
const node = this.node;
|
|
53
|
-
if (this._adoptNodePosition || this._adoptNodeAngle) body.setTransform(this._adoptNodePosition ? nodeWorldPosition(node) : body.position, this._adoptNodeAngle ? nodeWorldAngle(node) : body.angle);
|
|
54
|
-
this.world.add(body);
|
|
55
|
-
try {
|
|
56
|
-
this.world.bind(body, node);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
this.world.remove(body);
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
this._adoptNodePosition = false;
|
|
62
|
-
this._adoptNodeAngle = false;
|
|
63
|
-
}
|
|
64
|
-
onDisable() {
|
|
65
|
-
if (!this.body.destroyed) this.world.remove(this.body);
|
|
66
|
-
}
|
|
67
|
-
onDestroy() {
|
|
68
|
-
const body = this.body;
|
|
69
|
-
if (body.destroyed) return;
|
|
70
|
-
if (body.attached) this.world.destroyBody(body);
|
|
71
|
-
else body._discard();
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
export { PhysicsBodyComponent };
|
|
77
|
-
//# sourceMappingURL=PhysicsBodyComponent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsBodyComponent.js","names":[],"sources":["../../src/PhysicsBodyComponent.ts"],"sourcesContent":["import { Component } from '@codexo/exojs';\n\nimport { nodeWorldAngle, nodeWorldPosition } from './binding/nodeWorldTransform';\nimport { type BodyOptions, PhysicsBody } from './PhysicsBody';\nimport type { PhysicsWorld } from './PhysicsWorld';\n\n/**\n * Gives a scene node a {@link PhysicsBody} whose world membership follows the\n * component's lifecycle. While the component is active the body is in\n * {@link world} and drives the node. Whenever the component is disabled -\n * switched off, its node removed or reparented, its scene retained or ended -\n * the body leaves the world with its state kept, and the next activation puts\n * the same body back. Destroying the component, or its node, destroys the\n * body. Pausing the scene changes nothing here: a world registered as that\n * scene's system stops stepping with it, a world owned elsewhere keeps going.\n *\n * The body exists from construction, so {@link body} can be configured before\n * the node enters a scene. Unless `options.position` or `options.angle` is\n * given, the first activation places the body at the node's current world\n * position or rotation. The node must be world-space-rooted, as for\n * {@link PhysicsWorld.bind}.\n *\n * The world is never inferred: a node moved into a scene that steps another\n * world keeps this component's body in the world it was given. A\n * component-managed body cannot be constrained by a joint, and\n * {@link PhysicsWorld.addJoint} rejects it; use a manually managed\n * {@link PhysicsBody} for jointed bodies.\n *\n * @example\n * ```ts\n * const physics = ball.addComponent(new PhysicsBodyComponent(world, { colliders: [{ shape: new CircleShape(12) }] }));\n *\n * physics.body.applyImpulse(0, -300);\n * ```\n */\nexport class PhysicsBodyComponent extends Component {\n /** The world the body joins while the component is active. */\n public readonly world: PhysicsWorld;\n /** The body this component owns. Leave its world membership to the component. */\n public readonly body: PhysicsBody;\n\n private _adoptNodePosition: boolean;\n private _adoptNodeAngle: boolean;\n\n public constructor(world: PhysicsWorld, options: BodyOptions = {}) {\n super();\n this.world = world;\n this.body = new PhysicsBody(options);\n this.body._componentManaged = true;\n this._adoptNodePosition = options.position === undefined;\n this._adoptNodeAngle = options.angle === undefined;\n }\n\n protected override onEnable(): void {\n const body = this.body;\n const node = this.node;\n\n // Only the first successful activation reads the node: from then on the\n // body is the transform authority, and the node merely shows where it is.\n // A failed attempt leaves the flags set, so the retry reads the node anew.\n if (this._adoptNodePosition || this._adoptNodeAngle) {\n body.setTransform(this._adoptNodePosition ? nodeWorldPosition(node) : body.position, this._adoptNodeAngle ? nodeWorldAngle(node) : body.angle);\n }\n\n this.world.add(body);\n\n try {\n this.world.bind(body, node);\n } catch (error) {\n // A failed enable leaves the component inactive; the body must not keep\n // simulating behind it.\n this.world.remove(body);\n throw error;\n }\n\n this._adoptNodePosition = false;\n this._adoptNodeAngle = false;\n }\n\n protected override onDisable(): void {\n // A body the world already destroyed (the world itself ended first) has\n // nothing left to leave.\n if (!this.body.destroyed) {\n this.world.remove(this.body);\n }\n }\n\n protected override onDestroy(): void {\n const body = this.body;\n\n if (body.destroyed) {\n return;\n }\n\n if (body.attached) {\n this.world.destroyBody(body);\n } else {\n body._discard();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,uBAAb,cAA0C,UAAU;;CAElD,AAAgB;;CAEhB,AAAgB;CAEhB,AAAQ;CACR,AAAQ;CAER,AAAO,YAAY,OAAqB,UAAuB,CAAC,GAAG;EACjE,MAAM;EACN,KAAK,QAAQ;EACb,KAAK,OAAO,IAAI,YAAY,OAAO;EACnC,KAAK,KAAK,oBAAoB;EAC9B,KAAK,qBAAqB,QAAQ,aAAa;EAC/C,KAAK,kBAAkB,QAAQ,UAAU;CAC3C;CAEA,AAAmB,WAAiB;EAClC,MAAM,OAAO,KAAK;EAClB,MAAM,OAAO,KAAK;EAKlB,IAAI,KAAK,sBAAsB,KAAK,iBAClC,KAAK,aAAa,KAAK,qBAAqB,kBAAkB,IAAI,IAAI,KAAK,UAAU,KAAK,kBAAkB,eAAe,IAAI,IAAI,KAAK,KAAK;EAG/I,KAAK,MAAM,IAAI,IAAI;EAEnB,IAAI;GACF,KAAK,MAAM,KAAK,MAAM,IAAI;EAC5B,SAAS,OAAO;GAGd,KAAK,MAAM,OAAO,IAAI;GACtB,MAAM;EACR;EAEA,KAAK,qBAAqB;EAC1B,KAAK,kBAAkB;CACzB;CAEA,AAAmB,YAAkB;EAGnC,IAAI,CAAC,KAAK,KAAK,WACb,KAAK,MAAM,OAAO,KAAK,IAAI;CAE/B;CAEA,AAAmB,YAAkB;EACnC,MAAM,OAAO,KAAK;EAElB,IAAI,KAAK,WACP;EAGF,IAAI,KAAK,UACP,KAAK,MAAM,YAAY,IAAI;OAE3B,KAAK,SAAS;CAElB;AACF"}
|
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
import type { AabbLike, PointLike, SceneNode, Seconds } from '@codexo/exojs';
|
|
2
|
-
import { Signal, Vector } from '@codexo/exojs';
|
|
3
|
-
import type { PhysicsBackend } from './backend/PhysicsBackend';
|
|
4
|
-
import type { PhysicsBinding } from './binding/PhysicsBinding';
|
|
5
|
-
import { Collider } from './Collider';
|
|
6
|
-
import type { ContactModifier } from './ContactModifier';
|
|
7
|
-
import type { CollisionEvent, SensorEvent } from './events';
|
|
8
|
-
import { type Joint } from './joints/Joint';
|
|
9
|
-
import type { BodyOwner } from './PhysicsBody';
|
|
10
|
-
import { PhysicsBody } from './PhysicsBody';
|
|
11
|
-
import type { QueryFilter, RayHit } from './query/QueryEngine';
|
|
12
|
-
import type { AnyShape } from './shapes/AnyShape';
|
|
13
|
-
import { TimeStepper } from './TimeStepper';
|
|
14
|
-
import type { BodyType, CollisionFilter } from './types';
|
|
15
|
-
/** Construction options for a {@link PhysicsWorld}. */
|
|
16
|
-
export interface PhysicsWorldOptions {
|
|
17
|
-
/** Gravity in px/s² (+Y down). Integrated each sub-step. Default `(0, 0)`. */
|
|
18
|
-
gravity?: Readonly<PointLike>;
|
|
19
|
-
/** Fixed timestep in seconds. Default `1 / 60`. */
|
|
20
|
-
fixedDelta?: number;
|
|
21
|
-
/** Maximum fixed steps per `step` call (spiral-of-death guard). Default `8`. */
|
|
22
|
-
maxSubSteps?: number;
|
|
23
|
-
/**
|
|
24
|
-
* TGS-Soft sub-steps per fixed step (the solver's stiffness scales with this,
|
|
25
|
-
* not iteration count). Default `4`. Must be ≥ 1. Values below `2` visibly
|
|
26
|
-
* degrade tall-stack stability (a 10-box tower jitters at `1`), so the default
|
|
27
|
-
* is load-bearing - do not lower it for performance.
|
|
28
|
-
*/
|
|
29
|
-
subStepCount?: number;
|
|
30
|
-
/** Soft-contact stiffness in Hz (the contact behaves as a damped spring at this frequency). Default `30`. */
|
|
31
|
-
contactHertz?: number;
|
|
32
|
-
/** Soft-contact damping ratio (≥ 1 keeps contacts from oscillating). Default `10`. */
|
|
33
|
-
dampingRatio?: number;
|
|
34
|
-
/** Put resting bodies to sleep so they skip integration and solving. Default `true`. */
|
|
35
|
-
enableSleeping?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Adjust each solid contact for the coming step (one-way platforms,
|
|
38
|
-
* conditional friction, per-pair material overrides). At most one per world;
|
|
39
|
-
* see {@link PhysicsWorld.contactModifier}. Default none.
|
|
40
|
-
*/
|
|
41
|
-
contactModifier?: ContactModifier | null;
|
|
42
|
-
/**
|
|
43
|
-
* Place bound nodes between the last two fixed states instead of snapping them
|
|
44
|
-
* to the latest one, which smooths motion when the fixed rate is below the
|
|
45
|
-
* frame rate. Default `false`.
|
|
46
|
-
*
|
|
47
|
-
* The blend factor comes from {@link frameAlphaSource}; a world driven as a
|
|
48
|
-
* `System` has to supply one.
|
|
49
|
-
*/
|
|
50
|
-
interpolation?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Where interpolated bindings read their blend factor, in `[0, 1)`.
|
|
53
|
-
*
|
|
54
|
-
* Defaults to this world's own accumulator - correct when the world is driven
|
|
55
|
-
* with {@link PhysicsWorld.step}, which is what advances it. A world driven as
|
|
56
|
-
* a `System` goes through {@link PhysicsWorld.fixedUpdate} and bypasses that
|
|
57
|
-
* accumulator entirely, so the host owns the fraction: pass
|
|
58
|
-
* `() => app.frameAlpha`.
|
|
59
|
-
*/
|
|
60
|
-
frameAlphaSource?: () => number;
|
|
61
|
-
/** Linear speed at or below which a body is a sleep candidate, px/s. Default `5`. */
|
|
62
|
-
sleepLinearVelocity?: number;
|
|
63
|
-
/** Angular speed at or below which a body is a sleep candidate, rad/s. Default `0.06`. */
|
|
64
|
-
sleepAngularVelocity?: number;
|
|
65
|
-
/** Seconds a body must stay below the sleep thresholds before it sleeps. Default `0.5`. */
|
|
66
|
-
timeToSleep?: number;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* {@link PhysicsWorld.attach} convenience options: a body type plus a single
|
|
70
|
-
* collider, attached to a scene node in one call.
|
|
71
|
-
*/
|
|
72
|
-
export interface AttachOptions {
|
|
73
|
-
/** Simulation role of the created body. Default `'dynamic'`. */
|
|
74
|
-
type?: BodyType;
|
|
75
|
-
/** Initial world position of the body. Default the node's current WORLD position ({@link SceneNode.getWorldTransform}) at attach time. */
|
|
76
|
-
position?: Readonly<PointLike>;
|
|
77
|
-
/** Initial rotation (radians) of the body. Default the angle matching the node's current WORLD rotation at attach time, so the node keeps its orientation once the body syncs it. */
|
|
78
|
-
angle?: number;
|
|
79
|
-
/** Per-body multiplier on world gravity. Default `1`. */
|
|
80
|
-
gravityScale?: number;
|
|
81
|
-
/** When `true`, the body never rotates under contacts. Default `false`. */
|
|
82
|
-
fixedRotation?: boolean;
|
|
83
|
-
/** The collider geometry. */
|
|
84
|
-
shape: AnyShape;
|
|
85
|
-
/** Body-local offset of the collider. Default `(0, 0)`. */
|
|
86
|
-
offset?: Readonly<PointLike>;
|
|
87
|
-
/** Body-local rotation of the collider (radians). Default `0`. */
|
|
88
|
-
rotation?: number;
|
|
89
|
-
/** Collider density (mass per px²). Default `1`. */
|
|
90
|
-
density?: number;
|
|
91
|
-
/** Coulomb friction coefficient. Default `0.2`. */
|
|
92
|
-
friction?: number;
|
|
93
|
-
/** Restitution / bounciness in `[0, 1]`. Default `0`. */
|
|
94
|
-
restitution?: number;
|
|
95
|
-
/** When `true`, the collider generates overlap events but no contact response. Default `false`. */
|
|
96
|
-
isSensor?: boolean;
|
|
97
|
-
/** Category/mask/group collision filter; partials merge over the defaults. */
|
|
98
|
-
filter?: Partial<CollisionFilter>;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The collision/query world: owns bodies, colliders, the detection backend,
|
|
102
|
-
* bindings, the query engine and the fixed-step accumulator. Stepped by the
|
|
103
|
-
* caller (commonly from a `Scene.update`), each fixed sub-step it integrates
|
|
104
|
-
* body velocities, runs broad- and narrow-phase detection, solves contacts and
|
|
105
|
-
* integrates positions, then fires immutable contact/sensor events and writes
|
|
106
|
-
* bound node transforms. It holds **no module-level state**, so any number of
|
|
107
|
-
* worlds run in isolation.
|
|
108
|
-
*
|
|
109
|
-
* The dynamics are a native, warm-started **TGS-Soft** solver (Box2D-v3 "soft
|
|
110
|
-
* step"): each fixed step runs detection once, then several sub-steps, each
|
|
111
|
-
* integrating gravity over the sub-step and solving contacts with a soft
|
|
112
|
-
* position bias plus a bias-free relax pass; a 2-point block normal solve
|
|
113
|
-
* propagates stack loads, and restitution is a separate final pass. Decoupling
|
|
114
|
-
* stiffness from the iteration count keeps tall towers stable. The detection
|
|
115
|
-
* backend sits behind an internal seam, so the solver is swappable without
|
|
116
|
-
* touching this public surface.
|
|
117
|
-
*
|
|
118
|
-
* **Operating envelope.** The soft solver trades a little accuracy for
|
|
119
|
-
* robustness, so it has a few documented limits - each stays finite and stable,
|
|
120
|
-
* and each is pinned by a gate in `dynamics.test.ts` or
|
|
121
|
-
* `contact-push-out.test.ts`:
|
|
122
|
-
* - **Resting contacts** settle within a small, fixed tolerance. A face contact
|
|
123
|
-
* settles at exactly that tolerance; a single-point contact settles slightly
|
|
124
|
-
* deeper, and that gap grows with acceleration. Very high accelerations
|
|
125
|
-
* eventually exceed what the push-out can resolve within a step, at which
|
|
126
|
-
* point the contact holds a slightly deeper resting depth instead of the
|
|
127
|
-
* tolerance - keep gravity in the range ordinary 2D games use.
|
|
128
|
-
* - **Mass ratio** - contacts between bodies of very different mass degrade
|
|
129
|
-
* gradually rather than at a fixed ratio. What sets the practical limit is how
|
|
130
|
-
* thick the supporting geometry is relative to the lighter body, not the ratio
|
|
131
|
-
* alone: a light body squeezed against a boundary thinner than itself is the
|
|
132
|
-
* case that fails first, and it fails by sinking through.
|
|
133
|
-
* - **Scale-relative behaviour** - the solver's tolerances are absolute lengths,
|
|
134
|
-
* so a very small shape sees them as a large fraction of itself, and a very
|
|
135
|
-
* large one as a negligible one. Keep the shapes of one world within a couple
|
|
136
|
-
* of orders of magnitude of each other.
|
|
137
|
-
* - **CCD is opt-in and translation-only** - detection runs once per fixed
|
|
138
|
-
* step, so an ordinary body that crosses more than roughly half a barrier's
|
|
139
|
-
* total thickness within one step may end up on the wrong side of it, either
|
|
140
|
-
* passing through or being resolved out of the far face. Flag fast
|
|
141
|
-
* projectiles with {@link PhysicsBody.isBullet}: each of the body's colliders
|
|
142
|
-
* is then shape-cast along the step's motion (an exact translation-only sweep
|
|
143
|
-
* of the full shape, not just the centre) and clamped at the first impact.
|
|
144
|
-
* Rotation over the step is not swept - a long body spinning fast enough to
|
|
145
|
-
* sweep past an obstacle within one step can still miss it.
|
|
146
|
-
* - **{@link PhysicsWorldOptions.subStepCount}** - the default `4` is
|
|
147
|
-
* load-bearing for tall-stack stability; lowering it below `2` visibly
|
|
148
|
-
* degrades stacking, so do not reduce it for performance.
|
|
149
|
-
* - **Broad phase is a dynamic AABB tree** (`AabbTreeBroadPhase`), stateful
|
|
150
|
-
* across fixed steps: a collider whose tight AABB stays inside its stored
|
|
151
|
-
* fat AABB costs nothing to re-sync, and only colliders that actually move
|
|
152
|
-
* outside their margin trigger a tree update and a local re-query for new
|
|
153
|
-
* neighbours. Detection still walks every live collider once per step (a
|
|
154
|
-
* cheap containment check for each), so there is a small linear floor, but
|
|
155
|
-
* the dominant cost - reinsertion and neighbour discovery - is driven by
|
|
156
|
-
* how much actually moved, not by the total live collider count; sleeping
|
|
157
|
-
* bodies skip that dominant cost entirely. Scales to tens of thousands of
|
|
158
|
-
* simultaneously-live colliders, including dense clusters that would
|
|
159
|
-
* degrade a sort-and-sweep broad phase; very large or highly dynamic
|
|
160
|
-
* worlds may still benefit from splitting into several smaller
|
|
161
|
-
* `PhysicsWorld` instances (e.g. per room/chunk).
|
|
162
|
-
*/
|
|
163
|
-
export declare class PhysicsWorld implements BodyOwner {
|
|
164
|
-
/** Fires when two solid colliders begin touching. Argument is an immutable snapshot. */
|
|
165
|
-
readonly onCollisionStart: Signal<[CollisionEvent]>;
|
|
166
|
-
/**
|
|
167
|
-
* Fires when two solid colliders stop touching. A pair also ends when one of
|
|
168
|
-
* its colliders leaves the world (destroyed or removed); that end arrives with
|
|
169
|
-
* the next step's events, ahead of them. `destroy()` ends no pairs.
|
|
170
|
-
*/
|
|
171
|
-
readonly onCollisionEnd: Signal<[CollisionEvent]>;
|
|
172
|
-
/** Fires when a collider enters a sensor. */
|
|
173
|
-
readonly onSensorEnter: Signal<[SensorEvent]>;
|
|
174
|
-
/** Fires when a collider leaves a sensor, including by leaving the world; see {@link onCollisionEnd}. */
|
|
175
|
-
readonly onSensorExit: Signal<[SensorEvent]>;
|
|
176
|
-
/** World gravity (px/s², +Y down). Integrated each sub-step. */
|
|
177
|
-
readonly gravity: Vector;
|
|
178
|
-
/** The fixed-step accumulator. */
|
|
179
|
-
readonly timeStepper: TimeStepper;
|
|
180
|
-
/** TGS-Soft sub-steps per fixed step. */
|
|
181
|
-
readonly subStepCount: number;
|
|
182
|
-
/** Soft-contact stiffness in Hz. */
|
|
183
|
-
readonly contactHertz: number;
|
|
184
|
-
/** Soft-contact damping ratio. */
|
|
185
|
-
readonly dampingRatio: number;
|
|
186
|
-
/** Whether resting bodies are put to sleep. */
|
|
187
|
-
readonly enableSleeping: boolean;
|
|
188
|
-
/** Linear sleep threshold (px/s). */
|
|
189
|
-
readonly sleepLinearVelocity: number;
|
|
190
|
-
/** Angular sleep threshold (rad/s). */
|
|
191
|
-
readonly sleepAngularVelocity: number;
|
|
192
|
-
/** Seconds below the thresholds before a body sleeps. */
|
|
193
|
-
readonly timeToSleep: number;
|
|
194
|
-
/**
|
|
195
|
-
* Runs once per solid contact per fixed step, after contact generation and
|
|
196
|
-
* before island building and the solver, so a contact it disables applies no
|
|
197
|
-
* impulse and does not couple its two bodies into one sleeping island.
|
|
198
|
-
*
|
|
199
|
-
* At most one modifier per world - it mutates simulation state, so a
|
|
200
|
-
* multi-listener signal would make the outcome depend on registration order.
|
|
201
|
-
* Set to `null` to remove it; the per-contact values then stay at the
|
|
202
|
-
* defaults derived from the two colliders.
|
|
203
|
-
*/
|
|
204
|
-
contactModifier: ContactModifier | null;
|
|
205
|
-
/**
|
|
206
|
-
* Whether bound nodes are placed between the last two fixed states rather than
|
|
207
|
-
* snapped to the latest one. Toggleable at runtime; switching it off snaps
|
|
208
|
-
* every bound node back to the current fixed state on the next sync.
|
|
209
|
-
*/
|
|
210
|
-
interpolation: boolean;
|
|
211
|
-
/**
|
|
212
|
-
* Supplies the `[0, 1)` blend factor for interpolated bindings. Defaults to
|
|
213
|
-
* this world's own accumulator; point it at the host's own fraction
|
|
214
|
-
* (`() => app.frameAlpha`) when the world runs as a `System`, because
|
|
215
|
-
* {@link fixedUpdate} never advances the local accumulator.
|
|
216
|
-
*/
|
|
217
|
-
frameAlphaSource: () => number;
|
|
218
|
-
private readonly _backend;
|
|
219
|
-
private readonly _bodies;
|
|
220
|
-
private readonly _colliders;
|
|
221
|
-
/**
|
|
222
|
-
* What detection actually runs over: the authored colliders, with a chain
|
|
223
|
-
* replaced by the edge proxies it fans out into. The broad phase, the narrow
|
|
224
|
-
* phase and the queries all read this list; `_colliders` stays the authored
|
|
225
|
-
* set every public surface reports.
|
|
226
|
-
*/
|
|
227
|
-
private readonly _detectionColliders;
|
|
228
|
-
/** Pooled scratch for re-syncing a single body's broad-phase leaves. */
|
|
229
|
-
private readonly _leafScratch;
|
|
230
|
-
private readonly _joints;
|
|
231
|
-
/**
|
|
232
|
-
* The joints `_prepare` left active this fixed step, in `_joints` order -
|
|
233
|
-
* what the sub-step warm-start and solve passes iterate instead of the full
|
|
234
|
-
* list. Reused across steps; a scene whose joints are all asleep leaves it
|
|
235
|
-
* empty and the sub-steps touch no joint at all.
|
|
236
|
-
*/
|
|
237
|
-
private readonly _activeJoints;
|
|
238
|
-
/**
|
|
239
|
-
* The bodies this fixed step's sub-steps integrate (non-static and awake),
|
|
240
|
-
* collected once per step. Reused across steps; sleep state cannot change
|
|
241
|
-
* between the sub-steps, so the snapshot stays valid for all of them.
|
|
242
|
-
*/
|
|
243
|
-
private readonly _steppedBodies;
|
|
244
|
-
/**
|
|
245
|
-
* Body pairs the live joints have taken out of collision, reference-counted:
|
|
246
|
-
* several joints may connect one pair, and the pair collides again only once
|
|
247
|
-
* the last of them is gone.
|
|
248
|
-
*
|
|
249
|
-
* Keyed on the pair rather than expressed through collision filters, because
|
|
250
|
-
* a ragdoll limb has to keep colliding with everything except the limb it is
|
|
251
|
-
* jointed to - which a category/mask pair cannot say.
|
|
252
|
-
*/
|
|
253
|
-
private readonly _uncollidableJointPairs;
|
|
254
|
-
private readonly _bindings;
|
|
255
|
-
private readonly _query;
|
|
256
|
-
private readonly _commands;
|
|
257
|
-
/** Colliders with a deferred removal queued but not yet applied; see {@link assertBodyKeepsItsMass}. */
|
|
258
|
-
private readonly _pendingColliderRemovals;
|
|
259
|
-
/**
|
|
260
|
-
* Bodies with a `remove` queued but not applied yet. An `add` of such a body
|
|
261
|
-
* before the queue drains cancels the removal instead of failing, and a
|
|
262
|
-
* second `remove` is a no-op.
|
|
263
|
-
*/
|
|
264
|
-
private readonly _pendingBodyRemovals;
|
|
265
|
-
/** Joints with a deferred registration queued; `remove` counts them as live. */
|
|
266
|
-
private readonly _pendingJoints;
|
|
267
|
-
/** Shape kinds already reported as unswept by this world; see {@link warnUnsweptBulletShape}. */
|
|
268
|
-
private readonly _warnedUnsweptKinds;
|
|
269
|
-
/** Pooled union-find parent array for the per-step island pass (reused; sized to the body count). */
|
|
270
|
-
private readonly _islandParent;
|
|
271
|
-
/** Pooled per-island minimum sleep time, indexed by union-find root. */
|
|
272
|
-
private readonly _islandMinSleep;
|
|
273
|
-
/** Pooled scratch for the CCD pass (clamp target, per-pair sweep hit, best hit, swept AABB) - keeps the sweep allocation-free. */
|
|
274
|
-
private readonly _ccdClampPosition;
|
|
275
|
-
private readonly _ccdSweepHit;
|
|
276
|
-
private readonly _ccdBestHit;
|
|
277
|
-
private readonly _ccdSweptAabb;
|
|
278
|
-
/** Pooled result buffer for the CCD pass's broad-phase query (refilled per bullet collider). */
|
|
279
|
-
private readonly _ccdCandidates;
|
|
280
|
-
private _nextBodyId;
|
|
281
|
-
private _nextColliderId;
|
|
282
|
-
private _dispatching;
|
|
283
|
-
private _destroyed;
|
|
284
|
-
constructor(options?: PhysicsWorldOptions);
|
|
285
|
-
/** Live bodies (read-only view). */
|
|
286
|
-
get bodies(): readonly PhysicsBody[];
|
|
287
|
-
/** Live colliders (read-only view). */
|
|
288
|
-
get colliders(): readonly Collider[];
|
|
289
|
-
/**
|
|
290
|
-
* Add a body to the world: allocates the body and its collider ids, registers
|
|
291
|
-
* the colliders, computes the mass model and tracks the body for stepping.
|
|
292
|
-
* Construct the body freely first (`new PhysicsBody({ ... })`), then add it.
|
|
293
|
-
* Safe to call inside an event callback - the body push is deferred to the end
|
|
294
|
-
* of the step, exactly like collider registration. Returns the body. A body
|
|
295
|
-
* taken out with {@link remove} can be added again, here or to another world.
|
|
296
|
-
*
|
|
297
|
-
* @throws if the body has already been added to a world.
|
|
298
|
-
*/
|
|
299
|
-
add(body: PhysicsBody): PhysicsBody;
|
|
300
|
-
/**
|
|
301
|
-
* Convenience: create a body carrying a single collider, add it to the world
|
|
302
|
-
* and bind it to `node` in one call. The node tracks `body.position` after each
|
|
303
|
-
* step. Returns the body. Equivalent to `new PhysicsBody(...)` + `add` + `bind`.
|
|
304
|
-
*
|
|
305
|
-
* When `options.position`/`options.angle` are omitted, the body starts at
|
|
306
|
-
* `node`'s current WORLD position/rotation (via `getWorldTransform()`,
|
|
307
|
-
* composed through any transform-group boundary) rather than `(0, 0)` -
|
|
308
|
-
* otherwise a body attached to an already-placed node would visibly "teleport"
|
|
309
|
-
* to the origin on the next step. Pass `position`/`angle` explicitly to override.
|
|
310
|
-
*/
|
|
311
|
-
attach(node: SceneNode, options: AttachOptions): PhysicsBody;
|
|
312
|
-
/**
|
|
313
|
-
* Take a body out of the simulation without destroying it. Its transform,
|
|
314
|
-
* velocities, mass model and colliders are kept and its ids are released; a
|
|
315
|
-
* later {@link add}, into this world or another, assigns new ones and wakes
|
|
316
|
-
* it. Touching pairs end with the usual end and exit events, delivered with
|
|
317
|
-
* the next step's events, and bodies resting on it are woken. A binding to a
|
|
318
|
-
* node ends.
|
|
319
|
-
*
|
|
320
|
-
* The colliders in those end events are the body's own, so by the time the
|
|
321
|
-
* events arrive their ids read `-1`, or the new ids of a re-add. A removed
|
|
322
|
-
* body cannot be constrained by a joint until it is added again.
|
|
323
|
-
*
|
|
324
|
-
* Deferred when called inside an event callback. Adding the body back before
|
|
325
|
-
* that dispatch ends cancels the removal, and calling `remove` again in the
|
|
326
|
-
* meantime does nothing.
|
|
327
|
-
*
|
|
328
|
-
* @throws if the body is destroyed, does not belong to this world, or is
|
|
329
|
-
* constrained by a joint of this world (remove the joint first, or end the
|
|
330
|
-
* body with {@link destroyBody}).
|
|
331
|
-
*/
|
|
332
|
-
remove(body: PhysicsBody): void;
|
|
333
|
-
/**
|
|
334
|
-
* Destroy a body and its colliders. Every dynamic body touching it is woken,
|
|
335
|
-
* so anything that was resting on the destroyed body falls once its support is
|
|
336
|
-
* gone. Deferred when called inside a callback.
|
|
337
|
-
*/
|
|
338
|
-
destroyBody(body: PhysicsBody): void;
|
|
339
|
-
/**
|
|
340
|
-
* Destroy a single collider, recomputing its body's mass. Wakes every dynamic
|
|
341
|
-
* body touching it, the same way {@link destroyBody} does. Deferred when
|
|
342
|
-
* called inside a callback.
|
|
343
|
-
*/
|
|
344
|
-
destroyCollider(collider: Collider): void;
|
|
345
|
-
/** Live joints (read-only view). */
|
|
346
|
-
get joints(): readonly Joint[];
|
|
347
|
-
/**
|
|
348
|
-
* Add a constraint joint. Construct it first (`new DistanceJoint({ ... })`),
|
|
349
|
-
* then add it. Wakes both bodies; safe inside a callback (registration is
|
|
350
|
-
* deferred). Returns the joint.
|
|
351
|
-
*/
|
|
352
|
-
addJoint<T extends Joint>(joint: T): T;
|
|
353
|
-
/** Remove a joint, waking both bodies so they respond to the lost constraint. Deferred when called inside a callback. */
|
|
354
|
-
removeJoint(joint: Joint): void;
|
|
355
|
-
/**
|
|
356
|
-
* Reference-count one joint's claim that its two bodies do not collide.
|
|
357
|
-
*
|
|
358
|
-
* Driven from the deferred add and remove rather than from the constructor,
|
|
359
|
-
* so the set describes the joints the world is actually stepping.
|
|
360
|
-
*/
|
|
361
|
-
private _holdPairApart;
|
|
362
|
-
/**
|
|
363
|
-
* Advance the world by `frameDeltaSeconds`. Accumulates into fixed steps; each
|
|
364
|
-
* fixed step runs detection once, then a TGS-Soft sub-step loop (integrate
|
|
365
|
-
* gravity, solve contacts with a soft bias, integrate positions, relax) and a
|
|
366
|
-
* restitution pass, then writes the accumulated motion into each body. Finally
|
|
367
|
-
* dispatches events and writes bound node transforms.
|
|
368
|
-
*
|
|
369
|
-
* **Prefer registering the world as a system instead**
|
|
370
|
-
* (`app.systems.add(world, { order: SystemOrder.Physics })` or the scene
|
|
371
|
-
* equivalent) so {@link fixedUpdate} drives stepping directly from the
|
|
372
|
-
* engine's own fixed-timestep scheduler - one call per fixed step, no
|
|
373
|
-
* accumulator duplication. `step` remains available here for manual/advanced
|
|
374
|
-
* driving (e.g. a fixed-but-non-standard rate, or stepping outside the
|
|
375
|
-
* normal frame loop entirely): pass any delta and this accumulator converts
|
|
376
|
-
* it into the right number of fixed sub-steps (0, 1, or several, clamped by
|
|
377
|
-
* {@link PhysicsWorldOptions.maxSubSteps}).
|
|
378
|
-
*
|
|
379
|
-
* Either way the simulation is frame-rate independent and deterministic -
|
|
380
|
-
* the same sequence of deltas replays identically. `timeStepper.alpha`
|
|
381
|
-
* (`[0, 1)`) is the leftover sub-step fraction after this call, for callers
|
|
382
|
-
* that want to interpolate a bound node's rendered position between the last
|
|
383
|
-
* two fixed states instead of snapping to the latest one (bindings do not do
|
|
384
|
-
* this automatically - {@link bind} always writes the latest fixed-step
|
|
385
|
-
* transform verbatim).
|
|
386
|
-
*/
|
|
387
|
-
step(frameDeltaSeconds: number): void;
|
|
388
|
-
/**
|
|
389
|
-
* Advance by exactly one fixed step, driven directly by the engine's own
|
|
390
|
-
* fixed-timestep scheduler when this world is registered as a `System`
|
|
391
|
-
* (`app.systems.add(world, { order: SystemOrder.Physics })` or the scene
|
|
392
|
-
* equivalent) - bypasses {@link timeStepper}'s variable-delta accumulator
|
|
393
|
-
* entirely, since the caller has already decided exactly when a fixed step
|
|
394
|
-
* occurs. Prefer this over manual {@link step} once the world is
|
|
395
|
-
* system-registered; `step` remains available for advanced manual driving.
|
|
396
|
-
* Always advances by exactly {@link timeStepper}'s configured `fixedDelta`,
|
|
397
|
-
* regardless of the caller's actual fixed-step interval - if the engine's
|
|
398
|
-
* `Application.fixedTimeStep` doesn't match this world's `fixedDelta`, the
|
|
399
|
-
* simulation stays deterministic but runs at the wrong wall-clock speed
|
|
400
|
-
* relative to real time.
|
|
401
|
-
*/
|
|
402
|
-
fixedUpdate(_step: Seconds): void;
|
|
403
|
-
/**
|
|
404
|
-
* Variable-rate `System` phase: places bound nodes for the frame that is about
|
|
405
|
-
* to be drawn. Only does work while {@link interpolation} is on - otherwise
|
|
406
|
-
* {@link fixedUpdate} has already snapped them to the latest fixed state.
|
|
407
|
-
*/
|
|
408
|
-
update(_delta: Seconds): void;
|
|
409
|
-
/** Present bound nodes, snapping or interpolating according to {@link interpolation}. */
|
|
410
|
-
private _syncBindings;
|
|
411
|
-
private _stepOnce;
|
|
412
|
-
/**
|
|
413
|
-
* Collect the bodies this step touches: non-static and awake. The sub-step
|
|
414
|
-
* integrators and the finalize pass all reject a static or sleeping body
|
|
415
|
-
* anyway, so filtering here changes nothing but how often the rejection is
|
|
416
|
-
* paid - once per step instead of once per body per sub-step.
|
|
417
|
-
*
|
|
418
|
-
* Nothing between this call and the end of the step changes a body's sleep
|
|
419
|
-
* state, so one snapshot serves every pass.
|
|
420
|
-
*
|
|
421
|
-
* A sleeping body needs nothing from the finalize pass: every API that puts a
|
|
422
|
-
* force on a body or teleports it wakes the body first, so it cannot reach
|
|
423
|
-
* this set carrying either, and `_setSleeping` does the rest as it goes to
|
|
424
|
-
* sleep. A static body can, because nothing ever takes it out of this set, so
|
|
425
|
-
* its per-step inputs are dropped here instead - at the same point in the step
|
|
426
|
-
* the finalize pass used to, after the island pass has read the teleport flag.
|
|
427
|
-
*/
|
|
428
|
-
private _collectSteppedBodies;
|
|
429
|
-
/**
|
|
430
|
-
* Link a body to a scene node; the node tracks the body after each step.
|
|
431
|
-
* Destroying the node is enough to end the link - the next step drops it
|
|
432
|
-
* rather than writing into the node's released transform, so an explicit
|
|
433
|
-
* {@link unbind} is only needed to stop tracking a node that stays alive.
|
|
434
|
-
*
|
|
435
|
-
* @throws if `node` is already destroyed.
|
|
436
|
-
*/
|
|
437
|
-
bind(body: PhysicsBody, node: SceneNode): PhysicsBinding;
|
|
438
|
-
/** Remove a body↔node link. */
|
|
439
|
-
unbind(body: PhysicsBody): void;
|
|
440
|
-
/** Colliders containing `point`. Fresh array. */
|
|
441
|
-
queryPoint(point: Readonly<PointLike>, filter?: QueryFilter): Collider[];
|
|
442
|
-
/** Colliders whose AABB overlaps `bounds`. Writes into `out` (cleared) if given. */
|
|
443
|
-
queryAabb(bounds: AabbLike, filter?: QueryFilter, out?: Collider[]): Collider[];
|
|
444
|
-
/** Invoke `callback` for each collider whose AABB overlaps `bounds`. Allocation-free. */
|
|
445
|
-
forEachAabbHit(bounds: AabbLike, filter: QueryFilter | undefined, callback: (collider: Collider) => void): void;
|
|
446
|
-
/** Nearest collider hit by the ray, or `null`. */
|
|
447
|
-
rayCast(origin: Readonly<PointLike>, direction: Readonly<PointLike>, filter?: QueryFilter, maxDistance?: number): RayHit | null;
|
|
448
|
-
/** All collider hits along the ray, sorted by distance. Writes into `out` (cleared) if given. */
|
|
449
|
-
rayCastAll(origin: Readonly<PointLike>, direction: Readonly<PointLike>, filter?: QueryFilter, out?: RayHit[], maxDistance?: number): RayHit[];
|
|
450
|
-
/** Colliders overlapping `shape` placed at `position`/`angle`. Fresh array. */
|
|
451
|
-
overlapShape(shape: AnyShape, position: Readonly<PointLike>, filter?: QueryFilter, angle?: number): Collider[];
|
|
452
|
-
/**
|
|
453
|
-
* Release every body, collider, binding and backend resource. Changes queued
|
|
454
|
-
* from an event callback are applied first; if one of them throws, the world
|
|
455
|
-
* is still fully released and the first such error is rethrown afterwards.
|
|
456
|
-
*/
|
|
457
|
-
destroy(): void;
|
|
458
|
-
/** The detection backend (internal; consumed by the debug draw layer). */
|
|
459
|
-
get backend(): PhysicsBackend;
|
|
460
|
-
private _dispatchEvents;
|
|
461
|
-
/**
|
|
462
|
-
* Accumulate per-body sleep timers and put/keep islands of resting bodies
|
|
463
|
-
* asleep so a stack sleeps and wakes as one unit. An island is a connected
|
|
464
|
-
* component of dynamic bodies joined by touching solid contacts (static and
|
|
465
|
-
* kinematic bodies are boundaries, not nodes); it sleeps once every member has
|
|
466
|
-
* stayed below the sleep thresholds for `timeToSleep`, and wakes the instant
|
|
467
|
-
* any member does (e.g. an awake body merges into it via a new contact).
|
|
468
|
-
* A boundary that is itself moving resets the sleep timer of every dynamic
|
|
469
|
-
* body it touches, so a platform keeps its passengers awake however slowly it
|
|
470
|
-
* travels; so does a contact whose overlap the push-out is still working off,
|
|
471
|
-
* because that push-out moves bodies without showing up in their velocity and
|
|
472
|
-
* a body would otherwise be frozen embedded. Deterministic: union-find roots
|
|
473
|
-
* break ties by lower index and the contact set is id-sorted.
|
|
474
|
-
*/
|
|
475
|
-
private _updateSleeping;
|
|
476
|
-
/**
|
|
477
|
-
* Union dynamic↔dynamic solid contacts into islands. A dynamic body touching a
|
|
478
|
-
* MOVING static/kinematic body has its sleep timer reset instead: those types
|
|
479
|
-
* are island boundaries, not members, so nothing else would keep the passenger
|
|
480
|
-
* of a slow-moving platform awake - and the solver skips a contact whose
|
|
481
|
-
* dynamic side is asleep, letting the platform drive straight through it.
|
|
482
|
-
*
|
|
483
|
-
* The same traversal resets the sleep timer of both sides of a contact the
|
|
484
|
-
* push-out is still working off (see {@link isUnresolved}), so the island it
|
|
485
|
-
* belongs to stays awake until the overlap has reached the depth the contact's
|
|
486
|
-
* own load holds it at.
|
|
487
|
-
*
|
|
488
|
-
* Returns whether any sleep timer was reset.
|
|
489
|
-
*/
|
|
490
|
-
private _unionContactIslands;
|
|
491
|
-
/** Union-find union by lower index (deterministic roots). */
|
|
492
|
-
private _union;
|
|
493
|
-
/** Union-find find with path halving. */
|
|
494
|
-
private _find;
|
|
495
|
-
/** Build each joint's per-frame constraint data and collect the active ones (once per fixed step). */
|
|
496
|
-
private _prepareJoints;
|
|
497
|
-
/** Re-apply each active joint's accumulated impulse (each sub-step). */
|
|
498
|
-
private _warmStartJoints;
|
|
499
|
-
/** One joint velocity pass over the active joints (each sub-step, after the contacts). */
|
|
500
|
-
private _solveJoints;
|
|
501
|
-
/** Whether any dynamic body is flagged for continuous collision (bullet mode). */
|
|
502
|
-
private _hasBullets;
|
|
503
|
-
/** Snapshot each bullet's centre of mass at the start of the fixed step (the swept-test origin). */
|
|
504
|
-
private _recordBulletPositions;
|
|
505
|
-
/**
|
|
506
|
-
* Shape-cast each bullet's colliders along this fixed step's motion against
|
|
507
|
-
* every other body's colliders; if any would cross one, clamp the body at the
|
|
508
|
-
* earliest impact and resolve it about the surface normal (a slide for a
|
|
509
|
-
* non-bouncy body, an elastic reflection as restitution → 1) so it cannot
|
|
510
|
-
* tunnel. The sweep is an exact translation-only cast of the full shapes
|
|
511
|
-
* (Minkowski ray for circles, swept SAT for polygon pairs) - the step's
|
|
512
|
-
* rotation is applied before the sweep, not swept through. Pairs already
|
|
513
|
-
* overlapping at the start of the step are skipped: the discrete solver owns
|
|
514
|
-
* them (that hand-off is what lets a landed bullet rest on real contacts).
|
|
515
|
-
* Filters and sensors behave exactly as in the discrete narrow phase.
|
|
516
|
-
*/
|
|
517
|
-
private _advanceBullets;
|
|
518
|
-
/**
|
|
519
|
-
* Find the earliest impact for a bullet whose colliders translated by
|
|
520
|
-
* `(dx, dy)` this step. Each of the bullet's colliders queries the broad
|
|
521
|
-
* phase with its swept AABB, so the pass costs what the geometry around the
|
|
522
|
-
* bullet's path costs - not one iteration per collider in the world. Returns
|
|
523
|
-
* the blocking collider (with the impact written into {@link _ccdBestHit}),
|
|
524
|
-
* or `null` when nothing blocks the motion.
|
|
525
|
-
*/
|
|
526
|
-
private _sweepBulletColliders;
|
|
527
|
-
/** The highest restitution among a body's colliders (its CCD bounce factor). */
|
|
528
|
-
private _bulletRestitution;
|
|
529
|
-
/** Run `command` now, or queue it when inside an event dispatch (deferred to end of step). */
|
|
530
|
-
private _defer;
|
|
531
|
-
private _drainCommands;
|
|
532
|
-
private _removeBody;
|
|
533
|
-
private _teardownBody;
|
|
534
|
-
/** Drop every joint incident to `body`, releasing the pair claims they held. */
|
|
535
|
-
private _removeJointsOf;
|
|
536
|
-
/** Whether a live joint of this world constrains `body`. */
|
|
537
|
-
private _isJointed;
|
|
538
|
-
private _removeCollider;
|
|
539
|
-
private _detachCollider;
|
|
540
|
-
/** Take a collider (and a chain's edge proxies) out of every world structure, waking what touched it. */
|
|
541
|
-
private _leaveDetection;
|
|
542
|
-
/** Take a body out of the world without destroying it; see {@link remove}. */
|
|
543
|
-
private _detachBody;
|
|
544
|
-
/** Drop one broad-phase leaf: an authored collider, or one chain edge proxy. */
|
|
545
|
-
private _removeDetectionCollider;
|
|
546
|
-
/**
|
|
547
|
-
* The broad-phase leaves of one body - its colliders, with a chain replaced by
|
|
548
|
-
* its edge proxies. Returns pooled scratch, valid until the next call.
|
|
549
|
-
*/
|
|
550
|
-
private _detectionLeavesOf;
|
|
551
|
-
/**
|
|
552
|
-
* Wake every dynamic body still touching `collider` at the moment it leaves
|
|
553
|
-
* the world. A sleeping body's sleep timer is frozen, so the island pass alone
|
|
554
|
-
* can never re-open its sleep decision: losing the support it rested on just
|
|
555
|
-
* removes a contact, and the island (now smaller, or a lone body) still reports
|
|
556
|
-
* a long-expired timer and is put straight back to sleep - a stack whose floor,
|
|
557
|
-
* platform or bottom box is destroyed would hang in mid-air forever. Kinematic
|
|
558
|
-
* and static supports are the sharp edge, since they are island boundaries
|
|
559
|
-
* rather than nodes and so are invisible to wake propagation, but the same hole
|
|
560
|
-
* exists for a dynamic support. Waking the far side of each contact is enough:
|
|
561
|
-
* the woken body's reset timer propagates through the rest of its sleeping
|
|
562
|
-
* island on the next step, exactly like any other wake event.
|
|
563
|
-
*/
|
|
564
|
-
private _wakeTouchingBodies;
|
|
565
|
-
private _assertAlive;
|
|
566
|
-
}
|
|
567
|
-
//# sourceMappingURL=PhysicsWorld.d.ts.map
|