@react-three/rapier 0.7.4 → 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/AnyCollider.d.ts +38 -10
- package/dist/declarations/src/RigidBody.d.ts +1 -1
- package/dist/declarations/src/api.d.ts +19 -19
- package/dist/declarations/src/types.d.ts +23 -12
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/react-three-rapier.cjs.dev.js +154 -72
- package/dist/react-three-rapier.cjs.prod.js +154 -72
- package/dist/react-three-rapier.esm.js +155 -73
- package/package.json +9 -4
- package/readme.md +3 -1
@@ -3,7 +3,7 @@ export { CoefficientCombineRule, Collider as RapierCollider, RigidBody as Rapier
|
|
3
3
|
import React, { useState, useEffect, useRef, useMemo, createContext, useContext, memo, forwardRef, useImperativeHandle, useLayoutEffect } from 'react';
|
4
4
|
import { useAsset } from 'use-asset';
|
5
5
|
import { useFrame } from '@react-three/fiber';
|
6
|
-
import { Quaternion, Euler, Vector3, Object3D, Matrix4, MathUtils, InstancedMesh, MeshBasicMaterial, Color, PlaneGeometry,
|
6
|
+
import { Quaternion, Euler, Vector3, Object3D, Matrix4, MathUtils, InstancedMesh, MeshBasicMaterial, Color, PlaneGeometry, ConeGeometry, CapsuleGeometry, CylinderGeometry, BufferGeometry, BufferAttribute, SphereGeometry, BoxGeometry, DynamicDrawUsage } from 'three';
|
7
7
|
import { mergeVertices, RoundedBoxGeometry } from 'three-stdlib';
|
8
8
|
|
9
9
|
const _quaternion = new Quaternion();
|
@@ -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 {
|
@@ -59,24 +76,24 @@ const createRigidBodyApi = ref => {
|
|
59
76
|
|
60
77
|
mass: () => ref.current().mass(),
|
61
78
|
|
62
|
-
applyImpulse(impulseVector) {
|
63
|
-
ref.current().applyImpulse(impulseVector,
|
79
|
+
applyImpulse(impulseVector, wakeUp = true) {
|
80
|
+
ref.current().applyImpulse(impulseVector, wakeUp);
|
64
81
|
},
|
65
82
|
|
66
|
-
applyTorqueImpulse(torqueVector) {
|
67
|
-
ref.current().applyTorqueImpulse(torqueVector,
|
83
|
+
applyTorqueImpulse(torqueVector, wakeUp = true) {
|
84
|
+
ref.current().applyTorqueImpulse(torqueVector, wakeUp);
|
68
85
|
},
|
69
86
|
|
70
|
-
applyImpulseAtPoint: (impulseVector, impulsePoint) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint,
|
71
|
-
addForce: force => ref.current().addForce(force,
|
72
|
-
addForceAtPoint: (force, point) => ref.current().addForceAtPoint(force, point,
|
73
|
-
addTorque: torque => ref.current().addTorque(torque,
|
87
|
+
applyImpulseAtPoint: (impulseVector, impulsePoint, wakeUp = true) => ref.current().applyImpulseAtPoint(impulseVector, impulsePoint, wakeUp),
|
88
|
+
addForce: (force, wakeUp = true) => ref.current().addForce(force, wakeUp),
|
89
|
+
addForceAtPoint: (force, point, wakeUp = true) => ref.current().addForceAtPoint(force, point, wakeUp),
|
90
|
+
addTorque: (torque, wakeUp = true) => ref.current().addTorque(torque, wakeUp),
|
74
91
|
|
75
92
|
translation() {
|
76
93
|
return rapierVector3ToVector3(ref.current().translation());
|
77
94
|
},
|
78
95
|
|
79
|
-
setTranslation: translation => ref.current().setTranslation(translation,
|
96
|
+
setTranslation: (translation, wakeUp = true) => ref.current().setTranslation(translation, wakeUp),
|
80
97
|
|
81
98
|
rotation() {
|
82
99
|
const {
|
@@ -88,8 +105,8 @@ const createRigidBodyApi = ref => {
|
|
88
105
|
return new Quaternion(x, y, z, w);
|
89
106
|
},
|
90
107
|
|
91
|
-
setRotation: rotation => {
|
92
|
-
ref.current().setRotation(rotation,
|
108
|
+
setRotation: (rotation, wakeUp = true) => {
|
109
|
+
ref.current().setRotation(rotation, wakeUp);
|
93
110
|
},
|
94
111
|
|
95
112
|
linvel() {
|
@@ -101,7 +118,7 @@ const createRigidBodyApi = ref => {
|
|
101
118
|
return new Vector3(x, y, z);
|
102
119
|
},
|
103
120
|
|
104
|
-
setLinvel: velocity => ref.current().setLinvel(velocity,
|
121
|
+
setLinvel: (velocity, wakeUp = true) => ref.current().setLinvel(velocity, wakeUp),
|
105
122
|
|
106
123
|
angvel() {
|
107
124
|
const {
|
@@ -112,7 +129,7 @@ const createRigidBodyApi = ref => {
|
|
112
129
|
return new Vector3(x, y, z);
|
113
130
|
},
|
114
131
|
|
115
|
-
setAngvel: velocity => ref.current().setAngvel(velocity,
|
132
|
+
setAngvel: (velocity, wakeUp = true) => ref.current().setAngvel(velocity, wakeUp),
|
116
133
|
|
117
134
|
linearDamping() {
|
118
135
|
return ref.current().linearDamping();
|
@@ -129,12 +146,12 @@ const createRigidBodyApi = ref => {
|
|
129
146
|
ref.current().setNextKinematicRotation(rotation);
|
130
147
|
},
|
131
148
|
setNextKinematicTranslation: translation => ref.current().setNextKinematicTranslation(translation),
|
132
|
-
resetForces: () => ref.current().resetForces(
|
133
|
-
resetTorques: () => ref.current().resetTorques(
|
134
|
-
lockRotations: locked => ref.current().lockRotations(locked,
|
135
|
-
lockTranslations: locked => ref.current().lockTranslations(locked,
|
136
|
-
setEnabledRotations: (x, y, z) => ref.current().setEnabledRotations(x, y, z,
|
137
|
-
setEnabledTranslations: (x, y, z) => ref.current().setEnabledTranslations(x, y, z,
|
149
|
+
resetForces: (wakeUp = true) => ref.current().resetForces(wakeUp),
|
150
|
+
resetTorques: (wakeUp = true) => ref.current().resetTorques(wakeUp),
|
151
|
+
lockRotations: (locked, wakeUp = true) => ref.current().lockRotations(locked, wakeUp),
|
152
|
+
lockTranslations: (locked, wakeUp = true) => ref.current().lockTranslations(locked, wakeUp),
|
153
|
+
setEnabledRotations: (x, y, z, wakeUp = true) => ref.current().setEnabledRotations(x, y, z, wakeUp),
|
154
|
+
setEnabledTranslations: (x, y, z, wakeUp = true) => ref.current().setEnabledTranslations(x, y, z, wakeUp)
|
138
155
|
};
|
139
156
|
};
|
140
157
|
const createInstancedRigidBodiesApi = bodiesGetter => ({
|
@@ -157,9 +174,9 @@ const createWorldApi = ref => {
|
|
157
174
|
createRigidBody: desc => ref.current().createRigidBody(desc),
|
158
175
|
createCollider: (desc, rigidBody) => ref.current().createCollider(desc, rigidBody),
|
159
176
|
removeRigidBody: rigidBody => ref.current().removeRigidBody(rigidBody),
|
160
|
-
removeCollider: collider => ref.current().removeCollider(collider,
|
161
|
-
createImpulseJoint: (params, rigidBodyA, rigidBodyB) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB,
|
162
|
-
removeImpulseJoint: joint => ref.current().removeImpulseJoint(joint,
|
177
|
+
removeCollider: (collider, wakeUp = true) => ref.current().removeCollider(collider, wakeUp),
|
178
|
+
createImpulseJoint: (params, rigidBodyA, rigidBodyB, wakeUp = true) => ref.current().createImpulseJoint(params, rigidBodyA, rigidBodyB, wakeUp),
|
179
|
+
removeImpulseJoint: (joint, wakeUp = true) => ref.current().removeImpulseJoint(joint, wakeUp),
|
163
180
|
forEachCollider: callback => ref.current().forEachCollider(callback),
|
164
181
|
setGravity: ({
|
165
182
|
x,
|
@@ -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) => {
|
@@ -721,6 +746,32 @@ const createColliderFromOptions = (options, world, scale, rigidBody) => {
|
|
721
746
|
const desc = ColliderDesc[options.shape](...scaledArgs);
|
722
747
|
return world.createCollider(desc, rigidBody);
|
723
748
|
};
|
749
|
+
const massPropertiesConflictError = "Please pick ONLY ONE of the `density`, `mass` and `massProperties` options.";
|
750
|
+
|
751
|
+
const setColliderMassOptions = (collider, options) => {
|
752
|
+
if (options.density !== undefined) {
|
753
|
+
if (options.mass !== undefined || options.massProperties !== undefined) {
|
754
|
+
throw new Error(massPropertiesConflictError);
|
755
|
+
}
|
756
|
+
|
757
|
+
collider.setDensity(options.density);
|
758
|
+
return;
|
759
|
+
}
|
760
|
+
|
761
|
+
if (options.mass !== undefined) {
|
762
|
+
if (options.massProperties !== undefined) {
|
763
|
+
throw new Error(massPropertiesConflictError);
|
764
|
+
}
|
765
|
+
|
766
|
+
collider.setMass(options.mass);
|
767
|
+
return;
|
768
|
+
}
|
769
|
+
|
770
|
+
if (options.massProperties !== undefined) {
|
771
|
+
collider.setMassProperties(options.massProperties.mass, options.massProperties.centerOfMass, options.massProperties.principalAngularInertia, options.massProperties.angularInertiaLocalFrame);
|
772
|
+
}
|
773
|
+
};
|
774
|
+
|
724
775
|
const mutableColliderOptions = {
|
725
776
|
sensor: (collider, value) => {
|
726
777
|
collider.setSensor(value);
|
@@ -734,15 +785,20 @@ const mutableColliderOptions = {
|
|
734
785
|
friction: (collider, value) => {
|
735
786
|
collider.setFriction(value);
|
736
787
|
},
|
788
|
+
frictionCombineRule: (collider, value) => {
|
789
|
+
collider.setFrictionCombineRule(value);
|
790
|
+
},
|
737
791
|
restitution: (collider, value) => {
|
738
792
|
collider.setRestitution(value);
|
739
793
|
},
|
740
|
-
|
741
|
-
collider.
|
794
|
+
restitutionCombineRule: (collider, value) => {
|
795
|
+
collider.setRestitutionCombineRule(value);
|
742
796
|
},
|
743
|
-
|
744
|
-
|
745
|
-
}
|
797
|
+
// To make sure the options all mutalbe options are listed
|
798
|
+
quaternion: () => {},
|
799
|
+
position: () => {},
|
800
|
+
rotation: () => {},
|
801
|
+
scale: () => {}
|
746
802
|
};
|
747
803
|
const mutableColliderOptionKeys = Object.keys(mutableColliderOptions);
|
748
804
|
const setColliderOptions = (collider, options, states) => {
|
@@ -773,17 +829,26 @@ const setColliderOptions = (collider, options, states) => {
|
|
773
829
|
|
774
830
|
mutableColliderOptionKeys.forEach(key => {
|
775
831
|
if (key in options) {
|
776
|
-
|
832
|
+
const option = options[key];
|
833
|
+
mutableColliderOptions[key](collider, // @ts-ignore Option does not want to fit into the function, but it will
|
834
|
+
option, options);
|
777
835
|
}
|
778
|
-
});
|
836
|
+
}); // handle mass separately, because the assignments
|
837
|
+
// are exclusive.
|
838
|
+
|
839
|
+
setColliderMassOptions(collider, options);
|
779
840
|
}
|
780
841
|
};
|
781
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]);
|
782
847
|
useEffect(() => {
|
783
848
|
collidersRef.current.forEach(collider => {
|
784
849
|
setColliderOptions(collider, props, states);
|
785
850
|
});
|
786
|
-
},
|
851
|
+
}, mutablePropsAsFlatArray);
|
787
852
|
};
|
788
853
|
|
789
854
|
const isChildOfMeshCollider = child => {
|
@@ -924,7 +989,7 @@ const useColliderEvents = (collidersRef, props, events) => {
|
|
924
989
|
|
925
990
|
(_collidersRef$current2 = collidersRef.current) === null || _collidersRef$current2 === void 0 ? void 0 : _collidersRef$current2.forEach(collider => events.delete(collider.handle));
|
926
991
|
};
|
927
|
-
}, [onCollisionEnter, onCollisionExit]);
|
992
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
928
993
|
};
|
929
994
|
|
930
995
|
const useRapier = () => {
|
@@ -1084,7 +1149,7 @@ const usePrismaticJoint = (body1, body2, [body1Anchor, body2Anchor, axis]) => {
|
|
1084
1149
|
};
|
1085
1150
|
|
1086
1151
|
// Colliders
|
1087
|
-
const AnyCollider = /*#__PURE__*/memo(props => {
|
1152
|
+
const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
1088
1153
|
const {
|
1089
1154
|
children,
|
1090
1155
|
position,
|
@@ -1099,7 +1164,15 @@ const AnyCollider = /*#__PURE__*/memo(props => {
|
|
1099
1164
|
} = useRapier();
|
1100
1165
|
const rigidBodyContext = useRigidBodyContext();
|
1101
1166
|
const ref = useRef(null);
|
1102
|
-
const collidersRef =
|
1167
|
+
const collidersRef = useMemo(() => {
|
1168
|
+
if (forwardedRef !== null) {
|
1169
|
+
return forwardedRef;
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
const result = /*#__PURE__*/React.createRef();
|
1173
|
+
result.current = [];
|
1174
|
+
return result;
|
1175
|
+
}, []);
|
1103
1176
|
useEffect(() => {
|
1104
1177
|
const object = ref.current;
|
1105
1178
|
const worldScale = object.getWorldScale(new Vector3());
|
@@ -1144,57 +1217,66 @@ const AnyCollider = /*#__PURE__*/memo(props => {
|
|
1144
1217
|
scale: scale,
|
1145
1218
|
ref: ref
|
1146
1219
|
}, children);
|
1147
|
-
});
|
1148
|
-
const CuboidCollider = props => {
|
1220
|
+
}));
|
1221
|
+
const CuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1149
1222
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1150
|
-
shape: "cuboid"
|
1223
|
+
shape: "cuboid",
|
1224
|
+
ref: ref
|
1151
1225
|
}));
|
1152
|
-
};
|
1153
|
-
const RoundCuboidCollider = props => {
|
1226
|
+
});
|
1227
|
+
const RoundCuboidCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1154
1228
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1155
|
-
shape: "roundCuboid"
|
1229
|
+
shape: "roundCuboid",
|
1230
|
+
ref: ref
|
1156
1231
|
}));
|
1157
|
-
};
|
1158
|
-
const BallCollider = props => {
|
1232
|
+
});
|
1233
|
+
const BallCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1159
1234
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1160
|
-
shape: "ball"
|
1235
|
+
shape: "ball",
|
1236
|
+
ref: ref
|
1161
1237
|
}));
|
1162
|
-
};
|
1163
|
-
const CapsuleCollider = props => {
|
1238
|
+
});
|
1239
|
+
const CapsuleCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1164
1240
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1165
|
-
shape: "capsule"
|
1241
|
+
shape: "capsule",
|
1242
|
+
ref: ref
|
1166
1243
|
}));
|
1167
|
-
};
|
1168
|
-
const HeightfieldCollider = props => {
|
1244
|
+
});
|
1245
|
+
const HeightfieldCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1169
1246
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1170
|
-
shape: "heightfield"
|
1247
|
+
shape: "heightfield",
|
1248
|
+
ref: ref
|
1171
1249
|
}));
|
1172
|
-
};
|
1173
|
-
const TrimeshCollider = props => {
|
1250
|
+
});
|
1251
|
+
const TrimeshCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1174
1252
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1175
|
-
shape: "trimesh"
|
1253
|
+
shape: "trimesh",
|
1254
|
+
ref: ref
|
1176
1255
|
}));
|
1177
|
-
};
|
1178
|
-
const ConeCollider = props => {
|
1256
|
+
});
|
1257
|
+
const ConeCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1179
1258
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1180
|
-
shape: "cone"
|
1259
|
+
shape: "cone",
|
1260
|
+
ref: ref
|
1181
1261
|
}));
|
1182
|
-
};
|
1183
|
-
const CylinderCollider = props => {
|
1262
|
+
});
|
1263
|
+
const CylinderCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1184
1264
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1185
|
-
shape: "cylinder"
|
1265
|
+
shape: "cylinder",
|
1266
|
+
ref: ref
|
1186
1267
|
}));
|
1187
|
-
};
|
1188
|
-
const ConvexHullCollider = props => {
|
1268
|
+
});
|
1269
|
+
const ConvexHullCollider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
1189
1270
|
return /*#__PURE__*/React.createElement(AnyCollider, _extends({}, props, {
|
1190
|
-
shape: "convexHull"
|
1271
|
+
shape: "convexHull",
|
1272
|
+
ref: ref
|
1191
1273
|
}));
|
1192
|
-
};
|
1274
|
+
});
|
1193
1275
|
|
1194
1276
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion"];
|
1195
1277
|
const RigidBodyContext = /*#__PURE__*/createContext(undefined);
|
1196
1278
|
const useRigidBodyContext = () => useContext(RigidBodyContext);
|
1197
|
-
const RigidBody = /*#__PURE__*/forwardRef((props, ref) => {
|
1279
|
+
const RigidBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, ref) => {
|
1198
1280
|
const {
|
1199
1281
|
children,
|
1200
1282
|
type,
|
@@ -1224,7 +1306,7 @@ const RigidBody = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1224
1306
|
}), children, childColliderProps.map((colliderProps, index) => /*#__PURE__*/React.createElement(AnyCollider, _extends({
|
1225
1307
|
key: index
|
1226
1308
|
}, colliderProps)))));
|
1227
|
-
});
|
1309
|
+
}));
|
1228
1310
|
|
1229
1311
|
const MeshCollider = props => {
|
1230
1312
|
const {
|
@@ -1265,7 +1347,7 @@ const geometryFromCollider = collider => {
|
|
1265
1347
|
y,
|
1266
1348
|
z
|
1267
1349
|
} = collider.shape.halfExtents;
|
1268
|
-
return new
|
1350
|
+
return new BoxGeometry(x * 2 + 0.01, y * 2 + 0.01, z * 2 + 0.01);
|
1269
1351
|
}
|
1270
1352
|
|
1271
1353
|
case ShapeType.RoundCuboid:
|
@@ -1282,7 +1364,7 @@ const geometryFromCollider = collider => {
|
|
1282
1364
|
case ShapeType.Ball:
|
1283
1365
|
{
|
1284
1366
|
const r = collider.shape.radius;
|
1285
|
-
return new
|
1367
|
+
return new SphereGeometry(r + +0.01, 8, 8);
|
1286
1368
|
}
|
1287
1369
|
|
1288
1370
|
case ShapeType.TriMesh:
|
@@ -1314,7 +1396,7 @@ const geometryFromCollider = collider => {
|
|
1314
1396
|
{
|
1315
1397
|
const r = collider.shape.radius;
|
1316
1398
|
const h = collider.shape.halfHeight;
|
1317
|
-
const g = new
|
1399
|
+
const g = new CylinderGeometry(r, r, h * 2);
|
1318
1400
|
return g;
|
1319
1401
|
}
|
1320
1402
|
|
@@ -1322,7 +1404,7 @@ const geometryFromCollider = collider => {
|
|
1322
1404
|
{
|
1323
1405
|
const r = collider.shape.radius;
|
1324
1406
|
const h = collider.shape.halfHeight;
|
1325
|
-
const g = new
|
1407
|
+
const g = new CapsuleGeometry(r, h * 2, 4, 8);
|
1326
1408
|
return g;
|
1327
1409
|
}
|
1328
1410
|
|
@@ -1330,7 +1412,7 @@ const geometryFromCollider = collider => {
|
|
1330
1412
|
{
|
1331
1413
|
const r = collider.shape.radius;
|
1332
1414
|
const h = collider.shape.halfHeight;
|
1333
|
-
const g = new
|
1415
|
+
const g = new ConeGeometry(r, h * 2, 16);
|
1334
1416
|
return g;
|
1335
1417
|
}
|
1336
1418
|
|
@@ -1350,7 +1432,7 @@ const geometryFromCollider = collider => {
|
|
1350
1432
|
}
|
1351
1433
|
}
|
1352
1434
|
|
1353
|
-
return new
|
1435
|
+
return new BoxGeometry(1, 1, 1);
|
1354
1436
|
};
|
1355
1437
|
|
1356
1438
|
const DebugShape = /*#__PURE__*/memo(({
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-three/rapier",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.6",
|
4
4
|
"source": "src/index.ts",
|
5
5
|
"main": "dist/react-three-rapier.cjs.js",
|
6
6
|
"module": "dist/react-three-rapier.esm.js",
|
@@ -11,11 +11,16 @@
|
|
11
11
|
"devDependencies": {
|
12
12
|
"@react-three/drei": "^9.6.2",
|
13
13
|
"@react-three/fiber": "^8.0.12",
|
14
|
+
"@react-three/test-renderer": "^8.0.17",
|
14
15
|
"@types/react-dom": "^18.0.2",
|
15
16
|
"@types/three": "^0.139.0",
|
17
|
+
"@vitejs/plugin-react": "^2.1.0",
|
18
|
+
"@vitest/ui": "^0.23.4",
|
19
|
+
"happy-dom": "^6.0.4",
|
16
20
|
"react": "^18.1.0",
|
17
21
|
"react-dom": "^18.1.0",
|
18
|
-
"three": "^0.139.2"
|
22
|
+
"three": "^0.139.2",
|
23
|
+
"vitest": "^0.23.4"
|
19
24
|
},
|
20
25
|
"peerDependencies": {
|
21
26
|
"@react-three/fiber": "^8.0.12",
|
@@ -24,8 +29,8 @@
|
|
24
29
|
},
|
25
30
|
"dependencies": {
|
26
31
|
"@dimforge/rapier3d-compat": "0.9.0",
|
27
|
-
"
|
28
|
-
"
|
32
|
+
"three-stdlib": "^2.15.0",
|
33
|
+
"use-asset": "^1.0.4"
|
29
34
|
},
|
30
35
|
"repository": "https://github.com/pmndrs/react-three-rapier/tree/master/packages/react-three-rapier"
|
31
36
|
}
|
package/readme.md
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
|
10
10
|
<p align="center">⚠️ Under heavy development. All APIs are subject to change. ⚠️</p>
|
11
11
|
|
12
|
+
For contributions, please read the [contributing guide](https://github.com/pmndrs/react-three-rapier/blob/main/packages/react-three-rapier/CONTRIBUTING.md).
|
13
|
+
|
12
14
|
## Usage
|
13
15
|
|
14
16
|
```tsx
|
@@ -171,7 +173,7 @@ const Scene = () => {
|
|
171
173
|
colliders="ball"
|
172
174
|
>
|
173
175
|
<instancedMesh args={[undefined, undefined, COUNT]}>
|
174
|
-
<
|
176
|
+
<sphereGeometry args={[0.2]} />
|
175
177
|
<meshPhysicalGeometry color="blue" />
|
176
178
|
|
177
179
|
<CuboidCollider args={[0.1, 0.2, 0.1]} />
|