@react-three/rapier 0.1.2 → 0.2.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/CHANGELOG.md +12 -0
- package/dist/declarations/src/Physics.d.ts +10 -5
- package/dist/declarations/src/api.d.ts +33 -0
- package/dist/declarations/src/components.d.ts +11 -2
- package/dist/declarations/src/hooks.d.ts +172 -24
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +7 -1
- package/dist/declarations/src/utils.d.ts +4 -4
- package/dist/react-three-rapier.cjs.dev.js +284 -128
- package/dist/react-three-rapier.cjs.prod.js +284 -128
- package/dist/react-three-rapier.esm.js +285 -129
- package/package.json +1 -1
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var React = require('react');
|
6
6
|
var useAsset = require('use-asset');
|
7
7
|
var fiber = require('@react-three/fiber');
|
8
|
-
var rapier3dCompat = require('@dimforge/rapier3d-compat');
|
9
8
|
var three = require('three');
|
9
|
+
var rapier3dCompat = require('@dimforge/rapier3d-compat');
|
10
10
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
12
12
|
|
@@ -63,7 +63,7 @@ const scaleColliderArgs = (shape, args, scale) => {
|
|
63
63
|
const scaleArray = [scale.x, scale.y, scale.z];
|
64
64
|
return newArgs.map((arg, index) => scaleArray[index] * arg);
|
65
65
|
};
|
66
|
-
const createColliderFromOptions = (options, world,
|
66
|
+
const createColliderFromOptions = (options, world, rigidBodyHandle, scale = {
|
67
67
|
x: 1,
|
68
68
|
y: 1,
|
69
69
|
z: 1
|
@@ -105,12 +105,13 @@ const createColliderFromOptions = (options, world, body, scale = {
|
|
105
105
|
});
|
106
106
|
}
|
107
107
|
|
108
|
-
const collider = world.createCollider(colliderDesc,
|
108
|
+
const collider = world.createCollider(colliderDesc, rigidBodyHandle);
|
109
109
|
return collider;
|
110
110
|
};
|
111
111
|
const createCollidersFromChildren = (object, rigidBody, type, world) => {
|
112
112
|
const colliders = [];
|
113
113
|
let desc;
|
114
|
+
let offset = new three.Vector3();
|
114
115
|
object.traverse(child => {
|
115
116
|
if ("isMesh" in child) {
|
116
117
|
const {
|
@@ -137,6 +138,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
|
|
137
138
|
boundingBox
|
138
139
|
} = geometry;
|
139
140
|
const size = boundingBox.getSize(new three.Vector3());
|
141
|
+
boundingBox.getCenter(offset);
|
140
142
|
desc = rapier3dCompat.ColliderDesc.cuboid(size.x / 2 * scale.x, size.y / 2 * scale.y, size.z / 2 * scale.z);
|
141
143
|
}
|
142
144
|
break;
|
@@ -148,6 +150,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
|
|
148
150
|
boundingSphere
|
149
151
|
} = geometry;
|
150
152
|
const radius = boundingSphere.radius * scale.x;
|
153
|
+
offset.copy(boundingSphere.center);
|
151
154
|
desc = rapier3dCompat.ColliderDesc.ball(radius);
|
152
155
|
}
|
153
156
|
break;
|
@@ -172,7 +175,7 @@ const createCollidersFromChildren = (object, rigidBody, type, world) => {
|
|
172
175
|
|
173
176
|
|
174
177
|
const parentWorldScale = child.parent.getWorldScale(new three.Vector3());
|
175
|
-
desc.setTranslation(x * parentWorldScale.x, y * parentWorldScale.y, z * parentWorldScale.z).setRotation({
|
178
|
+
desc.setTranslation((x + offset.x) * parentWorldScale.x, (y + offset.y) * parentWorldScale.y, (z + offset.z) * parentWorldScale.z).setRotation({
|
176
179
|
x: rx,
|
177
180
|
y: ry,
|
178
181
|
z: rz,
|
@@ -196,6 +199,99 @@ const scaleVertices = (vertices, scale) => {
|
|
196
199
|
return scaledVerts;
|
197
200
|
};
|
198
201
|
|
202
|
+
// TODO: Flesh this out
|
203
|
+
const createRigidBodyApi = ref => {
|
204
|
+
return {
|
205
|
+
raw: () => ref.current(),
|
206
|
+
|
207
|
+
get handle() {
|
208
|
+
return ref.current().handle;
|
209
|
+
},
|
210
|
+
|
211
|
+
applyImpulse({
|
212
|
+
x,
|
213
|
+
y,
|
214
|
+
z
|
215
|
+
}) {
|
216
|
+
ref.current().applyImpulse({
|
217
|
+
x,
|
218
|
+
y,
|
219
|
+
z
|
220
|
+
}, true);
|
221
|
+
},
|
222
|
+
|
223
|
+
applyTorqueImpulse({
|
224
|
+
x,
|
225
|
+
y,
|
226
|
+
z
|
227
|
+
}) {
|
228
|
+
ref.current().applyTorqueImpulse({
|
229
|
+
x,
|
230
|
+
y,
|
231
|
+
z
|
232
|
+
}, true);
|
233
|
+
},
|
234
|
+
|
235
|
+
translation() {
|
236
|
+
const {
|
237
|
+
x,
|
238
|
+
y,
|
239
|
+
z
|
240
|
+
} = ref.current().translation();
|
241
|
+
return new three.Vector3(x, y, z);
|
242
|
+
},
|
243
|
+
|
244
|
+
rotation() {
|
245
|
+
const {
|
246
|
+
x,
|
247
|
+
y,
|
248
|
+
z,
|
249
|
+
w
|
250
|
+
} = ref.current().rotation();
|
251
|
+
return new three.Quaternion(x, y, z, w);
|
252
|
+
}
|
253
|
+
|
254
|
+
};
|
255
|
+
}; // TODO: Flesh this out
|
256
|
+
|
257
|
+
const createColliderApi = ref => {
|
258
|
+
return {
|
259
|
+
raw: () => ref.current(),
|
260
|
+
|
261
|
+
get handle() {
|
262
|
+
return ref.current().handle;
|
263
|
+
}
|
264
|
+
|
265
|
+
};
|
266
|
+
};
|
267
|
+
const createWorldApi = ref => {
|
268
|
+
return {
|
269
|
+
raw: () => ref.current(),
|
270
|
+
getCollider: handle => ref.current().getCollider(handle),
|
271
|
+
getRigidBody: handle => ref.current().getRigidBody(handle),
|
272
|
+
createRigidBody: desc => ref.current().createRigidBody(desc),
|
273
|
+
createCollider: (desc, rigidBodyHandle) => ref.current().createCollider(desc, rigidBodyHandle),
|
274
|
+
removeRigidBody: rigidBody => ref.current().removeRigidBody(rigidBody),
|
275
|
+
removeCollider: collider => ref.current().removeCollider(collider, true),
|
276
|
+
createImpulseJoint: (params, rigidBodyA, rigidBodyB) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB),
|
277
|
+
removeImpulseJoint: joint => ref.current().removeImpulseJoint(joint, true),
|
278
|
+
forEachCollider: callback => ref.current().forEachCollider(callback)
|
279
|
+
};
|
280
|
+
}; // TODO: Broken currently, waiting for Rapier3D to fix
|
281
|
+
|
282
|
+
const createJointApi = ref => {
|
283
|
+
return {
|
284
|
+
raw: () => ref.current(),
|
285
|
+
|
286
|
+
get handle() {
|
287
|
+
return ref.current().handle;
|
288
|
+
},
|
289
|
+
|
290
|
+
configureMotorPosition: (targetPos, stiffness, damping) => ref.current().configureMotorPosition(targetPos, stiffness, damping),
|
291
|
+
configureMotorVelocity: (targetVel, damping) => ref.current().configureMotorVelocity(targetVel, damping)
|
292
|
+
};
|
293
|
+
};
|
294
|
+
|
199
295
|
const RapierContext = /*#__PURE__*/React.createContext(undefined);
|
200
296
|
|
201
297
|
const importRapier = async () => {
|
@@ -210,30 +306,81 @@ const Physics = ({
|
|
210
306
|
children
|
211
307
|
}) => {
|
212
308
|
const rapier = useAsset.useAsset(importRapier);
|
213
|
-
const
|
214
|
-
const
|
215
|
-
if (!
|
216
|
-
|
217
|
-
|
218
|
-
|
309
|
+
const worldRef = React.useRef();
|
310
|
+
const getWorldRef = React.useRef(() => {
|
311
|
+
if (!worldRef.current) {
|
312
|
+
const world = new rapier.World(vectorArrayToObject(_gravity));
|
313
|
+
worldRef.current = world;
|
314
|
+
}
|
315
|
+
|
316
|
+
return worldRef.current;
|
317
|
+
});
|
318
|
+
const [colliderMeshes] = React.useState(() => new Map());
|
319
|
+
const [rigidBodyMeshes] = React.useState(() => new Map()); // Init world
|
320
|
+
|
321
|
+
React.useLayoutEffect(() => {
|
322
|
+
const world = getWorldRef.current();
|
323
|
+
return () => {
|
324
|
+
if (world) {
|
325
|
+
world.free();
|
326
|
+
worldRef.current = undefined;
|
327
|
+
}
|
328
|
+
};
|
329
|
+
}, []);
|
219
330
|
const time = React.useRef(performance.now());
|
220
331
|
fiber.useFrame(context => {
|
221
|
-
|
332
|
+
const world = worldRef.current;
|
333
|
+
if (!world) return; // Set timestep to current delta, to allow for variable frame rates
|
222
334
|
// We cap the delta at 100, so that the physics simulation doesn't get wild
|
335
|
+
|
223
336
|
const now = performance.now();
|
224
337
|
const delta = Math.min(100, now - time.current);
|
225
338
|
world.timestep = delta / 1000;
|
226
|
-
world.step(); //
|
339
|
+
world.step(); // Update meshes
|
340
|
+
|
341
|
+
rigidBodyMeshes.forEach((mesh, handle) => {
|
342
|
+
const rigidBody = world.getRigidBody(handle);
|
343
|
+
|
344
|
+
if (!rigidBody || rigidBody.isSleeping() || rigidBody.isFixed() || !mesh.parent) {
|
345
|
+
return;
|
346
|
+
}
|
227
347
|
|
228
|
-
|
348
|
+
const {
|
349
|
+
x,
|
350
|
+
y,
|
351
|
+
z
|
352
|
+
} = rigidBody.translation();
|
353
|
+
const {
|
354
|
+
x: rx,
|
355
|
+
y: ry,
|
356
|
+
z: rz,
|
357
|
+
w: rw
|
358
|
+
} = rigidBody.rotation();
|
359
|
+
const scale = mesh.getWorldScale(new three.Vector3()); // haha matrixes I have no idea what I'm doing :)
|
360
|
+
|
361
|
+
const o = new three.Object3D();
|
362
|
+
o.position.set(x, y, z);
|
363
|
+
o.rotation.setFromQuaternion(new three.Quaternion(rx, ry, rz, rw));
|
364
|
+
o.scale.set(scale.x, scale.y, scale.z);
|
365
|
+
o.updateMatrix();
|
366
|
+
o.applyMatrix4(mesh.parent.matrixWorld.clone().invert());
|
367
|
+
o.updateMatrix();
|
368
|
+
mesh.position.setFromMatrixPosition(o.matrix);
|
369
|
+
mesh.rotation.setFromRotationMatrix(o.matrix);
|
370
|
+
});
|
229
371
|
time.current = now;
|
230
372
|
});
|
373
|
+
const api = React.useMemo(() => createWorldApi(getWorldRef), []);
|
231
374
|
const context = React.useMemo(() => ({
|
232
|
-
|
233
|
-
world,
|
234
|
-
|
235
|
-
|
236
|
-
|
375
|
+
rapier,
|
376
|
+
world: api,
|
377
|
+
physicsOptions: {
|
378
|
+
colliders: _colliders,
|
379
|
+
gravity: _gravity
|
380
|
+
},
|
381
|
+
colliderMeshes,
|
382
|
+
rigidBodyMeshes
|
383
|
+
}), []);
|
237
384
|
return /*#__PURE__*/React__default["default"].createElement(RapierContext.Provider, {
|
238
385
|
value: context
|
239
386
|
}, children);
|
@@ -282,66 +429,45 @@ function _objectSpread2(target) {
|
|
282
429
|
|
283
430
|
const useRapier = () => {
|
284
431
|
return React.useContext(RapierContext);
|
285
|
-
}; // Private hook for updating the simulations on objects
|
286
|
-
|
287
|
-
const useRapierStep = callback => {
|
288
|
-
const {
|
289
|
-
stepFuncs
|
290
|
-
} = useRapier();
|
291
|
-
React.useEffect(() => {
|
292
|
-
stepFuncs.push(callback);
|
293
|
-
return () => {
|
294
|
-
const index = stepFuncs.indexOf(callback);
|
295
|
-
stepFuncs.splice(index, 1);
|
296
|
-
};
|
297
|
-
}, [callback]);
|
298
|
-
};
|
299
|
-
const useCollider = (body, options = {}) => {
|
300
|
-
const {
|
301
|
-
RAPIER,
|
302
|
-
world
|
303
|
-
} = useRapier();
|
304
|
-
const collider = React.useMemo(() => {
|
305
|
-
return createColliderFromOptions(options, world, body);
|
306
|
-
}, []);
|
307
|
-
React.useEffect(() => {
|
308
|
-
return () => {
|
309
|
-
world.removeCollider(collider, false);
|
310
|
-
};
|
311
|
-
}, []);
|
312
|
-
return [collider];
|
313
432
|
};
|
314
|
-
const useRigidBody = options => {
|
433
|
+
const useRigidBody = (options = {}) => {
|
315
434
|
const {
|
316
|
-
|
435
|
+
rapier,
|
317
436
|
world,
|
318
|
-
|
437
|
+
rigidBodyMeshes,
|
438
|
+
physicsOptions
|
319
439
|
} = useRapier();
|
320
440
|
const ref = React.useRef(); // Create rigidbody
|
321
441
|
|
322
|
-
const
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
442
|
+
const rigidBodyRef = React.useRef();
|
443
|
+
const getRigidBodyRef = React.useRef(() => {
|
444
|
+
if (!rigidBodyRef.current) {
|
445
|
+
var _options$linearVeloci, _options$angularVeloc, _options$gravityScale, _options$canSleep, _options$ccd;
|
446
|
+
|
447
|
+
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
448
|
+
const [lvx, lvy, lvz] = (_options$linearVeloci = options === null || options === void 0 ? void 0 : options.linearVelocity) !== null && _options$linearVeloci !== void 0 ? _options$linearVeloci : [0, 0, 0];
|
449
|
+
const [avx, avy, avz] = (_options$angularVeloc = options === null || options === void 0 ? void 0 : options.angularVelocity) !== null && _options$angularVeloc !== void 0 ? _options$angularVeloc : [0, 0, 0];
|
450
|
+
const gravityScale = (_options$gravityScale = options === null || options === void 0 ? void 0 : options.gravityScale) !== null && _options$gravityScale !== void 0 ? _options$gravityScale : 1;
|
451
|
+
const canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
452
|
+
const ccdEnabled = (_options$ccd = options === null || options === void 0 ? void 0 : options.ccd) !== null && _options$ccd !== void 0 ? _options$ccd : false;
|
453
|
+
const desc = new rapier.RigidBodyDesc(type).setLinvel(lvx, lvy, lvz).setAngvel({
|
454
|
+
x: avx,
|
455
|
+
y: avy,
|
456
|
+
z: avz
|
457
|
+
}).setGravityScale(gravityScale).setCanSleep(canSleep).setCcdEnabled(ccdEnabled);
|
458
|
+
const rigidBody = world.createRigidBody(desc);
|
459
|
+
rigidBodyRef.current = rigidBody;
|
460
|
+
}
|
461
|
+
|
462
|
+
return rigidBodyRef.current;
|
463
|
+
}); // Setup
|
341
464
|
|
342
465
|
React.useEffect(() => {
|
343
466
|
var _ref$current$parent, _ref, _options$colliders;
|
344
467
|
|
468
|
+
const rigidBody = getRigidBodyRef.current();
|
469
|
+
rigidBodyRef.current = rigidBody;
|
470
|
+
|
345
471
|
if (!ref.current) {
|
346
472
|
ref.current = new three.Object3D();
|
347
473
|
} // Get intitial world transforms
|
@@ -373,43 +499,42 @@ const useRigidBody = options => {
|
|
373
499
|
}, false);
|
374
500
|
rigidBody.resetForces(false);
|
375
501
|
rigidBody.resetTorques(false);
|
376
|
-
const colliderSetting = (_ref = (_options$colliders = options === null || options === void 0 ? void 0 : options.colliders) !== null && _options$colliders !== void 0 ? _options$colliders : colliders) !== null && _ref !== void 0 ? _ref : false;
|
502
|
+
const colliderSetting = (_ref = (_options$colliders = options === null || options === void 0 ? void 0 : options.colliders) !== null && _options$colliders !== void 0 ? _options$colliders : physicsOptions.colliders) !== null && _ref !== void 0 ? _ref : false;
|
377
503
|
const autoColliders = colliderSetting !== false ? createCollidersFromChildren(ref.current, rigidBody, colliderSetting, world) : [];
|
504
|
+
rigidBody.wakeUp();
|
505
|
+
rigidBodyMeshes.set(rigidBody.handle, ref.current);
|
378
506
|
return () => {
|
507
|
+
autoColliders.forEach(collider => world.removeCollider(collider));
|
379
508
|
world.removeRigidBody(rigidBody);
|
380
|
-
|
509
|
+
rigidBodyRef.current = undefined;
|
510
|
+
rigidBodyMeshes.delete(rigidBody.handle);
|
381
511
|
};
|
382
512
|
}, []);
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
} = rigidBody.rotation();
|
396
|
-
const scale = ref.current.getWorldScale(new three.Vector3());
|
397
|
-
|
398
|
-
if (ref.current.parent) {
|
399
|
-
// haha matrixes I have no idea what I'm doing :)
|
400
|
-
const o = new three.Object3D();
|
401
|
-
o.position.set(x, y, z);
|
402
|
-
o.rotation.setFromQuaternion(new three.Quaternion(rx, ry, rz, rw));
|
403
|
-
o.scale.set(scale.x, scale.y, scale.z);
|
404
|
-
o.updateMatrix();
|
405
|
-
o.applyMatrix4(ref.current.parent.matrixWorld.clone().invert());
|
406
|
-
o.updateMatrix();
|
407
|
-
ref.current.position.setFromMatrixPosition(o.matrix);
|
408
|
-
ref.current.rotation.setFromRotationMatrix(o.matrix);
|
409
|
-
}
|
513
|
+
const api = React.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
514
|
+
return [ref, api];
|
515
|
+
};
|
516
|
+
const useCollider = (body, options = {}) => {
|
517
|
+
const {
|
518
|
+
world
|
519
|
+
} = useRapier();
|
520
|
+
const colliderRef = React.useRef();
|
521
|
+
const objectRef = React.useRef();
|
522
|
+
const getColliderRef = React.useRef(() => {
|
523
|
+
if (!colliderRef.current) {
|
524
|
+
colliderRef.current = createColliderFromOptions(options, world, body.handle);
|
410
525
|
}
|
526
|
+
|
527
|
+
return colliderRef.current;
|
411
528
|
});
|
412
|
-
|
529
|
+
React.useEffect(() => {
|
530
|
+
const collider = getColliderRef.current();
|
531
|
+
return () => {
|
532
|
+
if (collider) world.removeCollider(collider);
|
533
|
+
colliderRef.current = undefined;
|
534
|
+
};
|
535
|
+
}, []);
|
536
|
+
const api = React.useMemo(() => createColliderApi(getColliderRef), []);
|
537
|
+
return [objectRef, api];
|
413
538
|
};
|
414
539
|
const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
|
415
540
|
const {
|
@@ -422,9 +547,9 @@ const useRigidBodyWithCollider = (rigidBodyOptions, colliderOptions) => {
|
|
422
547
|
}
|
423
548
|
|
424
549
|
const scale = ref.current.getWorldScale(new three.Vector3());
|
425
|
-
const collider = createColliderFromOptions(colliderOptions, world, rigidBody, scale);
|
550
|
+
const collider = createColliderFromOptions(colliderOptions, world, rigidBody.handle, scale);
|
426
551
|
return () => {
|
427
|
-
world.removeCollider(collider
|
552
|
+
world.removeCollider(collider);
|
428
553
|
};
|
429
554
|
}, []);
|
430
555
|
return [ref, rigidBody];
|
@@ -550,20 +675,42 @@ const useRoundConvexMesh = (rigidBodyOptions = {}, colliderOptions = {}) => {
|
|
550
675
|
|
551
676
|
const useImpulseJoint = (body1, body2, params) => {
|
552
677
|
const {
|
553
|
-
world
|
554
|
-
RAPIER
|
678
|
+
world
|
555
679
|
} = useRapier();
|
556
|
-
React.
|
557
|
-
|
680
|
+
const jointRef = React.useRef();
|
681
|
+
const getJointRef = React.useRef(() => {
|
682
|
+
if (!jointRef.current) {
|
683
|
+
let rb1;
|
684
|
+
let rb2;
|
685
|
+
|
686
|
+
if ('handle' in body1 && 'handle' in body2) {
|
687
|
+
rb1 = world.getRigidBody(body1.handle);
|
688
|
+
rb2 = world.getRigidBody(body2.handle);
|
689
|
+
jointRef.current = world.createImpulseJoint(params, rb1, rb2);
|
690
|
+
}
|
558
691
|
|
559
|
-
|
560
|
-
|
692
|
+
if ('current' in body1 && body1.current && 'current' in body2 && body2.current) {
|
693
|
+
rb1 = world.getRigidBody(body1.current.handle);
|
694
|
+
rb2 = world.getRigidBody(body2.current.handle);
|
695
|
+
const newJoint = world.createImpulseJoint(params, rb1, rb2);
|
696
|
+
jointRef.current = newJoint;
|
697
|
+
}
|
561
698
|
}
|
562
699
|
|
700
|
+
return jointRef.current;
|
701
|
+
});
|
702
|
+
React.useEffect(() => {
|
703
|
+
const joint = getJointRef.current();
|
563
704
|
return () => {
|
564
|
-
if (joint)
|
705
|
+
if (joint) {
|
706
|
+
console.log('remove joint', joint);
|
707
|
+
world.removeImpulseJoint(joint);
|
708
|
+
jointRef.current = undefined;
|
709
|
+
}
|
565
710
|
};
|
566
|
-
}, [
|
711
|
+
}, []);
|
712
|
+
const api = React.useMemo(() => createJointApi(getJointRef), []);
|
713
|
+
return api;
|
567
714
|
};
|
568
715
|
/**
|
569
716
|
*
|
@@ -574,9 +721,9 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
574
721
|
|
575
722
|
const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor, body2LocalFrame]) => {
|
576
723
|
const {
|
577
|
-
|
724
|
+
rapier
|
578
725
|
} = useRapier();
|
579
|
-
return useImpulseJoint(body1, body2,
|
726
|
+
return useImpulseJoint(body1, body2, rapier.JointData.fixed(vectorArrayToObject(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body1LocalFrame)), {}, {
|
580
727
|
w: 1
|
581
728
|
}), vectorArrayToObject(body2Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToObject(body2LocalFrame)), {}, {
|
582
729
|
w: 1
|
@@ -591,9 +738,9 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
|
|
591
738
|
|
592
739
|
const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
593
740
|
const {
|
594
|
-
|
741
|
+
rapier
|
595
742
|
} = useRapier();
|
596
|
-
return useImpulseJoint(body1, body2,
|
743
|
+
return useImpulseJoint(body1, body2, rapier.JointData.spherical(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor)));
|
597
744
|
};
|
598
745
|
/**
|
599
746
|
* The revolute joint prevents any relative movement between two rigid-bodies, except for relative
|
@@ -603,9 +750,9 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
|
603
750
|
|
604
751
|
const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
605
752
|
const {
|
606
|
-
|
753
|
+
rapier
|
607
754
|
} = useRapier();
|
608
|
-
return useImpulseJoint(body1, body2,
|
755
|
+
return useImpulseJoint(body1, body2, rapier.JointData.revolute(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
|
609
756
|
};
|
610
757
|
/**
|
611
758
|
* The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
|
@@ -615,9 +762,9 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
615
762
|
|
616
763
|
const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
617
764
|
const {
|
618
|
-
|
765
|
+
rapier
|
619
766
|
} = useRapier();
|
620
|
-
return useImpulseJoint(body1, body2,
|
767
|
+
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(vectorArrayToObject(body1Anchor), vectorArrayToObject(body2Anchor), vectorArrayToObject(axis)));
|
621
768
|
};
|
622
769
|
|
623
770
|
function _extends() {
|
@@ -672,7 +819,8 @@ function _objectWithoutProperties(source, excluded) {
|
|
672
819
|
return target;
|
673
820
|
}
|
674
821
|
|
675
|
-
const _excluded = ["children"]
|
822
|
+
const _excluded = ["children"],
|
823
|
+
_excluded2 = ["children"];
|
676
824
|
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
677
825
|
|
678
826
|
const useParentRigidBody = () => React.useContext(RigidBodyContext); // RigidBody
|
@@ -684,28 +832,36 @@ const RigidBody = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
684
832
|
} = _ref,
|
685
833
|
props = _objectWithoutProperties(_ref, _excluded);
|
686
834
|
|
687
|
-
const [
|
835
|
+
const [object, rigidBody] = useRigidBody(props);
|
688
836
|
React.useImperativeHandle(ref, () => rigidBody);
|
689
837
|
return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
|
690
|
-
value: [
|
691
|
-
}, /*#__PURE__*/React__default["default"].createElement("
|
692
|
-
ref:
|
838
|
+
value: [object, rigidBody]
|
839
|
+
}, /*#__PURE__*/React__default["default"].createElement("object3D", {
|
840
|
+
ref: object
|
693
841
|
}, children));
|
694
842
|
}); // Colliders
|
695
843
|
|
696
|
-
const AnyCollider =
|
844
|
+
const AnyCollider = _ref2 => {
|
845
|
+
let {
|
846
|
+
children
|
847
|
+
} = _ref2,
|
848
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
849
|
+
|
697
850
|
const {
|
698
851
|
world
|
699
852
|
} = useRapier();
|
700
|
-
const [
|
853
|
+
const [, rigidBody] = useParentRigidBody();
|
854
|
+
const ref = React.useRef(null);
|
701
855
|
React.useEffect(() => {
|
702
|
-
const scale =
|
703
|
-
const collider = createColliderFromOptions(props, world, rigidBody, scale);
|
856
|
+
const scale = ref.current.getWorldScale(new three.Vector3());
|
857
|
+
const collider = createColliderFromOptions(props, world, rigidBody.handle, scale);
|
704
858
|
return () => {
|
705
|
-
world.removeCollider(collider
|
859
|
+
world.removeCollider(collider);
|
706
860
|
};
|
707
861
|
}, []);
|
708
|
-
return
|
862
|
+
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
863
|
+
ref: ref
|
864
|
+
}, children);
|
709
865
|
};
|
710
866
|
|
711
867
|
const CuboidCollider = props => {
|
@@ -854,7 +1010,7 @@ const Debug = () => {
|
|
854
1010
|
|
855
1011
|
fiber.useFrame(() => {
|
856
1012
|
const newColliders = [];
|
857
|
-
world.
|
1013
|
+
world.forEachCollider(collider => {
|
858
1014
|
newColliders.push(collider.handle);
|
859
1015
|
});
|
860
1016
|
setColliders(newColliders);
|