@react-three/rapier 0.6.7 → 0.6.8

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.
@@ -6,7 +6,6 @@ import { Matrix4, Object3D, Vector3 } from "three";
6
6
  export interface RapierContext {
7
7
  rapier: typeof Rapier;
8
8
  world: WorldApi;
9
- colliderMeshes: Map<ColliderHandle, Object3D>;
10
9
  rigidBodyStates: Map<RigidBodyHandle, {
11
10
  mesh: Object3D;
12
11
  isSleeping: boolean;
@@ -58,7 +58,7 @@ export interface RigidBodyApi {
58
58
  /**
59
59
  * Sets the rotation quaternion of this rigid-body.
60
60
  */
61
- setRotation(rotation: Vector3Object): void;
61
+ setRotation(rotation: Quaternion): void;
62
62
  /**
63
63
  * The linear velocity of this rigid-body.
64
64
  */
@@ -99,7 +99,7 @@ export interface RigidBodyApi {
99
99
  * rigid-body from its current position and its next kinematic position. This velocity will be used
100
100
  * to compute forces on dynamic bodies interacting with this body.
101
101
  */
102
- setNextKinematicRotation(rotation: Vector3Object): void;
102
+ setNextKinematicRotation(rotation: Quaternion): void;
103
103
  /**
104
104
  * If this rigid body is kinematic, sets its future rotation after the next timestep integration.
105
105
  *
@@ -122,10 +122,6 @@ const createColliderFromOptions = ({
122
122
  w: qRotation.w
123
123
  }).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : rapier3dCompat.CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : rapier3dCompat.CoefficientCombineRule.Average);
124
124
 
125
- if (colliderShape === "heightfield") {
126
- console.log(colliderDesc);
127
- }
128
-
129
125
  if (hasCollisionEvents) {
130
126
  colliderDesc = colliderDesc.setActiveEvents(rapier3dCompat.ActiveEvents.COLLISION_EVENTS);
131
127
  } // If any of the mass properties are specified, add mass properties
@@ -172,7 +168,6 @@ const createCollidersFromChildren = ({
172
168
  }) => {
173
169
  const hasCollisionEvents = !!(options.onCollisionEnter || options.onCollisionExit);
174
170
  const colliders = [];
175
- new three.Vector3();
176
171
  object.traverseVisible(child => {
177
172
  if ("isMesh" in child) {
178
173
  if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
@@ -328,12 +323,7 @@ const createRigidBodyApi = ref => {
328
323
  addTorque: torque => ref.current().addTorque(torque, true),
329
324
 
330
325
  translation() {
331
- const {
332
- x,
333
- y,
334
- z
335
- } = ref.current().translation();
336
- return new three.Vector3(x, y, z);
326
+ return rapierVector3ToVector3(ref.current().translation());
337
327
  },
338
328
 
339
329
  setTranslation: translation => ref.current().setTranslation(translation, true),
@@ -348,18 +338,8 @@ const createRigidBodyApi = ref => {
348
338
  return new three.Quaternion(x, y, z, w);
349
339
  },
350
340
 
351
- setRotation: ({
352
- x,
353
- y,
354
- z
355
- }) => {
356
- const q = vector3ToQuaternion(new three.Vector3(x, y, z));
357
- ref.current().setRotation({
358
- x: q.x,
359
- y: q.y,
360
- z: q.z,
361
- w: q.w
362
- }, true);
341
+ setRotation: rotation => {
342
+ ref.current().setRotation(rotation, true);
363
343
  },
364
344
 
365
345
  linvel() {
@@ -395,18 +375,8 @@ const createRigidBodyApi = ref => {
395
375
  },
396
376
 
397
377
  setAngularDamping: factor => ref.current().setAngularDamping(factor),
398
- setNextKinematicRotation: ({
399
- x,
400
- y,
401
- z
402
- }) => {
403
- const q = vector3ToQuaternion(new three.Vector3(x, y, z));
404
- ref.current().setNextKinematicRotation({
405
- x: q.x,
406
- y: q.y,
407
- z: q.z,
408
- w: q.w
409
- });
378
+ setNextKinematicRotation: rotation => {
379
+ ref.current().setNextKinematicRotation(rotation);
410
380
  },
411
381
  setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
412
382
  resetForces: () => ref.current().resetForces(true),
@@ -496,7 +466,6 @@ const Physics = ({
496
466
 
497
467
  return worldRef.current;
498
468
  });
499
- const [colliderMeshes] = React.useState(() => new Map());
500
469
  const [rigidBodyStates] = React.useState(() => new Map());
501
470
  const [rigidBodyEvents] = React.useState(() => new Map());
502
471
  const [eventQueue] = React.useState(() => new rapier3dCompat.EventQueue(false)); // Init world
@@ -602,7 +571,7 @@ const Physics = ({
602
571
  const rigidBodyHandle1 = (_collider1$parent = collider1.parent()) === null || _collider1$parent === void 0 ? void 0 : _collider1$parent.handle;
603
572
  const rigidBodyHandle2 = (_collider2$parent = collider2.parent()) === null || _collider2$parent === void 0 ? void 0 : _collider2$parent.handle;
604
573
 
605
- if (!collider1 || !collider2 || !rigidBodyHandle1 || !rigidBodyHandle2) {
574
+ if (!collider1 || !collider2 || rigidBodyHandle1 === undefined || rigidBodyHandle2 === undefined) {
606
575
  return;
607
576
  }
608
577
 
@@ -646,7 +615,6 @@ const Physics = ({
646
615
  colliders: _colliders,
647
616
  gravity: _gravity
648
617
  },
649
- colliderMeshes,
650
618
  rigidBodyStates,
651
619
  rigidBodyEvents,
652
620
  isPaused
@@ -122,10 +122,6 @@ const createColliderFromOptions = ({
122
122
  w: qRotation.w
123
123
  }).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : rapier3dCompat.CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : rapier3dCompat.CoefficientCombineRule.Average);
124
124
 
125
- if (colliderShape === "heightfield") {
126
- console.log(colliderDesc);
127
- }
128
-
129
125
  if (hasCollisionEvents) {
130
126
  colliderDesc = colliderDesc.setActiveEvents(rapier3dCompat.ActiveEvents.COLLISION_EVENTS);
131
127
  } // If any of the mass properties are specified, add mass properties
@@ -172,7 +168,6 @@ const createCollidersFromChildren = ({
172
168
  }) => {
173
169
  const hasCollisionEvents = !!(options.onCollisionEnter || options.onCollisionExit);
174
170
  const colliders = [];
175
- new three.Vector3();
176
171
  object.traverseVisible(child => {
177
172
  if ("isMesh" in child) {
178
173
  if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
@@ -328,12 +323,7 @@ const createRigidBodyApi = ref => {
328
323
  addTorque: torque => ref.current().addTorque(torque, true),
329
324
 
330
325
  translation() {
331
- const {
332
- x,
333
- y,
334
- z
335
- } = ref.current().translation();
336
- return new three.Vector3(x, y, z);
326
+ return rapierVector3ToVector3(ref.current().translation());
337
327
  },
338
328
 
339
329
  setTranslation: translation => ref.current().setTranslation(translation, true),
@@ -348,18 +338,8 @@ const createRigidBodyApi = ref => {
348
338
  return new three.Quaternion(x, y, z, w);
349
339
  },
350
340
 
351
- setRotation: ({
352
- x,
353
- y,
354
- z
355
- }) => {
356
- const q = vector3ToQuaternion(new three.Vector3(x, y, z));
357
- ref.current().setRotation({
358
- x: q.x,
359
- y: q.y,
360
- z: q.z,
361
- w: q.w
362
- }, true);
341
+ setRotation: rotation => {
342
+ ref.current().setRotation(rotation, true);
363
343
  },
364
344
 
365
345
  linvel() {
@@ -395,18 +375,8 @@ const createRigidBodyApi = ref => {
395
375
  },
396
376
 
397
377
  setAngularDamping: factor => ref.current().setAngularDamping(factor),
398
- setNextKinematicRotation: ({
399
- x,
400
- y,
401
- z
402
- }) => {
403
- const q = vector3ToQuaternion(new three.Vector3(x, y, z));
404
- ref.current().setNextKinematicRotation({
405
- x: q.x,
406
- y: q.y,
407
- z: q.z,
408
- w: q.w
409
- });
378
+ setNextKinematicRotation: rotation => {
379
+ ref.current().setNextKinematicRotation(rotation);
410
380
  },
411
381
  setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
412
382
  resetForces: () => ref.current().resetForces(true),
@@ -496,7 +466,6 @@ const Physics = ({
496
466
 
497
467
  return worldRef.current;
498
468
  });
499
- const [colliderMeshes] = React.useState(() => new Map());
500
469
  const [rigidBodyStates] = React.useState(() => new Map());
501
470
  const [rigidBodyEvents] = React.useState(() => new Map());
502
471
  const [eventQueue] = React.useState(() => new rapier3dCompat.EventQueue(false)); // Init world
@@ -602,7 +571,7 @@ const Physics = ({
602
571
  const rigidBodyHandle1 = (_collider1$parent = collider1.parent()) === null || _collider1$parent === void 0 ? void 0 : _collider1$parent.handle;
603
572
  const rigidBodyHandle2 = (_collider2$parent = collider2.parent()) === null || _collider2$parent === void 0 ? void 0 : _collider2$parent.handle;
604
573
 
605
- if (!collider1 || !collider2 || !rigidBodyHandle1 || !rigidBodyHandle2) {
574
+ if (!collider1 || !collider2 || rigidBodyHandle1 === undefined || rigidBodyHandle2 === undefined) {
606
575
  return;
607
576
  }
608
577
 
@@ -646,7 +615,6 @@ const Physics = ({
646
615
  colliders: _colliders,
647
616
  gravity: _gravity
648
617
  },
649
- colliderMeshes,
650
618
  rigidBodyStates,
651
619
  rigidBodyEvents,
652
620
  isPaused
@@ -97,10 +97,6 @@ const createColliderFromOptions = ({
97
97
  w: qRotation.w
98
98
  }).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : CoefficientCombineRule.Average);
99
99
 
100
- if (colliderShape === "heightfield") {
101
- console.log(colliderDesc);
102
- }
103
-
104
100
  if (hasCollisionEvents) {
105
101
  colliderDesc = colliderDesc.setActiveEvents(ActiveEvents.COLLISION_EVENTS);
106
102
  } // If any of the mass properties are specified, add mass properties
@@ -147,7 +143,6 @@ const createCollidersFromChildren = ({
147
143
  }) => {
148
144
  const hasCollisionEvents = !!(options.onCollisionEnter || options.onCollisionExit);
149
145
  const colliders = [];
150
- new Vector3();
151
146
  object.traverseVisible(child => {
152
147
  if ("isMesh" in child) {
153
148
  if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
@@ -303,12 +298,7 @@ const createRigidBodyApi = ref => {
303
298
  addTorque: torque => ref.current().addTorque(torque, true),
304
299
 
305
300
  translation() {
306
- const {
307
- x,
308
- y,
309
- z
310
- } = ref.current().translation();
311
- return new Vector3(x, y, z);
301
+ return rapierVector3ToVector3(ref.current().translation());
312
302
  },
313
303
 
314
304
  setTranslation: translation => ref.current().setTranslation(translation, true),
@@ -323,18 +313,8 @@ const createRigidBodyApi = ref => {
323
313
  return new Quaternion(x, y, z, w);
324
314
  },
325
315
 
326
- setRotation: ({
327
- x,
328
- y,
329
- z
330
- }) => {
331
- const q = vector3ToQuaternion(new Vector3(x, y, z));
332
- ref.current().setRotation({
333
- x: q.x,
334
- y: q.y,
335
- z: q.z,
336
- w: q.w
337
- }, true);
316
+ setRotation: rotation => {
317
+ ref.current().setRotation(rotation, true);
338
318
  },
339
319
 
340
320
  linvel() {
@@ -370,18 +350,8 @@ const createRigidBodyApi = ref => {
370
350
  },
371
351
 
372
352
  setAngularDamping: factor => ref.current().setAngularDamping(factor),
373
- setNextKinematicRotation: ({
374
- x,
375
- y,
376
- z
377
- }) => {
378
- const q = vector3ToQuaternion(new Vector3(x, y, z));
379
- ref.current().setNextKinematicRotation({
380
- x: q.x,
381
- y: q.y,
382
- z: q.z,
383
- w: q.w
384
- });
353
+ setNextKinematicRotation: rotation => {
354
+ ref.current().setNextKinematicRotation(rotation);
385
355
  },
386
356
  setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
387
357
  resetForces: () => ref.current().resetForces(true),
@@ -471,7 +441,6 @@ const Physics = ({
471
441
 
472
442
  return worldRef.current;
473
443
  });
474
- const [colliderMeshes] = useState(() => new Map());
475
444
  const [rigidBodyStates] = useState(() => new Map());
476
445
  const [rigidBodyEvents] = useState(() => new Map());
477
446
  const [eventQueue] = useState(() => new EventQueue(false)); // Init world
@@ -577,7 +546,7 @@ const Physics = ({
577
546
  const rigidBodyHandle1 = (_collider1$parent = collider1.parent()) === null || _collider1$parent === void 0 ? void 0 : _collider1$parent.handle;
578
547
  const rigidBodyHandle2 = (_collider2$parent = collider2.parent()) === null || _collider2$parent === void 0 ? void 0 : _collider2$parent.handle;
579
548
 
580
- if (!collider1 || !collider2 || !rigidBodyHandle1 || !rigidBodyHandle2) {
549
+ if (!collider1 || !collider2 || rigidBodyHandle1 === undefined || rigidBodyHandle2 === undefined) {
581
550
  return;
582
551
  }
583
552
 
@@ -621,7 +590,6 @@ const Physics = ({
621
590
  colliders: _colliders,
622
591
  gravity: _gravity
623
592
  },
624
- colliderMeshes,
625
593
  rigidBodyStates,
626
594
  rigidBodyEvents,
627
595
  isPaused
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/rapier",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/react-three-rapier.cjs.js",
6
6
  "module": "dist/react-three-rapier.esm.js",