@vworlds/vecs-physics 1.0.37 → 1.0.39
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/adapter/engine.d.ts +14 -4
- package/adapter/engine.js +9 -11
- package/adapter/engine.js.map +1 -1
- package/adapter/queries.d.ts +1 -1
- package/adapter/queries.js +1 -1
- package/adapter/queries.js.map +1 -1
- package/adapter/runtime.js +1 -1
- package/adapter/runtime.js.map +1 -1
- package/{components/body.js → body/components.js} +2 -2
- package/body/components.js.map +1 -0
- package/body/lifecycle.d.ts +4 -0
- package/body/lifecycle.js +153 -0
- package/body/lifecycle.js.map +1 -0
- package/body/mass.d.ts +4 -0
- package/body/mass.js +45 -0
- package/body/mass.js.map +1 -0
- package/body/module.d.ts +4 -0
- package/body/module.js +22 -0
- package/body/module.js.map +1 -0
- package/body/pose_in.d.ts +4 -0
- package/body/pose_in.js +90 -0
- package/body/pose_in.js.map +1 -0
- package/body/pose_out.d.ts +4 -0
- package/body/pose_out.js +59 -0
- package/body/pose_out.js.map +1 -0
- package/{components/body_tuning.js → body/tuning.js} +1 -1
- package/body/tuning.js.map +1 -0
- package/core/module.d.ts +30 -0
- package/core/module.js +77 -0
- package/core/module.js.map +1 -0
- package/core/reaper.d.ts +4 -0
- package/core/reaper.js +45 -0
- package/core/reaper.js.map +1 -0
- package/core/step.d.ts +4 -0
- package/core/step.js +22 -0
- package/core/step.js.map +1 -0
- package/debug/validation.d.ts +4 -0
- package/{systems/debug.js → debug/validation.js} +51 -35
- package/debug/validation.js.map +1 -0
- package/{components/events.js → events/components.js} +1 -1
- package/events/components.js.map +1 -0
- package/events/module.d.ts +4 -0
- package/events/module.js +13 -0
- package/events/module.js.map +1 -0
- package/events/opt_in.d.ts +4 -0
- package/events/opt_in.js +86 -0
- package/events/opt_in.js.map +1 -0
- package/events/publish.d.ts +4 -0
- package/{systems/events.js → events/publish.js} +43 -34
- package/events/publish.js.map +1 -0
- package/{components/force.js → forces/components.js} +1 -1
- package/forces/components.js.map +1 -0
- package/forces/gather.d.ts +4 -0
- package/forces/gather.js +42 -0
- package/forces/gather.js.map +1 -0
- package/forces/impulses.d.ts +4 -0
- package/forces/impulses.js +79 -0
- package/forces/impulses.js.map +1 -0
- package/forces/module.d.ts +4 -0
- package/forces/module.js +20 -0
- package/forces/module.js.map +1 -0
- package/forces/zero.d.ts +4 -0
- package/forces/zero.js +34 -0
- package/forces/zero.js.map +1 -0
- package/index.d.ts +9 -8
- package/index.js +10 -8
- package/index.js.map +1 -1
- package/joints/components.d.ts +116 -0
- package/joints/components.js +150 -0
- package/joints/components.js.map +1 -0
- package/joints/features.d.ts +4 -0
- package/joints/features.js +158 -0
- package/joints/features.js.map +1 -0
- package/joints/lifecycle.d.ts +4 -0
- package/joints/lifecycle.js +191 -0
- package/joints/lifecycle.js.map +1 -0
- package/joints/module.d.ts +4 -0
- package/joints/module.js +33 -0
- package/joints/module.js.map +1 -0
- package/joints/predicates.d.ts +9 -0
- package/joints/predicates.js +10 -0
- package/joints/predicates.js.map +1 -0
- package/{components/target.js → kinematic/components.js} +1 -1
- package/kinematic/components.js.map +1 -0
- package/kinematic/module.d.ts +4 -0
- package/kinematic/module.js +16 -0
- package/kinematic/module.js.map +1 -0
- package/kinematic/targets.d.ts +4 -0
- package/{systems/kinematic.js → kinematic/targets.js} +27 -20
- package/kinematic/targets.js.map +1 -0
- package/{components/material.js → materials/components.js} +1 -1
- package/materials/components.js.map +1 -0
- package/materials/module.d.ts +4 -0
- package/materials/module.js +18 -0
- package/materials/module.js.map +1 -0
- package/materials/sync.d.ts +4 -0
- package/materials/sync.js +136 -0
- package/materials/sync.js.map +1 -0
- package/module.d.ts +3 -27
- package/module.js +45 -141
- package/module.js.map +1 -1
- package/package.json +2 -2
- package/shapes/chain.d.ts +8 -0
- package/{systems/chain_lifecycle.js → shapes/chain.js} +41 -31
- package/shapes/chain.js.map +1 -0
- package/{components/geometry.js → shapes/components.js} +2 -2
- package/{components/geometry.js.map → shapes/components.js.map} +1 -1
- package/{systems/shape_lifecycle.d.ts → shapes/lifecycle.d.ts} +7 -5
- package/{systems/shape_lifecycle.js → shapes/lifecycle.js} +53 -42
- package/shapes/lifecycle.js.map +1 -0
- package/shapes/module.d.ts +4 -0
- package/shapes/module.js +34 -0
- package/shapes/module.js.map +1 -0
- package/{components/shape_pose.js → shapes/pose_components.js} +1 -1
- package/shapes/pose_components.js.map +1 -0
- package/shapes/pose_sync.d.ts +4 -0
- package/shapes/pose_sync.js +70 -0
- package/shapes/pose_sync.js.map +1 -0
- package/{systems/shape_predicates.d.ts → shapes/predicates.d.ts} +2 -2
- package/{systems/shape_predicates.js → shapes/predicates.js} +3 -3
- package/shapes/predicates.js.map +1 -0
- package/util/resolve_body.js +1 -1
- package/components/body.js.map +0 -1
- package/components/body_tuning.js.map +0 -1
- package/components/events.js.map +0 -1
- package/components/force.js.map +0 -1
- package/components/material.js.map +0 -1
- package/components/shape_pose.js.map +0 -1
- package/components/target.js.map +0 -1
- package/systems/chain_lifecycle.d.ts +0 -6
- package/systems/chain_lifecycle.js.map +0 -1
- package/systems/debug.d.ts +0 -4
- package/systems/debug.js.map +0 -1
- package/systems/event_opt_in_sync.d.ts +0 -3
- package/systems/event_opt_in_sync.js +0 -73
- package/systems/event_opt_in_sync.js.map +0 -1
- package/systems/events.d.ts +0 -3
- package/systems/events.js.map +0 -1
- package/systems/forces.d.ts +0 -3
- package/systems/forces.js +0 -35
- package/systems/forces.js.map +0 -1
- package/systems/impulse_accumulate.d.ts +0 -4
- package/systems/impulse_accumulate.js +0 -74
- package/systems/impulse_accumulate.js.map +0 -1
- package/systems/impulse_zero.d.ts +0 -3
- package/systems/impulse_zero.js +0 -27
- package/systems/impulse_zero.js.map +0 -1
- package/systems/index.d.ts +0 -15
- package/systems/index.js +0 -80
- package/systems/index.js.map +0 -1
- package/systems/kinematic.d.ts +0 -3
- package/systems/kinematic.js.map +0 -1
- package/systems/lifecycle.d.ts +0 -4
- package/systems/lifecycle.js +0 -177
- package/systems/lifecycle.js.map +0 -1
- package/systems/mass_recompute.d.ts +0 -3
- package/systems/mass_recompute.js +0 -38
- package/systems/mass_recompute.js.map +0 -1
- package/systems/material_filter_sync.d.ts +0 -3
- package/systems/material_filter_sync.js +0 -129
- package/systems/material_filter_sync.js.map +0 -1
- package/systems/pose_sync_in.d.ts +0 -3
- package/systems/pose_sync_in.js +0 -79
- package/systems/pose_sync_in.js.map +0 -1
- package/systems/pose_sync_out.d.ts +0 -3
- package/systems/pose_sync_out.js +0 -52
- package/systems/pose_sync_out.js.map +0 -1
- package/systems/shape_lifecycle.js.map +0 -1
- package/systems/shape_pose_sync.d.ts +0 -3
- package/systems/shape_pose_sync.js +0 -63
- package/systems/shape_pose_sync.js.map +0 -1
- package/systems/shape_predicates.js.map +0 -1
- package/systems/step.d.ts +0 -3
- package/systems/step.js +0 -15
- package/systems/step.js.map +0 -1
- /package/{components/body.d.ts → body/components.d.ts} +0 -0
- /package/{components/body_tuning.d.ts → body/tuning.d.ts} +0 -0
- /package/{components/events.d.ts → events/components.d.ts} +0 -0
- /package/{components/force.d.ts → forces/components.d.ts} +0 -0
- /package/{components/target.d.ts → kinematic/components.d.ts} +0 -0
- /package/{components/material.d.ts → materials/components.d.ts} +0 -0
- /package/{components/geometry.d.ts → shapes/components.d.ts} +0 -0
- /package/{components/shape_pose.d.ts → shapes/pose_components.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../../src/kinematic/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,OAAO,eAAgB,SAAQ,MAAM;IAClC,IAAI;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAChC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAEzB,KAAK,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;QACzC,KAAK,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC;QAEzC,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Module } from "@vworlds/vecs";
|
|
2
|
+
import { getPhysicsEngine, PhysicsSystemTag, } from "../adapter/engine.js";
|
|
3
|
+
import { Body } from "../body/components.js";
|
|
4
|
+
import { KinematicTargetPosition, KinematicTargetRotation } from "./components.js";
|
|
3
5
|
import { scr_b2Vec2 } from "../adapter/runtime.js";
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.with({ all: [Body, { any: [KinematicTargetPosition, KinematicTargetRotation] }] })
|
|
13
|
-
.phase(phase)
|
|
14
|
-
.each([Body, KinematicTargetPosition, KinematicTargetRotation], (_entity, [body, positionTarget, rotationTarget]) => {
|
|
15
|
-
const bodyId = body._bodyId;
|
|
16
|
-
if (bodyId === undefined || !isKinematicBody(engine, bodyId)) {
|
|
6
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
7
|
+
export class KinematicTargetsModule extends Module {
|
|
8
|
+
init() {
|
|
9
|
+
const world = this.world;
|
|
10
|
+
world.module(PhysicsCoreModule);
|
|
11
|
+
const engine = getPhysicsEngine(world);
|
|
12
|
+
const dt = engine.fixedTimeStep;
|
|
13
|
+
if (dt <= 0) {
|
|
17
14
|
return;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
world
|
|
17
|
+
.system("PhysicsKinematicTargets")
|
|
18
|
+
.with({ all: [Body, { any: [KinematicTargetPosition, KinematicTargetRotation] }] })
|
|
19
|
+
.phase(engine.phases.preStep)
|
|
20
|
+
.each([Body, KinematicTargetPosition, KinematicTargetRotation], (_entity, [body, positionTarget, rotationTarget]) => {
|
|
21
|
+
const bodyId = body._bodyId;
|
|
22
|
+
if (bodyId === undefined || !isKinematicBody(engine, bodyId)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
drivePositionTarget(engine, bodyId, positionTarget, dt);
|
|
26
|
+
driveRotationTarget(engine, bodyId, rotationTarget, dt);
|
|
27
|
+
})
|
|
28
|
+
.add(PhysicsSystemTag);
|
|
29
|
+
}
|
|
23
30
|
}
|
|
24
31
|
function drivePositionTarget(engine, bodyId, target, dt) {
|
|
25
32
|
if (target === undefined) {
|
|
@@ -85,4 +92,4 @@ function wrap(value, min, max) {
|
|
|
85
92
|
const range = max - min;
|
|
86
93
|
return ((((value - min) % range) + range) % range) + min;
|
|
87
94
|
}
|
|
88
|
-
//# sourceMappingURL=
|
|
95
|
+
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../../../../src/kinematic/targets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GAGjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,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,IAAI,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IACnD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,CAAC;IACxB,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../../../src/materials/components.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,6EAA6E;AAC7E,oEAAoE;AACpE,EAAE;AACF,4EAA4E;AAC5E,0EAA0E;AAC1E,+EAA+E;AAC/E,2EAA2E;AAC3E,4DAA4D;AAE5D,+EAA+E;AAC/E,MAAM,OAAO,QAAQ;IAArB;QACE,YAAO,GAAG,CAAC,CAAC;QACZ,aAAQ,GAAG,GAAG,CAAC;QACf,gBAAW,GAAG,CAAC,CAAC;QAChB,sBAAiB,GAAG,CAAC,CAAC;QACtB,iBAAY,GAAG,CAAC,CAAC;QACjB,mBAAc,GAAG,CAAC,CAAC;IACrB,CAAC;CAAA;AAED,kFAAkF;AAClF,MAAM,OAAO,eAAe;IAA5B;QACE,iBAAY,GAAG,CAAC,CAAC;QACjB,aAAQ,GAAG,UAAU,CAAC;QACtB,eAAU,GAAG,CAAC,CAAC;IACjB,CAAC;CAAA;AAED,uEAAuE;AACvE,MAAM,OAAO,MAAM;CAAG;AAEtB;;8EAE8E;AAC9E,MAAM,OAAO,UAAU;CAAG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Module } from "@vworlds/vecs";
|
|
2
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
3
|
+
import { ShapesModule } from "../shapes/module.js";
|
|
4
|
+
import { CollisionFilter, Detectable, Material, Sensor } from "./components.js";
|
|
5
|
+
import { MaterialFilterSyncModule } from "./sync.js";
|
|
6
|
+
export class MaterialsModule extends Module {
|
|
7
|
+
init() {
|
|
8
|
+
const world = this.world;
|
|
9
|
+
world.module(PhysicsCoreModule);
|
|
10
|
+
world.module(ShapesModule);
|
|
11
|
+
world.component(Material);
|
|
12
|
+
world.component(CollisionFilter);
|
|
13
|
+
world.component(Sensor);
|
|
14
|
+
world.component(Detectable);
|
|
15
|
+
world.module(MaterialFilterSyncModule);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../../src/materials/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAErD,MAAM,OAAO,eAAgB,SAAQ,MAAM;IAClC,IAAI;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAChC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAE3B,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC1B,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QACjC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAE5B,KAAK,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ChildOf, Iter, Module } from "@vworlds/vecs";
|
|
2
|
+
import { getPhysicsEngine, PhysicsSystemTag } from "../adapter/engine.js";
|
|
3
|
+
import { Body } from "../body/components.js";
|
|
4
|
+
import { Chain, SingleShape } from "../shapes/components.js";
|
|
5
|
+
import { CollisionFilter, Material, Sensor } from "./components.js";
|
|
6
|
+
import { withAllocated } from "../adapter/disposal.js";
|
|
7
|
+
import { PhysicsCoreModule } from "../core/module.js";
|
|
8
|
+
import { recreateChainForEntity } from "../shapes/chain.js";
|
|
9
|
+
import { recreateSingleShapeForEntity } from "../shapes/lifecycle.js";
|
|
10
|
+
import { chainWithBodyParent, singleShapeWithBodyParent } from "../shapes/predicates.js";
|
|
11
|
+
export class MaterialFilterSyncModule extends Module {
|
|
12
|
+
init() {
|
|
13
|
+
const world = this.world;
|
|
14
|
+
world.module(PhysicsCoreModule);
|
|
15
|
+
const engine = getPhysicsEngine(world);
|
|
16
|
+
const phase = engine.phases.preStep;
|
|
17
|
+
world
|
|
18
|
+
.system("PhysicsMaterialFilterSync:Material")
|
|
19
|
+
.with(Material, singleShapeWithBodyParent)
|
|
20
|
+
.phase(phase)
|
|
21
|
+
.update({
|
|
22
|
+
watch: Material,
|
|
23
|
+
onEnter: true,
|
|
24
|
+
cursor: Iter,
|
|
25
|
+
inject: [SingleShape, { target: [ChildOf, [Body]] }],
|
|
26
|
+
}, (it, material, [shape, body]) => {
|
|
27
|
+
if (requiresMaterialRecreate(engine, shape, material)) {
|
|
28
|
+
// box2d3-wasm@5.2.0 exposes no shape setters for rollingResistance,
|
|
29
|
+
// tangentSpeed, or userMaterialId, so those updates recreate the shape.
|
|
30
|
+
recreateSingleShapeForEntity(engine, it.entity, it.src[1], body, shape);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const shapeId = shape?._shapeId;
|
|
34
|
+
if (shapeId !== undefined) {
|
|
35
|
+
engine.box2d.b2Shape_SetDensity(shapeId, material.density, true);
|
|
36
|
+
engine.box2d.b2Shape_SetFriction(shapeId, material.friction);
|
|
37
|
+
engine.box2d.b2Shape_SetRestitution(shapeId, material.restitution);
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
.add(PhysicsSystemTag);
|
|
41
|
+
world
|
|
42
|
+
.system("PhysicsMaterialFilterSync:ChainMaterial")
|
|
43
|
+
.with(Material, chainWithBodyParent)
|
|
44
|
+
.phase(phase)
|
|
45
|
+
.update({
|
|
46
|
+
watch: Material,
|
|
47
|
+
onEnter: true,
|
|
48
|
+
cursor: Iter,
|
|
49
|
+
inject: [Chain, { target: [ChildOf, [Body]] }],
|
|
50
|
+
}, (it, _material, [chain, body]) => {
|
|
51
|
+
recreateChainForEntity(engine, it.entity, it.src[1], body, chain);
|
|
52
|
+
})
|
|
53
|
+
.add(PhysicsSystemTag);
|
|
54
|
+
world
|
|
55
|
+
.system("PhysicsMaterialFilterSync:CollisionFilter")
|
|
56
|
+
.with(CollisionFilter, singleShapeWithBodyParent)
|
|
57
|
+
.phase(phase)
|
|
58
|
+
.update({
|
|
59
|
+
watch: CollisionFilter,
|
|
60
|
+
onEnter: true,
|
|
61
|
+
cursor: Iter,
|
|
62
|
+
inject: [SingleShape, { target: [ChildOf, [Body]] }],
|
|
63
|
+
}, (_it, filter, [shape]) => {
|
|
64
|
+
const shapeId = shape?._shapeId;
|
|
65
|
+
if (shapeId !== undefined) {
|
|
66
|
+
withAllocated(() => new engine.box2d.b2Filter(), (wasmFilter) => {
|
|
67
|
+
// Public filters are 32-bit numbers; Box2D stores 64-bit masks. The
|
|
68
|
+
// decimal string setters zero-pad the upper 32 bits explicitly.
|
|
69
|
+
wasmFilter.setCategoryBits64(String(filter.categoryBits >>> 0));
|
|
70
|
+
wasmFilter.setMaskBits64(String(filter.maskBits >>> 0));
|
|
71
|
+
wasmFilter.groupIndex = filter.groupIndex;
|
|
72
|
+
engine.box2d.b2Shape_SetFilter(shapeId, wasmFilter);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.add(PhysicsSystemTag);
|
|
77
|
+
world
|
|
78
|
+
.system("PhysicsMaterialFilterSync:ChainCollisionFilter")
|
|
79
|
+
.with(CollisionFilter, chainWithBodyParent)
|
|
80
|
+
.phase(phase)
|
|
81
|
+
.update({
|
|
82
|
+
watch: CollisionFilter,
|
|
83
|
+
onEnter: true,
|
|
84
|
+
cursor: Iter,
|
|
85
|
+
inject: [Chain, { target: [ChildOf, [Body]] }],
|
|
86
|
+
}, (it, _filter, [chain, body]) => {
|
|
87
|
+
recreateChainForEntity(engine, it.entity, it.src[1], body, chain);
|
|
88
|
+
})
|
|
89
|
+
.add(PhysicsSystemTag);
|
|
90
|
+
world
|
|
91
|
+
.system("PhysicsMaterialFilterSync:Sensor")
|
|
92
|
+
.with(Sensor, singleShapeWithBodyParent)
|
|
93
|
+
.phase(phase)
|
|
94
|
+
.update({
|
|
95
|
+
watch: Sensor,
|
|
96
|
+
onEnter: true,
|
|
97
|
+
cursor: Iter,
|
|
98
|
+
inject: [SingleShape, { target: [ChildOf, [Body]] }],
|
|
99
|
+
}, (it, _sensor, [shape, body]) => {
|
|
100
|
+
recreateSingleShapeForEntity(engine, it.entity, it.src[1], body, shape);
|
|
101
|
+
})
|
|
102
|
+
.add(PhysicsSystemTag);
|
|
103
|
+
world
|
|
104
|
+
.system("PhysicsMaterialFilterSync:ChainSensor")
|
|
105
|
+
.with(Sensor, chainWithBodyParent)
|
|
106
|
+
.phase(phase)
|
|
107
|
+
.update({
|
|
108
|
+
watch: Sensor,
|
|
109
|
+
onEnter: true,
|
|
110
|
+
cursor: Iter,
|
|
111
|
+
inject: [Chain, { target: [ChildOf, [Body]] }],
|
|
112
|
+
}, (it, _sensor, [chain, body]) => {
|
|
113
|
+
recreateChainForEntity(engine, it.entity, it.src[1], body, chain);
|
|
114
|
+
})
|
|
115
|
+
.add(PhysicsSystemTag);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function requiresMaterialRecreate(engine, shape, next) {
|
|
119
|
+
if (shape === undefined) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const shapeId = shape._shapeId;
|
|
123
|
+
if (shapeId === undefined || !engine.box2d.b2Shape_IsValid(shapeId)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const materialData = engine.box2d.b2Shape_GetSurfaceMaterial(shapeId);
|
|
127
|
+
try {
|
|
128
|
+
return (materialData.rollingResistance !== next.rollingResistance ||
|
|
129
|
+
materialData.tangentSpeed !== next.tangentSpeed ||
|
|
130
|
+
Number(materialData.userMaterialId) !== next.userMaterialId);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
materialData.delete();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../../src/materials/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzF,MAAM,OAAO,wBAAyB,SAAQ,MAAM;IAC3C,IAAI;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,KA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,EAAE,CAAC;QACpE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACtE,IAAI,CAAC;QACH,OAAO,CACL,YAAY,CAAC,iBAAiB,KAAK,IAAI,CAAC,iBAAiB;YACzD,YAAY,CAAC,YAAY,KAAK,IAAI,CAAC,YAAY;YAC/C,MAAM,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC,cAAc,CAC5D,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;AACH,CAAC"}
|
package/module.d.ts
CHANGED
|
@@ -1,30 +1,6 @@
|
|
|
1
|
-
import { Module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type PhysicsOptions = {
|
|
5
|
-
gravity?: {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
};
|
|
9
|
-
fixedTimeStep?: number;
|
|
10
|
-
subSteps?: number;
|
|
11
|
-
debug?: boolean;
|
|
12
|
-
/** Override the warning sink used by `PhysicsDebugValidation` when
|
|
13
|
-
* `debug: true`. Accepts any `(message: string) => void` callback.
|
|
14
|
-
* Primarily for tests; defaults to `console.warn`. */
|
|
15
|
-
debugSink?: (message: string) => void;
|
|
16
|
-
preStepPhase?: Entity | string;
|
|
17
|
-
stepPhase?: Entity | string;
|
|
18
|
-
postStepPhase?: Entity | string;
|
|
19
|
-
restitutionThreshold?: number;
|
|
20
|
-
hitEventThreshold?: number;
|
|
21
|
-
contactHertz?: number;
|
|
22
|
-
contactDampingRatio?: number;
|
|
23
|
-
contactSpeed?: number;
|
|
24
|
-
maximumLinearSpeed?: number;
|
|
25
|
-
enableSleep?: boolean;
|
|
26
|
-
enableContinuous?: boolean;
|
|
27
|
-
};
|
|
1
|
+
import { Module } from "@vworlds/vecs";
|
|
2
|
+
import { type PhysicsOptions } from "./core/module.js";
|
|
3
|
+
export type { PhysicsOptions } from "./core/module.js";
|
|
28
4
|
/** World module that installs physics when registered with `world.module`. */
|
|
29
5
|
export declare class PhysicsModule extends Module<PhysicsOptions | undefined> {
|
|
30
6
|
init(options: PhysicsOptions | undefined): void;
|
package/module.js
CHANGED
|
@@ -1,147 +1,51 @@
|
|
|
1
|
-
// `PhysicsModule`
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
const DEFAULT_PRE_STEP_PHASE = "physics-pre";
|
|
25
|
-
const DEFAULT_STEP_PHASE = "physics-step";
|
|
26
|
-
const DEFAULT_POST_STEP_PHASE = "physics-post";
|
|
1
|
+
// `PhysicsModule` is the public umbrella for vecs-physics. It keeps startup to
|
|
2
|
+
// `await preloadPhysics(); world.module(PhysicsModule, options);` while the
|
|
3
|
+
// implementation is split into feature modules that own their components and
|
|
4
|
+
// systems.
|
|
5
|
+
import { Module } from "@vworlds/vecs";
|
|
6
|
+
import { BodyMassModule } from "./body/mass.js";
|
|
7
|
+
import { BodyModule } from "./body/module.js";
|
|
8
|
+
import { BodyPoseInModule } from "./body/pose_in.js";
|
|
9
|
+
import { BodyPoseOutModule } from "./body/pose_out.js";
|
|
10
|
+
import { PhysicsCoreModule } from "./core/module.js";
|
|
11
|
+
import { PhysicsReaperModule } from "./core/reaper.js";
|
|
12
|
+
import { PhysicsStepModule } from "./core/step.js";
|
|
13
|
+
import { DebugModule } from "./debug/validation.js";
|
|
14
|
+
import { EventsModule } from "./events/module.js";
|
|
15
|
+
import { EventOptInModule } from "./events/opt_in.js";
|
|
16
|
+
import { EventPublishModule } from "./events/publish.js";
|
|
17
|
+
import { ForcesModule } from "./forces/module.js";
|
|
18
|
+
import { ImpulseZeroModule } from "./forces/zero.js";
|
|
19
|
+
import { JointsModule } from "./joints/module.js";
|
|
20
|
+
import { KinematicModule } from "./kinematic/module.js";
|
|
21
|
+
import { MaterialsModule } from "./materials/module.js";
|
|
22
|
+
import { ShapesModule } from "./shapes/module.js";
|
|
23
|
+
import { ShapePoseModule } from "./shapes/pose_sync.js";
|
|
27
24
|
/** World module that installs physics when registered with `world.module`. */
|
|
28
25
|
export class PhysicsModule extends Module {
|
|
29
26
|
init(options) {
|
|
30
|
-
|
|
27
|
+
const world = this.world;
|
|
28
|
+
world.module(PhysicsCoreModule, options ?? {});
|
|
29
|
+
// physics-pre: lifecycle + sync systems in dependency order.
|
|
30
|
+
world.module(BodyModule);
|
|
31
|
+
world.module(ShapesModule);
|
|
32
|
+
world.module(JointsModule);
|
|
33
|
+
world.module(MaterialsModule);
|
|
34
|
+
world.module(EventsModule);
|
|
35
|
+
world.module(EventOptInModule);
|
|
36
|
+
world.module(PhysicsReaperModule);
|
|
37
|
+
world.module(ShapePoseModule);
|
|
38
|
+
world.module(BodyPoseInModule);
|
|
39
|
+
world.module(KinematicModule);
|
|
40
|
+
world.module(ForcesModule);
|
|
41
|
+
world.module(BodyMassModule);
|
|
42
|
+
world.module(DebugModule);
|
|
43
|
+
// physics-step: integrator.
|
|
44
|
+
world.module(PhysicsStepModule);
|
|
45
|
+
// physics-post: writeback, events, and one-shot cleanup.
|
|
46
|
+
world.module(BodyPoseOutModule);
|
|
47
|
+
world.module(EventPublishModule);
|
|
48
|
+
world.module(ImpulseZeroModule);
|
|
31
49
|
}
|
|
32
50
|
}
|
|
33
|
-
function registerPhysics(world, opts) {
|
|
34
|
-
if (hasPhysicsEngine(world)) {
|
|
35
|
-
throw new Error("PhysicsModule has already been registered on this world");
|
|
36
|
-
}
|
|
37
|
-
// 1. Register every public component, in a stable order (see file header).
|
|
38
|
-
// `ChildOf` is built into Vecs: referenced, never registered.
|
|
39
|
-
world.component(Position);
|
|
40
|
-
world.component(Rotation);
|
|
41
|
-
world.component(LinearVelocity);
|
|
42
|
-
world.component(AngularVelocity);
|
|
43
|
-
world.component(Body);
|
|
44
|
-
world.component(Damping);
|
|
45
|
-
world.component(GravityScale);
|
|
46
|
-
world.component(MotionLocks);
|
|
47
|
-
world.component(Sleep);
|
|
48
|
-
world.component(ShapePosition);
|
|
49
|
-
world.component(ShapeRotation);
|
|
50
|
-
world.component(Shape);
|
|
51
|
-
world.component(SingleShape);
|
|
52
|
-
world.component(Box);
|
|
53
|
-
world.component(Circle);
|
|
54
|
-
world.component(Capsule);
|
|
55
|
-
world.component(Segment);
|
|
56
|
-
world.component(Polygon);
|
|
57
|
-
world.component(Chain);
|
|
58
|
-
world.component(Material);
|
|
59
|
-
world.component(CollisionFilter);
|
|
60
|
-
world.component(Sensor);
|
|
61
|
-
world.component(Detectable);
|
|
62
|
-
world.component(Force);
|
|
63
|
-
world.component(Torque);
|
|
64
|
-
world.component(Impulse);
|
|
65
|
-
world.component(AngularImpulse);
|
|
66
|
-
world.component(KinematicTargetPosition);
|
|
67
|
-
world.component(KinematicTargetRotation);
|
|
68
|
-
world.component(ContactEvents);
|
|
69
|
-
world.component(SensorEvents);
|
|
70
|
-
world.component(HitEvents);
|
|
71
|
-
// 2. Internal, non-exported components (`PhysicsEngine`, `PhysicsSystemTag`),
|
|
72
|
-
// registered in their documented order for deterministic type ids.
|
|
73
|
-
registerInternalComponents(world);
|
|
74
|
-
// 3. Geometry components implement `Shape` through either the internal
|
|
75
|
-
// `SingleShape` tier or Chain's direct umbrella implementation. This keeps
|
|
76
|
-
// geometry exclusivity while letting b2Shape-only systems query only singles.
|
|
77
|
-
world.component(SingleShape).set(Implements, { interfaces: [Shape] });
|
|
78
|
-
world.component(Box).set(Implements, { interfaces: [SingleShape] });
|
|
79
|
-
world.component(Circle).set(Implements, { interfaces: [SingleShape] });
|
|
80
|
-
world.component(Capsule).set(Implements, { interfaces: [SingleShape] });
|
|
81
|
-
world.component(Segment).set(Implements, { interfaces: [SingleShape] });
|
|
82
|
-
world.component(Polygon).set(Implements, { interfaces: [SingleShape] });
|
|
83
|
-
world.component(Chain).set(Implements, { interfaces: [Shape] });
|
|
84
|
-
// 4. Ensure the three physics phase entities exist and are ordered after update.
|
|
85
|
-
const preStep = resolvePhase(world, opts.preStepPhase, DEFAULT_PRE_STEP_PHASE);
|
|
86
|
-
const step = resolvePhase(world, opts.stepPhase, DEFAULT_STEP_PHASE);
|
|
87
|
-
const postStep = resolvePhase(world, opts.postStepPhase, DEFAULT_POST_STEP_PHASE);
|
|
88
|
-
const updatePhase = world.entity(ON_UPDATE);
|
|
89
|
-
insertPhaseAfter(preStep, updatePhase);
|
|
90
|
-
insertPhaseAfter(step, preStep);
|
|
91
|
-
insertPhaseAfter(postStep, step);
|
|
92
|
-
// 5. Allocate WASM engine, create the Box2D world, register the systems (bound
|
|
93
|
-
// to it), then attach it.
|
|
94
|
-
const box2d = getBox2D();
|
|
95
|
-
const options = resolveOptions(opts);
|
|
96
|
-
const engine = new PhysicsEngine(box2d, options, opts.debugSink);
|
|
97
|
-
engine.worldId = createWorldId(engine, options);
|
|
98
|
-
registerImpulseHooks(world, engine);
|
|
99
|
-
registerPhysicsSystems(world, engine, { preStep, step, postStep }, {
|
|
100
|
-
debug: opts.debug ?? false,
|
|
101
|
-
});
|
|
102
|
-
attachPhysicsEngine(world, engine);
|
|
103
|
-
}
|
|
104
|
-
function createWorldId(engine, options) {
|
|
105
|
-
const box2d = engine.box2d;
|
|
106
|
-
return withAllocated(box2d.b2DefaultWorldDef, (def) => {
|
|
107
|
-
def.gravity.x = options.gravityX;
|
|
108
|
-
def.gravity.y = options.gravityY;
|
|
109
|
-
def.restitutionThreshold = options.restitutionThreshold;
|
|
110
|
-
def.hitEventThreshold = options.hitEventThreshold;
|
|
111
|
-
def.contactHertz = options.contactHertz;
|
|
112
|
-
def.contactDampingRatio = options.contactDampingRatio;
|
|
113
|
-
def.maximumLinearSpeed = options.maximumLinearSpeed;
|
|
114
|
-
def.enableSleep = options.enableSleep;
|
|
115
|
-
def.enableContinuous = options.enableContinuous;
|
|
116
|
-
const worldId = box2d.b2CreateWorld(def);
|
|
117
|
-
box2d.b2World_SetContactTuning(worldId, options.contactHertz, options.contactDampingRatio, options.contactSpeed);
|
|
118
|
-
return worldId;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/** Resolve a phase placement option to a concrete phase entity. */
|
|
122
|
-
function resolvePhase(world, given, defaultName) {
|
|
123
|
-
const phase = typeof given === "string" || given === undefined ? world.entity(given ?? defaultName) : given;
|
|
124
|
-
phase.add(Phase);
|
|
125
|
-
return phase;
|
|
126
|
-
}
|
|
127
|
-
/** Apply Box2D-aligned defaults to `opts`. */
|
|
128
|
-
function resolveOptions(opts) {
|
|
129
|
-
return {
|
|
130
|
-
gravityX: opts.gravity?.x ?? 0,
|
|
131
|
-
gravityY: opts.gravity?.y ?? -10,
|
|
132
|
-
fixedTimeStep: opts.fixedTimeStep ?? 1 / 60,
|
|
133
|
-
subSteps: opts.subSteps ?? 4,
|
|
134
|
-
debug: opts.debug ?? false,
|
|
135
|
-
restitutionThreshold: opts.restitutionThreshold ?? 1.0,
|
|
136
|
-
// box2d b2DefaultWorldDef: def.hitEventThreshold = 1.0f * lengthUnits (types.c:16).
|
|
137
|
-
hitEventThreshold: opts.hitEventThreshold ?? 1.0,
|
|
138
|
-
contactHertz: opts.contactHertz ?? 30,
|
|
139
|
-
contactDampingRatio: opts.contactDampingRatio ?? 10,
|
|
140
|
-
// box2d b2DefaultWorldDef: def.contactSpeed = 3.0f * lengthUnits (types.c:18).
|
|
141
|
-
contactSpeed: opts.contactSpeed ?? 3.0,
|
|
142
|
-
maximumLinearSpeed: opts.maximumLinearSpeed ?? 400,
|
|
143
|
-
enableSleep: opts.enableSleep ?? true,
|
|
144
|
-
enableContinuous: opts.enableContinuous ?? true,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
51
|
//# sourceMappingURL=module.js.map
|
package/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/module.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/module.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,WAAW;AAEX,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAuB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MA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|
|
1
1
|
{
|
|
2
2
|
"name": "@vworlds/vecs-physics",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "git+https://github.com/vworlds/vecs.git"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@vworlds/vecs": "1.0.
|
|
18
|
+
"@vworlds/vecs": "1.0.39",
|
|
19
19
|
"box2d3-wasm": "^5.2.0"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Module, type Entity } from "@vworlds/vecs";
|
|
2
|
+
import { type PhysicsEngine } from "../adapter/engine.js";
|
|
3
|
+
import { Body } from "../body/components.js";
|
|
4
|
+
import { Chain } from "./components.js";
|
|
5
|
+
export declare class ChainLifecycleModule extends Module {
|
|
6
|
+
init(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function recreateChainForEntity(engine: PhysicsEngine, entity: Entity, parentEntity: Entity | undefined, parentBody: Body | undefined, chain: Chain | undefined): void;
|