@cyclonium/physics-2d 0.0.100
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/lib/body-collider-link.d.ts +32 -0
- package/lib/body-collider-link.js +164 -0
- package/lib/character-controller-2d.d.ts +69 -0
- package/lib/character-controller-2d.js +399 -0
- package/lib/collider-2d.d.ts +81 -0
- package/lib/collider-2d.js +364 -0
- package/lib/colliders/box-collider-2d.d.ts +20 -0
- package/lib/colliders/box-collider-2d.js +84 -0
- package/lib/colliders/capsule-collider-2d.d.ts +17 -0
- package/lib/colliders/capsule-collider-2d.js +78 -0
- package/lib/colliders/circle-collider-2d.d.ts +14 -0
- package/lib/colliders/circle-collider-2d.js +59 -0
- package/lib/colliders/polygon-collider-2d.d.ts +17 -0
- package/lib/colliders/polygon-collider-2d.js +77 -0
- package/lib/collision-matrix.d.ts +12 -0
- package/lib/collision-matrix.js +70 -0
- package/lib/contact.d.ts +7 -0
- package/lib/contact.js +2 -0
- package/lib/exchange.d.ts +5 -0
- package/lib/exchange.js +23 -0
- package/lib/gizmo-headless.d.ts +7 -0
- package/lib/gizmo-headless.js +7 -0
- package/lib/gizmo.d.ts +13 -0
- package/lib/gizmo.js +122 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +20 -0
- package/lib/physics-2d-debugger-headless.d.ts +6 -0
- package/lib/physics-2d-debugger-headless.js +9 -0
- package/lib/physics-2d-debugger.d.ts +11 -0
- package/lib/physics-2d-debugger.js +146 -0
- package/lib/physics-2d-settings.d.ts +13 -0
- package/lib/physics-2d-settings.js +53 -0
- package/lib/physics-component-2d-base.d.ts +22 -0
- package/lib/physics-component-2d-base.js +85 -0
- package/lib/physics-world-2d-scene-component.d.ts +20 -0
- package/lib/physics-world-2d-scene-component.js +107 -0
- package/lib/physics-world-2d.d.ts +103 -0
- package/lib/physics-world-2d.js +506 -0
- package/lib/physics-world-registry.d.ts +6 -0
- package/lib/physics-world-registry.js +26 -0
- package/lib/px2-impl.d.ts +4 -0
- package/lib/px2-impl.js +18 -0
- package/lib/rigid-body-2d.d.ts +72 -0
- package/lib/rigid-body-2d.js +391 -0
- package/lib/scene-query-probe-2d.d.ts +102 -0
- package/lib/scene-query-probe-2d.js +223 -0
- package/lib/scene-query-probes/box-scene-query-probe-2d.d.ts +21 -0
- package/lib/scene-query-probes/box-scene-query-probe-2d.js +62 -0
- package/lib/scene-query-probes/capsule-scene-query-probe-2d.d.ts +27 -0
- package/lib/scene-query-probes/capsule-scene-query-probe-2d.js +96 -0
- package/lib/scene-query-probes/circle-scene-query-probe-2d.d.ts +20 -0
- package/lib/scene-query-probes/circle-scene-query-probe-2d.js +64 -0
- package/lib/scene-query.d.ts +67 -0
- package/lib/scene-query.js +128 -0
- package/lib/shared.d.ts +9 -0
- package/lib/shared.js +42 -0
- package/lib/utils/3-to-2.d.ts +3 -0
- package/lib/utils/3-to-2.js +12 -0
- package/lib/wasm-binary-helper/index.d.ts +6 -0
- package/lib/wasm-binary-helper/index.js +14 -0
- package/lib/wasm-binary-helper/wasm-binary-id.d.ts +2 -0
- package/lib/wasm-binary-helper/wasm-binary-id.js +2 -0
- package/lib/wasm-binary-helper.d.ts +6 -0
- package/lib/wasm-binary-helper.js +6 -0
- package/package.json +50 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Vec2 } from '@cyclonium/core/math/vec2';
|
|
2
|
+
import { px2Impl } from './px2-impl.js';
|
|
3
|
+
import { fromPx2ImplVec2 } from './exchange.js';
|
|
4
|
+
export class SceneQueryFilter {
|
|
5
|
+
constructor() {
|
|
6
|
+
}
|
|
7
|
+
get dynamics() {
|
|
8
|
+
return this._getIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_DYNAMIC);
|
|
9
|
+
}
|
|
10
|
+
set dynamics(value) {
|
|
11
|
+
this._setIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_DYNAMIC, value);
|
|
12
|
+
}
|
|
13
|
+
get fixed() {
|
|
14
|
+
return this._getIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_FIXED);
|
|
15
|
+
}
|
|
16
|
+
set fixed(value) {
|
|
17
|
+
this._setIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_FIXED, value);
|
|
18
|
+
}
|
|
19
|
+
get kinematics() {
|
|
20
|
+
return this._getIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_KINEMATIC);
|
|
21
|
+
}
|
|
22
|
+
set kinematics(value) {
|
|
23
|
+
this._setIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_KINEMATIC, value);
|
|
24
|
+
}
|
|
25
|
+
get sensors() {
|
|
26
|
+
return this._getIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_SENSORS);
|
|
27
|
+
}
|
|
28
|
+
set sensors(value) {
|
|
29
|
+
this._setIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_SENSORS, value);
|
|
30
|
+
}
|
|
31
|
+
get solids() {
|
|
32
|
+
return this._getIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_SOLIDS);
|
|
33
|
+
}
|
|
34
|
+
set solids(value) {
|
|
35
|
+
this._setIncludesFlag(px2Impl.QueryFilterFlags.EXCLUDE_SOLIDS, value);
|
|
36
|
+
}
|
|
37
|
+
addTargetTag(tag) {
|
|
38
|
+
this._filterGroupFilter |= 1 << tag;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
get _filterFlags_internal() {
|
|
42
|
+
return this._filterFlags;
|
|
43
|
+
}
|
|
44
|
+
get _filterGroups_internal() {
|
|
45
|
+
// TODO
|
|
46
|
+
// return composeCollisionGroup(GROUP_MEMBERSHIP_ALLOW_SCENE_QUERY, this._filterGroupFilter);
|
|
47
|
+
return composeCollisionGroup(0xFFFF, this._filterGroupFilter);
|
|
48
|
+
}
|
|
49
|
+
_filterGroupFilter = 0;
|
|
50
|
+
_filterFlags = 0;
|
|
51
|
+
_getIncludesFlag(flag) {
|
|
52
|
+
return (this._filterFlags & flag) === 0;
|
|
53
|
+
}
|
|
54
|
+
_setIncludesFlag(flag, value) {
|
|
55
|
+
this._filterFlags = value ? this._filterFlags & ~flag : this._filterFlags | flag;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function composeCollisionGroup(membership, filter) {
|
|
59
|
+
// Per https://rapier.rs/docs/user_guides/javascript/colliders#collision-groups-and-solver-groups
|
|
60
|
+
// > The membership and filter are both 16-bit bit masks packed into a single 32-bits value.
|
|
61
|
+
// > The 16 left-most bits contain the memberships whereas the 16 right-most bits contain the filter.
|
|
62
|
+
return (membership << 16) | filter;
|
|
63
|
+
}
|
|
64
|
+
export class ColliderShapeCastHit {
|
|
65
|
+
constructor(impl, startPosition, direction, collider) {
|
|
66
|
+
this._impl = impl;
|
|
67
|
+
this._startPosition = new Vec2(startPosition.x, startPosition.y);
|
|
68
|
+
this._direction = new Vec2(direction.x, direction.y);
|
|
69
|
+
this._collider = collider;
|
|
70
|
+
}
|
|
71
|
+
get collider() {
|
|
72
|
+
return this._collider;
|
|
73
|
+
}
|
|
74
|
+
get impl() {
|
|
75
|
+
return this._impl;
|
|
76
|
+
}
|
|
77
|
+
get point() {
|
|
78
|
+
return this._startPosition.addMulScalar(this._direction, this._impl.time_of_impact);
|
|
79
|
+
}
|
|
80
|
+
get distance() {
|
|
81
|
+
return this._impl.time_of_impact;
|
|
82
|
+
}
|
|
83
|
+
get localPoint1() {
|
|
84
|
+
return fromPx2ImplVec2(this._impl.witness1);
|
|
85
|
+
}
|
|
86
|
+
get localPoint2() {
|
|
87
|
+
return fromPx2ImplVec2(this._impl.witness2);
|
|
88
|
+
}
|
|
89
|
+
get localNormal1() {
|
|
90
|
+
return fromPx2ImplVec2(this._impl.normal1);
|
|
91
|
+
}
|
|
92
|
+
get localNormal2() {
|
|
93
|
+
return fromPx2ImplVec2(this._impl.normal2);
|
|
94
|
+
}
|
|
95
|
+
_impl;
|
|
96
|
+
_startPosition;
|
|
97
|
+
_direction;
|
|
98
|
+
_collider;
|
|
99
|
+
}
|
|
100
|
+
export class ColliderShapeIntersection {
|
|
101
|
+
_collider;
|
|
102
|
+
constructor(_collider) {
|
|
103
|
+
this._collider = _collider;
|
|
104
|
+
}
|
|
105
|
+
get collider() {
|
|
106
|
+
return this._collider;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export class RayColliderIntersection {
|
|
110
|
+
constructor(collider, timeOfImpact, normal) {
|
|
111
|
+
this._collider = collider;
|
|
112
|
+
this._timeOfImpact = timeOfImpact;
|
|
113
|
+
this._normal = normal;
|
|
114
|
+
}
|
|
115
|
+
get collider() {
|
|
116
|
+
return this._collider;
|
|
117
|
+
}
|
|
118
|
+
get timeOfImpact() {
|
|
119
|
+
return this._timeOfImpact;
|
|
120
|
+
}
|
|
121
|
+
get normal() {
|
|
122
|
+
return this._normal;
|
|
123
|
+
}
|
|
124
|
+
_collider;
|
|
125
|
+
_timeOfImpact;
|
|
126
|
+
_normal;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=scene-query.js.map
|
package/lib/shared.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ManagedEventEmitter } from '@cyclonium/event';
|
|
2
|
+
export declare enum ContactEventListenerFlagIndex {
|
|
3
|
+
begin = 0,
|
|
4
|
+
stay = 1,
|
|
5
|
+
end = 2,
|
|
6
|
+
body = 8
|
|
7
|
+
}
|
|
8
|
+
export declare function createCollisionEventEmitter<T extends unknown[]>(callback: (hasAnyListener: boolean) => void): ManagedEventEmitter<T>;
|
|
9
|
+
//# sourceMappingURL=shared.d.ts.map
|
package/lib/shared.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ManagedEventEmitter } from '@cyclonium/event';
|
|
2
|
+
export var ContactEventListenerFlagIndex;
|
|
3
|
+
(function (ContactEventListenerFlagIndex) {
|
|
4
|
+
ContactEventListenerFlagIndex[ContactEventListenerFlagIndex["begin"] = 0] = "begin";
|
|
5
|
+
ContactEventListenerFlagIndex[ContactEventListenerFlagIndex["stay"] = 1] = "stay";
|
|
6
|
+
ContactEventListenerFlagIndex[ContactEventListenerFlagIndex["end"] = 2] = "end";
|
|
7
|
+
ContactEventListenerFlagIndex[ContactEventListenerFlagIndex["body"] = 8] = "body";
|
|
8
|
+
})(ContactEventListenerFlagIndex || (ContactEventListenerFlagIndex = {}));
|
|
9
|
+
class ManagedCollisionEventEmitter extends ManagedEventEmitter {
|
|
10
|
+
_callback;
|
|
11
|
+
constructor(_callback) {
|
|
12
|
+
super();
|
|
13
|
+
this._callback = _callback;
|
|
14
|
+
}
|
|
15
|
+
emit(...args) {
|
|
16
|
+
const r = super.emit(...args);
|
|
17
|
+
this._updateListenerFlag();
|
|
18
|
+
return r;
|
|
19
|
+
}
|
|
20
|
+
add(...args) {
|
|
21
|
+
const r = super.add(...args);
|
|
22
|
+
this._updateListenerFlag();
|
|
23
|
+
return r;
|
|
24
|
+
}
|
|
25
|
+
remove(...args) {
|
|
26
|
+
const r = super.remove(...args);
|
|
27
|
+
this._updateListenerFlag();
|
|
28
|
+
return r;
|
|
29
|
+
}
|
|
30
|
+
removeAll() {
|
|
31
|
+
const r = super.removeAll();
|
|
32
|
+
this._updateListenerFlag();
|
|
33
|
+
return r;
|
|
34
|
+
}
|
|
35
|
+
_updateListenerFlag() {
|
|
36
|
+
this._callback(this.listenerCount > 0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function createCollisionEventEmitter(callback) {
|
|
40
|
+
return new ManagedCollisionEventEmitter(callback);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { clamp } from '@cyclonium/core/math/number';
|
|
2
|
+
export function getZRotation(quat) {
|
|
3
|
+
const { z, w } = quat;
|
|
4
|
+
const halfTheta = Math.acos(clamp(w, -1, 1));
|
|
5
|
+
if (halfTheta === 0) {
|
|
6
|
+
return 0;
|
|
7
|
+
}
|
|
8
|
+
const sinSign = Math.sign(halfTheta);
|
|
9
|
+
const axisSign = sinSign * Math.sign(z);
|
|
10
|
+
return axisSign * halfTheta * 2;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=3-to-2.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { wasmBinaryId } from './wasm-binary-id.js';
|
|
2
|
+
// @ts-expect-error node specific
|
|
3
|
+
import { join, dirname } from 'node:path';
|
|
4
|
+
// @ts-expect-error node specific
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
export default {
|
|
7
|
+
source: (() => {
|
|
8
|
+
const rapier2dModule = fileURLToPath(import.meta.resolve('@cyclonium/rapier2d'));
|
|
9
|
+
const rapier2dPkg = dirname(rapier2dModule);
|
|
10
|
+
return join(rapier2dPkg, 'rapier_wasm2d_bg.wasm');
|
|
11
|
+
})(),
|
|
12
|
+
target: wasmBinaryId,
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cyclonium/physics-2d",
|
|
3
|
+
"version": "0.0.100",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib/**/*{.js,.d.ts}"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"imports": {
|
|
12
|
+
"#gizmo": {
|
|
13
|
+
"headless": "./lib/gizmo-headless.js",
|
|
14
|
+
"default": "./lib/gizmo.js"
|
|
15
|
+
},
|
|
16
|
+
"#physics-2d-debugger": {
|
|
17
|
+
"headless": "./lib/physics-2d-debugger-headless.js",
|
|
18
|
+
"default": "./lib/physics-2d-debugger.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@cyclonium/algorithm": "0.0.100",
|
|
23
|
+
"@cyclonium/web-assembly": "0.0.100",
|
|
24
|
+
"@cyclonium/event": "0.0.100",
|
|
25
|
+
"@cyclonium/debug-draw": "0.0.100",
|
|
26
|
+
"@cyclonium/rapier2d": "0.0.100"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@cyclonium/core": "0.0.100"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/fs-extra": "^11.0.4",
|
|
33
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
34
|
+
"fs-extra": "^11.3.0",
|
|
35
|
+
"playwright": "^1.59.1",
|
|
36
|
+
"typescript": "^6.0.2",
|
|
37
|
+
"vitest": "^4.1.5",
|
|
38
|
+
"@cyclonium/cc-test": "0.0.100",
|
|
39
|
+
"@cyclonium/workflow": "0.0.100",
|
|
40
|
+
"@cyclonium/types-cc": "0.0.100"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -b",
|
|
44
|
+
"dev": "tsc -b --watch",
|
|
45
|
+
"test:browser": "vitest --no-file-parallelism --disableConsoleIntercept",
|
|
46
|
+
"test": "npm run test:compile && npm run t",
|
|
47
|
+
"test:compile": "tsc -b test/tsconfig.json",
|
|
48
|
+
"t": "npm run test:browser -- run --browser.headless=true"
|
|
49
|
+
}
|
|
50
|
+
}
|