@react-three/rapier 0.6.1 → 0.6.2
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/InstancedRigidBodies.d.ts +1 -0
- package/dist/declarations/src/Physics.d.ts +2 -1
- package/dist/declarations/src/utils.d.ts +1 -5
- package/dist/react-three-rapier.cjs.dev.js +31 -20
- package/dist/react-three-rapier.cjs.prod.js +31 -20
- package/dist/react-three-rapier.esm.js +31 -20
- package/package.json +1 -1
- package/readme.md +10 -2
@@ -5,6 +5,7 @@ import { Vector3Array } from "./types";
|
|
5
5
|
interface InstancedRigidBodiesProps extends Omit<RigidBodyProps, "position" | "rotation" | "onCollisionEnter" | "onCollisionExit"> {
|
6
6
|
positions?: Vector3Array[];
|
7
7
|
rotations?: Vector3Array[];
|
8
|
+
scales?: Vector3Array[];
|
8
9
|
}
|
9
10
|
export declare const InstancedRigidBodies: React.ForwardRefExoticComponent<InstancedRigidBodiesProps & React.RefAttributes<InstancedRigidBodyApi>>;
|
10
11
|
export {};
|
@@ -10,7 +10,8 @@ export interface RapierContext {
|
|
10
10
|
rigidBodyStates: Map<RigidBodyHandle, {
|
11
11
|
mesh: Object3D;
|
12
12
|
isSleeping: boolean;
|
13
|
-
setMatrix
|
13
|
+
setMatrix(mat: Matrix4): void;
|
14
|
+
getMatrix(): Matrix4;
|
14
15
|
worldScale: Vector3;
|
15
16
|
invertedMatrixWorld: Matrix4;
|
16
17
|
}>;
|
@@ -1,11 +1,7 @@
|
|
1
1
|
import { Collider, ColliderDesc, RigidBody, RigidBodyDesc, Vector3 as RapierVector3, Quaternion as RapierQuaternion } from "@dimforge/rapier3d-compat";
|
2
2
|
import { BufferGeometry, Matrix4, Object3D, Quaternion, Vector3 } from "three";
|
3
3
|
import { RigidBodyApi, RigidBodyAutoCollider, RigidBodyShape, RigidBodyTypeString, UseColliderOptions, UseRigidBodyOptions, Vector3Array, WorldApi } from "./types";
|
4
|
-
export declare const
|
5
|
-
x: number;
|
6
|
-
y: number;
|
7
|
-
z: number;
|
8
|
-
};
|
4
|
+
export declare const vectorArrayToVector3: (arr: Vector3Array) => Vector3;
|
9
5
|
export declare const vector3ToQuaternion: (v: Vector3) => Quaternion;
|
10
6
|
export declare const rapierVector3ToVector3: ({ x, y, z }: RapierVector3) => Vector3;
|
11
7
|
export declare const rapierQuaternionToQuaternion: ({ x, y, z, w, }: RapierQuaternion) => Quaternion;
|
@@ -36,13 +36,9 @@ const _vector3 = new three.Vector3();
|
|
36
36
|
new three.Object3D();
|
37
37
|
const _matrix4 = new three.Matrix4();
|
38
38
|
|
39
|
-
const
|
39
|
+
const vectorArrayToVector3 = arr => {
|
40
40
|
const [x, y, z] = arr;
|
41
|
-
return
|
42
|
-
x,
|
43
|
-
y,
|
44
|
-
z
|
45
|
-
};
|
41
|
+
return new three.Vector3(x, y, z);
|
46
42
|
};
|
47
43
|
const vector3ToQuaternion = v => {
|
48
44
|
return _quaternion.setFromEuler(_euler.setFromVector3(v));
|
@@ -459,7 +455,7 @@ const Physics = ({
|
|
459
455
|
const worldRef = React.useRef();
|
460
456
|
const getWorldRef = React.useRef(() => {
|
461
457
|
if (!worldRef.current) {
|
462
|
-
const world = new rapier.World(
|
458
|
+
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
463
459
|
worldRef.current = world;
|
464
460
|
}
|
465
461
|
|
@@ -484,7 +480,7 @@ const Physics = ({
|
|
484
480
|
const world = worldRef.current;
|
485
481
|
|
486
482
|
if (world) {
|
487
|
-
world.gravity =
|
483
|
+
world.gravity = vectorArrayToVector3(_gravity);
|
488
484
|
}
|
489
485
|
}, [_gravity]);
|
490
486
|
const time = React.useRef(performance.now());
|
@@ -742,7 +738,8 @@ const useRigidBody = (options = {}) => {
|
|
742
738
|
invertedMatrixWorld: ref.current.parent.matrixWorld.clone().invert(),
|
743
739
|
isSleeping: false,
|
744
740
|
worldScale: ref.current.getWorldScale(_vector3).clone(),
|
745
|
-
setMatrix: mat => ref.current.matrix.copy(mat)
|
741
|
+
setMatrix: mat => ref.current.matrix.copy(mat),
|
742
|
+
getMatrix: () => ref.current.matrix
|
746
743
|
});
|
747
744
|
ref.current.matrixAutoUpdate = false;
|
748
745
|
return () => {
|
@@ -812,9 +809,9 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
|
|
812
809
|
const {
|
813
810
|
rapier
|
814
811
|
} = useRapier();
|
815
|
-
return useImpulseJoint(body1, body2, rapier.JointData.fixed(
|
812
|
+
return useImpulseJoint(body1, body2, rapier.JointData.fixed(vectorArrayToVector3(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToVector3(body1LocalFrame)), {}, {
|
816
813
|
w: 1
|
817
|
-
}),
|
814
|
+
}), vectorArrayToVector3(body2Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToVector3(body2LocalFrame)), {}, {
|
818
815
|
w: 1
|
819
816
|
})));
|
820
817
|
};
|
@@ -829,7 +826,7 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
|
829
826
|
const {
|
830
827
|
rapier
|
831
828
|
} = useRapier();
|
832
|
-
return useImpulseJoint(body1, body2, rapier.JointData.spherical(
|
829
|
+
return useImpulseJoint(body1, body2, rapier.JointData.spherical(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor)));
|
833
830
|
};
|
834
831
|
/**
|
835
832
|
* The revolute joint prevents any relative movement between two rigid-bodies, except for relative
|
@@ -841,7 +838,7 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
841
838
|
const {
|
842
839
|
rapier
|
843
840
|
} = useRapier();
|
844
|
-
return useImpulseJoint(body1, body2, rapier.JointData.revolute(
|
841
|
+
return useImpulseJoint(body1, body2, rapier.JointData.revolute(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor), vectorArrayToVector3(axis)));
|
845
842
|
};
|
846
843
|
/**
|
847
844
|
* The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
|
@@ -853,7 +850,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
853
850
|
const {
|
854
851
|
rapier
|
855
852
|
} = useRapier();
|
856
|
-
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(
|
853
|
+
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor), vectorArrayToVector3(axis)));
|
857
854
|
};
|
858
855
|
|
859
856
|
const _excluded$1 = ["children"];
|
@@ -1054,7 +1051,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1054
1051
|
const rigidBodies = instancesRefGetter.current();
|
1055
1052
|
|
1056
1053
|
if (object.current) {
|
1057
|
-
const
|
1054
|
+
const worldScale = object.current.getWorldScale(new three.Vector3());
|
1058
1055
|
let hasOneMesh = false;
|
1059
1056
|
object.current.traverse(mesh => {
|
1060
1057
|
if (mesh instanceof three.InstancedMesh) {
|
@@ -1065,11 +1062,18 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1065
1062
|
|
1066
1063
|
hasOneMesh = true;
|
1067
1064
|
mesh.instanceMatrix.setUsage(three.DynamicDrawUsage);
|
1068
|
-
const rigidBodyDesc = rigidBodyDescFromOptions(props);
|
1069
|
-
const colliderDesc = colliderDescFromGeometry(mesh.geometry, props.colliders || physicsOptions.colliders, scale, false // Collisions currently not enabled for instances
|
1070
|
-
);
|
1071
1065
|
|
1072
1066
|
for (let index = 0; index < mesh.count; index++) {
|
1067
|
+
const scale = worldScale.clone();
|
1068
|
+
const rigidBodyDesc = rigidBodyDescFromOptions(props);
|
1069
|
+
|
1070
|
+
if (props.scales && props.scales[index]) {
|
1071
|
+
const s = vectorArrayToVector3(props.scales[index]);
|
1072
|
+
scale.multiply(s);
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
const colliderDesc = colliderDescFromGeometry(mesh.geometry, props.colliders || physicsOptions.colliders, scale, false // Collisions currently not enabled for instances
|
1076
|
+
);
|
1073
1077
|
const rigidBody = world.createRigidBody(rigidBodyDesc);
|
1074
1078
|
const matrix = new three.Matrix4();
|
1075
1079
|
mesh.getMatrixAt(index, matrix);
|
@@ -1079,7 +1083,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1079
1083
|
} = decomposeMatrix4(matrix); // Set positions
|
1080
1084
|
|
1081
1085
|
if (props.positions && props.positions[index]) {
|
1082
|
-
rigidBody.setTranslation(
|
1086
|
+
rigidBody.setTranslation(vectorArrayToVector3(props.positions[index]), true);
|
1083
1087
|
} else {
|
1084
1088
|
rigidBody.setTranslation(position, true);
|
1085
1089
|
} // Set rotations
|
@@ -1098,7 +1102,14 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1098
1102
|
isSleeping: false,
|
1099
1103
|
invertedMatrixWorld: object.current.matrixWorld.clone().invert(),
|
1100
1104
|
setMatrix: matrix => mesh.setMatrixAt(index, matrix),
|
1101
|
-
|
1105
|
+
getMatrix: () => {
|
1106
|
+
const m = new three.Matrix4();
|
1107
|
+
mesh.getMatrixAt(index, m);
|
1108
|
+
return m;
|
1109
|
+
},
|
1110
|
+
// Setting the world scale to the scale here, because
|
1111
|
+
// we want the scales to be reflected by instance
|
1112
|
+
worldScale: scale
|
1102
1113
|
});
|
1103
1114
|
const api = createRigidBodyApi({
|
1104
1115
|
current() {
|
@@ -36,13 +36,9 @@ const _vector3 = new three.Vector3();
|
|
36
36
|
new three.Object3D();
|
37
37
|
const _matrix4 = new three.Matrix4();
|
38
38
|
|
39
|
-
const
|
39
|
+
const vectorArrayToVector3 = arr => {
|
40
40
|
const [x, y, z] = arr;
|
41
|
-
return
|
42
|
-
x,
|
43
|
-
y,
|
44
|
-
z
|
45
|
-
};
|
41
|
+
return new three.Vector3(x, y, z);
|
46
42
|
};
|
47
43
|
const vector3ToQuaternion = v => {
|
48
44
|
return _quaternion.setFromEuler(_euler.setFromVector3(v));
|
@@ -459,7 +455,7 @@ const Physics = ({
|
|
459
455
|
const worldRef = React.useRef();
|
460
456
|
const getWorldRef = React.useRef(() => {
|
461
457
|
if (!worldRef.current) {
|
462
|
-
const world = new rapier.World(
|
458
|
+
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
463
459
|
worldRef.current = world;
|
464
460
|
}
|
465
461
|
|
@@ -484,7 +480,7 @@ const Physics = ({
|
|
484
480
|
const world = worldRef.current;
|
485
481
|
|
486
482
|
if (world) {
|
487
|
-
world.gravity =
|
483
|
+
world.gravity = vectorArrayToVector3(_gravity);
|
488
484
|
}
|
489
485
|
}, [_gravity]);
|
490
486
|
const time = React.useRef(performance.now());
|
@@ -742,7 +738,8 @@ const useRigidBody = (options = {}) => {
|
|
742
738
|
invertedMatrixWorld: ref.current.parent.matrixWorld.clone().invert(),
|
743
739
|
isSleeping: false,
|
744
740
|
worldScale: ref.current.getWorldScale(_vector3).clone(),
|
745
|
-
setMatrix: mat => ref.current.matrix.copy(mat)
|
741
|
+
setMatrix: mat => ref.current.matrix.copy(mat),
|
742
|
+
getMatrix: () => ref.current.matrix
|
746
743
|
});
|
747
744
|
ref.current.matrixAutoUpdate = false;
|
748
745
|
return () => {
|
@@ -812,9 +809,9 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
|
|
812
809
|
const {
|
813
810
|
rapier
|
814
811
|
} = useRapier();
|
815
|
-
return useImpulseJoint(body1, body2, rapier.JointData.fixed(
|
812
|
+
return useImpulseJoint(body1, body2, rapier.JointData.fixed(vectorArrayToVector3(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToVector3(body1LocalFrame)), {}, {
|
816
813
|
w: 1
|
817
|
-
}),
|
814
|
+
}), vectorArrayToVector3(body2Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToVector3(body2LocalFrame)), {}, {
|
818
815
|
w: 1
|
819
816
|
})));
|
820
817
|
};
|
@@ -829,7 +826,7 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
|
829
826
|
const {
|
830
827
|
rapier
|
831
828
|
} = useRapier();
|
832
|
-
return useImpulseJoint(body1, body2, rapier.JointData.spherical(
|
829
|
+
return useImpulseJoint(body1, body2, rapier.JointData.spherical(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor)));
|
833
830
|
};
|
834
831
|
/**
|
835
832
|
* The revolute joint prevents any relative movement between two rigid-bodies, except for relative
|
@@ -841,7 +838,7 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
841
838
|
const {
|
842
839
|
rapier
|
843
840
|
} = useRapier();
|
844
|
-
return useImpulseJoint(body1, body2, rapier.JointData.revolute(
|
841
|
+
return useImpulseJoint(body1, body2, rapier.JointData.revolute(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor), vectorArrayToVector3(axis)));
|
845
842
|
};
|
846
843
|
/**
|
847
844
|
* The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
|
@@ -853,7 +850,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
853
850
|
const {
|
854
851
|
rapier
|
855
852
|
} = useRapier();
|
856
|
-
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(
|
853
|
+
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor), vectorArrayToVector3(axis)));
|
857
854
|
};
|
858
855
|
|
859
856
|
const _excluded$1 = ["children"];
|
@@ -1054,7 +1051,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1054
1051
|
const rigidBodies = instancesRefGetter.current();
|
1055
1052
|
|
1056
1053
|
if (object.current) {
|
1057
|
-
const
|
1054
|
+
const worldScale = object.current.getWorldScale(new three.Vector3());
|
1058
1055
|
let hasOneMesh = false;
|
1059
1056
|
object.current.traverse(mesh => {
|
1060
1057
|
if (mesh instanceof three.InstancedMesh) {
|
@@ -1065,11 +1062,18 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1065
1062
|
|
1066
1063
|
hasOneMesh = true;
|
1067
1064
|
mesh.instanceMatrix.setUsage(three.DynamicDrawUsage);
|
1068
|
-
const rigidBodyDesc = rigidBodyDescFromOptions(props);
|
1069
|
-
const colliderDesc = colliderDescFromGeometry(mesh.geometry, props.colliders || physicsOptions.colliders, scale, false // Collisions currently not enabled for instances
|
1070
|
-
);
|
1071
1065
|
|
1072
1066
|
for (let index = 0; index < mesh.count; index++) {
|
1067
|
+
const scale = worldScale.clone();
|
1068
|
+
const rigidBodyDesc = rigidBodyDescFromOptions(props);
|
1069
|
+
|
1070
|
+
if (props.scales && props.scales[index]) {
|
1071
|
+
const s = vectorArrayToVector3(props.scales[index]);
|
1072
|
+
scale.multiply(s);
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
const colliderDesc = colliderDescFromGeometry(mesh.geometry, props.colliders || physicsOptions.colliders, scale, false // Collisions currently not enabled for instances
|
1076
|
+
);
|
1073
1077
|
const rigidBody = world.createRigidBody(rigidBodyDesc);
|
1074
1078
|
const matrix = new three.Matrix4();
|
1075
1079
|
mesh.getMatrixAt(index, matrix);
|
@@ -1079,7 +1083,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1079
1083
|
} = decomposeMatrix4(matrix); // Set positions
|
1080
1084
|
|
1081
1085
|
if (props.positions && props.positions[index]) {
|
1082
|
-
rigidBody.setTranslation(
|
1086
|
+
rigidBody.setTranslation(vectorArrayToVector3(props.positions[index]), true);
|
1083
1087
|
} else {
|
1084
1088
|
rigidBody.setTranslation(position, true);
|
1085
1089
|
} // Set rotations
|
@@ -1098,7 +1102,14 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1098
1102
|
isSleeping: false,
|
1099
1103
|
invertedMatrixWorld: object.current.matrixWorld.clone().invert(),
|
1100
1104
|
setMatrix: matrix => mesh.setMatrixAt(index, matrix),
|
1101
|
-
|
1105
|
+
getMatrix: () => {
|
1106
|
+
const m = new three.Matrix4();
|
1107
|
+
mesh.getMatrixAt(index, m);
|
1108
|
+
return m;
|
1109
|
+
},
|
1110
|
+
// Setting the world scale to the scale here, because
|
1111
|
+
// we want the scales to be reflected by instance
|
1112
|
+
worldScale: scale
|
1102
1113
|
});
|
1103
1114
|
const api = createRigidBodyApi({
|
1104
1115
|
current() {
|
@@ -11,13 +11,9 @@ const _vector3 = new Vector3();
|
|
11
11
|
new Object3D();
|
12
12
|
const _matrix4 = new Matrix4();
|
13
13
|
|
14
|
-
const
|
14
|
+
const vectorArrayToVector3 = arr => {
|
15
15
|
const [x, y, z] = arr;
|
16
|
-
return
|
17
|
-
x,
|
18
|
-
y,
|
19
|
-
z
|
20
|
-
};
|
16
|
+
return new Vector3(x, y, z);
|
21
17
|
};
|
22
18
|
const vector3ToQuaternion = v => {
|
23
19
|
return _quaternion.setFromEuler(_euler.setFromVector3(v));
|
@@ -434,7 +430,7 @@ const Physics = ({
|
|
434
430
|
const worldRef = useRef();
|
435
431
|
const getWorldRef = useRef(() => {
|
436
432
|
if (!worldRef.current) {
|
437
|
-
const world = new rapier.World(
|
433
|
+
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
438
434
|
worldRef.current = world;
|
439
435
|
}
|
440
436
|
|
@@ -459,7 +455,7 @@ const Physics = ({
|
|
459
455
|
const world = worldRef.current;
|
460
456
|
|
461
457
|
if (world) {
|
462
|
-
world.gravity =
|
458
|
+
world.gravity = vectorArrayToVector3(_gravity);
|
463
459
|
}
|
464
460
|
}, [_gravity]);
|
465
461
|
const time = useRef(performance.now());
|
@@ -717,7 +713,8 @@ const useRigidBody = (options = {}) => {
|
|
717
713
|
invertedMatrixWorld: ref.current.parent.matrixWorld.clone().invert(),
|
718
714
|
isSleeping: false,
|
719
715
|
worldScale: ref.current.getWorldScale(_vector3).clone(),
|
720
|
-
setMatrix: mat => ref.current.matrix.copy(mat)
|
716
|
+
setMatrix: mat => ref.current.matrix.copy(mat),
|
717
|
+
getMatrix: () => ref.current.matrix
|
721
718
|
});
|
722
719
|
ref.current.matrixAutoUpdate = false;
|
723
720
|
return () => {
|
@@ -787,9 +784,9 @@ const useFixedJoint = (body1, body2, [body1Anchor, body1LocalFrame, body2Anchor,
|
|
787
784
|
const {
|
788
785
|
rapier
|
789
786
|
} = useRapier();
|
790
|
-
return useImpulseJoint(body1, body2, rapier.JointData.fixed(
|
787
|
+
return useImpulseJoint(body1, body2, rapier.JointData.fixed(vectorArrayToVector3(body1Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToVector3(body1LocalFrame)), {}, {
|
791
788
|
w: 1
|
792
|
-
}),
|
789
|
+
}), vectorArrayToVector3(body2Anchor), _objectSpread2(_objectSpread2({}, vectorArrayToVector3(body2LocalFrame)), {}, {
|
793
790
|
w: 1
|
794
791
|
})));
|
795
792
|
};
|
@@ -804,7 +801,7 @@ const useSphericalJoint = (body1, body2, [body1Anchor, body2Anchor]) => {
|
|
804
801
|
const {
|
805
802
|
rapier
|
806
803
|
} = useRapier();
|
807
|
-
return useImpulseJoint(body1, body2, rapier.JointData.spherical(
|
804
|
+
return useImpulseJoint(body1, body2, rapier.JointData.spherical(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor)));
|
808
805
|
};
|
809
806
|
/**
|
810
807
|
* The revolute joint prevents any relative movement between two rigid-bodies, except for relative
|
@@ -816,7 +813,7 @@ const useRevoluteJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
816
813
|
const {
|
817
814
|
rapier
|
818
815
|
} = useRapier();
|
819
|
-
return useImpulseJoint(body1, body2, rapier.JointData.revolute(
|
816
|
+
return useImpulseJoint(body1, body2, rapier.JointData.revolute(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor), vectorArrayToVector3(axis)));
|
820
817
|
};
|
821
818
|
/**
|
822
819
|
* The prismatic joint prevents any relative movement between two rigid-bodies, except for relative translations along one axis.
|
@@ -828,7 +825,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
828
825
|
const {
|
829
826
|
rapier
|
830
827
|
} = useRapier();
|
831
|
-
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(
|
828
|
+
return useImpulseJoint(body1, body2, rapier.JointData.prismatic(vectorArrayToVector3(body1Anchor), vectorArrayToVector3(body2Anchor), vectorArrayToVector3(axis)));
|
832
829
|
};
|
833
830
|
|
834
831
|
const _excluded$1 = ["children"];
|
@@ -1029,7 +1026,7 @@ const InstancedRigidBodies = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1029
1026
|
const rigidBodies = instancesRefGetter.current();
|
1030
1027
|
|
1031
1028
|
if (object.current) {
|
1032
|
-
const
|
1029
|
+
const worldScale = object.current.getWorldScale(new Vector3());
|
1033
1030
|
let hasOneMesh = false;
|
1034
1031
|
object.current.traverse(mesh => {
|
1035
1032
|
if (mesh instanceof InstancedMesh) {
|
@@ -1040,11 +1037,18 @@ const InstancedRigidBodies = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1040
1037
|
|
1041
1038
|
hasOneMesh = true;
|
1042
1039
|
mesh.instanceMatrix.setUsage(DynamicDrawUsage);
|
1043
|
-
const rigidBodyDesc = rigidBodyDescFromOptions(props);
|
1044
|
-
const colliderDesc = colliderDescFromGeometry(mesh.geometry, props.colliders || physicsOptions.colliders, scale, false // Collisions currently not enabled for instances
|
1045
|
-
);
|
1046
1040
|
|
1047
1041
|
for (let index = 0; index < mesh.count; index++) {
|
1042
|
+
const scale = worldScale.clone();
|
1043
|
+
const rigidBodyDesc = rigidBodyDescFromOptions(props);
|
1044
|
+
|
1045
|
+
if (props.scales && props.scales[index]) {
|
1046
|
+
const s = vectorArrayToVector3(props.scales[index]);
|
1047
|
+
scale.multiply(s);
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
const colliderDesc = colliderDescFromGeometry(mesh.geometry, props.colliders || physicsOptions.colliders, scale, false // Collisions currently not enabled for instances
|
1051
|
+
);
|
1048
1052
|
const rigidBody = world.createRigidBody(rigidBodyDesc);
|
1049
1053
|
const matrix = new Matrix4();
|
1050
1054
|
mesh.getMatrixAt(index, matrix);
|
@@ -1054,7 +1058,7 @@ const InstancedRigidBodies = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1054
1058
|
} = decomposeMatrix4(matrix); // Set positions
|
1055
1059
|
|
1056
1060
|
if (props.positions && props.positions[index]) {
|
1057
|
-
rigidBody.setTranslation(
|
1061
|
+
rigidBody.setTranslation(vectorArrayToVector3(props.positions[index]), true);
|
1058
1062
|
} else {
|
1059
1063
|
rigidBody.setTranslation(position, true);
|
1060
1064
|
} // Set rotations
|
@@ -1073,7 +1077,14 @@ const InstancedRigidBodies = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1073
1077
|
isSleeping: false,
|
1074
1078
|
invertedMatrixWorld: object.current.matrixWorld.clone().invert(),
|
1075
1079
|
setMatrix: matrix => mesh.setMatrixAt(index, matrix),
|
1076
|
-
|
1080
|
+
getMatrix: () => {
|
1081
|
+
const m = new Matrix4();
|
1082
|
+
mesh.getMatrixAt(index, m);
|
1083
|
+
return m;
|
1084
|
+
},
|
1085
|
+
// Setting the world scale to the scale here, because
|
1086
|
+
// we want the scales to be reflected by instance
|
1087
|
+
worldScale: scale
|
1077
1088
|
});
|
1078
1089
|
const api = createRigidBodyApi({
|
1079
1090
|
current() {
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<p align="center">
|
2
|
-
<img src="misc/hero.svg" />
|
2
|
+
<img src="https://raw.githubusercontent.com/pmndrs/react-three-rapier/HEAD/packages/react-three-rapier/misc/hero.svg" alt="@react-three/rapier" />
|
3
3
|
</p>
|
4
4
|
|
5
5
|
<p align="center">⚠️ Under heavy development. All APIs are subject to change. ⚠️</p>
|
@@ -139,7 +139,8 @@ const Scene = () => {
|
|
139
139
|
});
|
140
140
|
}, []);
|
141
141
|
|
142
|
-
// We can set the initial positions, and rotations,
|
142
|
+
// We can set the initial positions, and rotations, and scales, of
|
143
|
+
// the instances by providing an array equal to the instance count
|
143
144
|
const positions = Array.from({ length: COUNT }, (_, index) => [index, 0, 0]);
|
144
145
|
|
145
146
|
const rotations = Array.from({ length: COUNT }, (_, index) => [
|
@@ -148,11 +149,18 @@ const Scene = () => {
|
|
148
149
|
Math.random(),
|
149
150
|
]);
|
150
151
|
|
152
|
+
const scales = Array.from({ length: COUNT }, (_, index) => [
|
153
|
+
Math.random(),
|
154
|
+
Math.random(),
|
155
|
+
Math.random(),
|
156
|
+
]);
|
157
|
+
|
151
158
|
return (
|
152
159
|
<InstancedRigidBodies
|
153
160
|
ref={instancedApi}
|
154
161
|
positions={positions}
|
155
162
|
rotations={rotations}
|
163
|
+
scales={scales}
|
156
164
|
colliders="ball"
|
157
165
|
>
|
158
166
|
<instancedMesh args={[undefined, undefined, COUNT]}>
|