@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/module.js
CHANGED
|
@@ -37,6 +37,7 @@ function _inherits(subClass, superClass) {
|
|
|
37
37
|
*/ var PhysXColliderShape = /*#__PURE__*/ function() {
|
|
38
38
|
function PhysXColliderShape(physXPhysics) {
|
|
39
39
|
/** @internal */ this._controllers = new DisorderedArray();
|
|
40
|
+
/** @internal */ this._contractOffset = 0.02;
|
|
40
41
|
this._worldScale = new Vector3(1, 1, 1);
|
|
41
42
|
this._position = new Vector3();
|
|
42
43
|
this._rotation = null;
|
|
@@ -70,7 +71,7 @@ function _inherits(subClass, superClass) {
|
|
|
70
71
|
/**
|
|
71
72
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
72
73
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
73
|
-
this._worldScale.
|
|
74
|
+
this._worldScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
|
|
74
75
|
this._setLocalPose();
|
|
75
76
|
var controllers = this._controllers;
|
|
76
77
|
for(var i = 0, n = controllers.length; i < n; i++){
|
|
@@ -81,11 +82,15 @@ function _inherits(subClass, superClass) {
|
|
|
81
82
|
* {@inheritDoc IColliderShape.setContactOffset }
|
|
82
83
|
* @default 0.02f * PxTolerancesScale::length
|
|
83
84
|
*/ _proto.setContactOffset = function setContactOffset(offset) {
|
|
84
|
-
this.
|
|
85
|
+
this._contractOffset = offset;
|
|
85
86
|
var controllers = this._controllers;
|
|
86
|
-
|
|
87
|
-
var
|
|
88
|
-
|
|
87
|
+
if (controllers.length) {
|
|
88
|
+
for(var i = 0, n = controllers.length; i < n; i++){
|
|
89
|
+
var _controllers_get__pxController;
|
|
90
|
+
(_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
this._pxShape.setContactOffset(offset);
|
|
89
94
|
}
|
|
90
95
|
};
|
|
91
96
|
/**
|
|
@@ -141,7 +146,7 @@ PhysXColliderShape.transform = {
|
|
|
141
146
|
_inherits(PhysXBoxColliderShape, PhysXColliderShape);
|
|
142
147
|
function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
|
|
143
148
|
var _this;
|
|
144
|
-
_this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new Vector3()
|
|
149
|
+
_this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new Vector3();
|
|
145
150
|
var halfSize = _this._halfSize;
|
|
146
151
|
halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
|
|
147
152
|
_this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(halfSize.x, halfSize.y, halfSize.z);
|
|
@@ -156,7 +161,7 @@ PhysXColliderShape.transform = {
|
|
|
156
161
|
var halfSize = this._halfSize;
|
|
157
162
|
var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
|
|
158
163
|
halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
|
|
159
|
-
Vector3.multiply(halfSize, this.
|
|
164
|
+
Vector3.multiply(halfSize, this._worldScale, tempExtents);
|
|
160
165
|
this._pxGeometry.halfExtents = tempExtents;
|
|
161
166
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
162
167
|
this._updateController(tempExtents);
|
|
@@ -165,9 +170,8 @@ PhysXColliderShape.transform = {
|
|
|
165
170
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
166
171
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
167
172
|
PhysXColliderShape.prototype.setWorldScale.call(this, scale);
|
|
168
|
-
this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
|
|
169
173
|
var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
|
|
170
|
-
Vector3.multiply(this._halfSize, this.
|
|
174
|
+
Vector3.multiply(this._halfSize, this._worldScale, tempExtents);
|
|
171
175
|
this._pxGeometry.halfExtents = tempExtents;
|
|
172
176
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
173
177
|
this._updateController(tempExtents);
|
|
@@ -193,7 +197,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
193
197
|
_inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
|
|
194
198
|
function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
|
|
195
199
|
var _this;
|
|
196
|
-
_this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1
|
|
200
|
+
_this = PhysXColliderShape1.call(this, physXPhysics) || this, _this._upAxis = 1;
|
|
197
201
|
_this._radius = radius;
|
|
198
202
|
_this._halfHeight = height * 0.5;
|
|
199
203
|
_this._axis = new Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
|
|
@@ -208,7 +212,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
208
212
|
* {@inheritDoc ICapsuleColliderShape.setRadius }
|
|
209
213
|
*/ _proto.setRadius = function setRadius(value) {
|
|
210
214
|
this._radius = value;
|
|
211
|
-
var sizeScale = this.
|
|
215
|
+
var sizeScale = this._worldScale;
|
|
212
216
|
switch(this._upAxis){
|
|
213
217
|
case 0:
|
|
214
218
|
this._pxGeometry.radius = this._radius * Math.max(sizeScale.y, sizeScale.z);
|
|
@@ -232,7 +236,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
232
236
|
* {@inheritDoc ICapsuleColliderShape.setHeight }
|
|
233
237
|
*/ _proto.setHeight = function setHeight(value) {
|
|
234
238
|
this._halfHeight = value * 0.5;
|
|
235
|
-
var sizeScale = this.
|
|
239
|
+
var sizeScale = this._worldScale;
|
|
236
240
|
switch(this._upAxis){
|
|
237
241
|
case 0:
|
|
238
242
|
this._pxGeometry.halfHeight = this._halfHeight * sizeScale.x;
|
|
@@ -280,7 +284,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
280
284
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
281
285
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
282
286
|
PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
|
|
283
|
-
var sizeScale = this.
|
|
287
|
+
var sizeScale = this._worldScale;
|
|
284
288
|
var geometry = this._pxGeometry;
|
|
285
289
|
switch(this._upAxis){
|
|
286
290
|
case 0:
|
|
@@ -315,6 +319,7 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
315
319
|
* Base class for character controllers.
|
|
316
320
|
*/ var PhysXCharacterController = /*#__PURE__*/ function() {
|
|
317
321
|
function PhysXCharacterController(physXPhysics) {
|
|
322
|
+
/** @internal */ this._scene = null;
|
|
318
323
|
this._shapeScaledPosition = new Vector3();
|
|
319
324
|
this._worldPosition = null;
|
|
320
325
|
this._physXPhysics = physXPhysics;
|
|
@@ -368,17 +373,22 @@ PhysXBoxColliderShape._tempHalfExtents = new Vector3();
|
|
|
368
373
|
/**
|
|
369
374
|
* {@inheritDoc ICharacterController.addShape }
|
|
370
375
|
*/ _proto.addShape = function addShape(shape) {
|
|
376
|
+
var _this__pxController, _this__scene;
|
|
371
377
|
// When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
|
|
372
378
|
this._pxManager && this._createPXController(this._pxManager, shape);
|
|
373
379
|
this._shape = shape;
|
|
374
380
|
shape._controllers.add(this);
|
|
381
|
+
(_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape._contractOffset);
|
|
382
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
|
|
375
383
|
};
|
|
376
384
|
/**
|
|
377
385
|
* {@inheritDoc ICharacterController.removeShape }
|
|
378
386
|
*/ _proto.removeShape = function removeShape(shape) {
|
|
387
|
+
var _this__scene;
|
|
379
388
|
this._destroyPXController();
|
|
380
389
|
this._shape = null;
|
|
381
390
|
shape._controllers.delete(this);
|
|
391
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
|
|
382
392
|
};
|
|
383
393
|
/**
|
|
384
394
|
* {@inheritDoc ICharacterController.destroy }
|
|
@@ -435,18 +445,27 @@ PhysXCharacterController._tempVec = new Vector3();
|
|
|
435
445
|
* Abstract class of physical collider.
|
|
436
446
|
*/ var PhysXCollider = /*#__PURE__*/ function() {
|
|
437
447
|
function PhysXCollider(physXPhysics) {
|
|
448
|
+
/** @internal */ this._scene = null;
|
|
449
|
+
/** @internal */ this._shapes = new Array();
|
|
438
450
|
this._physXPhysics = physXPhysics;
|
|
439
451
|
}
|
|
440
452
|
var _proto = PhysXCollider.prototype;
|
|
441
453
|
/**
|
|
442
454
|
* {@inheritDoc ICollider.addShape }
|
|
443
455
|
*/ _proto.addShape = function addShape(shape) {
|
|
456
|
+
var _this__scene;
|
|
444
457
|
this._pxActor.attachShape(shape._pxShape);
|
|
458
|
+
this._shapes.push(shape);
|
|
459
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
|
|
445
460
|
};
|
|
446
461
|
/**
|
|
447
462
|
* {@inheritDoc ICollider.removeShape }
|
|
448
463
|
*/ _proto.removeShape = function removeShape(shape) {
|
|
464
|
+
var _this__scene;
|
|
449
465
|
this._pxActor.detachShape(shape._pxShape, true);
|
|
466
|
+
var shapes = this._shapes;
|
|
467
|
+
shapes.splice(shapes.indexOf(shape), 1);
|
|
468
|
+
(_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
|
|
450
469
|
};
|
|
451
470
|
/**
|
|
452
471
|
* {@inheritDoc ICollider.setWorldTransform }
|
|
@@ -493,21 +512,43 @@ PhysXCollider._tempTransform = {
|
|
|
493
512
|
}
|
|
494
513
|
var _proto = PhysXDynamicCollider.prototype;
|
|
495
514
|
/**
|
|
515
|
+
* {@inheritDoc IDynamicCollider.getLinearDamping }
|
|
516
|
+
*/ _proto.getLinearDamping = function getLinearDamping() {
|
|
517
|
+
return this._pxActor.getLinearDamping();
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
496
520
|
* {@inheritDoc IDynamicCollider.setLinearDamping }
|
|
497
521
|
*/ _proto.setLinearDamping = function setLinearDamping(value) {
|
|
498
522
|
this._pxActor.setLinearDamping(value);
|
|
499
523
|
};
|
|
500
524
|
/**
|
|
525
|
+
* {@inheritDoc IDynamicCollider.getAngularDamping }
|
|
526
|
+
*/ _proto.getAngularDamping = function getAngularDamping() {
|
|
527
|
+
return this._pxActor.getAngularDamping();
|
|
528
|
+
};
|
|
529
|
+
/**
|
|
501
530
|
* {@inheritDoc IDynamicCollider.setAngularDamping }
|
|
502
531
|
*/ _proto.setAngularDamping = function setAngularDamping(value) {
|
|
503
532
|
this._pxActor.setAngularDamping(value);
|
|
504
533
|
};
|
|
505
534
|
/**
|
|
535
|
+
* {@inheritDoc IDynamicCollider.getLinearVelocity }
|
|
536
|
+
*/ _proto.getLinearVelocity = function getLinearVelocity(out) {
|
|
537
|
+
var velocity = this._pxActor.getLinearVelocity();
|
|
538
|
+
return out.set(velocity.x, velocity.y, velocity.z);
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
506
541
|
* {@inheritDoc IDynamicCollider.setLinearVelocity }
|
|
507
542
|
*/ _proto.setLinearVelocity = function setLinearVelocity(value) {
|
|
508
543
|
this._pxActor.setLinearVelocity(value, true);
|
|
509
544
|
};
|
|
510
545
|
/**
|
|
546
|
+
* {@inheritDoc IDynamicCollider.getAngularVelocity }
|
|
547
|
+
*/ _proto.getAngularVelocity = function getAngularVelocity(out) {
|
|
548
|
+
var velocity = this._pxActor.getAngularVelocity();
|
|
549
|
+
return out.set(velocity.x, velocity.y, velocity.z);
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
511
552
|
* {@inheritDoc IDynamicCollider.setAngularVelocity }
|
|
512
553
|
*/ _proto.setAngularVelocity = function setAngularVelocity(value) {
|
|
513
554
|
this._pxActor.setAngularVelocity(value, true);
|
|
@@ -518,6 +559,12 @@ PhysXCollider._tempTransform = {
|
|
|
518
559
|
this._pxActor.setMass(value);
|
|
519
560
|
};
|
|
520
561
|
/**
|
|
562
|
+
* {@inheritDoc IDynamicCollider.getCenterOfMass }
|
|
563
|
+
*/ _proto.getCenterOfMass = function getCenterOfMass(out) {
|
|
564
|
+
var translation = this._pxActor.getCMassLocalPose().translation;
|
|
565
|
+
return out.set(translation.x, translation.y, translation.z);
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
521
568
|
* {@inheritDoc IDynamicCollider.setCenterOfMass }
|
|
522
569
|
*/ _proto.setCenterOfMass = function setCenterOfMass(position) {
|
|
523
570
|
this._pxActor.setCMassLocalPose(position);
|
|
@@ -528,11 +575,27 @@ PhysXCollider._tempTransform = {
|
|
|
528
575
|
this._pxActor.setMassSpaceInertiaTensor(value);
|
|
529
576
|
};
|
|
530
577
|
/**
|
|
578
|
+
* {@inheritDoc IDynamicCollider.getInertiaTensor }
|
|
579
|
+
*/ _proto.getInertiaTensor = function getInertiaTensor(out) {
|
|
580
|
+
var inertia = this._pxActor.getMassSpaceInertiaTensor();
|
|
581
|
+
return out.set(inertia.x, inertia.y, inertia.z);
|
|
582
|
+
};
|
|
583
|
+
/**
|
|
584
|
+
* {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
|
|
585
|
+
*/ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
|
|
586
|
+
this._pxActor.setMassAndUpdateInertia(mass);
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
531
589
|
* {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
|
|
532
590
|
*/ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
|
|
533
591
|
this._pxActor.setMaxAngularVelocity(value);
|
|
534
592
|
};
|
|
535
593
|
/**
|
|
594
|
+
* {@inheritDoc IDynamicCollider.getMaxDepenetrationVelocity }
|
|
595
|
+
*/ _proto.getMaxDepenetrationVelocity = function getMaxDepenetrationVelocity() {
|
|
596
|
+
return this._pxActor.getMaxDepenetrationVelocity();
|
|
597
|
+
};
|
|
598
|
+
/**
|
|
536
599
|
* {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
|
|
537
600
|
*/ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
|
|
538
601
|
this._pxActor.setMaxDepenetrationVelocity(value);
|
|
@@ -551,18 +614,20 @@ PhysXCollider._tempTransform = {
|
|
|
551
614
|
/**
|
|
552
615
|
* {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
|
|
553
616
|
*/ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
|
|
617
|
+
var physX = this._physXPhysics._physX;
|
|
554
618
|
switch(value){
|
|
555
619
|
case 1:
|
|
556
|
-
this._pxActor.setRigidBodyFlag(
|
|
620
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
|
|
557
621
|
break;
|
|
558
622
|
case 2:
|
|
559
|
-
this._pxActor.setRigidBodyFlag(
|
|
623
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
624
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
|
|
560
625
|
break;
|
|
561
626
|
case 3:
|
|
562
|
-
this._pxActor.setRigidBodyFlag(
|
|
627
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
628
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
|
|
563
629
|
break;
|
|
564
630
|
case 0:
|
|
565
|
-
var physX = this._physXPhysics._physX;
|
|
566
631
|
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
567
632
|
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
568
633
|
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
@@ -623,6 +688,11 @@ PhysXCollider._tempTransform = {
|
|
|
623
688
|
return this._pxActor.putToSleep();
|
|
624
689
|
};
|
|
625
690
|
/**
|
|
691
|
+
* {@inheritDoc IDynamicCollider.isSleeping }
|
|
692
|
+
*/ _proto.isSleeping = function isSleeping() {
|
|
693
|
+
return this._pxActor.isSleeping();
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
626
696
|
* {@inheritDoc IDynamicCollider.wakeUp }
|
|
627
697
|
*/ _proto.wakeUp = function wakeUp() {
|
|
628
698
|
return this._pxActor.wakeUp();
|
|
@@ -741,42 +811,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
741
811
|
this._pxScene.setGravity(value);
|
|
742
812
|
};
|
|
743
813
|
/**
|
|
744
|
-
* {@inheritDoc IPhysicsManager.addColliderShape }
|
|
745
|
-
*/ _proto.addColliderShape = function addColliderShape(colliderShape) {
|
|
746
|
-
this._physXManager._eventMap[colliderShape._id] = {};
|
|
747
|
-
};
|
|
748
|
-
/**
|
|
749
|
-
* {@inheritDoc IPhysicsManager.removeColliderShape }
|
|
750
|
-
*/ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
|
|
751
|
-
var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
|
|
752
|
-
var id = colliderShape._id;
|
|
753
|
-
var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
|
|
754
|
-
currentEvents.forEach(function(event, i) {
|
|
755
|
-
if (event.index1 == id) {
|
|
756
|
-
currentEvents.deleteByIndex(i);
|
|
757
|
-
eventPool.push(event);
|
|
758
|
-
} else if (event.index2 == id) {
|
|
759
|
-
currentEvents.deleteByIndex(i);
|
|
760
|
-
eventPool.push(event);
|
|
761
|
-
// If the shape is big index, should clear from the small index shape subMap
|
|
762
|
-
eventMap[event.index1][id] = undefined;
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
delete eventMap[id];
|
|
766
|
-
};
|
|
767
|
-
/**
|
|
768
814
|
* {@inheritDoc IPhysicsManager.addCollider }
|
|
769
815
|
*/ _proto.addCollider = function addCollider(collider) {
|
|
816
|
+
collider._scene = this;
|
|
770
817
|
this._pxScene.addActor(collider._pxActor, null);
|
|
818
|
+
var shapes = collider._shapes;
|
|
819
|
+
for(var i = 0, n = shapes.length; i < n; i++){
|
|
820
|
+
this._addColliderShape(shapes[i]._id);
|
|
821
|
+
}
|
|
771
822
|
};
|
|
772
823
|
/**
|
|
773
824
|
* {@inheritDoc IPhysicsManager.removeCollider }
|
|
774
825
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
826
|
+
collider._scene = null;
|
|
775
827
|
this._pxScene.removeActor(collider._pxActor, true);
|
|
828
|
+
var shapes = collider._shapes;
|
|
829
|
+
for(var i = 0, n = shapes.length; i < n; i++){
|
|
830
|
+
this._removeColliderShape(shapes[i]._id);
|
|
831
|
+
}
|
|
776
832
|
};
|
|
777
833
|
/**
|
|
778
834
|
* {@inheritDoc IPhysicsManager.addCharacterController }
|
|
779
835
|
*/ _proto.addCharacterController = function addCharacterController(characterController) {
|
|
836
|
+
characterController._scene = this;
|
|
780
837
|
// Physx have no API to remove/readd cct into scene.
|
|
781
838
|
if (!characterController._pxController) {
|
|
782
839
|
var shape = characterController._shape;
|
|
@@ -786,6 +843,7 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
786
843
|
lastPXManager && characterController._destroyPXController();
|
|
787
844
|
characterController._createPXController(this, shape);
|
|
788
845
|
}
|
|
846
|
+
this._addColliderShape(shape._id);
|
|
789
847
|
}
|
|
790
848
|
}
|
|
791
849
|
characterController._pxManager = this;
|
|
@@ -793,7 +851,11 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
793
851
|
/**
|
|
794
852
|
* {@inheritDoc IPhysicsManager.removeCharacterController }
|
|
795
853
|
*/ _proto.removeCharacterController = function removeCharacterController(characterController) {
|
|
854
|
+
characterController._scene = null;
|
|
796
855
|
characterController._pxManager = null;
|
|
856
|
+
characterController._destroyPXController();
|
|
857
|
+
var shape = characterController._shape;
|
|
858
|
+
shape && this._removeColliderShape(shape._id);
|
|
797
859
|
};
|
|
798
860
|
/**
|
|
799
861
|
* {@inheritDoc IPhysicsManager.update }
|
|
@@ -836,6 +898,29 @@ var PhysXPhysicsManager = function PhysXPhysicsManager() {
|
|
|
836
898
|
}
|
|
837
899
|
return pxControllerManager;
|
|
838
900
|
};
|
|
901
|
+
/**
|
|
902
|
+
* @internal
|
|
903
|
+
*/ _proto._addColliderShape = function _addColliderShape(id) {
|
|
904
|
+
this._physXManager._eventMap[id] = {};
|
|
905
|
+
};
|
|
906
|
+
/**
|
|
907
|
+
* @internal
|
|
908
|
+
*/ _proto._removeColliderShape = function _removeColliderShape(id) {
|
|
909
|
+
var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
|
|
910
|
+
var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
|
|
911
|
+
currentEvents.forEach(function(event, i) {
|
|
912
|
+
if (event.index1 == id) {
|
|
913
|
+
currentEvents.deleteByIndex(i);
|
|
914
|
+
eventPool.push(event);
|
|
915
|
+
} else if (event.index2 == id) {
|
|
916
|
+
currentEvents.deleteByIndex(i);
|
|
917
|
+
eventPool.push(event);
|
|
918
|
+
// If the shape is big index, should clear from the small index shape subMap
|
|
919
|
+
eventMap[event.index1][id] = undefined;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
delete eventMap[id];
|
|
923
|
+
};
|
|
839
924
|
_proto._simulate = function _simulate(elapsedTime) {
|
|
840
925
|
this._pxScene.simulate(elapsedTime, true);
|
|
841
926
|
};
|
|
@@ -909,7 +994,6 @@ PhysXPhysicsScene._tempNormal = new Vector3();
|
|
|
909
994
|
* a base interface providing common functionality for PhysX joints
|
|
910
995
|
*/ var PhysXJoint = /*#__PURE__*/ function() {
|
|
911
996
|
function PhysXJoint(physXPhysics) {
|
|
912
|
-
this._connectedAnchor = new Vector3();
|
|
913
997
|
this._breakForce = Number.MAX_VALUE;
|
|
914
998
|
this._breakTorque = Number.MAX_VALUE;
|
|
915
999
|
this._physXPhysics = physXPhysics;
|
|
@@ -919,33 +1003,37 @@ PhysXPhysicsScene._tempNormal = new Vector3();
|
|
|
919
1003
|
* {@inheritDoc IJoint.setConnectedCollider }
|
|
920
1004
|
*/ _proto.setConnectedCollider = function setConnectedCollider(value) {
|
|
921
1005
|
var _this__collider;
|
|
922
|
-
this._pxJoint.setActors((
|
|
1006
|
+
this._pxJoint.setActors(((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null, (value == null ? void 0 : value._pxActor) || null);
|
|
923
1007
|
};
|
|
924
1008
|
/**
|
|
925
1009
|
* {@inheritDoc IJoint.setConnectedAnchor }
|
|
926
|
-
*/ _proto.
|
|
927
|
-
this._connectedAnchor.copyFrom(value);
|
|
1010
|
+
*/ _proto.setAnchor = function setAnchor(value) {
|
|
928
1011
|
this._setLocalPose(0, value, PhysXJoint._defaultQuat);
|
|
929
1012
|
};
|
|
930
1013
|
/**
|
|
931
|
-
* {@inheritDoc IJoint.
|
|
932
|
-
*/ _proto.
|
|
933
|
-
this.
|
|
934
|
-
};
|
|
935
|
-
/**
|
|
936
|
-
* {@inheritDoc IJoint.setConnectedInertiaScale }
|
|
937
|
-
*/ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
|
|
938
|
-
this._pxJoint.setInvInertiaScale0(1 / value);
|
|
1014
|
+
* {@inheritDoc IJoint.setConnectedAnchor }
|
|
1015
|
+
*/ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
|
|
1016
|
+
this._setLocalPose(1, value, PhysXJoint._defaultQuat);
|
|
939
1017
|
};
|
|
940
1018
|
/**
|
|
941
1019
|
* {@inheritDoc IJoint.setMassScale }
|
|
942
1020
|
*/ _proto.setMassScale = function setMassScale(value) {
|
|
1021
|
+
this._pxJoint.setInvMassScale0(1 / value);
|
|
1022
|
+
};
|
|
1023
|
+
/**
|
|
1024
|
+
* {@inheritDoc IJoint.setConnectedMassScale }
|
|
1025
|
+
*/ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
|
|
943
1026
|
this._pxJoint.setInvMassScale1(1 / value);
|
|
944
1027
|
};
|
|
945
1028
|
/**
|
|
946
1029
|
* {@inheritDoc IJoint.setInertiaScale }
|
|
947
1030
|
*/ _proto.setInertiaScale = function setInertiaScale(value) {
|
|
948
|
-
this._pxJoint.
|
|
1031
|
+
this._pxJoint.setInvInertiaScale0(value);
|
|
1032
|
+
};
|
|
1033
|
+
/**
|
|
1034
|
+
* {@inheritDoc IJoint.setConnectedInertiaScale }
|
|
1035
|
+
*/ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
|
|
1036
|
+
this._pxJoint.setInvInertiaScale1(value);
|
|
949
1037
|
};
|
|
950
1038
|
/**
|
|
951
1039
|
* {@inheritDoc IJoint.setBreakForce }
|
|
@@ -960,6 +1048,14 @@ PhysXPhysicsScene._tempNormal = new Vector3();
|
|
|
960
1048
|
this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
|
|
961
1049
|
};
|
|
962
1050
|
/**
|
|
1051
|
+
* {@inheritDoc IJoint.destroy }
|
|
1052
|
+
*/ _proto.destroy = function destroy() {
|
|
1053
|
+
if (!this._pxJoint) return;
|
|
1054
|
+
this._pxJoint.release();
|
|
1055
|
+
this._pxJoint = null;
|
|
1056
|
+
this._collider = null;
|
|
1057
|
+
};
|
|
1058
|
+
/**
|
|
963
1059
|
* Set the joint local pose for an actor.
|
|
964
1060
|
* @param actor 0 for the first actor, 1 for the second actor.
|
|
965
1061
|
* @param position the local position for the actor this joint
|
|
@@ -969,7 +1065,6 @@ PhysXPhysicsScene._tempNormal = new Vector3();
|
|
|
969
1065
|
};
|
|
970
1066
|
return PhysXJoint;
|
|
971
1067
|
}();
|
|
972
|
-
PhysXJoint._xAxis = new Vector3(1, 0, 0);
|
|
973
1068
|
PhysXJoint._defaultVec = new Vector3();
|
|
974
1069
|
PhysXJoint._defaultQuat = new Quaternion();
|
|
975
1070
|
|
|
@@ -981,7 +1076,7 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
981
1076
|
var _this;
|
|
982
1077
|
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
983
1078
|
_this._collider = collider;
|
|
984
|
-
_this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(
|
|
1079
|
+
_this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
985
1080
|
return _this;
|
|
986
1081
|
}
|
|
987
1082
|
return PhysXFixedJoint;
|
|
@@ -993,29 +1088,32 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
993
1088
|
_inherits(PhysXHingeJoint, PhysXJoint1);
|
|
994
1089
|
function PhysXHingeJoint(physXPhysics, collider) {
|
|
995
1090
|
var _this;
|
|
996
|
-
_this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new Quaternion()
|
|
1091
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new Quaternion();
|
|
997
1092
|
_this._collider = collider;
|
|
998
|
-
_this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(
|
|
1093
|
+
_this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
999
1094
|
return _this;
|
|
1000
1095
|
}
|
|
1001
1096
|
var _proto = PhysXHingeJoint.prototype;
|
|
1002
1097
|
/**
|
|
1003
1098
|
* {@inheritDoc IHingeJoint.setAxis }
|
|
1004
1099
|
*/ _proto.setAxis = function setAxis(value) {
|
|
1005
|
-
var xAxis =
|
|
1100
|
+
var xAxis = PhysXHingeJoint._xAxis;
|
|
1006
1101
|
var axisRotationQuaternion = this._axisRotationQuaternion;
|
|
1007
1102
|
xAxis.set(1, 0, 0);
|
|
1008
1103
|
value.normalize();
|
|
1009
1104
|
var angle = Math.acos(Vector3.dot(xAxis, value));
|
|
1010
1105
|
Vector3.cross(xAxis, value, xAxis);
|
|
1011
1106
|
Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
|
|
1012
|
-
this._setLocalPose(0, this.
|
|
1107
|
+
this._setLocalPose(0, this._anchor, axisRotationQuaternion);
|
|
1108
|
+
this._setLocalPose(1, this._connectedAnchor, axisRotationQuaternion);
|
|
1013
1109
|
};
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1110
|
+
_proto.setAnchor = function setAnchor(value) {
|
|
1111
|
+
this._setLocalPose(0, value, this._axisRotationQuaternion);
|
|
1112
|
+
this._anchor = value;
|
|
1113
|
+
};
|
|
1114
|
+
_proto.setConnectedAnchor = function setConnectedAnchor(value) {
|
|
1115
|
+
this._setLocalPose(1, value, this._axisRotationQuaternion);
|
|
1116
|
+
this._connectedAnchor = value;
|
|
1019
1117
|
};
|
|
1020
1118
|
/**
|
|
1021
1119
|
* {@inheritDoc IHingeJoint.getAngle }
|
|
@@ -1060,6 +1158,7 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
1060
1158
|
};
|
|
1061
1159
|
return PhysXHingeJoint;
|
|
1062
1160
|
}(PhysXJoint);
|
|
1161
|
+
PhysXHingeJoint._xAxis = new Vector3(1, 0, 0);
|
|
1063
1162
|
|
|
1064
1163
|
/**
|
|
1065
1164
|
* a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
|
|
@@ -1067,7 +1166,7 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
1067
1166
|
_inherits(PhysXSpringJoint, PhysXJoint1);
|
|
1068
1167
|
function PhysXSpringJoint(physXPhysics, collider) {
|
|
1069
1168
|
var _this;
|
|
1070
|
-
_this = PhysXJoint1.call(this, physXPhysics) || this
|
|
1169
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
1071
1170
|
_this._collider = collider;
|
|
1072
1171
|
_this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
1073
1172
|
_this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
|
|
@@ -1077,12 +1176,6 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
1077
1176
|
}
|
|
1078
1177
|
var _proto = PhysXSpringJoint.prototype;
|
|
1079
1178
|
/**
|
|
1080
|
-
* {@inheritDoc ISpringJoint.setSwingOffset }
|
|
1081
|
-
*/ _proto.setSwingOffset = function setSwingOffset(value) {
|
|
1082
|
-
this._swingOffset.copyFrom(value);
|
|
1083
|
-
this._setLocalPose(1, value, PhysXJoint._defaultQuat);
|
|
1084
|
-
};
|
|
1085
|
-
/**
|
|
1086
1179
|
* {@inheritDoc ISpringJoint.setMinDistance }
|
|
1087
1180
|
*/ _proto.setMinDistance = function setMinDistance(distance) {
|
|
1088
1181
|
this._pxJoint.setMinDistance(distance);
|
|
@@ -1205,7 +1298,7 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
1205
1298
|
if (runtimeMode == PhysXRuntimeMode.JavaScript) {
|
|
1206
1299
|
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rnDeR58NNGoAAAAAAAAAAAAAARQnAQ/physx.release.js.js";
|
|
1207
1300
|
} else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
|
|
1208
|
-
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*
|
|
1301
|
+
script.src = "https://mdn.alipayobjects.com/rms/afts/file/A*rP-bRKBDf0YAAAAAAAAAAAAAARQnAQ/physx.release.js";
|
|
1209
1302
|
}
|
|
1210
1303
|
});
|
|
1211
1304
|
var initializePromise = new Promise(function(resolve, reject) {
|
|
@@ -1313,7 +1406,7 @@ PhysXJoint._defaultQuat = new Quaternion();
|
|
|
1313
1406
|
}();
|
|
1314
1407
|
|
|
1315
1408
|
//@ts-ignore
|
|
1316
|
-
var version = "1.4.0-alpha.
|
|
1409
|
+
var version = "1.4.0-alpha.1";
|
|
1317
1410
|
console.log("Galacean PhysX version: " + version);
|
|
1318
1411
|
|
|
1319
1412
|
export { PhysXPhysics, PhysXRuntimeMode, version };
|