@react-three/rapier 1.4.0 → 1.5.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/dist/declarations/src/components/AnyCollider.d.ts +2 -2
- package/dist/declarations/src/components/InstancedRigidBodies.d.ts +2 -2
- package/dist/declarations/src/components/MeshCollider.d.ts +2 -2
- package/dist/declarations/src/components/Physics.d.ts +8 -4
- package/dist/declarations/src/components/RigidBody.d.ts +1 -1
- package/dist/declarations/src/hooks/hooks.d.ts +3 -3
- package/dist/declarations/src/hooks/joints.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +15 -15
- package/dist/declarations/src/types.d.ts +2 -2
- package/dist/declarations/src/utils/interaction-groups.d.ts +1 -1
- package/dist/react-three-rapier.cjs.d.ts +1 -0
- package/dist/react-three-rapier.cjs.dev.js +148 -272
- package/dist/react-three-rapier.cjs.prod.js +148 -272
- package/dist/react-three-rapier.esm.js +148 -272
- package/package.json +8 -13
- package/readme.md +0 -2
- package/dist/declarations/src/components/Debug.d.ts +0 -2
- package/dist/declarations/src/components/FrameStepper.d.ts +0 -9
- package/dist/declarations/src/hooks/use-forwarded-ref.d.ts +0 -2
- package/dist/declarations/src/hooks/use-imperative-instance.d.ts +0 -5
- package/dist/declarations/src/utils/shared-objects.d.ts +0 -9
- package/dist/declarations/src/utils/singleton-proxy.d.ts +0 -11
- package/dist/declarations/src/utils/utils-collider.d.ts +0 -83
- package/dist/declarations/src/utils/utils-physics.d.ts +0 -1
- package/dist/declarations/src/utils/utils-rigidbody.d.ts +0 -24
- package/dist/declarations/src/utils/utils.d.ts +0 -14
@@ -6,45 +6,51 @@ import { Quaternion, Euler, Vector3, Object3D, Matrix4, BufferAttribute, MathUti
|
|
6
6
|
import { suspend } from 'suspend-react';
|
7
7
|
import { mergeVertices } from 'three-stdlib';
|
8
8
|
|
9
|
-
function
|
10
|
-
if (
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
});
|
17
|
-
} else {
|
18
|
-
obj[key] = value;
|
9
|
+
function _toPrimitive(t, r) {
|
10
|
+
if ("object" != typeof t || !t) return t;
|
11
|
+
var e = t[Symbol.toPrimitive];
|
12
|
+
if (void 0 !== e) {
|
13
|
+
var i = e.call(t, r || "default");
|
14
|
+
if ("object" != typeof i) return i;
|
15
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
19
16
|
}
|
17
|
+
return ("string" === r ? String : Number)(t);
|
18
|
+
}
|
20
19
|
|
21
|
-
|
20
|
+
function _toPropertyKey(t) {
|
21
|
+
var i = _toPrimitive(t, "string");
|
22
|
+
return "symbol" == typeof i ? i : i + "";
|
22
23
|
}
|
23
24
|
|
24
|
-
function
|
25
|
-
|
25
|
+
function _defineProperty(e, r, t) {
|
26
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
27
|
+
value: t,
|
28
|
+
enumerable: !0,
|
29
|
+
configurable: !0,
|
30
|
+
writable: !0
|
31
|
+
}) : e[r] = t, e;
|
32
|
+
}
|
26
33
|
|
34
|
+
function ownKeys(e, r) {
|
35
|
+
var t = Object.keys(e);
|
27
36
|
if (Object.getOwnPropertySymbols) {
|
28
|
-
var
|
29
|
-
|
30
|
-
return Object.getOwnPropertyDescriptor(
|
31
|
-
})),
|
37
|
+
var o = Object.getOwnPropertySymbols(e);
|
38
|
+
r && (o = o.filter(function (r) {
|
39
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
40
|
+
})), t.push.apply(t, o);
|
32
41
|
}
|
33
|
-
|
34
|
-
return keys;
|
42
|
+
return t;
|
35
43
|
}
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
44
|
+
function _objectSpread2(e) {
|
45
|
+
for (var r = 1; r < arguments.length; r++) {
|
46
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
47
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
48
|
+
_defineProperty(e, r, t[r]);
|
49
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
50
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
44
51
|
});
|
45
52
|
}
|
46
|
-
|
47
|
-
return target;
|
53
|
+
return e;
|
48
54
|
}
|
49
55
|
|
50
56
|
const _quaternion = new Quaternion();
|
@@ -92,41 +98,33 @@ const rigidBodyTypeMap = {
|
|
92
98
|
const rigidBodyTypeFromString = type => rigidBodyTypeMap[type];
|
93
99
|
const scaleVertices = (vertices, scale) => {
|
94
100
|
const scaledVerts = Array.from(vertices);
|
95
|
-
|
96
101
|
for (let i = 0; i < vertices.length / 3; i++) {
|
97
102
|
scaledVerts[i * 3] *= scale.x;
|
98
103
|
scaledVerts[i * 3 + 1] *= scale.y;
|
99
104
|
scaledVerts[i * 3 + 2] *= scale.z;
|
100
105
|
}
|
101
|
-
|
102
106
|
return scaledVerts;
|
103
107
|
};
|
104
108
|
const vectorToTuple = v => {
|
105
109
|
if (!v) return [0];
|
106
|
-
|
107
110
|
if (v instanceof Quaternion) {
|
108
111
|
return [v.x, v.y, v.z, v.w];
|
109
112
|
}
|
110
|
-
|
111
113
|
if (v instanceof Vector3 || v instanceof Euler) {
|
112
114
|
return [v.x, v.y, v.z];
|
113
115
|
}
|
114
|
-
|
115
116
|
if (Array.isArray(v)) {
|
116
117
|
return v;
|
117
118
|
}
|
118
|
-
|
119
119
|
return [v];
|
120
120
|
};
|
121
121
|
function useConst(initialValue) {
|
122
122
|
const ref = useRef();
|
123
|
-
|
124
123
|
if (ref.current === undefined) {
|
125
124
|
ref.current = {
|
126
125
|
value: typeof initialValue === "function" ? initialValue() : initialValue
|
127
126
|
};
|
128
127
|
}
|
129
|
-
|
130
128
|
return ref.current.value;
|
131
129
|
}
|
132
130
|
|
@@ -145,7 +143,6 @@ const useRaf = callback => {
|
|
145
143
|
cb.current(delta / 1000);
|
146
144
|
lastFrame.current = now;
|
147
145
|
};
|
148
|
-
|
149
146
|
raf.current = requestAnimationFrame(loop);
|
150
147
|
return () => cancelAnimationFrame(raf.current);
|
151
148
|
}, []);
|
@@ -160,7 +157,6 @@ const UseFrameStepper = ({
|
|
160
157
|
}, updatePriority);
|
161
158
|
return null;
|
162
159
|
};
|
163
|
-
|
164
160
|
const RafStepper = ({
|
165
161
|
onStep
|
166
162
|
}) => {
|
@@ -169,7 +165,6 @@ const RafStepper = ({
|
|
169
165
|
});
|
170
166
|
return null;
|
171
167
|
};
|
172
|
-
|
173
168
|
const FrameStepper = ({
|
174
169
|
onStep,
|
175
170
|
type,
|
@@ -182,98 +177,80 @@ const FrameStepper = ({
|
|
182
177
|
updatePriority: updatePriority
|
183
178
|
});
|
184
179
|
};
|
185
|
-
|
186
180
|
var FrameStepper$1 = /*#__PURE__*/memo(FrameStepper);
|
187
181
|
|
188
|
-
function _objectWithoutPropertiesLoose(
|
189
|
-
if (
|
190
|
-
var
|
191
|
-
var
|
192
|
-
|
193
|
-
|
194
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
195
|
-
key = sourceKeys[i];
|
196
|
-
if (excluded.indexOf(key) >= 0) continue;
|
197
|
-
target[key] = source[key];
|
182
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
183
|
+
if (null == r) return {};
|
184
|
+
var t = {};
|
185
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
186
|
+
if (e.includes(n)) continue;
|
187
|
+
t[n] = r[n];
|
198
188
|
}
|
199
|
-
|
200
|
-
return target;
|
189
|
+
return t;
|
201
190
|
}
|
202
191
|
|
203
|
-
function _objectWithoutProperties(
|
204
|
-
if (
|
205
|
-
var
|
206
|
-
|
207
|
-
|
192
|
+
function _objectWithoutProperties(e, t) {
|
193
|
+
if (null == e) return {};
|
194
|
+
var o,
|
195
|
+
r,
|
196
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
208
197
|
if (Object.getOwnPropertySymbols) {
|
209
|
-
var
|
210
|
-
|
211
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
212
|
-
key = sourceSymbolKeys[i];
|
213
|
-
if (excluded.indexOf(key) >= 0) continue;
|
214
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
215
|
-
target[key] = source[key];
|
216
|
-
}
|
198
|
+
var s = Object.getOwnPropertySymbols(e);
|
199
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
217
200
|
}
|
218
|
-
|
219
|
-
return target;
|
201
|
+
return i;
|
220
202
|
}
|
221
203
|
|
222
204
|
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
|
223
205
|
const scaleColliderArgs = (shape, args, scale) => {
|
224
|
-
const newArgs = args.slice();
|
206
|
+
const newArgs = args.slice();
|
225
207
|
|
208
|
+
// Heightfield uses a vector
|
226
209
|
if (shape === "heightfield") {
|
227
210
|
const s = newArgs[3];
|
228
211
|
s.x *= scale.x;
|
229
212
|
s.x *= scale.y;
|
230
213
|
s.x *= scale.z;
|
231
214
|
return newArgs;
|
232
|
-
}
|
233
|
-
|
215
|
+
}
|
234
216
|
|
217
|
+
// Trimesh and convex scale the vertices
|
235
218
|
if (shape === "trimesh" || shape === "convexHull") {
|
236
219
|
newArgs[0] = scaleVertices(newArgs[0], scale);
|
237
220
|
return newArgs;
|
238
|
-
}
|
239
|
-
|
221
|
+
}
|
240
222
|
|
223
|
+
// Prepfill with some extra
|
241
224
|
const scaleArray = [scale.x, scale.y, scale.z, scale.x, scale.x];
|
242
225
|
return newArgs.map((arg, index) => scaleArray[index] * arg);
|
243
226
|
};
|
244
227
|
const createColliderFromOptions = (options, world, scale, getRigidBody) => {
|
245
|
-
const scaledArgs = scaleColliderArgs(options.shape, options.args, scale);
|
246
|
-
|
228
|
+
const scaledArgs = scaleColliderArgs(options.shape, options.args, scale);
|
229
|
+
// @ts-ignore
|
247
230
|
const desc = ColliderDesc[options.shape](...scaledArgs);
|
248
231
|
return world.createCollider(desc, getRigidBody === null || getRigidBody === void 0 ? void 0 : getRigidBody());
|
249
232
|
};
|
250
233
|
const immutableColliderOptions = ["shape", "args"];
|
251
234
|
const massPropertiesConflictError = "Please pick ONLY ONE of the `density`, `mass` and `massProperties` options.";
|
252
|
-
|
253
235
|
const setColliderMassOptions = (collider, options) => {
|
254
236
|
if (options.density !== undefined) {
|
255
237
|
if (options.mass !== undefined || options.massProperties !== undefined) {
|
256
238
|
throw new Error(massPropertiesConflictError);
|
257
239
|
}
|
258
|
-
|
259
240
|
collider.setDensity(options.density);
|
260
241
|
return;
|
261
242
|
}
|
262
|
-
|
263
243
|
if (options.mass !== undefined) {
|
264
244
|
if (options.massProperties !== undefined) {
|
265
245
|
throw new Error(massPropertiesConflictError);
|
266
246
|
}
|
267
|
-
|
268
247
|
collider.setMass(options.mass);
|
269
248
|
return;
|
270
249
|
}
|
271
|
-
|
272
250
|
if (options.massProperties !== undefined) {
|
273
251
|
collider.setMassProperties(options.massProperties.mass, options.massProperties.centerOfMass, options.massProperties.principalAngularInertia, options.massProperties.angularInertiaLocalFrame);
|
274
252
|
}
|
275
253
|
};
|
276
|
-
|
277
254
|
const mutableColliderOptions = {
|
278
255
|
sensor: (collider, value) => {
|
279
256
|
collider.setSensor(value);
|
@@ -311,23 +288,17 @@ const mutableColliderOptions = {
|
|
311
288
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
312
289
|
const setColliderOptions = (collider, options, states) => {
|
313
290
|
const state = states.get(collider.handle);
|
314
|
-
|
315
291
|
if (state) {
|
316
292
|
var _state$worldParent;
|
317
|
-
|
318
293
|
// Update collider position based on the object's position
|
319
294
|
const parentWorldScale = state.object.parent.getWorldScale(_vector3);
|
320
295
|
const parentInvertedWorldMatrix = (_state$worldParent = state.worldParent) === null || _state$worldParent === void 0 ? void 0 : _state$worldParent.matrixWorld.clone().invert();
|
321
296
|
state.object.updateWorldMatrix(true, false);
|
322
|
-
|
323
297
|
_matrix4.copy(state.object.matrixWorld);
|
324
|
-
|
325
298
|
if (parentInvertedWorldMatrix) {
|
326
299
|
_matrix4.premultiply(parentInvertedWorldMatrix);
|
327
300
|
}
|
328
|
-
|
329
301
|
_matrix4.decompose(_position, _rotation, _scale);
|
330
|
-
|
331
302
|
if (collider.parent()) {
|
332
303
|
collider.setTranslationWrtParent({
|
333
304
|
x: _position.x * parentWorldScale.x,
|
@@ -343,16 +314,17 @@ const setColliderOptions = (collider, options, states) => {
|
|
343
314
|
});
|
344
315
|
collider.setRotation(_rotation);
|
345
316
|
}
|
346
|
-
|
347
317
|
mutableColliderOptionKeys.forEach(key => {
|
348
318
|
if (key in options) {
|
349
319
|
const option = options[key];
|
350
|
-
mutableColliderOptions[key](collider,
|
320
|
+
mutableColliderOptions[key](collider,
|
321
|
+
// @ts-ignore Option does not want to fit into the function, but it will
|
351
322
|
option, options);
|
352
323
|
}
|
353
|
-
});
|
354
|
-
// are exclusive.
|
324
|
+
});
|
355
325
|
|
326
|
+
// handle mass separately, because the assignments
|
327
|
+
// are exclusive.
|
356
328
|
setColliderMassOptions(collider, options);
|
357
329
|
}
|
358
330
|
};
|
@@ -366,7 +338,6 @@ const useUpdateColliderOptions = (getCollider, props, states) => {
|
|
366
338
|
setColliderOptions(collider, props, states);
|
367
339
|
}, [...mutablePropsAsFlatArray, getCollider]);
|
368
340
|
};
|
369
|
-
|
370
341
|
const isChildOfMeshCollider = child => {
|
371
342
|
let flag = false;
|
372
343
|
child.traverseAncestors(a => {
|
@@ -374,7 +345,6 @@ const isChildOfMeshCollider = child => {
|
|
374
345
|
});
|
375
346
|
return flag;
|
376
347
|
};
|
377
|
-
|
378
348
|
const createColliderState = (collider, object, rigidBodyObject) => {
|
379
349
|
return {
|
380
350
|
collider,
|
@@ -396,16 +366,13 @@ const createColliderPropsFromChildren = ({
|
|
396
366
|
const childColliderProps = [];
|
397
367
|
object.updateWorldMatrix(true, false);
|
398
368
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
399
|
-
|
400
369
|
const colliderFromChild = child => {
|
401
370
|
if ("isMesh" in child) {
|
402
371
|
if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
|
403
372
|
const worldScale = child.getWorldScale(_scale);
|
404
373
|
const shape = autoColliderMap[options.colliders || "cuboid"];
|
405
374
|
child.updateWorldMatrix(true, false);
|
406
|
-
|
407
375
|
_matrix4.copy(child.matrixWorld).premultiply(invertedParentMatrixWorld).decompose(_position, _rotation, _scale);
|
408
|
-
|
409
376
|
const rotationEuler = new Euler().setFromQuaternion(_rotation, "XYZ");
|
410
377
|
const {
|
411
378
|
geometry
|
@@ -414,7 +381,6 @@ const createColliderPropsFromChildren = ({
|
|
414
381
|
args,
|
415
382
|
offset
|
416
383
|
} = getColliderArgsFromGeometry(geometry, options.colliders || "cuboid");
|
417
|
-
|
418
384
|
const colliderProps = _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(options)), {}, {
|
419
385
|
args: args,
|
420
386
|
shape: shape,
|
@@ -422,17 +388,14 @@ const createColliderPropsFromChildren = ({
|
|
422
388
|
position: [_position.x + offset.x * worldScale.x, _position.y + offset.y * worldScale.y, _position.z + offset.z * worldScale.z],
|
423
389
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
424
390
|
});
|
425
|
-
|
426
391
|
childColliderProps.push(colliderProps);
|
427
392
|
}
|
428
393
|
};
|
429
|
-
|
430
394
|
if (options.includeInvisible) {
|
431
395
|
object.traverse(colliderFromChild);
|
432
396
|
} else {
|
433
397
|
object.traverseVisible(colliderFromChild);
|
434
398
|
}
|
435
|
-
|
436
399
|
return childColliderProps;
|
437
400
|
};
|
438
401
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
@@ -449,7 +412,6 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
449
412
|
offset: boundingBox.getCenter(new Vector3())
|
450
413
|
};
|
451
414
|
}
|
452
|
-
|
453
415
|
case "ball":
|
454
416
|
{
|
455
417
|
geometry.computeBoundingSphere();
|
@@ -462,18 +424,15 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
462
424
|
offset: boundingSphere.center
|
463
425
|
};
|
464
426
|
}
|
465
|
-
|
466
427
|
case "trimesh":
|
467
428
|
{
|
468
429
|
var _clonedGeometry$index;
|
469
|
-
|
470
430
|
const clonedGeometry = geometry.index ? geometry.clone() : mergeVertices(geometry);
|
471
431
|
return {
|
472
432
|
args: [clonedGeometry.attributes.position.array, (_clonedGeometry$index = clonedGeometry.index) === null || _clonedGeometry$index === void 0 ? void 0 : _clonedGeometry$index.array],
|
473
433
|
offset: new Vector3()
|
474
434
|
};
|
475
435
|
}
|
476
|
-
|
477
436
|
case "hull":
|
478
437
|
{
|
479
438
|
const g = geometry.clone();
|
@@ -483,7 +442,6 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
483
442
|
};
|
484
443
|
}
|
485
444
|
}
|
486
|
-
|
487
445
|
return {
|
488
446
|
args: [],
|
489
447
|
offset: new Vector3()
|
@@ -509,7 +467,6 @@ activeEvents = {}) => {
|
|
509
467
|
} = props;
|
510
468
|
useEffect(() => {
|
511
469
|
const collider = getCollider();
|
512
|
-
|
513
470
|
if (collider) {
|
514
471
|
const {
|
515
472
|
collision: collisionEventsActive,
|
@@ -517,7 +474,6 @@ activeEvents = {}) => {
|
|
517
474
|
} = getActiveCollisionEventsFromProps(props);
|
518
475
|
const hasCollisionEvent = collisionEventsActive || activeEvents.collision;
|
519
476
|
const hasContactForceEvent = contactForceEventsActive || activeEvents.contactForce;
|
520
|
-
|
521
477
|
if (hasCollisionEvent && hasContactForceEvent) {
|
522
478
|
collider.setActiveEvents(ActiveEvents.COLLISION_EVENTS | ActiveEvents.CONTACT_FORCE_EVENTS);
|
523
479
|
} else if (hasCollisionEvent) {
|
@@ -525,7 +481,6 @@ activeEvents = {}) => {
|
|
525
481
|
} else if (hasContactForceEvent) {
|
526
482
|
collider.setActiveEvents(ActiveEvents.CONTACT_FORCE_EVENTS);
|
527
483
|
}
|
528
|
-
|
529
484
|
events.set(collider.handle, {
|
530
485
|
onCollisionEnter,
|
531
486
|
onCollisionExit,
|
@@ -534,7 +489,6 @@ activeEvents = {}) => {
|
|
534
489
|
onContactForce
|
535
490
|
});
|
536
491
|
}
|
537
|
-
|
538
492
|
return () => {
|
539
493
|
if (collider) {
|
540
494
|
events.delete(collider.handle);
|
@@ -544,34 +498,33 @@ activeEvents = {}) => {
|
|
544
498
|
};
|
545
499
|
const cleanRigidBodyPropsForCollider = (props = {}) => {
|
546
500
|
const rest = _objectWithoutProperties(props, _excluded$2);
|
547
|
-
|
548
501
|
return rest;
|
549
502
|
};
|
550
503
|
|
504
|
+
// Utils
|
551
505
|
const useMutableCallback = fn => {
|
552
506
|
const ref = useRef(fn);
|
553
507
|
useEffect(() => {
|
554
508
|
ref.current = fn;
|
555
509
|
}, [fn]);
|
556
510
|
return ref;
|
557
|
-
};
|
511
|
+
};
|
558
512
|
|
513
|
+
// External hooks
|
559
514
|
/**
|
560
515
|
* Exposes the Rapier context, and world
|
561
516
|
* @category Hooks
|
562
517
|
*/
|
563
|
-
|
564
|
-
|
565
518
|
const useRapier = () => {
|
566
519
|
const rapier = useContext(rapierContext);
|
567
520
|
if (!rapier) throw new Error("react-three-rapier: useRapier must be used within <Physics />!");
|
568
521
|
return rapier;
|
569
522
|
};
|
523
|
+
|
570
524
|
/**
|
571
525
|
* Registers a callback to be called before the physics step
|
572
526
|
* @category Hooks
|
573
527
|
*/
|
574
|
-
|
575
528
|
const useBeforePhysicsStep = callback => {
|
576
529
|
const {
|
577
530
|
beforeStepCallbacks
|
@@ -584,11 +537,11 @@ const useBeforePhysicsStep = callback => {
|
|
584
537
|
};
|
585
538
|
}, []);
|
586
539
|
};
|
540
|
+
|
587
541
|
/**
|
588
542
|
* Registers a callback to be called after the physics step
|
589
543
|
* @category Hooks
|
590
544
|
*/
|
591
|
-
|
592
545
|
const useAfterPhysicsStep = callback => {
|
593
546
|
const {
|
594
547
|
afterStepCallbacks
|
@@ -600,17 +553,16 @@ const useAfterPhysicsStep = callback => {
|
|
600
553
|
afterStepCallbacks.delete(ref);
|
601
554
|
};
|
602
555
|
}, []);
|
603
|
-
};
|
556
|
+
};
|
604
557
|
|
558
|
+
// Internal hooks
|
605
559
|
/**
|
606
560
|
* @internal
|
607
561
|
*/
|
608
|
-
|
609
562
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
610
563
|
const [colliderProps, setColliderProps] = useState([]);
|
611
564
|
useEffect(() => {
|
612
565
|
const object = ref.current;
|
613
|
-
|
614
566
|
if (object && options.colliders !== false) {
|
615
567
|
setColliderProps(createColliderPropsFromChildren({
|
616
568
|
object: ref.current,
|
@@ -656,33 +608,26 @@ const createSingletonProxy = createInstance => {
|
|
656
608
|
if (!instance) {
|
657
609
|
instance = createInstance();
|
658
610
|
}
|
659
|
-
|
660
611
|
return Reflect.get(instance, prop);
|
661
612
|
},
|
662
|
-
|
663
613
|
set(target, prop, value) {
|
664
614
|
if (!instance) {
|
665
615
|
instance = createInstance();
|
666
616
|
}
|
667
|
-
|
668
617
|
return Reflect.set(instance, prop, value);
|
669
618
|
}
|
670
|
-
|
671
619
|
};
|
672
620
|
const proxy = new Proxy({}, handler);
|
673
|
-
|
674
621
|
const reset = () => {
|
675
622
|
instance = undefined;
|
676
623
|
};
|
677
|
-
|
678
624
|
const set = newInstance => {
|
679
625
|
instance = newInstance;
|
680
626
|
};
|
627
|
+
|
681
628
|
/**
|
682
629
|
* Return the proxy and a reset function
|
683
630
|
*/
|
684
|
-
|
685
|
-
|
686
631
|
return {
|
687
632
|
proxy,
|
688
633
|
reset,
|
@@ -691,10 +636,8 @@ const createSingletonProxy = createInstance => {
|
|
691
636
|
};
|
692
637
|
|
693
638
|
const rapierContext = /*#__PURE__*/createContext(undefined);
|
694
|
-
|
695
639
|
const getCollisionPayloadFromSource = (target, other) => {
|
696
640
|
var _target$collider$stat, _target$rigidBody$sta, _other$collider$state, _other$rigidBody$stat, _other$collider$state2, _other$rigidBody$stat2;
|
697
|
-
|
698
641
|
return {
|
699
642
|
target: {
|
700
643
|
rigidBody: target.rigidBody.object,
|
@@ -714,13 +657,11 @@ const getCollisionPayloadFromSource = (target, other) => {
|
|
714
657
|
rigidBodyObject: (_other$rigidBody$stat2 = other.rigidBody.state) === null || _other$rigidBody$stat2 === void 0 ? void 0 : _other$rigidBody$stat2.object
|
715
658
|
};
|
716
659
|
};
|
717
|
-
|
718
660
|
const importRapier = async () => {
|
719
661
|
let r = await import('@dimforge/rapier3d-compat');
|
720
662
|
await r.init();
|
721
663
|
return r;
|
722
664
|
};
|
723
|
-
|
724
665
|
/**
|
725
666
|
* The main physics component used to create a physics world.
|
726
667
|
* @category Components
|
@@ -743,7 +684,7 @@ const Physics = props => {
|
|
743
684
|
numInternalPgsIterations = 1,
|
744
685
|
minIslandSize = 128,
|
745
686
|
maxCcdSubsteps = 1,
|
746
|
-
|
687
|
+
contactNaturalFrequency = 30,
|
747
688
|
lengthUnit = 1
|
748
689
|
} = props;
|
749
690
|
const rapier = suspend(importRapier, ["@react-thee/rapier", importRapier]);
|
@@ -757,12 +698,12 @@ const Physics = props => {
|
|
757
698
|
const eventQueue = useConst(() => new EventQueue(false));
|
758
699
|
const beforeStepCallbacks = useConst(() => new Set());
|
759
700
|
const afterStepCallbacks = useConst(() => new Set());
|
701
|
+
|
760
702
|
/**
|
761
703
|
* Initiate the world
|
762
704
|
* This creates a singleton proxy, so that the world is only created when
|
763
705
|
* something within it is accessed.
|
764
706
|
*/
|
765
|
-
|
766
707
|
const {
|
767
708
|
proxy: worldProxy,
|
768
709
|
reset: resetWorldProxy,
|
@@ -773,8 +714,9 @@ const Physics = props => {
|
|
773
714
|
worldProxy.free();
|
774
715
|
resetWorldProxy();
|
775
716
|
};
|
776
|
-
}, []);
|
717
|
+
}, []);
|
777
718
|
|
719
|
+
// Update mutable props
|
778
720
|
useEffect(() => {
|
779
721
|
worldProxy.gravity = vector3ToRapierVector(gravity);
|
780
722
|
worldProxy.integrationParameters.numSolverIterations = numSolverIterations;
|
@@ -784,12 +726,11 @@ const Physics = props => {
|
|
784
726
|
worldProxy.integrationParameters.minIslandSize = minIslandSize;
|
785
727
|
worldProxy.integrationParameters.maxCcdSubsteps = maxCcdSubsteps;
|
786
728
|
worldProxy.integrationParameters.normalizedPredictionDistance = predictionDistance;
|
787
|
-
worldProxy.integrationParameters.erp = erp;
|
788
729
|
worldProxy.lengthUnit = lengthUnit;
|
789
|
-
|
730
|
+
worldProxy.integrationParameters.contact_natural_frequency = contactNaturalFrequency;
|
731
|
+
}, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, lengthUnit, contactNaturalFrequency]);
|
790
732
|
const getSourceFromColliderHandle = useCallback(handle => {
|
791
733
|
var _collider$parent;
|
792
|
-
|
793
734
|
const collider = worldProxy.getCollider(handle);
|
794
735
|
const colEvents = colliderEvents.get(handle);
|
795
736
|
const colliderState = colliderStates.get(handle);
|
@@ -817,37 +758,36 @@ const Physics = props => {
|
|
817
758
|
});
|
818
759
|
const step = useCallback(dt => {
|
819
760
|
const world = worldProxy;
|
761
|
+
|
820
762
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
821
763
|
once so we don't have to string-check every frame. */
|
822
|
-
|
823
764
|
const timeStepVariable = timeStep === "vary";
|
765
|
+
|
824
766
|
/**
|
825
767
|
* Fixed timeStep simulation progression
|
826
768
|
* @see https://gafferongames.com/post/fix_your_timestep/
|
827
769
|
*/
|
828
770
|
|
829
771
|
const clampedDelta = MathUtils.clamp(dt, 0, 0.5);
|
830
|
-
|
831
772
|
const stepWorld = delta => {
|
832
773
|
// Trigger beforeStep callbacks
|
833
774
|
beforeStepCallbacks.forEach(callback => {
|
834
775
|
callback.current(world);
|
835
776
|
});
|
836
777
|
world.timestep = delta;
|
837
|
-
world.step(eventQueue);
|
778
|
+
world.step(eventQueue);
|
838
779
|
|
780
|
+
// Trigger afterStep callbacks
|
839
781
|
afterStepCallbacks.forEach(callback => {
|
840
782
|
callback.current(world);
|
841
783
|
});
|
842
784
|
};
|
843
|
-
|
844
785
|
if (timeStepVariable) {
|
845
786
|
stepWorld(clampedDelta);
|
846
787
|
} else {
|
847
788
|
// don't step time forwards if paused
|
848
789
|
// Increase accumulator
|
849
790
|
steppingState.accumulator += clampedDelta;
|
850
|
-
|
851
791
|
while (steppingState.accumulator >= timeStep) {
|
852
792
|
// Set up previous state
|
853
793
|
// needed for accurate interpolations if the world steps more than once
|
@@ -860,57 +800,48 @@ const Physics = props => {
|
|
860
800
|
};
|
861
801
|
});
|
862
802
|
}
|
863
|
-
|
864
803
|
stepWorld(timeStep);
|
865
804
|
steppingState.accumulator -= timeStep;
|
866
805
|
}
|
867
806
|
}
|
807
|
+
const interpolationAlpha = timeStepVariable || !interpolate || paused ? 1 : steppingState.accumulator / timeStep;
|
868
808
|
|
869
|
-
|
870
|
-
|
809
|
+
// Update meshes
|
871
810
|
rigidBodyStates.forEach((state, handle) => {
|
872
811
|
const rigidBody = world.getRigidBody(handle);
|
873
812
|
const events = rigidBodyEvents.get(handle);
|
874
|
-
|
875
813
|
if (events !== null && events !== void 0 && events.onSleep || events !== null && events !== void 0 && events.onWake) {
|
876
814
|
if (rigidBody.isSleeping() && !state.isSleeping) {
|
877
815
|
var _events$onSleep;
|
878
|
-
|
879
816
|
events === null || events === void 0 ? void 0 : (_events$onSleep = events.onSleep) === null || _events$onSleep === void 0 ? void 0 : _events$onSleep.call(events);
|
880
817
|
}
|
881
|
-
|
882
818
|
if (!rigidBody.isSleeping() && state.isSleeping) {
|
883
819
|
var _events$onWake;
|
884
|
-
|
885
820
|
events === null || events === void 0 ? void 0 : (_events$onWake = events.onWake) === null || _events$onWake === void 0 ? void 0 : _events$onWake.call(events);
|
886
821
|
}
|
887
|
-
|
888
822
|
state.isSleeping = rigidBody.isSleeping();
|
889
823
|
}
|
890
|
-
|
891
824
|
if (!rigidBody || rigidBody.isSleeping() && !("isInstancedMesh" in state.object) || !state.setMatrix) {
|
892
825
|
return;
|
893
|
-
}
|
894
|
-
|
826
|
+
}
|
895
827
|
|
828
|
+
// New states
|
896
829
|
let t = rigidBody.translation();
|
897
830
|
let r = rigidBody.rotation();
|
898
831
|
let previousState = steppingState.previousState[handle];
|
899
|
-
|
900
832
|
if (previousState) {
|
901
833
|
// Get previous simulated world position
|
902
|
-
_matrix4.compose(previousState.position, rapierQuaternionToQuaternion(previousState.rotation), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
|
903
|
-
|
834
|
+
_matrix4.compose(previousState.position, rapierQuaternionToQuaternion(previousState.rotation), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
|
904
835
|
|
836
|
+
// Apply previous tick position
|
905
837
|
if (state.meshType == "mesh") {
|
906
838
|
state.object.position.copy(_position);
|
907
839
|
state.object.quaternion.copy(_rotation);
|
908
840
|
}
|
909
|
-
}
|
910
|
-
|
841
|
+
}
|
911
842
|
|
843
|
+
// Get new position
|
912
844
|
_matrix4.compose(t, rapierQuaternionToQuaternion(r), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
|
913
|
-
|
914
845
|
if (state.meshType == "instancedMesh") {
|
915
846
|
state.setMatrix(_matrix4);
|
916
847
|
} else {
|
@@ -921,19 +852,17 @@ const Physics = props => {
|
|
921
852
|
});
|
922
853
|
eventQueue.drainCollisionEvents((handle1, handle2, started) => {
|
923
854
|
const source1 = getSourceFromColliderHandle(handle1);
|
924
|
-
const source2 = getSourceFromColliderHandle(handle2);
|
855
|
+
const source2 = getSourceFromColliderHandle(handle2);
|
925
856
|
|
857
|
+
// Collision Events
|
926
858
|
if (!(source1 !== null && source1 !== void 0 && source1.collider.object) || !(source2 !== null && source2 !== void 0 && source2.collider.object)) {
|
927
859
|
return;
|
928
860
|
}
|
929
|
-
|
930
861
|
const collisionPayload1 = getCollisionPayloadFromSource(source1, source2);
|
931
862
|
const collisionPayload2 = getCollisionPayloadFromSource(source2, source1);
|
932
|
-
|
933
863
|
if (started) {
|
934
864
|
world.contactPair(source1.collider.object, source2.collider.object, (manifold, flipped) => {
|
935
865
|
var _source1$rigidBody$ev, _source1$rigidBody$ev2, _source2$rigidBody$ev, _source2$rigidBody$ev2, _source1$collider$eve, _source1$collider$eve2, _source2$collider$eve, _source2$collider$eve2;
|
936
|
-
|
937
866
|
/* RigidBody events */
|
938
867
|
(_source1$rigidBody$ev = source1.rigidBody.events) === null || _source1$rigidBody$ev === void 0 ? void 0 : (_source1$rigidBody$ev2 = _source1$rigidBody$ev.onCollisionEnter) === null || _source1$rigidBody$ev2 === void 0 ? void 0 : _source1$rigidBody$ev2.call(_source1$rigidBody$ev, _objectSpread2(_objectSpread2({}, collisionPayload1), {}, {
|
939
868
|
manifold,
|
@@ -943,8 +872,8 @@ const Physics = props => {
|
|
943
872
|
manifold,
|
944
873
|
flipped
|
945
874
|
}));
|
946
|
-
/* Collider events */
|
947
875
|
|
876
|
+
/* Collider events */
|
948
877
|
(_source1$collider$eve = source1.collider.events) === null || _source1$collider$eve === void 0 ? void 0 : (_source1$collider$eve2 = _source1$collider$eve.onCollisionEnter) === null || _source1$collider$eve2 === void 0 ? void 0 : _source1$collider$eve2.call(_source1$collider$eve, _objectSpread2(_objectSpread2({}, collisionPayload1), {}, {
|
949
878
|
manifold,
|
950
879
|
flipped
|
@@ -956,18 +885,16 @@ const Physics = props => {
|
|
956
885
|
});
|
957
886
|
} else {
|
958
887
|
var _source1$rigidBody$ev3, _source1$rigidBody$ev4, _source2$rigidBody$ev3, _source2$rigidBody$ev4, _source1$collider$eve3, _source1$collider$eve4, _source2$collider$eve3, _source2$collider$eve4;
|
959
|
-
|
960
888
|
(_source1$rigidBody$ev3 = source1.rigidBody.events) === null || _source1$rigidBody$ev3 === void 0 ? void 0 : (_source1$rigidBody$ev4 = _source1$rigidBody$ev3.onCollisionExit) === null || _source1$rigidBody$ev4 === void 0 ? void 0 : _source1$rigidBody$ev4.call(_source1$rigidBody$ev3, collisionPayload1);
|
961
889
|
(_source2$rigidBody$ev3 = source2.rigidBody.events) === null || _source2$rigidBody$ev3 === void 0 ? void 0 : (_source2$rigidBody$ev4 = _source2$rigidBody$ev3.onCollisionExit) === null || _source2$rigidBody$ev4 === void 0 ? void 0 : _source2$rigidBody$ev4.call(_source2$rigidBody$ev3, collisionPayload2);
|
962
890
|
(_source1$collider$eve3 = source1.collider.events) === null || _source1$collider$eve3 === void 0 ? void 0 : (_source1$collider$eve4 = _source1$collider$eve3.onCollisionExit) === null || _source1$collider$eve4 === void 0 ? void 0 : _source1$collider$eve4.call(_source1$collider$eve3, collisionPayload1);
|
963
891
|
(_source2$collider$eve3 = source2.collider.events) === null || _source2$collider$eve3 === void 0 ? void 0 : (_source2$collider$eve4 = _source2$collider$eve3.onCollisionExit) === null || _source2$collider$eve4 === void 0 ? void 0 : _source2$collider$eve4.call(_source2$collider$eve3, collisionPayload2);
|
964
|
-
}
|
965
|
-
|
892
|
+
}
|
966
893
|
|
894
|
+
// Sensor Intersections
|
967
895
|
if (started) {
|
968
896
|
if (world.intersectionPair(source1.collider.object, source2.collider.object)) {
|
969
897
|
var _source1$rigidBody$ev5, _source1$rigidBody$ev6, _source2$rigidBody$ev5, _source2$rigidBody$ev6, _source1$collider$eve5, _source1$collider$eve6, _source2$collider$eve5, _source2$collider$eve6;
|
970
|
-
|
971
898
|
(_source1$rigidBody$ev5 = source1.rigidBody.events) === null || _source1$rigidBody$ev5 === void 0 ? void 0 : (_source1$rigidBody$ev6 = _source1$rigidBody$ev5.onIntersectionEnter) === null || _source1$rigidBody$ev6 === void 0 ? void 0 : _source1$rigidBody$ev6.call(_source1$rigidBody$ev5, collisionPayload1);
|
972
899
|
(_source2$rigidBody$ev5 = source2.rigidBody.events) === null || _source2$rigidBody$ev5 === void 0 ? void 0 : (_source2$rigidBody$ev6 = _source2$rigidBody$ev5.onIntersectionEnter) === null || _source2$rigidBody$ev6 === void 0 ? void 0 : _source2$rigidBody$ev6.call(_source2$rigidBody$ev5, collisionPayload2);
|
973
900
|
(_source1$collider$eve5 = source1.collider.events) === null || _source1$collider$eve5 === void 0 ? void 0 : (_source1$collider$eve6 = _source1$collider$eve5.onIntersectionEnter) === null || _source1$collider$eve6 === void 0 ? void 0 : _source1$collider$eve6.call(_source1$collider$eve5, collisionPayload1);
|
@@ -975,7 +902,6 @@ const Physics = props => {
|
|
975
902
|
}
|
976
903
|
} else {
|
977
904
|
var _source1$rigidBody$ev7, _source1$rigidBody$ev8, _source2$rigidBody$ev7, _source2$rigidBody$ev8, _source1$collider$eve7, _source1$collider$eve8, _source2$collider$eve7, _source2$collider$eve8;
|
978
|
-
|
979
905
|
(_source1$rigidBody$ev7 = source1.rigidBody.events) === null || _source1$rigidBody$ev7 === void 0 ? void 0 : (_source1$rigidBody$ev8 = _source1$rigidBody$ev7.onIntersectionExit) === null || _source1$rigidBody$ev8 === void 0 ? void 0 : _source1$rigidBody$ev8.call(_source1$rigidBody$ev7, collisionPayload1);
|
980
906
|
(_source2$rigidBody$ev7 = source2.rigidBody.events) === null || _source2$rigidBody$ev7 === void 0 ? void 0 : (_source2$rigidBody$ev8 = _source2$rigidBody$ev7.onIntersectionExit) === null || _source2$rigidBody$ev8 === void 0 ? void 0 : _source2$rigidBody$ev8.call(_source2$rigidBody$ev7, collisionPayload2);
|
981
907
|
(_source1$collider$eve7 = source1.collider.events) === null || _source1$collider$eve7 === void 0 ? void 0 : (_source1$collider$eve8 = _source1$collider$eve7.onIntersectionExit) === null || _source1$collider$eve8 === void 0 ? void 0 : _source1$collider$eve8.call(_source1$collider$eve7, collisionPayload1);
|
@@ -984,14 +910,13 @@ const Physics = props => {
|
|
984
910
|
});
|
985
911
|
eventQueue.drainContactForceEvents(event => {
|
986
912
|
var _source1$rigidBody$ev9, _source1$rigidBody$ev10, _source2$rigidBody$ev9, _source2$rigidBody$ev10, _source1$collider$eve9, _source1$collider$eve10, _source2$collider$eve9, _source2$collider$eve10;
|
987
|
-
|
988
913
|
const source1 = getSourceFromColliderHandle(event.collider1());
|
989
|
-
const source2 = getSourceFromColliderHandle(event.collider2());
|
914
|
+
const source2 = getSourceFromColliderHandle(event.collider2());
|
990
915
|
|
916
|
+
// Collision Events
|
991
917
|
if (!(source1 !== null && source1 !== void 0 && source1.collider.object) || !(source2 !== null && source2 !== void 0 && source2.collider.object)) {
|
992
918
|
return;
|
993
919
|
}
|
994
|
-
|
995
920
|
const collisionPayload1 = getCollisionPayloadFromSource(source1, source2);
|
996
921
|
const collisionPayload2 = getCollisionPayloadFromSource(source2, source1);
|
997
922
|
(_source1$rigidBody$ev9 = source1.rigidBody.events) === null || _source1$rigidBody$ev9 === void 0 ? void 0 : (_source1$rigidBody$ev10 = _source1$rigidBody$ev9.onContactForce) === null || _source1$rigidBody$ev10 === void 0 ? void 0 : _source1$rigidBody$ev10.call(_source1$rigidBody$ev9, _objectSpread2(_objectSpread2({}, collisionPayload1), {}, {
|
@@ -1058,41 +983,30 @@ const Physics = props => {
|
|
1058
983
|
};
|
1059
984
|
|
1060
985
|
function _extends() {
|
1061
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
1062
|
-
for (var
|
1063
|
-
var
|
1064
|
-
|
1065
|
-
for (var key in source) {
|
1066
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1067
|
-
target[key] = source[key];
|
1068
|
-
}
|
1069
|
-
}
|
986
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
987
|
+
for (var e = 1; e < arguments.length; e++) {
|
988
|
+
var t = arguments[e];
|
989
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
1070
990
|
}
|
1071
|
-
|
1072
|
-
|
1073
|
-
};
|
1074
|
-
return _extends.apply(this, arguments);
|
991
|
+
return n;
|
992
|
+
}, _extends.apply(null, arguments);
|
1075
993
|
}
|
1076
994
|
|
1077
995
|
/**
|
1078
996
|
* Initiate an instance and return a safe getter
|
1079
997
|
*/
|
1080
|
-
|
1081
998
|
const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
1082
999
|
const ref = useRef();
|
1083
1000
|
const getInstance = useCallback(() => {
|
1084
1001
|
if (!ref.current) {
|
1085
1002
|
ref.current = createFn();
|
1086
1003
|
}
|
1087
|
-
|
1088
1004
|
return ref.current;
|
1089
1005
|
}, dependencyList);
|
1090
1006
|
useEffect(() => {
|
1091
1007
|
// Save the destroy function and instance
|
1092
1008
|
const instance = getInstance();
|
1093
|
-
|
1094
1009
|
const destroy = () => destroyFn(instance);
|
1095
|
-
|
1096
1010
|
return () => {
|
1097
1011
|
destroy();
|
1098
1012
|
ref.current = undefined;
|
@@ -1105,7 +1019,6 @@ const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
|
1105
1019
|
* Takes an object resembling a Vector3 and returs a Three.Vector3
|
1106
1020
|
* @category Math helpers
|
1107
1021
|
*/
|
1108
|
-
|
1109
1022
|
const vec3 = ({
|
1110
1023
|
x,
|
1111
1024
|
y,
|
@@ -1117,11 +1030,11 @@ const vec3 = ({
|
|
1117
1030
|
}) => {
|
1118
1031
|
return new Vector3(x, y, z);
|
1119
1032
|
};
|
1033
|
+
|
1120
1034
|
/**
|
1121
1035
|
* Takes an object resembling a Quaternion and returs a Three.Quaternion
|
1122
1036
|
* @category Math helpers
|
1123
1037
|
*/
|
1124
|
-
|
1125
1038
|
const quat = ({
|
1126
1039
|
x,
|
1127
1040
|
y,
|
@@ -1135,11 +1048,11 @@ const quat = ({
|
|
1135
1048
|
}) => {
|
1136
1049
|
return new Quaternion(x, y, z, w);
|
1137
1050
|
};
|
1051
|
+
|
1138
1052
|
/**
|
1139
1053
|
* Takes an object resembling an Euler and returs a Three.Euler
|
1140
1054
|
* @category Math helpers
|
1141
1055
|
*/
|
1142
|
-
|
1143
1056
|
const euler = ({
|
1144
1057
|
x,
|
1145
1058
|
y,
|
@@ -1152,17 +1065,17 @@ const euler = ({
|
|
1152
1065
|
return new Euler(x, y, z);
|
1153
1066
|
};
|
1154
1067
|
|
1068
|
+
// Need to catch the case where forwardedRef is a function... how to do that?
|
1155
1069
|
const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
1156
|
-
const innerRef = useRef(defaultValue);
|
1070
|
+
const innerRef = useRef(defaultValue);
|
1157
1071
|
|
1072
|
+
// Update the forwarded ref when the inner ref changes
|
1158
1073
|
if (forwardedRef && typeof forwardedRef !== "function") {
|
1159
1074
|
if (!forwardedRef.current) {
|
1160
1075
|
forwardedRef.current = innerRef.current;
|
1161
1076
|
}
|
1162
|
-
|
1163
1077
|
return forwardedRef;
|
1164
1078
|
}
|
1165
|
-
|
1166
1079
|
return innerRef;
|
1167
1080
|
};
|
1168
1081
|
|
@@ -1170,7 +1083,7 @@ const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
|
1170
1083
|
* A collider is a shape that can be attached to a rigid body to define its physical properties.
|
1171
1084
|
* @internal
|
1172
1085
|
*/
|
1173
|
-
const AnyCollider = /*#__PURE__*/memo(
|
1086
|
+
const AnyCollider = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef) => {
|
1174
1087
|
const {
|
1175
1088
|
children,
|
1176
1089
|
position,
|
@@ -1186,17 +1099,16 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwarded
|
|
1186
1099
|
} = useRapier();
|
1187
1100
|
const rigidBodyContext = useRigidBodyContext();
|
1188
1101
|
const colliderRef = useForwardedRef(forwardedRef);
|
1189
|
-
const objectRef = useRef(null);
|
1102
|
+
const objectRef = useRef(null);
|
1190
1103
|
|
1104
|
+
// We spread the props out here to make sure that the ref is updated when the props change.
|
1191
1105
|
const immutablePropArray = immutableColliderOptions.flatMap(key => Array.isArray(props[key]) ? [...props[key]] : props[key]);
|
1192
1106
|
const getInstance = useImperativeInstance(() => {
|
1193
1107
|
const worldScale = objectRef.current.getWorldScale(vec3());
|
1194
1108
|
const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
|
1195
|
-
|
1196
1109
|
if (typeof forwardedRef == "function") {
|
1197
1110
|
forwardedRef(collider);
|
1198
1111
|
}
|
1199
|
-
|
1200
1112
|
colliderRef.current = collider;
|
1201
1113
|
return collider;
|
1202
1114
|
}, collider => {
|
@@ -1225,7 +1137,6 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwarded
|
|
1225
1137
|
name: name
|
1226
1138
|
}, children);
|
1227
1139
|
}));
|
1228
|
-
|
1229
1140
|
/**
|
1230
1141
|
* A cuboid collider shape
|
1231
1142
|
* @category Colliders
|
@@ -1237,7 +1148,6 @@ const CuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1237
1148
|
}));
|
1238
1149
|
});
|
1239
1150
|
CuboidCollider.displayName = "CuboidCollider";
|
1240
|
-
|
1241
1151
|
/**
|
1242
1152
|
* A round cuboid collider shape
|
1243
1153
|
* @category Colliders
|
@@ -1247,7 +1157,6 @@ const RoundCuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__P
|
|
1247
1157
|
ref: ref
|
1248
1158
|
})));
|
1249
1159
|
RoundCuboidCollider.displayName = "RoundCuboidCollider";
|
1250
|
-
|
1251
1160
|
/**
|
1252
1161
|
* A ball collider shape
|
1253
1162
|
* @category Colliders
|
@@ -1257,7 +1166,6 @@ const BallCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/
|
|
1257
1166
|
ref: ref
|
1258
1167
|
})));
|
1259
1168
|
BallCollider.displayName = "BallCollider";
|
1260
|
-
|
1261
1169
|
/**
|
1262
1170
|
* A capsule collider shape
|
1263
1171
|
* @category Colliders
|
@@ -1267,7 +1175,6 @@ const CapsuleCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE_
|
|
1267
1175
|
ref: ref
|
1268
1176
|
})));
|
1269
1177
|
CapsuleCollider.displayName = "CapsuleCollider";
|
1270
|
-
|
1271
1178
|
/**
|
1272
1179
|
* A heightfield collider shape
|
1273
1180
|
* @category Colliders
|
@@ -1277,7 +1184,6 @@ const HeightfieldCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__P
|
|
1277
1184
|
ref: ref
|
1278
1185
|
})));
|
1279
1186
|
HeightfieldCollider.displayName = "HeightfieldCollider";
|
1280
|
-
|
1281
1187
|
/**
|
1282
1188
|
* A trimesh collider shape
|
1283
1189
|
* @category Colliders
|
@@ -1287,7 +1193,6 @@ const TrimeshCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE_
|
|
1287
1193
|
ref: ref
|
1288
1194
|
})));
|
1289
1195
|
TrimeshCollider.displayName = "TrimeshCollider";
|
1290
|
-
|
1291
1196
|
/**
|
1292
1197
|
* A cone collider shape
|
1293
1198
|
* @category Colliders
|
@@ -1297,7 +1202,6 @@ const ConeCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/
|
|
1297
1202
|
ref: ref
|
1298
1203
|
})));
|
1299
1204
|
ConeCollider.displayName = "ConeCollider";
|
1300
|
-
|
1301
1205
|
/**
|
1302
1206
|
* A round cylinder collider shape
|
1303
1207
|
* @category Colliders
|
@@ -1307,7 +1211,6 @@ const RoundConeCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PUR
|
|
1307
1211
|
ref: ref
|
1308
1212
|
})));
|
1309
1213
|
RoundConeCollider.displayName = "RoundConeCollider";
|
1310
|
-
|
1311
1214
|
/**
|
1312
1215
|
* A cylinder collider shape
|
1313
1216
|
* @category Colliders
|
@@ -1317,7 +1220,6 @@ const CylinderCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE
|
|
1317
1220
|
ref: ref
|
1318
1221
|
})));
|
1319
1222
|
CylinderCollider.displayName = "CylinderCollider";
|
1320
|
-
|
1321
1223
|
/**
|
1322
1224
|
* A round cylinder collider shape
|
1323
1225
|
* @category Colliders
|
@@ -1327,7 +1229,6 @@ const RoundCylinderCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#_
|
|
1327
1229
|
ref: ref
|
1328
1230
|
})));
|
1329
1231
|
CylinderCollider.displayName = "RoundCylinderCollider";
|
1330
|
-
|
1331
1232
|
/**
|
1332
1233
|
* A convex hull collider shape
|
1333
1234
|
* @category Colliders
|
@@ -1340,10 +1241,10 @@ ConvexHullCollider.displayName = "ConvexHullCollider";
|
|
1340
1241
|
|
1341
1242
|
const rigidBodyDescFromOptions = options => {
|
1342
1243
|
var _options$canSleep;
|
1343
|
-
|
1344
1244
|
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
1345
|
-
const desc = new RigidBodyDesc(type);
|
1245
|
+
const desc = new RigidBodyDesc(type);
|
1346
1246
|
|
1247
|
+
// Apply immutable options
|
1347
1248
|
desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
1348
1249
|
return desc;
|
1349
1250
|
};
|
@@ -1375,11 +1276,9 @@ const mutableRigidBodyOptions = {
|
|
1375
1276
|
gravityScale: (rb, value) => {
|
1376
1277
|
rb.setGravityScale(value, true);
|
1377
1278
|
},
|
1378
|
-
|
1379
1279
|
additionalSolverIterations(rb, value) {
|
1380
1280
|
rb.setAdditionalSolverIterations(value);
|
1381
1281
|
},
|
1382
|
-
|
1383
1282
|
linearDamping: (rb, value) => {
|
1384
1283
|
rb.setLinearDamping(value);
|
1385
1284
|
},
|
@@ -1424,11 +1323,9 @@ const mutableRigidBodyOptions = {
|
|
1424
1323
|
userData: (rb, value) => {
|
1425
1324
|
rb.userData = value;
|
1426
1325
|
},
|
1427
|
-
|
1428
1326
|
type(rb, value) {
|
1429
1327
|
rb.setBodyType(rigidBodyTypeFromString(value), true);
|
1430
1328
|
},
|
1431
|
-
|
1432
1329
|
position: () => {},
|
1433
1330
|
rotation: () => {},
|
1434
1331
|
quaternion: () => {},
|
@@ -1439,19 +1336,14 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
1439
1336
|
if (!rigidBody) {
|
1440
1337
|
return;
|
1441
1338
|
}
|
1442
|
-
|
1443
1339
|
const state = states.get(rigidBody.handle);
|
1444
|
-
|
1445
1340
|
if (state) {
|
1446
1341
|
if (updateTranslations) {
|
1447
1342
|
state.object.updateWorldMatrix(true, false);
|
1448
|
-
|
1449
1343
|
_matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
|
1450
|
-
|
1451
1344
|
rigidBody.setTranslation(_position, false);
|
1452
1345
|
rigidBody.setRotation(_rotation, false);
|
1453
1346
|
}
|
1454
|
-
|
1455
1347
|
mutableRigidBodyOptionKeys.forEach(key => {
|
1456
1348
|
if (key in options) {
|
1457
1349
|
mutableRigidBodyOptions[key](rigidBody, options[key]);
|
@@ -1500,23 +1392,21 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1500
1392
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1501
1393
|
const RigidBodyContext = /*#__PURE__*/createContext(undefined);
|
1502
1394
|
const useRigidBodyContext = () => useContext(RigidBodyContext);
|
1503
|
-
|
1504
1395
|
/**
|
1505
1396
|
* A rigid body is a physical object that can be simulated by the physics engine.
|
1506
1397
|
* @category Components
|
1507
1398
|
*/
|
1508
|
-
const RigidBody = /*#__PURE__*/memo(
|
1399
|
+
const RigidBody = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef) => {
|
1509
1400
|
const {
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1401
|
+
children,
|
1402
|
+
type,
|
1403
|
+
position,
|
1404
|
+
rotation,
|
1405
|
+
scale,
|
1406
|
+
quaternion,
|
1407
|
+
transformState
|
1408
|
+
} = props,
|
1409
|
+
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1520
1410
|
const objectRef = useRef(null);
|
1521
1411
|
const rigidBodyRef = useForwardedRef(forwardedRef);
|
1522
1412
|
const {
|
@@ -1533,24 +1423,24 @@ const RigidBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwardedRe
|
|
1533
1423
|
const immutablePropArray = immutableRigidBodyOptions.flatMap(key => {
|
1534
1424
|
return Array.isArray(mergedOptions[key]) ? [...mergedOptions[key]] : mergedOptions[key];
|
1535
1425
|
});
|
1536
|
-
const childColliderProps = useChildColliderProps(objectRef, mergedOptions);
|
1426
|
+
const childColliderProps = useChildColliderProps(objectRef, mergedOptions);
|
1537
1427
|
|
1428
|
+
// Provide a way to eagerly create rigidbody
|
1538
1429
|
const getRigidBody = useImperativeInstance(() => {
|
1539
1430
|
const desc = rigidBodyDescFromOptions(mergedOptions);
|
1540
1431
|
const rigidBody = world.createRigidBody(desc);
|
1541
|
-
|
1542
1432
|
if (typeof forwardedRef === "function") {
|
1543
1433
|
forwardedRef(rigidBody);
|
1544
1434
|
}
|
1545
|
-
|
1546
1435
|
rigidBodyRef.current = rigidBody;
|
1547
1436
|
return rigidBody;
|
1548
1437
|
}, rigidBody => {
|
1549
1438
|
if (world.getRigidBody(rigidBody.handle)) {
|
1550
1439
|
world.removeRigidBody(rigidBody);
|
1551
1440
|
}
|
1552
|
-
}, immutablePropArray);
|
1441
|
+
}, immutablePropArray);
|
1553
1442
|
|
1443
|
+
// Only provide a object state after the ref has been set
|
1554
1444
|
useEffect(() => {
|
1555
1445
|
const rigidBody = getRigidBody();
|
1556
1446
|
const state = createRigidBodyState({
|
@@ -1621,51 +1511,46 @@ const MeshCollider = /*#__PURE__*/memo(props => {
|
|
1621
1511
|
MeshCollider.displayName = "MeshCollider";
|
1622
1512
|
|
1623
1513
|
const _excluded = ["children", "instances", "colliderNodes", "position", "rotation", "quaternion", "scale"];
|
1624
|
-
const InstancedRigidBodies = /*#__PURE__*/memo(
|
1514
|
+
const InstancedRigidBodies = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef) => {
|
1625
1515
|
const rigidBodiesRef = useForwardedRef(forwardedRef, []);
|
1626
1516
|
const objectRef = useRef(null);
|
1627
1517
|
const instanceWrapperRef = useRef(null);
|
1628
|
-
|
1629
1518
|
const {
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1519
|
+
// instanced props
|
1520
|
+
children,
|
1521
|
+
instances,
|
1522
|
+
colliderNodes = [],
|
1523
|
+
// wrapper object props
|
1524
|
+
position,
|
1525
|
+
rotation,
|
1526
|
+
quaternion,
|
1527
|
+
scale
|
1528
|
+
|
1529
|
+
// rigid body specific props, and r3f-object props
|
1530
|
+
} = props,
|
1531
|
+
rigidBodyProps = _objectWithoutProperties(props, _excluded);
|
1642
1532
|
const childColliderProps = useChildColliderProps(objectRef, _objectSpread2(_objectSpread2({}, props), {}, {
|
1643
1533
|
children: undefined
|
1644
1534
|
}));
|
1645
|
-
|
1646
1535
|
const getInstancedMesh = () => {
|
1647
1536
|
const firstChild = instanceWrapperRef.current.children[0];
|
1648
|
-
|
1649
1537
|
if (firstChild && "isInstancedMesh" in firstChild) {
|
1650
1538
|
return firstChild;
|
1651
1539
|
}
|
1652
|
-
|
1653
1540
|
return undefined;
|
1654
1541
|
};
|
1655
|
-
|
1656
1542
|
useEffect(() => {
|
1657
1543
|
const instancedMesh = getInstancedMesh();
|
1658
|
-
|
1659
1544
|
if (instancedMesh) {
|
1660
1545
|
instancedMesh.instanceMatrix.setUsage(DynamicDrawUsage);
|
1661
1546
|
} else {
|
1662
1547
|
console.warn("InstancedRigidBodies expects exactly one child, which must be an InstancedMesh");
|
1663
1548
|
}
|
1664
|
-
}, []);
|
1549
|
+
}, []);
|
1665
1550
|
|
1551
|
+
// Update the RigidBodyStates whenever the instances change
|
1666
1552
|
const applyInstancedState = (state, index) => {
|
1667
1553
|
const instancedMesh = getInstancedMesh();
|
1668
|
-
|
1669
1554
|
if (instancedMesh) {
|
1670
1555
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
1671
1556
|
getMatrix: matrix => {
|
@@ -1679,10 +1564,8 @@ const InstancedRigidBodies = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props,
|
|
1679
1564
|
meshType: "instancedMesh"
|
1680
1565
|
});
|
1681
1566
|
}
|
1682
|
-
|
1683
1567
|
return state;
|
1684
1568
|
};
|
1685
|
-
|
1686
1569
|
return /*#__PURE__*/React.createElement("object3D", _extends({
|
1687
1570
|
ref: objectRef
|
1688
1571
|
}, rigidBodyProps, {
|
@@ -1706,7 +1589,6 @@ InstancedRigidBodies.displayName = "InstancedRigidBodies";
|
|
1706
1589
|
/**
|
1707
1590
|
* @internal
|
1708
1591
|
*/
|
1709
|
-
|
1710
1592
|
const useImpulseJoint = (body1, body2, params) => {
|
1711
1593
|
const {
|
1712
1594
|
world
|
@@ -1721,7 +1603,6 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1721
1603
|
}, joint => {
|
1722
1604
|
if (joint) {
|
1723
1605
|
jointRef.current = undefined;
|
1724
|
-
|
1725
1606
|
if (world.getImpulseJoint(joint.handle)) {
|
1726
1607
|
world.removeImpulseJoint(joint, true);
|
1727
1608
|
}
|
@@ -1729,6 +1610,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1729
1610
|
}, []);
|
1730
1611
|
return jointRef;
|
1731
1612
|
};
|
1613
|
+
|
1732
1614
|
/**
|
1733
1615
|
* A fixed joint ensures that two rigid-bodies don't move relative to each other.
|
1734
1616
|
* Fixed joints are characterized by one local frame (represented by an isometry) on each rigid-body.
|
@@ -1736,13 +1618,13 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1736
1618
|
*
|
1737
1619
|
* @category Hooks - Joints
|
1738
1620
|
*/
|
1739
|
-
|
1740
1621
|
const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor, body2LocalFrame]) => {
|
1741
1622
|
const {
|
1742
1623
|
rapier
|
1743
1624
|
} = useRapier();
|
1744
1625
|
return useImpulseJoint(body1, body2, rapier.JointData.fixed(vector3ToRapierVector(body1Anchor), quaternionToRapierQuaternion(body1LocalFrame), vector3ToRapierVector(body2Anchor), quaternionToRapierQuaternion(body2LocalFrame)));
|
1745
1626
|
};
|
1627
|
+
|
1746
1628
|
/**
|
1747
1629
|
* The spherical joint ensures that two points on the local-spaces of two rigid-bodies always coincide (it prevents any relative
|
1748
1630
|
* translational motion at this points). This is typically used to simulate ragdolls arms, pendulums, etc.
|
@@ -1751,13 +1633,13 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
|
|
1751
1633
|
*
|
1752
1634
|
* @category Hooks - Joints
|
1753
1635
|
*/
|
1754
|
-
|
1755
1636
|
const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
1756
1637
|
const {
|
1757
1638
|
rapier
|
1758
1639
|
} = useRapier();
|
1759
1640
|
return useImpulseJoint(body1, body2, rapier.JointData.spherical(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor)));
|
1760
1641
|
};
|
1642
|
+
|
1761
1643
|
/**
|
1762
1644
|
* The revolute joint prevents any relative movement between two rigid-bodies, except for relative
|
1763
1645
|
* rotations along one axis. This is typically used to simulate wheels, fans, etc.
|
@@ -1765,20 +1647,18 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
|
1765
1647
|
*
|
1766
1648
|
* @category Hooks - Joints
|
1767
1649
|
*/
|
1768
|
-
|
1769
1650
|
const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]) => {
|
1770
1651
|
const {
|
1771
1652
|
rapier
|
1772
1653
|
} = useRapier();
|
1773
1654
|
const params = rapier.JointData.revolute(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor), vector3ToRapierVector(axis));
|
1774
|
-
|
1775
1655
|
if (limits) {
|
1776
1656
|
params.limitsEnabled = true;
|
1777
1657
|
params.limits = limits;
|
1778
1658
|
}
|
1779
|
-
|
1780
1659
|
return useImpulseJoint(body1, body2, params);
|
1781
1660
|
};
|
1661
|
+
|
1782
1662
|
/**
|
1783
1663
|
* The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
|
1784
1664
|
* It is characterized by one local anchor as well as one local axis on each rigid-body. In 3D, an optional
|
@@ -1786,25 +1666,22 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]
|
|
1786
1666
|
*
|
1787
1667
|
* @category Hooks - Joints
|
1788
1668
|
*/
|
1789
|
-
|
1790
1669
|
const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]) => {
|
1791
1670
|
const {
|
1792
1671
|
rapier
|
1793
1672
|
} = useRapier();
|
1794
1673
|
const params = rapier.JointData.prismatic(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor), vector3ToRapierVector(axis));
|
1795
|
-
|
1796
1674
|
if (limits) {
|
1797
1675
|
params.limitsEnabled = true;
|
1798
1676
|
params.limits = limits;
|
1799
1677
|
}
|
1800
|
-
|
1801
1678
|
return useImpulseJoint(body1, body2, params);
|
1802
1679
|
};
|
1680
|
+
|
1803
1681
|
/**
|
1804
1682
|
* The rope joint limits the max distance between two bodies.
|
1805
1683
|
* @category Hooks - Joints
|
1806
1684
|
*/
|
1807
|
-
|
1808
1685
|
const useRopeJoint = (body1, body2, [body1Anchor, body2Anchor, length]) => {
|
1809
1686
|
const {
|
1810
1687
|
rapier
|
@@ -1814,11 +1691,11 @@ const useRopeJoint = (body1, body2, [body1Anchor, body2Anchor, length]) => {
|
|
1814
1691
|
const params = rapier.JointData.rope(length, vBody1Anchor, vBody2Anchor);
|
1815
1692
|
return useImpulseJoint(body1, body2, params);
|
1816
1693
|
};
|
1694
|
+
|
1817
1695
|
/**
|
1818
1696
|
* The spring joint applies a force proportional to the distance between two objects.
|
1819
1697
|
* @category Hooks - Joints
|
1820
1698
|
*/
|
1821
|
-
|
1822
1699
|
const useSpringJoint = (body1, body2, [body1Anchor, body2Anchor, restLength, stiffness, damping]) => {
|
1823
1700
|
const {
|
1824
1701
|
rapier
|
@@ -1862,7 +1739,6 @@ const useSpringJoint = (body1, body2, [body1Anchor, body2Anchor, restLength, sti
|
|
1862
1739
|
* @returns An InteractionGroup bitmask.
|
1863
1740
|
*/
|
1864
1741
|
const interactionGroups = (memberships, filters) => (bitmask(memberships) << 16) + (filters !== undefined ? bitmask(filters) : 0b1111111111111111);
|
1865
|
-
|
1866
1742
|
const bitmask = groups => [groups].flat().reduce((acc, layer) => acc | 1 << layer, 0);
|
1867
1743
|
|
1868
1744
|
export { AnyCollider, BallCollider, CapsuleCollider, ConeCollider, ConvexHullCollider, CuboidCollider, CylinderCollider, HeightfieldCollider, InstancedRigidBodies, MeshCollider, Physics, RigidBody, RoundConeCollider, RoundCuboidCollider, RoundCylinderCollider, TrimeshCollider, euler, interactionGroups, quat, useAfterPhysicsStep, useBeforePhysicsStep, useFixedJoint, useImpulseJoint, usePrismaticJoint, useRapier, useRevoluteJoint, useRopeJoint, useSphericalJoint, useSpringJoint, vec3 };
|