@galacean/engine-physics-physx 1.4.0-alpha.0 → 1.4.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/main.js CHANGED
@@ -41,9 +41,10 @@ function _inherits(subClass, superClass) {
41
41
  */ var PhysXColliderShape = /*#__PURE__*/ function() {
42
42
  function PhysXColliderShape(physXPhysics) {
43
43
  /** @internal */ this._controllers = new engine.DisorderedArray();
44
+ /** @internal */ this._contractOffset = 0.02;
44
45
  this._worldScale = new engine.Vector3(1, 1, 1);
45
46
  this._position = new engine.Vector3();
46
- this._rotation = null;
47
+ this._rotation = new engine.Vector3();
47
48
  this._axis = null;
48
49
  this._physXRotation = new engine.Quaternion();
49
50
  this._shapeFlags = 2 | 1;
@@ -53,8 +54,8 @@ function _inherits(subClass, superClass) {
53
54
  /**
54
55
  * {@inheritDoc IColliderShape.setRotation }
55
56
  */ _proto.setRotation = function setRotation(value) {
56
- this._rotation = value;
57
- engine.Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physXRotation);
57
+ var rotation = this._rotation.set(engine.MathUtil.degreeToRadian(value.x), engine.MathUtil.degreeToRadian(value.y), engine.MathUtil.degreeToRadian(value.z));
58
+ engine.Quaternion.rotationYawPitchRoll(rotation.y, rotation.x, rotation.z, this._physXRotation);
58
59
  this._axis && engine.Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
59
60
  this._physXRotation.normalize();
60
61
  this._setLocalPose();
@@ -74,7 +75,7 @@ function _inherits(subClass, superClass) {
74
75
  /**
75
76
  * {@inheritDoc IColliderShape.setWorldScale }
76
77
  */ _proto.setWorldScale = function setWorldScale(scale) {
77
- this._worldScale.copyFrom(scale);
78
+ this._worldScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
78
79
  this._setLocalPose();
79
80
  var controllers = this._controllers;
80
81
  for(var i = 0, n = controllers.length; i < n; i++){
@@ -85,11 +86,15 @@ function _inherits(subClass, superClass) {
85
86
  * {@inheritDoc IColliderShape.setContactOffset }
86
87
  * @default 0.02f * PxTolerancesScale::length
87
88
  */ _proto.setContactOffset = function setContactOffset(offset) {
88
- this._pxShape.setContactOffset(offset);
89
+ this._contractOffset = offset;
89
90
  var controllers = this._controllers;
90
- for(var i = 0, n = controllers.length; i < n; i++){
91
- var _controllers_get__pxController;
92
- (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
91
+ if (controllers.length) {
92
+ for(var i = 0, n = controllers.length; i < n; i++){
93
+ var _controllers_get__pxController;
94
+ (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
95
+ }
96
+ } else {
97
+ this._pxShape.setContactOffset(offset);
93
98
  }
94
99
  };
95
100
  /**
@@ -106,6 +111,15 @@ function _inherits(subClass, superClass) {
106
111
  this._setShapeFlags(this._shapeFlags);
107
112
  };
108
113
  /**
114
+ * {@inheritDoc IColliderShape.pointDistance }
115
+ */ _proto.pointDistance = function pointDistance(point) {
116
+ var info = this._pxGeometry.pointDistance(this._pxShape.getGlobalPose(), point);
117
+ var closestPoint = info.closestPoint;
118
+ var res = PhysXColliderShape._tempVector4;
119
+ res.set(closestPoint.x, closestPoint.y, closestPoint.z, info.distance);
120
+ return res;
121
+ };
122
+ /**
109
123
  * {@inheritDoc IColliderShape.destroy }
110
124
  */ _proto.destroy = function destroy() {
111
125
  this._pxShape.release();
@@ -133,6 +147,7 @@ function _inherits(subClass, superClass) {
133
147
  };
134
148
  return PhysXColliderShape;
135
149
  }();
150
+ PhysXColliderShape._tempVector4 = new engine.Vector4();
136
151
  PhysXColliderShape.halfSqrt = 0.70710678118655;
137
152
  PhysXColliderShape.transform = {
138
153
  translation: new engine.Vector3(),
@@ -145,7 +160,7 @@ PhysXColliderShape.transform = {
145
160
  _inherits(PhysXBoxColliderShape, PhysXColliderShape);
146
161
  function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
147
162
  var _this;
148
- _this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new engine.Vector3(), _this._sizeScale = new engine.Vector3(1, 1, 1);
163
+ _this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new engine.Vector3();
149
164
  var halfSize = _this._halfSize;
150
165
  halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
151
166
  _this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(halfSize.x, halfSize.y, halfSize.z);
@@ -160,7 +175,7 @@ PhysXColliderShape.transform = {
160
175
  var halfSize = this._halfSize;
161
176
  var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
162
177
  halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
163
- engine.Vector3.multiply(halfSize, this._sizeScale, tempExtents);
178
+ engine.Vector3.multiply(halfSize, this._worldScale, tempExtents);
164
179
  this._pxGeometry.halfExtents = tempExtents;
165
180
  this._pxShape.setGeometry(this._pxGeometry);
166
181
  this._updateController(tempExtents);
@@ -169,9 +184,8 @@ PhysXColliderShape.transform = {
169
184
  * {@inheritDoc IColliderShape.setWorldScale }
170
185
  */ _proto.setWorldScale = function setWorldScale(scale) {
171
186
  PhysXColliderShape.prototype.setWorldScale.call(this, scale);
172
- this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
173
187
  var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
174
- engine.Vector3.multiply(this._halfSize, this._sizeScale, tempExtents);
188
+ engine.Vector3.multiply(this._halfSize, this._worldScale, tempExtents);
175
189
  this._pxGeometry.halfExtents = tempExtents;
176
190
  this._pxShape.setGeometry(this._pxGeometry);
177
191
  this._updateController(tempExtents);
@@ -197,7 +211,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
197
211
  _inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
198
212
  function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
199
213
  var _this;
200
- _this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1, _this._sizeScale = new engine.Vector3(1, 1, 1);
214
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1;
201
215
  _this._radius = radius;
202
216
  _this._halfHeight = height * 0.5;
203
217
  _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
@@ -212,7 +226,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
212
226
  * {@inheritDoc ICapsuleColliderShape.setRadius }
213
227
  */ _proto.setRadius = function setRadius(value) {
214
228
  this._radius = value;
215
- var sizeScale = this._sizeScale;
229
+ var sizeScale = this._worldScale;
216
230
  switch(this._upAxis){
217
231
  case 0:
218
232
  this._pxGeometry.radius = this._radius * Math.max(sizeScale.y, sizeScale.z);
@@ -236,7 +250,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
236
250
  * {@inheritDoc ICapsuleColliderShape.setHeight }
237
251
  */ _proto.setHeight = function setHeight(value) {
238
252
  this._halfHeight = value * 0.5;
239
- var sizeScale = this._sizeScale;
253
+ var sizeScale = this._worldScale;
240
254
  switch(this._upAxis){
241
255
  case 0:
242
256
  this._pxGeometry.halfHeight = this._halfHeight * sizeScale.x;
@@ -273,7 +287,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
273
287
  break;
274
288
  }
275
289
  if (rotation) {
276
- engine.Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physXRotation);
290
+ engine.Quaternion.rotationYawPitchRoll(rotation.y, rotation.x, rotation.z, physXRotation);
277
291
  engine.Quaternion.multiply(physXRotation, axis, physXRotation);
278
292
  } else {
279
293
  physXRotation.copyFrom(axis);
@@ -284,7 +298,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
284
298
  * {@inheritDoc IColliderShape.setWorldScale }
285
299
  */ _proto.setWorldScale = function setWorldScale(scale) {
286
300
  PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
287
- var sizeScale = this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
301
+ var sizeScale = this._worldScale;
288
302
  var geometry = this._pxGeometry;
289
303
  switch(this._upAxis){
290
304
  case 0:
@@ -319,6 +333,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
319
333
  * Base class for character controllers.
320
334
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
321
335
  function PhysXCharacterController(physXPhysics) {
336
+ /** @internal */ this._scene = null;
322
337
  this._shapeScaledPosition = new engine.Vector3();
323
338
  this._worldPosition = null;
324
339
  this._physXPhysics = physXPhysics;
@@ -367,22 +382,27 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
367
382
  * {@inheritDoc ICharacterController.setSlopeLimit }
368
383
  */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
369
384
  var _this__pxController;
370
- (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(slopeLimit);
385
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(Math.cos(slopeLimit * Math.PI / 180));
371
386
  };
372
387
  /**
373
388
  * {@inheritDoc ICharacterController.addShape }
374
389
  */ _proto.addShape = function addShape(shape) {
390
+ var _this__pxController, _this__scene;
375
391
  // When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
376
392
  this._pxManager && this._createPXController(this._pxManager, shape);
377
393
  this._shape = shape;
378
394
  shape._controllers.add(this);
395
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape._contractOffset);
396
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
379
397
  };
380
398
  /**
381
399
  * {@inheritDoc ICharacterController.removeShape }
382
400
  */ _proto.removeShape = function removeShape(shape) {
401
+ var _this__scene;
383
402
  this._destroyPXController();
384
403
  this._shape = null;
385
404
  shape._controllers.delete(this);
405
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
386
406
  };
387
407
  /**
388
408
  * {@inheritDoc ICharacterController.destroy }
@@ -439,18 +459,27 @@ PhysXCharacterController._tempVec = new engine.Vector3();
439
459
  * Abstract class of physical collider.
440
460
  */ var PhysXCollider = /*#__PURE__*/ function() {
441
461
  function PhysXCollider(physXPhysics) {
462
+ /** @internal */ this._scene = null;
463
+ /** @internal */ this._shapes = new Array();
442
464
  this._physXPhysics = physXPhysics;
443
465
  }
444
466
  var _proto = PhysXCollider.prototype;
445
467
  /**
446
468
  * {@inheritDoc ICollider.addShape }
447
469
  */ _proto.addShape = function addShape(shape) {
470
+ var _this__scene;
448
471
  this._pxActor.attachShape(shape._pxShape);
472
+ this._shapes.push(shape);
473
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
449
474
  };
450
475
  /**
451
476
  * {@inheritDoc ICollider.removeShape }
452
477
  */ _proto.removeShape = function removeShape(shape) {
478
+ var _this__scene;
453
479
  this._pxActor.detachShape(shape._pxShape, true);
480
+ var shapes = this._shapes;
481
+ shapes.splice(shapes.indexOf(shape), 1);
482
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
454
483
  };
455
484
  /**
456
485
  * {@inheritDoc ICollider.setWorldTransform }
@@ -497,24 +526,47 @@ PhysXCollider._tempTransform = {
497
526
  }
498
527
  var _proto = PhysXDynamicCollider.prototype;
499
528
  /**
529
+ * {@inheritDoc IDynamicCollider.getLinearDamping }
530
+ */ _proto.getLinearDamping = function getLinearDamping() {
531
+ return this._pxActor.getLinearDamping();
532
+ };
533
+ /**
500
534
  * {@inheritDoc IDynamicCollider.setLinearDamping }
501
535
  */ _proto.setLinearDamping = function setLinearDamping(value) {
502
536
  this._pxActor.setLinearDamping(value);
503
537
  };
504
538
  /**
539
+ * {@inheritDoc IDynamicCollider.getAngularDamping }
540
+ */ _proto.getAngularDamping = function getAngularDamping() {
541
+ return this._pxActor.getAngularDamping();
542
+ };
543
+ /**
505
544
  * {@inheritDoc IDynamicCollider.setAngularDamping }
506
545
  */ _proto.setAngularDamping = function setAngularDamping(value) {
507
546
  this._pxActor.setAngularDamping(value);
508
547
  };
509
548
  /**
549
+ * {@inheritDoc IDynamicCollider.getLinearVelocity }
550
+ */ _proto.getLinearVelocity = function getLinearVelocity(out) {
551
+ var velocity = this._pxActor.getLinearVelocity();
552
+ return out.set(velocity.x, velocity.y, velocity.z);
553
+ };
554
+ /**
510
555
  * {@inheritDoc IDynamicCollider.setLinearVelocity }
511
556
  */ _proto.setLinearVelocity = function setLinearVelocity(value) {
512
557
  this._pxActor.setLinearVelocity(value, true);
513
558
  };
514
559
  /**
560
+ * {@inheritDoc IDynamicCollider.getAngularVelocity }
561
+ */ _proto.getAngularVelocity = function getAngularVelocity(out) {
562
+ var velocity = this._pxActor.getAngularVelocity();
563
+ return out.set(engine.MathUtil.radianToDegree(velocity.x), engine.MathUtil.radianToDegree(velocity.y), engine.MathUtil.radianToDegree(velocity.z));
564
+ };
565
+ /**
515
566
  * {@inheritDoc IDynamicCollider.setAngularVelocity }
516
567
  */ _proto.setAngularVelocity = function setAngularVelocity(value) {
517
- this._pxActor.setAngularVelocity(value, true);
568
+ PhysXDynamicCollider._tempTranslation.set(engine.MathUtil.degreeToRadian(value.x), engine.MathUtil.degreeToRadian(value.y), engine.MathUtil.degreeToRadian(value.z));
569
+ this._pxActor.setAngularVelocity(PhysXDynamicCollider._tempTranslation, true);
518
570
  };
519
571
  /**
520
572
  * {@inheritDoc IDynamicCollider.setMass }
@@ -522,6 +574,12 @@ PhysXCollider._tempTransform = {
522
574
  this._pxActor.setMass(value);
523
575
  };
524
576
  /**
577
+ * {@inheritDoc IDynamicCollider.getCenterOfMass }
578
+ */ _proto.getCenterOfMass = function getCenterOfMass(out) {
579
+ var translation = this._pxActor.getCMassLocalPose().translation;
580
+ return out.set(translation.x, translation.y, translation.z);
581
+ };
582
+ /**
525
583
  * {@inheritDoc IDynamicCollider.setCenterOfMass }
526
584
  */ _proto.setCenterOfMass = function setCenterOfMass(position) {
527
585
  this._pxActor.setCMassLocalPose(position);
@@ -532,9 +590,25 @@ PhysXCollider._tempTransform = {
532
590
  this._pxActor.setMassSpaceInertiaTensor(value);
533
591
  };
534
592
  /**
593
+ * {@inheritDoc IDynamicCollider.getInertiaTensor }
594
+ */ _proto.getInertiaTensor = function getInertiaTensor(out) {
595
+ var inertia = this._pxActor.getMassSpaceInertiaTensor();
596
+ return out.set(inertia.x, inertia.y, inertia.z);
597
+ };
598
+ /**
599
+ * {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
600
+ */ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
601
+ this._pxActor.setMassAndUpdateInertia(mass);
602
+ };
603
+ /**
535
604
  * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
536
605
  */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
537
- this._pxActor.setMaxAngularVelocity(value);
606
+ this._pxActor.setMaxAngularVelocity(engine.MathUtil.degreeToRadian(value));
607
+ };
608
+ /**
609
+ * {@inheritDoc IDynamicCollider.getMaxDepenetrationVelocity }
610
+ */ _proto.getMaxDepenetrationVelocity = function getMaxDepenetrationVelocity() {
611
+ return this._pxActor.getMaxDepenetrationVelocity();
538
612
  };
539
613
  /**
540
614
  * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
@@ -555,18 +629,20 @@ PhysXCollider._tempTransform = {
555
629
  /**
556
630
  * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
557
631
  */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
632
+ var physX = this._physXPhysics._physX;
558
633
  switch(value){
559
634
  case 1:
560
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
635
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
561
636
  break;
562
637
  case 2:
563
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
638
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
639
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
564
640
  break;
565
641
  case 3:
566
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
642
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
643
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
567
644
  break;
568
645
  case 0:
569
- var physX = this._physXPhysics._physX;
570
646
  this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
571
647
  this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
572
648
  this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
@@ -574,6 +650,11 @@ PhysXCollider._tempTransform = {
574
650
  }
575
651
  };
576
652
  /**
653
+ * {@inheritDoc IDynamicCollider.setUseGravity }
654
+ */ _proto.setUseGravity = function setUseGravity(value) {
655
+ this._pxActor.setActorFlag(this._physXPhysics._physX.PxActorFlag.eDISABLE_GRAVITY, !value);
656
+ };
657
+ /**
577
658
  * {@inheritDoc IDynamicCollider.setIsKinematic }
578
659
  */ _proto.setIsKinematic = function setIsKinematic(value) {
579
660
  if (value) {
@@ -627,6 +708,11 @@ PhysXCollider._tempTransform = {
627
708
  return this._pxActor.putToSleep();
628
709
  };
629
710
  /**
711
+ * {@inheritDoc IDynamicCollider.isSleeping }
712
+ */ _proto.isSleeping = function isSleeping() {
713
+ return this._pxActor.isSleeping();
714
+ };
715
+ /**
630
716
  * {@inheritDoc IDynamicCollider.wakeUp }
631
717
  */ _proto.wakeUp = function wakeUp() {
632
718
  return this._pxActor.wakeUp();
@@ -705,14 +791,14 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
705
791
  this._onTriggerExit = onTriggerExit;
706
792
  this._onTriggerStay = onTriggerStay;
707
793
  var triggerCallback = {
708
- onContactBegin: function(index1, index2) {
709
- _this._onContactEnter(index1, index2);
794
+ onContactBegin: function(collision) {
795
+ _this._onContactEnter(collision);
710
796
  },
711
- onContactEnd: function(index1, index2) {
712
- _this._onContactExit(index1, index2);
797
+ onContactEnd: function(collision) {
798
+ _this._onContactExit(collision);
713
799
  },
714
- onContactPersist: function(index1, index2) {
715
- _this._onContactStay(index1, index2);
800
+ onContactPersist: function(collision) {
801
+ _this._onContactStay(collision);
716
802
  },
717
803
  onTriggerBegin: function(index1, index2) {
718
804
  var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
@@ -745,42 +831,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
745
831
  this._pxScene.setGravity(value);
746
832
  };
747
833
  /**
748
- * {@inheritDoc IPhysicsManager.addColliderShape }
749
- */ _proto.addColliderShape = function addColliderShape(colliderShape) {
750
- this._physXManager._eventMap[colliderShape._id] = {};
751
- };
752
- /**
753
- * {@inheritDoc IPhysicsManager.removeColliderShape }
754
- */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
755
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
756
- var id = colliderShape._id;
757
- var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
758
- currentEvents.forEach(function(event, i) {
759
- if (event.index1 == id) {
760
- currentEvents.deleteByIndex(i);
761
- eventPool.push(event);
762
- } else if (event.index2 == id) {
763
- currentEvents.deleteByIndex(i);
764
- eventPool.push(event);
765
- // If the shape is big index, should clear from the small index shape subMap
766
- eventMap[event.index1][id] = undefined;
767
- }
768
- });
769
- delete eventMap[id];
770
- };
771
- /**
772
834
  * {@inheritDoc IPhysicsManager.addCollider }
773
835
  */ _proto.addCollider = function addCollider(collider) {
836
+ collider._scene = this;
774
837
  this._pxScene.addActor(collider._pxActor, null);
838
+ var shapes = collider._shapes;
839
+ for(var i = 0, n = shapes.length; i < n; i++){
840
+ this._addColliderShape(shapes[i]._id);
841
+ }
775
842
  };
776
843
  /**
777
844
  * {@inheritDoc IPhysicsManager.removeCollider }
778
845
  */ _proto.removeCollider = function removeCollider(collider) {
846
+ collider._scene = null;
779
847
  this._pxScene.removeActor(collider._pxActor, true);
848
+ var shapes = collider._shapes;
849
+ for(var i = 0, n = shapes.length; i < n; i++){
850
+ this._removeColliderShape(shapes[i]._id);
851
+ }
780
852
  };
781
853
  /**
782
854
  * {@inheritDoc IPhysicsManager.addCharacterController }
783
855
  */ _proto.addCharacterController = function addCharacterController(characterController) {
856
+ characterController._scene = this;
784
857
  // Physx have no API to remove/readd cct into scene.
785
858
  if (!characterController._pxController) {
786
859
  var shape = characterController._shape;
@@ -790,6 +863,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
790
863
  lastPXManager && characterController._destroyPXController();
791
864
  characterController._createPXController(this, shape);
792
865
  }
866
+ this._addColliderShape(shape._id);
793
867
  }
794
868
  }
795
869
  characterController._pxManager = this;
@@ -797,7 +871,11 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
797
871
  /**
798
872
  * {@inheritDoc IPhysicsManager.removeCharacterController }
799
873
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
874
+ characterController._scene = null;
800
875
  characterController._pxManager = null;
876
+ characterController._destroyPXController();
877
+ var shape = characterController._shape;
878
+ shape && this._removeColliderShape(shape._id);
801
879
  };
802
880
  /**
803
881
  * {@inheritDoc IPhysicsManager.update }
@@ -840,6 +918,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
840
918
  }
841
919
  return pxControllerManager;
842
920
  };
921
+ /**
922
+ * @internal
923
+ */ _proto._addColliderShape = function _addColliderShape(id) {
924
+ this._physXManager._eventMap[id] = {};
925
+ };
926
+ /**
927
+ * @internal
928
+ */ _proto._removeColliderShape = function _removeColliderShape(id) {
929
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
930
+ var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
931
+ currentEvents.forEach(function(event, i) {
932
+ if (event.index1 == id) {
933
+ currentEvents.deleteByIndex(i);
934
+ eventPool.push(event);
935
+ } else if (event.index2 == id) {
936
+ currentEvents.deleteByIndex(i);
937
+ eventPool.push(event);
938
+ // If the shape is big index, should clear from the small index shape subMap
939
+ eventMap[event.index1][id] = undefined;
940
+ }
941
+ });
942
+ delete eventMap[id];
943
+ };
843
944
  _proto._simulate = function _simulate(elapsedTime) {
844
945
  this._pxScene.simulate(elapsedTime, true);
845
946
  };
@@ -913,7 +1014,6 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
913
1014
  * a base interface providing common functionality for PhysX joints
914
1015
  */ var PhysXJoint = /*#__PURE__*/ function() {
915
1016
  function PhysXJoint(physXPhysics) {
916
- this._connectedAnchor = new engine.Vector3();
917
1017
  this._breakForce = Number.MAX_VALUE;
918
1018
  this._breakTorque = Number.MAX_VALUE;
919
1019
  this._physXPhysics = physXPhysics;
@@ -923,33 +1023,37 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
923
1023
  * {@inheritDoc IJoint.setConnectedCollider }
924
1024
  */ _proto.setConnectedCollider = function setConnectedCollider(value) {
925
1025
  var _this__collider;
926
- this._pxJoint.setActors((value == null ? void 0 : value._pxActor) || null, ((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null);
1026
+ this._pxJoint.setActors(((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null, (value == null ? void 0 : value._pxActor) || null);
927
1027
  };
928
1028
  /**
929
1029
  * {@inheritDoc IJoint.setConnectedAnchor }
930
- */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
931
- this._connectedAnchor.copyFrom(value);
1030
+ */ _proto.setAnchor = function setAnchor(value) {
932
1031
  this._setLocalPose(0, value, PhysXJoint._defaultQuat);
933
1032
  };
934
1033
  /**
935
- * {@inheritDoc IJoint.setConnectedMassScale }
936
- */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
937
- this._pxJoint.setInvMassScale0(1 / value);
938
- };
939
- /**
940
- * {@inheritDoc IJoint.setConnectedInertiaScale }
941
- */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
942
- this._pxJoint.setInvInertiaScale0(1 / value);
1034
+ * {@inheritDoc IJoint.setConnectedAnchor }
1035
+ */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
1036
+ this._setLocalPose(1, value, PhysXJoint._defaultQuat);
943
1037
  };
944
1038
  /**
945
1039
  * {@inheritDoc IJoint.setMassScale }
946
1040
  */ _proto.setMassScale = function setMassScale(value) {
1041
+ this._pxJoint.setInvMassScale0(1 / value);
1042
+ };
1043
+ /**
1044
+ * {@inheritDoc IJoint.setConnectedMassScale }
1045
+ */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
947
1046
  this._pxJoint.setInvMassScale1(1 / value);
948
1047
  };
949
1048
  /**
950
1049
  * {@inheritDoc IJoint.setInertiaScale }
951
1050
  */ _proto.setInertiaScale = function setInertiaScale(value) {
952
- this._pxJoint.setInvInertiaScale1(1 / value);
1051
+ this._pxJoint.setInvInertiaScale0(value);
1052
+ };
1053
+ /**
1054
+ * {@inheritDoc IJoint.setConnectedInertiaScale }
1055
+ */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
1056
+ this._pxJoint.setInvInertiaScale1(value);
953
1057
  };
954
1058
  /**
955
1059
  * {@inheritDoc IJoint.setBreakForce }
@@ -964,6 +1068,14 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
964
1068
  this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
965
1069
  };
966
1070
  /**
1071
+ * {@inheritDoc IJoint.destroy }
1072
+ */ _proto.destroy = function destroy() {
1073
+ if (!this._pxJoint) return;
1074
+ this._pxJoint.release();
1075
+ this._pxJoint = null;
1076
+ this._collider = null;
1077
+ };
1078
+ /**
967
1079
  * Set the joint local pose for an actor.
968
1080
  * @param actor 0 for the first actor, 1 for the second actor.
969
1081
  * @param position the local position for the actor this joint
@@ -973,7 +1085,6 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
973
1085
  };
974
1086
  return PhysXJoint;
975
1087
  }();
976
- PhysXJoint._xAxis = new engine.Vector3(1, 0, 0);
977
1088
  PhysXJoint._defaultVec = new engine.Vector3();
978
1089
  PhysXJoint._defaultQuat = new engine.Quaternion();
979
1090
 
@@ -985,7 +1096,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
985
1096
  var _this;
986
1097
  _this = PhysXJoint1.call(this, physXPhysics) || this;
987
1098
  _this._collider = collider;
988
- _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1099
+ _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
989
1100
  return _this;
990
1101
  }
991
1102
  return PhysXFixedJoint;
@@ -997,34 +1108,37 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
997
1108
  _inherits(PhysXHingeJoint, PhysXJoint1);
998
1109
  function PhysXHingeJoint(physXPhysics, collider) {
999
1110
  var _this;
1000
- _this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new engine.Quaternion(), _this._swingOffset = new engine.Vector3();
1111
+ _this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new engine.Quaternion();
1001
1112
  _this._collider = collider;
1002
- _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1113
+ _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1003
1114
  return _this;
1004
1115
  }
1005
1116
  var _proto = PhysXHingeJoint.prototype;
1006
1117
  /**
1007
1118
  * {@inheritDoc IHingeJoint.setAxis }
1008
1119
  */ _proto.setAxis = function setAxis(value) {
1009
- var xAxis = PhysXJoint._xAxis;
1120
+ var xAxis = PhysXHingeJoint._xAxis;
1010
1121
  var axisRotationQuaternion = this._axisRotationQuaternion;
1011
1122
  xAxis.set(1, 0, 0);
1012
1123
  value.normalize();
1013
1124
  var angle = Math.acos(engine.Vector3.dot(xAxis, value));
1014
1125
  engine.Vector3.cross(xAxis, value, xAxis);
1015
1126
  engine.Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
1016
- this._setLocalPose(0, this._swingOffset, axisRotationQuaternion);
1127
+ this._setLocalPose(0, this._anchor, axisRotationQuaternion);
1128
+ this._setLocalPose(1, this._connectedAnchor, axisRotationQuaternion);
1017
1129
  };
1018
- /**
1019
- * {@inheritDoc IHingeJoint.setSwingOffset }
1020
- */ _proto.setSwingOffset = function setSwingOffset(value) {
1021
- this._swingOffset.copyFrom(value);
1022
- this._setLocalPose(1, this._swingOffset, this._axisRotationQuaternion);
1130
+ _proto.setAnchor = function setAnchor(value) {
1131
+ this._setLocalPose(0, value, this._axisRotationQuaternion);
1132
+ this._anchor = value;
1133
+ };
1134
+ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
1135
+ this._setLocalPose(1, value, this._axisRotationQuaternion);
1136
+ this._connectedAnchor = value;
1023
1137
  };
1024
1138
  /**
1025
1139
  * {@inheritDoc IHingeJoint.getAngle }
1026
1140
  */ _proto.getAngle = function getAngle() {
1027
- return this._pxJoint.getAngle();
1141
+ return engine.MathUtil.radianToDegree(this._pxJoint.getAngle());
1028
1142
  };
1029
1143
  /**
1030
1144
  * {@inheritDoc IHingeJoint.getVelocity }
@@ -1034,12 +1148,12 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
1034
1148
  /**
1035
1149
  * {@inheritDoc IHingeJoint.setHardLimitCone }
1036
1150
  */ _proto.setHardLimit = function setHardLimit(lowerLimit, upperLimit, contactDist) {
1037
- this._pxJoint.setHardLimit(lowerLimit, upperLimit, contactDist);
1151
+ this._pxJoint.setHardLimit(engine.MathUtil.degreeToRadian(lowerLimit), engine.MathUtil.degreeToRadian(upperLimit), contactDist);
1038
1152
  };
1039
1153
  /**
1040
1154
  * {@inheritDoc IHingeJoint.setHardLimitCone }
1041
1155
  */ _proto.setSoftLimit = function setSoftLimit(lowerLimit, upperLimit, stiffness, damping) {
1042
- this._pxJoint.setSoftLimit(lowerLimit, upperLimit, stiffness, damping);
1156
+ this._pxJoint.setSoftLimit(engine.MathUtil.degreeToRadian(lowerLimit), engine.MathUtil.degreeToRadian(upperLimit), stiffness, damping);
1043
1157
  };
1044
1158
  /**
1045
1159
  * {@inheritDoc IHingeJoint.setDriveVelocity }
@@ -1064,6 +1178,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
1064
1178
  };
1065
1179
  return PhysXHingeJoint;
1066
1180
  }(PhysXJoint);
1181
+ PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
1067
1182
 
1068
1183
  /**
1069
1184
  * a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
@@ -1071,7 +1186,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
1071
1186
  _inherits(PhysXSpringJoint, PhysXJoint1);
1072
1187
  function PhysXSpringJoint(physXPhysics, collider) {
1073
1188
  var _this;
1074
- _this = PhysXJoint1.call(this, physXPhysics) || this, _this._swingOffset = new engine.Vector3();
1189
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
1075
1190
  _this._collider = collider;
1076
1191
  _this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1077
1192
  _this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
@@ -1081,12 +1196,6 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
1081
1196
  }
1082
1197
  var _proto = PhysXSpringJoint.prototype;
1083
1198
  /**
1084
- * {@inheritDoc ISpringJoint.setSwingOffset }
1085
- */ _proto.setSwingOffset = function setSwingOffset(value) {
1086
- this._swingOffset.copyFrom(value);
1087
- this._setLocalPose(1, value, PhysXJoint._defaultQuat);
1088
- };
1089
- /**
1090
1199
  * {@inheritDoc ISpringJoint.setMinDistance }
1091
1200
  */ _proto.setMinDistance = function setMinDistance(distance) {
1092
1201
  this._pxJoint.setMinDistance(distance);
@@ -1209,7 +1318,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
1209
1318
  if (runtimeMode == PhysXRuntimeMode.JavaScript) {
1210
1319
  script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
1211
1320
  } else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
1212
- script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js";
1321
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*04GyRKeSJw4AAAAAAAAAAAAAARQnAQ/physx.release.js";
1213
1322
  }
1214
1323
  });
1215
1324
  var initializePromise = new Promise(function(resolve, reject) {
@@ -1317,7 +1426,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
1317
1426
  }();
1318
1427
 
1319
1428
  //@ts-ignore
1320
- var version = "1.4.0-alpha.0";
1429
+ var version = "1.4.0-alpha.2";
1321
1430
  console.log("Galacean PhysX version: " + version);
1322
1431
 
1323
1432
  exports.PhysXPhysics = PhysXPhysics;