@react-three/rapier 1.3.1 → 1.4.0
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/Physics.d.ts +9 -0
- package/dist/declarations/src/types.d.ts +50 -8
- package/dist/declarations/src/utils/utils-collider.d.ts +2 -0
- package/dist/react-three-rapier.cjs.dev.js +16 -5
- package/dist/react-three-rapier.cjs.prod.js +16 -5
- package/dist/react-three-rapier.esm.js +16 -5
- package/package.json +2 -2
@@ -202,6 +202,15 @@ export interface PhysicsProps {
|
|
202
202
|
* @defaultValue 0.8
|
203
203
|
*/
|
204
204
|
erp?: number;
|
205
|
+
/**
|
206
|
+
* The approximate size of most dynamic objects in the scene.
|
207
|
+
*
|
208
|
+
* This value is used internally to estimate some length-based tolerance.
|
209
|
+
* This value can be understood as the number of units-per-meter in your physical world compared to a human-sized world in meter.
|
210
|
+
*
|
211
|
+
* @defaultValue 1
|
212
|
+
*/
|
213
|
+
lengthUnit?: number;
|
205
214
|
/**
|
206
215
|
* Set the base automatic colliders for this physics world
|
207
216
|
* All Meshes inside RigidBodies will generate a collider
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { MutableRefObject, RefObject } from "react";
|
2
|
-
import { CoefficientCombineRule, Collider as RapierCollider,
|
2
|
+
import { ActiveCollisionTypes, CoefficientCombineRule, ImpulseJoint, InteractionGroups, Collider as RapierCollider, RigidBody as RapierRigidBody, TempContactManifold } from "@dimforge/rapier3d-compat";
|
3
3
|
import { Rotation, Vector } from "@dimforge/rapier3d-compat/math";
|
4
|
-
import { Object3DProps,
|
4
|
+
import { Object3DProps, Quaternion, Vector3 } from "@react-three/fiber";
|
5
5
|
import { Object3D } from "three";
|
6
6
|
import { ColliderProps } from ".";
|
7
7
|
import { RigidBodyState } from "./components/Physics";
|
8
8
|
export { CoefficientCombineRule as CoefficientCombineRule } from "@dimforge/rapier3d-compat";
|
9
|
-
export {
|
9
|
+
export { RapierCollider, RapierRigidBody };
|
10
10
|
export declare type RefGetter<T> = MutableRefObject<() => T | undefined>;
|
11
11
|
export declare type RigidBodyAutoCollider = "ball" | "cuboid" | "hull" | "trimesh" | false;
|
12
12
|
export declare type CuboidArgs = [
|
@@ -139,7 +139,7 @@ export interface ColliderOptions<ColliderArgs extends Array<unknown>> {
|
|
139
139
|
*/
|
140
140
|
scale?: Object3DProps["scale"];
|
141
141
|
/**
|
142
|
-
* Callback when this collider
|
142
|
+
* Callback when this collider collideas with another collider.
|
143
143
|
*/
|
144
144
|
onCollisionEnter?: CollisionEnterHandler;
|
145
145
|
/**
|
@@ -166,6 +166,15 @@ export interface ColliderOptions<ColliderArgs extends Array<unknown>> {
|
|
166
166
|
* The bit mask configuring the groups and mask for solver handling.
|
167
167
|
*/
|
168
168
|
solverGroups?: InteractionGroups;
|
169
|
+
/**
|
170
|
+
* The collision types active for this collider.
|
171
|
+
*
|
172
|
+
* Use `ActiveCollisionTypes` to specify which collision types should be active for this collider.
|
173
|
+
*
|
174
|
+
* @see https://rapier.rs/javascript3d/classes/Collider.html#setActiveCollisionTypes
|
175
|
+
* @see https://rapier.rs/javascript3d/enums/ActiveCollisionTypes.html
|
176
|
+
*/
|
177
|
+
activeCollisionTypes?: ActiveCollisionTypes;
|
169
178
|
/**
|
170
179
|
* Sets the uniform density of this collider.
|
171
180
|
* If this is set, other mass-properties like the angular inertia tensor are computed
|
@@ -192,6 +201,18 @@ export interface ColliderOptions<ColliderArgs extends Array<unknown>> {
|
|
192
201
|
principalAngularInertia: Vector;
|
193
202
|
angularInertiaLocalFrame: Rotation;
|
194
203
|
};
|
204
|
+
/**
|
205
|
+
* The contact skin of the collider.
|
206
|
+
*
|
207
|
+
* The contact skin acts as if the collider was enlarged with a skin of width contactSkin around it, keeping objects further apart when colliding.
|
208
|
+
*
|
209
|
+
* A non-zero contact skin can increase performance, and in some cases, stability.
|
210
|
+
* However it creates a small gap between colliding object (equal to the sum of their skin).
|
211
|
+
* If the skin is sufficiently small, this might not be visually significant or can be hidden by the rendering assets.
|
212
|
+
*
|
213
|
+
* @defaultValue 0
|
214
|
+
*/
|
215
|
+
contactSkin?: number;
|
195
216
|
/**
|
196
217
|
* Sets whether or not this collider is a sensor.
|
197
218
|
*/
|
@@ -277,6 +298,20 @@ export interface RigidBodyOptions extends ColliderProps {
|
|
277
298
|
* @defaultValue false
|
278
299
|
*/
|
279
300
|
ccd?: boolean;
|
301
|
+
/**
|
302
|
+
* The maximum prediction distance Soft Continuous Collision-Detection.
|
303
|
+
*
|
304
|
+
* When set to 0, soft-CCD is disabled.
|
305
|
+
*
|
306
|
+
* Soft-CCD helps prevent tunneling especially of slow-but-thin to moderately fast objects.
|
307
|
+
* The soft CCD prediction distance indicates how far in the object’s path the CCD algorithm is allowed to inspect.
|
308
|
+
* Large values can impact performance badly by increasing the work needed from the broad-phase.
|
309
|
+
*
|
310
|
+
* It is a generally cheaper variant of regular CCD since it relies on predictive constraints instead of shape-cast and substeps.
|
311
|
+
*
|
312
|
+
* @defaultValue 0
|
313
|
+
*/
|
314
|
+
softCcdPrediction?: number;
|
280
315
|
/**
|
281
316
|
* Initial position of the RigidBody
|
282
317
|
*/
|
@@ -325,6 +360,16 @@ export interface RigidBodyOptions extends ColliderProps {
|
|
325
360
|
* Can be customized per-collider.
|
326
361
|
*/
|
327
362
|
solverGroups?: InteractionGroups;
|
363
|
+
/**
|
364
|
+
* The default active collision types for all colliders in this rigid body.
|
365
|
+
* Can be customized per-collider.
|
366
|
+
*
|
367
|
+
* Use `ActiveCollisionTypes` to specify which collision types should be active for this collider.
|
368
|
+
*
|
369
|
+
* @see https://rapier.rs/javascript3d/classes/Collider.html#setActiveCollisionTypes
|
370
|
+
* @see https://rapier.rs/javascript3d/enums/ActiveCollisionTypes.html
|
371
|
+
*/
|
372
|
+
activeCollisionTypes?: ActiveCollisionTypes;
|
328
373
|
onSleep?(): void;
|
329
374
|
onWake?(): void;
|
330
375
|
/**
|
@@ -357,10 +402,7 @@ export interface RigidBodyOptions extends ColliderProps {
|
|
357
402
|
*/
|
358
403
|
transformState?: (state: RigidBodyState) => RigidBodyState;
|
359
404
|
}
|
360
|
-
export declare type SphericalJointParams = [
|
361
|
-
body1Anchor: Vector3,
|
362
|
-
body2Anchor: Vector3
|
363
|
-
];
|
405
|
+
export declare type SphericalJointParams = [body1Anchor: Vector3, body2Anchor: Vector3];
|
364
406
|
export declare type FixedJointParams = [
|
365
407
|
body1Anchor: Vector3,
|
366
408
|
body1LocalFrame: Quaternion,
|
@@ -50,6 +50,7 @@ export declare const cleanRigidBodyPropsForCollider: (props?: RigidBodyProps) =>
|
|
50
50
|
additionalSolverIterations?: number | undefined;
|
51
51
|
collisionGroups?: number | undefined;
|
52
52
|
solverGroups?: number | undefined;
|
53
|
+
activeCollisionTypes?: import("@dimforge/rapier3d-compat").ActiveCollisionTypes | undefined;
|
53
54
|
onSleep?(): void;
|
54
55
|
onWake?(): void;
|
55
56
|
lockRotations?: boolean | undefined;
|
@@ -76,6 +77,7 @@ export declare const cleanRigidBodyPropsForCollider: (props?: RigidBodyProps) =>
|
|
76
77
|
principalAngularInertia: import("@dimforge/rapier3d-compat").Vector;
|
77
78
|
angularInertiaLocalFrame: import("@dimforge/rapier3d-compat").Rotation;
|
78
79
|
} | undefined;
|
80
|
+
contactSkin?: number | undefined;
|
79
81
|
sensor?: boolean | undefined;
|
80
82
|
};
|
81
83
|
export {};
|
@@ -244,7 +244,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
244
244
|
return target;
|
245
245
|
}
|
246
246
|
|
247
|
-
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
247
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
|
248
248
|
const scaleColliderArgs = (shape, args, scale) => {
|
249
249
|
const newArgs = args.slice(); // Heightfield uses a vector
|
250
250
|
|
@@ -321,6 +321,12 @@ const mutableColliderOptions = {
|
|
321
321
|
restitutionCombineRule: (collider, value) => {
|
322
322
|
collider.setRestitutionCombineRule(value);
|
323
323
|
},
|
324
|
+
activeCollisionTypes: (collider, value) => {
|
325
|
+
collider.setActiveCollisionTypes(value);
|
326
|
+
},
|
327
|
+
contactSkin: (collider, value) => {
|
328
|
+
collider.setContactSkin(value);
|
329
|
+
},
|
324
330
|
// To make sure the options all mutable options are listed
|
325
331
|
quaternion: () => {},
|
326
332
|
position: () => {},
|
@@ -762,7 +768,8 @@ const Physics = props => {
|
|
762
768
|
numInternalPgsIterations = 1,
|
763
769
|
minIslandSize = 128,
|
764
770
|
maxCcdSubsteps = 1,
|
765
|
-
erp = 0.8
|
771
|
+
erp = 0.8,
|
772
|
+
lengthUnit = 1
|
766
773
|
} = props;
|
767
774
|
const rapier = suspendReact.suspend(importRapier, ["@react-thee/rapier", importRapier]);
|
768
775
|
const {
|
@@ -798,12 +805,13 @@ const Physics = props => {
|
|
798
805
|
worldProxy.integrationParameters.numSolverIterations = numSolverIterations;
|
799
806
|
worldProxy.integrationParameters.numAdditionalFrictionIterations = numAdditionalFrictionIterations;
|
800
807
|
worldProxy.integrationParameters.numInternalPgsIterations = numInternalPgsIterations;
|
801
|
-
worldProxy.integrationParameters.
|
808
|
+
worldProxy.integrationParameters.normalizedAllowedLinearError = allowedLinearError;
|
802
809
|
worldProxy.integrationParameters.minIslandSize = minIslandSize;
|
803
810
|
worldProxy.integrationParameters.maxCcdSubsteps = maxCcdSubsteps;
|
804
|
-
worldProxy.integrationParameters.
|
811
|
+
worldProxy.integrationParameters.normalizedPredictionDistance = predictionDistance;
|
805
812
|
worldProxy.integrationParameters.erp = erp;
|
806
|
-
|
813
|
+
worldProxy.lengthUnit = lengthUnit;
|
814
|
+
}, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, erp, lengthUnit]);
|
807
815
|
const getSourceFromColliderHandle = React.useCallback(handle => {
|
808
816
|
var _collider$parent;
|
809
817
|
|
@@ -1435,6 +1443,9 @@ const mutableRigidBodyOptions = {
|
|
1435
1443
|
ccd: (rb, value) => {
|
1436
1444
|
rb.enableCcd(value);
|
1437
1445
|
},
|
1446
|
+
softCcdPrediction: (rb, value) => {
|
1447
|
+
rb.setSoftCcdPrediction(value);
|
1448
|
+
},
|
1438
1449
|
userData: (rb, value) => {
|
1439
1450
|
rb.userData = value;
|
1440
1451
|
},
|
@@ -244,7 +244,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
244
244
|
return target;
|
245
245
|
}
|
246
246
|
|
247
|
-
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
247
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
|
248
248
|
const scaleColliderArgs = (shape, args, scale) => {
|
249
249
|
const newArgs = args.slice(); // Heightfield uses a vector
|
250
250
|
|
@@ -321,6 +321,12 @@ const mutableColliderOptions = {
|
|
321
321
|
restitutionCombineRule: (collider, value) => {
|
322
322
|
collider.setRestitutionCombineRule(value);
|
323
323
|
},
|
324
|
+
activeCollisionTypes: (collider, value) => {
|
325
|
+
collider.setActiveCollisionTypes(value);
|
326
|
+
},
|
327
|
+
contactSkin: (collider, value) => {
|
328
|
+
collider.setContactSkin(value);
|
329
|
+
},
|
324
330
|
// To make sure the options all mutable options are listed
|
325
331
|
quaternion: () => {},
|
326
332
|
position: () => {},
|
@@ -762,7 +768,8 @@ const Physics = props => {
|
|
762
768
|
numInternalPgsIterations = 1,
|
763
769
|
minIslandSize = 128,
|
764
770
|
maxCcdSubsteps = 1,
|
765
|
-
erp = 0.8
|
771
|
+
erp = 0.8,
|
772
|
+
lengthUnit = 1
|
766
773
|
} = props;
|
767
774
|
const rapier = suspendReact.suspend(importRapier, ["@react-thee/rapier", importRapier]);
|
768
775
|
const {
|
@@ -798,12 +805,13 @@ const Physics = props => {
|
|
798
805
|
worldProxy.integrationParameters.numSolverIterations = numSolverIterations;
|
799
806
|
worldProxy.integrationParameters.numAdditionalFrictionIterations = numAdditionalFrictionIterations;
|
800
807
|
worldProxy.integrationParameters.numInternalPgsIterations = numInternalPgsIterations;
|
801
|
-
worldProxy.integrationParameters.
|
808
|
+
worldProxy.integrationParameters.normalizedAllowedLinearError = allowedLinearError;
|
802
809
|
worldProxy.integrationParameters.minIslandSize = minIslandSize;
|
803
810
|
worldProxy.integrationParameters.maxCcdSubsteps = maxCcdSubsteps;
|
804
|
-
worldProxy.integrationParameters.
|
811
|
+
worldProxy.integrationParameters.normalizedPredictionDistance = predictionDistance;
|
805
812
|
worldProxy.integrationParameters.erp = erp;
|
806
|
-
|
813
|
+
worldProxy.lengthUnit = lengthUnit;
|
814
|
+
}, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, erp, lengthUnit]);
|
807
815
|
const getSourceFromColliderHandle = React.useCallback(handle => {
|
808
816
|
var _collider$parent;
|
809
817
|
|
@@ -1435,6 +1443,9 @@ const mutableRigidBodyOptions = {
|
|
1435
1443
|
ccd: (rb, value) => {
|
1436
1444
|
rb.enableCcd(value);
|
1437
1445
|
},
|
1446
|
+
softCcdPrediction: (rb, value) => {
|
1447
|
+
rb.setSoftCcdPrediction(value);
|
1448
|
+
},
|
1438
1449
|
userData: (rb, value) => {
|
1439
1450
|
rb.userData = value;
|
1440
1451
|
},
|
@@ -219,7 +219,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
219
219
|
return target;
|
220
220
|
}
|
221
221
|
|
222
|
-
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
222
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale", "softCcdPrediction"];
|
223
223
|
const scaleColliderArgs = (shape, args, scale) => {
|
224
224
|
const newArgs = args.slice(); // Heightfield uses a vector
|
225
225
|
|
@@ -296,6 +296,12 @@ const mutableColliderOptions = {
|
|
296
296
|
restitutionCombineRule: (collider, value) => {
|
297
297
|
collider.setRestitutionCombineRule(value);
|
298
298
|
},
|
299
|
+
activeCollisionTypes: (collider, value) => {
|
300
|
+
collider.setActiveCollisionTypes(value);
|
301
|
+
},
|
302
|
+
contactSkin: (collider, value) => {
|
303
|
+
collider.setContactSkin(value);
|
304
|
+
},
|
299
305
|
// To make sure the options all mutable options are listed
|
300
306
|
quaternion: () => {},
|
301
307
|
position: () => {},
|
@@ -737,7 +743,8 @@ const Physics = props => {
|
|
737
743
|
numInternalPgsIterations = 1,
|
738
744
|
minIslandSize = 128,
|
739
745
|
maxCcdSubsteps = 1,
|
740
|
-
erp = 0.8
|
746
|
+
erp = 0.8,
|
747
|
+
lengthUnit = 1
|
741
748
|
} = props;
|
742
749
|
const rapier = suspend(importRapier, ["@react-thee/rapier", importRapier]);
|
743
750
|
const {
|
@@ -773,12 +780,13 @@ const Physics = props => {
|
|
773
780
|
worldProxy.integrationParameters.numSolverIterations = numSolverIterations;
|
774
781
|
worldProxy.integrationParameters.numAdditionalFrictionIterations = numAdditionalFrictionIterations;
|
775
782
|
worldProxy.integrationParameters.numInternalPgsIterations = numInternalPgsIterations;
|
776
|
-
worldProxy.integrationParameters.
|
783
|
+
worldProxy.integrationParameters.normalizedAllowedLinearError = allowedLinearError;
|
777
784
|
worldProxy.integrationParameters.minIslandSize = minIslandSize;
|
778
785
|
worldProxy.integrationParameters.maxCcdSubsteps = maxCcdSubsteps;
|
779
|
-
worldProxy.integrationParameters.
|
786
|
+
worldProxy.integrationParameters.normalizedPredictionDistance = predictionDistance;
|
780
787
|
worldProxy.integrationParameters.erp = erp;
|
781
|
-
|
788
|
+
worldProxy.lengthUnit = lengthUnit;
|
789
|
+
}, [worldProxy, ...gravity, numSolverIterations, numAdditionalFrictionIterations, numInternalPgsIterations, allowedLinearError, minIslandSize, maxCcdSubsteps, predictionDistance, erp, lengthUnit]);
|
782
790
|
const getSourceFromColliderHandle = useCallback(handle => {
|
783
791
|
var _collider$parent;
|
784
792
|
|
@@ -1410,6 +1418,9 @@ const mutableRigidBodyOptions = {
|
|
1410
1418
|
ccd: (rb, value) => {
|
1411
1419
|
rb.enableCcd(value);
|
1412
1420
|
},
|
1421
|
+
softCcdPrediction: (rb, value) => {
|
1422
|
+
rb.setSoftCcdPrediction(value);
|
1423
|
+
},
|
1413
1424
|
userData: (rb, value) => {
|
1414
1425
|
rb.userData = value;
|
1415
1426
|
},
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-three/rapier",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.0",
|
4
4
|
"source": "src/index.ts",
|
5
5
|
"main": "dist/react-three-rapier.cjs.js",
|
6
6
|
"module": "dist/react-three-rapier.esm.js",
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"three": ">=0.139.0"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@dimforge/rapier3d-compat": "0.
|
32
|
+
"@dimforge/rapier3d-compat": "0.13.1",
|
33
33
|
"suspend-react": "^0.1.3",
|
34
34
|
"three-stdlib": "2.23.9"
|
35
35
|
},
|