@series-inc/rundot-3d-engine 0.3.0 → 0.4.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/LICENSE.txt +6 -6
- package/docs/core/Component.md +321 -321
- package/docs/core/GameObject.md +204 -204
- package/docs/core/VenusGame.md +316 -316
- package/docs/patterns/ComponentCommunication.md +337 -337
- package/docs/patterns/CreatingGameObjects.md +290 -290
- package/docs/patterns/MeshColliders.md +338 -338
- package/docs/patterns/MeshLoading.md +316 -316
- package/docs/physics/Colliders.md +249 -249
- package/docs/physics/PhysicsSystem.md +151 -151
- package/docs/physics/RigidBodyComponent.md +201 -201
- package/docs/rendering/AssetManager.md +308 -308
- package/docs/rendering/InstancedRenderer.md +286 -286
- package/docs/rendering/MeshRenderer.md +286 -286
- package/docs/rendering/SkeletalRenderer.md +308 -308
- package/docs/systems/AnimationSystem.md +75 -75
- package/docs/systems/AudioSystem.md +79 -79
- package/docs/systems/InputManager.md +101 -101
- package/docs/systems/LightingSystem.md +101 -101
- package/docs/systems/ParticleSystem.md +44 -44
- package/docs/systems/PrefabSystem.md +60 -60
- package/docs/systems/StowKitSystem.md +77 -77
- package/docs/systems/TweenSystem.md +132 -132
- package/docs/systems/UISystem.md +73 -73
- package/package.json +1 -1
- package/scripts/postinstall.mjs +63 -51
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
# PhysicsSystem
|
|
2
|
-
|
|
3
|
-
PhysicsSystem manages Rapier3D physics simulation with fixed-step integration, collision detection, and trigger events.
|
|
4
|
-
|
|
5
|
-
## Quick Start
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { PhysicsSystem } from "@series-ai/rundot-3d-engine/systems"
|
|
9
|
-
|
|
10
|
-
// Initialize (done automatically by VenusGame)
|
|
11
|
-
await PhysicsSystem.initialize()
|
|
12
|
-
|
|
13
|
-
// Physics steps automatically in game loop
|
|
14
|
-
// Add RigidBodyComponent to GameObjects for physics
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Common Use Cases
|
|
18
|
-
|
|
19
|
-
### Adding Physics to GameObject
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { RigidBodyComponentThree, RigidBodyType } from "@series-ai/rundot-3d-engine/systems"
|
|
23
|
-
|
|
24
|
-
// Dynamic body (affected by gravity, forces)
|
|
25
|
-
const box = new GameObject("Box")
|
|
26
|
-
box.addComponent(new RigidBodyComponentThree({
|
|
27
|
-
type: RigidBodyType.DYNAMIC,
|
|
28
|
-
shape: ColliderShape.BOX,
|
|
29
|
-
size: new THREE.Vector3(1, 1, 1),
|
|
30
|
-
mass: 1.0
|
|
31
|
-
}))
|
|
32
|
-
|
|
33
|
-
// Static body (immovable, like ground)
|
|
34
|
-
const ground = new GameObject("Ground")
|
|
35
|
-
ground.addComponent(new RigidBodyComponentThree({
|
|
36
|
-
type: RigidBodyType.STATIC,
|
|
37
|
-
shape: ColliderShape.BOX,
|
|
38
|
-
size: new THREE.Vector3(10, 0.1, 10)
|
|
39
|
-
}))
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Configuring Physics Stepping
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// Configure fixed timestep (default: 120 Hz)
|
|
46
|
-
PhysicsSystem.configure({
|
|
47
|
-
fixedTimeStep: 1/60, // 60 Hz
|
|
48
|
-
maxSubSteps: 4 // Max catch-up steps
|
|
49
|
-
})
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Accessing Physics World
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
// Get Rapier world for advanced usage
|
|
56
|
-
const world = PhysicsSystem.getWorld()
|
|
57
|
-
if (world) {
|
|
58
|
-
// Direct Rapier API access
|
|
59
|
-
world.gravity.y = -20 // Stronger gravity
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## API Overview
|
|
64
|
-
|
|
65
|
-
### Initialization
|
|
66
|
-
|
|
67
|
-
- `PhysicsSystem.initialize(): Promise<void>` - Initialize Rapier physics
|
|
68
|
-
- `PhysicsSystem.isReady(): boolean` - Check if initialized
|
|
69
|
-
|
|
70
|
-
### Configuration
|
|
71
|
-
|
|
72
|
-
- `configure(params)` - Set fixedTimeStep, maxSubSteps
|
|
73
|
-
- `getInterpolationAlpha(): number` - Get render interpolation value
|
|
74
|
-
|
|
75
|
-
### World Access
|
|
76
|
-
|
|
77
|
-
- `getWorld(): World | null` - Get Rapier physics world
|
|
78
|
-
- `step(deltaTime)` - Step simulation (called automatically)
|
|
79
|
-
|
|
80
|
-
### Body Management
|
|
81
|
-
|
|
82
|
-
- `createRigidBody(id, desc, colliderDesc?)` - Create physics body
|
|
83
|
-
- `getRigidBody(id): RigidBody | null` - Get body by ID
|
|
84
|
-
- `removeRigidBody(id)` - Remove and cleanup body
|
|
85
|
-
|
|
86
|
-
### Collision Events
|
|
87
|
-
|
|
88
|
-
- `registerGameObject(colliderId, gameObject)` - Register for collision events
|
|
89
|
-
- `registerTriggerComponent(colliderId, component)` - Register for trigger callbacks
|
|
90
|
-
- `unregisterGameObject(colliderId)` - Unregister GameObject
|
|
91
|
-
- `unregisterTriggerComponent(colliderId)` - Unregister component
|
|
92
|
-
|
|
93
|
-
### Debug Visualization
|
|
94
|
-
|
|
95
|
-
- `enableDebug(scene)` - Show collision shapes
|
|
96
|
-
- `disableDebug()` - Hide debug visualization
|
|
97
|
-
- `isDebugEnabled(): boolean` - Check debug state
|
|
98
|
-
|
|
99
|
-
## Fixed-Step Integration
|
|
100
|
-
|
|
101
|
-
PhysicsSystem uses fixed timestep for deterministic simulation:
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
// Physics steps at fixed rate (default 120 Hz)
|
|
105
|
-
// Rendering can be any framerate (60 Hz, 144 Hz, etc.)
|
|
106
|
-
// System accumulates time and steps physics in fixed increments
|
|
107
|
-
|
|
108
|
-
// Example: 60 FPS render, 120 Hz physics
|
|
109
|
-
// Each render frame = 2 physics steps
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Benefits:
|
|
113
|
-
- Deterministic simulation
|
|
114
|
-
- Stable at any framerate
|
|
115
|
-
- No physics explosions on slow frames
|
|
116
|
-
|
|
117
|
-
## Patterns & Best Practices
|
|
118
|
-
|
|
119
|
-
### Use RigidBodyComponent
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
// Good - Use component system
|
|
123
|
-
const obj = new GameObject("PhysicsObject")
|
|
124
|
-
obj.addComponent(new RigidBodyComponentThree({
|
|
125
|
-
type: RigidBodyType.DYNAMIC
|
|
126
|
-
}))
|
|
127
|
-
|
|
128
|
-
// Avoid - Direct PhysicsSystem calls
|
|
129
|
-
// PhysicsSystem.createRigidBody(...) // Manual management
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Configure Once at Startup
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
class MyGame extends VenusGame {
|
|
136
|
-
protected async onStart(): Promise<void> {
|
|
137
|
-
// Configure physics before creating bodies
|
|
138
|
-
PhysicsSystem.configure({
|
|
139
|
-
fixedTimeStep: 1/120,
|
|
140
|
-
maxSubSteps: 8
|
|
141
|
-
})
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Related Systems
|
|
147
|
-
|
|
148
|
-
- [RigidBodyComponent](RigidBodyComponent.md) - Add physics to GameObjects
|
|
149
|
-
- [Colliders](Colliders.md) - Collision shapes and triggers
|
|
150
|
-
- [VenusGame](../core/VenusGame.md) - Initializes PhysicsSystem
|
|
151
|
-
|
|
1
|
+
# PhysicsSystem
|
|
2
|
+
|
|
3
|
+
PhysicsSystem manages Rapier3D physics simulation with fixed-step integration, collision detection, and trigger events.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { PhysicsSystem } from "@series-ai/rundot-3d-engine/systems"
|
|
9
|
+
|
|
10
|
+
// Initialize (done automatically by VenusGame)
|
|
11
|
+
await PhysicsSystem.initialize()
|
|
12
|
+
|
|
13
|
+
// Physics steps automatically in game loop
|
|
14
|
+
// Add RigidBodyComponent to GameObjects for physics
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Common Use Cases
|
|
18
|
+
|
|
19
|
+
### Adding Physics to GameObject
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { RigidBodyComponentThree, RigidBodyType } from "@series-ai/rundot-3d-engine/systems"
|
|
23
|
+
|
|
24
|
+
// Dynamic body (affected by gravity, forces)
|
|
25
|
+
const box = new GameObject("Box")
|
|
26
|
+
box.addComponent(new RigidBodyComponentThree({
|
|
27
|
+
type: RigidBodyType.DYNAMIC,
|
|
28
|
+
shape: ColliderShape.BOX,
|
|
29
|
+
size: new THREE.Vector3(1, 1, 1),
|
|
30
|
+
mass: 1.0
|
|
31
|
+
}))
|
|
32
|
+
|
|
33
|
+
// Static body (immovable, like ground)
|
|
34
|
+
const ground = new GameObject("Ground")
|
|
35
|
+
ground.addComponent(new RigidBodyComponentThree({
|
|
36
|
+
type: RigidBodyType.STATIC,
|
|
37
|
+
shape: ColliderShape.BOX,
|
|
38
|
+
size: new THREE.Vector3(10, 0.1, 10)
|
|
39
|
+
}))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Configuring Physics Stepping
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Configure fixed timestep (default: 120 Hz)
|
|
46
|
+
PhysicsSystem.configure({
|
|
47
|
+
fixedTimeStep: 1/60, // 60 Hz
|
|
48
|
+
maxSubSteps: 4 // Max catch-up steps
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Accessing Physics World
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// Get Rapier world for advanced usage
|
|
56
|
+
const world = PhysicsSystem.getWorld()
|
|
57
|
+
if (world) {
|
|
58
|
+
// Direct Rapier API access
|
|
59
|
+
world.gravity.y = -20 // Stronger gravity
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API Overview
|
|
64
|
+
|
|
65
|
+
### Initialization
|
|
66
|
+
|
|
67
|
+
- `PhysicsSystem.initialize(): Promise<void>` - Initialize Rapier physics
|
|
68
|
+
- `PhysicsSystem.isReady(): boolean` - Check if initialized
|
|
69
|
+
|
|
70
|
+
### Configuration
|
|
71
|
+
|
|
72
|
+
- `configure(params)` - Set fixedTimeStep, maxSubSteps
|
|
73
|
+
- `getInterpolationAlpha(): number` - Get render interpolation value
|
|
74
|
+
|
|
75
|
+
### World Access
|
|
76
|
+
|
|
77
|
+
- `getWorld(): World | null` - Get Rapier physics world
|
|
78
|
+
- `step(deltaTime)` - Step simulation (called automatically)
|
|
79
|
+
|
|
80
|
+
### Body Management
|
|
81
|
+
|
|
82
|
+
- `createRigidBody(id, desc, colliderDesc?)` - Create physics body
|
|
83
|
+
- `getRigidBody(id): RigidBody | null` - Get body by ID
|
|
84
|
+
- `removeRigidBody(id)` - Remove and cleanup body
|
|
85
|
+
|
|
86
|
+
### Collision Events
|
|
87
|
+
|
|
88
|
+
- `registerGameObject(colliderId, gameObject)` - Register for collision events
|
|
89
|
+
- `registerTriggerComponent(colliderId, component)` - Register for trigger callbacks
|
|
90
|
+
- `unregisterGameObject(colliderId)` - Unregister GameObject
|
|
91
|
+
- `unregisterTriggerComponent(colliderId)` - Unregister component
|
|
92
|
+
|
|
93
|
+
### Debug Visualization
|
|
94
|
+
|
|
95
|
+
- `enableDebug(scene)` - Show collision shapes
|
|
96
|
+
- `disableDebug()` - Hide debug visualization
|
|
97
|
+
- `isDebugEnabled(): boolean` - Check debug state
|
|
98
|
+
|
|
99
|
+
## Fixed-Step Integration
|
|
100
|
+
|
|
101
|
+
PhysicsSystem uses fixed timestep for deterministic simulation:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
// Physics steps at fixed rate (default 120 Hz)
|
|
105
|
+
// Rendering can be any framerate (60 Hz, 144 Hz, etc.)
|
|
106
|
+
// System accumulates time and steps physics in fixed increments
|
|
107
|
+
|
|
108
|
+
// Example: 60 FPS render, 120 Hz physics
|
|
109
|
+
// Each render frame = 2 physics steps
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Benefits:
|
|
113
|
+
- Deterministic simulation
|
|
114
|
+
- Stable at any framerate
|
|
115
|
+
- No physics explosions on slow frames
|
|
116
|
+
|
|
117
|
+
## Patterns & Best Practices
|
|
118
|
+
|
|
119
|
+
### Use RigidBodyComponent
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Good - Use component system
|
|
123
|
+
const obj = new GameObject("PhysicsObject")
|
|
124
|
+
obj.addComponent(new RigidBodyComponentThree({
|
|
125
|
+
type: RigidBodyType.DYNAMIC
|
|
126
|
+
}))
|
|
127
|
+
|
|
128
|
+
// Avoid - Direct PhysicsSystem calls
|
|
129
|
+
// PhysicsSystem.createRigidBody(...) // Manual management
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Configure Once at Startup
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
class MyGame extends VenusGame {
|
|
136
|
+
protected async onStart(): Promise<void> {
|
|
137
|
+
// Configure physics before creating bodies
|
|
138
|
+
PhysicsSystem.configure({
|
|
139
|
+
fixedTimeStep: 1/120,
|
|
140
|
+
maxSubSteps: 8
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Related Systems
|
|
147
|
+
|
|
148
|
+
- [RigidBodyComponent](RigidBodyComponent.md) - Add physics to GameObjects
|
|
149
|
+
- [Colliders](Colliders.md) - Collision shapes and triggers
|
|
150
|
+
- [VenusGame](../core/VenusGame.md) - Initializes PhysicsSystem
|
|
151
|
+
|