@react-three/rapier 1.3.1 → 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 +17 -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 +52 -10
- 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 +162 -275
- package/dist/react-three-rapier.cjs.prod.js +162 -275
- package/dist/react-three-rapier.esm.js +162 -275
- 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 -81
- 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
|
-
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
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);
|
@@ -296,6 +273,12 @@ const mutableColliderOptions = {
|
|
296
273
|
restitutionCombineRule: (collider, value) => {
|
297
274
|
collider.setRestitutionCombineRule(value);
|
298
275
|
},
|
276
|
+
activeCollisionTypes: (collider, value) => {
|
277
|
+
collider.setActiveCollisionTypes(value);
|
278
|
+
},
|
279
|
+
contactSkin: (collider, value) => {
|
280
|
+
collider.setContactSkin(value);
|
281
|
+
},
|
299
282
|
// To make sure the options all mutable options are listed
|
300
283
|
quaternion: () => {},
|
301
284
|
position: () => {},
|
@@ -305,23 +288,17 @@ const mutableColliderOptions = {
|
|
305
288
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
306
289
|
const setColliderOptions = (collider, options, states) => {
|
307
290
|
const state = states.get(collider.handle);
|
308
|
-
|
309
291
|
if (state) {
|
310
292
|
var _state$worldParent;
|
311
|
-
|
312
293
|
// Update collider position based on the object's position
|
313
294
|
const parentWorldScale = state.object.parent.getWorldScale(_vector3);
|
314
295
|
const parentInvertedWorldMatrix = (_state$worldParent = state.worldParent) === null || _state$worldParent === void 0 ? void 0 : _state$worldParent.matrixWorld.clone().invert();
|
315
296
|
state.object.updateWorldMatrix(true, false);
|
316
|
-
|
317
297
|
_matrix4.copy(state.object.matrixWorld);
|
318
|
-
|
319
298
|
if (parentInvertedWorldMatrix) {
|
320
299
|
_matrix4.premultiply(parentInvertedWorldMatrix);
|
321
300
|
}
|
322
|
-
|
323
301
|
_matrix4.decompose(_position, _rotation, _scale);
|
324
|
-
|
325
302
|
if (collider.parent()) {
|
326
303
|
collider.setTranslationWrtParent({
|
327
304
|
x: _position.x * parentWorldScale.x,
|
@@ -337,16 +314,17 @@ const setColliderOptions = (collider, options, states) => {
|
|
337
314
|
});
|
338
315
|
collider.setRotation(_rotation);
|
339
316
|
}
|
340
|
-
|
341
317
|
mutableColliderOptionKeys.forEach(key => {
|
342
318
|
if (key in options) {
|
343
319
|
const option = options[key];
|
344
|
-
mutableColliderOptions[key](collider,
|
320
|
+
mutableColliderOptions[key](collider,
|
321
|
+
// @ts-ignore Option does not want to fit into the function, but it will
|
345
322
|
option, options);
|
346
323
|
}
|
347
|
-
});
|
348
|
-
// are exclusive.
|
324
|
+
});
|
349
325
|
|
326
|
+
// handle mass separately, because the assignments
|
327
|
+
// are exclusive.
|
350
328
|
setColliderMassOptions(collider, options);
|
351
329
|
}
|
352
330
|
};
|
@@ -360,7 +338,6 @@ const useUpdateColliderOptions = (getCollider, props, states) => {
|
|
360
338
|
setColliderOptions(collider, props, states);
|
361
339
|
}, [...mutablePropsAsFlatArray, getCollider]);
|
362
340
|
};
|
363
|
-
|
364
341
|
const isChildOfMeshCollider = child => {
|
365
342
|
let flag = false;
|
366
343
|
child.traverseAncestors(a => {
|
@@ -368,7 +345,6 @@ const isChildOfMeshCollider = child => {
|
|
368
345
|
});
|
369
346
|
return flag;
|
370
347
|
};
|
371
|
-
|
372
348
|
const createColliderState = (collider, object, rigidBodyObject) => {
|
373
349
|
return {
|
374
350
|
collider,
|
@@ -390,16 +366,13 @@ const createColliderPropsFromChildren = ({
|
|
390
366
|
const childColliderProps = [];
|
391
367
|
object.updateWorldMatrix(true, false);
|
392
368
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
393
|
-
|
394
369
|
const colliderFromChild = child => {
|
395
370
|
if ("isMesh" in child) {
|
396
371
|
if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
|
397
372
|
const worldScale = child.getWorldScale(_scale);
|
398
373
|
const shape = autoColliderMap[options.colliders || "cuboid"];
|
399
374
|
child.updateWorldMatrix(true, false);
|
400
|
-
|
401
375
|
_matrix4.copy(child.matrixWorld).premultiply(invertedParentMatrixWorld).decompose(_position, _rotation, _scale);
|
402
|
-
|
403
376
|
const rotationEuler = new Euler().setFromQuaternion(_rotation, "XYZ");
|
404
377
|
const {
|
405
378
|
geometry
|
@@ -408,7 +381,6 @@ const createColliderPropsFromChildren = ({
|
|
408
381
|
args,
|
409
382
|
offset
|
410
383
|
} = getColliderArgsFromGeometry(geometry, options.colliders || "cuboid");
|
411
|
-
|
412
384
|
const colliderProps = _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(options)), {}, {
|
413
385
|
args: args,
|
414
386
|
shape: shape,
|
@@ -416,17 +388,14 @@ const createColliderPropsFromChildren = ({
|
|
416
388
|
position: [_position.x + offset.x * worldScale.x, _position.y + offset.y * worldScale.y, _position.z + offset.z * worldScale.z],
|
417
389
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
418
390
|
});
|
419
|
-
|
420
391
|
childColliderProps.push(colliderProps);
|
421
392
|
}
|
422
393
|
};
|
423
|
-
|
424
394
|
if (options.includeInvisible) {
|
425
395
|
object.traverse(colliderFromChild);
|
426
396
|
} else {
|
427
397
|
object.traverseVisible(colliderFromChild);
|
428
398
|
}
|
429
|
-
|
430
399
|
return childColliderProps;
|
431
400
|
};
|
432
401
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
@@ -443,7 +412,6 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
443
412
|
offset: boundingBox.getCenter(new Vector3())
|
444
413
|
};
|
445
414
|
}
|
446
|
-
|
447
415
|
case "ball":
|
448
416
|
{
|
449
417
|
geometry.computeBoundingSphere();
|
@@ -456,18 +424,15 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
456
424
|
offset: boundingSphere.center
|
457
425
|
};
|
458
426
|
}
|
459
|
-
|
460
427
|
case "trimesh":
|
461
428
|
{
|
462
429
|
var _clonedGeometry$index;
|
463
|
-
|
464
430
|
const clonedGeometry = geometry.index ? geometry.clone() : mergeVertices(geometry);
|
465
431
|
return {
|
466
432
|
args: [clonedGeometry.attributes.position.array, (_clonedGeometry$index = clonedGeometry.index) === null || _clonedGeometry$index === void 0 ? void 0 : _clonedGeometry$index.array],
|
467
433
|
offset: new Vector3()
|
468
434
|
};
|
469
435
|
}
|
470
|
-
|
471
436
|
case "hull":
|
472
437
|
{
|
473
438
|
const g = geometry.clone();
|
@@ -477,7 +442,6 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
477
442
|
};
|
478
443
|
}
|
479
444
|
}
|
480
|
-
|
481
445
|
return {
|
482
446
|
args: [],
|
483
447
|
offset: new Vector3()
|
@@ -503,7 +467,6 @@ activeEvents = {}) => {
|
|
503
467
|
} = props;
|
504
468
|
useEffect(() => {
|
505
469
|
const collider = getCollider();
|
506
|
-
|
507
470
|
if (collider) {
|
508
471
|
const {
|
509
472
|
collision: collisionEventsActive,
|
@@ -511,7 +474,6 @@ activeEvents = {}) => {
|
|
511
474
|
} = getActiveCollisionEventsFromProps(props);
|
512
475
|
const hasCollisionEvent = collisionEventsActive || activeEvents.collision;
|
513
476
|
const hasContactForceEvent = contactForceEventsActive || activeEvents.contactForce;
|
514
|
-
|
515
477
|
if (hasCollisionEvent && hasContactForceEvent) {
|
516
478
|
collider.setActiveEvents(ActiveEvents.COLLISION_EVENTS | ActiveEvents.CONTACT_FORCE_EVENTS);
|
517
479
|
} else if (hasCollisionEvent) {
|
@@ -519,7 +481,6 @@ activeEvents = {}) => {
|
|
519
481
|
} else if (hasContactForceEvent) {
|
520
482
|
collider.setActiveEvents(ActiveEvents.CONTACT_FORCE_EVENTS);
|
521
483
|
}
|
522
|
-
|
523
484
|
events.set(collider.handle, {
|
524
485
|
onCollisionEnter,
|
525
486
|
onCollisionExit,
|
@@ -528,7 +489,6 @@ activeEvents = {}) => {
|
|
528
489
|
onContactForce
|
529
490
|
});
|
530
491
|
}
|
531
|
-
|
532
492
|
return () => {
|
533
493
|
if (collider) {
|
534
494
|
events.delete(collider.handle);
|
@@ -538,34 +498,33 @@ activeEvents = {}) => {
|
|
538
498
|
};
|
539
499
|
const cleanRigidBodyPropsForCollider = (props = {}) => {
|
540
500
|
const rest = _objectWithoutProperties(props, _excluded$2);
|
541
|
-
|
542
501
|
return rest;
|
543
502
|
};
|
544
503
|
|
504
|
+
// Utils
|
545
505
|
const useMutableCallback = fn => {
|
546
506
|
const ref = useRef(fn);
|
547
507
|
useEffect(() => {
|
548
508
|
ref.current = fn;
|
549
509
|
}, [fn]);
|
550
510
|
return ref;
|
551
|
-
};
|
511
|
+
};
|
552
512
|
|
513
|
+
// External hooks
|
553
514
|
/**
|
554
515
|
* Exposes the Rapier context, and world
|
555
516
|
* @category Hooks
|
556
517
|
*/
|
557
|
-
|
558
|
-
|
559
518
|
const useRapier = () => {
|
560
519
|
const rapier = useContext(rapierContext);
|
561
520
|
if (!rapier) throw new Error("react-three-rapier: useRapier must be used within <Physics />!");
|
562
521
|
return rapier;
|
563
522
|
};
|
523
|
+
|
564
524
|
/**
|
565
525
|
* Registers a callback to be called before the physics step
|
566
526
|
* @category Hooks
|
567
527
|
*/
|
568
|
-
|
569
528
|
const useBeforePhysicsStep = callback => {
|
570
529
|
const {
|
571
530
|
beforeStepCallbacks
|
@@ -578,11 +537,11 @@ const useBeforePhysicsStep = callback => {
|
|
578
537
|
};
|
579
538
|
}, []);
|
580
539
|
};
|
540
|
+
|
581
541
|
/**
|
582
542
|
* Registers a callback to be called after the physics step
|
583
543
|
* @category Hooks
|
584
544
|
*/
|
585
|
-
|
586
545
|
const useAfterPhysicsStep = callback => {
|
587
546
|
const {
|
588
547
|
afterStepCallbacks
|
@@ -594,17 +553,16 @@ const useAfterPhysicsStep = callback => {
|
|
594
553
|
afterStepCallbacks.delete(ref);
|
595
554
|
};
|
596
555
|
}, []);
|
597
|
-
};
|
556
|
+
};
|
598
557
|
|
558
|
+
// Internal hooks
|
599
559
|
/**
|
600
560
|
* @internal
|
601
561
|
*/
|
602
|
-
|
603
562
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
604
563
|
const [colliderProps, setColliderProps] = useState([]);
|
605
564
|
useEffect(() => {
|
606
565
|
const object = ref.current;
|
607
|
-
|
608
566
|
if (object && options.colliders !== false) {
|
609
567
|
setColliderProps(createColliderPropsFromChildren({
|
610
568
|
object: ref.current,
|
@@ -650,33 +608,26 @@ const createSingletonProxy = createInstance => {
|
|
650
608
|
if (!instance) {
|
651
609
|
instance = createInstance();
|
652
610
|
}
|
653
|
-
|
654
611
|
return Reflect.get(instance, prop);
|
655
612
|
},
|
656
|
-
|
657
613
|
set(target, prop, value) {
|
658
614
|
if (!instance) {
|
659
615
|
instance = createInstance();
|
660
616
|
}
|
661
|
-
|
662
617
|
return Reflect.set(instance, prop, value);
|
663
618
|
}
|
664
|
-
|
665
619
|
};
|
666
620
|
const proxy = new Proxy({}, handler);
|
667
|
-
|
668
621
|
const reset = () => {
|
669
622
|
instance = undefined;
|
670
623
|
};
|
671
|
-
|
672
624
|
const set = newInstance => {
|
673
625
|
instance = newInstance;
|
674
626
|
};
|
627
|
+
|
675
628
|
/**
|
676
629
|
* Return the proxy and a reset function
|
677
630
|
*/
|
678
|
-
|
679
|
-
|
680
631
|
return {
|
681
632
|
proxy,
|
682
633
|
reset,
|
@@ -685,10 +636,8 @@ const createSingletonProxy = createInstance => {
|
|
685
636
|
};
|
686
637
|
|
687
638
|
const rapierContext = /*#__PURE__*/createContext(undefined);
|
688
|
-
|
689
639
|
const getCollisionPayloadFromSource = (target, other) => {
|
690
640
|
var _target$collider$stat, _target$rigidBody$sta, _other$collider$state, _other$rigidBody$stat, _other$collider$state2, _other$rigidBody$stat2;
|
691
|
-
|
692
641
|
return {
|
693
642
|
target: {
|
694
643
|
rigidBody: target.rigidBody.object,
|
@@ -708,13 +657,11 @@ const getCollisionPayloadFromSource = (target, other) => {
|
|
708
657
|
rigidBodyObject: (_other$rigidBody$stat2 = other.rigidBody.state) === null || _other$rigidBody$stat2 === void 0 ? void 0 : _other$rigidBody$stat2.object
|
709
658
|
};
|
710
659
|
};
|
711
|
-
|
712
660
|
const importRapier = async () => {
|
713
661
|
let r = await import('@dimforge/rapier3d-compat');
|
714
662
|
await r.init();
|
715
663
|
return r;
|
716
664
|
};
|
717
|
-
|
718
665
|
/**
|
719
666
|
* The main physics component used to create a physics world.
|
720
667
|
* @category Components
|
@@ -737,7 +684,8 @@ const Physics = props => {
|
|
737
684
|
numInternalPgsIterations = 1,
|
738
685
|
minIslandSize = 128,
|
739
686
|
maxCcdSubsteps = 1,
|
740
|
-
|
687
|
+
contactNaturalFrequency = 30,
|
688
|
+
lengthUnit = 1
|
741
689
|
} = props;
|
742
690
|
const rapier = suspend(importRapier, ["@react-thee/rapier", importRapier]);
|
743
691
|
const {
|
@@ -750,12 +698,12 @@ const Physics = props => {
|
|
750
698
|
const eventQueue = useConst(() => new EventQueue(false));
|
751
699
|
const beforeStepCallbacks = useConst(() => new Set());
|
752
700
|
const afterStepCallbacks = useConst(() => new Set());
|
701
|
+
|
753
702
|
/**
|
754
703
|
* Initiate the world
|
755
704
|
* This creates a singleton proxy, so that the world is only created when
|
756
705
|
* something within it is accessed.
|
757
706
|
*/
|
758
|
-
|
759
707
|
const {
|
760
708
|
proxy: worldProxy,
|
761
709
|
reset: resetWorldProxy,
|
@@ -766,22 +714,23 @@ const Physics = props => {
|
|
766
714
|
worldProxy.free();
|
767
715
|
resetWorldProxy();
|
768
716
|
};
|
769
|
-
}, []);
|
717
|
+
}, []);
|
770
718
|
|
719
|
+
// Update mutable props
|
771
720
|
useEffect(() => {
|
772
721
|
worldProxy.gravity = vector3ToRapierVector(gravity);
|
773
722
|
worldProxy.integrationParameters.numSolverIterations = numSolverIterations;
|
774
723
|
worldProxy.integrationParameters.numAdditionalFrictionIterations = numAdditionalFrictionIterations;
|
775
724
|
worldProxy.integrationParameters.numInternalPgsIterations = numInternalPgsIterations;
|
776
|
-
worldProxy.integrationParameters.
|
725
|
+
worldProxy.integrationParameters.normalizedAllowedLinearError = allowedLinearError;
|
777
726
|
worldProxy.integrationParameters.minIslandSize = minIslandSize;
|
778
727
|
worldProxy.integrationParameters.maxCcdSubsteps = maxCcdSubsteps;
|
779
|
-
worldProxy.integrationParameters.
|
780
|
-
worldProxy.
|
781
|
-
|
728
|
+
worldProxy.integrationParameters.normalizedPredictionDistance = predictionDistance;
|
729
|
+
worldProxy.lengthUnit = lengthUnit;
|
730
|
+
worldProxy.integrationParameters.contact_natural_frequency = contactNaturalFrequency;
|
731
|
+
}, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, lengthUnit, contactNaturalFrequency]);
|
782
732
|
const getSourceFromColliderHandle = useCallback(handle => {
|
783
733
|
var _collider$parent;
|
784
|
-
|
785
734
|
const collider = worldProxy.getCollider(handle);
|
786
735
|
const colEvents = colliderEvents.get(handle);
|
787
736
|
const colliderState = colliderStates.get(handle);
|
@@ -809,37 +758,36 @@ const Physics = props => {
|
|
809
758
|
});
|
810
759
|
const step = useCallback(dt => {
|
811
760
|
const world = worldProxy;
|
761
|
+
|
812
762
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
813
763
|
once so we don't have to string-check every frame. */
|
814
|
-
|
815
764
|
const timeStepVariable = timeStep === "vary";
|
765
|
+
|
816
766
|
/**
|
817
767
|
* Fixed timeStep simulation progression
|
818
768
|
* @see https://gafferongames.com/post/fix_your_timestep/
|
819
769
|
*/
|
820
770
|
|
821
771
|
const clampedDelta = MathUtils.clamp(dt, 0, 0.5);
|
822
|
-
|
823
772
|
const stepWorld = delta => {
|
824
773
|
// Trigger beforeStep callbacks
|
825
774
|
beforeStepCallbacks.forEach(callback => {
|
826
775
|
callback.current(world);
|
827
776
|
});
|
828
777
|
world.timestep = delta;
|
829
|
-
world.step(eventQueue);
|
778
|
+
world.step(eventQueue);
|
830
779
|
|
780
|
+
// Trigger afterStep callbacks
|
831
781
|
afterStepCallbacks.forEach(callback => {
|
832
782
|
callback.current(world);
|
833
783
|
});
|
834
784
|
};
|
835
|
-
|
836
785
|
if (timeStepVariable) {
|
837
786
|
stepWorld(clampedDelta);
|
838
787
|
} else {
|
839
788
|
// don't step time forwards if paused
|
840
789
|
// Increase accumulator
|
841
790
|
steppingState.accumulator += clampedDelta;
|
842
|
-
|
843
791
|
while (steppingState.accumulator >= timeStep) {
|
844
792
|
// Set up previous state
|
845
793
|
// needed for accurate interpolations if the world steps more than once
|
@@ -852,57 +800,48 @@ const Physics = props => {
|
|
852
800
|
};
|
853
801
|
});
|
854
802
|
}
|
855
|
-
|
856
803
|
stepWorld(timeStep);
|
857
804
|
steppingState.accumulator -= timeStep;
|
858
805
|
}
|
859
806
|
}
|
807
|
+
const interpolationAlpha = timeStepVariable || !interpolate || paused ? 1 : steppingState.accumulator / timeStep;
|
860
808
|
|
861
|
-
|
862
|
-
|
809
|
+
// Update meshes
|
863
810
|
rigidBodyStates.forEach((state, handle) => {
|
864
811
|
const rigidBody = world.getRigidBody(handle);
|
865
812
|
const events = rigidBodyEvents.get(handle);
|
866
|
-
|
867
813
|
if (events !== null && events !== void 0 && events.onSleep || events !== null && events !== void 0 && events.onWake) {
|
868
814
|
if (rigidBody.isSleeping() && !state.isSleeping) {
|
869
815
|
var _events$onSleep;
|
870
|
-
|
871
816
|
events === null || events === void 0 ? void 0 : (_events$onSleep = events.onSleep) === null || _events$onSleep === void 0 ? void 0 : _events$onSleep.call(events);
|
872
817
|
}
|
873
|
-
|
874
818
|
if (!rigidBody.isSleeping() && state.isSleeping) {
|
875
819
|
var _events$onWake;
|
876
|
-
|
877
820
|
events === null || events === void 0 ? void 0 : (_events$onWake = events.onWake) === null || _events$onWake === void 0 ? void 0 : _events$onWake.call(events);
|
878
821
|
}
|
879
|
-
|
880
822
|
state.isSleeping = rigidBody.isSleeping();
|
881
823
|
}
|
882
|
-
|
883
824
|
if (!rigidBody || rigidBody.isSleeping() && !("isInstancedMesh" in state.object) || !state.setMatrix) {
|
884
825
|
return;
|
885
|
-
}
|
886
|
-
|
826
|
+
}
|
887
827
|
|
828
|
+
// New states
|
888
829
|
let t = rigidBody.translation();
|
889
830
|
let r = rigidBody.rotation();
|
890
831
|
let previousState = steppingState.previousState[handle];
|
891
|
-
|
892
832
|
if (previousState) {
|
893
833
|
// Get previous simulated world position
|
894
|
-
_matrix4.compose(previousState.position, rapierQuaternionToQuaternion(previousState.rotation), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
|
895
|
-
|
834
|
+
_matrix4.compose(previousState.position, rapierQuaternionToQuaternion(previousState.rotation), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
|
896
835
|
|
836
|
+
// Apply previous tick position
|
897
837
|
if (state.meshType == "mesh") {
|
898
838
|
state.object.position.copy(_position);
|
899
839
|
state.object.quaternion.copy(_rotation);
|
900
840
|
}
|
901
|
-
}
|
902
|
-
|
841
|
+
}
|
903
842
|
|
843
|
+
// Get new position
|
904
844
|
_matrix4.compose(t, rapierQuaternionToQuaternion(r), state.scale).premultiply(state.invertedWorldMatrix).decompose(_position, _rotation, _scale);
|
905
|
-
|
906
845
|
if (state.meshType == "instancedMesh") {
|
907
846
|
state.setMatrix(_matrix4);
|
908
847
|
} else {
|
@@ -913,19 +852,17 @@ const Physics = props => {
|
|
913
852
|
});
|
914
853
|
eventQueue.drainCollisionEvents((handle1, handle2, started) => {
|
915
854
|
const source1 = getSourceFromColliderHandle(handle1);
|
916
|
-
const source2 = getSourceFromColliderHandle(handle2);
|
855
|
+
const source2 = getSourceFromColliderHandle(handle2);
|
917
856
|
|
857
|
+
// Collision Events
|
918
858
|
if (!(source1 !== null && source1 !== void 0 && source1.collider.object) || !(source2 !== null && source2 !== void 0 && source2.collider.object)) {
|
919
859
|
return;
|
920
860
|
}
|
921
|
-
|
922
861
|
const collisionPayload1 = getCollisionPayloadFromSource(source1, source2);
|
923
862
|
const collisionPayload2 = getCollisionPayloadFromSource(source2, source1);
|
924
|
-
|
925
863
|
if (started) {
|
926
864
|
world.contactPair(source1.collider.object, source2.collider.object, (manifold, flipped) => {
|
927
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;
|
928
|
-
|
929
866
|
/* RigidBody events */
|
930
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), {}, {
|
931
868
|
manifold,
|
@@ -935,8 +872,8 @@ const Physics = props => {
|
|
935
872
|
manifold,
|
936
873
|
flipped
|
937
874
|
}));
|
938
|
-
/* Collider events */
|
939
875
|
|
876
|
+
/* Collider events */
|
940
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), {}, {
|
941
878
|
manifold,
|
942
879
|
flipped
|
@@ -948,18 +885,16 @@ const Physics = props => {
|
|
948
885
|
});
|
949
886
|
} else {
|
950
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;
|
951
|
-
|
952
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);
|
953
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);
|
954
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);
|
955
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);
|
956
|
-
}
|
957
|
-
|
892
|
+
}
|
958
893
|
|
894
|
+
// Sensor Intersections
|
959
895
|
if (started) {
|
960
896
|
if (world.intersectionPair(source1.collider.object, source2.collider.object)) {
|
961
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;
|
962
|
-
|
963
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);
|
964
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);
|
965
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);
|
@@ -967,7 +902,6 @@ const Physics = props => {
|
|
967
902
|
}
|
968
903
|
} else {
|
969
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;
|
970
|
-
|
971
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);
|
972
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);
|
973
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);
|
@@ -976,14 +910,13 @@ const Physics = props => {
|
|
976
910
|
});
|
977
911
|
eventQueue.drainContactForceEvents(event => {
|
978
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;
|
979
|
-
|
980
913
|
const source1 = getSourceFromColliderHandle(event.collider1());
|
981
|
-
const source2 = getSourceFromColliderHandle(event.collider2());
|
914
|
+
const source2 = getSourceFromColliderHandle(event.collider2());
|
982
915
|
|
916
|
+
// Collision Events
|
983
917
|
if (!(source1 !== null && source1 !== void 0 && source1.collider.object) || !(source2 !== null && source2 !== void 0 && source2.collider.object)) {
|
984
918
|
return;
|
985
919
|
}
|
986
|
-
|
987
920
|
const collisionPayload1 = getCollisionPayloadFromSource(source1, source2);
|
988
921
|
const collisionPayload2 = getCollisionPayloadFromSource(source2, source1);
|
989
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), {}, {
|
@@ -1050,41 +983,30 @@ const Physics = props => {
|
|
1050
983
|
};
|
1051
984
|
|
1052
985
|
function _extends() {
|
1053
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
1054
|
-
for (var
|
1055
|
-
var
|
1056
|
-
|
1057
|
-
for (var key in source) {
|
1058
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1059
|
-
target[key] = source[key];
|
1060
|
-
}
|
1061
|
-
}
|
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]);
|
1062
990
|
}
|
1063
|
-
|
1064
|
-
|
1065
|
-
};
|
1066
|
-
return _extends.apply(this, arguments);
|
991
|
+
return n;
|
992
|
+
}, _extends.apply(null, arguments);
|
1067
993
|
}
|
1068
994
|
|
1069
995
|
/**
|
1070
996
|
* Initiate an instance and return a safe getter
|
1071
997
|
*/
|
1072
|
-
|
1073
998
|
const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
1074
999
|
const ref = useRef();
|
1075
1000
|
const getInstance = useCallback(() => {
|
1076
1001
|
if (!ref.current) {
|
1077
1002
|
ref.current = createFn();
|
1078
1003
|
}
|
1079
|
-
|
1080
1004
|
return ref.current;
|
1081
1005
|
}, dependencyList);
|
1082
1006
|
useEffect(() => {
|
1083
1007
|
// Save the destroy function and instance
|
1084
1008
|
const instance = getInstance();
|
1085
|
-
|
1086
1009
|
const destroy = () => destroyFn(instance);
|
1087
|
-
|
1088
1010
|
return () => {
|
1089
1011
|
destroy();
|
1090
1012
|
ref.current = undefined;
|
@@ -1097,7 +1019,6 @@ const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
|
1097
1019
|
* Takes an object resembling a Vector3 and returs a Three.Vector3
|
1098
1020
|
* @category Math helpers
|
1099
1021
|
*/
|
1100
|
-
|
1101
1022
|
const vec3 = ({
|
1102
1023
|
x,
|
1103
1024
|
y,
|
@@ -1109,11 +1030,11 @@ const vec3 = ({
|
|
1109
1030
|
}) => {
|
1110
1031
|
return new Vector3(x, y, z);
|
1111
1032
|
};
|
1033
|
+
|
1112
1034
|
/**
|
1113
1035
|
* Takes an object resembling a Quaternion and returs a Three.Quaternion
|
1114
1036
|
* @category Math helpers
|
1115
1037
|
*/
|
1116
|
-
|
1117
1038
|
const quat = ({
|
1118
1039
|
x,
|
1119
1040
|
y,
|
@@ -1127,11 +1048,11 @@ const quat = ({
|
|
1127
1048
|
}) => {
|
1128
1049
|
return new Quaternion(x, y, z, w);
|
1129
1050
|
};
|
1051
|
+
|
1130
1052
|
/**
|
1131
1053
|
* Takes an object resembling an Euler and returs a Three.Euler
|
1132
1054
|
* @category Math helpers
|
1133
1055
|
*/
|
1134
|
-
|
1135
1056
|
const euler = ({
|
1136
1057
|
x,
|
1137
1058
|
y,
|
@@ -1144,17 +1065,17 @@ const euler = ({
|
|
1144
1065
|
return new Euler(x, y, z);
|
1145
1066
|
};
|
1146
1067
|
|
1068
|
+
// Need to catch the case where forwardedRef is a function... how to do that?
|
1147
1069
|
const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
1148
|
-
const innerRef = useRef(defaultValue);
|
1070
|
+
const innerRef = useRef(defaultValue);
|
1149
1071
|
|
1072
|
+
// Update the forwarded ref when the inner ref changes
|
1150
1073
|
if (forwardedRef && typeof forwardedRef !== "function") {
|
1151
1074
|
if (!forwardedRef.current) {
|
1152
1075
|
forwardedRef.current = innerRef.current;
|
1153
1076
|
}
|
1154
|
-
|
1155
1077
|
return forwardedRef;
|
1156
1078
|
}
|
1157
|
-
|
1158
1079
|
return innerRef;
|
1159
1080
|
};
|
1160
1081
|
|
@@ -1162,7 +1083,7 @@ const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
|
1162
1083
|
* A collider is a shape that can be attached to a rigid body to define its physical properties.
|
1163
1084
|
* @internal
|
1164
1085
|
*/
|
1165
|
-
const AnyCollider = /*#__PURE__*/memo(
|
1086
|
+
const AnyCollider = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef) => {
|
1166
1087
|
const {
|
1167
1088
|
children,
|
1168
1089
|
position,
|
@@ -1178,17 +1099,16 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwarded
|
|
1178
1099
|
} = useRapier();
|
1179
1100
|
const rigidBodyContext = useRigidBodyContext();
|
1180
1101
|
const colliderRef = useForwardedRef(forwardedRef);
|
1181
|
-
const objectRef = useRef(null);
|
1102
|
+
const objectRef = useRef(null);
|
1182
1103
|
|
1104
|
+
// We spread the props out here to make sure that the ref is updated when the props change.
|
1183
1105
|
const immutablePropArray = immutableColliderOptions.flatMap(key => Array.isArray(props[key]) ? [...props[key]] : props[key]);
|
1184
1106
|
const getInstance = useImperativeInstance(() => {
|
1185
1107
|
const worldScale = objectRef.current.getWorldScale(vec3());
|
1186
1108
|
const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
|
1187
|
-
|
1188
1109
|
if (typeof forwardedRef == "function") {
|
1189
1110
|
forwardedRef(collider);
|
1190
1111
|
}
|
1191
|
-
|
1192
1112
|
colliderRef.current = collider;
|
1193
1113
|
return collider;
|
1194
1114
|
}, collider => {
|
@@ -1217,7 +1137,6 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwarded
|
|
1217
1137
|
name: name
|
1218
1138
|
}, children);
|
1219
1139
|
}));
|
1220
|
-
|
1221
1140
|
/**
|
1222
1141
|
* A cuboid collider shape
|
1223
1142
|
* @category Colliders
|
@@ -1229,7 +1148,6 @@ const CuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1229
1148
|
}));
|
1230
1149
|
});
|
1231
1150
|
CuboidCollider.displayName = "CuboidCollider";
|
1232
|
-
|
1233
1151
|
/**
|
1234
1152
|
* A round cuboid collider shape
|
1235
1153
|
* @category Colliders
|
@@ -1239,7 +1157,6 @@ const RoundCuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__P
|
|
1239
1157
|
ref: ref
|
1240
1158
|
})));
|
1241
1159
|
RoundCuboidCollider.displayName = "RoundCuboidCollider";
|
1242
|
-
|
1243
1160
|
/**
|
1244
1161
|
* A ball collider shape
|
1245
1162
|
* @category Colliders
|
@@ -1249,7 +1166,6 @@ const BallCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/
|
|
1249
1166
|
ref: ref
|
1250
1167
|
})));
|
1251
1168
|
BallCollider.displayName = "BallCollider";
|
1252
|
-
|
1253
1169
|
/**
|
1254
1170
|
* A capsule collider shape
|
1255
1171
|
* @category Colliders
|
@@ -1259,7 +1175,6 @@ const CapsuleCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE_
|
|
1259
1175
|
ref: ref
|
1260
1176
|
})));
|
1261
1177
|
CapsuleCollider.displayName = "CapsuleCollider";
|
1262
|
-
|
1263
1178
|
/**
|
1264
1179
|
* A heightfield collider shape
|
1265
1180
|
* @category Colliders
|
@@ -1269,7 +1184,6 @@ const HeightfieldCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__P
|
|
1269
1184
|
ref: ref
|
1270
1185
|
})));
|
1271
1186
|
HeightfieldCollider.displayName = "HeightfieldCollider";
|
1272
|
-
|
1273
1187
|
/**
|
1274
1188
|
* A trimesh collider shape
|
1275
1189
|
* @category Colliders
|
@@ -1279,7 +1193,6 @@ const TrimeshCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE_
|
|
1279
1193
|
ref: ref
|
1280
1194
|
})));
|
1281
1195
|
TrimeshCollider.displayName = "TrimeshCollider";
|
1282
|
-
|
1283
1196
|
/**
|
1284
1197
|
* A cone collider shape
|
1285
1198
|
* @category Colliders
|
@@ -1289,7 +1202,6 @@ const ConeCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/
|
|
1289
1202
|
ref: ref
|
1290
1203
|
})));
|
1291
1204
|
ConeCollider.displayName = "ConeCollider";
|
1292
|
-
|
1293
1205
|
/**
|
1294
1206
|
* A round cylinder collider shape
|
1295
1207
|
* @category Colliders
|
@@ -1299,7 +1211,6 @@ const RoundConeCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PUR
|
|
1299
1211
|
ref: ref
|
1300
1212
|
})));
|
1301
1213
|
RoundConeCollider.displayName = "RoundConeCollider";
|
1302
|
-
|
1303
1214
|
/**
|
1304
1215
|
* A cylinder collider shape
|
1305
1216
|
* @category Colliders
|
@@ -1309,7 +1220,6 @@ const CylinderCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE
|
|
1309
1220
|
ref: ref
|
1310
1221
|
})));
|
1311
1222
|
CylinderCollider.displayName = "CylinderCollider";
|
1312
|
-
|
1313
1223
|
/**
|
1314
1224
|
* A round cylinder collider shape
|
1315
1225
|
* @category Colliders
|
@@ -1319,7 +1229,6 @@ const RoundCylinderCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#_
|
|
1319
1229
|
ref: ref
|
1320
1230
|
})));
|
1321
1231
|
CylinderCollider.displayName = "RoundCylinderCollider";
|
1322
|
-
|
1323
1232
|
/**
|
1324
1233
|
* A convex hull collider shape
|
1325
1234
|
* @category Colliders
|
@@ -1332,10 +1241,10 @@ ConvexHullCollider.displayName = "ConvexHullCollider";
|
|
1332
1241
|
|
1333
1242
|
const rigidBodyDescFromOptions = options => {
|
1334
1243
|
var _options$canSleep;
|
1335
|
-
|
1336
1244
|
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
1337
|
-
const desc = new RigidBodyDesc(type);
|
1245
|
+
const desc = new RigidBodyDesc(type);
|
1338
1246
|
|
1247
|
+
// Apply immutable options
|
1339
1248
|
desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
1340
1249
|
return desc;
|
1341
1250
|
};
|
@@ -1367,11 +1276,9 @@ const mutableRigidBodyOptions = {
|
|
1367
1276
|
gravityScale: (rb, value) => {
|
1368
1277
|
rb.setGravityScale(value, true);
|
1369
1278
|
},
|
1370
|
-
|
1371
1279
|
additionalSolverIterations(rb, value) {
|
1372
1280
|
rb.setAdditionalSolverIterations(value);
|
1373
1281
|
},
|
1374
|
-
|
1375
1282
|
linearDamping: (rb, value) => {
|
1376
1283
|
rb.setLinearDamping(value);
|
1377
1284
|
},
|
@@ -1410,14 +1317,15 @@ const mutableRigidBodyOptions = {
|
|
1410
1317
|
ccd: (rb, value) => {
|
1411
1318
|
rb.enableCcd(value);
|
1412
1319
|
},
|
1320
|
+
softCcdPrediction: (rb, value) => {
|
1321
|
+
rb.setSoftCcdPrediction(value);
|
1322
|
+
},
|
1413
1323
|
userData: (rb, value) => {
|
1414
1324
|
rb.userData = value;
|
1415
1325
|
},
|
1416
|
-
|
1417
1326
|
type(rb, value) {
|
1418
1327
|
rb.setBodyType(rigidBodyTypeFromString(value), true);
|
1419
1328
|
},
|
1420
|
-
|
1421
1329
|
position: () => {},
|
1422
1330
|
rotation: () => {},
|
1423
1331
|
quaternion: () => {},
|
@@ -1428,19 +1336,14 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
1428
1336
|
if (!rigidBody) {
|
1429
1337
|
return;
|
1430
1338
|
}
|
1431
|
-
|
1432
1339
|
const state = states.get(rigidBody.handle);
|
1433
|
-
|
1434
1340
|
if (state) {
|
1435
1341
|
if (updateTranslations) {
|
1436
1342
|
state.object.updateWorldMatrix(true, false);
|
1437
|
-
|
1438
1343
|
_matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
|
1439
|
-
|
1440
1344
|
rigidBody.setTranslation(_position, false);
|
1441
1345
|
rigidBody.setRotation(_rotation, false);
|
1442
1346
|
}
|
1443
|
-
|
1444
1347
|
mutableRigidBodyOptionKeys.forEach(key => {
|
1445
1348
|
if (key in options) {
|
1446
1349
|
mutableRigidBodyOptions[key](rigidBody, options[key]);
|
@@ -1489,23 +1392,21 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1489
1392
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1490
1393
|
const RigidBodyContext = /*#__PURE__*/createContext(undefined);
|
1491
1394
|
const useRigidBodyContext = () => useContext(RigidBodyContext);
|
1492
|
-
|
1493
1395
|
/**
|
1494
1396
|
* A rigid body is a physical object that can be simulated by the physics engine.
|
1495
1397
|
* @category Components
|
1496
1398
|
*/
|
1497
|
-
const RigidBody = /*#__PURE__*/memo(
|
1399
|
+
const RigidBody = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef) => {
|
1498
1400
|
const {
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1401
|
+
children,
|
1402
|
+
type,
|
1403
|
+
position,
|
1404
|
+
rotation,
|
1405
|
+
scale,
|
1406
|
+
quaternion,
|
1407
|
+
transformState
|
1408
|
+
} = props,
|
1409
|
+
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1509
1410
|
const objectRef = useRef(null);
|
1510
1411
|
const rigidBodyRef = useForwardedRef(forwardedRef);
|
1511
1412
|
const {
|
@@ -1522,24 +1423,24 @@ const RigidBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwardedRe
|
|
1522
1423
|
const immutablePropArray = immutableRigidBodyOptions.flatMap(key => {
|
1523
1424
|
return Array.isArray(mergedOptions[key]) ? [...mergedOptions[key]] : mergedOptions[key];
|
1524
1425
|
});
|
1525
|
-
const childColliderProps = useChildColliderProps(objectRef, mergedOptions);
|
1426
|
+
const childColliderProps = useChildColliderProps(objectRef, mergedOptions);
|
1526
1427
|
|
1428
|
+
// Provide a way to eagerly create rigidbody
|
1527
1429
|
const getRigidBody = useImperativeInstance(() => {
|
1528
1430
|
const desc = rigidBodyDescFromOptions(mergedOptions);
|
1529
1431
|
const rigidBody = world.createRigidBody(desc);
|
1530
|
-
|
1531
1432
|
if (typeof forwardedRef === "function") {
|
1532
1433
|
forwardedRef(rigidBody);
|
1533
1434
|
}
|
1534
|
-
|
1535
1435
|
rigidBodyRef.current = rigidBody;
|
1536
1436
|
return rigidBody;
|
1537
1437
|
}, rigidBody => {
|
1538
1438
|
if (world.getRigidBody(rigidBody.handle)) {
|
1539
1439
|
world.removeRigidBody(rigidBody);
|
1540
1440
|
}
|
1541
|
-
}, immutablePropArray);
|
1441
|
+
}, immutablePropArray);
|
1542
1442
|
|
1443
|
+
// Only provide a object state after the ref has been set
|
1543
1444
|
useEffect(() => {
|
1544
1445
|
const rigidBody = getRigidBody();
|
1545
1446
|
const state = createRigidBodyState({
|
@@ -1610,51 +1511,46 @@ const MeshCollider = /*#__PURE__*/memo(props => {
|
|
1610
1511
|
MeshCollider.displayName = "MeshCollider";
|
1611
1512
|
|
1612
1513
|
const _excluded = ["children", "instances", "colliderNodes", "position", "rotation", "quaternion", "scale"];
|
1613
|
-
const InstancedRigidBodies = /*#__PURE__*/memo(
|
1514
|
+
const InstancedRigidBodies = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef) => {
|
1614
1515
|
const rigidBodiesRef = useForwardedRef(forwardedRef, []);
|
1615
1516
|
const objectRef = useRef(null);
|
1616
1517
|
const instanceWrapperRef = useRef(null);
|
1617
|
-
|
1618
1518
|
const {
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
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);
|
1631
1532
|
const childColliderProps = useChildColliderProps(objectRef, _objectSpread2(_objectSpread2({}, props), {}, {
|
1632
1533
|
children: undefined
|
1633
1534
|
}));
|
1634
|
-
|
1635
1535
|
const getInstancedMesh = () => {
|
1636
1536
|
const firstChild = instanceWrapperRef.current.children[0];
|
1637
|
-
|
1638
1537
|
if (firstChild && "isInstancedMesh" in firstChild) {
|
1639
1538
|
return firstChild;
|
1640
1539
|
}
|
1641
|
-
|
1642
1540
|
return undefined;
|
1643
1541
|
};
|
1644
|
-
|
1645
1542
|
useEffect(() => {
|
1646
1543
|
const instancedMesh = getInstancedMesh();
|
1647
|
-
|
1648
1544
|
if (instancedMesh) {
|
1649
1545
|
instancedMesh.instanceMatrix.setUsage(DynamicDrawUsage);
|
1650
1546
|
} else {
|
1651
1547
|
console.warn("InstancedRigidBodies expects exactly one child, which must be an InstancedMesh");
|
1652
1548
|
}
|
1653
|
-
}, []);
|
1549
|
+
}, []);
|
1654
1550
|
|
1551
|
+
// Update the RigidBodyStates whenever the instances change
|
1655
1552
|
const applyInstancedState = (state, index) => {
|
1656
1553
|
const instancedMesh = getInstancedMesh();
|
1657
|
-
|
1658
1554
|
if (instancedMesh) {
|
1659
1555
|
return _objectSpread2(_objectSpread2({}, state), {}, {
|
1660
1556
|
getMatrix: matrix => {
|
@@ -1668,10 +1564,8 @@ const InstancedRigidBodies = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props,
|
|
1668
1564
|
meshType: "instancedMesh"
|
1669
1565
|
});
|
1670
1566
|
}
|
1671
|
-
|
1672
1567
|
return state;
|
1673
1568
|
};
|
1674
|
-
|
1675
1569
|
return /*#__PURE__*/React.createElement("object3D", _extends({
|
1676
1570
|
ref: objectRef
|
1677
1571
|
}, rigidBodyProps, {
|
@@ -1695,7 +1589,6 @@ InstancedRigidBodies.displayName = "InstancedRigidBodies";
|
|
1695
1589
|
/**
|
1696
1590
|
* @internal
|
1697
1591
|
*/
|
1698
|
-
|
1699
1592
|
const useImpulseJoint = (body1, body2, params) => {
|
1700
1593
|
const {
|
1701
1594
|
world
|
@@ -1710,7 +1603,6 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1710
1603
|
}, joint => {
|
1711
1604
|
if (joint) {
|
1712
1605
|
jointRef.current = undefined;
|
1713
|
-
|
1714
1606
|
if (world.getImpulseJoint(joint.handle)) {
|
1715
1607
|
world.removeImpulseJoint(joint, true);
|
1716
1608
|
}
|
@@ -1718,6 +1610,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1718
1610
|
}, []);
|
1719
1611
|
return jointRef;
|
1720
1612
|
};
|
1613
|
+
|
1721
1614
|
/**
|
1722
1615
|
* A fixed joint ensures that two rigid-bodies don't move relative to each other.
|
1723
1616
|
* Fixed joints are characterized by one local frame (represented by an isometry) on each rigid-body.
|
@@ -1725,13 +1618,13 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1725
1618
|
*
|
1726
1619
|
* @category Hooks - Joints
|
1727
1620
|
*/
|
1728
|
-
|
1729
1621
|
const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor, body2LocalFrame]) => {
|
1730
1622
|
const {
|
1731
1623
|
rapier
|
1732
1624
|
} = useRapier();
|
1733
1625
|
return useImpulseJoint(body1, body2, rapier.JointData.fixed(vector3ToRapierVector(body1Anchor), quaternionToRapierQuaternion(body1LocalFrame), vector3ToRapierVector(body2Anchor), quaternionToRapierQuaternion(body2LocalFrame)));
|
1734
1626
|
};
|
1627
|
+
|
1735
1628
|
/**
|
1736
1629
|
* The spherical joint ensures that two points on the local-spaces of two rigid-bodies always coincide (it prevents any relative
|
1737
1630
|
* translational motion at this points). This is typically used to simulate ragdolls arms, pendulums, etc.
|
@@ -1740,13 +1633,13 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
|
|
1740
1633
|
*
|
1741
1634
|
* @category Hooks - Joints
|
1742
1635
|
*/
|
1743
|
-
|
1744
1636
|
const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
1745
1637
|
const {
|
1746
1638
|
rapier
|
1747
1639
|
} = useRapier();
|
1748
1640
|
return useImpulseJoint(body1, body2, rapier.JointData.spherical(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor)));
|
1749
1641
|
};
|
1642
|
+
|
1750
1643
|
/**
|
1751
1644
|
* The revolute joint prevents any relative movement between two rigid-bodies, except for relative
|
1752
1645
|
* rotations along one axis. This is typically used to simulate wheels, fans, etc.
|
@@ -1754,20 +1647,18 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
|
1754
1647
|
*
|
1755
1648
|
* @category Hooks - Joints
|
1756
1649
|
*/
|
1757
|
-
|
1758
1650
|
const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]) => {
|
1759
1651
|
const {
|
1760
1652
|
rapier
|
1761
1653
|
} = useRapier();
|
1762
1654
|
const params = rapier.JointData.revolute(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor), vector3ToRapierVector(axis));
|
1763
|
-
|
1764
1655
|
if (limits) {
|
1765
1656
|
params.limitsEnabled = true;
|
1766
1657
|
params.limits = limits;
|
1767
1658
|
}
|
1768
|
-
|
1769
1659
|
return useImpulseJoint(body1, body2, params);
|
1770
1660
|
};
|
1661
|
+
|
1771
1662
|
/**
|
1772
1663
|
* The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
|
1773
1664
|
* It is characterized by one local anchor as well as one local axis on each rigid-body. In 3D, an optional
|
@@ -1775,25 +1666,22 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]
|
|
1775
1666
|
*
|
1776
1667
|
* @category Hooks - Joints
|
1777
1668
|
*/
|
1778
|
-
|
1779
1669
|
const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis, limits]) => {
|
1780
1670
|
const {
|
1781
1671
|
rapier
|
1782
1672
|
} = useRapier();
|
1783
1673
|
const params = rapier.JointData.prismatic(vector3ToRapierVector(body1Anchor), vector3ToRapierVector(body2Anchor), vector3ToRapierVector(axis));
|
1784
|
-
|
1785
1674
|
if (limits) {
|
1786
1675
|
params.limitsEnabled = true;
|
1787
1676
|
params.limits = limits;
|
1788
1677
|
}
|
1789
|
-
|
1790
1678
|
return useImpulseJoint(body1, body2, params);
|
1791
1679
|
};
|
1680
|
+
|
1792
1681
|
/**
|
1793
1682
|
* The rope joint limits the max distance between two bodies.
|
1794
1683
|
* @category Hooks - Joints
|
1795
1684
|
*/
|
1796
|
-
|
1797
1685
|
const useRopeJoint = (body1, body2, [body1Anchor, body2Anchor, length]) => {
|
1798
1686
|
const {
|
1799
1687
|
rapier
|
@@ -1803,11 +1691,11 @@ const useRopeJoint = (body1, body2, [body1Anchor, body2Anchor, length]) => {
|
|
1803
1691
|
const params = rapier.JointData.rope(length, vBody1Anchor, vBody2Anchor);
|
1804
1692
|
return useImpulseJoint(body1, body2, params);
|
1805
1693
|
};
|
1694
|
+
|
1806
1695
|
/**
|
1807
1696
|
* The spring joint applies a force proportional to the distance between two objects.
|
1808
1697
|
* @category Hooks - Joints
|
1809
1698
|
*/
|
1810
|
-
|
1811
1699
|
const useSpringJoint = (body1, body2, [body1Anchor, body2Anchor, restLength, stiffness, damping]) => {
|
1812
1700
|
const {
|
1813
1701
|
rapier
|
@@ -1851,7 +1739,6 @@ const useSpringJoint = (body1, body2, [body1Anchor, body2Anchor, restLength, sti
|
|
1851
1739
|
* @returns An InteractionGroup bitmask.
|
1852
1740
|
*/
|
1853
1741
|
const interactionGroups = (memberships, filters) => (bitmask(memberships) << 16) + (filters !== undefined ? bitmask(filters) : 0b1111111111111111);
|
1854
|
-
|
1855
1742
|
const bitmask = groups => [groups].flat().reduce((acc, layer) => acc | 1 << layer, 0);
|
1856
1743
|
|
1857
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 };
|