@react-three/rapier 0.7.6 → 0.8.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/Debug.d.ts +0 -8
- package/dist/declarations/src/api.d.ts +7 -6
- package/dist/declarations/src/bitmasks.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +9 -5
- package/dist/declarations/src/utils-collider.d.ts +2 -2
- package/dist/react-three-rapier.cjs.dev.js +110 -249
- package/dist/react-three-rapier.cjs.prod.js +110 -249
- package/dist/react-three-rapier.esm.js +87 -226
- package/package.json +9 -6
- package/readme.md +12 -7
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
5
|
var rapier3dCompat = require('@dimforge/rapier3d-compat');
|
6
|
-
var React = require('react');
|
6
|
+
var React$1 = require('react');
|
7
7
|
var useAsset = require('use-asset');
|
8
8
|
var fiber = require('@react-three/fiber');
|
9
9
|
var three = require('three');
|
@@ -29,7 +29,7 @@ function _interopNamespace(e) {
|
|
29
29
|
return Object.freeze(n);
|
30
30
|
}
|
31
31
|
|
32
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
32
|
+
var React__default = /*#__PURE__*/_interopDefault(React$1);
|
33
33
|
|
34
34
|
const _quaternion = new three.Quaternion();
|
35
35
|
new three.Euler();
|
@@ -198,10 +198,19 @@ const createWorldApi = ref => {
|
|
198
198
|
getRigidBody: handle => ref.current().getRigidBody(handle),
|
199
199
|
createRigidBody: desc => ref.current().createRigidBody(desc),
|
200
200
|
createCollider: (desc, rigidBody) => ref.current().createCollider(desc, rigidBody),
|
201
|
-
removeRigidBody: rigidBody =>
|
202
|
-
|
201
|
+
removeRigidBody: rigidBody => {
|
202
|
+
if (!ref.current().bodies.contains(rigidBody.handle)) return;
|
203
|
+
ref.current().removeRigidBody(rigidBody);
|
204
|
+
},
|
205
|
+
removeCollider: (collider, wakeUp = true) => {
|
206
|
+
if (!ref.current().colliders.contains(collider.handle)) return;
|
207
|
+
ref.current().removeCollider(collider, wakeUp);
|
208
|
+
},
|
203
209
|
createImpulseJoint: (params, rigidBodyA, rigidBodyB, wakeUp = true) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB, wakeUp),
|
204
|
-
removeImpulseJoint: (joint, wakeUp = true) =>
|
210
|
+
removeImpulseJoint: (joint, wakeUp = true) => {
|
211
|
+
if (!ref.current().impulseJoints.contains(joint.handle)) return;
|
212
|
+
ref.current().removeImpulseJoint(joint, wakeUp);
|
213
|
+
},
|
205
214
|
forEachCollider: callback => ref.current().forEachCollider(callback),
|
206
215
|
setGravity: ({
|
207
216
|
x,
|
@@ -211,7 +220,8 @@ const createWorldApi = ref => {
|
|
211
220
|
x,
|
212
221
|
y,
|
213
222
|
z
|
214
|
-
}
|
223
|
+
},
|
224
|
+
debugRender: () => ref.current().debugRender()
|
215
225
|
};
|
216
226
|
}; // TODO: Broken currently, waiting for Rapier3D to fix
|
217
227
|
|
@@ -228,7 +238,7 @@ const createJointApi = ref => {
|
|
228
238
|
};
|
229
239
|
};
|
230
240
|
|
231
|
-
const RapierContext = /*#__PURE__*/React.createContext(undefined);
|
241
|
+
const RapierContext = /*#__PURE__*/React$1.createContext(undefined);
|
232
242
|
|
233
243
|
const importRapier = async () => {
|
234
244
|
let r = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@dimforge/rapier3d-compat')); });
|
@@ -245,12 +255,8 @@ const Physics = ({
|
|
245
255
|
updatePriority
|
246
256
|
}) => {
|
247
257
|
const rapier = useAsset.useAsset(importRapier);
|
248
|
-
const
|
249
|
-
React.
|
250
|
-
setIsPaused(_paused);
|
251
|
-
}, [_paused]);
|
252
|
-
const worldRef = React.useRef();
|
253
|
-
const getWorldRef = React.useRef(() => {
|
258
|
+
const worldRef = React$1.useRef();
|
259
|
+
const getWorldRef = React$1.useRef(() => {
|
254
260
|
if (!worldRef.current) {
|
255
261
|
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
256
262
|
worldRef.current = world;
|
@@ -258,29 +264,30 @@ const Physics = ({
|
|
258
264
|
|
259
265
|
return worldRef.current;
|
260
266
|
});
|
261
|
-
const [rigidBodyStates] = React.useState(() => new Map());
|
262
|
-
const [colliderStates] = React.useState(() => new Map());
|
263
|
-
const [rigidBodyEvents] = React.useState(() => new Map());
|
264
|
-
const [colliderEvents] = React.useState(() => new Map());
|
265
|
-
const [eventQueue] = React.useState(() => new rapier3dCompat.EventQueue(false)); // Init world
|
267
|
+
const [rigidBodyStates] = React$1.useState(() => new Map());
|
268
|
+
const [colliderStates] = React$1.useState(() => new Map());
|
269
|
+
const [rigidBodyEvents] = React$1.useState(() => new Map());
|
270
|
+
const [colliderEvents] = React$1.useState(() => new Map());
|
271
|
+
const [eventQueue] = React$1.useState(() => new rapier3dCompat.EventQueue(false)); // Init world
|
266
272
|
|
267
|
-
React.useEffect(() => {
|
273
|
+
React$1.useEffect(() => {
|
268
274
|
const world = getWorldRef.current();
|
269
275
|
return () => {
|
270
276
|
if (world) {
|
271
277
|
world.free();
|
278
|
+
worldRef.current = undefined;
|
272
279
|
}
|
273
280
|
};
|
274
281
|
}, []); // Update gravity
|
275
282
|
|
276
|
-
React.useEffect(() => {
|
283
|
+
React$1.useEffect(() => {
|
277
284
|
const world = worldRef.current;
|
278
285
|
|
279
286
|
if (world) {
|
280
287
|
world.gravity = vectorArrayToVector3(_gravity);
|
281
288
|
}
|
282
289
|
}, [_gravity]);
|
283
|
-
const [steppingState] = React.useState({
|
290
|
+
const [steppingState] = React$1.useState({
|
284
291
|
accumulator: 0
|
285
292
|
});
|
286
293
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
@@ -490,8 +497,8 @@ const Physics = ({
|
|
490
497
|
}
|
491
498
|
});
|
492
499
|
}, updatePriority);
|
493
|
-
const api = React.useMemo(() => createWorldApi(getWorldRef), []);
|
494
|
-
const context = React.useMemo(() => ({
|
500
|
+
const api = React$1.useMemo(() => createWorldApi(getWorldRef), []);
|
501
|
+
const context = React$1.useMemo(() => ({
|
495
502
|
rapier,
|
496
503
|
world: api,
|
497
504
|
physicsOptions: {
|
@@ -502,15 +509,15 @@ const Physics = ({
|
|
502
509
|
colliderStates,
|
503
510
|
rigidBodyEvents,
|
504
511
|
colliderEvents,
|
505
|
-
isPaused
|
506
|
-
}), [
|
512
|
+
isPaused: _paused
|
513
|
+
}), [_paused]);
|
507
514
|
return /*#__PURE__*/React__default["default"].createElement(RapierContext.Provider, {
|
508
515
|
value: context
|
509
516
|
}, children);
|
510
517
|
};
|
511
518
|
|
512
519
|
function _extends() {
|
513
|
-
_extends = Object.assign
|
520
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
514
521
|
for (var i = 1; i < arguments.length; i++) {
|
515
522
|
var source = arguments[i];
|
516
523
|
|
@@ -523,7 +530,6 @@ function _extends() {
|
|
523
530
|
|
524
531
|
return target;
|
525
532
|
};
|
526
|
-
|
527
533
|
return _extends.apply(this, arguments);
|
528
534
|
}
|
529
535
|
|
@@ -693,15 +699,15 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
693
699
|
};
|
694
700
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
695
701
|
// TODO: Improve this, split each prop into its own effect
|
696
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
702
|
+
const mutablePropsAsFlatArray = React$1.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
697
703
|
return vectorToTuple(props[key]);
|
698
704
|
}), [props]);
|
699
|
-
React.useEffect(() => {
|
700
|
-
if (
|
701
|
-
rigidBodyRef.current
|
705
|
+
React$1.useEffect(() => {
|
706
|
+
if (Array.isArray(rigidBodyRef.current)) {
|
707
|
+
for (const rigidBody of rigidBodyRef.current) {
|
702
708
|
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
703
|
-
}
|
704
|
-
} else {
|
709
|
+
}
|
710
|
+
} else if (rigidBodyRef.current) {
|
705
711
|
setRigidBodyOptions(rigidBodyRef.current, props, states, updateTranslations);
|
706
712
|
}
|
707
713
|
}, mutablePropsAsFlatArray);
|
@@ -723,21 +729,21 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
723
729
|
onIntersectionEnter,
|
724
730
|
onIntersectionExit
|
725
731
|
};
|
726
|
-
React.useEffect(() => {
|
727
|
-
if (
|
728
|
-
rigidBodyRef.current
|
732
|
+
React$1.useEffect(() => {
|
733
|
+
if (Array.isArray(rigidBodyRef.current)) {
|
734
|
+
for (const rigidBody of rigidBodyRef.current) {
|
729
735
|
events.set(rigidBody.handle, eventHandlers);
|
730
|
-
}
|
731
|
-
} else {
|
736
|
+
}
|
737
|
+
} else if (rigidBodyRef.current) {
|
732
738
|
events.set(rigidBodyRef.current.handle, eventHandlers);
|
733
739
|
}
|
734
740
|
|
735
741
|
return () => {
|
736
|
-
if (
|
737
|
-
rigidBodyRef.current
|
742
|
+
if (Array.isArray(rigidBodyRef.current)) {
|
743
|
+
for (const rigidBody of rigidBodyRef.current) {
|
738
744
|
events.delete(rigidBody.handle);
|
739
|
-
}
|
740
|
-
} else {
|
745
|
+
}
|
746
|
+
} else if (rigidBodyRef.current) {
|
741
747
|
events.delete(rigidBodyRef.current.handle);
|
742
748
|
}
|
743
749
|
};
|
@@ -866,10 +872,10 @@ const setColliderOptions = (collider, options, states) => {
|
|
866
872
|
};
|
867
873
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
868
874
|
// TODO: Improve this, split each prop into its own effect
|
869
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
875
|
+
const mutablePropsAsFlatArray = React$1.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
870
876
|
return vectorToTuple(props[key]);
|
871
877
|
}), [props]);
|
872
|
-
React.useEffect(() => {
|
878
|
+
React$1.useEffect(() => {
|
873
879
|
collidersRef.current.forEach(collider => {
|
874
880
|
setColliderOptions(collider, props, states);
|
875
881
|
});
|
@@ -905,7 +911,8 @@ const createColliderPropsFromChildren = ({
|
|
905
911
|
const colliderProps = [];
|
906
912
|
object.updateWorldMatrix(true, false);
|
907
913
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
908
|
-
|
914
|
+
|
915
|
+
const colliderFromChild = child => {
|
909
916
|
if ("isMesh" in child) {
|
910
917
|
if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
|
911
918
|
const worldScale = child.getWorldScale(_scale);
|
@@ -930,7 +937,14 @@ const createColliderPropsFromChildren = ({
|
|
930
937
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
931
938
|
}));
|
932
939
|
}
|
933
|
-
}
|
940
|
+
};
|
941
|
+
|
942
|
+
if (options.includeInvisible) {
|
943
|
+
object.traverse(colliderFromChild);
|
944
|
+
} else {
|
945
|
+
object.traverseVisible(colliderFromChild);
|
946
|
+
}
|
947
|
+
|
934
948
|
return colliderProps;
|
935
949
|
};
|
936
950
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
@@ -994,7 +1008,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
994
1008
|
onIntersectionEnter,
|
995
1009
|
onIntersectionExit
|
996
1010
|
} = props;
|
997
|
-
React.useEffect(() => {
|
1011
|
+
React$1.useEffect(() => {
|
998
1012
|
var _collidersRef$current;
|
999
1013
|
|
1000
1014
|
(_collidersRef$current = collidersRef.current) === null || _collidersRef$current === void 0 ? void 0 : _collidersRef$current.forEach(collider => {
|
@@ -1018,11 +1032,11 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
1018
1032
|
};
|
1019
1033
|
|
1020
1034
|
const useRapier = () => {
|
1021
|
-
return React.useContext(RapierContext);
|
1035
|
+
return React$1.useContext(RapierContext);
|
1022
1036
|
};
|
1023
1037
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
1024
|
-
const [colliderProps, setColliderProps] = React.useState([]);
|
1025
|
-
React.useEffect(() => {
|
1038
|
+
const [colliderProps, setColliderProps] = React$1.useState([]);
|
1039
|
+
React$1.useEffect(() => {
|
1026
1040
|
const object = ref.current;
|
1027
1041
|
|
1028
1042
|
if (object && options.colliders !== false) {
|
@@ -1042,16 +1056,16 @@ const useRigidBody = (options = {}) => {
|
|
1042
1056
|
physicsOptions,
|
1043
1057
|
rigidBodyEvents
|
1044
1058
|
} = useRapier();
|
1045
|
-
const ref = React.useRef();
|
1046
|
-
const mergedOptions = React.useMemo(() => {
|
1059
|
+
const ref = React$1.useRef();
|
1060
|
+
const mergedOptions = React$1.useMemo(() => {
|
1047
1061
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1048
1062
|
children: undefined
|
1049
1063
|
});
|
1050
1064
|
}, [physicsOptions, options]);
|
1051
1065
|
const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
|
1052
1066
|
|
1053
|
-
const rigidBodyRef = React.useRef();
|
1054
|
-
const getRigidBodyRef = React.useRef(() => {
|
1067
|
+
const rigidBodyRef = React$1.useRef();
|
1068
|
+
const getRigidBodyRef = React$1.useRef(() => {
|
1055
1069
|
if (!rigidBodyRef.current) {
|
1056
1070
|
const desc = rigidBodyDescFromOptions(options);
|
1057
1071
|
const rigidBody = world.createRigidBody(desc);
|
@@ -1061,7 +1075,7 @@ const useRigidBody = (options = {}) => {
|
|
1061
1075
|
return rigidBodyRef.current;
|
1062
1076
|
}); // Setup
|
1063
1077
|
|
1064
|
-
React.useEffect(() => {
|
1078
|
+
React$1.useEffect(() => {
|
1065
1079
|
const rigidBody = getRigidBodyRef.current();
|
1066
1080
|
rigidBodyRef.current = rigidBody;
|
1067
1081
|
|
@@ -1078,11 +1092,12 @@ const useRigidBody = (options = {}) => {
|
|
1078
1092
|
return () => {
|
1079
1093
|
world.removeRigidBody(rigidBody);
|
1080
1094
|
rigidBodyStates.delete(rigidBody.handle);
|
1095
|
+
rigidBodyRef.current = undefined;
|
1081
1096
|
};
|
1082
1097
|
}, []);
|
1083
1098
|
useUpdateRigidBodyOptions(rigidBodyRef, mergedOptions, rigidBodyStates);
|
1084
1099
|
useRigidBodyEvents(rigidBodyRef, mergedOptions, rigidBodyEvents);
|
1085
|
-
const api = React.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
1100
|
+
const api = React$1.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
1086
1101
|
return [ref, api, childColliderProps];
|
1087
1102
|
}; // Joints
|
1088
1103
|
|
@@ -1090,8 +1105,8 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1090
1105
|
const {
|
1091
1106
|
world
|
1092
1107
|
} = useRapier();
|
1093
|
-
const jointRef = React.useRef();
|
1094
|
-
const getJointRef = React.useRef(() => {
|
1108
|
+
const jointRef = React$1.useRef();
|
1109
|
+
const getJointRef = React$1.useRef(() => {
|
1095
1110
|
if (!jointRef.current) {
|
1096
1111
|
let rb1;
|
1097
1112
|
let rb2;
|
@@ -1106,7 +1121,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1106
1121
|
|
1107
1122
|
return jointRef.current;
|
1108
1123
|
});
|
1109
|
-
React.useEffect(() => {
|
1124
|
+
React$1.useEffect(() => {
|
1110
1125
|
const joint = getJointRef.current();
|
1111
1126
|
return () => {
|
1112
1127
|
if (joint) {
|
@@ -1115,7 +1130,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1115
1130
|
}
|
1116
1131
|
};
|
1117
1132
|
}, []);
|
1118
|
-
const api = React.useMemo(() => createJointApi(getJointRef), []);
|
1133
|
+
const api = React$1.useMemo(() => createJointApi(getJointRef), []);
|
1119
1134
|
return api;
|
1120
1135
|
};
|
1121
1136
|
/**
|
@@ -1174,7 +1189,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
1174
1189
|
};
|
1175
1190
|
|
1176
1191
|
// Colliders
|
1177
|
-
const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["default"].forwardRef((props, forwardedRef) => {
|
1192
|
+
const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["default"].forwardRef((props, forwardedRef) => {
|
1178
1193
|
const {
|
1179
1194
|
children,
|
1180
1195
|
position,
|
@@ -1188,8 +1203,8 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["defaul
|
|
1188
1203
|
colliderStates
|
1189
1204
|
} = useRapier();
|
1190
1205
|
const rigidBodyContext = useRigidBodyContext();
|
1191
|
-
const ref = React.useRef(null);
|
1192
|
-
const collidersRef = React.useMemo(() => {
|
1206
|
+
const ref = React$1.useRef(null);
|
1207
|
+
const collidersRef = React$1.useMemo(() => {
|
1193
1208
|
if (forwardedRef !== null) {
|
1194
1209
|
return forwardedRef;
|
1195
1210
|
}
|
@@ -1198,7 +1213,7 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["defaul
|
|
1198
1213
|
result.current = [];
|
1199
1214
|
return result;
|
1200
1215
|
}, []);
|
1201
|
-
React.useEffect(() => {
|
1216
|
+
React$1.useEffect(() => {
|
1202
1217
|
const object = ref.current;
|
1203
1218
|
const worldScale = object.getWorldScale(new three.Vector3());
|
1204
1219
|
const colliders = []; // If this is an InstancedRigidBody api
|
@@ -1230,7 +1245,7 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["defaul
|
|
1230
1245
|
});
|
1231
1246
|
};
|
1232
1247
|
}, []);
|
1233
|
-
const mergedProps = React.useMemo(() => {
|
1248
|
+
const mergedProps = React$1.useMemo(() => {
|
1234
1249
|
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1235
1250
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1236
1251
|
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
@@ -1299,9 +1314,9 @@ const ConvexHullCollider = /*#__PURE__*/React__default["default"].forwardRef((pr
|
|
1299
1314
|
});
|
1300
1315
|
|
1301
1316
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1302
|
-
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1303
|
-
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1304
|
-
const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, ref) => {
|
1317
|
+
const RigidBodyContext = /*#__PURE__*/React$1.createContext(undefined);
|
1318
|
+
const useRigidBodyContext = () => React$1.useContext(RigidBodyContext);
|
1319
|
+
const RigidBody = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
1305
1320
|
const {
|
1306
1321
|
children,
|
1307
1322
|
type,
|
@@ -1313,8 +1328,8 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
|
|
1313
1328
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1314
1329
|
|
1315
1330
|
const [object, api, childColliderProps] = useRigidBody(props);
|
1316
|
-
React.useImperativeHandle(ref, () => api);
|
1317
|
-
const contextValue = React.useMemo(() => ({
|
1331
|
+
React$1.useImperativeHandle(ref, () => api);
|
1332
|
+
const contextValue = React$1.useMemo(() => ({
|
1318
1333
|
ref: object,
|
1319
1334
|
api,
|
1320
1335
|
options: props
|
@@ -1342,11 +1357,11 @@ const MeshCollider = props => {
|
|
1342
1357
|
physicsOptions,
|
1343
1358
|
world
|
1344
1359
|
} = useRapier();
|
1345
|
-
const object = React.useRef(null);
|
1360
|
+
const object = React$1.useRef(null);
|
1346
1361
|
const {
|
1347
1362
|
options
|
1348
1363
|
} = useRigidBodyContext();
|
1349
|
-
const mergedOptions = React.useMemo(() => {
|
1364
|
+
const mergedOptions = React$1.useMemo(() => {
|
1350
1365
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1351
1366
|
children: undefined,
|
1352
1367
|
colliders: type
|
@@ -1363,189 +1378,35 @@ const MeshCollider = props => {
|
|
1363
1378
|
}, colliderProps))));
|
1364
1379
|
};
|
1365
1380
|
|
1366
|
-
const
|
1367
|
-
switch (collider.shape.type) {
|
1368
|
-
case rapier3dCompat.ShapeType.Cuboid:
|
1369
|
-
{
|
1370
|
-
const {
|
1371
|
-
x,
|
1372
|
-
y,
|
1373
|
-
z
|
1374
|
-
} = collider.shape.halfExtents;
|
1375
|
-
return new three.BoxGeometry(x * 2 + 0.01, y * 2 + 0.01, z * 2 + 0.01);
|
1376
|
-
}
|
1377
|
-
|
1378
|
-
case rapier3dCompat.ShapeType.RoundCuboid:
|
1379
|
-
{
|
1380
|
-
const {
|
1381
|
-
x,
|
1382
|
-
y,
|
1383
|
-
z
|
1384
|
-
} = collider.shape.halfExtents;
|
1385
|
-
const radius = collider.shape.borderRadius;
|
1386
|
-
return new threeStdlib.RoundedBoxGeometry(x * 2 + radius * 2, y * 2 + radius * 2, z * 2 + radius * 2, 8, radius);
|
1387
|
-
}
|
1388
|
-
|
1389
|
-
case rapier3dCompat.ShapeType.Ball:
|
1390
|
-
{
|
1391
|
-
const r = collider.shape.radius;
|
1392
|
-
return new three.SphereGeometry(r + +0.01, 8, 8);
|
1393
|
-
}
|
1394
|
-
|
1395
|
-
case rapier3dCompat.ShapeType.TriMesh:
|
1396
|
-
{
|
1397
|
-
var _g$index;
|
1398
|
-
|
1399
|
-
const v = collider.shape.vertices;
|
1400
|
-
const i = collider.shape.indices;
|
1401
|
-
const g = new three.BufferGeometry(); // Vertices are not always a float3darray (???), so we need to convert them
|
1402
|
-
|
1403
|
-
const safeVerts = Float32Array.from(v);
|
1404
|
-
g.setAttribute("position", new three.BufferAttribute(safeVerts, 3));
|
1405
|
-
(_g$index = g.index) === null || _g$index === void 0 ? void 0 : _g$index.set(i);
|
1406
|
-
g.setDrawRange(0, g.attributes.position.array.length / 3 - 1);
|
1407
|
-
return g;
|
1408
|
-
}
|
1409
|
-
|
1410
|
-
case rapier3dCompat.ShapeType.ConvexPolyhedron:
|
1411
|
-
{
|
1412
|
-
const cv = collider.shape.vertices; // Vertices are not always a float3darray (???), so we need to convert them
|
1413
|
-
|
1414
|
-
const safeVerts = Float32Array.from(cv);
|
1415
|
-
const cg = new three.BufferGeometry();
|
1416
|
-
cg.setAttribute("position", new three.BufferAttribute(safeVerts, 3));
|
1417
|
-
return cg;
|
1418
|
-
}
|
1419
|
-
|
1420
|
-
case rapier3dCompat.ShapeType.Cylinder:
|
1421
|
-
{
|
1422
|
-
const r = collider.shape.radius;
|
1423
|
-
const h = collider.shape.halfHeight;
|
1424
|
-
const g = new three.CylinderGeometry(r, r, h * 2);
|
1425
|
-
return g;
|
1426
|
-
}
|
1427
|
-
|
1428
|
-
case rapier3dCompat.ShapeType.Capsule:
|
1429
|
-
{
|
1430
|
-
const r = collider.shape.radius;
|
1431
|
-
const h = collider.shape.halfHeight;
|
1432
|
-
const g = new three.CapsuleGeometry(r, h * 2, 4, 8);
|
1433
|
-
return g;
|
1434
|
-
}
|
1435
|
-
|
1436
|
-
case rapier3dCompat.ShapeType.Cone:
|
1437
|
-
{
|
1438
|
-
const r = collider.shape.radius;
|
1439
|
-
const h = collider.shape.halfHeight;
|
1440
|
-
const g = new three.ConeGeometry(r, h * 2, 16);
|
1441
|
-
return g;
|
1442
|
-
}
|
1443
|
-
|
1444
|
-
case rapier3dCompat.ShapeType.HeightField:
|
1445
|
-
{
|
1446
|
-
const rows = collider.shape.nrows;
|
1447
|
-
const cols = collider.shape.ncols;
|
1448
|
-
const heights = collider.shape.heights;
|
1449
|
-
const scale = collider.shape.scale;
|
1450
|
-
const g = new three.PlaneGeometry(scale.x, scale.z, cols, rows);
|
1451
|
-
const verts = g.attributes.position.array;
|
1452
|
-
verts.forEach((v, index) => verts[index * 3 + 2] = heights[index] * scale.y);
|
1453
|
-
g.scale(1, -1, 1);
|
1454
|
-
g.rotateX(-Math.PI / 2);
|
1455
|
-
g.rotateY(-Math.PI / 2);
|
1456
|
-
return g;
|
1457
|
-
}
|
1458
|
-
}
|
1459
|
-
|
1460
|
-
return new three.BoxGeometry(1, 1, 1);
|
1461
|
-
};
|
1462
|
-
|
1463
|
-
const DebugShape = /*#__PURE__*/React.memo(({
|
1464
|
-
colliderHandle,
|
1465
|
-
color,
|
1466
|
-
sleepColor
|
1467
|
-
}) => {
|
1381
|
+
const Debug = () => {
|
1468
1382
|
const {
|
1469
1383
|
world
|
1470
1384
|
} = useRapier();
|
1471
|
-
const ref = React.useRef(null);
|
1472
|
-
const [material] = React.useState(new three.MeshBasicMaterial({
|
1473
|
-
color,
|
1474
|
-
wireframe: true
|
1475
|
-
}));
|
1385
|
+
const ref = React$1.useRef(null);
|
1476
1386
|
fiber.useFrame(() => {
|
1477
|
-
const
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
y: ry,
|
1483
|
-
z: rz,
|
1484
|
-
w: rw
|
1485
|
-
} = collider.rotation();
|
1486
|
-
const {
|
1487
|
-
x,
|
1488
|
-
y,
|
1489
|
-
z
|
1490
|
-
} = collider.translation();
|
1491
|
-
const parent = collider.parent();
|
1492
|
-
|
1493
|
-
if (parent !== null && parent !== void 0 && parent.isSleeping() || parent !== null && parent !== void 0 && parent.isFixed() || parent !== null && parent !== void 0 && parent.isKinematic()) {
|
1494
|
-
material.color = new three.Color(sleepColor);
|
1495
|
-
} else {
|
1496
|
-
material.color = new three.Color(color);
|
1497
|
-
}
|
1498
|
-
|
1499
|
-
ref.current.position.set(x, y, z);
|
1500
|
-
ref.current.rotation.setFromQuaternion(new three.Quaternion(rx, ry, rz, rw));
|
1501
|
-
}
|
1502
|
-
});
|
1503
|
-
const geometry = React.useMemo(() => {
|
1504
|
-
const collider = world.getCollider(colliderHandle);
|
1505
|
-
return geometryFromCollider(collider);
|
1506
|
-
}, [colliderHandle]);
|
1507
|
-
return /*#__PURE__*/React__default["default"].createElement("mesh", {
|
1508
|
-
ref: ref,
|
1509
|
-
material: material
|
1510
|
-
}, /*#__PURE__*/React__default["default"].createElement("primitive", {
|
1511
|
-
object: geometry,
|
1512
|
-
attach: "geometry"
|
1513
|
-
}));
|
1514
|
-
});
|
1515
|
-
const Debug = ({
|
1516
|
-
color: _color = "red",
|
1517
|
-
sleepColor: _sleepColor = "blue"
|
1518
|
-
}) => {
|
1519
|
-
const {
|
1520
|
-
world
|
1521
|
-
} = useRapier();
|
1522
|
-
const [colliders, setColliders] = React.useState([]);
|
1523
|
-
React.useRef({});
|
1524
|
-
|
1525
|
-
fiber.useFrame(() => {
|
1526
|
-
const newColliders = [];
|
1527
|
-
world.forEachCollider(collider => {
|
1528
|
-
newColliders.push(collider.handle);
|
1529
|
-
});
|
1530
|
-
setColliders(newColliders);
|
1387
|
+
const mesh = ref.current;
|
1388
|
+
if (!mesh) return;
|
1389
|
+
const buffers = world.debugRender();
|
1390
|
+
mesh.geometry.setAttribute("position", new three.BufferAttribute(buffers.vertices, 3));
|
1391
|
+
mesh.geometry.setAttribute("color", new three.BufferAttribute(buffers.colors, 4));
|
1531
1392
|
});
|
1532
|
-
return /*#__PURE__*/
|
1533
|
-
|
1534
|
-
|
1535
|
-
color:
|
1536
|
-
|
1537
|
-
})));
|
1393
|
+
return /*#__PURE__*/React.createElement("lineSegments", {
|
1394
|
+
ref: ref
|
1395
|
+
}, /*#__PURE__*/React.createElement("lineBasicMaterial", {
|
1396
|
+
color: 0xffffff,
|
1397
|
+
vertexColors: true
|
1398
|
+
}), /*#__PURE__*/React.createElement("bufferGeometry", null));
|
1538
1399
|
};
|
1539
1400
|
|
1540
1401
|
const _excluded = ["positions", "rotations", "children"];
|
1541
|
-
const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1402
|
+
const InstancedRigidBodies = /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
1542
1403
|
const {
|
1543
1404
|
world,
|
1544
1405
|
rigidBodyStates,
|
1545
1406
|
physicsOptions,
|
1546
1407
|
rigidBodyEvents
|
1547
1408
|
} = useRapier();
|
1548
|
-
const object = React.useRef(null);
|
1409
|
+
const object = React$1.useRef(null);
|
1549
1410
|
|
1550
1411
|
const {
|
1551
1412
|
positions,
|
@@ -1554,20 +1415,20 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1554
1415
|
} = props,
|
1555
1416
|
options = _objectWithoutProperties(props, _excluded);
|
1556
1417
|
|
1557
|
-
const instancesRef = React.useRef([]);
|
1558
|
-
const rigidBodyRefs = React.useRef([]);
|
1559
|
-
const instancesRefGetter = React.useRef(() => {
|
1418
|
+
const instancesRef = React$1.useRef([]);
|
1419
|
+
const rigidBodyRefs = React$1.useRef([]);
|
1420
|
+
const instancesRefGetter = React$1.useRef(() => {
|
1560
1421
|
if (!instancesRef.current) {
|
1561
1422
|
instancesRef.current = [];
|
1562
1423
|
}
|
1563
1424
|
|
1564
1425
|
return instancesRef.current;
|
1565
1426
|
});
|
1566
|
-
const mergedOptions = React.useMemo(() => {
|
1427
|
+
const mergedOptions = React$1.useMemo(() => {
|
1567
1428
|
return _objectSpread2(_objectSpread2({}, physicsOptions), options);
|
1568
1429
|
}, [physicsOptions, options]);
|
1569
1430
|
const childColliderProps = useChildColliderProps(object, mergedOptions);
|
1570
|
-
React.useLayoutEffect(() => {
|
1431
|
+
React$1.useLayoutEffect(() => {
|
1571
1432
|
object.current.updateWorldMatrix(true, false);
|
1572
1433
|
const instances = instancesRefGetter.current();
|
1573
1434
|
const invertedWorld = object.current.matrixWorld.clone().invert();
|
@@ -1628,11 +1489,11 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1628
1489
|
instancesRef.current = [];
|
1629
1490
|
};
|
1630
1491
|
}, []);
|
1631
|
-
const api = React.useMemo(() => createInstancedRigidBodiesApi(instancesRefGetter), []);
|
1632
|
-
React.useImperativeHandle(ref, () => api);
|
1492
|
+
const api = React$1.useMemo(() => createInstancedRigidBodiesApi(instancesRefGetter), []);
|
1493
|
+
React$1.useImperativeHandle(ref, () => api);
|
1633
1494
|
useUpdateRigidBodyOptions(rigidBodyRefs, mergedOptions, rigidBodyStates, false);
|
1634
1495
|
useRigidBodyEvents(rigidBodyRefs, mergedOptions, rigidBodyEvents);
|
1635
|
-
const contextValue = React.useMemo(() => {
|
1496
|
+
const contextValue = React$1.useMemo(() => {
|
1636
1497
|
return {
|
1637
1498
|
ref: object,
|
1638
1499
|
api,
|