@galacean/engine-physics-physx 0.9.0-beta.80 → 1.0.0-alpha.6

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
@@ -12,28 +12,6 @@ function _instanceof(left, right) {
12
12
  }
13
13
  }
14
14
 
15
- /******************************************************************************
16
- Copyright (c) Microsoft Corporation.
17
-
18
- Permission to use, copy, modify, and/or distribute this software for any
19
- purpose with or without fee is hereby granted.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
- PERFORMANCE OF THIS SOFTWARE.
28
- ***************************************************************************** */
29
-
30
- function __decorate(decorators, target, key, desc) {
31
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
32
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
33
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
34
- return c > 3 && r && Object.defineProperty(target, key, r), r;
35
- }
36
-
37
15
  /**
38
16
  * PhysX runtime mode.
39
17
  */ exports.PhysXRuntimeMode = void 0;
@@ -74,10 +52,11 @@ function _inherits(subClass, superClass) {
74
52
  /**
75
53
  * a base interface providing common functionality for PhysX joints
76
54
  */ var PhysXJoint = /*#__PURE__*/ function() {
77
- function PhysXJoint() {
55
+ function PhysXJoint(physXPhysics) {
78
56
  this._connectedAnchor = new engine.Vector3();
79
57
  this._breakForce = Number.MAX_VALUE;
80
58
  this._breakTorque = Number.MAX_VALUE;
59
+ this._physXPhysics = physXPhysics;
81
60
  }
82
61
  var _proto = PhysXJoint.prototype;
83
62
  /**
@@ -142,11 +121,11 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
142
121
  * A fixed joint permits no relative movement between two colliders. ie the bodies are glued together.
143
122
  */ var PhysXFixedJoint = /*#__PURE__*/ function(PhysXJoint1) {
144
123
  _inherits(PhysXFixedJoint, PhysXJoint1);
145
- function PhysXFixedJoint(collider) {
124
+ function PhysXFixedJoint(physXPhysics, collider) {
146
125
  var _this;
147
- _this = PhysXJoint1.call(this) || this;
126
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
148
127
  _this._collider = collider;
149
- _this._pxJoint = exports.PhysXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
128
+ _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
150
129
  return _this;
151
130
  }
152
131
  return PhysXFixedJoint;
@@ -156,14 +135,14 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
156
135
  * A joint which behaves in a similar way to a hinge or axle.
157
136
  */ var PhysXHingeJoint = /*#__PURE__*/ function(PhysXJoint1) {
158
137
  _inherits(PhysXHingeJoint, PhysXJoint1);
159
- function PhysXHingeJoint(collider) {
138
+ function PhysXHingeJoint(physXPhysics, collider) {
160
139
  var _this;
161
- _this = PhysXJoint1.call(this) || this;
140
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
162
141
  _this._axisRotationQuaternion = new engine.Quaternion();
163
142
  _this._swingOffset = new engine.Vector3();
164
143
  _this._velocity = new engine.Vector3();
165
144
  _this._collider = collider;
166
- _this._pxJoint = exports.PhysXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
145
+ _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
167
146
  return _this;
168
147
  }
169
148
  var _proto = PhysXHingeJoint.prototype;
@@ -234,12 +213,12 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
234
213
  * a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
235
214
  */ var PhysXSpringJoint = /*#__PURE__*/ function(PhysXJoint1) {
236
215
  _inherits(PhysXSpringJoint, PhysXJoint1);
237
- function PhysXSpringJoint(collider) {
216
+ function PhysXSpringJoint(physXPhysics, collider) {
238
217
  var _this;
239
- _this = PhysXJoint1.call(this) || this;
218
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
240
219
  _this._swingOffset = new engine.Vector3();
241
220
  _this._collider = collider;
242
- _this._pxJoint = exports.PhysXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
221
+ _this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
243
222
  _this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
244
223
  _this._pxJoint.setDistanceJointFlag(4, true); // enable min distance;
245
224
  _this._pxJoint.setDistanceJointFlag(8, true); // enable spring;
@@ -335,24 +314,25 @@ var ShapeFlag;
335
314
  /**
336
315
  * Abstract class for collider shapes.
337
316
  */ var PhysXColliderShape = /*#__PURE__*/ function() {
338
- function PhysXColliderShape() {
317
+ function PhysXColliderShape(physXPhysics) {
339
318
  /** @internal */ this._controllers = new DisorderedArray();
340
319
  this._scale = new engine.Vector3(1, 1, 1);
341
320
  this._position = new engine.Vector3();
342
321
  this._rotation = null;
343
322
  this._axis = null;
344
- this._physxRotation = new engine.Quaternion();
323
+ this._physXRotation = new engine.Quaternion();
345
324
  this._shapeFlags = 2 | 1;
346
325
  /** @internal */ this._pxMaterials = new Array(1);
326
+ this._physXPhysics = physXPhysics;
347
327
  }
348
328
  var _proto = PhysXColliderShape.prototype;
349
329
  /**
350
330
  * {@inheritDoc IColliderShape.setRotation }
351
331
  */ _proto.setRotation = function setRotation(value) {
352
332
  this._rotation = value;
353
- engine.Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physxRotation);
354
- this._axis && engine.Quaternion.multiply(this._physxRotation, this._axis, this._physxRotation);
355
- this._physxRotation.normalize();
333
+ engine.Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physXRotation);
334
+ this._axis && engine.Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
335
+ this._physXRotation.normalize();
356
336
  this._setLocalPose();
357
337
  };
358
338
  /**
@@ -395,19 +375,19 @@ var ShapeFlag;
395
375
  * @internal
396
376
  */ _proto._setShapeFlags = function _setShapeFlags(flags) {
397
377
  this._shapeFlags = flags;
398
- this._pxShape.setFlags(new exports.PhysXPhysics._physX.PxShapeFlags(this._shapeFlags));
378
+ this._pxShape.setFlags(new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
399
379
  };
400
380
  _proto._setLocalPose = function _setLocalPose() {
401
381
  var transform = PhysXColliderShape.transform;
402
382
  engine.Vector3.multiply(this._position, this._scale, transform.translation);
403
- transform.rotation = this._physxRotation;
383
+ transform.rotation = this._physXRotation;
404
384
  this._pxShape.setLocalPose(transform);
405
385
  };
406
386
  _proto._initialize = function _initialize(material, id) {
407
387
  this._id = id;
408
388
  this._pxMaterials[0] = material._pxMaterial;
409
- this._pxShape = exports.PhysXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new exports.PhysXPhysics._physX.PxShapeFlags(this._shapeFlags));
410
- this._pxShape.setQueryFilterData(new exports.PhysXPhysics._physX.PxFilterData(id, 0, 0, 0));
389
+ this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
390
+ this._pxShape.setUUID(id);
411
391
  };
412
392
  _proto._modifyFlag = function _modifyFlag(flag, value) {
413
393
  this._shapeFlags = value ? this._shapeFlags | flag : this._shapeFlags & ~flag;
@@ -424,12 +404,12 @@ PhysXColliderShape.transform = {
424
404
  * Box collider shape in PhysX.
425
405
  */ var PhysXBoxColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
426
406
  _inherits(PhysXBoxColliderShape, PhysXColliderShape);
427
- function PhysXBoxColliderShape(uniqueID, size, material) {
407
+ function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
428
408
  var _this;
429
- _this = PhysXColliderShape.call(this) || this;
409
+ _this = PhysXColliderShape.call(this, physXPhysics) || this;
430
410
  /** @internal */ _this._halfSize = new engine.Vector3();
431
411
  _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
432
- _this._pxGeometry = new exports.PhysXPhysics._physX.PxBoxGeometry(_this._halfSize.x * _this._scale.x, _this._halfSize.y * _this._scale.y, _this._halfSize.z * _this._scale.z);
412
+ _this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(_this._halfSize.x * _this._scale.x, _this._halfSize.y * _this._scale.y, _this._halfSize.z * _this._scale.z);
433
413
  _this._initialize(material, uniqueID);
434
414
  _this._setLocalPose();
435
415
  return _this;
@@ -467,15 +447,15 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
467
447
  * Capsule collider shape in PhysX.
468
448
  */ var PhysXCapsuleColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
469
449
  _inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
470
- function PhysXCapsuleColliderShape(uniqueID, radius, height, material) {
450
+ function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
471
451
  var _this;
472
- _this = PhysXColliderShape1.call(this) || this;
452
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this;
473
453
  _this._upAxis = /** Up axis is Y. */ 1;
474
454
  _this._radius = radius;
475
455
  _this._halfHeight = height * 0.5;
476
456
  _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
477
- _this._physxRotation.copyFrom(_this._axis);
478
- _this._pxGeometry = new exports.PhysXPhysics._physX.PxCapsuleGeometry(_this._radius, _this._halfHeight);
457
+ _this._physXRotation.copyFrom(_this._axis);
458
+ _this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(_this._radius, _this._halfHeight);
479
459
  _this._initialize(material, uniqueID);
480
460
  _this._setLocalPose();
481
461
  return _this;
@@ -526,7 +506,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
526
506
  /**
527
507
  * {@inheritDoc ICapsuleColliderShape.setUpAxis }
528
508
  */ _proto.setUpAxis = function setUpAxis(upAxis) {
529
- var _this = this, rotation = _this._rotation, axis = _this._axis, physxRotation = _this._physxRotation;
509
+ var _this = this, rotation = _this._rotation, axis = _this._axis, physXRotation = _this._physXRotation;
530
510
  this._upAxis = upAxis;
531
511
  switch(this._upAxis){
532
512
  case 0:
@@ -540,10 +520,10 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
540
520
  break;
541
521
  }
542
522
  if (rotation) {
543
- engine.Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physxRotation);
544
- engine.Quaternion.multiply(physxRotation, axis, physxRotation);
523
+ engine.Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physXRotation);
524
+ engine.Quaternion.multiply(physXRotation, axis, physXRotation);
545
525
  } else {
546
- physxRotation.copyFrom(axis);
526
+ physXRotation.copyFrom(axis);
547
527
  }
548
528
  this._setLocalPose();
549
529
  };
@@ -582,7 +562,9 @@ var /**
582
562
  /**
583
563
  * Base class for character controllers.
584
564
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
585
- function PhysXCharacterController() {}
565
+ function PhysXCharacterController(physXPhysics) {
566
+ this._physXPhysics = physXPhysics;
567
+ }
586
568
  var _proto = PhysXCharacterController.prototype;
587
569
  /**
588
570
  * {@inheritDoc ICharacterController.move }
@@ -643,12 +625,12 @@ var /**
643
625
  */ _proto._createPXController = function _createPXController(pxManager, shape) {
644
626
  var desc;
645
627
  if (_instanceof(shape, PhysXBoxColliderShape)) {
646
- desc = new exports.PhysXPhysics._physX.PxBoxControllerDesc();
628
+ desc = new this._physXPhysics._physX.PxBoxControllerDesc();
647
629
  desc.halfHeight = shape._halfSize.x;
648
630
  desc.halfSideExtent = shape._halfSize.y;
649
631
  desc.halfForwardExtent = shape._halfSize.z;
650
632
  } else if (_instanceof(shape, PhysXCapsuleColliderShape)) {
651
- desc = new exports.PhysXPhysics._physX.PxCapsuleControllerDesc();
633
+ desc = new this._physXPhysics._physX.PxCapsuleControllerDesc();
652
634
  desc.radius = shape._radius;
653
635
  desc.height = shape._halfHeight * 2;
654
636
  desc.climbingMode = 1; // constraint mode
@@ -657,7 +639,7 @@ var /**
657
639
  }
658
640
  desc.setMaterial(shape._pxMaterials[0]);
659
641
  this._pxController = pxManager._getControllerManager().createController(desc);
660
- this._pxController.setQueryFilterData(new exports.PhysXPhysics._physX.PxFilterData(shape._id, 0, 0, 0));
642
+ this._pxController.setUUID(shape._id);
661
643
  };
662
644
  /**
663
645
  * @internal
@@ -673,7 +655,9 @@ var /**
673
655
  /**
674
656
  * Abstract class of physical collider.
675
657
  */ var PhysXCollider = /*#__PURE__*/ function() {
676
- function PhysXCollider() {}
658
+ function PhysXCollider(physXPhysics) {
659
+ this._physXPhysics = physXPhysics;
660
+ }
677
661
  var _proto = PhysXCollider.prototype;
678
662
  /**
679
663
  * {@inheritDoc ICollider.addShape }
@@ -728,11 +712,11 @@ var CollisionDetectionMode;
728
712
  * A dynamic collider can act with self-defined movement or physical force
729
713
  */ var PhysXDynamicCollider = /*#__PURE__*/ function(PhysXCollider) {
730
714
  _inherits(PhysXDynamicCollider, PhysXCollider);
731
- function PhysXDynamicCollider(position, rotation) {
715
+ function PhysXDynamicCollider(physXPhysics, position, rotation) {
732
716
  var _this;
733
- _this = PhysXCollider.call(this) || this;
717
+ _this = PhysXCollider.call(this, physXPhysics) || this;
734
718
  var transform = _this._transform(position, rotation);
735
- _this._pxActor = exports.PhysXPhysics._pxPhysics.createRigidDynamic(transform);
719
+ _this._pxActor = physXPhysics._pxPhysics.createRigidDynamic(transform);
736
720
  return _this;
737
721
  }
738
722
  var _proto = PhysXDynamicCollider.prototype;
@@ -797,18 +781,19 @@ var CollisionDetectionMode;
797
781
  */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
798
782
  switch(value){
799
783
  case 1:
800
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
784
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
801
785
  break;
802
786
  case 2:
803
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
787
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
804
788
  break;
805
789
  case 3:
806
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
790
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
807
791
  break;
808
792
  case 0:
809
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, false);
810
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
811
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
793
+ var physX = this._physXPhysics._physX;
794
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
795
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
796
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
812
797
  break;
813
798
  }
814
799
  };
@@ -816,9 +801,9 @@ var CollisionDetectionMode;
816
801
  * {@inheritDoc IDynamicCollider.setIsKinematic }
817
802
  */ _proto.setIsKinematic = function setIsKinematic(value) {
818
803
  if (value) {
819
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
804
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
820
805
  } else {
821
- this._pxActor.setRigidBodyFlag(exports.PhysXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
806
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
822
807
  }
823
808
  };
824
809
  /**
@@ -878,12 +863,17 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
878
863
  /**
879
864
  * A manager is a collection of colliders and constraints which can interact.
880
865
  */ var PhysXPhysicsManager = /*#__PURE__*/ function() {
881
- function PhysXPhysicsManager(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
866
+ function PhysXPhysicsManager(physXPhysics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
882
867
  var _this = this;
883
868
  /** @internal */ this._pxControllerManager = null;
884
869
  this._currentEvents = new DisorderedArray();
885
870
  this._eventMap = {};
886
871
  this._eventPool = [];
872
+ this._physXPhysics = physXPhysics;
873
+ var physX = physXPhysics._physX;
874
+ this._pxRaycastHit = new physX.PxRaycastHit();
875
+ this._pxFilterData = new physX.PxQueryFilterData();
876
+ this._pxFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4);
887
877
  this._onContactEnter = onContactEnter;
888
878
  this._onContactExit = onContactExit;
889
879
  this._onContactStay = onContactStay;
@@ -891,31 +881,21 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
891
881
  this._onTriggerExit = onTriggerExit;
892
882
  this._onTriggerStay = onTriggerStay;
893
883
  var triggerCallback = {
894
- onContactBegin: function(obj1, obj2) {
895
- var index1 = obj1.getQueryFilterData().word0;
896
- var index2 = obj2.getQueryFilterData().word0;
884
+ onContactBegin: function(index1, index2) {
897
885
  _this._onContactEnter(index1, index2);
898
886
  },
899
- onContactEnd: function(obj1, obj2) {
900
- var index1 = obj1.getQueryFilterData().word0;
901
- var index2 = obj2.getQueryFilterData().word0;
887
+ onContactEnd: function(index1, index2) {
902
888
  _this._onContactExit(index1, index2);
903
889
  },
904
- onContactPersist: function(obj1, obj2) {
905
- var index1 = obj1.getQueryFilterData().word0;
906
- var index2 = obj2.getQueryFilterData().word0;
890
+ onContactPersist: function(index1, index2) {
907
891
  _this._onContactStay(index1, index2);
908
892
  },
909
- onTriggerBegin: function(obj1, obj2) {
910
- var index1 = obj1.getQueryFilterData().word0;
911
- var index2 = obj2.getQueryFilterData().word0;
893
+ onTriggerBegin: function(index1, index2) {
912
894
  var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
913
895
  event.state = 0;
914
896
  _this._currentEvents.add(event);
915
897
  },
916
- onTriggerEnd: function(obj1, obj2) {
917
- var index1 = obj1.getQueryFilterData().word0;
918
- var index2 = obj2.getQueryFilterData().word0;
898
+ onTriggerEnd: function(index1, index2) {
919
899
  var event;
920
900
  if (index1 < index2) {
921
901
  var subMap = _this._eventMap[index1];
@@ -929,9 +909,10 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
929
909
  event.state = 2;
930
910
  }
931
911
  };
932
- var PHYSXSimulationCallbackInstance = exports.PhysXPhysics._physX.PxSimulationEventCallback.implement(triggerCallback);
933
- var sceneDesc = exports.PhysXPhysics._physX.getDefaultSceneDesc(exports.PhysXPhysics._pxPhysics.getTolerancesScale(), 0, PHYSXSimulationCallbackInstance);
934
- this._pxScene = exports.PhysXPhysics._pxPhysics.createScene(sceneDesc);
912
+ var pxPhysics = physXPhysics._pxPhysics;
913
+ var physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
914
+ var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, physXSimulationCallbackInstance);
915
+ this._pxScene = pxPhysics.createScene(sceneDesc);
935
916
  }
936
917
  var _proto = PhysXPhysicsManager.prototype;
937
918
  /**
@@ -978,16 +959,13 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
978
959
  lastPXManager && characterController._destroyPXController();
979
960
  characterController._createPXController(this, shape);
980
961
  }
981
- this._pxScene.addController(characterController._pxController);
982
962
  }
983
963
  characterController._pxManager = this;
984
964
  };
985
965
  /**
986
966
  * {@inheritDoc IPhysicsManager.removeCharacterController }
987
967
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
988
- if (characterController._shape) {
989
- this._pxScene.removeController(characterController._pxController);
990
- }
968
+ characterController._pxController = null;
991
969
  characterController._pxManager = null;
992
970
  };
993
971
  /**
@@ -1000,11 +978,10 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
1000
978
  /**
1001
979
  * {@inheritDoc IPhysicsManager.raycast }
1002
980
  */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
1003
- var pxHitResult = PhysXPhysicsManager._pxRaycastHit;
981
+ var _this = this, pxHitResult = _this._pxRaycastHit;
1004
982
  distance = Math.min(distance, 3.4e38); // float32 max value limit in physx raycast.
1005
983
  var raycastCallback = {
1006
- preFilter: function(filterData, shape, actor) {
1007
- var index = shape.getQueryFilterData().word0;
984
+ preFilter: function(filterData, index, actor) {
1008
985
  if (onRaycast(index)) {
1009
986
  return 2; // eBLOCK
1010
987
  } else {
@@ -1013,13 +990,13 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
1013
990
  },
1014
991
  postFilter: function(filterData, hit) {}
1015
992
  };
1016
- var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, PhysXPhysicsManager._pxFilterData, exports.PhysXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback));
993
+ var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback));
1017
994
  if (result && hit != undefined) {
1018
995
  var position = PhysXPhysicsManager._tempPosition, normal = PhysXPhysicsManager._tempNormal;
1019
996
  var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
1020
997
  position.set(pxPosition.x, pxPosition.y, pxPosition.z);
1021
998
  normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
1022
- hit(pxHitResult.getShape().getQueryFilterData().word0, pxHitResult.distance, position, normal);
999
+ hit(pxHitResult.getShape().getUUID(), pxHitResult.distance, position, normal);
1023
1000
  }
1024
1001
  return result;
1025
1002
  };
@@ -1067,11 +1044,6 @@ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
1067
1044
  }
1068
1045
  }
1069
1046
  };
1070
- PhysXPhysicsManager._init = function _init() {
1071
- PhysXPhysicsManager._pxRaycastHit = new exports.PhysXPhysics._physX.PxRaycastHit();
1072
- PhysXPhysicsManager._pxFilterData = new exports.PhysXPhysics._physX.PxQueryFilterData();
1073
- PhysXPhysicsManager._pxFilterData.flags = new exports.PhysXPhysics._physX.PxQueryFlags(1 | 2 | 4);
1074
- };
1075
1047
  return PhysXPhysicsManager;
1076
1048
  }();
1077
1049
  PhysXPhysicsManager._tempPosition = new engine.Vector3();
@@ -1105,8 +1077,9 @@ var /**
1105
1077
  /**
1106
1078
  * Physics material describes how to handle colliding objects (friction, bounciness).
1107
1079
  */ var PhysXPhysicsMaterial = /*#__PURE__*/ function() {
1108
- function PhysXPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1109
- var pxMaterial = exports.PhysXPhysics._pxPhysics.createMaterial(staticFriction, dynamicFriction, bounciness);
1080
+ function PhysXPhysicsMaterial(physXPhysics, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1081
+ this._physXPhysics = physXPhysics;
1082
+ var pxMaterial = physXPhysics._pxPhysics.createMaterial(staticFriction, dynamicFriction, bounciness);
1110
1083
  pxMaterial.setFrictionCombineMode(frictionCombine);
1111
1084
  pxMaterial.setRestitutionCombineMode(bounceCombine);
1112
1085
  this._pxMaterial = pxMaterial;
@@ -1159,10 +1132,10 @@ var /**
1159
1132
  * @remarks Mostly used for object which always stays at the same place and never moves around.
1160
1133
  */ var PhysXStaticCollider = /*#__PURE__*/ function(PhysXCollider) {
1161
1134
  _inherits(PhysXStaticCollider, PhysXCollider);
1162
- function PhysXStaticCollider(position, rotation) {
1135
+ function PhysXStaticCollider(physXPhysics, position, rotation) {
1163
1136
  var _this;
1164
- _this = PhysXCollider.call(this) || this;
1165
- _this._pxActor = exports.PhysXPhysics._pxPhysics.createRigidStatic(_this._transform(position, rotation));
1137
+ _this = PhysXCollider.call(this, physXPhysics) || this;
1138
+ _this._pxActor = physXPhysics._pxPhysics.createRigidStatic(_this._transform(position, rotation));
1166
1139
  return _this;
1167
1140
  }
1168
1141
  return PhysXStaticCollider;
@@ -1172,12 +1145,12 @@ var /**
1172
1145
  * Plane collider shape in PhysX.
1173
1146
  */ var PhysXPlaneColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
1174
1147
  _inherits(PhysXPlaneColliderShape, PhysXColliderShape1);
1175
- function PhysXPlaneColliderShape(uniqueID, material) {
1148
+ function PhysXPlaneColliderShape(physXPhysics, uniqueID, material) {
1176
1149
  var _this;
1177
- _this = PhysXColliderShape1.call(this) || this;
1150
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this;
1178
1151
  _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
1179
- _this._physxRotation.copyFrom(_this._axis);
1180
- _this._pxGeometry = new exports.PhysXPhysics._physX.PxPlaneGeometry();
1152
+ _this._physXRotation.copyFrom(_this._axis);
1153
+ _this._pxGeometry = new physXPhysics._physX.PxPlaneGeometry();
1181
1154
  _this._initialize(material, uniqueID);
1182
1155
  _this._setLocalPose();
1183
1156
  return _this;
@@ -1196,12 +1169,12 @@ var /**
1196
1169
  * Sphere collider shape in PhysX.
1197
1170
  */ var PhysXSphereColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
1198
1171
  _inherits(PhysXSphereColliderShape, PhysXColliderShape);
1199
- function PhysXSphereColliderShape(uniqueID, radius, material) {
1172
+ function PhysXSphereColliderShape(physXPhysics, uniqueID, radius, material) {
1200
1173
  var _this;
1201
- _this = PhysXColliderShape.call(this) || this;
1174
+ _this = PhysXColliderShape.call(this, physXPhysics) || this;
1202
1175
  _this._maxScale = 1;
1203
1176
  _this._radius = radius;
1204
- _this._pxGeometry = new exports.PhysXPhysics._physX.PxSphereGeometry(_this._radius * _this._maxScale);
1177
+ _this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(_this._radius * _this._maxScale);
1205
1178
  _this._initialize(material, uniqueID);
1206
1179
  _this._setLocalPose();
1207
1180
  return _this;
@@ -1227,21 +1200,26 @@ var /**
1227
1200
  }(PhysXColliderShape);
1228
1201
 
1229
1202
  /**
1230
- * Static interface implement decorator.
1231
- * https://stackoverflow.com/questions/13955157/how-to-define-static-property-in-typescript-interface
1232
- */ function StaticInterfaceImplement() {
1233
- return function(constructor) {
1234
- };
1235
- }
1236
-
1237
- exports.PhysXPhysics = /*#__PURE__*/ function() {
1238
- function PhysXPhysics1() {}
1203
+ * PhysX object creation.
1204
+ */ var PhysXPhysics = /*#__PURE__*/ function() {
1205
+ function PhysXPhysics(runtimeMode) {
1206
+ if (runtimeMode === void 0) runtimeMode = exports.PhysXRuntimeMode.Auto;
1207
+ this._initializeState = 0;
1208
+ this._runTimeMode = runtimeMode;
1209
+ }
1210
+ var _proto = PhysXPhysics.prototype;
1239
1211
  /**
1240
1212
  * Initialize PhysXPhysics.
1241
1213
  * @param runtimeMode - Runtime mode
1242
1214
  * @returns Promise object
1243
- */ PhysXPhysics1.initialize = function initialize(runtimeMode) {
1244
- if (runtimeMode === void 0) runtimeMode = exports.PhysXRuntimeMode.Auto;
1215
+ */ _proto.initialize = function initialize() {
1216
+ var _this = this;
1217
+ if (this._initializeState === 2) {
1218
+ return Promise.resolve();
1219
+ } else if (this._initializeState === 1) {
1220
+ return this._initializePromise;
1221
+ }
1222
+ var runtimeMode = this._runTimeMode;
1245
1223
  var scriptPromise = new Promise(function(resolve, reject) {
1246
1224
  var script = document.createElement("script");
1247
1225
  document.body.appendChild(script);
@@ -1265,105 +1243,115 @@ exports.PhysXPhysics = /*#__PURE__*/ function() {
1265
1243
  }
1266
1244
  }
1267
1245
  if (runtimeMode == exports.PhysXRuntimeMode.JavaScript) {
1268
- script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/0.9.0-beta.56/libs/physx.release.js.js";
1246
+ script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js.js";
1269
1247
  } else if (runtimeMode == exports.PhysXRuntimeMode.WebAssembly) {
1270
- script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/0.9.0-beta.56/libs/physx.release.js";
1248
+ script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js";
1271
1249
  }
1272
1250
  });
1273
- return new Promise(function(resolve, reject) {
1251
+ var initializePromise = new Promise(function(resolve, reject) {
1274
1252
  scriptPromise.then(function() {
1275
1253
  return window.PHYSX().then(function(PHYSX) {
1276
- exports.PhysXPhysics._init(PHYSX);
1254
+ _this._init(PHYSX);
1255
+ _this._initializeState = 2;
1256
+ _this._initializePromise = null;
1277
1257
  console.log("PhysX loaded.");
1278
1258
  resolve();
1279
1259
  }, reject);
1280
1260
  }, reject).catch(reject);
1281
1261
  });
1262
+ this._initializePromise = initializePromise;
1263
+ return initializePromise;
1282
1264
  };
1283
1265
  /**
1284
1266
  * Destroy PhysXPhysics.
1285
- */ PhysXPhysics1.destroy = function destroy() {
1286
- this._pxFoundation.release();
1267
+ */ _proto.destroy = function destroy() {
1268
+ this._physX.PxCloseExtensions();
1287
1269
  this._pxPhysics.release();
1270
+ this._pxFoundation.release();
1288
1271
  this._physX = null;
1289
1272
  this._pxFoundation = null;
1290
1273
  this._pxPhysics = null;
1291
1274
  };
1292
1275
  /**
1293
1276
  * {@inheritDoc IPhysics.createPhysicsManager }
1294
- */ PhysXPhysics1.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
1295
- return new PhysXPhysicsManager(onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
1277
+ */ _proto.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
1278
+ var manager = new PhysXPhysicsManager(this, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
1279
+ return manager;
1296
1280
  };
1297
1281
  /**
1298
1282
  * {@inheritDoc IPhysics.createStaticCollider }
1299
- */ PhysXPhysics1.createStaticCollider = function createStaticCollider(position, rotation) {
1300
- return new PhysXStaticCollider(position, rotation);
1283
+ */ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
1284
+ return new PhysXStaticCollider(this, position, rotation);
1301
1285
  };
1302
1286
  /**
1303
1287
  * {@inheritDoc IPhysics.createDynamicCollider }
1304
- */ PhysXPhysics1.createDynamicCollider = function createDynamicCollider(position, rotation) {
1305
- return new PhysXDynamicCollider(position, rotation);
1288
+ */ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
1289
+ return new PhysXDynamicCollider(this, position, rotation);
1306
1290
  };
1307
1291
  /**
1308
1292
  * {@inheritDoc IPhysics.createCharacterController }
1309
- */ PhysXPhysics1.createCharacterController = function createCharacterController() {
1310
- return new PhysXCharacterController();
1293
+ */ _proto.createCharacterController = function createCharacterController() {
1294
+ return new PhysXCharacterController(this);
1311
1295
  };
1312
1296
  /**
1313
1297
  * {@inheritDoc IPhysics.createPhysicsMaterial }
1314
- */ PhysXPhysics1.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1315
- return new PhysXPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1298
+ */ _proto.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1299
+ return new PhysXPhysicsMaterial(this, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1316
1300
  };
1317
1301
  /**
1318
1302
  * {@inheritDoc IPhysics.createBoxColliderShape }
1319
- */ PhysXPhysics1.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1320
- return new PhysXBoxColliderShape(uniqueID, size, material);
1303
+ */ _proto.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1304
+ return new PhysXBoxColliderShape(this, uniqueID, size, material);
1321
1305
  };
1322
1306
  /**
1323
1307
  * {@inheritDoc IPhysics.createSphereColliderShape }
1324
- */ PhysXPhysics1.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1325
- return new PhysXSphereColliderShape(uniqueID, radius, material);
1308
+ */ _proto.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1309
+ return new PhysXSphereColliderShape(this, uniqueID, radius, material);
1326
1310
  };
1327
1311
  /**
1328
1312
  * {@inheritDoc IPhysics.createPlaneColliderShape }
1329
- */ PhysXPhysics1.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1330
- return new PhysXPlaneColliderShape(uniqueID, material);
1313
+ */ _proto.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1314
+ return new PhysXPlaneColliderShape(this, uniqueID, material);
1331
1315
  };
1332
1316
  /**
1333
1317
  * {@inheritDoc IPhysics.createCapsuleColliderShape }
1334
- */ PhysXPhysics1.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1335
- return new PhysXCapsuleColliderShape(uniqueID, radius, height, material);
1318
+ */ _proto.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1319
+ return new PhysXCapsuleColliderShape(this, uniqueID, radius, height, material);
1336
1320
  };
1337
1321
  /**
1338
1322
  * {@inheritDoc IPhysics.createFixedJoint }
1339
- */ PhysXPhysics1.createFixedJoint = function createFixedJoint(collider) {
1340
- return new PhysXFixedJoint(collider);
1323
+ */ _proto.createFixedJoint = function createFixedJoint(collider) {
1324
+ return new PhysXFixedJoint(this, collider);
1341
1325
  };
1342
1326
  /**
1343
1327
  * {@inheritDoc IPhysics.createHingeJoint }
1344
- */ PhysXPhysics1.createHingeJoint = function createHingeJoint(collider) {
1345
- return new PhysXHingeJoint(collider);
1328
+ */ _proto.createHingeJoint = function createHingeJoint(collider) {
1329
+ return new PhysXHingeJoint(this, collider);
1346
1330
  };
1347
1331
  /**
1348
1332
  * {@inheritDoc IPhysics.createSpringJoint }
1349
- */ PhysXPhysics1.createSpringJoint = function createSpringJoint(collider) {
1350
- return new PhysXSpringJoint(collider);
1333
+ */ _proto.createSpringJoint = function createSpringJoint(collider) {
1334
+ return new PhysXSpringJoint(this, collider);
1351
1335
  };
1352
- PhysXPhysics1._init = function _init(physX) {
1336
+ _proto._init = function _init(physX) {
1353
1337
  var version = physX.PX_PHYSICS_VERSION;
1354
1338
  var defaultErrorCallback = new physX.PxDefaultErrorCallback();
1355
1339
  var allocator = new physX.PxDefaultAllocator();
1356
1340
  var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
1357
1341
  var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, new physX.PxTolerancesScale(), false, null);
1358
1342
  physX.PxInitExtensions(pxPhysics, null);
1359
- exports.PhysXPhysics._physX = physX;
1360
- exports.PhysXPhysics._pxFoundation = pxFoundation;
1361
- exports.PhysXPhysics._pxPhysics = pxPhysics;
1362
- PhysXPhysicsManager._init();
1343
+ this._physX = physX;
1344
+ this._pxFoundation = pxFoundation;
1345
+ this._pxPhysics = pxPhysics;
1363
1346
  };
1364
- return PhysXPhysics1;
1347
+ return PhysXPhysics;
1365
1348
  }();
1366
- exports.PhysXPhysics = __decorate([
1367
- StaticInterfaceImplement()
1368
- ], exports.PhysXPhysics);
1349
+ var InitializeState;
1350
+ (function(InitializeState) {
1351
+ InitializeState[InitializeState["Uninitialized"] = 0] = "Uninitialized";
1352
+ InitializeState[InitializeState["Initializing"] = 1] = "Initializing";
1353
+ InitializeState[InitializeState["Initialized"] = 2] = "Initialized";
1354
+ })(InitializeState || (InitializeState = {}));
1355
+
1356
+ exports.PhysXPhysics = PhysXPhysics;
1369
1357
  //# sourceMappingURL=main.js.map