@galacean/engine-physics-physx 2.0.0-alpha.2 → 2.0.0-alpha.5

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/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Vector3, Vector4, MathUtil, Quaternion, DisorderedArray } from '@galacean/engine';
1
+ import { Vector3, Vector4, MathUtil, Quaternion, DisorderedArray, MeshColliderShapeCookingFlag, SystemInfo } from '@galacean/engine';
2
2
 
3
3
  function _instanceof(left, right) {
4
4
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
@@ -6,12 +6,6 @@ function _instanceof(left, right) {
6
6
  } else return left instanceof right;
7
7
  }
8
8
 
9
- function _type_of(obj) {
10
- "@swc/helpers - typeof";
11
-
12
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
13
- }
14
-
15
9
  function _set_prototype_of(o, p) {
16
10
  _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
17
11
  o.__proto__ = p;
@@ -1216,9 +1210,9 @@ PhysXPhysicsScene._tempShapeIDs = [];
1216
1210
  /**
1217
1211
  * PhysX runtime mode.
1218
1212
  */ var PhysXRuntimeMode = /*#__PURE__*/ function(PhysXRuntimeMode) {
1219
- /** Use webAssembly mode first, if WebAssembly mode is not supported, roll back to JavaScript mode. */ PhysXRuntimeMode[PhysXRuntimeMode["Auto"] = 0] = "Auto";
1213
+ /** Use WebAssembly SIMD mode first, then WebAssembly as fallback. */ PhysXRuntimeMode[PhysXRuntimeMode["Auto"] = 0] = "Auto";
1220
1214
  /** WebAssembly mode. */ PhysXRuntimeMode[PhysXRuntimeMode["WebAssembly"] = 1] = "WebAssembly";
1221
- /** JavaScript mode. */ PhysXRuntimeMode[PhysXRuntimeMode["JavaScript"] = 2] = "JavaScript";
1215
+ /** WebAssembly SIMD mode. */ PhysXRuntimeMode[PhysXRuntimeMode["WebAssemblySIMD"] = 2] = "WebAssemblySIMD";
1222
1216
  return PhysXRuntimeMode;
1223
1217
  }({});
1224
1218
 
@@ -1450,62 +1444,62 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1450
1444
  return PhysXSpringJoint;
1451
1445
  }(PhysXJoint);
1452
1446
 
1453
- /** TriangleMesh flag: eDOUBLE_SIDED = 2 (1<<1) */ var DOUBLE_SIDED_FLAG = 2;
1454
- /** ConvexMesh flag: eTIGHT_BOUNDS = 1 (1<<0) */ var TIGHT_BOUNDS_FLAG = 1;
1447
+ function _assert_this_initialized(self) {
1448
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1449
+
1450
+ return self;
1451
+ }
1452
+
1453
+ function _type_of(obj) {
1454
+ "@swc/helpers - typeof";
1455
+
1456
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1457
+ }
1458
+
1459
+ function _possible_constructor_return(self, call) {
1460
+ if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
1461
+
1462
+ return _assert_this_initialized(self);
1463
+ }
1464
+
1455
1465
  /**
1456
1466
  * Mesh collider shape in PhysX.
1457
1467
  */ var PhysXMeshColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
1458
1468
  _inherits(PhysXMeshColliderShape, PhysXColliderShape);
