@galacean/engine-xr-webxr 1.3.24 → 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/module.js CHANGED
@@ -66,17 +66,18 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
66
66
  };
67
67
 
68
68
  function _is_native_reflect_construct() {
69
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
70
- if (Reflect.construct.sham) return false;
71
- if (typeof Proxy === "function") return true;
72
-
69
+ // Since Reflect.construct can't be properly polyfilled, some
70
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
71
+ // Those polyfills don't allow us to subclass built-ins, so we need to
72
+ // use our fallback implementation.
73
73
  try {
74
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
75
-
76
- return true;
77
- } catch (e) {
78
- return false;
79
- }
74
+ // If the internal slots aren't set, this throws an error similar to
75
+ // TypeError: this is not a Boolean object.
76
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
77
+ } catch (_) {}
78
+ return (_is_native_reflect_construct = function() {
79
+ return !!result;
80
+ })();
80
81
  }
81
82
 
82
83
  function _construct(Parent, args, Class) {
@@ -145,33 +146,6 @@ function viewToCamera(type) {
145
146
  }
146
147
  }
147
148
 
148
- /**
149
- * Defines how the bounding volumes intersects or contain one another.
150
- */ var ContainmentType;
151
- (function(ContainmentType) {
152
- ContainmentType[ContainmentType[/** Indicates that there is no overlap between two bounding volumes. */ "Disjoint"] = 0] = "Disjoint";
153
- ContainmentType[ContainmentType[/** Indicates that one bounding volume completely contains another volume. */ "Contains"] = 1] = "Contains";
154
- ContainmentType[ContainmentType[/** Indicates that bounding volumes partially overlap one another. */ "Intersects"] = 2] = "Intersects";
155
- })(ContainmentType || (ContainmentType = {}));
156
- /**
157
- * Defines the intersection between a plane and a bounding volume.
158
- */ var PlaneIntersectionType;
159
- (function(PlaneIntersectionType) {
160
- PlaneIntersectionType[PlaneIntersectionType[/** There is no intersection, the bounding volume is in the back of the plane. */ "Back"] = 0] = "Back";
161
- PlaneIntersectionType[PlaneIntersectionType[/** There is no intersection, the bounding volume is in the front of the plane. */ "Front"] = 1] = "Front";
162
- PlaneIntersectionType[PlaneIntersectionType[/** The plane is intersected. */ "Intersecting"] = 2] = "Intersecting";
163
- })(PlaneIntersectionType || (PlaneIntersectionType = {}));
164
- /**
165
- * Frustum face
166
- */ var FrustumFace;
167
- (function(FrustumFace) {
168
- FrustumFace[FrustumFace[/** Near face */ "Near"] = 0] = "Near";
169
- FrustumFace[FrustumFace[/** Far face */ "Far"] = 1] = "Far";
170
- FrustumFace[FrustumFace[/** Left face */ "Left"] = 2] = "Left";
171
- FrustumFace[FrustumFace[/** Right face */ "Right"] = 3] = "Right";
172
- FrustumFace[FrustumFace[/** Bottom face */ "Bottom"] = 4] = "Bottom";
173
- FrustumFace[FrustumFace[/** Top face */ "Top"] = 5] = "Top";
174
- })(FrustumFace || (FrustumFace = {}));
175
149
  function _defineProperties(target, props) {
176
150
  for(var i = 0; i < props.length; i++){
177
151
  var descriptor = props[i];
@@ -189,7 +163,7 @@ function _create_class(Constructor, protoProps, staticProps) {
189
163
  /**
190
164
  * Common utility methods for math operations.
191
165
  */ var MathUtil = /*#__PURE__*/ function() {
192
- var MathUtil = function MathUtil() {};
166
+ function MathUtil() {}
193
167
  /**
194
168
  * Clamps the specified value.
195
169
  * @param v - The specified value
@@ -240,19 +214,13 @@ function _create_class(Constructor, protoProps, staticProps) {
240
214
  };
241
215
  return MathUtil;
242
216
  }();
243
- (function() {
244
- /** The value for which all absolute numbers smaller than are considered equal to zero. */ MathUtil.zeroTolerance = 1e-6;
245
- })();
246
- (function() {
247
- /** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
248
- })();
249
- (function() {
250
- /** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
251
- })();
217
+ /** The value for which all absolute numbers smaller than are considered equal to zero. */ MathUtil.zeroTolerance = 1e-6;
218
+ /** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
219
+ /** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
252
220
  /**
253
221
  * Describes a 3D-vector.
254
222
  */ var Vector3 = /*#__PURE__*/ function() {
255
- var Vector3 = function Vector3(x, y, z) {
223
+ function Vector3(x, y, z) {
256
224
  if (x === void 0) x = 0;
257
225
  if (y === void 0) y = 0;
258
226
  if (z === void 0) z = 0;
@@ -260,7 +228,7 @@ function _create_class(Constructor, protoProps, staticProps) {
260
228
  this._x = x;
261
229
  this._y = y;
262
230
  this._z = z;
263
- };
231
+ }
264
232
  var _proto = Vector3.prototype;
265
233
  /**
266
234
  * Set the value of this vector.
@@ -756,655 +724,18 @@ function _create_class(Constructor, protoProps, staticProps) {
756
724
  ]);
757
725
  return Vector3;
758
726
  }();
759
- (function() {
760
- /** @internal */ Vector3._zero = new Vector3(0.0, 0.0, 0.0);
761
- })();
762
- (function() {
763
- /** @internal */ Vector3._one = new Vector3(1.0, 1.0, 1.0);
764
- })();
765
- /**
766
- * A bounding sphere.
767
- * */ var BoundingSphere = /*#__PURE__*/ function() {
768
- var BoundingSphere = function BoundingSphere(center, radius) {
769
- if (center === void 0) center = null;
770
- if (radius === void 0) radius = 0;
771
- /** The center point of the sphere. */ this.center = new Vector3();
772
- /** The radius of the sphere. */ this.radius = 0;
773
- center && this.center.copyFrom(center);
774
- this.radius = radius;
775
- };
776
- var _proto = BoundingSphere.prototype;
777
- /**
778
- * Creates a clone of this sphere.
779
- * @returns A clone of this sphere
780
- */ _proto.clone = function clone() {
781
- return new BoundingSphere(this.center, this.radius);
782
- };
783
- /**
784
- * Copy this sphere from the specified sphere.
785
- * @param source - The specified sphere
786
- * @returns This sphere
787
- */ _proto.copyFrom = function copyFrom(source) {
788
- this.center.copyFrom(source.center);
789
- this.radius = source.radius;
790
- return this;
791
- };
792
- /**
793
- * Calculate a bounding sphere that fully contains the given points.
794
- * @param points - The given points
795
- * @param out - The calculated bounding sphere
796
- */ BoundingSphere.fromPoints = function fromPoints(points, out) {
797
- if (!points || points.length === 0) {
798
- throw new Error("points must be array and length must > 0");
799
- }
800
- var len = points.length;
801
- var center = BoundingSphere._tempVec30;
802
- center.x = center.y = center.z = 0;
803
- // Calculate the center of the sphere.
804
- for(var i = 0; i < len; ++i){
805
- Vector3.add(points[i], center, center);
806
- }
807
- // The center of the sphere.
808
- Vector3.scale(center, 1 / len, out.center);
809
- // Calculate the radius of the sphere.
810
- var radius = 0.0;
811
- for(var i1 = 0; i1 < len; ++i1){
812
- var distance = Vector3.distanceSquared(center, points[i1]);
813
- distance > radius && (radius = distance);
814
- }
815
- // The radius of the sphere.
816
- out.radius = Math.sqrt(radius);
817
- };
818
- /**
819
- * Calculate a bounding sphere from a given box.
820
- * @param box - The given box
821
- * @param out - The calculated bounding sphere
822
- */ BoundingSphere.fromBox = function fromBox(box, out) {
823
- var center = out.center;
824
- var min = box.min, max = box.max;
825
- center.x = (min.x + max.x) * 0.5;
826
- center.y = (min.y + max.y) * 0.5;
827
- center.z = (min.z + max.z) * 0.5;
828
- out.radius = Vector3.distance(center, max);
829
- };
830
- return BoundingSphere;
831
- }();
832
- (function() {
833
- BoundingSphere._tempVec30 = new Vector3();
834
- })();
835
- /**
836
- * Axis Aligned Bound Box (AABB).
837
- */ var BoundingBox = /*#__PURE__*/ function() {
838
- var BoundingBox = function BoundingBox(min, max) {
839
- if (min === void 0) min = null;
840
- if (max === void 0) max = null;
841
- /** The minimum point of the box. */ this.min = new Vector3();
842
- /** The maximum point of the box. */ this.max = new Vector3();
843
- min && this.min.copyFrom(min);
844
- max && this.max.copyFrom(max);
845
- };
846
- var _proto = BoundingBox.prototype;
847
- /**
848
- * Get the center point of this bounding box.
849
- * @param out - The center point of this bounding box
850
- * @returns The center point of this bounding box
851
- */ _proto.getCenter = function getCenter(out) {
852
- var _this = this, min = _this.min, max = _this.max;
853
- var centerX = max._x + min._x;
854
- var centerY = max._y + min._y;
855
- var centerZ = max._z + min._z;
856
- out.set(isNaN(centerX) ? 0 : centerX * 0.5, isNaN(centerY) ? 0 : centerY * 0.5, isNaN(centerZ) ? 0 : centerZ * 0.5);
857
- return out;
858
- };
859
- /**
860
- * Get the extent of this bounding box.
861
- * @param out - The extent of this bounding box
862
- * @returns The extent of this bounding box
863
- */ _proto.getExtent = function getExtent(out) {
864
- var _this = this, min = _this.min, max = _this.max;
865
- var extentX = max._x - min._x;
866
- var extentY = max._y - min._y;
867
- var extentZ = max._z - min._z;
868
- out.set(isNaN(extentX) ? 0 : extentX * 0.5, isNaN(extentY) ? 0 : extentY * 0.5, isNaN(extentZ) ? 0 : extentZ * 0.5);
869
- return out;
870
- };
871
- /**
872
- * Get the eight corners of this bounding box.
873
- * @param out - An array of points representing the eight corners of this bounding box
874
- * @returns An array of points representing the eight corners of this bounding box
875
- */ _proto.getCorners = function getCorners(out) {
876
- if (out === void 0) out = [];
877
- var _this = this, min = _this.min, max = _this.max;
878
- var minX = min.x;
879
- var minY = min.y;
880
- var minZ = min.z;
881
- var maxX = max.x;
882
- var maxY = max.y;
883
- var maxZ = max.z;
884
- var len = out.length;
885
- // The array length is less than 8 to make up
886
- if (len < 8) {
887
- for(var i = 0, l = 8 - len; i < l; ++i){
888
- out[len + i] = new Vector3();
889
- }
890
- }
891
- out[0].set(minX, maxY, maxZ);
892
- out[1].set(maxX, maxY, maxZ);
893
- out[2].set(maxX, minY, maxZ);
894
- out[3].set(minX, minY, maxZ);
895
- out[4].set(minX, maxY, minZ);
896
- out[5].set(maxX, maxY, minZ);
897
- out[6].set(maxX, minY, minZ);
898
- out[7].set(minX, minY, minZ);
899
- return out;
900
- };
901
- /**
902
- * Transform a bounding box.
903
- * @param matrix - The transform to apply to the bounding box
904
- * @returns The transformed bounding box
905
- */ _proto.transform = function transform(matrix) {
906
- BoundingBox.transform(this, matrix, this);
907
- return this;
908
- };
909
- /**
910
- * Creates a clone of this box.
911
- * @returns A clone of this box
912
- */ _proto.clone = function clone() {
913
- return new BoundingBox(this.min, this.max);
914
- };
915
- /**
916
- * Copy this bounding box from the specified box.
917
- * @param source - The specified box
918
- * @returns This bounding box
919
- */ _proto.copyFrom = function copyFrom(source) {
920
- this.min.copyFrom(source.min);
921
- this.max.copyFrom(source.max);
922
- return this;
923
- };
924
- /**
925
- * Calculate a bounding box from the center point and the extent of the bounding box.
926
- * @param center - The center point
927
- * @param extent - The extent of the bounding box
928
- * @param out - The calculated bounding box
929
- */ BoundingBox.fromCenterAndExtent = function fromCenterAndExtent(center, extent, out) {
930
- Vector3.subtract(center, extent, out.min);
931
- Vector3.add(center, extent, out.max);
932
- };
933
- /**
934
- * Calculate a bounding box that fully contains the given points.
935
- * @param points - The given points
936
- * @param out - The calculated bounding box
937
- */ BoundingBox.fromPoints = function fromPoints(points, out) {
938
- if (!points || points.length === 0) {
939
- throw new Error("points must be array and length must > 0");
940
- }
941
- var min = out.min, max = out.max;
942
- min.x = min.y = min.z = Number.MAX_VALUE;
943
- max.x = max.y = max.z = -Number.MAX_VALUE;
944
- for(var i = 0, l = points.length; i < l; ++i){
945
- var point = points[i];
946
- Vector3.min(min, point, min);
947
- Vector3.max(max, point, max);
948
- }
949
- };
950
- /**
951
- * Calculate a bounding box from a given sphere.
952
- * @param sphere - The given sphere
953
- * @param out - The calculated bounding box
954
- */ BoundingBox.fromSphere = function fromSphere(sphere, out) {
955
- var center = sphere.center, radius = sphere.radius;
956
- var min = out.min, max = out.max;
957
- min.x = center.x - radius;
958
- min.y = center.y - radius;
959
- min.z = center.z - radius;
960
- max.x = center.x + radius;
961
- max.y = center.y + radius;
962
- max.z = center.z + radius;
963
- };
964
- /**
965
- * Transform a bounding box.
966
- * @param source - The original bounding box
967
- * @param matrix - The transform to apply to the bounding box
968
- * @param out - The transformed bounding box
969
- */ BoundingBox.transform = function transform(source, matrix, out) {
970
- // https://zeux.io/2010/10/17/aabb-from-obb-with-component-wise-abs/
971
- var center = BoundingBox._tempVec30;
972
- var extent = BoundingBox._tempVec31;
973
- source.getCenter(center);
974
- source.getExtent(extent);
975
- Vector3.transformCoordinate(center, matrix, center);
976
- var x = extent.x, y = extent.y, z = extent.z;
977
- var e = matrix.elements;
978
- // prettier-ignore
979
- var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e8 = e[8], e9 = e[9], e10 = e[10];
980
- extent.set((e0 === 0 ? 0 : Math.abs(x * e0)) + (e4 === 0 ? 0 : Math.abs(y * e4)) + (e8 === 0 ? 0 : Math.abs(z * e8)), (e1 === 0 ? 0 : Math.abs(x * e1)) + (e5 === 0 ? 0 : Math.abs(y * e5)) + (e9 === 0 ? 0 : Math.abs(z * e9)), (e2 === 0 ? 0 : Math.abs(x * e2)) + (e6 === 0 ? 0 : Math.abs(y * e6)) + (e10 === 0 ? 0 : Math.abs(z * e10)));
981
- // set min、max
982
- Vector3.subtract(center, extent, out.min);
983
- Vector3.add(center, extent, out.max);
984
- };
985
- /**
986
- * Calculate a bounding box that is as large as the total combined area of the two specified boxes.
987
- * @param box1 - The first box to merge
988
- * @param box2 - The second box to merge
989
- * @param out - The merged bounding box
990
- * @returns The merged bounding box
991
- */ BoundingBox.merge = function merge(box1, box2, out) {
992
- Vector3.min(box1.min, box2.min, out.min);
993
- Vector3.max(box1.max, box2.max, out.max);
994
- return out;
995
- };
996
- return BoundingBox;
997
- }();
998
- (function() {
999
- BoundingBox._tempVec30 = new Vector3();
1000
- })();
1001
- (function() {
1002
- BoundingBox._tempVec31 = new Vector3();
1003
- })();
1004
- /**
1005
- * Contains static methods to help in determining intersections, containment, etc.
1006
- */ var CollisionUtil = /*#__PURE__*/ function() {
1007
- var CollisionUtil = function CollisionUtil() {};
1008
- /**
1009
- * Calculate the intersection point of three plane.
1010
- * @param p1 - Plane 1
1011
- * @param p2 - Plane 2
1012
- * @param p3 - Plane 3
1013
- * @param out - intersection point
1014
- */ CollisionUtil.intersectionPointThreePlanes = function intersectionPointThreePlanes(p1, p2, p3, out) {
1015
- var p1Nor = p1.normal;
1016
- var p2Nor = p2.normal;
1017
- var p3Nor = p3.normal;
1018
- Vector3.cross(p2Nor, p3Nor, CollisionUtil._tempVec30);
1019
- Vector3.cross(p3Nor, p1Nor, CollisionUtil._tempVec31);
1020
- Vector3.cross(p1Nor, p2Nor, CollisionUtil._tempVec32);
1021
- var a = -Vector3.dot(p1Nor, CollisionUtil._tempVec30);
1022
- var b = -Vector3.dot(p2Nor, CollisionUtil._tempVec31);
1023
- var c = -Vector3.dot(p3Nor, CollisionUtil._tempVec32);
1024
- Vector3.scale(CollisionUtil._tempVec30, p1.distance / a, CollisionUtil._tempVec30);
1025
- Vector3.scale(CollisionUtil._tempVec31, p2.distance / b, CollisionUtil._tempVec31);
1026
- Vector3.scale(CollisionUtil._tempVec32, p3.distance / c, CollisionUtil._tempVec32);
1027
- Vector3.add(CollisionUtil._tempVec30, CollisionUtil._tempVec31, out);
1028
- Vector3.add(out, CollisionUtil._tempVec32, out);
1029
- };
1030
- /**
1031
- * Calculate the distance from a point to a plane.
1032
- * @param plane - The plane
1033
- * @param point - The point
1034
- * @returns The distance from a point to a plane
1035
- */ CollisionUtil.distancePlaneAndPoint = function distancePlaneAndPoint(plane, point) {
1036
- return Vector3.dot(plane.normal, point) + plane.distance;
1037
- };
1038
- /**
1039
- * Get the intersection type between a plane and a point.
1040
- * @param plane - The plane
1041
- * @param point - The point
1042
- * @returns The intersection type
1043
- */ CollisionUtil.intersectsPlaneAndPoint = function intersectsPlaneAndPoint(plane, point) {
1044
- var distance = CollisionUtil.distancePlaneAndPoint(plane, point);
1045
- if (distance > 0) {
1046
- return PlaneIntersectionType.Front;
1047
- }
1048
- if (distance < 0) {
1049
- return PlaneIntersectionType.Back;
1050
- }
1051
- return PlaneIntersectionType.Intersecting;
1052
- };
1053
- /**
1054
- * Get the intersection type between a plane and a box (AABB).
1055
- * @param plane - The plane
1056
- * @param box - The box
1057
- * @returns The intersection type
1058
- */ CollisionUtil.intersectsPlaneAndBox = function intersectsPlaneAndBox(plane, box) {
1059
- var min = box.min, max = box.max;
1060
- var normal = plane.normal;
1061
- var front = CollisionUtil._tempVec30;
1062
- var back = CollisionUtil._tempVec31;
1063
- if (normal.x >= 0) {
1064
- front.x = max.x;
1065
- back.x = min.x;
1066
- } else {
1067
- front.x = min.x;
1068
- back.x = max.x;
1069
- }
1070
- if (normal.y >= 0) {
1071
- front.y = max.y;
1072
- back.y = min.y;
1073
- } else {
1074
- front.y = min.y;
1075
- back.y = max.y;
1076
- }
1077
- if (normal.z >= 0) {
1078
- front.z = max.z;
1079
- back.z = min.z;
1080
- } else {
1081
- front.z = min.z;
1082
- back.z = max.z;
1083
- }
1084
- if (CollisionUtil.distancePlaneAndPoint(plane, front) < 0) {
1085
- return PlaneIntersectionType.Back;
1086
- }
1087
- if (CollisionUtil.distancePlaneAndPoint(plane, back) > 0) {
1088
- return PlaneIntersectionType.Front;
1089
- }
1090
- return PlaneIntersectionType.Intersecting;
1091
- };
1092
- /**
1093
- * Get the intersection type between a plane and a sphere.
1094
- * @param plane - The plane
1095
- * @param sphere - The sphere
1096
- * @returns The intersection type
1097
- */ CollisionUtil.intersectsPlaneAndSphere = function intersectsPlaneAndSphere(plane, sphere) {
1098
- var center = sphere.center, radius = sphere.radius;
1099
- var distance = CollisionUtil.distancePlaneAndPoint(plane, center);
1100
- if (distance > radius) {
1101
- return PlaneIntersectionType.Front;
1102
- }
1103
- if (distance < -radius) {
1104
- return PlaneIntersectionType.Back;
1105
- }
1106
- return PlaneIntersectionType.Intersecting;
1107
- };
1108
- /**
1109
- * Get the intersection type between a ray and a plane.
1110
- * @param ray - The ray
1111
- * @param plane - The plane
1112
- * @returns The distance from ray to plane if intersecting, -1 otherwise
1113
- */ CollisionUtil.intersectsRayAndPlane = function intersectsRayAndPlane(ray, plane) {
1114
- var normal = plane.normal;
1115
- var zeroTolerance = MathUtil.zeroTolerance;
1116
- var dir = Vector3.dot(normal, ray.direction);
1117
- // Parallel
1118
- if (Math.abs(dir) < zeroTolerance) {
1119
- return -1;
1120
- }
1121
- var position = Vector3.dot(normal, ray.origin);
1122
- var distance = (-plane.distance - position) / dir;
1123
- if (distance < 0) {
1124
- if (distance < -zeroTolerance) {
1125
- return -1;
1126
- }
1127
- distance = 0;
1128
- }
1129
- return distance;
1130
- };
1131
- /**
1132
- * Get the intersection type between a ray and a box (AABB).
1133
- * @param ray - The ray
1134
- * @param box - The box
1135
- * @returns The distance from ray to box if intersecting, -1 otherwise
1136
- */ CollisionUtil.intersectsRayAndBox = function intersectsRayAndBox(ray, box) {
1137
- var zeroTolerance = MathUtil.zeroTolerance;
1138
- var origin = ray.origin, direction = ray.direction;
1139
- var min = box.min, max = box.max;
1140
- var dirX = direction.x;
1141
- var dirY = direction.y;
1142
- var dirZ = direction.z;
1143
- var oriX = origin.x;
1144
- var oriY = origin.y;
1145
- var oriZ = origin.z;
1146
- var distance = 0;
1147
- var tmax = Number.MAX_VALUE;
1148
- if (Math.abs(dirX) < zeroTolerance) {
1149
- if (oriX < min.x || oriX > max.x) {
1150
- return -1;
1151
- }
1152
- } else {
1153
- var inverse = 1.0 / dirX;
1154
- var t1 = (min.x - oriX) * inverse;
1155
- var t2 = (max.x - oriX) * inverse;
1156
- if (t1 > t2) {
1157
- var temp = t1;
1158
- t1 = t2;
1159
- t2 = temp;
1160
- }
1161
- distance = Math.max(t1, distance);
1162
- tmax = Math.min(t2, tmax);
1163
- if (distance > tmax) {
1164
- return -1;
1165
- }
1166
- }
1167
- if (Math.abs(dirY) < zeroTolerance) {
1168
- if (oriY < min.y || oriY > max.y) {
1169
- return -1;
1170
- }
1171
- } else {
1172
- var inverse1 = 1.0 / dirY;
1173
- var t11 = (min.y - oriY) * inverse1;
1174
- var t21 = (max.y - oriY) * inverse1;
1175
- if (t11 > t21) {
1176
- var temp1 = t11;
1177
- t11 = t21;
1178
- t21 = temp1;
1179
- }
1180
- distance = Math.max(t11, distance);
1181
- tmax = Math.min(t21, tmax);
1182
- if (distance > tmax) {
1183
- return -1;
1184
- }
1185
- }
1186
- if (Math.abs(dirZ) < zeroTolerance) {
1187
- if (oriZ < min.z || oriZ > max.z) {
1188
- return -1;
1189
- }
1190
- } else {
1191
- var inverse2 = 1.0 / dirZ;
1192
- var t12 = (min.z - oriZ) * inverse2;
1193
- var t22 = (max.z - oriZ) * inverse2;
1194
- if (t12 > t22) {
1195
- var temp2 = t12;
1196
- t12 = t22;
1197
- t22 = temp2;
1198
- }
1199
- distance = Math.max(t12, distance);
1200
- tmax = Math.min(t22, tmax);
1201
- if (distance > tmax) {
1202
- return -1;
1203
- }
1204
- }
1205
- return distance;
1206
- };
1207
- /**
1208
- * Get the intersection type between a ray and a sphere.
1209
- * @param ray - The ray
1210
- * @param sphere - The sphere
1211
- * @returns The distance from ray to sphere if intersecting, -1 otherwise
1212
- */ CollisionUtil.intersectsRayAndSphere = function intersectsRayAndSphere(ray, sphere) {
1213
- var origin = ray.origin, direction = ray.direction;
1214
- var center = sphere.center, radius = sphere.radius;
1215
- var m = CollisionUtil._tempVec30;
1216
- Vector3.subtract(origin, center, m);
1217
- var b = Vector3.dot(m, direction);
1218
- var c = Vector3.dot(m, m) - radius * radius;
1219
- if (b > 0 && c > 0) {
1220
- return -1;
1221
- }
1222
- var discriminant = b * b - c;
1223
- if (discriminant < 0) {
1224
- return -1;
1225
- }
1226
- var distance = -b - Math.sqrt(discriminant);
1227
- if (distance < 0) {
1228
- distance = 0;
1229
- }
1230
- return distance;
1231
- };
1232
- /**
1233
- * Check whether the boxes intersect.
1234
- * @param boxA - The first box to check
1235
- * @param boxB - The second box to check
1236
- * @returns True if the boxes intersect, false otherwise
1237
- */ CollisionUtil.intersectsBoxAndBox = function intersectsBoxAndBox(boxA, boxB) {
1238
- if (boxA.min.x > boxB.max.x || boxB.min.x > boxA.max.x) {
1239
- return false;
1240
- }
1241
- if (boxA.min.y > boxB.max.y || boxB.min.y > boxA.max.y) {
1242
- return false;
1243
- }
1244
- return !(boxA.min.z > boxB.max.z || boxB.min.z > boxA.max.z);
1245
- };
1246
- /**
1247
- * Check whether the spheres intersect.
1248
- * @param sphereA - The first sphere to check
1249
- * @param sphereB - The second sphere to check
1250
- * @returns True if the spheres intersect, false otherwise
1251
- */ CollisionUtil.intersectsSphereAndSphere = function intersectsSphereAndSphere(sphereA, sphereB) {
1252
- var radiisum = sphereA.radius + sphereB.radius;
1253
- return Vector3.distanceSquared(sphereA.center, sphereB.center) < radiisum * radiisum;
1254
- };
1255
- /**
1256
- * Check whether the sphere and the box intersect.
1257
- * @param sphere - The sphere to check
1258
- * @param box - The box to check
1259
- * @returns True if the sphere and the box intersect, false otherwise
1260
- */ CollisionUtil.intersectsSphereAndBox = function intersectsSphereAndBox(sphere, box) {
1261
- var center = sphere.center;
1262
- var max = box.max;
1263
- var min = box.min;
1264
- var closestPoint = CollisionUtil._tempVec30;
1265
- closestPoint.set(Math.max(min.x, Math.min(center.x, max.x)), Math.max(min.y, Math.min(center.y, max.y)), Math.max(min.z, Math.min(center.z, max.z)));
1266
- var distance = Vector3.distanceSquared(center, closestPoint);
1267
- return distance <= sphere.radius * sphere.radius;
1268
- };
1269
- /**
1270
- * Get whether or not a specified bounding box intersects with this frustum (Contains or Intersects).
1271
- * @param frustum - The frustum
1272
- * @param box - The box
1273
- * @returns True if bounding box intersects with this frustum, false otherwise
1274
- */ CollisionUtil.intersectsFrustumAndBox = function intersectsFrustumAndBox(frustum, box) {
1275
- var min = box.min, max = box.max;
1276
- var p = CollisionUtil._tempVec30;
1277
- for(var i = 0; i < 6; ++i){
1278
- var plane = frustum.getPlane(i);
1279
- var normal = plane.normal;
1280
- p.set(normal.x >= 0 ? max.x : min.x, normal.y >= 0 ? max.y : min.y, normal.z >= 0 ? max.z : min.z);
1281
- if (Vector3.dot(normal, p) < -plane.distance) {
1282
- return false;
1283
- }
1284
- }
1285
- return true;
1286
- };
1287
- /**
1288
- * Get the containment type between a frustum and a point.
1289
- * @param frustum - The frustum
1290
- * @param point - The point
1291
- * @returns The containment type
1292
- */ CollisionUtil.frustumContainsPoint = function frustumContainsPoint(frustum, point) {
1293
- var distance = CollisionUtil.distancePlaneAndPoint(frustum.near, point);
1294
- if (Math.abs(distance) < MathUtil.zeroTolerance) {
1295
- return ContainmentType.Intersects;
1296
- } else if (distance < 0) {
1297
- return ContainmentType.Disjoint;
1298
- }
1299
- distance = CollisionUtil.distancePlaneAndPoint(frustum.far, point);
1300
- if (Math.abs(distance) < MathUtil.zeroTolerance) {
1301
- return ContainmentType.Intersects;
1302
- } else if (distance < 0) {
1303
- return ContainmentType.Disjoint;
1304
- }
1305
- distance = CollisionUtil.distancePlaneAndPoint(frustum.left, point);
1306
- if (Math.abs(distance) < MathUtil.zeroTolerance) {
1307
- return ContainmentType.Intersects;
1308
- } else if (distance < 0) {
1309
- return ContainmentType.Disjoint;
1310
- }
1311
- distance = CollisionUtil.distancePlaneAndPoint(frustum.right, point);
1312
- if (Math.abs(distance) < MathUtil.zeroTolerance) {
1313
- return ContainmentType.Intersects;
1314
- } else if (distance < 0) {
1315
- return ContainmentType.Disjoint;
1316
- }
1317
- distance = CollisionUtil.distancePlaneAndPoint(frustum.top, point);
1318
- if (Math.abs(distance) < MathUtil.zeroTolerance) {
1319
- return ContainmentType.Intersects;
1320
- } else if (distance < 0) {
1321
- return ContainmentType.Disjoint;
1322
- }
1323
- distance = CollisionUtil.distancePlaneAndPoint(frustum.bottom, point);
1324
- if (Math.abs(distance) < MathUtil.zeroTolerance) {
1325
- return ContainmentType.Intersects;
1326
- } else if (distance < 0) {
1327
- return ContainmentType.Disjoint;
1328
- }
1329
- return ContainmentType.Contains;
1330
- };
1331
- /**
1332
- * Get the containment type between a frustum and a box (AABB).
1333
- * @param frustum - The frustum
1334
- * @param box - The box
1335
- * @returns The containment type
1336
- */ CollisionUtil.frustumContainsBox = function frustumContainsBox(frustum, box) {
1337
- var min = box.min, max = box.max;
1338
- var p = CollisionUtil._tempVec30;
1339
- var n = CollisionUtil._tempVec31;
1340
- var result = ContainmentType.Contains;
1341
- for(var i = 0; i < 6; ++i){
1342
- var plane = frustum.getPlane(i);
1343
- var normal = plane.normal;
1344
- if (normal.x >= 0) {
1345
- p.x = max.x;
1346
- n.x = min.x;
1347
- } else {
1348
- p.x = min.x;
1349
- n.x = max.x;
1350
- }
1351
- if (normal.y >= 0) {
1352
- p.y = max.y;
1353
- n.y = min.y;
1354
- } else {
1355
- p.y = min.y;
1356
- n.y = max.y;
1357
- }
1358
- if (normal.z >= 0) {
1359
- p.z = max.z;
1360
- n.z = min.z;
1361
- } else {
1362
- p.z = min.z;
1363
- n.z = max.z;
1364
- }
1365
- if (CollisionUtil.intersectsPlaneAndPoint(plane, p) === PlaneIntersectionType.Back) {
1366
- return ContainmentType.Disjoint;
1367
- }
1368
- if (CollisionUtil.intersectsPlaneAndPoint(plane, n) === PlaneIntersectionType.Back) {
1369
- result = ContainmentType.Intersects;
1370
- }
1371
- }
1372
- return result;
1373
- };
1374
- /**
1375
- * Get the containment type between a frustum and a sphere.
1376
- * @param frustum - The frustum
1377
- * @param sphere - The sphere
1378
- * @returns The containment type
1379
- */ CollisionUtil.frustumContainsSphere = function frustumContainsSphere(frustum, sphere) {
1380
- var result = ContainmentType.Contains;
1381
- for(var i = 0; i < 6; ++i){
1382
- var plane = frustum.getPlane(i);
1383
- var intersectionType = CollisionUtil.intersectsPlaneAndSphere(plane, sphere);
1384
- if (intersectionType === PlaneIntersectionType.Back) {
1385
- return ContainmentType.Disjoint;
1386
- } else if (intersectionType === PlaneIntersectionType.Intersecting) {
1387
- result = ContainmentType.Intersects;
1388
- break;
1389
- }
1390
- }
1391
- return result;
1392
- };
1393
- return CollisionUtil;
1394
- }();
1395
- (function() {
1396
- CollisionUtil._tempVec30 = new Vector3();
1397
- })();
1398
- (function() {
1399
- CollisionUtil._tempVec31 = new Vector3();
1400
- })();
1401
- (function() {
1402
- CollisionUtil._tempVec32 = new Vector3();
1403
- })();
727
+ /** @internal */ Vector3._zero = new Vector3(0.0, 0.0, 0.0);
728
+ /** @internal */ Vector3._one = new Vector3(1.0, 1.0, 1.0);
729
+ new Vector3();
730
+ new Vector3();
731
+ new Vector3();
732
+ new Vector3();
733
+ new Vector3();
734
+ new Vector3();
1404
735
  /**
1405
736
  * Represents a 3x3 mathematical matrix.
1406
737
  */ var Matrix3x3 = /*#__PURE__*/ function() {
1407
- var Matrix3x3 = function Matrix3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33) {
738
+ function Matrix3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33) {
1408
739
  if (m11 === void 0) m11 = 1;
1409
740
  if (m12 === void 0) m12 = 0;
1410
741
  if (m13 === void 0) m13 = 0;
@@ -1433,7 +764,7 @@ function _create_class(Constructor, protoProps, staticProps) {
1433
764
  e[6] = m31;
1434
765
  e[7] = m32;
1435
766
  e[8] = m33;
1436
- };
767
+ }
1437
768
  var _proto = Matrix3x3.prototype;
1438
769
  /**
1439
770
  * Set the value of this matrix, and return this matrix.
@@ -1946,7 +1277,7 @@ function _create_class(Constructor, protoProps, staticProps) {
1946
1277
  /**
1947
1278
  * Represents a four dimensional mathematical quaternion.
1948
1279
  */ var Quaternion = /*#__PURE__*/ function() {
1949
- var Quaternion = function Quaternion(x, y, z, w) {
1280
+ function Quaternion(x, y, z, w) {
1950
1281
  if (x === void 0) x = 0;
1951
1282
  if (y === void 0) y = 0;
1952
1283
  if (z === void 0) z = 0;
@@ -1956,7 +1287,7 @@ function _create_class(Constructor, protoProps, staticProps) {
1956
1287
  this._y = y;
1957
1288
  this._z = z;
1958
1289
  this._w = w;
1959
- };
1290
+ }
1960
1291
  var _proto = Quaternion.prototype;
1961
1292
  /**
1962
1293
  * Set the value of this quaternion, and return this quaternion.
@@ -2602,16 +1933,12 @@ function _create_class(Constructor, protoProps, staticProps) {
2602
1933
  ]);
2603
1934
  return Quaternion;
2604
1935
  }();
2605
- (function() {
2606
- /** @internal */ Quaternion._tempVector3 = new Vector3();
2607
- })();
2608
- (function() {
2609
- /** @internal */ Quaternion._tempQuat1 = new Quaternion();
2610
- })();
1936
+ /** @internal */ Quaternion._tempVector3 = new Vector3();
1937
+ /** @internal */ Quaternion._tempQuat1 = new Quaternion();
2611
1938
  /**
2612
1939
  * Represents a 4x4 mathematical matrix.
2613
1940
  */ var Matrix = /*#__PURE__*/ function() {
2614
- var Matrix = function Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
1941
+ function Matrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
2615
1942
  if (m11 === void 0) m11 = 1;
2616
1943
  if (m12 === void 0) m12 = 0;
2617
1944
  if (m13 === void 0) m13 = 0;
@@ -2655,7 +1982,7 @@ function _create_class(Constructor, protoProps, staticProps) {
2655
1982
  e[13] = m42;
2656
1983
  e[14] = m43;
2657
1984
  e[15] = m44;
2658
- };
1985
+ }
2659
1986
  var _proto = Matrix.prototype;
2660
1987
  /**
2661
1988
  * Set the value of this matrix, and return this matrix.
@@ -3547,897 +2874,107 @@ function _create_class(Constructor, protoProps, staticProps) {
3547
2874
  };
3548
2875
  return Matrix;
3549
2876
  }();
3550
- (function() {
3551
- Matrix._tempVec30 = new Vector3();
3552
- })();
3553
- (function() {
3554
- Matrix._tempVec31 = new Vector3();
3555
- })();
3556
- (function() {
3557
- Matrix._tempVec32 = new Vector3();
3558
- })();
3559
- (function() {
3560
- Matrix._tempMat30 = new Matrix3x3();
3561
- })();
3562
- (function() {
3563
- /** @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);
3564
- })();
3565
- /**
3566
- * Describes a 2D-vector.
3567
- */ var Vector2 = /*#__PURE__*/ function() {
3568
- var Vector2 = function Vector2(x, y) {
3569
- if (x === void 0) x = 0;
3570
- if (y === void 0) y = 0;
3571
- /** @internal */ this._onValueChanged = null;
3572
- this._x = x;
3573
- this._y = y;
3574
- };
3575
- var _proto = Vector2.prototype;
3576
- /**
3577
- * Set the value of this vector.
3578
- * @param x - The x component of the vector
3579
- * @param y - The y component of the vector
3580
- * @returns This vector
3581
- */ _proto.set = function set(x, y) {
3582
- this._x = x;
3583
- this._y = y;
3584
- this._onValueChanged && this._onValueChanged();
3585
- return this;
2877
+ Matrix._tempVec30 = new Vector3();
2878
+ Matrix._tempVec31 = new Vector3();
2879
+ Matrix._tempVec32 = new Vector3();
2880
+ Matrix._tempMat30 = new Matrix3x3();
2881
+ /** @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);
2882
+
2883
+ var WebXRFrame = /*#__PURE__*/ function() {
2884
+ function WebXRFrame(session) {
2885
+ this._session = session;
2886
+ }
2887
+ var _proto = WebXRFrame.prototype;
2888
+ _proto.updateInputs = function updateInputs(inputs) {
2889
+ if (!this._platformFrame) return;
2890
+ this._updateController(inputs);
2891
+ this._updateCamera(inputs);
3586
2892
  };
3587
- /**
3588
- * Determines the sum of this vector and the specified vector.
3589
- * @param right - The specified vector
3590
- * @returns This vector
3591
- */ _proto.add = function add(right) {
3592
- this._x += right._x;
3593
- this._y += right._y;
3594
- this._onValueChanged && this._onValueChanged();
3595
- return this;
2893
+ _proto._updateController = function _updateController(inputs) {
2894
+ var _this = this, frame = _this._platformFrame;
2895
+ var _this__session = this._session, session = _this__session._platformSession, referenceSpace = _this__session._platformReferenceSpace;
2896
+ var inputSources = session.inputSources;
2897
+ for(var i = 0, n = inputSources.length; i < n; i++){
2898
+ var inputSource = inputSources[i];
2899
+ var type = getInputSource(inputSource);
2900
+ var input = inputs[type];
2901
+ switch(inputSource.targetRayMode){
2902
+ case "screen":
2903
+ case "tracked-pointer":
2904
+ var gripSpace = inputSource.gripSpace, targetRaySpace = inputSource.targetRaySpace;
2905
+ if (gripSpace) {
2906
+ var _frame_getPose = frame.getPose(gripSpace, referenceSpace), transform = _frame_getPose.transform, emulatedPosition = _frame_getPose.emulatedPosition;
2907
+ if (transform) {
2908
+ var gripPose = input.gripPose;
2909
+ gripPose.matrix.copyFromArray(transform.matrix);
2910
+ gripPose.position.copyFrom(transform.position);
2911
+ gripPose.rotation.copyFrom(transform.orientation);
2912
+ }
2913
+ input.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2914
+ }
2915
+ if (targetRaySpace) {
2916
+ var _frame_getPose1 = frame.getPose(targetRaySpace, referenceSpace), transform1 = _frame_getPose1.transform, emulatedPosition1 = _frame_getPose1.emulatedPosition;
2917
+ if (transform1) {
2918
+ var targetRayPose = input.targetRayPose;
2919
+ targetRayPose.matrix.copyFromArray(transform1.matrix);
2920
+ targetRayPose.position.copyFrom(transform1.position);
2921
+ targetRayPose.rotation.copyFrom(transform1.orientation);
2922
+ input.trackingState = emulatedPosition1 ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2923
+ }
2924
+ }
2925
+ break;
2926
+ }
2927
+ }
3596
2928
  };
3597
- /**
3598
- * Determines the difference of this vector and the specified vector.
3599
- * @param right - The specified vector
3600
- * @returns This vector
3601
- */ _proto.subtract = function subtract(right) {
3602
- this._x -= right._x;
3603
- this._y -= right._y;
3604
- this._onValueChanged && this._onValueChanged();
3605
- return this;
3606
- };
3607
- /**
3608
- * Determines the product of this vector and the specified vector.
3609
- * @param right - The specified vector
3610
- * @returns This vector
3611
- */ _proto.multiply = function multiply(right) {
3612
- this._x *= right._x;
3613
- this._y *= right._y;
3614
- this._onValueChanged && this._onValueChanged();
3615
- return this;
3616
- };
3617
- /**
3618
- * Determines the divisor of this vector and the specified vector.
3619
- * @param right - The specified vector
3620
- * @returns This vector
3621
- */ _proto.divide = function divide(right) {
3622
- this._x /= right._x;
3623
- this._y /= right._y;
3624
- this._onValueChanged && this._onValueChanged();
3625
- return this;
3626
- };
3627
- /**
3628
- * Calculate the length of this vector.
3629
- * @returns The length of this vector
3630
- */ _proto.length = function length() {
3631
- var _this = this, _x = _this._x, _y = _this._y;
3632
- return Math.sqrt(_x * _x + _y * _y);
3633
- };
3634
- /**
3635
- * Calculate the squared length of this vector.
3636
- * @returns The squared length of this vector
3637
- */ _proto.lengthSquared = function lengthSquared() {
3638
- var _this = this, _x = _this._x, _y = _this._y;
3639
- return _x * _x + _y * _y;
3640
- };
3641
- /**
3642
- * Reverses the direction of this vector.
3643
- * @returns This vector
3644
- */ _proto.negate = function negate() {
3645
- this._x = -this._x;
3646
- this._y = -this._y;
3647
- this._onValueChanged && this._onValueChanged();
3648
- return this;
3649
- };
3650
- /**
3651
- * Converts this vector into a unit vector.
3652
- * @returns This vector
3653
- */ _proto.normalize = function normalize() {
3654
- Vector2.normalize(this, this);
3655
- return this;
3656
- };
3657
- /**
3658
- * Scale this vector by the given value.
3659
- * @param s - The amount by which to scale the vector
3660
- * @returns This vector
3661
- */ _proto.scale = function scale(s) {
3662
- this._x *= s;
3663
- this._y *= s;
3664
- this._onValueChanged && this._onValueChanged();
3665
- return this;
3666
- };
3667
- /**
3668
- * Creates a clone of this vector.
3669
- * @returns A clone of this vector
3670
- */ _proto.clone = function clone() {
3671
- return new Vector2(this._x, this._y);
3672
- };
3673
- /**
3674
- * Copy from vector2 like object.
3675
- * @param source - Vector2 like object
3676
- * @returns This vector
3677
- */ _proto.copyFrom = function copyFrom(source) {
3678
- this._x = source.x;
3679
- this._y = source.y;
3680
- this._onValueChanged && this._onValueChanged();
3681
- return this;
3682
- };
3683
- /**
3684
- * Copy to vector2 like object.
3685
- * @param target - Vector2 like object
3686
- * @returns This Vector2 like object
3687
- */ _proto.copyTo = function copyTo(target) {
3688
- target.x = this._x;
3689
- target.y = this._y;
3690
- return target;
3691
- };
3692
- /**
3693
- * Copy the value of this vector from an array.
3694
- * @param array - The array
3695
- * @param offset - The start offset of the array
3696
- * @returns This vector
3697
- */ _proto.copyFromArray = function copyFromArray(array, offset) {
3698
- if (offset === void 0) offset = 0;
3699
- this._x = array[offset];
3700
- this._y = array[offset + 1];
3701
- this._onValueChanged && this._onValueChanged();
3702
- return this;
3703
- };
3704
- /**
3705
- * Copy the value of this vector to an array.
3706
- * @param out - The array
3707
- * @param outOffset - The start offset of the array
3708
- */ _proto.copyToArray = function copyToArray(out, outOffset) {
3709
- if (outOffset === void 0) outOffset = 0;
3710
- out[outOffset] = this._x;
3711
- out[outOffset + 1] = this._y;
3712
- };
3713
- /**
3714
- * Serialize this vector to a JSON representation.
3715
- * @returns A JSON representation of this vector
3716
- */ _proto.toJSON = function toJSON() {
3717
- return {
3718
- x: this._x,
3719
- y: this._y
3720
- };
3721
- };
3722
- /**
3723
- * Determines the sum of two vectors.
3724
- * @param left - The first vector to add
3725
- * @param right - The second vector to add
3726
- * @param out - The sum of two vectors
3727
- */ Vector2.add = function add(left, right, out) {
3728
- out._x = left._x + right._x;
3729
- out._y = left._y + right._y;
3730
- out._onValueChanged && out._onValueChanged();
3731
- };
3732
- /**
3733
- * Determines the difference between two vectors.
3734
- * @param left - The first vector to subtract
3735
- * @param right - The second vector to subtract
3736
- * @param out - The difference between two vectors
3737
- */ Vector2.subtract = function subtract(left, right, out) {
3738
- out._x = left._x - right._x;
3739
- out._y = left._y - right._y;
3740
- out._onValueChanged && out._onValueChanged();
3741
- };
3742
- /**
3743
- * Determines the product of two vectors.
3744
- * @param left - The first vector to multiply
3745
- * @param right - The second vector to multiply
3746
- * @param out - The product of two vectors
3747
- */ Vector2.multiply = function multiply(left, right, out) {
3748
- out._x = left._x * right._x;
3749
- out._y = left._y * right._y;
3750
- out._onValueChanged && out._onValueChanged();
3751
- };
3752
- /**
3753
- * Determines the divisor of two vectors.
3754
- * @param left - The first vector to divide
3755
- * @param right - The second vector to divide
3756
- * @param out - The divisor of two vectors
3757
- */ Vector2.divide = function divide(left, right, out) {
3758
- out._x = left._x / right._x;
3759
- out._y = left._y / right._y;
3760
- out._onValueChanged && out._onValueChanged();
3761
- };
3762
- /**
3763
- * Determines the dot product of two vectors.
3764
- * @param left - The first vector to dot
3765
- * @param right - The second vector to dot
3766
- * @returns The dot product of two vectors
3767
- */ Vector2.dot = function dot(left, right) {
3768
- return left._x * right._x + left._y * right._y;
3769
- };
3770
- /**
3771
- * Determines the distance of two vectors.
3772
- * @param left - The first vector
3773
- * @param right - The second vector
3774
- * @returns The distance of two vectors
3775
- */ Vector2.distance = function distance(left, right) {
3776
- var x = right._x - left._x;
3777
- var y = right._y - left._y;
3778
- return Math.sqrt(x * x + y * y);
3779
- };
3780
- /**
3781
- * Determines the squared distance of two vectors.
3782
- * @param left - The first vector
3783
- * @param right - The second vector
3784
- * @returns The squared distance of two vectors
3785
- */ Vector2.distanceSquared = function distanceSquared(left, right) {
3786
- var x = right._x - left._x;
3787
- var y = right._y - left._y;
3788
- return x * x + y * y;
3789
- };
3790
- /**
3791
- * Determines whether the specified vectors are equals.
3792
- * @param left - The first vector to compare
3793
- * @param right - The second vector to compare
3794
- * @returns True if the specified vectors are equals, false otherwise
3795
- */ Vector2.equals = function equals(left, right) {
3796
- return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y);
3797
- };
3798
- /**
3799
- * Performs a linear interpolation between two vectors.
3800
- * @param left - The first vector
3801
- * @param right - The second vector
3802
- * @param t - The blend amount where 0 returns left and 1 right
3803
- * @param out - The result of linear blending between two vectors
3804
- */ Vector2.lerp = function lerp(left, right, t, out) {
3805
- var _x = left._x, _y = left._y;
3806
- out._x = _x + (right._x - _x) * t;
3807
- out._y = _y + (right._y - _y) * t;
3808
- out._onValueChanged && out._onValueChanged();
3809
- };
3810
- /**
3811
- * Calculate a vector containing the largest components of the specified vectors.
3812
- * @param left - The first vector
3813
- * @param right - The second vector
3814
- * @param out - The vector containing the largest components of the specified vectors
3815
- */ Vector2.max = function max(left, right, out) {
3816
- out._x = Math.max(left._x, right._x);
3817
- out._y = Math.max(left._y, right._y);
3818
- out._onValueChanged && out._onValueChanged();
3819
- };
3820
- /**
3821
- * Calculate a vector containing the smallest components of the specified vectors.
3822
- * @param left - The first vector
3823
- * @param right - The second vector
3824
- * @param out - The vector containing the smallest components of the specified vectors
3825
- */ Vector2.min = function min(left, right, out) {
3826
- out._x = Math.min(left._x, right._x);
3827
- out._y = Math.min(left._y, right._y);
3828
- out._onValueChanged && out._onValueChanged();
3829
- };
3830
- /**
3831
- * Reverses the direction of a given vector.
3832
- * @param left - The vector to negate
3833
- * @param out - The vector facing in the opposite direction
3834
- */ Vector2.negate = function negate(left, out) {
3835
- out._x = -left._x;
3836
- out._y = -left._y;
3837
- out._onValueChanged && out._onValueChanged();
3838
- };
3839
- /**
3840
- * Converts the vector into a unit vector.
3841
- * @param left - The vector to normalize
3842
- * @param out - The normalized vector
3843
- */ Vector2.normalize = function normalize(left, out) {
3844
- var _x = left._x, _y = left._y;
3845
- var len = Math.sqrt(_x * _x + _y * _y);
3846
- if (len > MathUtil.zeroTolerance) {
3847
- len = 1 / len;
3848
- out._x = _x * len;
3849
- out._y = _y * len;
3850
- out._onValueChanged && out._onValueChanged();
3851
- }
3852
- };
3853
- /**
3854
- * Scale a vector by the given value.
3855
- * @param left - The vector to scale
3856
- * @param s - The amount by which to scale the vector
3857
- * @param out - The scaled vector
3858
- */ Vector2.scale = function scale(left, s, out) {
3859
- out._x = left._x * s;
3860
- out._y = left._y * s;
3861
- out._onValueChanged && out._onValueChanged();
3862
- };
3863
- _create_class(Vector2, [
3864
- {
3865
- key: "x",
3866
- get: /**
3867
- * The x component of the vector.
3868
- */ function get() {
3869
- return this._x;
3870
- },
3871
- set: function set(value) {
3872
- this._x = value;
3873
- this._onValueChanged && this._onValueChanged();
3874
- }
3875
- },
3876
- {
3877
- key: "y",
3878
- get: /**
3879
- * The y component of the vector.
3880
- */ function get() {
3881
- return this._y;
3882
- },
3883
- set: function set(value) {
3884
- this._y = value;
3885
- this._onValueChanged && this._onValueChanged();
3886
- }
3887
- }
3888
- ]);
3889
- return Vector2;
3890
- }();
3891
- (function() {
3892
- /** @internal */ Vector2._zero = new Vector2(0.0, 0.0);
3893
- })();
3894
- (function() {
3895
- /** @internal */ Vector2._one = new Vector2(1.0, 1.0);
3896
- })();
3897
- /**
3898
- * Describes a 4D-vector.
3899
- */ var Vector4 = /*#__PURE__*/ function() {
3900
- var Vector4 = function Vector4(x, y, z, w) {
3901
- if (x === void 0) x = 0;
3902
- if (y === void 0) y = 0;
3903
- if (z === void 0) z = 0;
3904
- if (w === void 0) w = 0;
3905
- /** @internal */ this._onValueChanged = null;
3906
- this._x = x;
3907
- this._y = y;
3908
- this._z = z;
3909
- this._w = w;
3910
- };
3911
- var _proto = Vector4.prototype;
3912
- /**
3913
- * Set the value of this vector.
3914
- * @param x - The x component of the vector
3915
- * @param y - The y component of the vector
3916
- * @param z - The z component of the vector
3917
- * @param w - The w component of the vector
3918
- * @returns This vector
3919
- */ _proto.set = function set(x, y, z, w) {
3920
- this._x = x;
3921
- this._y = y;
3922
- this._z = z;
3923
- this._w = w;
3924
- this._onValueChanged && this._onValueChanged();
3925
- return this;
3926
- };
3927
- /**
3928
- * Determines the sum of this vector and the specified vector.
3929
- * @param right - The specified vector
3930
- * @returns This vector
3931
- */ _proto.add = function add(right) {
3932
- this._x += right._x;
3933
- this._y += right._y;
3934
- this._z += right._z;
3935
- this._w += right._w;
3936
- this._onValueChanged && this._onValueChanged();
3937
- return this;
3938
- };
3939
- /**
3940
- * Determines the difference of this vector and the specified vector.
3941
- * @param right - the specified vector
3942
- * @returns This vector
3943
- */ _proto.subtract = function subtract(right) {
3944
- this._x -= right._x;
3945
- this._y -= right._y;
3946
- this._z -= right._z;
3947
- this._w -= right._w;
3948
- this._onValueChanged && this._onValueChanged();
3949
- return this;
3950
- };
3951
- /**
3952
- * Determines the product of this vector and the specified vector.
3953
- * @param right - the specified vector
3954
- * @returns This vector
3955
- */ _proto.multiply = function multiply(right) {
3956
- this._x *= right._x;
3957
- this._y *= right._y;
3958
- this._z *= right._z;
3959
- this._w *= right._w;
3960
- this._onValueChanged && this._onValueChanged();
3961
- return this;
3962
- };
3963
- /**
3964
- * Determines the divisor of this vector and the specified vector.
3965
- * @param right - the specified vector
3966
- * @returns This vector
3967
- */ _proto.divide = function divide(right) {
3968
- this._x /= right._x;
3969
- this._y /= right._y;
3970
- this._z /= right._z;
3971
- this._w /= right._w;
3972
- this._onValueChanged && this._onValueChanged();
3973
- return this;
3974
- };
3975
- /**
3976
- * Calculate the length of this vector.
3977
- * @returns The length of this vector
3978
- */ _proto.length = function length() {
3979
- var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
3980
- return Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
3981
- };
3982
- /**
3983
- * Calculate the squared length of this vector.
3984
- * @returns The squared length of this vector
3985
- */ _proto.lengthSquared = function lengthSquared() {
3986
- var _this = this, _x = _this._x, _y = _this._y, _z = _this._z, _w = _this._w;
3987
- return _x * _x + _y * _y + _z * _z + _w * _w;
3988
- };
3989
- /**
3990
- * Reverses the direction of this vector.
3991
- * @returns This vector
3992
- */ _proto.negate = function negate() {
3993
- this._x = -this._x;
3994
- this._y = -this._y;
3995
- this._z = -this._z;
3996
- this._w = -this._w;
3997
- this._onValueChanged && this._onValueChanged();
3998
- return this;
3999
- };
4000
- /**
4001
- * Converts this vector into a unit vector.
4002
- * @returns This vector
4003
- */ _proto.normalize = function normalize() {
4004
- Vector4.normalize(this, this);
4005
- return this;
4006
- };
4007
- /**
4008
- * Scale this vector by the given value.
4009
- * @param s - The amount by which to scale the vector
4010
- * @returns This vector
4011
- */ _proto.scale = function scale(s) {
4012
- this._x *= s;
4013
- this._y *= s;
4014
- this._z *= s;
4015
- this._w *= s;
4016
- this._onValueChanged && this._onValueChanged();
4017
- return this;
4018
- };
4019
- /**
4020
- * Creates a clone of this vector.
4021
- * @returns A clone of this vector
4022
- */ _proto.clone = function clone() {
4023
- var ret = new Vector4(this._x, this._y, this._z, this._w);
4024
- return ret;
4025
- };
4026
- /**
4027
- * Copy from vector3 like object.
4028
- * @param source - Vector3 like object.
4029
- * @returns This vector
4030
- */ _proto.copyFrom = function copyFrom(source) {
4031
- this._x = source.x;
4032
- this._y = source.y;
4033
- this._z = source.z;
4034
- this._w = source.w;
4035
- this._onValueChanged && this._onValueChanged();
4036
- return this;
4037
- };
4038
- /**
4039
- * Copy to vector4 like object.
4040
- * @param target - Vector4 like object
4041
- * @returns This Vector4 like object
4042
- */ _proto.copyTo = function copyTo(target) {
4043
- target.x = this._x;
4044
- target.y = this._y;
4045
- target.z = this._z;
4046
- target.w = this._w;
4047
- return target;
4048
- };
4049
- /**
4050
- * Copy the value of this vector by an array.
4051
- * @param array - The array
4052
- * @param offset - The start offset of the array
4053
- * @returns This vector
4054
- */ _proto.copyFromArray = function copyFromArray(array, offset) {
4055
- if (offset === void 0) offset = 0;
4056
- this._x = array[offset];
4057
- this._y = array[offset + 1];
4058
- this._z = array[offset + 2];
4059
- this._w = array[offset + 3];
4060
- this._onValueChanged && this._onValueChanged();
4061
- return this;
4062
- };
4063
- /**
4064
- * Copy the value of this vector to an array.
4065
- * @param out - The array
4066
- * @param outOffset - The start offset of the array
4067
- */ _proto.copyToArray = function copyToArray(out, outOffset) {
4068
- if (outOffset === void 0) outOffset = 0;
4069
- out[outOffset] = this._x;
4070
- out[outOffset + 1] = this._y;
4071
- out[outOffset + 2] = this._z;
4072
- out[outOffset + 3] = this._w;
4073
- };
4074
- /**
4075
- * Serialize this vector to a JSON representation.
4076
- * @returns A JSON representation of this vector
4077
- */ _proto.toJSON = function toJSON() {
4078
- return {
4079
- x: this._x,
4080
- y: this._y,
4081
- z: this._z,
4082
- w: this._w
4083
- };
4084
- };
4085
- /**
4086
- * Determines the sum of two vectors.
4087
- * @param left - The first vector to add
4088
- * @param right - The second vector to add
4089
- * @param out - The sum of two vectors
4090
- */ Vector4.add = function add(left, right, out) {
4091
- out._x = left._x + right._x;
4092
- out._y = left._y + right._y;
4093
- out._z = left._z + right._z;
4094
- out._w = left._w + right._w;
4095
- out._onValueChanged && out._onValueChanged();
4096
- };
4097
- /**
4098
- * Determines the difference between two vectors.
4099
- * @param left - The first vector to subtract
4100
- * @param right - The second vector to subtract
4101
- * @param out - The difference between two vectors
4102
- */ Vector4.subtract = function subtract(left, right, out) {
4103
- out._x = left._x - right._x;
4104
- out._y = left._y - right._y;
4105
- out._z = left._z - right._z;
4106
- out._w = left._w - right._w;
4107
- out._onValueChanged && out._onValueChanged();
4108
- };
4109
- /**
4110
- * Determines the product of two vectors.
4111
- * @param left - The first vector to multiply
4112
- * @param right - The second vector to multiply
4113
- * @param out - The product of two vectors
4114
- */ Vector4.multiply = function multiply(left, right, out) {
4115
- out._x = left._x * right._x;
4116
- out._y = left._y * right._y;
4117
- out._z = left._z * right._z;
4118
- out._w = left._w * right._w;
4119
- out._onValueChanged && out._onValueChanged();
4120
- };
4121
- /**
4122
- * Determines the divisor of two vectors.
4123
- * @param left - The first vector to divide
4124
- * @param right - The second vector to divide
4125
- * @param out - The divisor of two vectors
4126
- */ Vector4.divide = function divide(left, right, out) {
4127
- out._x = left._x / right._x;
4128
- out._y = left._y / right._y;
4129
- out._z = left._z / right._z;
4130
- out._w = left._w / right._w;
4131
- out._onValueChanged && out._onValueChanged();
4132
- };
4133
- /**
4134
- * Determines the dot product of two vectors.
4135
- * @param left - The first vector to dot
4136
- * @param right - The second vector to dot
4137
- * @returns The dot product of two vectors
4138
- */ Vector4.dot = function dot(left, right) {
4139
- return left._x * right._x + left._y * right._y + left._z * right._z + left._w * right._w;
4140
- };
4141
- /**
4142
- * Determines the distance of two vectors.
4143
- * @param a - The first vector
4144
- * @param b - The second vector
4145
- * @returns The distance of two vectors
4146
- */ Vector4.distance = function distance(a, b) {
4147
- var x = b._x - a._x;
4148
- var y = b._y - a._y;
4149
- var z = b._z - a._z;
4150
- var w = b._w - a._w;
4151
- return Math.sqrt(x * x + y * y + z * z + w * w);
4152
- };
4153
- /**
4154
- * Determines the squared distance of two vectors.
4155
- * @param a - The first vector
4156
- * @param b - The second vector
4157
- * @returns The squared distance of two vectors
4158
- */ Vector4.distanceSquared = function distanceSquared(a, b) {
4159
- var x = b._x - a._x;
4160
- var y = b._y - a._y;
4161
- var z = b._z - a._z;
4162
- var w = b._w - a._w;
4163
- return x * x + y * y + z * z + w * w;
4164
- };
4165
- /**
4166
- * Determines whether the specified vectors are equals.
4167
- * @param left - The first vector to compare
4168
- * @param right - The second vector to compare
4169
- * @returns True if the specified vectors are equals, false otherwise
4170
- */ Vector4.equals = function equals(left, right) {
4171
- return MathUtil.equals(left._x, right._x) && MathUtil.equals(left._y, right._y) && MathUtil.equals(left._z, right._z) && MathUtil.equals(left._w, right._w);
4172
- };
4173
- /**
4174
- * Performs a linear interpolation between two vectors.
4175
- * @param start - The first vector
4176
- * @param end - The second vector
4177
- * @param t - The blend amount where 0 returns start and 1 end
4178
- * @param out - The result of linear blending between two vectors
4179
- */ Vector4.lerp = function lerp(start, end, t, out) {
4180
- var _x = start._x, _y = start._y, _z = start._z, _w = start._w;
4181
- out._x = _x + (end._x - _x) * t;
4182
- out._y = _y + (end._y - _y) * t;
4183
- out._z = _z + (end._z - _z) * t;
4184
- out._w = _w + (end._w - _w) * t;
4185
- out._onValueChanged && out._onValueChanged();
4186
- };
4187
- /**
4188
- * Calculate a vector containing the largest components of the specified vectors.
4189
- * @param left - The first vector
4190
- * @param right - The second vector
4191
- * @param out - The vector containing the largest components of the specified vectors
4192
- */ Vector4.max = function max(left, right, out) {
4193
- out._x = Math.max(left._x, right._x);
4194
- out._y = Math.max(left._y, right._y);
4195
- out._z = Math.max(left._z, right._z);
4196
- out._w = Math.max(left._w, right._w);
4197
- out._onValueChanged && out._onValueChanged();
4198
- };
4199
- /**
4200
- * Calculate a vector containing the smallest components of the specified vectors.
4201
- * @param left - The first vector
4202
- * @param right - The second vector
4203
- * @param out - The vector containing the smallest components of the specified vectors
4204
- */ Vector4.min = function min(left, right, out) {
4205
- out._x = Math.min(left._x, right._x);
4206
- out._y = Math.min(left._y, right._y);
4207
- out._z = Math.min(left._z, right._z);
4208
- out._w = Math.min(left._w, right._w);
4209
- out._onValueChanged && out._onValueChanged();
4210
- };
4211
- /**
4212
- * Reverses the direction of a given vector.
4213
- * @param a - The vector to negate
4214
- * @param out - The vector facing in the opposite direction
4215
- */ Vector4.negate = function negate(a, out) {
4216
- out._x = -a._x;
4217
- out._y = -a._y;
4218
- out._z = -a._z;
4219
- out._w = -a._w;
4220
- out._onValueChanged && out._onValueChanged();
4221
- };
4222
- /**
4223
- * Converts the vector into a unit vector.
4224
- * @param a - The vector to normalize
4225
- * @param out - The normalized vector
4226
- */ Vector4.normalize = function normalize(a, out) {
4227
- var _x = a._x, _y = a._y, _z = a._z, _w = a._w;
4228
- var len = Math.sqrt(_x * _x + _y * _y + _z * _z + _w * _w);
4229
- if (len > MathUtil.zeroTolerance) {
4230
- len = 1 / len;
4231
- out._x = _x * len;
4232
- out._y = _y * len;
4233
- out._z = _z * len;
4234
- out._w = _w * len;
4235
- out._onValueChanged && out._onValueChanged();
4236
- }
4237
- };
4238
- /**
4239
- * Scale a vector by the given value.
4240
- * @param a - The vector to scale
4241
- * @param s - The amount by which to scale the vector
4242
- * @param out - The scaled vector
4243
- */ Vector4.scale = function scale(a, s, out) {
4244
- out._x = a._x * s;
4245
- out._y = a._y * s;
4246
- out._z = a._z * s;
4247
- out._w = a._w * s;
4248
- out._onValueChanged && out._onValueChanged();
4249
- };
4250
- /**
4251
- * Performs a transformation using the given 4x4 matrix.
4252
- * @param v - The vector to transform
4253
- * @param m - The transform matrix
4254
- * @param out - The transformed vector3
4255
- */ Vector4.transform = function transform(v, m, out) {
4256
- var _x = v._x, _y = v._y, _z = v._z, _w = v._w;
4257
- var e = m.elements;
4258
- out._x = _x * e[0] + _y * e[4] + _z * e[8] + _w * e[12];
4259
- out._y = _x * e[1] + _y * e[5] + _z * e[9] + _w * e[13];
4260
- out._z = _x * e[2] + _y * e[6] + _z * e[10] + _w * e[14];
4261
- out._w = _x * e[3] + _y * e[7] + _z * e[11] + _w * e[15];
4262
- out._onValueChanged && out._onValueChanged();
4263
- };
4264
- /**
4265
- * Performs a transformation using the given quaternion.
4266
- * @param v - The vector to transform
4267
- * @param q - The transform quaternion
4268
- * @param out - The transformed vector
4269
- */ Vector4.transformByQuat = function transformByQuat(v, q, out) {
4270
- var x = v._x, y = v._y, z = v._z, w = v._w;
4271
- var qx = q._x;
4272
- var qy = q._y;
4273
- var qz = q._z;
4274
- var qw = q._w;
4275
- // calculate quat * vec
4276
- var ix = qw * x + qy * z - qz * y;
4277
- var iy = qw * y + qz * x - qx * z;
4278
- var iz = qw * z + qx * y - qy * x;
4279
- var iw = -qx * x - qy * y - qz * z;
4280
- // calculate result * inverse quat
4281
- out._x = ix * qw - iw * qx - iy * qz + iz * qy;
4282
- out._y = iy * qw - iw * qy - iz * qx + ix * qz;
4283
- out._z = iz * qw - iw * qz - ix * qy + iy * qx;
4284
- out._w = w;
4285
- out._onValueChanged && out._onValueChanged();
4286
- };
4287
- _create_class(Vector4, [
4288
- {
4289
- key: "x",
4290
- get: /**
4291
- * The x component of the vector.
4292
- */ function get() {
4293
- return this._x;
4294
- },
4295
- set: function set(value) {
4296
- this._x = value;
4297
- this._onValueChanged && this._onValueChanged();
4298
- }
4299
- },
4300
- {
4301
- key: "y",
4302
- get: /**
4303
- * The y component of the vector.
4304
- */ function get() {
4305
- return this._y;
4306
- },
4307
- set: function set(value) {
4308
- this._y = value;
4309
- this._onValueChanged && this._onValueChanged();
4310
- }
4311
- },
4312
- {
4313
- key: "z",
4314
- get: /**
4315
- * The z component of the vector.
4316
- */ function get() {
4317
- return this._z;
4318
- },
4319
- set: function set(value) {
4320
- this._z = value;
4321
- this._onValueChanged && this._onValueChanged();
4322
- }
4323
- },
4324
- {
4325
- key: "w",
4326
- get: /**
4327
- * The w component of the vector.
4328
- */ function get() {
4329
- return this._w;
4330
- },
4331
- set: function set(value) {
4332
- this._w = value;
4333
- this._onValueChanged && this._onValueChanged();
4334
- }
4335
- }
4336
- ]);
4337
- return Vector4;
4338
- }();
4339
- (function() {
4340
- /** @internal */ Vector4._zero = new Vector4(0.0, 0.0, 0.0, 0.0);
4341
- })();
4342
- (function() {
4343
- /** @internal */ Vector4._one = new Vector4(1.0, 1.0, 1.0, 1.0);
4344
- })();
4345
-
4346
- var WebXRFrame = /*#__PURE__*/ function() {
4347
- function WebXRFrame(session) {
4348
- this._session = session;
4349
- }
4350
- var _proto = WebXRFrame.prototype;
4351
- _proto.updateInputs = function updateInputs(inputs) {
4352
- if (!this._platformFrame) return;
4353
- this._updateController(inputs);
4354
- this._updateCamera(inputs);
4355
- };
4356
- _proto._updateController = function _updateController(inputs) {
4357
- var _this = this, frame = _this._platformFrame;
4358
- var _this__session = this._session, session = _this__session._platformSession, referenceSpace = _this__session._platformReferenceSpace;
4359
- var inputSources = session.inputSources;
4360
- for(var i = 0, n = inputSources.length; i < n; i++){
4361
- var inputSource = inputSources[i];
4362
- var type = getInputSource(inputSource);
4363
- var input = inputs[type];
4364
- switch(inputSource.targetRayMode){
4365
- case "screen":
4366
- case "tracked-pointer":
4367
- var gripSpace = inputSource.gripSpace, targetRaySpace = inputSource.targetRaySpace;
4368
- if (gripSpace) {
4369
- var _frame_getPose = frame.getPose(gripSpace, referenceSpace), transform = _frame_getPose.transform, emulatedPosition = _frame_getPose.emulatedPosition;
4370
- if (transform) {
4371
- var gripPose = input.gripPose;
4372
- gripPose.matrix.copyFromArray(transform.matrix);
4373
- gripPose.position.copyFrom(transform.position);
4374
- gripPose.rotation.copyFrom(transform.orientation);
4375
- }
4376
- input.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
4377
- }
4378
- if (targetRaySpace) {
4379
- var _frame_getPose1 = frame.getPose(targetRaySpace, referenceSpace), transform1 = _frame_getPose1.transform, emulatedPosition1 = _frame_getPose1.emulatedPosition;
4380
- if (transform1) {
4381
- var targetRayPose = input.targetRayPose;
4382
- targetRayPose.matrix.copyFromArray(transform1.matrix);
4383
- targetRayPose.position.copyFrom(transform1.position);
4384
- targetRayPose.rotation.copyFrom(transform1.orientation);
4385
- input.trackingState = emulatedPosition1 ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
4386
- }
4387
- }
4388
- break;
4389
- }
4390
- }
4391
- };
4392
- _proto._updateCamera = function _updateCamera(inputs) {
4393
- var _this = this, frame = _this._platformFrame;
4394
- var _this__session = this._session, referenceSpace = _this__session._platformReferenceSpace, layer = _this__session._platformLayer, framebufferWidth = _this__session.framebufferWidth, framebufferHeight = _this__session.framebufferHeight;
4395
- var viewerPose = frame.getViewerPose(referenceSpace);
4396
- if (viewerPose) {
4397
- var hadUpdateCenterViewer = false;
4398
- var views = viewerPose.views, emulatedPosition = viewerPose.emulatedPosition;
4399
- for(var i = 0, n = views.length; i < n; i++){
4400
- var view = views[i];
4401
- var type = viewToCamera(view.eye);
4402
- var transform = views[i].transform;
4403
- if (type === XRTrackedInputDevice.Camera) {
4404
- hadUpdateCenterViewer || (hadUpdateCenterViewer = true);
4405
- }
4406
- var xrCamera = inputs[type];
4407
- var pose = xrCamera.pose;
4408
- pose.matrix.copyFromArray(transform.matrix);
4409
- pose.position.copyFrom(transform.position);
4410
- pose.rotation.copyFrom(transform.orientation);
4411
- xrCamera.projectionMatrix.copyFromArray(view.projectionMatrix);
4412
- xrCamera.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
4413
- var xrViewport = layer.getViewport(view);
4414
- var width = xrViewport.width / framebufferWidth;
4415
- var height = xrViewport.height / framebufferHeight;
4416
- var x = xrViewport.x / framebufferWidth;
4417
- var y = 1 - xrViewport.y / framebufferHeight - height;
4418
- xrCamera.viewport.set(x, y, width, height);
4419
- }
4420
- if (!hadUpdateCenterViewer) {
4421
- var leftCameraDevice = inputs[XRTrackedInputDevice.LeftCamera];
4422
- var rightCameraDevice = inputs[XRTrackedInputDevice.RightCamera];
4423
- var cameraDevice = inputs[XRTrackedInputDevice.Camera];
4424
- var leftCameraPose = leftCameraDevice.pose;
4425
- var rightCameraPose = rightCameraDevice.pose;
4426
- var cameraPose = cameraDevice.pose;
4427
- cameraPose.rotation.copyFrom(leftCameraPose.rotation);
4428
- var position = cameraPose.position, matrix = cameraPose.matrix;
4429
- Vector3.add(leftCameraPose.position, rightCameraPose.position, position);
4430
- position.scale(0.5);
4431
- matrix.copyFrom(leftCameraPose.matrix);
4432
- var elements = matrix.elements;
4433
- elements[12] = position.x;
4434
- elements[13] = position.y;
4435
- elements[14] = position.z;
4436
- cameraDevice.projectionMatrix.copyFrom(leftCameraDevice.projectionMatrix);
4437
- cameraDevice.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
4438
- cameraDevice.viewport = leftCameraDevice.viewport.width && leftCameraDevice.viewport.height ? leftCameraDevice.viewport : rightCameraDevice.viewport;
4439
- }
4440
- }
2929
+ _proto._updateCamera = function _updateCamera(inputs) {
2930
+ var _this = this, frame = _this._platformFrame;
2931
+ var _this__session = this._session, referenceSpace = _this__session._platformReferenceSpace, layer = _this__session._platformLayer, framebufferWidth = _this__session.framebufferWidth, framebufferHeight = _this__session.framebufferHeight;
2932
+ var viewerPose = frame.getViewerPose(referenceSpace);
2933
+ if (viewerPose) {
2934
+ var hadUpdateCenterViewer = false;
2935
+ var views = viewerPose.views, emulatedPosition = viewerPose.emulatedPosition;
2936
+ for(var i = 0, n = views.length; i < n; i++){
2937
+ var view = views[i];
2938
+ var type = viewToCamera(view.eye);
2939
+ var transform = views[i].transform;
2940
+ if (type === XRTrackedInputDevice.Camera) {
2941
+ hadUpdateCenterViewer || (hadUpdateCenterViewer = true);
2942
+ }
2943
+ var xrCamera = inputs[type];
2944
+ var pose = xrCamera.pose;
2945
+ pose.matrix.copyFromArray(transform.matrix);
2946
+ pose.position.copyFrom(transform.position);
2947
+ pose.rotation.copyFrom(transform.orientation);
2948
+ xrCamera.projectionMatrix.copyFromArray(view.projectionMatrix);
2949
+ xrCamera.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2950
+ var xrViewport = layer.getViewport(view);
2951
+ var width = xrViewport.width / framebufferWidth;
2952
+ var height = xrViewport.height / framebufferHeight;
2953
+ var x = xrViewport.x / framebufferWidth;
2954
+ var y = 1 - xrViewport.y / framebufferHeight - height;
2955
+ xrCamera.viewport.set(x, y, width, height);
2956
+ }
2957
+ if (!hadUpdateCenterViewer) {
2958
+ var leftCameraDevice = inputs[XRTrackedInputDevice.LeftCamera];
2959
+ var rightCameraDevice = inputs[XRTrackedInputDevice.RightCamera];
2960
+ var cameraDevice = inputs[XRTrackedInputDevice.Camera];
2961
+ var leftCameraPose = leftCameraDevice.pose;
2962
+ var rightCameraPose = rightCameraDevice.pose;
2963
+ var cameraPose = cameraDevice.pose;
2964
+ cameraPose.rotation.copyFrom(leftCameraPose.rotation);
2965
+ var position = cameraPose.position, matrix = cameraPose.matrix;
2966
+ Vector3.add(leftCameraPose.position, rightCameraPose.position, position);
2967
+ position.scale(0.5);
2968
+ matrix.copyFrom(leftCameraPose.matrix);
2969
+ var elements = matrix.elements;
2970
+ elements[12] = position.x;
2971
+ elements[13] = position.y;
2972
+ elements[14] = position.z;
2973
+ cameraDevice.projectionMatrix.copyFrom(leftCameraDevice.projectionMatrix);
2974
+ cameraDevice.trackingState = emulatedPosition ? XRTrackingState.TrackingLost : XRTrackingState.Tracking;
2975
+ cameraDevice.viewport = leftCameraDevice.viewport.width && leftCameraDevice.viewport.height ? leftCameraDevice.viewport : rightCameraDevice.viewport;
2976
+ }
2977
+ }
4441
2978
  };
4442
2979
  return WebXRFrame;
4443
2980
  }();
@@ -4727,9 +3264,7 @@ var WebXRDevice = /*#__PURE__*/ function() {
4727
3264
  };
4728
3265
  return WebXRDevice;
4729
3266
  }();
4730
- (function() {
4731
- /** @internal */ WebXRDevice._platformFeatureMap = [];
4732
- })();
3267
+ /** @internal */ WebXRDevice._platformFeatureMap = [];
4733
3268
  function registerXRPlatformFeature(type) {
4734
3269
  return function(platformFeatureConstructor) {
4735
3270
  WebXRDevice._platformFeatureMap[type] = platformFeatureConstructor;
@@ -4743,10 +3278,10 @@ function registerXRPlatformFeature(type) {
4743
3278
 
4744
3279
  /**
4745
3280
  * @internal
4746
- */ var WebXRTrackableFeature = /*#__PURE__*/ function(WebXRFeature1) {
4747
- _inherits(WebXRTrackableFeature, WebXRFeature1);
3281
+ */ var WebXRTrackableFeature = /*#__PURE__*/ function(WebXRFeature) {
3282
+ _inherits(WebXRTrackableFeature, WebXRFeature);
4748
3283
  function WebXRTrackableFeature() {
4749
- return WebXRFeature1.apply(this, arguments);
3284
+ return WebXRFeature.apply(this, arguments) || this;
4750
3285
  }
4751
3286
  var _proto = WebXRTrackableFeature.prototype;
4752
3287
  _proto.onAddRequestTracking = function onAddRequestTracking(requestTracking) {};
@@ -4764,10 +3299,10 @@ function registerXRPlatformFeature(type) {
4764
3299
  return WebXRTrackableFeature;
4765
3300
  }(WebXRFeature);
4766
3301
 
4767
- var WebXRAnchorTracking = /*#__PURE__*/ function(WebXRTrackableFeature1) {
4768
- _inherits(WebXRAnchorTracking, WebXRTrackableFeature1);
3302
+ var WebXRAnchorTracking = /*#__PURE__*/ function(WebXRTrackableFeature) {
3303
+ _inherits(WebXRAnchorTracking, WebXRTrackableFeature);
4769
3304
  function WebXRAnchorTracking() {
4770
- return WebXRTrackableFeature1.apply(this, arguments);
3305
+ return WebXRTrackableFeature.apply(this, arguments) || this;
4771
3306
  }
4772
3307
  var _proto = WebXRAnchorTracking.prototype;
4773
3308
  _proto.checkAvailable = function checkAvailable(session, frame, requestTrackings) {
@@ -4878,14 +3413,11 @@ WebXRAnchorTracking = __decorate([
4878
3413
  registerXRPlatformFeature(XRFeatureType.AnchorTracking)
4879
3414
  ], WebXRAnchorTracking);
4880
3415
 
4881
- var WebXRImageTracking = /*#__PURE__*/ function(WebXRTrackableFeature1) {
4882
- _inherits(WebXRImageTracking, WebXRTrackableFeature1);
3416
+ var WebXRImageTracking = /*#__PURE__*/ function(WebXRTrackableFeature) {
3417
+ _inherits(WebXRImageTracking, WebXRTrackableFeature);
4883
3418
  function WebXRImageTracking(images) {
4884
3419
  var _this;
4885
- _this = WebXRTrackableFeature1.call(this) || this;
4886
- _this._trackingScoreStatus = 0;
4887
- _this._tempIdx = 0;
4888
- _this._tempArr = [];
3420
+ _this = WebXRTrackableFeature.call(this) || this, _this._trackingScoreStatus = 0, _this._tempIdx = 0, _this._tempArr = [];
4889
3421
  _this._images = images;
4890
3422
  return _this;
4891
3423
  }
@@ -5002,17 +3534,12 @@ var WebXRImageTracking = /*#__PURE__*/ function(WebXRTrackableFeature1) {
5002
3534
  WebXRImageTracking = __decorate([
5003
3535
  registerXRPlatformFeature(XRFeatureType.ImageTracking)
5004
3536
  ], WebXRImageTracking);
5005
- var ImageTrackingScoreStatus;
5006
- (function(ImageTrackingScoreStatus) {
5007
- ImageTrackingScoreStatus[ImageTrackingScoreStatus["NotReceived"] = 0] = "NotReceived";
5008
- ImageTrackingScoreStatus[ImageTrackingScoreStatus["Waiting"] = 1] = "Waiting";
5009
- ImageTrackingScoreStatus[ImageTrackingScoreStatus["Received"] = 2] = "Received";
5010
- })(ImageTrackingScoreStatus || (ImageTrackingScoreStatus = {}));
5011
3537
 
5012
- var WebXRPlaneTracking = /*#__PURE__*/ function(WebXRTrackableFeature1) {
5013
- _inherits(WebXRPlaneTracking, WebXRTrackableFeature1);
3538
+ var WebXRPlaneTracking = /*#__PURE__*/ function(WebXRTrackableFeature) {
3539
+ _inherits(WebXRPlaneTracking, WebXRTrackableFeature);
5014
3540
  function WebXRPlaneTracking(detectedMode) {
5015
- var _this = WebXRTrackableFeature1.call(this);
3541
+ var _this;
3542
+ _this = WebXRTrackableFeature.call(this) || this;
5016
3543
  if (detectedMode !== XRPlaneMode.EveryThing) {
5017
3544
  console.warn("WebXR only support XRPlaneMode.EveryThing");
5018
3545
  }
@@ -5041,8 +3568,7 @@ var WebXRPlaneTracking = /*#__PURE__*/ function(WebXRTrackableFeature1) {
5041
3568
  }
5042
3569
  var _this1 = this, lastDetectedPlanes = _this1._lastDetectedPlanes;
5043
3570
  detectedPlanes.forEach(function(xrPlane) {
5044
- var _lastDetectedPlanes;
5045
- if (!((_lastDetectedPlanes = lastDetectedPlanes) == null ? void 0 : _lastDetectedPlanes.has(xrPlane))) {
3571
+ if (!(lastDetectedPlanes == null ? void 0 : lastDetectedPlanes.has(xrPlane))) {
5046
3572
  var plane = generateTracked();
5047
3573
  plane.xrPlane = xrPlane;
5048
3574
  plane.lastChangedTime = -1;