@react-three/rapier 0.7.2 → 0.7.4
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/Physics.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/types.d.ts +9 -9
- package/dist/react-three-rapier.cjs.dev.js +23 -11
- package/dist/react-three-rapier.cjs.prod.js +23 -11
- package/dist/react-three-rapier.esm.js +24 -12
- package/package.json +1 -1
- package/readme.md +3 -3
@@ -15,7 +15,7 @@ export interface RigidBodyState {
|
|
15
15
|
scale: Vector3;
|
16
16
|
isSleeping: boolean;
|
17
17
|
}
|
18
|
-
export declare type RigidBodyStateMap = Map<RigidBody[
|
18
|
+
export declare type RigidBodyStateMap = Map<RigidBody["handle"], RigidBodyState>;
|
19
19
|
export interface ColliderState {
|
20
20
|
collider: Collider;
|
21
21
|
object: Object3D;
|
@@ -25,7 +25,7 @@ export interface ColliderState {
|
|
25
25
|
*/
|
26
26
|
worldParent: Object3D;
|
27
27
|
}
|
28
|
-
export declare type ColliderStateMap = Map<Collider[
|
28
|
+
export declare type ColliderStateMap = Map<Collider["handle"], ColliderState>;
|
29
29
|
export interface RapierContext {
|
30
30
|
rapier: typeof Rapier;
|
31
31
|
world: WorldApi;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
export * from "./types";
|
2
2
|
export type { RigidBodyApi, WorldApi, InstancedRigidBodyApi } from "./api";
|
3
|
-
export type { RigidBodyProps } from
|
4
|
-
export type { InstancedRigidBodiesProps } from
|
5
|
-
export type { CylinderColliderProps, BallColliderProps, CapsuleColliderProps, ConeColliderProps, ConvexHullColliderProps, CuboidColliderProps, HeightfieldColliderProps, RoundCuboidColliderProps, TrimeshColliderProps } from
|
3
|
+
export type { RigidBodyProps } from "./RigidBody";
|
4
|
+
export type { InstancedRigidBodiesProps } from "./InstancedRigidBodies";
|
5
|
+
export type { CylinderColliderProps, BallColliderProps, CapsuleColliderProps, ConeColliderProps, ConvexHullColliderProps, CuboidColliderProps, HeightfieldColliderProps, RoundCuboidColliderProps, TrimeshColliderProps } from "./AnyCollider";
|
6
6
|
export { Physics } from "./Physics";
|
7
7
|
export { RigidBody } from "./RigidBody";
|
8
8
|
export { MeshCollider } from "./MeshCollider";
|
@@ -118,19 +118,19 @@ export interface UseColliderOptions<ColliderArgs extends Array<unknown>> {
|
|
118
118
|
/**
|
119
119
|
* The position of this collider relative to the rigid body
|
120
120
|
*/
|
121
|
-
position?: Object3DProps[
|
121
|
+
position?: Object3DProps["position"];
|
122
122
|
/**
|
123
123
|
* The rotation of this collider relative to the rigid body
|
124
124
|
*/
|
125
|
-
rotation?: Object3DProps[
|
125
|
+
rotation?: Object3DProps["rotation"];
|
126
126
|
/**
|
127
127
|
* The rotation, as a Quaternion, of this collider relative to the rigid body
|
128
128
|
*/
|
129
|
-
quaternion?: Object3DProps[
|
129
|
+
quaternion?: Object3DProps["quaternion"];
|
130
130
|
/**
|
131
131
|
* The scale of this collider relative to the rigid body
|
132
132
|
*/
|
133
|
-
scale?: Object3DProps[
|
133
|
+
scale?: Object3DProps["scale"];
|
134
134
|
/**
|
135
135
|
* Callback when this collider collides with another collider.
|
136
136
|
*/
|
@@ -219,11 +219,11 @@ export interface UseRigidBodyOptions extends ColliderProps {
|
|
219
219
|
/**
|
220
220
|
* Initial position of the RigidBody
|
221
221
|
*/
|
222
|
-
position?: Object3DProps[
|
222
|
+
position?: Object3DProps["position"];
|
223
223
|
/**
|
224
224
|
* Initial rotation of the RigidBody
|
225
225
|
*/
|
226
|
-
rotation?: Object3DProps[
|
226
|
+
rotation?: Object3DProps["rotation"];
|
227
227
|
/**
|
228
228
|
* Automatically generate colliders based on meshes inside this
|
229
229
|
* rigid body.
|
@@ -250,8 +250,8 @@ export interface UseRigidBodyOptions extends ColliderProps {
|
|
250
250
|
*/
|
251
251
|
collisionGroups?: InteractionGroups;
|
252
252
|
/**
|
253
|
-
|
254
|
-
|
253
|
+
* The default solver groups bitmask for all colliders in this rigid body.
|
254
|
+
* Can be customized per-collider.
|
255
255
|
*/
|
256
256
|
solverGroups?: InteractionGroups;
|
257
257
|
onSleep?(): void;
|
@@ -275,7 +275,7 @@ export interface UseRigidBodyOptions extends ColliderProps {
|
|
275
275
|
/**
|
276
276
|
* Passed down to the object3d representing this collider.
|
277
277
|
*/
|
278
|
-
userData?: Object3DProps[
|
278
|
+
userData?: Object3DProps["userData"];
|
279
279
|
}
|
280
280
|
export declare type SphericalJointParams = [
|
281
281
|
body1Anchor: Vector3Array,
|
@@ -7,7 +7,6 @@ var React = require('react');
|
|
7
7
|
var useAsset = require('use-asset');
|
8
8
|
var fiber = require('@react-three/fiber');
|
9
9
|
var three = require('three');
|
10
|
-
var MathUtils = require('three/src/math/MathUtils');
|
11
10
|
var threeStdlib = require('three-stdlib');
|
12
11
|
|
13
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
@@ -277,9 +276,9 @@ const Physics = ({
|
|
277
276
|
/**
|
278
277
|
* Fixed timeStep simulation progression
|
279
278
|
* @see https://gafferongames.com/post/fix_your_timestep/
|
280
|
-
|
279
|
+
*/
|
281
280
|
|
282
|
-
const clampedDelta = MathUtils.clamp(dt, 0, 0.2);
|
281
|
+
const clampedDelta = three.MathUtils.clamp(dt, 0, 0.2);
|
283
282
|
|
284
283
|
if (timeStepVariable) {
|
285
284
|
world.timestep = clampedDelta;
|
@@ -781,12 +780,22 @@ const setColliderOptions = (collider, options, states) => {
|
|
781
780
|
|
782
781
|
_matrix4.copy(state.object.matrixWorld).premultiply(state.worldParent.matrixWorld.clone().invert()).decompose(_position, _rotation, _scale);
|
783
782
|
|
784
|
-
collider.
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
783
|
+
if (collider.parent()) {
|
784
|
+
collider.setTranslationWrtParent({
|
785
|
+
x: _position.x * parentWorldScale.x,
|
786
|
+
y: _position.y * parentWorldScale.y,
|
787
|
+
z: _position.z * parentWorldScale.z
|
788
|
+
});
|
789
|
+
collider.setRotationWrtParent(_rotation);
|
790
|
+
} else {
|
791
|
+
collider.setTranslation({
|
792
|
+
x: _position.x * parentWorldScale.x,
|
793
|
+
y: _position.y * parentWorldScale.y,
|
794
|
+
z: _position.z * parentWorldScale.z
|
795
|
+
});
|
796
|
+
collider.setRotation(_rotation);
|
797
|
+
}
|
798
|
+
|
790
799
|
mutableColliderOptionKeys.forEach(key => {
|
791
800
|
if (key in options) {
|
792
801
|
mutableColliderOptions[key](collider, options[key]);
|
@@ -1148,8 +1157,11 @@ const AnyCollider = /*#__PURE__*/React.memo(props => {
|
|
1148
1157
|
});
|
1149
1158
|
};
|
1150
1159
|
}, []);
|
1151
|
-
|
1152
|
-
|
1160
|
+
const mergedProps = React.useMemo(() => {
|
1161
|
+
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1162
|
+
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1163
|
+
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
1164
|
+
useColliderEvents(collidersRef, mergedProps, colliderEvents);
|
1153
1165
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1154
1166
|
position: position,
|
1155
1167
|
rotation: rotation,
|
@@ -7,7 +7,6 @@ var React = require('react');
|
|
7
7
|
var useAsset = require('use-asset');
|
8
8
|
var fiber = require('@react-three/fiber');
|
9
9
|
var three = require('three');
|
10
|
-
var MathUtils = require('three/src/math/MathUtils');
|
11
10
|
var threeStdlib = require('three-stdlib');
|
12
11
|
|
13
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
@@ -277,9 +276,9 @@ const Physics = ({
|
|
277
276
|
/**
|
278
277
|
* Fixed timeStep simulation progression
|
279
278
|
* @see https://gafferongames.com/post/fix_your_timestep/
|
280
|
-
|
279
|
+
*/
|
281
280
|
|
282
|
-
const clampedDelta = MathUtils.clamp(dt, 0, 0.2);
|
281
|
+
const clampedDelta = three.MathUtils.clamp(dt, 0, 0.2);
|
283
282
|
|
284
283
|
if (timeStepVariable) {
|
285
284
|
world.timestep = clampedDelta;
|
@@ -781,12 +780,22 @@ const setColliderOptions = (collider, options, states) => {
|
|
781
780
|
|
782
781
|
_matrix4.copy(state.object.matrixWorld).premultiply(state.worldParent.matrixWorld.clone().invert()).decompose(_position, _rotation, _scale);
|
783
782
|
|
784
|
-
collider.
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
783
|
+
if (collider.parent()) {
|
784
|
+
collider.setTranslationWrtParent({
|
785
|
+
x: _position.x * parentWorldScale.x,
|
786
|
+
y: _position.y * parentWorldScale.y,
|
787
|
+
z: _position.z * parentWorldScale.z
|
788
|
+
});
|
789
|
+
collider.setRotationWrtParent(_rotation);
|
790
|
+
} else {
|
791
|
+
collider.setTranslation({
|
792
|
+
x: _position.x * parentWorldScale.x,
|
793
|
+
y: _position.y * parentWorldScale.y,
|
794
|
+
z: _position.z * parentWorldScale.z
|
795
|
+
});
|
796
|
+
collider.setRotation(_rotation);
|
797
|
+
}
|
798
|
+
|
790
799
|
mutableColliderOptionKeys.forEach(key => {
|
791
800
|
if (key in options) {
|
792
801
|
mutableColliderOptions[key](collider, options[key]);
|
@@ -1148,8 +1157,11 @@ const AnyCollider = /*#__PURE__*/React.memo(props => {
|
|
1148
1157
|
});
|
1149
1158
|
};
|
1150
1159
|
}, []);
|
1151
|
-
|
1152
|
-
|
1160
|
+
const mergedProps = React.useMemo(() => {
|
1161
|
+
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1162
|
+
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1163
|
+
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
1164
|
+
useColliderEvents(collidersRef, mergedProps, colliderEvents);
|
1153
1165
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1154
1166
|
position: position,
|
1155
1167
|
rotation: rotation,
|
@@ -3,8 +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, InstancedMesh, MeshBasicMaterial, Color, PlaneGeometry, ConeBufferGeometry, CapsuleBufferGeometry, CylinderBufferGeometry, BufferGeometry, BufferAttribute, SphereBufferGeometry, BoxBufferGeometry, DynamicDrawUsage } from 'three';
|
7
|
-
import { clamp } from 'three/src/math/MathUtils';
|
6
|
+
import { Quaternion, Euler, Vector3, Object3D, Matrix4, MathUtils, InstancedMesh, MeshBasicMaterial, Color, PlaneGeometry, ConeBufferGeometry, CapsuleBufferGeometry, CylinderBufferGeometry, BufferGeometry, BufferAttribute, SphereBufferGeometry, BoxBufferGeometry, DynamicDrawUsage } from 'three';
|
8
7
|
import { mergeVertices, RoundedBoxGeometry } from 'three-stdlib';
|
9
8
|
|
10
9
|
const _quaternion = new Quaternion();
|
@@ -252,9 +251,9 @@ const Physics = ({
|
|
252
251
|
/**
|
253
252
|
* Fixed timeStep simulation progression
|
254
253
|
* @see https://gafferongames.com/post/fix_your_timestep/
|
255
|
-
|
254
|
+
*/
|
256
255
|
|
257
|
-
const clampedDelta = clamp(dt, 0, 0.2);
|
256
|
+
const clampedDelta = MathUtils.clamp(dt, 0, 0.2);
|
258
257
|
|
259
258
|
if (timeStepVariable) {
|
260
259
|
world.timestep = clampedDelta;
|
@@ -756,12 +755,22 @@ const setColliderOptions = (collider, options, states) => {
|
|
756
755
|
|
757
756
|
_matrix4.copy(state.object.matrixWorld).premultiply(state.worldParent.matrixWorld.clone().invert()).decompose(_position, _rotation, _scale);
|
758
757
|
|
759
|
-
collider.
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
758
|
+
if (collider.parent()) {
|
759
|
+
collider.setTranslationWrtParent({
|
760
|
+
x: _position.x * parentWorldScale.x,
|
761
|
+
y: _position.y * parentWorldScale.y,
|
762
|
+
z: _position.z * parentWorldScale.z
|
763
|
+
});
|
764
|
+
collider.setRotationWrtParent(_rotation);
|
765
|
+
} else {
|
766
|
+
collider.setTranslation({
|
767
|
+
x: _position.x * parentWorldScale.x,
|
768
|
+
y: _position.y * parentWorldScale.y,
|
769
|
+
z: _position.z * parentWorldScale.z
|
770
|
+
});
|
771
|
+
collider.setRotation(_rotation);
|
772
|
+
}
|
773
|
+
|
765
774
|
mutableColliderOptionKeys.forEach(key => {
|
766
775
|
if (key in options) {
|
767
776
|
mutableColliderOptions[key](collider, options[key]);
|
@@ -1123,8 +1132,11 @@ const AnyCollider = /*#__PURE__*/memo(props => {
|
|
1123
1132
|
});
|
1124
1133
|
};
|
1125
1134
|
}, []);
|
1126
|
-
|
1127
|
-
|
1135
|
+
const mergedProps = useMemo(() => {
|
1136
|
+
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1137
|
+
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1138
|
+
useUpdateColliderOptions(collidersRef, mergedProps, colliderStates);
|
1139
|
+
useColliderEvents(collidersRef, mergedProps, colliderEvents);
|
1128
1140
|
return /*#__PURE__*/React.createElement("object3D", {
|
1129
1141
|
position: position,
|
1130
1142
|
rotation: rotation,
|
package/package.json
CHANGED
package/readme.md
CHANGED
@@ -141,7 +141,7 @@ const Scene = () => {
|
|
141
141
|
instancedApi.at(40).applyImpulse({ x: 0, y: 10, z: 0 });
|
142
142
|
|
143
143
|
// Or update all instances as if they were in an array
|
144
|
-
instancedApi.forEach(api => {
|
144
|
+
instancedApi.forEach((api) => {
|
145
145
|
api.applyImpulse({ x: 0, y: 10, z: 0 });
|
146
146
|
});
|
147
147
|
}, []);
|
@@ -239,10 +239,10 @@ You may also subscribe to collision events on individual Colliders:
|
|
239
239
|
|
240
240
|
```tsx
|
241
241
|
<CuboidCollider
|
242
|
-
onCollisionEnter={payload => {
|
242
|
+
onCollisionEnter={(payload) => {
|
243
243
|
/* ... */
|
244
244
|
}}
|
245
|
-
onCollisionExit={payload => {
|
245
|
+
onCollisionExit={(payload) => {
|
246
246
|
/* ... */
|
247
247
|
}}
|
248
248
|
/>
|