@react-three/rapier 0.12.0 → 0.12.1
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.
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
import React from "react";
|
2
2
|
import { InstancedRigidBodyApi } from "./api";
|
3
3
|
import { RigidBodyProps } from "./RigidBody";
|
4
4
|
import { Vector3Array } from "./types";
|
@@ -7,4 +7,4 @@ export interface InstancedRigidBodiesProps extends Omit<RigidBodyProps, "positio
|
|
7
7
|
rotations?: Vector3Array[];
|
8
8
|
scales?: Vector3Array[];
|
9
9
|
}
|
10
|
-
export declare const InstancedRigidBodies:
|
10
|
+
export declare const InstancedRigidBodies: React.ForwardRefExoticComponent<InstancedRigidBodiesProps & React.RefAttributes<InstancedRigidBodyApi>>;
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var rapier3dCompat = require('@dimforge/rapier3d-compat');
|
6
6
|
var fiber = require('@react-three/fiber');
|
7
|
-
var React
|
7
|
+
var React = require('react');
|
8
8
|
var three = require('three');
|
9
9
|
var useAsset = require('use-asset');
|
10
10
|
var threeStdlib = require('three-stdlib');
|
@@ -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);
|
33
33
|
|
34
34
|
function _defineProperty(obj, key, value) {
|
35
35
|
if (key in obj) {
|
@@ -138,7 +138,7 @@ const vectorToTuple = v => {
|
|
138
138
|
return [v];
|
139
139
|
};
|
140
140
|
function useConst(initialValue) {
|
141
|
-
const ref = React
|
141
|
+
const ref = React.useRef();
|
142
142
|
|
143
143
|
if (ref.current === undefined) {
|
144
144
|
ref.current = {
|
@@ -426,10 +426,10 @@ const setColliderOptions = (collider, options, states) => {
|
|
426
426
|
};
|
427
427
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
428
428
|
// TODO: Improve this, split each prop into its own effect
|
429
|
-
const mutablePropsAsFlatArray = React
|
429
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
430
430
|
return vectorToTuple(props[key]);
|
431
431
|
}), [props]);
|
432
|
-
React
|
432
|
+
React.useEffect(() => {
|
433
433
|
collidersRef.current.forEach(collider => {
|
434
434
|
setColliderOptions(collider, props, states);
|
435
435
|
});
|
@@ -563,7 +563,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
563
563
|
onIntersectionExit,
|
564
564
|
onContactForce
|
565
565
|
} = props;
|
566
|
-
React
|
566
|
+
React.useEffect(() => {
|
567
567
|
var _collidersRef$current;
|
568
568
|
|
569
569
|
(_collidersRef$current = collidersRef.current) === null || _collidersRef$current === void 0 ? void 0 : _collidersRef$current.forEach(collider => {
|
@@ -703,10 +703,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
703
703
|
};
|
704
704
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
705
705
|
// TODO: Improve this, split each prop into its own effect
|
706
|
-
const mutablePropsAsFlatArray = React
|
706
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
707
707
|
return vectorToTuple(props[key]);
|
708
708
|
}), [props]);
|
709
|
-
React
|
709
|
+
React.useEffect(() => {
|
710
710
|
if (Array.isArray(rigidBodyRef.current)) {
|
711
711
|
for (const rigidBody of rigidBodyRef.current) {
|
712
712
|
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
@@ -733,7 +733,7 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
733
733
|
onIntersectionEnter,
|
734
734
|
onIntersectionExit
|
735
735
|
};
|
736
|
-
React
|
736
|
+
React.useEffect(() => {
|
737
737
|
if (Array.isArray(rigidBodyRef.current)) {
|
738
738
|
for (const rigidBody of rigidBodyRef.current) {
|
739
739
|
events.set(rigidBody.handle, eventHandlers);
|
@@ -755,13 +755,13 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
755
755
|
};
|
756
756
|
|
757
757
|
const useRapier = () => {
|
758
|
-
return React
|
758
|
+
return React.useContext(rapierContext);
|
759
759
|
};
|
760
760
|
const useBeforePhysicsStep = callback => {
|
761
761
|
const {
|
762
762
|
beforeStepCallbacks
|
763
763
|
} = useRapier();
|
764
|
-
React
|
764
|
+
React.useEffect(() => {
|
765
765
|
beforeStepCallbacks.add(callback);
|
766
766
|
return () => {
|
767
767
|
beforeStepCallbacks.delete(callback);
|
@@ -772,7 +772,7 @@ const useAfterPhysicsStep = callback => {
|
|
772
772
|
const {
|
773
773
|
afterStepCallbacks
|
774
774
|
} = useRapier();
|
775
|
-
React
|
775
|
+
React.useEffect(() => {
|
776
776
|
afterStepCallbacks.add(callback);
|
777
777
|
return () => {
|
778
778
|
afterStepCallbacks.delete(callback);
|
@@ -781,8 +781,8 @@ const useAfterPhysicsStep = callback => {
|
|
781
781
|
}; // Internal hooks
|
782
782
|
|
783
783
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
784
|
-
const [colliderProps, setColliderProps] = React
|
785
|
-
React
|
784
|
+
const [colliderProps, setColliderProps] = React.useState([]);
|
785
|
+
React.useEffect(() => {
|
786
786
|
const object = ref.current;
|
787
787
|
|
788
788
|
if (object && options.colliders !== false) {
|
@@ -802,16 +802,16 @@ const useRigidBody = (options = {}) => {
|
|
802
802
|
physicsOptions,
|
803
803
|
rigidBodyEvents
|
804
804
|
} = useRapier();
|
805
|
-
const ref = React
|
806
|
-
const mergedOptions = React
|
805
|
+
const ref = React.useRef();
|
806
|
+
const mergedOptions = React.useMemo(() => {
|
807
807
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
808
808
|
children: undefined
|
809
809
|
});
|
810
810
|
}, [physicsOptions, options]);
|
811
811
|
const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
|
812
812
|
|
813
|
-
const rigidBodyRef = React
|
814
|
-
const getRigidBodyRef = React
|
813
|
+
const rigidBodyRef = React.useRef();
|
814
|
+
const getRigidBodyRef = React.useRef(() => {
|
815
815
|
if (!rigidBodyRef.current) {
|
816
816
|
const desc = rigidBodyDescFromOptions(options);
|
817
817
|
const rigidBody = world.createRigidBody(desc);
|
@@ -821,7 +821,7 @@ const useRigidBody = (options = {}) => {
|
|
821
821
|
return rigidBodyRef.current;
|
822
822
|
}); // Setup
|
823
823
|
|
824
|
-
React
|
824
|
+
React.useEffect(() => {
|
825
825
|
const rigidBody = getRigidBodyRef.current();
|
826
826
|
rigidBodyRef.current = rigidBody;
|
827
827
|
|
@@ -841,7 +841,7 @@ const useRigidBody = (options = {}) => {
|
|
841
841
|
}, []);
|
842
842
|
useUpdateRigidBodyOptions(rigidBodyRef, mergedOptions, rigidBodyStates);
|
843
843
|
useRigidBodyEvents(rigidBodyRef, mergedOptions, rigidBodyEvents);
|
844
|
-
const api = React
|
844
|
+
const api = React.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
845
845
|
return [ref, api, childColliderProps];
|
846
846
|
};
|
847
847
|
|
@@ -891,7 +891,7 @@ const applyAttractorForceOnRigidBody = (rigidBody, {
|
|
891
891
|
}
|
892
892
|
}
|
893
893
|
};
|
894
|
-
const Attractor = /*#__PURE__*/React
|
894
|
+
const Attractor = /*#__PURE__*/React.memo(props => {
|
895
895
|
const {
|
896
896
|
position = [0, 0, 0],
|
897
897
|
strength = 1,
|
@@ -903,8 +903,8 @@ const Attractor = /*#__PURE__*/React$1.memo(props => {
|
|
903
903
|
const {
|
904
904
|
attractorStates
|
905
905
|
} = useRapier();
|
906
|
-
const object = React
|
907
|
-
React
|
906
|
+
const object = React.useRef(null);
|
907
|
+
React.useEffect(() => {
|
908
908
|
var _object$current;
|
909
909
|
|
910
910
|
let uuid = ((_object$current = object.current) === null || _object$current === void 0 ? void 0 : _object$current.uuid) || "_";
|
@@ -930,7 +930,7 @@ const Attractor = /*#__PURE__*/React$1.memo(props => {
|
|
930
930
|
});
|
931
931
|
});
|
932
932
|
|
933
|
-
const rapierContext = /*#__PURE__*/React
|
933
|
+
const rapierContext = /*#__PURE__*/React.createContext(undefined);
|
934
934
|
|
935
935
|
const getCollisionPayloadFromSource = (target, other) => {
|
936
936
|
var _target$collider$stat, _target$rigidBody$sta, _other$collider$state, _other$rigidBody$stat, _other$collider$state2, _other$rigidBody$stat2;
|
@@ -971,8 +971,8 @@ const Physics = ({
|
|
971
971
|
interpolate: _interpolate = true
|
972
972
|
}) => {
|
973
973
|
const rapier = useAsset.useAsset(importRapier);
|
974
|
-
const worldRef = React
|
975
|
-
const getWorldRef = React
|
974
|
+
const worldRef = React.useRef();
|
975
|
+
const getWorldRef = React.useRef(() => {
|
976
976
|
if (!worldRef.current) {
|
977
977
|
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
978
978
|
worldRef.current = world;
|
@@ -989,7 +989,7 @@ const Physics = ({
|
|
989
989
|
const beforeStepCallbacks = useConst(() => new Set());
|
990
990
|
const afterStepCallbacks = useConst(() => new Set()); // Init world
|
991
991
|
|
992
|
-
React
|
992
|
+
React.useEffect(() => {
|
993
993
|
const world = getWorldRef.current();
|
994
994
|
return () => {
|
995
995
|
if (world) {
|
@@ -999,15 +999,15 @@ const Physics = ({
|
|
999
999
|
};
|
1000
1000
|
}, []); // Update gravity
|
1001
1001
|
|
1002
|
-
React
|
1002
|
+
React.useEffect(() => {
|
1003
1003
|
const world = worldRef.current;
|
1004
1004
|
|
1005
1005
|
if (world) {
|
1006
1006
|
world.gravity = vectorArrayToVector3(_gravity);
|
1007
1007
|
}
|
1008
1008
|
}, [_gravity]);
|
1009
|
-
const api = React
|
1010
|
-
const getSourceFromColliderHandle = React
|
1009
|
+
const api = React.useMemo(() => createWorldApi(getWorldRef), []);
|
1010
|
+
const getSourceFromColliderHandle = React.useCallback(handle => {
|
1011
1011
|
const world = worldRef.current;
|
1012
1012
|
|
1013
1013
|
if (world) {
|
@@ -1035,11 +1035,11 @@ const Physics = ({
|
|
1035
1035
|
return source;
|
1036
1036
|
}
|
1037
1037
|
}, []);
|
1038
|
-
const [steppingState] = React
|
1038
|
+
const [steppingState] = React.useState({
|
1039
1039
|
previousState: {},
|
1040
1040
|
accumulator: 0
|
1041
1041
|
});
|
1042
|
-
const step = React
|
1042
|
+
const step = React.useCallback(dt => {
|
1043
1043
|
const world = worldRef.current;
|
1044
1044
|
if (!world) return;
|
1045
1045
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
@@ -1254,7 +1254,7 @@ const Physics = ({
|
|
1254
1254
|
fiber.useFrame((_, dt) => {
|
1255
1255
|
if (!_paused) step(dt);
|
1256
1256
|
}, updatePriority);
|
1257
|
-
const context = React
|
1257
|
+
const context = React.useMemo(() => ({
|
1258
1258
|
rapier,
|
1259
1259
|
world: api,
|
1260
1260
|
physicsOptions: {
|
@@ -1328,7 +1328,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
1328
1328
|
}
|
1329
1329
|
|
1330
1330
|
// Colliders
|
1331
|
-
const AnyCollider = /*#__PURE__*/React
|
1331
|
+
const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["default"].forwardRef((props, forwardedRef) => {
|
1332
1332
|
const {
|
1333
1333
|
children,
|
1334
1334
|
position,
|
@@ -1343,8 +1343,8 @@ const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["defa
|
|
1343
1343
|
colliderStates
|
1344
1344
|
} = useRapier();
|
1345
1345
|
const rigidBodyContext = useRigidBodyContext();
|
1346
|
-
const ref = React
|
1347
|
-
const collidersRef = React
|
1346
|
+
const ref = React.useRef(null);
|
1347
|
+
const collidersRef = React.useMemo(() => {
|
1348
1348
|
if (forwardedRef !== null) {
|
1349
1349
|
return forwardedRef;
|
1350
1350
|
}
|
@@ -1353,7 +1353,7 @@ const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["defa
|
|
1353
1353
|
result.current = [];
|
1354
1354
|
return result;
|
1355
1355
|
}, []);
|
1356
|
-
React
|
1356
|
+
React.useEffect(() => {
|
1357
1357
|
const object = ref.current;
|
1358
1358
|
const worldScale = object.getWorldScale(new three.Vector3());
|
1359
1359
|
const colliders = []; // If this is an InstancedRigidBody api
|
@@ -1385,7 +1385,7 @@ const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["defa
|
|
1385
1385
|
});
|
1386
1386
|
};
|
1387
1387
|
}, []);
|
1388
|
-
const mergedProps = React
|
1388
|
+
const mergedProps = React.useMemo(() => {
|
1389
1389
|
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1390
1390
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1391
1391
|
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
@@ -1464,9 +1464,9 @@ CylinderCollider.displayName = "CylinderCollider";
|
|
1464
1464
|
ConvexHullCollider.displayName = "ConvexHullCollider";
|
1465
1465
|
|
1466
1466
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1467
|
-
const RigidBodyContext = /*#__PURE__*/React
|
1468
|
-
const useRigidBodyContext = () => React
|
1469
|
-
const RigidBody = /*#__PURE__*/React
|
1467
|
+
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1468
|
+
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1469
|
+
const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, ref) => {
|
1470
1470
|
const {
|
1471
1471
|
children,
|
1472
1472
|
type,
|
@@ -1478,8 +1478,8 @@ const RigidBody = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((pr
|
|
1478
1478
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1479
1479
|
|
1480
1480
|
const [object, api, childColliderProps] = useRigidBody(props);
|
1481
|
-
React
|
1482
|
-
const contextValue = React
|
1481
|
+
React.useImperativeHandle(ref, () => api);
|
1482
|
+
const contextValue = React.useMemo(() => ({
|
1483
1483
|
ref: object,
|
1484
1484
|
api,
|
1485
1485
|
options: props
|
@@ -1499,7 +1499,7 @@ const RigidBody = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((pr
|
|
1499
1499
|
}));
|
1500
1500
|
RigidBody.displayName = "RigidBody";
|
1501
1501
|
|
1502
|
-
const MeshCollider = /*#__PURE__*/React
|
1502
|
+
const MeshCollider = /*#__PURE__*/React.memo(props => {
|
1503
1503
|
const {
|
1504
1504
|
children,
|
1505
1505
|
type
|
@@ -1508,11 +1508,11 @@ const MeshCollider = /*#__PURE__*/React$1.memo(props => {
|
|
1508
1508
|
physicsOptions,
|
1509
1509
|
world
|
1510
1510
|
} = useRapier();
|
1511
|
-
const object = React
|
1511
|
+
const object = React.useRef(null);
|
1512
1512
|
const {
|
1513
1513
|
options
|
1514
1514
|
} = useRigidBodyContext();
|
1515
|
-
const mergedOptions = React
|
1515
|
+
const mergedOptions = React.useMemo(() => {
|
1516
1516
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1517
1517
|
children: undefined,
|
1518
1518
|
colliders: type
|
@@ -1552,10 +1552,10 @@ const AttractorHelper = props => {
|
|
1552
1552
|
const {
|
1553
1553
|
scene
|
1554
1554
|
} = fiber.useThree();
|
1555
|
-
const ref = React
|
1556
|
-
const normalsHelper = React
|
1555
|
+
const ref = React.useRef(null);
|
1556
|
+
const normalsHelper = React.useRef();
|
1557
1557
|
const color = props.strength > 0 ? 0x0000ff : 0xff0000;
|
1558
|
-
React
|
1558
|
+
React.useEffect(() => {
|
1559
1559
|
if (ref.current) {
|
1560
1560
|
normalsHelper.current = new threeStdlib.VertexNormalsHelper(ref.current, props.range, color);
|
1561
1561
|
normalsHelper.current.frustumCulled = false;
|
@@ -1589,14 +1589,14 @@ const AttractorHelper = props => {
|
|
1589
1589
|
}));
|
1590
1590
|
};
|
1591
1591
|
|
1592
|
-
const Debug = /*#__PURE__*/React
|
1592
|
+
const Debug = /*#__PURE__*/React.memo(() => {
|
1593
1593
|
const {
|
1594
1594
|
world,
|
1595
1595
|
attractorStates
|
1596
1596
|
} = useRapier();
|
1597
|
-
const ref = React
|
1598
|
-
const [attractors, setAttractors] = React
|
1599
|
-
const currMap = React
|
1597
|
+
const ref = React.useRef(null);
|
1598
|
+
const [attractors, setAttractors] = React.useState([]);
|
1599
|
+
const currMap = React.useRef(new Map());
|
1600
1600
|
fiber.useFrame(() => {
|
1601
1601
|
const mesh = ref.current;
|
1602
1602
|
if (!mesh) return;
|
@@ -1621,14 +1621,14 @@ const Debug = /*#__PURE__*/React$1.memo(() => {
|
|
1621
1621
|
});
|
1622
1622
|
|
1623
1623
|
const _excluded = ["positions", "rotations", "children"];
|
1624
|
-
const InstancedRigidBodies = /*#__PURE__*/React
|
1624
|
+
const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1625
1625
|
const {
|
1626
1626
|
world,
|
1627
1627
|
rigidBodyStates,
|
1628
1628
|
physicsOptions,
|
1629
1629
|
rigidBodyEvents
|
1630
1630
|
} = useRapier();
|
1631
|
-
const object = React
|
1631
|
+
const object = React.useRef(null);
|
1632
1632
|
|
1633
1633
|
const {
|
1634
1634
|
positions,
|
@@ -1637,20 +1637,20 @@ const InstancedRigidBodies = /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
|
1637
1637
|
} = props,
|
1638
1638
|
options = _objectWithoutProperties(props, _excluded);
|
1639
1639
|
|
1640
|
-
const instancesRef = React
|
1641
|
-
const rigidBodyRefs = React
|
1642
|
-
const instancesRefGetter = React
|
1640
|
+
const instancesRef = React.useRef([]);
|
1641
|
+
const rigidBodyRefs = React.useRef([]);
|
1642
|
+
const instancesRefGetter = React.useRef(() => {
|
1643
1643
|
if (!instancesRef.current) {
|
1644
1644
|
instancesRef.current = [];
|
1645
1645
|
}
|
1646
1646
|
|
1647
1647
|
return instancesRef.current;
|
1648
1648
|
});
|
1649
|
-
const mergedOptions = React
|
1649
|
+
const mergedOptions = React.useMemo(() => {
|
1650
1650
|
return _objectSpread2(_objectSpread2({}, physicsOptions), options);
|
1651
1651
|
}, [physicsOptions, options]);
|
1652
1652
|
const childColliderProps = useChildColliderProps(object, mergedOptions);
|
1653
|
-
React
|
1653
|
+
React.useLayoutEffect(() => {
|
1654
1654
|
object.current.updateWorldMatrix(true, false);
|
1655
1655
|
const instances = instancesRefGetter.current();
|
1656
1656
|
const invertedWorld = object.current.matrixWorld.clone().invert();
|
@@ -1711,22 +1711,22 @@ const InstancedRigidBodies = /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
|
1711
1711
|
instancesRef.current = [];
|
1712
1712
|
};
|
1713
1713
|
}, []);
|
1714
|
-
const api = React
|
1715
|
-
React
|
1714
|
+
const api = React.useMemo(() => createInstancedRigidBodiesApi(instancesRefGetter), []);
|
1715
|
+
React.useImperativeHandle(ref, () => api);
|
1716
1716
|
useUpdateRigidBodyOptions(rigidBodyRefs, mergedOptions, rigidBodyStates, false);
|
1717
1717
|
useRigidBodyEvents(rigidBodyRefs, mergedOptions, rigidBodyEvents);
|
1718
|
-
const contextValue = React
|
1718
|
+
const contextValue = React.useMemo(() => {
|
1719
1719
|
return {
|
1720
1720
|
ref: object,
|
1721
1721
|
api,
|
1722
1722
|
options: mergedOptions
|
1723
1723
|
};
|
1724
1724
|
}, [api, mergedOptions]);
|
1725
|
-
return /*#__PURE__*/
|
1725
|
+
return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
|
1726
1726
|
value: contextValue
|
1727
|
-
}, /*#__PURE__*/
|
1727
|
+
}, /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1728
1728
|
ref: object
|
1729
|
-
}, props.children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/
|
1729
|
+
}, props.children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1730
1730
|
key: index
|
1731
1731
|
}, colliderProps)))));
|
1732
1732
|
});
|
@@ -1736,8 +1736,8 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1736
1736
|
const {
|
1737
1737
|
world
|
1738
1738
|
} = useRapier();
|
1739
|
-
const jointRef = React
|
1740
|
-
const getJointRef = React
|
1739
|
+
const jointRef = React.useRef();
|
1740
|
+
const getJointRef = React.useRef(() => {
|
1741
1741
|
if (!jointRef.current) {
|
1742
1742
|
let rb1;
|
1743
1743
|
let rb2;
|
@@ -1752,7 +1752,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1752
1752
|
|
1753
1753
|
return jointRef.current;
|
1754
1754
|
});
|
1755
|
-
React
|
1755
|
+
React.useEffect(() => {
|
1756
1756
|
const joint = getJointRef.current();
|
1757
1757
|
return () => {
|
1758
1758
|
if (joint) {
|
@@ -1761,7 +1761,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1761
1761
|
}
|
1762
1762
|
};
|
1763
1763
|
}, []);
|
1764
|
-
const api = React
|
1764
|
+
const api = React.useMemo(() => createJointApi(getJointRef), []);
|
1765
1765
|
return api;
|
1766
1766
|
};
|
1767
1767
|
/**
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var rapier3dCompat = require('@dimforge/rapier3d-compat');
|
6
6
|
var fiber = require('@react-three/fiber');
|
7
|
-
var React
|
7
|
+
var React = require('react');
|
8
8
|
var three = require('three');
|
9
9
|
var useAsset = require('use-asset');
|
10
10
|
var threeStdlib = require('three-stdlib');
|
@@ -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);
|
33
33
|
|
34
34
|
function _defineProperty(obj, key, value) {
|
35
35
|
if (key in obj) {
|
@@ -138,7 +138,7 @@ const vectorToTuple = v => {
|
|
138
138
|
return [v];
|
139
139
|
};
|
140
140
|
function useConst(initialValue) {
|
141
|
-
const ref = React
|
141
|
+
const ref = React.useRef();
|
142
142
|
|
143
143
|
if (ref.current === undefined) {
|
144
144
|
ref.current = {
|
@@ -426,10 +426,10 @@ const setColliderOptions = (collider, options, states) => {
|
|
426
426
|
};
|
427
427
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
428
428
|
// TODO: Improve this, split each prop into its own effect
|
429
|
-
const mutablePropsAsFlatArray = React
|
429
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
430
430
|
return vectorToTuple(props[key]);
|
431
431
|
}), [props]);
|
432
|
-
React
|
432
|
+
React.useEffect(() => {
|
433
433
|
collidersRef.current.forEach(collider => {
|
434
434
|
setColliderOptions(collider, props, states);
|
435
435
|
});
|
@@ -563,7 +563,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
563
563
|
onIntersectionExit,
|
564
564
|
onContactForce
|
565
565
|
} = props;
|
566
|
-
React
|
566
|
+
React.useEffect(() => {
|
567
567
|
var _collidersRef$current;
|
568
568
|
|
569
569
|
(_collidersRef$current = collidersRef.current) === null || _collidersRef$current === void 0 ? void 0 : _collidersRef$current.forEach(collider => {
|
@@ -703,10 +703,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
703
703
|
};
|
704
704
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
705
705
|
// TODO: Improve this, split each prop into its own effect
|
706
|
-
const mutablePropsAsFlatArray = React
|
706
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
707
707
|
return vectorToTuple(props[key]);
|
708
708
|
}), [props]);
|
709
|
-
React
|
709
|
+
React.useEffect(() => {
|
710
710
|
if (Array.isArray(rigidBodyRef.current)) {
|
711
711
|
for (const rigidBody of rigidBodyRef.current) {
|
712
712
|
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
@@ -733,7 +733,7 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
733
733
|
onIntersectionEnter,
|
734
734
|
onIntersectionExit
|
735
735
|
};
|
736
|
-
React
|
736
|
+
React.useEffect(() => {
|
737
737
|
if (Array.isArray(rigidBodyRef.current)) {
|
738
738
|
for (const rigidBody of rigidBodyRef.current) {
|
739
739
|
events.set(rigidBody.handle, eventHandlers);
|
@@ -755,13 +755,13 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
755
755
|
};
|
756
756
|
|
757
757
|
const useRapier = () => {
|
758
|
-
return React
|
758
|
+
return React.useContext(rapierContext);
|
759
759
|
};
|
760
760
|
const useBeforePhysicsStep = callback => {
|
761
761
|
const {
|
762
762
|
beforeStepCallbacks
|
763
763
|
} = useRapier();
|
764
|
-
React
|
764
|
+
React.useEffect(() => {
|
765
765
|
beforeStepCallbacks.add(callback);
|
766
766
|
return () => {
|
767
767
|
beforeStepCallbacks.delete(callback);
|
@@ -772,7 +772,7 @@ const useAfterPhysicsStep = callback => {
|
|
772
772
|
const {
|
773
773
|
afterStepCallbacks
|
774
774
|
} = useRapier();
|
775
|
-
React
|
775
|
+
React.useEffect(() => {
|
776
776
|
afterStepCallbacks.add(callback);
|
777
777
|
return () => {
|
778
778
|
afterStepCallbacks.delete(callback);
|
@@ -781,8 +781,8 @@ const useAfterPhysicsStep = callback => {
|
|
781
781
|
}; // Internal hooks
|
782
782
|
|
783
783
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
784
|
-
const [colliderProps, setColliderProps] = React
|
785
|
-
React
|
784
|
+
const [colliderProps, setColliderProps] = React.useState([]);
|
785
|
+
React.useEffect(() => {
|
786
786
|
const object = ref.current;
|
787
787
|
|
788
788
|
if (object && options.colliders !== false) {
|
@@ -802,16 +802,16 @@ const useRigidBody = (options = {}) => {
|
|
802
802
|
physicsOptions,
|
803
803
|
rigidBodyEvents
|
804
804
|
} = useRapier();
|
805
|
-
const ref = React
|
806
|
-
const mergedOptions = React
|
805
|
+
const ref = React.useRef();
|
806
|
+
const mergedOptions = React.useMemo(() => {
|
807
807
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
808
808
|
children: undefined
|
809
809
|
});
|
810
810
|
}, [physicsOptions, options]);
|
811
811
|
const childColliderProps = useChildColliderProps(ref, mergedOptions); // Create rigidbody
|
812
812
|
|
813
|
-
const rigidBodyRef = React
|
814
|
-
const getRigidBodyRef = React
|
813
|
+
const rigidBodyRef = React.useRef();
|
814
|
+
const getRigidBodyRef = React.useRef(() => {
|
815
815
|
if (!rigidBodyRef.current) {
|
816
816
|
const desc = rigidBodyDescFromOptions(options);
|
817
817
|
const rigidBody = world.createRigidBody(desc);
|
@@ -821,7 +821,7 @@ const useRigidBody = (options = {}) => {
|
|
821
821
|
return rigidBodyRef.current;
|
822
822
|
}); // Setup
|
823
823
|
|
824
|
-
React
|
824
|
+
React.useEffect(() => {
|
825
825
|
const rigidBody = getRigidBodyRef.current();
|
826
826
|
rigidBodyRef.current = rigidBody;
|
827
827
|
|
@@ -841,7 +841,7 @@ const useRigidBody = (options = {}) => {
|
|
841
841
|
}, []);
|
842
842
|
useUpdateRigidBodyOptions(rigidBodyRef, mergedOptions, rigidBodyStates);
|
843
843
|
useRigidBodyEvents(rigidBodyRef, mergedOptions, rigidBodyEvents);
|
844
|
-
const api = React
|
844
|
+
const api = React.useMemo(() => createRigidBodyApi(getRigidBodyRef), []);
|
845
845
|
return [ref, api, childColliderProps];
|
846
846
|
};
|
847
847
|
|
@@ -891,7 +891,7 @@ const applyAttractorForceOnRigidBody = (rigidBody, {
|
|
891
891
|
}
|
892
892
|
}
|
893
893
|
};
|
894
|
-
const Attractor = /*#__PURE__*/React
|
894
|
+
const Attractor = /*#__PURE__*/React.memo(props => {
|
895
895
|
const {
|
896
896
|
position = [0, 0, 0],
|
897
897
|
strength = 1,
|
@@ -903,8 +903,8 @@ const Attractor = /*#__PURE__*/React$1.memo(props => {
|
|
903
903
|
const {
|
904
904
|
attractorStates
|
905
905
|
} = useRapier();
|
906
|
-
const object = React
|
907
|
-
React
|
906
|
+
const object = React.useRef(null);
|
907
|
+
React.useEffect(() => {
|
908
908
|
var _object$current;
|
909
909
|
|
910
910
|
let uuid = ((_object$current = object.current) === null || _object$current === void 0 ? void 0 : _object$current.uuid) || "_";
|
@@ -930,7 +930,7 @@ const Attractor = /*#__PURE__*/React$1.memo(props => {
|
|
930
930
|
});
|
931
931
|
});
|
932
932
|
|
933
|
-
const rapierContext = /*#__PURE__*/React
|
933
|
+
const rapierContext = /*#__PURE__*/React.createContext(undefined);
|
934
934
|
|
935
935
|
const getCollisionPayloadFromSource = (target, other) => {
|
936
936
|
var _target$collider$stat, _target$rigidBody$sta, _other$collider$state, _other$rigidBody$stat, _other$collider$state2, _other$rigidBody$stat2;
|
@@ -971,8 +971,8 @@ const Physics = ({
|
|
971
971
|
interpolate: _interpolate = true
|
972
972
|
}) => {
|
973
973
|
const rapier = useAsset.useAsset(importRapier);
|
974
|
-
const worldRef = React
|
975
|
-
const getWorldRef = React
|
974
|
+
const worldRef = React.useRef();
|
975
|
+
const getWorldRef = React.useRef(() => {
|
976
976
|
if (!worldRef.current) {
|
977
977
|
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
978
978
|
worldRef.current = world;
|
@@ -989,7 +989,7 @@ const Physics = ({
|
|
989
989
|
const beforeStepCallbacks = useConst(() => new Set());
|
990
990
|
const afterStepCallbacks = useConst(() => new Set()); // Init world
|
991
991
|
|
992
|
-
React
|
992
|
+
React.useEffect(() => {
|
993
993
|
const world = getWorldRef.current();
|
994
994
|
return () => {
|
995
995
|
if (world) {
|
@@ -999,15 +999,15 @@ const Physics = ({
|
|
999
999
|
};
|
1000
1000
|
}, []); // Update gravity
|
1001
1001
|
|
1002
|
-
React
|
1002
|
+
React.useEffect(() => {
|
1003
1003
|
const world = worldRef.current;
|
1004
1004
|
|
1005
1005
|
if (world) {
|
1006
1006
|
world.gravity = vectorArrayToVector3(_gravity);
|
1007
1007
|
}
|
1008
1008
|
}, [_gravity]);
|
1009
|
-
const api = React
|
1010
|
-
const getSourceFromColliderHandle = React
|
1009
|
+
const api = React.useMemo(() => createWorldApi(getWorldRef), []);
|
1010
|
+
const getSourceFromColliderHandle = React.useCallback(handle => {
|
1011
1011
|
const world = worldRef.current;
|
1012
1012
|
|
1013
1013
|
if (world) {
|
@@ -1035,11 +1035,11 @@ const Physics = ({
|
|
1035
1035
|
return source;
|
1036
1036
|
}
|
1037
1037
|
}, []);
|
1038
|
-
const [steppingState] = React
|
1038
|
+
const [steppingState] = React.useState({
|
1039
1039
|
previousState: {},
|
1040
1040
|
accumulator: 0
|
1041
1041
|
});
|
1042
|
-
const step = React
|
1042
|
+
const step = React.useCallback(dt => {
|
1043
1043
|
const world = worldRef.current;
|
1044
1044
|
if (!world) return;
|
1045
1045
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
@@ -1254,7 +1254,7 @@ const Physics = ({
|
|
1254
1254
|
fiber.useFrame((_, dt) => {
|
1255
1255
|
if (!_paused) step(dt);
|
1256
1256
|
}, updatePriority);
|
1257
|
-
const context = React
|
1257
|
+
const context = React.useMemo(() => ({
|
1258
1258
|
rapier,
|
1259
1259
|
world: api,
|
1260
1260
|
physicsOptions: {
|
@@ -1328,7 +1328,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
1328
1328
|
}
|
1329
1329
|
|
1330
1330
|
// Colliders
|
1331
|
-
const AnyCollider = /*#__PURE__*/React
|
1331
|
+
const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React__default["default"].forwardRef((props, forwardedRef) => {
|
1332
1332
|
const {
|
1333
1333
|
children,
|
1334
1334
|
position,
|
@@ -1343,8 +1343,8 @@ const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["defa
|
|
1343
1343
|
colliderStates
|
1344
1344
|
} = useRapier();
|
1345
1345
|
const rigidBodyContext = useRigidBodyContext();
|
1346
|
-
const ref = React
|
1347
|
-
const collidersRef = React
|
1346
|
+
const ref = React.useRef(null);
|
1347
|
+
const collidersRef = React.useMemo(() => {
|
1348
1348
|
if (forwardedRef !== null) {
|
1349
1349
|
return forwardedRef;
|
1350
1350
|
}
|
@@ -1353,7 +1353,7 @@ const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["defa
|
|
1353
1353
|
result.current = [];
|
1354
1354
|
return result;
|
1355
1355
|
}, []);
|
1356
|
-
React
|
1356
|
+
React.useEffect(() => {
|
1357
1357
|
const object = ref.current;
|
1358
1358
|
const worldScale = object.getWorldScale(new three.Vector3());
|
1359
1359
|
const colliders = []; // If this is an InstancedRigidBody api
|
@@ -1385,7 +1385,7 @@ const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React__default["defa
|
|
1385
1385
|
});
|
1386
1386
|
};
|
1387
1387
|
}, []);
|
1388
|
-
const mergedProps = React
|
1388
|
+
const mergedProps = React.useMemo(() => {
|
1389
1389
|
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1390
1390
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1391
1391
|
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
@@ -1464,9 +1464,9 @@ CylinderCollider.displayName = "CylinderCollider";
|
|
1464
1464
|
ConvexHullCollider.displayName = "ConvexHullCollider";
|
1465
1465
|
|
1466
1466
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1467
|
-
const RigidBodyContext = /*#__PURE__*/React
|
1468
|
-
const useRigidBodyContext = () => React
|
1469
|
-
const RigidBody = /*#__PURE__*/React
|
1467
|
+
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1468
|
+
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1469
|
+
const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, ref) => {
|
1470
1470
|
const {
|
1471
1471
|
children,
|
1472
1472
|
type,
|
@@ -1478,8 +1478,8 @@ const RigidBody = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((pr
|
|
1478
1478
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1479
1479
|
|
1480
1480
|
const [object, api, childColliderProps] = useRigidBody(props);
|
1481
|
-
React
|
1482
|
-
const contextValue = React
|
1481
|
+
React.useImperativeHandle(ref, () => api);
|
1482
|
+
const contextValue = React.useMemo(() => ({
|
1483
1483
|
ref: object,
|
1484
1484
|
api,
|
1485
1485
|
options: props
|
@@ -1499,7 +1499,7 @@ const RigidBody = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((pr
|
|
1499
1499
|
}));
|
1500
1500
|
RigidBody.displayName = "RigidBody";
|
1501
1501
|
|
1502
|
-
const MeshCollider = /*#__PURE__*/React
|
1502
|
+
const MeshCollider = /*#__PURE__*/React.memo(props => {
|
1503
1503
|
const {
|
1504
1504
|
children,
|
1505
1505
|
type
|
@@ -1508,11 +1508,11 @@ const MeshCollider = /*#__PURE__*/React$1.memo(props => {
|
|
1508
1508
|
physicsOptions,
|
1509
1509
|
world
|
1510
1510
|
} = useRapier();
|
1511
|
-
const object = React
|
1511
|
+
const object = React.useRef(null);
|
1512
1512
|
const {
|
1513
1513
|
options
|
1514
1514
|
} = useRigidBodyContext();
|
1515
|
-
const mergedOptions = React
|
1515
|
+
const mergedOptions = React.useMemo(() => {
|
1516
1516
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1517
1517
|
children: undefined,
|
1518
1518
|
colliders: type
|
@@ -1552,10 +1552,10 @@ const AttractorHelper = props => {
|
|
1552
1552
|
const {
|
1553
1553
|
scene
|
1554
1554
|
} = fiber.useThree();
|
1555
|
-
const ref = React
|
1556
|
-
const normalsHelper = React
|
1555
|
+
const ref = React.useRef(null);
|
1556
|
+
const normalsHelper = React.useRef();
|
1557
1557
|
const color = props.strength > 0 ? 0x0000ff : 0xff0000;
|
1558
|
-
React
|
1558
|
+
React.useEffect(() => {
|
1559
1559
|
if (ref.current) {
|
1560
1560
|
normalsHelper.current = new threeStdlib.VertexNormalsHelper(ref.current, props.range, color);
|
1561
1561
|
normalsHelper.current.frustumCulled = false;
|
@@ -1589,14 +1589,14 @@ const AttractorHelper = props => {
|
|
1589
1589
|
}));
|
1590
1590
|
};
|
1591
1591
|
|
1592
|
-
const Debug = /*#__PURE__*/React
|
1592
|
+
const Debug = /*#__PURE__*/React.memo(() => {
|
1593
1593
|
const {
|
1594
1594
|
world,
|
1595
1595
|
attractorStates
|
1596
1596
|
} = useRapier();
|
1597
|
-
const ref = React
|
1598
|
-
const [attractors, setAttractors] = React
|
1599
|
-
const currMap = React
|
1597
|
+
const ref = React.useRef(null);
|
1598
|
+
const [attractors, setAttractors] = React.useState([]);
|
1599
|
+
const currMap = React.useRef(new Map());
|
1600
1600
|
fiber.useFrame(() => {
|
1601
1601
|
const mesh = ref.current;
|
1602
1602
|
if (!mesh) return;
|
@@ -1621,14 +1621,14 @@ const Debug = /*#__PURE__*/React$1.memo(() => {
|
|
1621
1621
|
});
|
1622
1622
|
|
1623
1623
|
const _excluded = ["positions", "rotations", "children"];
|
1624
|
-
const InstancedRigidBodies = /*#__PURE__*/React
|
1624
|
+
const InstancedRigidBodies = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1625
1625
|
const {
|
1626
1626
|
world,
|
1627
1627
|
rigidBodyStates,
|
1628
1628
|
physicsOptions,
|
1629
1629
|
rigidBodyEvents
|
1630
1630
|
} = useRapier();
|
1631
|
-
const object = React
|
1631
|
+
const object = React.useRef(null);
|
1632
1632
|
|
1633
1633
|
const {
|
1634
1634
|
positions,
|
@@ -1637,20 +1637,20 @@ const InstancedRigidBodies = /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
|
1637
1637
|
} = props,
|
1638
1638
|
options = _objectWithoutProperties(props, _excluded);
|
1639
1639
|
|
1640
|
-
const instancesRef = React
|
1641
|
-
const rigidBodyRefs = React
|
1642
|
-
const instancesRefGetter = React
|
1640
|
+
const instancesRef = React.useRef([]);
|
1641
|
+
const rigidBodyRefs = React.useRef([]);
|
1642
|
+
const instancesRefGetter = React.useRef(() => {
|
1643
1643
|
if (!instancesRef.current) {
|
1644
1644
|
instancesRef.current = [];
|
1645
1645
|
}
|
1646
1646
|
|
1647
1647
|
return instancesRef.current;
|
1648
1648
|
});
|
1649
|
-
const mergedOptions = React
|
1649
|
+
const mergedOptions = React.useMemo(() => {
|
1650
1650
|
return _objectSpread2(_objectSpread2({}, physicsOptions), options);
|
1651
1651
|
}, [physicsOptions, options]);
|
1652
1652
|
const childColliderProps = useChildColliderProps(object, mergedOptions);
|
1653
|
-
React
|
1653
|
+
React.useLayoutEffect(() => {
|
1654
1654
|
object.current.updateWorldMatrix(true, false);
|
1655
1655
|
const instances = instancesRefGetter.current();
|
1656
1656
|
const invertedWorld = object.current.matrixWorld.clone().invert();
|
@@ -1711,22 +1711,22 @@ const InstancedRigidBodies = /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
|
1711
1711
|
instancesRef.current = [];
|
1712
1712
|
};
|
1713
1713
|
}, []);
|
1714
|
-
const api = React
|
1715
|
-
React
|
1714
|
+
const api = React.useMemo(() => createInstancedRigidBodiesApi(instancesRefGetter), []);
|
1715
|
+
React.useImperativeHandle(ref, () => api);
|
1716
1716
|
useUpdateRigidBodyOptions(rigidBodyRefs, mergedOptions, rigidBodyStates, false);
|
1717
1717
|
useRigidBodyEvents(rigidBodyRefs, mergedOptions, rigidBodyEvents);
|
1718
|
-
const contextValue = React
|
1718
|
+
const contextValue = React.useMemo(() => {
|
1719
1719
|
return {
|
1720
1720
|
ref: object,
|
1721
1721
|
api,
|
1722
1722
|
options: mergedOptions
|
1723
1723
|
};
|
1724
1724
|
}, [api, mergedOptions]);
|
1725
|
-
return /*#__PURE__*/
|
1725
|
+
return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
|
1726
1726
|
value: contextValue
|
1727
|
-
}, /*#__PURE__*/
|
1727
|
+
}, /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1728
1728
|
ref: object
|
1729
|
-
}, props.children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/
|
1729
|
+
}, props.children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1730
1730
|
key: index
|
1731
1731
|
}, colliderProps)))));
|
1732
1732
|
});
|
@@ -1736,8 +1736,8 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1736
1736
|
const {
|
1737
1737
|
world
|
1738
1738
|
} = useRapier();
|
1739
|
-
const jointRef = React
|
1740
|
-
const getJointRef = React
|
1739
|
+
const jointRef = React.useRef();
|
1740
|
+
const getJointRef = React.useRef(() => {
|
1741
1741
|
if (!jointRef.current) {
|
1742
1742
|
let rb1;
|
1743
1743
|
let rb2;
|
@@ -1752,7 +1752,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1752
1752
|
|
1753
1753
|
return jointRef.current;
|
1754
1754
|
});
|
1755
|
-
React
|
1755
|
+
React.useEffect(() => {
|
1756
1756
|
const joint = getJointRef.current();
|
1757
1757
|
return () => {
|
1758
1758
|
if (joint) {
|
@@ -1761,7 +1761,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1761
1761
|
}
|
1762
1762
|
};
|
1763
1763
|
}, []);
|
1764
|
-
const api = React
|
1764
|
+
const api = React.useMemo(() => createJointApi(getJointRef), []);
|
1765
1765
|
return api;
|
1766
1766
|
};
|
1767
1767
|
/**
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ColliderDesc, ActiveEvents, RigidBodyDesc, EventQueue } 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
|
4
|
+
import React, { useRef, useMemo, useEffect, useContext, useState, memo, createContext, useCallback, forwardRef, useImperativeHandle, useLayoutEffect } from 'react';
|
5
5
|
import { Quaternion, Euler, Vector3, Object3D, Matrix4, MathUtils, InstancedMesh, BufferAttribute, DynamicDrawUsage } from 'three';
|
6
6
|
import { useAsset } from 'use-asset';
|
7
7
|
import { mergeVertices, VertexNormalsHelper } from 'three-stdlib';
|
@@ -899,7 +899,7 @@ const Attractor = /*#__PURE__*/memo(props => {
|
|
899
899
|
attractorStates.delete(uuid);
|
900
900
|
};
|
901
901
|
}, [props]);
|
902
|
-
return /*#__PURE__*/React
|
902
|
+
return /*#__PURE__*/React.createElement("object3D", {
|
903
903
|
ref: object,
|
904
904
|
position: position
|
905
905
|
});
|
@@ -1246,7 +1246,7 @@ const Physics = ({
|
|
1246
1246
|
isPaused: _paused,
|
1247
1247
|
step
|
1248
1248
|
}), [_paused, step]);
|
1249
|
-
return /*#__PURE__*/React
|
1249
|
+
return /*#__PURE__*/React.createElement(rapierContext.Provider, {
|
1250
1250
|
value: context
|
1251
1251
|
}, children);
|
1252
1252
|
};
|
@@ -1303,7 +1303,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
1303
1303
|
}
|
1304
1304
|
|
1305
1305
|
// Colliders
|
1306
|
-
const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/React
|
1306
|
+
const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
1307
1307
|
const {
|
1308
1308
|
children,
|
1309
1309
|
position,
|
@@ -1324,7 +1324,7 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/React$1.forwardRef((props, f
|
|
1324
1324
|
return forwardedRef;
|
1325
1325
|
}
|
1326
1326
|
|
1327
|
-
const result = /*#__PURE__*/React
|
1327
|
+
const result = /*#__PURE__*/React.createRef();
|
1328
1328
|
result.current = [];
|
1329
1329
|
return result;
|
1330
1330
|
}, []);
|
@@ -1365,7 +1365,7 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/React$1.forwardRef((props, f
|
|
1365
1365
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1366
1366
|
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
1367
1367
|
useColliderEvents(collidersRef, mergedProps, colliderEvents);
|
1368
|
-
return /*#__PURE__*/React
|
1368
|
+
return /*#__PURE__*/React.createElement("object3D", {
|
1369
1369
|
position: position,
|
1370
1370
|
rotation: rotation,
|
1371
1371
|
quaternion: quaternion,
|
@@ -1374,56 +1374,56 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/React$1.forwardRef((props, f
|
|
1374
1374
|
name: name
|
1375
1375
|
}, children);
|
1376
1376
|
}));
|
1377
|
-
const CuboidCollider = /*#__PURE__*/React
|
1378
|
-
return /*#__PURE__*/React
|
1377
|
+
const CuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1378
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1379
1379
|
shape: "cuboid",
|
1380
1380
|
ref: ref
|
1381
1381
|
}));
|
1382
1382
|
});
|
1383
|
-
const RoundCuboidCollider = /*#__PURE__*/React
|
1384
|
-
return /*#__PURE__*/React
|
1383
|
+
const RoundCuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1384
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1385
1385
|
shape: "roundCuboid",
|
1386
1386
|
ref: ref
|
1387
1387
|
}));
|
1388
1388
|
});
|
1389
|
-
const BallCollider = /*#__PURE__*/React
|
1390
|
-
return /*#__PURE__*/React
|
1389
|
+
const BallCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1390
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1391
1391
|
shape: "ball",
|
1392
1392
|
ref: ref
|
1393
1393
|
}));
|
1394
1394
|
});
|
1395
|
-
const CapsuleCollider = /*#__PURE__*/React
|
1396
|
-
return /*#__PURE__*/React
|
1395
|
+
const CapsuleCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1396
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1397
1397
|
shape: "capsule",
|
1398
1398
|
ref: ref
|
1399
1399
|
}));
|
1400
1400
|
});
|
1401
|
-
const HeightfieldCollider = /*#__PURE__*/React
|
1402
|
-
return /*#__PURE__*/React
|
1401
|
+
const HeightfieldCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1402
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1403
1403
|
shape: "heightfield",
|
1404
1404
|
ref: ref
|
1405
1405
|
}));
|
1406
1406
|
});
|
1407
|
-
const TrimeshCollider = /*#__PURE__*/React
|
1408
|
-
return /*#__PURE__*/React
|
1407
|
+
const TrimeshCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1408
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1409
1409
|
shape: "trimesh",
|
1410
1410
|
ref: ref
|
1411
1411
|
}));
|
1412
1412
|
});
|
1413
|
-
const ConeCollider = /*#__PURE__*/React
|
1414
|
-
return /*#__PURE__*/React
|
1413
|
+
const ConeCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1414
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1415
1415
|
shape: "cone",
|
1416
1416
|
ref: ref
|
1417
1417
|
}));
|
1418
1418
|
});
|
1419
|
-
const CylinderCollider = /*#__PURE__*/React
|
1420
|
-
return /*#__PURE__*/React
|
1419
|
+
const CylinderCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1420
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1421
1421
|
shape: "cylinder",
|
1422
1422
|
ref: ref
|
1423
1423
|
}));
|
1424
1424
|
});
|
1425
|
-
const ConvexHullCollider = /*#__PURE__*/React
|
1426
|
-
return /*#__PURE__*/React
|
1425
|
+
const ConvexHullCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1426
|
+
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1427
1427
|
shape: "convexHull",
|
1428
1428
|
ref: ref
|
1429
1429
|
}));
|
@@ -1459,16 +1459,16 @@ const RigidBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, ref) => {
|
|
1459
1459
|
api,
|
1460
1460
|
options: props
|
1461
1461
|
}), [object, api, props]);
|
1462
|
-
return /*#__PURE__*/React
|
1462
|
+
return /*#__PURE__*/React.createElement(RigidBodyContext.Provider, {
|
1463
1463
|
value: contextValue
|
1464
|
-
}, /*#__PURE__*/React
|
1464
|
+
}, /*#__PURE__*/React.createElement("object3D", _extends({
|
1465
1465
|
ref: object
|
1466
1466
|
}, objectProps, {
|
1467
1467
|
position: position,
|
1468
1468
|
rotation: rotation,
|
1469
1469
|
quaternion: quaternion,
|
1470
1470
|
scale: scale
|
1471
|
-
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React
|
1471
|
+
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React.createElement(AnyCollider, _extends({
|
1472
1472
|
key: index
|
1473
1473
|
}, colliderProps)))));
|
1474
1474
|
}));
|
@@ -1494,12 +1494,12 @@ const MeshCollider = /*#__PURE__*/memo(props => {
|
|
1494
1494
|
});
|
1495
1495
|
}, [physicsOptions, options]);
|
1496
1496
|
const childColliderProps = useChildColliderProps(object, mergedOptions, false);
|
1497
|
-
return /*#__PURE__*/React
|
1497
|
+
return /*#__PURE__*/React.createElement("object3D", {
|
1498
1498
|
ref: object,
|
1499
1499
|
userData: {
|
1500
1500
|
r3RapierType: "MeshCollider"
|
1501
1501
|
}
|
1502
|
-
}, children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React
|
1502
|
+
}, children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React.createElement(AnyCollider, _extends({
|
1503
1503
|
key: index
|
1504
1504
|
}, colliderProps))));
|
1505
1505
|
});
|
@@ -1552,13 +1552,13 @@ const AttractorHelper = props => {
|
|
1552
1552
|
(_normalsHelper$curren = normalsHelper.current) === null || _normalsHelper$curren === void 0 ? void 0 : _normalsHelper$curren.update();
|
1553
1553
|
}
|
1554
1554
|
});
|
1555
|
-
return /*#__PURE__*/React
|
1555
|
+
return /*#__PURE__*/React.createElement("mesh", {
|
1556
1556
|
ref: ref,
|
1557
1557
|
position: props.object.position,
|
1558
1558
|
frustumCulled: false
|
1559
|
-
}, /*#__PURE__*/React
|
1559
|
+
}, /*#__PURE__*/React.createElement("sphereGeometry", {
|
1560
1560
|
args: [0.2, 6, 6]
|
1561
|
-
}), /*#__PURE__*/React
|
1561
|
+
}), /*#__PURE__*/React.createElement("meshBasicMaterial", {
|
1562
1562
|
color: color,
|
1563
1563
|
wireframe: true
|
1564
1564
|
}));
|
@@ -1584,13 +1584,13 @@ const Debug = /*#__PURE__*/memo(() => {
|
|
1584
1584
|
currMap.current = new Map(attractorStates);
|
1585
1585
|
}
|
1586
1586
|
});
|
1587
|
-
return /*#__PURE__*/React
|
1587
|
+
return /*#__PURE__*/React.createElement("group", null, /*#__PURE__*/React.createElement("lineSegments", {
|
1588
1588
|
ref: ref,
|
1589
1589
|
frustumCulled: false
|
1590
|
-
}, /*#__PURE__*/React
|
1590
|
+
}, /*#__PURE__*/React.createElement("lineBasicMaterial", {
|
1591
1591
|
color: 0xffffff,
|
1592
1592
|
vertexColors: true
|
1593
|
-
}), /*#__PURE__*/React
|
1593
|
+
}), /*#__PURE__*/React.createElement("bufferGeometry", null)), attractors.map((attractor, i) => /*#__PURE__*/React.createElement(AttractorHelper, _extends({
|
1594
1594
|
key: attractor.object.uuid
|
1595
1595
|
}, attractor))));
|
1596
1596
|
});
|