@react-three/rapier 0.7.3 → 0.7.5
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/AnyCollider.d.ts +38 -10
- package/dist/declarations/src/api.d.ts +19 -19
- package/dist/declarations/src/types.d.ts +23 -12
- package/dist/react-three-rapier.cjs.dev.js +134 -73
- package/dist/react-three-rapier.cjs.prod.js +134 -73
- package/dist/react-three-rapier.esm.js +135 -74
- package/package.json +9 -4
- package/readme.md +3 -1
@@ -84,24 +84,24 @@ const createRigidBodyApi = ref => {
|
|
84
84
|
|
85
85
|
mass: () => ref.current().mass(),
|
86
86
|
|
87
|
-
applyImpulse(impulseVector) {
|
88
|
-
ref.current().applyImpulse(impulseVector,
|
87
|
+
applyImpulse(impulseVector, wakeUp = true) {
|
88
|
+
ref.current().applyImpulse(impulseVector, wakeUp);
|
89
89
|
},
|
90
90
|
|
91
|
-
applyTorqueImpulse(torqueVector) {
|
92
|
-
ref.current().applyTorqueImpulse(torqueVector,
|
91
|
+
applyTorqueImpulse(torqueVector, wakeUp = true) {
|
92
|
+
ref.current().applyTorqueImpulse(torqueVector, wakeUp);
|
93
93
|
},
|
94
94
|
|
95
|
-
applyImpulseAtPoint: (impulseVector, impulsePoint) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint,
|
96
|
-
addForce: force => ref.current().addForce(force,
|
97
|
-
addForceAtPoint: (force, point) => ref.current().addForceAtPoint(force, point,
|
98
|
-
addTorque: torque => ref.current().addTorque(torque,
|
95
|
+
applyImpulseAtPoint: (impulseVector, impulsePoint, wakeUp = true) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint, wakeUp),
|
96
|
+
addForce: (force, wakeUp = true) => ref.current().addForce(force, wakeUp),
|
97
|
+
addForceAtPoint: (force, point, wakeUp = true) => ref.current().addForceAtPoint(force, point, wakeUp),
|
98
|
+
addTorque: (torque, wakeUp = true) => ref.current().addTorque(torque, wakeUp),
|
99
99
|
|
100
100
|
translation() {
|
101
101
|
return rapierVector3ToVector3(ref.current().translation());
|
102
102
|
},
|
103
103
|
|
104
|
-
setTranslation: translation => ref.current().setTranslation(translation,
|
104
|
+
setTranslation: (translation, wakeUp = true) => ref.current().setTranslation(translation, wakeUp),
|
105
105
|
|
106
106
|
rotation() {
|
107
107
|
const {
|
@@ -113,8 +113,8 @@ const createRigidBodyApi = ref => {
|
|
113
113
|
return new three.Quaternion(x, y, z, w);
|
114
114
|
},
|
115
115
|
|
116
|
-
setRotation: rotation => {
|
117
|
-
ref.current().setRotation(rotation,
|
116
|
+
setRotation: (rotation, wakeUp = true) => {
|
117
|
+
ref.current().setRotation(rotation, wakeUp);
|
118
118
|
},
|
119
119
|
|
120
120
|
linvel() {
|
@@ -126,7 +126,7 @@ const createRigidBodyApi = ref => {
|
|
126
126
|
return new three.Vector3(x, y, z);
|
127
127
|
},
|
128
128
|
|
129
|
-
setLinvel: velocity => ref.current().setLinvel(velocity,
|
129
|
+
setLinvel: (velocity, wakeUp = true) => ref.current().setLinvel(velocity, wakeUp),
|
130
130
|
|
131
131
|
angvel() {
|
132
132
|
const {
|
@@ -137,7 +137,7 @@ const createRigidBodyApi = ref => {
|
|
137
137
|
return new three.Vector3(x, y, z);
|
138
138
|
},
|
139
139
|
|
140
|
-
setAngvel: velocity => ref.current().setAngvel(velocity,
|
140
|
+
setAngvel: (velocity, wakeUp = true) => ref.current().setAngvel(velocity, wakeUp),
|
141
141
|
|
142
142
|
linearDamping() {
|
143
143
|
return ref.current().linearDamping();
|
@@ -154,12 +154,12 @@ const createRigidBodyApi = ref => {
|
|
154
154
|
ref.current().setNextKinematicRotation(rotation);
|
155
155
|
},
|
156
156
|
setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
|
157
|
-
resetForces: () => ref.current().resetForces(
|
158
|
-
resetTorques: () => ref.current().resetTorques(
|
159
|
-
lockRotations: locked => ref.current().lockRotations(locked,
|
160
|
-
lockTranslations: locked => ref.current().lockTranslations(locked,
|
161
|
-
setEnabledRotations: (x, y, z) => ref.current().setEnabledRotations(x, y, z,
|
162
|
-
setEnabledTranslations: (x, y, z) => ref.current().setEnabledTranslations(x, y, z,
|
157
|
+
resetForces: (wakeUp = true) => ref.current().resetForces(wakeUp),
|
158
|
+
resetTorques: (wakeUp = true) => ref.current().resetTorques(wakeUp),
|
159
|
+
lockRotations: (locked, wakeUp = true) => ref.current().lockRotations(locked, wakeUp),
|
160
|
+
lockTranslations: (locked, wakeUp = true) => ref.current().lockTranslations(locked, wakeUp),
|
161
|
+
setEnabledRotations: (x, y, z, wakeUp = true) => ref.current().setEnabledRotations(x, y, z, wakeUp),
|
162
|
+
setEnabledTranslations: (x, y, z, wakeUp = true) => ref.current().setEnabledTranslations(x, y, z, wakeUp)
|
163
163
|
};
|
164
164
|
};
|
165
165
|
const createInstancedRigidBodiesApi = bodiesGetter => ({
|
@@ -182,9 +182,9 @@ const createWorldApi = ref => {
|
|
182
182
|
createRigidBody: desc => ref.current().createRigidBody(desc),
|
183
183
|
createCollider: (desc, rigidBody) => ref.current().createCollider(desc, rigidBody),
|
184
184
|
removeRigidBody: rigidBody => ref.current().removeRigidBody(rigidBody),
|
185
|
-
removeCollider: collider => ref.current().removeCollider(collider,
|
186
|
-
createImpulseJoint: (params, rigidBodyA, rigidBodyB) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB,
|
187
|
-
removeImpulseJoint: joint => ref.current().removeImpulseJoint(joint,
|
185
|
+
removeCollider: (collider, wakeUp = true) => ref.current().removeCollider(collider, wakeUp),
|
186
|
+
createImpulseJoint: (params, rigidBodyA, rigidBodyB, wakeUp = true) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB, wakeUp),
|
187
|
+
removeImpulseJoint: (joint, wakeUp = true) => ref.current().removeImpulseJoint(joint, wakeUp),
|
188
188
|
forEachCollider: callback => ref.current().forEachCollider(callback),
|
189
189
|
setGravity: ({
|
190
190
|
x,
|
@@ -746,6 +746,32 @@ const createColliderFromOptions = (options, world, scale, rigidBody) => {
|
|
746
746
|
const desc = rapier3dCompat.ColliderDesc[options.shape](...scaledArgs);
|
747
747
|
return world.createCollider(desc, rigidBody);
|
748
748
|
};
|
749
|
+
const massPropertiesConflictError = "Please pick ONLY ONE of the `density`, `mass` and `massProperties` options.";
|
750
|
+
|
751
|
+
const setColliderMassOptions = (collider, options) => {
|
752
|
+
if (options.density !== undefined) {
|
753
|
+
if (options.mass !== undefined || options.massProperties !== undefined) {
|
754
|
+
throw new Error(massPropertiesConflictError);
|
755
|
+
}
|
756
|
+
|
757
|
+
collider.setDensity(options.density);
|
758
|
+
return;
|
759
|
+
}
|
760
|
+
|
761
|
+
if (options.mass !== undefined) {
|
762
|
+
if (options.massProperties !== undefined) {
|
763
|
+
throw new Error(massPropertiesConflictError);
|
764
|
+
}
|
765
|
+
|
766
|
+
collider.setMass(options.mass);
|
767
|
+
return;
|
768
|
+
}
|
769
|
+
|
770
|
+
if (options.massProperties !== undefined) {
|
771
|
+
collider.setMassProperties(options.massProperties.mass, options.massProperties.centerOfMass, options.massProperties.principalAngularInertia, options.massProperties.angularInertiaLocalFrame);
|
772
|
+
}
|
773
|
+
};
|
774
|
+
|
749
775
|
const mutableColliderOptions = {
|
750
776
|
sensor: (collider, value) => {
|
751
777
|
collider.setSensor(value);
|
@@ -759,14 +785,14 @@ const mutableColliderOptions = {
|
|
759
785
|
friction: (collider, value) => {
|
760
786
|
collider.setFriction(value);
|
761
787
|
},
|
788
|
+
frictionCombineRule: (collider, value) => {
|
789
|
+
collider.setFrictionCombineRule(value);
|
790
|
+
},
|
762
791
|
restitution: (collider, value) => {
|
763
792
|
collider.setRestitution(value);
|
764
793
|
},
|
765
|
-
|
766
|
-
collider.
|
767
|
-
},
|
768
|
-
mass: (collider, value) => {
|
769
|
-
collider.setMass(value);
|
794
|
+
restitutionCombineRule: (collider, value) => {
|
795
|
+
collider.setRestitutionCombineRule(value);
|
770
796
|
}
|
771
797
|
};
|
772
798
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
@@ -780,17 +806,32 @@ const setColliderOptions = (collider, options, states) => {
|
|
780
806
|
|
781
807
|
_matrix4.copy(state.object.matrixWorld).premultiply(state.worldParent.matrixWorld.clone().invert()).decompose(_position, _rotation, _scale);
|
782
808
|
|
783
|
-
collider.
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
809
|
+
if (collider.parent()) {
|
810
|
+
collider.setTranslationWrtParent({
|
811
|
+
x: _position.x * parentWorldScale.x,
|
812
|
+
y: _position.y * parentWorldScale.y,
|
813
|
+
z: _position.z * parentWorldScale.z
|
814
|
+
});
|
815
|
+
collider.setRotationWrtParent(_rotation);
|
816
|
+
} else {
|
817
|
+
collider.setTranslation({
|
818
|
+
x: _position.x * parentWorldScale.x,
|
819
|
+
y: _position.y * parentWorldScale.y,
|
820
|
+
z: _position.z * parentWorldScale.z
|
821
|
+
});
|
822
|
+
collider.setRotation(_rotation);
|
823
|
+
}
|
824
|
+
|
789
825
|
mutableColliderOptionKeys.forEach(key => {
|
790
826
|
if (key in options) {
|
791
|
-
|
827
|
+
const option = options[key];
|
828
|
+
mutableColliderOptions[key](collider, // @ts-ignore Option does not want to fit into the function, but it will
|
829
|
+
option, options);
|
792
830
|
}
|
793
|
-
});
|
831
|
+
}); // handle mass separately, because the assignments
|
832
|
+
// are exclusive.
|
833
|
+
|
834
|
+
setColliderMassOptions(collider, options);
|
794
835
|
}
|
795
836
|
};
|
796
837
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
@@ -1099,7 +1140,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
1099
1140
|
};
|
1100
1141
|
|
1101
1142
|
// Colliders
|
1102
|
-
const AnyCollider = /*#__PURE__*/React.memo(props => {
|
1143
|
+
const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["default"].forwardRef((props, forwardedRef) => {
|
1103
1144
|
const {
|
1104
1145
|
children,
|
1105
1146
|
position,
|
@@ -1114,7 +1155,15 @@ const AnyCollider = /*#__PURE__*/React.memo(props => {
|
|
1114
1155
|
} = useRapier();
|
1115
1156
|
const rigidBodyContext = useRigidBodyContext();
|
1116
1157
|
const ref = React.useRef(null);
|
1117
|
-
const collidersRef = React.
|
1158
|
+
const collidersRef = React.useMemo(() => {
|
1159
|
+
if (forwardedRef !== null) {
|
1160
|
+
return forwardedRef;
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
const result = /*#__PURE__*/React__default["default"].createRef();
|
1164
|
+
result.current = [];
|
1165
|
+
return result;
|
1166
|
+
}, []);
|
1118
1167
|
React.useEffect(() => {
|
1119
1168
|
const object = ref.current;
|
1120
1169
|
const worldScale = object.getWorldScale(new three.Vector3());
|
@@ -1147,8 +1196,11 @@ const AnyCollider = /*#__PURE__*/React.memo(props => {
|
|
1147
1196
|
});
|
1148
1197
|
};
|
1149
1198
|
}, []);
|
1150
|
-
|
1151
|
-
|
1199
|
+
const mergedProps = React.useMemo(() => {
|
1200
|
+
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1201
|
+
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1202
|
+
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
1203
|
+
useColliderEvents(collidersRef, mergedProps, colliderEvents);
|
1152
1204
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1153
1205
|
position: position,
|
1154
1206
|
rotation: rotation,
|
@@ -1156,52 +1208,61 @@ const AnyCollider = /*#__PURE__*/React.memo(props => {
|
|
1156
1208
|
scale: scale,
|
1157
1209
|
ref: ref
|
1158
1210
|
}, children);
|
1159
|
-
});
|
1160
|
-
const CuboidCollider = props => {
|
1211
|
+
}));
|
1212
|
+
const CuboidCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1161
1213
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1162
|
-
shape: "cuboid"
|
1214
|
+
shape: "cuboid",
|
1215
|
+
ref: ref
|
1163
1216
|
}));
|
1164
|
-
};
|
1165
|
-
const RoundCuboidCollider = props => {
|
1217
|
+
});
|
1218
|
+
const RoundCuboidCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1166
1219
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1167
|
-
shape: "roundCuboid"
|
1220
|
+
shape: "roundCuboid",
|
1221
|
+
ref: ref
|
1168
1222
|
}));
|
1169
|
-
};
|
1170
|
-
const BallCollider = props => {
|
1223
|
+
});
|
1224
|
+
const BallCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1171
1225
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1172
|
-
shape: "ball"
|
1226
|
+
shape: "ball",
|
1227
|
+
ref: ref
|
1173
1228
|
}));
|
1174
|
-
};
|
1175
|
-
const CapsuleCollider = props => {
|
1229
|
+
});
|
1230
|
+
const CapsuleCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1176
1231
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1177
|
-
shape: "capsule"
|
1232
|
+
shape: "capsule",
|
1233
|
+
ref: ref
|
1178
1234
|
}));
|
1179
|
-
};
|
1180
|
-
const HeightfieldCollider = props => {
|
1235
|
+
});
|
1236
|
+
const HeightfieldCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1181
1237
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1182
|
-
shape: "heightfield"
|
1238
|
+
shape: "heightfield",
|
1239
|
+
ref: ref
|
1183
1240
|
}));
|
1184
|
-
};
|
1185
|
-
const TrimeshCollider = props => {
|
1241
|
+
});
|
1242
|
+
const TrimeshCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1186
1243
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1187
|
-
shape: "trimesh"
|
1244
|
+
shape: "trimesh",
|
1245
|
+
ref: ref
|
1188
1246
|
}));
|
1189
|
-
};
|
1190
|
-
const ConeCollider = props => {
|
1247
|
+
});
|
1248
|
+
const ConeCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1191
1249
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1192
|
-
shape: "cone"
|
1250
|
+
shape: "cone",
|
1251
|
+
ref: ref
|
1193
1252
|
}));
|
1194
|
-
};
|
1195
|
-
const CylinderCollider = props => {
|
1253
|
+
});
|
1254
|
+
const CylinderCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1196
1255
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1197
|
-
shape: "cylinder"
|
1256
|
+
shape: "cylinder",
|
1257
|
+
ref: ref
|
1198
1258
|
}));
|
1199
|
-
};
|
1200
|
-
const ConvexHullCollider = props => {
|
1259
|
+
});
|
1260
|
+
const ConvexHullCollider = /*#__PURE__*/React__default["default"].forwardRef((props, ref) => {
|
1201
1261
|
return /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({}, props, {
|
1202
|
-
shape: "convexHull"
|
1262
|
+
shape: "convexHull",
|
1263
|
+
ref: ref
|
1203
1264
|
}));
|
1204
|
-
};
|
1265
|
+
});
|
1205
1266
|
|
1206
1267
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1207
1268
|
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
@@ -1277,7 +1338,7 @@ const geometryFromCollider = collider => {
|
|
1277
1338
|
y,
|
1278
1339
|
z
|
1279
1340
|
} = collider.shape.halfExtents;
|
1280
|
-
return new three.
|
1341
|
+
return new three.BoxGeometry(x * 2 + 0.01, y * 2 + 0.01, z * 2 + 0.01);
|
1281
1342
|
}
|
1282
1343
|
|
1283
1344
|
case rapier3dCompat.ShapeType.RoundCuboid:
|
@@ -1294,7 +1355,7 @@ const geometryFromCollider = collider => {
|
|
1294
1355
|
case rapier3dCompat.ShapeType.Ball:
|
1295
1356
|
{
|
1296
1357
|
const r = collider.shape.radius;
|
1297
|
-
return new three.
|
1358
|
+
return new three.SphereGeometry(r + +0.01, 8, 8);
|
1298
1359
|
}
|
1299
1360
|
|
1300
1361
|
case rapier3dCompat.ShapeType.TriMesh:
|
@@ -1326,7 +1387,7 @@ const geometryFromCollider = collider => {
|
|
1326
1387
|
{
|
1327
1388
|
const r = collider.shape.radius;
|
1328
1389
|
const h = collider.shape.halfHeight;
|
1329
|
-
const g = new three.
|
1390
|
+
const g = new three.CylinderGeometry(r, r, h * 2);
|
1330
1391
|
return g;
|
1331
1392
|
}
|
1332
1393
|
|
@@ -1334,7 +1395,7 @@ const geometryFromCollider = collider => {
|
|
1334
1395
|
{
|
1335
1396
|
const r = collider.shape.radius;
|
1336
1397
|
const h = collider.shape.halfHeight;
|
1337
|
-
const g = new three.
|
1398
|
+
const g = new three.CapsuleGeometry(r, h * 2, 4, 8);
|
1338
1399
|
return g;
|
1339
1400
|
}
|
1340
1401
|
|
@@ -1342,7 +1403,7 @@ const geometryFromCollider = collider => {
|
|
1342
1403
|
{
|
1343
1404
|
const r = collider.shape.radius;
|
1344
1405
|
const h = collider.shape.halfHeight;
|
1345
|
-
const g = new three.
|
1406
|
+
const g = new three.ConeGeometry(r, h * 2, 16);
|
1346
1407
|
return g;
|
1347
1408
|
}
|
1348
1409
|
|
@@ -1362,7 +1423,7 @@ const geometryFromCollider = collider => {
|
|
1362
1423
|
}
|
1363
1424
|
}
|
1364
1425
|
|
1365
|
-
return new three.
|
1426
|
+
return new three.BoxGeometry(1, 1, 1);
|
1366
1427
|
};
|
1367
1428
|
|
1368
1429
|
const DebugShape = /*#__PURE__*/React.memo(({
|