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

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,11 +1,9 @@
1
1
  import { Vector3, Quaternion } from '@galacean/engine';
2
2
 
3
3
  function _instanceof(left, right) {
4
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
5
- return !!right[Symbol.hasInstance](left);
6
- } else {
7
- return left instanceof right;
8
- }
4
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
5
+ return !!right[Symbol.hasInstance](left);
6
+ } else return left instanceof right;
9
7
  }
10
8
 
11
9
  /**
@@ -17,32 +15,24 @@ function _instanceof(left, right) {
17
15
  PhysXRuntimeMode[PhysXRuntimeMode[/** JavaScript mode. */ "JavaScript"] = 2] = "JavaScript";
18
16
  })(PhysXRuntimeMode || (PhysXRuntimeMode = {}));
19
17
 
20
- function setPrototypeOf(o, p) {
21
- setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(o, p) {
22
- o.__proto__ = p;
23
- return o;
24
- };
18
+ function _set_prototype_of(o, p) {
19
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
20
+ o.__proto__ = p;
25
21
 
26
- return setPrototypeOf(o, p);
27
- }
22
+ return o;
23
+ };
28
24
 
29
- function _setPrototypeOf(o, p) {
30
- return setPrototypeOf(o, p);
25
+ return _set_prototype_of(o, p);
31
26
  }
32
27
 
33
28
  function _inherits(subClass, superClass) {
34
- if (typeof superClass !== "function" && superClass !== null) {
35
- throw new TypeError("Super expression must either be null or a function");
36
- }
37
-
38
- subClass.prototype = Object.create(superClass && superClass.prototype, {
39
- constructor: {
40
- value: subClass,
41
- writable: true,
42
- configurable: true
29
+ if (typeof superClass !== "function" && superClass !== null) {
30
+ throw new TypeError("Super expression must either be null or a function");
43
31
  }
44
- });
45
- if (superClass) _setPrototypeOf(subClass, superClass);
32
+
33
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
34
+
35
+ if (superClass) _set_prototype_of(subClass, superClass);
46
36
  }
47
37
 
48
38
  /**
@@ -109,9 +99,15 @@ function _inherits(subClass, superClass) {
109
99
  };
110
100
  return PhysXJoint;
111
101
  }();
112
- PhysXJoint._xAxis = new Vector3(1, 0, 0);
113
- PhysXJoint._defaultVec = new Vector3();
114
- PhysXJoint._defaultQuat = new Quaternion();
102
+ (function() {
103
+ PhysXJoint._xAxis = new Vector3(1, 0, 0);
104
+ })();
105
+ (function() {
106
+ PhysXJoint._defaultVec = new Vector3();
107
+ })();
108
+ (function() {
109
+ PhysXJoint._defaultQuat = new Quaternion();
110
+ })();
115
111
 
116
112
  /**
117
113
  * A fixed joint permits no relative movement between two colliders. ie the bodies are glued together.
@@ -337,7 +333,21 @@ var ShapeFlag;
337
333
  if (value !== this._position) {
338
334
  this._position.copyFrom(value);
339
335
  }
336
+ var controllers = this._controllers;
337
+ for(var i = 0, n = controllers.length; i < n; i++){
338
+ controllers.get(i)._pxController.setLocalPosition(this._position, this._scale);
339
+ }
340
+ this._setLocalPose();
341
+ };
342
+ /**
343
+ * {@inheritDoc IColliderShape.setWorldScale }
344
+ */ _proto.setWorldScale = function setWorldScale(scale) {
345
+ this._scale.copyFrom(scale);
340
346
  this._setLocalPose();
347
+ var controllers = this._controllers;
348
+ for(var i = 0, n = controllers.length; i < n; i++){
349
+ controllers.get(i)._setLocalPosition(this._position, this._scale);
350
+ }
341
351
  };
342
352
  /**
343
353
  * {@inheritDoc IColliderShape.setContactOffset }
@@ -390,11 +400,15 @@ var ShapeFlag;
390
400
  };
391
401
  return PhysXColliderShape;
392
402
  }();
393
- PhysXColliderShape.halfSqrt = 0.70710678118655;
394
- PhysXColliderShape.transform = {
395
- translation: new Vector3(),
396
- rotation: null
397
- };
403
+ (function() {
404
+ PhysXColliderShape.halfSqrt = 0.70710678118655;
405
+ })();
406
+ (function() {
407
+ PhysXColliderShape.transform = {
408
+ translation: new Vector3(),
409
+ rotation: null
410
+ };
411
+ })();
398
412
 
399
413
  /**
400
414
  * Box collider shape in PhysX.
@@ -414,30 +428,37 @@ PhysXColliderShape.transform = {
414
428
  /**
415
429
  * {@inheritDoc IBoxColliderShape.setSize }
416
430
  */ _proto.setSize = function setSize(value) {
431
+ var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
417
432
  this._halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
418
- Vector3.multiply(this._halfSize, this._scale, PhysXBoxColliderShape._tempHalfExtents);
419
- this._pxGeometry.halfExtents = PhysXBoxColliderShape._tempHalfExtents;
433
+ Vector3.multiply(this._halfSize, this._scale, tempExtents);
434
+ this._pxGeometry.halfExtents = tempExtents;
420
435
  this._pxShape.setGeometry(this._pxGeometry);
421
- var controllers = this._controllers;
422
- for(var i = 0, n = controllers.length; i < n; i++){
423
- var pxController = controllers.get(i)._pxController;
424
- pxController.setHalfHeight(this._halfSize.x);
425
- pxController.setHalfSideExtent(this._halfSize.y);
426
- pxController.setHalfForwardExtent(this._halfSize.z);
427
- }
436
+ this._updateController(tempExtents);
428
437
  };
429
438
  /**
430
439
  * {@inheritDoc IColliderShape.setWorldScale }
431
440
  */ _proto.setWorldScale = function setWorldScale(scale) {
432
- this._scale.copyFrom(scale);
433
- this._setLocalPose();
434
- Vector3.multiply(this._halfSize, this._scale, PhysXBoxColliderShape._tempHalfExtents);
435
- this._pxGeometry.halfExtents = PhysXBoxColliderShape._tempHalfExtents;
441
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
442
+ var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
443
+ Vector3.multiply(this._halfSize, this._scale, tempExtents);
444
+ this._pxGeometry.halfExtents = tempExtents;
436
445
  this._pxShape.setGeometry(this._pxGeometry);
446
+ this._updateController(tempExtents);
447
+ };
448
+ _proto._updateController = function _updateController(extents) {
449
+ var controllers = this._controllers;
450
+ for(var i = 0, n = controllers.length; i < n; i++){
451
+ var pxController = controllers.get(i)._pxController;
452
+ pxController.setHalfHeight(extents.x);
453
+ pxController.setHalfSideExtent(extents.y);
454
+ pxController.setHalfForwardExtent(extents.z);
455
+ }
437
456
  };
438
457
  return PhysXBoxColliderShape;
439
458
  }(PhysXColliderShape);
