@galacean/engine-physics-physx 1.5.14 → 1.6.0-alpha.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.
- package/dist/browser.js +156 -12
- 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 +156 -12
- package/dist/main.js.map +1 -1
- package/dist/module.js +157 -13
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/PhysXPhysicsScene.d.ts +33 -1
- package/types/shape/PhysXColliderShape.d.ts +2 -1
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector3, Vector4, MathUtil, Quaternion, DisorderedArray } from '@galacean/engine';
|
|
2
2
|
|
|
3
3
|
function _instanceof(left, right) {
|
|
4
4
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -148,12 +148,12 @@ function _inherits(subClass, superClass) {
|
|
|
148
148
|
};
|
|
149
149
|
return PhysXColliderShape;
|
|
150
150
|
}();
|
|
151
|
-
PhysXColliderShape._tempVector4 = new Vector4();
|
|
152
151
|
PhysXColliderShape.halfSqrt = 0.70710678118655;
|
|
153
152
|
PhysXColliderShape.transform = {
|
|
154
153
|
translation: new Vector3(),
|
|
155
154
|
rotation: null
|
|
156
155
|
};
|
|
156
|
+
PhysXColliderShape._tempVector4 = new Vector4();
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Box collider shape in PhysX.
|
|
@@ -225,7 +225,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
225
225
|
_this._halfHeight = height * 0.5;
|
|
226
226
|
_this._axis = new Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
|
|
227
227
|
_this._physXRotation.copyFrom(_this._axis);
|
|
228
|
-
_this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(
|
|
228
|
+
_this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(radius, _this._halfHeight);
|
|
229
229
|
_this._initialize(material, uniqueID);
|
|
230
230
|
_this._setLocalPose();
|
|
231
231
|
return _this;
|
|
@@ -816,6 +816,10 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
816
816
|
function PhysXPhysicsScene(physXPhysics, physicsManager, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
817
817
|
var _this = this;
|
|
818
818
|
/** @internal */ this._pxControllerManager = null;
|
|
819
|
+
// Cached geometry objects for reuse
|
|
820
|
+
this._boxGeometry = null;
|
|
821
|
+
this._sphereGeometry = null;
|
|
822
|
+
this._capsuleGeometry = null;
|
|
819
823
|
this._currentEvents = new DisorderedArray();
|
|
820
824
|
this._eventPool = [];
|
|
821
825
|
this._physXPhysics = physXPhysics;
|
|
@@ -929,7 +933,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
929
933
|
* {@inheritDoc IPhysicsScene.raycast }
|
|
930
934
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
931
935
|
var _this = this, pxHitResult = _this._pxRaycastHit;
|
|
932
|
-
distance = Math.min(distance, 3.4e38); // float32 max value limit in
|
|
936
|
+
distance = Math.min(distance, 3.4e38); // float32 max value limit in physX raycast.
|
|
933
937
|
var raycastCallback = {
|
|
934
938
|
preFilter: function(filterData, index, actor) {
|
|
935
939
|
if (onRaycast(index)) {
|
|
@@ -937,8 +941,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
937
941
|
} else {
|
|
938
942
|
return 0; // eNONE
|
|
939
943
|
}
|
|
940
|
-
}
|
|
941
|
-
postFilter: function(filterData, hit) {}
|
|
944
|
+
}
|
|
942
945
|
};
|
|
943
946
|
var pxRaycastCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback);
|
|
944
947
|
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, pxRaycastCallback);
|
|
@@ -953,10 +956,99 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
953
956
|
return result;
|
|
954
957
|
};
|
|
955
958
|
/**
|
|
959
|
+
* {@inheritDoc IPhysicsScene.boxCast }
|
|
960
|
+
*/ _proto.boxCast = function boxCast(center, orientation, halfExtents, direction, distance, onSweep, outHitResult) {
|
|
961
|
+
if (!this._boxGeometry) {
|
|
962
|
+
this._boxGeometry = new this._physXPhysics._physX.PxBoxGeometry(halfExtents.x, halfExtents.y, halfExtents.z);
|
|
963
|
+
} else {
|
|
964
|
+
this._boxGeometry.halfExtents = halfExtents;
|
|
965
|
+
}
|
|
966
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
967
|
+
pose.translation.copyFrom(center);
|
|
968
|
+
pose.rotation.copyFrom(orientation);
|
|
969
|
+
return this._sweepSingle(this._boxGeometry, pose, direction, distance, onSweep, outHitResult);
|
|
970
|
+
};
|
|
971
|
+
/**
|
|
972
|
+
* {@inheritDoc IPhysicsScene.sphereCast }
|
|
973
|
+
*/ _proto.sphereCast = function sphereCast(center, radius, direction, distance, onSweep, outHitResult) {
|
|
974
|
+
if (!this._sphereGeometry) {
|
|
975
|
+
this._sphereGeometry = new this._physXPhysics._physX.PxSphereGeometry(radius);
|
|
976
|
+
} else {
|
|
977
|
+
this._sphereGeometry.radius = radius;
|
|
978
|
+
}
|
|
979
|
+
var tempQuat = PhysXPhysicsScene._tempQuaternion;
|
|
980
|
+
tempQuat.set(0, 0, 0, 1); // Identity quaternion
|
|
981
|
+
var pose = {
|
|
982
|
+
translation: center,
|
|
983
|
+
rotation: tempQuat
|
|
984
|
+
};
|
|
985
|
+
return this._sweepSingle(this._sphereGeometry, pose, direction, distance, onSweep, outHitResult);
|
|
986
|
+
};
|
|
987
|
+
/**
|
|
988
|
+
* {@inheritDoc IPhysicsScene.capsuleCast }
|
|
989
|
+
*/ _proto.capsuleCast = function capsuleCast(center, radius, height, orientation, direction, distance, onSweep, outHitResult) {
|
|
990
|
+
if (!this._capsuleGeometry) {
|
|
991
|
+
this._capsuleGeometry = new this._physXPhysics._physX.PxCapsuleGeometry(radius, height * 0.5);
|
|
992
|
+
} else {
|
|
993
|
+
this._capsuleGeometry.radius = radius;
|
|
994
|
+
this._capsuleGeometry.halfHeight = height * 0.5;
|
|
995
|
+
}
|
|
996
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
997
|
+
pose.translation.copyFrom(center);
|
|
998
|
+
pose.rotation.copyFrom(orientation);
|
|
999
|
+
return this._sweepSingle(this._capsuleGeometry, pose, direction, distance, onSweep, outHitResult);
|
|
1000
|
+
};
|
|
1001
|
+
/**
|
|
1002
|
+
* {@inheritDoc IPhysicsScene.overlapBoxAll }
|
|
1003
|
+
*/ _proto.overlapBoxAll = function overlapBoxAll(center, orientation, halfExtents, onOverlap) {
|
|
1004
|
+
if (!this._boxGeometry) {
|
|
1005
|
+
this._boxGeometry = new this._physXPhysics._physX.PxBoxGeometry(halfExtents.x, halfExtents.y, halfExtents.z);
|
|
1006
|
+
} else {
|
|
1007
|
+
this._boxGeometry.halfExtents = halfExtents;
|
|
1008
|
+
}
|
|
1009
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
1010
|
+
pose.translation.copyFrom(center);
|
|
1011
|
+
pose.rotation.copyFrom(orientation);
|
|
1012
|
+
return this._overlapMultiple(this._boxGeometry, pose, onOverlap);
|
|
1013
|
+
};
|
|
1014
|
+
/**
|
|
1015
|
+
* {@inheritDoc IPhysicsScene.overlapSphereAll }
|
|
1016
|
+
*/ _proto.overlapSphereAll = function overlapSphereAll(center, radius, onOverlap) {
|
|
1017
|
+
if (!this._sphereGeometry) {
|
|
1018
|
+
this._sphereGeometry = new this._physXPhysics._physX.PxSphereGeometry(radius);
|
|
1019
|
+
} else {
|
|
1020
|
+
this._sphereGeometry.radius = radius;
|
|
1021
|
+
}
|
|
1022
|
+
var tempQuat = PhysXPhysicsScene._tempQuaternion;
|
|
1023
|
+
tempQuat.set(0, 0, 0, 1);
|
|
1024
|
+
var pose = {
|
|
1025
|
+
translation: center,
|
|
1026
|
+
rotation: tempQuat
|
|
1027
|
+
};
|
|
1028
|
+
return this._overlapMultiple(this._sphereGeometry, pose, onOverlap);
|
|
1029
|
+
};
|
|
1030
|
+
/**
|
|
1031
|
+
* {@inheritDoc IPhysicsScene.overlapCapsuleAll }
|
|
1032
|
+
*/ _proto.overlapCapsuleAll = function overlapCapsuleAll(center, radius, height, orientation, onOverlap) {
|
|
1033
|
+
if (!this._capsuleGeometry) {
|
|
1034
|
+
this._capsuleGeometry = new this._physXPhysics._physX.PxCapsuleGeometry(radius, height * 0.5);
|
|
1035
|
+
} else {
|
|
1036
|
+
this._capsuleGeometry.radius = radius;
|
|
1037
|
+
this._capsuleGeometry.halfHeight = height * 0.5;
|
|
1038
|
+
}
|
|
1039
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
1040
|
+
pose.translation.copyFrom(center);
|
|
1041
|
+
pose.rotation.copyFrom(orientation);
|
|
1042
|
+
return this._overlapMultiple(this._capsuleGeometry, pose, onOverlap);
|
|
1043
|
+
};
|
|
1044
|
+
/**
|
|
956
1045
|
* {@inheritDoc IPhysicsScene.destroy }
|
|
957
1046
|
*/ _proto.destroy = function destroy() {
|
|
958
|
-
var // Need to release the controller manager before release the scene.
|
|
1047
|
+
var _this__boxGeometry, _this__sphereGeometry, _this__capsuleGeometry, // Need to release the controller manager before release the scene.
|
|
959
1048
|
_this__pxControllerManager;
|
|
1049
|
+
(_this__boxGeometry = this._boxGeometry) == null ? void 0 : _this__boxGeometry.delete();
|
|
1050
|
+
(_this__sphereGeometry = this._sphereGeometry) == null ? void 0 : _this__sphereGeometry.delete();
|
|
1051
|
+
(_this__capsuleGeometry = this._capsuleGeometry) == null ? void 0 : _this__capsuleGeometry.delete();
|
|
960
1052
|
this._physXSimulationCallbackInstance.delete();
|
|
961
1053
|
this._pxRaycastHit.delete();
|
|
962
1054
|
this._pxFilterData.flags.delete();
|
|
@@ -996,6 +1088,52 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
996
1088
|
});
|
|
997
1089
|
delete eventMap[id];
|
|
998
1090
|
};
|
|
1091
|
+
_proto._sweepSingle = function _sweepSingle(geometry, pose, direction, distance, onSweep, outHitResult) {
|
|
1092
|
+
distance = Math.min(distance, 3.4e38); // float32 max value limit in physx sweep
|
|
1093
|
+
var sweepCallback = {
|
|
1094
|
+
preFilter: function(filterData, index, actor) {
|
|
1095
|
+
if (onSweep(index)) {
|
|
1096
|
+
return 2; // eBLOCK
|
|
1097
|
+
} else {
|
|
1098
|
+
return 0; // eNONE
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
var pxSweepCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(sweepCallback);
|
|
1103
|
+
var pxSweepHit = new this._physXPhysics._physX.PxSweepHit();
|
|
1104
|
+
var result = this._pxScene.sweepSingle(geometry, pose, direction, distance, pxSweepHit, this._pxFilterData, pxSweepCallback);
|
|
1105
|
+
if (result && outHitResult != undefined) {
|
|
1106
|
+
var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
|
|
1107
|
+
var pxPosition = pxSweepHit.position, pxNormal = pxSweepHit.normal;
|
|
1108
|
+
position.set(pxPosition.x, pxPosition.y, pxPosition.z);
|
|
1109
|
+
normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
|
|
1110
|
+
outHitResult(pxSweepHit.getShape().getUUID(), pxSweepHit.distance, position, normal);
|
|
1111
|
+
}
|
|
1112
|
+
pxSweepCallback.delete();
|
|
1113
|
+
pxSweepHit.delete();
|
|
1114
|
+
return result;
|
|
1115
|
+
};
|
|
1116
|
+
_proto._overlapMultiple = function _overlapMultiple(geometry, pose, onOverlap) {
|
|
1117
|
+
var overlapCallback = {
|
|
1118
|
+
preFilter: function(filterData, index, actor) {
|
|
1119
|
+
return onOverlap(index) ? 2 : 0;
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
var pxOverlapCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(overlapCallback);
|
|
1123
|
+
var maxHits = 256;
|
|
1124
|
+
var hits = this._pxScene.overlapMultiple(geometry, pose, maxHits, this._pxFilterData, pxOverlapCallback);
|
|
1125
|
+
var result = PhysXPhysicsScene._tempShapeIDs;
|
|
1126
|
+
result.length = 0;
|
|
1127
|
+
if (hits) {
|
|
1128
|
+
// PhysX overlapMultiple returns a collection with size() method
|
|
1129
|
+
for(var i = 0, n = hits.size(); i < n; i++){
|
|
1130
|
+
result.push(hits.get(i).getShape().getUUID());
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
pxOverlapCallback.delete();
|
|
1134
|
+
hits == null ? void 0 : hits.delete();
|
|
1135
|
+
return result;
|
|
1136
|
+
};
|
|
999
1137
|
_proto._simulate = function _simulate(elapsedTime) {
|
|
1000
1138
|
this._pxScene.simulate(elapsedTime, true);
|
|
1001
1139
|
};
|
|
@@ -1034,7 +1172,13 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
1034
1172
|
return PhysXPhysicsScene;
|
|
1035
1173
|
}();
|
|
1036
1174
|
PhysXPhysicsScene._tempPosition = new Vector3();
|
|
1175
|
+
PhysXPhysicsScene._tempQuaternion = new Quaternion();
|
|
1037
1176
|
PhysXPhysicsScene._tempNormal = new Vector3();
|
|
1177
|
+
PhysXPhysicsScene._tempPose = {
|
|
1178
|
+
translation: new Vector3(),
|
|
1179
|
+
rotation: new Quaternion()
|
|
1180
|
+
};
|
|
1181
|
+
PhysXPhysicsScene._tempShapeIDs = [];
|
|
1038
1182
|
/**
|
|
1039
1183
|
* Trigger event to store interactive object ids and state.
|
|
1040
1184
|
*/ var TriggerEvent = function TriggerEvent(index1, index2) {
|
|
@@ -1318,7 +1462,7 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1318
1462
|
var _this;
|
|
1319
1463
|
_this = PhysXColliderShape.call(this, physXPhysics) || this, _this._maxScale = 1;
|
|
1320
1464
|
_this._radius = radius;
|
|
1321
|
-
_this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(
|
|
1465
|
+
_this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(radius * _this._maxScale);
|
|
1322
1466
|
_this._initialize(material, uniqueID);
|
|
1323
1467
|
_this._setLocalPose();
|
|
1324
1468
|
return _this;
|
|
@@ -1350,9 +1494,9 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1350
1494
|
this._initializeState = 0;
|
|
1351
1495
|
this._runTimeMode = runtimeMode;
|
|
1352
1496
|
var _runtimeUrls_wasmModeUrl;
|
|
1353
|
-
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1497
|
+
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*m04iQojeKRgAAAAASWAAAAgAehQnAQ/physx.release.js";
|
|
1354
1498
|
var _runtimeUrls_javaScriptModeUrl;
|
|
1355
|
-
this._downgradeModeUrl = (_runtimeUrls_javaScriptModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.javaScriptModeUrl) != null ? _runtimeUrls_javaScriptModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1499
|
+
this._downgradeModeUrl = (_runtimeUrls_javaScriptModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.javaScriptModeUrl) != null ? _runtimeUrls_javaScriptModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*13gEToqpJWcAAAAAgEAAAAgAehQnAQ/physx.release.downgrade.js";
|
|
1356
1500
|
}
|
|
1357
1501
|
var _proto = PhysXPhysics.prototype;
|
|
1358
1502
|
/**
|
|
@@ -1377,8 +1521,8 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1377
1521
|
var supported = function() {
|
|
1378
1522
|
try {
|
|
1379
1523
|
if ((typeof WebAssembly === "undefined" ? "undefined" : _type_of(WebAssembly)) === "object" && typeof WebAssembly.instantiate === "function") {
|
|
1380
|
-
var
|
|
1381
|
-
if (_instanceof(
|
|
1524
|
+
var wasmModule = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
|
|
1525
|
+
if (_instanceof(wasmModule, WebAssembly.Module)) return _instanceof(new WebAssembly.Instance(wasmModule), WebAssembly.Instance);
|
|
1382
1526
|
}
|
|
1383
1527
|
} catch (e) {}
|
|
1384
1528
|
return false;
|
|
@@ -1514,7 +1658,7 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1514
1658
|
}();
|
|
1515
1659
|
|
|
1516
1660
|
//@ts-ignore
|
|
1517
|
-
var version = "1.
|
|
1661
|
+
var version = "1.6.0-alpha.1";
|
|
1518
1662
|
console.log("Galacean Engine Physics PhysX Version: " + version);
|
|
1519
1663
|
|
|
1520
1664
|
export { PhysXPhysics, PhysXRuntimeMode, version };
|