@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
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Vector3 as Vector3$1, Quaternion as Quaternion$1, ActiveEvents, ColliderDesc, EventQueue, RigidBodyDesc } from '@dimforge/rapier3d-compat';
|
2
2
|
export { CoefficientCombineRule, Collider as RapierCollider, RigidBody as RapierRigidBody } from '@dimforge/rapier3d-compat';
|
3
3
|
import { useFrame, useThree } from '@react-three/fiber';
|
4
|
-
import React, { useRef, useEffect, memo, useMemo, useContext, useState, createContext, useCallback,
|
4
|
+
import React, { useRef, useEffect, memo, useMemo, useContext, useState, createContext, useCallback, Fragment } from 'react';
|
5
5
|
import { Quaternion, Euler, Vector3, Object3D, Matrix4, BufferAttribute, MathUtils, DynamicDrawUsage } from 'three';
|
6
6
|
import { suspend } from 'suspend-react';
|
7
7
|
import { mergeVertices } from 'three-stdlib';
|
@@ -119,7 +119,7 @@ const vectorToTuple = v => {
|
|
119
119
|
return [v];
|
120
120
|
};
|
121
121
|
function useConst(initialValue) {
|
122
|
-
const ref = useRef();
|
122
|
+
const ref = useRef(undefined);
|
123
123
|
if (ref.current === undefined) {
|
124
124
|
ref.current = {
|
125
125
|
value: typeof initialValue === "function" ? initialValue() : initialValue
|
@@ -183,7 +183,7 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
183
183
|
if (null == r) return {};
|
184
184
|
var t = {};
|
185
185
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
186
|
-
if (e.
|
186
|
+
if (-1 !== e.indexOf(n)) continue;
|
187
187
|
t[n] = r[n];
|
188
188
|
}
|
189
189
|
return t;
|
@@ -195,13 +195,13 @@ function _objectWithoutProperties(e, t) {
|
|
195
195
|
r,
|
196
196
|
i = _objectWithoutPropertiesLoose(e, t);
|
197
197
|
if (Object.getOwnPropertySymbols) {
|
198
|
-
var
|
199
|
-
for (r = 0; r <
|
198
|
+
var n = Object.getOwnPropertySymbols(e);
|
199
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
200
200
|
}
|
201
201
|
return i;
|
202
202
|
}
|
203
203
|
|
204
|
-
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
|
204
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction", "ref"];
|
205
205
|
const scaleColliderArgs = (shape, args, scale) => {
|
206
206
|
const newArgs = args.slice();
|
207
207
|
|
@@ -992,11 +992,25 @@ function _extends() {
|
|
992
992
|
}, _extends.apply(null, arguments);
|
993
993
|
}
|
994
994
|
|
995
|
+
// Need to catch the case where forwardedRef is a function... how to do that?
|
996
|
+
const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
997
|
+
const innerRef = useRef(defaultValue);
|
998
|
+
|
999
|
+
// Update the forwarded ref when the inner ref changes
|
1000
|
+
if (forwardedRef && typeof forwardedRef !== "function") {
|
1001
|
+
if (!forwardedRef.current) {
|
1002
|
+
forwardedRef.current = innerRef.current;
|
1003
|
+
}
|
1004
|
+
return forwardedRef;
|
1005
|
+
}
|
1006
|
+
return innerRef;
|
1007
|
+
};
|
1008
|
+
|
995
1009
|
/**
|
996
1010
|
* Initiate an instance and return a safe getter
|
997
1011
|
*/
|
998
1012
|
const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
999
|
-
const ref = useRef();
|
1013
|
+
const ref = useRef(undefined);
|
1000
1014
|
const getInstance = useCallback(() => {
|
1001
1015
|
if (!ref.current) {
|
1002
1016
|
ref.current = createFn();
|
@@ -1015,6 +1029,156 @@ const useImperativeInstance = (createFn, destroyFn, dependencyList) => {
|
|
1015
1029
|
return getInstance;
|
1016
1030
|
};
|
1017
1031
|
|
1032
|
+
const rigidBodyDescFromOptions = options => {
|
1033
|
+
var _options$canSleep;
|
1034
|
+
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
1035
|
+
const desc = new RigidBodyDesc(type);
|
1036
|
+
|
1037
|
+
// Apply immutable options
|
1038
|
+
desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
1039
|
+
return desc;
|
1040
|
+
};
|
1041
|
+
const createRigidBodyState = ({
|
1042
|
+
rigidBody,
|
1043
|
+
object,
|
1044
|
+
setMatrix,
|
1045
|
+
getMatrix,
|
1046
|
+
worldScale,
|
1047
|
+
meshType: _meshType = "mesh"
|
1048
|
+
}) => {
|
1049
|
+
object.updateWorldMatrix(true, false);
|
1050
|
+
const invertedWorldMatrix = object.parent.matrixWorld.clone().invert();
|
1051
|
+
return {
|
1052
|
+
object,
|
1053
|
+
rigidBody,
|
1054
|
+
invertedWorldMatrix,
|
1055
|
+
setMatrix: setMatrix ? setMatrix : matrix => {
|
1056
|
+
object.matrix.copy(matrix);
|
1057
|
+
},
|
1058
|
+
getMatrix: getMatrix ? getMatrix : matrix => matrix.copy(object.matrix),
|
1059
|
+
scale: worldScale || object.getWorldScale(_scale).clone(),
|
1060
|
+
isSleeping: false,
|
1061
|
+
meshType: _meshType
|
1062
|
+
};
|
1063
|
+
};
|
1064
|
+
const immutableRigidBodyOptions = ["args", "colliders", "canSleep"];
|
1065
|
+
const mutableRigidBodyOptions = {
|
1066
|
+
gravityScale: (rb, value) => {
|
1067
|
+
rb.setGravityScale(value, true);
|
1068
|
+
},
|
1069
|
+
additionalSolverIterations(rb, value) {
|
1070
|
+
rb.setAdditionalSolverIterations(value);
|
1071
|
+
},
|
1072
|
+
linearDamping: (rb, value) => {
|
1073
|
+
rb.setLinearDamping(value);
|
1074
|
+
},
|
1075
|
+
angularDamping: (rb, value) => {
|
1076
|
+
rb.setAngularDamping(value);
|
1077
|
+
},
|
1078
|
+
dominanceGroup: (rb, value) => {
|
1079
|
+
rb.setDominanceGroup(value);
|
1080
|
+
},
|
1081
|
+
enabledRotations: (rb, [x, y, z]) => {
|
1082
|
+
rb.setEnabledRotations(x, y, z, true);
|
1083
|
+
},
|
1084
|
+
enabledTranslations: (rb, [x, y, z]) => {
|
1085
|
+
rb.setEnabledTranslations(x, y, z, true);
|
1086
|
+
},
|
1087
|
+
lockRotations: (rb, value) => {
|
1088
|
+
rb.lockRotations(value, true);
|
1089
|
+
},
|
1090
|
+
lockTranslations: (rb, value) => {
|
1091
|
+
rb.lockTranslations(value, true);
|
1092
|
+
},
|
1093
|
+
angularVelocity: (rb, [x, y, z]) => {
|
1094
|
+
rb.setAngvel({
|
1095
|
+
x,
|
1096
|
+
y,
|
1097
|
+
z
|
1098
|
+
}, true);
|
1099
|
+
},
|
1100
|
+
linearVelocity: (rb, [x, y, z]) => {
|
1101
|
+
rb.setLinvel({
|
1102
|
+
x,
|
1103
|
+
y,
|
1104
|
+
z
|
1105
|
+
}, true);
|
1106
|
+
},
|
1107
|
+
ccd: (rb, value) => {
|
1108
|
+
rb.enableCcd(value);
|
1109
|
+
},
|
1110
|
+
softCcdPrediction: (rb, value) => {
|
1111
|
+
rb.setSoftCcdPrediction(value);
|
1112
|
+
},
|
1113
|
+
userData: (rb, value) => {
|
1114
|
+
rb.userData = value;
|
1115
|
+
},
|
1116
|
+
type(rb, value) {
|
1117
|
+
rb.setBodyType(rigidBodyTypeFromString(value), true);
|
1118
|
+
},
|
1119
|
+
position: () => {},
|
1120
|
+
rotation: () => {},
|
1121
|
+
quaternion: () => {},
|
1122
|
+
scale: () => {}
|
1123
|
+
};
|
1124
|
+
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
1125
|
+
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
1126
|
+
if (!rigidBody) {
|
1127
|
+
return;
|
1128
|
+
}
|
1129
|
+
const state = states.get(rigidBody.handle);
|
1130
|
+
if (state) {
|
1131
|
+
if (updateTranslations) {
|
1132
|
+
state.object.updateWorldMatrix(true, false);
|
1133
|
+
_matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
|
1134
|
+
rigidBody.setTranslation(_position, false);
|
1135
|
+
rigidBody.setRotation(_rotation, false);
|
1136
|
+
}
|
1137
|
+
mutableRigidBodyOptionKeys.forEach(key => {
|
1138
|
+
if (key in options) {
|
1139
|
+
mutableRigidBodyOptions[key](rigidBody, options[key]);
|
1140
|
+
}
|
1141
|
+
});
|
1142
|
+
}
|
1143
|
+
};
|
1144
|
+
const useUpdateRigidBodyOptions = (getRigidBody, props, states, updateTranslations = true) => {
|
1145
|
+
// TODO: Improve this, split each prop into its own effect
|
1146
|
+
const mutablePropsAsFlatArray = useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
1147
|
+
return vectorToTuple(props[key]);
|
1148
|
+
}), [props]);
|
1149
|
+
useEffect(() => {
|
1150
|
+
const rigidBody = getRigidBody();
|
1151
|
+
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
1152
|
+
}, mutablePropsAsFlatArray);
|
1153
|
+
};
|
1154
|
+
const useRigidBodyEvents = (getRigidBody, props, events) => {
|
1155
|
+
const {
|
1156
|
+
onWake,
|
1157
|
+
onSleep,
|
1158
|
+
onCollisionEnter,
|
1159
|
+
onCollisionExit,
|
1160
|
+
onIntersectionEnter,
|
1161
|
+
onIntersectionExit,
|
1162
|
+
onContactForce
|
1163
|
+
} = props;
|
1164
|
+
const eventHandlers = {
|
1165
|
+
onWake,
|
1166
|
+
onSleep,
|
1167
|
+
onCollisionEnter,
|
1168
|
+
onCollisionExit,
|
1169
|
+
onIntersectionEnter,
|
1170
|
+
onIntersectionExit,
|
1171
|
+
onContactForce
|
1172
|
+
};
|
1173
|
+
useEffect(() => {
|
1174
|
+
const rigidBody = getRigidBody();
|
1175
|
+
events.set(rigidBody.handle, eventHandlers);
|
1176
|
+
return () => {
|
1177
|
+
events.delete(rigidBody.handle);
|
1178
|
+
};
|
1179
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1180
|
+
};
|
1181
|
+
|
1018
1182
|
/**
|
1019
1183
|
* Takes an object resembling a Vector3 and returs a Three.Vector3
|
1020
1184
|
* @category Math helpers
|
@@ -1065,25 +1229,11 @@ const euler = ({
|
|
1065
1229
|
return new Euler(x, y, z);
|
1066
1230
|
};
|
1067
1231
|
|
1068
|
-
// Need to catch the case where forwardedRef is a function... how to do that?
|
1069
|
-
const useForwardedRef = (forwardedRef, defaultValue = null) => {
|
1070
|
-
const innerRef = useRef(defaultValue);
|
1071
|
-
|
1072
|
-
// Update the forwarded ref when the inner ref changes
|
1073
|
-
if (forwardedRef && typeof forwardedRef !== "function") {
|
1074
|
-
if (!forwardedRef.current) {
|
1075
|
-
forwardedRef.current = innerRef.current;
|
1076
|
-
}
|
1077
|
-
return forwardedRef;
|
1078
|
-
}
|
1079
|
-
return innerRef;
|
1080
|
-
};
|
1081
|
-
|
1082
1232
|
/**
|
1083
1233
|
* A collider is a shape that can be attached to a rigid body to define its physical properties.
|
1084
1234
|
* @internal
|
1085
1235
|
*/
|
1086
|
-
const AnyCollider = /*#__PURE__*/memo(
|
1236
|
+
const AnyCollider = /*#__PURE__*/memo(props => {
|
1087
1237
|
const {
|
1088
1238
|
children,
|
1089
1239
|
position,
|
@@ -1098,16 +1248,18 @@ const AnyCollider = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedR
|
|
1098
1248
|
colliderStates
|
1099
1249
|
} = useRapier();
|
1100
1250
|
const rigidBodyContext = useRigidBodyContext();
|
1101
|
-
const colliderRef = useForwardedRef(
|
1251
|
+
const colliderRef = useForwardedRef(props.ref);
|
1102
1252
|
const objectRef = useRef(null);
|
1103
1253
|
|
1104
1254
|
// We spread the props out here to make sure that the ref is updated when the props change.
|
1105
|
-
const immutablePropArray = immutableColliderOptions.flatMap(key =>
|
1255
|
+
const immutablePropArray = immutableColliderOptions.flatMap(key =>
|
1256
|
+
// Array.isArray(props[key]) ? [...props[key]] : props[key]
|
1257
|
+
Array.isArray(props[key]) ? props[key] : [props[key]]);
|
1106
1258
|
const getInstance = useImperativeInstance(() => {
|
1107
1259
|
const worldScale = objectRef.current.getWorldScale(vec3());
|
1108
1260
|
const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
|
1109
|
-
if (typeof
|
1110
|
-
|
1261
|
+
if (typeof props.ref == "function") {
|
1262
|
+
props.ref(collider);
|
1111
1263
|
}
|
1112
1264
|
colliderRef.current = collider;
|
1113
1265
|
return collider;
|
@@ -1136,7 +1288,7 @@ const AnyCollider = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedR
|
|
1136
1288
|
ref: objectRef,
|
1137
1289
|
name: name
|
1138
1290
|
}, children);
|
1139
|
-
})
|
1291
|
+
});
|
1140
1292
|
/**
|
1141
1293
|
* A cuboid collider shape
|
1142
1294
|
* @category Colliders
|
@@ -1239,165 +1391,16 @@ const ConvexHullCollider = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PU
|
|
1239
1391
|
})));
|
1240
1392
|
ConvexHullCollider.displayName = "ConvexHullCollider";
|
1241
1393
|
|
1242
|
-
const
|
1243
|
-
var _options$canSleep;
|
1244
|
-
const type = rigidBodyTypeFromString((options === null || options === void 0 ? void 0 : options.type) || "dynamic");
|
1245
|
-
const desc = new RigidBodyDesc(type);
|
1246
|
-
|
1247
|
-
// Apply immutable options
|
1248
|
-
desc.canSleep = (_options$canSleep = options === null || options === void 0 ? void 0 : options.canSleep) !== null && _options$canSleep !== void 0 ? _options$canSleep : true;
|
1249
|
-
return desc;
|
1250
|
-
};
|
1251
|
-
const createRigidBodyState = ({
|
1252
|
-
rigidBody,
|
1253
|
-
object,
|
1254
|
-
setMatrix,
|
1255
|
-
getMatrix,
|
1256
|
-
worldScale,
|
1257
|
-
meshType: _meshType = "mesh"
|
1258
|
-
}) => {
|
1259
|
-
object.updateWorldMatrix(true, false);
|
1260
|
-
const invertedWorldMatrix = object.parent.matrixWorld.clone().invert();
|
1261
|
-
return {
|
1262
|
-
object,
|
1263
|
-
rigidBody,
|
1264
|
-
invertedWorldMatrix,
|
1265
|
-
setMatrix: setMatrix ? setMatrix : matrix => {
|
1266
|
-
object.matrix.copy(matrix);
|
1267
|
-
},
|
1268
|
-
getMatrix: getMatrix ? getMatrix : matrix => matrix.copy(object.matrix),
|
1269
|
-
scale: worldScale || object.getWorldScale(_scale).clone(),
|
1270
|
-
isSleeping: false,
|
1271
|
-
meshType: _meshType
|
1272
|
-
};
|
1273
|
-
};
|
1274
|
-
const immutableRigidBodyOptions = ["args", "colliders", "canSleep"];
|
1275
|
-
const mutableRigidBodyOptions = {
|
1276
|
-
gravityScale: (rb, value) => {
|
1277
|
-
rb.setGravityScale(value, true);
|
1278
|
-
},
|
1279
|
-
additionalSolverIterations(rb, value) {
|
1280
|
-
rb.setAdditionalSolverIterations(value);
|
1281
|
-
},
|
1282
|
-
linearDamping: (rb, value) => {
|
1283
|
-
rb.setLinearDamping(value);
|
1284
|
-
},
|
1285
|
-
angularDamping: (rb, value) => {
|
1286
|
-
rb.setAngularDamping(value);
|
1287
|
-
},
|
1288
|
-
dominanceGroup: (rb, value) => {
|
1289
|
-
rb.setDominanceGroup(value);
|
1290
|
-
},
|
1291
|
-
enabledRotations: (rb, [x, y, z]) => {
|
1292
|
-
rb.setEnabledRotations(x, y, z, true);
|
1293
|
-
},
|
1294
|
-
enabledTranslations: (rb, [x, y, z]) => {
|
1295
|
-
rb.setEnabledTranslations(x, y, z, true);
|
1296
|
-
},
|
1297
|
-
lockRotations: (rb, value) => {
|
1298
|
-
rb.lockRotations(value, true);
|
1299
|
-
},
|
1300
|
-
lockTranslations: (rb, value) => {
|
1301
|
-
rb.lockTranslations(value, true);
|
1302
|
-
},
|
1303
|
-
angularVelocity: (rb, [x, y, z]) => {
|
1304
|
-
rb.setAngvel({
|
1305
|
-
x,
|
1306
|
-
y,
|
1307
|
-
z
|
1308
|
-
}, true);
|
1309
|
-
},
|
1310
|
-
linearVelocity: (rb, [x, y, z]) => {
|
1311
|
-
rb.setLinvel({
|
1312
|
-
x,
|
1313
|
-
y,
|
1314
|
-
z
|
1315
|
-
}, true);
|
1316
|
-
},
|
1317
|
-
ccd: (rb, value) => {
|
1318
|
-
rb.enableCcd(value);
|
1319
|
-
},
|
1320
|
-
softCcdPrediction: (rb, value) => {
|
1321
|
-
rb.setSoftCcdPrediction(value);
|
1322
|
-
},
|
1323
|
-
userData: (rb, value) => {
|
1324
|
-
rb.userData = value;
|
1325
|
-
},
|
1326
|
-
type(rb, value) {
|
1327
|
-
rb.setBodyType(rigidBodyTypeFromString(value), true);
|
1328
|
-
},
|
1329
|
-
position: () => {},
|
1330
|
-
rotation: () => {},
|
1331
|
-
quaternion: () => {},
|
1332
|
-
scale: () => {}
|
1333
|
-
};
|
1334
|
-
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
1335
|
-
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
1336
|
-
if (!rigidBody) {
|
1337
|
-
return;
|
1338
|
-
}
|
1339
|
-
const state = states.get(rigidBody.handle);
|
1340
|
-
if (state) {
|
1341
|
-
if (updateTranslations) {
|
1342
|
-
state.object.updateWorldMatrix(true, false);
|
1343
|
-
_matrix4.copy(state.object.matrixWorld).decompose(_position, _rotation, _scale);
|
1344
|
-
rigidBody.setTranslation(_position, false);
|
1345
|
-
rigidBody.setRotation(_rotation, false);
|
1346
|
-
}
|
1347
|
-
mutableRigidBodyOptionKeys.forEach(key => {
|
1348
|
-
if (key in options) {
|
1349
|
-
mutableRigidBodyOptions[key](rigidBody, options[key]);
|
1350
|
-
}
|
1351
|
-
});
|
1352
|
-
}
|
1353
|
-
};
|
1354
|
-
const useUpdateRigidBodyOptions = (getRigidBody, props, states, updateTranslations = true) => {
|
1355
|
-
// TODO: Improve this, split each prop into its own effect
|
1356
|
-
const mutablePropsAsFlatArray = useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
1357
|
-
return vectorToTuple(props[key]);
|
1358
|
-
}), [props]);
|
1359
|
-
useEffect(() => {
|
1360
|
-
const rigidBody = getRigidBody();
|
1361
|
-
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
1362
|
-
}, mutablePropsAsFlatArray);
|
1363
|
-
};
|
1364
|
-
const useRigidBodyEvents = (getRigidBody, props, events) => {
|
1365
|
-
const {
|
1366
|
-
onWake,
|
1367
|
-
onSleep,
|
1368
|
-
onCollisionEnter,
|
1369
|
-
onCollisionExit,
|
1370
|
-
onIntersectionEnter,
|
1371
|
-
onIntersectionExit,
|
1372
|
-
onContactForce
|
1373
|
-
} = props;
|
1374
|
-
const eventHandlers = {
|
1375
|
-
onWake,
|
1376
|
-
onSleep,
|
1377
|
-
onCollisionEnter,
|
1378
|
-
onCollisionExit,
|
1379
|
-
onIntersectionEnter,
|
1380
|
-
onIntersectionExit,
|
1381
|
-
onContactForce
|
1382
|
-
};
|
1383
|
-
useEffect(() => {
|
1384
|
-
const rigidBody = getRigidBody();
|
1385
|
-
events.set(rigidBody.handle, eventHandlers);
|
1386
|
-
return () => {
|
1387
|
-
events.delete(rigidBody.handle);
|
1388
|
-
};
|
1389
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1390
|
-
};
|
1391
|
-
|
1392
|
-
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1394
|
+
const _excluded$1 = ["ref", "children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1393
1395
|
const RigidBodyContext = /*#__PURE__*/createContext(undefined);
|
1394
1396
|
const useRigidBodyContext = () => useContext(RigidBodyContext);
|
1395
1397
|
/**
|
1396
1398
|
* A rigid body is a physical object that can be simulated by the physics engine.
|
1397
1399
|
* @category Components
|
1398
1400
|
*/
|
1399
|
-
const RigidBody = /*#__PURE__*/memo(
|
1401
|
+
const RigidBody = /*#__PURE__*/memo(props => {
|
1400
1402
|
const {
|
1403
|
+
ref,
|
1401
1404
|
children,
|
1402
1405
|
type,
|
1403
1406
|
position,
|
@@ -1408,7 +1411,7 @@ const RigidBody = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef
|
|
1408
1411
|
} = props,
|
1409
1412
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1410
1413
|
const objectRef = useRef(null);
|
1411
|
-
const rigidBodyRef = useForwardedRef(
|
1414
|
+
const rigidBodyRef = useForwardedRef(ref);
|
1412
1415
|
const {
|
1413
1416
|
world,
|
1414
1417
|
rigidBodyStates,
|
@@ -1429,8 +1432,8 @@ const RigidBody = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef
|
|
1429
1432
|
const getRigidBody = useImperativeInstance(() => {
|
1430
1433
|
const desc = rigidBodyDescFromOptions(mergedOptions);
|
1431
1434
|
const rigidBody = world.createRigidBody(desc);
|
1432
|
-
if (typeof
|
1433
|
-
|
1435
|
+
if (typeof ref === "function") {
|
1436
|
+
ref(rigidBody);
|
1434
1437
|
}
|
1435
1438
|
rigidBodyRef.current = rigidBody;
|
1436
1439
|
return rigidBody;
|
@@ -1473,7 +1476,7 @@ const RigidBody = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, forwardedRef
|
|
1473
1476
|
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React.createElement(AnyCollider, _extends({
|
1474
1477
|
key: index
|
1475
1478
|
}, colliderProps)))));
|
1476
|
-
})
|
1479
|
+
});
|
1477
1480
|
RigidBody.displayName = "RigidBody";
|
1478
1481
|
|
1479
1482
|
/**
|
@@ -1510,9 +1513,14 @@ const MeshCollider = /*#__PURE__*/memo(props => {
|
|
1510
1513
|
});
|
1511
1514
|
MeshCollider.displayName = "MeshCollider";
|
1512
1515
|
|
1513
|
-
const _excluded = ["
|
1514
|
-
|
1515
|
-
|
1516
|
+
const _excluded = ["ref"],
|
1517
|
+
_excluded2 = ["children", "instances", "colliderNodes", "position", "rotation", "quaternion", "scale"];
|
1518
|
+
const InstancedRigidBodies = /*#__PURE__*/memo(_ref => {
|
1519
|
+
let {
|
1520
|
+
ref
|
1521
|
+
} = _ref,
|
1522
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
1523
|
+
const rigidBodiesRef = useForwardedRef(ref, []);
|
1516
1524
|
const objectRef = useRef(null);
|
1517
1525
|
const instanceWrapperRef = useRef(null);
|
1518
1526
|
const {
|
@@ -1528,7 +1536,7 @@ const InstancedRigidBodies = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, f
|
|
1528
1536
|
|
1529
1537
|
// rigid body specific props, and r3f-object props
|
1530
1538
|
} = props,
|
1531
|
-
rigidBodyProps = _objectWithoutProperties(props,
|
1539
|
+
rigidBodyProps = _objectWithoutProperties(props, _excluded2);
|
1532
1540
|
const childColliderProps = useChildColliderProps(objectRef, _objectSpread2(_objectSpread2({}, props), {}, {
|
1533
1541
|
children: undefined
|
1534
1542
|
}));
|
@@ -1576,14 +1584,16 @@ const InstancedRigidBodies = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((props, f
|
|
1576
1584
|
}), /*#__PURE__*/React.createElement("object3D", {
|
1577
1585
|
ref: instanceWrapperRef
|
1578
1586
|
}, children), instances === null || instances === void 0 ? void 0 : instances.map((instance, index) => /*#__PURE__*/React.createElement(RigidBody, _extends({}, rigidBodyProps, instance, {
|
1579
|
-
ref: body =>
|
1587
|
+
ref: body => {
|
1588
|
+
rigidBodiesRef.current[index] = body;
|
1589
|
+
},
|
1580
1590
|
transformState: state => applyInstancedState(state, index)
|
1581
1591
|
}), /*#__PURE__*/React.createElement(React.Fragment, null, colliderNodes.map((node, index) => /*#__PURE__*/React.createElement(Fragment, {
|
1582
1592
|
key: index
|
1583
1593
|
}, node)), childColliderProps.map((colliderProps, colliderIndex) => /*#__PURE__*/React.createElement(AnyCollider, _extends({
|
1584
1594
|
key: colliderIndex
|
1585
1595
|
}, colliderProps)))))));
|
1586
|
-
})
|
1596
|
+
});
|
1587
1597
|
InstancedRigidBodies.displayName = "InstancedRigidBodies";
|
1588
1598
|
|
1589
1599
|
/**
|
@@ -1593,7 +1603,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1593
1603
|
const {
|
1594
1604
|
world
|
1595
1605
|
} = useRapier();
|
1596
|
-
const jointRef = useRef();
|
1606
|
+
const jointRef = useRef(undefined);
|
1597
1607
|
useImperativeInstance(() => {
|
1598
1608
|
if (body1.current && body2.current) {
|
1599
1609
|
const newJoint = world.createImpulseJoint(params, body1.current, body2.current, true);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-three/rapier",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
4
4
|
"source": "src/index.ts",
|
5
5
|
"main": "dist/react-three-rapier.cjs.js",
|
6
6
|
"module": "dist/react-three-rapier.esm.js",
|
@@ -9,24 +9,25 @@
|
|
9
9
|
"dist"
|
10
10
|
],
|
11
11
|
"devDependencies": {
|
12
|
-
"@react-three/drei": "
|
13
|
-
"@react-three/fiber": "
|
14
|
-
"@react-three/test-renderer": "
|
15
|
-
"@types/react
|
16
|
-
"@types/
|
17
|
-
"
|
18
|
-
"react
|
19
|
-
"
|
12
|
+
"@react-three/drei": "10.0.1",
|
13
|
+
"@react-three/fiber": "9.0.4",
|
14
|
+
"@react-three/test-renderer": "9.0.1",
|
15
|
+
"@types/react": "19.0.8",
|
16
|
+
"@types/react-dom": "19.0.3",
|
17
|
+
"@types/three": "0.172.0",
|
18
|
+
"react": "19.0.0",
|
19
|
+
"react-dom": "19.0.0",
|
20
|
+
"three": "0.172.0"
|
20
21
|
},
|
21
22
|
"peerDependencies": {
|
22
|
-
"@react-three/fiber": "
|
23
|
-
"react": "
|
24
|
-
"three": ">=0.
|
23
|
+
"@react-three/fiber": "^9.0.4",
|
24
|
+
"react": "^19",
|
25
|
+
"three": ">=0.159.0"
|
25
26
|
},
|
26
27
|
"dependencies": {
|
27
28
|
"@dimforge/rapier3d-compat": "0.14.0",
|
28
29
|
"suspend-react": "^0.1.3",
|
29
|
-
"three-stdlib": "^2.
|
30
|
+
"three-stdlib": "^2.35.12"
|
30
31
|
},
|
31
32
|
"repository": "https://github.com/pmndrs/react-three-rapier/tree/master/packages/react-three-rapier"
|
32
33
|
}
|