@galacean/engine-physics-lite 1.4.0-alpha.1 → 1.4.0-alpha.2
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 +103 -31
- 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 +103 -31
- package/dist/main.js.map +1 -1
- package/dist/module.js +104 -32
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/LiteDynamicCollider.d.ts +4 -0
- package/types/LitePhysics.d.ts +2 -2
- package/types/LitePhysicsScene.d.ts +2 -2
- package/types/shape/LiteBoxColliderShape.d.ts +7 -1
- package/types/shape/LiteColliderShape.d.ts +11 -2
- package/types/shape/LiteSphereColliderShape.d.ts +5 -1
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Utils,
|
|
1
|
+
import { Utils, Vector3, Quaternion, Vector4, Ray, MathUtil, Matrix, Logger, BoundingBox, BoundingSphere, DisorderedArray, CollisionUtil } from '@galacean/engine';
|
|
2
2
|
|
|
3
3
|
function _set_prototype_of(o, p) {
|
|
4
4
|
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
@@ -90,6 +90,7 @@ function _instanceof(left, right) {
|
|
|
90
90
|
/** @internal */ this._worldScale = new Vector3(1, 1, 1);
|
|
91
91
|
/** @internal */ this._transform = new LiteTransform();
|
|
92
92
|
/** @internal */ this._invModelMatrix = new Matrix();
|
|
93
|
+
this._rotation = new Vector3();
|
|
93
94
|
this._transform.owner = this;
|
|
94
95
|
this._inverseWorldMatFlag = this._transform.registerWorldChangeFlag();
|
|
95
96
|
}
|
|
@@ -97,7 +98,8 @@ function _instanceof(left, right) {
|
|
|
97
98
|
/**
|
|
98
99
|
* {@inheritDoc IColliderShape.setRotation }
|
|
99
100
|
*/ _proto.setRotation = function setRotation(rotation) {
|
|
100
|
-
|
|
101
|
+
var rotationInRadians = this._rotation.set(MathUtil.degreeToRadian(rotation.x), MathUtil.degreeToRadian(rotation.y), MathUtil.degreeToRadian(rotation.z));
|
|
102
|
+
Quaternion.rotationEuler(rotationInRadians.x, rotationInRadians.y, rotationInRadians.z, this._transform.rotationQuaternion);
|
|
101
103
|
};
|
|
102
104
|
/**
|
|
103
105
|
* {@inheritDoc IColliderShape.setPosition }
|
|
@@ -172,8 +174,12 @@ function _instanceof(left, right) {
|
|
|
172
174
|
};
|
|
173
175
|
return LiteColliderShape;
|
|
174
176
|
}();
|
|
175
|
-
LiteColliderShape.
|
|
177
|
+
LiteColliderShape._tempPos = new Vector3();
|
|
178
|
+
LiteColliderShape._tempRot = new Quaternion();
|
|
179
|
+
LiteColliderShape._tempScale = new Vector3();
|
|
176
180
|
LiteColliderShape._tempPoint = new Vector3();
|
|
181
|
+
LiteColliderShape._tempVector4 = new Vector4();
|
|
182
|
+
LiteColliderShape._ray = new Ray();
|
|
177
183
|
|
|
178
184
|
/**
|
|
179
185
|
* Used to implement transformation related functions.
|
|
@@ -547,19 +553,19 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
547
553
|
/**
|
|
548
554
|
* {@inheritDoc IDynamicCollider.getInertiaTensor }
|
|
549
555
|
*/ _proto.getInertiaTensor = function getInertiaTensor(out) {
|
|
550
|
-
|
|
556
|
+
Logger.error("Physics-lite don't support getInertiaTensor. Use Physics-PhysX instead!");
|
|
551
557
|
return out;
|
|
552
558
|
};
|
|
553
559
|
/**
|
|
554
560
|
* {@inheritDoc IDynamicCollider.getCenterOfMass }
|
|
555
561
|
*/ _proto.getCenterOfMass = function getCenterOfMass(out) {
|
|
556
|
-
|
|
562
|
+
Logger.error("Physics-lite don't support getCenterOfMass. Use Physics-PhysX instead!");
|
|
557
563
|
return out;
|
|
558
564
|
};
|
|
559
565
|
/**
|
|
560
566
|
* {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
|
|
561
567
|
*/ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
|
|
562
|
-
|
|
568
|
+
Logger.error("Physics-lite don't support setMassAndUpdateInertia. Use Physics-PhysX instead!");
|
|
563
569
|
};
|
|
564
570
|
/**
|
|
565
571
|
* {@inheritDoc IDynamicCollider.addForce }
|
|
@@ -594,43 +600,48 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
594
600
|
/**
|
|
595
601
|
* {@inheritDoc IDynamicCollider.setAngularDamping }
|
|
596
602
|
*/ _proto.setAngularDamping = function setAngularDamping(value) {
|
|
597
|
-
|
|
603
|
+
Logger.error("Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!");
|
|
598
604
|
};
|
|
599
605
|
/**
|
|
600
606
|
* {@inheritDoc IDynamicCollider.getAngularVelocity }
|
|
601
607
|
*/ _proto.getAngularVelocity = function getAngularVelocity(out) {
|
|
602
|
-
|
|
608
|
+
Logger.error("Physics-lite don't support getAngularVelocity. Use Physics-PhysX instead!");
|
|
603
609
|
return out;
|
|
604
610
|
};
|
|
605
611
|
/**
|
|
606
612
|
* {@inheritDoc IDynamicCollider.setAngularVelocity }
|
|
607
613
|
*/ _proto.setAngularVelocity = function setAngularVelocity(value) {
|
|
608
|
-
|
|
614
|
+
Logger.error("Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!");
|
|
609
615
|
};
|
|
610
616
|
/**
|
|
611
617
|
* {@inheritDoc IDynamicCollider.setCenterOfMass }
|
|
612
618
|
*/ _proto.setCenterOfMass = function setCenterOfMass(value) {
|
|
613
|
-
|
|
619
|
+
Logger.error("Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!");
|
|
614
620
|
};
|
|
615
621
|
/**
|
|
616
622
|
* {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
|
|
617
623
|
*/ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
|
|
618
|
-
|
|
624
|
+
Logger.error("Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!");
|
|
619
625
|
};
|
|
620
626
|
/**
|
|
621
627
|
* {@inheritDoc IDynamicCollider.setConstraints }
|
|
622
628
|
*/ _proto.setConstraints = function setConstraints(flags) {
|
|
623
|
-
|
|
629
|
+
Logger.error("Physics-lite don't support setConstraints. Use Physics-PhysX instead!");
|
|
624
630
|
};
|
|
625
631
|
/**
|
|
626
632
|
* {@inheritDoc IDynamicCollider.setInertiaTensor }
|
|
627
633
|
*/ _proto.setInertiaTensor = function setInertiaTensor(value) {
|
|
628
|
-
|
|
634
|
+
Logger.error("Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!");
|
|
635
|
+
};
|
|
636
|
+
/**
|
|
637
|
+
* {@inheritDoc IDynamicCollider.setUseGravity }
|
|
638
|
+
*/ _proto.setUseGravity = function setUseGravity(value) {
|
|
639
|
+
throw "Physics-lite don't support setUseGravity. Use Physics-PhysX instead!";
|
|
629
640
|
};
|
|
630
641
|
/**
|
|
631
642
|
* {@inheritDoc IDynamicCollider.setIsKinematic }
|
|
632
643
|
*/ _proto.setIsKinematic = function setIsKinematic(value) {
|
|
633
|
-
|
|
644
|
+
Logger.error("Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!");
|
|
634
645
|
};
|
|
635
646
|
/**
|
|
636
647
|
* {@inheritDoc IDynamicCollider.setLinearDamping }
|
|
@@ -640,28 +651,28 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
640
651
|
/**
|
|
641
652
|
* {@inheritDoc IDynamicCollider.setLinearDamping }
|
|
642
653
|
*/ _proto.setLinearDamping = function setLinearDamping(value) {
|
|
643
|
-
|
|
654
|
+
Logger.error("Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!");
|
|
644
655
|
};
|
|
645
656
|
/**
|
|
646
657
|
* {@inheritDoc IDynamicCollider.getLinearVelocity }
|
|
647
658
|
*/ _proto.getLinearVelocity = function getLinearVelocity(out) {
|
|
648
|
-
|
|
659
|
+
Logger.error("Physics-lite don't support getLinearVelocity. Use Physics-PhysX instead!");
|
|
649
660
|
return out;
|
|
650
661
|
};
|
|
651
662
|
/**
|
|
652
663
|
* {@inheritDoc IDynamicCollider.setLinearVelocity }
|
|
653
664
|
*/ _proto.setLinearVelocity = function setLinearVelocity(value) {
|
|
654
|
-
|
|
665
|
+
Logger.error("Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!");
|
|
655
666
|
};
|
|
656
667
|
/**
|
|
657
668
|
* {@inheritDoc IDynamicCollider.setMass }
|
|
658
669
|
*/ _proto.setMass = function setMass(value) {
|
|
659
|
-
|
|
670
|
+
Logger.error("Physics-lite don't support setMass. Use Physics-PhysX instead!");
|
|
660
671
|
};
|
|
661
672
|
/**
|
|
662
673
|
* {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
|
|
663
674
|
*/ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
|
|
664
|
-
|
|
675
|
+
Logger.error("Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!");
|
|
665
676
|
};
|
|
666
677
|
/**
|
|
667
678
|
* {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
|
|
@@ -671,17 +682,17 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
671
682
|
/**
|
|
672
683
|
* {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
|
|
673
684
|
*/ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
|
|
674
|
-
|
|
685
|
+
Logger.error("Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!");
|
|
675
686
|
};
|
|
676
687
|
/**
|
|
677
688
|
* {@inheritDoc IDynamicCollider.setSleepThreshold }
|
|
678
689
|
*/ _proto.setSleepThreshold = function setSleepThreshold(value) {
|
|
679
|
-
|
|
690
|
+
Logger.error("Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!");
|
|
680
691
|
};
|
|
681
692
|
/**
|
|
682
693
|
* {@inheritDoc IDynamicCollider.setSolverIterations }
|
|
683
694
|
*/ _proto.setSolverIterations = function setSolverIterations(value) {
|
|
684
|
-
|
|
695
|
+
Logger.error("Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!");
|
|
685
696
|
};
|
|
686
697
|
/**
|
|
687
698
|
* {@inheritDoc IDynamicCollider.wakeUp }
|
|
@@ -739,11 +750,11 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
739
750
|
|
|
740
751
|
/**
|
|
741
752
|
* Box collider shape in Lite.
|
|
742
|
-
*/ var LiteBoxColliderShape = /*#__PURE__*/ function(
|
|
743
|
-
_inherits(LiteBoxColliderShape,
|
|
753
|
+
*/ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
|
|
754
|
+
_inherits(LiteBoxColliderShape, LiteColliderShape1);
|
|
744
755
|
function LiteBoxColliderShape(uniqueID, size, material) {
|
|
745
756
|
var _this;
|
|
746
|
-
_this =
|
|
757
|
+
_this = LiteColliderShape1.call(this) || this, _this._halfSize = new Vector3(), _this._sizeScale = new Vector3(1, 1, 1), /** @internal */ _this._boxMin = new Vector3(-0.5, -0.5, -0.5), /** @internal */ _this._boxMax = new Vector3(0.5, 0.5, 0.5);
|
|
747
758
|
_this._id = uniqueID;
|
|
748
759
|
_this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
|
|
749
760
|
_this._setBondingBox();
|
|
@@ -753,13 +764,13 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
753
764
|
/**
|
|
754
765
|
* {@inheritDoc IColliderShape.setPosition }
|
|
755
766
|
*/ _proto.setPosition = function setPosition(position) {
|
|
756
|
-
|
|
767
|
+
LiteColliderShape1.prototype.setPosition.call(this, position);
|
|
757
768
|
this._setBondingBox();
|
|
758
769
|
};
|
|
759
770
|
/**
|
|
760
771
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
761
772
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
762
|
-
|
|
773
|
+
LiteColliderShape1.prototype.setWorldScale.call(this, scale);
|
|
763
774
|
this._sizeScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
|
|
764
775
|
this._setBondingBox();
|
|
765
776
|
};
|
|
@@ -770,6 +781,44 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
770
781
|
this._setBondingBox();
|
|
771
782
|
};
|
|
772
783
|
/**
|
|
784
|
+
* {@inheritDoc IColliderShape.pointDistance }
|
|
785
|
+
*/ _proto.pointDistance = function pointDistance(point) {
|
|
786
|
+
var position = LiteColliderShape._tempPos;
|
|
787
|
+
var rotation = LiteColliderShape._tempRot;
|
|
788
|
+
this._transform.worldMatrix.decompose(position, rotation, LiteColliderShape._tempScale);
|
|
789
|
+
var _this__transform = this._transform, shapePosition = _this__transform.position;
|
|
790
|
+
var m = LiteBoxColliderShape._tempMatrix;
|
|
791
|
+
var invM = LiteBoxColliderShape._tempInvMatrix;
|
|
792
|
+
var p = LiteColliderShape._tempPoint;
|
|
793
|
+
var scale = this._sizeScale;
|
|
794
|
+
var boundingBox = LiteBoxColliderShape._tempBox;
|
|
795
|
+
var _this = this, _boxMin = _this._boxMin, _boxMax = _this._boxMax;
|
|
796
|
+
p.copyFrom(_boxMin);
|
|
797
|
+
p.subtract(shapePosition);
|
|
798
|
+
p.divide(scale);
|
|
799
|
+
boundingBox.min.copyFrom(p);
|
|
800
|
+
p.copyFrom(_boxMax);
|
|
801
|
+
p.subtract(shapePosition);
|
|
802
|
+
p.divide(scale);
|
|
803
|
+
boundingBox.max.copyFrom(p);
|
|
804
|
+
Matrix.affineTransformation(scale, rotation, position, m);
|
|
805
|
+
Matrix.invert(m, invM);
|
|
806
|
+
Vector3.transformCoordinate(point, invM, p);
|
|
807
|
+
var min = boundingBox.min;
|
|
808
|
+
var max = boundingBox.max;
|
|
809
|
+
p.x = Math.max(min.x, Math.min(p.x, max.x));
|
|
810
|
+
p.y = Math.max(min.y, Math.min(p.y, max.y));
|
|
811
|
+
p.z = Math.max(min.z, Math.min(p.z, max.z));
|
|
812
|
+
Vector3.transformCoordinate(p, m, p);
|
|
813
|
+
var res = LiteColliderShape._tempVector4;
|
|
814
|
+
if (Vector3.equals(p, point)) {
|
|
815
|
+
res.set(point.x, point.y, point.z, 0);
|
|
816
|
+
} else {
|
|
817
|
+
res.set(p.x, p.y, p.z, Vector3.distanceSquared(p, point));
|
|
818
|
+
}
|
|
819
|
+
return res;
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
773
822
|
* @internal
|
|
774
823
|
*/ _proto._raycast = function _raycast(ray, hit) {
|
|
775
824
|
var localRay = this._getLocalRay(ray);
|
|
@@ -796,14 +845,16 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
796
845
|
return LiteBoxColliderShape;
|
|
797
846
|
}(LiteColliderShape);
|
|
798
847
|
LiteBoxColliderShape._tempBox = new BoundingBox();
|
|
848
|
+
LiteBoxColliderShape._tempMatrix = new Matrix();
|
|
849
|
+
LiteBoxColliderShape._tempInvMatrix = new Matrix();
|
|
799
850
|
|
|
800
851
|
/**
|
|
801
852
|
* Sphere collider shape in Lite.
|
|
802
|
-
*/ var LiteSphereColliderShape = /*#__PURE__*/ function(
|
|
803
|
-
_inherits(LiteSphereColliderShape,
|
|
853
|
+
*/ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape1) {
|
|
854
|
+
_inherits(LiteSphereColliderShape, LiteColliderShape1);
|
|
804
855
|
function LiteSphereColliderShape(uniqueID, radius, material) {
|
|
805
856
|
var _this;
|
|
806
|
-
_this =
|
|
857
|
+
_this = LiteColliderShape1.call(this) || this, _this._radius = 1, _this._maxScale = 1;
|
|
807
858
|
_this._radius = radius;
|
|
808
859
|
_this._id = uniqueID;
|
|
809
860
|
return _this;
|
|
@@ -817,10 +868,31 @@ LiteBoxColliderShape._tempBox = new BoundingBox();
|
|
|
817
868
|
/**
|
|
818
869
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
819
870
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
820
|
-
|
|
871
|
+
LiteColliderShape1.prototype.setWorldScale.call(this, scale);
|
|
821
872
|
this._maxScale = Math.max(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
|
|
822
873
|
};
|
|
823
874
|
/**
|
|
875
|
+
* {@inheritDoc IColliderShape.pointDistance }
|
|
876
|
+
*/ _proto.pointDistance = function pointDistance(point) {
|
|
877
|
+
var position = LiteColliderShape._tempPos;
|
|
878
|
+
var worldRadius = this.worldRadius;
|
|
879
|
+
this._transform.worldMatrix.decompose(position, LiteColliderShape._tempRot, LiteColliderShape._tempScale);
|
|
880
|
+
var p = LiteColliderShape._tempPoint;
|
|
881
|
+
Vector3.subtract(point, position, p);
|
|
882
|
+
var distanceFromCenter = p.lengthSquared();
|
|
883
|
+
var direction = p.normalize();
|
|
884
|
+
Vector3.scale(direction, worldRadius, p);
|
|
885
|
+
p.add(position);
|
|
886
|
+
var res = LiteColliderShape._tempVector4;
|
|
887
|
+
var distanceSquared = Vector3.distanceSquared(p, point);
|
|
888
|
+
if (distanceFromCenter <= worldRadius * worldRadius) {
|
|
889
|
+
res.set(point.x, point.y, point.z, 0);
|
|
890
|
+
} else {
|
|
891
|
+
res.set(p.x, p.y, p.z, distanceSquared);
|
|
892
|
+
}
|
|
893
|
+
return res;
|
|
894
|
+
};
|
|
895
|
+
/**
|
|
824
896
|
* @internal
|
|
825
897
|
*/ _proto._raycast = function _raycast(ray, hit) {
|
|
826
898
|
var boundingSphere = LiteSphereColliderShape._tempSphere;
|
|
@@ -1222,7 +1294,7 @@ var LitePhysics = /*#__PURE__*/ function() {
|
|
|
1222
1294
|
}();
|
|
1223
1295
|
|
|
1224
1296
|
//@ts-ignore
|
|
1225
|
-
var version = "1.4.0-alpha.
|
|
1297
|
+
var version = "1.4.0-alpha.2";
|
|
1226
1298
|
console.log("Galacean PhysicsLite version: " + version);
|
|
1227
1299
|
|
|
1228
1300
|
export { LitePhysics, version };
|