@galacean/engine-physics-physx 1.4.0-alpha.0 → 1.4.0-alpha.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/browser.js +167 -74
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/dist/main.js +167 -74
- package/dist/main.js.map +1 -1
- package/dist/module.js +167 -74
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/PhysXDynamicCollider.d.ts +36 -0
- package/types/PhysXPhysicsScene.d.ts +0 -9
- package/types/joint/PhysXHingeJoint.d.ts +5 -5
- package/types/joint/PhysXJoint.d.ts +15 -9
- package/types/joint/PhysXSpringJoint.d.ts +0 -6
- package/types/shape/PhysXBoxColliderShape.d.ts +0 -1
- package/types/shape/PhysXCapsuleColliderShape.d.ts +0 -1
package/dist/main.js
CHANGED
|
@@ -41,6 +41,7 @@ function _inherits(subClass, superClass) {
|
|
|
41
41
|
*/ var PhysXColliderShape = /*#__PURE__*/ function() {
|
|
42
42
|
function PhysXColliderShape(physXPhysics) {
|
|
43
43
|
/** @internal */ this._controllers = new engine.DisorderedArray();
|
|
44
|
+
/** @internal */ this._contractOffset = 0.02;
|
|
44
45
|
this._worldScale = new engine.Vector3(1, 1, 1);
|
|
45
46
|
this._position = new engine.Vector3();
|
|
46
47
|
this._rotation = null;
|
|
@@ -74,7 +75,7 @@ function _inherits(subClass, superClass) {
|
|
|
74
75
|
/**
|
|
75
76
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
76
77
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
77
|
-
this._worldScale.
|
|
78
|
+
this._worldScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
|
|
78
79
|
this._setLocalPose();
|
|
79
80
|
var controllers = this._controllers;
|
|
80
81
|
for(var i = 0, n = controllers.length; i < n; i++){
|
|
@@ -85,11 +86,15 @@ function _inherits(subClass, superClass) {
|
|
|
85
86
|
* {@inheritDoc IColliderShape.setContactOffset }
|
|
86
87
|
* @default 0.02f * PxTolerancesScale::length
|
|
87
88
|
*/ _proto.setContactOffset = function setContactOffset(offset) {
|
|
88
|
-
this.
|
|
89
|
+
this._contractOffset = offset;
|
|
89
90
|
var controllers = this._controllers;
|
|
90
|
-
|
|
91
|
-
var
|
|
92
|
-
|
|
91
|
+
if (controllers.length) {
|
|
92
|
+
for(var i = 0, n = controllers.length; i < n; i++){
|
|
93
|
+
var _controllers_get__pxController;
|
|
94
|
+
(_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
this._pxShape.setContactOffset(offset);
|
|
93
98
|
}
|
|
94
99
|
};
|
|
95
100
|
/**
|
|
@@ -145,7 +150,7 @@ PhysXColliderShape.transform = {
|
|
|
145
150
|
_inherits(PhysXBoxColliderShape, PhysXColliderShape);
|
|
146
151
|
function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
|
|
147
152
|
var _this;
|
|
148
|
-
_this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new engine.Vector3()
|
|
153
|
+
_this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new engine.Vector3();
|
|
149
154
|
var halfSize = _this._halfSize;
|
|
150
155
|
halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
|
|
151
156
|
_this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(halfSize.x, halfSize.y, halfSize.z);
|
|
@@ -160,7 +165,7 @@ PhysXColliderShape.transform = {
|
|
|
160
165
|
var halfSize = this._halfSize;
|
|
161
166
|
var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
|
|
162
167
|
halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
|
|
163
|
-
engine.Vector3.multiply(halfSize, this.
|
|
168
|
+
engine.Vector3.multiply(halfSize, this._worldScale, tempExtents);
|
|
164
169
|
this._pxGeometry.halfExtents = tempExtents;
|
|
165
170
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
166
171
|
this._updateController(tempExtents);
|
|
@@ -169,9 +174,8 @@ PhysXColliderShape.transform = {
|
|
|
169
174
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
170
175
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
171
176
|
PhysXColliderShape.prototype.setWorldScale.call(this, scale);
|
|
172
|
-
this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
|
|
173
177
|
var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
|
|
174
|
-
engine.Vector3.multiply(this._halfSize, this.
|
|
178
|
+
engine.Vector3.multiply(this._halfSize, this._worldScale, tempExtents);
|
|
175
179
|
this._pxGeometry.halfExtents = tempExtents;
|
|
176
180
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
177
181
|
this._updateController(tempExtents);
|
|
@@ -197,7 +201,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
197
201
|
_inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
|
|
198
202
|
function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
|
|
199
203
|
var _this;
|
|
200
|
-
_this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1
|
|
204
|
+
_this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1;
|
|
201
205
|
_this._radius = radius;
|
|
202
206
|
_this._halfHeight = height * 0.5;
|
|
203
207
|
_this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
|
|
@@ -212,7 +216,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
212
216
|
* {@inheritDoc ICapsuleColliderShape.setRadius }
|
|
213
217
|
*/ _proto.setRadius = function setRadius(value) {
|
|
214
218
|
this._radius = value;
|
|
215
|
-
var sizeScale = this.
|
|
219
|
+
var sizeScale = this._worldScale;
|
|
216
220
|
switch(this._upAxis){
|
|
217
221
|
case 0:
|
|
218
222
|
this._pxGeometry.radius = this._radius * Math.max(sizeScale.y, sizeScale.z);
|
|
@@ -236,7 +240,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
236
240
|
* {@inheritDoc ICapsuleColliderShape.setHeight }
|
|
237
241
|
*/ _proto.setHeight = function setHeight(value) {
|
|
238
242
|
this._halfHeight = value * 0.5;
|
|
239
|
-
var sizeScale = this.
|
|
243
|
+
var sizeScale = this._worldScale;
|
|
240
244
|
switch(this._upAxis){
|
|
241
245
|
case 0:
|
|
242
246
|
this._pxGeometry.halfHeight = this._halfHeight * sizeScale.x;
|
|
@@ -284,7 +288,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
284
288
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
285
289
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
286
290
|
PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
|
|
287
|
-
var sizeScale = this.
|
|
291
|
+
var sizeScale = this._worldScale;
|
|
288
292
|
var geometry = this._pxGeometry;
|
|
289
293
|
switch(this._upAxis){
|
|
290
294
|
case 0:
|
|
@@ -319,6 +323,7 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
319
323
|
* Base class for character controllers.
|
|
320
324
|
*/ var PhysXCharacterController = /*#__PURE__*/ function() {
|
|
321
325
|
function PhysXCharacterController(physXPhysics) {
|
|
326
|
+
/** @internal */ this._scene = null;
|
|
322
327
|
this._shapeScaledPosition = new engine.Vector3();
|
|
323
328
|
this._worldPosition = null;
|
|
324
329
|
this._physXPhysics = physXPhysics;
|
|
@@ -372,17 +377,22 @@ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
|
|
|
372
377
|
/**
|
|
373
378
|
* {@inheritDoc ICharacterController.addShape }
|
|
374
379
|
*/ _proto.addShape = function addShape(shape) {
|
|
380
|
+
var _this__pxController, _this__scene;
|
|
375
381
|
// When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
|
|
376
382
|
this._pxManager && this._createPXController(this._pxManager, shape);
|
|
377
383
|
this._shape = shape;
|
|
378
384
|
shape._controllers.add(this);
|
|
385
|
+
(_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape._contractOffset);
|
|
386
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
|
|
379
387
|
};
|
|
380
388
|
/**
|
|
381
389
|
* {@inheritDoc ICharacterController.removeShape }
|
|
382
390
|
*/ _proto.removeShape = function removeShape(shape) {
|
|
391
|
+
var _this__scene;
|
|
383
392
|
this._destroyPXController();
|
|
384
393
|
this._shape = null;
|
|
385
394
|
shape._controllers.delete(this);
|
|
395
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
|
|
386
396
|
};
|
|
387
397
|
/**
|
|
388
398
|
* {@inheritDoc ICharacterController.destroy }
|
|
@@ -439,18 +449,27 @@ PhysXCharacterController._tempVec = new engine.Vector3();
|
|
|
439
449
|
* Abstract class of physical collider.
|
|
440
450
|
*/ var PhysXCollider = /*#__PURE__*/ function() {
|
|
441
451
|
function PhysXCollider(physXPhysics) {
|
|
452
|
+
/** @internal */ this._scene = null;
|
|
453
|
+
/** @internal */ this._shapes = new Array();
|
|
442
454
|
this._physXPhysics = physXPhysics;
|
|
443
455
|
}
|
|
444
456
|
var _proto = PhysXCollider.prototype;
|
|
445
457
|
/**
|
|
446
458
|
* {@inheritDoc ICollider.addShape }
|
|
447
459
|
*/ _proto.addShape = function addShape(shape) {
|
|
460
|
+
var _this__scene;
|
|
448
461
|
this._pxActor.attachShape(shape._pxShape);
|
|
462
|
+
this._shapes.push(shape);
|
|
463
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
|
|
449
464
|
};
|
|
450
465
|
/**
|
|
451
466
|
* {@inheritDoc ICollider.removeShape }
|
|
452
467
|
*/ _proto.removeShape = function removeShape(shape) {
|
|
468
|
+
var _this__scene;
|
|
453
469
|
this._pxActor.detachShape(shape._pxShape, true);
|
|
470
|
+
var shapes = this._shapes;
|
|
471
|
+
shapes.splice(shapes.indexOf(shape), 1);
|
|
472
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
|
|
454
473
|
};
|
|
455
474
|
/**
|
|
456
475
|
* {@inheritDoc ICollider.setWorldTransform }
|
|
@@ -497,21 +516,43 @@ PhysXCollider._tempTransform = {
|
|
|
497
516
|
}
|
|
498
517
|
var _proto = PhysXDynamicCollider.prototype;
|
|
499
518
|
/**
|
|
519
|
+
* {@inheritDoc IDynamicCollider.getLinearDamping }
|
|
520
|
+
*/ _proto.getLinearDamping = function getLinearDamping() {
|
|
521
|
+
return this._pxActor.getLinearDamping();
|
|
522
|
+
};
|
|
523
|
+
/**
|
|
500
524
|
* {@inheritDoc IDynamicCollider.setLinearDamping }
|
|
501
525
|
*/ _proto.setLinearDamping = function setLinearDamping(value) {
|
|
502
526
|
this._pxActor.setLinearDamping(value);
|
|
503
527
|
};
|
|
504
528
|
/**
|
|
529
|
+
* {@inheritDoc IDynamicCollider.getAngularDamping }
|
|
530
|
+
*/ _proto.getAngularDamping = function getAngularDamping() {
|
|
531
|
+
return this._pxActor.getAngularDamping();
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
505
534
|
* {@inheritDoc IDynamicCollider.setAngularDamping }
|
|
506
535
|
*/ _proto.setAngularDamping = function setAngularDamping(value) {
|
|
507
536
|
this._pxActor.setAngularDamping(value);
|
|
508
537
|
};
|
|
509
538
|
/**
|
|
539
|
+
* {@inheritDoc IDynamicCollider.getLinearVelocity }
|
|
540
|
+
*/ _proto.getLinearVelocity = function getLinearVelocity(out) {
|
|
541
|
+
var velocity = this._pxActor.getLinearVelocity();
|
|
542
|
+
return out.set(velocity.x, velocity.y, velocity.z);
|
|
543
|
+
};
|
|
544
|
+
/**
|
|
510
545
|
* {@inheritDoc IDynamicCollider.setLinearVelocity }
|
|
511
546
|
*/ _proto.setLinearVelocity = function setLinearVelocity(value) {
|
|
512
547
|
this._pxActor.setLinearVelocity(value, true);
|
|
513
548
|
};
|
|
514
549
|
/**
|
|
550
|
+
* {@inheritDoc IDynamicCollider.getAngularVelocity }
|
|
551
|
+
*/ _proto.getAngularVelocity = function getAngularVelocity(out) {
|
|
552
|
+
var velocity = this._pxActor.getAngularVelocity();
|
|
553
|
+
return out.set(velocity.x, velocity.y, velocity.z);
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
515
556
|
* {@inheritDoc IDynamicCollider.setAngularVelocity }
|
|
516
557
|
*/ _proto.setAngularVelocity = function setAngularVelocity(value) {
|
|
517
558
|
this._pxActor.setAngularVelocity(value, true);
|
|
@@ -522,6 +563,12 @@ PhysXCollider._tempTransform = {
|
|
|
522
563
|
this._pxActor.setMass(value);
|
|
523
564
|
};
|
|
524
565
|
/**
|
|
566
|
+
* {@inheritDoc IDynamicCollider.getCenterOfMass }
|
|
567
|
+
*/ _proto.getCenterOfMass = function getCenterOfMass(out) {
|
|
568
|
+
var translation = this._pxActor.getCMassLocalPose().translation;
|
|
569
|
+
return out.set(translation.x, translation.y, translation.z);
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
525
572
|
* {@inheritDoc IDynamicCollider.setCenterOfMass }
|
|
526
573
|
*/ _proto.setCenterOfMass = function setCenterOfMass(position) {
|
|
527
574
|
this._pxActor.setCMassLocalPose(position);
|
|
@@ -532,11 +579,27 @@ PhysXCollider._tempTransform = {
|
|
|
532
579
|
this._pxActor.setMassSpaceInertiaTensor(value);
|
|
533
580
|
};
|
|
534
581
|
/**
|
|
582
|
+
* {@inheritDoc IDynamicCollider.getInertiaTensor }
|
|
583
|
+
*/ _proto.getInertiaTensor = function getInertiaTensor(out) {
|
|
584
|
+
var inertia = this._pxActor.getMassSpaceInertiaTensor();
|
|
585
|
+
return out.set(inertia.x, inertia.y, inertia.z);
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
|
|
589
|
+
*/ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
|
|
590
|
+
this._pxActor.setMassAndUpdateInertia(mass);
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
535
593
|
* {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
|
|
536
594
|
*/ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
|
|
537
595
|
this._pxActor.setMaxAngularVelocity(value);
|
|
538
596
|
};
|
|
539
597
|
/**
|
|
598
|
+
* {@inheritDoc IDynamicCollider.getMaxDepenetrationVelocity }
|
|
599
|
+
*/ _proto.getMaxDepenetrationVelocity = function getMaxDepenetrationVelocity() {
|
|
600
|
+
return this._pxActor.getMaxDepenetrationVelocity();
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
540
603
|
* {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
|
|
541
604
|
*/ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
|
|
542
605
|
this._pxActor.setMaxDepenetrationVelocity(value);
|
|
@@ -555,18 +618,20 @@ PhysXCollider._tempTransform = {
|
|
|
555
618
|
/**
|
|
556
619
|
* {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
|
|
557
620
|
*/ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
|
|
621
|
+
var physX = this._physXPhysics._physX;
|
|
558
622
|
switch(value){
|
|
559
623
|
case 1:
|
|
560
|
-
this._pxActor.setRigidBodyFlag(
|
|
624
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
|
|
561
625
|
break;
|
|
562
626
|
case 2:
|
|
563
|
-
this._pxActor.setRigidBodyFlag(
|
|
627
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
628
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
|
|
564
629
|
break;
|
|
565
630
|
case 3:
|
|
566
|
-
this._pxActor.setRigidBodyFlag(
|
|
631
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
632
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
|
|
567
633
|
break;
|
|
568
634
|
case 0:
|
|
569
|
-
var physX = this._physXPhysics._physX;
|
|
570
635
|
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
571
636
|
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
572
637
|
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
@@ -627,6 +692,11 @@ PhysXCollider._tempTransform = {
|
|
|
627
692
|
return this._pxActor.putToSleep();
|
|
628
693
|
};
|
|
629
694
|
/**
|
|
695
|
+
* {@inheritDoc IDynamicCollider.isSleeping }
|
|
696
|
+
*/ _proto.isSleeping = function isSleeping() {
|
|
697
|
+
return this._pxActor.isSleeping();
|
|
698
|
+
};
|
|
699
|
+
/**
|
|
630
700
|
* {@inheritDoc IDynamicCollider.wakeUp }
|
|
631
701
|
*/ _proto.wakeUp = function wakeUp() {
|
|
632
702
|
return this._pxActor.wakeUp();
|
|
@@ -745,42 +815,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
745
815
|
this._pxScene.setGravity(value);
|
|
746
816
|
};
|
|
747
817
|
/**
|
|
748
|
-
* {@inheritDoc IPhysicsManager.addColliderShape }
|
|
749
|
-
*/ _proto.addColliderShape = function addColliderShape(colliderShape) {
|
|
750
|
-
this._physXManager._eventMap[colliderShape._id] = {};
|
|
751
|
-
};
|
|
752
|
-
/**
|
|
753
|
-
* {@inheritDoc IPhysicsManager.removeColliderShape }
|
|
754
|
-
*/ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
|
|
755
|
-
var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
|
|
756
|
-
var id = colliderShape._id;
|
|
757
|
-
var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
|
|
758
|
-
currentEvents.forEach(function(event, i) {
|
|
759
|
-
if (event.index1 == id) {
|
|
760
|
-
currentEvents.deleteByIndex(i);
|
|
761
|
-
eventPool.push(event);
|
|
762
|
-
} else if (event.index2 == id) {
|
|
763
|
-
currentEvents.deleteByIndex(i);
|
|
764
|
-
eventPool.push(event);
|
|
765
|
-
// If the shape is big index, should clear from the small index shape subMap
|
|
766
|
-
eventMap[event.index1][id] = undefined;
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
delete eventMap[id];
|
|
770
|
-
};
|
|
771
|
-
/**
|
|
772
818
|
* {@inheritDoc IPhysicsManager.addCollider }
|
|
773
819
|
*/ _proto.addCollider = function addCollider(collider) {
|
|
820
|
+
collider._scene = this;
|
|
774
821
|
this._pxScene.addActor(collider._pxActor, null);
|
|
822
|
+
var shapes = collider._shapes;
|
|
823
|
+
for(var i = 0, n = shapes.length; i < n; i++){
|
|
824
|
+
this._addColliderShape(shapes[i]._id);
|
|
825
|
+
}
|
|
775
826
|
};
|
|
776
827
|
/**
|
|
777
828
|
* {@inheritDoc IPhysicsManager.removeCollider }
|
|
778
829
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
830
|
+
collider._scene = null;
|
|
779
831
|
this._pxScene.removeActor(collider._pxActor, true);
|
|
832
|
+
var shapes = collider._shapes;
|
|
833
|
+
for(var i = 0, n = shapes.length; i < n; i++){
|
|
834
|
+
this._removeColliderShape(shapes[i]._id);
|
|
835
|
+
}
|
|
780
836
|
};
|
|
781
837
|
/**
|
|
782
838
|
* {@inheritDoc IPhysicsManager.addCharacterController }
|
|
783
839
|
*/ _proto.addCharacterController = function addCharacterController(characterController) {
|
|
840
|
+
characterController._scene = this;
|
|
784
841
|
// Physx have no API to remove/readd cct into scene.
|
|
785
842
|
if (!characterController._pxController) {
|
|
786
843
|
var shape = characterController._shape;
|
|
@@ -790,6 +847,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
790
847
|
lastPXManager && characterController._destroyPXController();
|
|
791
848
|
characterController._createPXController(this, shape);
|
|
792
849
|
}
|
|
850
|
+
this._addColliderShape(shape._id);
|
|
793
851
|
}
|
|
794
852
|
}
|
|
795
853
|
characterController._pxManager = this;
|
|
@@ -797,7 +855,11 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
797
855
|
/**
|
|
798
856
|
* {@inheritDoc IPhysicsManager.removeCharacterController }
|
|
799
857
|
*/ _proto.removeCharacterController = function removeCharacterController(characterController) {
|
|
858
|
+
characterController._scene = null;
|
|
800
859
|
characterController._pxManager = null;
|
|
860
|
+
characterController._destroyPXController();
|
|
861
|
+
var shape = characterController._shape;
|
|
862
|
+
shape && this._removeColliderShape(shape._id);
|
|
801
863
|
};
|
|
802
864
|
/**
|
|
803
865
|
* {@inheritDoc IPhysicsManager.update }
|
|
@@ -840,6 +902,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
840
902
|
}
|
|
841
903
|
return pxControllerManager;
|
|
842
904
|
};
|
|
905
|
+
/**
|
|
906
|
+
* @internal
|
|
907
|
+
*/ _proto._addColliderShape = function _addColliderShape(id) {
|
|
908
|
+
this._physXManager._eventMap[id] = {};
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* @internal
|
|
912
|
+
*/ _proto._removeColliderShape = function _removeColliderShape(id) {
|
|
913
|
+
var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
|
|
914
|
+
var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
|
|
915
|
+
currentEvents.forEach(function(event, i) {
|
|
916
|
+
if (event.index1 == id) {
|
|
917
|
+
currentEvents.deleteByIndex(i);
|
|
918
|
+
eventPool.push(event);
|
|
919
|
+
} else if (event.index2 == id) {
|
|
920
|
+
currentEvents.deleteByIndex(i);
|
|
921
|
+
eventPool.push(event);
|
|
922
|
+
// If the shape is big index, should clear from the small index shape subMap
|
|
923
|
+
eventMap[event.index1][id] = undefined;
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
delete eventMap[id];
|
|
927
|
+
};
|
|
843
928
|
_proto._simulate = function _simulate(elapsedTime) {
|
|
844
929
|
this._pxScene.simulate(elapsedTime, true);
|
|
845
930
|
};
|
|
@@ -913,7 +998,6 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
|
|
|
913
998
|
* a base interface providing common functionality for PhysX joints
|
|
914
999
|
*/ var PhysXJoint = /*#__PURE__*/ function() {
|
|
915
1000
|
function PhysXJoint(physXPhysics) {
|
|
916
|
-
this._connectedAnchor = new engine.Vector3();
|
|
917
1001
|
this._breakForce = Number.MAX_VALUE;
|
|
918
1002
|
this._breakTorque = Number.MAX_VALUE;
|
|
919
1003
|
this._physXPhysics = physXPhysics;
|
|
@@ -923,33 +1007,37 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
|
|
|
923
1007
|
* {@inheritDoc IJoint.setConnectedCollider }
|
|
924
1008
|
*/ _proto.setConnectedCollider = function setConnectedCollider(value) {
|
|
925
1009
|
var _this__collider;
|
|
926
|
-
this._pxJoint.setActors((
|
|
1010
|
+
this._pxJoint.setActors(((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null, (value == null ? void 0 : value._pxActor) || null);
|
|
927
1011
|
};
|
|
928
1012
|
/**
|
|
929
1013
|
* {@inheritDoc IJoint.setConnectedAnchor }
|
|
930
|
-
*/ _proto.
|
|
931
|
-
this._connectedAnchor.copyFrom(value);
|
|
1014
|
+
*/ _proto.setAnchor = function setAnchor(value) {
|
|
932
1015
|
this._setLocalPose(0, value, PhysXJoint._defaultQuat);
|
|
933
1016
|
};
|
|
934
1017
|
/**
|
|
935
|
-
* {@inheritDoc IJoint.
|
|
936
|
-
*/ _proto.
|
|
937
|
-
this.
|
|
938
|
-
};
|
|
939
|
-
/**
|
|
940
|
-
* {@inheritDoc IJoint.setConnectedInertiaScale }
|
|
941
|
-
*/ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
|
|
942
|
-
this._pxJoint.setInvInertiaScale0(1 / value);
|
|
1018
|
+
* {@inheritDoc IJoint.setConnectedAnchor }
|
|
1019
|
+
*/ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
|
|
1020
|
+
this._setLocalPose(1, value, PhysXJoint._defaultQuat);
|
|
943
1021
|
};
|
|
944
1022
|
/**
|
|
945
1023
|
* {@inheritDoc IJoint.setMassScale }
|
|
946
1024
|
*/ _proto.setMassScale = function setMassScale(value) {
|
|
1025
|
+
this._pxJoint.setInvMassScale0(1 / value);
|
|
1026
|
+
};
|
|
1027
|
+
/**
|
|
1028
|
+
* {@inheritDoc IJoint.setConnectedMassScale }
|
|
1029
|
+
*/ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
|
|
947
1030
|
this._pxJoint.setInvMassScale1(1 / value);
|
|
948
1031
|
};
|
|
949
1032
|
/**
|
|
950
1033
|
* {@inheritDoc IJoint.setInertiaScale }
|
|
951
1034
|
*/ _proto.setInertiaScale = function setInertiaScale(value) {
|
|
952
|
-
this._pxJoint.
|
|
1035
|
+
this._pxJoint.setInvInertiaScale0(value);
|
|
1036
|
+
};
|
|
1037
|
+
/**
|
|
1038
|
+
* {@inheritDoc IJoint.setConnectedInertiaScale }
|
|
1039
|
+
*/ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
|
|
1040
|
+
this._pxJoint.setInvInertiaScale1(value);
|
|
953
1041
|
};
|
|
954
1042
|
/**
|
|
955
1043
|
* {@inheritDoc IJoint.setBreakForce }
|
|
@@ -964,6 +1052,14 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
|
|
|
964
1052
|
this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
|
|
965
1053
|
};
|
|
966
1054
|
/**
|
|
1055
|
+
* {@inheritDoc IJoint.destroy }
|
|
1056
|
+
*/ _proto.destroy = function destroy() {
|
|
1057
|
+
if (!this._pxJoint) return;
|
|
1058
|
+
this._pxJoint.release();
|
|
1059
|
+
this._pxJoint = null;
|
|
1060
|
+
this._collider = null;
|
|
1061
|
+
};
|
|
1062
|
+
/**
|
|
967
1063
|
* Set the joint local pose for an actor.
|
|
968
1064
|
* @param actor 0 for the first actor, 1 for the second actor.
|
|
969
1065
|
* @param position the local position for the actor this joint
|
|
@@ -973,7 +1069,6 @@ PhysXPhysicsScene._tempNormal = new engine.Vector3();
|
|
|
973
1069
|
};
|
|
974
1070
|
return PhysXJoint;
|
|
975
1071
|
}();
|
|
976
|
-
PhysXJoint._xAxis = new engine.Vector3(1, 0, 0);
|
|
977
1072
|
PhysXJoint._defaultVec = new engine.Vector3();
|
|
978
1073
|
PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
979
1074
|
|
|
@@ -985,7 +1080,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
985
1080
|
var _this;
|
|
986
1081
|
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
987
1082
|
_this._collider = collider;
|
|
988
|
-
_this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(
|
|
1083
|
+
_this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
989
1084
|
return _this;
|
|
990
1085
|
}
|
|
991
1086
|
return PhysXFixedJoint;
|
|
@@ -997,29 +1092,32 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
997
1092
|
_inherits(PhysXHingeJoint, PhysXJoint1);
|
|
998
1093
|
function PhysXHingeJoint(physXPhysics, collider) {
|
|
999
1094
|
var _this;
|
|
1000
|
-
_this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new engine.Quaternion()
|
|
1095
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new engine.Quaternion();
|
|
1001
1096
|
_this._collider = collider;
|
|
1002
|
-
_this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(
|
|
1097
|
+
_this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
1003
1098
|
return _this;
|
|
1004
1099
|
}
|
|
1005
1100
|
var _proto = PhysXHingeJoint.prototype;
|
|
1006
1101
|
/**
|
|
1007
1102
|
* {@inheritDoc IHingeJoint.setAxis }
|
|
1008
1103
|
*/ _proto.setAxis = function setAxis(value) {
|
|
1009
|
-
var xAxis =
|
|
1104
|
+
var xAxis = PhysXHingeJoint._xAxis;
|
|
1010
1105
|
var axisRotationQuaternion = this._axisRotationQuaternion;
|
|
1011
1106
|
xAxis.set(1, 0, 0);
|
|
1012
1107
|
value.normalize();
|
|
1013
1108
|
var angle = Math.acos(engine.Vector3.dot(xAxis, value));
|
|
1014
1109
|
engine.Vector3.cross(xAxis, value, xAxis);
|
|
1015
1110
|
engine.Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
|
|
1016
|
-
this._setLocalPose(0, this.
|
|
1111
|
+
this._setLocalPose(0, this._anchor, axisRotationQuaternion);
|
|
1112
|
+
this._setLocalPose(1, this._connectedAnchor, axisRotationQuaternion);
|
|
1017
1113
|
};
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1114
|
+
_proto.setAnchor = function setAnchor(value) {
|
|
1115
|
+
this._setLocalPose(0, value, this._axisRotationQuaternion);
|
|
1116
|
+
this._anchor = value;
|
|
1117
|
+
};
|
|
1118
|
+
_proto.setConnectedAnchor = function setConnectedAnchor(value) {
|
|
1119
|
+
this._setLocalPose(1, value, this._axisRotationQuaternion);
|
|
1120
|
+
this._connectedAnchor = value;
|
|
1023
1121
|
};
|
|
1024
1122
|
/**
|
|
1025
1123
|
* {@inheritDoc IHingeJoint.getAngle }
|
|
@@ -1064,6 +1162,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
1064
1162
|
};
|
|
1065
1163
|
return PhysXHingeJoint;
|
|
1066
1164
|
}(PhysXJoint);
|
|
1165
|
+
PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
|
|
1067
1166
|
|
|
1068
1167
|
/**
|
|
1069
1168
|
* a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
|
|
@@ -1071,7 +1170,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
1071
1170
|
_inherits(PhysXSpringJoint, PhysXJoint1);
|
|
1072
1171
|
function PhysXSpringJoint(physXPhysics, collider) {
|
|
1073
1172
|
var _this;
|
|
1074
|
-
_this = PhysXJoint1.call(this, physXPhysics) || this
|
|
1173
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
1075
1174
|
_this._collider = collider;
|
|
1076
1175
|
_this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
1077
1176
|
_this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
|
|
@@ -1081,12 +1180,6 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
1081
1180
|
}
|
|
1082
1181
|
var _proto = PhysXSpringJoint.prototype;
|
|
1083
1182
|
/**
|
|
1084
|
-
* {@inheritDoc ISpringJoint.setSwingOffset }
|
|
1085
|
-
*/ _proto.setSwingOffset = function setSwingOffset(value) {
|
|
1086
|
-
this._swingOffset.copyFrom(value);
|
|
1087
|
-
this._setLocalPose(1, value, PhysXJoint._defaultQuat);
|
|
1088
|
-
};
|
|
1089
|
-
/**
|
|
1090
1183
|
* {@inheritDoc ISpringJoint.setMinDistance }
|
|
1091
1184
|
*/ _proto.setMinDistance = function setMinDistance(distance) {
|
|
1092
1185
|
this._pxJoint.setMinDistance(distance);
|
|
@@ -1209,7 +1302,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
1209
1302
|
if (runtimeMode == PhysXRuntimeMode.JavaScript) {
|
|
1210
1303
|
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
|
|
1211
1304
|
} else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
|
|
1212
|
-
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1305
|
+
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rP-bRKBDf0YAAAAAAAAAAAAAARQnAQ/physx.release.js";
|
|
1213
1306
|
}
|
|
1214
1307
|
});
|
|
1215
1308
|
var initializePromise = new Promise(function(resolve, reject) {
|
|
@@ -1317,7 +1410,7 @@ PhysXJoint._defaultQuat = new engine.Quaternion();
|
|
|
1317
1410
|
}();
|
|
1318
1411
|
|
|
1319
1412
|
//@ts-ignore
|
|
1320
|
-
var version = "1.4.0-alpha.
|
|
1413
|
+
var version = "1.4.0-alpha.1";
|
|
1321
1414
|
console.log("Galacean PhysX version: " + version);
|
|
1322
1415
|
|
|
1323
1416
|
exports.PhysXPhysics = PhysXPhysics;
|