@galacean/engine-physics-physx 0.0.0-experimental-2.0-skill.0 → 0.0.0-experimental-2.0-migrate.7
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 +192 -59
- 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 +192 -59
- package/dist/main.js.map +1 -1
- package/dist/module.js +192 -59
- 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 +4 -4
- package/types/PhysXDynamicCollider.d.ts +38 -1
- package/types/PhysXPhysics.d.ts +28 -1
- package/types/PhysXPhysicsScene.d.ts +5 -0
- package/types/index.d.ts +1 -0
package/dist/module.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Vector3, Vector4, MathUtil, Quaternion, DisorderedArray, MeshColliderShapeCookingFlag, SystemInfo } from '@galacean/engine';
|
|
2
2
|
|
|
3
|
+
function _type_of(obj) {
|
|
4
|
+
"@swc/helpers - typeof";
|
|
5
|
+
|
|
6
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
function _instanceof(left, right) {
|
|
4
10
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
5
11
|
return !!right[Symbol.hasInstance](left);
|
|
@@ -39,7 +45,7 @@ function _inherits(subClass, superClass) {
|
|
|
39
45
|
*/ var PhysXColliderShape = /*#__PURE__*/ function() {
|
|
40
46
|
function PhysXColliderShape(physXPhysics) {
|
|
41
47
|
/** @internal */ this._controllers = new DisorderedArray();
|
|
42
|
-
/** @internal */ this.
|
|
48
|
+
/** @internal */ this._contactOffset = 0.02;
|
|
43
49
|
/** @internal */ this._worldScale = new Vector3(1, 1, 1);
|
|
44
50
|
/** @internal */ this._position = new Vector3();
|
|
45
51
|
/** @internal */ this._rotation = new Vector3();
|
|
@@ -47,6 +53,7 @@ function _inherits(subClass, superClass) {
|
|
|
47
53
|
this._physXRotation = new Quaternion();
|
|
48
54
|
this._shapeFlags = 2 | 1;
|
|
49
55
|
this._physXPhysics = physXPhysics;
|
|
56
|
+
this._contactOffset = physXPhysics.getDefaultContactOffset();
|
|
50
57
|
}
|
|
51
58
|
var _proto = PhysXColliderShape.prototype;
|
|
52
59
|
/**
|
|
@@ -84,7 +91,7 @@ function _inherits(subClass, superClass) {
|
|
|
84
91
|
* {@inheritDoc IColliderShape.setContactOffset }
|
|
85
92
|
* @default 0.02f * PxTolerancesScale::length
|
|
86
93
|
*/ _proto.setContactOffset = function setContactOffset(offset) {
|
|
87
|
-
this.
|
|
94
|
+
this._contactOffset = offset;
|
|
88
95
|
var controllers = this._controllers;
|
|
89
96
|
if (controllers.length) {
|
|
90
97
|
for(var i = 0, n = controllers.length; i < n; i++){
|
|
@@ -425,7 +432,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
425
432
|
this._pxManager && this._createPXController(this._pxManager, shape);
|
|
426
433
|
this._shape = shape;
|
|
427
434
|
shape._controllers.add(this);
|
|
428
|
-
(_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape.
|
|
435
|
+
(_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape._contactOffset);
|
|
429
436
|
(_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
|
|
430
437
|
};
|
|
431
438
|
/**
|
|
@@ -579,7 +586,15 @@ PhysXCollider._tempTransform = {
|
|
|
579
586
|
_inherits(PhysXDynamicCollider, PhysXCollider);
|
|
580
587
|
function PhysXDynamicCollider(physXPhysics, position, rotation) {
|
|
581
588
|
var _this;
|
|
582
|
-
_this = PhysXCollider.call(this, physXPhysics) || this
|
|
589
|
+
_this = PhysXCollider.call(this, physXPhysics) || this, /**
|
|
590
|
+
* Whether actor is currently kinematic.
|
|
591
|
+
* PhysX 拒绝在 kinematic actor 上启用 CCD(会打印警告并忽略),
|
|
592
|
+
* 所以 setCollisionDetectionMode 在 kinematic 状态下只缓存目标值,
|
|
593
|
+
* 等切回 dynamic 时再真正写到 PhysX。
|
|
594
|
+
*/ _this._isKinematic = false, /**
|
|
595
|
+
* Cached collision detection mode. Always reflects user's intent.
|
|
596
|
+
* 实际 PhysX CCD flag 可能跟这个不一致(kinematic 时强制 Discrete)。
|
|
597
|
+
*/ _this._collisionDetectionMode = 0;
|
|
583
598
|
var transform = _this._transform(position, rotation);
|
|
584
599
|
_this._pxActor = physXPhysics._pxPhysics.createRigidDynamic(transform);
|
|
585
600
|
return _this;
|
|
@@ -662,7 +677,7 @@ PhysXCollider._tempTransform = {
|
|
|
662
677
|
};
|
|
663
678
|
/**
|
|
664
679
|
* {@inheritDoc IDynamicCollider.setSleepThreshold }
|
|
665
|
-
* @default
|
|
680
|
+
* @default 5e-5f * PxTolerancesScale::speed * PxTolerancesScale::speed
|
|
666
681
|
*/ _proto.setSleepThreshold = function setSleepThreshold(value) {
|
|
667
682
|
this._pxActor.setSleepThreshold(value);
|
|
668
683
|
};
|
|
@@ -673,7 +688,45 @@ PhysXCollider._tempTransform = {
|
|
|
673
688
|
};
|
|
674
689
|
/**
|
|
675
690
|
* {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
|
|
691
|
+
*
|
|
692
|
+
* PhysX 在 kinematic actor 上调用 setRigidBodyFlag(eENABLE_CCD, true) 会触发警告:
|
|
693
|
+
* "kinematic bodies with CCD enabled are not supported! CCD will be ignored"
|
|
694
|
+
* 虽然 PhysX 会忽略这次调用而非真的拒绝(切回 dynamic 时 flag 不会自动恢复),
|
|
695
|
+
* 但每次 setIsKinematic 切换都会让这个 warning 重复打印,污染日志,
|
|
696
|
+
* 同时让 actor 在 dynamic 状态下 CCD flag 状态不确定。
|
|
697
|
+
*
|
|
698
|
+
* 解决: 只在 dynamic 状态时立即 apply CCD flags。kinematic 时仅缓存到
|
|
699
|
+
* `_collisionDetectionMode`,等切回 dynamic 时由 setIsKinematic 重新 apply。
|
|
676
700
|
*/ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
|
|
701
|
+
this._collisionDetectionMode = value;
|
|
702
|
+
if (!this._isKinematic) {
|
|
703
|
+
this._applyCollisionDetectionFlags(value);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* {@inheritDoc IDynamicCollider.setUseGravity }
|
|
708
|
+
*/ _proto.setUseGravity = function setUseGravity(value) {
|
|
709
|
+
this._pxActor.setActorFlag(this._physXPhysics._physX.PxActorFlag.eDISABLE_GRAVITY, !value);
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* {@inheritDoc IDynamicCollider.setIsKinematic }
|
|
713
|
+
*
|
|
714
|
+
* 切换 kinematic 状态时同步处理 CCD flag:
|
|
715
|
+
* - 切到 kinematic 前先关 CCD(避免 PhysX 警告 + 让状态显式)
|
|
716
|
+
* - 切回 dynamic 后恢复用户期望的 CCD mode(来自 `_collisionDetectionMode` 缓存)
|
|
717
|
+
*/ _proto.setIsKinematic = function setIsKinematic(value) {
|
|
718
|
+
if (this._isKinematic === value) return;
|
|
719
|
+
var physX = this._physXPhysics._physX;
|
|
720
|
+
if (value) {
|
|
721
|
+
this._applyCollisionDetectionFlags(0);
|
|
722
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eKINEMATIC, true);
|
|
723
|
+
} else {
|
|
724
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eKINEMATIC, false);
|
|
725
|
+
this._applyCollisionDetectionFlags(this._collisionDetectionMode);
|
|
726
|
+
}
|
|
727
|
+
this._isKinematic = value;
|
|
728
|
+
};
|
|
729
|
+
_proto._applyCollisionDetectionFlags = function _applyCollisionDetectionFlags(value) {
|
|
677
730
|
var physX = this._physXPhysics._physX;
|
|
678
731
|
switch(value){
|
|
679
732
|
case 1:
|
|
@@ -699,27 +752,20 @@ PhysXCollider._tempTransform = {
|
|
|
699
752
|
}
|
|
700
753
|
};
|
|
701
754
|
/**
|
|
702
|
-
* {@inheritDoc IDynamicCollider.setUseGravity }
|
|
703
|
-
*/ _proto.setUseGravity = function setUseGravity(value) {
|
|
704
|
-
this._pxActor.setActorFlag(this._physXPhysics._physX.PxActorFlag.eDISABLE_GRAVITY, !value);
|
|
705
|
-
};
|
|
706
|
-
/**
|
|
707
|
-
* {@inheritDoc IDynamicCollider.setIsKinematic }
|
|
708
|
-
*/ _proto.setIsKinematic = function setIsKinematic(value) {
|
|
709
|
-
if (value) {
|
|
710
|
-
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
|
|
711
|
-
} else {
|
|
712
|
-
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
/**
|
|
716
755
|
* {@inheritDoc IDynamicCollider.setConstraints }
|
|
717
756
|
*/ _proto.setConstraints = function setConstraints(flags) {
|
|
718
757
|
this._pxActor.setRigidDynamicLockFlags(flags);
|
|
719
758
|
};
|
|
720
759
|
/**
|
|
721
760
|
* {@inheritDoc IDynamicCollider.addForce }
|
|
761
|
+
*
|
|
762
|
+
* PhysX 在 kinematic actor 上调 addForce 是 no-op(doc: "kinematic bodies don't
|
|
763
|
+
* respond to forces")。提前 return 避免无意义的 wasm boundary cross。
|
|
764
|
+
*
|
|
765
|
+
* Sleeping actor 不需要显式 wakeUp — wasm binding 调用 `addForce(force, eFORCE,
|
|
766
|
+
* autowake=true)`,PhysX 自动唤醒(已通过 `applyForce on sleeping actor` 测试验证)。
|
|
722
767
|
*/ _proto.addForce = function addForce(force) {
|
|
768
|
+
if (this._isKinematic) return;
|
|
723
769
|
this._pxActor.addForce(force);
|
|
724
770
|
};
|
|
725
771
|
/**
|
|
@@ -729,23 +775,33 @@ PhysXCollider._tempTransform = {
|
|
|
729
775
|
};
|
|
730
776
|
/**
|
|
731
777
|
* {@inheritDoc IDynamicCollider.addTorque }
|
|
778
|
+
*
|
|
779
|
+
* 同 addForce — kinematic 提前 return,sleeping 由 PhysX autowake 自动处理。
|
|
732
780
|
*/ _proto.addTorque = function addTorque(torque) {
|
|
781
|
+
if (this._isKinematic) return;
|
|
733
782
|
this._pxActor.addTorque(torque);
|
|
734
783
|
};
|
|
735
784
|
/**
|
|
736
785
|
* {@inheritDoc IDynamicCollider.move }
|
|
786
|
+
*
|
|
787
|
+
* PhysX 要求 setKinematicTarget 的 rotation 是 normalized quaternion,否则会触发
|
|
788
|
+
* 内部 assertion / 警告,并把 actor 转到错误的姿态。所以在写入 wasm 边界前统一 normalize。
|
|
737
789
|
*/ _proto.move = function move(positionOrRotation, rotation) {
|
|
790
|
+
var tempTranslation = PhysXDynamicCollider._tempTranslation;
|
|
791
|
+
var tempRotation = PhysXDynamicCollider._tempRotation;
|
|
738
792
|
if (rotation) {
|
|
739
|
-
|
|
793
|
+
tempRotation.copyFrom(rotation).normalize();
|
|
794
|
+
this._pxActor.setKinematicTarget(positionOrRotation, tempRotation);
|
|
740
795
|
return;
|
|
741
796
|
}
|
|
742
|
-
var tempTranslation = PhysXDynamicCollider._tempTranslation;
|
|
743
|
-
var tempRotation = PhysXDynamicCollider._tempRotation;
|
|
744
|
-
this.getWorldTransform(tempTranslation, tempRotation);
|
|
745
797
|
if (_instanceof(positionOrRotation, Vector3)) {
|
|
798
|
+
this.getWorldTransform(tempTranslation, tempRotation);
|
|
799
|
+
// current rotation read from PhysX is already normalized; no extra work needed
|
|
746
800
|
this._pxActor.setKinematicTarget(positionOrRotation, tempRotation);
|
|
747
801
|
} else {
|
|
748
|
-
this.
|
|
802
|
+
this.getWorldTransform(tempTranslation, tempRotation);
|
|
803
|
+
tempRotation.copyFrom(positionOrRotation).normalize();
|
|
804
|
+
this._pxActor.setKinematicTarget(tempTranslation, tempRotation);
|
|
749
805
|
}
|
|
750
806
|
};
|
|
751
807
|
/**
|
|
@@ -848,6 +904,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
848
904
|
this._activeTriggers = new DisorderedArray();
|
|
849
905
|
this._contactEvents = [];
|
|
850
906
|
this._contactEventCount = 0;
|
|
907
|
+
this._contactEventEnabled = true;
|
|
851
908
|
this._triggerEvents = [];
|
|
852
909
|
this._physicsEvents = {
|
|
853
910
|
contactEvents: [],
|
|
@@ -970,6 +1027,17 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
970
1027
|
this._fetchResults();
|
|
971
1028
|
};
|
|
972
1029
|
/**
|
|
1030
|
+
* {@inheritDoc IPhysicsScene.setContactEventEnabled }
|
|
1031
|
+
*/ _proto.setContactEventEnabled = function setContactEventEnabled(enabled) {
|
|
1032
|
+
if (this._contactEventEnabled === enabled) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
this._contactEventEnabled = enabled;
|
|
1036
|
+
if (!enabled) {
|
|
1037
|
+
this._contactEventCount = 0;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
/**
|
|
973
1041
|
* {@inheritDoc IPhysicsScene.updateEvents }
|
|
974
1042
|
*/ _proto.updateEvents = function updateEvents() {
|
|
975
1043
|
var physicsEvents = this._physicsEvents;
|
|
@@ -1217,6 +1285,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1217
1285
|
};
|
|
1218
1286
|
_proto._bufferContactEvent = function _bufferContactEvent(collision, state) {
|
|
1219
1287
|
var _this__contactEvents, _index;
|
|
1288
|
+
if (!this._contactEventEnabled) return;
|
|
1220
1289
|
var index = this._contactEventCount++;
|
|
1221
1290
|
var event = (_this__contactEvents = this._contactEvents)[_index = index] || (_this__contactEvents[_index] = new ContactEvent());
|
|
1222
1291
|
event.shape0Id = collision.shape0Id;
|
|
@@ -1554,12 +1623,6 @@ function _assert_this_initialized(self) {
|
|
|
1554
1623
|
return self;
|
|
1555
1624
|
}
|
|
1556
1625
|
|
|
1557
|
-
function _type_of(obj) {
|
|
1558
|
-
"@swc/helpers - typeof";
|
|
1559
|
-
|
|
1560
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
1626
|
function _possible_constructor_return(self, call) {
|
|
1564
1627
|
if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
|
|
1565
1628
|
|
|
@@ -1574,7 +1637,8 @@ function _possible_constructor_return(self, call) {
|
|
|
1574
1637
|
var _this;
|
|
1575
1638
|
_this = PhysXColliderShape.call(this, physXPhysics) || this, _this._pxMesh = null;
|
|
1576
1639
|
_this._isConvex = isConvex;
|
|
1577
|
-
|
|
1640
|
+
var cooked = _this._cookMesh(positions, indices, isConvex, cookingFlags);
|
|
1641
|
+
if (!cooked) {
|
|
1578
1642
|
return _possible_constructor_return(_this);
|
|
1579
1643
|
}
|
|
1580
1644
|
var physX = physXPhysics._physX, physics = physXPhysics._pxPhysics;
|
|
@@ -1582,9 +1646,11 @@ function _possible_constructor_return(self, call) {
|
|
|
1582
1646
|
var shapeFlags = ShapeFlag.SCENE_QUERY_SHAPE | ShapeFlag.SIMULATION_SHAPE;
|
|
1583
1647
|
var meshFlag = isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
|
|
1584
1648
|
var createShapeFn = isConvex ? physX.createConvexMeshShape : physX.createTriMeshShape;
|
|
1585
|
-
_this._pxShape = createShapeFn(
|
|
1649
|
+
_this._pxShape = createShapeFn(cooked.mesh, scaleX, scaleY, scaleZ, meshFlag, shapeFlags, material._pxMaterial, physics);
|
|
1586
1650
|
_this._id = uniqueID;
|
|
1587
1651
|
_this._pxMaterial = material._pxMaterial;
|
|
1652
|
+
_this._pxMesh = cooked.mesh;
|
|
1653
|
+
_this._pxGeometry = cooked.geometry;
|
|
1588
1654
|
_this._pxShape.setUUID(uniqueID);
|
|
1589
1655
|
_this._setLocalPose();
|
|
1590
1656
|
return _this;
|
|
@@ -1593,16 +1659,25 @@ function _possible_constructor_return(self, call) {
|
|
|
1593
1659
|
/**
|
|
1594
1660
|
* {@inheritDoc IMeshColliderShape.setMeshData }
|
|
1595
1661
|
*/ _proto.setMeshData = function setMeshData(positions, indices, isConvex, cookingFlags) {
|
|
1596
|
-
var
|
|
1597
|
-
(
|
|
1598
|
-
(_this__pxGeometry = this._pxGeometry) == null ? void 0 : _this__pxGeometry.delete();
|
|
1599
|
-
this._pxMesh = null;
|
|
1600
|
-
this._pxGeometry = null;
|
|
1601
|
-
this._isConvex = isConvex;
|
|
1602
|
-
if (!this._cookMesh(positions, indices, cookingFlags)) {
|
|
1662
|
+
var cooked = this._cookMesh(positions, indices, isConvex, cookingFlags);
|
|
1663
|
+
if (!cooked) {
|
|
1603
1664
|
return false;
|
|
1604
1665
|
}
|
|
1605
|
-
this.
|
|
1666
|
+
var oldMesh = this._pxMesh;
|
|
1667
|
+
var oldGeometry = this._pxGeometry;
|
|
1668
|
+
try {
|
|
1669
|
+
this._pxShape.setGeometry(cooked.geometry);
|
|
1670
|
+
} catch (error) {
|
|
1671
|
+
var _cooked_mesh, _cooked_geometry;
|
|
1672
|
+
(_cooked_mesh = cooked.mesh) == null ? void 0 : _cooked_mesh.release();
|
|
1673
|
+
(_cooked_geometry = cooked.geometry) == null ? void 0 : _cooked_geometry.delete();
|
|
1674
|
+
throw error;
|
|
1675
|
+
}
|
|
1676
|
+
this._pxMesh = cooked.mesh;
|
|
1677
|
+
this._pxGeometry = cooked.geometry;
|
|
1678
|
+
this._isConvex = isConvex;
|
|
1679
|
+
oldMesh == null ? void 0 : oldMesh.release();
|
|
1680
|
+
oldGeometry == null ? void 0 : oldGeometry.delete();
|
|
1606
1681
|
return true;
|
|
1607
1682
|
};
|
|
1608
1683
|
/**
|
|
@@ -1618,7 +1693,7 @@ function _possible_constructor_return(self, call) {
|
|
|
1618
1693
|
(_this__pxMesh = this._pxMesh) == null ? void 0 : _this__pxMesh.release();
|
|
1619
1694
|
PhysXColliderShape.prototype.destroy.call(this);
|
|
1620
1695
|
};
|
|
1621
|
-
_proto._cookMesh = function _cookMesh(positions, indices, cookingFlags) {
|
|
1696
|
+
_proto._cookMesh = function _cookMesh(positions, indices, isConvex, cookingFlags) {
|
|
1622
1697
|
var _this__physXPhysics = this._physXPhysics, physX = _this__physXPhysics._physX, physics = _this__physXPhysics._pxPhysics, cooking = _this__physXPhysics._pxCooking, cookingParams = _this__physXPhysics._pxCookingParams;
|
|
1623
1698
|
// Apply per-shape cooking flags
|
|
1624
1699
|
var preprocessFlags = 0;
|
|
@@ -1631,33 +1706,37 @@ function _possible_constructor_return(self, call) {
|
|
|
1631
1706
|
physX.setCookingMeshPreprocessParams(cookingParams, preprocessFlags);
|
|
1632
1707
|
cooking.setParams(cookingParams);
|
|
1633
1708
|
var verticesPtr = this._allocatePositions(positions);
|
|
1634
|
-
|
|
1635
|
-
|
|
1709
|
+
var pxMesh = null;
|
|
1710
|
+
if (isConvex) {
|
|
1711
|
+
pxMesh = cooking.createConvexMesh(verticesPtr, positions.length, physics);
|
|
1636
1712
|
physX._free(verticesPtr);
|
|
1637
|
-
if (!
|
|
1713
|
+
if (!pxMesh) {
|
|
1638
1714
|
this._logConvexCookingError(physX);
|
|
1639
|
-
return
|
|
1715
|
+
return null;
|
|
1640
1716
|
}
|
|
1641
1717
|
} else {
|
|
1642
1718
|
if (!indices) {
|
|
1643
1719
|
physX._free(verticesPtr);
|
|
1644
1720
|
console.error("PhysXMeshColliderShape: Triangle mesh requires indices.");
|
|
1645
|
-
return
|
|
1721
|
+
return null;
|
|
1646
1722
|
}
|
|
1647
1723
|
var isU32 = _instanceof(indices, Uint32Array);
|
|
1648
1724
|
var indicesPtr = this._allocateIndices(indices, isU32);
|
|
1649
|
-
|
|
1725
|
+
pxMesh = cooking.createTriMesh(verticesPtr, positions.length, indicesPtr, indices.length / 3, !isU32, physics);
|
|
1650
1726
|
physX._free(verticesPtr);
|
|
1651
1727
|
physX._free(indicesPtr);
|
|
1652
|
-
if (!
|
|
1728
|
+
if (!pxMesh) {
|
|
1653
1729
|
this._logTriMeshCookingError(physX);
|
|
1654
|
-
return
|
|
1730
|
+
return null;
|
|
1655
1731
|
}
|
|
1656
1732
|
}
|
|
1657
1733
|
var _this__worldScale = this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
|
|
1658
|
-
var meshFlag =
|
|
1659
|
-
|
|
1660
|
-
return
|
|
1734
|
+
var meshFlag = isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
|
|
1735
|
+
var geometry = isConvex ? physX.createConvexMeshGeometry(pxMesh, scaleX, scaleY, scaleZ, meshFlag) : physX.createTriMeshGeometry(pxMesh, scaleX, scaleY, scaleZ, meshFlag);
|
|
1736
|
+
return {
|
|
1737
|
+
mesh: pxMesh,
|
|
1738
|
+
geometry: geometry
|
|
1739
|
+
};
|
|
1661
1740
|
};
|
|
1662
1741
|
_proto._logConvexCookingError = function _logConvexCookingError(physX) {
|
|
1663
1742
|
switch(physX.getLastConvexCookingResult()){
|
|
@@ -1707,9 +1786,15 @@ function _possible_constructor_return(self, call) {
|
|
|
1707
1786
|
var _this__worldScale = this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
|
|
1708
1787
|
var meshFlag = this._isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
|
|
1709
1788
|
var newGeometry = this._isConvex ? physX.createConvexMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag) : physX.createTriMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag);
|
|
1710
|
-
this._pxGeometry
|
|
1789
|
+
var oldGeometry = this._pxGeometry;
|
|
1790
|
+
try {
|
|
1791
|
+
this._pxShape.setGeometry(newGeometry);
|
|
1792
|
+
} catch (error) {
|
|
1793
|
+
newGeometry == null ? void 0 : newGeometry.delete();
|
|
1794
|
+
throw error;
|
|
1795
|
+
}
|
|
1711
1796
|
this._pxGeometry = newGeometry;
|
|
1712
|
-
|
|
1797
|
+
oldGeometry == null ? void 0 : oldGeometry.delete();
|
|
1713
1798
|
};
|
|
1714
1799
|
return PhysXMeshColliderShape;
|
|
1715
1800
|
}(PhysXColliderShape);
|
|
@@ -1768,14 +1853,27 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1768
1853
|
/**
|
|
1769
1854
|
* PhysX object creation.
|
|
1770
1855
|
*/ var PhysXPhysics = /*#__PURE__*/ function() {
|
|
1771
|
-
function PhysXPhysics(
|
|
1772
|
-
if (
|
|
1856
|
+
function PhysXPhysics(runtimeModeOrOptions, runtimeUrls, options) {
|
|
1857
|
+
if (runtimeModeOrOptions === void 0) runtimeModeOrOptions = PhysXRuntimeMode.Auto;
|
|
1858
|
+
var _this__tolerancesScaleOptions, _this__tolerancesScaleOptions1;
|
|
1773
1859
|
this._initializeState = 0;
|
|
1860
|
+
this._defaultContactOffset = 0.02;
|
|
1861
|
+
this._defaultSleepThreshold = 5e-3;
|
|
1862
|
+
var isOptionsObject = (typeof runtimeModeOrOptions === "undefined" ? "undefined" : _type_of(runtimeModeOrOptions)) === "object";
|
|
1863
|
+
var runtimeMode = isOptionsObject ? PhysXRuntimeMode.Auto : runtimeModeOrOptions != null ? runtimeModeOrOptions : PhysXRuntimeMode.Auto;
|
|
1864
|
+
var resolvedOptions = isOptionsObject ? runtimeModeOrOptions : options;
|
|
1774
1865
|
this._runTimeMode = runtimeMode;
|
|
1775
1866
|
var _runtimeUrls_wasmSIMDModeUrl;
|
|
1776
|
-
this._wasmSIMDModeUrl = (_runtimeUrls_wasmSIMDModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmSIMDModeUrl) != null ? _runtimeUrls_wasmSIMDModeUrl : "https://mdn.alipayobjects.com/rms/uri/file/as/apwallet/
|
|
1867
|
+
this._wasmSIMDModeUrl = (_runtimeUrls_wasmSIMDModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmSIMDModeUrl) != null ? _runtimeUrls_wasmSIMDModeUrl : "https://mdn.alipayobjects.com/rms/uri/file/as/apwallet/1786450043249/suyi/physx.release.simd.js";
|
|
1777
1868
|
var _runtimeUrls_wasmModeUrl;
|
|
1778
|
-
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/uri/file/as/apwallet/
|
|
1869
|
+
this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/uri/file/as/apwallet/1786450043249/suyi/physx.release.js";
|
|
1870
|
+
this._tolerancesScaleOptions = resolvedOptions == null ? void 0 : resolvedOptions.tolerancesScale;
|
|
1871
|
+
var _this__tolerancesScaleOptions_length;
|
|
1872
|
+
var length = (_this__tolerancesScaleOptions_length = (_this__tolerancesScaleOptions = this._tolerancesScaleOptions) == null ? void 0 : _this__tolerancesScaleOptions.length) != null ? _this__tolerancesScaleOptions_length : 1;
|
|
1873
|
+
var _this__tolerancesScaleOptions_speed;
|
|
1874
|
+
var speed = (_this__tolerancesScaleOptions_speed = (_this__tolerancesScaleOptions1 = this._tolerancesScaleOptions) == null ? void 0 : _this__tolerancesScaleOptions1.speed) != null ? _this__tolerancesScaleOptions_speed : 10;
|
|
1875
|
+
this._validateTolerancesScale(length, speed);
|
|
1876
|
+
this._updateScaledDefaults(length, speed);
|
|
1779
1877
|
}
|
|
1780
1878
|
var _proto = PhysXPhysics.prototype;
|
|
1781
1879
|
/**
|
|
@@ -1845,6 +1943,16 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1845
1943
|
return scene;
|
|
1846
1944
|
};
|
|
1847
1945
|
/**
|
|
1946
|
+
* {@inheritDoc IPhysics.getDefaultContactOffset }
|
|
1947
|
+
*/ _proto.getDefaultContactOffset = function getDefaultContactOffset() {
|
|
1948
|
+
return this._defaultContactOffset;
|
|
1949
|
+
};
|
|
1950
|
+
/**
|
|
1951
|
+
* {@inheritDoc IPhysics.getDefaultSleepThreshold }
|
|
1952
|
+
*/ _proto.getDefaultSleepThreshold = function getDefaultSleepThreshold() {
|
|
1953
|
+
return this._defaultSleepThreshold;
|
|
1954
|
+
};
|
|
1955
|
+
/**
|
|
1848
1956
|
* {@inheritDoc IPhysics.createStaticCollider }
|
|
1849
1957
|
*/ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
|
|
1850
1958
|
return new PhysXStaticCollider(this, position, rotation);
|
|
@@ -1921,6 +2029,7 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1921
2029
|
var allocator = new physX.PxDefaultAllocator();
|
|
1922
2030
|
var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
|
|
1923
2031
|
var tolerancesScale = new physX.PxTolerancesScale();
|
|
2032
|
+
this._applyTolerancesScale(tolerancesScale);
|
|
1924
2033
|
var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, tolerancesScale, false, null);
|
|
1925
2034
|
physX.PxInitExtensions(pxPhysics, null);
|
|
1926
2035
|
// Initialize cooking for mesh colliders
|
|
@@ -1941,11 +2050,35 @@ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
|
|
|
1941
2050
|
this._allocator = allocator;
|
|
1942
2051
|
this._tolerancesScale = tolerancesScale;
|
|
1943
2052
|
};
|
|
2053
|
+
_proto._applyTolerancesScale = function _applyTolerancesScale(tolerancesScale) {
|
|
2054
|
+
var _this__tolerancesScaleOptions, _this__tolerancesScaleOptions1;
|
|
2055
|
+
var _this__tolerancesScaleOptions_length;
|
|
2056
|
+
var length = (_this__tolerancesScaleOptions_length = (_this__tolerancesScaleOptions = this._tolerancesScaleOptions) == null ? void 0 : _this__tolerancesScaleOptions.length) != null ? _this__tolerancesScaleOptions_length : tolerancesScale.length;
|
|
2057
|
+
var _this__tolerancesScaleOptions_speed;
|
|
2058
|
+
var speed = (_this__tolerancesScaleOptions_speed = (_this__tolerancesScaleOptions1 = this._tolerancesScaleOptions) == null ? void 0 : _this__tolerancesScaleOptions1.speed) != null ? _this__tolerancesScaleOptions_speed : tolerancesScale.speed;
|
|
2059
|
+
this._validateTolerancesScale(length, speed);
|
|
2060
|
+
tolerancesScale.length = length;
|
|
2061
|
+
tolerancesScale.speed = speed;
|
|
2062
|
+
this._updateScaledDefaults(length, speed);
|
|
2063
|
+
};
|
|
2064
|
+
_proto._assertPositiveFinite = function _assertPositiveFinite(value, name) {
|
|
2065
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
2066
|
+
throw new Error("PhysXPhysics " + name + " must be a positive finite number.");
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
_proto._validateTolerancesScale = function _validateTolerancesScale(length, speed) {
|
|
2070
|
+
this._assertPositiveFinite(length, "tolerancesScale.length");
|
|
2071
|
+
this._assertPositiveFinite(speed, "tolerancesScale.speed");
|
|
2072
|
+
};
|
|
2073
|
+
_proto._updateScaledDefaults = function _updateScaledDefaults(length, speed) {
|
|
2074
|
+
this._defaultContactOffset = 0.02 * length;
|
|
2075
|
+
this._defaultSleepThreshold = 5e-5 * speed * speed;
|
|
2076
|
+
};
|
|
1944
2077
|
return PhysXPhysics;
|
|
1945
2078
|
}();
|
|
1946
2079
|
|
|
1947
2080
|
//@ts-ignore
|
|
1948
|
-
var version = "0.0.0-experimental-2.0-
|
|
2081
|
+
var version = "0.0.0-experimental-2.0-migrate.7";
|
|
1949
2082
|
console.log("Galacean Engine Physics PhysX Version: " + version);
|
|
1950
2083
|
|
|
1951
2084
|
export { PhysXPhysics, PhysXRuntimeMode, version };
|