@react-three/rapier 0.7.7 → 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 +2 -1
- package/dist/declarations/src/types.d.ts +4 -0
- package/dist/react-three-rapier.cjs.dev.js +81 -226
- package/dist/react-three-rapier.cjs.prod.js +81 -226
- package/dist/react-three-rapier.esm.js +58 -203
- package/package.json +4 -1
- package/readme.md +12 -7
@@ -1,13 +1,5 @@
|
|
1
1
|
import { FC } from "react";
|
2
2
|
interface DebugProps {
|
3
|
-
/**
|
4
|
-
* The color of the wireframe representing an active collider that is affected by forces and not sleeping.
|
5
|
-
*/
|
6
|
-
color?: string;
|
7
|
-
/**
|
8
|
-
* The color of the wireframe representing a static (fixed or kinematic) or sleeping collider.
|
9
|
-
*/
|
10
|
-
sleepColor?: string;
|
11
3
|
}
|
12
4
|
export declare const Debug: FC<DebugProps>;
|
13
5
|
export {};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Collider, ColliderDesc, ImpulseJoint, JointData, RigidBody, RigidBodyDesc, World } from "@dimforge/rapier3d-compat";
|
1
|
+
import { Collider, ColliderDesc, DebugRenderBuffers, ImpulseJoint, JointData, RigidBody, RigidBodyDesc, World } from "@dimforge/rapier3d-compat";
|
2
2
|
import { Quaternion, Vector3 } from "three";
|
3
3
|
import { RefGetter } from "./types";
|
4
4
|
declare type Vector3Object = {
|
@@ -160,6 +160,7 @@ export interface WorldApi {
|
|
160
160
|
removeImpulseJoint(joint: ImpulseJoint, wakeUp?: boolean): void;
|
161
161
|
forEachCollider(callback: (collider: Collider) => void): void;
|
162
162
|
setGravity(gravity: Vector3): void;
|
163
|
+
debugRender(): DebugRenderBuffers;
|
163
164
|
}
|
164
165
|
export declare const createWorldApi: (ref: RefGetter<World>) => WorldApi;
|
165
166
|
export declare const createJointApi: (ref: RefGetter<ImpulseJoint>) => {
|
@@ -287,6 +287,10 @@ export interface UseRigidBodyOptions extends ColliderProps {
|
|
287
287
|
* Passed down to the object3d representing this collider.
|
288
288
|
*/
|
289
289
|
userData?: Object3DProps["userData"];
|
290
|
+
/**
|
291
|
+
* Include invisible objects on the collider creation estimation.
|
292
|
+
*/
|
293
|
+
includeInvisible?: boolean;
|
290
294
|
}
|
291
295
|
export declare type SphericalJointParams = [
|
292
296
|
body1Anchor: Vector3Array,
|
@@ -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();
|
@@ -220,7 +220,8 @@ const createWorldApi = ref => {
|
|
220
220
|
x,
|
221
221
|
y,
|
222
222
|
z
|
223
|
-
}
|
223
|
+
},
|
224
|
+
debugRender: () => ref.current().debugRender()
|
224
225
|
};
|
225
226
|
}; // TODO: Broken currently, waiting for Rapier3D to fix
|
226
227
|
|
@@ -237,7 +238,7 @@ const createJointApi = ref => {
|
|
237
238
|
};
|
238
239
|
};
|
239
240
|
|
240
|
-
const RapierContext = /*#__PURE__*/React.createContext(undefined);
|
241
|
+
const RapierContext = /*#__PURE__*/React$1.createContext(undefined);
|
241
242
|
|
242
243
|
const importRapier = async () => {
|
243
244
|
let r = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@dimforge/rapier3d-compat')); });
|
@@ -254,8 +255,8 @@ const Physics = ({
|
|
254
255
|
updatePriority
|
255
256
|
}) => {
|
256
257
|
const rapier = useAsset.useAsset(importRapier);
|
257
|
-
const worldRef = React.useRef();
|
258
|
-
const getWorldRef = React.useRef(() => {
|
258
|
+
const worldRef = React$1.useRef();
|
259
|
+
const getWorldRef = React$1.useRef(() => {
|
259
260
|
if (!worldRef.current) {
|
260
261
|
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
261
262
|
worldRef.current = world;
|
@@ -263,13 +264,13 @@ const Physics = ({
|
|
263
264
|
|
264
265
|
return worldRef.current;
|
265
266
|
});
|
266
|
-
const [rigidBodyStates] = React.useState(() => new Map());
|
267
|
-
const [colliderStates] = React.useState(() => new Map());
|
268
|
-
const [rigidBodyEvents] = React.useState(() => new Map());
|
269
|
-
const [colliderEvents] = React.useState(() => new Map());
|
270
|
-
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
|
271
272
|
|
272
|
-
React.useEffect(() => {
|
273
|
+
React$1.useEffect(() => {
|
273
274
|
const world = getWorldRef.current();
|
274
275
|
return () => {
|
275
276
|
if (world) {
|
@@ -279,14 +280,14 @@ const Physics = ({
|
|
279
280
|
};
|
280
281
|
}, []); // Update gravity
|
281
282
|
|
282
|
-
React.useEffect(() => {
|
283
|
+
React$1.useEffect(() => {
|
283
284
|
const world = worldRef.current;
|
284
285
|
|
285
286
|
if (world) {
|
286
287
|
world.gravity = vectorArrayToVector3(_gravity);
|
287
288
|
}
|
288
289
|
}, [_gravity]);
|
289
|
-
const [steppingState] = React.useState({
|
290
|
+
const [steppingState] = React$1.useState({
|
290
291
|
accumulator: 0
|
291
292
|
});
|
292
293
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
@@ -496,8 +497,8 @@ const Physics = ({
|
|
496
497
|
}
|
497
498
|
});
|
498
499
|
}, updatePriority);
|
499
|
-
const api = React.useMemo(() => createWorldApi(getWorldRef), []);
|
500
|
-
const context = React.useMemo(() => ({
|
500
|
+
const api = React$1.useMemo(() => createWorldApi(getWorldRef), []);
|
501
|
+
const context = React$1.useMemo(() => ({
|
501
502
|
rapier,
|
502
503
|
world: api,
|
503
504
|
physicsOptions: {
|
@@ -698,10 +699,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
698
699
|
};
|
699
700
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
700
701
|
// TODO: Improve this, split each prop into its own effect
|
701
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
702
|
+
const mutablePropsAsFlatArray = React$1.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
702
703
|
return vectorToTuple(props[key]);
|
703
704
|
}), [props]);
|
704
|
-
React.useEffect(() => {
|
705
|
+
React$1.useEffect(() => {
|
705
706
|
if (Array.isArray(rigidBodyRef.current)) {
|
706
707
|
for (const rigidBody of rigidBodyRef.current) {
|
707
708
|
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
@@ -728,7 +729,7 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
728
729
|
onIntersectionEnter,
|
729
730
|
onIntersectionExit
|
730
731
|
};
|
731
|
-
React.useEffect(() => {
|
732
|
+
React$1.useEffect(() => {
|
732
733
|
if (Array.isArray(rigidBodyRef.current)) {
|
733
734
|
for (const rigidBody of rigidBodyRef.current) {
|
734
735
|
events.set(rigidBody.handle, eventHandlers);
|
@@ -871,10 +872,10 @@ const setColliderOptions = (collider, options, states) => {
|
|
871
872
|
};
|
872
873
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
873
874
|
// TODO: Improve this, split each prop into its own effect
|
874
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
875
|
+
const mutablePropsAsFlatArray = React$1.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
875
876
|
return vectorToTuple(props[key]);
|
876
877
|
}), [props]);
|
877
|
-
React.useEffect(() => {
|
878
|
+
React$1.useEffect(() => {
|
878
879
|
collidersRef.current.forEach(collider => {
|
879
880
|
setColliderOptions(collider, props, states);
|
880
881
|
});
|
@@ -910,7 +911,8 @@ const createColliderPropsFromChildren = ({
|
|
910
911
|
const colliderProps = [];
|
911
912
|
object.updateWorldMatrix(true, false);
|
912
913
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
913
|
-
|
914
|
+
|
915
|
+
const colliderFromChild = child => {
|
914
916
|
if ("isMesh" in child) {
|
915
917
|
if (_ignoreMeshColliders && isChildOfMeshCollider(child)) return;
|
916
918
|
const worldScale = child.getWorldScale(_scale);
|
@@ -935,7 +937,14 @@ const createColliderPropsFromChildren = ({
|
|
935
937
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
936
938
|
}));
|
937
939
|
}
|
938
|
-
}
|
940
|
+
};
|
941
|
+
|
942
|
+
if (options.includeInvisible) {
|
943
|
+
object.traverse(colliderFromChild);
|
944
|
+
} else {
|
945
|
+
object.traverseVisible(colliderFromChild);
|
946
|
+
}
|
947
|
+
|
939
948
|
return colliderProps;
|
940
949
|
};
|
941
950
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
@@ -999,7 +1008,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
999
1008
|
onIntersectionEnter,
|
1000
1009
|
onIntersectionExit
|
1001
1010
|
} = props;
|
1002
|
-
React.useEffect(() => {
|
1011
|
+
React$1.useEffect(() => {
|
1003
1012
|
var _collidersRef$current;
|
1004
1013
|
|
1005
1014
|
(_collidersRef$current = collidersRef.current) === null || _collidersRef$current === void 0 ? void 0 : _collidersRef$current.forEach(collider => {
|
@@ -1023,11 +1032,11 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
1023
1032
|
};
|
1024
1033
|
|
1025
1034
|
const useRapier = () => {
|
1026
|
-
return React.useContext(RapierContext);
|
1035
|
+
return React$1.useContext(RapierContext);
|
1027
1036
|
};
|
1028
1037
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
1029
|
-
const [colliderProps, setColliderProps] = React.useState([]);
|
1030
|
-
React.useEffect(() => {
|
1038
|
+
const [colliderProps, setColliderProps] = React$1.useState([]);
|
1039
|
+
React$1.useEffect(() => {
|
1031
1040
|
const object = ref.current;
|
1032
1041
|
|
1033
1042
|
if (object && options.colliders !== false) {
|
@@ -1047,16 +1056,16 @@ const useRigidBody = (options = {}) => {
|
|
1047
1056
|
physicsOptions,
|
1048
1057
|
rigidBodyEvents
|
1049
1058
|
} = useRapier();
|
1050
|
-
const ref = React.useRef();
|
1051
|
-
const mergedOptions = React.useMemo(() => {
|
1059
|
+
const ref = React$1.useRef();
|
1060
|
+
const mergedOptions = React$1.useMemo(() => {
|
1052
1061
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1053
1062
|
children: undefined
|
1054
1063
|
});
|
1055
1064
|
}, [physicsOptions, options]);
|
1056
1065
|
const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
|
1057
1066
|
|
1058
|
-
const rigidBodyRef = React.useRef();
|
1059
|
-
const getRigidBodyRef = React.useRef(() => {
|
1067
|
+
const rigidBodyRef = React$1.useRef();
|
1068
|
+
const getRigidBodyRef = React$1.useRef(() => {
|
1060
1069
|
if (!rigidBodyRef.current) {
|
1061
1070
|
const desc = rigidBodyDescFromOptions(options);
|
1062
1071
|
const rigidBody = world.createRigidBody(desc);
|
@@ -1066,7 +1075,7 @@ const useRigidBody = (options = {}) => {
|
|
1066
1075
|
return rigidBodyRef.current;
|
1067
1076
|
}); // Setup
|
1068
1077
|
|
1069
|
-
React.useEffect(() => {
|
1078
|
+
React$1.useEffect(() => {
|
1070
1079
|
const rigidBody = getRigidBodyRef.current();
|
1071
1080
|
rigidBodyRef.current = rigidBody;
|
1072
1081
|
|
@@ -1088,7 +1097,7 @@ const useRigidBody = (options = {}) => {
|
|
1088
1097
|
}, []);
|
1089
1098
|
useUpdateRigidBodyOptions(rigidBodyRef, mergedOptions, rigidBodyStates);
|
1090
1099
|
useRigidBodyEvents(rigidBodyRef, mergedOptions, rigidBodyEvents);
|
1091
|
-
const api = React.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
1100
|
+
const api = React$1.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
1092
1101
|
return [ref, api, childColliderProps];
|
1093
1102
|
}; // Joints
|
1094
1103
|
|
@@ -1096,8 +1105,8 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1096
1105
|
const {
|
1097
1106
|
world
|
1098
1107
|
} = useRapier();
|
1099
|
-
const jointRef = React.useRef();
|
1100
|
-
const getJointRef = React.useRef(() => {
|
1108
|
+
const jointRef = React$1.useRef();
|
1109
|
+
const getJointRef = React$1.useRef(() => {
|
1101
1110
|
if (!jointRef.current) {
|
1102
1111
|
let rb1;
|
1103
1112
|
let rb2;
|
@@ -1112,7 +1121,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1112
1121
|
|
1113
1122
|
return jointRef.current;
|
1114
1123
|
});
|
1115
|
-
React.useEffect(() => {
|
1124
|
+
React$1.useEffect(() => {
|
1116
1125
|
const joint = getJointRef.current();
|
1117
1126
|
return () => {
|
1118
1127
|
if (joint) {
|
@@ -1121,7 +1130,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1121
1130
|
}
|
1122
1131
|
};
|
1123
1132
|
}, []);
|
1124
|
-
const api = React.useMemo(() => createJointApi(getJointRef), []);
|
1133
|
+
const api = React$1.useMemo(() => createJointApi(getJointRef), []);
|
1125
1134
|
return api;
|
1126
1135
|
};
|
1127
1136
|
/**
|
@@ -1180,7 +1189,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
1180
1189
|
};
|
1181
1190
|
|
1182
1191
|
// Colliders
|
1183
|
-
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) => {
|
1184
1193
|
const {
|
1185
1194
|
children,
|
1186
1195
|
position,
|
@@ -1194,8 +1203,8 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["defaul
|
|
1194
1203
|
colliderStates
|
1195
1204
|
} = useRapier();
|
1196
1205
|
const rigidBodyContext = useRigidBodyContext();
|
1197
|
-
const ref = React.useRef(null);
|
1198
|
-
const collidersRef = React.useMemo(() => {
|
1206
|
+
const ref = React$1.useRef(null);
|
1207
|
+
const collidersRef = React$1.useMemo(() => {
|
1199
1208
|
if (forwardedRef !== null) {
|
1200
1209
|
return forwardedRef;
|
1201
1210
|
}
|
@@ -1204,7 +1213,7 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["defaul
|
|
1204
1213
|
result.current = [];
|
1205
1214
|
return result;
|
1206
1215
|
}, []);
|
1207
|
-
React.useEffect(() => {
|
1216
|
+
React$1.useEffect(() => {
|
1208
1217
|
const object = ref.current;
|
1209
1218
|
const worldScale = object.getWorldScale(new three.Vector3());
|
1210
1219
|
const colliders = []; // If this is an InstancedRigidBody api
|
@@ -1236,7 +1245,7 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["defaul
|
|
1236
1245
|
});
|
1237
1246
|
};
|
1238
1247
|
}, []);
|
1239
|
-
const mergedProps = React.useMemo(() => {
|
1248
|
+
const mergedProps = React$1.useMemo(() => {
|
1240
1249
|
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1241
1250
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1242
1251
|
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
@@ -1305,9 +1314,9 @@ const ConvexHullCollider = /*#__PURE__*/React__default["default"].forwardRef((pr
|
|
1305
1314
|
});
|
1306
1315
|
|
1307
1316
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1308
|
-
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1309
|
-
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1310
|
-
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) => {
|
1311
1320
|
const {
|
1312
1321
|
children,
|
1313
1322
|
type,
|
@@ -1319,8 +1328,8 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
|
|
1319
1328
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1320
1329
|
|
1321
1330
|
const [object, api, childColliderProps] = useRigidBody(props);
|
1322
|
-
React.useImperativeHandle(ref, () => api);
|
1323
|
-
const contextValue = React.useMemo(() => ({
|
1331
|
+
React$1.useImperativeHandle(ref, () => api);
|
1332
|
+
const contextValue = React$1.useMemo(() => ({
|
1324
1333
|
ref: object,
|
1325
1334
|
api,
|
1326
1335
|
options: props
|
@@ -1348,11 +1357,11 @@ const MeshCollider = props => {
|
|
1348
1357
|
physicsOptions,
|
1349
1358
|
world
|
1350
1359
|
} = useRapier();
|
1351
|
-
const object = React.useRef(null);
|
1360
|
+
const object = React$1.useRef(null);
|
1352
1361
|
const {
|
1353
1362
|
options
|
1354
1363
|
} = useRigidBodyContext();
|
1355
|
-
const mergedOptions = React.useMemo(() => {
|
1364
|
+
const mergedOptions = React$1.useMemo(() => {
|
1356
1365
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1357
1366
|
children: undefined,
|
1358
1367
|
colliders: type
|
@@ -1369,189 +1378,35 @@ const MeshCollider = props => {
|
|
1369
1378
|
}, colliderProps))));
|
1370
1379
|
};
|
1371
1380
|
|
1372
|
-
const
|
1373
|
-
switch (collider.shape.type) {
|
1374
|
-
case rapier3dCompat.ShapeType.Cuboid:
|
1375
|
-
{
|
1376
|
-
const {
|
1377
|
-
x,
|
1378
|
-
y,
|
1379
|
-
z
|
1380
|
-
} = collider.shape.halfExtents;
|
1381
|
-
return new three.BoxGeometry(x * 2 + 0.01, y * 2 + 0.01, z * 2 + 0.01);
|
1382
|
-
}
|
1383
|
-
|
1384
|
-
case rapier3dCompat.ShapeType.RoundCuboid:
|
1385
|
-
{
|
1386
|
-
const {
|
1387
|
-
x,
|
1388
|
-
y,
|
1389
|
-
z
|
1390
|
-
} = collider.shape.halfExtents;
|
1391
|
-
const radius = collider.shape.borderRadius;
|
1392
|
-
return new threeStdlib.RoundedBoxGeometry(x * 2 + radius * 2, y * 2 + radius * 2, z * 2 + radius * 2, 8, radius);
|
1393
|
-
}
|
1394
|
-
|
1395
|
-
case rapier3dCompat.ShapeType.Ball:
|
1396
|
-
{
|
1397
|
-
const r = collider.shape.radius;
|
1398
|
-
return new three.SphereGeometry(r + +0.01, 8, 8);
|
1399
|
-
}
|
1400
|
-
|
1401
|
-
case rapier3dCompat.ShapeType.TriMesh:
|
1402
|
-
{
|
1403
|
-
var _g$index;
|
1404
|
-
|
1405
|
-
const v = collider.shape.vertices;
|
1406
|
-
const i = collider.shape.indices;
|
1407
|
-
const g = new three.BufferGeometry(); // Vertices are not always a float3darray (???), so we need to convert them
|
1408
|
-
|
1409
|
-
const safeVerts = Float32Array.from(v);
|
1410
|
-
g.setAttribute("position", new three.BufferAttribute(safeVerts, 3));
|
1411
|
-
(_g$index = g.index) === null || _g$index === void 0 ? void 0 : _g$index.set(i);
|
1412
|
-
g.setDrawRange(0, g.attributes.position.array.length / 3 - 1);
|
1413
|
-
return g;
|
1414
|
-
}
|
1415
|
-
|
1416
|
-
case rapier3dCompat.ShapeType.ConvexPolyhedron:
|
1417
|
-
{
|
1418
|
-
const cv = collider.shape.vertices; // Vertices are not always a float3darray (???), so we need to convert them
|
1419
|
-
|
1420
|
-
const safeVerts = Float32Array.from(cv);
|
1421
|
-
const cg = new three.BufferGeometry();
|
1422
|
-
cg.setAttribute("position", new three.BufferAttribute(safeVerts, 3));
|
1423
|
-
return cg;
|
1424
|
-
}
|
1425
|
-
|
1426
|
-
case rapier3dCompat.ShapeType.Cylinder:
|
1427
|
-
{
|
1428
|
-
const r = collider.shape.radius;
|
1429
|
-
const h = collider.shape.halfHeight;
|
1430
|
-
const g = new three.CylinderGeometry(r, r, h * 2);
|
1431
|
-
return g;
|
1432
|
-
}
|
1433
|
-
|
1434
|
-
case rapier3dCompat.ShapeType.Capsule:
|
1435
|
-
{
|
1436
|
-
const r = collider.shape.radius;
|
1437
|
-
const h = collider.shape.halfHeight;
|
1438
|
-
const g = new three.CapsuleGeometry(r, h * 2, 4, 8);
|
1439
|
-
return g;
|
1440
|
-
}
|
1441
|
-
|
1442
|
-
case rapier3dCompat.ShapeType.Cone:
|
1443
|
-
{
|
1444
|
-
const r = collider.shape.radius;
|
1445
|
-
const h = collider.shape.halfHeight;
|
1446
|
-
const g = new three.ConeGeometry(r, h * 2, 16);
|
1447
|
-
return g;
|
1448
|
-
}
|
1449
|
-
|
1450
|
-
case rapier3dCompat.ShapeType.HeightField:
|
1451
|
-
{
|
1452
|
-
const rows = collider.shape.nrows;
|
1453
|
-
const cols = collider.shape.ncols;
|
1454
|
-
const heights = collider.shape.heights;
|
1455
|
-
const scale = collider.shape.scale;
|
1456
|
-
const g = new three.PlaneGeometry(scale.x, scale.z, cols, rows);
|
1457
|
-
const verts = g.attributes.position.array;
|
1458
|
-
verts.forEach((v, index) => verts[index * 3 + 2] = heights[index] * scale.y);
|
1459
|
-
g.scale(1, -1, 1);
|
1460
|
-
g.rotateX(-Math.PI / 2);
|
1461
|
-
g.rotateY(-Math.PI / 2);
|
1462
|
-
return g;
|
1463
|
-
}
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
return new three.BoxGeometry(1, 1, 1);
|
1467
|
-
};
|
1468
|
-
|
1469
|
-
const DebugShape = /*#__PURE__*/React.memo(({
|
1470
|
-
colliderHandle,
|
1471
|
-
color,
|
1472
|
-
sleepColor
|
1473
|
-
}) => {
|
1474
|
-
const {
|
1475
|
-
world
|
1476
|
-
} = useRapier();
|
1477
|
-
const ref = React.useRef(null);
|
1478
|
-
const [material] = React.useState(new three.MeshBasicMaterial({
|
1479
|
-
color,
|
1480
|
-
wireframe: true
|
1481
|
-
}));
|
1482
|
-
fiber.useFrame(() => {
|
1483
|
-
const collider = world.getCollider(colliderHandle);
|
1484
|
-
|
1485
|
-
if (ref.current && collider) {
|
1486
|
-
const {
|
1487
|
-
x: rx,
|
1488
|
-
y: ry,
|
1489
|
-
z: rz,
|
1490
|
-
w: rw
|
1491
|
-
} = collider.rotation();
|
1492
|
-
const {
|
1493
|
-
x,
|
1494
|
-
y,
|
1495
|
-
z
|
1496
|
-
} = collider.translation();
|
1497
|
-
const parent = collider.parent();
|
1498
|
-
|
1499
|
-
if (parent !== null && parent !== void 0 && parent.isSleeping() || parent !== null && parent !== void 0 && parent.isFixed() || parent !== null && parent !== void 0 && parent.isKinematic()) {
|
1500
|
-
material.color = new three.Color(sleepColor);
|
1501
|
-
} else {
|
1502
|
-
material.color = new three.Color(color);
|
1503
|
-
}
|
1504
|
-
|
1505
|
-
ref.current.position.set(x, y, z);
|
1506
|
-
ref.current.rotation.setFromQuaternion(new three.Quaternion(rx, ry, rz, rw));
|
1507
|
-
}
|
1508
|
-
});
|
1509
|
-
const geometry = React.useMemo(() => {
|
1510
|
-
const collider = world.getCollider(colliderHandle);
|
1511
|
-
return geometryFromCollider(collider);
|
1512
|
-
}, [colliderHandle]);
|
1513
|
-
return /*#__PURE__*/React__default["default"].createElement("mesh", {
|
1514
|
-
ref: ref,
|
1515
|
-
material: material
|
1516
|
-
}, /*#__PURE__*/React__default["default"].createElement("primitive", {
|
1517
|
-
object: geometry,
|
1518
|
-
attach: "geometry"
|
1519
|
-
}));
|
1520
|
-
});
|
1521
|
-
const Debug = ({
|
1522
|
-
color: _color = "red",
|
1523
|
-
sleepColor: _sleepColor = "blue"
|
1524
|
-
}) => {
|
1381
|
+
const Debug = () => {
|
1525
1382
|
const {
|
1526
1383
|
world
|
1527
1384
|
} = useRapier();
|
1528
|
-
const
|
1529
|
-
React.useRef({});
|
1530
|
-
|
1385
|
+
const ref = React$1.useRef(null);
|
1531
1386
|
fiber.useFrame(() => {
|
1532
|
-
const
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
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));
|
1537
1392
|
});
|
1538
|
-
return /*#__PURE__*/
|
1539
|
-
|
1540
|
-
|
1541
|
-
color:
|
1542
|
-
|
1543
|
-
})));
|
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));
|
1544
1399
|
};
|
1545
1400
|
|
1546
1401
|
const _excluded = ["positions", "rotations", "children"];
|
1547
|
-
const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1402
|
+
const InstancedRigidBodies = /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
1548
1403
|
const {
|
1549
1404
|
world,
|
1550
1405
|
rigidBodyStates,
|
1551
1406
|
physicsOptions,
|
1552
1407
|
rigidBodyEvents
|
1553
1408
|
} = useRapier();
|
1554
|
-
const object = React.useRef(null);
|
1409
|
+
const object = React$1.useRef(null);
|
1555
1410
|
|
1556
1411
|
const {
|
1557
1412
|
positions,
|
@@ -1560,20 +1415,20 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1560
1415
|
} = props,
|
1561
1416
|
options = _objectWithoutProperties(props, _excluded);
|
1562
1417
|
|
1563
|
-
const instancesRef = React.useRef([]);
|
1564
|
-
const rigidBodyRefs = React.useRef([]);
|
1565
|
-
const instancesRefGetter = React.useRef(() => {
|
1418
|
+
const instancesRef = React$1.useRef([]);
|
1419
|
+
const rigidBodyRefs = React$1.useRef([]);
|
1420
|
+
const instancesRefGetter = React$1.useRef(() => {
|
1566
1421
|
if (!instancesRef.current) {
|
1567
1422
|
instancesRef.current = [];
|
1568
1423
|
}
|
1569
1424
|
|
1570
1425
|
return instancesRef.current;
|
1571
1426
|
});
|
1572
|
-
const mergedOptions = React.useMemo(() => {
|
1427
|
+
const mergedOptions = React$1.useMemo(() => {
|
1573
1428
|
return _objectSpread2(_objectSpread2({}, physicsOptions), options);
|
1574
1429
|
}, [physicsOptions, options]);
|
1575
1430
|
const childColliderProps = useChildColliderProps(object, mergedOptions);
|
1576
|
-
React.useLayoutEffect(() => {
|
1431
|
+
React$1.useLayoutEffect(() => {
|
1577
1432
|
object.current.updateWorldMatrix(true, false);
|
1578
1433
|
const instances = instancesRefGetter.current();
|
1579
1434
|
const invertedWorld = object.current.matrixWorld.clone().invert();
|
@@ -1634,11 +1489,11 @@ const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1634
1489
|
instancesRef.current = [];
|
1635
1490
|
};
|
1636
1491
|
}, []);
|
1637
|
-
const api = React.useMemo(() => createInstancedRigidBodiesApi(instancesRefGetter), []);
|
1638
|
-
React.useImperativeHandle(ref, () => api);
|
1492
|
+
const api = React$1.useMemo(() => createInstancedRigidBodiesApi(instancesRefGetter), []);
|
1493
|
+
React$1.useImperativeHandle(ref, () => api);
|
1639
1494
|
useUpdateRigidBodyOptions(rigidBodyRefs, mergedOptions, rigidBodyStates, false);
|
1640
1495
|
useRigidBodyEvents(rigidBodyRefs, mergedOptions, rigidBodyEvents);
|
1641
|
-
const contextValue = React.useMemo(() => {
|
1496
|
+
const contextValue = React$1.useMemo(() => {
|
1642
1497
|
return {
|
1643
1498
|
ref: object,
|
1644
1499
|
api,
|