@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/browser.js
CHANGED
|
@@ -152,12 +152,12 @@
|
|
|
152
152
|
};
|
|
153
153
|
return PhysXColliderShape;
|
|
154
154
|
}();
|
|
155
|
-
PhysXColliderShape._tempVector4 = new engine.Vector4();
|
|
156
155
|
PhysXColliderShape.halfSqrt = 0.70710678118655;
|
|
157
156
|
PhysXColliderShape.transform = {
|
|
158
157
|
translation: new engine.Vector3(),
|
|
159
158
|
rotation: null
|
|
160
159
|
};
|
|
160
|
+
PhysXColliderShape._tempVector4 = new engine.Vector4();
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
163
|
* Box collider shape in PhysX.
|
|
@@ -229,7 +229,7 @@
|
|
|
229
229
|
_this._halfHeight = height * 0.5;
|
|
230
230
|
_this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
|
|
231
231
|
_this._physXRotation.copyFrom(_this._axis);
|
|
232
|
-
_this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(
|
|
232
|
+
_this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(radius, _this._halfHeight);
|
|
233
233
|
_this._initialize(material, uniqueID);
|
|
234
234
|
_this._setLocalPose();
|
|
235
235
|
return _this;
|
|
@@ -820,6 +820,10 @@
|
|
|
820
820
|
function PhysXPhysicsScene(physXPhysics, physicsManager, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
821
821
|
var _this = this;
|
|
822
822
|
/** @internal */ this._pxControllerManager = null;
|
|
823
|
+
// Cached geometry objects for reuse
|
|
824
|
+
this._boxGeometry = null;
|
|
825
|
+
this._sphereGeometry = null;
|
|
826
|
+
this._capsuleGeometry = null;
|
|
823
827
|
this._currentEvents = new engine.DisorderedArray();
|
|
824
828
|
this._eventPool = [];
|
|
825
829
|
this._physXPhysics = physXPhysics;
|
|
@@ -933,7 +937,7 @@
|
|
|
933
937
|
* {@inheritDoc IPhysicsScene.raycast }
|
|
934
938
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
935
939
|
var _this = this, pxHitResult = _this._pxRaycastHit;
|
|
936
|
-
distance = Math.min(distance, 3.4e38); // float32 max value limit in
|
|
940
|
+
distance = Math.min(distance, 3.4e38); // float32 max value limit in physX raycast.
|
|
937
941
|
var raycastCallback = {
|
|
938
942
|
preFilter: function(filterData, index, actor) {
|
|
939
943
|
if (onRaycast(index)) {
|
|
@@ -941,8 +945,7 @@
|
|
|
941
945
|
} else {
|
|
942
946
|
return 0; // eNONE
|
|
943
947
|
}
|
|
944
|
-
}
|
|
945
|
-
postFilter: function(filterData, hit) {}
|
|
948
|
+
}
|
|
946
949
|
};
|
|
947
950
|
var pxRaycastCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback);
|
|
948
951
|
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, pxRaycastCallback);
|
|
@@ -957,10 +960,99 @@
|
|
|
957
960
|
return result;
|
|
958
961
|
};
|
|
959
962
|
/**
|
|
963
|
+
* {@inheritDoc IPhysicsScene.boxCast }
|
|
964
|
+
*/ _proto.boxCast = function boxCast(center, orientation, halfExtents, direction, distance, onSweep, outHitResult) {
|
|
965
|
+
if (!this._boxGeometry) {
|
|
966
|
+
this._boxGeometry = new this._physXPhysics._physX.PxBoxGeometry(halfExtents.x, halfExtents.y, halfExtents.z);
|
|
967
|
+
} else {
|
|
968
|
+
this._boxGeometry.halfExtents = halfExtents;
|
|
969
|
+
}
|
|
970
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
971
|
+
pose.translation.copyFrom(center);
|
|
972
|
+
pose.rotation.copyFrom(orientation);
|
|
973
|
+
return this._sweepSingle(this._boxGeometry, pose, direction, distance, onSweep, outHitResult);
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* {@inheritDoc IPhysicsScene.sphereCast }
|
|
977
|
+
*/ _proto.sphereCast = function sphereCast(center, radius, direction, distance, onSweep, outHitResult) {
|
|
978
|
+
if (!this._sphereGeometry) {
|
|
979
|
+
this._sphereGeometry = new this._physXPhysics._physX.PxSphereGeometry(radius);
|
|
980
|
+
} else {
|
|
981
|
+
this._sphereGeometry.radius = radius;
|
|
982
|
+
}
|
|
983
|
+
var tempQuat = PhysXPhysicsScene._tempQuaternion;
|
|
984
|
+
tempQuat.set(0, 0, 0, 1); // Identity quaternion
|
|
985
|
+
var pose = {
|
|
986
|
+
translation: center,
|
|
987
|
+
rotation: tempQuat
|
|
988
|
+
};
|
|
989
|
+
return this._sweepSingle(this._sphereGeometry, pose, direction, distance, onSweep, outHitResult);
|
|
990
|
+
};
|
|
991
|
+
/**
|
|
992
|
+
* {@inheritDoc IPhysicsScene.capsuleCast }
|
|
993
|
+
*/ _proto.capsuleCast = function capsuleCast(center, radius, height, orientation, direction, distance, onSweep, outHitResult) {
|
|
994
|
+
if (!this._capsuleGeometry) {
|
|
995
|
+
this._capsuleGeometry = new this._physXPhysics._physX.PxCapsuleGeometry(radius, height * 0.5);
|
|
996
|
+
} else {
|
|
997
|
+
this._capsuleGeometry.radius = radius;
|
|
998
|
+
this._capsuleGeometry.halfHeight = height * 0.5;
|
|
999
|
+
}
|
|
1000
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
1001
|
+
pose.translation.copyFrom(center);
|
|
1002
|
+
pose.rotation.copyFrom(orientation);
|
|
1003
|
+
return this._sweepSingle(this._capsuleGeometry, pose, direction, distance, onSweep, outHitResult);
|
|
1004
|
+
};
|
|
1005
|
+
/**
|
|
1006
|
+
* {@inheritDoc IPhysicsScene.overlapBoxAll }
|
|
1007
|
+
*/ _proto.overlapBoxAll = function overlapBoxAll(center, orientation, halfExtents, onOverlap) {
|
|
1008
|
+
if (!this._boxGeometry) {
|
|
1009
|
+
this._boxGeometry = new this._physXPhysics._physX.PxBoxGeometry(halfExtents.x, halfExtents.y, halfExtents.z);
|
|
1010
|
+
} else {
|
|
1011
|
+
this._boxGeometry.halfExtents = halfExtents;
|
|
1012
|
+
}
|
|
1013
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
1014
|
+
pose.translation.copyFrom(center);
|
|
1015
|
+
pose.rotation.copyFrom(orientation);
|
|
1016
|
+
return this._overlapMultiple(this._boxGeometry, pose, onOverlap);
|
|
1017
|
+
};
|
|
1018
|
+
/**
|
|
1019
|
+
* {@inheritDoc IPhysicsScene.overlapSphereAll }
|
|
1020
|
+
*/ _proto.overlapSphereAll = function overlapSphereAll(center, radius, onOverlap) {
|
|
1021
|
+
if (!this._sphereGeometry) {
|
|
1022
|
+
this._sphereGeometry = new this._physXPhysics._physX.PxSphereGeometry(radius);
|
|
1023
|
+
} else {
|
|
1024
|
+
this._sphereGeometry.radius = radius;
|
|
1025
|
+
}
|
|
1026
|
+
var tempQuat = PhysXPhysicsScene._tempQuaternion;
|
|
1027
|
+
tempQuat.set(0, 0, 0, 1);
|
|
1028
|
+
var pose = {
|
|
1029
|
+
translation: center,
|
|
1030
|
+
rotation: tempQuat
|
|
1031
|
+
};
|
|
1032
|
+
return this._overlapMultiple(this._sphereGeometry, pose, onOverlap);
|
|
1033
|
+
};
|
|
1034
|
+
/**
|
|
1035
|
+
* {@inheritDoc IPhysicsScene.overlapCapsuleAll }
|
|
1036
|
+
*/ _proto.overlapCapsuleAll = function overlapCapsuleAll(center, radius, height, orientation, onOverlap) {
|
|
1037
|
+
if (!this._capsuleGeometry) {
|
|
1038
|
+
this._capsuleGeometry = new this._physXPhysics._physX.PxCapsuleGeometry(radius, height * 0.5);
|
|
1039
|
+
} else {
|
|
1040
|
+
this._capsuleGeometry.radius = radius;
|
|
1041
|
+
this._capsuleGeometry.halfHeight = height * 0.5;
|
|
1042
|
+
}
|
|
1043
|
+
var pose = PhysXPhysicsScene._tempPose;
|
|
1044
|
+
pose.translation.copyFrom(center);
|
|
1045
|
+
pose.rotation.copyFrom(orientation);
|
|
1046
|
+
return this._overlapMultiple(this._capsuleGeometry, pose, onOverlap);
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
960
1049
|
* {@inheritDoc IPhysicsScene.destroy }
|
|
961
1050
|
*/ _proto.destroy = function destroy() {
|
|
962
|
-
var // Need to release the controller manager before release the scene.
|
|
1051
|
+
var _this__boxGeometry, _this__sphereGeometry, _this__capsuleGeometry, // Need to release the controller manager before release the scene.
|
|
963
1052
|
_this__pxControllerManager;
|
|
1053
|
+
(_this__boxGeometry = this._boxGeometry) == null ? void 0 : _this__boxGeometry.delete();
|
|
1054
|
+
(_this__sphereGeometry = this._sphereGeometry) == null ? void 0 : _this__sphereGeometry.delete();
|
|
1055
|
+
(_this__capsuleGeometry = this._capsuleGeometry) == null ? void 0 : _this__capsuleGeometry.delete();
|
|
964
1056
|
this._physXSimulationCallbackInstance.delete();
|
|
965
1057
|
this._pxRaycastHit.delete();
|
|
966
1058
|
this._pxFilterData.flags.delete();
|
|
@@ -1000,6 +1092,52 @@
|
|
|
1000
1092
|
});
|
|
1001
1093
|
delete eventMap[id];
|
|
1002
1094
|
};
|
|
1095
|
+
_proto._sweepSingle = function _sweepSingle(geometry, pose, direction, distance, onSweep, outHitResult) {
|
|
1096
|
+
distance = Math.min(distance, 3.4e38); // float32 max value limit in physx sweep
|
|
1097
|
+
var sweepCallback = {
|
|
1098
|
+
preFilter: function(filterData, index, actor) {
|
|
1099
|
+
if (onSweep(index)) {
|
|
1100
|
+
return 2; // eBLOCK
|
|
1101
|
+
} else {
|
|
1102
|
+
return 0; // eNONE
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
var pxSweepCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(sweepCallback);
|
|
1107
|
+
var pxSweepHit = new this._physXPhysics._physX.PxSweepHit();
|
|
1108
|
+
var result = this._pxScene.sweepSingle(geometry, pose, direction, distance, pxSweepHit, this._pxFilterData, pxSweepCallback);
|
|
1109
|
+
if (result && outHitResult != undefined) {
|
|
1110
|
+
var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
|
|
1111
|
+
var pxPosition = pxSweepHit.position, pxNormal = pxSweepHit.normal;
|
|
1112
|
+
position.set(pxPosition.x, pxPosition.y, pxPosition.z);
|
|
1113
|
+
normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
|
|
1114
|
+
outHitResult(pxSweepHit.getShape().getUUID(), pxSweepHit.distance, position, normal);
|
|
1115
|
+
}
|
|
1116
|
+
pxSweepCallback.delete();
|
|
1117
|
+
pxSweepHit.delete();
|
|
1118
|
+
return result;
|
|
1119
|
+
};
|
|
1120
|
+
_proto._overlapMultiple = function _overlapMultiple(geometry, pose, onOverlap) {
|
|
1121
|
+
var overlapCallback = {
|
|
1122
|
+
preFilter: function(filterData, index, actor) {
|
|
1123
|
+
return onOverlap(index) ? 2 : 0;
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
var pxOverlapCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(overlapCallback);
|
|
1127
|
+
var maxHits = 256;
|
|
1128
|
+
var hits = this._pxScene.overlapMultiple(geometry, pose, maxHits, this._pxFilterData, pxOverlapCallback);
|
|
1129
|
+
var result = PhysXPhysicsScene._tempShapeIDs;
|
|
1130
|
+
result.length = 0;
|
|
1131
|
+
if (hits) {
|
|
1132
|
+
// PhysX overlapMultiple returns a collection with size() method
|
|
1133
|
+
for(var i = 0, n = hits.size(); i < n; i++){
|
|
1134
|
+
result.push(hits.get(i).getShape().getUUID());
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
pxOverlapCallback.delete();
|
|
1138
|
+
hits == null ? void 0 : hits.delete();
|
|
1139
|
+
return result;
|
|
1140
|
+
};
|
|
1003
1141
|
_proto._simulate = function _simulate(elapsedTime) {
|
|
1004
1142
|
this._pxScene.simulate(elapsedTime, true);
|
|
1005
1143
|
};
|
|
@@ -1038,7 +1176,13 @@
|
|
|
1038
1176
|
return PhysXPhysicsScene;
|
|
1039
1177
|
}();
|
|
1040
1178
|
PhysXPhysicsScene._tempPosition = new engine.Vector3();
|
|
1179
|
+
PhysXPhysicsScene._tempQuaternion = new engine.Quaternion();
|
|
1041
1180
|
PhysXPhysicsScene._tempNormal = new engine.Vector3();
|
|
1181
|
+
PhysXPhysicsScene._tempPose = {
|
|
1182
|
+
translation: new engine.Vector3(),
|
|
1183
|
+
rotation: new engine.Quaternion()
|
|
1184
|
+
};
|
|
1185
|
+
PhysXPhysicsScene._tempShapeIDs = [];
|
|
1042
1186
|
/**
|
|
1043
1187
|
* Trigger event to store interactive object ids and state.
|
|
1044
1188
|
*/ var TriggerEvent = function TriggerEvent(index1, index2) {
|
|
@@ -1322,7 +1466,7 @@
|
|
|
1322
1466
|
var _this;
|
|
1323
1467
|
_this = PhysXColliderShape.call(this, physXPhysics) || this, _this._maxScale = 1;
|
|
1324
1468
|
_this._radius = radius;
|
|
1325
|
-
_this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(
|
|
1469
|
+
_this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(radius * _this._maxScale);
|
|
1326
1470
|
_this._initialize(material, uniqueID);
|
|
1327
1471
|
_this._setLocalPose();
|
|
1328
1472
|
return _this;
|
|
@@ -1354,9 +1498,9 @@
|
|
|
1354
1498
|
this._initializeState = 0;
|
|
1355
1499
|
this._runTimeMode = runtimeMode;
|
|
1356
1500
|
var _runtimeUrls_wasmModeUrl;
|
|
1357
|
-
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1501
|
+
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";
|
|
1358
1502
|
var _runtimeUrls_javaScriptModeUrl;
|
|
1359
|
-
this._downgradeModeUrl = (_runtimeUrls_javaScriptModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.javaScriptModeUrl) != null ? _runtimeUrls_javaScriptModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1503
|
+
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";
|
|
1360
1504
|
}
|
|
1361
1505
|
var _proto = PhysXPhysics.prototype;
|
|
1362
1506
|
/**
|
|
@@ -1381,8 +1525,8 @@
|
|
|
1381
1525
|
var supported = function() {
|
|
1382
1526
|
try {
|
|
1383
1527
|
if ((typeof WebAssembly === "undefined" ? "undefined" : _type_of(WebAssembly)) === "object" && typeof WebAssembly.instantiate === "function") {
|
|
1384
|
-
var
|
|
1385
|
-
if (_instanceof(
|
|
1528
|
+
var wasmModule = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
|
|
1529
|
+
if (_instanceof(wasmModule, WebAssembly.Module)) return _instanceof(new WebAssembly.Instance(wasmModule), WebAssembly.Instance);
|
|
1386
1530
|
}
|
|
1387
1531
|
} catch (e) {}
|
|
1388
1532
|
return false;
|
|
@@ -1518,7 +1662,7 @@
|
|
|
1518
1662
|
}();
|
|
1519
1663
|
|
|
1520
1664
|
//@ts-ignore
|
|
1521
|
-
var version = "1.
|
|
1665
|
+
var version = "1.6.0-alpha.1";
|
|
1522
1666
|
console.log("Galacean Engine Physics PhysX Version: " + version);
|
|
1523
1667
|
|
|
1524
1668
|
exports.PhysXPhysics = PhysXPhysics;
|