440
- PhysXBoxColliderShape._tempHalfExtents = new Vector3();
459
+ (function() {
460
+ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
461
+ })();
441
462
 
442
463
  /**
443
464
  * Capsule collider shape in PhysX.
@@ -473,9 +494,10 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
473
494
  break;
474
495
  }
475
496
  this._pxShape.setGeometry(this._pxGeometry);
497
+ var radius = this._pxGeometry.radius;
476
498
  var controllers = this._controllers;
477
499
  for(var i = 0, n = controllers.length; i < n; i++){
478
- controllers.get(i)._pxController.setRadius(value);
500
+ controllers.get(i)._pxController.setRadius(radius);
479
501
  }
480
502
  };
481
503
  /**
@@ -494,9 +516,10 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
494
516
  break;
495
517
  }
496
518
  this._pxShape.setGeometry(this._pxGeometry);
519
+ var height = this._pxGeometry.halfHeight * 2;
497
520
  var controllers = this._controllers;
498
521
  for(var i = 0, n = controllers.length; i < n; i++){
499
- controllers.get(i)._pxController.setHeight(value);
522
+ controllers.get(i)._pxController.setHeight(height);
500
523
  }
501
524
  };
502
525
  /**
@@ -526,23 +549,31 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
526
549
  /**
527
550
  * {@inheritDoc IColliderShape.setWorldScale }
528
551
  */ _proto.setWorldScale = function setWorldScale(scale) {
529
- this._scale.copyFrom(scale);
530
- this._setLocalPose();
552
+ PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
553
+ var geometry = this._pxGeometry;
531
554
  switch(this._upAxis){
532
555
  case 0:
533
- this._pxGeometry.radius = this._radius * Math.max(scale.y, scale.z);
534
- this._pxGeometry.halfHeight = this._halfHeight * scale.x;
556
+ geometry.radius = this._radius * Math.max(scale.y, scale.z);
557
+ geometry.halfHeight = this._halfHeight * scale.x;
535
558
  break;
536
559
  case 1:
537
- this._pxGeometry.radius = this._radius * Math.max(scale.x, scale.z);
538
- this._pxGeometry.halfHeight = this._halfHeight * scale.y;
560
+ geometry.radius = this._radius * Math.max(scale.x, scale.z);
561
+ geometry.halfHeight = this._halfHeight * scale.y;
539
562
  break;
540
563
  case 2:
541
- this._pxGeometry.radius = this._radius * Math.max(scale.x, scale.y);
542
- this._pxGeometry.halfHeight = this._halfHeight * scale.z;
564
+ geometry.radius = this._radius * Math.max(scale.x, scale.y);
565
+ geometry.halfHeight = this._halfHeight * scale.z;
543
566
  break;
544
567
  }
545
- this._pxShape.setGeometry(this._pxGeometry);
568
+ this._pxShape.setGeometry(geometry);
569
+ var radius = geometry.radius;
570
+ var height = geometry.halfHeight * 2;
571
+ var controllers = this._controllers;
572
+ for(var i = 0, n = controllers.length; i < n; i++){
573
+ var pxController = controllers.get(i)._pxController;
574
+ pxController.setRadius(radius);
575
+ pxController.setHeight(height);
576
+ }
546
577
  };
