@galacean/engine-physics-physx 1.1.0-beta.2 → 1.1.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -93,7 +93,6 @@
93
93
  this._axis = null;
94
94
  this._physXRotation = new engine.Quaternion();
95
95
  this._shapeFlags = 2 | 1;
96
- /** @internal */ this._pxMaterials = new Array(1);
97
96
  this._physXPhysics = physXPhysics;
98
97
  }
99
98
  var _proto = PhysXColliderShape.prototype;
@@ -114,7 +113,7 @@
114
113
  }
115
114
  var controllers = this._controllers;
116
115
  for(var i = 0, n = controllers.length; i < n; i++){
117
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
116
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
118
117
  }
119
118
  this._setLocalPose();
120
119
  };
@@ -125,7 +124,7 @@
125
124
  this._setLocalPose();
126
125
  var controllers = this._controllers;
127
126
  for(var i = 0, n = controllers.length; i < n; i++){
128
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
127
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
129
128
  }
130
129
  };
131
130
  /**
@@ -141,8 +140,8 @@
141
140
  /**
142
141
  * {@inheritDoc IColliderShape.setMaterial }
143
142
  */ _proto.setMaterial = function setMaterial(value) {
144
- this._pxMaterials[0] = value._pxMaterial;
145
- this._pxShape.setMaterials(this._pxMaterials);
143
+ this._pxMaterial = value._pxMaterial;
144
+ this._pxShape.setMaterial(this._pxMaterial);
146
145
  };
147
146
  /**
148
147
  * {@inheritDoc IColliderShape.setIsTrigger }
@@ -170,7 +169,7 @@
170
169
  };
171
170
  _proto._initialize = function _initialize(material, id) {
172
171
  this._id = id;
173
- this._pxMaterials[0] = material._pxMaterial;
172
+ this._pxMaterial = material._pxMaterial;
174
173
  this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
175
174
  this._pxShape.setUUID(id);
176
175
  };
@@ -369,50 +368,55 @@
369
368
  * Base class for character controllers.
370
369
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
371
370
  function PhysXCharacterController(physXPhysics) {
372
- this._scaledOffset = new engine.Vector3();
373
- this._position = null;
371
+ this._shapeScaledPosition = new engine.Vector3();
372
+ this._worldPosition = null;
374
373
  this._physXPhysics = physXPhysics;
375
374
  }
376
375
  var _proto = PhysXCharacterController.prototype;
377
376
  /**
378
377
  * {@inheritDoc ICharacterController.move }
379
378
  */ _proto.move = function move(disp, minDist, elapsedTime) {
380
- return this._pxController.move(disp, minDist, elapsedTime);
379
+ var _this__pxController;
380
+ var _this__pxController_move;
381
+ return (_this__pxController_move = (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.move(disp, minDist, elapsedTime)) != null ? _this__pxController_move : 0;
381
382
  };
382
383
  /**
383
384
  * {@inheritDoc ICharacterController.setWorldPosition }
384
385
  */ _proto.setWorldPosition = function setWorldPosition(position) {
385
- this._position = position;
386
- if (this._pxController) {
387
- engine.Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
388
- this._pxController.setPosition(PhysXCharacterController._tempVec);
389
- }
386
+ this._worldPosition = position;
387
+ this._updateNativePosition();
390
388
  };
391
389
  /**
392
390
  * {@inheritDoc ICharacterController.getWorldPosition }
393
391
  */ _proto.getWorldPosition = function getWorldPosition(position) {
394
- position.copyFrom(this._pxController.getPosition());
395
- position.subtract(this._scaledOffset);
392
+ if (this._pxController) {
393
+ position.copyFrom(this._pxController.getPosition());
394
+ position.subtract(this._shapeScaledPosition);
395
+ }
396
396
  };
397
397
  /**
398
398
  * {@inheritDoc ICharacterController.setStepOffset }
399
399
  */ _proto.setStepOffset = function setStepOffset(offset) {
400
- this._pxController.setStepOffset(offset);
400
+ var _this__pxController;
401
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setStepOffset(offset);
401
402
  };
402
403
  /**
403
404
  * {@inheritDoc ICharacterController.setNonWalkableMode }
404
405
  */ _proto.setNonWalkableMode = function setNonWalkableMode(flag) {
405
- this._pxController.setNonWalkableMode(flag);
406
+ var _this__pxController;
407
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setNonWalkableMode(flag);
406
408
  };
407
409
  /**
408
410
  * {@inheritDoc ICharacterController.setUpDirection }
409
411
  */ _proto.setUpDirection = function setUpDirection(up) {
410
- this._pxController.setUpDirection(up);
412
+ var _this__pxController;
413
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setUpDirection(up);
411
414
  };
412
415
  /**
413
416
  * {@inheritDoc ICharacterController.setSlopeLimit }
414
417
  */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
415
- this._pxController.setSlopeLimit(slopeLimit);
418
+ var _this__pxController;
419
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(slopeLimit);
416
420
  };
417
421
  /**
418
422
  * {@inheritDoc ICharacterController.addShape }
@@ -450,7 +454,7 @@
450
454
  } else {
451
455
  throw "unsupported shape type";
452
456
  }
453
- desc.setMaterial(shape._pxMaterials[0]);
457
+ desc.setMaterial(shape._pxMaterial);
454
458
  this._pxController = pxManager._getControllerManager().createController(desc);
455
459
  this._pxController.setUUID(shape._id);
456
460
  };
@@ -464,9 +468,16 @@
464
468
  };
465
469
  /**
466
470
  * @internal
467
- */ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
468
- engine.Vector3.multiply(position, scale, this._scaledOffset);
469
- this.setWorldPosition(position);
471
+ */ _proto._updateShapePosition = function _updateShapePosition(shapePosition, worldScale) {
472
+ engine.Vector3.multiply(shapePosition, worldScale, this._shapeScaledPosition);
473
+ this._updateNativePosition();
474
+ };
475
+ _proto._updateNativePosition = function _updateNativePosition() {
476
+ var worldPosition = this._worldPosition;
477
+ if (this._pxController && worldPosition) {
478
+ engine.Vector3.add(worldPosition, this._shapeScaledPosition, PhysXCharacterController._tempVec);
479
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
480
+ }
470
481
  };
471
482
  return PhysXCharacterController;
472
483
  }();
@@ -1085,7 +1096,6 @@
1085
1096
  _this = PhysXJoint1.call(this, physXPhysics) || this;
1086
1097
  _this._axisRotationQuaternion = new engine.Quaternion();
1087
1098
  _this._swingOffset = new engine.Vector3();
1088
- _this._velocity = new engine.Vector3();
1089
1099
  _this._collider = collider;
1090
1100
  _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1091
1101
  return _this;
@@ -1117,9 +1127,7 @@
1117
1127
  /**
1118
1128
  * {@inheritDoc IHingeJoint.getVelocity }
1119
1129
  */ _proto.getVelocity = function getVelocity() {
1120
- var velocity = this._velocity;
1121
- velocity.copyFrom(this._pxJoint.getVelocity());
1122
- return velocity;
1130
+ return this._pxJoint.getVelocity();
1123
1131
  };
