@react-three/rapier 0.7.5 → 0.7.6
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/RigidBody.d.ts +1 -1
- package/dist/declarations/src/api.d.ts +19 -19
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/react-three-rapier.cjs.dev.js +42 -8
- package/dist/react-three-rapier.cjs.prod.js +42 -8
- package/dist/react-three-rapier.esm.js +42 -8
- package/package.json +1 -1
@@ -17,4 +17,4 @@ export declare const useRigidBodyContext: () => {
|
|
17
17
|
export interface RigidBodyProps extends UseRigidBodyOptions {
|
18
18
|
children?: ReactNode;
|
19
19
|
}
|
20
|
-
export declare const RigidBody: React.ForwardRefExoticComponent<RigidBodyProps & React.RefAttributes<import("./api").RigidBodyApi
|
20
|
+
export declare const RigidBody: React.MemoExoticComponent<React.ForwardRefExoticComponent<RigidBodyProps & React.RefAttributes<import("./api").RigidBodyApi>>>;
|
@@ -22,27 +22,27 @@ export interface RigidBodyApi {
|
|
22
22
|
/**
|
23
23
|
* Applies an impulse at the center-of-mass of this rigid-body.
|
24
24
|
*/
|
25
|
-
applyImpulse(impulseVector: Vector3Object, wakeUp
|
25
|
+
applyImpulse(impulseVector: Vector3Object, wakeUp?: boolean): void;
|
26
26
|
/**
|
27
27
|
* Applies an impulsive torque at the center-of-mass of this rigid-body.
|
28
28
|
*/
|
29
|
-
applyTorqueImpulse(torqueVector: Vector3Object, wakeUp
|
29
|
+
applyTorqueImpulse(torqueVector: Vector3Object, wakeUp?: boolean): void;
|
30
30
|
/**
|
31
31
|
* Applies an impulse at the given world-space point of this rigid-body.
|
32
32
|
*/
|
33
|
-
applyImpulseAtPoint(impulseVector: Vector3Object, impulsePoint: Vector3Object, wakeUp
|
33
|
+
applyImpulseAtPoint(impulseVector: Vector3Object, impulsePoint: Vector3Object, wakeUp?: boolean): void;
|
34
34
|
/**
|
35
35
|
* Adds a force at the center-of-mass of this rigid-body.
|
36
36
|
*/
|
37
|
-
addForce(force: Vector3Object, wakeUp
|
37
|
+
addForce(force: Vector3Object, wakeUp?: boolean): void;
|
38
38
|
/**
|
39
39
|
* Adds a force at the given world-space point of this rigid-body.
|
40
40
|
*/
|
41
|
-
addForceAtPoint(force: Vector3Object, point: Vector3Object, wakeUp
|
41
|
+
addForceAtPoint(force: Vector3Object, point: Vector3Object, wakeUp?: boolean): void;
|
42
42
|
/**
|
43
43
|
* Adds a torque at the center-of-mass of this rigid-body.
|
44
44
|
*/
|
45
|
-
addTorque(torque: Vector3Object, wakeUp
|
45
|
+
addTorque(torque: Vector3Object, wakeUp?: boolean): void;
|
46
46
|
/**
|
47
47
|
* The world-space translation of this rigid-body.
|
48
48
|
*/
|
@@ -50,7 +50,7 @@ export interface RigidBodyApi {
|
|
50
50
|
/**
|
51
51
|
* Sets the translation of this rigid-body.
|
52
52
|
*/
|
53
|
-
setTranslation(translation: Vector3Object, wakeUp
|
53
|
+
setTranslation(translation: Vector3Object, wakeUp?: boolean): void;
|
54
54
|
/**
|
55
55
|
* The world-space orientation of this rigid-body.
|
56
56
|
*/
|
@@ -58,7 +58,7 @@ export interface RigidBodyApi {
|
|
58
58
|
/**
|
59
59
|
* Sets the rotation quaternion of this rigid-body.
|
60
60
|
*/
|
61
|
-
setRotation(rotation: Quaternion, wakeUp
|
61
|
+
setRotation(rotation: Quaternion, wakeUp?: boolean): void;
|
62
62
|
/**
|
63
63
|
* The linear velocity of this rigid-body.
|
64
64
|
*/
|
@@ -66,7 +66,7 @@ export interface RigidBodyApi {
|
|
66
66
|
/**
|
67
67
|
* Sets the linear velocity of this rigid-body.
|
68
68
|
*/
|
69
|
-
setLinvel(velocity: Vector3Object, wakeUp
|
69
|
+
setLinvel(velocity: Vector3Object, wakeUp?: boolean): void;
|
70
70
|
/**
|
71
71
|
* The angular velocity of this rigid-body.
|
72
72
|
*/
|
@@ -74,7 +74,7 @@ export interface RigidBodyApi {
|
|
74
74
|
/**
|
75
75
|
* Sets the angular velocity of this rigid-body.
|
76
76
|
*/
|
77
|
-
setAngvel(velocity: Vector3Object, wakeUp
|
77
|
+
setAngvel(velocity: Vector3Object, wakeUp?: boolean): void;
|
78
78
|
/**
|
79
79
|
* The linear damping of this rigid-body.
|
80
80
|
*/
|
@@ -112,27 +112,27 @@ export interface RigidBodyApi {
|
|
112
112
|
/**
|
113
113
|
* Resets to zero the user forces (but not torques) applied to this rigid-body.
|
114
114
|
*/
|
115
|
-
resetForces(wakeUp
|
115
|
+
resetForces(wakeUp?: boolean): void;
|
116
116
|
/**
|
117
117
|
* Resets to zero the user torques applied to this rigid-body.
|
118
118
|
*/
|
119
|
-
resetTorques(wakeUp
|
119
|
+
resetTorques(wakeUp?: boolean): void;
|
120
120
|
/**
|
121
121
|
* Locks or unlocks the ability of this rigid-body to rotate.
|
122
122
|
*/
|
123
|
-
lockRotations(locked: boolean, wakeUp
|
123
|
+
lockRotations(locked: boolean, wakeUp?: boolean): void;
|
124
124
|
/**
|
125
125
|
* Locks or unlocks the ability of this rigid-body to translate.
|
126
126
|
*/
|
127
|
-
lockTranslations(locked: boolean, wakeUp
|
127
|
+
lockTranslations(locked: boolean, wakeUp?: boolean): void;
|
128
128
|
/**
|
129
129
|
* Locks or unlocks the ability of this rigid-body to rotate along individual coordinate axes.
|
130
130
|
*/
|
131
|
-
setEnabledRotations(x: boolean, y: boolean, z: boolean, wakeUp
|
131
|
+
setEnabledRotations(x: boolean, y: boolean, z: boolean, wakeUp?: boolean): void;
|
132
132
|
/**
|
133
133
|
* Locks or unlocks the ability of this rigid-body to translate along individual coordinate axes.
|
134
134
|
*/
|
135
|
-
setEnabledTranslations(x: boolean, y: boolean, z: boolean, wakeUp
|
135
|
+
setEnabledTranslations(x: boolean, y: boolean, z: boolean, wakeUp?: boolean): void;
|
136
136
|
}
|
137
137
|
export declare const createRigidBodyApi: (ref: RefGetter<RigidBody>) => RigidBodyApi;
|
138
138
|
export interface InstancedRigidBodyApi {
|
@@ -155,9 +155,9 @@ export interface WorldApi {
|
|
155
155
|
createRigidBody(desc: RigidBodyDesc): RigidBody;
|
156
156
|
createCollider(desc: ColliderDesc, parent?: RigidBody): Collider;
|
157
157
|
removeRigidBody(rigidBody: RigidBody): void;
|
158
|
-
removeCollider(collider: Collider, wakeUp
|
159
|
-
createImpulseJoint(params: JointData, rigidBodyA: RigidBody, rigidBodyB: RigidBody, wakeUp
|
160
|
-
removeImpulseJoint(joint: ImpulseJoint, wakeUp
|
158
|
+
removeCollider(collider: Collider, wakeUp?: boolean): void;
|
159
|
+
createImpulseJoint(params: JointData, rigidBodyA: RigidBody, rigidBodyB: RigidBody, wakeUp?: boolean): ImpulseJoint;
|
160
|
+
removeImpulseJoint(joint: ImpulseJoint, wakeUp?: boolean): void;
|
161
161
|
forEachCollider(callback: (collider: Collider) => void): void;
|
162
162
|
setGravity(gravity: Vector3): void;
|
163
163
|
}
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { Quaternion as RapierQuaternion, Vector3 as RapierVector3 } from "@dimforge/rapier3d-compat";
|
2
|
-
import { Vector3 } from "three";
|
2
|
+
import { Euler, Quaternion, Vector3 } from "three";
|
3
3
|
import { RigidBodyTypeString, Vector3Array } from "./types";
|
4
4
|
export declare const vectorArrayToVector3: (arr: Vector3Array) => Vector3;
|
5
|
-
export declare const vector3ToQuaternion: (v: Vector3) =>
|
5
|
+
export declare const vector3ToQuaternion: (v: Vector3) => Quaternion;
|
6
6
|
export declare const rapierVector3ToVector3: ({ x, y, z }: RapierVector3) => Vector3;
|
7
|
-
export declare const rapierQuaternionToQuaternion: ({ x, y, z, w }: RapierQuaternion) =>
|
7
|
+
export declare const rapierQuaternionToQuaternion: ({ x, y, z, w }: RapierQuaternion) => Quaternion;
|
8
8
|
export declare const rigidBodyTypeFromString: (type: RigidBodyTypeString) => number;
|
9
9
|
export declare const scaleVertices: (vertices: ArrayLike<number>, scale: Vector3) => number[];
|
10
|
+
export declare const vectorToTuple: (v: Vector3 | Quaternion | any[] | undefined | number | Euler) => any[];
|
@@ -73,6 +73,23 @@ const scaleVertices = (vertices, scale) => {
|
|
73
73
|
|
74
74
|
return scaledVerts;
|
75
75
|
};
|
76
|
+
const vectorToTuple = v => {
|
77
|
+
if (!v) return [0];
|
78
|
+
|
79
|
+
if (v instanceof three.Quaternion) {
|
80
|
+
return [v.x, v.y, v.z, v.w];
|
81
|
+
}
|
82
|
+
|
83
|
+
if (v instanceof three.Vector3 || v instanceof three.Euler) {
|
84
|
+
return [v.x, v.y, v.z];
|
85
|
+
}
|
86
|
+
|
87
|
+
if (Array.isArray(v)) {
|
88
|
+
return v;
|
89
|
+
}
|
90
|
+
|
91
|
+
return [v];
|
92
|
+
};
|
76
93
|
|
77
94
|
const createRigidBodyApi = ref => {
|
78
95
|
return {
|
@@ -643,7 +660,11 @@ const mutableRigidBodyOptions = {
|
|
643
660
|
},
|
644
661
|
ccd: (rb, value) => {
|
645
662
|
rb.enableCcd(value);
|
646
|
-
}
|
663
|
+
},
|
664
|
+
position: () => {},
|
665
|
+
rotation: () => {},
|
666
|
+
quaternion: () => {},
|
667
|
+
scale: () => {}
|
647
668
|
};
|
648
669
|
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
649
670
|
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
@@ -671,6 +692,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
671
692
|
}
|
672
693
|
};
|
673
694
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
695
|
+
// TODO: Improve this, split each prop into its own effect
|
696
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
697
|
+
return vectorToTuple(props[key]);
|
698
|
+
}), [props]);
|
674
699
|
React.useEffect(() => {
|
675
700
|
if ("length" in rigidBodyRef.current) {
|
676
701
|
rigidBodyRef.current.forEach(rigidBody => {
|
@@ -679,7 +704,7 @@ const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslatio
|
|
679
704
|
} else {
|
680
705
|
setRigidBodyOptions(rigidBodyRef.current, props, states, updateTranslations);
|
681
706
|
}
|
682
|
-
},
|
707
|
+
}, mutablePropsAsFlatArray);
|
683
708
|
};
|
684
709
|
const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
685
710
|
const {
|
@@ -716,7 +741,7 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
716
741
|
events.delete(rigidBodyRef.current.handle);
|
717
742
|
}
|
718
743
|
};
|
719
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit]);
|
744
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
720
745
|
};
|
721
746
|
|
722
747
|
const scaleColliderArgs = (shape, args, scale) => {
|
@@ -793,7 +818,12 @@ const mutableColliderOptions = {
|
|
793
818
|
},
|
794
819
|
restitutionCombineRule: (collider, value) => {
|
795
820
|
collider.setRestitutionCombineRule(value);
|
796
|
-
}
|
821
|
+
},
|
822
|
+
// To make sure the options all mutalbe options are listed
|
823
|
+
quaternion: () => {},
|
824
|
+
position: () => {},
|
825
|
+
rotation: () => {},
|
826
|
+
scale: () => {}
|
797
827
|
};
|
798
828
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
799
829
|
const setColliderOptions = (collider, options, states) => {
|
@@ -835,11 +865,15 @@ const setColliderOptions = (collider, options, states) => {
|
|
835
865
|
}
|
836
866
|
};
|
837
867
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
868
|
+
// TODO: Improve this, split each prop into its own effect
|
869
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
870
|
+
return vectorToTuple(props[key]);
|
871
|
+
}), [props]);
|
838
872
|
React.useEffect(() => {
|
839
873
|
collidersRef.current.forEach(collider => {
|
840
874
|
setColliderOptions(collider, props, states);
|
841
875
|
});
|
842
|
-
},
|
876
|
+
}, mutablePropsAsFlatArray);
|
843
877
|
};
|
844
878
|
|
845
879
|
const isChildOfMeshCollider = child => {
|
@@ -980,7 +1014,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
980
1014
|
|
981
1015
|
(_collidersRef$current2 = collidersRef.current) === null || _collidersRef$current2 === void 0 ? void 0 : _collidersRef$current2.forEach(collider => events.delete(collider.handle));
|
982
1016
|
};
|
983
|
-
}, [onCollisionEnter, onCollisionExit]);
|
1017
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
984
1018
|
};
|
985
1019
|
|
986
1020
|
const useRapier = () => {
|
@@ -1267,7 +1301,7 @@ const ConvexHullCollider = /*#__PURE__*/React__default["default"].forwardRef((pr
|
|
1267
1301
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1268
1302
|
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1269
1303
|
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1270
|
-
const RigidBody = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1304
|
+
const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, ref) => {
|
1271
1305
|
const {
|
1272
1306
|
children,
|
1273
1307
|
type,
|
@@ -1297,7 +1331,7 @@ const RigidBody = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1297
1331
|
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1298
1332
|
key: index
|
1299
1333
|
}, colliderProps)))));
|
1300
|
-
});
|
1334
|
+
}));
|
1301
1335
|
|
1302
1336
|
const MeshCollider = props => {
|
1303
1337
|
const {
|
@@ -73,6 +73,23 @@ const scaleVertices = (vertices, scale) => {
|
|
73
73
|
|
74
74
|
return scaledVerts;
|
75
75
|
};
|
76
|
+
const vectorToTuple = v => {
|
77
|
+
if (!v) return [0];
|
78
|
+
|
79
|
+
if (v instanceof three.Quaternion) {
|
80
|
+
return [v.x, v.y, v.z, v.w];
|
81
|
+
}
|
82
|
+
|
83
|
+
if (v instanceof three.Vector3 || v instanceof three.Euler) {
|
84
|
+
return [v.x, v.y, v.z];
|
85
|
+
}
|
86
|
+
|
87
|
+
if (Array.isArray(v)) {
|
88
|
+
return v;
|
89
|
+
}
|
90
|
+
|
91
|
+
return [v];
|
92
|
+
};
|
76
93
|
|
77
94
|
const createRigidBodyApi = ref => {
|
78
95
|
return {
|
@@ -643,7 +660,11 @@ const mutableRigidBodyOptions = {
|
|
643
660
|
},
|
644
661
|
ccd: (rb, value) => {
|
645
662
|
rb.enableCcd(value);
|
646
|
-
}
|
663
|
+
},
|
664
|
+
position: () => {},
|
665
|
+
rotation: () => {},
|
666
|
+
quaternion: () => {},
|
667
|
+
scale: () => {}
|
647
668
|
};
|
648
669
|
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
649
670
|
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
@@ -671,6 +692,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
671
692
|
}
|
672
693
|
};
|
673
694
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
695
|
+
// TODO: Improve this, split each prop into its own effect
|
696
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
697
|
+
return vectorToTuple(props[key]);
|
698
|
+
}), [props]);
|
674
699
|
React.useEffect(() => {
|
675
700
|
if ("length" in rigidBodyRef.current) {
|
676
701
|
rigidBodyRef.current.forEach(rigidBody => {
|
@@ -679,7 +704,7 @@ const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslatio
|
|
679
704
|
} else {
|
680
705
|
setRigidBodyOptions(rigidBodyRef.current, props, states, updateTranslations);
|
681
706
|
}
|
682
|
-
},
|
707
|
+
}, mutablePropsAsFlatArray);
|
683
708
|
};
|
684
709
|
const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
685
710
|
const {
|
@@ -716,7 +741,7 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
716
741
|
events.delete(rigidBodyRef.current.handle);
|
717
742
|
}
|
718
743
|
};
|
719
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit]);
|
744
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
720
745
|
};
|
721
746
|
|
722
747
|
const scaleColliderArgs = (shape, args, scale) => {
|
@@ -793,7 +818,12 @@ const mutableColliderOptions = {
|
|
793
818
|
},
|
794
819
|
restitutionCombineRule: (collider, value) => {
|
795
820
|
collider.setRestitutionCombineRule(value);
|
796
|
-
}
|
821
|
+
},
|
822
|
+
// To make sure the options all mutalbe options are listed
|
823
|
+
quaternion: () => {},
|
824
|
+
position: () => {},
|
825
|
+
rotation: () => {},
|
826
|
+
scale: () => {}
|
797
827
|
};
|
798
828
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
799
829
|
const setColliderOptions = (collider, options, states) => {
|
@@ -835,11 +865,15 @@ const setColliderOptions = (collider, options, states) => {
|
|
835
865
|
}
|
836
866
|
};
|
837
867
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
868
|
+
// TODO: Improve this, split each prop into its own effect
|
869
|
+
const mutablePropsAsFlatArray = React.useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
870
|
+
return vectorToTuple(props[key]);
|
871
|
+
}), [props]);
|
838
872
|
React.useEffect(() => {
|
839
873
|
collidersRef.current.forEach(collider => {
|
840
874
|
setColliderOptions(collider, props, states);
|
841
875
|
});
|
842
|
-
},
|
876
|
+
}, mutablePropsAsFlatArray);
|
843
877
|
};
|
844
878
|
|
845
879
|
const isChildOfMeshCollider = child => {
|
@@ -980,7 +1014,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
980
1014
|
|
981
1015
|
(_collidersRef$current2 = collidersRef.current) === null || _collidersRef$current2 === void 0 ? void 0 : _collidersRef$current2.forEach(collider => events.delete(collider.handle));
|
982
1016
|
};
|
983
|
-
}, [onCollisionEnter, onCollisionExit]);
|
1017
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
984
1018
|
};
|
985
1019
|
|
986
1020
|
const useRapier = () => {
|
@@ -1267,7 +1301,7 @@ const ConvexHullCollider = /*#__PURE__*/React__default["default"].forwardRef((pr
|
|
1267
1301
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1268
1302
|
const RigidBodyContext = /*#__PURE__*/React.createContext(undefined);
|
1269
1303
|
const useRigidBodyContext = () => React.useContext(RigidBodyContext);
|
1270
|
-
const RigidBody = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1304
|
+
const RigidBody = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((props, ref) => {
|
1271
1305
|
const {
|
1272
1306
|
children,
|
1273
1307
|
type,
|
@@ -1297,7 +1331,7 @@ const RigidBody = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1297
1331
|
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React__default["default"].createElement(AnyCollider, _extends({
|
1298
1332
|
key: index
|
1299
1333
|
}, colliderProps)))));
|
1300
|
-
});
|
1334
|
+
}));
|
1301
1335
|
|
1302
1336
|
const MeshCollider = props => {
|
1303
1337
|
const {
|
@@ -48,6 +48,23 @@ const scaleVertices = (vertices, scale) => {
|
|
48
48
|
|
49
49
|
return scaledVerts;
|
50
50
|
};
|
51
|
+
const vectorToTuple = v => {
|
52
|
+
if (!v) return [0];
|
53
|
+
|
54
|
+
if (v instanceof Quaternion) {
|
55
|
+
return [v.x, v.y, v.z, v.w];
|
56
|
+
}
|
57
|
+
|
58
|
+
if (v instanceof Vector3 || v instanceof Euler) {
|
59
|
+
return [v.x, v.y, v.z];
|
60
|
+
}
|
61
|
+
|
62
|
+
if (Array.isArray(v)) {
|
63
|
+
return v;
|
64
|
+
}
|
65
|
+
|
66
|
+
return [v];
|
67
|
+
};
|
51
68
|
|
52
69
|
const createRigidBodyApi = ref => {
|
53
70
|
return {
|
@@ -618,7 +635,11 @@ const mutableRigidBodyOptions = {
|
|
618
635
|
},
|
619
636
|
ccd: (rb, value) => {
|
620
637
|
rb.enableCcd(value);
|
621
|
-
}
|
638
|
+
},
|
639
|
+
position: () => {},
|
640
|
+
rotation: () => {},
|
641
|
+
quaternion: () => {},
|
642
|
+
scale: () => {}
|
622
643
|
};
|
623
644
|
const mutableRigidBodyOptionKeys = Object.keys(mutableRigidBodyOptions);
|
624
645
|
const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = true) => {
|
@@ -646,6 +667,10 @@ const setRigidBodyOptions = (rigidBody, options, states, updateTranslations = tr
|
|
646
667
|
}
|
647
668
|
};
|
648
669
|
const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslations = true) => {
|
670
|
+
// TODO: Improve this, split each prop into its own effect
|
671
|
+
const mutablePropsAsFlatArray = useMemo(() => mutableRigidBodyOptionKeys.flatMap(key => {
|
672
|
+
return vectorToTuple(props[key]);
|
673
|
+
}), [props]);
|
649
674
|
useEffect(() => {
|
650
675
|
if ("length" in rigidBodyRef.current) {
|
651
676
|
rigidBodyRef.current.forEach(rigidBody => {
|
@@ -654,7 +679,7 @@ const useUpdateRigidBodyOptions = (rigidBodyRef, props, states, updateTranslatio
|
|
654
679
|
} else {
|
655
680
|
setRigidBodyOptions(rigidBodyRef.current, props, states, updateTranslations);
|
656
681
|
}
|
657
|
-
},
|
682
|
+
}, mutablePropsAsFlatArray);
|
658
683
|
};
|
659
684
|
const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
660
685
|
const {
|
@@ -691,7 +716,7 @@ const useRigidBodyEvents = (rigidBodyRef, props, events) => {
|
|
691
716
|
events.delete(rigidBodyRef.current.handle);
|
692
717
|
}
|
693
718
|
};
|
694
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit]);
|
719
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
695
720
|
};
|
696
721
|
|
697
722
|
const scaleColliderArgs = (shape, args, scale) => {
|
@@ -768,7 +793,12 @@ const mutableColliderOptions = {
|
|
768
793
|
},
|
769
794
|
restitutionCombineRule: (collider, value) => {
|
770
795
|
collider.setRestitutionCombineRule(value);
|
771
|
-
}
|
796
|
+
},
|
797
|
+
// To make sure the options all mutalbe options are listed
|
798
|
+
quaternion: () => {},
|
799
|
+
position: () => {},
|
800
|
+
rotation: () => {},
|
801
|
+
scale: () => {}
|
772
802
|
};
|
773
803
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
774
804
|
const setColliderOptions = (collider, options, states) => {
|
@@ -810,11 +840,15 @@ const setColliderOptions = (collider, options, states) => {
|
|
810
840
|
}
|
811
841
|
};
|
812
842
|
const useUpdateColliderOptions = (collidersRef, props, states) => {
|
843
|
+
// TODO: Improve this, split each prop into its own effect
|
844
|
+
const mutablePropsAsFlatArray = useMemo(() => mutableColliderOptionKeys.flatMap(key => {
|
845
|
+
return vectorToTuple(props[key]);
|
846
|
+
}), [props]);
|
813
847
|
useEffect(() => {
|
814
848
|
collidersRef.current.forEach(collider => {
|
815
849
|
setColliderOptions(collider, props, states);
|
816
850
|
});
|
817
|
-
},
|
851
|
+
}, mutablePropsAsFlatArray);
|
818
852
|
};
|
819
853
|
|
820
854
|
const isChildOfMeshCollider = child => {
|
@@ -955,7 +989,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
955
989
|
|
956
990
|
(_collidersRef$current2 = collidersRef.current) === null || _collidersRef$current2 === void 0 ? void 0 : _collidersRef$current2.forEach(collider => events.delete(collider.handle));
|
957
991
|
};
|
958
|
-
}, [onCollisionEnter, onCollisionExit]);
|
992
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
959
993
|
};
|
960
994
|
|
961
995
|
const useRapier = () => {
|
@@ -1242,7 +1276,7 @@ const ConvexHullCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
1242
1276
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1243
1277
|
const RigidBodyContext = /*#__PURE__*/createContext(undefined);
|
1244
1278
|
const useRigidBodyContext = () => useContext(RigidBodyContext);
|
1245
|
-
const RigidBody = /*#__PURE__*/forwardRef((props, ref) => {
|
1279
|
+
const RigidBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, ref) => {
|
1246
1280
|
const {
|
1247
1281
|
children,
|
1248
1282
|
type,
|
@@ -1272,7 +1306,7 @@ const RigidBody = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1272
1306
|
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React.createElement(AnyCollider, _extends({
|
1273
1307
|
key: index
|
1274
1308
|
}, colliderProps)))));
|
1275
|
-
});
|
1309
|
+
}));
|
1276
1310
|
|
1277
1311
|
const MeshCollider = props => {
|
1278
1312
|
const {
|