547
578
  return PhysXCapsuleColliderShape;
548
579
  }(PhysXColliderShape);
@@ -559,6 +590,8 @@ var /**
559
590
  * Base class for character controllers.
560
591
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
561
592
  function PhysXCharacterController(physXPhysics) {
593
+ this._scaledOffset = new Vector3();
594
+ this._position = null;
562
595
  this._physXPhysics = physXPhysics;
563
596
  }
564
597
  var _proto = PhysXCharacterController.prototype;
@@ -570,12 +603,17 @@ var /**
570
603
  /**
571
604
  * {@inheritDoc ICharacterController.setWorldPosition }
572
605
  */ _proto.setWorldPosition = function setWorldPosition(position) {
573
- this._pxController && this._pxController.setPosition(position);
606
+ this._position = position;
607
+ if (this._pxController) {
608
+ Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
609
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
610
+ }
574
611
  };
575
612
  /**
576
613
  * {@inheritDoc ICharacterController.getWorldPosition }
577
614
  */ _proto.getWorldPosition = function getWorldPosition(position) {
578
615
  position.copyFrom(this._pxController.getPosition());
616
+ position.subtract(this._scaledOffset);
579
617
  };
580
618
  /**
581
619
  * {@inheritDoc ICharacterController.setStepOffset }
@@ -645,8 +683,17 @@ var /**
645
683
  this._pxController = null;
646
684
  }
647
685
  };
686
+ /**
687
+ * @internal
688
+ */ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
689
+ Vector3.multiply(position, scale, this._scaledOffset);
690
+ this.setWorldPosition(this._position);
691
+ };
648
692
  return PhysXCharacterController;
649
693
  }();
694
+ (function() {
695
+ PhysXCharacterController._tempVec = new Vector3();
696
+ })();
650
697
 
651
698
  /**
652
699
  * Abstract class of physical collider.
@@ -692,10 +739,12 @@ var /**
692
739
  };
693
740
  return PhysXCollider;
694
741
  }();
695
- PhysXCollider._tempTransform = {
696
- translation: null,
697
- rotation: null
698
- };
742
+ (function() {
743
+ PhysXCollider._tempTransform = {
744
+ translation: null,
745
+ rotation: null
746
+ };
747
+ })();
699
748
 
700
749
  var CollisionDetectionMode;
701
750
  (function(CollisionDetectionMode) {
@@ -853,8 +902,12 @@ var CollisionDetectionMode;
853
902
  };
854
903
  return PhysXDynamicCollider;
855
904
  }(PhysXCollider);
856
- PhysXDynamicCollider._tempTranslation = new Vector3();
857
- PhysXDynamicCollider._tempRotation = new Quaternion();
905
+ (function() {
906
+ PhysXDynamicCollider._tempTranslation = new Vector3();
907
+ })();
908
+ (function() {
909
+ PhysXDynamicCollider._tempRotation = new Quaternion();
910
+ })();
858
911
 
859
912
  /**
860
913
  * A manager is a collection of colliders and constraints which can interact.
@@ -1042,8 +1095,12 @@ PhysXDynamicCollider._tempRotation = new Quaternion();
1042
1095
  };
1043
1096
  return PhysXPhysicsManager;
1044
1097
  }();
1045
- PhysXPhysicsManager._tempPosition = new Vector3();
1046
- PhysXPhysicsManager._tempNormal = new Vector3();
1098
+ (function() {
1099
+ PhysXPhysicsManager._tempPosition = new Vector3();
1100
+ })();
1101
+ (function() {
1102
+ PhysXPhysicsManager._tempNormal = new Vector3();
1103
+ })();
1047
1104
  var /**
1048
1105
  * Filtering flags for scene queries.
1049
1106
  */ QueryFlag;
@@ -1151,13 +1208,6 @@ var /**
1151
1208
  _this._setLocalPose();
1152
1209
  return _this;
1153
1210
  }
1154
- var _proto = PhysXPlaneColliderShape.prototype;
1155
- /**
1156
- * {@inheritDoc IColliderShape.setWorldScale }
1157
- */ _proto.setWorldScale = function setWorldScale(scale) {
1158
- this._scale.copyFrom(scale);
1159
- this._setLocalPose();
1160
- };
1161
1211
  return PhysXPlaneColliderShape;
1162
1212
  }(PhysXColliderShape);
1163
1213
 
@@ -1186,8 +1236,7 @@ var /**
1186
1236
  /**
1187
1237
  * {@inheritDoc IColliderShape.setWorldScale }
1188
1238
  */ _proto.setWorldScale = function setWorldScale(scale) {
1189
- this._scale.copyFrom(scale);
1190
- this._setLocalPose();
1239
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
1191
1240
  this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
1192
1241
  this._pxGeometry.radius = this._radius * this._maxScale;
1193
1242
  this._pxShape.setGeometry(this._pxGeometry);