1124
1132
  /**
1125
1133
  * {@inheritDoc IHingeJoint.setHardLimitCone }
@@ -1133,8 +1141,9 @@
1133
1141
  };
1134
1142
  /**
1135
1143
  * {@inheritDoc IHingeJoint.setDriveVelocity }
1136
- */ _proto.setDriveVelocity = function setDriveVelocity(velocity) {
1137
- this._pxJoint.setDriveVelocity(velocity);
1144
+ */ _proto.setDriveVelocity = function setDriveVelocity(velocity, autowake) {
1145
+ if (autowake === void 0) autowake = true;
1146
+ this._pxJoint.setDriveVelocity(velocity, autowake);
1138
1147
  };
1139
1148
  /**
1140
1149
  * {@inheritDoc IHingeJoint.setDriveForceLimit }
@@ -1298,9 +1307,9 @@
1298
1307
  }
1299
1308
  }
1300
1309
  if (runtimeMode == exports.PhysXRuntimeMode.JavaScript) {
1301
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + engine.version + "/libs/physx.release.js.js";
1310
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
1302
1311
  } else if (runtimeMode == exports.PhysXRuntimeMode.WebAssembly) {
1303
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + engine.version + "/libs/physx.release.js";
1312
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js";
1304
1313
  }
1305
1314
  });
1306
1315
  var initializePromise = new Promise(function(resolve, reject) {
@@ -1413,7 +1422,12 @@
1413
1422
  InitializeState[InitializeState["Initialized"] = 2] = "Initialized";
1414
1423
  })(InitializeState || (InitializeState = {}));
1415
1424
 
1425
+ //@ts-ignore
1426
+ var version = "1.1.0-beta.20";
1427
+ console.log("Galacean PhysX version: " + version);
1428
+
1416
1429
  exports.PhysXPhysics = PhysXPhysics;
1430
+ exports.version = version;
1417
1431
 
1418
1432
  Object.defineProperty(exports, '__esModule', { value: true });
1419
1433
 
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/engine")):"function"==typeof define&&define.amd?define(["exports","@galacean/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).Galacean=t.Galacean||{},t.Galacean.PhysicsPhysX={}),t.Galacean)}(this,function(t,e){"use strict";function i(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}var o,r,a,l,h,c,_,u,p,f,x,y,d,g,m,S=function(){function t(t){void 0===t&&(t=0),this.length=0,this._elements=Array(t)}var e=t.prototype;return e.add=function(t){this.length===this._elements.length?this._elements.push(t):this._elements[this.length]=t,this.length++},e.delete=function(t){var e=this._elements.indexOf(t);this.deleteByIndex(e)},e.get=function(t){if(t>=this.length)throw"Index is out of range.";return this._elements[t]},e.deleteByIndex=function(t){var e=this._elements,i=null,n=this.length-1;return t!==n&&(i=e[n],e[t]=i),this.length--,i},e.garbageCollection=function(){this._elements.length=this.length},t}();(o=p||(p={}))[o.SIMULATION_SHAPE=1]="SIMULATION_SHAPE",o[o.SCENE_QUERY_SHAPE=2]="SCENE_QUERY_SHAPE",o[o.TRIGGER_SHAPE=4]="TRIGGER_SHAPE";var v=function(){function t(t){this._controllers=new S,this._worldScale=new e.Vector3(1,1,1),this._position=new e.Vector3,this._rotation=null,this._axis=null,this._physXRotation=new e.Quaternion,this._shapeFlags=3,this._pxMaterials=[,],this._physXPhysics=t}var i=t.prototype;return i.setRotation=function(t){this._rotation=t,e.Quaternion.rotationYawPitchRoll(t.x,t.y,t.z,this._physXRotation),this._axis&&e.Quaternion.multiply(this._physXRotation,this._axis,this._physXRotation),this._physXRotation.normalize(),this._setLocalPose()},i.setPosition=function(t){t!==this._position&&this._position.copyFrom(t);for(var e=this._controllers,i=0,n=e.length;i<n;i++)e.get(i)._setLocalPosition(this._position,this._worldScale);this._setLocalPose()},i.setWorldScale=function(t){this._worldScale.copyFrom(t),this._setLocalPose();for(var e=this._controllers,i=0,n=e.length;i<n;i++)e.get(i)._setLocalPosition(this._position,this._worldScale)},i.setContactOffset=function(t){this._pxShape.setContactOffset(t);for(var e=this._controllers,i=0,n=e.length;i<n;i++)e.get(i)._pxController.setContactOffset(t)},i.setMaterial=function(t){this._pxMaterials[0]=t._pxMaterial,this._pxShape.setMaterials(this._pxMaterials)},i.setIsTrigger=function(t){this._modifyFlag(1,!t),this._modifyFlag(4,t),this._setShapeFlags(this._shapeFlags)},i.destroy=function(){this._pxShape.release()},i._setShapeFlags=function(t){this._shapeFlags=t,this._pxShape.setFlags(new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags))},i._setLocalPose=function(){var i=t.transform;e.Vector3.multiply(this._position,this._worldScale,i.translation),i.rotation=this._physXRotation,this._pxShape.setLocalPose(i)},i._initialize=function(t,e){this._id=e,this._pxMaterials[0]=t._pxMaterial,this._pxShape=this._physXPhysics._pxPhysics.createShape(this._pxGeometry,t._pxMaterial,!0,new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags)),this._pxShape.setUUID(e)},i._modifyFlag=function(t,e){this._shapeFlags=e?this._shapeFlags|t:this._shapeFlags&~t},t}();v.halfSqrt=.70710678118655,v.transform={translation:new e.Vector3,rotation:null};var P=function(t){function i(i,n,s,o){var r;return(r=t.call(this,i)||this)._halfSize=new e.Vector3,r._halfSize.set(.5*s.x,.5*s.y,.5*s.z),r._pxGeometry=new i._physX.PxBoxGeometry(r._halfSize.x*r._worldScale.x,r._halfSize.y*r._worldScale.y,r._halfSize.z*r._worldScale.z),r._initialize(o,n),r._setLocalPose(),r}s(i,t);var n=i.prototype;return n.setSize=function(t){var n=i._tempHalfExtents;this._halfSize.set(.5*t.x,.5*t.y,.5*t.z),e.Vector3.multiply(this._halfSize,this._worldScale,n),this._pxGeometry.halfExtents=n,this._pxShape.setGeometry(this._pxGeometry),this._updateController(n)},n.setWorldScale=function(n){t.prototype.setWorldScale.call(this,n);var s=i._tempHalfExtents;e.Vector3.multiply(this._halfSize,this._worldScale,s),this._pxGeometry.halfExtents=s,this._pxShape.setGeometry(this._pxGeometry),this._updateController(s)},n._updateController=function(t){for(var e=this._controllers,i=0,n=e.length;i<n;i++){var s=e.get(i)._pxController;s.setHalfHeight(t.x),s.setHalfSideExtent(t.y),s.setHalfForwardExtent(t.z)}},i}(v);P._tempHalfExtents=new e.Vector3;var C=function(t){function i(i,n,s,o,r){var a;return(a=t.call(this,i)||this)._upAxis=1,a._radius=s,a._halfHeight=.5*o,a._axis=new e.Quaternion(0,0,v.halfSqrt,v.halfSqrt),a._physXRotation.copyFrom(a._axis),a._pxGeometry=new i._physX.PxCapsuleGeometry(a._radius,a._halfHeight),a._initialize(r,n),a._setLocalPose(),a}s(i,t);var n=i.prototype;return n.setRadius=function(t){switch(this._radius=t,this._upAxis){case 0:this._pxGeometry.radius=this._radius*Math.max(this._worldScale.y,this._worldScale.z);break;case 1:this._pxGeometry.radius=this._radius*Math.max(this._worldScale.x,this._worldScale.z);break;case 2:this._pxGeometry.radius=this._radius*Math.max(this._worldScale.x,this._worldScale.y)}this._pxShape.setGeometry(this._pxGeometry);for(var e=this._pxGeometry.radius,i=this._controllers,n=0,s=i.length;n<s;n++)i.get(n)._pxController.setRadius(e)},n.setHeight=function(t){switch(this._halfHeight=.5*t,this._upAxis){case 0:this._pxGeometry.halfHeight=this._halfHeight*this._worldScale.x;break;case 1:this._pxGeometry.halfHeight=this._halfHeight*this._worldScale.y;break;case 2:this._pxGeometry.halfHeight=this._halfHeight*this._worldScale.z}this._pxShape.setGeometry(this._pxGeometry);for(var e=2*this._pxGeometry.halfHeight,i=this._controllers,n=0,s=i.length;n<s;n++)i.get(n)._pxController.setHeight(e)},n.setUpAxis=function(t){var i=this._rotation,n=this._axis,s=this._physXRotation;switch(this._upAxis=t,this._upAxis){case 0:n.set(0,0,0,1);break;case 1:n.set(0,0,v.halfSqrt,v.halfSqrt);break;case 2:n.set(0,v.halfSqrt,0,v.halfSqrt)}i?(e.Quaternion.rotationYawPitchRoll(i.x,i.y,i.z,s),e.Quaternion.multiply(s,n,s)):s.copyFrom(n),this._setLocalPose()},n.setWorldScale=function(e){t.prototype.setWorldScale.call(this,e);var i=this._pxGeometry;switch(this._upAxis){case 0:i.radius=this._radius*Math.max(e.y,e.z),i.halfHeight=this._halfHeight*e.x;break;case 1:i.radius=this._radius*Math.max(e.x,e.z),i.halfHeight=this._halfHeight*e.y;break;case 2:i.radius=this._radius*Math.max(e.x,e.y),i.halfHeight=this._halfHeight*e.z}this._pxShape.setGeometry(i);for(var n=i.radius,s=2*i.halfHeight,o=this._controllers,r=0,a=o.length;r<a;r++){var l=o.get(r)._pxController;l.setRadius(n),l.setHeight(s)}},i}(v);(r=f||(f={}))[r.X=0]="X",r[r.Y=1]="Y",r[r.Z=2]="Z";var A=function(){function t(t){this._scaledOffset=new e.Vector3,this._position=null,this._physXPhysics=t}var n=t.prototype;return n.move=function(t,e,i){return this._pxController.move(t,e,i)},n.setWorldPosition=function(i){this._position=i,this._pxController&&(e.Vector3.add(i,this._scaledOffset,t._tempVec),this._pxController.setPosition(t._tempVec))},n.getWorldPosition=function(t){t.copyFrom(this._pxController.getPosition()),t.subtract(this._scaledOffset)},n.setStepOffset=function(t){this._pxController.setStepOffset(t)},n.setNonWalkableMode=function(t){this._pxController.setNonWalkableMode(t)},n.setUpDirection=function(t){this._pxController.setUpDirection(t)},n.setSlopeLimit=function(t){this._pxController.setSlopeLimit(t)},n.addShape=function(t){this._pxManager&&this._createPXController(this._pxManager,t),this._shape=t,t._controllers.add(this)},n.removeShape=function(t){this._destroyPXController(),this._shape=null,t._controllers.delete(this)},n.destroy=function(){this._destroyPXController()},n._createPXController=function(t,e){var n;if(i(e,P))(n=new this._physXPhysics._physX.PxBoxControllerDesc).halfHeight=e._halfSize.x,n.halfSideExtent=e._halfSize.y,n.halfForwardExtent=e._halfSize.z;else if(i(e,C))(n=new this._physXPhysics._physX.PxCapsuleControllerDesc).radius=e._radius,n.height=2*e._halfHeight,n.climbingMode=1;else throw"unsupported shape type";n.setMaterial(e._pxMaterials[0]),this._pxController=t._getControllerManager().createController(n),this._pxController.setUUID(e._id)},n._destroyPXController=function(){this._pxController&&(this._pxController.release(),this._pxController=null)},n._setLocalPosition=function(t,i){e.Vector3.multiply(t,i,this._scaledOffset),this.setWorldPosition(t)},t}();A._tempVec=new e.Vector3;var M=function(){function t(t){this._physXPhysics=t}var e=t.prototype;return e.addShape=function(t){this._pxActor.attachShape(t._pxShape)},e.removeShape=function(t){this._pxActor.detachShape(t._pxShape,!0)},e.setWorldTransform=function(t,e){this._pxActor.setGlobalPose(this._transform(t,e),!0)},e.getWorldTransform=function(t,e){var i=this._pxActor.getGlobalPose();t.set(i.translation.x,i.translation.y,i.translation.z),e.set(i.rotation.x,i.rotation.y,i.rotation.z,i.rotation.w)},e.destroy=function(){this._pxActor.release()},e._transform=function(e,i){var n=t._tempTransform;return n.translation=e,n.rotation=i.normalize(),n},t}();M._tempTransform={translation:null,rotation:null},(a=x||(x={}))[a.Discrete=0]="Discrete",a[a.Continuous=1]="Continuous",a[a.ContinuousDynamic=2]="ContinuousDynamic",a[a.ContinuousSpeculative=3]="ContinuousSpeculative";var w=function(t){function n(e,i,n){var s,o=(s=t.call(this,e)||this)._transform(i,n);return s._pxActor=e._pxPhysics.createRigidDynamic(o),s}s(n,t);var o=n.prototype;return o.setLinearDamping=function(t){this._pxActor.setLinearDamping(t)},o.setAngularDamping=function(t){this._pxActor.setAngularDamping(t)},o.setLinearVelocity=function(t){this._pxActor.setLinearVelocity(t,!0)},o.setAngularVelocity=function(t){this._pxActor.setAngularVelocity(t,!0)},o.setMass=function(t){this._pxActor.setMass(t)},o.setCenterOfMass=function(t){this._pxActor.setCMassLocalPose(t)},o.setInertiaTensor=function(t){this._pxActor.setMassSpaceInertiaTensor(t)},o.setMaxAngularVelocity=function(t){this._pxActor.setMaxAngularVelocity(t)},o.setMaxDepenetrationVelocity=function(t){this._pxActor.setMaxDepenetrationVelocity(t)},o.setSleepThreshold=function(t){this._pxActor.setSleepThreshold(t)},o.setSolverIterations=function(t){this._pxActor.setSolverIterationCounts(t,1)},o.setCollisionDetectionMode=function(t){switch(t){case 1:this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD,!0);break;case 2:this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION,!0);break;case 3:this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD,!0);break;case 0:var e=this._physXPhysics._physX;this._pxActor.setRigidBodyFlag(e.PxRigidBodyFlag.eENABLE_CCD,!1),this._pxActor.setRigidBodyFlag(e.PxRigidBodyFlag.eENABLE_CCD_FRICTION,!1),this._pxActor.setRigidBodyFlag(e.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD,!1)}},o.setIsKinematic=function(t){t?this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC,!0):this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC,!1)},o.setConstraints=function(t){this._pxActor.setRigidDynamicLockFlags(t)},o.addForce=function(t){this._pxActor.addForce({x:t.x,y:t.y,z:t.z})},o.addTorque=function(t){this._pxActor.addTorque({x:t.x,y:t.y,z:t.z})},o.move=function(t,s){if(s){this._pxActor.setKinematicTarget(t,s);return}var o=n._tempTranslation,r=n._tempRotation;this.getWorldTransform(o,r),i(t,e.Vector3)?this._pxActor.setKinematicTarget(t,r):this._pxActor.setKinematicTarget(o,t)},o.sleep=function(){return this._pxActor.putToSleep()},o.wakeUp=function(){return this._pxActor.wakeUp()},n}(M);w._tempTranslation=new e.Vector3,w._tempRotation=new e.Quaternion;var F=function(){this._eventMap={}},b=function(){function t(t,e,i,n,s,o){this._physXPhysics=t;var r=t._pxPhysics.createMaterial(e,i,n);r.setFrictionCombineMode(s),r.setRestitutionCombineMode(o),this._pxMaterial=r}var e=t.prototype;return e.setBounciness=function(t){this._pxMaterial.setRestitution(t)},e.setDynamicFriction=function(t){this._pxMaterial.setDynamicFriction(t)},e.setStaticFriction=function(t){this._pxMaterial.setStaticFriction(t)},e.setBounceCombine=function(t){this._pxMaterial.setRestitutionCombineMode(t)},e.setFrictionCombine=function(t){this._pxMaterial.setFrictionCombineMode(t)},e.destroy=function(){this._pxMaterial.release()},t}();(l=y||(y={}))[l.Average=0]="Average",l[l.Minimum=1]="Minimum",l[l.Multiply=2]="Multiply",l[l.Maximum=3]="Maximum";var R=function(){function t(t,e,i,n,s,o,r,a){var l=this;this._pxControllerManager=null,this._currentEvents=new S,this._eventPool=[],this._physXPhysics=t,this._physXManager=e;var h=t._physX;this._pxRaycastHit=new h.PxRaycastHit,this._pxFilterData=new h.PxQueryFilterData,this._pxFilterData.flags=new h.PxQueryFlags(7),this._onContactEnter=i,this._onContactExit=n,this._onContactStay=s,this._onTriggerEnter=o,this._onTriggerExit=r,this._onTriggerStay=a;var c=t._pxPhysics,_=h.PxSimulationEventCallback.implement({onContactBegin:function(t,e){l._onContactEnter(t,e)},onContactEnd:function(t,e){l._onContactExit(t,e)},onContactPersist:function(t,e){l._onContactStay(t,e)},onTriggerBegin:function(t,e){var i=t<e?l._getTrigger(t,e):l._getTrigger(e,t);i.state=0,l._currentEvents.add(i)},onTriggerEnd:function(t,e){var i;if(t<e){var n=l._physXManager._eventMap[t];i=n[e],n[e]=void 0}else{var s=l._physXManager._eventMap[e];i=s[t],s[t]=void 0}i.state=2}}),u=h.getDefaultSceneDesc(c.getTolerancesScale(),0,_);this._pxScene=c.createScene(u)}var e=t.prototype;return e.setGravity=function(t){this._pxScene.setGravity(t)},e.addColliderShape=function(t){this._physXManager._eventMap[t._id]={}},e.removeColliderShape=function(t){for(var e=this._eventPool,i=this._currentEvents,n=t._id,s=i.length-1;s>=0;s--){var o=i.get(s);(o.index1==n||o.index2==n)&&(i.deleteByIndex(s),e.push(o))}delete this._physXManager._eventMap[n]},e.addCollider=function(t){this._pxScene.addActor(t._pxActor,null)},e.removeCollider=function(t){this._pxScene.removeActor(t._pxActor,!0)},e.addCharacterController=function(t){if(!t._pxController){var e=t._shape;if(e){var i=t._pxManager;i!==this&&(i&&t._destroyPXController(),t._createPXController(this,e))}}t._pxManager=this},e.removeCharacterController=function(t){t._pxManager=null},e.update=function(t){this._simulate(t),this._fetchResults(),this._fireEvent()},e.raycast=function(e,i,n,s){var o=this._pxRaycastHit;i=Math.min(i,34e37);var r=this._pxScene.raycastSingle(e.origin,e.direction,i,o,this._pxFilterData,this._physXPhysics._physX.PxQueryFilterCallback.implement({preFilter:function(t,e,i){return n(e)?2:0},postFilter:function(t,e){}}));if(r&&void 0!=s){var a=t._tempPosition,l=t._tempNormal,h=o.position,c=o.normal;a.set(h.x,h.y,h.z),l.set(c.x,c.y,c.z),s(o.getShape().getUUID(),o.distance,a,l)}return r},e._getControllerManager=function(){var t=this._pxControllerManager;return null===t&&(this._pxControllerManager=t=this._pxScene.createControllerManager()),t},e._simulate=function(t){this._pxScene.simulate(t,!0)},e._fetchResults=function(t){void 0===t&&(t=!0),this._pxScene.fetchResults(t)},e._getTrigger=function(t,e){var i;return this._eventPool.length?((i=this._eventPool.pop()).index1=t,i.index2=e):i=new X(t,e),this._physXManager._eventMap[t][e]=i,i},e._fireEvent=function(){for(var t=this._eventPool,e=this._currentEvents,i=e.length-1;i>=0;i--){var n=e.get(i);0==n.state?(this._onTriggerEnter(n.index1,n.index2),n.state=1):1==n.state?this._onTriggerStay(n.index1,n.index2):2==n.state&&(this._onTriggerExit(n.index1,n.index2),e.deleteByIndex(i),t.push(n))}},t}();R._tempPosition=new e.Vector3,R._tempNormal=new e.Vector3,(h=d||(d={}))[h.STATIC=1]="STATIC",h[h.DYNAMIC=2]="DYNAMIC",h[h.PRE_FILTER=4]="PRE_FILTER",h[h.POST_FILTER=8]="POST_FILTER",h[h.ANY_HIT=16]="ANY_HIT",h[h.NO_BLOCK=32]="NO_BLOCK",(c=g||(g={}))[c.Enter=0]="Enter",c[c.Stay=1]="Stay",c[c.Exit=2]="Exit";var X=function(t,e){this.index1=t,this.index2=e},E=function(t){function e(e,i,n){var s;return(s=t.call(this,e)||this)._pxActor=e._pxPhysics.createRigidStatic(s._transform(i,n)),s}return s(e,t),e}(M);t.PhysXRuntimeMode=void 0,(_=t.PhysXRuntimeMode||(t.PhysXRuntimeMode={}))[_.Auto=0]="Auto",_[_.WebAssembly=1]="WebAssembly",_[_.JavaScript=2]="JavaScript";var T=function(){function t(t){this._connectedAnchor=new e.Vector3,this._breakForce=Number.MAX_VALUE,this._breakTorque=Number.MAX_VALUE,this._physXPhysics=t}var i=t.prototype;return i.setConnectedCollider=function(t){var e;this._pxJoint.setActors((null==t?void 0:t._pxActor)||null,(null==(e=this._collider)?void 0:e._pxActor)||null)},i.setConnectedAnchor=function(e){this._connectedAnchor.copyFrom(e),this._setLocalPose(0,e,t._defaultQuat)},i.setConnectedMassScale=function(t){this._pxJoint.setInvMassScale0(1/t)},i.setConnectedInertiaScale=function(t){this._pxJoint.setInvInertiaScale0(1/t)},i.setMassScale=function(t){this._pxJoint.setInvMassScale1(1/t)},i.setInertiaScale=function(t){this._pxJoint.setInvInertiaScale1(1/t)},i.setBreakForce=function(t){this._breakForce=t,this._pxJoint.setBreakForce(this._breakForce,this._breakTorque)},i.setBreakTorque=function(t){this._breakTorque=t,this._pxJoint.setBreakForce(this._breakForce,this._breakTorque)},i._setLocalPose=function(t,e,i){this._pxJoint.setLocalPose(t,e,i)},t}();T._xAxis=new e.Vector3(1,0,0),T._defaultVec=new e.Vector3,T._defaultQuat=new e.Quaternion;var I=function(t){function e(e,i){var n;return(n=t.call(this,e)||this)._collider=i,n._pxJoint=e._pxPhysics.createFixedJoint(null,T._defaultVec,T._defaultQuat,i._pxActor,T._defaultVec,T._defaultQuat),n}return s(e,t),e}(T),z=function(t){function i(i,n){var s;return(s=t.call(this,i)||this)._axisRotationQuaternion=new e.Quaternion,s._swingOffset=new e.Vector3,s._velocity=new e.Vector3,s._collider=n,s._pxJoint=i._pxPhysics.createRevoluteJoint(null,T._defaultVec,T._defaultQuat,n._pxActor,T._defaultVec,T._defaultQuat),s}s(i,t);var n=i.prototype;return n.setAxis=function(t){var i=T._xAxis,n=this._axisRotationQuaternion;i.set(1,0,0),t.normalize();var s=Math.acos(e.Vector3.dot(i,t));e.Vector3.cross(i,t,i),e.Quaternion.rotationAxisAngle(i,s,n),this._setLocalPose(0,this._swingOffset,n)},n.setSwingOffset=function(t){this._swingOffset.copyFrom(t),this._setLocalPose(1,this._swingOffset,this._axisRotationQuaternion)},n.getAngle=function(){return this._pxJoint.getAngle()},n.getVelocity=function(){var t=this._velocity;return t.copyFrom(this._pxJoint.getVelocity()),t},n.setHardLimit=function(t,e,i){this._pxJoint.setHardLimit(t,e,i)},n.setSoftLimit=function(t,e,i,n){this._pxJoint.setSoftLimit(t,e,i,n)},n.setDriveVelocity=function(t){this._pxJoint.setDriveVelocity(t)},n.setDriveForceLimit=function(t){this._pxJoint.setDriveForceLimit(t)},n.setDriveGearRatio=function(t){this._pxJoint.setDriveGearRatio(t)},n.setHingeJointFlag=function(t,e){this._pxJoint.setRevoluteJointFlag(t,e)},i}(T),D=function(t){function i(i,n){var s;return(s=t.call(this,i)||this)._swingOffset=new e.Vector3,s._collider=n,s._pxJoint=i._pxPhysics.createDistanceJoint(null,T._defaultVec,T._defaultQuat,n._pxActor,T._defaultVec,T._defaultQuat),s._pxJoint.setDistanceJointFlag(2,!0),s._pxJoint.setDistanceJointFlag(4,!0),s._pxJoint.setDistanceJointFlag(8,!0),s}s(i,t);var n=i.prototype;return n.setSwingOffset=function(t){this._swingOffset.copyFrom(t),this._setLocalPose(1,t,T._defaultQuat)},n.setMinDistance=function(t){this._pxJoint.setMinDistance(t)},n.setMaxDistance=function(t){this._pxJoint.setMaxDistance(t)},n.setTolerance=function(t){this._pxJoint.setTolerance(t)},n.setStiffness=function(t){this._pxJoint.setStiffness(t)},n.setDamping=function(t){this._pxJoint.setDamping(t)},i}(T),L=function(t){function i(i,n,s){var o;return(o=t.call(this,i)||this)._axis=new e.Quaternion(0,0,v.halfSqrt,v.halfSqrt),o._physXRotation.copyFrom(o._axis),o._pxGeometry=new i._physX.PxPlaneGeometry,o._initialize(s,n),o._setLocalPose(),o}return s(i,t),i}(v),V=function(t){function e(e,i,n,s){var o;return(o=t.call(this,e)||this)._maxScale=1,o._radius=n,o._pxGeometry=new e._physX.PxSphereGeometry(o._radius*o._maxScale),o._initialize(s,i),o._setLocalPose(),o}s(e,t);var i=e.prototype;return i.setRadius=function(t){this._radius=t,this._pxGeometry.radius=t*this._maxScale,this._pxShape.setGeometry(this._pxGeometry)},i.setWorldScale=function(e){t.prototype.setWorldScale.call(this,e),this._maxScale=Math.max(e.x,e.y,e.z),this._pxGeometry.radius=this._radius*this._maxScale,this._pxShape.setGeometry(this._pxGeometry)},e}(v),G=function(){function n(e){void 0===e&&(e=t.PhysXRuntimeMode.Auto),this._initializeState=0,this._runTimeMode=e}var s=n.prototype;return s.initialize=function(){var n=this;if(2===this._initializeState)return Promise.resolve();if(1===this._initializeState)return this._initializePromise;var s=this._runTimeMode,o=new Promise(function(n,o){var r=document.createElement("script");document.body.appendChild(r),r.async=!0,r.onload=n,r.onerror=o,s==t.PhysXRuntimeMode.Auto&&(s=!function(){try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){var t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(i(t,WebAssembly.Module))return i(new WebAssembly.Instance(t),WebAssembly.Instance)}}catch(t){}return!1}()?t.PhysXRuntimeMode.JavaScript:t.PhysXRuntimeMode.WebAssembly),s==t.PhysXRuntimeMode.JavaScript?r.src="https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/"+e.version+"/libs/physx.release.js.js":s==t.PhysXRuntimeMode.WebAssembly&&(r.src="https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/"+e.version+"/libs/physx.release.js")}),r=new Promise(function(t,e){o.then(function(){return window.PHYSX().then(function(e){n._init(e),n._initializeState=2,n._initializePromise=null,console.log("PhysX loaded."),t()},e)},e).catch(e)});return this._initializePromise=r,r},s.destroy=function(){this._physX.PxCloseExtensions(),this._pxPhysics.release(),this._pxFoundation.release(),this._physX=null,this._pxFoundation=null,this._pxPhysics=null},s.createPhysicsManager=function(){return new F},s.createPhysicsScene=function(t,e,i,n,s,o,r){return new R(this,t,e,i,n,s,o,r)},s.createStaticCollider=function(t,e){return new E(this,t,e)},s.createDynamicCollider=function(t,e){return new w(this,t,e)},s.createCharacterController=function(){return new A(this)},s.createPhysicsMaterial=function(t,e,i,n,s){return new b(this,t,e,i,n,s)},s.createBoxColliderShape=function(t,e,i){return new P(this,t,e,i)},s.createSphereColliderShape=function(t,e,i){return new V(this,t,e,i)},s.createPlaneColliderShape=function(t,e){return new L(this,t,e)},s.createCapsuleColliderShape=function(t,e,i,n){return new C(this,t,e,i,n)},s.createFixedJoint=function(t){return new I(this,t)},s.createHingeJoint=function(t){return new z(this,t)},s.createSpringJoint=function(t){return new D(this,t)},s._init=function(t){var e=t.PX_PHYSICS_VERSION,i=new t.PxDefaultErrorCallback,n=new t.PxDefaultAllocator,s=t.PxCreateFoundation(e,n,i),o=t.PxCreatePhysics(e,s,new t.PxTolerancesScale,!1,null);t.PxInitExtensions(o,null),this._physX=t,this._pxFoundation=s,this._pxPhysics=o},n}();(u=m||(m={}))[u.Uninitialized=0]="Uninitialized",u[u.Initializing=1]="Initializing",u[u.Initialized=2]="Initialized",t.PhysXPhysics=G,Object.defineProperty(t,"__esModule",{value:!0})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/engine")):"function"==typeof define&&define.amd?define(["exports","@galacean/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).Galacean=t.Galacean||{},t.Galacean.PhysicsPhysX={}),t.Galacean)}(this,function(t,e){"use strict";function i(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}var o,r,a,l,h,c,_,u,p,f,x,d,y,g,m,S=function(){function t(t){void 0===t&&(t=0),this.length=0,this._elements=Array(t)}var e=t.prototype;return e.add=function(t){this.length===this._elements.length?this._elements.push(t):this._elements[this.length]=t,this.length++},e.delete=function(t){var e=this._elements.indexOf(t);this.deleteByIndex(e)},e.get=function(t){if(t>=this.length)throw"Index is out of range.";return this._elements[t]},e.deleteByIndex=function(t){var e=this._elements,i=null,n=this.length-1;return t!==n&&(i=e[n],e[t]=i),this.length--,i},e.garbageCollection=function(){this._elements.length=this.length},t}();(o=p||(p={}))[o.SIMULATION_SHAPE=1]="SIMULATION_SHAPE",o[o.SCENE_QUERY_SHAPE=2]="SCENE_QUERY_SHAPE",o[o.TRIGGER_SHAPE=4]="TRIGGER_SHAPE";var v=function(){function t(t){this._controllers=new S,this._worldScale=new e.Vector3(1,1,1),this._position=new e.Vector3,this._rotation=null,this._axis=null,this._physXRotation=new e.Quaternion,this._shapeFlags=3,this._physXPhysics=t}var i=t.prototype;return i.setRotation=function(t){this._rotation=t,e.Quaternion.rotationYawPitchRoll(t.x,t.y,t.z,this._physXRotation),this._axis&&e.Quaternion.multiply(this._physXRotation,this._axis,this._physXRotation),this._physXRotation.normalize(),this._setLocalPose()},i.setPosition=function(t){t!==this._position&&this._position.copyFrom(t);for(var e=this._controllers,i=0,n=e.length;i<n;i++)e.get(i)._updateShapePosition(this._position,this._worldScale);this._setLocalPose()},i.setWorldScale=function(t){this._worldScale.copyFrom(t),this._setLocalPose();for(var e=this._controllers,i=0,n=e.length;i<n;i++)e.get(i)._updateShapePosition(this._position,this._worldScale)},i.setContactOffset=function(t){this._pxShape.setContactOffset(t);for(var e=this._controllers,i=0,n=e.length;i<n;i++)e.get(i)._pxController.setContactOffset(t)},i.setMaterial=function(t){this._pxMaterial=t._pxMaterial,this._pxShape.setMaterial(this._pxMaterial)},i.setIsTrigger=function(t){this._modifyFlag(1,!t),this._modifyFlag(4,t),this._setShapeFlags(this._shapeFlags)},i.destroy=function(){this._pxShape.release()},i._setShapeFlags=function(t){this._shapeFlags=t,this._pxShape.setFlags(new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags))},i._setLocalPose=function(){var i=t.transform;e.Vector3.multiply(this._position,this._worldScale,i.translation),i.rotation=this._physXRotation,this._pxShape.setLocalPose(i)},i._initialize=function(t,e){this._id=e,this._pxMaterial=t._pxMaterial,this._pxShape=this._physXPhysics._pxPhysics.createShape(this._pxGeometry,t._pxMaterial,!0,new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags)),this._pxShape.setUUID(e)},i._modifyFlag=function(t,e){this._shapeFlags=e?this._shapeFlags|t:this._shapeFlags&~t},t}();v.halfSqrt=.70710678118655,v.transform={translation:new e.Vector3,rotation:null};var P=function(t){function i(i,n,s,o){var r;return(r=t.call(this,i)||this)._halfSize=new e.Vector3,r._halfSize.set(.5*s.x,.5*s.y,.5*s.z),r._pxGeometry=new i._physX.PxBoxGeometry(r._halfSize.x*r._worldScale.x,r._halfSize.y*r._worldScale.y,r._halfSize.z*r._worldScale.z),r._initialize(o,n),r._setLocalPose(),r}s(i,t);var n=i.prototype;return n.setSize=function(t){var n=i._tempHalfExtents;this._halfSize.set(.5*t.x,.5*t.y,.5*t.z),e.Vector3.multiply(this._halfSize,this._worldScale,n),this._pxGeometry.halfExtents=n,this._pxShape.setGeometry(this._pxGeometry),this._updateController(n)},n.setWorldScale=function(n){t.prototype.setWorldScale.call(this,n);var s=i._tempHalfExtents;e.Vector3.multiply(this._halfSize,this._worldScale,s),this._pxGeometry.halfExtents=s,this._pxShape.setGeometry(this._pxGeometry),this._updateController(s)},n._updateController=function(t){for(var e=this._controllers,i=0,n=e.length;i<n;i++){var s=e.get(i)._pxController;s.setHalfHeight(t.x),s.setHalfSideExtent(t.y),s.setHalfForwardExtent(t.z)}},i}(v);P._tempHalfExtents=new e.Vector3;var A=function(t){function i(i,n,s,o,r){var a;return(a=t.call(this,i)||this)._upAxis=1,a._radius=s,a._halfHeight=.5*o,a._axis=new e.Quaternion(0,0,v.halfSqrt,v.halfSqrt),a._physXRotation.copyFrom(a._axis),a._pxGeometry=new i._physX.PxCapsuleGeometry(a._radius,a._halfHeight),a._initialize(r,n),a._setLocalPose(),a}s(i,t);var n=i.prototype;return n.setRadius=function(t){switch(this._radius=t,this._upAxis){case 0:this._pxGeometry.radius=this._radius*Math.max(this._worldScale.y,this._worldScale.z);break;case 1:this._pxGeometry.radius=this._radius*Math.max(this._worldScale.x,this._worldScale.z);break;case 2:this._pxGeometry.radius=this._radius*Math.max(this._worldScale.x,this._worldScale.y)}this._pxShape.setGeometry(this._pxGeometry);for(var e=this._pxGeometry.radius,i=this._controllers,n=0,s=i.length;n<s;n++)i.get(n)._pxController.setRadius(e)},n.setHeight=function(t){switch(this._halfHeight=.5*t,this._upAxis){case 0:this._pxGeometry.halfHeight=this._halfHeight*this._worldScale.x;break;case 1:this._pxGeometry.halfHeight=this._halfHeight*this._worldScale.y;break;case 2:this._pxGeometry.halfHeight=this._halfHeight*this._worldScale.z}this._pxShape.setGeometry(this._pxGeometry);for(var e=2*this._pxGeometry.halfHeight,i=this._controllers,n=0,s=i.length;n<s;n++)i.get(n)._pxController.setHeight(e)},n.setUpAxis=function(t){var i=this._rotation,n=this._axis,s=this._physXRotation;switch(this._upAxis=t,this._upAxis){case 0:n.set(0,0,0,1);break;case 1:n.set(0,0,v.halfSqrt,v.halfSqrt);break;case 2:n.set(0,v.halfSqrt,0,v.halfSqrt)}i?(e.Quaternion.rotationYawPitchRoll(i.x,i.y,i.z,s),e.Quaternion.multiply(s,n,s)):s.copyFrom(n),this._setLocalPose()},n.setWorldScale=function(e){t.prototype.setWorldScale.call(this,e);var i=this._pxGeometry;switch(this._upAxis){case 0:i.radius=this._radius*Math.max(e.y,e.z),i.halfHeight=this._halfHeight*e.x;break;case 1:i.radius=this._radius*Math.max(e.x,e.z),i.halfHeight=this._halfHeight*e.y;break;case 2:i.radius=this._radius*Math.max(e.x,e.y),i.halfHeight=this._halfHeight*e.z}this._pxShape.setGeometry(i);for(var n=i.radius,s=2*i.halfHeight,o=this._controllers,r=0,a=o.length;r<a;r++){var l=o.get(r)._pxController;l.setRadius(n),l.setHeight(s)}},i}(v);(r=f||(f={}))[r.X=0]="X",r[r.Y=1]="Y",r[r.Z=2]="Z";var C=function(){function t(t){this._shapeScaledPosition=new e.Vector3,this._worldPosition=null,this._physXPhysics=t}var n=t.prototype;return n.move=function(t,e,i){var n,s;return null!=(s=null==(n=this._pxController)?void 0:n.move(t,e,i))?s:0},n.setWorldPosition=function(t){this._worldPosition=t,this._updateNativePosition()},n.getWorldPosition=function(t){this._pxController&&(t.copyFrom(this._pxController.getPosition()),t.subtract(this._shapeScaledPosition))},n.setStepOffset=function(t){var e;null==(e=this._pxController)||e.setStepOffset(t)},n.setNonWalkableMode=function(t){var e;null==(e=this._pxController)||e.setNonWalkableMode(t)},n.setUpDirection=function(t){var e;null==(e=this._pxController)||e.setUpDirection(t)},n.setSlopeLimit=function(t){var e;null==(e=this._pxController)||e.setSlopeLimit(t)},n.addShape=function(t){this._pxManager&&this._createPXController(this._pxManager,t),this._shape=t,t._controllers.add(this)},n.removeShape=function(t){this._destroyPXController(),this._shape=null,t._controllers.delete(this)},n.destroy=function(){this._destroyPXController()},n._createPXController=function(t,e){var n;if(i(e,P))(n=new this._physXPhysics._physX.PxBoxControllerDesc).halfHeight=e._halfSize.x,n.halfSideExtent=e._halfSize.y,n.halfForwardExtent=e._halfSize.z;else if(i(e,A))(n=new this._physXPhysics._physX.PxCapsuleControllerDesc).radius=e._radius,n.height=2*e._halfHeight,n.climbingMode=1;else throw"unsupported shape type";n.setMaterial(e._pxMaterial),this._pxController=t._getControllerManager().createController(n),this._pxController.setUUID(e._id)},n._destroyPXController=function(){this._pxController&&(this._pxController.release(),this._pxController=null)},n._updateShapePosition=function(t,i){e.Vector3.multiply(t,i,this._shapeScaledPosition),this._updateNativePosition()},n._updateNativePosition=function(){var i=this._worldPosition;this._pxController&&i&&(e.Vector3.add(i,this._shapeScaledPosition,t._tempVec),this._pxController.setPosition(t._tempVec))},t}();C._tempVec=new e.Vector3;var M=function(){function t(t){this._physXPhysics=t}var e=t.prototype;return e.addShape=function(t){this._pxActor.attachShape(t._pxShape)},e.removeShape=function(t){this._pxActor.detachShape(t._pxShape,!0)},e.setWorldTransform=function(t,e){this._pxActor.setGlobalPose(this._transform(t,e),!0)},e.getWorldTransform=function(t,e){var i=this._pxActor.getGlobalPose();t.set(i.translation.x,i.translation.y,i.translation.z),e.set(i.rotation.x,i.rotation.y,i.rotation.z,i.rotation.w)},e.destroy=function(){this._pxActor.release()},e._transform=function(e,i){var n=t._tempTransform;return n.translation=e,n.rotation=i.normalize(),n},t}();M._tempTransform={translation:null,rotation:null},(a=x||(x={}))[a.Discrete=0]="Discrete",a[a.Continuous=1]="Continuous",a[a.ContinuousDynamic=2]="ContinuousDynamic",a[a.ContinuousSpeculative=3]="ContinuousSpeculative";var w=function(t){function n(e,i,n){var s,o=(s=t.call(this,e)||this)._transform(i,n);return s._pxActor=e._pxPhysics.createRigidDynamic(o),s}s(n,t);var o=n.prototype;return o.setLinearDamping=function(t){this._pxActor.setLinearDamping(t)},o.setAngularDamping=function(t){this._pxActor.setAngularDamping(t)},o.setLinearVelocity=function(t){this._pxActor.setLinearVelocity(t,!0)},o.setAngularVelocity=function(t){this._pxActor.setAngularVelocity(t,!0)},o.setMass=function(t){this._pxActor.setMass(t)},o.setCenterOfMass=function(t){this._pxActor.setCMassLocalPose(t)},o.setInertiaTensor=function(t){this._pxActor.setMassSpaceInertiaTensor(t)},o.setMaxAngularVelocity=function(t){this._pxActor.setMaxAngularVelocity(t)},o.setMaxDepenetrationVelocity=function(t){this._pxActor.setMaxDepenetrationVelocity(t)},o.setSleepThreshold=function(t){this._pxActor.setSleepThreshold(t)},o.setSolverIterations=function(t){this._pxActor.setSolverIterationCounts(t,1)},o.setCollisionDetectionMode=function(t){switch(t){case 1:this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD,!0);break;case 2:this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION,!0);break;case 3:this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD,!0);break;case 0:var e=this._physXPhysics._physX;this._pxActor.setRigidBodyFlag(e.PxRigidBodyFlag.eENABLE_CCD,!1),this._pxActor.setRigidBodyFlag(e.PxRigidBodyFlag.eENABLE_CCD_FRICTION,!1),this._pxActor.setRigidBodyFlag(e.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD,!1)}},o.setIsKinematic=function(t){t?this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC,!0):this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC,!1)},o.setConstraints=function(t){this._pxActor.setRigidDynamicLockFlags(t)},o.addForce=function(t){this._pxActor.addForce({x:t.x,y:t.y,z:t.z})},o.addTorque=function(t){this._pxActor.addTorque({x:t.x,y:t.y,z:t.z})},o.move=function(t,s){if(s){this._pxActor.setKinematicTarget(t,s);return}var o=n._tempTranslation,r=n._tempRotation;this.getWorldTransform(o,r),i(t,e.Vector3)?this._pxActor.setKinematicTarget(t,r):this._pxActor.setKinematicTarget(o,t)},o.sleep=function(){return this._pxActor.putToSleep()},o.wakeUp=function(){return this._pxActor.wakeUp()},n}(M);w._tempTranslation=new e.Vector3,w._tempRotation=new e.Quaternion;var F=function(){this._eventMap={}},R=function(){function t(t,e,i,n,s,o){this._physXPhysics=t;var r=t._pxPhysics.createMaterial(e,i,n);r.setFrictionCombineMode(s),r.setRestitutionCombineMode(o),this._pxMaterial=r}var e=t.prototype;return e.setBounciness=function(t){this._pxMaterial.setRestitution(t)},e.setDynamicFriction=function(t){this._pxMaterial.setDynamicFriction(t)},e.setStaticFriction=function(t){this._pxMaterial.setStaticFriction(t)},e.setBounceCombine=function(t){this._pxMaterial.setRestitutionCombineMode(t)},e.setFrictionCombine=function(t){this._pxMaterial.setFrictionCombineMode(t)},e.destroy=function(){this._pxMaterial.release()},t}();(l=d||(d={}))[l.Average=0]="Average",l[l.Minimum=1]="Minimum",l[l.Multiply=2]="Multiply",l[l.Maximum=3]="Maximum";var X=function(){function t(t,e,i,n,s,o,r,a){var l=this;this._pxControllerManager=null,this._currentEvents=new S,this._eventPool=[],this._physXPhysics=t,this._physXManager=e;var h=t._physX;this._pxRaycastHit=new h.PxRaycastHit,this._pxFilterData=new h.PxQueryFilterData,this._pxFilterData.flags=new h.PxQueryFlags(7),this._onContactEnter=i,this._onContactExit=n,this._onContactStay=s,this._onTriggerEnter=o,this._onTriggerExit=r,this._onTriggerStay=a;var c=t._pxPhysics,_=h.PxSimulationEventCallback.implement({onContactBegin:function(t,e){l._onContactEnter(t,e)},onContactEnd:function(t,e){l._onContactExit(t,e)},onContactPersist:function(t,e){l._onContactStay(t,e)},onTriggerBegin:function(t,e){var i=t<e?l._getTrigger(t,e):l._getTrigger(e,t);i.state=0,l._currentEvents.add(i)},onTriggerEnd:function(t,e){var i;if(t<e){var n=l._physXManager._eventMap[t];i=n[e],n[e]=void 0}else{var s=l._physXManager._eventMap[e];i=s[t],s[t]=void 0}i.state=2}}),u=h.getDefaultSceneDesc(c.getTolerancesScale(),0,_);this._pxScene=c.createScene(u)}var e=t.prototype;return e.setGravity=function(t){this._pxScene.setGravity(t)},e.addColliderShape=function(t){this._physXManager._eventMap[t._id]={}},e.removeColliderShape=function(t){for(var e=this._eventPool,i=this._currentEvents,n=t._id,s=i.length-1;s>=0;s--){var o=i.get(s);(o.index1==n||o.index2==n)&&(i.deleteByIndex(s),e.push(o))}delete this._physXManager._eventMap[n]},e.addCollider=function(t){this._pxScene.addActor(t._pxActor,null)},e.removeCollider=function(t){this._pxScene.removeActor(t._pxActor,!0)},e.addCharacterController=function(t){if(!t._pxController){var e=t._shape;if(e){var i=t._pxManager;i!==this&&(i&&t._destroyPXController(),t._createPXController(this,e))}}t._pxManager=this},e.removeCharacterController=function(t){t._pxManager=null},e.update=function(t){this._simulate(t),this._fetchResults(),this._fireEvent()},e.raycast=function(e,i,n,s){var o=this._pxRaycastHit;i=Math.min(i,34e37);var r=this._pxScene.raycastSingle(e.origin,e.direction,i,o,this._pxFilterData,this._physXPhysics._physX.PxQueryFilterCallback.implement({preFilter:function(t,e,i){return n(e)?2:0},postFilter:function(t,e){}}));if(r&&void 0!=s){var a=t._tempPosition,l=t._tempNormal,h=o.position,c=o.normal;a.set(h.x,h.y,h.z),l.set(c.x,c.y,c.z),s(o.getShape().getUUID(),o.distance,a,l)}return r},e._getControllerManager=function(){var t=this._pxControllerManager;return null===t&&(this._pxControllerManager=t=this._pxScene.createControllerManager()),t},e._simulate=function(t){this._pxScene.simulate(t,!0)},e._fetchResults=function(t){void 0===t&&(t=!0),this._pxScene.fetchResults(t)},e._getTrigger=function(t,e){var i;return this._eventPool.length?((i=this._eventPool.pop()).index1=t,i.index2=e):i=new E(t,e),this._physXManager._eventMap[t][e]=i,i},e._fireEvent=function(){for(var t=this._eventPool,e=this._currentEvents,i=e.length-1;i>=0;i--){var n=e.get(i);0==n.state?(this._onTriggerEnter(n.index1,n.index2),n.state=1):1==n.state?this._onTriggerStay(n.index1,n.index2):2==n.state&&(this._onTriggerExit(n.index1,n.index2),e.deleteByIndex(i),t.push(n))}},t}();X._tempPosition=new e.Vector3,X._tempNormal=new e.Vector3,(h=y||(y={}))[h.STATIC=1]="STATIC",h[h.DYNAMIC=2]="DYNAMIC",h[h.PRE_FILTER=4]="PRE_FILTER",h[h.POST_FILTER=8]="POST_FILTER",h[h.ANY_HIT=16]="ANY_HIT",h[h.NO_BLOCK=32]="NO_BLOCK",(c=g||(g={}))[c.Enter=0]="Enter",c[c.Stay=1]="Stay",c[c.Exit=2]="Exit";var E=function(t,e){this.index1=t,this.index2=e},b=function(t){function e(e,i,n){var s;return(s=t.call(this,e)||this)._pxActor=e._pxPhysics.createRigidStatic(s._transform(i,n)),s}return s(e,t),e}(M);t.PhysXRuntimeMode=void 0,(_=t.PhysXRuntimeMode||(t.PhysXRuntimeMode={}))[_.Auto=0]="Auto",_[_.WebAssembly=1]="WebAssembly",_[_.JavaScript=2]="JavaScript";var T=function(){function t(t){this._connectedAnchor=new e.Vector3,this._breakForce=Number.MAX_VALUE,this._breakTorque=Number.MAX_VALUE,this._physXPhysics=t}var i=t.prototype;return i.setConnectedCollider=function(t){var e;this._pxJoint.setActors((null==t?void 0:t._pxActor)||null,(null==(e=this._collider)?void 0:e._pxActor)||null)},i.setConnectedAnchor=function(e){this._connectedAnchor.copyFrom(e),this._setLocalPose(0,e,t._defaultQuat)},i.setConnectedMassScale=function(t){this._pxJoint.setInvMassScale0(1/t)},i.setConnectedInertiaScale=function(t){this._pxJoint.setInvInertiaScale0(1/t)},i.setMassScale=function(t){this._pxJoint.setInvMassScale1(1/t)},i.setInertiaScale=function(t){this._pxJoint.setInvInertiaScale1(1/t)},i.setBreakForce=function(t){this._breakForce=t,this._pxJoint.setBreakForce(this._breakForce,this._breakTorque)},i.setBreakTorque=function(t){this._breakTorque=t,this._pxJoint.setBreakForce(this._breakForce,this._breakTorque)},i._setLocalPose=function(t,e,i){this._pxJoint.setLocalPose(t,e,i)},t}();T._xAxis=new e.Vector3(1,0,0),T._defaultVec=new e.Vector3,T._defaultQuat=new e.Quaternion;var I=function(t){function e(e,i){var n;return(n=t.call(this,e)||this)._collider=i,n._pxJoint=e._pxPhysics.createFixedJoint(null,T._defaultVec,T._defaultQuat,i._pxActor,T._defaultVec,T._defaultQuat),n}return s(e,t),e}(T),z=function(t){function i(i,n){var s;return(s=t.call(this,i)||this)._axisRotationQuaternion=new e.Quaternion,s._swingOffset=new e.Vector3,s._collider=n,s._pxJoint=i._pxPhysics.createRevoluteJoint(null,T._defaultVec,T._defaultQuat,n._pxActor,T._defaultVec,T._defaultQuat),s}s(i,t);var n=i.prototype;return n.setAxis=function(t){var i=T._xAxis,n=this._axisRotationQuaternion;i.set(1,0,0),t.normalize();var s=Math.acos(e.Vector3.dot(i,t));e.Vector3.cross(i,t,i),e.Quaternion.rotationAxisAngle(i,s,n),this._setLocalPose(0,this._swingOffset,n)},n.setSwingOffset=function(t){this._swingOffset.copyFrom(t),this._setLocalPose(1,this._swingOffset,this._axisRotationQuaternion)},n.getAngle=function(){return this._pxJoint.getAngle()},n.getVelocity=function(){return this._pxJoint.getVelocity()},n.setHardLimit=function(t,e,i){this._pxJoint.setHardLimit(t,e,i)},n.setSoftLimit=function(t,e,i,n){this._pxJoint.setSoftLimit(t,e,i,n)},n.setDriveVelocity=function(t,e){void 0===e&&(e=!0),this._pxJoint.setDriveVelocity(t,e)},n.setDriveForceLimit=function(t){this._pxJoint.setDriveForceLimit(t)},n.setDriveGearRatio=function(t){this._pxJoint.setDriveGearRatio(t)},n.setHingeJointFlag=function(t,e){this._pxJoint.setRevoluteJointFlag(t,e)},i}(T),D=function(t){function i(i,n){var s;return(s=t.call(this,i)||this)._swingOffset=new e.Vector3,s._collider=n,s._pxJoint=i._pxPhysics.createDistanceJoint(null,T._defaultVec,T._defaultQuat,n._pxActor,T._defaultVec,T._defaultQuat),s._pxJoint.setDistanceJointFlag(2,!0),s._pxJoint.setDistanceJointFlag(4,!0),s._pxJoint.setDistanceJointFlag(8,!0),s}s(i,t);var n=i.prototype;return n.setSwingOffset=function(t){this._swingOffset.copyFrom(t),this._setLocalPose(1,t,T._defaultQuat)},n.setMinDistance=function(t){this._pxJoint.setMinDistance(t)},n.setMaxDistance=function(t){this._pxJoint.setMaxDistance(t)},n.setTolerance=function(t){this._pxJoint.setTolerance(t)},n.setStiffness=function(t){this._pxJoint.setStiffness(t)},n.setDamping=function(t){this._pxJoint.setDamping(t)},i}(T),G=function(t){function i(i,n,s){var o;return(o=t.call(this,i)||this)._axis=new e.Quaternion(0,0,v.halfSqrt,v.halfSqrt),o._physXRotation.copyFrom(o._axis),o._pxGeometry=new i._physX.PxPlaneGeometry,o._initialize(s,n),o._setLocalPose(),o}return s(i,t),i}(v),V=function(t){function e(e,i,n,s){var o;return(o=t.call(this,e)||this)._maxScale=1,o._radius=n,o._pxGeometry=new e._physX.PxSphereGeometry(o._radius*o._maxScale),o._initialize(s,i),o._setLocalPose(),o}s(e,t);var i=e.prototype;return i.setRadius=function(t){this._radius=t,this._pxGeometry.radius=t*this._maxScale,this._pxShape.setGeometry(this._pxGeometry)},i.setWorldScale=function(e){t.prototype.setWorldScale.call(this,e),this._maxScale=Math.max(e.x,e.y,e.z),this._pxGeometry.radius=this._radius*this._maxScale,this._pxShape.setGeometry(this._pxGeometry)},e}(v),L=function(){function e(e){void 0===e&&(e=t.PhysXRuntimeMode.Auto),this._initializeState=0,this._runTimeMode=e}var n=e.prototype;return n.initialize=function(){var e=this;if(2===this._initializeState)return Promise.resolve();if(1===this._initializeState)return this._initializePromise;var n=this._runTimeMode,s=new Promise(function(e,s){var o=document.createElement("script");document.body.appendChild(o),o.async=!0,o.onload=e,o.onerror=s,n==t.PhysXRuntimeMode.Auto&&(n=!function(){try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){var t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(i(t,WebAssembly.Module))return i(new WebAssembly.Instance(t),WebAssembly.Instance)}}catch(t){}return!1}()?t.PhysXRuntimeMode.JavaScript:t.PhysXRuntimeMode.WebAssembly),n==t.PhysXRuntimeMode.JavaScript?o.src="https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js":n==t.PhysXRuntimeMode.WebAssembly&&(o.src="https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js")}),o=new Promise(function(t,i){s.then(function(){return window.PHYSX().then(function(i){e._init(i),e._initializeState=2,e._initializePromise=null,console.log("PhysX loaded."),t()},i)},i).catch(i)});return this._initializePromise=o,o},n.destroy=function(){this._physX.PxCloseExtensions(),this._pxPhysics.release(),this._pxFoundation.release(),this._physX=null,this._pxFoundation=null,this._pxPhysics=null},n.createPhysicsManager=function(){return new F},n.createPhysicsScene=function(t,e,i,n,s,o,r){return new X(this,t,e,i,n,s,o,r)},n.createStaticCollider=function(t,e){return new b(this,t,e)},n.createDynamicCollider=function(t,e){return new w(this,t,e)},n.createCharacterController=function(){return new C(this)},n.createPhysicsMaterial=function(t,e,i,n,s){return new R(this,t,e,i,n,s)},n.createBoxColliderShape=function(t,e,i){return new P(this,t,e,i)},n.createSphereColliderShape=function(t,e,i){return new V(this,t,e,i)},n.createPlaneColliderShape=function(t,e){return new G(this,t,e)},n.createCapsuleColliderShape=function(t,e,i,n){return new A(this,t,e,i,n)},n.createFixedJoint=function(t){return new I(this,t)},n.createHingeJoint=function(t){return new z(this,t)},n.createSpringJoint=function(t){return new D(this,t)},n._init=function(t){var e=t.PX_PHYSICS_VERSION,i=new t.PxDefaultErrorCallback,n=new t.PxDefaultAllocator,s=t.PxCreateFoundation(e,n,i),o=t.PxCreatePhysics(e,s,new t.PxTolerancesScale,!1,null);t.PxInitExtensions(o,null),this._physX=t,this._pxFoundation=s,this._pxPhysics=o},e}();(u=m||(m={}))[u.Uninitialized=0]="Uninitialized",u[u.Initializing=1]="Initializing",u[u.Initialized=2]="Initialized";var H="1.1.0-beta.20";console.log("Galacean PhysX version: "+H),t.PhysXPhysics=L,t.version=H,Object.defineProperty(t,"__esModule",{value:!0})});
package/dist/main.js CHANGED
@@ -93,7 +93,6 @@ var ShapeFlag;
93
93
  this._axis = null;
94
94
  this._physXRotation = new engine.Quaternion();
95
95
  this._shapeFlags = 2 | 1;
96
- /** @internal */ this._pxMaterials = new Array(1);
97
96
  this._physXPhysics = physXPhysics;
98
97
  }
