@galacean/engine-physics-physx 1.1.0-beta.5 → 1.1.0-beta.50

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.
@@ -94,7 +94,6 @@ var ShapeFlag;
94
94
  this._axis = null;
95
95
  this._physXRotation = new miniprogram.Quaternion();
96
96
  this._shapeFlags = 2 | 1;
97
- /** @internal */ this._pxMaterials = new Array(1);
98
97
  this._physXPhysics = physXPhysics;
99
98
  }
100
99
  var _proto = PhysXColliderShape.prototype;
@@ -115,7 +114,7 @@ var ShapeFlag;
115
114
  }
116
115
  var controllers = this._controllers;
117
116
  for(var i = 0, n = controllers.length; i < n; i++){
118
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
117
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
119
118
  }
120
119
  this._setLocalPose();
121
120
  };
@@ -126,7 +125,7 @@ var ShapeFlag;
126
125
  this._setLocalPose();
127
126
  var controllers = this._controllers;
128
127
  for(var i = 0, n = controllers.length; i < n; i++){
129
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
128
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
130
129
  }
131
130
  };
132
131
  /**
@@ -142,8 +141,8 @@ var ShapeFlag;
142
141
  /**
143
142
  * {@inheritDoc IColliderShape.setMaterial }
144
143
  */ _proto.setMaterial = function setMaterial(value) {
145
- this._pxMaterials[0] = value._pxMaterial;
146
- this._pxShape.setMaterials(this._pxMaterials);
144
+ this._pxMaterial = value._pxMaterial;
145
+ this._pxShape.setMaterial(this._pxMaterial);
147
146
  };
148
147
  /**
149
148
  * {@inheritDoc IColliderShape.setIsTrigger }
@@ -171,7 +170,7 @@ var ShapeFlag;
171
170
  };
172
171
  _proto._initialize = function _initialize(material, id) {
173
172
  this._id = id;
174
- this._pxMaterials[0] = material._pxMaterial;
173
+ this._pxMaterial = material._pxMaterial;
175
174
  this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
176
175
  this._pxShape.setUUID(id);
177
176
  };
@@ -370,8 +369,8 @@ var /**
370
369
  * Base class for character controllers.
371
370
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
372
371
  function PhysXCharacterController(physXPhysics) {
373
- this._scaledOffset = new miniprogram.Vector3();
374
- this._position = null;
372
+ this._shapeScaledPosition = new miniprogram.Vector3();
373
+ this._worldPosition = null;
375
374
  this._physXPhysics = physXPhysics;
376
375
  }
377
376
  var _proto = PhysXCharacterController.prototype;
@@ -385,18 +384,15 @@ var /**
385
384
  /**
386
385
  * {@inheritDoc ICharacterController.setWorldPosition }
387
386
  */ _proto.setWorldPosition = function setWorldPosition(position) {
388
- this._position = position;
389
- if (this._pxController) {
390
- miniprogram.Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
391
- this._pxController.setPosition(PhysXCharacterController._tempVec);
392
- }
387
+ this._worldPosition = position;
388
+ this._updateNativePosition();
393
389
  };
394
390
  /**
395
391
  * {@inheritDoc ICharacterController.getWorldPosition }
396
392
  */ _proto.getWorldPosition = function getWorldPosition(position) {
397
393
  if (this._pxController) {
398
394
  position.copyFrom(this._pxController.getPosition());
399
- position.subtract(this._scaledOffset);
395
+ position.subtract(this._shapeScaledPosition);
400
396
  }
401
397
  };
402
398
  /**
@@ -459,7 +455,7 @@ var /**
459
455
  } else {
460
456
  throw "unsupported shape type";
461
457
  }
462
- desc.setMaterial(shape._pxMaterials[0]);
458
+ desc.setMaterial(shape._pxMaterial);
463
459
  this._pxController = pxManager._getControllerManager().createController(desc);
464
460
  this._pxController.setUUID(shape._id);
465
461
  };
@@ -473,9 +469,16 @@ var /**
473
469
  };
474
470
  /**
475
471
  * @internal
476
- */ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
477
- miniprogram.Vector3.multiply(position, scale, this._scaledOffset);
478
- this.setWorldPosition(position);
472
+ */ _proto._updateShapePosition = function _updateShapePosition(shapePosition, worldScale) {
473
+ miniprogram.Vector3.multiply(shapePosition, worldScale, this._shapeScaledPosition);
474
+ this._updateNativePosition();
475
+ };
476
+ _proto._updateNativePosition = function _updateNativePosition() {
477
+ var worldPosition = this._worldPosition;
478
+ if (this._pxController && worldPosition) {
479
+ miniprogram.Vector3.add(worldPosition, this._shapeScaledPosition, PhysXCharacterController._tempVec);
480
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
481
+ }
479
482
  };
