@galacean/engine-physics-physx 1.5.0-alpha.0 → 1.5.0-alpha.2
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/main.js
CHANGED
|
@@ -42,8 +42,8 @@ function _inherits(subClass, superClass) {
|
|
|
42
42
|
function PhysXColliderShape(physXPhysics) {
|
|
43
43
|
/** @internal */ this._controllers = new engine.DisorderedArray();
|
|
44
44
|
/** @internal */ this._contractOffset = 0.02;
|
|
45
|
-
this._worldScale = new engine.Vector3(1, 1, 1);
|
|
46
|
-
this._position = new engine.Vector3();
|
|
45
|
+
/** @internal */ this._worldScale = new engine.Vector3(1, 1, 1);
|
|
46
|
+
/** @internal */ this._position = new engine.Vector3();
|
|
47
47
|
this._rotation = new engine.Vector3();
|
|
48
48
|
this._axis = null;
|
|
49
49
|
this._physXRotation = new engine.Quaternion();
|
|
@@ -123,12 +123,15 @@ function _inherits(subClass, superClass) {
|
|
|
123
123
|
* {@inheritDoc IColliderShape.destroy }
|
|
124
124
|
*/ _proto.destroy = function destroy() {
|
|
125
125
|
this._pxShape.release();
|
|
126
|
+
this._pxGeometry.delete();
|
|
126
127
|
};
|
|
127
128
|
/**
|
|
128
129
|
* @internal
|
|
129
130
|
*/ _proto._setShapeFlags = function _setShapeFlags(flags) {
|
|
130
131
|
this._shapeFlags = flags;
|
|
131
|
-
|
|
132
|
+
var shapeFlags = new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags);
|
|
133
|
+
this._pxShape.setFlags(shapeFlags);
|
|
134
|
+
shapeFlags.delete();
|
|
132
135
|
};
|
|
133
136
|
_proto._setLocalPose = function _setLocalPose() {
|
|
134
137
|
var transform = PhysXColliderShape.transform;
|
|
@@ -139,7 +142,9 @@ function _inherits(subClass, superClass) {
|
|
|
139
142
|
_proto._initialize = function _initialize(material, id) {
|
|
140
143
|
this._id = id;
|
|
141
144
|
this._pxMaterial = material._pxMaterial;
|
|
142
|
-
|
|
145
|
+
var shapeFlags = new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags);
|
|
146
|
+
this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, shapeFlags);
|
|
147
|
+
shapeFlags.delete();
|
|
143
148
|
this._pxShape.setUUID(id);
|
|
144
149
|
};
|
|
145
150
|
_proto._modifyFlag = function _modifyFlag(flag, value) {
|
|
@@ -388,6 +393,8 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
388
393
|
* {@inheritDoc ICharacterController.addShape }
|
|
389
394
|
*/ _proto.addShape = function addShape(shape) {
|
|
390
395
|
var _this__pxController, _this__scene;
|
|
396
|
+
// Add shape should sync latest position and world scale to pxController
|
|
397
|
+
this._updateShapePosition(shape._position, shape._worldScale);
|
|
391
398
|
// When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
|
|
392
399
|
this._pxManager && this._createPXController(this._pxManager, shape);
|
|
393
400
|
this._shape = shape;
|
|
@@ -405,6 +412,15 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
405
412
|
(_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
|
|
406
413
|
};
|
|
407
414
|
/**
|
|
415
|
+
* {@inheritDoc ICollider.setCollisionLayer }
|
|
416
|
+
*/ _proto.setCollisionLayer = function setCollisionLayer(layer) {
|
|
417
|
+
var _this__pxController;
|
|
418
|
+
var actor = (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.getActor();
|
|
419
|
+
if (actor) {
|
|
420
|
+
this._physXPhysics._physX.setGroup(actor, layer);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
408
424
|
* {@inheritDoc ICharacterController.destroy }
|
|
409
425
|
*/ _proto.destroy = function destroy() {
|
|
410
426
|
this._destroyPXController();
|
|
@@ -428,7 +444,9 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
428
444
|
}
|
|
429
445
|
desc.setMaterial(shape._pxMaterial);
|
|
430
446
|
this._pxController = pxManager._getControllerManager().createController(desc);
|
|
447
|
+
desc.delete();
|
|
431
448
|
this._pxController.setUUID(shape._id);
|
|
449
|
+
this._updateNativePosition();
|
|
432
450
|
};
|
|
433
451
|
/**
|
|
434
452
|
* @internal
|
|
@@ -494,6 +512,11 @@ PhysXCharacterController._tempVec = new engine.Vector3();
|
|
|
494
512
|
outRotation.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
|
|
495
513
|
};
|
|
496
514
|
/**
|
|
515
|
+
* {@inheritDoc ICollider.setCollisionLayer }
|
|
516
|
+
*/ _proto.setCollisionLayer = function setCollisionLayer(layer) {
|
|
517
|
+
this._physXPhysics._physX.setGroup(this._pxActor, layer);
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
497
520
|
* {@inheritDoc ICollider.destroy }
|
|
498
521
|
*/ _proto.destroy = function destroy() {
|
|
499
522
|
this._pxActor.release();
|
|
@@ -805,18 +828,19 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
805
828
|
}
|
|
806
829
|
};
|
|
807
830
|
var pxPhysics = physXPhysics._pxPhysics;
|
|
808
|
-
|
|
809
|
-
var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0,
|
|
831
|
+
this._physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
|
|
832
|
+
var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, this._physXSimulationCallbackInstance);
|
|
810
833
|
this._pxScene = pxPhysics.createScene(sceneDesc);
|
|
834
|
+
sceneDesc.delete();
|
|
811
835
|
}
|
|
812
836
|
var _proto = PhysXPhysicsScene.prototype;
|
|
813
837
|
/**
|
|
814
|
-
* {@inheritDoc
|
|
838
|
+
* {@inheritDoc IPhysicsScene.setGravity }
|
|
815
839
|
*/ _proto.setGravity = function setGravity(value) {
|
|
816
840
|
this._pxScene.setGravity(value);
|
|
817
841
|
};
|
|
818
842
|
/**
|
|
819
|
-
* {@inheritDoc
|
|
843
|
+
* {@inheritDoc IPhysicsScene.addCollider }
|
|
820
844
|
*/ _proto.addCollider = function addCollider(collider) {
|
|
821
845
|
collider._scene = this;
|
|
822
846
|
this._pxScene.addActor(collider._pxActor, null);
|
|
@@ -826,7 +850,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
826
850
|
}
|
|
827
851
|
};
|
|
828
852
|
/**
|
|
829
|
-
* {@inheritDoc
|
|
853
|
+
* {@inheritDoc IPhysicsScene.removeCollider }
|
|
830
854
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
831
855
|
collider._scene = null;
|
|
832
856
|
this._pxScene.removeActor(collider._pxActor, true);
|
|
@@ -836,7 +860,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
836
860
|
}
|
|
837
861
|
};
|
|
838
862
|
/**
|
|
839
|
-
* {@inheritDoc
|
|
863
|
+
* {@inheritDoc IPhysicsScene.addCharacterController }
|
|
840
864
|
*/ _proto.addCharacterController = function addCharacterController(characterController) {
|
|
841
865
|
characterController._scene = this;
|
|
842
866
|
// Physx have no API to remove/readd cct into scene.
|
|
@@ -854,7 +878,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
854
878
|
characterController._pxManager = this;
|
|
855
879
|
};
|
|
856
880
|
/**
|
|
857
|
-
* {@inheritDoc
|
|
881
|
+
* {@inheritDoc IPhysicsScene.removeCharacterController }
|
|
858
882
|
*/ _proto.removeCharacterController = function removeCharacterController(characterController) {
|
|
859
883
|
characterController._scene = null;
|
|
860
884
|
characterController._pxManager = null;
|
|
@@ -863,14 +887,14 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
863
887
|
shape && this._removeColliderShape(shape._id);
|
|
864
888
|
};
|
|
865
889
|
/**
|
|
866
|
-
* {@inheritDoc
|
|
890
|
+
* {@inheritDoc IPhysicsScene.update }
|
|
867
891
|
*/ _proto.update = function update(elapsedTime) {
|
|
868
892
|
this._simulate(elapsedTime);
|
|
869
893
|
this._fetchResults();
|
|
870
894
|
this._fireEvent();
|
|
871
895
|
};
|
|
872
896
|
/**
|
|
873
|
-
* {@inheritDoc
|
|
897
|
+
* {@inheritDoc IPhysicsScene.raycast }
|
|
874
898
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
875
899
|
var _this = this, pxHitResult = _this._pxRaycastHit;
|
|
876
900
|
distance = Math.min(distance, 3.4e38); // float32 max value limit in physx raycast.
|
|
@@ -884,7 +908,9 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
884
908
|
},
|
|
885
909
|
postFilter: function(filterData, hit) {}
|
|
886
910
|
};
|
|
887
|
-
var
|
|
911
|
+
var pxRaycastCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback);
|
|
912
|
+
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, pxRaycastCallback);
|
|
913
|
+
pxRaycastCallback.delete();
|
|
888
914
|
if (result && hit != undefined) {
|
|
889
915
|
var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
|
|
890
916
|
var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
|
|
@@ -895,6 +921,17 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
895
921
|
return result;
|
|
896
922
|
};
|
|
897
923
|
/**
|
|
924
|
+
* {@inheritDoc IPhysicsScene.destroy }
|
|
925
|
+
*/ _proto.destroy = function destroy() {
|
|
926
|
+
var _this__pxControllerManager;
|
|
927
|
+
this._pxScene.release();
|
|
928
|
+
this._physXSimulationCallbackInstance.delete();
|
|
929
|
+
this._pxRaycastHit.delete();
|
|
930
|
+
this._pxFilterData.flags.delete();
|
|
931
|
+
this._pxFilterData.delete();
|
|
932
|
+
(_this__pxControllerManager = this._pxControllerManager) == null ? void 0 : _this__pxControllerManager.release();
|
|
933
|
+
};
|
|
934
|
+
/**
|
|
898
935
|
* @internal
|
|
899
936
|
*/ _proto._getControllerManager = function _getControllerManager() {
|
|
900
937
|
var pxControllerManager = this._pxControllerManager;
|
|
@@ -906,7 +943,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
906
943
|
/**
|
|
907
944
|
* @internal
|
|
908
945
|
*/ _proto._addColliderShape = function _addColliderShape(id) {
|
|
909
|
-
this._physXManager._eventMap[id] =
|
|
946
|
+
this._physXManager._eventMap[id] = Object.create(null);
|
|
910
947
|
};
|
|
911
948
|
/**
|
|
912
949
|
* @internal
|
|
@@ -1064,7 +1101,6 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
|
|
|
1064
1101
|
*/ _proto.destroy = function destroy() {
|
|
1065
1102
|
if (!this._pxJoint) return;
|
|
1066
1103
|
this._pxJoint.release();
|
|
1067
|
-
this._pxJoint = null;
|
|
1068
1104
|
this._collider = null;
|
|
1069
1105
|
};
|
|
1070
1106
|
/**
|
|
@@ -1317,9 +1353,9 @@ PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
|
|
|
1317
1353
|
}
|
|
1318
1354
|
}
|
|
1319
1355
|
if (runtimeMode == PhysXRuntimeMode.JavaScript) {
|
|
1320
|
-
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1356
|
+
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*V4pqRqM65UMAAAAAAAAAAAAAARQnAQ/physx.release.downgrade.js";
|
|
1321
1357
|
} else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
|
|
1322
|
-
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1358
|
+
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nL1PSrCPoZ0AAAAAAAAAAAAAARQnAQ/physx.release.js";
|
|
1323
1359
|
}
|
|
1324
1360
|
});
|
|
1325
1361
|
var initializePromise = new Promise(function(resolve, reject) {
|
|
@@ -1342,9 +1378,9 @@ PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
|
|
|
1342
1378
|
this._physX.PxCloseExtensions();
|
|
1343
1379
|
this._pxPhysics.release();
|
|
1344
1380
|
this._pxFoundation.release();
|
|
1345
|
-
this.
|
|
1346
|
-
this.
|
|
1347
|
-
this.
|
|
1381
|
+
this._defaultErrorCallback.delete();
|
|
1382
|
+
this._allocator.delete();
|
|
1383
|
+
this._tolerancesScale.delete();
|
|
1348
1384
|
};
|
|
1349
1385
|
/**
|
|
1350
1386
|
* {@inheritDoc IPhysics.createPhysicsManager }
|
|
@@ -1354,8 +1390,8 @@ PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
|
|
|
1354
1390
|
/**
|
|
1355
1391
|
* {@inheritDoc IPhysics.createPhysicsScene }
|
|
1356
1392
|
*/ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
|
|
1357
|
-
var
|
|
1358
|
-
return
|
|
1393
|
+
var scene = new PhysXPhysicsScene(this, physicsManager, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
|
|
1394
|
+
return scene;
|
|
1359
1395
|
};
|
|
1360
1396
|
/**
|
|
1361
1397
|
* {@inheritDoc IPhysics.createStaticCollider }
|
|
@@ -1412,22 +1448,36 @@ PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
|
|
|
1412
1448
|
*/ _proto.createSpringJoint = function createSpringJoint(collider) {
|
|
1413
1449
|
return new PhysXSpringJoint(this, collider);
|
|
1414
1450
|
};
|
|
1451
|
+
/**
|
|
1452
|
+
* {@inheritDoc IPhysics.getColliderLayerCollision }
|
|
1453
|
+
*/ _proto.getColliderLayerCollision = function getColliderLayerCollision(layer1, layer2) {
|
|
1454
|
+
return this._physX.getGroupCollisionFlag(layer1, layer2);
|
|
1455
|
+
};
|
|
1456
|
+
/**
|
|
1457
|
+
* {@inheritDoc IPhysics.setColliderLayerCollision }
|
|
1458
|
+
*/ _proto.setColliderLayerCollision = function setColliderLayerCollision(layer1, layer2, isCollide) {
|
|
1459
|
+
this._physX.setGroupCollisionFlag(layer1, layer2, isCollide);
|
|
1460
|
+
};
|
|
1415
1461
|
_proto._init = function _init(physX) {
|
|
1416
1462
|
var version = physX.PX_PHYSICS_VERSION;
|
|
1417
1463
|
var defaultErrorCallback = new physX.PxDefaultErrorCallback();
|
|
1418
1464
|
var allocator = new physX.PxDefaultAllocator();
|
|
1419
1465
|
var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
|
|
1420
|
-
var
|
|
1466
|
+
var tolerancesScale = new physX.PxTolerancesScale();
|
|
1467
|
+
var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, tolerancesScale, false, null);
|
|
1421
1468
|
physX.PxInitExtensions(pxPhysics, null);
|
|
1422
1469
|
this._physX = physX;
|
|
1423
1470
|
this._pxFoundation = pxFoundation;
|
|
1424
1471
|
this._pxPhysics = pxPhysics;
|
|
1472
|
+
this._defaultErrorCallback = defaultErrorCallback;
|
|
1473
|
+
this._allocator = allocator;
|
|
1474
|
+
this._tolerancesScale = tolerancesScale;
|
|
1425
1475
|
};
|
|
1426
1476
|
return PhysXPhysics;
|
|
1427
1477
|
}();
|
|
1428
1478
|
|
|
1429
1479
|
//@ts-ignore
|
|
1430
|
-
var version = "1.5.0-alpha.
|
|
1480
|
+
var version = "1.5.0-alpha.2";
|
|
1431
1481
|
console.log("Galacean Engine Physics PhysX Version: " + version);
|
|
1432
1482
|
|
|
1433
1483
|
exports.PhysXPhysics = PhysXPhysics;
|