99
98
  var _proto = PhysXColliderShape.prototype;
@@ -114,7 +113,7 @@ var ShapeFlag;
114
113
  }
115
114
  var controllers = this._controllers;
116
115
  for(var i = 0, n = controllers.length; i < n; i++){
117
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
116
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
118
117
  }
119
118
  this._setLocalPose();
120
119
  };
@@ -125,7 +124,7 @@ var ShapeFlag;
125
124
  this._setLocalPose();
126
125
  var controllers = this._controllers;
127
126
  for(var i = 0, n = controllers.length; i < n; i++){
128
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
127
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
129
128
  }
130
129
  };
131
130
  /**
@@ -141,8 +140,8 @@ var ShapeFlag;
141
140
  /**
142
141
  * {@inheritDoc IColliderShape.setMaterial }
143
142
  */ _proto.setMaterial = function setMaterial(value) {
144
- this._pxMaterials[0] = value._pxMaterial;
145
- this._pxShape.setMaterials(this._pxMaterials);
143
+ this._pxMaterial = value._pxMaterial;
144
+ this._pxShape.setMaterial(this._pxMaterial);
146
145
  };
147
146
  /**
148
147
  * {@inheritDoc IColliderShape.setIsTrigger }
@@ -170,7 +169,7 @@ var ShapeFlag;
170
169
  };
171
170
  _proto._initialize = function _initialize(material, id) {
172
171
  this._id = id;
173
- this._pxMaterials[0] = material._pxMaterial;
172
+ this._pxMaterial = material._pxMaterial;
174
173
  this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
175
174
  this._pxShape.setUUID(id);
176
175
  };
@@ -369,50 +368,55 @@ var /**
369
368
  * Base class for character controllers.
370
369
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
371
370
  function PhysXCharacterController(physXPhysics) {
372
- this._scaledOffset = new engine.Vector3();
373
- this._position = null;
371
+ this._shapeScaledPosition = new engine.Vector3();
372
+ this._worldPosition = null;
374
373
  this._physXPhysics = physXPhysics;
375
374
  }
376
375
  var _proto = PhysXCharacterController.prototype;
377
376
  /**
378
377
  * {@inheritDoc ICharacterController.move }
379
378
  */ _proto.move = function move(disp, minDist, elapsedTime) {
380
- return this._pxController.move(disp, minDist, elapsedTime);
379
+ var _this__pxController;
380
+ var _this__pxController_move;
381
+ return (_this__pxController_move = (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.move(disp, minDist, elapsedTime)) != null ? _this__pxController_move : 0;
381
382
  };
382
383
  /**
383
384
  * {@inheritDoc ICharacterController.setWorldPosition }
384
385
  */ _proto.setWorldPosition = function setWorldPosition(position) {
385
- this._position = position;
386
- if (this._pxController) {
387
- engine.Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
388
- this._pxController.setPosition(PhysXCharacterController._tempVec);
389
- }
386
+ this._worldPosition = position;
387
+ this._updateNativePosition();
390
388
  };
391
389
  /**
392
390
  * {@inheritDoc ICharacterController.getWorldPosition }
393
391
  */ _proto.getWorldPosition = function getWorldPosition(position) {
394
- position.copyFrom(this._pxController.getPosition());
395
- position.subtract(this._scaledOffset);
392
+ if (this._pxController) {
393
+ position.copyFrom(this._pxController.getPosition());
394
+ position.subtract(this._shapeScaledPosition);
395
+ }
396
396
  };
397
397
  /**
398
398
  * {@inheritDoc ICharacterController.setStepOffset }
399
399
  */ _proto.setStepOffset = function setStepOffset(offset) {
400
- this._pxController.setStepOffset(offset);
400
+ var _this__pxController;
401
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setStepOffset(offset);
401
402
  };
402
403
  /**
403
404
  * {@inheritDoc ICharacterController.setNonWalkableMode }
404
405
  */ _proto.setNonWalkableMode = function setNonWalkableMode(flag) {
405
- this._pxController.setNonWalkableMode(flag);
406
+ var _this__pxController;
407
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setNonWalkableMode(flag);
406
408
  };
407
409
  /**
408
410
  * {@inheritDoc ICharacterController.setUpDirection }
409
411
  */ _proto.setUpDirection = function setUpDirection(up) {
410
- this._pxController.setUpDirection(up);
412
+ var _this__pxController;
413
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setUpDirection(up);
411
414
  };
412
415
  /**
413
416
  * {@inheritDoc ICharacterController.setSlopeLimit }
414
417
  */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
415
- this._pxController.setSlopeLimit(slopeLimit);
418
+ var _this__pxController;
419
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(slopeLimit);
416
420
  };
