@react-three/rapier 0.5.1 → 0.5.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.
@@ -2,9 +2,9 @@ import { MutableRefObject } from "react";
|
|
2
2
|
import { CoefficientCombineRule, RigidBody as RapierRigidBody, Collider as RapierCollider, TempContactManifold } from "@dimforge/rapier3d-compat";
|
3
3
|
import { createColliderApi, createJointApi, createRigidBodyApi, createWorldApi } from "./api";
|
4
4
|
export { RapierRigidBody, RapierCollider };
|
5
|
-
export { CoefficientCombineRule as CoefficientCombineRule
|
5
|
+
export { CoefficientCombineRule as CoefficientCombineRule } from "@dimforge/rapier3d-compat";
|
6
6
|
export declare type RefGetter<T> = MutableRefObject<() => T | undefined>;
|
7
|
-
export declare type RigidBodyAutoCollider =
|
7
|
+
export declare type RigidBodyAutoCollider = "ball" | "cuboid" | "hull" | "trimesh" | false;
|
8
8
|
export interface UseRigidBodyAPI {
|
9
9
|
rigidBody: RapierRigidBody;
|
10
10
|
collider: RapierCollider;
|
@@ -65,7 +65,7 @@ export declare type RigidBodyTypeString = "fixed" | "dynamic" | "kinematicPositi
|
|
65
65
|
export declare type RigidBodyShape = "cuboid" | "trimesh" | "ball" | "capsule" | "convexHull" | "heightfield" | "polyline" | "roundCuboid" | "cylinder" | "roundCylinder" | "cone" | "roundCone" | "convexMesh" | "roundConvexHull" | "roundConvexMesh";
|
66
66
|
export declare type Vector3Array = [x: number, y: number, z: number];
|
67
67
|
export declare type Boolean3Array = [x: boolean, y: boolean, z: boolean];
|
68
|
-
export interface UseColliderOptions<
|
68
|
+
export interface UseColliderOptions<ColliderArgs> {
|
69
69
|
/**
|
70
70
|
* The shape of your collider
|
71
71
|
*/
|
@@ -73,7 +73,7 @@ export interface UseColliderOptions<A> {
|
|
73
73
|
/**
|
74
74
|
* Arguments to pass to the collider
|
75
75
|
*/
|
76
|
-
args?:
|
76
|
+
args?: ColliderArgs;
|
77
77
|
/**
|
78
78
|
* The mass of this rigid body.
|
79
79
|
* The mass and density is automatically calculated based on the shape of the collider.
|
@@ -6,13 +6,23 @@ export declare const vectorArrayToObject: (arr: Vector3Array) => {
|
|
6
6
|
y: number;
|
7
7
|
z: number;
|
8
8
|
};
|
9
|
+
export declare const vector3ToQuaternion: (v: Vector3) => Quaternion;
|
9
10
|
export declare const rigidBodyTypeFromString: (type: RigidBodyTypeString) => number;
|
10
11
|
export declare const scaleColliderArgs: (shape: RigidBodyShape, args: (number | ArrayLike<number>)[], scale: Vector3) => (number | ArrayLike<number>)[];
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
interface CreateColliderFromOptions {
|
13
|
+
<ColliderArgs>(options: {
|
14
|
+
options: UseColliderOptions<ColliderArgs>;
|
15
|
+
world: WorldApi;
|
16
|
+
rigidBody?: RigidBody;
|
17
|
+
scale: {
|
18
|
+
x: number;
|
19
|
+
y: number;
|
20
|
+
z: number;
|
21
|
+
};
|
22
|
+
hasCollisionEvents: boolean;
|
23
|
+
}): Collider;
|
24
|
+
}
|
25
|
+
export declare const createColliderFromOptions: CreateColliderFromOptions;
|
16
26
|
export declare const createCollidersFromChildren: (object: Object3D, rigidBody: RigidBodyApi, options: UseRigidBodyOptions, world: WorldApi, ignoreMeshColliders?: boolean) => Collider[];
|
17
27
|
export declare const scaleVertices: (vertices: ArrayLike<number>, scale: Vector3) => number[];
|
18
|
-
export
|
28
|
+
export {};
|
@@ -38,6 +38,11 @@ const vectorArrayToObject = arr => {
|
|
38
38
|
z
|
39
39
|
};
|
40
40
|
};
|
41
|
+
const quaternion = new three.Quaternion();
|
42
|
+
const euler = new three.Euler();
|
43
|
+
const vector3ToQuaternion = v => {
|
44
|
+
return quaternion.setFromEuler(euler.setFromVector3(v));
|
45
|
+
};
|
41
46
|
const rigidBodyTypeMap = {
|
42
47
|
fixed: 1,
|
43
48
|
dynamic: 0,
|
@@ -63,11 +68,13 @@ const scaleColliderArgs = (shape, args, scale) => {
|
|
63
68
|
const scaleArray = [scale.x, scale.y, scale.z];
|
64
69
|
return newArgs.map((arg, index) => scaleArray[index] * arg);
|
65
70
|
};
|
66
|
-
const createColliderFromOptions = (
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
const createColliderFromOptions = ({
|
72
|
+
options,
|
73
|
+
world,
|
74
|
+
rigidBody,
|
75
|
+
scale,
|
76
|
+
hasCollisionEvents
|
77
|
+
}) => {
|
71
78
|
var _options$shape, _options$args, _options$restitution, _options$restitutionC, _options$friction, _options$frictionComb;
|
72
79
|
|
73
80
|
const mass = (options === null || options === void 0 ? void 0 : options.mass) || 1;
|
@@ -76,15 +83,16 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
76
83
|
const [cmx, cmy, cmz] = (options === null || options === void 0 ? void 0 : options.centerOfMass) || [0, 0, 0];
|
77
84
|
const [pix, piy, piz] = (options === null || options === void 0 ? void 0 : options.principalAngularInertia) || [mass * 0.2, mass * 0.2, mass * 0.2];
|
78
85
|
const [x, y, z] = (options === null || options === void 0 ? void 0 : options.position) || [0, 0, 0];
|
79
|
-
const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
|
86
|
+
const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
|
87
|
+
const qRotation = vector3ToQuaternion(new three.Vector3(rx, ry, rz)); // @ts-ignore
|
80
88
|
|
81
89
|
const scaledArgs = scaleColliderArgs(options.shape, colliderArgs, scale);
|
82
90
|
let colliderDesc = rapier3dCompat.ColliderDesc[colliderShape]( // @ts-ignore
|
83
91
|
...scaledArgs).setTranslation(x * scale.x, y * scale.y, z * scale.z).setRotation({
|
84
|
-
x:
|
85
|
-
y:
|
86
|
-
z:
|
87
|
-
w:
|
92
|
+
x: qRotation.x,
|
93
|
+
y: qRotation.y,
|
94
|
+
z: qRotation.z,
|
95
|
+
w: qRotation.w
|
88
96
|
}).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : rapier3dCompat.CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : rapier3dCompat.CoefficientCombineRule.Average);
|
89
97
|
|
90
98
|
if (hasCollisionEvents) {
|
@@ -92,6 +100,8 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
92
100
|
} // If any of the mass properties are specified, add mass properties
|
93
101
|
|
94
102
|
|
103
|
+
const qMassRot = vector3ToQuaternion(new three.Vector3(0, 0, 0));
|
104
|
+
|
95
105
|
if (options !== null && options !== void 0 && options.mass || options !== null && options !== void 0 && options.centerOfMass || options !== null && options !== void 0 && options.principalAngularInertia) {
|
96
106
|
colliderDesc.setDensity(0);
|
97
107
|
colliderDesc.setMassProperties(mass, {
|
@@ -103,10 +113,10 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
103
113
|
y: piy,
|
104
114
|
z: piz
|
105
115
|
}, {
|
106
|
-
x:
|
107
|
-
y:
|
108
|
-
z:
|
109
|
-
w:
|
116
|
+
x: qMassRot.x,
|
117
|
+
y: qMassRot.y,
|
118
|
+
z: qMassRot.z,
|
119
|
+
w: qMassRot.w
|
110
120
|
});
|
111
121
|
}
|
112
122
|
|
@@ -218,11 +228,6 @@ const scaleVertices = (vertices, scale) => {
|
|
218
228
|
|
219
229
|
return scaledVerts;
|
220
230
|
};
|
221
|
-
const quaternion = new three.Quaternion();
|
222
|
-
const euler = new three.Euler();
|
223
|
-
const vector3ToQuaternion = v => {
|
224
|
-
return quaternion.setFromEuler(euler.setFromVector3(v));
|
225
|
-
};
|
226
231
|
|
227
232
|
const createRigidBodyApi = ref => {
|
228
233
|
return {
|
@@ -870,10 +875,15 @@ const RigidBody = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
870
875
|
} = _ref,
|
871
876
|
props = _objectWithoutProperties(_ref, _excluded);
|
872
877
|
|
873
|
-
const [object,
|
874
|
-
React.useImperativeHandle(ref, () =>
|
878
|
+
const [object, api] = useRigidBody(props);
|
879
|
+
React.useImperativeHandle(ref, () => api);
|
875
880
|
return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
|
876
|
-
value:
|
881
|
+
value: {
|
882
|
+
ref: object,
|
883
|
+
api,
|
884
|
+
hasCollisionEvents: !!(props.onCollisionEnter || props.onCollisionExit),
|
885
|
+
options: props
|
886
|
+
}
|
877
887
|
}, /*#__PURE__*/React__default["default"].createElement("object3D", {
|
878
888
|
ref: object
|
879
889
|
}, children));
|
@@ -887,7 +897,10 @@ const MeshCollider = ({
|
|
887
897
|
world
|
888
898
|
} = useRapier();
|
889
899
|
const object = React.useRef(null);
|
890
|
-
const
|
900
|
+
const {
|
901
|
+
api,
|
902
|
+
options
|
903
|
+
} = useRigidBodyContext();
|
891
904
|
React.useEffect(() => {
|
892
905
|
let autoColliders = [];
|
893
906
|
|
@@ -895,7 +908,7 @@ const MeshCollider = ({
|
|
895
908
|
var _ref2;
|
896
909
|
|
897
910
|
const colliderSetting = (_ref2 = type !== null && type !== void 0 ? type : physicsOptions.colliders) !== null && _ref2 !== void 0 ? _ref2 : false;
|
898
|
-
autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current,
|
911
|
+
autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current, api, _objectSpread2(_objectSpread2({}, options), {}, {
|
899
912
|
colliders: colliderSetting
|
900
913
|
}), world, false) : [];
|
901
914
|
}
|
@@ -909,7 +922,7 @@ const MeshCollider = ({
|
|
909
922
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
910
923
|
ref: object,
|
911
924
|
userData: {
|
912
|
-
r3RapierType:
|
925
|
+
r3RapierType: "MeshCollider"
|
913
926
|
}
|
914
927
|
}, children);
|
915
928
|
}; // Colliders
|
@@ -923,11 +936,19 @@ const AnyCollider = _ref3 => {
|
|
923
936
|
const {
|
924
937
|
world
|
925
938
|
} = useRapier();
|
926
|
-
const
|
939
|
+
const rigidBodyContext = useRigidBodyContext();
|
927
940
|
const ref = React.useRef(null);
|
928
941
|
React.useEffect(() => {
|
942
|
+
var _rigidBodyContext$api;
|
943
|
+
|
929
944
|
const scale = ref.current.getWorldScale(new three.Vector3());
|
930
|
-
const collider = createColliderFromOptions(
|
945
|
+
const collider = createColliderFromOptions({
|
946
|
+
options: props,
|
947
|
+
world,
|
948
|
+
rigidBody: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : (_rigidBodyContext$api = rigidBodyContext.api) === null || _rigidBodyContext$api === void 0 ? void 0 : _rigidBodyContext$api.raw(),
|
949
|
+
scale,
|
950
|
+
hasCollisionEvents: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.hasCollisionEvents
|
951
|
+
});
|
931
952
|
return () => {
|
932
953
|
world.removeCollider(collider);
|
933
954
|
};
|
@@ -38,6 +38,11 @@ const vectorArrayToObject = arr => {
|
|
38
38
|
z
|
39
39
|
};
|
40
40
|
};
|
41
|
+
const quaternion = new three.Quaternion();
|
42
|
+
const euler = new three.Euler();
|
43
|
+
const vector3ToQuaternion = v => {
|
44
|
+
return quaternion.setFromEuler(euler.setFromVector3(v));
|
45
|
+
};
|
41
46
|
const rigidBodyTypeMap = {
|
42
47
|
fixed: 1,
|
43
48
|
dynamic: 0,
|
@@ -63,11 +68,13 @@ const scaleColliderArgs = (shape, args, scale) => {
|
|
63
68
|
const scaleArray = [scale.x, scale.y, scale.z];
|
64
69
|
return newArgs.map((arg, index) => scaleArray[index] * arg);
|
65
70
|
};
|
66
|
-
const createColliderFromOptions = (
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
const createColliderFromOptions = ({
|
72
|
+
options,
|
73
|
+
world,
|
74
|
+
rigidBody,
|
75
|
+
scale,
|
76
|
+
hasCollisionEvents
|
77
|
+
}) => {
|
71
78
|
var _options$shape, _options$args, _options$restitution, _options$restitutionC, _options$friction, _options$frictionComb;
|
72
79
|
|
73
80
|
const mass = (options === null || options === void 0 ? void 0 : options.mass) || 1;
|
@@ -76,15 +83,16 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
76
83
|
const [cmx, cmy, cmz] = (options === null || options === void 0 ? void 0 : options.centerOfMass) || [0, 0, 0];
|
77
84
|
const [pix, piy, piz] = (options === null || options === void 0 ? void 0 : options.principalAngularInertia) || [mass * 0.2, mass * 0.2, mass * 0.2];
|
78
85
|
const [x, y, z] = (options === null || options === void 0 ? void 0 : options.position) || [0, 0, 0];
|
79
|
-
const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
|
86
|
+
const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
|
87
|
+
const qRotation = vector3ToQuaternion(new three.Vector3(rx, ry, rz)); // @ts-ignore
|
80
88
|
|
81
89
|
const scaledArgs = scaleColliderArgs(options.shape, colliderArgs, scale);
|
82
90
|
let colliderDesc = rapier3dCompat.ColliderDesc[colliderShape]( // @ts-ignore
|
83
91
|
...scaledArgs).setTranslation(x * scale.x, y * scale.y, z * scale.z).setRotation({
|
84
|
-
x:
|
85
|
-
y:
|
86
|
-
z:
|
87
|
-
w:
|
92
|
+
x: qRotation.x,
|
93
|
+
y: qRotation.y,
|
94
|
+
z: qRotation.z,
|
95
|
+
w: qRotation.w
|
88
96
|
}).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : rapier3dCompat.CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : rapier3dCompat.CoefficientCombineRule.Average);
|
89
97
|
|
90
98
|
if (hasCollisionEvents) {
|
@@ -92,6 +100,8 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
92
100
|
} // If any of the mass properties are specified, add mass properties
|
93
101
|
|
94
102
|
|
103
|
+
const qMassRot = vector3ToQuaternion(new three.Vector3(0, 0, 0));
|
104
|
+
|
95
105
|
if (options !== null && options !== void 0 && options.mass || options !== null && options !== void 0 && options.centerOfMass || options !== null && options !== void 0 && options.principalAngularInertia) {
|
96
106
|
colliderDesc.setDensity(0);
|
97
107
|
colliderDesc.setMassProperties(mass, {
|
@@ -103,10 +113,10 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
103
113
|
y: piy,
|
104
114
|
z: piz
|
105
115
|
}, {
|
106
|
-
x:
|
107
|
-
y:
|
108
|
-
z:
|
109
|
-
w:
|
116
|
+
x: qMassRot.x,
|
117
|
+
y: qMassRot.y,
|
118
|
+
z: qMassRot.z,
|
119
|
+
w: qMassRot.w
|
110
120
|
});
|
111
121
|
}
|
112
122
|
|
@@ -218,11 +228,6 @@ const scaleVertices = (vertices, scale) => {
|
|
218
228
|
|
219
229
|
return scaledVerts;
|
220
230
|
};
|
221
|
-
const quaternion = new three.Quaternion();
|
222
|
-
const euler = new three.Euler();
|
223
|
-
const vector3ToQuaternion = v => {
|
224
|
-
return quaternion.setFromEuler(euler.setFromVector3(v));
|
225
|
-
};
|
226
231
|
|
227
232
|
const createRigidBodyApi = ref => {
|
228
233
|
return {
|
@@ -870,10 +875,15 @@ const RigidBody = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
870
875
|
} = _ref,
|
871
876
|
props = _objectWithoutProperties(_ref, _excluded);
|
872
877
|
|
873
|
-
const [object,
|
874
|
-
React.useImperativeHandle(ref, () =>
|
878
|
+
const [object, api] = useRigidBody(props);
|
879
|
+
React.useImperativeHandle(ref, () => api);
|
875
880
|
return /*#__PURE__*/React__default["default"].createElement(RigidBodyContext.Provider, {
|
876
|
-
value:
|
881
|
+
value: {
|
882
|
+
ref: object,
|
883
|
+
api,
|
884
|
+
hasCollisionEvents: !!(props.onCollisionEnter || props.onCollisionExit),
|
885
|
+
options: props
|
886
|
+
}
|
877
887
|
}, /*#__PURE__*/React__default["default"].createElement("object3D", {
|
878
888
|
ref: object
|
879
889
|
}, children));
|
@@ -887,7 +897,10 @@ const MeshCollider = ({
|
|
887
897
|
world
|
888
898
|
} = useRapier();
|
889
899
|
const object = React.useRef(null);
|
890
|
-
const
|
900
|
+
const {
|
901
|
+
api,
|
902
|
+
options
|
903
|
+
} = useRigidBodyContext();
|
891
904
|
React.useEffect(() => {
|
892
905
|
let autoColliders = [];
|
893
906
|
|
@@ -895,7 +908,7 @@ const MeshCollider = ({
|
|
895
908
|
var _ref2;
|
896
909
|
|
897
910
|
const colliderSetting = (_ref2 = type !== null && type !== void 0 ? type : physicsOptions.colliders) !== null && _ref2 !== void 0 ? _ref2 : false;
|
898
|
-
autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current,
|
911
|
+
autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current, api, _objectSpread2(_objectSpread2({}, options), {}, {
|
899
912
|
colliders: colliderSetting
|
900
913
|
}), world, false) : [];
|
901
914
|
}
|
@@ -909,7 +922,7 @@ const MeshCollider = ({
|
|
909
922
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
910
923
|
ref: object,
|
911
924
|
userData: {
|
912
|
-
r3RapierType:
|
925
|
+
r3RapierType: "MeshCollider"
|
913
926
|
}
|
914
927
|
}, children);
|
915
928
|
}; // Colliders
|
@@ -923,11 +936,19 @@ const AnyCollider = _ref3 => {
|
|
923
936
|
const {
|
924
937
|
world
|
925
938
|
} = useRapier();
|
926
|
-
const
|
939
|
+
const rigidBodyContext = useRigidBodyContext();
|
927
940
|
const ref = React.useRef(null);
|
928
941
|
React.useEffect(() => {
|
942
|
+
var _rigidBodyContext$api;
|
943
|
+
|
929
944
|
const scale = ref.current.getWorldScale(new three.Vector3());
|
930
|
-
const collider = createColliderFromOptions(
|
945
|
+
const collider = createColliderFromOptions({
|
946
|
+
options: props,
|
947
|
+
world,
|
948
|
+
rigidBody: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : (_rigidBodyContext$api = rigidBodyContext.api) === null || _rigidBodyContext$api === void 0 ? void 0 : _rigidBodyContext$api.raw(),
|
949
|
+
scale,
|
950
|
+
hasCollisionEvents: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.hasCollisionEvents
|
951
|
+
});
|
931
952
|
return () => {
|
932
953
|
world.removeCollider(collider);
|
933
954
|
};
|
@@ -13,6 +13,11 @@ const vectorArrayToObject = arr => {
|
|
13
13
|
z
|
14
14
|
};
|
15
15
|
};
|
16
|
+
const quaternion = new Quaternion();
|
17
|
+
const euler = new Euler();
|
18
|
+
const vector3ToQuaternion = v => {
|
19
|
+
return quaternion.setFromEuler(euler.setFromVector3(v));
|
20
|
+
};
|
16
21
|
const rigidBodyTypeMap = {
|
17
22
|
fixed: 1,
|
18
23
|
dynamic: 0,
|
@@ -38,11 +43,13 @@ const scaleColliderArgs = (shape, args, scale) => {
|
|
38
43
|
const scaleArray = [scale.x, scale.y, scale.z];
|
39
44
|
return newArgs.map((arg, index) => scaleArray[index] * arg);
|
40
45
|
};
|
41
|
-
const createColliderFromOptions = (
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
const createColliderFromOptions = ({
|
47
|
+
options,
|
48
|
+
world,
|
49
|
+
rigidBody,
|
50
|
+
scale,
|
51
|
+
hasCollisionEvents
|
52
|
+
}) => {
|
46
53
|
var _options$shape, _options$args, _options$restitution, _options$restitutionC, _options$friction, _options$frictionComb;
|
47
54
|
|
48
55
|
const mass = (options === null || options === void 0 ? void 0 : options.mass) || 1;
|
@@ -51,15 +58,16 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
51
58
|
const [cmx, cmy, cmz] = (options === null || options === void 0 ? void 0 : options.centerOfMass) || [0, 0, 0];
|
52
59
|
const [pix, piy, piz] = (options === null || options === void 0 ? void 0 : options.principalAngularInertia) || [mass * 0.2, mass * 0.2, mass * 0.2];
|
53
60
|
const [x, y, z] = (options === null || options === void 0 ? void 0 : options.position) || [0, 0, 0];
|
54
|
-
const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
|
61
|
+
const [rx, ry, rz] = (options === null || options === void 0 ? void 0 : options.rotation) || [0, 0, 0];
|
62
|
+
const qRotation = vector3ToQuaternion(new Vector3(rx, ry, rz)); // @ts-ignore
|
55
63
|
|
56
64
|
const scaledArgs = scaleColliderArgs(options.shape, colliderArgs, scale);
|
57
65
|
let colliderDesc = ColliderDesc[colliderShape]( // @ts-ignore
|
58
66
|
...scaledArgs).setTranslation(x * scale.x, y * scale.y, z * scale.z).setRotation({
|
59
|
-
x:
|
60
|
-
y:
|
61
|
-
z:
|
62
|
-
w:
|
67
|
+
x: qRotation.x,
|
68
|
+
y: qRotation.y,
|
69
|
+
z: qRotation.z,
|
70
|
+
w: qRotation.w
|
63
71
|
}).setRestitution((_options$restitution = options === null || options === void 0 ? void 0 : options.restitution) !== null && _options$restitution !== void 0 ? _options$restitution : 0).setRestitutionCombineRule((_options$restitutionC = options === null || options === void 0 ? void 0 : options.restitutionCombineRule) !== null && _options$restitutionC !== void 0 ? _options$restitutionC : CoefficientCombineRule.Average).setFriction((_options$friction = options === null || options === void 0 ? void 0 : options.friction) !== null && _options$friction !== void 0 ? _options$friction : 0.7).setFrictionCombineRule((_options$frictionComb = options === null || options === void 0 ? void 0 : options.frictionCombineRule) !== null && _options$frictionComb !== void 0 ? _options$frictionComb : CoefficientCombineRule.Average);
|
64
72
|
|
65
73
|
if (hasCollisionEvents) {
|
@@ -67,6 +75,8 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
67
75
|
} // If any of the mass properties are specified, add mass properties
|
68
76
|
|
69
77
|
|
78
|
+
const qMassRot = vector3ToQuaternion(new Vector3(0, 0, 0));
|
79
|
+
|
70
80
|
if (options !== null && options !== void 0 && options.mass || options !== null && options !== void 0 && options.centerOfMass || options !== null && options !== void 0 && options.principalAngularInertia) {
|
71
81
|
colliderDesc.setDensity(0);
|
72
82
|
colliderDesc.setMassProperties(mass, {
|
@@ -78,10 +88,10 @@ const createColliderFromOptions = (options, world, rigidBody, scale = {
|
|
78
88
|
y: piy,
|
79
89
|
z: piz
|
80
90
|
}, {
|
81
|
-
x:
|
82
|
-
y:
|
83
|
-
z:
|
84
|
-
w:
|
91
|
+
x: qMassRot.x,
|
92
|
+
y: qMassRot.y,
|
93
|
+
z: qMassRot.z,
|
94
|
+
w: qMassRot.w
|
85
95
|
});
|
86
96
|
}
|
87
97
|
|
@@ -193,11 +203,6 @@ const scaleVertices = (vertices, scale) => {
|
|
193
203
|
|
194
204
|
return scaledVerts;
|
195
205
|
};
|
196
|
-
const quaternion = new Quaternion();
|
197
|
-
const euler = new Euler();
|
198
|
-
const vector3ToQuaternion = v => {
|
199
|
-
return quaternion.setFromEuler(euler.setFromVector3(v));
|
200
|
-
};
|
201
206
|
|
202
207
|
const createRigidBodyApi = ref => {
|
203
208
|
return {
|
@@ -845,10 +850,15 @@ const RigidBody = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
845
850
|
} = _ref,
|
846
851
|
props = _objectWithoutProperties(_ref, _excluded);
|
847
852
|
|
848
|
-
const [object,
|
849
|
-
useImperativeHandle(ref, () =>
|
853
|
+
const [object, api] = useRigidBody(props);
|
854
|
+
useImperativeHandle(ref, () => api);
|
850
855
|
return /*#__PURE__*/React.createElement(RigidBodyContext.Provider, {
|
851
|
-
value:
|
856
|
+
value: {
|
857
|
+
ref: object,
|
858
|
+
api,
|
859
|
+
hasCollisionEvents: !!(props.onCollisionEnter || props.onCollisionExit),
|
860
|
+
options: props
|
861
|
+
}
|
852
862
|
}, /*#__PURE__*/React.createElement("object3D", {
|
853
863
|
ref: object
|
854
864
|
}, children));
|
@@ -862,7 +872,10 @@ const MeshCollider = ({
|
|
862
872
|
world
|
863
873
|
} = useRapier();
|
864
874
|
const object = useRef(null);
|
865
|
-
const
|
875
|
+
const {
|
876
|
+
api,
|
877
|
+
options
|
878
|
+
} = useRigidBodyContext();
|
866
879
|
useEffect(() => {
|
867
880
|
let autoColliders = [];
|
868
881
|
|
@@ -870,7 +883,7 @@ const MeshCollider = ({
|
|
870
883
|
var _ref2;
|
871
884
|
|
872
885
|
const colliderSetting = (_ref2 = type !== null && type !== void 0 ? type : physicsOptions.colliders) !== null && _ref2 !== void 0 ? _ref2 : false;
|
873
|
-
autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current,
|
886
|
+
autoColliders = colliderSetting !== false ? createCollidersFromChildren(object.current, api, _objectSpread2(_objectSpread2({}, options), {}, {
|
874
887
|
colliders: colliderSetting
|
875
888
|
}), world, false) : [];
|
876
889
|
}
|
@@ -884,7 +897,7 @@ const MeshCollider = ({
|
|
884
897
|
return /*#__PURE__*/React.createElement("object3D", {
|
885
898
|
ref: object,
|
886
899
|
userData: {
|
887
|
-
r3RapierType:
|
900
|
+
r3RapierType: "MeshCollider"
|
888
901
|
}
|
889
902
|
}, children);
|
890
903
|
}; // Colliders
|
@@ -898,11 +911,19 @@ const AnyCollider = _ref3 => {
|
|
898
911
|
const {
|
899
912
|
world
|
900
913
|
} = useRapier();
|
901
|
-
const
|
914
|
+
const rigidBodyContext = useRigidBodyContext();
|
902
915
|
const ref = useRef(null);
|
903
916
|
useEffect(() => {
|
917
|
+
var _rigidBodyContext$api;
|
918
|
+
|
904
919
|
const scale = ref.current.getWorldScale(new Vector3());
|
905
|
-
const collider = createColliderFromOptions(
|
920
|
+
const collider = createColliderFromOptions({
|
921
|
+
options: props,
|
922
|
+
world,
|
923
|
+
rigidBody: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : (_rigidBodyContext$api = rigidBodyContext.api) === null || _rigidBodyContext$api === void 0 ? void 0 : _rigidBodyContext$api.raw(),
|
924
|
+
scale,
|
925
|
+
hasCollisionEvents: rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.hasCollisionEvents
|
926
|
+
});
|
906
927
|
return () => {
|
907
928
|
world.removeCollider(collider);
|
908
929
|
};
|
package/package.json
CHANGED
package/CHANGELOG.md
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
# @react-three/rapier
|
2
|
-
|
3
|
-
## 0.5.1
|
4
|
-
|
5
|
-
### Patch Changes
|
6
|
-
|
7
|
-
- c36be39: Add MeshCollider, allowing more fine control over automatic collider creation
|
8
|
-
|
9
|
-
## 0.5.0
|
10
|
-
|
11
|
-
### Minor Changes
|
12
|
-
|
13
|
-
- a3be5f6: Remove hooks api in favor of better fleshed out components
|
14
|
-
|
15
|
-
### Patch Changes
|
16
|
-
|
17
|
-
- a3be5f6: Update types for Joints -- now only allow RefObjects of RigidBodyApi
|
18
|
-
- a3be5f6: Fix setKinematicRotation (convert Vector3 to Quaternion)
|
19
|
-
- a3be5f6: Update to @dimforge/rapier3d-compat@0.9.0
|
20
|
-
- a3be5f6: Allow setting the physics timeStep
|
21
|
-
- a3be5f6: Add rotational and transitional constraits to RigidBody
|
22
|
-
- a3be5f6: Allow updating the gravity at runtime
|
23
|
-
|
24
|
-
## 0.4.3
|
25
|
-
|
26
|
-
### Patch Changes
|
27
|
-
|
28
|
-
- f7a8a2d: Rigid body creation hooks should not use auto colliders
|
29
|
-
- 663eeb5: Fix default collider setting
|
30
|
-
|
31
|
-
## 0.4.2
|
32
|
-
|
33
|
-
### Patch Changes
|
34
|
-
|
35
|
-
- 387b32c: Add restitution and friction as props for auto-generated colliders on RigidBody
|
36
|
-
|
37
|
-
## 0.4.1
|
38
|
-
|
39
|
-
### Patch Changes
|
40
|
-
|
41
|
-
- bb7a269: Add useful proxied api methods to rigidbody
|
42
|
-
|
43
|
-
## 0.4.0
|
44
|
-
|
45
|
-
### Minor Changes
|
46
|
-
|
47
|
-
- dd535aa: Update to @dimforge/rapier3d-compat@0.8.1, pinned version
|
48
|
-
|
49
|
-
### Patch Changes
|
50
|
-
|
51
|
-
- dd535aa: Better <Physics /> lifecycle making reinitialization more stable
|
52
|
-
|
53
|
-
## 0.3.1
|
54
|
-
|
55
|
-
### Patch Changes
|
56
|
-
|
57
|
-
- 37d2621: Pin rapier3d version to 0.8.0-alpha.2
|
58
|
-
|
59
|
-
## 0.3.0
|
60
|
-
|
61
|
-
### Minor Changes
|
62
|
-
|
63
|
-
- 7e36172: Add collision and sleep/awake events
|
64
|
-
|
65
|
-
## 0.2.0
|
66
|
-
|
67
|
-
### Minor Changes
|
68
|
-
|
69
|
-
- 584ce08: Expose joint api, however no joint is returned when created (rapier bug?)
|
70
|
-
|
71
|
-
### Patch Changes
|
72
|
-
|
73
|
-
- 584ce08: All parts now uses a more rigid initiation process
|
74
|
-
- 584ce08: Apply bounding box offset for auto colliders
|
75
|
-
- 584ce08: Use single update loop instead of individual rigid body callbacks
|
76
|
-
|
77
|
-
## 0.1.2
|
78
|
-
|
79
|
-
### Patch Changes
|
80
|
-
|
81
|
-
- 4f7440c: fix: make global colliders setting progate to children
|
82
|
-
|
83
|
-
## 0.1.1
|
84
|
-
|
85
|
-
### Patch Changes
|
86
|
-
|
87
|
-
- 260e6d1: Fix Physics "colliders" value not being applied in children by default
|
88
|
-
|
89
|
-
## 0.1.0
|
90
|
-
|
91
|
-
### Minor Changes
|
92
|
-
|
93
|
-
- First release with base functionality of RigidBodies in Rapier
|