480
483
  return PhysXCharacterController;
481
484
  }();
@@ -823,15 +826,21 @@ var /**
823
826
  * {@inheritDoc IPhysicsManager.removeColliderShape }
824
827
  */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
825
828
  var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
826
- var shapeID = colliderShape._id;
829
+ var id = colliderShape._id;
830
+ var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
827
831
  for(var i = currentEvents.length - 1; i >= 0; i--){
828
832
  var event = currentEvents.get(i);
829
- if (event.index1 == shapeID || event.index2 == shapeID) {
833
+ if (event.index1 == id) {
834
+ currentEvents.deleteByIndex(i);
835
+ eventPool.push(event);
836
+ } else if (event.index2 == id) {
830
837
  currentEvents.deleteByIndex(i);
831
838
  eventPool.push(event);
839
+ // If the shape is big index, should clear from the small index shape subMap
840
+ eventMap[event.index1][id] = undefined;
832
841
  }
833
842
  }
834
- delete this._physXManager._eventMap[shapeID];
843
+ delete eventMap[id];
835
844
  };
836
845
  /**
837
846
  * {@inheritDoc IPhysicsManager.addCollider }
@@ -1094,7 +1103,6 @@ var /**
1094
1103
  _this = PhysXJoint1.call(this, physXPhysics) || this;
1095
1104
  _this._axisRotationQuaternion = new miniprogram.Quaternion();
1096
1105
  _this._swingOffset = new miniprogram.Vector3();
1097
- _this._velocity = new miniprogram.Vector3();
1098
1106
  _this._collider = collider;
1099
1107
  _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1100
1108
  return _this;
@@ -1126,9 +1134,7 @@ var /**
1126
1134
  /**
1127
1135
  * {@inheritDoc IHingeJoint.getVelocity }
1128
1136
  */ _proto.getVelocity = function getVelocity() {
1129
- var velocity = this._velocity;
1130
- velocity.copyFrom(this._pxJoint.getVelocity());
1131
- return velocity;
1137
+ return this._pxJoint.getVelocity();
1132
1138
  };
1133
1139
  /**
1134
1140
  * {@inheritDoc IHingeJoint.setHardLimitCone }
@@ -1142,8 +1148,9 @@ var /**
1142
1148
  };
1143
1149
  /**
1144
1150
  * {@inheritDoc IHingeJoint.setDriveVelocity }
1145
- */ _proto.setDriveVelocity = function setDriveVelocity(velocity) {
1146
- this._pxJoint.setDriveVelocity(velocity);
1151
+ */ _proto.setDriveVelocity = function setDriveVelocity(velocity, autowake) {
1152
+ if (autowake === void 0) autowake = true;
1153
+ this._pxJoint.setDriveVelocity(velocity, autowake);
1147
1154
  };
1148
1155
  /**
1149
1156
  * {@inheritDoc IHingeJoint.setDriveForceLimit }
@@ -1307,9 +1314,9 @@ var /**
1307
1314
  }
1308
1315
  }
1309
1316
  if (runtimeMode == exports.PhysXRuntimeMode.JavaScript) {
1310
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + miniprogram.version + "/libs/physx.release.js.js";
1317
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
1311
1318
  } else if (runtimeMode == exports.PhysXRuntimeMode.WebAssembly) {
1312
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + miniprogram.version + "/libs/physx.release.js";
1319
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js";
1313
1320
  }
1314
1321
  });
1315
1322
  var initializePromise = new Promise(function(resolve, reject) {
@@ -1423,7 +1430,7 @@ var InitializeState;
1423
1430
  })(InitializeState || (InitializeState = {}));
1424
1431
 
1425
1432
  //@ts-ignore
1426
- var version = "1.1.0-beta.5";
1433
+ var version = "1.1.0-beta.50";
1427
1434
  console.log("Galacean PhysX version: " + version);
1428
1435
 
1429
1436
  exports.PhysXPhysics = PhysXPhysics;
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Vector3, Quaternion, version as version$1 } from '@galacean/engine';
1
+ import { Vector3, Quaternion } from '@galacean/engine';
2
2
 
3
3
  function _instanceof(left, right) {
4
4
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
@@ -89,7 +89,6 @@ var ShapeFlag;
89
89
  this._axis = null;
90
90
  this._physXRotation = new Quaternion();
91
91
  this._shapeFlags = 2 | 1;
92
- /** @internal */ this._pxMaterials = new Array(1);
93
92
  this._physXPhysics = physXPhysics;
94
93
  }