417
421
  /**
418
422
  * {@inheritDoc ICharacterController.addShape }
@@ -450,7 +454,7 @@ var /**
450
454
  } else {
451
455
  throw "unsupported shape type";
452
456
  }
453
- desc.setMaterial(shape._pxMaterials[0]);
457
+ desc.setMaterial(shape._pxMaterial);
454
458
  this._pxController = pxManager._getControllerManager().createController(desc);
455
459
  this._pxController.setUUID(shape._id);
456
460
  };
@@ -464,9 +468,16 @@ var /**
464
468
  };
465
469
  /**
466
470
  * @internal
467
- */ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
468
- engine.Vector3.multiply(position, scale, this._scaledOffset);
469
- this.setWorldPosition(position);
471
+ */ _proto._updateShapePosition = function _updateShapePosition(shapePosition, worldScale) {
472
+ engine.Vector3.multiply(shapePosition, worldScale, this._shapeScaledPosition);
473
+ this._updateNativePosition();
474
+ };
475
+ _proto._updateNativePosition = function _updateNativePosition() {
476
+ var worldPosition = this._worldPosition;
477
+ if (this._pxController && worldPosition) {
478
+ engine.Vector3.add(worldPosition, this._shapeScaledPosition, PhysXCharacterController._tempVec);
479
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
480
+ }
470
481
  };
