@galacean/engine-math 1.3.24 → 1.4.0-alpha.0
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/main.js +85 -126
- package/dist/main.js.map +1 -1
- package/dist/module.js +43 -87
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/dist/miniprogram.js +0 -5095
package/dist/main.js
CHANGED
|
@@ -4,33 +4,33 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Defines how the bounding volumes intersects or contain one another.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
ContainmentType
|
|
12
|
-
}
|
|
7
|
+
*/ var ContainmentType = /*#__PURE__*/ function(ContainmentType) {
|
|
8
|
+
/** Indicates that there is no overlap between two bounding volumes. */ ContainmentType[ContainmentType["Disjoint"] = 0] = "Disjoint";
|
|
9
|
+
/** Indicates that one bounding volume completely contains another volume. */ ContainmentType[ContainmentType["Contains"] = 1] = "Contains";
|
|
10
|
+
/** Indicates that bounding volumes partially overlap one another. */ ContainmentType[ContainmentType["Intersects"] = 2] = "Intersects";
|
|
11
|
+
return ContainmentType;
|
|
12
|
+
}({});
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Defines the intersection between a plane and a bounding volume.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
PlaneIntersectionType
|
|
21
|
-
}
|
|
16
|
+
*/ var PlaneIntersectionType = /*#__PURE__*/ function(PlaneIntersectionType) {
|
|
17
|
+
/** There is no intersection, the bounding volume is in the back of the plane. */ PlaneIntersectionType[PlaneIntersectionType["Back"] = 0] = "Back";
|
|
18
|
+
/** There is no intersection, the bounding volume is in the front of the plane. */ PlaneIntersectionType[PlaneIntersectionType["Front"] = 1] = "Front";
|
|
19
|
+
/** The plane is intersected. */ PlaneIntersectionType[PlaneIntersectionType["Intersecting"] = 2] = "Intersecting";
|
|
20
|
+
return PlaneIntersectionType;
|
|
21
|
+
}({});
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Frustum face
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
FrustumFace
|
|
33
|
-
}
|
|
25
|
+
*/ var FrustumFace = /*#__PURE__*/ function(FrustumFace) {
|
|
26
|
+
/** Near face */ FrustumFace[FrustumFace["Near"] = 0] = "Near";
|
|
27
|
+
/** Far face */ FrustumFace[FrustumFace["Far"] = 1] = "Far";
|
|
28
|
+
/** Left face */ FrustumFace[FrustumFace["Left"] = 2] = "Left";
|
|
29
|
+
/** Right face */ FrustumFace[FrustumFace["Right"] = 3] = "Right";
|
|
30
|
+
/** Bottom face */ FrustumFace[FrustumFace["Bottom"] = 4] = "Bottom";
|
|
31
|
+
/** Top face */ FrustumFace[FrustumFace["Top"] = 5] = "Top";
|
|
32
|
+
return FrustumFace;
|
|
33
|
+
}({});
|
|
34
34
|
|
|
35
35
|
function _defineProperties(target, props) {
|
|
36
36
|
for (var i = 0; i < props.length; i++) {
|
|
@@ -104,15 +104,9 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
104
104
|
};
|
|
105
105
|
return MathUtil;
|
|
106
106
|
}();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
(function() {
|
|
111
|
-
/** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
|
|
112
|
-
})();
|
|
113
|
-
(function() {
|
|
114
|
-
/** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
|
|
115
|
-
})();
|
|
107
|
+
/** The value for which all absolute numbers smaller than are considered equal to zero. */ MathUtil.zeroTolerance = 1e-6;
|
|
108
|
+
/** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
|
|
109
|
+
/** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
|
|
116
110
|
|
|
117
111
|
/**
|
|
118
112
|
* Describes a 3D-vector.
|
|
@@ -621,12 +615,8 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
621
615
|
]);
|
|
622
616
|
return Vector3;
|
|
623
617
|
}();
|
|
624
|
-
(
|
|
625
|
-
|
|
626
|
-
})();
|
|
627
|
-
(function() {
|
|
628
|
-
/** @internal */ Vector3._one = new Vector3(1.0, 1.0, 1.0);
|
|
629
|
-
})();
|
|
618
|
+
/** @internal */ Vector3._zero = new Vector3(0.0, 0.0, 0.0);
|
|
619
|
+
/** @internal */ Vector3._one = new Vector3(1.0, 1.0, 1.0);
|
|
630
620
|
|
|
631
621
|
/**
|
|
632
622
|
* A bounding sphere.
|
|
@@ -695,9 +685,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
695
685
|
};
|
|
696
686
|
return BoundingSphere;
|
|
697
687
|
}();
|
|
698
|
-
(
|
|
699
|
-
BoundingSphere._tempVec30 = new Vector3();
|
|
700
|
-
})();
|
|
688
|
+
BoundingSphere._tempVec30 = new Vector3();
|
|
701
689
|
|
|
702
690
|
/**
|
|
703
691
|
* Axis Aligned Bound Box (AABB).
|
|
@@ -862,12 +850,8 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
862
850
|
};
|
|
863
851
|
return BoundingBox;
|
|
864
852
|
}();
|
|
865
|
-
(
|
|
866
|
-
|
|
867
|
-
})();
|
|
868
|
-
(function() {
|
|
869
|
-
BoundingBox._tempVec31 = new Vector3();
|
|
870
|
-
})();
|
|
853
|
+
BoundingBox._tempVec30 = new Vector3();
|
|
854
|
+
BoundingBox._tempVec31 = new Vector3();
|
|
871
855
|
|
|
872
856
|
/**
|
|
873
857
|
* Contains static methods to help in determining intersections, containment, etc.
|
|
@@ -911,12 +895,12 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
911
895
|
*/ CollisionUtil.intersectsPlaneAndPoint = function intersectsPlaneAndPoint(plane, point) {
|
|
912
896
|
var distance = CollisionUtil.distancePlaneAndPoint(plane, point);
|
|
913
897
|
if (distance > 0) {
|
|
914
|
-
return
|
|
898
|
+
return PlaneIntersectionType.Front;
|
|
915
899
|
}
|
|
916
900
|
if (distance < 0) {
|
|
917
|
-
return
|
|
901
|
+
return PlaneIntersectionType.Back;
|
|
918
902
|
}
|
|
919
|
-
return
|
|
903
|
+
return PlaneIntersectionType.Intersecting;
|
|
920
904
|
};
|
|
921
905
|
/**
|
|
922
906
|
* Get the intersection type between a plane and a box (AABB).
|
|
@@ -950,12 +934,12 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
950
934
|
back.z = max.z;
|
|
951
935
|
}
|
|
952
936
|
if (CollisionUtil.distancePlaneAndPoint(plane, front) < 0) {
|
|
953
|
-
return
|
|
937
|
+
return PlaneIntersectionType.Back;
|
|
954
938
|
}
|
|
955
939
|
if (CollisionUtil.distancePlaneAndPoint(plane, back) > 0) {
|
|
956
|
-
return
|
|
940
|
+
return PlaneIntersectionType.Front;
|
|
957
941
|
}
|
|
958
|
-
return
|
|
942
|
+
return PlaneIntersectionType.Intersecting;
|
|
959
943
|
};
|
|
960
944
|
/**
|
|
961
945
|
* Get the intersection type between a plane and a sphere.
|
|
@@ -966,12 +950,12 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
966
950
|
var center = sphere.center, radius = sphere.radius;
|
|
967
951
|
var distance = CollisionUtil.distancePlaneAndPoint(plane, center);
|
|
968
952
|
if (distance > radius) {
|
|
969
|
-
return
|
|
953
|
+
return PlaneIntersectionType.Front;
|
|
970
954
|
}
|
|
971
955
|
if (distance < -radius) {
|
|
972
|
-
return
|
|
956
|
+
return PlaneIntersectionType.Back;
|
|
973
957
|
}
|
|
974
|
-
return
|
|
958
|
+
return PlaneIntersectionType.Intersecting;
|
|
975
959
|
};
|
|
976
960
|
/**
|
|
977
961
|
* Get the intersection type between a ray and a plane.
|
|
@@ -1160,41 +1144,41 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1160
1144
|
*/ CollisionUtil.frustumContainsPoint = function frustumContainsPoint(frustum, point) {
|
|
1161
1145
|
var distance = CollisionUtil.distancePlaneAndPoint(frustum.near, point);
|
|
1162
1146
|
if (Math.abs(distance) < MathUtil.zeroTolerance) {
|
|
1163
|
-
return
|
|
1147
|
+
return ContainmentType.Intersects;
|
|
1164
1148
|
} else if (distance < 0) {
|
|
1165
|
-
return
|
|
1149
|
+
return ContainmentType.Disjoint;
|
|
1166
1150
|
}
|
|
1167
1151
|
distance = CollisionUtil.distancePlaneAndPoint(frustum.far, point);
|
|
1168
1152
|
if (Math.abs(distance) < MathUtil.zeroTolerance) {
|
|
1169
|
-
return
|
|
1153
|
+
return ContainmentType.Intersects;
|
|
1170
1154
|
} else if (distance < 0) {
|
|
1171
|
-
return
|
|
1155
|
+
return ContainmentType.Disjoint;
|
|
1172
1156
|
}
|
|
1173
1157
|
distance = CollisionUtil.distancePlaneAndPoint(frustum.left, point);
|
|
1174
1158
|
if (Math.abs(distance) < MathUtil.zeroTolerance) {
|
|
1175
|
-
return
|
|
1159
|
+
return ContainmentType.Intersects;
|
|
1176
1160
|
} else if (distance < 0) {
|
|
1177
|
-
return
|
|
1161
|
+
return ContainmentType.Disjoint;
|
|
1178
1162
|
}
|
|
1179
1163
|
distance = CollisionUtil.distancePlaneAndPoint(frustum.right, point);
|
|
1180
1164
|
if (Math.abs(distance) < MathUtil.zeroTolerance) {
|
|
1181
|
-
return
|
|
1165
|
+
return ContainmentType.Intersects;
|
|
1182
1166
|
} else if (distance < 0) {
|
|
1183
|
-
return
|
|
1167
|
+
return ContainmentType.Disjoint;
|
|
1184
1168
|
}
|
|
1185
1169
|
distance = CollisionUtil.distancePlaneAndPoint(frustum.top, point);
|
|
1186
1170
|
if (Math.abs(distance) < MathUtil.zeroTolerance) {
|
|
1187
|
-
return
|
|
1171
|
+
return ContainmentType.Intersects;
|
|
1188
1172
|
} else if (distance < 0) {
|
|
1189
|
-
return
|
|
1173
|
+
return ContainmentType.Disjoint;
|
|
1190
1174
|
}
|
|
1191
1175
|
distance = CollisionUtil.distancePlaneAndPoint(frustum.bottom, point);
|
|
1192
1176
|
if (Math.abs(distance) < MathUtil.zeroTolerance) {
|
|
1193
|
-
return
|
|
1177
|
+
return ContainmentType.Intersects;
|
|
1194
1178
|
} else if (distance < 0) {
|
|
1195
|
-
return
|
|
1179
|
+
return ContainmentType.Disjoint;
|
|
1196
1180
|
}
|
|
1197
|
-
return
|
|
1181
|
+
return ContainmentType.Contains;
|
|
1198
1182
|
};
|
|
1199
1183
|
/**
|
|
1200
1184
|
* Get the containment type between a frustum and a box (AABB).
|
|
@@ -1205,7 +1189,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1205
1189
|
var min = box.min, max = box.max;
|
|
1206
1190
|
var p = CollisionUtil._tempVec30;
|
|
1207
1191
|
var n = CollisionUtil._tempVec31;
|
|
1208
|
-
var result =
|
|
1192
|
+
var result = ContainmentType.Contains;
|
|
1209
1193
|
for(var i = 0; i < 6; ++i){
|
|
1210
1194
|
var plane = frustum.getPlane(i);
|
|
1211
1195
|
var normal = plane.normal;
|
|
@@ -1230,11 +1214,11 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1230
1214
|
p.z = min.z;
|
|
1231
1215
|
n.z = max.z;
|
|
1232
1216
|
}
|
|
1233
|
-
if (CollisionUtil.intersectsPlaneAndPoint(plane, p) ===
|
|
1234
|
-
return
|
|
1217
|
+
if (CollisionUtil.intersectsPlaneAndPoint(plane, p) === PlaneIntersectionType.Back) {
|
|
1218
|
+
return ContainmentType.Disjoint;
|
|
1235
1219
|
}
|
|
1236
|
-
if (CollisionUtil.intersectsPlaneAndPoint(plane, n) ===
|
|
1237
|
-
result =
|
|
1220
|
+
if (CollisionUtil.intersectsPlaneAndPoint(plane, n) === PlaneIntersectionType.Back) {
|
|
1221
|
+
result = ContainmentType.Intersects;
|
|
1238
1222
|
}
|
|
1239
1223
|
}
|
|
1240
1224
|
return result;
|
|
@@ -1245,14 +1229,14 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1245
1229
|
* @param sphere - The sphere
|
|
1246
1230
|
* @returns The containment type
|
|
1247
1231
|
*/ CollisionUtil.frustumContainsSphere = function frustumContainsSphere(frustum, sphere) {
|
|
1248
|
-
var result =
|
|
1232
|
+
var result = ContainmentType.Contains;
|
|
1249
1233
|
for(var i = 0; i < 6; ++i){
|
|
1250
1234
|
var plane = frustum.getPlane(i);
|
|
1251
1235
|
var intersectionType = CollisionUtil.intersectsPlaneAndSphere(plane, sphere);
|
|
1252
|
-
if (intersectionType ===
|
|
1253
|
-
return
|
|
1254
|
-
} else if (intersectionType ===
|
|
1255
|
-
result =
|
|
1236
|
+
if (intersectionType === PlaneIntersectionType.Back) {
|
|
1237
|
+
return ContainmentType.Disjoint;
|
|
1238
|
+
} else if (intersectionType === PlaneIntersectionType.Intersecting) {
|
|
1239
|
+
result = ContainmentType.Intersects;
|
|
1256
1240
|
break;
|
|
1257
1241
|
}
|
|
1258
1242
|
}
|
|
@@ -1260,15 +1244,9 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1260
1244
|
};
|
|
1261
1245
|
return CollisionUtil;
|
|
1262
1246
|
}();
|
|
1263
|
-
(
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
(function() {
|
|
1267
|
-
CollisionUtil._tempVec31 = new Vector3();
|
|
1268
|
-
})();
|
|
1269
|
-
(function() {
|
|
1270
|
-
CollisionUtil._tempVec32 = new Vector3();
|
|
1271
|
-
})();
|
|
1247
|
+
CollisionUtil._tempVec30 = new Vector3();
|
|
1248
|
+
CollisionUtil._tempVec31 = new Vector3();
|
|
1249
|
+
CollisionUtil._tempVec32 = new Vector3();
|
|
1272
1250
|
|
|
1273
1251
|
/**
|
|
1274
1252
|
* Represents a plane in three-dimensional space.
|
|
@@ -1368,17 +1346,17 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1368
1346
|
* @returns The plane get
|
|
1369
1347
|
*/ _proto.getPlane = function getPlane(face) {
|
|
1370
1348
|
switch(face){
|
|
1371
|
-
case
|
|
1349
|
+
case FrustumFace.Near:
|
|
1372
1350
|
return this.near;
|
|
1373
|
-
case
|
|
1351
|
+
case FrustumFace.Far:
|
|
1374
1352
|
return this.far;
|
|
1375
|
-
case
|
|
1353
|
+
case FrustumFace.Left:
|
|
1376
1354
|
return this.left;
|
|
1377
|
-
case
|
|
1355
|
+
case FrustumFace.Right:
|
|
1378
1356
|
return this.right;
|
|
1379
|
-
case
|
|
1357
|
+
case FrustumFace.Bottom:
|
|
1380
1358
|
return this.bottom;
|
|
1381
|
-
case
|
|
1359
|
+
case FrustumFace.Top:
|
|
1382
1360
|
return this.top;
|
|
1383
1361
|
default:
|
|
1384
1362
|
return null;
|
|
@@ -1448,7 +1426,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
1448
1426
|
* @param sphere - The sphere for testing
|
|
1449
1427
|
* @returns True if bounding sphere intersects with this frustum, false otherwise
|
|
1450
1428
|
*/ _proto.intersectsSphere = function intersectsSphere(sphere) {
|
|
1451
|
-
return CollisionUtil.frustumContainsSphere(this, sphere) !==
|
|
1429
|
+
return CollisionUtil.frustumContainsSphere(this, sphere) !== ContainmentType.Disjoint;
|
|
1452
1430
|
};
|
|
1453
1431
|
/**
|
|
1454
1432
|
* Creates a clone of this frustum.
|
|
@@ -2676,12 +2654,8 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
2676
2654
|
]);
|
|
2677
2655
|
return Quaternion;
|
|
2678
2656
|
}();
|
|
2679
|
-
(
|
|
2680
|
-
|
|
2681
|
-
})();
|
|
2682
|
-
(function() {
|
|
2683
|
-
/** @internal */ Quaternion._tempQuat1 = new Quaternion();
|
|
2684
|
-
})();
|
|
2657
|
+
/** @internal */ Quaternion._tempVector3 = new Vector3();
|
|
2658
|
+
/** @internal */ Quaternion._tempQuat1 = new Quaternion();
|
|
2685
2659
|
|
|
2686
2660
|
/**
|
|
2687
2661
|
* Represents a 4x4 mathematical matrix.
|
|
@@ -3622,21 +3596,11 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
3622
3596
|
};
|
|
3623
3597
|
return Matrix;
|
|
3624
3598
|
}();
|
|
3625
|
-
(
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
(
|
|
3629
|
-
|
|
3630
|
-
})();
|
|
3631
|
-
(function() {
|
|
3632
|
-
Matrix._tempVec32 = new Vector3();
|
|
3633
|
-
})();
|
|
3634
|
-
(function() {
|
|
3635
|
-
Matrix._tempMat30 = new Matrix3x3();
|
|
3636
|
-
})();
|
|
3637
|
-
(function() {
|
|
3638
|
-
/** @internal Identity matrix. */ Matrix._identity = new Matrix(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
|
|
3639
|
-
})();
|
|
3599
|
+
Matrix._tempVec30 = new Vector3();
|
|
3600
|
+
Matrix._tempVec31 = new Vector3();
|
|
3601
|
+
Matrix._tempVec32 = new Vector3();
|
|
3602
|
+
Matrix._tempMat30 = new Matrix3x3();
|
|
3603
|
+
/** @internal Identity matrix. */ Matrix._identity = new Matrix(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
|
|
3640
3604
|
|
|
3641
3605
|
/**
|
|
3642
3606
|
* Represents a ray with an origin and a direction in 3D space.
|
|
@@ -4009,12 +3973,8 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
4009
3973
|
]);
|
|
4010
3974
|
return Vector2;
|
|
4011
3975
|
}();
|
|
4012
|
-
(
|
|
4013
|
-
|
|
4014
|
-
})();
|
|
4015
|
-
(function() {
|
|
4016
|
-
/** @internal */ Vector2._one = new Vector2(1.0, 1.0);
|
|
4017
|
-
})();
|
|
3976
|
+
/** @internal */ Vector2._zero = new Vector2(0.0, 0.0);
|
|
3977
|
+
/** @internal */ Vector2._one = new Vector2(1.0, 1.0);
|
|
4018
3978
|
|
|
4019
3979
|
/**
|
|
4020
3980
|
* Describes a 4D-vector.
|
|
@@ -4458,12 +4418,8 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
4458
4418
|
]);
|
|
4459
4419
|
return Vector4;
|
|
4460
4420
|
}();
|
|
4461
|
-
(
|
|
4462
|
-
|
|
4463
|
-
})();
|
|
4464
|
-
(function() {
|
|
4465
|
-
/** @internal */ Vector4._one = new Vector4(1.0, 1.0, 1.0, 1.0);
|
|
4466
|
-
})();
|
|
4421
|
+
/** @internal */ Vector4._zero = new Vector4(0.0, 0.0, 0.0, 0.0);
|
|
4422
|
+
/** @internal */ Vector4._one = new Vector4(1.0, 1.0, 1.0, 1.0);
|
|
4467
4423
|
|
|
4468
4424
|
/**
|
|
4469
4425
|
* Describes a color in the from of RGBA (in order: R, G, B, A).
|
|
@@ -5081,10 +5037,13 @@ exports.BoundingFrustum = BoundingFrustum;
|
|
|
5081
5037
|
exports.BoundingSphere = BoundingSphere;
|
|
5082
5038
|
exports.CollisionUtil = CollisionUtil;
|
|
5083
5039
|
exports.Color = Color;
|
|
5040
|
+
exports.ContainmentType = ContainmentType;
|
|
5041
|
+
exports.FrustumFace = FrustumFace;
|
|
5084
5042
|
exports.MathUtil = MathUtil;
|
|
5085
5043
|
exports.Matrix = Matrix;
|
|
5086
5044
|
exports.Matrix3x3 = Matrix3x3;
|
|
5087
5045
|
exports.Plane = Plane;
|
|
5046
|
+
exports.PlaneIntersectionType = PlaneIntersectionType;
|
|
5088
5047
|
exports.Quaternion = Quaternion;
|
|
5089
5048
|
exports.Rand = Rand;
|
|
5090
5049
|
exports.Ray = Ray;
|