95
94
  var _proto = PhysXColliderShape.prototype;
@@ -110,7 +109,7 @@ var ShapeFlag;
110
109
  }
111
110
  var controllers = this._controllers;
112
111
  for(var i = 0, n = controllers.length; i < n; i++){
113
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
112
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
114
113
  }
115
114
  this._setLocalPose();
116
115
  };
@@ -121,7 +120,7 @@ var ShapeFlag;
121
120
  this._setLocalPose();
122
121
  var controllers = this._controllers;
123
122
  for(var i = 0, n = controllers.length; i < n; i++){
124
- controllers.get(i)._setLocalPosition(this._position, this._worldScale);
123
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
125
124
  }
126
125
  };
127
126
  /**
@@ -137,8 +136,8 @@ var ShapeFlag;
137
136
  /**
138
137
  * {@inheritDoc IColliderShape.setMaterial }
139
138
  */ _proto.setMaterial = function setMaterial(value) {
140
- this._pxMaterials[0] = value._pxMaterial;
141
- this._pxShape.setMaterials(this._pxMaterials);
139
+ this._pxMaterial = value._pxMaterial;
140
+ this._pxShape.setMaterial(this._pxMaterial);
142
141
  };
143
142
  /**
144
143
  * {@inheritDoc IColliderShape.setIsTrigger }
@@ -166,7 +165,7 @@ var ShapeFlag;
166
165
  };
167
166
  _proto._initialize = function _initialize(material, id) {
168
167
  this._id = id;
169
- this._pxMaterials[0] = material._pxMaterial;
168
+ this._pxMaterial = material._pxMaterial;
170
169
  this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
171
170
  this._pxShape.setUUID(id);
172
171
  };
@@ -365,8 +364,8 @@ var /**
365
364
  * Base class for character controllers.
366
365
  */ var PhysXCharacterController = /*#__PURE__*/ function() {
367
366
  function PhysXCharacterController(physXPhysics) {
368
- this._scaledOffset = new Vector3();
369
- this._position = null;
367
+ this._shapeScaledPosition = new Vector3();
368
+ this._worldPosition = null;
370
369
  this._physXPhysics = physXPhysics;
371
370
  }
372
371
  var _proto = PhysXCharacterController.prototype;
@@ -380,18 +379,15 @@ var /**
380
379
  /**
381
380
  * {@inheritDoc ICharacterController.setWorldPosition }
382
381
  */ _proto.setWorldPosition = function setWorldPosition(position) {
383
- this._position = position;
384
- if (this._pxController) {
385
- Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
386
- this._pxController.setPosition(PhysXCharacterController._tempVec);
387
- }
382
+ this._worldPosition = position;
383
+ this._updateNativePosition();
388
384
  };
389
385
  /**
390
386
  * {@inheritDoc ICharacterController.getWorldPosition }
391
387
  */ _proto.getWorldPosition = function getWorldPosition(position) {
392
388
  if (this._pxController) {
393
389
  position.copyFrom(this._pxController.getPosition());
394
- position.subtract(this._scaledOffset);
390
+ position.subtract(this._shapeScaledPosition);
395
391
  }
396
392
  };
397
393
  /**
@@ -454,7 +450,7 @@ var /**
454
450
  } else {
455
451
  throw "unsupported shape type";
456
452
  }
457
- desc.setMaterial(shape._pxMaterials[0]);
453
+ desc.setMaterial(shape._pxMaterial);
458
454
  this._pxController = pxManager._getControllerManager().createController(desc);
459
455
  this._pxController.setUUID(shape._id);
460
456
  };
@@ -468,9 +464,16 @@ var /**
468
464
  };
469
465
  /**
470
466
  * @internal
471
- */ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
472
- Vector3.multiply(position, scale, this._scaledOffset);
473
- this.setWorldPosition(position);
467
+ */ _proto._updateShapePosition = function _updateShapePosition(shapePosition, worldScale) {
468
+ Vector3.multiply(shapePosition, worldScale, this._shapeScaledPosition);
469
+ this._updateNativePosition();
470
+ };
471
+ _proto._updateNativePosition = function _updateNativePosition() {
472
+ var worldPosition = this._worldPosition;
473
+ if (this._pxController && worldPosition) {
474
+ Vector3.add(worldPosition, this._shapeScaledPosition, PhysXCharacterController._tempVec);
475
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
476
+ }
474
477
  };
475
478
  return PhysXCharacterController;
476
479
  }();