471
482
  return PhysXCharacterController;
472
483
  }();
@@ -1085,7 +1096,6 @@ var /**
1085
1096
  _this = PhysXJoint1.call(this, physXPhysics) || this;
1086
1097
  _this._axisRotationQuaternion = new engine.Quaternion();
1087
1098
  _this._swingOffset = new engine.Vector3();
1088
- _this._velocity = new engine.Vector3();
1089
1099
  _this._collider = collider;
1090
1100
  _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1091
1101
  return _this;
@@ -1117,9 +1127,7 @@ var /**
1117
1127
  /**
1118
1128
  * {@inheritDoc IHingeJoint.getVelocity }
1119
1129
  */ _proto.getVelocity = function getVelocity() {
1120
- var velocity = this._velocity;
1121
- velocity.copyFrom(this._pxJoint.getVelocity());
1122
- return velocity;
1130
+ return this._pxJoint.getVelocity();
1123
1131
  };
1124
1132
  /**
1125
1133
  * {@inheritDoc IHingeJoint.setHardLimitCone }
@@ -1133,8 +1141,9 @@ var /**
1133
1141
  };
1134
1142
  /**
1135
1143
  * {@inheritDoc IHingeJoint.setDriveVelocity }
1136
- */ _proto.setDriveVelocity = function setDriveVelocity(velocity) {
1137
- this._pxJoint.setDriveVelocity(velocity);
1144
+ */ _proto.setDriveVelocity = function setDriveVelocity(velocity, autowake) {
1145
+ if (autowake === void 0) autowake = true;
1146
+ this._pxJoint.setDriveVelocity(velocity, autowake);
1138
1147
  };
1139
1148
  /**
1140
1149
  * {@inheritDoc IHingeJoint.setDriveForceLimit }
@@ -1298,9 +1307,9 @@ var /**
1298
1307
  }
1299
1308
  }
1300
1309
  if (runtimeMode == exports.PhysXRuntimeMode.JavaScript) {
1301
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + engine.version + "/libs/physx.release.js.js";
1310
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
1302
1311
  } else if (runtimeMode == exports.PhysXRuntimeMode.WebAssembly) {
1303
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + engine.version + "/libs/physx.release.js";
1312
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js";
1304
1313
  }
1305
1314
  });
1306
1315
  var initializePromise = new Promise(function(resolve, reject) {
@@ -1413,5 +1422,10 @@ var InitializeState;
1413
1422
  InitializeState[InitializeState["Initialized"] = 2] = "Initialized";
1414
1423
  })(InitializeState || (InitializeState = {}));
1415
1424
 
1425
+ //@ts-ignore
1426
+ var version = "1.1.0-beta.20";
1427
+ console.log("Galacean PhysX version: " + version);
1428
+
1416
1429
  exports.PhysXPhysics = PhysXPhysics;
1430
+ exports.version = version;
1417
1431
  //# sourceMappingURL=main.js.map