dacha 0.18.0-alpha.3 → 0.18.0-alpha.4
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/build/contrib/components/collider/index.d.ts +6 -6
- package/build/contrib/components/collider/index.js +5 -2
- package/build/contrib/components/rigid-body/index.d.ts +53 -7
- package/build/contrib/components/rigid-body/index.js +63 -7
- package/build/contrib/systems/physics-system/api.d.ts +15 -15
- package/build/contrib/systems/physics-system/api.js +15 -15
- package/build/contrib/systems/physics-system/physics-system.js +1 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-box-cast-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-box-cast-aabb.js +18 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-capsule-cast-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-capsule-cast-aabb.js +21 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-cast-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-cast-aabb.js +15 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/index.js +6 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-cast-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-cast-geometry.js +24 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.js +1 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-cast-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-cast-geometry.js +43 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-geometry.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-capsule-geometry.js +36 -11
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-cast-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-cast-geometry.js +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.js +1 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.js +1 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.d.ts +6 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.js +6 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.d.ts +7 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +26 -11
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.js +1 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-capsule/check-box-and-capsule-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-capsule/check-box-and-capsule-intersection.js +1 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-capsule/utils.js +10 -10
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.js +3 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.js +2 -4
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.js +8 -8
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/capsule-capsule/check-capsules-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/capsule-capsule/check-capsules-intersection.js +1 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-capsule/check-circle-and-capsule-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-capsule/check-circle-and-capsule-intersection.js +3 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.js +5 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.js +3 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/capsule.js +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/cast.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/cast.js +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/points.js +2 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/projections.js +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/common/segment-distance.js +6 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.js +0 -10
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.js +4 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-capsule/check-point-and-capsule-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-capsule/check-point-and-capsule-intersection.js +3 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.js +3 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.js +3 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/segment-capsule/check-segment-and-capsule-intersection.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/segment-capsule/check-segment-and-capsule-intersection.js +1 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.d.ts +3 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.js +38 -28
- package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.d.ts +11 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.js +74 -14
- package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/index.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/index.js +12 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-box/check-ray-and-box-intersection.d.ts +3 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-box/check-ray-and-box-intersection.js +8 -12
- package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/ray-capsule/check-ray-and-capsule-intersection.d.ts +20 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-capsule/check-ray-and-capsule-intersection.js +27 -39
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-circle/check-ray-and-circle-intersection.d.ts +3 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-circle/check-ray-and-circle-intersection.js +8 -10
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/check-ray-and-segment-intersection.d.ts +3 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/check-ray-and-segment-intersection.js +9 -13
- package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/types.d.ts +4 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/raycast-checkers/types.js +1 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/check-collider.js +1 -4
- package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/get-orientation-data.js +1 -4
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-box/check-box-cast-and-box.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-box/check-box-cast-and-box.js +12 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-capsule/check-box-cast-and-capsule.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-capsule/check-box-cast-and-capsule.js +12 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-circle/check-box-cast-and-circle.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-circle/check-box-cast-and-circle.js +12 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-segment/check-box-cast-and-segment.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-segment/check-box-cast-and-segment.js +15 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-utils.d.ts +7 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/box-utils.js +146 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-box/check-capsule-cast-and-box.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-box/check-capsule-cast-and-box.js +22 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-capsule/check-capsule-cast-and-capsule.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-capsule/check-capsule-cast-and-capsule.js +21 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-circle/check-capsule-cast-and-circle.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-circle/check-capsule-cast-and-circle.js +20 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-segment/check-capsule-cast-and-segment.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-segment/check-capsule-cast-and-segment.js +21 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-utils.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/capsule-utils.js +16 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-box/check-circle-cast-and-box.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-box/check-circle-cast-and-box.js +22 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-capsule/check-circle-cast-and-capsule.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-capsule/check-circle-cast-and-capsule.js +18 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-circle/check-circle-cast-and-circle.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-circle/check-circle-cast-and-circle.js +22 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-segment/check-circle-cast-and-segment.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/circle-segment/check-circle-cast-and-segment.js +18 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/index.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/index.js +32 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/tests/helpers.d.ts +6 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/tests/helpers.js +39 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/types.d.ts +4 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/types.js +1 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/utils.d.ts +4 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/shape-cast-checkers/utils.js +11 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +12 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/utils.d.ts +5 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/utils.js +6 -0
- package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.d.ts +6 -0
- package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.js +65 -4
- package/build/contrib/systems/physics-system/subsystems/physics/index.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/physics/index.js +43 -5
- package/build/contrib/systems/physics-system/tests/helpers.d.ts +20 -0
- package/build/contrib/systems/physics-system/tests/helpers.js +129 -0
- package/build/contrib/systems/physics-system/types.d.ts +53 -6
- package/build/engine/math-lib/vector/ops.d.ts +9 -1
- package/build/engine/math-lib/vector/ops.js +15 -0
- package/build/engine/template/template-collection.js +3 -0
- package/package.json +1 -1
- package/build/contrib/systems/physics-system/consts.d.ts +0 -4
- package/build/contrib/systems/physics-system/consts.js +0 -4
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-capsule/check-ray-and-capsule-intersection.d.ts +0 -11
- /package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/utils.d.ts +0 -0
- /package/build/contrib/systems/physics-system/subsystems/collision-detection/{intersection-checkers → raycast-checkers}/ray-segment/utils.js +0 -0
|
@@ -7,6 +7,7 @@ export interface BaseColliderConfig {
|
|
|
7
7
|
offsetY: number;
|
|
8
8
|
layer: string;
|
|
9
9
|
debugColor?: string;
|
|
10
|
+
disabled: boolean;
|
|
10
11
|
}
|
|
11
12
|
export interface BoxColliderConfig extends BaseColliderConfig {
|
|
12
13
|
type: 'box';
|
|
@@ -26,10 +27,7 @@ export interface SegmentColliderConfig extends BaseColliderConfig {
|
|
|
26
27
|
}
|
|
27
28
|
export interface CapsuleColliderConfig extends BaseColliderConfig {
|
|
28
29
|
type: 'capsule';
|
|
29
|
-
|
|
30
|
-
point1Y: number;
|
|
31
|
-
point2X: number;
|
|
32
|
-
point2Y: number;
|
|
30
|
+
height: number;
|
|
33
31
|
radius: number;
|
|
34
32
|
}
|
|
35
33
|
export type ColliderConfig = BoxColliderConfig | CircleColliderConfig | SegmentColliderConfig | CapsuleColliderConfig;
|
|
@@ -48,8 +46,7 @@ export interface SegmentColliderShape {
|
|
|
48
46
|
}
|
|
49
47
|
export interface CapsuleColliderShape {
|
|
50
48
|
type: 'capsule';
|
|
51
|
-
|
|
52
|
-
point2: Point;
|
|
49
|
+
height: number;
|
|
53
50
|
radius: number;
|
|
54
51
|
}
|
|
55
52
|
export type ColliderShape = BoxColliderShape | CircleColliderShape | SegmentColliderShape | CapsuleColliderShape;
|
|
@@ -69,6 +66,7 @@ export type ColliderShape = BoxColliderShape | CircleColliderShape | SegmentColl
|
|
|
69
66
|
* sizeX: 64,
|
|
70
67
|
* sizeY: 64,
|
|
71
68
|
* layer: 'default',
|
|
69
|
+
* disabled: false,
|
|
72
70
|
* });
|
|
73
71
|
*
|
|
74
72
|
* // Create a circle collider
|
|
@@ -78,6 +76,7 @@ export type ColliderShape = BoxColliderShape | CircleColliderShape | SegmentColl
|
|
|
78
76
|
* offsetY: 0,
|
|
79
77
|
* radius: 32,
|
|
80
78
|
* layer: 'default',
|
|
79
|
+
* disabled: false,
|
|
81
80
|
* });
|
|
82
81
|
*
|
|
83
82
|
* // Add to actor
|
|
@@ -90,6 +89,7 @@ export declare class Collider extends Component {
|
|
|
90
89
|
offset: Point;
|
|
91
90
|
layer: string;
|
|
92
91
|
debugColor?: string;
|
|
92
|
+
disabled: boolean;
|
|
93
93
|
shape: ColliderShape;
|
|
94
94
|
constructor(config: ColliderConfig);
|
|
95
95
|
}
|
|
@@ -15,6 +15,7 @@ import { Component } from '../../../engine/component';
|
|
|
15
15
|
* sizeX: 64,
|
|
16
16
|
* sizeY: 64,
|
|
17
17
|
* layer: 'default',
|
|
18
|
+
* disabled: false,
|
|
18
19
|
* });
|
|
19
20
|
*
|
|
20
21
|
* // Create a circle collider
|
|
@@ -24,6 +25,7 @@ import { Component } from '../../../engine/component';
|
|
|
24
25
|
* offsetY: 0,
|
|
25
26
|
* radius: 32,
|
|
26
27
|
* layer: 'default',
|
|
28
|
+
* disabled: false,
|
|
27
29
|
* });
|
|
28
30
|
*
|
|
29
31
|
* // Add to actor
|
|
@@ -36,12 +38,14 @@ export class Collider extends Component {
|
|
|
36
38
|
offset;
|
|
37
39
|
layer;
|
|
38
40
|
debugColor;
|
|
41
|
+
disabled;
|
|
39
42
|
shape;
|
|
40
43
|
constructor(config) {
|
|
41
44
|
super();
|
|
42
45
|
this.offset = { x: config.offsetX, y: config.offsetY };
|
|
43
46
|
this.layer = config.layer;
|
|
44
47
|
this.debugColor = config.debugColor;
|
|
48
|
+
this.disabled = config.disabled;
|
|
45
49
|
switch (config.type) {
|
|
46
50
|
case 'box':
|
|
47
51
|
this.shape = {
|
|
@@ -65,8 +69,7 @@ export class Collider extends Component {
|
|
|
65
69
|
case 'capsule':
|
|
66
70
|
this.shape = {
|
|
67
71
|
type: config.type,
|
|
68
|
-
|
|
69
|
-
point2: { x: config.point2X, y: config.point2Y },
|
|
72
|
+
height: config.height,
|
|
70
73
|
radius: config.radius,
|
|
71
74
|
};
|
|
72
75
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Component } from '../../../engine/component';
|
|
2
2
|
import { Vector2 } from '../../../engine/math-lib';
|
|
3
|
-
export type RigidBodyType = 'dynamic' | 'static';
|
|
3
|
+
export type RigidBodyType = 'dynamic' | 'static' | 'kinematic';
|
|
4
4
|
export interface RigidBodyConfig {
|
|
5
5
|
type: RigidBodyType;
|
|
6
|
-
mass
|
|
7
|
-
gravityScale
|
|
8
|
-
linearDamping
|
|
6
|
+
mass?: number;
|
|
7
|
+
gravityScale?: number;
|
|
8
|
+
linearDamping?: number;
|
|
9
9
|
disabled: boolean;
|
|
10
|
+
oneWay: boolean;
|
|
11
|
+
oneWayNormalX?: number;
|
|
12
|
+
oneWayNormalY?: number;
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* RigidBody component for defining rigid body physics.
|
|
@@ -37,9 +40,10 @@ export interface RigidBodyConfig {
|
|
|
37
40
|
export declare class RigidBody extends Component {
|
|
38
41
|
private _mass;
|
|
39
42
|
private _inverseMass;
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
+
/** @internal Pending one-step kinematic movement target */
|
|
44
|
+
_movementTarget: Vector2 | null;
|
|
45
|
+
/** Body type that defines how the rigid body participates in simulation */
|
|
46
|
+
readonly type: RigidBodyType;
|
|
43
47
|
/** Gravity scale of the rigid body */
|
|
44
48
|
gravityScale: number;
|
|
45
49
|
/** Linear damping value used to slow down movement over time */
|
|
@@ -50,19 +54,61 @@ export declare class RigidBody extends Component {
|
|
|
50
54
|
disabled: boolean;
|
|
51
55
|
/** Whether rigid body is sleeping */
|
|
52
56
|
sleeping: boolean;
|
|
57
|
+
/** Force applied to the rigid body */
|
|
53
58
|
force: Vector2;
|
|
59
|
+
/** Impulse applied to the rigid body */
|
|
54
60
|
impulse: Vector2;
|
|
61
|
+
/** Whether contacts should only be resolved from one side */
|
|
62
|
+
oneWay: boolean;
|
|
63
|
+
/** Local-space normal that points toward the blocking side */
|
|
64
|
+
oneWayNormal?: Vector2;
|
|
55
65
|
/**
|
|
56
66
|
* Creates a new RigidBody component.
|
|
57
67
|
* @param config - Configuration for the rigid body
|
|
58
68
|
*/
|
|
59
69
|
constructor(config: RigidBodyConfig);
|
|
60
70
|
get mass(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Sets the mass used by dynamic bodies.
|
|
73
|
+
*
|
|
74
|
+
* Non-positive values make the body immovable by forces and impulses.
|
|
75
|
+
*/
|
|
61
76
|
set mass(value: number);
|
|
77
|
+
/**
|
|
78
|
+
* Returns the inverse mass.
|
|
79
|
+
*
|
|
80
|
+
* Bodies with zero or negative mass return `0`.
|
|
81
|
+
*/
|
|
62
82
|
get inverseMass(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Adds a continuous force to a dynamic body for the next physics step.
|
|
85
|
+
*
|
|
86
|
+
* Affects only active dynamic bodies.
|
|
87
|
+
*/
|
|
63
88
|
applyForce(force: Vector2): void;
|
|
89
|
+
/**
|
|
90
|
+
* Adds an instantaneous impulse to a dynamic body for the next physics step.
|
|
91
|
+
*
|
|
92
|
+
* Affects only active dynamic bodies.
|
|
93
|
+
*/
|
|
64
94
|
applyImpulse(impulse: Vector2): void;
|
|
95
|
+
/**
|
|
96
|
+
* Marks the rigid body as awake so it can be simulated.
|
|
97
|
+
*/
|
|
65
98
|
wakeUp(): void;
|
|
99
|
+
/**
|
|
100
|
+
* Marks the rigid body as sleeping so dynamic integration can skip it.
|
|
101
|
+
*/
|
|
66
102
|
sleep(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Clears all accumulated force and impulse values.
|
|
105
|
+
*/
|
|
67
106
|
clearForces(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Moves a kinematic body to a target position on the next physics step.
|
|
109
|
+
*
|
|
110
|
+
* The physics system computes a one-step velocity from the current position
|
|
111
|
+
* to this target so contacts can react to the kinematic movement.
|
|
112
|
+
*/
|
|
113
|
+
movePosition(position: Vector2): void;
|
|
68
114
|
}
|
|
@@ -29,9 +29,10 @@ import { Vector2 } from '../../../engine/math-lib';
|
|
|
29
29
|
export class RigidBody extends Component {
|
|
30
30
|
_mass;
|
|
31
31
|
_inverseMass;
|
|
32
|
-
/**
|
|
32
|
+
/** @internal Pending one-step kinematic movement target */
|
|
33
|
+
_movementTarget;
|
|
34
|
+
/** Body type that defines how the rigid body participates in simulation */
|
|
33
35
|
type;
|
|
34
|
-
/** Mass of the rigid body */
|
|
35
36
|
/** Gravity scale of the rigid body */
|
|
36
37
|
gravityScale;
|
|
37
38
|
/** Linear damping value used to slow down movement over time */
|
|
@@ -42,8 +43,14 @@ export class RigidBody extends Component {
|
|
|
42
43
|
disabled;
|
|
43
44
|
/** Whether rigid body is sleeping */
|
|
44
45
|
sleeping;
|
|
46
|
+
/** Force applied to the rigid body */
|
|
45
47
|
force;
|
|
48
|
+
/** Impulse applied to the rigid body */
|
|
46
49
|
impulse;
|
|
50
|
+
/** Whether contacts should only be resolved from one side */
|
|
51
|
+
oneWay;
|
|
52
|
+
/** Local-space normal that points toward the blocking side */
|
|
53
|
+
oneWayNormal;
|
|
47
54
|
/**
|
|
48
55
|
* Creates a new RigidBody component.
|
|
49
56
|
* @param config - Configuration for the rigid body
|
|
@@ -52,49 +59,98 @@ export class RigidBody extends Component {
|
|
|
52
59
|
super();
|
|
53
60
|
this._mass = 0;
|
|
54
61
|
this._inverseMass = 0;
|
|
62
|
+
this._movementTarget = null;
|
|
55
63
|
this.type = config.type;
|
|
56
|
-
this.mass = config.mass;
|
|
57
|
-
this.gravityScale = config.gravityScale;
|
|
58
|
-
this.linearDamping = config.linearDamping;
|
|
64
|
+
this.mass = config.mass ?? 0;
|
|
65
|
+
this.gravityScale = config.gravityScale ?? 0;
|
|
66
|
+
this.linearDamping = config.linearDamping ?? 0;
|
|
59
67
|
this.linearVelocity = new Vector2(0, 0);
|
|
60
68
|
this.disabled = config.disabled;
|
|
61
69
|
this.sleeping = false;
|
|
62
70
|
this.force = new Vector2(0, 0);
|
|
63
71
|
this.impulse = new Vector2(0, 0);
|
|
72
|
+
this.oneWay = config.oneWay ?? false;
|
|
73
|
+
if (this.oneWay) {
|
|
74
|
+
this.oneWayNormal = new Vector2(config.oneWayNormalX ?? 0, config.oneWayNormalY ?? 0).normalize();
|
|
75
|
+
if (this.oneWayNormal.magnitude === 0) {
|
|
76
|
+
throw new Error('One-way rigid body normal must be non-zero');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
64
79
|
}
|
|
65
80
|
get mass() {
|
|
66
81
|
return this._mass;
|
|
67
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Sets the mass used by dynamic bodies.
|
|
85
|
+
*
|
|
86
|
+
* Non-positive values make the body immovable by forces and impulses.
|
|
87
|
+
*/
|
|
68
88
|
set mass(value) {
|
|
69
89
|
this._mass = value;
|
|
70
90
|
this._inverseMass = value > 0 ? 1 / value : 0;
|
|
71
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the inverse mass.
|
|
94
|
+
*
|
|
95
|
+
* Bodies with zero or negative mass return `0`.
|
|
96
|
+
*/
|
|
72
97
|
get inverseMass() {
|
|
73
98
|
return this._inverseMass;
|
|
74
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Adds a continuous force to a dynamic body for the next physics step.
|
|
102
|
+
*
|
|
103
|
+
* Affects only active dynamic bodies.
|
|
104
|
+
*/
|
|
75
105
|
applyForce(force) {
|
|
76
|
-
if (this.disabled || this.type
|
|
106
|
+
if (this.disabled || this.type !== 'dynamic') {
|
|
77
107
|
return;
|
|
78
108
|
}
|
|
79
109
|
this.wakeUp();
|
|
80
110
|
this.force.add(force);
|
|
81
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Adds an instantaneous impulse to a dynamic body for the next physics step.
|
|
114
|
+
*
|
|
115
|
+
* Affects only active dynamic bodies.
|
|
116
|
+
*/
|
|
82
117
|
applyImpulse(impulse) {
|
|
83
|
-
if (this.disabled || this.type
|
|
118
|
+
if (this.disabled || this.type !== 'dynamic') {
|
|
84
119
|
return;
|
|
85
120
|
}
|
|
86
121
|
this.wakeUp();
|
|
87
122
|
this.impulse.add(impulse);
|
|
88
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Marks the rigid body as awake so it can be simulated.
|
|
126
|
+
*/
|
|
89
127
|
wakeUp() {
|
|
90
128
|
this.sleeping = false;
|
|
91
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Marks the rigid body as sleeping so dynamic integration can skip it.
|
|
132
|
+
*/
|
|
92
133
|
sleep() {
|
|
93
134
|
this.sleeping = true;
|
|
94
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Clears all accumulated force and impulse values.
|
|
138
|
+
*/
|
|
95
139
|
clearForces() {
|
|
96
140
|
this.force.multiplyNumber(0);
|
|
97
141
|
this.impulse.multiplyNumber(0);
|
|
98
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Moves a kinematic body to a target position on the next physics step.
|
|
145
|
+
*
|
|
146
|
+
* The physics system computes a one-step velocity from the current position
|
|
147
|
+
* to this target so contacts can react to the kinematic movement.
|
|
148
|
+
*/
|
|
149
|
+
movePosition(position) {
|
|
150
|
+
if (this.disabled || this.type !== 'kinematic') {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this._movementTarget = position.clone();
|
|
154
|
+
}
|
|
99
155
|
}
|
|
100
156
|
RigidBody.componentName = 'RigidBody';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Actor } from '../../../engine/actor';
|
|
2
2
|
import type { CollisionDetectionSubsystem } from './subsystems';
|
|
3
|
-
import type {
|
|
3
|
+
import type { CastHit, RaycastParams, OverlapParams, ShapeCastParams } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* API that provides methods for performing physics queries such as raycasting and overlap tests.
|
|
6
6
|
*
|
|
@@ -23,7 +23,7 @@ export declare class PhysicsAPI {
|
|
|
23
23
|
* @param params - Raycast parameters
|
|
24
24
|
* @returns The nearest hit or `null` when nothing is hit
|
|
25
25
|
*/
|
|
26
|
-
raycast(params: RaycastParams):
|
|
26
|
+
raycast(params: RaycastParams): CastHit | null;
|
|
27
27
|
/**
|
|
28
28
|
* Casts a ray and returns all hits sorted by distance.
|
|
29
29
|
*
|
|
@@ -33,26 +33,26 @@ export declare class PhysicsAPI {
|
|
|
33
33
|
* @param params - Raycast parameters
|
|
34
34
|
* @returns All hits sorted from nearest to farthest
|
|
35
35
|
*/
|
|
36
|
-
raycastAll(params: RaycastParams):
|
|
36
|
+
raycastAll(params: RaycastParams): CastHit[];
|
|
37
37
|
/**
|
|
38
|
-
* Returns all actors whose colliders
|
|
38
|
+
* Returns all actors whose colliders overlap the given query shape.
|
|
39
39
|
*
|
|
40
|
-
* @param params -
|
|
41
|
-
* @returns Actors whose colliders overlap the
|
|
40
|
+
* @param params - Overlap parameters
|
|
41
|
+
* @returns Actors whose colliders overlap the shape
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
overlapShape(params: OverlapParams): Actor[];
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Casts a shape and returns the nearest hit, if any.
|
|
46
46
|
*
|
|
47
|
-
* @param params -
|
|
48
|
-
* @returns
|
|
47
|
+
* @param params - Shape cast parameters
|
|
48
|
+
* @returns The nearest hit or `null` when nothing is hit
|
|
49
49
|
*/
|
|
50
|
-
|
|
50
|
+
shapeCast(params: ShapeCastParams): CastHit | null;
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
52
|
+
* Casts a shape and returns all hits sorted by distance.
|
|
53
53
|
*
|
|
54
|
-
* @param params -
|
|
55
|
-
* @returns
|
|
54
|
+
* @param params - Shape cast parameters
|
|
55
|
+
* @returns All hits sorted from nearest to farthest
|
|
56
56
|
*/
|
|
57
|
-
|
|
57
|
+
shapeCastAll(params: ShapeCastParams): CastHit[];
|
|
58
58
|
}
|
|
@@ -38,30 +38,30 @@ export class PhysicsAPI {
|
|
|
38
38
|
return this.collisionDetectionSubsystem.raycastAll(params);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Returns all actors whose colliders
|
|
41
|
+
* Returns all actors whose colliders overlap the given query shape.
|
|
42
42
|
*
|
|
43
|
-
* @param params -
|
|
44
|
-
* @returns Actors whose colliders overlap the
|
|
43
|
+
* @param params - Overlap parameters
|
|
44
|
+
* @returns Actors whose colliders overlap the shape
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
return this.collisionDetectionSubsystem.
|
|
46
|
+
overlapShape(params) {
|
|
47
|
+
return this.collisionDetectionSubsystem.overlapShape(params);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Casts a shape and returns the nearest hit, if any.
|
|
51
51
|
*
|
|
52
|
-
* @param params -
|
|
53
|
-
* @returns
|
|
52
|
+
* @param params - Shape cast parameters
|
|
53
|
+
* @returns The nearest hit or `null` when nothing is hit
|
|
54
54
|
*/
|
|
55
|
-
|
|
56
|
-
return this.collisionDetectionSubsystem.
|
|
55
|
+
shapeCast(params) {
|
|
56
|
+
return this.collisionDetectionSubsystem.shapeCast(params);
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Casts a shape and returns all hits sorted by distance.
|
|
60
60
|
*
|
|
61
|
-
* @param params -
|
|
62
|
-
* @returns
|
|
61
|
+
* @param params - Shape cast parameters
|
|
62
|
+
* @returns All hits sorted from nearest to farthest
|
|
63
63
|
*/
|
|
64
|
-
|
|
65
|
-
return this.collisionDetectionSubsystem.
|
|
64
|
+
shapeCastAll(params) {
|
|
65
|
+
return this.collisionDetectionSubsystem.shapeCastAll(params);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -42,6 +42,7 @@ export class PhysicsSystem extends SceneSystem {
|
|
|
42
42
|
const contacts = this.collisionDetectionSubsystem.update();
|
|
43
43
|
this.constraintSolver.update(contacts);
|
|
44
44
|
this.collisionBroadcastSubsystem.update(contacts);
|
|
45
|
+
this.physicsSubsystem.lateUpdate();
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const buildBoxCastAABB = (params) => {
|
|
2
|
+
const { points, direction, maxDistance } = params;
|
|
3
|
+
const endPoints = points.map((point) => ({
|
|
4
|
+
x: point.x + direction.x * maxDistance,
|
|
5
|
+
y: point.y + direction.y * maxDistance,
|
|
6
|
+
}));
|
|
7
|
+
const castPoints = [...points, ...endPoints];
|
|
8
|
+
return {
|
|
9
|
+
min: {
|
|
10
|
+
x: Math.min(...castPoints.map((point) => point.x)),
|
|
11
|
+
y: Math.min(...castPoints.map((point) => point.y)),
|
|
12
|
+
},
|
|
13
|
+
max: {
|
|
14
|
+
x: Math.max(...castPoints.map((point) => point.x)),
|
|
15
|
+
y: Math.max(...castPoints.map((point) => point.y)),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const buildCapsuleCastAABB = (params) => {
|
|
2
|
+
const { point1, point2, radius, direction, maxDistance } = params;
|
|
3
|
+
const endPoint1 = {
|
|
4
|
+
x: point1.x + direction.x * maxDistance,
|
|
5
|
+
y: point1.y + direction.y * maxDistance,
|
|
6
|
+
};
|
|
7
|
+
const endPoint2 = {
|
|
8
|
+
x: point2.x + direction.x * maxDistance,
|
|
9
|
+
y: point2.y + direction.y * maxDistance,
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
min: {
|
|
13
|
+
x: Math.min(point1.x, point2.x, endPoint1.x, endPoint2.x) - radius,
|
|
14
|
+
y: Math.min(point1.y, point2.y, endPoint1.y, endPoint2.y) - radius,
|
|
15
|
+
},
|
|
16
|
+
max: {
|
|
17
|
+
x: Math.max(point1.x, point2.x, endPoint1.x, endPoint2.x) + radius,
|
|
18
|
+
y: Math.max(point1.y, point2.y, endPoint1.y, endPoint2.y) + radius,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const buildCircleCastAABB = (params) => {
|
|
2
|
+
const { center, radius, direction, maxDistance } = params;
|
|
3
|
+
const endX = center.x + direction.x * maxDistance;
|
|
4
|
+
const endY = center.y + direction.y * maxDistance;
|
|
5
|
+
return {
|
|
6
|
+
min: {
|
|
7
|
+
x: Math.min(center.x, endX) - radius,
|
|
8
|
+
y: Math.min(center.y, endY) - radius,
|
|
9
|
+
},
|
|
10
|
+
max: {
|
|
11
|
+
x: Math.max(center.x, endX) + radius,
|
|
12
|
+
y: Math.max(center.y, endY) + radius,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
};
|
package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/index.js
CHANGED
|
@@ -4,6 +4,9 @@ import { buildCircleAABB } from './build-circle-aabb';
|
|
|
4
4
|
import { buildPointAABB } from './build-point-aabb';
|
|
5
5
|
import { buildRayAABB } from './build-ray-aabb';
|
|
6
6
|
import { buildSegmentAABB } from './build-segment-aabb';
|
|
7
|
+
import { buildCircleCastAABB } from './build-circle-cast-aabb';
|
|
8
|
+
import { buildCapsuleCastAABB } from './build-capsule-cast-aabb';
|
|
9
|
+
import { buildBoxCastAABB } from './build-box-cast-aabb';
|
|
7
10
|
export const aabbBuilders = {
|
|
8
11
|
box: buildBoxAABB,
|
|
9
12
|
capsule: buildCapsuleAABB,
|
|
@@ -11,4 +14,7 @@ export const aabbBuilders = {
|
|
|
11
14
|
segment: buildSegmentAABB,
|
|
12
15
|
point: buildPointAABB,
|
|
13
16
|
ray: buildRayAABB,
|
|
17
|
+
circleCast: buildCircleCastAABB,
|
|
18
|
+
capsuleCast: buildCapsuleCastAABB,
|
|
19
|
+
boxCast: buildBoxCastAABB,
|
|
14
20
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { buildBoxGeometry } from './build-box-geometry';
|
|
2
|
+
export function buildBoxCastGeometry(shapeCast) {
|
|
3
|
+
const box = buildBoxGeometry(shapeCast);
|
|
4
|
+
let minX = Infinity;
|
|
5
|
+
let maxX = -Infinity;
|
|
6
|
+
let minY = Infinity;
|
|
7
|
+
let maxY = -Infinity;
|
|
8
|
+
for (const point of box.points) {
|
|
9
|
+
minX = Math.min(minX, point.x);
|
|
10
|
+
maxX = Math.max(maxX, point.x);
|
|
11
|
+
minY = Math.min(minY, point.y);
|
|
12
|
+
maxY = Math.max(maxY, point.y);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
...box,
|
|
16
|
+
origin: box.center,
|
|
17
|
+
direction: shapeCast.direction.normalize(),
|
|
18
|
+
maxDistance: shapeCast.maxDistance,
|
|
19
|
+
halfExtents: {
|
|
20
|
+
x: (maxX - minX) / 2,
|
|
21
|
+
y: (maxY - minY) / 2,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isZero, isDefinitelyPositive } from '../utils';
|
|
2
|
+
import { buildCapsuleGeometry } from './build-capsule-geometry';
|
|
3
|
+
import { buildBoxCastGeometry } from './build-box-cast-geometry';
|
|
4
|
+
export function buildCapsuleCastGeometry(shapeCast) {
|
|
5
|
+
const capsule = buildCapsuleGeometry(shapeCast);
|
|
6
|
+
const boxSizeX = isZero(capsule.point2.x - capsule.point1.x)
|
|
7
|
+
? capsule.radius * 2
|
|
8
|
+
: Math.abs(capsule.point2.x - capsule.point1.x);
|
|
9
|
+
const boxSizeY = isZero(capsule.point2.y - capsule.point1.y)
|
|
10
|
+
? capsule.radius * 2
|
|
11
|
+
: Math.abs(capsule.point2.y - capsule.point1.y);
|
|
12
|
+
return {
|
|
13
|
+
...capsule,
|
|
14
|
+
cap1: {
|
|
15
|
+
center: capsule.point1,
|
|
16
|
+
origin: capsule.point1,
|
|
17
|
+
radius: capsule.radius,
|
|
18
|
+
direction: shapeCast.direction,
|
|
19
|
+
maxDistance: shapeCast.maxDistance,
|
|
20
|
+
},
|
|
21
|
+
cap2: {
|
|
22
|
+
center: capsule.point2,
|
|
23
|
+
origin: capsule.point2,
|
|
24
|
+
radius: capsule.radius,
|
|
25
|
+
direction: shapeCast.direction,
|
|
26
|
+
maxDistance: shapeCast.maxDistance,
|
|
27
|
+
},
|
|
28
|
+
box: isDefinitelyPositive(boxSizeX) && isDefinitelyPositive(boxSizeY)
|
|
29
|
+
? buildBoxCastGeometry({
|
|
30
|
+
shape: {
|
|
31
|
+
type: 'box',
|
|
32
|
+
center: capsule.center,
|
|
33
|
+
size: { x: boxSizeX, y: boxSizeY },
|
|
34
|
+
},
|
|
35
|
+
direction: shapeCast.direction,
|
|
36
|
+
maxDistance: shapeCast.maxDistance,
|
|
37
|
+
})
|
|
38
|
+
: null,
|
|
39
|
+
origin: capsule.center,
|
|
40
|
+
direction: shapeCast.direction.normalize(),
|
|
41
|
+
maxDistance: shapeCast.maxDistance,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Collider, Transform } from '../../../../../components';
|
|
2
2
|
import type { CapsuleGeometry } from '../types';
|
|
3
|
+
import type { OverlapCapsuleParams } from '../../../types';
|
|
4
|
+
export declare function buildCapsuleGeometry(overlap: OverlapCapsuleParams): CapsuleGeometry;
|
|
3
5
|
export declare function buildCapsuleGeometry(collider: Collider, transform: Transform): CapsuleGeometry;
|