@galacean/engine-physics-physx 2.0.0-alpha.5 → 2.0.0-alpha.51
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/browser.js +218 -122
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/dist/main.js +218 -122
- package/dist/main.js.map +1 -1
- package/dist/module.js +218 -122
- package/dist/module.js.map +1 -1
- package/libs/physx.release.js +1 -1
- package/libs/physx.release.simd.js +1 -1
- package/libs/physx.release.simd.wasm +0 -0
- package/libs/physx.release.wasm +0 -0
- package/package.json +6 -5
- package/types/PhysXCharacterController.d.ts +23 -0
- package/types/PhysXCollider.d.ts +14 -0
- package/types/PhysXDynamicCollider.d.ts +6 -6
- package/types/PhysXPhysics.d.ts +12 -2
- package/types/PhysXPhysicsManager.d.ts +3 -0
- package/types/PhysXPhysicsMaterial.d.ts +2 -0
- package/types/PhysXPhysicsScene.d.ts +44 -24
- package/types/shape/PhysXBoxColliderShape.d.ts +2 -0
- package/types/shape/PhysXCapsuleColliderShape.d.ts +6 -0
- package/types/shape/PhysXColliderShape.d.ts +25 -3
package/dist/module.js
CHANGED
|
@@ -293,7 +293,8 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
293
293
|
/**
|
|
294
294
|
* {@inheritDoc ICapsuleColliderShape.setUpAxis }
|
|
295
295
|
*/ _proto.setUpAxis = function setUpAxis(upAxis) {
|
|
296
|
-
var _this = this, rotation = _this._rotation,
|
|
296
|
+
var _this = this, rotation = _this._rotation, physXRotation = _this._physXRotation;
|
|
297
|
+
var axis = this._axis;
|
|
297
298
|
this._upAxis = upAxis;
|
|
298
299
|
switch(this._upAxis){
|
|
299
300
|
case 0:
|
|
@@ -521,7 +522,9 @@ PhysXCharacterController._tempVec = new Vector3();
|
|
|
521
522
|
* {@inheritDoc ICollider.addShape }
|
|
522
523
|
*/ _proto.addShape = function addShape(shape) {
|
|
523
524
|
var _this__scene;
|
|
524
|
-
this._pxActor.attachShape(shape._pxShape)
|
|
525
|
+
if (!this._pxActor.attachShape(shape._pxShape)) {
|
|
526
|
+
throw new Error("PhysXCollider: failed to attach shape to the native actor.");
|
|
527
|
+
}
|
|
525
528
|
this._shapes.push(shape);
|
|
526
529
|
(_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
|
|
527
530
|
};
|
|
@@ -670,44 +673,27 @@ PhysXCollider._tempTransform = {
|
|
|
670
673
|
this._pxActor.setSolverIterationCounts(value, 1);
|
|
671
674
|
};
|
|
672
675
|
/**
|
|
673
|
-
* {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
|
|
674
|
-
*/ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
|
|
675
|
-
var physX = this._physXPhysics._physX;
|
|
676
|
-
switch(value){
|
|
677
|
-
case 1:
|
|
678
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
|
|
679
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
680
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
681
|
-
break;
|
|
682
|
-
case 2:
|
|
683
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
|
|
684
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
|
|
685
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
686
|
-
break;
|
|
687
|
-
case 3:
|
|
688
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
689
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
690
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
|
|
691
|
-
break;
|
|
692
|
-
case 0:
|
|
693
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
694
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
695
|
-
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
696
|
-
break;
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
/**
|
|
700
676
|
* {@inheritDoc IDynamicCollider.setUseGravity }
|
|
701
677
|
*/ _proto.setUseGravity = function setUseGravity(value) {
|
|
702
678
|
this._pxActor.setActorFlag(this._physXPhysics._physX.PxActorFlag.eDISABLE_GRAVITY, !value);
|
|
703
679
|
};
|
|
704
680
|
/**
|
|
705
|
-
* {@inheritDoc IDynamicCollider.
|
|
706
|
-
*/ _proto.
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
681
|
+
* {@inheritDoc IDynamicCollider.setMotionState }
|
|
682
|
+
*/ _proto.setMotionState = function setMotionState(isKinematic, collisionDetectionMode) {
|
|
683
|
+
var PxRigidBodyFlag = this._physXPhysics._physX.PxRigidBodyFlag;
|
|
684
|
+
// PhysX 4.1 does not support sweep-based CCD on kinematic bodies
|
|
685
|
+
var useSpeculativeCCD = collisionDetectionMode === 3 || isKinematic && collisionDetectionMode !== 0;
|
|
686
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eENABLE_CCD, false);
|
|
687
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
688
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
689
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eKINEMATIC, isKinematic);
|
|
690
|
+
if (useSpeculativeCCD) {
|
|
691
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
|
|
692
|
+
} else if (collisionDetectionMode !== 0) {
|
|
693
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eENABLE_CCD, true);
|
|
694
|
+
if (collisionDetectionMode === 2) {
|
|
695
|
+
this._pxActor.setRigidBodyFlag(PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
|
|
696
|
+
}
|
|
711
697
|
}
|
|
712
698
|
};
|
|
713
699
|
/**
|
|
@@ -718,20 +704,17 @@ PhysXCollider._tempTransform = {
|
|
|
718
704
|
/**
|
|
719
705
|
* {@inheritDoc IDynamicCollider.addForce }
|
|
720
706
|
*/ _proto.addForce = function addForce(force) {
|
|
721
|
-
this._pxActor.addForce(
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
707
|
+
this._pxActor.addForce(force);
|
|
708
|
+
};
|
|
709
|
+
/**
|
|
710
|
+
* {@inheritDoc IDynamicCollider.addForceAtPosition }
|
|
711
|
+
*/ _proto.addForceAtPosition = function addForceAtPosition(force, position) {
|
|
712
|
+
this._pxActor.addForceAtPos(force, position);
|
|
726
713
|
};
|
|
727
714
|
/**
|
|
728
715
|
* {@inheritDoc IDynamicCollider.addTorque }
|
|
729
716
|
*/ _proto.addTorque = function addTorque(torque) {
|
|
730
|
-
this._pxActor.addTorque(
|
|
731
|
-
x: torque.x,
|
|
732
|
-
y: torque.y,
|
|
733
|
-
z: torque.z
|
|
734
|
-
});
|
|
717
|
+
this._pxActor.addTorque(torque);
|
|
735
718
|
};
|
|
736
719
|
/**
|
|
737
720
|
* {@inheritDoc IDynamicCollider.move }
|
|
@@ -817,44 +800,68 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
817
800
|
return PhysXPhysicsMaterial;
|
|
818
801
|
}();
|
|
819
802
|
|
|
803
|
+
function _defineProperties(target, props) {
|
|
804
|
+
for (var i = 0; i < props.length; i++) {
|
|
805
|
+
var descriptor = props[i];
|
|
806
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
807
|
+
descriptor.configurable = true;
|
|
808
|
+
|
|
809
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
810
|
+
|
|
811
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
815
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
816
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
817
|
+
|
|
818
|
+
return Constructor;
|
|
819
|
+
}
|
|
820
|
+
|
|
820
821
|
/**
|
|
821
822
|
* A manager is a collection of colliders and constraints which can interact.
|
|
822
823
|
*/ var PhysXPhysicsScene = /*#__PURE__*/ function() {
|
|
823
|
-
function PhysXPhysicsScene(physXPhysics, physicsManager
|
|
824
|
+
function PhysXPhysicsScene(physXPhysics, physicsManager) {
|
|
824
825
|
var _this = this;
|
|
825
826
|
/** @internal */ this._pxControllerManager = null;
|
|
826
827
|
// Cached geometry objects for reuse
|
|
827
828
|
this._boxGeometry = null;
|
|
828
829
|
this._sphereGeometry = null;
|
|
829
830
|
this._capsuleGeometry = null;
|
|
830
|
-
this.
|
|
831
|
-
this.
|
|
831
|
+
this._currentOnQuery = null;
|
|
832
|
+
this._activeTriggers = new DisorderedArray();
|
|
833
|
+
this._contactEvents = [];
|
|
834
|
+
this._contactEventCount = 0;
|
|
835
|
+
this._triggerEvents = [];
|
|
836
|
+
this._physicsEvents = {
|
|
837
|
+
contactEvents: [],
|
|
838
|
+
contactEventCount: 0,
|
|
839
|
+
triggerEvents: []
|
|
840
|
+
};
|
|
841
|
+
this._triggerEventPool = [];
|
|
832
842
|
this._physXPhysics = physXPhysics;
|
|
833
843
|
this._physXManager = physicsManager;
|
|
834
844
|
var physX = physXPhysics._physX;
|
|
835
845
|
this._pxRaycastHit = new physX.PxRaycastHit();
|
|
846
|
+
this._pxSweepHit = new physX.PxSweepHit();
|
|
836
847
|
this._pxFilterData = new physX.PxQueryFilterData();
|
|
837
848
|
this._pxFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4);
|
|
838
|
-
this.
|
|
839
|
-
this.
|
|
840
|
-
this._onContactStay = onContactStay;
|
|
841
|
-
this._onTriggerEnter = onTriggerEnter;
|
|
842
|
-
this._onTriggerExit = onTriggerExit;
|
|
843
|
-
this._onTriggerStay = onTriggerStay;
|
|
849
|
+
this._pxRaycastSweepFilterData = new physX.PxQueryFilterData();
|
|
850
|
+
this._pxRaycastSweepFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4 | 8);
|
|
844
851
|
var triggerCallback = {
|
|
845
852
|
onContactBegin: function(collision) {
|
|
846
|
-
_this.
|
|
853
|
+
_this._bufferContactEvent(collision, 0);
|
|
847
854
|
},
|
|
848
855
|
onContactEnd: function(collision) {
|
|
849
|
-
_this.
|
|
856
|
+
_this._bufferContactEvent(collision, 2);
|
|
850
857
|
},
|
|
851
858
|
onContactPersist: function(collision) {
|
|
852
|
-
_this.
|
|
859
|
+
_this._bufferContactEvent(collision, 1);
|
|
853
860
|
},
|
|
854
861
|
onTriggerBegin: function(index1, index2) {
|
|
855
862
|
var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
|
|
856
863
|
event.state = 0;
|
|
857
|
-
_this.
|
|
864
|
+
_this._activeTriggers.add(event);
|
|
858
865
|
},
|
|
859
866
|
onTriggerEnd: function(index1, index2) {
|
|
860
867
|
var event;
|
|
@@ -875,6 +882,16 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
875
882
|
var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, this._physXSimulationCallbackInstance);
|
|
876
883
|
this._pxScene = pxPhysics.createScene(sceneDesc);
|
|
877
884
|
sceneDesc.delete();
|
|
885
|
+
this._pxQueryCallback = physX.PxQueryFilterCallback.implement({
|
|
886
|
+
preFilter: function(_filterData, index, _actor) {
|
|
887
|
+
return _this._currentOnQuery(index) ? 2 : 0;
|
|
888
|
+
},
|
|
889
|
+
// distance <= 0 means initial overlap — drop the hit so subsequent hits can be considered.
|
|
890
|
+
// Only invoked when the query's filter data includes POST_FILTER (raycast/sweep, not overlap).
|
|
891
|
+
postFilter: function(_filterData, distance) {
|
|
892
|
+
return distance <= 0 ? 0 : 2;
|
|
893
|
+
}
|
|
894
|
+
});
|
|
878
895
|
}
|
|
879
896
|
var _proto = PhysXPhysicsScene.prototype;
|
|
880
897
|
/**
|
|
@@ -932,27 +949,53 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
932
949
|
/**
|
|
933
950
|
* {@inheritDoc IPhysicsScene.update }
|
|
934
951
|
*/ _proto.update = function update(elapsedTime) {
|
|
952
|
+
this._contactEventCount = 0;
|
|
935
953
|
this._simulate(elapsedTime);
|
|
936
954
|
this._fetchResults();
|
|
937
|
-
|
|
955
|
+
};
|
|
956
|
+
/**
|
|
957
|
+
* {@inheritDoc IPhysicsScene.setContactEventEnabled }
|
|
958
|
+
*/ _proto.setContactEventEnabled = function setContactEventEnabled(enabled) {
|
|
959
|
+
this._physXPhysics._physX.setContactEventEnabled(this._physXSimulationCallbackInstance, enabled);
|
|
960
|
+
if (!enabled) {
|
|
961
|
+
this._contactEventCount = 0;
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
/**
|
|
965
|
+
* {@inheritDoc IPhysicsScene.updateEvents }
|
|
966
|
+
*/ _proto.updateEvents = function updateEvents() {
|
|
967
|
+
var physicsEvents = this._physicsEvents;
|
|
968
|
+
// Collect trigger events: snapshot state for dispatch, then advance
|
|
969
|
+
var _this = this, triggerEventPool = _this._triggerEventPool, activeTriggers = _this._activeTriggers, triggerEvents = _this._triggerEvents;
|
|
970
|
+
triggerEvents.length = 0;
|
|
971
|
+
activeTriggers.forEach(function(event, i) {
|
|
972
|
+
event.dispatchState = event.state;
|
|
973
|
+
triggerEvents.push(event);
|
|
974
|
+
if (event.state === 0) {
|
|
975
|
+
event.state = 1;
|
|
976
|
+
} else if (event.state === 2) {
|
|
977
|
+
activeTriggers.deleteByIndex(i);
|
|
978
|
+
triggerEventPool.push(event);
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
physicsEvents.contactEvents = this._contactEvents;
|
|
982
|
+
physicsEvents.contactEventCount = this._contactEventCount;
|
|
983
|
+
physicsEvents.triggerEvents = triggerEvents;
|
|
984
|
+
return physicsEvents;
|
|
938
985
|
};
|
|
939
986
|
/**
|
|
940
987
|
* {@inheritDoc IPhysicsScene.raycast }
|
|
941
|
-
*/ _proto.raycast = function raycast(
|
|
988
|
+
*/ _proto.raycast = function raycast(origin, direction, distance, onRaycast, hit) {
|
|
942
989
|
var _this = this, pxHitResult = _this._pxRaycastHit;
|
|
943
990
|
distance = Math.min(distance, 3.4e38); // float32 max value limit in physX raycast.
|
|
944
|
-
var
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
};
|
|
953
|
-
var pxRaycastCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback);
|
|
954
|
-
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, pxRaycastCallback);
|
|
955
|
-
pxRaycastCallback.delete();
|
|
991
|
+
var prevOnQuery = this._currentOnQuery;
|
|
992
|
+
this._currentOnQuery = onRaycast;
|
|
993
|
+
var result;
|
|
994
|
+
try {
|
|
995
|
+
result = this._pxScene.raycastSingle(origin, direction, distance, pxHitResult, this._pxRaycastSweepFilterData, this._pxQueryCallback);
|
|
996
|
+
} finally{
|
|
997
|
+
this._currentOnQuery = prevOnQuery;
|
|
998
|
+
}
|
|
956
999
|
if (result && hit != undefined) {
|
|
957
1000
|
var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
|
|
958
1001
|
var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
|
|
@@ -1049,6 +1092,11 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1049
1092
|
return this._overlapMultiple(this._capsuleGeometry, pose, onOverlap);
|
|
1050
1093
|
};
|
|
1051
1094
|
/**
|
|
1095
|
+
* {@inheritDoc IPhysicsScene.gc }
|
|
1096
|
+
*/ _proto.gc = function gc() {
|
|
1097
|
+
this._contactEvents.length = this._contactEventCount;
|
|
1098
|
+
};
|
|
1099
|
+
/**
|
|
1052
1100
|
* {@inheritDoc IPhysicsScene.destroy }
|
|
1053
1101
|
*/ _proto.destroy = function destroy() {
|
|
1054
1102
|
var _this__boxGeometry, _this__sphereGeometry, _this__capsuleGeometry, // Need to release the controller manager before release the scene.
|
|
@@ -1058,8 +1106,12 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1058
1106
|
(_this__capsuleGeometry = this._capsuleGeometry) == null ? void 0 : _this__capsuleGeometry.delete();
|
|
1059
1107
|
this._physXSimulationCallbackInstance.delete();
|
|
1060
1108
|
this._pxRaycastHit.delete();
|
|
1109
|
+
this._pxSweepHit.delete();
|
|
1061
1110
|
this._pxFilterData.flags.delete();
|
|
1062
1111
|
this._pxFilterData.delete();
|
|
1112
|
+
this._pxRaycastSweepFilterData.flags.delete();
|
|
1113
|
+
this._pxRaycastSweepFilterData.delete();
|
|
1114
|
+
this._pxQueryCallback.delete();
|
|
1063
1115
|
(_this__pxControllerManager = this._pxControllerManager) == null ? void 0 : _this__pxControllerManager.release();
|
|
1064
1116
|
this._pxScene.release();
|
|
1065
1117
|
};
|
|
@@ -1080,15 +1132,15 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1080
1132
|
/**
|
|
1081
1133
|
* @internal
|
|
1082
1134
|
*/ _proto._removeColliderShape = function _removeColliderShape(id) {
|
|
1083
|
-
var _this = this,
|
|
1135
|
+
var _this = this, triggerEventPool = _this._triggerEventPool, activeTriggers = _this._activeTriggers;
|
|
1084
1136
|
var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
|
|
1085
|
-
|
|
1137
|
+
activeTriggers.forEach(function(event, i) {
|
|
1086
1138
|
if (event.index1 == id) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1139
|
+
activeTriggers.deleteByIndex(i);
|
|
1140
|
+
triggerEventPool.push(event);
|
|
1089
1141
|
} else if (event.index2 == id) {
|
|
1090
|
-
|
|
1091
|
-
|
|
1142
|
+
activeTriggers.deleteByIndex(i);
|
|
1143
|
+
triggerEventPool.push(event);
|
|
1092
1144
|
// If the shape is big index, should clear from the small index shape subMap
|
|
1093
1145
|
eventMap[event.index1][id] = undefined;
|
|
1094
1146
|
}
|
|
@@ -1096,19 +1148,16 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1096
1148
|
delete eventMap[id];
|
|
1097
1149
|
};
|
|
1098
1150
|
_proto._sweepSingle = function _sweepSingle(geometry, pose, direction, distance, onSweep, outHitResult) {
|
|
1151
|
+
var _this = this, pxSweepHit = _this._pxSweepHit;
|
|
1099
1152
|
distance = Math.min(distance, 3.4e38); // float32 max value limit in physx sweep
|
|
1100
|
-
var
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
};
|
|
1109
|
-
var pxSweepCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(sweepCallback);
|
|
1110
|
-
var pxSweepHit = new this._physXPhysics._physX.PxSweepHit();
|
|
1111
|
-
var result = this._pxScene.sweepSingle(geometry, pose, direction, distance, pxSweepHit, this._pxFilterData, pxSweepCallback);
|
|
1153
|
+
var prevOnQuery = this._currentOnQuery;
|
|
1154
|
+
this._currentOnQuery = onSweep;
|
|
1155
|
+
var result;
|
|
1156
|
+
try {
|
|
1157
|
+
result = this._pxScene.sweepSingle(geometry, pose, direction, distance, pxSweepHit, this._pxRaycastSweepFilterData, this._pxQueryCallback);
|
|
1158
|
+
} finally{
|
|
1159
|
+
this._currentOnQuery = prevOnQuery;
|
|
1160
|
+
}
|
|
1112
1161
|
if (result && outHitResult != undefined) {
|
|
1113
1162
|
var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
|
|
1114
1163
|
var pxPosition = pxSweepHit.position, pxNormal = pxSweepHit.normal;
|
|
@@ -1116,19 +1165,18 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1116
1165
|
normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
|
|
1117
1166
|
outHitResult(pxSweepHit.getShape().getUUID(), pxSweepHit.distance, position, normal);
|
|
1118
1167
|
}
|
|
1119
|
-
pxSweepCallback.delete();
|
|
1120
|
-
pxSweepHit.delete();
|
|
1121
1168
|
return result;
|
|
1122
1169
|
};
|
|
1123
1170
|
_proto._overlapMultiple = function _overlapMultiple(geometry, pose, onOverlap) {
|
|
1124
|
-
var
|
|
1125
|
-
|
|
1126
|
-
return onOverlap(index) ? 2 : 0;
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
var pxOverlapCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(overlapCallback);
|
|
1171
|
+
var prevOnQuery = this._currentOnQuery;
|
|
1172
|
+
this._currentOnQuery = onOverlap;
|
|
1130
1173
|
var maxHits = 256;
|
|
1131
|
-
var hits
|
|
1174
|
+
var hits;
|
|
1175
|
+
try {
|
|
1176
|
+
hits = this._pxScene.overlapMultiple(geometry, pose, maxHits, this._pxFilterData, this._pxQueryCallback);
|
|
1177
|
+
} finally{
|
|
1178
|
+
this._currentOnQuery = prevOnQuery;
|
|
1179
|
+
}
|
|
1132
1180
|
var result = PhysXPhysicsScene._tempShapeIDs;
|
|
1133
1181
|
result.length = 0;
|
|
1134
1182
|
if (hits) {
|
|
@@ -1137,7 +1185,6 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1137
1185
|
result.push(hits.get(i).getShape().getUUID());
|
|
1138
1186
|
}
|
|
1139
1187
|
}
|
|
1140
|
-
pxOverlapCallback.delete();
|
|
1141
1188
|
hits == null ? void 0 : hits.delete();
|
|
1142
1189
|
return result;
|
|
1143
1190
|
};
|
|
@@ -1150,8 +1197,8 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1150
1197
|
};
|
|
1151
1198
|
_proto._getTrigger = function _getTrigger(index1, index2) {
|
|
1152
1199
|
var event;
|
|
1153
|
-
if (this.
|
|
1154
|
-
event = this.
|
|
1200
|
+
if (this._triggerEventPool.length) {
|
|
1201
|
+
event = this._triggerEventPool.pop();
|
|
1155
1202
|
event.index1 = index1;
|
|
1156
1203
|
event.index2 = index2;
|
|
1157
1204
|
} else {
|
|
@@ -1160,21 +1207,27 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1160
1207
|
this._physXManager._eventMap[index1][index2] = event;
|
|
1161
1208
|
return event;
|
|
1162
1209
|
};
|
|
1163
|
-
_proto.
|
|
1164
|
-
var
|
|
1165
|
-
var
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1210
|
+
_proto._bufferContactEvent = function _bufferContactEvent(collision, state) {
|
|
1211
|
+
var _this__contactEvents, _index;
|
|
1212
|
+
var index = this._contactEventCount++;
|
|
1213
|
+
var event = (_this__contactEvents = this._contactEvents)[_index = index] || (_this__contactEvents[_index] = new ContactEvent());
|
|
1214
|
+
event.shape0Id = collision.shape0Id;
|
|
1215
|
+
event.shape1Id = collision.shape1Id;
|
|
1216
|
+
event.state = state;
|
|
1217
|
+
// Copy contact points from PhysX (the native data is only valid during fetchResults)
|
|
1218
|
+
var nativeContacts = collision.getContacts();
|
|
1219
|
+
var count = nativeContacts.size();
|
|
1220
|
+
var bufferedContacts = event._bufferedContacts;
|
|
1221
|
+
bufferedContacts.contactCount = count;
|
|
1222
|
+
for(var i = 0; i < count; i++){
|
|
1223
|
+
var _bufferedContacts_contacts, _i;
|
|
1224
|
+
var src = nativeContacts.get(i);
|
|
1225
|
+
var dst = (_bufferedContacts_contacts = bufferedContacts.contacts)[_i = i] || (_bufferedContacts_contacts[_i] = new BufferedContactPoint());
|
|
1226
|
+
dst.position.copyFrom(src.position);
|
|
1227
|
+
dst.normal.copyFrom(src.normal);
|
|
1228
|
+
dst.impulse.copyFrom(src.impulse);
|
|
1229
|
+
dst.separation = src.separation;
|
|
1230
|
+
}
|
|
1178
1231
|
};
|
|
1179
1232
|
return PhysXPhysicsScene;
|
|
1180
1233
|
}();
|
|
@@ -1192,6 +1245,49 @@ PhysXPhysicsScene._tempShapeIDs = [];
|
|
|
1192
1245
|
this.index1 = index1;
|
|
1193
1246
|
this.index2 = index2;
|
|
1194
1247
|
};
|
|
1248
|
+
/**
|
|
1249
|
+
* Buffered contact point data, copied from PhysX during fetchResults.
|
|
1250
|
+
*/ var BufferedContactPoint = function BufferedContactPoint() {
|
|
1251
|
+
this.position = new Vector3();
|
|
1252
|
+
this.normal = new Vector3();
|
|
1253
|
+
this.impulse = new Vector3();
|
|
1254
|
+
this.separation = 0;
|
|
1255
|
+
};
|
|
1256
|
+
/**
|
|
1257
|
+
* Contact event buffered from PhysX fetchResults callback.
|
|
1258
|
+
* Implements ICollision so it can be passed directly to the core layer.
|
|
1259
|
+
*/ var BufferedContacts = /*#__PURE__*/ function() {
|
|
1260
|
+
function BufferedContacts() {
|
|
1261
|
+
this.contactCount = 0;
|
|
1262
|
+
this.contacts = [];
|
|
1263
|
+
}
|
|
1264
|
+
var _proto = BufferedContacts.prototype;
|
|
1265
|
+
_proto.size = function size() {
|
|
1266
|
+
return this.contactCount;
|
|
1267
|
+
};
|
|
1268
|
+
_proto.get = function get(index) {
|
|
1269
|
+
return this.contacts[index];
|
|
1270
|
+
};
|
|
1271
|
+
return BufferedContacts;
|
|
1272
|
+
}();
|
|
1273
|
+
var ContactEvent = /*#__PURE__*/ function() {
|
|
1274
|
+
function ContactEvent() {
|
|
1275
|
+
/** @internal */ this._bufferedContacts = new BufferedContacts();
|
|
1276
|
+
}
|
|
1277
|
+
var _proto = ContactEvent.prototype;
|
|
1278
|
+
_proto.getContacts = function getContacts() {
|
|
1279
|
+
return this._bufferedContacts;
|
|
1280
|
+
};
|
|
1281
|
+
_create_class(ContactEvent, [
|
|
1282
|
+
{
|
|
1283
|
+
key: "contactCount",
|
|
1284
|
+
get: function get() {
|
|
1285
|
+
return this._bufferedContacts.contactCount;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
]);
|
|
1289
|
+
return ContactEvent;
|
|
1290
|
+
}();
|
|
1195
1291
|
|
|
1196
1292
|
/**
|
|
1197
1293
|
* A static collider component that will not move.
|
|
@@ -1669,9 +1765,9 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1669
1765
|
this._initializeState = 0;
|
|
1670
1766
|
this._runTimeMode = runtimeMode;
|
|
1671
1767
|
var _runtimeUrls_wasmSIMDModeUrl;
|
|
1672
|
-
this._wasmSIMDModeUrl = (_runtimeUrls_wasmSIMDModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmSIMDModeUrl) != null ? _runtimeUrls_wasmSIMDModeUrl : "https://mdn.alipayobjects.com/rms/
|
|
1768
|
+
this._wasmSIMDModeUrl = (_runtimeUrls_wasmSIMDModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmSIMDModeUrl) != null ? _runtimeUrls_wasmSIMDModeUrl : "https://mdn.alipayobjects.com/rms/uri/file/as/apwallet/1787063975729/suyi/physx.release.simd.js";
|
|
1673
1769
|
var _runtimeUrls_wasmModeUrl;
|
|
1674
|
-
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/
|
|
1770
|
+
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/uri/file/as/apwallet/1787063975729/suyi/physx.release.js";
|
|
1675
1771
|
}
|
|
1676
1772
|
var _proto = PhysXPhysics.prototype;
|
|
1677
1773
|
/**
|
|
@@ -1736,8 +1832,8 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1736
1832
|
};
|
|
1737
1833
|
/**
|
|
1738
1834
|
* {@inheritDoc IPhysics.createPhysicsScene }
|
|
1739
|
-
*/ _proto.createPhysicsScene = function createPhysicsScene(physicsManager
|
|
1740
|
-
var scene = new PhysXPhysicsScene(this, physicsManager
|
|
1835
|
+
*/ _proto.createPhysicsScene = function createPhysicsScene(physicsManager) {
|
|
1836
|
+
var scene = new PhysXPhysicsScene(this, physicsManager);
|
|
1741
1837
|
return scene;
|
|
1742
1838
|
};
|
|
1743
1839
|
/**
|
|
@@ -1841,7 +1937,7 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1841
1937
|
}();
|
|
1842
1938
|
|
|
1843
1939
|
//@ts-ignore
|
|
1844
|
-
var version = "2.0.0-alpha.
|
|
1940
|
+
var version = "2.0.0-alpha.51";
|
|
1845
1941
|
console.log("Galacean Engine Physics PhysX Version: " + version);
|
|
1846
1942
|
|
|
1847
1943
|
export { PhysXPhysics, PhysXRuntimeMode, version };
|