@ue-too/dynamics 0.9.5 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +538 -4
- package/collision-filter.d.ts +115 -0
- package/constraint.d.ts +70 -0
- package/dynamic-tree.d.ts +16 -0
- package/index.d.ts +189 -0
- package/index.js +2 -1947
- package/index.js.map +9 -9
- package/package.json +3 -3
- package/pair-manager.d.ts +36 -0
- package/quadtree.d.ts +4 -0
- package/rigidbody.d.ts +21 -0
- package/world.d.ts +51 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ue-too/dynamics",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"./package.json": "./package.json"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ue-too/math": "^0.
|
|
24
|
-
"@ue-too/ecs": "^0.
|
|
23
|
+
"@ue-too/math": "^0.11.0",
|
|
24
|
+
"@ue-too/ecs": "^0.11.0"
|
|
25
25
|
},
|
|
26
26
|
"main": "./index.js",
|
|
27
27
|
"types": "./index.d.ts",
|
package/pair-manager.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { RigidBody } from "./rigidbody";
|
|
2
2
|
import { Point } from "@ue-too/math";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a collision pair between two bodies.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Tracks collision information across multiple frames, enabling
|
|
8
|
+
* detection of collision start, update, and end events.
|
|
9
|
+
*
|
|
10
|
+
* @category Collision
|
|
11
|
+
*/
|
|
3
12
|
export interface CollisionPair {
|
|
4
13
|
bodyA: RigidBody;
|
|
5
14
|
bodyB: RigidBody;
|
|
@@ -16,6 +25,33 @@ export interface PairEvents {
|
|
|
16
25
|
updated: CollisionPair[];
|
|
17
26
|
removed: CollisionPair[];
|
|
18
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Manages collision pairs across frames.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Tracks which bodies are colliding and for how long, enabling
|
|
33
|
+
* collision lifecycle events (start, update, end). This is useful for
|
|
34
|
+
* game logic like damage on collision start or triggers.
|
|
35
|
+
*
|
|
36
|
+
* Automatically cleans up old inactive pairs to prevent memory leaks.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* Using collision events
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const pairManager = world.getPairManager();
|
|
42
|
+
*
|
|
43
|
+
* world.step(dt);
|
|
44
|
+
*
|
|
45
|
+
* const events = pairManager.getActivePairs();
|
|
46
|
+
* events.forEach(pair => {
|
|
47
|
+
* if (pair.frameCreated === world.currentFrame) {
|
|
48
|
+
* console.log('Collision started!');
|
|
49
|
+
* }
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @category Collision
|
|
54
|
+
*/
|
|
19
55
|
export declare class PairManager {
|
|
20
56
|
private pairs;
|
|
21
57
|
private frameNumber;
|
package/quadtree.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export declare class RectangleBound {
|
|
|
10
10
|
getbottomLeft(): Point;
|
|
11
11
|
}
|
|
12
12
|
export type QuadTreeObject = SpatialIndexObject;
|
|
13
|
+
/**
|
|
14
|
+
* QuadTree spatial indexing structure for efficient collision detection.
|
|
15
|
+
* @category Spatial Indexing
|
|
16
|
+
*/
|
|
13
17
|
export declare class QuadTree<T extends QuadTreeObject> implements SpatialIndex<T> {
|
|
14
18
|
private MAX_OBJECTS;
|
|
15
19
|
private MAX_LEVELS;
|
package/rigidbody.d.ts
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
import { Point } from "@ue-too/math";
|
|
2
2
|
import { CollisionFilter } from "./collision-filter";
|
|
3
|
+
/**
|
|
4
|
+
* Rigid body interface for 2D physics simulation.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Represents a physical object in the physics world with mass, velocity,
|
|
8
|
+
* rotation, and collision properties. Can be either static (immovable) or
|
|
9
|
+
* dynamic (responds to forces).
|
|
10
|
+
*
|
|
11
|
+
* Implemented by {@link Circle} and {@link Polygon} classes.
|
|
12
|
+
*
|
|
13
|
+
* @category Core
|
|
14
|
+
*/
|
|
3
15
|
export interface RigidBody {
|
|
16
|
+
/** Center position in world coordinates */
|
|
4
17
|
center: Point;
|
|
18
|
+
/** Rotation angle in radians */
|
|
5
19
|
orientationAngle: number;
|
|
20
|
+
/** Linear velocity (pixels/second) */
|
|
6
21
|
linearVelocity: Point;
|
|
22
|
+
/** Angular velocity (radians/second) */
|
|
7
23
|
angularVelocity: number;
|
|
24
|
+
/** Axis-Aligned Bounding Box for broad phase collision */
|
|
8
25
|
AABB: {
|
|
9
26
|
min: Point;
|
|
10
27
|
max: Point;
|
|
11
28
|
};
|
|
29
|
+
/** Mass in arbitrary units (affects force response) */
|
|
12
30
|
mass: number;
|
|
31
|
+
/** Static friction coefficient (0-1) */
|
|
13
32
|
staticFrictionCoeff: number;
|
|
33
|
+
/** Moment of inertia (rotational mass) */
|
|
14
34
|
momentOfInertia: number;
|
|
35
|
+
/** Collision filtering configuration */
|
|
15
36
|
collisionFilter: CollisionFilter;
|
|
16
37
|
isSleeping: boolean;
|
|
17
38
|
sleepThreshold: number;
|
package/world.d.ts
CHANGED
|
@@ -2,7 +2,58 @@ import { RigidBody } from "./rigidbody";
|
|
|
2
2
|
import { Point } from "@ue-too/math";
|
|
3
3
|
import { Constraint } from "./constraint";
|
|
4
4
|
import { PairManager } from "./pair-manager";
|
|
5
|
+
/**
|
|
6
|
+
* Spatial indexing algorithm types.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Different algorithms have different performance characteristics:
|
|
10
|
+
* - **quadtree**: Best for static or mostly-static worlds
|
|
11
|
+
* - **dynamictree**: Good balance for mixed static/dynamic
|
|
12
|
+
* - **sap**: Best for many dynamic bodies (sweep-and-prune)
|
|
13
|
+
*
|
|
14
|
+
* @category Core
|
|
15
|
+
*/
|
|
5
16
|
export type SpatialIndexType = 'quadtree' | 'dynamictree' | 'sap';
|
|
17
|
+
/**
|
|
18
|
+
* Main physics world managing rigid body simulation.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* The World class is the main entry point for physics simulation. It manages
|
|
22
|
+
* all rigid bodies, runs collision detection and response, enforces constraints,
|
|
23
|
+
* and provides performance optimizations like sleeping and spatial indexing.
|
|
24
|
+
*
|
|
25
|
+
* ### Simulation Loop
|
|
26
|
+
*
|
|
27
|
+
* Call `world.step(deltaTime)` each frame to advance the simulation. This:
|
|
28
|
+
* 1. Updates sleeping states
|
|
29
|
+
* 2. Detects collisions (broad and narrow phase)
|
|
30
|
+
* 3. Resolves collisions with impulses
|
|
31
|
+
* 4. Enforces constraints
|
|
32
|
+
* 5. Updates body positions and velocities
|
|
33
|
+
*
|
|
34
|
+
* ### Performance Tuning
|
|
35
|
+
*
|
|
36
|
+
* - Choose appropriate spatial index for your use case
|
|
37
|
+
* - Enable sleeping for better performance with many bodies
|
|
38
|
+
* - Use collision filtering to reduce collision checks
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* Basic setup
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const world = new World(2000, 2000, 'dynamictree');
|
|
44
|
+
*
|
|
45
|
+
* // Add bodies
|
|
46
|
+
* const ball = new Circle({ x: 0, y: 100 }, 20, 0, 10, false);
|
|
47
|
+
* world.addRigidBody('ball', ball);
|
|
48
|
+
*
|
|
49
|
+
* // Simulation loop
|
|
50
|
+
* function update(dt: number) {
|
|
51
|
+
* world.step(dt);
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @category Core
|
|
56
|
+
*/
|
|
6
57
|
export declare class World {
|
|
7
58
|
private rigidBodyList;
|
|
8
59
|
private rigidBodyMap;
|