@react-three/rapier 1.5.0 → 2.0.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 +16 -16
- package/dist/declarations/src/components/InstancedRigidBodies.d.ts +5 -4
- package/dist/declarations/src/components/Physics.d.ts +6 -6
- package/dist/declarations/src/components/RigidBody.d.ts +8 -10
- package/dist/declarations/src/hooks/hooks.d.ts +2 -2
- package/dist/declarations/src/hooks/joints.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +52 -64
- package/dist/declarations/src/utils/interaction-groups.d.ts +1 -1
- package/dist/react-three-rapier.cjs.dev.js +199 -189
- package/dist/react-three-rapier.cjs.prod.js +199 -189
- package/dist/react-three-rapier.esm.js +200 -190
- package/package.json +14 -13
@@ -144,7 +144,7 @@ const vectorToTuple = v => {
|
|
144
144
|
return [v];
|
145
145
|
};
|
146
146
|
function useConst(initialValue) {
|
147
|
-
const ref = React.useRef();
|
147
|
+
const ref = React.useRef(undefined);
|
148
148
|
if (ref.current === undefined) {
|
149
149
|
ref.current = {
|
150
150
|
value: typeof initialValue === "function" ? initialValue() : initialValue
|
@@ -208,7 +208,7 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
208
208
|
if (null == r) return {};
|
209
209
|
var t = {};
|
210
210
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
211
|
-
if (e.
|
211
|
+
if (-1 !== e.indexOf(n)) continue;
|
212
212
|
t[n] = r[n];
|
213
213
|
}
|
214
214
|
return t;
|
@@ -220,13 +220,13 @@ function _objectWithoutProperties(e, t) {
|
|
220
220
|
r,
|
221
221
|
i = _objectWithoutPropertiesLoose(e, t);
|
222
222
|
if (Object.getOwnPropertySymbols) {
|
223
|
-
var
|
224
|
-
for (r = 0; r <
|
223
|
+
var n = Object.getOwnPropertySymbols(e);
|
224
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
225
225
|
}
|
226
226
|
return i;
|
227
227
|
}
|
228
228
|
|
229
|
-
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
|
229
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction", "ref"];
|
230
230
|
const scaleColliderArgs = (shape, args, scale) => {
|
231
231
|
const newArgs = args.slice();
|
232
232
|
|
@@ -1017,11 +1017,25 @@ function _extends() {
|
|
1017
1017
|
}, _extends.apply(null, arguments);
|
1018
1018
|
}
|
1019
1019
|
|
1020
|
+
// Need to catch the case where forwardedRef is a function... how to do that?
|
1021
|
+
const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
1022
|
+
const innerRef = React.useRef(defaultValue);
|
1023
|
+
|
1024
|
+
// Update the forwarded ref when the inner ref changes
|
1025
|
+
if (forwardedRef && typeof forwardedRef !== "function") {
|
1026
|
+
if (!forwardedRef.current) {
|
1027
|
+
forwardedRef.current = innerRef.current;
|
1028
|
+
}
|
1029
|
+
return forwardedRef;
|
1030
|
+
}
|
1031
|
+
return innerRef;
|
1032
|
+
};
|
1033
|
+
|
1020
1034
|
/**
|
1021
1035
|
* Initiate an instance and return a safe getter
|
1022
1036
|
*/
|
1023
1037
|
const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
1024
|
-
const ref = React.useRef();
|
1038
|
+
const ref = React.useRef(undefined);
|
1025
1039
|
const getInstance = React.useCallback(() => {
|
1026
1040
|
if (!ref.current) {
|
1027
1041
|
ref.current = createFn();
|
@@ -1040,6 +1054,156 @@ const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
|
1040
1054
|
return getInstance;
|
1041
1055
|
};
|
1042
1056
|
|
1057
|
+
const rigidBodyDescFromOptions = options => {
|
1058
|
+
var _options$canSleep;
|
1059
|
+
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
1060
|
+
const desc = new rapier3dCompat.RigidBodyDesc(type);
|
1061
|
+
|
1062
|
+
// Apply immutable options
|
1063
|
+
desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
1064
|
+
return desc;
|
1065
|
+
};
|
1066
|
+
const createRigidBodyState = ({
|
1067
|
+
rigidBody,
|
1068
|
+
object,
|
1069
|
+
setMatrix,
|
1070
|
+
getMatrix,
|
1071
|
+
worldScale,
|
1072
|
+
meshType: _meshType = "mesh"
|
1073
|
+
}) => {
|
1074
|
+
object.updateWorldMatrix(true, false);
|
1075
|
+
const invertedWorldMatrix = object.parent.matrixWorld.clone().invert();
|
1076
|
+
return {
|
1077
|
+
object,
|
1078
|
+
rigidBody,
|
1079
|
+
invertedWorldMatrix,
|
1080
|
+
setMatrix: setMatrix ? setMatrix : matrix => {
|
1081
|
+
object.matrix.copy(matrix);
|
1082
|
+
},
|
1083
|
+
getMatrix: getMatrix ? getMatrix : matrix => matrix.copy(object.matrix),
|
1084
|
+
scale: worldScale || object.getWorldScale(_scale).clone(),
|
1085
|
+
isSleeping: false,
|
1086
|
+
meshType: _meshType
|
1087
|
+
};
|
1088
|
+
};
|
1089
|
+
const immutableRigidBodyOptions = ["args", "colliders", "canSleep"];
|
1090
|
+
const mutableRigidBodyOptions = {
|
1091
|
+
gravityScale: (rb, value) => {
|
1092
|
+
rb.setGravityScale(value, true);
|
1093
|
+
},
|
1094
|
+
additionalSolverIterations(rb, value) {
|
1095
|
+
rb.setAdditionalSolverIterations(value);
|
1096
|
+
},
|
1097
|
+
linearDamping: (rb, value) => {
|
1098
|
+
rb.setLinearDamping(value);
|
1099
|
+
},
|
1100
|
+
angularDamping: (rb, value) => {
|
1101
|
+
rb.setAngularDamping(value);
|
1102
|
+
},
|
1103
|
+
dominanceGroup: (rb, value) => {
|
1104
|
+
rb.setDominanceGroup(value);
|
1105
|
+
},
|
1106
|
+
enabledRotations: (rb, [x, y, z]) => {
|
1107
|
+
rb.setEnabledRotations(x, y, z, true);
|
1108
|
+
},
|
1109
|
+
enabledTranslations: (rb, [x, y, z]) => {
|
1110
|
+
rb.setEnabledTranslations(x, y, z, true);
|
1111
|
+
},
|
1112
|
+
lockRotations: (rb, value) => {
|
1113
|
+
rb.lockRotations(value, true);
|
1114
|
+
},
|
1115
|
+
lockTranslations: (rb, value) => {
|
1116
|
+
rb.lockTranslations(value, true);
|
1117
|
+
},
|
1118
|
+
angularVelocity: (rb, [x, y, z]) => {
|
1119
|
+
rb.setAngvel({
|
1120
|
+
x,
|
1121
|
+
y,
|
1122
|
+
z
|
1123
|
+
}, true);
|
1124
|
+
},
|
1125
|
+
linearVelocity: (rb, [x, y, z]) => {
|
1126
|
+
rb.setLinvel({
|
1127
|
+
x,
|
1128
|
+
y,
|
1129
|
+
z
|
1130
|
+
}, true);
|
1131
|
+
},
|
1132
|
+
ccd: (rb, value) => {
|
1133
|
+
rb.enableCcd(value);
|
1134
|
+
},
|
1135
|
+
softCcdPrediction: (rb, value) => {
|
1136
|
+
rb.setSoftCcdPrediction(value);
|
1137
|
+
},
|
1138
|
+
userData: (rb, value) => {
|
1139
|
+
rb.userData = value;
|
1140
|
+
},
|
1141
|
+
type(rb, value) {
|
1142
|
+
rb.setBodyType(rigidBodyTypeFromString(value), true);
|
1143
|
+
},
|
1144
|
+
position: () => {},
|
1145
|
+
rotation: () => {},
|
1146
|
+
quaternion: () => {},
|
1147
|
+
scale: () => {}
|
1148
|
+
};
|
1149
|
+
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
1150
|
+
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
1151
|
+
if (!rigidBody) {
|
1152
|
+
return;
|
1153
|
+
}
|
1154
|
+
const state = states.get(rigidBody.handle);
|
1155
|
+
if (state) {
|
1156
|
+
if (updateTranslations) {
|
1157
|
+
state.object.updateWorldMatrix(true, false);
|
1158
|
+
_matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
|
1159
|
+
rigidBody.setTranslation(_position, false);
|
1160
|
+
rigidBody.setRotation(_rotation, false);
|
1161
|
+
}
|
1162
|
+
mutableRigidBodyOptionKeys.forEach(key => {
|
1163
|
+
if (key in options) {
|
1164
|
+
mutableRigidBodyOptions[key](rigidBody, options[key]);
|
1165
|
+
}
|
1166
|
+
});
|
1167
|
+
}
|
1168
|
+
};
|
1169
|
+
const useUpdateRigidBodyOptions = (getRigidBody, props, states, updateTranslations = true) => {
|
1170
|
+
// TODO: Improve this, split each prop into its own effect
|
1171
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
1172
|
+
return vectorToTuple(props[key]);
|
1173
|
+
}), [props]);
|
1174
|
+
React.useEffect(() => {
|
1175
|
+
const rigidBody = getRigidBody();
|
1176
|
+
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
1177
|
+
}, mutablePropsAsFlatArray);
|
1178
|
+
};
|
1179
|
+
const useRigidBodyEvents = (getRigidBody, props, events) => {
|
1180
|
+
const {
|
1181
|
+
onWake,
|
1182
|
+
onSleep,
|
1183
|
+
onCollisionEnter,
|
1184
|
+
onCollisionExit,
|
1185
|
+
onIntersectionEnter,
|
1186
|
+
onIntersectionExit,
|
1187
|
+
onContactForce
|
1188
|
+
} = props;
|
1189
|
+
const eventHandlers = {
|
1190
|
+
onWake,
|
1191
|
+
onSleep,
|
1192
|
+
onCollisionEnter,
|
1193
|
+
onCollisionExit,
|
1194
|
+
onIntersectionEnter,
|
1195
|
+
onIntersectionExit,
|
1196
|
+
onContactForce
|
1197
|
+
};
|
1198
|
+
React.useEffect(() => {
|
1199
|
+
const rigidBody = getRigidBody();
|
1200
|
+
events.set(rigidBody.handle, eventHandlers);
|
1201
|
+
return () => {
|
1202
|
+
events.delete(rigidBody.handle);
|
1203
|
+
};
|
1204
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1205
|
+
};
|
1206
|
+
|
1043
1207
|
/**
|
1044
1208
|
* Takes an object resembling a Vector3 and returs a Three.Vector3
|
1045
1209
|
* @category Math helpers
|
@@ -1090,25 +1254,11 @@ const euler = ({
|
|
1090
1254
|
return new three.Euler(x, y, z);
|
1091
1255
|
};
|
1092
1256
|
|
1093
|
-
// Need to catch the case where forwardedRef is a function... how to do that?
|
1094
|
-
const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
1095
|
-
const innerRef = React.useRef(defaultValue);
|
1096
|
-
|
1097
|
-
// Update the forwarded ref when the inner ref changes
|
1098
|
-
if (forwardedRef && typeof forwardedRef !== "function") {
|
1099
|
-
if (!forwardedRef.current) {
|
1100
|
-
forwardedRef.current = innerRef.current;
|
1101
|
-
}
|
1102
|
-
return forwardedRef;
|
1103
|
-
}
|
1104
|
-
return innerRef;
|
1105
|
-
};
|
1106
|
-
|
1107
1257
|
/**
|
1108
1258
|
* A collider is a shape that can be attached to a rigid body to define its physical properties.
|
1109
1259
|
* @internal
|
1110
1260
|
*/
|
1111
|
-
const AnyCollider = /*#__PURE__*/React.memo(
|
1261
|
+
const AnyCollider = /*#__PURE__*/React.memo(props => {
|
1112
1262
|
const {
|
1113
1263
|
children,
|
1114
1264
|
position,
|
@@ -1123,16 +1273,18 @@ const AnyCollider = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props
|
|
1123
1273
|
colliderStates
|
1124
1274
|
} = useRapier();
|
1125
1275
|
const rigidBodyContext = useRigidBodyContext();
|
1126
|
-
const colliderRef = useForwardedRef(
|
1276
|
+
const colliderRef = useForwardedRef(props.ref);
|
1127
1277
|
const objectRef = React.useRef(null);
|
1128
1278
|
|
1129
1279
|
// We spread the props out here to make sure that the ref is updated when the props change.
|
1130
|
-
const immutablePropArray = immutableColliderOptions.flatMap(key =>
|
1280
|
+
const immutablePropArray = immutableColliderOptions.flatMap(key =>
|
1281
|
+
// Array.isArray(props[key]) ? [...props[key]] : props[key]
|
1282
|
+
Array.isArray(props[key]) ? props[key] : [props[key]]);
|
1131
1283
|
const getInstance = useImperativeInstance(() => {
|
1132
1284
|
const worldScale = objectRef.current.getWorldScale(vec3());
|
1133
1285
|
const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
|
1134
|
-
if (typeof
|
1135
|
-
|
1286
|
+
if (typeof props.ref == "function") {
|
1287
|
+
props.ref(collider);
|
1136
1288
|
}
|
1137
1289
|
colliderRef.current = collider;
|
1138
1290
|
return collider;
|
@@ -1161,7 +1313,7 @@ const AnyCollider = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props
|
|
1161
1313
|
ref: objectRef,
|
1162
1314
|
name: name
|
1163
1315
|
}, children);
|
1164
|
-
})
|
1316
|
+
});
|
1165
1317
|
/**
|
1166
1318
|
* A cuboid collider shape
|
1167
1319
|
* @category Colliders
|
@@ -1264,165 +1416,16 @@ const ConvexHullCollider = /*#__PURE__*/React__default["default"].forwardRef((pr
|
|
1264
1416
|
})));
|
1265
1417
|
ConvexHullCollider.displayName = "ConvexHullCollider";
|
1266
1418
|
|
1267
|
-
const
|
1268
|
-
var _options$canSleep;
|
1269
|
-
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
1270
|
-
const desc = new rapier3dCompat.RigidBodyDesc(type);
|
1271
|
-
|
1272
|
-
// Apply immutable options
|
1273
|
-
desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
1274
|
-
return desc;
|
1275
|
-
};
|
1276
|
-
const createRigidBodyState = ({
|
1277
|
-
rigidBody,
|
1278
|
-
object,
|
1279
|
-
setMatrix,
|
1280
|
-
getMatrix,
|
1281
|
-
worldScale,
|
1282
|
-
meshType: _meshType = "mesh"
|
1283
|
-
}) => {
|
1284
|
-
object.updateWorldMatrix(true, false);
|
1285
|
-
const invertedWorldMatrix = object.parent.matrixWorld.clone().invert();
|
1286
|
-
return {
|
1287
|
-
object,
|
1288
|
-
rigidBody,
|
1289
|
-
invertedWorldMatrix,
|
1290
|
-
setMatrix: setMatrix ? setMatrix : matrix => {
|
1291
|
-
object.matrix.copy(matrix);
|
1292
|
-
},
|
1293
|
-
getMatrix: getMatrix ? getMatrix : matrix => matrix.copy(object.matrix),
|
1294
|
-
scale: worldScale || object.getWorldScale(_scale).clone(),
|
1295
|
-
isSleeping: false,
|
1296
|
-
meshType: _meshType
|
1297
|
-
};
|
1298
|
-
};
|
1299
|
-
const immutableRigidBodyOptions = ["args", "colliders", "canSleep"];
|
1300
|
-
const mutableRigidBodyOptions = {
|
1301
|
-
gravityScale: (rb, value) => {
|
1302
|
-
rb.setGravityScale(value, true);
|
1303
|
-
},
|
1304
|
-
additionalSolverIterations(rb, value) {
|
1305
|
-
rb.setAdditionalSolverIterations(value);
|
1306
|
-
},
|
1307
|
-
linearDamping: (rb, value) => {
|
1308
|
-
rb.setLinearDamping(value);
|
1309
|
-
},
|
1310
|
-
angularDamping: (rb, value) => {
|
1311
|
-
rb.setAngularDamping(value);
|
1312
|
-
},
|
1313
|
-
dominanceGroup: (rb, value) => {
|
1314
|
-
rb.setDominanceGroup(value);
|
1315
|
-
},
|
1316
|
-
enabledRotations: (rb, [x, y, z]) => {
|
1317
|
-
rb.setEnabledRotations(x, y, z, true);
|
1318
|
-
},
|
1319
|
-
enabledTranslations: (rb, [x, y, z]) => {
|
1320
|
-
rb.setEnabledTranslations(x, y, z, true);
|
1321
|
-
},
|
1322
|
-
lockRotations: (rb, value) => {
|
1323
|
-
rb.lockRotations(value, true);
|
1324
|
-
},
|
1325
|
-
lockTranslations: (rb, value) => {
|
1326
|
-
rb.lockTranslations(value, true);
|
1327
|
-
},
|
1328
|
-
angularVelocity: (rb, [x, y, z]) => {
|
1329
|
-
rb.setAngvel({
|
1330
|
-
x,
|
1331
|
-
y,
|
1332
|
-
z
|
1333
|
-
}, true);
|
1334
|
-
},
|
1335
|
-
linearVelocity: (rb, [x, y, z]) => {
|
1336
|
-
rb.setLinvel({
|
1337
|
-
x,
|
1338
|
-
y,
|
1339
|
-
z
|
1340
|
-
}, true);
|
1341
|
-
},
|
1342
|
-
ccd: (rb, value) => {
|
1343
|
-
rb.enableCcd(value);
|
1344
|
-
},
|
1345
|
-
softCcdPrediction: (rb, value) => {
|
1346
|
-
rb.setSoftCcdPrediction(value);
|
1347
|
-
},
|
1348
|
-
userData: (rb, value) => {
|
1349
|
-
rb.userData = value;
|
1350
|
-
},
|
1351
|
-
type(rb, value) {
|
1352
|
-
rb.setBodyType(rigidBodyTypeFromString(value), true);
|
1353
|
-
},
|
1354
|
-
position: () => {},
|
1355
|
-
rotation: () => {},
|
1356
|
-
quaternion: () => {},
|
1357
|
-
scale: () => {}
|
1358
|
-
};
|
1359
|
-
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
1360
|
-
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
1361
|
-
if (!rigidBody) {
|
1362
|
-
return;
|
1363
|
-
}
|
1364
|
-
const state = states.get(rigidBody.handle);
|
1365
|
-
if (state) {
|
1366
|
-
if (updateTranslations) {
|
1367
|
-
state.object.updateWorldMatrix(true, false);
|
1368
|
-
_matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
|
1369
|
-
rigidBody.setTranslation(_position, false);
|
1370
|
-
rigidBody.setRotation(_rotation, false);
|
1371
|
-
}
|
1372
|
-
mutableRigidBodyOptionKeys.forEach(key => {
|
1373
|
-
if (key in options) {
|
1374
|
-
mutableRigidBodyOptions[key](rigidBody, options[key]);
|
1375
|
-
}
|
1376
|
-
});
|
1377
|
-
}
|
1378
|
-
};
|
1379
|
-
const useUpdateRigidBodyOptions = (getRigidBody, props, states, updateTranslations = true) => {
|
1380
|
-
// TODO: Improve this, split each prop into its own effect
|
1381
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
1382
|
-
return vectorToTuple(props[key]);
|
1383
|
-
}), [props]);
|
1384
|
-
React.useEffect(() => {
|
1385
|
-
const rigidBody = getRigidBody();
|
1386
|
-
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
1387
|
-
}, mutablePropsAsFlatArray);
|
1388
|
-
};
|
1389
|
-
const useRigidBodyEvents = (getRigidBody, props, events) => {
|
1390
|
-
const {
|
1391
|
-
onWake,
|
1392
|
-
onSleep,
|
1393
|
-
onCollisionEnter,
|
1394
|
-
onCollisionExit,
|
1395
|
-
onIntersectionEnter,
|
1396
|
-
onIntersectionExit,
|
1397
|
-
onContactForce
|
1398
|
-
} = props;
|
1399
|
-
const eventHandlers = {
|
1400
|
-
onWake,
|
1401
|
-
onSleep,
|
1402
|
-
onCollisionEnter,
|
1403
|
-
onCollisionExit,
|
1404
|
-
onIntersectionEnter,
|
1405
|
-
onIntersectionExit,
|
1406
|
-
onContactForce
|
1407
|
-
};
|
1408
|
-
React.useEffect(() => {
|
1409
|
-
const rigidBody = getRigidBody();
|
1410
|
-
events.set(rigidBody.handle, eventHandlers);
|
1411
|
-
return () => {
|
1412
|
-
events.delete(rigidBody.handle);
|
1413
|
-
};
|
1414
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1415
|
-
};
|
1416
|
-
|
1417
|
-
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1419
|
+
const _excluded$1 = ["ref", "children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1418
1420
|
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1419
1421
|
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1420
1422
|
/**
|
1421
1423
|
* A rigid body is a physical object that can be simulated by the physics engine.
|
1422
1424
|
* @category Components
|
1423
1425
|
*/
|
1424
|
-
const RigidBody = /*#__PURE__*/React.memo(
|
1426
|
+
const RigidBody = /*#__PURE__*/React.memo(props => {
|
1425
1427
|
const {
|
1428
|
+
ref,
|
1426
1429
|
children,
|
1427
1430
|
type,
|
1428
1431
|
position,
|
@@ -1433,7 +1436,7 @@ const RigidBody = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props,
|
|
1433
1436
|
} = props,
|
1434
1437
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1435
1438
|
const objectRef = React.useRef(null);
|
1436
|
-
const rigidBodyRef = useForwardedRef(
|
1439
|
+
const rigidBodyRef = useForwardedRef(ref);
|
1437
1440
|
const {
|
1438
1441
|
world,
|
1439
1442
|
rigidBodyStates,
|
@@ -1454,8 +1457,8 @@ const RigidBody = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props,
|
|
1454
1457
|
const getRigidBody = useImperativeInstance(() => {
|
1455
1458
|
const desc = rigidBodyDescFromOptions(mergedOptions);
|
1456
1459
|
const rigidBody = world.createRigidBody(desc);
|
1457
|
-
if (typeof
|
1458
|
-
|
1460
|
+
if (typeof ref === "function") {
|
1461
|
+
ref(rigidBody);
|
1459
1462
|
}
|
1460
1463
|
rigidBodyRef.current = rigidBody;
|
1461
1464
|
return rigidBody;
|
@@ -1498,7 +1501,7 @@ const RigidBody = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((props,
|
|
1498
1501
|
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1499
1502
|
key: index
|
1500
1503
|
}, colliderProps)))));
|
1501
|
-
})
|
1504
|
+
});
|
1502
1505
|
RigidBody.displayName = "RigidBody";
|
1503
1506
|
|
1504
1507
|
/**
|
@@ -1535,9 +1538,14 @@ const MeshCollider = /*#__PURE__*/React.memo(props => {
|
|
1535
1538
|
});
|
1536
1539
|
MeshCollider.displayName = "MeshCollider";
|
1537
1540
|
|
1538
|
-
const _excluded = ["
|
1539
|
-
|
1540
|
-
|
1541
|
+
const _excluded = ["ref"],
|
1542
|
+
_excluded2 = ["children", "instances", "colliderNodes", "position", "rotation", "quaternion", "scale"];
|
1543
|
+
const InstancedRigidBodies = /*#__PURE__*/React.memo(_ref => {
|
1544
|
+
let {
|
1545
|
+
ref
|
1546
|
+
} = _ref,
|
1547
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
1548
|
+
const rigidBodiesRef = useForwardedRef(ref, []);
|
1541
1549
|
const objectRef = React.useRef(null);
|
1542
1550
|
const instanceWrapperRef = React.useRef(null);
|
1543
1551
|
const {
|
@@ -1553,7 +1561,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardR
|
|
1553
1561
|
|
1554
1562
|
// rigid body specific props, and r3f-object props
|
1555
1563
|
} = props,
|
1556
|
-
rigidBodyProps = _objectWithoutProperties(props,
|
1564
|
+
rigidBodyProps = _objectWithoutProperties(props, _excluded2);
|
1557
1565
|
const childColliderProps = useChildColliderProps(objectRef, _objectSpread2(_objectSpread2({}, props), {}, {
|
1558
1566
|
children: undefined
|
1559
1567
|
}));
|
@@ -1601,14 +1609,16 @@ const InstancedRigidBodies = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardR
|
|
1601
1609
|
}), /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1602
1610
|
ref: instanceWrapperRef
|
1603
1611
|
}, children), instances === null || instances === void 0 ? void 0 : instances.map((instance, index) => /*#__PURE__*/React__default["default"].createElement(RigidBody, _extends({}, rigidBodyProps, instance, {
|
1604
|
-
ref: body =>
|
1612
|
+
ref: body => {
|
1613
|
+
rigidBodiesRef.current[index] = body;
|
1614
|
+
},
|
1605
1615
|
transformState: state => applyInstancedState(state, index)
|
1606
1616
|
}), /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, colliderNodes.map((node, index) => /*#__PURE__*/React__default["default"].createElement(React.Fragment, {
|
1607
1617
|
key: index
|
1608
1618
|
}, node)), childColliderProps.map((colliderProps, colliderIndex) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1609
1619
|
key: colliderIndex
|
1610
1620
|
}, colliderProps)))))));
|
1611
|
-
})
|
1621
|
+
});
|
1612
1622
|
InstancedRigidBodies.displayName = "InstancedRigidBodies";
|
1613
1623
|
|
1614
1624
|
/**
|
@@ -1618,7 +1628,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1618
1628
|
const {
|
1619
1629
|
world
|
1620
1630
|
} = useRapier();
|
1621
|
-
const jointRef = React.useRef();
|
1631
|
+
const jointRef = React.useRef(undefined);
|
1622
1632
|
useImperativeInstance(() => {
|
1623
1633
|
if (body1.current && body2.current) {
|
1624
1634
|
const newJoint = world.createImpulseJoint(params, body1.current, body2.current, true);
|