@galacean/engine-physics-physx 1.5.0-alpha.1 → 1.5.0-beta.0
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 +75 -25
- 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 +75 -25
- package/dist/main.js.map +1 -1
- package/dist/module.js +75 -25
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/PhysXCharacterController.d.ts +4 -0
- package/types/PhysXCollider.d.ts +4 -0
- package/types/PhysXPhysics.d.ts +11 -0
- package/types/PhysXPhysicsScene.d.ts +12 -7
- package/types/shape/PhysXColliderShape.d.ts +0 -2
package/dist/module.js
CHANGED
|
@@ -38,8 +38,8 @@ function _inherits(subClass, superClass) {
|
|
|
38
38
|
function PhysXColliderShape(physXPhysics) {
|
|
39
39
|
/** @internal */ this._controllers = new DisorderedArray();
|
|
40
40
|
/** @internal */ this._contractOffset = 0.02;
|
|
41
|
-
this._worldScale = new Vector3(1, 1, 1);
|
|
42
|
-
this._position = new Vector3();
|
|
41
|
+
/** @internal */ this._worldScale = new Vector3(1, 1, 1);
|
|
42
|
+
/** @internal */ this._position = new Vector3();
|
|
43
43
|
this._rotation = new Vector3();
|
|
44
44
|
this._axis = null;
|
|
45
45
|
this._physXRotation = new Quaternion();
|
|
@@ -119,12 +119,15 @@ function _inherits(subClass, superClass) {
|
|
|
119
119
|
* {@inheritDoc IColliderShape.destroy }
|
|
120
120
|
*/ _proto.destroy = function destroy() {
|
|
121
121
|
this._pxShape.release();
|
|
122
|
+
this._pxGeometry.delete();
|
|
122
123
|
};
|
|
123
124
|
/**
|
|
124
125
|
* @internal
|
|
125
126
|
*/ _proto._setShapeFlags = function _setShapeFlags(flags) {
|
|
126
127
|
this._shapeFlags = flags;
|
|
127
|
-
|
|
128
|
+
var shapeFlags = new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags);
|
|
129
|
+
this._pxShape.setFlags(shapeFlags);
|
|
130
|
+
shapeFlags.delete();
|
|
128
131
|
};
|
|
129
132
|
_proto._setLocalPose = function _setLocalPose() {
|
|
130
133
|
var transform = PhysXColliderShape.transform;
|
|
@@ -135,7 +138,9 @@ function _inherits(subClass, superClass) {
|
|
|
135
138
|
_proto._initialize = function _initialize(material, id) {
|
|
136
139
|
this._id = id;
|
|
137
140
|
this._pxMaterial = material._pxMaterial;
|
|
138
|
-
|
|
141
|
+
var shapeFlags = new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags);
|
|
142
|
+
this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, shapeFlags);
|
|
143
|
+
shapeFlags.delete();
|
|
139
144
|
this._pxShape.setUUID(id);
|
|
140
145
|
};
|
|
141
146
|
_proto._modifyFlag = function _modifyFlag(flag, value) {
|
|
@@ -384,6 +389,8 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
384
389
|
* {@inheritDoc ICharacterController.addShape }
|
|
385
390
|
*/ _proto.addShape = function addShape(shape) {
|
|
386
391
|
var _this__pxController, _this__scene;
|
|
392
|
+
// Add shape should sync latest position and world scale to pxController
|
|
393
|
+
this._updateShapePosition(shape._position, shape._worldScale);
|
|
387
394
|
// When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
|
|
388
395
|
this._pxManager && this._createPXController(this._pxManager, shape);
|
|
389
396
|
this._shape = shape;
|
|
@@ -401,6 +408,15 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
401
408
|
(_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
|
|
402
409
|
};
|
|
403
410
|
/**
|
|
411
|
+
* {@inheritDoc ICollider.setCollisionLayer }
|
|
412
|
+
*/ _proto.setCollisionLayer = function setCollisionLayer(layer) {
|
|
413
|
+
var _this__pxController;
|
|
414
|
+
var actor = (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.getActor();
|
|
415
|
+
if (actor) {
|
|
416
|
+
this._physXPhysics._physX.setGroup(actor, layer);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
404
420
|
* {@inheritDoc ICharacterController.destroy }
|
|
405
421
|
*/ _proto.destroy = function destroy() {
|
|
406
422
|
this._destroyPXController();
|
|
@@ -424,7 +440,9 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
424
440
|
}
|
|
425
441
|
desc.setMaterial(shape._pxMaterial);
|
|
426
442
|
this._pxController = pxManager._getControllerManager().createController(desc);
|
|
443
|
+
desc.delete();
|
|
427
444
|
this._pxController.setUUID(shape._id);
|
|
445
|
+
this._updateNativePosition();
|
|
428
446
|
};
|
|
429
447
|
/**
|
|
430
448
|
* @internal
|
|
@@ -490,6 +508,11 @@ PhysXCharacterController._tempVec = new Vector3();
|
|
|
490
508
|
outRotation.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
|
|
491
509
|
};
|
|
492
510
|
/**
|
|
511
|
+
* {@inheritDoc ICollider.setCollisionLayer }
|
|
512
|
+
*/ _proto.setCollisionLayer = function setCollisionLayer(layer) {
|
|
513
|
+
this._physXPhysics._physX.setGroup(this._pxActor, layer);
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
493
516
|
* {@inheritDoc ICollider.destroy }
|
|
494
517
|
*/ _proto.destroy = function destroy() {
|
|
495
518
|
this._pxActor.release();
|
|
@@ -801,18 +824,19 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
801
824
|
}
|
|
802
825
|
};
|
|
803
826
|
var pxPhysics = physXPhysics._pxPhysics;
|
|
804
|
-
|
|
805
|
-
var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0,
|
|
827
|
+
this._physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
|
|
828
|
+
var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, this._physXSimulationCallbackInstance);
|
|
806
829
|
this._pxScene = pxPhysics.createScene(sceneDesc);
|
|
830
|
+
sceneDesc.delete();
|
|
807
831
|
}
|
|
808
832
|
var _proto = PhysXPhysicsScene.prototype;
|
|
809
833
|
/**
|
|
810
|
-
* {@inheritDoc
|
|
834
|
+
* {@inheritDoc IPhysicsScene.setGravity }
|
|
811
835
|
*/ _proto.setGravity = function setGravity(value) {
|
|
812
836
|
this._pxScene.setGravity(value);
|
|
813
837
|
};
|
|
814
838
|
/**
|
|
815
|
-
* {@inheritDoc
|
|
839
|
+
* {@inheritDoc IPhysicsScene.addCollider }
|
|
816
840
|
*/ _proto.addCollider = function addCollider(collider) {
|
|
817
841
|
collider._scene = this;
|
|
818
842
|
this._pxScene.addActor(collider._pxActor, null);
|
|
@@ -822,7 +846,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
822
846
|
}
|
|
823
847
|
};
|
|
824
848
|
/**
|
|
825
|
-
* {@inheritDoc
|
|
849
|
+
* {@inheritDoc IPhysicsScene.removeCollider }
|
|
826
850
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
827
851
|
collider._scene = null;
|
|
828
852
|
this._pxScene.removeActor(collider._pxActor, true);
|
|
@@ -832,7 +856,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
832
856
|
}
|
|
833
857
|
};
|
|
834
858
|
/**
|
|
835
|
-
* {@inheritDoc
|
|
859
|
+
* {@inheritDoc IPhysicsScene.addCharacterController }
|
|
836
860
|
*/ _proto.addCharacterController = function addCharacterController(characterController) {
|
|
837
861
|
characterController._scene = this;
|
|
838
862
|
// Physx have no API to remove/readd cct into scene.
|
|
@@ -850,7 +874,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
850
874
|
characterController._pxManager = this;
|
|
851
875
|
};
|
|
852
876
|
/**
|
|
853
|
-
* {@inheritDoc
|
|
877
|
+
* {@inheritDoc IPhysicsScene.removeCharacterController }
|
|
854
878
|
*/ _proto.removeCharacterController = function removeCharacterController(characterController) {
|
|
855
879
|
characterController._scene = null;
|
|
856
880
|
characterController._pxManager = null;
|
|
@@ -859,14 +883,14 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
859
883
|
shape && this._removeColliderShape(shape._id);
|
|
860
884
|
};
|
|
861
885
|
/**
|
|
862
|
-
* {@inheritDoc
|
|
886
|
+
* {@inheritDoc IPhysicsScene.update }
|
|
863
887
|
*/ _proto.update = function update(elapsedTime) {
|
|
864
888
|
this._simulate(elapsedTime);
|
|
865
889
|
this._fetchResults();
|
|
866
890
|
this._fireEvent();
|
|
867
891
|
};
|
|
868
892
|
/**
|
|
869
|
-
* {@inheritDoc
|
|
893
|
+
* {@inheritDoc IPhysicsScene.raycast }
|
|
870
894
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
871
895
|
var _this = this, pxHitResult = _this._pxRaycastHit;
|
|
872
896
|
distance = Math.min(distance, 3.4e38); // float32 max value limit in physx raycast.
|
|
@@ -880,7 +904,9 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
880
904
|
},
|
|
881
905
|
postFilter: function(filterData, hit) {}
|
|
882
906
|
};
|
|
883
|
-
var
|
|
907
|
+
var pxRaycastCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback);
|
|
908
|
+
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, pxRaycastCallback);
|
|
909
|
+
pxRaycastCallback.delete();
|
|
884
910
|
if (result && hit != undefined) {
|
|
885
911
|
var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
|
|
886
912
|
var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
|
|
@@ -891,6 +917,17 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
891
917
|
return result;
|
|
892
918
|
};
|
|
893
919
|
/**
|
|
920
|
+
* {@inheritDoc IPhysicsScene.destroy }
|
|
921
|
+
*/ _proto.destroy = function destroy() {
|
|
922
|
+
var _this__pxControllerManager;
|
|
923
|
+
this._pxScene.release();
|
|
924
|
+
this._physXSimulationCallbackInstance.delete();
|
|
925
|
+
this._pxRaycastHit.delete();
|
|
926
|
+
this._pxFilterData.flags.delete();
|
|
927
|
+
this._pxFilterData.delete();
|
|
928
|
+
(_this__pxControllerManager = this._pxControllerManager) == null ? void 0 : _this__pxControllerManager.release();
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
894
931
|
* @internal
|
|
895
932
|
*/ _proto._getControllerManager = function _getControllerManager() {
|
|
896
933
|
var pxControllerManager = this._pxControllerManager;
|
|
@@ -902,7 +939,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
902
939
|
/**
|
|
903
940
|
* @internal
|
|
904
941
|
*/ _proto._addColliderShape = function _addColliderShape(id) {
|
|
905
|
-
this._physXManager._eventMap[id] =
|
|
942
|
+
this._physXManager._eventMap[id] = Object.create(null);
|
|
906
943
|
};
|
|
907
944
|
/**
|
|
908
945
|
* @internal
|
|
@@ -1060,7 +1097,6 @@ PhysXPhysicsScene._tempNormal = new Vector3();
|
|
|
1060
1097
|
*/ _proto.destroy = function destroy() {
|
|
1061
1098
|
if (!this._pxJoint) return;
|
|
1062
1099
|
this._pxJoint.release();
|
|
1063
|
-
this._pxJoint = null;
|
|
1064
1100
|
this._collider = null;
|
|
1065
1101
|
};
|
|
1066
1102
|
/**
|
|
@@ -1313,9 +1349,9 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1313
1349
|
}
|
|
1314
1350
|
}
|
|
1315
1351
|
if (runtimeMode == PhysXRuntimeMode.JavaScript) {
|
|
1316
|
-
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1352
|
+
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*V4pqRqM65UMAAAAAAAAAAAAAARQnAQ/physx.release.downgrade.js";
|
|
1317
1353
|
} else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
|
|
1318
|
-
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1354
|
+
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nL1PSrCPoZ0AAAAAAAAAAAAAARQnAQ/physx.release.js";
|
|
1319
1355
|
}
|
|
1320
1356
|
});
|
|
1321
1357
|
var initializePromise = new Promise(function(resolve, reject) {
|
|
@@ -1338,9 +1374,9 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1338
1374
|
this._physX.PxCloseExtensions();
|
|
1339
1375
|
this._pxPhysics.release();
|
|
1340
1376
|
this._pxFoundation.release();
|
|
1341
|
-
this.
|
|
1342
|
-
this.
|
|
1343
|
-
this.
|
|
1377
|
+
this._defaultErrorCallback.delete();
|
|
1378
|
+
this._allocator.delete();
|
|
1379
|
+
this._tolerancesScale.delete();
|
|
1344
1380
|
};
|
|
1345
1381
|
/**
|
|
1346
1382
|
* {@inheritDoc IPhysics.createPhysicsManager }
|
|
@@ -1350,8 +1386,8 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1350
1386
|
/**
|
|
1351
1387
|
* {@inheritDoc IPhysics.createPhysicsScene }
|
|
1352
1388
|
*/ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
|
|
1353
|
-
var
|
|
1354
|
-
return
|
|
1389
|
+
var scene = new PhysXPhysicsScene(this, physicsManager, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
|
|
1390
|
+
return scene;
|
|
1355
1391
|
};
|
|
1356
1392
|
/**
|
|
1357
1393
|
* {@inheritDoc IPhysics.createStaticCollider }
|
|
@@ -1408,22 +1444,36 @@ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
|
1408
1444
|
*/ _proto.createSpringJoint = function createSpringJoint(collider) {
|
|
1409
1445
|
return new PhysXSpringJoint(this, collider);
|
|
1410
1446
|
};
|
|
1447
|
+
/**
|
|
1448
|
+
* {@inheritDoc IPhysics.getColliderLayerCollision }
|
|
1449
|
+
*/ _proto.getColliderLayerCollision = function getColliderLayerCollision(layer1, layer2) {
|
|
1450
|
+
return this._physX.getGroupCollisionFlag(layer1, layer2);
|
|
1451
|
+
};
|
|
1452
|
+
/**
|
|
1453
|
+
* {@inheritDoc IPhysics.setColliderLayerCollision }
|
|
1454
|
+
*/ _proto.setColliderLayerCollision = function setColliderLayerCollision(layer1, layer2, isCollide) {
|
|
1455
|
+
this._physX.setGroupCollisionFlag(layer1, layer2, isCollide);
|
|
1456
|
+
};
|
|
1411
1457
|
_proto._init = function _init(physX) {
|
|
1412
1458
|
var version = physX.PX_PHYSICS_VERSION;
|
|
1413
1459
|
var defaultErrorCallback = new physX.PxDefaultErrorCallback();
|
|
1414
1460
|
var allocator = new physX.PxDefaultAllocator();
|
|
1415
1461
|
var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
|
|
1416
|
-
var
|
|
1462
|
+
var tolerancesScale = new physX.PxTolerancesScale();
|
|
1463
|
+
var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, tolerancesScale, false, null);
|
|
1417
1464
|
physX.PxInitExtensions(pxPhysics, null);
|
|
1418
1465
|
this._physX = physX;
|
|
1419
1466
|
this._pxFoundation = pxFoundation;
|
|
1420
1467
|
this._pxPhysics = pxPhysics;
|
|
1468
|
+
this._defaultErrorCallback = defaultErrorCallback;
|
|
1469
|
+
this._allocator = allocator;
|
|
1470
|
+
this._tolerancesScale = tolerancesScale;
|
|
1421
1471
|
};
|
|
1422
1472
|
return PhysXPhysics;
|
|
1423
1473
|
}();
|
|
1424
1474
|
|
|
1425
1475
|
//@ts-ignore
|
|
1426
|
-
var version = "1.5.0-
|
|
1476
|
+
var version = "1.5.0-beta.0";
|
|
1427
1477
|
console.log("Galacean Engine Physics PhysX Version: " + version);
|
|
1428
1478
|
|
|
1429
1479
|
export { PhysXPhysics, PhysXRuntimeMode, version };
|