@@ -818,15 +821,21 @@ var /**
818
821
  * {@inheritDoc IPhysicsManager.removeColliderShape }
819
822
  */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
820
823
  var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
821
- var shapeID = colliderShape._id;
824
+ var id = colliderShape._id;
825
+ var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
822
826
  for(var i = currentEvents.length - 1; i >= 0; i--){
823
827
  var event = currentEvents.get(i);
824
- if (event.index1 == shapeID || event.index2 == shapeID) {
828
+ if (event.index1 == id) {
829
+ currentEvents.deleteByIndex(i);
830
+ eventPool.push(event);
831
+ } else if (event.index2 == id) {
825
832
  currentEvents.deleteByIndex(i);
826
833
  eventPool.push(event);
834
+ // If the shape is big index, should clear from the small index shape subMap
835
+ eventMap[event.index1][id] = undefined;
827
836
  }
828
837
  }
829
- delete this._physXManager._eventMap[shapeID];
838
+ delete eventMap[id];
830
839
  };
831
840
  /**
832
841
  * {@inheritDoc IPhysicsManager.addCollider }
@@ -1089,7 +1098,6 @@ var /**
1089
1098
  _this = PhysXJoint1.call(this, physXPhysics) || this;
1090
1099
  _this._axisRotationQuaternion = new Quaternion();
1091
1100
  _this._swingOffset = new Vector3();
1092
- _this._velocity = new Vector3();
1093
1101
  _this._collider = collider;
1094
1102
  _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1095
1103
  return _this;
@@ -1121,9 +1129,7 @@ var /**
1121
1129
  /**
1122
1130
  * {@inheritDoc IHingeJoint.getVelocity }
1123
1131
  */ _proto.getVelocity = function getVelocity() {
1124
- var velocity = this._velocity;
1125
- velocity.copyFrom(this._pxJoint.getVelocity());
1126
- return velocity;
1132
+ return this._pxJoint.getVelocity();
1127
1133
  };
1128
1134
  /**
1129
1135
  * {@inheritDoc IHingeJoint.setHardLimitCone }
@@ -1137,8 +1143,9 @@ var /**
1137
1143
  };
1138
1144
  /**
1139
1145
  * {@inheritDoc IHingeJoint.setDriveVelocity }
1140
- */ _proto.setDriveVelocity = function setDriveVelocity(velocity) {
1141
- this._pxJoint.setDriveVelocity(velocity);
1146
+ */ _proto.setDriveVelocity = function setDriveVelocity(velocity, autowake) {
1147
+ if (autowake === void 0) autowake = true;
1148
+ this._pxJoint.setDriveVelocity(velocity, autowake);
1142
1149
  };
1143
1150
  /**
1144
1151
  * {@inheritDoc IHingeJoint.setDriveForceLimit }
@@ -1302,9 +1309,9 @@ var /**
1302
1309
  }
1303
1310
  }
1304
1311
  if (runtimeMode == PhysXRuntimeMode.JavaScript) {
1305
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + version$1 + "/libs/physx.release.js.js";
1312
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
1306
1313
  } else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
1307
- script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + version$1 + "/libs/physx.release.js";
1314
+ script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*nA97QLQehRMAAAAAAAAAAAAAARQnAQ/physx.release.js";
1308
1315
  }
1309
1316
  });
1310
1317
  var initializePromise = new Promise(function(resolve, reject) {
@@ -1418,7 +1425,7 @@ var InitializeState;
1418
1425
  })(InitializeState || (InitializeState = {}));
1419
1426
 
1420
1427
  //@ts-ignore
1421
- var version = "1.1.0-beta.5";
1428
+ var version = "1.1.0-beta.50";
1422
1429
  console.log("Galacean PhysX version: " + version);
1423
1430
 
1424
1431
  export { PhysXPhysics, PhysXRuntimeMode, version };