@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,201 +1,201 @@
|
|
|
1
|
-
# RigidBodyComponent
|
|
2
|
-
|
|
3
|
-
RigidBodyComponentThree adds Rapier physics to GameObjects with automatic position syncing, collision detection, and trigger events.
|
|
4
|
-
|
|
5
|
-
## Quick Start
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { RigidBodyComponentThree, RigidBodyType, ColliderShape } from "@series-ai/rundot-3d-engine/systems"
|
|
9
|
-
|
|
10
|
-
// Dynamic physics object
|
|
11
|
-
const ball = new GameObject("Ball")
|
|
12
|
-
ball.addComponent(new RigidBodyComponentThree({
|
|
13
|
-
type: RigidBodyType.DYNAMIC,
|
|
14
|
-
shape: ColliderShape.SPHERE,
|
|
15
|
-
radius: 0.5,
|
|
16
|
-
mass: 1.0,
|
|
17
|
-
restitution: 0.8 // Bouncy!
|
|
18
|
-
}))
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Common Use Cases
|
|
22
|
-
|
|
23
|
-
### Dynamic Body (Moves with Physics)
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
const crate = new GameObject("Crate")
|
|
27
|
-
crate.addComponent(new RigidBodyComponentThree({
|
|
28
|
-
type: RigidBodyType.DYNAMIC,
|
|
29
|
-
shape: ColliderShape.BOX,
|
|
30
|
-
size: new THREE.Vector3(1, 1, 1),
|
|
31
|
-
mass: 10,
|
|
32
|
-
friction: 0.5,
|
|
33
|
-
restitution: 0.2
|
|
34
|
-
}))
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Static Body (Immovable)
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
const ground = new GameObject("Ground")
|
|
41
|
-
ground.addComponent(new RigidBodyComponentThree({
|
|
42
|
-
type: RigidBodyType.STATIC,
|
|
43
|
-
shape: ColliderShape.BOX,
|
|
44
|
-
size: new THREE.Vector3(20, 0.5, 20)
|
|
45
|
-
}))
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Kinematic Body (Script-Controlled)
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
const platform = new GameObject("MovingPlatform")
|
|
52
|
-
const rb = new RigidBodyComponentThree({
|
|
53
|
-
type: RigidBodyType.KINEMATIC,
|
|
54
|
-
shape: ColliderShape.BOX,
|
|
55
|
-
size: new THREE.Vector3(3, 0.5, 3)
|
|
56
|
-
})
|
|
57
|
-
platform.addComponent(rb)
|
|
58
|
-
|
|
59
|
-
// Move kinematically
|
|
60
|
-
rb.setNextKinematicTranslation(new THREE.Vector3(5, 2, 0))
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Trigger Collider (No Physics, Detects Overlap)
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
class TriggerZone extends Component {
|
|
67
|
-
protected onCreate(): void {
|
|
68
|
-
const trigger = new RigidBodyComponentThree({
|
|
69
|
-
type: RigidBodyType.STATIC,
|
|
70
|
-
shape: ColliderShape.BOX,
|
|
71
|
-
size: new THREE.Vector3(5, 5, 5),
|
|
72
|
-
isSensor: true // Trigger mode
|
|
73
|
-
})
|
|
74
|
-
this.gameObject.addComponent(trigger)
|
|
75
|
-
|
|
76
|
-
// Register callbacks
|
|
77
|
-
trigger.onTriggerEnter((other) => {
|
|
78
|
-
console.log("Entered:", other.name)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
trigger.onTriggerExit((other) => {
|
|
82
|
-
console.log("Exited:", other.name)
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Auto-Fit to Mesh Bounds
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
// Automatically calculate size from mesh
|
|
92
|
-
const renderer = new MeshRenderer("complex_mesh")
|
|
93
|
-
const meshObj = new GameObject("MeshObject")
|
|
94
|
-
meshObj.addComponent(renderer)
|
|
95
|
-
this.gameObject.add(meshObj)
|
|
96
|
-
|
|
97
|
-
this.gameObject.addComponent(new RigidBodyComponentThree({
|
|
98
|
-
type: RigidBodyType.DYNAMIC,
|
|
99
|
-
shape: ColliderShape.BOX,
|
|
100
|
-
fitToMesh: true // Auto-calculates size
|
|
101
|
-
}))
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Lock Rotations/Translations
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
// Character controller - no rotation
|
|
108
|
-
const character = new GameObject("Character")
|
|
109
|
-
character.addComponent(new RigidBodyComponentThree({
|
|
110
|
-
type: RigidBodyType.DYNAMIC,
|
|
111
|
-
shape: ColliderShape.CAPSULE,
|
|
112
|
-
radius: 0.5,
|
|
113
|
-
height: 2,
|
|
114
|
-
lockRotationX: true,
|
|
115
|
-
lockRotationY: true,
|
|
116
|
-
lockRotationZ: true
|
|
117
|
-
}))
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## API Overview
|
|
121
|
-
|
|
122
|
-
### Constructor Options
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
interface RigidBodyOptions {
|
|
126
|
-
type?: RigidBodyType // DYNAMIC, STATIC, KINEMATIC
|
|
127
|
-
shape?: ColliderShape // BOX, SPHERE, CAPSULE
|
|
128
|
-
size?: THREE.Vector3 // Box dimensions
|
|
129
|
-
radius?: number // Sphere/capsule radius
|
|
130
|
-
height?: number // Capsule height
|
|
131
|
-
mass?: number // Body mass
|
|
132
|
-
restitution?: number // Bounciness (0-1)
|
|
133
|
-
friction?: number // Surface friction
|
|
134
|
-
isSensor?: boolean // Trigger mode
|
|
135
|
-
fitToMesh?: boolean // Auto-size from mesh
|
|
136
|
-
centerOffset?: THREE.Vector3 // Collider offset
|
|
137
|
-
linearDamping?: number // Velocity damping
|
|
138
|
-
angularDamping?: number // Rotation damping
|
|
139
|
-
lockRotationX/Y/Z?: boolean // Lock rotations
|
|
140
|
-
lockTranslationX/Y/Z?: boolean // Lock movement
|
|
141
|
-
enableCollisionEvents?: boolean // Collision callbacks
|
|
142
|
-
collisionGroups?: number // Collision filtering
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Methods
|
|
147
|
-
|
|
148
|
-
- `applyForce(force: THREE.Vector3)` - Apply force at center
|
|
149
|
-
- `applyImpulse(impulse: THREE.Vector3)` - Apply instant impulse
|
|
150
|
-
- `setLinearVelocity(velocity: THREE.Vector3)` - Set velocity directly
|
|
151
|
-
- `getLinearVelocity(): THREE.Vector3` - Get current velocity
|
|
152
|
-
- `setAngularVelocity(velocity: THREE.Vector3)` - Set rotation velocity
|
|
153
|
-
- `setNextKinematicTranslation(position: THREE.Vector3)` - Move kinematic body
|
|
154
|
-
- `onTriggerEnter(callback)` - Register trigger enter callback
|
|
155
|
-
- `onTriggerExit(callback)` - Register trigger exit callback
|
|
156
|
-
|
|
157
|
-
## Patterns & Best Practices
|
|
158
|
-
|
|
159
|
-
### Choose Correct Body Type
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
// Dynamic - Affected by forces, gravity, collisions
|
|
163
|
-
RigidBodyType.DYNAMIC // Use for: balls, crates, ragdolls
|
|
164
|
-
|
|
165
|
-
// Static - Never moves, infinite mass
|
|
166
|
-
RigidBodyType.STATIC // Use for: ground, walls, buildings
|
|
167
|
-
|
|
168
|
-
// Kinematic - Script-controlled, affects others
|
|
169
|
-
RigidBodyType.KINEMATIC // Use for: moving platforms, doors
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Use Appropriate Shapes
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
// Box - Most common, good performance
|
|
176
|
-
ColliderShape.BOX
|
|
177
|
-
|
|
178
|
-
// Sphere - Best for balls, rolling objects
|
|
179
|
-
ColliderShape.SPHERE
|
|
180
|
-
|
|
181
|
-
// Capsule - Perfect for characters (smooth movement)
|
|
182
|
-
ColliderShape.CAPSULE
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Damping for Smooth Movement
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
// Add damping to prevent sliding
|
|
189
|
-
new RigidBodyComponentThree({
|
|
190
|
-
type: RigidBodyType.DYNAMIC,
|
|
191
|
-
linearDamping: 0.5, // Slows down over time
|
|
192
|
-
angularDamping: 0.5 // Reduces spinning
|
|
193
|
-
})
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
## Related Systems
|
|
197
|
-
|
|
198
|
-
- [PhysicsSystem](PhysicsSystem.md) - Physics simulation manager
|
|
199
|
-
- [Colliders](Colliders.md) - Collision shapes and triggers
|
|
200
|
-
- [GameObject](../core/GameObject.md) - Entity class
|
|
201
|
-
|
|
1
|
+
# RigidBodyComponent
|
|
2
|
+
|
|
3
|
+
RigidBodyComponentThree adds Rapier physics to GameObjects with automatic position syncing, collision detection, and trigger events.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { RigidBodyComponentThree, RigidBodyType, ColliderShape } from "@series-ai/rundot-3d-engine/systems"
|
|
9
|
+
|
|
10
|
+
// Dynamic physics object
|
|
11
|
+
const ball = new GameObject("Ball")
|
|
12
|
+
ball.addComponent(new RigidBodyComponentThree({
|
|
13
|
+
type: RigidBodyType.DYNAMIC,
|
|
14
|
+
shape: ColliderShape.SPHERE,
|
|
15
|
+
radius: 0.5,
|
|
16
|
+
mass: 1.0,
|
|
17
|
+
restitution: 0.8 // Bouncy!
|
|
18
|
+
}))
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Common Use Cases
|
|
22
|
+
|
|
23
|
+
### Dynamic Body (Moves with Physics)
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
const crate = new GameObject("Crate")
|
|
27
|
+
crate.addComponent(new RigidBodyComponentThree({
|
|
28
|
+
type: RigidBodyType.DYNAMIC,
|
|
29
|
+
shape: ColliderShape.BOX,
|
|
30
|
+
size: new THREE.Vector3(1, 1, 1),
|
|
31
|
+
mass: 10,
|
|
32
|
+
friction: 0.5,
|
|
33
|
+
restitution: 0.2
|
|
34
|
+
}))
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Static Body (Immovable)
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const ground = new GameObject("Ground")
|
|
41
|
+
ground.addComponent(new RigidBodyComponentThree({
|
|
42
|
+
type: RigidBodyType.STATIC,
|
|
43
|
+
shape: ColliderShape.BOX,
|
|
44
|
+
size: new THREE.Vector3(20, 0.5, 20)
|
|
45
|
+
}))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Kinematic Body (Script-Controlled)
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const platform = new GameObject("MovingPlatform")
|
|
52
|
+
const rb = new RigidBodyComponentThree({
|
|
53
|
+
type: RigidBodyType.KINEMATIC,
|
|
54
|
+
shape: ColliderShape.BOX,
|
|
55
|
+
size: new THREE.Vector3(3, 0.5, 3)
|
|
56
|
+
})
|
|
57
|
+
platform.addComponent(rb)
|
|
58
|
+
|
|
59
|
+
// Move kinematically
|
|
60
|
+
rb.setNextKinematicTranslation(new THREE.Vector3(5, 2, 0))
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Trigger Collider (No Physics, Detects Overlap)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
class TriggerZone extends Component {
|
|
67
|
+
protected onCreate(): void {
|
|
68
|
+
const trigger = new RigidBodyComponentThree({
|
|
69
|
+
type: RigidBodyType.STATIC,
|
|
70
|
+
shape: ColliderShape.BOX,
|
|
71
|
+
size: new THREE.Vector3(5, 5, 5),
|
|
72
|
+
isSensor: true // Trigger mode
|
|
73
|
+
})
|
|
74
|
+
this.gameObject.addComponent(trigger)
|
|
75
|
+
|
|
76
|
+
// Register callbacks
|
|
77
|
+
trigger.onTriggerEnter((other) => {
|
|
78
|
+
console.log("Entered:", other.name)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
trigger.onTriggerExit((other) => {
|
|
82
|
+
console.log("Exited:", other.name)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Auto-Fit to Mesh Bounds
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Automatically calculate size from mesh
|
|
92
|
+
const renderer = new MeshRenderer("complex_mesh")
|
|
93
|
+
const meshObj = new GameObject("MeshObject")
|
|
94
|
+
meshObj.addComponent(renderer)
|
|
95
|
+
this.gameObject.add(meshObj)
|
|
96
|
+
|
|
97
|
+
this.gameObject.addComponent(new RigidBodyComponentThree({
|
|
98
|
+
type: RigidBodyType.DYNAMIC,
|
|
99
|
+
shape: ColliderShape.BOX,
|
|
100
|
+
fitToMesh: true // Auto-calculates size
|
|
101
|
+
}))
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Lock Rotations/Translations
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// Character controller - no rotation
|
|
108
|
+
const character = new GameObject("Character")
|
|
109
|
+
character.addComponent(new RigidBodyComponentThree({
|
|
110
|
+
type: RigidBodyType.DYNAMIC,
|
|
111
|
+
shape: ColliderShape.CAPSULE,
|
|
112
|
+
radius: 0.5,
|
|
113
|
+
height: 2,
|
|
114
|
+
lockRotationX: true,
|
|
115
|
+
lockRotationY: true,
|
|
116
|
+
lockRotationZ: true
|
|
117
|
+
}))
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## API Overview
|
|
121
|
+
|
|
122
|
+
### Constructor Options
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
interface RigidBodyOptions {
|
|
126
|
+
type?: RigidBodyType // DYNAMIC, STATIC, KINEMATIC
|
|
127
|
+
shape?: ColliderShape // BOX, SPHERE, CAPSULE
|
|
128
|
+
size?: THREE.Vector3 // Box dimensions
|
|
129
|
+
radius?: number // Sphere/capsule radius
|
|
130
|
+
height?: number // Capsule height
|
|
131
|
+
mass?: number // Body mass
|
|
132
|
+
restitution?: number // Bounciness (0-1)
|
|
133
|
+
friction?: number // Surface friction
|
|
134
|
+
isSensor?: boolean // Trigger mode
|
|
135
|
+
fitToMesh?: boolean // Auto-size from mesh
|
|
136
|
+
centerOffset?: THREE.Vector3 // Collider offset
|
|
137
|
+
linearDamping?: number // Velocity damping
|
|
138
|
+
angularDamping?: number // Rotation damping
|
|
139
|
+
lockRotationX/Y/Z?: boolean // Lock rotations
|
|
140
|
+
lockTranslationX/Y/Z?: boolean // Lock movement
|
|
141
|
+
enableCollisionEvents?: boolean // Collision callbacks
|
|
142
|
+
collisionGroups?: number // Collision filtering
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Methods
|
|
147
|
+
|
|
148
|
+
- `applyForce(force: THREE.Vector3)` - Apply force at center
|
|
149
|
+
- `applyImpulse(impulse: THREE.Vector3)` - Apply instant impulse
|
|
150
|
+
- `setLinearVelocity(velocity: THREE.Vector3)` - Set velocity directly
|
|
151
|
+
- `getLinearVelocity(): THREE.Vector3` - Get current velocity
|
|
152
|
+
- `setAngularVelocity(velocity: THREE.Vector3)` - Set rotation velocity
|
|
153
|
+
- `setNextKinematicTranslation(position: THREE.Vector3)` - Move kinematic body
|
|
154
|
+
- `onTriggerEnter(callback)` - Register trigger enter callback
|
|
155
|
+
- `onTriggerExit(callback)` - Register trigger exit callback
|
|
156
|
+
|
|
157
|
+
## Patterns & Best Practices
|
|
158
|
+
|
|
159
|
+
### Choose Correct Body Type
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Dynamic - Affected by forces, gravity, collisions
|
|
163
|
+
RigidBodyType.DYNAMIC // Use for: balls, crates, ragdolls
|
|
164
|
+
|
|
165
|
+
// Static - Never moves, infinite mass
|
|
166
|
+
RigidBodyType.STATIC // Use for: ground, walls, buildings
|
|
167
|
+
|
|
168
|
+
// Kinematic - Script-controlled, affects others
|
|
169
|
+
RigidBodyType.KINEMATIC // Use for: moving platforms, doors
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Use Appropriate Shapes
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// Box - Most common, good performance
|
|
176
|
+
ColliderShape.BOX
|
|
177
|
+
|
|
178
|
+
// Sphere - Best for balls, rolling objects
|
|
179
|
+
ColliderShape.SPHERE
|
|
180
|
+
|
|
181
|
+
// Capsule - Perfect for characters (smooth movement)
|
|
182
|
+
ColliderShape.CAPSULE
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Damping for Smooth Movement
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// Add damping to prevent sliding
|
|
189
|
+
new RigidBodyComponentThree({
|
|
190
|
+
type: RigidBodyType.DYNAMIC,
|
|
191
|
+
linearDamping: 0.5, // Slows down over time
|
|
192
|
+
angularDamping: 0.5 // Reduces spinning
|
|
193
|
+
})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Related Systems
|
|
197
|
+
|
|
198
|
+
- [PhysicsSystem](PhysicsSystem.md) - Physics simulation manager
|
|
199
|
+
- [Colliders](Colliders.md) - Collision shapes and triggers
|
|
200
|
+
- [GameObject](../core/GameObject.md) - Entity class
|
|
201
|
+
|