dacha 0.17.2 → 0.18.0-alpha.1
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 +17 -4
- package/build/contrib/components/collider/index.js +30 -2
- package/build/contrib/components/rigid-body/index.d.ts +29 -17
- package/build/contrib/components/rigid-body/index.js +64 -21
- package/build/contrib/components/shape/index.d.ts +17 -2
- package/build/contrib/components/shape/index.js +16 -0
- package/build/contrib/events/index.d.ts +10 -75
- package/build/contrib/events/index.js +0 -36
- package/build/contrib/systems/camera-system/{service.d.ts → api.d.ts} +4 -4
- package/build/contrib/systems/camera-system/{service.js → api.js} +2 -2
- package/build/contrib/systems/camera-system/index.d.ts +1 -1
- package/build/contrib/systems/camera-system/index.js +1 -1
- package/build/contrib/systems/camera-system/system.d.ts +1 -1
- package/build/contrib/systems/camera-system/system.js +5 -4
- package/build/contrib/systems/index.d.ts +3 -3
- package/build/contrib/systems/index.js +3 -3
- package/build/contrib/systems/mouse-input-system/subsystems/coordinates-projector/index.d.ts +0 -1
- package/build/contrib/systems/mouse-input-system/subsystems/coordinates-projector/index.js +4 -5
- package/build/contrib/systems/physics-system/api.d.ts +58 -0
- package/build/contrib/systems/physics-system/api.js +67 -0
- package/build/contrib/systems/physics-system/index.d.ts +2 -21
- package/build/contrib/systems/physics-system/index.js +2 -40
- package/build/contrib/systems/physics-system/physics-system.d.ts +24 -0
- package/build/contrib/systems/physics-system/physics-system.js +47 -0
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/collision.d.ts +5 -3
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/collision.js +7 -5
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/index.d.ts +4 -6
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/index.js +20 -17
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-aabb.js +1 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-point-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-point-aabb.js +7 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-ray-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-ray-aabb.js +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-segment-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-segment-aabb.js +14 -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-geometry.d.ts +3 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.js +52 -16
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.d.ts +3 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.js +32 -7
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.js +5 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-ray-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-ray-geometry.js +7 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-segment-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-segment-geometry.js +33 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.d.ts +12 -1
- 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 +21 -9
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +177 -92
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.js +36 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.d.ts +17 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.js +126 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.js +46 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.js +28 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.d.ts +19 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.js +76 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.d.ts +12 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.js +47 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.js +33 -0
- 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 +27 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.js +36 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.js +33 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.js +26 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-box/check-ray-and-box-intersection.d.ts +11 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-box/check-ray-and-box-intersection.js +69 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-circle/check-ray-and-circle-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-circle/check-ray-and-circle-intersection.js +45 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/check-ray-and-segment-intersection.d.ts +16 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/check-ray-and-segment-intersection.js +51 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/utils.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/utils.js +4 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.d.ts +20 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.js +69 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.js +23 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.js +63 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/check-collider.js +17 -8
- package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +41 -11
- package/build/contrib/systems/physics-system/subsystems/collision-detection/types.js +0 -3
- package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.d.ts +7 -10
- package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.js +117 -79
- package/build/contrib/systems/physics-system/subsystems/index.d.ts +0 -1
- package/build/contrib/systems/physics-system/subsystems/index.js +0 -1
- package/build/contrib/systems/physics-system/subsystems/physics/index.d.ts +3 -9
- package/build/contrib/systems/physics-system/subsystems/physics/index.js +57 -93
- package/build/contrib/systems/physics-system/types.d.ts +37 -0
- package/build/contrib/systems/renderer/actor-render-tree.js +1 -2
- package/build/contrib/systems/renderer/{service → api}/index.d.ts +6 -6
- package/build/contrib/systems/renderer/{service → api}/index.js +14 -16
- package/build/contrib/systems/renderer/api/utils.d.ts +4 -0
- package/build/contrib/systems/renderer/{service → api}/utils.js +5 -0
- package/build/contrib/systems/renderer/builders/shape-builder/index.js +9 -1
- package/build/contrib/systems/renderer/builders/shape-builder/utils.js +16 -0
- package/build/contrib/systems/renderer/index.d.ts +1 -1
- package/build/contrib/systems/renderer/index.js +1 -1
- package/build/contrib/systems/renderer/renderer.d.ts +2 -1
- package/build/contrib/systems/renderer/renderer.js +9 -7
- package/build/engine/actor/actor-creator.js +6 -4
- package/build/engine/math-lib/math/ops.d.ts +1 -2
- package/build/engine/math-lib/math/ops.js +3 -3
- package/build/engine/math-lib/vector/ops.d.ts +18 -3
- package/build/engine/math-lib/vector/ops.js +28 -5
- package/build/engine/math-lib/vector/vector2.d.ts +22 -7
- package/build/engine/math-lib/vector/vector2.js +29 -5
- package/build/engine/template/template-collection.js +1 -1
- package/build/engine/world/index.d.ts +4 -24
- package/build/engine/world/index.js +5 -33
- package/build/engine/world/system-api-registry.d.ts +17 -0
- package/build/engine/world/system-api-registry.js +34 -0
- package/build/events/index.d.ts +2 -2
- package/build/events/index.js +1 -1
- package/build/types/global.d.ts +4 -0
- package/package.json +4 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-box-and-circle-intersection.d.ts +0 -16
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-box-and-circle-intersection.js +0 -80
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-boxes-intersection.d.ts +0 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-boxes-intersection.js +0 -72
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-circles-intersection.d.ts +0 -11
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-circles-intersection.js +0 -39
- package/build/contrib/systems/physics-system/subsystems/collision-solver/index.d.ts +0 -10
- package/build/contrib/systems/physics-system/subsystems/collision-solver/index.js +0 -50
- package/build/contrib/systems/renderer/service/utils.d.ts +0 -3
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { Animator } from './animator';
|
|
2
|
-
export { CameraSystem,
|
|
2
|
+
export { CameraSystem, CameraAPI } from './camera-system';
|
|
3
3
|
export { GameStatsMeter } from './game-stats-meter';
|
|
4
4
|
export { KeyboardInputSystem } from './keyboard-input-system';
|
|
5
5
|
export { KeyboardControlSystem } from './keyboard-control-system';
|
|
6
6
|
export { MouseControlSystem } from './mouse-control-system';
|
|
7
7
|
export { MouseInputSystem } from './mouse-input-system';
|
|
8
|
-
export { PhysicsSystem } from './physics-system';
|
|
8
|
+
export { PhysicsSystem, PhysicsAPI } from './physics-system';
|
|
9
9
|
export { BehaviorSystem, Behavior } from './behavior-system';
|
|
10
10
|
export type { BehaviorOptions } from './behavior-system';
|
|
11
11
|
export { UIBridge } from './ui-bridge';
|
|
12
12
|
export type { UIOptions, UIInitFn, UIDestroyFn, LoadUIFn } from './ui-bridge';
|
|
13
13
|
export { AudioSystem } from './audio-system';
|
|
14
|
-
export { Renderer,
|
|
14
|
+
export { Renderer, RendererAPI, FilterEffect, Shader } from './renderer';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { Animator } from './animator';
|
|
2
|
-
export { CameraSystem,
|
|
2
|
+
export { CameraSystem, CameraAPI } from './camera-system';
|
|
3
3
|
export { GameStatsMeter } from './game-stats-meter';
|
|
4
4
|
export { KeyboardInputSystem } from './keyboard-input-system';
|
|
5
5
|
export { KeyboardControlSystem } from './keyboard-control-system';
|
|
6
6
|
export { MouseControlSystem } from './mouse-control-system';
|
|
7
7
|
export { MouseInputSystem } from './mouse-input-system';
|
|
8
|
-
export { PhysicsSystem } from './physics-system';
|
|
8
|
+
export { PhysicsSystem, PhysicsAPI } from './physics-system';
|
|
9
9
|
export { BehaviorSystem, Behavior } from './behavior-system';
|
|
10
10
|
export { UIBridge } from './ui-bridge';
|
|
11
11
|
export { AudioSystem } from './audio-system';
|
|
12
|
-
export { Renderer,
|
|
12
|
+
export { Renderer, RendererAPI, FilterEffect, Shader } from './renderer';
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { MouseInput } from '../../../../events';
|
|
2
|
-
import {
|
|
3
|
-
import { getProjectedX, getProjectedY } from '../../../../utils/coordinates-projection';
|
|
2
|
+
import { CameraAPI } from '../../../camera-system';
|
|
3
|
+
import { getProjectedX, getProjectedY, } from '../../../../utils/coordinates-projection';
|
|
4
4
|
export class CoordinatesProjector {
|
|
5
5
|
world;
|
|
6
|
-
cameraService;
|
|
7
6
|
constructor(options) {
|
|
8
7
|
const { world } = options;
|
|
9
8
|
this.world = world;
|
|
10
|
-
this.cameraService = world.getService(CameraService);
|
|
11
9
|
this.world.addEventListener(MouseInput, this.handleMouseInput);
|
|
12
10
|
}
|
|
13
11
|
destroy() {
|
|
14
12
|
this.world.removeEventListener(MouseInput, this.handleMouseInput);
|
|
15
13
|
}
|
|
16
14
|
handleMouseInput = (event) => {
|
|
17
|
-
const
|
|
15
|
+
const cameraApi = this.world.systemApi.get(CameraAPI);
|
|
16
|
+
const currentCamera = cameraApi.getCurrentCamera();
|
|
18
17
|
event.x = currentCamera ? getProjectedX(event.x, currentCamera) : event.x;
|
|
19
18
|
event.y = currentCamera ? getProjectedY(event.y, currentCamera) : event.y;
|
|
20
19
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Actor } from '../../../engine/actor';
|
|
2
|
+
import type { CollisionDetectionSubsystem } from './subsystems';
|
|
3
|
+
import type { RaycastHit, RaycastParams, OverlapBoxParams, OverlapCircleParams, OverlapPointParams } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* API that provides methods for performing physics queries such as raycasting and overlap tests.
|
|
6
|
+
*
|
|
7
|
+
* Query results are based on the latest prepared physics state.
|
|
8
|
+
* That state is updated during the physics system fixed update step,
|
|
9
|
+
* so direct transform or collider changes made outside physics update
|
|
10
|
+
* are not guaranteed to be reflected immediately in query results.
|
|
11
|
+
*
|
|
12
|
+
* @category Systems
|
|
13
|
+
*/
|
|
14
|
+
export declare class PhysicsAPI {
|
|
15
|
+
private collisionDetectionSubsystem;
|
|
16
|
+
constructor(collisionDetectionSubsystem: CollisionDetectionSubsystem);
|
|
17
|
+
/**
|
|
18
|
+
* Casts a ray and returns the nearest hit, if any.
|
|
19
|
+
*
|
|
20
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
21
|
+
* and is limited by `params.maxDistance`.
|
|
22
|
+
*
|
|
23
|
+
* @param params - Raycast parameters
|
|
24
|
+
* @returns The nearest hit or `null` when nothing is hit
|
|
25
|
+
*/
|
|
26
|
+
raycast(params: RaycastParams): RaycastHit | null;
|
|
27
|
+
/**
|
|
28
|
+
* Casts a ray and returns all hits sorted by distance.
|
|
29
|
+
*
|
|
30
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
31
|
+
* and is limited by `params.maxDistance`.
|
|
32
|
+
*
|
|
33
|
+
* @param params - Raycast parameters
|
|
34
|
+
* @returns All hits sorted from nearest to farthest
|
|
35
|
+
*/
|
|
36
|
+
raycastAll(params: RaycastParams): RaycastHit[];
|
|
37
|
+
/**
|
|
38
|
+
* Returns all actors whose colliders contain the given point.
|
|
39
|
+
*
|
|
40
|
+
* @param params - Point overlap parameters
|
|
41
|
+
* @returns Actors whose colliders overlap the point
|
|
42
|
+
*/
|
|
43
|
+
overlapPoint(params: OverlapPointParams): Actor[];
|
|
44
|
+
/**
|
|
45
|
+
* Returns all actors whose colliders overlap the given circle.
|
|
46
|
+
*
|
|
47
|
+
* @param params - Circle overlap parameters
|
|
48
|
+
* @returns Actors whose colliders overlap the circle
|
|
49
|
+
*/
|
|
50
|
+
overlapCircle(params: OverlapCircleParams): Actor[];
|
|
51
|
+
/**
|
|
52
|
+
* Returns all actors whose colliders overlap the given box.
|
|
53
|
+
*
|
|
54
|
+
* @param params - Box overlap parameters
|
|
55
|
+
* @returns Actors whose colliders overlap the box
|
|
56
|
+
*/
|
|
57
|
+
overlapBox(params: OverlapBoxParams): Actor[];
|
|
58
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API that provides methods for performing physics queries such as raycasting and overlap tests.
|
|
3
|
+
*
|
|
4
|
+
* Query results are based on the latest prepared physics state.
|
|
5
|
+
* That state is updated during the physics system fixed update step,
|
|
6
|
+
* so direct transform or collider changes made outside physics update
|
|
7
|
+
* are not guaranteed to be reflected immediately in query results.
|
|
8
|
+
*
|
|
9
|
+
* @category Systems
|
|
10
|
+
*/
|
|
11
|
+
export class PhysicsAPI {
|
|
12
|
+
collisionDetectionSubsystem;
|
|
13
|
+
constructor(collisionDetectionSubsystem) {
|
|
14
|
+
this.collisionDetectionSubsystem = collisionDetectionSubsystem;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Casts a ray and returns the nearest hit, if any.
|
|
18
|
+
*
|
|
19
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
20
|
+
* and is limited by `params.maxDistance`.
|
|
21
|
+
*
|
|
22
|
+
* @param params - Raycast parameters
|
|
23
|
+
* @returns The nearest hit or `null` when nothing is hit
|
|
24
|
+
*/
|
|
25
|
+
raycast(params) {
|
|
26
|
+
return this.collisionDetectionSubsystem.raycast(params);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Casts a ray and returns all hits sorted by distance.
|
|
30
|
+
*
|
|
31
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
32
|
+
* and is limited by `params.maxDistance`.
|
|
33
|
+
*
|
|
34
|
+
* @param params - Raycast parameters
|
|
35
|
+
* @returns All hits sorted from nearest to farthest
|
|
36
|
+
*/
|
|
37
|
+
raycastAll(params) {
|
|
38
|
+
return this.collisionDetectionSubsystem.raycastAll(params);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns all actors whose colliders contain the given point.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Point overlap parameters
|
|
44
|
+
* @returns Actors whose colliders overlap the point
|
|
45
|
+
*/
|
|
46
|
+
overlapPoint(params) {
|
|
47
|
+
return this.collisionDetectionSubsystem.overlapPoint(params);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns all actors whose colliders overlap the given circle.
|
|
51
|
+
*
|
|
52
|
+
* @param params - Circle overlap parameters
|
|
53
|
+
* @returns Actors whose colliders overlap the circle
|
|
54
|
+
*/
|
|
55
|
+
overlapCircle(params) {
|
|
56
|
+
return this.collisionDetectionSubsystem.overlapCircle(params);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns all actors whose colliders overlap the given box.
|
|
60
|
+
*
|
|
61
|
+
* @param params - Box overlap parameters
|
|
62
|
+
* @returns Actors whose colliders overlap the box
|
|
63
|
+
*/
|
|
64
|
+
overlapBox(params) {
|
|
65
|
+
return this.collisionDetectionSubsystem.overlapBox(params);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Physics system that handles 2D physics simulation and collision detection
|
|
5
|
-
*
|
|
6
|
-
* Manages rigid body physics and collision detection and resolution.
|
|
7
|
-
*
|
|
8
|
-
* @extends SceneSystem
|
|
9
|
-
*
|
|
10
|
-
* @category Systems
|
|
11
|
-
*/
|
|
12
|
-
export declare class PhysicsSystem extends SceneSystem {
|
|
13
|
-
private physicsSubsystem;
|
|
14
|
-
private collisionDetectionSubsystem;
|
|
15
|
-
private collisionBroadcastSubsystem;
|
|
16
|
-
private collisionSolver;
|
|
17
|
-
private constraintSolver;
|
|
18
|
-
constructor(options: SceneSystemOptions);
|
|
19
|
-
onSceneDestroy(): void;
|
|
20
|
-
fixedUpdate(options: UpdateOptions): void;
|
|
21
|
-
}
|
|
1
|
+
export { PhysicsSystem } from './physics-system';
|
|
2
|
+
export { PhysicsAPI } from './api';
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Physics system that handles 2D physics simulation and collision detection
|
|
5
|
-
*
|
|
6
|
-
* Manages rigid body physics and collision detection and resolution.
|
|
7
|
-
*
|
|
8
|
-
* @extends SceneSystem
|
|
9
|
-
*
|
|
10
|
-
* @category Systems
|
|
11
|
-
*/
|
|
12
|
-
export class PhysicsSystem extends SceneSystem {
|
|
13
|
-
physicsSubsystem;
|
|
14
|
-
collisionDetectionSubsystem;
|
|
15
|
-
collisionBroadcastSubsystem;
|
|
16
|
-
collisionSolver;
|
|
17
|
-
constraintSolver;
|
|
18
|
-
constructor(options) {
|
|
19
|
-
super();
|
|
20
|
-
this.physicsSubsystem = new PhysicsSubsystem(options);
|
|
21
|
-
this.collisionDetectionSubsystem = new CollisionDetectionSubsystem(options);
|
|
22
|
-
this.collisionBroadcastSubsystem = new CollisionBroadcastSubsystem(options);
|
|
23
|
-
this.collisionSolver = new CollisionSolver(options);
|
|
24
|
-
this.constraintSolver = new ConstraintSolver(options);
|
|
25
|
-
}
|
|
26
|
-
onSceneDestroy() {
|
|
27
|
-
this.physicsSubsystem.destroy();
|
|
28
|
-
this.collisionDetectionSubsystem.destroy();
|
|
29
|
-
this.collisionSolver.destroy();
|
|
30
|
-
this.constraintSolver.destroy();
|
|
31
|
-
this.collisionBroadcastSubsystem.destroy();
|
|
32
|
-
}
|
|
33
|
-
fixedUpdate(options) {
|
|
34
|
-
this.physicsSubsystem.update(options);
|
|
35
|
-
this.collisionDetectionSubsystem.update();
|
|
36
|
-
this.constraintSolver.update();
|
|
37
|
-
this.collisionBroadcastSubsystem.update();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
1
|
+
export { PhysicsSystem } from './physics-system';
|
|
2
|
+
export { PhysicsAPI } from './api';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SceneSystem } from '../../../engine/system';
|
|
2
|
+
import type { SceneSystemOptions, UpdateOptions } from '../../../engine/system';
|
|
3
|
+
/**
|
|
4
|
+
* Physics system that handles 2D physics simulation and collision detection
|
|
5
|
+
*
|
|
6
|
+
* Manages rigid body physics and collision detection and resolution.
|
|
7
|
+
*
|
|
8
|
+
* @extends SceneSystem
|
|
9
|
+
*
|
|
10
|
+
* @category Systems
|
|
11
|
+
*/
|
|
12
|
+
export declare class PhysicsSystem extends SceneSystem {
|
|
13
|
+
private world;
|
|
14
|
+
private physicsSubsystem;
|
|
15
|
+
private collisionDetectionSubsystem;
|
|
16
|
+
private collisionBroadcastSubsystem;
|
|
17
|
+
private constraintSolver;
|
|
18
|
+
private physicsApi;
|
|
19
|
+
constructor(options: SceneSystemOptions);
|
|
20
|
+
onSceneEnter(): void;
|
|
21
|
+
onSceneExit(): void;
|
|
22
|
+
onSceneDestroy(): void;
|
|
23
|
+
fixedUpdate(options: UpdateOptions): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SceneSystem } from '../../../engine/system';
|
|
2
|
+
import { PhysicsSubsystem, CollisionDetectionSubsystem, CollisionBroadcastSubsystem, ConstraintSolver, } from './subsystems';
|
|
3
|
+
import { PhysicsAPI } from './api';
|
|
4
|
+
/**
|
|
5
|
+
* Physics system that handles 2D physics simulation and collision detection
|
|
6
|
+
*
|
|
7
|
+
* Manages rigid body physics and collision detection and resolution.
|
|
8
|
+
*
|
|
9
|
+
* @extends SceneSystem
|
|
10
|
+
*
|
|
11
|
+
* @category Systems
|
|
12
|
+
*/
|
|
13
|
+
export class PhysicsSystem extends SceneSystem {
|
|
14
|
+
world;
|
|
15
|
+
physicsSubsystem;
|
|
16
|
+
collisionDetectionSubsystem;
|
|
17
|
+
collisionBroadcastSubsystem;
|
|
18
|
+
constraintSolver;
|
|
19
|
+
physicsApi;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super();
|
|
22
|
+
this.world = options.world;
|
|
23
|
+
this.physicsSubsystem = new PhysicsSubsystem(options);
|
|
24
|
+
this.collisionDetectionSubsystem = new CollisionDetectionSubsystem(options);
|
|
25
|
+
this.collisionBroadcastSubsystem = new CollisionBroadcastSubsystem();
|
|
26
|
+
this.constraintSolver = new ConstraintSolver();
|
|
27
|
+
this.physicsApi = new PhysicsAPI(this.collisionDetectionSubsystem);
|
|
28
|
+
}
|
|
29
|
+
onSceneEnter() {
|
|
30
|
+
this.world.systemApi.register(this.physicsApi);
|
|
31
|
+
}
|
|
32
|
+
onSceneExit() {
|
|
33
|
+
this.world.systemApi.unregister(PhysicsAPI);
|
|
34
|
+
}
|
|
35
|
+
onSceneDestroy() {
|
|
36
|
+
this.world.systemApi.unregister(PhysicsAPI);
|
|
37
|
+
this.physicsSubsystem.destroy();
|
|
38
|
+
this.collisionDetectionSubsystem.destroy();
|
|
39
|
+
}
|
|
40
|
+
fixedUpdate(options) {
|
|
41
|
+
this.physicsSubsystem.update(options);
|
|
42
|
+
const contacts = this.collisionDetectionSubsystem.update();
|
|
43
|
+
this.constraintSolver.update(contacts);
|
|
44
|
+
this.collisionBroadcastSubsystem.update(contacts);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Actor } from '../../../../../engine/actor';
|
|
2
2
|
import type { Vector2 } from '../../../../../engine/math-lib';
|
|
3
|
+
import type { Point } from '../collision-detection/types';
|
|
3
4
|
export type CollisionState = 'enter' | 'stay' | 'leave';
|
|
4
5
|
export declare class Collision {
|
|
5
6
|
private lifetime;
|
|
6
7
|
actor1: Actor;
|
|
7
8
|
actor2: Actor;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
normal: Vector2;
|
|
10
|
+
penetration: number;
|
|
11
|
+
contactPoints: Point[];
|
|
12
|
+
constructor(actor1: Actor, actor2: Actor, normal: Vector2, penetration: number, contactPoints: Point[]);
|
|
11
13
|
isFinished(): boolean;
|
|
12
14
|
signal(): void;
|
|
13
15
|
tick(): void;
|
|
@@ -7,14 +7,16 @@ export class Collision {
|
|
|
7
7
|
lifetime;
|
|
8
8
|
actor1;
|
|
9
9
|
actor2;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
normal;
|
|
11
|
+
penetration;
|
|
12
|
+
contactPoints;
|
|
13
|
+
constructor(actor1, actor2, normal, penetration, contactPoints) {
|
|
13
14
|
this.actor1 = actor1;
|
|
14
15
|
this.actor2 = actor2;
|
|
15
16
|
this.lifetime = 2;
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
17
|
+
this.normal = normal;
|
|
18
|
+
this.penetration = penetration;
|
|
19
|
+
this.contactPoints = contactPoints;
|
|
18
20
|
}
|
|
19
21
|
isFinished() {
|
|
20
22
|
return this.lifetime < 0;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Contact } from '../collision-detection/types';
|
|
2
2
|
export declare class CollisionBroadcastSubsystem {
|
|
3
|
-
private scene;
|
|
4
3
|
private collisionMap;
|
|
5
4
|
private activeCollisions;
|
|
6
|
-
constructor(
|
|
7
|
-
|
|
8
|
-
private handleCollision;
|
|
5
|
+
constructor();
|
|
6
|
+
private trackCollision;
|
|
9
7
|
private publishEvent;
|
|
10
|
-
update(): void;
|
|
8
|
+
update(contacts: Contact[]): void;
|
|
11
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollisionEnter, CollisionStay, CollisionLeave, } from '../../../../events';
|
|
2
2
|
import { Collision } from './collision';
|
|
3
3
|
const STATE_TO_EVENT = {
|
|
4
4
|
enter: CollisionEnter,
|
|
@@ -6,40 +6,43 @@ const STATE_TO_EVENT = {
|
|
|
6
6
|
leave: CollisionLeave,
|
|
7
7
|
};
|
|
8
8
|
export class CollisionBroadcastSubsystem {
|
|
9
|
-
scene;
|
|
10
9
|
collisionMap;
|
|
11
10
|
activeCollisions;
|
|
12
|
-
constructor(
|
|
13
|
-
this.scene = options.scene;
|
|
11
|
+
constructor() {
|
|
14
12
|
this.collisionMap = {};
|
|
15
13
|
this.activeCollisions = [];
|
|
16
|
-
this.scene.addEventListener(RawCollision, this.handleCollision);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
this.scene.removeEventListener(RawCollision, this.handleCollision);
|
|
20
|
-
}
|
|
21
|
-
handleCollision = (event) => {
|
|
22
|
-
const { actor1, actor2, mtv1, mtv2, } = event;
|
|
15
|
+
trackCollision(actor1, actor2, normal, penetration, contactPoints) {
|
|
23
16
|
this.collisionMap[actor1.id] = this.collisionMap[actor1.id] || {};
|
|
24
17
|
if (!this.collisionMap[actor1.id][actor2.id]) {
|
|
25
|
-
const collision = new Collision(actor1, actor2,
|
|
18
|
+
const collision = new Collision(actor1, actor2, normal, penetration, contactPoints);
|
|
26
19
|
this.collisionMap[actor1.id][actor2.id] = collision;
|
|
27
20
|
this.activeCollisions.push(collision);
|
|
28
21
|
}
|
|
29
22
|
else {
|
|
30
|
-
this.collisionMap[actor1.id][actor2.id].
|
|
31
|
-
this.collisionMap[actor1.id][actor2.id].
|
|
23
|
+
this.collisionMap[actor1.id][actor2.id].normal = normal;
|
|
24
|
+
this.collisionMap[actor1.id][actor2.id].penetration = penetration;
|
|
25
|
+
this.collisionMap[actor1.id][actor2.id].contactPoints = contactPoints;
|
|
32
26
|
this.collisionMap[actor1.id][actor2.id].signal();
|
|
33
27
|
}
|
|
34
|
-
}
|
|
28
|
+
}
|
|
35
29
|
publishEvent(collision) {
|
|
36
|
-
const { actor1, actor2,
|
|
30
|
+
const { actor1, actor2, normal, penetration, contactPoints } = collision;
|
|
37
31
|
actor1.dispatchEvent(STATE_TO_EVENT[collision.getState()], {
|
|
38
32
|
actor: actor2,
|
|
39
|
-
|
|
33
|
+
normal,
|
|
34
|
+
penetration,
|
|
35
|
+
contactPoints,
|
|
40
36
|
});
|
|
41
37
|
}
|
|
42
|
-
update() {
|
|
38
|
+
update(contacts) {
|
|
39
|
+
contacts.forEach((contact) => {
|
|
40
|
+
const { actor1, actor2, normal, penetration, contactPoints } = contact;
|
|
41
|
+
const normal2 = contact.normal.clone();
|
|
42
|
+
normal2.multiplyNumber(-1);
|
|
43
|
+
this.trackCollision(actor1, actor2, normal, penetration, contactPoints);
|
|
44
|
+
this.trackCollision(actor2, actor1, normal2, penetration, contactPoints);
|
|
45
|
+
});
|
|
43
46
|
this.activeCollisions = this.activeCollisions.filter((collision) => {
|
|
44
47
|
const { actor1, actor2 } = collision;
|
|
45
48
|
this.publishEvent(collision);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export const buildCircleAABB = (geometry) => {
|
|
2
|
-
const { radius } = geometry;
|
|
3
|
-
const { x: centerX, y: centerY } = geometry.center;
|
|
2
|
+
const { radius, center: { x: centerX, y: centerY }, } = geometry;
|
|
4
3
|
return {
|
|
5
4
|
min: { x: centerX - radius, y: centerY - radius },
|
|
6
5
|
max: { x: centerX + radius, y: centerY + radius },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const buildRayAABB = (geometry) => {
|
|
2
|
+
const { origin, direction, maxDistance } = geometry;
|
|
3
|
+
const endX = origin.x + direction.x * maxDistance;
|
|
4
|
+
const endY = origin.y + direction.y * maxDistance;
|
|
5
|
+
return {
|
|
6
|
+
min: { x: Math.min(origin.x, endX), y: Math.min(origin.y, endY) },
|
|
7
|
+
max: { x: Math.max(origin.x, endX), y: Math.max(origin.y, endY) },
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { INTERSECTION_EPSILON } from '../intersection-checkers/utils';
|
|
2
|
+
export const buildSegmentAABB = (geometry) => {
|
|
3
|
+
const { point1, point2 } = geometry;
|
|
4
|
+
return {
|
|
5
|
+
min: {
|
|
6
|
+
x: Math.min(point1.x, point2.x) - INTERSECTION_EPSILON,
|
|
7
|
+
y: Math.min(point1.y, point2.y) - INTERSECTION_EPSILON,
|
|
8
|
+
},
|
|
9
|
+
max: {
|
|
10
|
+
x: Math.max(point1.x, point2.x) + INTERSECTION_EPSILON,
|
|
11
|
+
y: Math.max(point1.y, point2.y) + INTERSECTION_EPSILON,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { buildBoxAABB } from './build-box-aabb';
|
|
2
2
|
import { buildCircleAABB } from './build-circle-aabb';
|
|
3
|
+
import { buildPointAABB } from './build-point-aabb';
|
|
4
|
+
import { buildRayAABB } from './build-ray-aabb';
|
|
5
|
+
import { buildSegmentAABB } from './build-segment-aabb';
|
|
3
6
|
export const aabbBuilders = {
|
|
4
7
|
box: buildBoxAABB,
|
|
5
8
|
circle: buildCircleAABB,
|
|
9
|
+
segment: buildSegmentAABB,
|
|
10
|
+
point: buildPointAABB,
|
|
11
|
+
ray: buildRayAABB,
|
|
6
12
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Collider, Transform } from '../../../../../components';
|
|
2
2
|
import type { BoxGeometry } from '../types';
|
|
3
|
-
|
|
3
|
+
import type { OverlapBoxParams } from '../../../types';
|
|
4
|
+
export declare function buildBoxGeometry(overlap: OverlapBoxParams): BoxGeometry;
|
|
5
|
+
export declare function buildBoxGeometry(collider: Collider, transform: Transform): BoxGeometry;
|
|
@@ -1,16 +1,50 @@
|
|
|
1
1
|
import { VectorOps } from '../../../../../../engine/math-lib';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
|
|
2
|
+
export function buildBoxGeometry(colliderOrOverlap, transform) {
|
|
3
|
+
let centerX;
|
|
4
|
+
let centerY;
|
|
5
|
+
let sizeX;
|
|
6
|
+
let sizeY;
|
|
7
|
+
let positionX;
|
|
8
|
+
let positionY;
|
|
9
|
+
let rotation;
|
|
10
|
+
let scaleX;
|
|
11
|
+
let scaleY;
|
|
12
|
+
if (transform !== undefined) {
|
|
13
|
+
const collider = colliderOrOverlap;
|
|
14
|
+
centerX = collider.centerX;
|
|
15
|
+
centerY = collider.centerY;
|
|
16
|
+
sizeX = collider.sizeX;
|
|
17
|
+
sizeY = collider.sizeY;
|
|
18
|
+
positionX = transform.world.position.x;
|
|
19
|
+
positionY = transform.world.position.y;
|
|
20
|
+
rotation = transform.world.rotation;
|
|
21
|
+
scaleX = transform.world.scale.x;
|
|
22
|
+
scaleY = transform.world.scale.y;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const overlap = colliderOrOverlap;
|
|
26
|
+
centerX = 0;
|
|
27
|
+
centerY = 0;
|
|
28
|
+
sizeX = overlap.size.x;
|
|
29
|
+
sizeY = overlap.size.y;
|
|
30
|
+
positionX = overlap.center.x;
|
|
31
|
+
positionY = overlap.center.y;
|
|
32
|
+
rotation = overlap.rotation ?? 0;
|
|
33
|
+
scaleX = 1;
|
|
34
|
+
scaleY = 1;
|
|
35
|
+
}
|
|
6
36
|
const x1 = -(sizeX / 2);
|
|
7
37
|
const x2 = sizeX / 2;
|
|
8
38
|
const y1 = -(sizeY / 2);
|
|
9
39
|
const y2 = sizeY / 2;
|
|
10
40
|
const cos = Math.cos(rotation);
|
|
11
41
|
const sin = Math.sin(rotation);
|
|
12
|
-
centerX +=
|
|
13
|
-
centerY +=
|
|
42
|
+
centerX += positionX;
|
|
43
|
+
centerY += positionY;
|
|
44
|
+
const center = {
|
|
45
|
+
x: centerX,
|
|
46
|
+
y: centerY,
|
|
47
|
+
};
|
|
14
48
|
const points = [
|
|
15
49
|
{ x: x1, y: y1 },
|
|
16
50
|
{ x: x1, y: y2 },
|
|
@@ -19,27 +53,29 @@ export const buildBoxGeometry = (collider, transform) => {
|
|
|
19
53
|
];
|
|
20
54
|
points.forEach((point) => {
|
|
21
55
|
const { x, y } = point;
|
|
22
|
-
const scaledX = x *
|
|
23
|
-
const scaledY = y *
|
|
56
|
+
const scaledX = x * scaleX;
|
|
57
|
+
const scaledY = y * scaleY;
|
|
24
58
|
const rotatedX = scaledX * cos - scaledY * sin;
|
|
25
59
|
const rotatedY = scaledX * sin + scaledY * cos;
|
|
26
|
-
point.x = rotatedX +
|
|
27
|
-
point.y = rotatedY +
|
|
60
|
+
point.x = rotatedX + center.x;
|
|
61
|
+
point.y = rotatedY + center.y;
|
|
28
62
|
});
|
|
29
63
|
const edges = points.map((point1, index, array) => {
|
|
30
64
|
const point2 = array[(index + 1) % array.length];
|
|
65
|
+
const normal = VectorOps.getNormal(point1.x, point2.x, point1.y, point2.y);
|
|
66
|
+
const offset = VectorOps.dotProduct(point1, normal);
|
|
67
|
+
if (VectorOps.dotProduct(center, normal) - offset > 0) {
|
|
68
|
+
normal.multiplyNumber(-1);
|
|
69
|
+
}
|
|
31
70
|
return {
|
|
32
71
|
point1,
|
|
33
72
|
point2,
|
|
34
|
-
normal
|
|
73
|
+
normal,
|
|
35
74
|
};
|
|
36
75
|
});
|
|
37
76
|
return {
|
|
38
|
-
center
|
|
39
|
-
x: centerX,
|
|
40
|
-
y: centerY,
|
|
41
|
-
},
|
|
77
|
+
center,
|
|
42
78
|
points,
|
|
43
79
|
edges,
|
|
44
80
|
};
|
|
45
|
-
}
|
|
81
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Collider, Transform } from '../../../../../components';
|
|
2
2
|
import type { CircleGeometry } from '../types';
|
|
3
|
-
|
|
3
|
+
import type { OverlapCircleParams } from '../../../types';
|
|
4
|
+
export declare function buildCircleGeometry(overlap: OverlapCircleParams): CircleGeometry;
|
|
5
|
+
export declare function buildCircleGeometry(collider: Collider, transform: Transform): CircleGeometry;
|