@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/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Vector3, Quaternion, DisorderedArray } from '@galacean/engine';
1
+ import { Vector4, Vector3, MathUtil, Quaternion, DisorderedArray } from '@galacean/engine';
2
2
 
3
3
  function _instanceof(left, right) {
4
4
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
@@ -37,9 +37,10 @@ function _inherits(subClass, superClass) {
37
37
  */ var PhysXColliderShape = /*#__PURE__*/ function() {
38
38
  function PhysXColliderShape(physXPhysics) {
39
39
  /** @internal */ this._controllers = new DisorderedArray();
40
+ /** @internal */ this._contractOffset = 0.02;
40
41
  this._worldScale = new Vector3(1, 1, 1);
41
42
  this._position = new Vector3();
42
- this._rotation = null;
43
+ this._rotation = new Vector3();
43
44
  this._axis = null;
44
45
  this._physXRotation = new Quaternion();
45
46
  this._shapeFlags = 2 | 1;
@@ -49,8 +50,8 @@ function _inherits(subClass, superClass) {
49
50
  /**
50
51
  * {@inheritDoc IColliderShape.setRotation }
51
52
  */ _proto.setRotation = function setRotation(value) {
52
- this._rotation = value;
53
- Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physXRotation);
53
+ var rotation = this._rotation.set(MathUtil.degreeToRadian(value.x), MathUtil.degreeToRadian(value.y), MathUtil.degreeToRadian(value.z));
54
+ Quaternion.rotationYawPitchRoll(rotation.y, rotation.x, rotation.z, this._physXRotation);
54
55
  this._axis && Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
55
56
  this._physXRotation.normalize();
56
57
  this._setLocalPose();
@@ -70,7 +71,7 @@ function _inherits(subClass, superClass) {
70
71
  /**
71
72
  * {@inheritDoc IColliderShape.setWorldScale }
72
73
  */ _proto.setWorldScale = function setWorldScale(scale) {
73
- this._worldScale.copyFrom(scale);
74
+ this._worldScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
74
75
  this._setLocalPose();
75
76
  var controllers = this._controllers;
76
77
  for(var i = 0, n = controllers.length; i < n; i++){
@@ -81,11 +82,15 @@ function _inherits(subClass, superClass) {
81
82
  * {@inheritDoc IColliderShape.setContactOffset }
82
83
  * @default 0.02f * PxTolerancesScale::length
83
84
  */ _proto.setContactOffset = function setContactOffset(offset) {
84
- this._pxShape.setContactOffset(offset);
85
+ this._contractOffset = offset;
85
86
  var controllers = this._controllers;
86
- for(var i = 0, n = controllers.length; i < n; i++){
87
- var _controllers_get__pxController;
88
- (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
87
+ if (controllers.length) {
88
+ for(var i = 0, n = controllers.length; i < n; i++){
89
+ var _controllers_get__pxController;
90
+ (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
91
+ }
92
+ } else {
93
+ this._pxShape.setContactOffset(offset);
89
94
  }
90
95
  };
91
96
  /**
@@ -102,6 +107,15 @@ function _inherits(subClass, superClass) {
102
107
  this._setShapeFlags(this._shapeFlags);
103
108
  };
104
109
  /**
110
+ * {@inheritDoc IColliderShape.pointDistance }
111
+ */ _proto.pointDistance = function pointDistance(point) {
112
+ var info = this._pxGeometry.pointDistance(this._pxShape.getGlobalPose(), point);
113
+ var closestPoint = info.closestPoint;
114
+ var res = PhysXColliderShape._tempVector4;
115
+ res.set(closestPoint.x, closestPoint.y, closestPoint.z, info.distance);
116
+ return res;
117
+ };
118
+ /**
105
119
  * {@inheritDoc IColliderShape.destroy }
106
120
  */ _proto.destroy = function destroy() {
107
121
  this._pxShape.release();
@@ -129,6 +143,7 @@ function _inherits(subClass, superClass) {
129
143
  };
130
144
  return PhysXColliderShape;
131
145
  }();
146
+ PhysXColliderShape._tempVector4 = new Vector4();
132
147
  PhysXColliderShape.halfSqrt = 0.70710678118655;
133
148
  PhysXColliderShape.transform = {
134
149
  translation: new Vector3(),
@@ -141,7 +156,7 @@ PhysXColliderShape.transform = {
141
156
  _inherits(PhysXBoxColliderShape, PhysXColliderShape);
142
157
  function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
143
158
  var _this;
144
- _this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new Vector3(), _this._sizeScale = new Vector3(1, 1, 1);
159
+ _this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new Vector3();
145
160
  var halfSize = _this._halfSize;
146
161
  halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
147
162
  _this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(halfSize.x, halfSize.y, halfSize.z);
@@ -156,7 +171,7 @@ PhysXColliderShape.transform = {
156
171
  var halfSize = this._halfSize;
157
172
  var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
158
173
  halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
159
- Vector3.multiply(halfSize, this._sizeScale, tempExtents);
174
+ Vector3.multiply(halfSize, this._worldScale, tempExtents);
160
175
  this._pxGeometry.halfExtents = tempExtents;
161
176
  this._pxShape.setGeometry(this._pxGeometry);
162
177
  this._updateController(tempExtents);
@@ -165,9 +180,8 @@ PhysXColliderShape.transform = {
165
180
  * {@inheritDoc IColliderShape.setWorldScale }
166
181
  */ _proto.setWorldScale = function setWorldScale(scale) {
167
182
  PhysXColliderShape.prototype.setWorldScale.call(this, scale);
168
- this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
169
183
  var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
170
- Vector3.multiply(this._halfSize, this._sizeScale, tempExtents);
184
+ Vector3.multiply(this._halfSize, this._worldScale, tempExtents);
171
185
  this._pxGeometry.halfExtents = tempExtents;
172
186
  this._pxShape.setGeometry(this._pxGeometry);
173
187
  this._updateController(tempExtents);
@@ -193,7 +207,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
193
207
  _inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
194
208
  function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
195
209
  var _this;
196
- _this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1, _this._sizeScale = new Vector3(1, 1, 1);
210
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1;
197
211
  _this._radius = radius;
198
212
  _this._halfHeight = height * 0.5;
199
213
  _this._axis = new Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
@@ -208,7 +222,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
208
222
  * {@inheritDoc ICapsuleColliderShape.setRadius }
209
223
  */ _proto.setRadius = function setRadius(value) {
210
224
  this._radius = value;
211
- var sizeScale = this._sizeScale;
225
+ var sizeScale = this._worldScale;
212
226
  switch(this._upAxis){
213
227
  case 0:
214
228
  this._pxGeometry.radius = this._radius * Math.max(sizeScale.y, sizeScale.z);
@@ -232,7 +246,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
232
246
  * {@inheritDoc ICapsuleColliderShape.setHeight }
233
247
  */ _proto.setHeight = function setHeight(value) {
234
248
  this._halfHeight = value * 0.5;
235
- var sizeScale = this._sizeScale;
249
+ var sizeScale = this._worldScale;
236
250
  switch(this._upAxis){
237
251
  case 0:
238
252
  this._pxGeometry.halfHeight = this._halfHeight * sizeScale.x;
@@ -269,7 +283,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
269
283
  break;
270
284
  }
271
285
  if (rotation) {
272
- Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physXRotation);
286
+ Quaternion.rotationYawPitchRoll(rotation.y, rotation.x, rotation.z, physXRotation);
273
287
  Quaternion.multiply(physXRotation, axis, physXRotation);
274
288
  } else {
275
289
  physXRotation.copyFrom(axis);
@@ -280,7 +294,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
280
294
  * {@inheritDoc IColliderShape.setWorldScale }
281
295
  */ _proto.setWorldScale = function setWorldScale(scale) {
282
296
  PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
283
- var sizeScale = this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
297
+ var sizeScale = this._worldScale;
284
298
  var geometry = this._pxGeometry;
285
299
  switch(this._upAxis){
286
300
  case 0:
@@ -315,6 +329,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
315
329
  * Base class for character controllers.
316
330
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
317
331
  function PhysXCharacterController(physXPhysics) {
332
+ /** @internal */ this._scene = null;
318
333
  this._shapeScaledPosition = new Vector3();
319
334
  this._worldPosition = null;
320
335
  this._physXPhysics = physXPhysics;
@@ -363,22 +378,27 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
363
378
  * {@inheritDoc ICharacterController.setSlopeLimit }
364
379
  */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
365
380
  var _this__pxController;
366
- (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(slopeLimit);
381
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(Math.cos(slopeLimit * Math.PI / 180));
367
382
  };
368
383
  /**
369
384
  * {@inheritDoc ICharacterController.addShape }
370
385
  */ _proto.addShape = function addShape(shape) {
386
+ var _this__pxController, _this__scene;
371
387
  // When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
372
388
  this._pxManager && this._createPXController(this._pxManager, shape);
373
389
  this._shape = shape;
374
390
  shape._controllers.add(this);
391
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape._contractOffset);
392
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
375
393
  };
376
394
  /**
377
395
  * {@inheritDoc ICharacterController.removeShape }
378
396
  */ _proto.removeShape = function removeShape(shape) {
397
+ var _this__scene;
379
398
  this._destroyPXController();
380
399
  this._shape = null;
381
400
  shape._controllers.delete(this);
401
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
382
402
  };
383
403
  /**
384
404
  * {@inheritDoc ICharacterController.destroy }
@@ -435,18 +455,27 @@ PhysXCharacterController._tempVec = new Vector3();
435
455
  * Abstract class of physical collider.
436
456
  */ var PhysXCollider = /*#__PURE__*/ function() {
437
457
  function PhysXCollider(physXPhysics) {
458
+ /** @internal */ this._scene = null;
459
+ /** @internal */ this._shapes = new Array();
438
460
  this._physXPhysics = physXPhysics;
439
461
  }
440
462
  var _proto = PhysXCollider.prototype;
441
463
  /**
442
464
  * {@inheritDoc ICollider.addShape }
443
465
  */ _proto.addShape = function addShape(shape) {
466
+ var _this__scene;
444
467
  this._pxActor.attachShape(shape._pxShape);
468
+ this._shapes.push(shape);
469
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
445
470
  };
446
471
  /**
447
472
  * {@inheritDoc ICollider.removeShape }
448
473
  */ _proto.removeShape = function removeShape(shape) {
474
+ var _this__scene;
449
475
  this._pxActor.detachShape(shape._pxShape, true);
476
+ var shapes = this._shapes;
477
+ shapes.splice(shapes.indexOf(shape), 1);
478
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
450
479
  };
451
480
  /**
452
481
  * {@inheritDoc ICollider.setWorldTransform }
@@ -493,24 +522,47 @@ PhysXCollider._tempTransform = {
493
522
  }
494
523
  var _proto = PhysXDynamicCollider.prototype;
495
524
  /**
525
+ * {@inheritDoc IDynamicCollider.getLinearDamping }
526
+ */ _proto.getLinearDamping = function getLinearDamping() {
527
+ return this._pxActor.getLinearDamping();
528
+ };
529
+ /**
496
530
  * {@inheritDoc IDynamicCollider.setLinearDamping }
497
531
  */ _proto.setLinearDamping = function setLinearDamping(value) {
498
532
  this._pxActor.setLinearDamping(value);
499
533
  };
500
534
  /**
535
+ * {@inheritDoc IDynamicCollider.getAngularDamping }
536
+ */ _proto.getAngularDamping = function getAngularDamping() {
537
+ return this._pxActor.getAngularDamping();
538
+ };
539
+ /**
501
540
  * {@inheritDoc IDynamicCollider.setAngularDamping }
502
541
  */ _proto.setAngularDamping = function setAngularDamping(value) {
503
542
  this._pxActor.setAngularDamping(value);
504
543
  };
505
544
  /**
545
+ * {@inheritDoc IDynamicCollider.getLinearVelocity }
546
+ */ _proto.getLinearVelocity = function getLinearVelocity(out) {
547
+ var velocity = this._pxActor.getLinearVelocity();
548
+ return out.set(velocity.x, velocity.y, velocity.z);
549
+ };
550
+ /**
506
551
  * {@inheritDoc IDynamicCollider.setLinearVelocity }
507
552
  */ _proto.setLinearVelocity = function setLinearVelocity(value) {
508
553
  this._pxActor.setLinearVelocity(value, true);
509
554
  };
510
555
  /**
556
+ * {@inheritDoc IDynamicCollider.getAngularVelocity }
557
+ */ _proto.getAngularVelocity = function getAngularVelocity(out) {
558
+ var velocity = this._pxActor.getAngularVelocity();
559
+ return out.set(MathUtil.radianToDegree(velocity.x), MathUtil.radianToDegree(velocity.y), MathUtil.radianToDegree(velocity.z));
560
+ };
561
+ /**
511
562
  * {@inheritDoc IDynamicCollider.setAngularVelocity }
512
563
  */ _proto.setAngularVelocity = function setAngularVelocity(value) {
513
- this._pxActor.setAngularVelocity(value, true);
564
+ PhysXDynamicCollider._tempTranslation.set(MathUtil.degreeToRadian(value.x), MathUtil.degreeToRadian(value.y), MathUtil.degreeToRadian(value.z));
565
+ this._pxActor.setAngularVelocity(PhysXDynamicCollider._tempTranslation, true);
514
566
  };
515
567
  /**
516
568
  * {@inheritDoc IDynamicCollider.setMass }
@@ -518,6 +570,12 @@ PhysXCollider._tempTransform = {
518
570
  this._pxActor.setMass(value);
519
571
  };
520
572
  /**
573
+ * {@inheritDoc IDynamicCollider.getCenterOfMass }
574
+ */ _proto.getCenterOfMass = function getCenterOfMass(out) {
575
+ var translation = this._pxActor.getCMassLocalPose().translation;
576
+ return out.set(translation.x, translation.y, translation.z);
577
+ };
578
+ /**
521
579
  * {@inheritDoc IDynamicCollider.setCenterOfMass }
522
580
  */ _proto.setCenterOfMass = function setCenterOfMass(position) {
523
581
  this._pxActor.setCMassLocalPose(position);
@@ -528,9 +586,25 @@ PhysXCollider._tempTransform = {
528
586
  this._pxActor.setMassSpaceInertiaTensor(value);
529
587
  };
530
588
  /**
589
+ * {@inheritDoc IDynamicCollider.getInertiaTensor }
590
+ */ _proto.getInertiaTensor = function getInertiaTensor(out) {
591
+ var inertia = this._pxActor.getMassSpaceInertiaTensor();
592
+ return out.set(inertia.x, inertia.y, inertia.z);
593
+ };
594
+ /**
595
+ * {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
596
+ */ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
597
+ this._pxActor.setMassAndUpdateInertia(mass);
598
+ };
599
+ /**
531
600
  * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
532
601
  */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
533
- this._pxActor.setMaxAngularVelocity(value);
602
+ this._pxActor.setMaxAngularVelocity(MathUtil.degreeToRadian(value));
603
+ };
604
+ /**
605
+ * {@inheritDoc IDynamicCollider.getMaxDepenetrationVelocity }
606
+ */ _proto.getMaxDepenetrationVelocity = function getMaxDepenetrationVelocity() {
607
+ return this._pxActor.getMaxDepenetrationVelocity();
534
608
  };
535
609
  /**
536
610
  * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
@@ -551,18 +625,20 @@ PhysXCollider._tempTransform = {
551
625
  /**
552
626
  * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
553
627
  */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
628
+ var physX = this._physXPhysics._physX;
554
629
  switch(value){
555
630
  case 1:
556
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
631
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
557
632
  break;
558
633
  case 2:
559
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
634
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
635
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
560
636
  break;
561
637
  case 3:
562
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
638
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
639
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
563
640
  break;
564
641
  case 0:
565
- var physX = this._physXPhysics._physX;
566
642
  this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
567
643
  this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
568
644
  this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
@@ -570,6 +646,11 @@ PhysXCollider._tempTransform = {
570
646
  }
571
647
  };
572
648
  /**
649
+ * {@inheritDoc IDynamicCollider.setUseGravity }
650
+ */ _proto.setUseGravity = function setUseGravity(value) {
651
+ this._pxActor.setActorFlag(this._physXPhysics._physX.PxActorFlag.eDISABLE_GRAVITY, !value);
652
+ };
653
+ /**
573
654
  * {@inheritDoc IDynamicCollider.setIsKinematic }
574
655
  */ _proto.setIsKinematic = function setIsKinematic(value) {
575
656
  if (value) {
@@ -623,6 +704,11 @@ PhysXCollider._tempTransform = {
623
704
  return this._pxActor.putToSleep();
624
705
  };
625
706
  /**
707
+ * {@inheritDoc IDynamicCollider.isSleeping }
708
+ */ _proto.isSleeping = function isSleeping() {
709
+ return this._pxActor.isSleeping();
710
+ };
711
+ /**
626
712
  * {@inheritDoc IDynamicCollider.wakeUp }
627
713
  */ _proto.wakeUp = function wakeUp() {
628
714
  return this._pxActor.wakeUp();
@@ -701,14 +787,14 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
701
787
  this._onTriggerExit = onTriggerExit;
702
788
  this._onTriggerStay = onTriggerStay;
703
789
  var triggerCallback = {
704
- onContactBegin: function(index1, index2) {
705
- _this._onContactEnter(index1, index2);
790
+ onContactBegin: function(collision) {
791
+ _this._onContactEnter(collision);
706
792
  },
707
- onContactEnd: function(index1, index2) {
708
- _this._onContactExit(index1, index2);
793
+ onContactEnd: function(collision) {
794
+ _this._onContactExit(collision);
709
795
  },
710
- onContactPersist: function(index1, index2) {
711
- _this._onContactStay(index1, index2);
796
+ onContactPersist: function(collision) {
797
+ _this._onContactStay(collision);
712
798
  },
713
799
  onTriggerBegin: function(index1, index2) {
714
800
  var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
@@ -741,42 +827,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
741
827
  this._pxScene.setGravity(value);
742
828
  };
743
829
  /**
744
- * {@inheritDoc IPhysicsManager.addColliderShape }
745
- */ _proto.addColliderShape = function addColliderShape(colliderShape) {
746
- this._physXManager._eventMap[colliderShape._id] = {};
747
- };
748
- /**
749
- * {@inheritDoc IPhysicsManager.removeColliderShape }
750
- */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
751
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
752
- var id = colliderShape._id;
753
- var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
754
- currentEvents.forEach(function(event, i) {
755
- if (event.index1 == id) {
756
- currentEvents.deleteByIndex(i);
757
- eventPool.push(event);
758
- } else if (event.index2 == id) {
759
- currentEvents.deleteByIndex(i);
760
- eventPool.push(event);
761
- // If the shape is big index, should clear from the small index shape subMap
762
- eventMap[event.index1][id] = undefined;
763
- }
764
- });
765
- delete eventMap[id];
766
- };
767
- /**
768
830
  * {@inheritDoc IPhysicsManager.addCollider }
769
831
  */ _proto.addCollider = function addCollider(collider) {
832
+ collider._scene = this;
770
833
  this._pxScene.addActor(collider._pxActor, null);
834
+ var shapes = collider._shapes;
835
+ for(var i = 0, n = shapes.length; i < n; i++){
836
+ this._addColliderShape(shapes[i]._id);
837
+ }
771
838
  };
772
839
  /**
773
840
  * {@inheritDoc IPhysicsManager.removeCollider }
774
841
  */ _proto.removeCollider = function removeCollider(collider) {
842
+ collider._scene = null;
775
843
  this._pxScene.removeActor(collider._pxActor, true);
844
+ var shapes = collider._shapes;
845
+ for(var i = 0, n = shapes.length; i < n; i++){
846
+ this._removeColliderShape(shapes[i]._id);
847
+ }
776
848
  };
777
849
  /**
778
850
  * {@inheritDoc IPhysicsManager.addCharacterController }
779
851
  */ _proto.addCharacterController = function addCharacterController(characterController) {
852
+ characterController._scene = this;
780
853
  // Physx have no API to remove/readd cct into scene.
781
854
  if (!characterController._pxController) {
782
855
  var shape = characterController._shape;
@@ -786,6 +859,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
786
859
  lastPXManager && characterController._destroyPXController();
787
860
  characterController._createPXController(this, shape);
788
861
  }
862
+ this._addColliderShape(shape._id);
789
863
  }
790
864
  }
791
865
  characterController._pxManager = this;
@@ -793,7 +867,11 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
793
867
  /**
794
868
  * {@inheritDoc IPhysicsManager.removeCharacterController }
795
869
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
870
+ characterController._scene = null;
796
871
  characterController._pxManager = null;
872
+ characterController._destroyPXController();
873
+ var shape = characterController._shape;
874
+ shape && this._removeColliderShape(shape._id);
797
875
  };
798
876
  /**
799
877
  * {@inheritDoc IPhysicsManager.update }
@@ -836,6 +914,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
836
914
  }
837
915
  return pxControllerManager;
838
916
  };
917
+ /**
918
+ * @internal
919
+ */ _proto._addColliderShape = function _addColliderShape(id) {
920
+ this._physXManager._eventMap[id] = {};
921
+ };
922
+ /**
923
+ * @internal
924
+ */ _proto._removeColliderShape = function _removeColliderShape(id) {
925
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
926
+ var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
927
+ currentEvents.forEach(function(event, i) {
928
+ if (event.index1 == id) {
929
+ currentEvents.deleteByIndex(i);
930
+ eventPool.push(event);
931
+ } else if (event.index2 == id) {
932
+ currentEvents.deleteByIndex(i);
933
+ eventPool.push(event);
934
+ // If the shape is big index, should clear from the small index shape subMap
935
+ eventMap[event.index1][id] = undefined;
936
+ }
937
+ });
938
+ delete eventMap[id];
939
+ };
839
940
  _proto._simulate = function _simulate(elapsedTime) {
840
941
  this._pxScene.simulate(elapsedTime, true);
841
942
  };
@@ -909,7 +1010,6 @@ PhysXPhysicsScene._tempNormal = new Vector3();
909
1010
  * a base interface providing common functionality for PhysX joints
910
1011
  */ var PhysXJoint = /*#__PURE__*/ function() {
911
1012
  function PhysXJoint(physXPhysics) {
912
- this._connectedAnchor = new Vector3();
913
1013
  this._breakForce = Number.MAX_VALUE;
914
1014
  this._breakTorque = Number.MAX_VALUE;
915
1015
  this._physXPhysics = physXPhysics;
@@ -919,33 +1019,37 @@ PhysXPhysicsScene._tempNormal = new Vector3();
919
1019
  * {@inheritDoc IJoint.setConnectedCollider }
920
1020
  */ _proto.setConnectedCollider = function setConnectedCollider(value) {
921
1021
  var _this__collider;
922
- this._pxJoint.setActors((value == null ? void 0 : value._pxActor) || null, ((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null);
1022
+ this._pxJoint.setActors(((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null, (value == null ? void 0 : value._pxActor) || null);
923
1023
  };
924
1024
  /**
925
1025
  * {@inheritDoc IJoint.setConnectedAnchor }
926
- */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
927
- this._connectedAnchor.copyFrom(value);
1026
+ */ _proto.setAnchor = function setAnchor(value) {
928
1027
  this._setLocalPose(0, value, PhysXJoint._defaultQuat);
929
1028
  };
930
1029
  /**
931
- * {@inheritDoc IJoint.setConnectedMassScale }
932
- */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
933
- this._pxJoint.setInvMassScale0(1 / value);
934
- };
935
- /**
936
- * {@inheritDoc IJoint.setConnectedInertiaScale }
937
- */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
938
- this._pxJoint.setInvInertiaScale0(1 / value);
1030
+ * {@inheritDoc IJoint.setConnectedAnchor }
1031
+ */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
1032
+ this._setLocalPose(1, value, PhysXJoint._defaultQuat);
939
1033
  };
940
1034
  /**
941
1035
  * {@inheritDoc IJoint.setMassScale }
942
1036
  */ _proto.setMassScale = function setMassScale(value) {
1037
+ this._pxJoint.setInvMassScale0(1 / value);
1038
+ };
1039
+ /**
1040
+ * {@inheritDoc IJoint.setConnectedMassScale }
1041
+ */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
943
1042
  this._pxJoint.setInvMassScale1(1 / value);
944
1043
  };
945
1044
  /**
946
1045
  * {@inheritDoc IJoint.setInertiaScale }
947
1046
  */ _proto.setInertiaScale = function setInertiaScale(value) {
948
- this._pxJoint.setInvInertiaScale1(1 / value);
1047
+ this._pxJoint.setInvInertiaScale0(value);
1048
+ };
1049
+ /**
1050
+ * {@inheritDoc IJoint.setConnectedInertiaScale }
1051
+ */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
1052
+ this._pxJoint.setInvInertiaScale1(value);
949
1053
  };
950
1054
  /**
951
1055
  * {@inheritDoc IJoint.setBreakForce }
@@ -960,6 +1064,14 @@ PhysXPhysicsScene._tempNormal = new Vector3();
960
1064
  this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
961
1065
  };
962
1066
  /**
1067
+ * {@inheritDoc IJoint.destroy }
1068
+ */ _proto.destroy = function destroy() {
1069
+ if (!this._pxJoint) return;
1070
+ this._pxJoint.release();
1071
+ this._pxJoint = null;
1072
+ this._collider = null;
1073
+ };
1074
+ /**
963
1075
  * Set the joint local pose for an actor.
964
1076
  * @param actor 0 for the first actor, 1 for the second actor.
965
1077
  * @param position the local position for the actor this joint
@@ -969,7 +1081,6 @@ PhysXPhysicsScene._tempNormal = new Vector3();
969
1081
  };
970
1082
  return PhysXJoint;
971
1083
  }();
972
- PhysXJoint._xAxis = new Vector3(1, 0, 0);
973
1084
  PhysXJoint._defaultVec = new Vector3();
974
1085
  PhysXJoint._defaultQuat = new Quaternion();
975
1086
 
@@ -981,7 +1092,7 @@ PhysXJoint._defaultQuat = new Quaternion();
981
1092
  var _this;
982
1093
  _this = PhysXJoint1.call(this, physXPhysics) || this;
983
1094
  _this._collider = collider;
984
- _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1095
+ _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
985
1096
  return _this;
986
1097
  }
987
1098
  return PhysXFixedJoint;
@@ -993,34 +1104,37 @@ PhysXJoint._defaultQuat = new Quaternion();
993
1104
  _inherits(PhysXHingeJoint, PhysXJoint1);
994
1105
  function PhysXHingeJoint(physXPhysics, collider) {
995
1106
  var _this;
996
- _this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new Quaternion(), _this._swingOffset = new Vector3();
1107
+ _this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new Quaternion();
997
1108
  _this._collider = collider;
998
- _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1109
+ _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
999
1110
  return _this;
1000
1111
  }
1001
1112
  var _proto = PhysXHingeJoint.prototype;
1002
1113
  /**
1003
1114
  * {@inheritDoc IHingeJoint.setAxis }
1004
1115
  */ _proto.setAxis = function setAxis(value) {
1005
- var xAxis = PhysXJoint._xAxis;
1116
+ var xAxis = PhysXHingeJoint._xAxis;
1006
1117
  var axisRotationQuaternion = this._axisRotationQuaternion;
1007
1118
  xAxis.set(1, 0, 0);
1008
1119
  value.normalize();
1009
1120
  var angle = Math.acos(Vector3.dot(xAxis, value));
1010
1121
  Vector3.cross(xAxis, value, xAxis);
1011
1122
  Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
1012
- this._setLocalPose(0, this._swingOffset, axisRotationQuaternion);
1123
+ this._setLocalPose(0, this._anchor, axisRotationQuaternion);
1124
+ this._setLocalPose(1, this._connectedAnchor, axisRotationQuaternion);
1013
1125
  };
1014
- /**
1015
- * {@inheritDoc IHingeJoint.setSwingOffset }
1016
- */ _proto.setSwingOffset = function setSwingOffset(value) {
1017
- this._swingOffset.copyFrom(value);
1018
- this._setLocalPose(1, this._swingOffset, this._axisRotationQuaternion);
1126
+ _proto.setAnchor = function setAnchor(value) {
1127
+ this._setLocalPose(0, value, this._axisRotationQuaternion);
1128
+ this._anchor = value;
1129
+ };
1130
+ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
1131
+ this._setLocalPose(1, value, this._axisRotationQuaternion);
1132
+ this._connectedAnchor = value;
1019
1133
  };
1020
1134
  /**
1021
1135
  * {@inheritDoc IHingeJoint.getAngle }
1022
1136
  */ _proto.getAngle = function getAngle() {
1023
- return this._pxJoint.getAngle();
1137
+ return MathUtil.radianToDegree(this._pxJoint.getAngle());
1024
1138
  };
1025
1139
  /**
1026
1140
  * {@inheritDoc IHingeJoint.getVelocity }
@@ -1030,12 +1144,12 @@ PhysXJoint._defaultQuat = new Quaternion();
1030
1144
  /**
1031
1145
  * {@inheritDoc IHingeJoint.setHardLimitCone }
1032
1146
  */ _proto.setHardLimit = function setHardLimit(lowerLimit, upperLimit, contactDist) {
1033
- this._pxJoint.setHardLimit(lowerLimit, upperLimit, contactDist);
1147
+ this._pxJoint.setHardLimit(MathUtil.degreeToRadian(lowerLimit), MathUtil.degreeToRadian(upperLimit), contactDist);
1034
1148
  };
1035
1149
  /**
1036
1150
  * {@inheritDoc IHingeJoint.setHardLimitCone }
1037
1151
  */ _proto.setSoftLimit = function setSoftLimit(lowerLimit, upperLimit, stiffness, damping) {
1038
- this._pxJoint.setSoftLimit(lowerLimit, upperLimit, stiffness, damping);
1152
+ this._pxJoint.setSoftLimit(MathUtil.degreeToRadian(lowerLimit), MathUtil.degreeToRadian(upperLimit), stiffness, damping);
1039
1153
  };
1040
1154
  /**
1041
1155
  * {@inheritDoc IHingeJoint.setDriveVelocity }
@@ -1060,6 +1174,7 @@ PhysXJoint._defaultQuat = new Quaternion();
1060
1174
  };
1061
1175
  return PhysXHingeJoint;
1062
1176
  }(PhysXJoint);
1177
+ PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
1063
1178
 
1064
1179
  /**
1065
1180
  * a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
@@ -1067,7 +1182,7 @@ PhysXJoint._defaultQuat = new Quaternion();
1067
1182
  _inherits(PhysXSpringJoint, PhysXJoint1);
1068
1183
  function PhysXSpringJoint(physXPhysics, collider) {
1069
1184
  var _this;
1070
- _this = PhysXJoint1.call(this, physXPhysics) || this, _this._swingOffset = new Vector3();
1185
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
1071
1186
  _this._collider = collider;
1072
1187
  _this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1073
1188
  _this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
@@ -1077,12 +1192,6 @@ PhysXJoint._defaultQuat = new Quaternion();
1077
1192
  }
1078
1193
  var _proto = PhysXSpringJoint.prototype;
1079
1194
  /**
1080
- * {@inheritDoc ISpringJoint.setSwingOffset }
1081
- */ _proto.setSwingOffset = function setSwingOffset(value) {
1082
- this._swingOffset.copyFrom(value);
1083
- this._setLocalPose(1, value, PhysXJoint._defaultQuat);
1084
- };
1085
- /**
1086
1195
  * {@inheritDoc ISpringJoint.setMinDistance }
1087
1196
  */ _proto.setMinDistance = function setMinDistance(distance) {
1088
1197
  this._pxJoint.setMinDistance(distance);
@@ -1205,7 +1314,7 @@ PhysXJoint._defaultQuat = new Quaternion();
1205
1314
  if (runtimeMode == PhysXRuntimeMode.JavaScript) {
1206
1315
  script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
1207
1316
  } else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
1208
- script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js";
1317
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*04GyRKeSJw4AAAAAAAAAAAAAARQnAQ/physx.release.js";
1209
1318
  }
1210
1319
  });
1211
1320
  var initializePromise = new Promise(function(resolve, reject) {
@@ -1313,7 +1422,7 @@ PhysXJoint._defaultQuat = new Quaternion();
1313
1422
  }();
1314
1423
 
1315
1424
  //@ts-ignore
1316
- var version = "1.4.0-alpha.0";
1425
+ var version = "1.4.0-alpha.2";
1317
1426
  console.log("Galacean PhysX version: " + version);
1318
1427
 
1319
1428
  export { PhysXPhysics, PhysXRuntimeMode, version };