@react-three/rapier 0.14.0-rc.1 → 0.14.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarations/src/components/FrameStepper.d.ts +9 -0
- package/dist/declarations/src/components/Physics.d.ts +24 -0
- package/dist/react-three-rapier.cjs.dev.js +132 -90
- package/dist/react-three-rapier.cjs.prod.js +132 -90
- package/dist/react-three-rapier.esm.js +108 -66
- package/package.json +1 -1
- package/readme.md +11 -1
@@ -0,0 +1,9 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { PhysicsProps } from "./Physics";
|
3
|
+
interface FrameStepperProps {
|
4
|
+
type?: PhysicsProps["updateLoop"];
|
5
|
+
onStep: (dt: number) => void;
|
6
|
+
updatePriority?: number;
|
7
|
+
}
|
8
|
+
declare const _default: import("react").MemoExoticComponent<({ onStep, type, updatePriority }: FrameStepperProps) => JSX.Element>;
|
9
|
+
export default _default;
|
@@ -147,6 +147,30 @@ export interface PhysicsProps {
|
|
147
147
|
* @defaultValue true
|
148
148
|
**/
|
149
149
|
interpolate?: boolean;
|
150
|
+
/**
|
151
|
+
* The update priority at which the physics simulation should run.
|
152
|
+
* Only used when `updateLoop` is set to "follow".
|
153
|
+
*
|
154
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#taking-over-the-render-loop
|
155
|
+
* @defaultValue undefined
|
156
|
+
*/
|
157
|
+
updatePriority?: number;
|
158
|
+
/**
|
159
|
+
* Set the update loop strategy for the physics world.
|
160
|
+
*
|
161
|
+
* If set to "follow", the physics world will be stepped
|
162
|
+
* in a `useFrame` callback, managed by @react-three/fiber.
|
163
|
+
* You can use `updatePriority` prop to manage the scheduling.
|
164
|
+
*
|
165
|
+
* If set to "independent", the physics world will be stepped
|
166
|
+
* in a separate loop, not tied to the render loop.
|
167
|
+
* This is useful when using the "demand" `frameloop` strategy for the
|
168
|
+
* @react-three/fiber `<Canvas />`.
|
169
|
+
*
|
170
|
+
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
|
171
|
+
* @defaultValue "follow"
|
172
|
+
*/
|
173
|
+
updateLoop?: "follow" | "independent";
|
150
174
|
}
|
151
175
|
/**
|
152
176
|
* The main physics component used to create a physics world.
|
@@ -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 = require('react');
|
7
|
+
var React$1 = 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$1);
|
33
33
|
|
34
34
|
function _defineProperty(obj, key, value) {
|
35
35
|
if (key in obj) {
|
@@ -167,7 +167,7 @@ const vectorToTuple = v => {
|
|
167
167
|
return [v];
|
168
168
|
};
|
169
169
|
function useConst(initialValue) {
|
170
|
-
const ref = React.useRef();
|
170
|
+
const ref = React$1.useRef();
|
171
171
|
|
172
172
|
if (ref.current === undefined) {
|
173
173
|
ref.current = {
|
@@ -178,27 +178,6 @@ function useConst(initialValue) {
|
|
178
178
|
return ref.current.value;
|
179
179
|
}
|
180
180
|
|
181
|
-
const useRaf = callback => {
|
182
|
-
const cb = React.useRef(callback);
|
183
|
-
const raf = React.useRef(0);
|
184
|
-
const lastFrame = React.useRef(0);
|
185
|
-
React.useEffect(() => {
|
186
|
-
cb.current = callback;
|
187
|
-
}, [callback]);
|
188
|
-
React.useEffect(() => {
|
189
|
-
const loop = () => {
|
190
|
-
const now = performance.now();
|
191
|
-
const delta = now - lastFrame.current;
|
192
|
-
raf.current = requestAnimationFrame(loop);
|
193
|
-
cb.current(delta / 1000);
|
194
|
-
lastFrame.current = now;
|
195
|
-
};
|
196
|
-
|
197
|
-
raf.current = requestAnimationFrame(loop);
|
198
|
-
return () => cancelAnimationFrame(raf.current);
|
199
|
-
}, []);
|
200
|
-
};
|
201
|
-
|
202
181
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
203
182
|
if (source == null) return {};
|
204
183
|
var target = {};
|
@@ -365,10 +344,10 @@ const setColliderOptions = (collider, options, states) => {
|
|
365
344
|
};
|
366
345
|
const useUpdateColliderOptions = (getCollider, props, states) => {
|
367
346
|
// TODO: Improve this, split each prop into its own effect
|
368
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
347
|
+
const mutablePropsAsFlatArray = React$1.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
369
348
|
return vectorToTuple(props[key]);
|
370
349
|
}), [props]);
|
371
|
-
React.useEffect(() => {
|
350
|
+
React$1.useEffect(() => {
|
372
351
|
const collider = getCollider();
|
373
352
|
setColliderOptions(collider, props, states);
|
374
353
|
}, mutablePropsAsFlatArray);
|
@@ -514,7 +493,7 @@ activeEvents = {}) => {
|
|
514
493
|
onIntersectionExit,
|
515
494
|
onContactForce
|
516
495
|
} = props;
|
517
|
-
React.useEffect(() => {
|
496
|
+
React$1.useEffect(() => {
|
518
497
|
const collider = getCollider();
|
519
498
|
|
520
499
|
if (collider) {
|
@@ -556,8 +535,8 @@ const cleanRigidBodyPropsForCollider = (props = {}) => {
|
|
556
535
|
};
|
557
536
|
|
558
537
|
const useMutableCallback = fn => {
|
559
|
-
const ref = React.useRef(fn);
|
560
|
-
React.useEffect(() => {
|
538
|
+
const ref = React$1.useRef(fn);
|
539
|
+
React$1.useEffect(() => {
|
561
540
|
ref.current = fn;
|
562
541
|
}, [fn]);
|
563
542
|
return ref;
|
@@ -570,7 +549,7 @@ const useMutableCallback = fn => {
|
|
570
549
|
|
571
550
|
|
572
551
|
const useRapier = () => {
|
573
|
-
return React.useContext(rapierContext);
|
552
|
+
return React$1.useContext(rapierContext);
|
574
553
|
};
|
575
554
|
/**
|
576
555
|
* Registers a callback to be called before the physics step
|
@@ -582,7 +561,7 @@ const useBeforePhysicsStep = callback => {
|
|
582
561
|
beforeStepCallbacks
|
583
562
|
} = useRapier();
|
584
563
|
const ref = useMutableCallback(callback);
|
585
|
-
React.useEffect(() => {
|
564
|
+
React$1.useEffect(() => {
|
586
565
|
beforeStepCallbacks.add(ref);
|
587
566
|
return () => {
|
588
567
|
beforeStepCallbacks.delete(ref);
|
@@ -599,7 +578,7 @@ const useAfterPhysicsStep = callback => {
|
|
599
578
|
afterStepCallbacks
|
600
579
|
} = useRapier();
|
601
580
|
const ref = useMutableCallback(callback);
|
602
|
-
React.useEffect(() => {
|
581
|
+
React$1.useEffect(() => {
|
603
582
|
afterStepCallbacks.add(ref);
|
604
583
|
return () => {
|
605
584
|
afterStepCallbacks.delete(ref);
|
@@ -612,8 +591,8 @@ const useAfterPhysicsStep = callback => {
|
|
612
591
|
*/
|
613
592
|
|
614
593
|
const useChildColliderProps = (ref, options, ignoreMeshColliders = true) => {
|
615
|
-
const [colliderProps, setColliderProps] = React.useState([]);
|
616
|
-
React.useEffect(() => {
|
594
|
+
const [colliderProps, setColliderProps] = React$1.useState([]);
|
595
|
+
React$1.useEffect(() => {
|
617
596
|
const object = ref.current;
|
618
597
|
|
619
598
|
if (object && options.colliders !== false) {
|
@@ -673,7 +652,7 @@ const applyAttractorForceOnRigidBody = (rigidBody, {
|
|
673
652
|
}
|
674
653
|
}
|
675
654
|
};
|
676
|
-
const Attractor = /*#__PURE__*/React.memo(props => {
|
655
|
+
const Attractor = /*#__PURE__*/React$1.memo(props => {
|
677
656
|
const {
|
678
657
|
position = [0, 0, 0],
|
679
658
|
strength = 1,
|
@@ -685,8 +664,8 @@ const Attractor = /*#__PURE__*/React.memo(props => {
|
|
685
664
|
const {
|
686
665
|
attractorStates
|
687
666
|
} = useRapier();
|
688
|
-
const object = React.useRef(null);
|
689
|
-
React.useEffect(() => {
|
667
|
+
const object = React$1.useRef(null);
|
668
|
+
React$1.useEffect(() => {
|
690
669
|
var _object$current;
|
691
670
|
|
692
671
|
let uuid = ((_object$current = object.current) === null || _object$current === void 0 ? void 0 : _object$current.uuid) || "_";
|
@@ -712,7 +691,62 @@ const Attractor = /*#__PURE__*/React.memo(props => {
|
|
712
691
|
});
|
713
692
|
});
|
714
693
|
|
715
|
-
const
|
694
|
+
const useRaf = callback => {
|
695
|
+
const cb = React$1.useRef(callback);
|
696
|
+
const raf = React$1.useRef(0);
|
697
|
+
const lastFrame = React$1.useRef(0);
|
698
|
+
React$1.useEffect(() => {
|
699
|
+
cb.current = callback;
|
700
|
+
}, [callback]);
|
701
|
+
React$1.useEffect(() => {
|
702
|
+
const loop = () => {
|
703
|
+
const now = performance.now();
|
704
|
+
const delta = now - lastFrame.current;
|
705
|
+
raf.current = requestAnimationFrame(loop);
|
706
|
+
cb.current(delta / 1000);
|
707
|
+
lastFrame.current = now;
|
708
|
+
};
|
709
|
+
|
710
|
+
raf.current = requestAnimationFrame(loop);
|
711
|
+
return () => cancelAnimationFrame(raf.current);
|
712
|
+
}, []);
|
713
|
+
};
|
714
|
+
|
715
|
+
const UseFrameStepper = ({
|
716
|
+
onStep,
|
717
|
+
updatePriority
|
718
|
+
}) => {
|
719
|
+
fiber.useFrame((_, dt) => {
|
720
|
+
onStep(dt);
|
721
|
+
}, updatePriority);
|
722
|
+
return null;
|
723
|
+
};
|
724
|
+
|
725
|
+
const RafStepper = ({
|
726
|
+
onStep
|
727
|
+
}) => {
|
728
|
+
useRaf(dt => {
|
729
|
+
onStep(dt);
|
730
|
+
});
|
731
|
+
return null;
|
732
|
+
};
|
733
|
+
|
734
|
+
const FrameStepper = ({
|
735
|
+
onStep,
|
736
|
+
type,
|
737
|
+
updatePriority
|
738
|
+
}) => {
|
739
|
+
return type === "independent" ? /*#__PURE__*/React.createElement(RafStepper, {
|
740
|
+
onStep: onStep
|
741
|
+
}) : /*#__PURE__*/React.createElement(UseFrameStepper, {
|
742
|
+
onStep: onStep,
|
743
|
+
updatePriority: updatePriority
|
744
|
+
});
|
745
|
+
};
|
746
|
+
|
747
|
+
var FrameStepper$1 = /*#__PURE__*/React$1.memo(FrameStepper);
|
748
|
+
|
749
|
+
const rapierContext = /*#__PURE__*/React$1.createContext(undefined);
|
716
750
|
|
717
751
|
const getCollisionPayloadFromSource = (target, other) => {
|
718
752
|
var _target$collider$stat, _target$rigidBody$sta, _other$collider$state, _other$rigidBody$stat, _other$collider$state2, _other$rigidBody$stat2;
|
@@ -753,14 +787,16 @@ const Physics = ({
|
|
753
787
|
children,
|
754
788
|
timeStep: _timeStep = 1 / 60,
|
755
789
|
paused: _paused = false,
|
756
|
-
interpolate: _interpolate = true
|
790
|
+
interpolate: _interpolate = true,
|
791
|
+
updatePriority,
|
792
|
+
updateLoop: _updateLoop = "follow"
|
757
793
|
}) => {
|
758
794
|
const rapier = useAsset.useAsset(importRapier);
|
759
795
|
const {
|
760
796
|
invalidate
|
761
797
|
} = fiber.useThree();
|
762
|
-
const worldRef = React.useRef();
|
763
|
-
const getWorldRef = React.useRef(() => {
|
798
|
+
const worldRef = React$1.useRef();
|
799
|
+
const getWorldRef = React$1.useRef(() => {
|
764
800
|
if (!worldRef.current) {
|
765
801
|
const world = new rapier.World(vectorArrayToVector3(_gravity));
|
766
802
|
worldRef.current = world;
|
@@ -777,7 +813,7 @@ const Physics = ({
|
|
777
813
|
const beforeStepCallbacks = useConst(() => new Set());
|
778
814
|
const afterStepCallbacks = useConst(() => new Set()); // Init world
|
779
815
|
|
780
|
-
React.useEffect(() => {
|
816
|
+
React$1.useEffect(() => {
|
781
817
|
const world = getWorldRef.current();
|
782
818
|
return () => {
|
783
819
|
if (world) {
|
@@ -787,15 +823,15 @@ const Physics = ({
|
|
787
823
|
};
|
788
824
|
}, []); // Update gravity
|
789
825
|
|
790
|
-
React.useEffect(() => {
|
826
|
+
React$1.useEffect(() => {
|
791
827
|
const world = worldRef.current;
|
792
828
|
|
793
829
|
if (world) {
|
794
830
|
world.gravity = vectorArrayToVector3(_gravity);
|
795
831
|
}
|
796
832
|
}, [_gravity]);
|
797
|
-
const api = React.useMemo(() => createWorldApi(getWorldRef), []);
|
798
|
-
const getSourceFromColliderHandle = React.useCallback(handle => {
|
833
|
+
const api = React$1.useMemo(() => createWorldApi(getWorldRef), []);
|
834
|
+
const getSourceFromColliderHandle = React$1.useCallback(handle => {
|
799
835
|
const world = worldRef.current;
|
800
836
|
|
801
837
|
if (world) {
|
@@ -823,11 +859,11 @@ const Physics = ({
|
|
823
859
|
return source;
|
824
860
|
}
|
825
861
|
}, []);
|
826
|
-
const [steppingState] = React.useState({
|
862
|
+
const [steppingState] = React$1.useState({
|
827
863
|
previousState: {},
|
828
864
|
accumulator: 0
|
829
865
|
});
|
830
|
-
const step = React.useCallback(dt => {
|
866
|
+
const step = React$1.useCallback(dt => {
|
831
867
|
const world = worldRef.current;
|
832
868
|
if (!world) return;
|
833
869
|
/* Check if the timestep is supposed to be variable. We'll do this here
|
@@ -1039,14 +1075,11 @@ const Physics = ({
|
|
1039
1075
|
maxForceMagnitude: event.maxForceMagnitude()
|
1040
1076
|
}));
|
1041
1077
|
});
|
1042
|
-
world.forEachActiveRigidBody(
|
1078
|
+
world.forEachActiveRigidBody(() => {
|
1043
1079
|
invalidate();
|
1044
1080
|
});
|
1045
1081
|
}, [_paused, _timeStep, _interpolate]);
|
1046
|
-
|
1047
|
-
if (!_paused) step(dt);
|
1048
|
-
});
|
1049
|
-
const context = React.useMemo(() => ({
|
1082
|
+
const context = React$1.useMemo(() => ({
|
1050
1083
|
rapier,
|
1051
1084
|
world: api,
|
1052
1085
|
physicsOptions: {
|
@@ -1063,9 +1096,18 @@ const Physics = ({
|
|
1063
1096
|
isPaused: _paused,
|
1064
1097
|
step
|
1065
1098
|
}), [_paused, step]);
|
1099
|
+
const stepCallback = React$1.useCallback(delta => {
|
1100
|
+
if (!_paused) {
|
1101
|
+
step(delta);
|
1102
|
+
}
|
1103
|
+
}, [_paused, step]);
|
1066
1104
|
return /*#__PURE__*/React__default["default"].createElement(rapierContext.Provider, {
|
1067
1105
|
value: context
|
1068
|
-
},
|
1106
|
+
}, /*#__PURE__*/React__default["default"].createElement(FrameStepper$1, {
|
1107
|
+
onStep: stepCallback,
|
1108
|
+
type: _updateLoop,
|
1109
|
+
updatePriority: updatePriority
|
1110
|
+
}), children);
|
1069
1111
|
};
|
1070
1112
|
|
1071
1113
|
function _extends() {
|
@@ -1090,15 +1132,15 @@ function _extends() {
|
|
1090
1132
|
*/
|
1091
1133
|
|
1092
1134
|
const useImperativeInstance = (createFn, destroyFn) => {
|
1093
|
-
const ref = React.useRef();
|
1094
|
-
const refGetter = React.useMemo(() => () => {
|
1135
|
+
const ref = React$1.useRef();
|
1136
|
+
const refGetter = React$1.useMemo(() => () => {
|
1095
1137
|
if (!ref.current) {
|
1096
1138
|
ref.current = createFn();
|
1097
1139
|
}
|
1098
1140
|
|
1099
1141
|
return ref.current;
|
1100
1142
|
}, []);
|
1101
|
-
React.useEffect(() => {
|
1143
|
+
React$1.useEffect(() => {
|
1102
1144
|
const instance = refGetter();
|
1103
1145
|
return () => {
|
1104
1146
|
destroyFn(instance);
|
@@ -1165,7 +1207,7 @@ const euler = ({
|
|
1165
1207
|
* A collider is a shape that can be attached to a rigid body to define its physical properties.
|
1166
1208
|
* @internal
|
1167
1209
|
*/
|
1168
|
-
const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
1210
|
+
const AnyCollider = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((props, forwardedRef) => {
|
1169
1211
|
const {
|
1170
1212
|
children,
|
1171
1213
|
position,
|
@@ -1180,7 +1222,7 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
|
|
1180
1222
|
colliderStates
|
1181
1223
|
} = useRapier();
|
1182
1224
|
const rigidBodyContext = useRigidBodyContext();
|
1183
|
-
const ref = React.useRef(null);
|
1225
|
+
const ref = React$1.useRef(null);
|
1184
1226
|
const getInstance = useImperativeInstance(() => {
|
1185
1227
|
const worldScale = ref.current.getWorldScale(vec3());
|
1186
1228
|
const collider = createColliderFromOptions(props, world, worldScale, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.getRigidBody);
|
@@ -1188,15 +1230,15 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
|
|
1188
1230
|
}, collider => {
|
1189
1231
|
world.removeCollider(collider);
|
1190
1232
|
});
|
1191
|
-
React.useEffect(() => {
|
1233
|
+
React$1.useEffect(() => {
|
1192
1234
|
const collider = getInstance();
|
1193
1235
|
colliderStates.set(collider.handle, createColliderState(collider, ref.current, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.ref.current));
|
1194
1236
|
return () => {
|
1195
1237
|
colliderStates.delete(collider.handle);
|
1196
1238
|
};
|
1197
1239
|
}, []);
|
1198
|
-
React.useImperativeHandle(forwardedRef, () => getInstance());
|
1199
|
-
const mergedProps = React.useMemo(() => {
|
1240
|
+
React$1.useImperativeHandle(forwardedRef, () => getInstance());
|
1241
|
+
const mergedProps = React$1.useMemo(() => {
|
1200
1242
|
return _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options)), props);
|
1201
1243
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1202
1244
|
useUpdateColliderOptions(getInstance, mergedProps, colliderStates);
|
@@ -1433,10 +1475,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
1433
1475
|
};
|
1434
1476
|
const useUpdateRigidBodyOptions = (getRigidBody, props, states, updateTranslations = true) => {
|
1435
1477
|
// TODO: Improve this, split each prop into its own effect
|
1436
|
-
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
1478
|
+
const mutablePropsAsFlatArray = React$1.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
1437
1479
|
return vectorToTuple(props[key]);
|
1438
1480
|
}), [props]);
|
1439
|
-
React.useEffect(() => {
|
1481
|
+
React$1.useEffect(() => {
|
1440
1482
|
const rigidBody = getRigidBody();
|
1441
1483
|
setRigidBodyOptions(rigidBody, props, states, updateTranslations);
|
1442
1484
|
}, mutablePropsAsFlatArray);
|
@@ -1460,7 +1502,7 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1460
1502
|
onIntersectionExit,
|
1461
1503
|
onContactForce
|
1462
1504
|
};
|
1463
|
-
React.useEffect(() => {
|
1505
|
+
React$1.useEffect(() => {
|
1464
1506
|
const rigidBody = getRigidBody();
|
1465
1507
|
events.set(rigidBody.handle, eventHandlers);
|
1466
1508
|
return () => {
|
@@ -1470,14 +1512,14 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1470
1512
|
};
|
1471
1513
|
|
1472
1514
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
1473
|
-
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1474
|
-
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1515
|
+
const RigidBodyContext = /*#__PURE__*/React$1.createContext(undefined);
|
1516
|
+
const useRigidBodyContext = () => React$1.useContext(RigidBodyContext);
|
1475
1517
|
|
1476
1518
|
/**
|
1477
1519
|
* A rigid body is a physical object that can be simulated by the physics engine.
|
1478
1520
|
* @category Components
|
1479
1521
|
*/
|
1480
|
-
const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
1522
|
+
const RigidBody = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((props, forwardedRef) => {
|
1481
1523
|
const {
|
1482
1524
|
children,
|
1483
1525
|
type,
|
@@ -1489,14 +1531,14 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
|
|
1489
1531
|
} = props,
|
1490
1532
|
objectProps = _objectWithoutProperties(props, _excluded$1);
|
1491
1533
|
|
1492
|
-
const ref = React.useRef(null);
|
1534
|
+
const ref = React$1.useRef(null);
|
1493
1535
|
const {
|
1494
1536
|
world,
|
1495
1537
|
rigidBodyStates,
|
1496
1538
|
physicsOptions,
|
1497
1539
|
rigidBodyEvents
|
1498
1540
|
} = useRapier();
|
1499
|
-
const mergedOptions = React.useMemo(() => {
|
1541
|
+
const mergedOptions = React$1.useMemo(() => {
|
1500
1542
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), props), {}, {
|
1501
1543
|
children: undefined
|
1502
1544
|
});
|
@@ -1511,7 +1553,7 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
|
|
1511
1553
|
world.removeRigidBody(rigidBody);
|
1512
1554
|
}); // Only provide a object state after the ref has been set
|
1513
1555
|
|
1514
|
-
React.useEffect(() => {
|
1556
|
+
React$1.useEffect(() => {
|
1515
1557
|
const rigidBody = getInstance();
|
1516
1558
|
const state = createRigidBodyState({
|
1517
1559
|
rigidBody,
|
@@ -1524,8 +1566,8 @@ const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props,
|
|
1524
1566
|
}, []);
|
1525
1567
|
useUpdateRigidBodyOptions(getInstance, mergedOptions, rigidBodyStates);
|
1526
1568
|
useRigidBodyEvents(getInstance, mergedOptions, rigidBodyEvents);
|
1527
|
-
React.useImperativeHandle(forwardedRef, () => getInstance());
|
1528
|
-
const contextValue = React.useMemo(() => {
|
1569
|
+
React$1.useImperativeHandle(forwardedRef, () => getInstance());
|
1570
|
+
const contextValue = React$1.useMemo(() => {
|
1529
1571
|
return {
|
1530
1572
|
ref,
|
1531
1573
|
getRigidBody: getInstance,
|
@@ -1551,7 +1593,7 @@ RigidBody.displayName = "RigidBody";
|
|
1551
1593
|
* A mesh collider is a collider that is automatically generated from the geometry of the children.
|
1552
1594
|
* @category Colliders
|
1553
1595
|
*/
|
1554
|
-
const MeshCollider = /*#__PURE__*/React.memo(props => {
|
1596
|
+
const MeshCollider = /*#__PURE__*/React$1.memo(props => {
|
1555
1597
|
const {
|
1556
1598
|
children,
|
1557
1599
|
type
|
@@ -1559,11 +1601,11 @@ const MeshCollider = /*#__PURE__*/React.memo(props => {
|
|
1559
1601
|
const {
|
1560
1602
|
physicsOptions
|
1561
1603
|
} = useRapier();
|
1562
|
-
const object = React.useRef(null);
|
1604
|
+
const object = React$1.useRef(null);
|
1563
1605
|
const {
|
1564
1606
|
options
|
1565
1607
|
} = useRigidBodyContext();
|
1566
|
-
const mergedOptions = React.useMemo(() => {
|
1608
|
+
const mergedOptions = React$1.useMemo(() => {
|
1567
1609
|
return _objectSpread2(_objectSpread2(_objectSpread2({}, physicsOptions), options), {}, {
|
1568
1610
|
children: undefined,
|
1569
1611
|
colliders: type
|
@@ -1603,10 +1645,10 @@ const AttractorHelper = props => {
|
|
1603
1645
|
const {
|
1604
1646
|
scene
|
1605
1647
|
} = fiber.useThree();
|
1606
|
-
const ref = React.useRef(null);
|
1607
|
-
const normalsHelper = React.useRef();
|
1648
|
+
const ref = React$1.useRef(null);
|
1649
|
+
const normalsHelper = React$1.useRef();
|
1608
1650
|
const color = props.strength > 0 ? 0x0000ff : 0xff0000;
|
1609
|
-
React.useEffect(() => {
|
1651
|
+
React$1.useEffect(() => {
|
1610
1652
|
if (ref.current) {
|
1611
1653
|
normalsHelper.current = new threeStdlib.VertexNormalsHelper(ref.current, props.range, color);
|
1612
1654
|
normalsHelper.current.frustumCulled = false;
|
@@ -1640,14 +1682,14 @@ const AttractorHelper = props => {
|
|
1640
1682
|
}));
|
1641
1683
|
};
|
1642
1684
|
|
1643
|
-
const Debug = /*#__PURE__*/React.memo(() => {
|
1685
|
+
const Debug = /*#__PURE__*/React$1.memo(() => {
|
1644
1686
|
const {
|
1645
1687
|
world,
|
1646
1688
|
attractorStates
|
1647
1689
|
} = useRapier();
|
1648
|
-
const ref = React.useRef(null);
|
1649
|
-
const [attractors, setAttractors] = React.useState([]);
|
1650
|
-
const currMap = React.useRef(new Map());
|
1690
|
+
const ref = React$1.useRef(null);
|
1691
|
+
const [attractors, setAttractors] = React$1.useState([]);
|
1692
|
+
const currMap = React$1.useRef(new Map());
|
1651
1693
|
fiber.useFrame(() => {
|
1652
1694
|
const mesh = ref.current;
|
1653
1695
|
if (!mesh) return;
|
@@ -1672,9 +1714,9 @@ const Debug = /*#__PURE__*/React.memo(() => {
|
|
1672
1714
|
});
|
1673
1715
|
|
1674
1716
|
const _excluded = ["children", "instances", "colliderNodes", "position", "rotation", "quaternion", "scale"];
|
1675
|
-
const InstancedRigidBodies = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, ref) => {
|
1676
|
-
const object = React.useRef(null);
|
1677
|
-
const instancedWrapper = React.useRef(null);
|
1717
|
+
const InstancedRigidBodies = /*#__PURE__*/React$1.memo( /*#__PURE__*/React$1.forwardRef((props, ref) => {
|
1718
|
+
const object = React$1.useRef(null);
|
1719
|
+
const instancedWrapper = React$1.useRef(null);
|
1678
1720
|
|
1679
1721
|
const {
|
1680
1722
|
// instanced props
|
@@ -1689,8 +1731,8 @@ const InstancedRigidBodies = /*#__PURE__*/React.memo( /*#__PURE__*/React.forward
|
|
1689
1731
|
} = props,
|
1690
1732
|
rigidBodyProps = _objectWithoutProperties(props, _excluded);
|
1691
1733
|
|
1692
|
-
const rigidBodyApis = React.useRef([]);
|
1693
|
-
React.useImperativeHandle(ref, () => rigidBodyApis.current, [instances]);
|
1734
|
+
const rigidBodyApis = React$1.useRef([]);
|
1735
|
+
React$1.useImperativeHandle(ref, () => rigidBodyApis.current, [instances]);
|
1694
1736
|
const childColliderProps = useChildColliderProps(object, _objectSpread2(_objectSpread2({}, props), {}, {
|
1695
1737
|
children: undefined
|
1696
1738
|
}));
|
@@ -1705,7 +1747,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.memo( /*#__PURE__*/React.forward
|
|
1705
1747
|
return undefined;
|
1706
1748
|
};
|
1707
1749
|
|
1708
|
-
React.useEffect(() => {
|
1750
|
+
React$1.useEffect(() => {
|
1709
1751
|
const instancedMesh = getInstancedMesh();
|
1710
1752
|
|
1711
1753
|
if (instancedMesh) {
|
@@ -1747,7 +1789,7 @@ const InstancedRigidBodies = /*#__PURE__*/React.memo( /*#__PURE__*/React.forward
|
|
1747
1789
|
}, children), instances === null || instances === void 0 ? void 0 : instances.map((instance, index) => /*#__PURE__*/React__default["default"].createElement(RigidBody, _extends({}, rigidBodyProps, instance, {
|
1748
1790
|
ref: body => rigidBodyApis.current[index] = body,
|
1749
1791
|
transformState: state => applyInstancedState(state, index)
|
1750
|
-
}), /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, colliderNodes.map((node, index) => /*#__PURE__*/React__default["default"].createElement(React.Fragment, {
|
1792
|
+
}), /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, colliderNodes.map((node, index) => /*#__PURE__*/React__default["default"].createElement(React$1.Fragment, {
|
1751
1793
|
key: index
|
1752
1794
|
}, node)), childColliderProps.map((colliderProps, colliderIndex) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1753
1795
|
key: colliderIndex
|
@@ -1763,7 +1805,7 @@ const useImpulseJoint = (body1, body2, params) => {
|
|
1763
1805
|
const {
|
1764
1806
|
world
|
1765
1807
|
} = useRapier();
|
1766
|
-
const jointRef = React.useRef();
|
1808
|
+
const jointRef = React$1.useRef();
|
1767
1809
|
useImperativeInstance(() => {
|
1768
1810
|
if (body1.current && body2.current) {
|
1769
1811
|
const newJoint = world.createImpulseJoint(params, body1.current, body2.current);
|