1459
- function PhysXMeshColliderShape(physXPhysics, uniqueID, vertices, vertexCount, indices, isConvex, material) {
1469
+ function PhysXMeshColliderShape(physXPhysics, uniqueID, positions, indices, isConvex, material, cookingFlags) {
1460
1470
  var _this;
1461
- _this = PhysXColliderShape.call(this, physXPhysics) || this, _this._pxMesh = null, _this._doubleSided = false, _this._tightBounds = true;
1471
+ _this = PhysXColliderShape.call(this, physXPhysics) || this, _this._pxMesh = null;
1462
1472
  _this._isConvex = isConvex;
1463
- _this._vertices = vertices;
1464
- _this._vertexCount = vertexCount;
1465
- _this._indices = indices;
1466
- _this._createMeshAndShape(material, uniqueID);
1473
+ if (!_this._cookMesh(positions, indices, cookingFlags)) {
1474
+ return _possible_constructor_return(_this);
1475
+ }
1476
+ var physX = physXPhysics._physX, physics = physXPhysics._pxPhysics;
1477
+ var _this__worldScale = _this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
1478
+ var shapeFlags = ShapeFlag.SCENE_QUERY_SHAPE | ShapeFlag.SIMULATION_SHAPE;
1479
+ var meshFlag = isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
1480
+ var createShapeFn = isConvex ? physX.createConvexMeshShape : physX.createTriMeshShape;
1481
+ _this._pxShape = createShapeFn(_this._pxMesh, scaleX, scaleY, scaleZ, meshFlag, shapeFlags, material._pxMaterial, physics);
1482
+ _this._id = uniqueID;
1483
+ _this._pxMaterial = material._pxMaterial;
1484
+ _this._pxShape.setUUID(uniqueID);
1467
1485
  _this._setLocalPose();
1468
1486
  return _this;
1469
1487
  }
1470
1488
  var _proto = PhysXMeshColliderShape.prototype;
1471
1489
  /**
1472
1490
  * {@inheritDoc IMeshColliderShape.setMeshData }
1473
- */ _proto.setMeshData = function setMeshData(vertices, vertexCount, indices, isConvex) {
1474
- // Save old resources
1475
- var oldMesh = this._pxMesh;
1476
- var oldGeometry = this._pxGeometry;
1477
- // Update data and create new mesh (may throw on failure)
1491
+ */ _proto.setMeshData = function setMeshData(positions, indices, isConvex, cookingFlags) {
1492
+ var _this__pxMesh, _this__pxGeometry;
1493
+ (_this__pxMesh = this._pxMesh) == null ? void 0 : _this__pxMesh.release();
1494
+ (_this__pxGeometry = this._pxGeometry) == null ? void 0 : _this__pxGeometry.delete();
1478
1495
  this._pxMesh = null;
1479
1496
  this._pxGeometry = null;
1480
1497
  this._isConvex = isConvex;
1481
- this._vertices = vertices;
1482
- this._vertexCount = vertexCount;
1483
- this._indices = indices;
1484
- this._createMesh();
1485
- this._pxShape.setGeometry(this._pxGeometry);
1486
- // Release old resources only after successful creation
1487
- if (oldMesh) {
1488
- oldMesh.release();
1489
- }
1490
- if (oldGeometry) {
1491
- oldGeometry.delete();
1492
- }
1493
- };
1494
- /**
1495
- * {@inheritDoc IMeshColliderShape.setDoubleSided }
1496
- */ _proto.setDoubleSided = function setDoubleSided(value) {
1497
- this._doubleSided = value;
1498
- if (!this._isConvex && this._pxMesh) {
1499
- this._updateGeometry();
1500
- }
1501
- };
1502
- /**
1503
- * {@inheritDoc IMeshColliderShape.setTightBounds }
1504
- */ _proto.setTightBounds = function setTightBounds(value) {
1505
- this._tightBounds = value;
1506
- if (this._isConvex && this._pxMesh) {
1507
- this._updateGeometry();
1498
+ if (!this._cookMesh(positions, indices, cookingFlags)) {
1499
+ return false;
1508
1500
  }
1501
+ this._pxShape.setGeometry(this._pxGeometry);
1502
+ return true;
1509
1503
  };
1510
1504
  /**
1511
1505
  * {@inheritDoc IColliderShape.setWorldScale }
@@ -1516,103 +1510,107 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1516
1510
  /**
1517
1511
  * {@inheritDoc IColliderShape.destroy }
1518
1512
  */ _proto.destroy = function destroy() {
1519
- this._releaseMesh();
1513
+ var _this__pxMesh;
1514
+ (_this__pxMesh = this._pxMesh) == null ? void 0 : _this__pxMesh.release();
1520
1515
  PhysXColliderShape.prototype.destroy.call(this);
1521
1516
  };
1522
- _proto._createMeshAndShape = function _createMeshAndShape(material, uniqueID) {
1523
- var physX = this._physXPhysics._physX;
1524
- var physics = this._physXPhysics._pxPhysics;
1525
- var shapeFlags = ShapeFlag.SCENE_QUERY_SHAPE | ShapeFlag.SIMULATION_SHAPE;
1526
- this._createMesh();
1527
- // Create shape with material
1517
+ _proto._cookMesh = function _cookMesh(positions, indices, cookingFlags) {
1518
+ var _this__physXPhysics = this._physXPhysics, physX = _this__physXPhysics._physX, physics = _this__physXPhysics._pxPhysics, cooking = _this__physXPhysics._pxCooking, cookingParams = _this__physXPhysics._pxCookingParams;
1519
+ // Apply per-shape cooking flags
1520
+ var preprocessFlags = 0;
1521
+ if (cookingFlags & MeshColliderShapeCookingFlag.VertexWelding) {
1522
+ preprocessFlags |= 1; // eWELD_VERTICES
1523
+ }
1524
+ if (!(cookingFlags & MeshColliderShapeCookingFlag.Cleaning)) {
1525
+ preprocessFlags |= 2; // eDISABLE_CLEAN_MESH
1526
+ }
1527
+ physX.setCookingMeshPreprocessParams(cookingParams, preprocessFlags);
1528
+ cooking.setParams(cookingParams);
1529
+ var verticesPtr = this._allocatePositions(positions);
1528
1530
  if (this._isConvex) {
1529
- this._pxShape = physX.createConvexMeshShape(this._pxMesh, this._worldScale.x, this._worldScale.y, this._worldScale.z, this._tightBounds ? TIGHT_BOUNDS_FLAG : 0, shapeFlags, material._pxMaterial, physics);
1531
+ this._pxMesh = cooking.createConvexMesh(verticesPtr, positions.length, physics);
1532
+ physX._free(verticesPtr);
1533
+ if (!this._pxMesh) {
1534
+ this._logConvexCookingError(physX);
1535
+ return false;
1536
+ }
1530
1537
  } else {
1531
- this._pxShape = physX.createTriMeshShape(this._pxMesh, this._worldScale.x, this._worldScale.y, this._worldScale.z, this._doubleSided ? DOUBLE_SIDED_FLAG : 0, shapeFlags, material._pxMaterial, physics);
1532
- }
1533
- this._id = uniqueID;
1534
- this._pxMaterial = material._pxMaterial;
1535
- this._pxShape.setUUID(uniqueID);
1536
- };
1537
- _proto._createMesh = function _createMesh() {
1538
- var physX = this._physXPhysics._physX;
1539
- var physics = this._physXPhysics._pxPhysics;
1540
- var cooking = this._physXPhysics._pxCooking;
1541
- var verticesPtr = this._allocateVertices();
1542
- var indicesPtr = 0;
1543
- try {
1544
- if (this._isConvex) {
1545
- this._pxMesh = cooking.createConvexMesh(verticesPtr, this._vertexCount, physics);
1546
- if (!this._pxMesh) {
1547
- throw new Error("Failed to create convex mesh. Check if vertex count <= 255 and geometry is valid.");
1548
- }
1549
- this._pxGeometry = physX.createConvexMeshGeometry(this._pxMesh, this._worldScale.x, this._worldScale.y, this._worldScale.z, this._tightBounds ? TIGHT_BOUNDS_FLAG : 0);
1550
- } else {
1551
- if (!this._indices) {
1552
- throw new Error("Triangle mesh requires indices");
1553
- }
1554
- var _this__allocateIndices = this._allocateIndices(), ptr = _this__allocateIndices.ptr, isU16 = _this__allocateIndices.isU16, triangleCount = _this__allocateIndices.triangleCount;
1555
- indicesPtr = ptr;
1556
- this._pxMesh = cooking.createTriMesh(verticesPtr, this._vertexCount, indicesPtr, triangleCount, isU16, physics);
1557
- if (!this._pxMesh) {
1558
- throw new Error("Failed to create triangle mesh. Check if geometry is valid.");
1559
- }
1560
- this._pxGeometry = physX.createTriMeshGeometry(this._pxMesh, this._worldScale.x, this._worldScale.y, this._worldScale.z, this._doubleSided ? DOUBLE_SIDED_FLAG : 0);
1538
+ if (!indices) {
1539
+ physX._free(verticesPtr);
1540
+ console.error("PhysXMeshColliderShape: Triangle mesh requires indices.");
1541
+ return false;
1561
1542
  }
1562
- } finally{
1543
+ var isU32 = _instanceof(indices, Uint32Array);
1544
+ var indicesPtr = this._allocateIndices(indices, isU32);
1545
+ this._pxMesh = cooking.createTriMesh(verticesPtr, positions.length, indicesPtr, indices.length / 3, !isU32, physics);
1563
1546
  physX._free(verticesPtr);
1564
- if (indicesPtr) {
1565
- physX._free(indicesPtr);
1547
+ physX._free(indicesPtr);
1548
+ if (!this._pxMesh) {
1549
+ this._logTriMeshCookingError(physX);
1550
+ return false;
1566
1551
  }
1567
- // Release JS memory after copying to WASM
1568
- this._vertices = null;
1569
- this._indices = null;
1570
1552
  }
1553
+ var _this__worldScale = this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
1554
+ var meshFlag = this._isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
1555
+ this._pxGeometry = this._isConvex ? physX.createConvexMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag) : physX.createTriMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag);
1556
+ return true;
1571
1557
  };
1572
- _proto._allocateVertices = function _allocateVertices() {
1558
+ _proto._logConvexCookingError = function _logConvexCookingError(physX) {
1559
+ switch(physX.getLastConvexCookingResult()){
1560
+ case 1:
1561
+ console.error("PhysXMeshColliderShape: Failed to create convex mesh. Could not find 4 vertices that do not form a zero-area triangle.");
1562
+ break;
1563
+ case 2:
1564
+ console.error("PhysXMeshColliderShape: Failed to create convex mesh within the maximum polygons limit (256). Consider simplifying the mesh.");
1565
+ break;
1566
+ default:
1567
+ console.error("PhysXMeshColliderShape: Failed to create convex mesh. The input geometry may be invalid.");
1568
+ break;
1569
+ }
1570
+ };
1571
+ _proto._logTriMeshCookingError = function _logTriMeshCookingError(physX) {
1572
+ switch(physX.getLastTriMeshCookingResult()){
1573
+ case 1:
1574
+ console.error("PhysXMeshColliderShape: Failed to create triangle mesh. One of the triangles is too large. Consider tessellating large triangles.");
1575
+ break;
1576
+ default:
1577
+ console.error("PhysXMeshColliderShape: Failed to create triangle mesh. The input geometry may be invalid.");
1578
+ break;
1579
+ }
1580
+ };
1581
+ _proto._allocatePositions = function _allocatePositions(positions) {
1573
1582
  var physX = this._physXPhysics._physX;
1574
- var ptr = physX._malloc(this._vertexCount * 3 * 4);
1575
- var view = new Float32Array(physX.HEAPF32.buffer, ptr, this._vertexCount * 3);
1576
- view.set(this._vertices);
1583
+ var length = positions.length;
1584
+ var ptr = physX._malloc(length * 3 * 4);
1585
+ var view = new Float32Array(physX.HEAPF32.buffer, ptr, length * 3);
1586
+ for(var i = 0, offset = 0; i < length; i++, offset += 3){
1587
+ positions[i].copyToArray(view, offset);
1588
+ }
1577
1589
  return ptr;
1578
1590
  };
1579
- _proto._allocateIndices = function _allocateIndices() {
1591
+ _proto._allocateIndices = function _allocateIndices(indices, isU32) {
1580
1592
  var physX = this._physXPhysics._physX;
1581
- var indices = this._indices;
1582
- var isU16 = _instanceof(indices, Uint16Array);
1583
- var triangleCount = indices.length / 3;
1584
- var bytesPerIndex = isU16 ? 2 : 4;
1585
- var ptr = physX._malloc(indices.length * bytesPerIndex);
1586
- if (isU16) {
1587
- new Uint16Array(physX.HEAPU16.buffer, ptr, indices.length).set(indices);
1588
- } else {
1589
- new Uint32Array(physX.HEAPU32.buffer, ptr, indices.length).set(indices);
1590
- }
1591
- return {
1592
- ptr: ptr,
1593
- isU16: isU16,
1594
- triangleCount: triangleCount
1595
- };
1593
+ // Uint8Array and Uint16Array both write as Uint16 (PhysX minimum index size)
1594
+ var TypedArrayCtor = isU32 ? Uint32Array : Uint16Array;
1595
+ var heap = isU32 ? physX.HEAPU32 : physX.HEAPU16;
1596
+ var ptr = physX._malloc(indices.length * TypedArrayCtor.BYTES_PER_ELEMENT);
1597
+ new TypedArrayCtor(heap.buffer, ptr, indices.length).set(indices);
1598
+ return ptr;
1596
1599
  };
1597
1600
  _proto._updateGeometry = function _updateGeometry() {
1601
+ if (!this._pxMesh) return;
1598
1602
  var physX = this._physXPhysics._physX;
1599
- var newGeometry = this._isConvex ? physX.createConvexMeshGeometry(this._pxMesh, this._worldScale.x, this._worldScale.y, this._worldScale.z, this._tightBounds ? TIGHT_BOUNDS_FLAG : 0) : physX.createTriMeshGeometry(this._pxMesh, this._worldScale.x, this._worldScale.y, this._worldScale.z, this._doubleSided ? DOUBLE_SIDED_FLAG : 0);
1603
+ var _this__worldScale = this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
1604
+ var meshFlag = this._isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
1605
+ var newGeometry = this._isConvex ? physX.createConvexMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag) : physX.createTriMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag);
1600
1606
  this._pxGeometry.delete();
1601
1607
  this._pxGeometry = newGeometry;
1602
1608
  this._pxShape.setGeometry(this._pxGeometry);
1603
1609
  };
1604
- _proto._releaseMesh = function _releaseMesh() {
1605
- if (this._pxMesh) {
1606
- this._pxMesh.release();
1607
- this._pxMesh = null;
1608
- }
1609
- if (this._pxGeometry) {
1610
- this._pxGeometry.delete();
1611
- this._pxGeometry = null;
1612
- }
1613
- };
1614
1610
  return PhysXMeshColliderShape;
1615
1611
  }(PhysXColliderShape);
1612
+ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
1613
+ ;
1616
1614
 
1617
1615
  /**
1618
1616
  * Plane collider shape in PhysX.
@@ -1670,10 +1668,10 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1670
1668
  if (runtimeMode === void 0) runtimeMode = PhysXRuntimeMode.Auto;
1671
1669
  this._initializeState = 0;
1672
1670
  this._runTimeMode = runtimeMode;
1671
+ var _runtimeUrls_wasmSIMDModeUrl;
1672
+ this._wasmSIMDModeUrl = (_runtimeUrls_wasmSIMDModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmSIMDModeUrl) != null ? _runtimeUrls_wasmSIMDModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*FHYHS4_ZL5UAAAAAQ4AAAAgAehQnAQ/physx.release.simd.js";
1673
1673
  var _runtimeUrls_wasmModeUrl;
1674
- this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*8pf0QJKeUXsAAAAASWAAAAgAehQnAQ/physx.release.js";
1675
- var _runtimeUrls_javaScriptModeUrl;
1676
- this._downgradeModeUrl = (_runtimeUrls_javaScriptModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.javaScriptModeUrl) != null ? _runtimeUrls_javaScriptModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*PLtBTLf8Sm0AAAAAgFAAAAgAehQnAQ/physx.release.downgrade.js";
1674
+ this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*2fv0RLMK1d0AAAAAQ4AAAAgAehQnAQ/physx.release.js";
1677
1675
  }
1678
1676
  var _proto = PhysXPhysics.prototype;
1679
1677
  /**
@@ -1687,6 +1685,7 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1687
1685
  } else if (this._initializeState === 1) {
1688
1686
  return this._initializePromise;
1689
1687
  }
1688
+ this._initializeState = 1;
1690
1689
  var runtimeMode = this._runTimeMode;
1691
1690
  var scriptPromise = new Promise(function(resolve, reject) {
1692
1691
  var script = document.createElement("script");
@@ -1695,30 +1694,18 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1695
1694
  script.onload = resolve;
1696
1695
  script.onerror = reject;
1697
1696
  if (runtimeMode == PhysXRuntimeMode.Auto) {
1698
- var supported = function() {
1699
- try {
1700
- if ((typeof WebAssembly === "undefined" ? "undefined" : _type_of(WebAssembly)) === "object" && typeof WebAssembly.instantiate === "function") {
1701
- var wasmModule = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
1702
- if (_instanceof(wasmModule, WebAssembly.Module)) return _instanceof(new WebAssembly.Instance(wasmModule), WebAssembly.Instance);
1703
- }
1704
- } catch (e) {}
1705
- return false;
1706
- }();
1707
- if (supported) {
1708
- runtimeMode = PhysXRuntimeMode.WebAssembly;
1709
- } else {
1710
- runtimeMode = PhysXRuntimeMode.JavaScript;
1711
- }
1697
+ runtimeMode = SystemInfo._detectSIMDSupported() ? PhysXRuntimeMode.WebAssemblySIMD : PhysXRuntimeMode.WebAssembly;
1712
1698
  }
1713
- if (runtimeMode == PhysXRuntimeMode.JavaScript) {
1714
- script.src = _this._downgradeModeUrl;
1715
- } else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
1699
+ if (runtimeMode == PhysXRuntimeMode.WebAssemblySIMD) {
1700
+ script.src = _this._wasmSIMDModeUrl;
1701
+ } else {
1716
1702
  script.src = _this._wasmModeUrl;
1717
1703
  }
1718
1704
  });
1719
1705
  var initializePromise = new Promise(function(resolve, reject) {
1720
1706
  scriptPromise.then(function() {
1721
1707
  return window.PHYSX().then(function(PHYSX) {
1708
+ _this._runTimeMode = runtimeMode;
1722
1709
  _this._init(PHYSX);
1723
1710
  _this._initializeState = 2;
1724
1711
  _this._initializePromise = null;
@@ -1743,18 +1730,6 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1743
1730
  this._tolerancesScale.delete();
1744
1731
  };
1745
1732
  /**
1746
- * Set cooking parameters for mesh colliders.
1747
- * @param params - Cooking parameters
1748
- */ _proto.setCookingParams = function setCookingParams(params) {
1749
- var cp = this._pxCookingParams;
1750
- if (params.meshWeldTolerance !== undefined) {
1751
- cp.meshWeldTolerance = params.meshWeldTolerance;
1752
- }
1753
- if (params.meshPreprocessParams !== undefined) {
1754
- this._physX.setCookingMeshPreprocessParams(cp, params.meshPreprocessParams);
1755
- }
1756
- };
1757
- /**
1758
1733
  * {@inheritDoc IPhysics.createPhysicsManager }
1759
1734
  */ _proto.createPhysicsManager = function createPhysicsManager() {
1760
1735
  return new PhysXPhysicsManager();
@@ -1807,8 +1782,9 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1807
1782
  };
1808
1783
  /**
1809
1784
  * {@inheritDoc IPhysics.createMeshColliderShape }
1810
- */ _proto.createMeshColliderShape = function createMeshColliderShape(uniqueID, vertices, vertexCount, indices, isConvex, material) {
1811
- return new PhysXMeshColliderShape(this, uniqueID, vertices, vertexCount, indices, isConvex, material);
1785
+ */ _proto.createMeshColliderShape = function createMeshColliderShape(uniqueID, positions, indices, isConvex, material, cookingFlags) {
1786
+ var shape = new PhysXMeshColliderShape(this, uniqueID, positions, indices, isConvex, material, cookingFlags);
1787
+ return shape._pxShape ? shape : null;
1812
1788
  };
1813
1789
  /**
1814
1790
  * {@inheritDoc IPhysics.createFixedJoint }
@@ -1845,9 +1821,12 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1845
1821
  physX.PxInitExtensions(pxPhysics, null);
1846
1822
  // Initialize cooking for mesh colliders
1847
1823
  var cookingParams = new physX.PxCookingParams(tolerancesScale);
1848
- // Set default cooking params (WeldVertices + small tolerance)
1849
- physX.setCookingMeshPreprocessParams(cookingParams, 1); // WeldVertices = 1
1824
+ physX.setCookingMeshPreprocessParams(cookingParams, 1); // eWELD_VERTICES
1850
1825
  cookingParams.meshWeldTolerance = 0.001;
1826
+ // BVH34 midphase requires SSE2; SIMD WASM provides SSE2 via WASM SIMD
1827
+ if (this._runTimeMode === PhysXRuntimeMode.WebAssemblySIMD) {
1828
+ physX.setCookingMidphaseType(cookingParams, 1); // eBVH34
1829
+ }
1851
1830
  var pxCooking = physX.PxCreateCooking(version, pxFoundation, cookingParams);
1852
1831
  this._physX = physX;
1853
1832
  this._pxFoundation = pxFoundation;
@@ -1861,34 +1840,9 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1861
1840
  return PhysXPhysics;
1862
1841
  }();
1863
1842
 
1864
- /**
1865
- * Mesh preprocessing flags for cooking options.
1866
- * @remarks These flags control how the mesh is preprocessed during cooking.
1867
- */ var MeshPreprocessingFlag = /*#__PURE__*/ function(MeshPreprocessingFlag) {
1868
- /**
1869
- * When set, mesh welding is performed.
1870
- * Vertices within the meshWeldTolerance distance will be merged.
1871
- * Clean mesh must be enabled for this to work.
1872
- */ MeshPreprocessingFlag[MeshPreprocessingFlag["WeldVertices"] = 1] = "WeldVertices";
1873
- /**
1874
- * When set, mesh cleaning is disabled.
1875
- * This makes cooking faster but requires the input mesh to be valid.
1876
- * When clean mesh is disabled, vertex welding is also disabled.
1877
- */ MeshPreprocessingFlag[MeshPreprocessingFlag["DisableCleanMesh"] = 2] = "DisableCleanMesh";
1878
- /**
1879
- * When set, active edges computation is disabled.
1880
- * This makes cooking faster but may slow down contact generation.
1881
- */ MeshPreprocessingFlag[MeshPreprocessingFlag["DisableActiveEdgesPrecompute"] = 4] = "DisableActiveEdgesPrecompute";
1882
- /**
1883
- * When set, 32-bit indices will always be used regardless of triangle count.
1884
- * By default, 16-bit indices are used for meshes with <= 65535 triangles.
1885
- */ MeshPreprocessingFlag[MeshPreprocessingFlag["Force32BitIndices"] = 8] = "Force32BitIndices";
1886
- return MeshPreprocessingFlag;
1887
- }({});
1888
-
1889
1843
  //@ts-ignore
1890
- var version = "2.0.0-alpha.2";
1844
+ var version = "2.0.0-alpha.5";
1891
1845
  console.log("Galacean Engine Physics PhysX Version: " + version);
1892
1846
 
1893
- export { MeshPreprocessingFlag, PhysXPhysics, PhysXRuntimeMode, version };
1847
+ export { PhysXPhysics, PhysXRuntimeMode, version };
1894
1848
  //# sourceMappingURL=module.js.map