@react-three/rapier 0.14.0-rc.0 → 0.14.0-rc.1
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.
@@ -31,5 +31,51 @@ export declare const getColliderArgsFromGeometry: (geometry: BufferGeometry, col
|
|
31
31
|
args: unknown[];
|
32
32
|
offset: Vector3;
|
33
33
|
};
|
34
|
-
export declare const
|
34
|
+
export declare const getActiveCollisionEventsFromProps: (props?: ColliderProps) => {
|
35
|
+
collision: boolean;
|
36
|
+
contactForce: boolean;
|
37
|
+
};
|
38
|
+
export declare const useColliderEvents: (getCollider: () => Collider, props: ColliderProps, events: EventMap, activeEvents?: {
|
39
|
+
collision?: boolean;
|
40
|
+
contactForce?: boolean;
|
41
|
+
}) => void;
|
42
|
+
export declare const cleanRigidBodyPropsForCollider: (props?: RigidBodyProps) => {
|
43
|
+
linearVelocity?: import("..").Vector3Array | undefined;
|
44
|
+
angularVelocity?: import("..").Vector3Array | undefined;
|
45
|
+
dominanceGroup?: number | undefined;
|
46
|
+
position?: import("@react-three/fiber").Vector3 | undefined;
|
47
|
+
rotation?: import("@react-three/fiber").Euler | undefined;
|
48
|
+
colliders?: RigidBodyAutoCollider | undefined;
|
49
|
+
friction?: number | undefined;
|
50
|
+
restitution?: number | undefined;
|
51
|
+
collisionGroups?: number | undefined;
|
52
|
+
solverGroups?: number | undefined;
|
53
|
+
onSleep?(): void;
|
54
|
+
onWake?(): void;
|
55
|
+
lockRotations?: boolean | undefined;
|
56
|
+
lockTranslations?: boolean | undefined;
|
57
|
+
enabledRotations?: import("..").Boolean3Array | undefined;
|
58
|
+
enabledTranslations?: import("..").Boolean3Array | undefined;
|
59
|
+
userData?: {
|
60
|
+
[key: string]: any;
|
61
|
+
} | undefined;
|
62
|
+
includeInvisible?: boolean | undefined;
|
63
|
+
transformState?: ((state: import("../components/Physics").RigidBodyState) => import("../components/Physics").RigidBodyState) | undefined;
|
64
|
+
name?: string | undefined;
|
65
|
+
shape?: ColliderShape | undefined;
|
66
|
+
args?: any;
|
67
|
+
principalAngularInertia?: import("..").Vector3Array | undefined;
|
68
|
+
restitutionCombineRule?: import("@dimforge/rapier3d-compat").CoefficientCombineRule | undefined;
|
69
|
+
frictionCombineRule?: import("@dimforge/rapier3d-compat").CoefficientCombineRule | undefined;
|
70
|
+
quaternion?: import("@react-three/fiber").Quaternion | undefined;
|
71
|
+
scale?: import("@react-three/fiber").Vector3 | undefined;
|
72
|
+
density?: number | undefined;
|
73
|
+
massProperties?: {
|
74
|
+
mass: number;
|
75
|
+
centerOfMass: import("@dimforge/rapier3d-compat").Vector;
|
76
|
+
principalAngularInertia: import("@dimforge/rapier3d-compat").Vector;
|
77
|
+
angularInertiaLocalFrame: import("@dimforge/rapier3d-compat").Rotation;
|
78
|
+
} | undefined;
|
79
|
+
sensor?: boolean | undefined;
|
80
|
+
};
|
35
81
|
export {};
|
@@ -199,6 +199,41 @@ const useRaf = callback => {
|
|
199
199
|
}, []);
|
200
200
|
};
|
201
201
|
|
202
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
203
|
+
if (source == null) return {};
|
204
|
+
var target = {};
|
205
|
+
var sourceKeys = Object.keys(source);
|
206
|
+
var key, i;
|
207
|
+
|
208
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
209
|
+
key = sourceKeys[i];
|
210
|
+
if (excluded.indexOf(key) >= 0) continue;
|
211
|
+
target[key] = source[key];
|
212
|
+
}
|
213
|
+
|
214
|
+
return target;
|
215
|
+
}
|
216
|
+
|
217
|
+
function _objectWithoutProperties(source, excluded) {
|
218
|
+
if (source == null) return {};
|
219
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
220
|
+
var key, i;
|
221
|
+
|
222
|
+
if (Object.getOwnPropertySymbols) {
|
223
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
224
|
+
|
225
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
226
|
+
key = sourceSymbolKeys[i];
|
227
|
+
if (excluded.indexOf(key) >= 0) continue;
|
228
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
229
|
+
target[key] = source[key];
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
return target;
|
234
|
+
}
|
235
|
+
|
236
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
202
237
|
const scaleColliderArgs = (shape, args, scale) => {
|
203
238
|
const newArgs = args.slice(); // Heightfield uses a vector
|
204
239
|
|
@@ -365,7 +400,7 @@ const createColliderPropsFromChildren = ({
|
|
365
400
|
ignoreMeshColliders: _ignoreMeshColliders = true,
|
366
401
|
options
|
367
402
|
}) => {
|
368
|
-
const
|
403
|
+
const childColliderProps = [];
|
369
404
|
object.updateWorldMatrix(true, false);
|
370
405
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
371
406
|
|
@@ -386,13 +421,16 @@ const createColliderPropsFromChildren = ({
|
|
386
421
|
args,
|
387
422
|
offset
|
388
423
|
} = getColliderArgsFromGeometry(geometry, options.colliders || "cuboid");
|
389
|
-
|
424
|
+
|
425
|
+
const colliderProps = _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(options)), {}, {
|
390
426
|
args: args,
|
391
427
|
shape: shape,
|
392
428
|
rotation: [rotationEuler.x, rotationEuler.y, rotationEuler.z],
|
393
429
|
position: [_position.x + offset.x * worldScale.x, _position.y + offset.y * worldScale.y, _position.z + offset.z * worldScale.z],
|
394
430
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
395
|
-
})
|
431
|
+
});
|
432
|
+
|
433
|
+
childColliderProps.push(colliderProps);
|
396
434
|
}
|
397
435
|
};
|
398
436
|
|
@@ -402,7 +440,7 @@ const createColliderPropsFromChildren = ({
|
|
402
440
|
object.traverseVisible(colliderFromChild);
|
403
441
|
}
|
404
442
|
|
405
|
-
return
|
443
|
+
return childColliderProps;
|
406
444
|
};
|
407
445
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
408
446
|
switch (colliders) {
|
@@ -458,7 +496,17 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
458
496
|
offset: new three.Vector3()
|
459
497
|
};
|
460
498
|
};
|
461
|
-
const
|
499
|
+
const getActiveCollisionEventsFromProps = props => {
|
500
|
+
return {
|
501
|
+
collision: !!(props !== null && props !== void 0 && props.onCollisionEnter || props !== null && props !== void 0 && props.onCollisionExit || props !== null && props !== void 0 && props.onIntersectionEnter || props !== null && props !== void 0 && props.onIntersectionExit),
|
502
|
+
contactForce: !!(props !== null && props !== void 0 && props.onContactForce)
|
503
|
+
};
|
504
|
+
};
|
505
|
+
const useColliderEvents = (getCollider, props, events,
|
506
|
+
/**
|
507
|
+
* The RigidBody can pass down active events to the collider without attaching the event listners
|
508
|
+
*/
|
509
|
+
activeEvents = {}) => {
|
462
510
|
const {
|
463
511
|
onCollisionEnter,
|
464
512
|
onCollisionExit,
|
@@ -470,8 +518,12 @@ const useColliderEvents = (getCollider, props, events) => {
|
|
470
518
|
const collider = getCollider();
|
471
519
|
|
472
520
|
if (collider) {
|
473
|
-
const
|
474
|
-
|
521
|
+
const {
|
522
|
+
collision: collisionEventsActive,
|
523
|
+
contactForce: contactForceEventsActive
|
524
|
+
} = getActiveCollisionEventsFromProps(props);
|
525
|
+
const hasCollisionEvent = collisionEventsActive || activeEvents.collision;
|
526
|
+
const hasContactForceEvent = contactForceEventsActive || activeEvents.contactForce;
|
475
527
|
|
476
528
|
if (hasCollisionEvent && hasContactForceEvent) {
|
477
529
|
collider.setActiveEvents(rapier3dCompat.ActiveEvents.COLLISION_EVENTS | rapier3dCompat.ActiveEvents.CONTACT_FORCE_EVENTS);
|
@@ -495,7 +547,12 @@ const useColliderEvents = (getCollider, props, events) => {
|
|
495
547
|
events.delete(collider.handle);
|
496
548
|
}
|
497
549
|
};
|
498
|
-
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
550
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce, activeEvents]);
|
551
|
+
};
|
552
|
+
const cleanRigidBodyPropsForCollider = (props = {}) => {
|
553
|
+
const rest = _objectWithoutProperties(props, _excluded$2);
|
554
|
+
|
555
|
+
return rest;
|
499
556
|
};
|
500
557
|
|
501
558
|
const useMutableCallback = fn => {
|
@@ -1028,40 +1085,6 @@ function _extends() {
|
|
1028
1085
|
return _extends.apply(this, arguments);
|
1029
1086
|
}
|
1030
1087
|
|
1031
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
1032
|
-
if (source == null) return {};
|
1033
|
-
var target = {};
|
1034
|
-
var sourceKeys = Object.keys(source);
|
1035
|
-
var key, i;
|
1036
|
-
|
1037
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
1038
|
-
key = sourceKeys[i];
|
1039
|
-
if (excluded.indexOf(key) >= 0) continue;
|
1040
|
-
target[key] = source[key];
|
1041
|
-
}
|
1042
|
-
|
1043
|
-
return target;
|
1044
|
-
}
|
1045
|
-
|
1046
|
-
function _objectWithoutProperties(source, excluded) {
|
1047
|
-
if (source == null) return {};
|
1048
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
1049
|
-
var key, i;
|
1050
|
-
|
1051
|
-
if (Object.getOwnPropertySymbols) {
|
1052
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
1053
|
-
|
1054
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
1055
|
-
key = sourceSymbolKeys[i];
|
1056
|
-
if (excluded.indexOf(key) >= 0) continue;
|
1057
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
1058
|
-
target[key] = source[key];
|
1059
|
-
}
|
1060
|
-
}
|
1061
|
-
|
1062
|
-
return target;
|
1063
|
-
}
|
1064
|
-
|
1065
1088
|
/**
|
1066
1089
|
* Initiate an instance and return a safe getter
|
1067
1090
|
*/
|
@@ -1174,10 +1197,10 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
|
|
1174
1197
|
}, []);
|
1175
1198
|
React.useImperativeHandle(forwardedRef, () => getInstance());
|
1176
1199
|
const mergedProps = React.useMemo(() => {
|
1177
|
-
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1200
|
+
return _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options)), props);
|
1178
1201
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1179
1202
|
useUpdateColliderOptions(getInstance, mergedProps, colliderStates);
|
1180
|
-
useColliderEvents(getInstance, mergedProps, colliderEvents);
|
1203
|
+
useColliderEvents(getInstance, mergedProps, colliderEvents, getActiveCollisionEventsFromProps(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options));
|
1181
1204
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1182
1205
|
position: position,
|
1183
1206
|
rotation: rotation,
|
@@ -1425,7 +1448,8 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1425
1448
|
onCollisionEnter,
|
1426
1449
|
onCollisionExit,
|
1427
1450
|
onIntersectionEnter,
|
1428
|
-
onIntersectionExit
|
1451
|
+
onIntersectionExit,
|
1452
|
+
onContactForce
|
1429
1453
|
} = props;
|
1430
1454
|
const eventHandlers = {
|
1431
1455
|
onWake,
|
@@ -1433,7 +1457,8 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1433
1457
|
onCollisionEnter,
|
1434
1458
|
onCollisionExit,
|
1435
1459
|
onIntersectionEnter,
|
1436
|
-
onIntersectionExit
|
1460
|
+
onIntersectionExit,
|
1461
|
+
onContactForce
|
1437
1462
|
};
|
1438
1463
|
React.useEffect(() => {
|
1439
1464
|
const rigidBody = getRigidBody();
|
@@ -1441,7 +1466,7 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1441
1466
|
return () => {
|
1442
1467
|
events.delete(rigidBody.handle);
|
1443
1468
|
};
|
1444
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
1469
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1445
1470
|
};
|
1446
1471
|
|
1447
1472
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
@@ -199,6 +199,41 @@ const useRaf = callback => {
|
|
199
199
|
}, []);
|
200
200
|
};
|
201
201
|
|
202
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
203
|
+
if (source == null) return {};
|
204
|
+
var target = {};
|
205
|
+
var sourceKeys = Object.keys(source);
|
206
|
+
var key, i;
|
207
|
+
|
208
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
209
|
+
key = sourceKeys[i];
|
210
|
+
if (excluded.indexOf(key) >= 0) continue;
|
211
|
+
target[key] = source[key];
|
212
|
+
}
|
213
|
+
|
214
|
+
return target;
|
215
|
+
}
|
216
|
+
|
217
|
+
function _objectWithoutProperties(source, excluded) {
|
218
|
+
if (source == null) return {};
|
219
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
220
|
+
var key, i;
|
221
|
+
|
222
|
+
if (Object.getOwnPropertySymbols) {
|
223
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
224
|
+
|
225
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
226
|
+
key = sourceSymbolKeys[i];
|
227
|
+
if (excluded.indexOf(key) >= 0) continue;
|
228
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
229
|
+
target[key] = source[key];
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
return target;
|
234
|
+
}
|
235
|
+
|
236
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
202
237
|
const scaleColliderArgs = (shape, args, scale) => {
|
203
238
|
const newArgs = args.slice(); // Heightfield uses a vector
|
204
239
|
|
@@ -365,7 +400,7 @@ const createColliderPropsFromChildren = ({
|
|
365
400
|
ignoreMeshColliders: _ignoreMeshColliders = true,
|
366
401
|
options
|
367
402
|
}) => {
|
368
|
-
const
|
403
|
+
const childColliderProps = [];
|
369
404
|
object.updateWorldMatrix(true, false);
|
370
405
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
371
406
|
|
@@ -386,13 +421,16 @@ const createColliderPropsFromChildren = ({
|
|
386
421
|
args,
|
387
422
|
offset
|
388
423
|
} = getColliderArgsFromGeometry(geometry, options.colliders || "cuboid");
|
389
|
-
|
424
|
+
|
425
|
+
const colliderProps = _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(options)), {}, {
|
390
426
|
args: args,
|
391
427
|
shape: shape,
|
392
428
|
rotation: [rotationEuler.x, rotationEuler.y, rotationEuler.z],
|
393
429
|
position: [_position.x + offset.x * worldScale.x, _position.y + offset.y * worldScale.y, _position.z + offset.z * worldScale.z],
|
394
430
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
395
|
-
})
|
431
|
+
});
|
432
|
+
|
433
|
+
childColliderProps.push(colliderProps);
|
396
434
|
}
|
397
435
|
};
|
398
436
|
|
@@ -402,7 +440,7 @@ const createColliderPropsFromChildren = ({
|
|
402
440
|
object.traverseVisible(colliderFromChild);
|
403
441
|
}
|
404
442
|
|
405
|
-
return
|
443
|
+
return childColliderProps;
|
406
444
|
};
|
407
445
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
408
446
|
switch (colliders) {
|
@@ -458,7 +496,17 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
458
496
|
offset: new three.Vector3()
|
459
497
|
};
|
460
498
|
};
|
461
|
-
const
|
499
|
+
const getActiveCollisionEventsFromProps = props => {
|
500
|
+
return {
|
501
|
+
collision: !!(props !== null && props !== void 0 && props.onCollisionEnter || props !== null && props !== void 0 && props.onCollisionExit || props !== null && props !== void 0 && props.onIntersectionEnter || props !== null && props !== void 0 && props.onIntersectionExit),
|
502
|
+
contactForce: !!(props !== null && props !== void 0 && props.onContactForce)
|
503
|
+
};
|
504
|
+
};
|
505
|
+
const useColliderEvents = (getCollider, props, events,
|
506
|
+
/**
|
507
|
+
* The RigidBody can pass down active events to the collider without attaching the event listners
|
508
|
+
*/
|
509
|
+
activeEvents = {}) => {
|
462
510
|
const {
|
463
511
|
onCollisionEnter,
|
464
512
|
onCollisionExit,
|
@@ -470,8 +518,12 @@ const useColliderEvents = (getCollider, props, events) => {
|
|
470
518
|
const collider = getCollider();
|
471
519
|
|
472
520
|
if (collider) {
|
473
|
-
const
|
474
|
-
|
521
|
+
const {
|
522
|
+
collision: collisionEventsActive,
|
523
|
+
contactForce: contactForceEventsActive
|
524
|
+
} = getActiveCollisionEventsFromProps(props);
|
525
|
+
const hasCollisionEvent = collisionEventsActive || activeEvents.collision;
|
526
|
+
const hasContactForceEvent = contactForceEventsActive || activeEvents.contactForce;
|
475
527
|
|
476
528
|
if (hasCollisionEvent && hasContactForceEvent) {
|
477
529
|
collider.setActiveEvents(rapier3dCompat.ActiveEvents.COLLISION_EVENTS | rapier3dCompat.ActiveEvents.CONTACT_FORCE_EVENTS);
|
@@ -495,7 +547,12 @@ const useColliderEvents = (getCollider, props, events) => {
|
|
495
547
|
events.delete(collider.handle);
|
496
548
|
}
|
497
549
|
};
|
498
|
-
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
550
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce, activeEvents]);
|
551
|
+
};
|
552
|
+
const cleanRigidBodyPropsForCollider = (props = {}) => {
|
553
|
+
const rest = _objectWithoutProperties(props, _excluded$2);
|
554
|
+
|
555
|
+
return rest;
|
499
556
|
};
|
500
557
|
|
501
558
|
const useMutableCallback = fn => {
|
@@ -1028,40 +1085,6 @@ function _extends() {
|
|
1028
1085
|
return _extends.apply(this, arguments);
|
1029
1086
|
}
|
1030
1087
|
|
1031
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
1032
|
-
if (source == null) return {};
|
1033
|
-
var target = {};
|
1034
|
-
var sourceKeys = Object.keys(source);
|
1035
|
-
var key, i;
|
1036
|
-
|
1037
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
1038
|
-
key = sourceKeys[i];
|
1039
|
-
if (excluded.indexOf(key) >= 0) continue;
|
1040
|
-
target[key] = source[key];
|
1041
|
-
}
|
1042
|
-
|
1043
|
-
return target;
|
1044
|
-
}
|
1045
|
-
|
1046
|
-
function _objectWithoutProperties(source, excluded) {
|
1047
|
-
if (source == null) return {};
|
1048
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
1049
|
-
var key, i;
|
1050
|
-
|
1051
|
-
if (Object.getOwnPropertySymbols) {
|
1052
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
1053
|
-
|
1054
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
1055
|
-
key = sourceSymbolKeys[i];
|
1056
|
-
if (excluded.indexOf(key) >= 0) continue;
|
1057
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
1058
|
-
target[key] = source[key];
|
1059
|
-
}
|
1060
|
-
}
|
1061
|
-
|
1062
|
-
return target;
|
1063
|
-
}
|
1064
|
-
|
1065
1088
|
/**
|
1066
1089
|
* Initiate an instance and return a safe getter
|
1067
1090
|
*/
|
@@ -1174,10 +1197,10 @@ const AnyCollider = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((prop
|
|
1174
1197
|
}, []);
|
1175
1198
|
React.useImperativeHandle(forwardedRef, () => getInstance());
|
1176
1199
|
const mergedProps = React.useMemo(() => {
|
1177
|
-
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1200
|
+
return _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options)), props);
|
1178
1201
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1179
1202
|
useUpdateColliderOptions(getInstance, mergedProps, colliderStates);
|
1180
|
-
useColliderEvents(getInstance, mergedProps, colliderEvents);
|
1203
|
+
useColliderEvents(getInstance, mergedProps, colliderEvents, getActiveCollisionEventsFromProps(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options));
|
1181
1204
|
return /*#__PURE__*/React__default["default"].createElement("object3D", {
|
1182
1205
|
position: position,
|
1183
1206
|
rotation: rotation,
|
@@ -1425,7 +1448,8 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1425
1448
|
onCollisionEnter,
|
1426
1449
|
onCollisionExit,
|
1427
1450
|
onIntersectionEnter,
|
1428
|
-
onIntersectionExit
|
1451
|
+
onIntersectionExit,
|
1452
|
+
onContactForce
|
1429
1453
|
} = props;
|
1430
1454
|
const eventHandlers = {
|
1431
1455
|
onWake,
|
@@ -1433,7 +1457,8 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1433
1457
|
onCollisionEnter,
|
1434
1458
|
onCollisionExit,
|
1435
1459
|
onIntersectionEnter,
|
1436
|
-
onIntersectionExit
|
1460
|
+
onIntersectionExit,
|
1461
|
+
onContactForce
|
1437
1462
|
};
|
1438
1463
|
React.useEffect(() => {
|
1439
1464
|
const rigidBody = getRigidBody();
|
@@ -1441,7 +1466,7 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1441
1466
|
return () => {
|
1442
1467
|
events.delete(rigidBody.handle);
|
1443
1468
|
};
|
1444
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
1469
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1445
1470
|
};
|
1446
1471
|
|
1447
1472
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|
@@ -174,6 +174,41 @@ const useRaf = callback => {
|
|
174
174
|
}, []);
|
175
175
|
};
|
176
176
|
|
177
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
178
|
+
if (source == null) return {};
|
179
|
+
var target = {};
|
180
|
+
var sourceKeys = Object.keys(source);
|
181
|
+
var key, i;
|
182
|
+
|
183
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
184
|
+
key = sourceKeys[i];
|
185
|
+
if (excluded.indexOf(key) >= 0) continue;
|
186
|
+
target[key] = source[key];
|
187
|
+
}
|
188
|
+
|
189
|
+
return target;
|
190
|
+
}
|
191
|
+
|
192
|
+
function _objectWithoutProperties(source, excluded) {
|
193
|
+
if (source == null) return {};
|
194
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
195
|
+
var key, i;
|
196
|
+
|
197
|
+
if (Object.getOwnPropertySymbols) {
|
198
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
199
|
+
|
200
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
201
|
+
key = sourceSymbolKeys[i];
|
202
|
+
if (excluded.indexOf(key) >= 0) continue;
|
203
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
204
|
+
target[key] = source[key];
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
return target;
|
209
|
+
}
|
210
|
+
|
211
|
+
const _excluded$2 = ["mass", "linearDamping", "angularDamping", "type", "onCollisionEnter", "onCollisionExit", "onIntersectionEnter", "onIntersectionExit", "onContactForce", "children", "canSleep", "ccd", "gravityScale"];
|
177
212
|
const scaleColliderArgs = (shape, args, scale) => {
|
178
213
|
const newArgs = args.slice(); // Heightfield uses a vector
|
179
214
|
|
@@ -340,7 +375,7 @@ const createColliderPropsFromChildren = ({
|
|
340
375
|
ignoreMeshColliders: _ignoreMeshColliders = true,
|
341
376
|
options
|
342
377
|
}) => {
|
343
|
-
const
|
378
|
+
const childColliderProps = [];
|
344
379
|
object.updateWorldMatrix(true, false);
|
345
380
|
const invertedParentMatrixWorld = object.matrixWorld.clone().invert();
|
346
381
|
|
@@ -361,13 +396,16 @@ const createColliderPropsFromChildren = ({
|
|
361
396
|
args,
|
362
397
|
offset
|
363
398
|
} = getColliderArgsFromGeometry(geometry, options.colliders || "cuboid");
|
364
|
-
|
399
|
+
|
400
|
+
const colliderProps = _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(options)), {}, {
|
365
401
|
args: args,
|
366
402
|
shape: shape,
|
367
403
|
rotation: [rotationEuler.x, rotationEuler.y, rotationEuler.z],
|
368
404
|
position: [_position.x + offset.x * worldScale.x, _position.y + offset.y * worldScale.y, _position.z + offset.z * worldScale.z],
|
369
405
|
scale: [worldScale.x, worldScale.y, worldScale.z]
|
370
|
-
})
|
406
|
+
});
|
407
|
+
|
408
|
+
childColliderProps.push(colliderProps);
|
371
409
|
}
|
372
410
|
};
|
373
411
|
|
@@ -377,7 +415,7 @@ const createColliderPropsFromChildren = ({
|
|
377
415
|
object.traverseVisible(colliderFromChild);
|
378
416
|
}
|
379
417
|
|
380
|
-
return
|
418
|
+
return childColliderProps;
|
381
419
|
};
|
382
420
|
const getColliderArgsFromGeometry = (geometry, colliders) => {
|
383
421
|
switch (colliders) {
|
@@ -433,7 +471,17 @@ const getColliderArgsFromGeometry = (geometry, colliders) => {
|
|
433
471
|
offset: new Vector3()
|
434
472
|
};
|
435
473
|
};
|
436
|
-
const
|
474
|
+
const getActiveCollisionEventsFromProps = props => {
|
475
|
+
return {
|
476
|
+
collision: !!(props !== null && props !== void 0 && props.onCollisionEnter || props !== null && props !== void 0 && props.onCollisionExit || props !== null && props !== void 0 && props.onIntersectionEnter || props !== null && props !== void 0 && props.onIntersectionExit),
|
477
|
+
contactForce: !!(props !== null && props !== void 0 && props.onContactForce)
|
478
|
+
};
|
479
|
+
};
|
480
|
+
const useColliderEvents = (getCollider, props, events,
|
481
|
+
/**
|
482
|
+
* The RigidBody can pass down active events to the collider without attaching the event listners
|
483
|
+
*/
|
484
|
+
activeEvents = {}) => {
|
437
485
|
const {
|
438
486
|
onCollisionEnter,
|
439
487
|
onCollisionExit,
|
@@ -445,8 +493,12 @@ const useColliderEvents = (getCollider, props, events) => {
|
|
445
493
|
const collider = getCollider();
|
446
494
|
|
447
495
|
if (collider) {
|
448
|
-
const
|
449
|
-
|
496
|
+
const {
|
497
|
+
collision: collisionEventsActive,
|
498
|
+
contactForce: contactForceEventsActive
|
499
|
+
} = getActiveCollisionEventsFromProps(props);
|
500
|
+
const hasCollisionEvent = collisionEventsActive || activeEvents.collision;
|
501
|
+
const hasContactForceEvent = contactForceEventsActive || activeEvents.contactForce;
|
450
502
|
|
451
503
|
if (hasCollisionEvent && hasContactForceEvent) {
|
452
504
|
collider.setActiveEvents(ActiveEvents.COLLISION_EVENTS | ActiveEvents.CONTACT_FORCE_EVENTS);
|
@@ -470,7 +522,12 @@ const useColliderEvents = (getCollider, props, events) => {
|
|
470
522
|
events.delete(collider.handle);
|
471
523
|
}
|
472
524
|
};
|
473
|
-
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
525
|
+
}, [onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce, activeEvents]);
|
526
|
+
};
|
527
|
+
const cleanRigidBodyPropsForCollider = (props = {}) => {
|
528
|
+
const rest = _objectWithoutProperties(props, _excluded$2);
|
529
|
+
|
530
|
+
return rest;
|
474
531
|
};
|
475
532
|
|
476
533
|
const useMutableCallback = fn => {
|
@@ -1003,40 +1060,6 @@ function _extends() {
|
|
1003
1060
|
return _extends.apply(this, arguments);
|
1004
1061
|
}
|
1005
1062
|
|
1006
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
1007
|
-
if (source == null) return {};
|
1008
|
-
var target = {};
|
1009
|
-
var sourceKeys = Object.keys(source);
|
1010
|
-
var key, i;
|
1011
|
-
|
1012
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
1013
|
-
key = sourceKeys[i];
|
1014
|
-
if (excluded.indexOf(key) >= 0) continue;
|
1015
|
-
target[key] = source[key];
|
1016
|
-
}
|
1017
|
-
|
1018
|
-
return target;
|
1019
|
-
}
|
1020
|
-
|
1021
|
-
function _objectWithoutProperties(source, excluded) {
|
1022
|
-
if (source == null) return {};
|
1023
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
1024
|
-
var key, i;
|
1025
|
-
|
1026
|
-
if (Object.getOwnPropertySymbols) {
|
1027
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
1028
|
-
|
1029
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
1030
|
-
key = sourceSymbolKeys[i];
|
1031
|
-
if (excluded.indexOf(key) >= 0) continue;
|
1032
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
1033
|
-
target[key] = source[key];
|
1034
|
-
}
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
return target;
|
1038
|
-
}
|
1039
|
-
|
1040
1063
|
/**
|
1041
1064
|
* Initiate an instance and return a safe getter
|
1042
1065
|
*/
|
@@ -1149,10 +1172,10 @@ const AnyCollider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((props, forwarded
|
|
1149
1172
|
}, []);
|
1150
1173
|
useImperativeHandle(forwardedRef, () => getInstance());
|
1151
1174
|
const mergedProps = useMemo(() => {
|
1152
|
-
return _objectSpread2(_objectSpread2({}, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options), props);
|
1175
|
+
return _objectSpread2(_objectSpread2({}, cleanRigidBodyPropsForCollider(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options)), props);
|
1153
1176
|
}, [props, rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options]);
|
1154
1177
|
useUpdateColliderOptions(getInstance, mergedProps, colliderStates);
|
1155
|
-
useColliderEvents(getInstance, mergedProps, colliderEvents);
|
1178
|
+
useColliderEvents(getInstance, mergedProps, colliderEvents, getActiveCollisionEventsFromProps(rigidBodyContext === null || rigidBodyContext === void 0 ? void 0 : rigidBodyContext.options));
|
1156
1179
|
return /*#__PURE__*/React.createElement("object3D", {
|
1157
1180
|
position: position,
|
1158
1181
|
rotation: rotation,
|
@@ -1400,7 +1423,8 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1400
1423
|
onCollisionEnter,
|
1401
1424
|
onCollisionExit,
|
1402
1425
|
onIntersectionEnter,
|
1403
|
-
onIntersectionExit
|
1426
|
+
onIntersectionExit,
|
1427
|
+
onContactForce
|
1404
1428
|
} = props;
|
1405
1429
|
const eventHandlers = {
|
1406
1430
|
onWake,
|
@@ -1408,7 +1432,8 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1408
1432
|
onCollisionEnter,
|
1409
1433
|
onCollisionExit,
|
1410
1434
|
onIntersectionEnter,
|
1411
|
-
onIntersectionExit
|
1435
|
+
onIntersectionExit,
|
1436
|
+
onContactForce
|
1412
1437
|
};
|
1413
1438
|
useEffect(() => {
|
1414
1439
|
const rigidBody = getRigidBody();
|
@@ -1416,7 +1441,7 @@ const useRigidBodyEvents = (getRigidBody, props, events) => {
|
|
1416
1441
|
return () => {
|
1417
1442
|
events.delete(rigidBody.handle);
|
1418
1443
|
};
|
1419
|
-
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit]);
|
1444
|
+
}, [onWake, onSleep, onCollisionEnter, onCollisionExit, onIntersectionEnter, onIntersectionExit, onContactForce]);
|
1420
1445
|
};
|
1421
1446
|
|
1422
1447
|
const _excluded$1 = ["children", "type", "position", "rotation", "scale", "quaternion", "transformState"];
|