@perplexdotgg/bounce 1.6.0 → 1.7.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/build/bounce.js CHANGED
@@ -798,9 +798,9 @@ class Vec3 extends createClass()(vec3Props) {
798
798
  return Math.abs(this.x - other.x) <= tolerance && Math.abs(this.y - other.y) <= tolerance && Math.abs(this.z - other.z) <= tolerance;
799
799
  }
800
800
  minVector(a3) {
801
- this.x = Math.min(this.x, a3.x);
802
- this.y = Math.min(this.y, a3.y);
803
- this.z = Math.min(this.z, a3.z);
801
+ if (a3.x < this.x) this.x = a3.x;
802
+ if (a3.y < this.y) this.y = a3.y;
803
+ if (a3.z < this.z) this.z = a3.z;
804
804
  return this;
805
805
  }
806
806
  minVectors(a3, b3) {
@@ -810,9 +810,9 @@ class Vec3 extends createClass()(vec3Props) {
810
810
  return this;
811
811
  }
812
812
  maxVector(a3) {
813
- this.x = Math.max(this.x, a3.x);
814
- this.y = Math.max(this.y, a3.y);
815
- this.z = Math.max(this.z, a3.z);
813
+ if (a3.x > this.x) this.x = a3.x;
814
+ if (a3.y > this.y) this.y = a3.y;
815
+ if (a3.z > this.z) this.z = a3.z;
816
816
  return this;
817
817
  }
818
818
  maxVectors(a3, b3) {
@@ -923,1365 +923,1287 @@ const rb = /* @__PURE__ */ Vec3.create();
923
923
  const temp = /* @__PURE__ */ Vec3.create();
924
924
  const rotatedVector = /* @__PURE__ */ Vec3.create();
925
925
  const rotationMatrix$3 = /* @__PURE__ */ Mat3.create();
926
- const lineProps = props({
927
- a: Vec3,
928
- b: Vec3
926
+ const segmentProps = props({
927
+ pointA: Vec3,
928
+ pointB: Vec3
929
929
  });
930
- class Line extends createClass()(lineProps) {
931
- setFromPointAndDirection(point2, direction2, length) {
932
- this.a.copy(point2);
933
- this.b.addScaledToVector(point2, direction2, length);
930
+ class Segment extends createClass()(segmentProps) {
931
+ computeCenter(out) {
932
+ out.addVectors(this.pointA, this.pointB);
933
+ out.scaleVector(out, 0.5);
934
+ }
935
+ computeHalfExtents(out) {
936
+ out.subtractVectors(this.pointB, this.pointA);
937
+ out.scaleVector(out, 0.5);
938
+ }
939
+ setFromRay(ray2) {
940
+ this.pointA.copy(ray2.origin);
941
+ this.pointB.addScaledToVector(ray2.origin, ray2.direction, ray2.length);
934
942
  }
935
943
  }
936
- const quatKeys = ["x", "y", "z", "w"];
937
- const quatProps = props({
938
- x: 0,
939
- y: 0,
940
- z: 0,
941
- w: 1
944
+ const epsilon$2 = 1e-7;
945
+ const newMin = /* @__PURE__ */ Vec3.create();
946
+ const newMax = /* @__PURE__ */ Vec3.create();
947
+ const col = /* @__PURE__ */ Vec3.create();
948
+ const a$2 = /* @__PURE__ */ Vec3.create();
949
+ const b$1 = /* @__PURE__ */ Vec3.create();
950
+ const aabbProps = props({
951
+ min: Vec3,
952
+ max: Vec3,
953
+ centroid: ChildType(Vec3, void 0, true)
942
954
  });
943
- class Quat extends createClass()(quatProps) {
944
- constructor(data, index, pool) {
945
- if (Array.isArray(data)) {
946
- if (data.length && data.length < 4) {
947
- tempQuat.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
948
- } else {
949
- tempQuat.x = data[0] ?? 0;
950
- tempQuat.y = data[1] ?? 0;
951
- tempQuat.z = data[2] ?? 0;
952
- tempQuat.w = data[3] ?? 1;
953
- }
954
- super(tempQuat, index, pool);
955
- return;
956
- }
957
- super(data, index, pool);
955
+ class Aabb extends createClass()(aabbProps) {
956
+ computeSupport(out, direction2) {
957
+ out.x = direction2.x < 0 ? this.min.x : this.max.x;
958
+ out.y = direction2.y < 0 ? this.min.y : this.max.y;
959
+ out.z = direction2.z < 0 ? this.min.z : this.max.z;
958
960
  }
959
- reset(data) {
960
- if (Array.isArray(data)) {
961
- if (data.length && data.length < 4) {
962
- return this.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
961
+ computeSupportingFace(out, inDirection) {
962
+ const absX = Math.abs(inDirection.x);
963
+ const absY = Math.abs(inDirection.y);
964
+ const absZ = Math.abs(inDirection.z);
965
+ const axis2 = absX > absY ? absX > absZ ? 0 : 2 : absY > absZ ? 1 : 2;
966
+ const component = inDirection.getComponentAtIndex(axis2);
967
+ if (component < 0) {
968
+ switch (axis2) {
969
+ case 0: {
970
+ out.pushVertexValues(this.max.x, this.min.y, this.min.z);
971
+ out.pushVertexValues(this.max.x, this.max.y, this.min.z);
972
+ out.pushVertexValues(this.max.x, this.max.y, this.max.z);
973
+ out.pushVertexValues(this.max.x, this.min.y, this.max.z);
974
+ break;
975
+ }
976
+ case 1: {
977
+ out.pushVertexValues(this.min.x, this.max.y, this.min.z);
978
+ out.pushVertexValues(this.min.x, this.max.y, this.max.z);
979
+ out.pushVertexValues(this.max.x, this.max.y, this.max.z);
980
+ out.pushVertexValues(this.max.x, this.max.y, this.min.z);
981
+ break;
982
+ }
983
+ case 2: {
984
+ out.pushVertexValues(this.min.x, this.min.y, this.max.z);
985
+ out.pushVertexValues(this.max.x, this.min.y, this.max.z);
986
+ out.pushVertexValues(this.max.x, this.max.y, this.max.z);
987
+ out.pushVertexValues(this.min.x, this.max.y, this.max.z);
988
+ break;
989
+ }
963
990
  }
964
- this.x = data[0] ?? 0;
965
- this.y = data[1] ?? 0;
966
- this.z = data[2] ?? 0;
967
- this.w = data[3] ?? 1;
968
991
  } else {
969
- if (data && data.w === void 0 && (data.x || data.y || data.z)) {
970
- return this.setFromEulerRadians(data.x ?? 0, data.y ?? 0, data.z ?? 0);
992
+ switch (axis2) {
993
+ case 0: {
994
+ out.pushVertexValues(this.min.x, this.min.y, this.min.z);
995
+ out.pushVertexValues(this.min.x, this.min.y, this.max.z);
996
+ out.pushVertexValues(this.min.x, this.max.y, this.max.z);
997
+ out.pushVertexValues(this.min.x, this.max.y, this.min.z);
998
+ break;
999
+ }
1000
+ case 1: {
1001
+ out.pushVertexValues(this.min.x, this.min.y, this.min.z);
1002
+ out.pushVertexValues(this.max.x, this.min.y, this.min.z);
1003
+ out.pushVertexValues(this.max.x, this.min.y, this.max.z);
1004
+ out.pushVertexValues(this.min.x, this.min.y, this.max.z);
1005
+ break;
1006
+ }
1007
+ case 2: {
1008
+ out.pushVertexValues(this.min.x, this.min.y, this.min.z);
1009
+ out.pushVertexValues(this.min.x, this.max.y, this.min.z);
1010
+ out.pushVertexValues(this.max.x, this.max.y, this.min.z);
1011
+ out.pushVertexValues(this.max.x, this.min.y, this.min.z);
1012
+ break;
1013
+ }
971
1014
  }
972
- this.x = data?.x ?? 0;
973
- this.y = data?.y ?? 0;
974
- this.z = data?.z ?? 0;
975
- this.w = data?.w ?? 1;
976
1015
  }
1016
+ }
1017
+ translate(translation) {
1018
+ this.min.addVector(translation);
1019
+ this.max.addVector(translation);
1020
+ this.computeCentroid(this.centroid);
1021
+ }
1022
+ translateAabb(aabb, translation) {
1023
+ this.min.addVectors(aabb.min, translation);
1024
+ this.max.addVectors(aabb.max, translation);
1025
+ this.computeCentroid(this.centroid);
977
1026
  return this;
978
1027
  }
979
- set(data) {
980
- if (Array.isArray(data)) {
981
- if (data.length && data.length < 4) {
982
- return this.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
983
- }
984
- this.x = data[0] ?? 0;
985
- this.y = data[1] ?? 0;
986
- this.z = data[2] ?? 0;
987
- this.w = data[3] ?? 1;
988
- } else if (data) {
989
- if (data.x !== void 0) {
990
- this.x = data.x;
991
- }
992
- if (data.y !== void 0) {
993
- this.y = data.y;
994
- }
995
- if (data.z !== void 0) {
996
- this.z = data.z;
997
- }
998
- if (data.w !== void 0) {
999
- this.w = data.w;
1000
- }
1028
+ transform(transform2) {
1029
+ transform2.matrix.getTranslation(newMin);
1030
+ transform2.matrix.getTranslation(newMax);
1031
+ for (let c3 = 0; c3 < 3; ++c3) {
1032
+ transform2.matrix.getColumn3(col, c3);
1033
+ const minComponent = this.min.getComponentAtIndex(c3);
1034
+ const maxComponent = this.max.getComponentAtIndex(c3);
1035
+ a$2.scaleVector(col, minComponent);
1036
+ b$1.scaleVector(col, maxComponent);
1037
+ newMin.x += Math.min(a$2.x, b$1.x);
1038
+ newMin.y += Math.min(a$2.y, b$1.y);
1039
+ newMin.z += Math.min(a$2.z, b$1.z);
1040
+ newMax.x += Math.max(a$2.x, b$1.x);
1041
+ newMax.y += Math.max(a$2.y, b$1.y);
1042
+ newMax.z += Math.max(a$2.z, b$1.z);
1001
1043
  }
1044
+ this.min.copy(newMin);
1045
+ this.max.copy(newMax);
1046
+ this.computeCentroid(this.centroid);
1002
1047
  return this;
1003
1048
  }
1004
- length() {
1005
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
1006
- }
1007
- normalize() {
1008
- const length = this.length();
1009
- if (length > 0) {
1010
- this.x /= length;
1011
- this.y /= length;
1012
- this.z /= length;
1013
- this.w /= length;
1049
+ transformAabb(aabb, transform2) {
1050
+ transform2.matrix.getTranslation(newMin);
1051
+ transform2.matrix.getTranslation(newMax);
1052
+ for (let c3 = 0; c3 < 3; ++c3) {
1053
+ transform2.matrix.getColumn3(col, c3);
1054
+ const minComponent = aabb.min.getComponentAtIndex(c3);
1055
+ const maxComponent = aabb.max.getComponentAtIndex(c3);
1056
+ a$2.scaleVector(col, minComponent);
1057
+ b$1.scaleVector(col, maxComponent);
1058
+ newMin.x += Math.min(a$2.x, b$1.x);
1059
+ newMin.y += Math.min(a$2.y, b$1.y);
1060
+ newMin.z += Math.min(a$2.z, b$1.z);
1061
+ newMax.x += Math.max(a$2.x, b$1.x);
1062
+ newMax.y += Math.max(a$2.y, b$1.y);
1063
+ newMax.z += Math.max(a$2.z, b$1.z);
1014
1064
  }
1065
+ this.min.copy(newMin);
1066
+ this.max.copy(newMax);
1067
+ this.computeCentroid(this.centroid);
1015
1068
  return this;
1016
1069
  }
1017
- identity() {
1018
- this.x = 0;
1019
- this.y = 0;
1020
- this.z = 0;
1021
- this.w = 1;
1070
+ intersectsAabb(aabb) {
1071
+ return this.min.x <= aabb.max.x && this.max.x >= aabb.min.x && this.min.y <= aabb.max.y && this.max.y >= aabb.min.y && this.min.z <= aabb.max.z && this.max.z >= aabb.min.z;
1072
+ }
1073
+ unionAabb(aabb) {
1074
+ this.min.minVectors(this.min, aabb.min);
1075
+ this.max.maxVectors(this.max, aabb.max);
1076
+ this.computeCentroid(this.centroid);
1022
1077
  return this;
1023
1078
  }
1024
- conjugateQuat(a3) {
1025
- this.x = -a3.x;
1026
- this.y = -a3.y;
1027
- this.z = -a3.z;
1028
- this.w = a3.w;
1079
+ unionAabbs(boxA, boxB) {
1080
+ this.min.minVectors(boxA.min, boxB.min);
1081
+ this.max.maxVectors(boxA.max, boxB.max);
1082
+ this.computeCentroid(this.centroid);
1029
1083
  return this;
1030
1084
  }
1031
- multiplyQuats(a3, b3) {
1032
- const ax = a3.x;
1033
- const ay = a3.y;
1034
- const az = a3.z;
1035
- const aw = a3.w;
1036
- const bx = b3.x;
1037
- const by = b3.y;
1038
- const bz = b3.z;
1039
- const bw = b3.w;
1040
- this.x = ax * bw + aw * bx + ay * bz - az * by;
1041
- this.y = ay * bw + aw * by + az * bx - ax * bz;
1042
- this.z = az * bw + aw * bz + ax * by - ay * bx;
1043
- this.w = aw * bw - ax * bx - ay * by - az * bz;
1085
+ expand(value) {
1086
+ this.min.x -= value;
1087
+ this.min.y -= value;
1088
+ this.min.z -= value;
1089
+ this.max.x += value;
1090
+ this.max.y += value;
1091
+ this.max.z += value;
1092
+ this.computeCentroid(this.centroid);
1093
+ }
1094
+ expandAabb(aabb, value) {
1095
+ this.min.x = aabb.min.x - value;
1096
+ this.min.y = aabb.min.y - value;
1097
+ this.min.z = aabb.min.z - value;
1098
+ this.max.x = aabb.max.x + value;
1099
+ this.max.y = aabb.max.y + value;
1100
+ this.max.z = aabb.max.z + value;
1101
+ this.computeCentroid(this.centroid);
1044
1102
  return this;
1045
1103
  }
1046
- normalizeQuat(a3) {
1047
- const x2 = a3.x;
1048
- const y4 = a3.y;
1049
- const z = a3.z;
1050
- const w3 = a3.w;
1051
- let len = x2 * x2 + y4 * y4 + z * z + w3 * w3;
1052
- if (len > 0) {
1053
- len = 1 / Math.sqrt(len);
1054
- }
1055
- this.x = x2 * len;
1056
- this.y = y4 * len;
1057
- this.z = z * len;
1058
- this.w = w3 * len;
1059
- return this;
1060
- }
1061
- setAxisAngle(axis2, angle) {
1062
- angle = angle * 0.5;
1063
- let s2 = Math.sin(angle);
1064
- this.x = s2 * axis2.x;
1065
- this.y = s2 * axis2.y;
1066
- this.z = s2 * axis2.z;
1067
- this.w = Math.cos(angle);
1104
+ setExtents(min, max) {
1105
+ this.min.set(min);
1106
+ this.max.set(max);
1107
+ this.computeCentroid(this.centroid);
1068
1108
  return this;
1069
1109
  }
1070
- dot(b3) {
1071
- return this.x * b3.x + this.y * b3.y + this.z * b3.z + this.w * b3.w;
1072
- }
1073
- notEquals(other, tolerance = 1e-6) {
1074
- return Math.abs(this.x - other.x) >= tolerance || Math.abs(this.y - other.y) >= tolerance || Math.abs(this.z - other.z) >= tolerance || Math.abs(this.w - other.w) >= tolerance;
1110
+ computeSurfaceArea() {
1111
+ const dx = this.max.x - this.min.x;
1112
+ const dy = this.max.y - this.min.y;
1113
+ const dz = this.max.z - this.min.z;
1114
+ return 2 * (dx * dy + dy * dz + dz * dx);
1075
1115
  }
1076
- equals(other, tolerance = 1e-6) {
1077
- return Math.abs(this.x - other.x) < tolerance && Math.abs(this.y - other.y) < tolerance && Math.abs(this.z - other.z) < tolerance && Math.abs(this.w - other.w) < tolerance;
1116
+ computeExtents(out) {
1117
+ out.x = this.max.x - this.min.x;
1118
+ out.y = this.max.y - this.min.y;
1119
+ out.z = this.max.z - this.min.z;
1078
1120
  }
1079
- intoEuler(out) {
1080
- if (this.w < 0) {
1081
- out.x = -this.x * 2;
1082
- out.y = -this.y * 2;
1083
- out.z = -this.z * 2;
1084
- } else {
1085
- out.x = this.x * 2;
1086
- out.y = this.y * 2;
1087
- out.z = this.z * 2;
1121
+ computeLargestAxis() {
1122
+ const dx = this.max.x - this.min.x;
1123
+ const dy = this.max.y - this.min.y;
1124
+ const dz = this.max.z - this.min.z;
1125
+ if (dx >= dy && dx >= dz) {
1126
+ return 0;
1088
1127
  }
1089
- return this;
1128
+ if (dy >= dx && dy >= dz) {
1129
+ return 1;
1130
+ }
1131
+ return 2;
1090
1132
  }
1091
- fromMat3(m) {
1092
- let fTrace = m.e0 + m.e4 + m.e8;
1093
- let fRoot;
1094
- if (fTrace > 0) {
1095
- fRoot = Math.sqrt(fTrace + 1);
1096
- this.w = 0.5 * fRoot;
1097
- fRoot = 0.5 / fRoot;
1098
- this.x = (m.e5 - m.e7) * fRoot;
1099
- this.y = (m.e6 - m.e2) * fRoot;
1100
- this.z = (m.e1 - m.e3) * fRoot;
1101
- } else {
1102
- let i = 0;
1103
- if (m.e4 > m.e0) i = 1;
1104
- if (m.e8 > m[mat3Keys[i * 3 + i]]) i = 2;
1105
- let j = (i + 1) % 3;
1106
- let k = (i + 2) % 3;
1107
- fRoot = Math.sqrt(m[mat3Keys[i * 3 + i]] - m[mat3Keys[j * 3 + j]] - m[mat3Keys[k * 3 + k]] + 1);
1108
- this[quatKeys[i]] = 0.5 * fRoot;
1109
- fRoot = 0.5 / fRoot;
1110
- this.w = (m[mat3Keys[j * 3 + k]] - m[mat3Keys[k * 3 + j]]) * fRoot;
1111
- this[quatKeys[j]] = (m[mat3Keys[j * 3 + i]] + m[mat3Keys[i * 3 + j]]) * fRoot;
1112
- this[quatKeys[k]] = (m[mat3Keys[k * 3 + i]] + m[mat3Keys[i * 3 + k]]) * fRoot;
1133
+ computeLargestComponent() {
1134
+ const dx = this.max.x - this.min.x;
1135
+ const dy = this.max.y - this.min.y;
1136
+ const dz = this.max.z - this.min.z;
1137
+ if (dx >= dy && dx >= dz) {
1138
+ return "x";
1113
1139
  }
1114
- return this;
1140
+ if (dy >= dx && dy >= dz) {
1141
+ return "y";
1142
+ }
1143
+ return "z";
1115
1144
  }
1116
- fromMat4(m) {
1117
- tempMat3.fromMat4(m);
1118
- this.fromMat3(tempMat3);
1119
- return this;
1145
+ computeCentroid(out) {
1146
+ out.x = (this.min.x + this.max.x) * 0.5;
1147
+ out.y = (this.min.y + this.max.y) * 0.5;
1148
+ out.z = (this.min.z + this.max.z) * 0.5;
1149
+ return out;
1120
1150
  }
1121
- computeRotationAngle(axis2) {
1122
- if (this.w === 0) {
1123
- return Math.PI;
1124
- } else {
1125
- vector.x = this.x;
1126
- vector.y = this.y;
1127
- vector.z = this.z;
1128
- return 2 * Math.atan(vector.dot(axis2) / this.w);
1129
- }
1151
+ computeHalfExtents(out) {
1152
+ out.subtractVectors(this.max, this.min);
1153
+ out.scaleVector(out, 0.5);
1130
1154
  }
1131
- setFromEulerRadians(x2, y4, z) {
1132
- const halfX = x2 * 0.5;
1133
- const halfY = y4 * 0.5;
1134
- const halfZ = z * 0.5;
1135
- const c12 = Math.cos(halfX);
1136
- const c22 = Math.cos(halfY);
1137
- const c3 = Math.cos(halfZ);
1138
- const s1 = Math.sin(halfX);
1139
- const s2 = Math.sin(halfY);
1140
- const s3 = Math.sin(halfZ);
1141
- this.x = s1 * c22 * c3 + c12 * s2 * s3;
1142
- this.y = c12 * s2 * c3 - s1 * c22 * s3;
1143
- this.z = c12 * c22 * s3 + s1 * s2 * c3;
1144
- this.w = c12 * c22 * c3 - s1 * s2 * s3;
1155
+ /**
1156
+ * expand this aabb to include the given point
1157
+ * @param point the vec3 to expand to. meaning if the point is outside the aabb, it will expand to include the point
1158
+ * @returns
1159
+ */
1160
+ expandToPoint(point2) {
1161
+ this.min.minVector(point2);
1162
+ this.max.maxVector(point2);
1145
1163
  return this;
1146
1164
  }
1165
+ enclosesAabb(aabb) {
1166
+ return this.min.x < aabb.min.x && this.max.x > aabb.max.x && this.min.y < aabb.min.y && this.max.y > aabb.max.y && this.min.z < aabb.min.z && this.max.z > aabb.max.z;
1167
+ }
1168
+ expandByVector(vector2) {
1169
+ this.min.x -= vector2.x;
1170
+ this.min.y -= vector2.y;
1171
+ this.min.z -= vector2.z;
1172
+ this.max.x += vector2.x;
1173
+ this.max.y += vector2.y;
1174
+ this.max.z += vector2.z;
1175
+ }
1176
+ toString() {
1177
+ return `Aabb(min: ${[this.min.x, this.min.y, this.min.z].join(", ")}, max: ${[
1178
+ this.max.x,
1179
+ this.max.y,
1180
+ this.max.z
1181
+ ].join(", ")})`;
1182
+ }
1183
+ intersectsRay(ray2) {
1184
+ segment.setFromRay(ray2);
1185
+ return this.intersectsSegment(segment);
1186
+ }
1187
+ /**
1188
+ * from Christer Ericson's book "Real-Time Collision Detection", "5.3.3 Intersecting Ray or Segment Against Box"
1189
+ */
1190
+ intersectsSegment(segment2) {
1191
+ this.computeCentroid(aabbCenter);
1192
+ this.computeHalfExtents(aabbHalfExtents);
1193
+ segment2.computeCenter(segmentCenter);
1194
+ segment2.computeHalfExtents(segmentHalfExtents);
1195
+ segmentCenter.subtractVectors(segmentCenter, aabbCenter);
1196
+ let adx = Math.abs(segmentHalfExtents.x);
1197
+ if (Math.abs(segmentCenter.x) > aabbHalfExtents.x + adx) {
1198
+ return false;
1199
+ }
1200
+ let ady = Math.abs(segmentHalfExtents.y);
1201
+ if (Math.abs(segmentCenter.y) > aabbHalfExtents.y + ady) {
1202
+ return false;
1203
+ }
1204
+ let adz = Math.abs(segmentHalfExtents.z);
1205
+ if (Math.abs(segmentCenter.z) > aabbHalfExtents.z + adz) {
1206
+ return false;
1207
+ }
1208
+ adx += epsilon$2;
1209
+ ady += epsilon$2;
1210
+ adz += epsilon$2;
1211
+ if (Math.abs(segmentCenter.y * segmentHalfExtents.z - segmentCenter.z * segmentHalfExtents.y) > aabbHalfExtents.y * adz + aabbHalfExtents.z * ady) {
1212
+ return false;
1213
+ }
1214
+ if (Math.abs(segmentCenter.z * segmentHalfExtents.x - segmentCenter.x * segmentHalfExtents.z) > aabbHalfExtents.x * adz + aabbHalfExtents.z * adx) {
1215
+ return false;
1216
+ }
1217
+ if (Math.abs(segmentCenter.x * segmentHalfExtents.y - segmentCenter.y * segmentHalfExtents.x) > aabbHalfExtents.x * ady + aabbHalfExtents.y * adx) {
1218
+ return false;
1219
+ }
1220
+ return true;
1221
+ }
1147
1222
  toObject() {
1148
1223
  return {
1149
- x: this.x,
1150
- y: this.y,
1151
- z: this.z,
1152
- w: this.w
1224
+ min: this.min.toObject(),
1225
+ max: this.max.toObject()
1153
1226
  };
1154
1227
  }
1155
1228
  }
1156
- const vector = /* @__PURE__ */ Vec3.create();
1157
- const tempMat3 = /* @__PURE__ */ Mat3.create();
1158
- const tempQuat = /* @__PURE__ */ Quat.create();
1159
- const rotationMatrix$2 = /* @__PURE__ */ Mat3.create();
1160
- const scaling = /* @__PURE__ */ Vec3.create();
1161
- const conjugatedRotation = /* @__PURE__ */ Quat.create();
1162
- const rotatedTranslation = /* @__PURE__ */ Vec3.create();
1163
- const mat4Props = props({
1164
- e0: 0,
1165
- e1: 0,
1166
- e2: 0,
1167
- e3: 0,
1168
- e4: 0,
1169
- e5: 0,
1170
- e6: 0,
1171
- e7: 0,
1172
- e8: 0,
1173
- e9: 0,
1174
- e10: 0,
1175
- e11: 0,
1176
- e12: 0,
1177
- e13: 0,
1178
- e14: 0,
1179
- e15: 0
1229
+ const segment = /* @__PURE__ */ Segment.create();
1230
+ const aabbCenter = /* @__PURE__ */ Vec3.create();
1231
+ const aabbHalfExtents = /* @__PURE__ */ Vec3.create();
1232
+ const segmentCenter = /* @__PURE__ */ Vec3.create();
1233
+ const segmentHalfExtents = /* @__PURE__ */ Vec3.create();
1234
+ const triangleProps$1 = props({
1235
+ computedBounds: ChildType(Aabb, void 0, true),
1236
+ normal: ChildType(Vec3, void 0, true),
1237
+ a: Vec3,
1238
+ b: Vec3,
1239
+ c: Vec3,
1240
+ subShapeId: NumberType(0, true),
1241
+ activeEdges: NumberType(0, true)
1242
+ // aabb: { struct: Aabb, readOnly: true },
1243
+ // activeEdges: { struct: Uint32, optional: true },
1244
+ // translation: { struct: Vec3, optional: true },
1180
1245
  });
1181
- class Mat4 extends createClass()(mat4Props) {
1182
- multiply3x3(out, a3) {
1183
- const x2 = a3.x;
1184
- const y4 = a3.y;
1185
- const z = a3.z;
1186
- out.x = this.e0 * x2 + this.e4 * y4 + this.e8 * z;
1187
- out.y = this.e1 * x2 + this.e5 * y4 + this.e9 * z;
1188
- out.z = this.e2 * x2 + this.e6 * y4 + this.e10 * z;
1189
- return out;
1246
+ const ab$5 = /* @__PURE__ */ Vec3.create();
1247
+ const ac$3 = /* @__PURE__ */ Vec3.create();
1248
+ let Triangle$1 = class Triangle extends createClass()(triangleProps$1) {
1249
+ // type: ShapeType.triangle = ShapeType.triangle;
1250
+ computeNormal(out) {
1251
+ ab$5.subtractVectors(this.b, this.a);
1252
+ ac$3.subtractVectors(this.c, this.a);
1253
+ out.crossVectors(ab$5, ac$3);
1254
+ out.normalize();
1190
1255
  }
1191
- multiply3x3Transposed(out, a3) {
1192
- rotationMatrix$2.fromMat4(this);
1193
- rotationMatrix$2.transpose();
1194
- out.transformVectorFromMat3(a3, rotationMatrix$2);
1256
+ computeCentroid(out) {
1257
+ out.addVectors(this.a, this.b).addVector(this.c).scale(1 / 3);
1195
1258
  }
1196
- computeScaling(out) {
1197
- let m11 = this.e0;
1198
- let m12 = this.e1;
1199
- let m13 = this.e2;
1200
- let m21 = this.e4;
1201
- let m22 = this.e5;
1202
- let m23 = this.e6;
1203
- let m31 = this.e8;
1204
- let m32 = this.e9;
1205
- let m33 = this.e10;
1206
- out.x = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
1207
- out.y = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
1208
- out.z = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
1209
- return out;
1259
+ computeUnnormalizedNormal(out) {
1260
+ ab$5.subtractVectors(this.b, this.a);
1261
+ ac$3.subtractVectors(this.c, this.a);
1262
+ out.crossVectors(ab$5, ac$3);
1210
1263
  }
1211
- computeRotation(out) {
1212
- this.computeScaling(scaling);
1213
- let is1 = 1 / scaling.x;
1214
- let is2 = 1 / scaling.y;
1215
- let is3 = 1 / scaling.z;
1216
- let sm11 = this.e0 * is1;
1217
- let sm12 = this.e1 * is2;
1218
- let sm13 = this.e2 * is3;
1219
- let sm21 = this.e4 * is1;
1220
- let sm22 = this.e5 * is2;
1221
- let sm23 = this.e6 * is3;
1222
- let sm31 = this.e8 * is1;
1223
- let sm32 = this.e9 * is2;
1224
- let sm33 = this.e10 * is3;
1225
- let trace = sm11 + sm22 + sm33;
1226
- let S = 0;
1227
- if (trace > 0) {
1228
- S = Math.sqrt(trace + 1) * 2;
1229
- out.w = 0.25 * S;
1230
- out.x = (sm23 - sm32) / S;
1231
- out.y = (sm31 - sm13) / S;
1232
- out.z = (sm12 - sm21) / S;
1233
- } else if (sm11 > sm22 && sm11 > sm33) {
1234
- S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
1235
- out.w = (sm23 - sm32) / S;
1236
- out.x = 0.25 * S;
1237
- out.y = (sm12 + sm21) / S;
1238
- out.z = (sm31 + sm13) / S;
1239
- } else if (sm22 > sm33) {
1240
- S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
1241
- out.w = (sm31 - sm13) / S;
1242
- out.x = (sm12 + sm21) / S;
1243
- out.y = 0.25 * S;
1244
- out.z = (sm23 + sm32) / S;
1264
+ computeSurfaceNormal(out, inLocalSurfacePosition2, subShapeId) {
1265
+ this.computeNormal(out);
1266
+ }
1267
+ transform(isometry2) {
1268
+ this.a.transformByMat4(isometry2);
1269
+ this.b.transformByMat4(isometry2);
1270
+ this.c.transformByMat4(isometry2);
1271
+ }
1272
+ computeLocalBounds(out) {
1273
+ out.min.x = Math.min(this.a.x, this.b.x, this.c.x);
1274
+ out.min.y = Math.min(this.a.y, this.b.y, this.c.y);
1275
+ out.min.z = Math.min(this.a.z, this.b.z, this.c.z);
1276
+ out.max.x = Math.max(this.a.x, this.b.x, this.c.x);
1277
+ out.max.y = Math.max(this.a.y, this.b.y, this.c.y);
1278
+ out.max.z = Math.max(this.a.z, this.b.z, this.c.z);
1279
+ out.computeCentroid(out.centroid);
1280
+ }
1281
+ computeSupport(out, direction2) {
1282
+ const dotA = this.a.dot(direction2);
1283
+ const dotB = this.b.dot(direction2);
1284
+ const dotC = this.c.dot(direction2);
1285
+ if (dotA > dotB) {
1286
+ if (dotA > dotC) {
1287
+ out.copy(this.a);
1288
+ } else {
1289
+ out.copy(this.c);
1290
+ }
1245
1291
  } else {
1246
- S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
1247
- out.w = (sm12 - sm21) / S;
1248
- out.x = (sm31 + sm13) / S;
1249
- out.y = (sm23 + sm32) / S;
1250
- out.z = 0.25 * S;
1292
+ if (dotB > dotC) {
1293
+ out.copy(this.b);
1294
+ } else {
1295
+ out.copy(this.c);
1296
+ }
1251
1297
  }
1252
- return out;
1253
- }
1254
- getTranslation(out) {
1255
- out.x = this.e12;
1256
- out.y = this.e13;
1257
- out.z = this.e14;
1258
1298
  }
1259
- setTranslation(v4) {
1260
- this.e12 = v4.x;
1261
- this.e13 = v4.y;
1262
- this.e14 = v4.z;
1263
- this.e15 = 1;
1299
+ getConvexRadius() {
1300
+ return 0;
1264
1301
  }
1265
- preTranslated(translation) {
1266
- this.e12 += this.e0 * translation.x + this.e4 * translation.y + this.e8 * translation.z;
1267
- this.e13 += this.e1 * translation.x + this.e5 * translation.y + this.e9 * translation.z;
1268
- this.e14 += this.e2 * translation.x + this.e6 * translation.y + this.e10 * translation.z;
1269
- this.e15 = 1;
1302
+ computeSupportShape(mode, scale2) {
1270
1303
  return this;
1271
1304
  }
1272
- postTranslated(translation) {
1273
- this.e12 += translation.x;
1274
- this.e13 += translation.y;
1275
- this.e14 += translation.z;
1276
- this.e15 = 1;
1277
- return this;
1305
+ toObject() {
1306
+ return {
1307
+ a: this.a.toObject(),
1308
+ b: this.b.toObject(),
1309
+ c: this.c.toObject(),
1310
+ normal: this.normal.toObject()
1311
+ };
1278
1312
  }
1279
- postTranslatedMatrix(mat, translation) {
1280
- this.e0 = mat.e0;
1281
- this.e1 = mat.e1;
1282
- this.e2 = mat.e2;
1283
- this.e3 = mat.e3;
1284
- this.e4 = mat.e4;
1285
- this.e5 = mat.e5;
1286
- this.e6 = mat.e6;
1287
- this.e7 = mat.e7;
1288
- this.e8 = mat.e8;
1289
- this.e9 = mat.e9;
1290
- this.e10 = mat.e10;
1291
- this.e11 = mat.e11;
1292
- this.e12 = mat.e12 + translation.x;
1293
- this.e13 = mat.e13 + translation.y;
1294
- this.e14 = mat.e14 + translation.z;
1295
- this.e15 = 1;
1296
- return this;
1313
+ computeSupportingFace(out, subShapeID, direction2, scale2, centerOfMassTransform2) {
1314
+ out.clear();
1315
+ out.pushVertex(this.a);
1316
+ out.pushVertex(this.b);
1317
+ out.pushVertex(this.c);
1318
+ out.transform(centerOfMassTransform2);
1297
1319
  }
1298
- fromRotationTranslation(q4, v4) {
1299
- const x2 = q4.x;
1300
- const y4 = q4.y;
1301
- const z = q4.z;
1302
- const w3 = q4.w;
1303
- const x22 = x2 + x2;
1304
- const y22 = y4 + y4;
1305
- const z2 = z + z;
1306
- const xx = x2 * x22;
1307
- const xy = x2 * y22;
1308
- const xz = x2 * z2;
1309
- const yy = y4 * y22;
1310
- const yz = y4 * z2;
1311
- const zz = z * z2;
1312
- const wx = w3 * x22;
1313
- const wy = w3 * y22;
1314
- const wz = w3 * z2;
1315
- this.e0 = 1 - (yy + zz);
1316
- this.e1 = xy + wz;
1317
- this.e2 = xz - wy;
1318
- this.e3 = 0;
1319
- this.e4 = xy - wz;
1320
- this.e5 = 1 - (xx + zz);
1321
- this.e6 = yz + wx;
1322
- this.e7 = 0;
1323
- this.e8 = xz + wy;
1324
- this.e9 = yz - wx;
1325
- this.e10 = 1 - (xx + yy);
1326
- this.e11 = 0;
1327
- this.e12 = v4.x;
1328
- this.e13 = v4.y;
1329
- this.e14 = v4.z;
1330
- this.e15 = 1;
1331
- return this;
1320
+ };
1321
+ const faceProps = props({
1322
+ numVertices: 0,
1323
+ buffer: LazyReferenceListType(() => Vec3)
1324
+ });
1325
+ const triangle$1 = /* @__PURE__ */ Triangle$1.create();
1326
+ const tempVertex = /* @__PURE__ */ Vec3.create();
1327
+ class Face extends createClass()(faceProps) {
1328
+ clear() {
1329
+ this.numVertices = 0;
1332
1330
  }
1333
- fromAxisAngle(axis2, angle) {
1334
- rotation$3.setAxisAngle(axis2, angle);
1335
- this.fromQuat(rotation$3);
1336
- this.e12 = 0;
1337
- this.e13 = 0;
1338
- this.e14 = 0;
1339
- this.e15 = 1;
1340
- return this;
1331
+ isEmpty() {
1332
+ return this.numVertices === 0;
1341
1333
  }
1342
- fromQuat(q4) {
1343
- let x2 = q4.x, y4 = q4.y, z = q4.z, w3 = q4.w;
1344
- let x22 = x2 + x2;
1345
- let y22 = y4 + y4;
1346
- let z2 = z + z;
1347
- let xx = x2 * x22;
1348
- let yx = y4 * x22;
1349
- let yy = y4 * y22;
1350
- let zx = z * x22;
1351
- let zy = z * y22;
1352
- let zz = z * z2;
1353
- let wx = w3 * x22;
1354
- let wy = w3 * y22;
1355
- let wz = w3 * z2;
1356
- this.e0 = 1 - yy - zz;
1357
- this.e1 = yx + wz;
1358
- this.e2 = zx - wy;
1359
- this.e3 = 0;
1360
- this.e4 = yx - wz;
1361
- this.e5 = 1 - xx - zz;
1362
- this.e6 = zy + wx;
1363
- this.e7 = 0;
1364
- this.e8 = zx + wy;
1365
- this.e9 = zy - wx;
1366
- this.e10 = 1 - xx - yy;
1367
- this.e11 = 0;
1368
- this.e12 = 0;
1369
- this.e13 = 0;
1370
- this.e14 = 0;
1371
- this.e15 = 1;
1372
- return this;
1334
+ isFull() {
1335
+ return this.numVertices === this.buffer.maxLength;
1373
1336
  }
1374
- fromInverseRotationAndTranslation(rotation2, translation) {
1375
- conjugatedRotation.conjugateQuat(rotation2);
1376
- this.fromQuat(conjugatedRotation);
1377
- this.multiply3x3(rotatedTranslation, translation);
1378
- rotatedTranslation.negate();
1379
- this.setTranslation(rotatedTranslation);
1380
- return this;
1337
+ getVertex(out, index) {
1338
+ out.copy(this.buffer.getAtIndex(index));
1381
1339
  }
1382
- invert() {
1383
- const a00 = this.e0;
1384
- const a01 = this.e1;
1385
- const a02 = this.e2;
1386
- const a03 = this.e3;
1387
- const a10 = this.e4;
1388
- const a11 = this.e5;
1389
- const a12 = this.e6;
1390
- const a13 = this.e7;
1391
- const a20 = this.e8;
1392
- const a21 = this.e9;
1393
- const a22 = this.e10;
1394
- const a23 = this.e11;
1395
- const a30 = this.e12;
1396
- const a31 = this.e13;
1397
- const a32 = this.e14;
1398
- const a33 = this.e15;
1399
- const b00 = a00 * a11 - a01 * a10;
1400
- const b01 = a00 * a12 - a02 * a10;
1401
- const b02 = a00 * a13 - a03 * a10;
1402
- const b03 = a01 * a12 - a02 * a11;
1403
- const b04 = a01 * a13 - a03 * a11;
1404
- const b05 = a02 * a13 - a03 * a12;
1405
- const b06 = a20 * a31 - a21 * a30;
1406
- const b07 = a20 * a32 - a22 * a30;
1407
- const b08 = a20 * a33 - a23 * a30;
1408
- const b09 = a21 * a32 - a22 * a31;
1409
- const b10 = a21 * a33 - a23 * a31;
1410
- const b11 = a22 * a33 - a23 * a32;
1411
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1412
- if (!det) {
1413
- return null;
1340
+ pushVertex(value) {
1341
+ if (this.numVertices >= this.buffer.maxLength) {
1342
+ throw new Error("Face is full");
1414
1343
  }
1415
- det = 1 / det;
1416
- this.e0 = (a11 * b11 - a12 * b10 + a13 * b09) * det;
1417
- this.e1 = (a02 * b10 - a01 * b11 - a03 * b09) * det;
1418
- this.e2 = (a31 * b05 - a32 * b04 + a33 * b03) * det;
1419
- this.e3 = (a22 * b04 - a21 * b05 - a23 * b03) * det;
1420
- this.e4 = (a12 * b08 - a10 * b11 - a13 * b07) * det;
1421
- this.e5 = (a00 * b11 - a02 * b08 + a03 * b07) * det;
1422
- this.e6 = (a32 * b02 - a30 * b05 - a33 * b01) * det;
1423
- this.e7 = (a20 * b05 - a22 * b02 + a23 * b01) * det;
1424
- this.e8 = (a10 * b10 - a11 * b08 + a13 * b06) * det;
1425
- this.e9 = (a01 * b08 - a00 * b10 - a03 * b06) * det;
1426
- this.e10 = (a30 * b04 - a31 * b02 + a33 * b00) * det;
1427
- this.e11 = (a21 * b02 - a20 * b04 - a23 * b00) * det;
1428
- this.e12 = (a11 * b07 - a10 * b09 - a12 * b06) * det;
1429
- this.e13 = (a00 * b09 - a01 * b07 + a02 * b06) * det;
1430
- this.e14 = (a31 * b01 - a30 * b03 - a32 * b00) * det;
1431
- this.e15 = (a20 * b03 - a21 * b01 + a22 * b00) * det;
1432
- return this;
1344
+ this.buffer.getAtIndex(this.numVertices).copy(value);
1345
+ this.numVertices++;
1433
1346
  }
1434
- invertMatrix(a3) {
1435
- const a00 = a3.e0;
1436
- const a01 = a3.e1;
1437
- const a02 = a3.e2;
1438
- const a03 = a3.e3;
1439
- const a10 = a3.e4;
1440
- const a11 = a3.e5;
1441
- const a12 = a3.e6;
1442
- const a13 = a3.e7;
1443
- const a20 = a3.e8;
1444
- const a21 = a3.e9;
1445
- const a22 = a3.e10;
1446
- const a23 = a3.e11;
1447
- const a30 = a3.e12;
1448
- const a31 = a3.e13;
1449
- const a32 = a3.e14;
1450
- const a33 = a3.e15;
1451
- const b00 = a00 * a11 - a01 * a10;
1452
- const b01 = a00 * a12 - a02 * a10;
1453
- const b02 = a00 * a13 - a03 * a10;
1454
- const b03 = a01 * a12 - a02 * a11;
1455
- const b04 = a01 * a13 - a03 * a11;
1456
- const b05 = a02 * a13 - a03 * a12;
1457
- const b06 = a20 * a31 - a21 * a30;
1458
- const b07 = a20 * a32 - a22 * a30;
1459
- const b08 = a20 * a33 - a23 * a30;
1460
- const b09 = a21 * a32 - a22 * a31;
1461
- const b10 = a21 * a33 - a23 * a31;
1462
- const b11 = a22 * a33 - a23 * a32;
1463
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1464
- if (!det) {
1465
- return null;
1347
+ pushVertexValues(x2, y4, z) {
1348
+ if (this.numVertices >= this.buffer.maxLength) {
1349
+ throw new Error("Face is full");
1466
1350
  }
1467
- det = 1 / det;
1468
- this.e0 = (a11 * b11 - a12 * b10 + a13 * b09) * det;
1469
- this.e1 = (a02 * b10 - a01 * b11 - a03 * b09) * det;
1470
- this.e2 = (a31 * b05 - a32 * b04 + a33 * b03) * det;
1471
- this.e3 = (a22 * b04 - a21 * b05 - a23 * b03) * det;
1472
- this.e4 = (a12 * b08 - a10 * b11 - a13 * b07) * det;
1473
- this.e5 = (a00 * b11 - a02 * b08 + a03 * b07) * det;
1474
- this.e6 = (a32 * b02 - a30 * b05 - a33 * b01) * det;
1475
- this.e7 = (a20 * b05 - a22 * b02 + a23 * b01) * det;
1476
- this.e8 = (a10 * b10 - a11 * b08 + a13 * b06) * det;
1477
- this.e9 = (a01 * b08 - a00 * b10 - a03 * b06) * det;
1478
- this.e10 = (a30 * b04 - a31 * b02 + a33 * b00) * det;
1479
- this.e11 = (a21 * b02 - a20 * b04 - a23 * b00) * det;
1480
- this.e12 = (a11 * b07 - a10 * b09 - a12 * b06) * det;
1481
- this.e13 = (a00 * b09 - a01 * b07 + a02 * b06) * det;
1482
- this.e14 = (a31 * b01 - a30 * b03 - a32 * b00) * det;
1483
- this.e15 = (a20 * b03 - a21 * b01 + a22 * b00) * det;
1484
- return this;
1351
+ const vertex3 = this.buffer.getAtIndex(this.numVertices);
1352
+ vertex3.x = x2;
1353
+ vertex3.y = y4;
1354
+ vertex3.z = z;
1355
+ this.numVertices++;
1485
1356
  }
1486
- getColumn3(out, index) {
1487
- switch (index) {
1488
- case 0: {
1489
- out.x = this.e0;
1490
- out.y = this.e1;
1491
- out.z = this.e2;
1492
- break;
1493
- }
1494
- case 1: {
1495
- out.x = this.e4;
1496
- out.y = this.e5;
1497
- out.z = this.e6;
1498
- break;
1499
- }
1357
+ transform(isometry2) {
1358
+ for (let i = 0; i < this.numVertices; i++) {
1359
+ this.buffer.getAtIndex(i).transformByMat4(isometry2);
1360
+ }
1361
+ }
1362
+ getCentroid(out) {
1363
+ out.zero();
1364
+ for (let i = 0; i < this.numVertices; i++) {
1365
+ out.addVector(this.buffer.getAtIndex(i));
1366
+ }
1367
+ out.scale(1 / this.numVertices);
1368
+ }
1369
+ getNormal(out) {
1370
+ switch (this.numVertices) {
1371
+ case 0:
1372
+ case 1:
1500
1373
  case 2: {
1501
- out.x = this.e8;
1502
- out.y = this.e9;
1503
- out.z = this.e10;
1374
+ out.zero();
1504
1375
  break;
1505
1376
  }
1377
+ default: {
1378
+ triangle$1.a.copy(this.buffer.getAtIndex(0));
1379
+ triangle$1.b.copy(this.buffer.getAtIndex(1));
1380
+ triangle$1.c.copy(this.buffer.getAtIndex(2));
1381
+ triangle$1.computeNormal(out);
1382
+ }
1506
1383
  }
1507
1384
  }
1508
- multiplyMatrix(b3) {
1509
- let a00 = this.e0, a01 = this.e1, a02 = this.e2, a03 = this.e3;
1510
- let a10 = this.e4, a11 = this.e5, a12 = this.e6, a13 = this.e7;
1511
- let a20 = this.e8, a21 = this.e9, a22 = this.e10, a23 = this.e11;
1512
- let a30 = this.e12, a31 = this.e13, a32 = this.e14, a33 = this.e15;
1513
- let b0 = b3.e0, b12 = b3.e1, b22 = b3.e2, b32 = b3.e3;
1514
- this.e0 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1515
- this.e1 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1516
- this.e2 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1517
- this.e3 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1518
- b0 = b3.e4;
1519
- b12 = b3.e5;
1520
- b22 = b3.e6;
1521
- b32 = b3.e7;
1522
- this.e4 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1523
- this.e5 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1524
- this.e6 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1525
- this.e7 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1526
- b0 = b3.e8;
1527
- b12 = b3.e9;
1528
- b22 = b3.e10;
1529
- b32 = b3.e11;
1530
- this.e8 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1531
- this.e9 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1532
- this.e10 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1533
- this.e11 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1534
- b0 = b3.e12;
1535
- b12 = b3.e13;
1536
- b22 = b3.e14;
1537
- b32 = b3.e15;
1538
- this.e12 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1539
- this.e13 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1540
- this.e14 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1541
- this.e15 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1542
- return this;
1385
+ translate(translation) {
1386
+ for (let i = 0; i < this.numVertices; i++) {
1387
+ this.buffer.getAtIndex(i).addVector(translation);
1388
+ }
1543
1389
  }
1544
- multiplyMatrices(a3, b3) {
1545
- let a00 = a3.e0, a01 = a3.e1, a02 = a3.e2, a03 = a3.e3;
1546
- let a10 = a3.e4, a11 = a3.e5, a12 = a3.e6, a13 = a3.e7;
1547
- let a20 = a3.e8, a21 = a3.e9, a22 = a3.e10, a23 = a3.e11;
1548
- let a30 = a3.e12, a31 = a3.e13, a32 = a3.e14, a33 = a3.e15;
1549
- let b0 = b3.e0, b12 = b3.e1, b22 = b3.e2, b32 = b3.e3;
1550
- this.e0 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1551
- this.e1 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1552
- this.e2 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1553
- this.e3 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1554
- b0 = b3.e4;
1555
- b12 = b3.e5;
1556
- b22 = b3.e6;
1557
- b32 = b3.e7;
1558
- this.e4 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1559
- this.e5 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1560
- this.e6 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1561
- this.e7 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1562
- b0 = b3.e8;
1563
- b12 = b3.e9;
1564
- b22 = b3.e10;
1565
- b32 = b3.e11;
1566
- this.e8 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1567
- this.e9 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1568
- this.e10 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1569
- this.e11 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1570
- b0 = b3.e12;
1571
- b12 = b3.e13;
1572
- b22 = b3.e14;
1573
- b32 = b3.e15;
1574
- this.e12 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1575
- this.e13 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1576
- this.e14 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1577
- this.e15 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1578
- return this;
1390
+ swap(other) {
1391
+ if (this.numVertices !== other.numVertices) {
1392
+ throw new Error("Cannot swap faces of different sizes");
1393
+ }
1394
+ for (let i = 0; i < this.numVertices; i++) {
1395
+ tempVertex.copy(this.buffer.getAtIndex(i));
1396
+ this.buffer.getAtIndex(i).copy(other.buffer.getAtIndex(i));
1397
+ other.buffer.getAtIndex(i).copy(tempVertex);
1398
+ }
1579
1399
  }
1580
- preScaled(scale2) {
1581
- this.e0 *= scale2.x;
1582
- this.e1 *= scale2.x;
1583
- this.e2 *= scale2.x;
1584
- this.e4 *= scale2.y;
1585
- this.e5 *= scale2.y;
1586
- this.e6 *= scale2.y;
1587
- this.e8 *= scale2.z;
1588
- this.e9 *= scale2.z;
1589
- this.e10 *= scale2.z;
1590
- return this;
1400
+ }
1401
+ const oldCreate$b = Face.create;
1402
+ Face.create = function() {
1403
+ const face = oldCreate$b.apply(this, arguments);
1404
+ if (isFinite(face.buffer.maxLength)) {
1405
+ for (let i = 0; i < face.buffer.maxLength; i++) {
1406
+ face.buffer.create();
1407
+ }
1591
1408
  }
1592
- toObject() {
1593
- return {
1594
- e0: this.e0,
1595
- e1: this.e1,
1596
- e2: this.e2,
1597
- e3: this.e3,
1598
- e4: this.e4,
1599
- e5: this.e5,
1600
- e6: this.e6,
1601
- e7: this.e7,
1602
- e8: this.e8,
1603
- e9: this.e9,
1604
- e10: this.e10,
1605
- e11: this.e11,
1606
- e12: this.e12,
1607
- e13: this.e13,
1608
- e14: this.e14,
1609
- e15: this.e15
1610
- };
1611
- }
1612
- identity() {
1613
- this.e0 = 1;
1614
- this.e1 = 0;
1615
- this.e2 = 0;
1616
- this.e3 = 0;
1617
- this.e4 = 0;
1618
- this.e5 = 1;
1619
- this.e6 = 0;
1620
- this.e7 = 0;
1621
- this.e8 = 0;
1622
- this.e9 = 0;
1623
- this.e10 = 1;
1624
- this.e11 = 0;
1625
- this.e12 = 0;
1626
- this.e13 = 0;
1627
- this.e14 = 0;
1628
- this.e15 = 1;
1629
- return this;
1630
- }
1631
- getRotationMatrix4(out) {
1632
- out.copy(this);
1633
- out.e12 = 0;
1634
- out.e13 = 0;
1635
- out.e14 = 0;
1636
- out.e15 = 1;
1409
+ return face;
1410
+ };
1411
+ const quatKeys = ["x", "y", "z", "w"];
1412
+ const quatProps = props({
1413
+ x: 0,
1414
+ y: 0,
1415
+ z: 0,
1416
+ w: 1
1417
+ });
1418
+ class Quat extends createClass()(quatProps) {
1419
+ constructor(data, index, pool) {
1420
+ if (Array.isArray(data)) {
1421
+ if (data.length && data.length < 4) {
1422
+ tempQuat.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
1423
+ } else {
1424
+ tempQuat.x = data[0] ?? 0;
1425
+ tempQuat.y = data[1] ?? 0;
1426
+ tempQuat.z = data[2] ?? 0;
1427
+ tempQuat.w = data[3] ?? 1;
1428
+ }
1429
+ super(tempQuat, index, pool);
1430
+ return;
1431
+ }
1432
+ super(data, index, pool);
1637
1433
  }
1638
- decompose(outTranslation, outOrientation, outScale) {
1639
- outTranslation.x = this.e12;
1640
- outTranslation.y = this.e13;
1641
- outTranslation.z = this.e14;
1642
- let m11 = this.e0;
1643
- let m12 = this.e1;
1644
- let m13 = this.e2;
1645
- let m21 = this.e4;
1646
- let m22 = this.e5;
1647
- let m23 = this.e6;
1648
- let m31 = this.e8;
1649
- let m32 = this.e9;
1650
- let m33 = this.e10;
1651
- outScale.x = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
1652
- outScale.y = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
1653
- outScale.z = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
1654
- let is1 = 1 / outScale.x;
1655
- let is2 = 1 / outScale.y;
1656
- let is3 = 1 / outScale.z;
1657
- let sm11 = m11 * is1;
1658
- let sm12 = m12 * is2;
1659
- let sm13 = m13 * is3;
1660
- let sm21 = m21 * is1;
1661
- let sm22 = m22 * is2;
1662
- let sm23 = m23 * is3;
1663
- let sm31 = m31 * is1;
1664
- let sm32 = m32 * is2;
1665
- let sm33 = m33 * is3;
1666
- let trace = sm11 + sm22 + sm33;
1667
- let S = 0;
1668
- if (trace > 0) {
1669
- S = Math.sqrt(trace + 1) * 2;
1670
- outOrientation.w = 0.25 * S;
1671
- outOrientation.x = (sm23 - sm32) / S;
1672
- outOrientation.y = (sm31 - sm13) / S;
1673
- outOrientation.z = (sm12 - sm21) / S;
1674
- } else if (sm11 > sm22 && sm11 > sm33) {
1675
- S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
1676
- outOrientation.w = (sm23 - sm32) / S;
1677
- outOrientation.x = 0.25 * S;
1678
- outOrientation.y = (sm12 + sm21) / S;
1679
- outOrientation.z = (sm31 + sm13) / S;
1680
- } else if (sm22 > sm33) {
1681
- S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
1682
- outOrientation.w = (sm31 - sm13) / S;
1683
- outOrientation.x = (sm12 + sm21) / S;
1684
- outOrientation.y = 0.25 * S;
1685
- outOrientation.z = (sm23 + sm32) / S;
1434
+ reset(data) {
1435
+ if (Array.isArray(data)) {
1436
+ if (data.length && data.length < 4) {
1437
+ return this.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
1438
+ }
1439
+ this.x = data[0] ?? 0;
1440
+ this.y = data[1] ?? 0;
1441
+ this.z = data[2] ?? 0;
1442
+ this.w = data[3] ?? 1;
1686
1443
  } else {
1687
- S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
1688
- outOrientation.w = (sm12 - sm21) / S;
1689
- outOrientation.x = (sm31 + sm13) / S;
1690
- outOrientation.y = (sm23 + sm32) / S;
1691
- outOrientation.z = 0.25 * S;
1444
+ if (data && data.w === void 0 && (data.x || data.y || data.z)) {
1445
+ return this.setFromEulerRadians(data.x ?? 0, data.y ?? 0, data.z ?? 0);
1446
+ }
1447
+ this.x = data?.x ?? 0;
1448
+ this.y = data?.y ?? 0;
1449
+ this.z = data?.z ?? 0;
1450
+ this.w = data?.w ?? 1;
1692
1451
  }
1693
1452
  return this;
1694
1453
  }
1695
- compose(translation, orientation, scale2) {
1696
- let x2 = orientation.x, y4 = orientation.y, z = orientation.z, w3 = orientation.w;
1697
- let x22 = x2 + x2;
1698
- let y22 = y4 + y4;
1699
- let z2 = z + z;
1700
- let xx = x2 * x22;
1701
- let xy = x2 * y22;
1702
- let xz = x2 * z2;
1703
- let yy = y4 * y22;
1704
- let yz = y4 * z2;
1705
- let zz = z * z2;
1706
- let wx = w3 * x22;
1707
- let wy = w3 * y22;
1708
- let wz = w3 * z2;
1709
- let sx = scale2.x;
1710
- let sy = scale2.y;
1711
- let sz = scale2.z;
1712
- this.e0 = (1 - (yy + zz)) * sx;
1713
- this.e1 = (xy + wz) * sx;
1714
- this.e2 = (xz - wy) * sx;
1715
- this.e3 = 0;
1716
- this.e4 = (xy - wz) * sy;
1717
- this.e5 = (1 - (xx + zz)) * sy;
1718
- this.e6 = (yz + wx) * sy;
1719
- this.e7 = 0;
1720
- this.e8 = (xz + wy) * sz;
1721
- this.e9 = (yz - wx) * sz;
1722
- this.e10 = (1 - (xx + yy)) * sz;
1723
- this.e11 = 0;
1724
- this.e12 = translation.x;
1725
- this.e13 = translation.y;
1726
- this.e14 = translation.z;
1727
- this.e15 = 1;
1454
+ set(data) {
1455
+ if (Array.isArray(data)) {
1456
+ if (data.length && data.length < 4) {
1457
+ return this.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
1458
+ }
1459
+ this.x = data[0] ?? 0;
1460
+ this.y = data[1] ?? 0;
1461
+ this.z = data[2] ?? 0;
1462
+ this.w = data[3] ?? 1;
1463
+ } else if (data) {
1464
+ if (data.x !== void 0) {
1465
+ this.x = data.x;
1466
+ }
1467
+ if (data.y !== void 0) {
1468
+ this.y = data.y;
1469
+ }
1470
+ if (data.z !== void 0) {
1471
+ this.z = data.z;
1472
+ }
1473
+ if (data.w !== void 0) {
1474
+ this.w = data.w;
1475
+ }
1476
+ }
1728
1477
  return this;
1729
1478
  }
1730
- }
1731
- const rotation$3 = /* @__PURE__ */ Quat.create();
1732
- const cross_bn_cn = /* @__PURE__ */ Vec3.create();
1733
- const planeProps = props({
1734
- normal: Vec3,
1735
- constant: 0
1736
- });
1737
- class Plane extends createClass()(planeProps) {
1738
- toObject() {
1739
- return {
1740
- normal: this.normal.toObject(),
1741
- constant: this.constant
1742
- };
1743
- }
1744
- fromPointAndNormal(point2, normal4) {
1745
- this.normal.copy(normal4);
1746
- this.constant = -normal4.dot(point2);
1747
- }
1748
- signedDistance(point2) {
1749
- return point2.dot(this.normal) + this.constant;
1479
+ length() {
1480
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
1750
1481
  }
1751
- offsetAlongNormal(out, inDistance) {
1752
- out.copy(this);
1753
- out.constant -= inDistance;
1482
+ normalize() {
1483
+ const length = this.length();
1484
+ if (length > 0) {
1485
+ this.x /= length;
1486
+ this.y /= length;
1487
+ this.z /= length;
1488
+ this.w /= length;
1489
+ }
1490
+ return this;
1754
1491
  }
1755
- offsetPlaneAlongNormal(plane, inDistance) {
1756
- this.normal.copy(plane.normal);
1757
- this.constant = plane.constant - inDistance;
1492
+ identity() {
1493
+ this.x = 0;
1494
+ this.y = 0;
1495
+ this.z = 0;
1496
+ this.w = 1;
1497
+ return this;
1758
1498
  }
1759
- toString() {
1760
- return `Plane { normal: ${this.normal.toString()}, constant: ${this.constant} }`;
1499
+ conjugateQuat(a3) {
1500
+ this.x = -a3.x;
1501
+ this.y = -a3.y;
1502
+ this.z = -a3.z;
1503
+ this.w = a3.w;
1504
+ return this;
1761
1505
  }
1762
- static intersectPlanes(planeA, planeB, planeC, outPoint) {
1763
- cross_bn_cn.crossVectors(planeB.normal, planeC.normal);
1764
- const denominator = planeA.normal.dot(cross_bn_cn);
1765
- if (denominator === 0) {
1766
- return false;
1767
- }
1768
- const a3 = planeA.normal;
1769
- const b3 = planeB.normal;
1770
- const c3 = planeC.normal;
1506
+ multiplyQuats(a3, b3) {
1771
1507
  const ax = a3.x;
1772
1508
  const ay = a3.y;
1773
1509
  const az = a3.z;
1510
+ const aw = a3.w;
1774
1511
  const bx = b3.x;
1775
1512
  const by = b3.y;
1776
1513
  const bz = b3.z;
1777
- const cx = c3.x;
1778
- const cy = c3.y;
1779
- const cz = c3.z;
1780
- const aw = planeA.constant;
1781
- const bw = planeB.constant;
1782
- const cw = planeC.constant;
1783
- outPoint.x = aw * (bz * cy - by * cz) + ay * (bw * cz - bz * cw) + az * (by * cw - bw * cy);
1784
- outPoint.y = aw * (bx * cz - bz * cx) + ax * (bz * cw - bw * cz) + az * (bw * cx - bx * cw);
1785
- outPoint.z = aw * (by * cx - bx * cy) + ax * (bw * cy - by * cw) + ay * (bx * cw - bw * cx);
1786
- outPoint.scale(1 / denominator);
1787
- return true;
1788
- }
1789
- /**
1790
- * return the normalized fraction of the ray that intersects the plane in the interval [0.0, 1.0]
1791
- */
1792
- castRay(ray2) {
1793
- const denominator = this.normal.dot(ray2.direction);
1794
- if (Math.abs(denominator) < 1e-6) {
1795
- return 1;
1796
- }
1797
- const t = (this.constant - this.normal.dot(ray2.origin)) / denominator;
1798
- const fraction = t / ray2.length;
1799
- if (fraction < 0 || fraction > 1) {
1800
- return 1;
1514
+ const bw = b3.w;
1515
+ this.x = ax * bw + aw * bx + ay * bz - az * by;
1516
+ this.y = ay * bw + aw * by + az * bx - ax * bz;
1517
+ this.z = az * bw + aw * bz + ax * by - ay * bx;
1518
+ this.w = aw * bw - ax * bx - ay * by - az * bz;
1519
+ return this;
1520
+ }
1521
+ normalizeQuat(a3) {
1522
+ const x2 = a3.x;
1523
+ const y4 = a3.y;
1524
+ const z = a3.z;
1525
+ const w3 = a3.w;
1526
+ let len = x2 * x2 + y4 * y4 + z * z + w3 * w3;
1527
+ if (len > 0) {
1528
+ len = 1 / Math.sqrt(len);
1801
1529
  }
1802
- return fraction;
1530
+ this.x = x2 * len;
1531
+ this.y = y4 * len;
1532
+ this.z = z * len;
1533
+ this.w = w3 * len;
1534
+ return this;
1803
1535
  }
1804
- }
1805
- const segmentProps = props({
1806
- pointA: Vec3,
1807
- pointB: Vec3
1808
- });
1809
- class Segment extends createClass()(segmentProps) {
1810
- computeCenter(out) {
1811
- out.addVectors(this.pointA, this.pointB);
1812
- out.scaleVector(out, 0.5);
1536
+ setAxisAngle(axis2, angle) {
1537
+ angle = angle * 0.5;
1538
+ let s2 = Math.sin(angle);
1539
+ this.x = s2 * axis2.x;
1540
+ this.y = s2 * axis2.y;
1541
+ this.z = s2 * axis2.z;
1542
+ this.w = Math.cos(angle);
1543
+ return this;
1813
1544
  }
1814
- computeHalfExtents(out) {
1815
- out.subtractVectors(this.pointB, this.pointA);
1816
- out.scaleVector(out, 0.5);
1545
+ dot(b3) {
1546
+ return this.x * b3.x + this.y * b3.y + this.z * b3.z + this.w * b3.w;
1817
1547
  }
1818
- setFromRay(ray2) {
1819
- this.pointA.copy(ray2.origin);
1820
- this.pointB.addScaledToVector(ray2.origin, ray2.direction, ray2.length);
1548
+ notEquals(other, tolerance = 1e-6) {
1549
+ return Math.abs(this.x - other.x) >= tolerance || Math.abs(this.y - other.y) >= tolerance || Math.abs(this.z - other.z) >= tolerance || Math.abs(this.w - other.w) >= tolerance;
1821
1550
  }
1822
- }
1823
- const epsilon$2 = 1e-7;
1824
- const newMin = /* @__PURE__ */ Vec3.create();
1825
- const newMax = /* @__PURE__ */ Vec3.create();
1826
- const col = /* @__PURE__ */ Vec3.create();
1827
- const a$2 = /* @__PURE__ */ Vec3.create();
1828
- const b$1 = /* @__PURE__ */ Vec3.create();
1829
- const aabbProps = props({
1830
- min: Vec3,
1831
- max: Vec3,
1832
- centroid: ChildType(Vec3, void 0, true)
1833
- });
1834
- class Aabb extends createClass()(aabbProps) {
1835
- computeSupport(out, direction2) {
1836
- out.x = direction2.x < 0 ? this.min.x : this.max.x;
1837
- out.y = direction2.y < 0 ? this.min.y : this.max.y;
1838
- out.z = direction2.z < 0 ? this.min.z : this.max.z;
1551
+ equals(other, tolerance = 1e-6) {
1552
+ return Math.abs(this.x - other.x) < tolerance && Math.abs(this.y - other.y) < tolerance && Math.abs(this.z - other.z) < tolerance && Math.abs(this.w - other.w) < tolerance;
1839
1553
  }
1840
- computeSupportingFace(out, inDirection) {
1841
- const absX = Math.abs(inDirection.x);
1842
- const absY = Math.abs(inDirection.y);
1843
- const absZ = Math.abs(inDirection.z);
1844
- const axis2 = absX > absY ? absX > absZ ? 0 : 2 : absY > absZ ? 1 : 2;
1845
- const component = inDirection.getComponentAtIndex(axis2);
1846
- if (component < 0) {
1847
- switch (axis2) {
1848
- case 0: {
1849
- out.pushVertexValues(this.max.x, this.min.y, this.min.z);
1850
- out.pushVertexValues(this.max.x, this.max.y, this.min.z);
1851
- out.pushVertexValues(this.max.x, this.max.y, this.max.z);
1852
- out.pushVertexValues(this.max.x, this.min.y, this.max.z);
1853
- break;
1854
- }
1855
- case 1: {
1856
- out.pushVertexValues(this.min.x, this.max.y, this.min.z);
1857
- out.pushVertexValues(this.min.x, this.max.y, this.max.z);
1858
- out.pushVertexValues(this.max.x, this.max.y, this.max.z);
1859
- out.pushVertexValues(this.max.x, this.max.y, this.min.z);
1860
- break;
1861
- }
1862
- case 2: {
1863
- out.pushVertexValues(this.min.x, this.min.y, this.max.z);
1864
- out.pushVertexValues(this.max.x, this.min.y, this.max.z);
1865
- out.pushVertexValues(this.max.x, this.max.y, this.max.z);
1866
- out.pushVertexValues(this.min.x, this.max.y, this.max.z);
1867
- break;
1868
- }
1869
- }
1554
+ intoEuler(out) {
1555
+ if (this.w < 0) {
1556
+ out.x = -this.x * 2;
1557
+ out.y = -this.y * 2;
1558
+ out.z = -this.z * 2;
1870
1559
  } else {
1871
- switch (axis2) {
1872
- case 0: {
1873
- out.pushVertexValues(this.min.x, this.min.y, this.min.z);
1874
- out.pushVertexValues(this.min.x, this.min.y, this.max.z);
1875
- out.pushVertexValues(this.min.x, this.max.y, this.max.z);
1876
- out.pushVertexValues(this.min.x, this.max.y, this.min.z);
1877
- break;
1878
- }
1879
- case 1: {
1880
- out.pushVertexValues(this.min.x, this.min.y, this.min.z);
1881
- out.pushVertexValues(this.max.x, this.min.y, this.min.z);
1882
- out.pushVertexValues(this.max.x, this.min.y, this.max.z);
1883
- out.pushVertexValues(this.min.x, this.min.y, this.max.z);
1884
- break;
1885
- }
1886
- case 2: {
1887
- out.pushVertexValues(this.min.x, this.min.y, this.min.z);
1888
- out.pushVertexValues(this.min.x, this.max.y, this.min.z);
1889
- out.pushVertexValues(this.max.x, this.max.y, this.min.z);
1890
- out.pushVertexValues(this.max.x, this.min.y, this.min.z);
1891
- break;
1892
- }
1893
- }
1560
+ out.x = this.x * 2;
1561
+ out.y = this.y * 2;
1562
+ out.z = this.z * 2;
1894
1563
  }
1895
- }
1896
- translate(translation) {
1897
- this.min.addVector(translation);
1898
- this.max.addVector(translation);
1899
- this.computeCentroid(this.centroid);
1900
- }
1901
- translateAabb(aabb, translation) {
1902
- this.min.addVectors(aabb.min, translation);
1903
- this.max.addVectors(aabb.max, translation);
1904
- this.computeCentroid(this.centroid);
1905
1564
  return this;
1906
1565
  }
1907
- transform(transform2) {
1908
- transform2.matrix.getTranslation(newMin);
1909
- transform2.matrix.getTranslation(newMax);
1910
- for (let c3 = 0; c3 < 3; ++c3) {
1911
- transform2.matrix.getColumn3(col, c3);
1912
- const minComponent = this.min.getComponentAtIndex(c3);
1913
- const maxComponent = this.max.getComponentAtIndex(c3);
1914
- a$2.scaleVector(col, minComponent);
1915
- b$1.scaleVector(col, maxComponent);
1916
- newMin.x += Math.min(a$2.x, b$1.x);
1917
- newMin.y += Math.min(a$2.y, b$1.y);
1918
- newMin.z += Math.min(a$2.z, b$1.z);
1919
- newMax.x += Math.max(a$2.x, b$1.x);
1920
- newMax.y += Math.max(a$2.y, b$1.y);
1921
- newMax.z += Math.max(a$2.z, b$1.z);
1566
+ fromMat3(m) {
1567
+ let fTrace = m.e0 + m.e4 + m.e8;
1568
+ let fRoot;
1569
+ if (fTrace > 0) {
1570
+ fRoot = Math.sqrt(fTrace + 1);
1571
+ this.w = 0.5 * fRoot;
1572
+ fRoot = 0.5 / fRoot;
1573
+ this.x = (m.e5 - m.e7) * fRoot;
1574
+ this.y = (m.e6 - m.e2) * fRoot;
1575
+ this.z = (m.e1 - m.e3) * fRoot;
1576
+ } else {
1577
+ let i = 0;
1578
+ if (m.e4 > m.e0) i = 1;
1579
+ if (m.e8 > m[mat3Keys[i * 3 + i]]) i = 2;
1580
+ let j = (i + 1) % 3;
1581
+ let k = (i + 2) % 3;
1582
+ fRoot = Math.sqrt(m[mat3Keys[i * 3 + i]] - m[mat3Keys[j * 3 + j]] - m[mat3Keys[k * 3 + k]] + 1);
1583
+ this[quatKeys[i]] = 0.5 * fRoot;
1584
+ fRoot = 0.5 / fRoot;
1585
+ this.w = (m[mat3Keys[j * 3 + k]] - m[mat3Keys[k * 3 + j]]) * fRoot;
1586
+ this[quatKeys[j]] = (m[mat3Keys[j * 3 + i]] + m[mat3Keys[i * 3 + j]]) * fRoot;
1587
+ this[quatKeys[k]] = (m[mat3Keys[k * 3 + i]] + m[mat3Keys[i * 3 + k]]) * fRoot;
1922
1588
  }
1923
- this.min.copy(newMin);
1924
- this.max.copy(newMax);
1925
- this.computeCentroid(this.centroid);
1926
1589
  return this;
1927
1590
  }
1928
- transformAabb(aabb, transform2) {
1929
- transform2.matrix.getTranslation(newMin);
1930
- transform2.matrix.getTranslation(newMax);
1931
- for (let c3 = 0; c3 < 3; ++c3) {
1932
- transform2.matrix.getColumn3(col, c3);
1933
- const minComponent = aabb.min.getComponentAtIndex(c3);
1934
- const maxComponent = aabb.max.getComponentAtIndex(c3);
1935
- a$2.scaleVector(col, minComponent);
1936
- b$1.scaleVector(col, maxComponent);
1937
- newMin.x += Math.min(a$2.x, b$1.x);
1938
- newMin.y += Math.min(a$2.y, b$1.y);
1939
- newMin.z += Math.min(a$2.z, b$1.z);
1940
- newMax.x += Math.max(a$2.x, b$1.x);
1941
- newMax.y += Math.max(a$2.y, b$1.y);
1942
- newMax.z += Math.max(a$2.z, b$1.z);
1943
- }
1944
- this.min.copy(newMin);
1945
- this.max.copy(newMax);
1946
- this.computeCentroid(this.centroid);
1591
+ fromMat4(m) {
1592
+ tempMat3.fromMat4(m);
1593
+ this.fromMat3(tempMat3);
1947
1594
  return this;
1948
1595
  }
1949
- intersectsAabb(aabb) {
1950
- return this.min.x <= aabb.max.x && this.max.x >= aabb.min.x && this.min.y <= aabb.max.y && this.max.y >= aabb.min.y && this.min.z <= aabb.max.z && this.max.z >= aabb.min.z;
1596
+ computeRotationAngle(axis2) {
1597
+ if (this.w === 0) {
1598
+ return Math.PI;
1599
+ } else {
1600
+ vector.x = this.x;
1601
+ vector.y = this.y;
1602
+ vector.z = this.z;
1603
+ return 2 * Math.atan(vector.dot(axis2) / this.w);
1604
+ }
1951
1605
  }
1952
- unionAabb(aabb) {
1953
- this.min.minVectors(this.min, aabb.min);
1954
- this.max.maxVectors(this.max, aabb.max);
1955
- this.computeCentroid(this.centroid);
1606
+ setFromEulerRadians(x2, y4, z) {
1607
+ const halfX = x2 * 0.5;
1608
+ const halfY = y4 * 0.5;
1609
+ const halfZ = z * 0.5;
1610
+ const c12 = Math.cos(halfX);
1611
+ const c22 = Math.cos(halfY);
1612
+ const c3 = Math.cos(halfZ);
1613
+ const s1 = Math.sin(halfX);
1614
+ const s2 = Math.sin(halfY);
1615
+ const s3 = Math.sin(halfZ);
1616
+ this.x = s1 * c22 * c3 + c12 * s2 * s3;
1617
+ this.y = c12 * s2 * c3 - s1 * c22 * s3;
1618
+ this.z = c12 * c22 * s3 + s1 * s2 * c3;
1619
+ this.w = c12 * c22 * c3 - s1 * s2 * s3;
1956
1620
  return this;
1957
1621
  }
1958
- unionAabbs(boxA, boxB) {
1959
- this.min.minVectors(boxA.min, boxB.min);
1960
- this.max.maxVectors(boxA.max, boxB.max);
1961
- this.computeCentroid(this.centroid);
1962
- return this;
1622
+ toObject() {
1623
+ return {
1624
+ x: this.x,
1625
+ y: this.y,
1626
+ z: this.z,
1627
+ w: this.w
1628
+ };
1963
1629
  }
1964
- expand(value) {
1965
- this.min.x -= value;
1966
- this.min.y -= value;
1967
- this.min.z -= value;
1968
- this.max.x += value;
1969
- this.max.y += value;
1970
- this.max.z += value;
1971
- this.computeCentroid(this.centroid);
1972
- }
1973
- expandAabb(aabb, value) {
1974
- this.min.x = aabb.min.x - value;
1975
- this.min.y = aabb.min.y - value;
1976
- this.min.z = aabb.min.z - value;
1977
- this.max.x = aabb.max.x + value;
1978
- this.max.y = aabb.max.y + value;
1979
- this.max.z = aabb.max.z + value;
1980
- this.computeCentroid(this.centroid);
1981
- return this;
1982
- }
1983
- setExtents(min, max) {
1984
- this.min.set(min);
1985
- this.max.set(max);
1986
- this.computeCentroid(this.centroid);
1987
- return this;
1988
- }
1989
- computeSurfaceArea() {
1990
- const dx = this.max.x - this.min.x;
1991
- const dy = this.max.y - this.min.y;
1992
- const dz = this.max.z - this.min.z;
1993
- return 2 * (dx * dy + dy * dz + dz * dx);
1630
+ }
1631
+ const vector = /* @__PURE__ */ Vec3.create();
1632
+ const tempMat3 = /* @__PURE__ */ Mat3.create();
1633
+ const tempQuat = /* @__PURE__ */ Quat.create();
1634
+ const rotationMatrix$2 = /* @__PURE__ */ Mat3.create();
1635
+ const scaling = /* @__PURE__ */ Vec3.create();
1636
+ const conjugatedRotation = /* @__PURE__ */ Quat.create();
1637
+ const rotatedTranslation = /* @__PURE__ */ Vec3.create();
1638
+ const mat4Props = props({
1639
+ e0: 0,
1640
+ e1: 0,
1641
+ e2: 0,
1642
+ e3: 0,
1643
+ e4: 0,
1644
+ e5: 0,
1645
+ e6: 0,
1646
+ e7: 0,
1647
+ e8: 0,
1648
+ e9: 0,
1649
+ e10: 0,
1650
+ e11: 0,
1651
+ e12: 0,
1652
+ e13: 0,
1653
+ e14: 0,
1654
+ e15: 0
1655
+ });
1656
+ class Mat4 extends createClass()(mat4Props) {
1657
+ multiply3x3(out, a3) {
1658
+ const x2 = a3.x;
1659
+ const y4 = a3.y;
1660
+ const z = a3.z;
1661
+ out.x = this.e0 * x2 + this.e4 * y4 + this.e8 * z;
1662
+ out.y = this.e1 * x2 + this.e5 * y4 + this.e9 * z;
1663
+ out.z = this.e2 * x2 + this.e6 * y4 + this.e10 * z;
1664
+ return out;
1994
1665
  }
1995
- computeExtents(out) {
1996
- out.x = this.max.x - this.min.x;
1997
- out.y = this.max.y - this.min.y;
1998
- out.z = this.max.z - this.min.z;
1666
+ multiply3x3Transposed(out, a3) {
1667
+ rotationMatrix$2.fromMat4(this);
1668
+ rotationMatrix$2.transpose();
1669
+ out.transformVectorFromMat3(a3, rotationMatrix$2);
1999
1670
  }
2000
- computeLargestAxis() {
2001
- const dx = this.max.x - this.min.x;
2002
- const dy = this.max.y - this.min.y;
2003
- const dz = this.max.z - this.min.z;
2004
- if (dx >= dy && dx >= dz) {
2005
- return 0;
2006
- }
2007
- if (dy >= dx && dy >= dz) {
2008
- return 1;
2009
- }
2010
- return 2;
1671
+ computeScaling(out) {
1672
+ let m11 = this.e0;
1673
+ let m12 = this.e1;
1674
+ let m13 = this.e2;
1675
+ let m21 = this.e4;
1676
+ let m22 = this.e5;
1677
+ let m23 = this.e6;
1678
+ let m31 = this.e8;
1679
+ let m32 = this.e9;
1680
+ let m33 = this.e10;
1681
+ out.x = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
1682
+ out.y = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
1683
+ out.z = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
1684
+ return out;
2011
1685
  }
2012
- computeLargestComponent() {
2013
- const dx = this.max.x - this.min.x;
2014
- const dy = this.max.y - this.min.y;
2015
- const dz = this.max.z - this.min.z;
2016
- if (dx >= dy && dx >= dz) {
2017
- return "x";
2018
- }
2019
- if (dy >= dx && dy >= dz) {
2020
- return "y";
1686
+ computeRotation(out) {
1687
+ this.computeScaling(scaling);
1688
+ let is1 = 1 / scaling.x;
1689
+ let is2 = 1 / scaling.y;
1690
+ let is3 = 1 / scaling.z;
1691
+ let sm11 = this.e0 * is1;
1692
+ let sm12 = this.e1 * is2;
1693
+ let sm13 = this.e2 * is3;
1694
+ let sm21 = this.e4 * is1;
1695
+ let sm22 = this.e5 * is2;
1696
+ let sm23 = this.e6 * is3;
1697
+ let sm31 = this.e8 * is1;
1698
+ let sm32 = this.e9 * is2;
1699
+ let sm33 = this.e10 * is3;
1700
+ let trace = sm11 + sm22 + sm33;
1701
+ let S = 0;
1702
+ if (trace > 0) {
1703
+ S = Math.sqrt(trace + 1) * 2;
1704
+ out.w = 0.25 * S;
1705
+ out.x = (sm23 - sm32) / S;
1706
+ out.y = (sm31 - sm13) / S;
1707
+ out.z = (sm12 - sm21) / S;
1708
+ } else if (sm11 > sm22 && sm11 > sm33) {
1709
+ S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
1710
+ out.w = (sm23 - sm32) / S;
1711
+ out.x = 0.25 * S;
1712
+ out.y = (sm12 + sm21) / S;
1713
+ out.z = (sm31 + sm13) / S;
1714
+ } else if (sm22 > sm33) {
1715
+ S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
1716
+ out.w = (sm31 - sm13) / S;
1717
+ out.x = (sm12 + sm21) / S;
1718
+ out.y = 0.25 * S;
1719
+ out.z = (sm23 + sm32) / S;
1720
+ } else {
1721
+ S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
1722
+ out.w = (sm12 - sm21) / S;
1723
+ out.x = (sm31 + sm13) / S;
1724
+ out.y = (sm23 + sm32) / S;
1725
+ out.z = 0.25 * S;
2021
1726
  }
2022
- return "z";
2023
- }
2024
- computeCentroid(out) {
2025
- out.x = (this.min.x + this.max.x) * 0.5;
2026
- out.y = (this.min.y + this.max.y) * 0.5;
2027
- out.z = (this.min.z + this.max.z) * 0.5;
2028
1727
  return out;
2029
1728
  }
2030
- computeHalfExtents(out) {
2031
- out.subtractVectors(this.max, this.min);
2032
- out.scaleVector(out, 0.5);
2033
- }
2034
- expandToPoint(point2) {
2035
- this.min.minVector(point2);
2036
- this.max.maxVector(point2);
2037
- return this;
2038
- }
2039
- enclosesAabb(aabb) {
2040
- return this.min.x < aabb.min.x && this.max.x > aabb.max.x && this.min.y < aabb.min.y && this.max.y > aabb.max.y && this.min.z < aabb.min.z && this.max.z > aabb.max.z;
2041
- }
2042
- expandByVector(vector2) {
2043
- this.min.x -= vector2.x;
2044
- this.min.y -= vector2.y;
2045
- this.min.z -= vector2.z;
2046
- this.max.x += vector2.x;
2047
- this.max.y += vector2.y;
2048
- this.max.z += vector2.z;
1729
+ getTranslation(out) {
1730
+ out.x = this.e12;
1731
+ out.y = this.e13;
1732
+ out.z = this.e14;
2049
1733
  }
2050
- toString() {
2051
- return `Aabb(min: ${[this.min.x, this.min.y, this.min.z].join(", ")}, max: ${[
2052
- this.max.x,
2053
- this.max.y,
2054
- this.max.z
2055
- ].join(", ")})`;
1734
+ setTranslation(v4) {
1735
+ this.e12 = v4.x;
1736
+ this.e13 = v4.y;
1737
+ this.e14 = v4.z;
1738
+ this.e15 = 1;
2056
1739
  }
2057
- intersectsRay(ray2) {
2058
- segment.setFromRay(ray2);
2059
- return this.intersectsSegment(segment);
1740
+ preTranslated(translation) {
1741
+ this.e12 += this.e0 * translation.x + this.e4 * translation.y + this.e8 * translation.z;
1742
+ this.e13 += this.e1 * translation.x + this.e5 * translation.y + this.e9 * translation.z;
1743
+ this.e14 += this.e2 * translation.x + this.e6 * translation.y + this.e10 * translation.z;
1744
+ this.e15 = 1;
1745
+ return this;
2060
1746
  }
2061
- /**
2062
- * from Christer Ericson's book "Real-Time Collision Detection", "5.3.3 Intersecting Ray or Segment Against Box"
2063
- */
2064
- intersectsSegment(segment2) {
2065
- this.computeCentroid(aabbCenter);
2066
- this.computeHalfExtents(aabbHalfExtents);
2067
- segment2.computeCenter(segmentCenter);
2068
- segment2.computeHalfExtents(segmentHalfExtents);
2069
- segmentCenter.subtractVectors(segmentCenter, aabbCenter);
2070
- let adx = Math.abs(segmentHalfExtents.x);
2071
- if (Math.abs(segmentCenter.x) > aabbHalfExtents.x + adx) {
2072
- return false;
2073
- }
2074
- let ady = Math.abs(segmentHalfExtents.y);
2075
- if (Math.abs(segmentCenter.y) > aabbHalfExtents.y + ady) {
2076
- return false;
2077
- }
2078
- let adz = Math.abs(segmentHalfExtents.z);
2079
- if (Math.abs(segmentCenter.z) > aabbHalfExtents.z + adz) {
2080
- return false;
2081
- }
2082
- adx += epsilon$2;
2083
- ady += epsilon$2;
2084
- adz += epsilon$2;
2085
- if (Math.abs(segmentCenter.y * segmentHalfExtents.z - segmentCenter.z * segmentHalfExtents.y) > aabbHalfExtents.y * adz + aabbHalfExtents.z * ady) {
2086
- return false;
2087
- }
2088
- if (Math.abs(segmentCenter.z * segmentHalfExtents.x - segmentCenter.x * segmentHalfExtents.z) > aabbHalfExtents.x * adz + aabbHalfExtents.z * adx) {
2089
- return false;
2090
- }
2091
- if (Math.abs(segmentCenter.x * segmentHalfExtents.y - segmentCenter.y * segmentHalfExtents.x) > aabbHalfExtents.x * ady + aabbHalfExtents.y * adx) {
2092
- return false;
2093
- }
2094
- return true;
1747
+ postTranslated(translation) {
1748
+ this.e12 += translation.x;
1749
+ this.e13 += translation.y;
1750
+ this.e14 += translation.z;
1751
+ this.e15 = 1;
1752
+ return this;
2095
1753
  }
2096
- toObject() {
2097
- return {
2098
- min: this.min.toObject(),
2099
- max: this.max.toObject()
2100
- };
1754
+ postTranslatedMatrix(mat, translation) {
1755
+ this.e0 = mat.e0;
1756
+ this.e1 = mat.e1;
1757
+ this.e2 = mat.e2;
1758
+ this.e3 = mat.e3;
1759
+ this.e4 = mat.e4;
1760
+ this.e5 = mat.e5;
1761
+ this.e6 = mat.e6;
1762
+ this.e7 = mat.e7;
1763
+ this.e8 = mat.e8;
1764
+ this.e9 = mat.e9;
1765
+ this.e10 = mat.e10;
1766
+ this.e11 = mat.e11;
1767
+ this.e12 = mat.e12 + translation.x;
1768
+ this.e13 = mat.e13 + translation.y;
1769
+ this.e14 = mat.e14 + translation.z;
1770
+ this.e15 = 1;
1771
+ return this;
2101
1772
  }
2102
- }
2103
- const segment = /* @__PURE__ */ Segment.create();
2104
- const aabbCenter = /* @__PURE__ */ Vec3.create();
2105
- const aabbHalfExtents = /* @__PURE__ */ Vec3.create();
2106
- const segmentCenter = /* @__PURE__ */ Vec3.create();
2107
- const segmentHalfExtents = /* @__PURE__ */ Vec3.create();
2108
- const triangleProps$1 = props({
2109
- computedBounds: ChildType(Aabb, void 0, true),
2110
- normal: ChildType(Vec3, void 0, true),
2111
- a: Vec3,
2112
- b: Vec3,
2113
- c: Vec3,
2114
- subShapeId: NumberType(0, true),
2115
- activeEdges: NumberType(0, true)
2116
- // aabb: { struct: Aabb, readOnly: true },
2117
- // activeEdges: { struct: Uint32, optional: true },
2118
- // translation: { struct: Vec3, optional: true },
2119
- });
2120
- const ab$5 = /* @__PURE__ */ Vec3.create();
2121
- const ac$3 = /* @__PURE__ */ Vec3.create();
2122
- let Triangle$1 = class Triangle extends createClass()(triangleProps$1) {
2123
- // type: ShapeType.triangle = ShapeType.triangle;
2124
- computeNormal(out) {
2125
- ab$5.subtractVectors(this.b, this.a);
2126
- ac$3.subtractVectors(this.c, this.a);
2127
- out.crossVectors(ab$5, ac$3);
2128
- out.normalize();
1773
+ fromRotationTranslation(q4, v4) {
1774
+ const x2 = q4.x;
1775
+ const y4 = q4.y;
1776
+ const z = q4.z;
1777
+ const w3 = q4.w;
1778
+ const x22 = x2 + x2;
1779
+ const y22 = y4 + y4;
1780
+ const z2 = z + z;
1781
+ const xx = x2 * x22;
1782
+ const xy = x2 * y22;
1783
+ const xz = x2 * z2;
1784
+ const yy = y4 * y22;
1785
+ const yz = y4 * z2;
1786
+ const zz = z * z2;
1787
+ const wx = w3 * x22;
1788
+ const wy = w3 * y22;
1789
+ const wz = w3 * z2;
1790
+ this.e0 = 1 - (yy + zz);
1791
+ this.e1 = xy + wz;
1792
+ this.e2 = xz - wy;
1793
+ this.e3 = 0;
1794
+ this.e4 = xy - wz;
1795
+ this.e5 = 1 - (xx + zz);
1796
+ this.e6 = yz + wx;
1797
+ this.e7 = 0;
1798
+ this.e8 = xz + wy;
1799
+ this.e9 = yz - wx;
1800
+ this.e10 = 1 - (xx + yy);
1801
+ this.e11 = 0;
1802
+ this.e12 = v4.x;
1803
+ this.e13 = v4.y;
1804
+ this.e14 = v4.z;
1805
+ this.e15 = 1;
1806
+ return this;
2129
1807
  }
2130
- computeCentroid(out) {
2131
- out.addVectors(this.a, this.b).addVector(this.c).scale(1 / 3);
1808
+ fromAxisAngle(axis2, angle) {
1809
+ rotation$3.setAxisAngle(axis2, angle);
1810
+ this.fromQuat(rotation$3);
1811
+ this.e12 = 0;
1812
+ this.e13 = 0;
1813
+ this.e14 = 0;
1814
+ this.e15 = 1;
1815
+ return this;
2132
1816
  }
2133
- computeUnnormalizedNormal(out) {
2134
- ab$5.subtractVectors(this.b, this.a);
2135
- ac$3.subtractVectors(this.c, this.a);
2136
- out.crossVectors(ab$5, ac$3);
1817
+ fromQuat(q4) {
1818
+ let x2 = q4.x, y4 = q4.y, z = q4.z, w3 = q4.w;
1819
+ let x22 = x2 + x2;
1820
+ let y22 = y4 + y4;
1821
+ let z2 = z + z;
1822
+ let xx = x2 * x22;
1823
+ let yx = y4 * x22;
1824
+ let yy = y4 * y22;
1825
+ let zx = z * x22;
1826
+ let zy = z * y22;
1827
+ let zz = z * z2;
1828
+ let wx = w3 * x22;
1829
+ let wy = w3 * y22;
1830
+ let wz = w3 * z2;
1831
+ this.e0 = 1 - yy - zz;
1832
+ this.e1 = yx + wz;
1833
+ this.e2 = zx - wy;
1834
+ this.e3 = 0;
1835
+ this.e4 = yx - wz;
1836
+ this.e5 = 1 - xx - zz;
1837
+ this.e6 = zy + wx;
1838
+ this.e7 = 0;
1839
+ this.e8 = zx + wy;
1840
+ this.e9 = zy - wx;
1841
+ this.e10 = 1 - xx - yy;
1842
+ this.e11 = 0;
1843
+ this.e12 = 0;
1844
+ this.e13 = 0;
1845
+ this.e14 = 0;
1846
+ this.e15 = 1;
1847
+ return this;
2137
1848
  }
2138
- computeSurfaceNormal(out, inLocalSurfacePosition2, subShapeId) {
2139
- this.computeNormal(out);
1849
+ fromInverseRotationAndTranslation(rotation2, translation) {
1850
+ conjugatedRotation.conjugateQuat(rotation2);
1851
+ this.fromQuat(conjugatedRotation);
1852
+ this.multiply3x3(rotatedTranslation, translation);
1853
+ rotatedTranslation.negate();
1854
+ this.setTranslation(rotatedTranslation);
1855
+ return this;
2140
1856
  }
2141
- transform(isometry2) {
2142
- this.a.transformByMat4(isometry2);
2143
- this.b.transformByMat4(isometry2);
2144
- this.c.transformByMat4(isometry2);
1857
+ invert() {
1858
+ const a00 = this.e0;
1859
+ const a01 = this.e1;
1860
+ const a02 = this.e2;
1861
+ const a03 = this.e3;
1862
+ const a10 = this.e4;
1863
+ const a11 = this.e5;
1864
+ const a12 = this.e6;
1865
+ const a13 = this.e7;
1866
+ const a20 = this.e8;
1867
+ const a21 = this.e9;
1868
+ const a22 = this.e10;
1869
+ const a23 = this.e11;
1870
+ const a30 = this.e12;
1871
+ const a31 = this.e13;
1872
+ const a32 = this.e14;
1873
+ const a33 = this.e15;
1874
+ const b00 = a00 * a11 - a01 * a10;
1875
+ const b01 = a00 * a12 - a02 * a10;
1876
+ const b02 = a00 * a13 - a03 * a10;
1877
+ const b03 = a01 * a12 - a02 * a11;
1878
+ const b04 = a01 * a13 - a03 * a11;
1879
+ const b05 = a02 * a13 - a03 * a12;
1880
+ const b06 = a20 * a31 - a21 * a30;
1881
+ const b07 = a20 * a32 - a22 * a30;
1882
+ const b08 = a20 * a33 - a23 * a30;
1883
+ const b09 = a21 * a32 - a22 * a31;
1884
+ const b10 = a21 * a33 - a23 * a31;
1885
+ const b11 = a22 * a33 - a23 * a32;
1886
+ let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1887
+ if (!det) {
1888
+ return null;
1889
+ }
1890
+ det = 1 / det;
1891
+ this.e0 = (a11 * b11 - a12 * b10 + a13 * b09) * det;
1892
+ this.e1 = (a02 * b10 - a01 * b11 - a03 * b09) * det;
1893
+ this.e2 = (a31 * b05 - a32 * b04 + a33 * b03) * det;
1894
+ this.e3 = (a22 * b04 - a21 * b05 - a23 * b03) * det;
1895
+ this.e4 = (a12 * b08 - a10 * b11 - a13 * b07) * det;
1896
+ this.e5 = (a00 * b11 - a02 * b08 + a03 * b07) * det;
1897
+ this.e6 = (a32 * b02 - a30 * b05 - a33 * b01) * det;
1898
+ this.e7 = (a20 * b05 - a22 * b02 + a23 * b01) * det;
1899
+ this.e8 = (a10 * b10 - a11 * b08 + a13 * b06) * det;
1900
+ this.e9 = (a01 * b08 - a00 * b10 - a03 * b06) * det;
1901
+ this.e10 = (a30 * b04 - a31 * b02 + a33 * b00) * det;
1902
+ this.e11 = (a21 * b02 - a20 * b04 - a23 * b00) * det;
1903
+ this.e12 = (a11 * b07 - a10 * b09 - a12 * b06) * det;
1904
+ this.e13 = (a00 * b09 - a01 * b07 + a02 * b06) * det;
1905
+ this.e14 = (a31 * b01 - a30 * b03 - a32 * b00) * det;
1906
+ this.e15 = (a20 * b03 - a21 * b01 + a22 * b00) * det;
1907
+ return this;
2145
1908
  }
2146
- computeLocalBounds(out) {
2147
- out.min.x = Math.min(this.a.x, this.b.x, this.c.x);
2148
- out.min.y = Math.min(this.a.y, this.b.y, this.c.y);
2149
- out.min.z = Math.min(this.a.z, this.b.z, this.c.z);
2150
- out.max.x = Math.max(this.a.x, this.b.x, this.c.x);
2151
- out.max.y = Math.max(this.a.y, this.b.y, this.c.y);
2152
- out.max.z = Math.max(this.a.z, this.b.z, this.c.z);
2153
- out.computeCentroid(out.centroid);
1909
+ invertMatrix(a3) {
1910
+ const a00 = a3.e0;
1911
+ const a01 = a3.e1;
1912
+ const a02 = a3.e2;
1913
+ const a03 = a3.e3;
1914
+ const a10 = a3.e4;
1915
+ const a11 = a3.e5;
1916
+ const a12 = a3.e6;
1917
+ const a13 = a3.e7;
1918
+ const a20 = a3.e8;
1919
+ const a21 = a3.e9;
1920
+ const a22 = a3.e10;
1921
+ const a23 = a3.e11;
1922
+ const a30 = a3.e12;
1923
+ const a31 = a3.e13;
1924
+ const a32 = a3.e14;
1925
+ const a33 = a3.e15;
1926
+ const b00 = a00 * a11 - a01 * a10;
1927
+ const b01 = a00 * a12 - a02 * a10;
1928
+ const b02 = a00 * a13 - a03 * a10;
1929
+ const b03 = a01 * a12 - a02 * a11;
1930
+ const b04 = a01 * a13 - a03 * a11;
1931
+ const b05 = a02 * a13 - a03 * a12;
1932
+ const b06 = a20 * a31 - a21 * a30;
1933
+ const b07 = a20 * a32 - a22 * a30;
1934
+ const b08 = a20 * a33 - a23 * a30;
1935
+ const b09 = a21 * a32 - a22 * a31;
1936
+ const b10 = a21 * a33 - a23 * a31;
1937
+ const b11 = a22 * a33 - a23 * a32;
1938
+ let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
1939
+ if (!det) {
1940
+ return null;
1941
+ }
1942
+ det = 1 / det;
1943
+ this.e0 = (a11 * b11 - a12 * b10 + a13 * b09) * det;
1944
+ this.e1 = (a02 * b10 - a01 * b11 - a03 * b09) * det;
1945
+ this.e2 = (a31 * b05 - a32 * b04 + a33 * b03) * det;
1946
+ this.e3 = (a22 * b04 - a21 * b05 - a23 * b03) * det;
1947
+ this.e4 = (a12 * b08 - a10 * b11 - a13 * b07) * det;
1948
+ this.e5 = (a00 * b11 - a02 * b08 + a03 * b07) * det;
1949
+ this.e6 = (a32 * b02 - a30 * b05 - a33 * b01) * det;
1950
+ this.e7 = (a20 * b05 - a22 * b02 + a23 * b01) * det;
1951
+ this.e8 = (a10 * b10 - a11 * b08 + a13 * b06) * det;
1952
+ this.e9 = (a01 * b08 - a00 * b10 - a03 * b06) * det;
1953
+ this.e10 = (a30 * b04 - a31 * b02 + a33 * b00) * det;
1954
+ this.e11 = (a21 * b02 - a20 * b04 - a23 * b00) * det;
1955
+ this.e12 = (a11 * b07 - a10 * b09 - a12 * b06) * det;
1956
+ this.e13 = (a00 * b09 - a01 * b07 + a02 * b06) * det;
1957
+ this.e14 = (a31 * b01 - a30 * b03 - a32 * b00) * det;
1958
+ this.e15 = (a20 * b03 - a21 * b01 + a22 * b00) * det;
1959
+ return this;
2154
1960
  }
2155
- computeSupport(out, direction2) {
2156
- const dotA = this.a.dot(direction2);
2157
- const dotB = this.b.dot(direction2);
2158
- const dotC = this.c.dot(direction2);
2159
- if (dotA > dotB) {
2160
- if (dotA > dotC) {
2161
- out.copy(this.a);
2162
- } else {
2163
- out.copy(this.c);
1961
+ getColumn3(out, index) {
1962
+ switch (index) {
1963
+ case 0: {
1964
+ out.x = this.e0;
1965
+ out.y = this.e1;
1966
+ out.z = this.e2;
1967
+ break;
2164
1968
  }
2165
- } else {
2166
- if (dotB > dotC) {
2167
- out.copy(this.b);
2168
- } else {
2169
- out.copy(this.c);
1969
+ case 1: {
1970
+ out.x = this.e4;
1971
+ out.y = this.e5;
1972
+ out.z = this.e6;
1973
+ break;
1974
+ }
1975
+ case 2: {
1976
+ out.x = this.e8;
1977
+ out.y = this.e9;
1978
+ out.z = this.e10;
1979
+ break;
2170
1980
  }
2171
1981
  }
2172
1982
  }
2173
- getConvexRadius() {
2174
- return 0;
1983
+ multiplyMatrix(b3) {
1984
+ let a00 = this.e0, a01 = this.e1, a02 = this.e2, a03 = this.e3;
1985
+ let a10 = this.e4, a11 = this.e5, a12 = this.e6, a13 = this.e7;
1986
+ let a20 = this.e8, a21 = this.e9, a22 = this.e10, a23 = this.e11;
1987
+ let a30 = this.e12, a31 = this.e13, a32 = this.e14, a33 = this.e15;
1988
+ let b0 = b3.e0, b12 = b3.e1, b22 = b3.e2, b32 = b3.e3;
1989
+ this.e0 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1990
+ this.e1 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1991
+ this.e2 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
1992
+ this.e3 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
1993
+ b0 = b3.e4;
1994
+ b12 = b3.e5;
1995
+ b22 = b3.e6;
1996
+ b32 = b3.e7;
1997
+ this.e4 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
1998
+ this.e5 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
1999
+ this.e6 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2000
+ this.e7 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2001
+ b0 = b3.e8;
2002
+ b12 = b3.e9;
2003
+ b22 = b3.e10;
2004
+ b32 = b3.e11;
2005
+ this.e8 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
2006
+ this.e9 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
2007
+ this.e10 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2008
+ this.e11 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2009
+ b0 = b3.e12;
2010
+ b12 = b3.e13;
2011
+ b22 = b3.e14;
2012
+ b32 = b3.e15;
2013
+ this.e12 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
2014
+ this.e13 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
2015
+ this.e14 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2016
+ this.e15 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2017
+ return this;
2175
2018
  }
2176
- computeSupportShape(mode, scale2) {
2019
+ multiplyMatrices(a3, b3) {
2020
+ let a00 = a3.e0, a01 = a3.e1, a02 = a3.e2, a03 = a3.e3;
2021
+ let a10 = a3.e4, a11 = a3.e5, a12 = a3.e6, a13 = a3.e7;
2022
+ let a20 = a3.e8, a21 = a3.e9, a22 = a3.e10, a23 = a3.e11;
2023
+ let a30 = a3.e12, a31 = a3.e13, a32 = a3.e14, a33 = a3.e15;
2024
+ let b0 = b3.e0, b12 = b3.e1, b22 = b3.e2, b32 = b3.e3;
2025
+ this.e0 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
2026
+ this.e1 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
2027
+ this.e2 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2028
+ this.e3 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2029
+ b0 = b3.e4;
2030
+ b12 = b3.e5;
2031
+ b22 = b3.e6;
2032
+ b32 = b3.e7;
2033
+ this.e4 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
2034
+ this.e5 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
2035
+ this.e6 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2036
+ this.e7 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2037
+ b0 = b3.e8;
2038
+ b12 = b3.e9;
2039
+ b22 = b3.e10;
2040
+ b32 = b3.e11;
2041
+ this.e8 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
2042
+ this.e9 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
2043
+ this.e10 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2044
+ this.e11 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2045
+ b0 = b3.e12;
2046
+ b12 = b3.e13;
2047
+ b22 = b3.e14;
2048
+ b32 = b3.e15;
2049
+ this.e12 = b0 * a00 + b12 * a10 + b22 * a20 + b32 * a30;
2050
+ this.e13 = b0 * a01 + b12 * a11 + b22 * a21 + b32 * a31;
2051
+ this.e14 = b0 * a02 + b12 * a12 + b22 * a22 + b32 * a32;
2052
+ this.e15 = b0 * a03 + b12 * a13 + b22 * a23 + b32 * a33;
2053
+ return this;
2054
+ }
2055
+ preScaled(scale2) {
2056
+ this.e0 *= scale2.x;
2057
+ this.e1 *= scale2.x;
2058
+ this.e2 *= scale2.x;
2059
+ this.e4 *= scale2.y;
2060
+ this.e5 *= scale2.y;
2061
+ this.e6 *= scale2.y;
2062
+ this.e8 *= scale2.z;
2063
+ this.e9 *= scale2.z;
2064
+ this.e10 *= scale2.z;
2177
2065
  return this;
2178
2066
  }
2179
2067
  toObject() {
2180
2068
  return {
2181
- a: this.a.toObject(),
2182
- b: this.b.toObject(),
2183
- c: this.c.toObject(),
2184
- normal: this.normal.toObject()
2069
+ e0: this.e0,
2070
+ e1: this.e1,
2071
+ e2: this.e2,
2072
+ e3: this.e3,
2073
+ e4: this.e4,
2074
+ e5: this.e5,
2075
+ e6: this.e6,
2076
+ e7: this.e7,
2077
+ e8: this.e8,
2078
+ e9: this.e9,
2079
+ e10: this.e10,
2080
+ e11: this.e11,
2081
+ e12: this.e12,
2082
+ e13: this.e13,
2083
+ e14: this.e14,
2084
+ e15: this.e15
2185
2085
  };
2186
2086
  }
2187
- computeSupportingFace(out, subShapeID, direction2, scale2, centerOfMassTransform2) {
2188
- out.clear();
2189
- out.pushVertex(this.a);
2190
- out.pushVertex(this.b);
2191
- out.pushVertex(this.c);
2192
- out.transform(centerOfMassTransform2);
2193
- }
2194
- };
2195
- const faceProps = props({
2196
- numVertices: 0,
2197
- buffer: LazyReferenceListType(() => Vec3)
2198
- });
2199
- const triangle$1 = /* @__PURE__ */ Triangle$1.create();
2200
- const tempVertex = /* @__PURE__ */ Vec3.create();
2201
- class Face extends createClass()(faceProps) {
2202
- clear() {
2203
- this.numVertices = 0;
2204
- }
2205
- isEmpty() {
2206
- return this.numVertices === 0;
2207
- }
2208
- isFull() {
2209
- return this.numVertices === this.buffer.maxLength;
2210
- }
2211
- getVertex(out, index) {
2212
- out.copy(this.buffer.getAtIndex(index));
2213
- }
2214
- pushVertex(value) {
2215
- if (this.numVertices >= this.buffer.maxLength) {
2216
- throw new Error("Face is full");
2217
- }
2218
- this.buffer.getAtIndex(this.numVertices).copy(value);
2219
- this.numVertices++;
2220
- }
2221
- pushVertexValues(x2, y4, z) {
2222
- if (this.numVertices >= this.buffer.maxLength) {
2223
- throw new Error("Face is full");
2224
- }
2225
- const vertex3 = this.buffer.getAtIndex(this.numVertices);
2226
- vertex3.x = x2;
2227
- vertex3.y = y4;
2228
- vertex3.z = z;
2229
- this.numVertices++;
2230
- }
2231
- transform(isometry2) {
2232
- for (let i = 0; i < this.numVertices; i++) {
2233
- this.buffer.getAtIndex(i).transformByMat4(isometry2);
2234
- }
2235
- }
2236
- getCentroid(out) {
2237
- out.zero();
2238
- for (let i = 0; i < this.numVertices; i++) {
2239
- out.addVector(this.buffer.getAtIndex(i));
2240
- }
2241
- out.scale(1 / this.numVertices);
2087
+ identity() {
2088
+ this.e0 = 1;
2089
+ this.e1 = 0;
2090
+ this.e2 = 0;
2091
+ this.e3 = 0;
2092
+ this.e4 = 0;
2093
+ this.e5 = 1;
2094
+ this.e6 = 0;
2095
+ this.e7 = 0;
2096
+ this.e8 = 0;
2097
+ this.e9 = 0;
2098
+ this.e10 = 1;
2099
+ this.e11 = 0;
2100
+ this.e12 = 0;
2101
+ this.e13 = 0;
2102
+ this.e14 = 0;
2103
+ this.e15 = 1;
2104
+ return this;
2242
2105
  }
2243
- getNormal(out) {
2244
- switch (this.numVertices) {
2245
- case 0:
2246
- case 1:
2247
- case 2: {
2248
- out.zero();
2249
- break;
2250
- }
2251
- default: {
2252
- triangle$1.a.copy(this.buffer.getAtIndex(0));
2253
- triangle$1.b.copy(this.buffer.getAtIndex(1));
2254
- triangle$1.c.copy(this.buffer.getAtIndex(2));
2255
- triangle$1.computeNormal(out);
2256
- }
2257
- }
2106
+ getRotationMatrix4(out) {
2107
+ out.copy(this);
2108
+ out.e12 = 0;
2109
+ out.e13 = 0;
2110
+ out.e14 = 0;
2111
+ out.e15 = 1;
2258
2112
  }
2259
- translate(translation) {
2260
- for (let i = 0; i < this.numVertices; i++) {
2261
- this.buffer.getAtIndex(i).addVector(translation);
2113
+ decompose(outTranslation, outOrientation, outScale) {
2114
+ outTranslation.x = this.e12;
2115
+ outTranslation.y = this.e13;
2116
+ outTranslation.z = this.e14;
2117
+ let m11 = this.e0;
2118
+ let m12 = this.e1;
2119
+ let m13 = this.e2;
2120
+ let m21 = this.e4;
2121
+ let m22 = this.e5;
2122
+ let m23 = this.e6;
2123
+ let m31 = this.e8;
2124
+ let m32 = this.e9;
2125
+ let m33 = this.e10;
2126
+ outScale.x = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2127
+ outScale.y = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2128
+ outScale.z = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2129
+ let is1 = 1 / outScale.x;
2130
+ let is2 = 1 / outScale.y;
2131
+ let is3 = 1 / outScale.z;
2132
+ let sm11 = m11 * is1;
2133
+ let sm12 = m12 * is2;
2134
+ let sm13 = m13 * is3;
2135
+ let sm21 = m21 * is1;
2136
+ let sm22 = m22 * is2;
2137
+ let sm23 = m23 * is3;
2138
+ let sm31 = m31 * is1;
2139
+ let sm32 = m32 * is2;
2140
+ let sm33 = m33 * is3;
2141
+ let trace = sm11 + sm22 + sm33;
2142
+ let S = 0;
2143
+ if (trace > 0) {
2144
+ S = Math.sqrt(trace + 1) * 2;
2145
+ outOrientation.w = 0.25 * S;
2146
+ outOrientation.x = (sm23 - sm32) / S;
2147
+ outOrientation.y = (sm31 - sm13) / S;
2148
+ outOrientation.z = (sm12 - sm21) / S;
2149
+ } else if (sm11 > sm22 && sm11 > sm33) {
2150
+ S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
2151
+ outOrientation.w = (sm23 - sm32) / S;
2152
+ outOrientation.x = 0.25 * S;
2153
+ outOrientation.y = (sm12 + sm21) / S;
2154
+ outOrientation.z = (sm31 + sm13) / S;
2155
+ } else if (sm22 > sm33) {
2156
+ S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
2157
+ outOrientation.w = (sm31 - sm13) / S;
2158
+ outOrientation.x = (sm12 + sm21) / S;
2159
+ outOrientation.y = 0.25 * S;
2160
+ outOrientation.z = (sm23 + sm32) / S;
2161
+ } else {
2162
+ S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
2163
+ outOrientation.w = (sm12 - sm21) / S;
2164
+ outOrientation.x = (sm31 + sm13) / S;
2165
+ outOrientation.y = (sm23 + sm32) / S;
2166
+ outOrientation.z = 0.25 * S;
2262
2167
  }
2168
+ return this;
2263
2169
  }
2264
- swap(other) {
2265
- if (this.numVertices !== other.numVertices) {
2266
- throw new Error("Cannot swap faces of different sizes");
2267
- }
2268
- for (let i = 0; i < this.numVertices; i++) {
2269
- tempVertex.copy(this.buffer.getAtIndex(i));
2270
- this.buffer.getAtIndex(i).copy(other.buffer.getAtIndex(i));
2271
- other.buffer.getAtIndex(i).copy(tempVertex);
2272
- }
2170
+ compose(translation, orientation, scale2) {
2171
+ let x2 = orientation.x, y4 = orientation.y, z = orientation.z, w3 = orientation.w;
2172
+ let x22 = x2 + x2;
2173
+ let y22 = y4 + y4;
2174
+ let z2 = z + z;
2175
+ let xx = x2 * x22;
2176
+ let xy = x2 * y22;
2177
+ let xz = x2 * z2;
2178
+ let yy = y4 * y22;
2179
+ let yz = y4 * z2;
2180
+ let zz = z * z2;
2181
+ let wx = w3 * x22;
2182
+ let wy = w3 * y22;
2183
+ let wz = w3 * z2;
2184
+ let sx = scale2.x;
2185
+ let sy = scale2.y;
2186
+ let sz = scale2.z;
2187
+ this.e0 = (1 - (yy + zz)) * sx;
2188
+ this.e1 = (xy + wz) * sx;
2189
+ this.e2 = (xz - wy) * sx;
2190
+ this.e3 = 0;
2191
+ this.e4 = (xy - wz) * sy;
2192
+ this.e5 = (1 - (xx + zz)) * sy;
2193
+ this.e6 = (yz + wx) * sy;
2194
+ this.e7 = 0;
2195
+ this.e8 = (xz + wy) * sz;
2196
+ this.e9 = (yz - wx) * sz;
2197
+ this.e10 = (1 - (xx + yy)) * sz;
2198
+ this.e11 = 0;
2199
+ this.e12 = translation.x;
2200
+ this.e13 = translation.y;
2201
+ this.e14 = translation.z;
2202
+ this.e15 = 1;
2203
+ return this;
2273
2204
  }
2274
2205
  }
2275
- const oldCreate$b = Face.create;
2276
- Face.create = function() {
2277
- const face = oldCreate$b.apply(this, arguments);
2278
- if (isFinite(face.buffer.maxLength)) {
2279
- for (let i = 0; i < face.buffer.maxLength; i++) {
2280
- face.buffer.create();
2281
- }
2282
- }
2283
- return face;
2284
- };
2206
+ const rotation$3 = /* @__PURE__ */ Quat.create();
2285
2207
  var ReferenceFrame = /* @__PURE__ */ ((ReferenceFrame2) => {
2286
2208
  ReferenceFrame2[ReferenceFrame2["local"] = 0] = "local";
2287
2209
  ReferenceFrame2[ReferenceFrame2["world"] = 1] = "world";
@@ -3985,41 +3907,6 @@ function createBitFlags(keys) {
3985
3907
  function shouldPairCollide(groupA, maskA, groupB, maskB) {
3986
3908
  return (groupA & maskB) !== 0 && (groupB & maskA) !== 0;
3987
3909
  }
3988
- function shouldCollide(maskA, groupB) {
3989
- return (groupB & maskA) !== 0;
3990
- }
3991
- function addFlag(flag, value) {
3992
- return flag | value;
3993
- }
3994
- function removeFlag(flag, value) {
3995
- return flag & ~value;
3996
- }
3997
- function toggleFlag(flag, value) {
3998
- return flag ^ value;
3999
- }
4000
- function hasFlag(flag, value) {
4001
- return (flag & value) !== 0;
4002
- }
4003
- function doesNotHaveFlag(flag, value) {
4004
- return (flag & value) === 0;
4005
- }
4006
- function setFlags(...values) {
4007
- return values.reduce((acc, value) => acc | value, 0);
4008
- }
4009
- const CollisionFilter = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4010
- __proto__: null,
4011
- AllFlag,
4012
- NoneFlag,
4013
- addFlag,
4014
- createBitFlags,
4015
- doesNotHaveFlag,
4016
- hasFlag,
4017
- removeFlag,
4018
- setFlags,
4019
- shouldCollide,
4020
- shouldPairCollide,
4021
- toggleFlag
4022
- }, Symbol.toStringTag, { value: "Module" }));
4023
3910
  const leftAabb = /* @__PURE__ */ Aabb.create();
4024
3911
  const rightAabb = /* @__PURE__ */ Aabb.create();
4025
3912
  const centroidBounds$1 = /* @__PURE__ */ Aabb.create();
@@ -4570,6 +4457,79 @@ class BasicTransform extends createClass()(basicTransformProps) {
4570
4457
  return this.position.equals(other.position, tolerance) && this.rotation.equals(other.rotation, tolerance) && Math.abs(this.scale - other.scale) < tolerance;
4571
4458
  }
4572
4459
  }
4460
+ const cross_bn_cn = /* @__PURE__ */ Vec3.create();
4461
+ const planeProps = props({
4462
+ normal: Vec3,
4463
+ constant: 0
4464
+ });
4465
+ class Plane extends createClass()(planeProps) {
4466
+ toObject() {
4467
+ return {
4468
+ normal: this.normal.toObject(),
4469
+ constant: this.constant
4470
+ };
4471
+ }
4472
+ fromPointAndNormal(point2, normal4) {
4473
+ this.normal.copy(normal4);
4474
+ this.constant = -normal4.dot(point2);
4475
+ }
4476
+ signedDistance(point2) {
4477
+ return point2.dot(this.normal) + this.constant;
4478
+ }
4479
+ offsetAlongNormal(out, inDistance) {
4480
+ out.copy(this);
4481
+ out.constant -= inDistance;
4482
+ }
4483
+ offsetPlaneAlongNormal(plane, inDistance) {
4484
+ this.normal.copy(plane.normal);
4485
+ this.constant = plane.constant - inDistance;
4486
+ }
4487
+ toString() {
4488
+ return `Plane { normal: ${this.normal.toString()}, constant: ${this.constant} }`;
4489
+ }
4490
+ static intersectPlanes(planeA, planeB, planeC, outPoint) {
4491
+ cross_bn_cn.crossVectors(planeB.normal, planeC.normal);
4492
+ const denominator = planeA.normal.dot(cross_bn_cn);
4493
+ if (denominator === 0) {
4494
+ return false;
4495
+ }
4496
+ const a3 = planeA.normal;
4497
+ const b3 = planeB.normal;
4498
+ const c3 = planeC.normal;
4499
+ const ax = a3.x;
4500
+ const ay = a3.y;
4501
+ const az = a3.z;
4502
+ const bx = b3.x;
4503
+ const by = b3.y;
4504
+ const bz = b3.z;
4505
+ const cx = c3.x;
4506
+ const cy = c3.y;
4507
+ const cz = c3.z;
4508
+ const aw = planeA.constant;
4509
+ const bw = planeB.constant;
4510
+ const cw = planeC.constant;
4511
+ outPoint.x = aw * (bz * cy - by * cz) + ay * (bw * cz - bz * cw) + az * (by * cw - bw * cy);
4512
+ outPoint.y = aw * (bx * cz - bz * cx) + ax * (bz * cw - bw * cz) + az * (bw * cx - bx * cw);
4513
+ outPoint.z = aw * (by * cx - bx * cy) + ax * (bw * cy - by * cw) + ay * (bx * cw - bw * cx);
4514
+ outPoint.scale(1 / denominator);
4515
+ return true;
4516
+ }
4517
+ /**
4518
+ * return the normalized fraction of the ray that intersects the plane in the interval [0.0, 1.0]
4519
+ */
4520
+ castRay(ray2) {
4521
+ const denominator = this.normal.dot(ray2.direction);
4522
+ if (Math.abs(denominator) < 1e-6) {
4523
+ return 1;
4524
+ }
4525
+ const t = (this.constant - this.normal.dot(ray2.origin)) / denominator;
4526
+ const fraction = t / ray2.length;
4527
+ if (fraction < 0 || fraction > 1) {
4528
+ return 1;
4529
+ }
4530
+ return fraction;
4531
+ }
4532
+ }
4573
4533
  const numberValueProps = props({
4574
4534
  value: 0
4575
4535
  });
@@ -8030,29 +7990,31 @@ class Body extends createClass({ afterConstructorCode })(bodyProps) {
8030
7990
  return this["shape" + this.shapeType];
8031
7991
  }
8032
7992
  set shape(newShape) {
8033
- this.setShape(newShape);
7993
+ this.setShape(newShape, Boolean(newShape));
8034
7994
  }
8035
7995
  setShape(newShape, updateBroadphase = true) {
8036
7996
  this["shape" + this.shapeType] = null;
8037
- this["shape" + newShape.type] = newShape;
8038
- this.shapeType = newShape.type;
8039
- if (newShape.type === ShapeType.triangleMesh && this.type === 0 && !newShape.computedVolume) {
8040
- const float32Array = new Float32Array(newShape.vertexPositions.length * 3);
8041
- let index = 0;
8042
- for (const vertexPosition of newShape.vertexPositions) {
8043
- float32Array[index++] = vertexPosition.x;
8044
- float32Array[index++] = vertexPosition.y;
8045
- float32Array[index++] = vertexPosition.z;
8046
- }
8047
- const hull = this.world.triangleMeshBuilder.convexHullBuilder.buildFromPoints(
8048
- float32Array,
8049
- 0.02,
8050
- 1e-3,
8051
- Infinity,
8052
- Infinity
8053
- );
8054
- newShape.computedVolume = hull.computedVolume;
8055
- newShape.inertia.copy(hull.inertia);
7997
+ if (newShape) {
7998
+ this["shape" + newShape.type] = newShape;
7999
+ this.shapeType = newShape.type;
8000
+ if (newShape.type === ShapeType.triangleMesh && this.type === 0 && !newShape.computedVolume) {
8001
+ const float32Array = new Float32Array(newShape.vertexPositions.length * 3);
8002
+ let index = 0;
8003
+ for (const vertexPosition of newShape.vertexPositions) {
8004
+ float32Array[index++] = vertexPosition.x;
8005
+ float32Array[index++] = vertexPosition.y;
8006
+ float32Array[index++] = vertexPosition.z;
8007
+ }
8008
+ const hull = this.world.triangleMeshBuilder.convexHullBuilder.buildFromPoints(
8009
+ float32Array,
8010
+ 0.02,
8011
+ 1e-3,
8012
+ Infinity,
8013
+ Infinity
8014
+ );
8015
+ newShape.computedVolume = hull.computedVolume;
8016
+ newShape.inertia.copy(hull.inertia);
8017
+ }
8056
8018
  }
8057
8019
  if (updateBroadphase) {
8058
8020
  updateBody(this);
@@ -8305,6 +8267,10 @@ class Body extends createClass({ afterConstructorCode })(bodyProps) {
8305
8267
  this.world.sleepModule.wakeBodyUp(this);
8306
8268
  }
8307
8269
  markBodyAsDirty() {
8270
+ if (this.type === 2) {
8271
+ this.world.broadphase.markStaticBodyAsDirty(this);
8272
+ return;
8273
+ }
8308
8274
  this.world.broadphase.markDynamicBodyAsDirty(this);
8309
8275
  }
8310
8276
  }
@@ -8379,8 +8345,95 @@ function updateBody(body2, updateBroadphase = true) {
8379
8345
  if (updateBroadphase) {
8380
8346
  body2.markBodyAsDirty();
8381
8347
  }
8382
- }
8383
- const castResultProps = props({
8348
+ }
8349
+ const castResultProps = props({
8350
+ status: NumberType(
8351
+ 2
8352
+ /* Indeterminate */
8353
+ ),
8354
+ hasContact: BooleanType(false),
8355
+ penetration: 0,
8356
+ contactPointA: Vec3,
8357
+ contactPointB: Vec3,
8358
+ normalA: Vec3,
8359
+ normalB: Vec3,
8360
+ momentArmA: Vec3,
8361
+ momentArmB: Vec3,
8362
+ surfaceNormalA: Vec3,
8363
+ surfaceNormalB: Vec3,
8364
+ bodyA: LazyReferenceType((() => Body)),
8365
+ bodyB: LazyReferenceType((() => Body)),
8366
+ subShapeIdA: 0,
8367
+ subShapeIdB: 0,
8368
+ isBackFace: BooleanType(false),
8369
+ faceA: Face,
8370
+ faceB: Face,
8371
+ fraction: 0,
8372
+ isBackFaceHit: BooleanType(false)
8373
+ });
8374
+ class CastResult extends createClass()(castResultProps) {
8375
+ /**
8376
+ * swaps the A and B data
8377
+ */
8378
+ swap() {
8379
+ this.contactPointA.swap(this.contactPointB);
8380
+ this.normalA.swap(this.normalB);
8381
+ this.momentArmA.swap(this.momentArmB);
8382
+ this.surfaceNormalA.swap(this.surfaceNormalB);
8383
+ const tempBody = this.bodyA;
8384
+ this.bodyA = this.bodyB;
8385
+ this.bodyB = tempBody;
8386
+ const tempSubShapeId = this.subShapeIdA;
8387
+ this.subShapeIdA = this.subShapeIdB;
8388
+ this.subShapeIdB = tempSubShapeId;
8389
+ this.faceA.swap(this.faceB);
8390
+ }
8391
+ getEarlyOutFraction() {
8392
+ return this.fraction > 0 ? this.fraction : -this.penetration;
8393
+ }
8394
+ }
8395
+ const _CastCollector = class _CastCollector {
8396
+ constructor() {
8397
+ this.earlyOutFraction = _CastCollector.initialEarlyOutFraction;
8398
+ this.body2 = null;
8399
+ }
8400
+ getEarlyOutFraction() {
8401
+ return this.earlyOutFraction;
8402
+ }
8403
+ getPositiveEarlyOutFraction() {
8404
+ return Math.max(Number.MIN_VALUE, this.earlyOutFraction);
8405
+ }
8406
+ reset() {
8407
+ this.earlyOutFraction = _CastCollector.initialEarlyOutFraction;
8408
+ this.body2 = null;
8409
+ return this;
8410
+ }
8411
+ updateEarlyOutFraction(inFraction) {
8412
+ if (inFraction <= this.earlyOutFraction) {
8413
+ this.earlyOutFraction = inFraction;
8414
+ }
8415
+ }
8416
+ addHit(result2) {
8417
+ }
8418
+ addMiss() {
8419
+ }
8420
+ };
8421
+ _CastCollector.initialEarlyOutFraction = 1 + 1e-4;
8422
+ _CastCollector.shouldEarlyOutFraction = -Infinity;
8423
+ let CastCollector = _CastCollector;
8424
+ var QueryPrecision = /* @__PURE__ */ ((QueryPrecision2) => {
8425
+ QueryPrecision2[QueryPrecision2["approximate"] = 0] = "approximate";
8426
+ QueryPrecision2[QueryPrecision2["precise"] = 1] = "precise";
8427
+ QueryPrecision2[QueryPrecision2["preciseWithContacts"] = 2] = "preciseWithContacts";
8428
+ return QueryPrecision2;
8429
+ })(QueryPrecision || {});
8430
+ var CollisionStatus = /* @__PURE__ */ ((CollisionStatus2) => {
8431
+ CollisionStatus2[CollisionStatus2["NotColliding"] = 0] = "NotColliding";
8432
+ CollisionStatus2[CollisionStatus2["Colliding"] = 1] = "Colliding";
8433
+ CollisionStatus2[CollisionStatus2["Indeterminate"] = 2] = "Indeterminate";
8434
+ return CollisionStatus2;
8435
+ })(CollisionStatus || {});
8436
+ const collisionResultProps = props({
8384
8437
  status: NumberType(
8385
8438
  2
8386
8439
  /* Indeterminate */
@@ -8401,11 +8454,9 @@ const castResultProps = props({
8401
8454
  subShapeIdB: 0,
8402
8455
  isBackFace: BooleanType(false),
8403
8456
  faceA: Face,
8404
- faceB: Face,
8405
- fraction: 0,
8406
- isBackFaceHit: BooleanType(false)
8457
+ faceB: Face
8407
8458
  });
8408
- class CastResult extends createClass()(castResultProps) {
8459
+ class CollisionResult extends createClass()(collisionResultProps) {
8409
8460
  /**
8410
8461
  * swaps the A and B data
8411
8462
  */
@@ -8420,51 +8471,95 @@ class CastResult extends createClass()(castResultProps) {
8420
8471
  const tempSubShapeId = this.subShapeIdA;
8421
8472
  this.subShapeIdA = this.subShapeIdB;
8422
8473
  this.subShapeIdB = tempSubShapeId;
8423
- this.faceA.swap(this.faceB);
8424
- }
8425
- getEarlyOutFraction() {
8426
- return this.fraction > 0 ? this.fraction : -this.penetration;
8474
+ const tempFace = this.faceA;
8475
+ this.faceA = this.faceB;
8476
+ this.faceB = tempFace;
8427
8477
  }
8428
8478
  }
8429
- const _CastCollector = class _CastCollector {
8479
+ const _CollisionCollector = class _CollisionCollector {
8430
8480
  constructor() {
8431
- this.earlyOutFraction = _CastCollector.initialEarlyOutFraction;
8481
+ this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
8432
8482
  this.body2 = null;
8433
8483
  }
8434
8484
  getEarlyOutFraction() {
8435
- return this.earlyOutFraction;
8485
+ return _CollisionCollector.initialEarlyOutFraction;
8436
8486
  }
8437
8487
  getPositiveEarlyOutFraction() {
8438
8488
  return Math.max(Number.MIN_VALUE, this.earlyOutFraction);
8439
8489
  }
8440
8490
  reset() {
8441
- this.earlyOutFraction = _CastCollector.initialEarlyOutFraction;
8491
+ this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
8442
8492
  this.body2 = null;
8443
8493
  return this;
8444
8494
  }
8445
- updateEarlyOutFraction(inFraction) {
8446
- if (inFraction <= this.earlyOutFraction) {
8447
- this.earlyOutFraction = inFraction;
8448
- }
8449
- }
8450
8495
  addHit(result2) {
8451
8496
  }
8452
8497
  addMiss() {
8453
8498
  }
8454
8499
  };
8455
- _CastCollector.initialEarlyOutFraction = 1 + 1e-4;
8456
- _CastCollector.shouldEarlyOutFraction = -Infinity;
8457
- let CastCollector = _CastCollector;
8458
- var QueryPrecision = /* @__PURE__ */ ((QueryPrecision2) => {
8459
- QueryPrecision2[QueryPrecision2["approximate"] = 0] = "approximate";
8460
- QueryPrecision2[QueryPrecision2["precise"] = 1] = "precise";
8461
- QueryPrecision2[QueryPrecision2["preciseWithContacts"] = 2] = "preciseWithContacts";
8462
- return QueryPrecision2;
8463
- })(QueryPrecision || {});
8500
+ _CollisionCollector.initialEarlyOutFraction = Infinity;
8501
+ _CollisionCollector.shouldEarlyOutFraction = -Infinity;
8502
+ let CollisionCollector = _CollisionCollector;
8503
+ var CollectFacesMode = /* @__PURE__ */ ((CollectFacesMode2) => {
8504
+ CollectFacesMode2[CollectFacesMode2["CollectFaces"] = 0] = "CollectFaces";
8505
+ CollectFacesMode2[CollectFacesMode2["NoFaces"] = 1] = "NoFaces";
8506
+ return CollectFacesMode2;
8507
+ })(CollectFacesMode || {});
8508
+ var ActiveEdgeMode = /* @__PURE__ */ ((ActiveEdgeMode2) => {
8509
+ ActiveEdgeMode2[ActiveEdgeMode2["CollideOnlyWithActive"] = 0] = "CollideOnlyWithActive";
8510
+ ActiveEdgeMode2[ActiveEdgeMode2["CollideWithAll"] = 1] = "CollideWithAll";
8511
+ return ActiveEdgeMode2;
8512
+ })(ActiveEdgeMode || {});
8513
+ var BackFaceMode = /* @__PURE__ */ ((BackFaceMode2) => {
8514
+ BackFaceMode2[BackFaceMode2["IgnoreBackFaces"] = 0] = "IgnoreBackFaces";
8515
+ BackFaceMode2[BackFaceMode2["CollideWithBackFaces"] = 1] = "CollideWithBackFaces";
8516
+ return BackFaceMode2;
8517
+ })(BackFaceMode || {});
8518
+ const result$9 = CollisionResult.create({
8519
+ faceA: {
8520
+ numVertices: 0,
8521
+ buffer: { pool: new Vec3.Pool(32), maxLength: 32 }
8522
+ },
8523
+ faceB: {
8524
+ numVertices: 0,
8525
+ buffer: { pool: new Vec3.Pool(32), maxLength: 32 }
8526
+ }
8527
+ });
8528
+ const positionA$3 = /* @__PURE__ */ Vec3.create();
8529
+ const positionB$3 = /* @__PURE__ */ Vec3.create();
8464
8530
  const ab$4 = /* @__PURE__ */ Vec3.create();
8531
+ function collideSphereVsSphere(penetrationDepthModule2, collector2, shapeA, shapeB2, isometryA2, isometryB2, settings, bodyA, bodyB, initialDirection, subShapeIdA = 0, subShapeIdB = 0) {
8532
+ result$9.reset();
8533
+ result$9.bodyA = bodyA;
8534
+ result$9.bodyB = bodyB;
8535
+ isometryA2.matrix.getTranslation(positionA$3);
8536
+ isometryB2.matrix.getTranslation(positionB$3);
8537
+ ab$4.subtractVectors(positionB$3, positionA$3);
8538
+ if (ab$4.squaredLength() > squared(shapeA.radius + shapeB2.radius)) {
8539
+ result$9.hasContact = false;
8540
+ collector2.addMiss();
8541
+ return;
8542
+ }
8543
+ result$9.hasContact = true;
8544
+ result$9.bodyA = bodyA;
8545
+ result$9.bodyB = bodyB;
8546
+ result$9.subShapeIdA = subShapeIdA;
8547
+ result$9.subShapeIdB = subShapeIdB;
8548
+ result$9.normalA.normalizeVector(ab$4);
8549
+ result$9.normalB.negateVector(result$9.normalA);
8550
+ result$9.contactPointA.addScaledToVector(positionA$3, result$9.normalA, shapeA.radius);
8551
+ result$9.contactPointB.addScaledToVector(positionB$3, result$9.normalB, shapeB2.radius);
8552
+ result$9.momentArmA.subtractVectors(result$9.contactPointA, positionA$3);
8553
+ result$9.momentArmB.subtractVectors(result$9.contactPointB, positionB$3);
8554
+ result$9.penetration = shapeA.radius + shapeB2.radius - ab$4.length();
8555
+ result$9.normalA.normalizeVector(result$9.normalA);
8556
+ result$9.normalB.normalizeVector(result$9.normalB);
8557
+ collector2.addHit(result$9);
8558
+ }
8559
+ const ab$3 = /* @__PURE__ */ Vec3.create();
8465
8560
  function computeBarycentricCoordinates2d(outBarycentric, a3, b3, squaredTolerance = 1e-10) {
8466
- ab$4.subtractVectors(b3, a3);
8467
- const denominator = ab$4.squaredLength();
8561
+ ab$3.subtractVectors(b3, a3);
8562
+ const denominator = ab$3.squaredLength();
8468
8563
  if (denominator < squaredTolerance) {
8469
8564
  if (a3.squaredLength() < b3.squaredLength()) {
8470
8565
  outBarycentric.u = 1;
@@ -8476,7 +8571,7 @@ function computeBarycentricCoordinates2d(outBarycentric, a3, b3, squaredToleranc
8476
8571
  outBarycentric.isValid = false;
8477
8572
  return;
8478
8573
  } else {
8479
- outBarycentric.v = -a3.dot(ab$4) / denominator;
8574
+ outBarycentric.v = -a3.dot(ab$3) / denominator;
8480
8575
  outBarycentric.u = 1 - outBarycentric.v;
8481
8576
  }
8482
8577
  outBarycentric.isValid = true;
@@ -8497,19 +8592,19 @@ class BarycentricCoordinatesResult extends createClass()(
8497
8592
  barycentricCoordinatesResultProps
8498
8593
  ) {
8499
8594
  }
8500
- const ab$3 = /* @__PURE__ */ Vec3.create();
8595
+ const ab$2 = /* @__PURE__ */ Vec3.create();
8501
8596
  const ac$2 = /* @__PURE__ */ Vec3.create();
8502
8597
  const bc$2 = /* @__PURE__ */ Vec3.create();
8503
8598
  const otherBarycentric = /* @__PURE__ */ BarycentricCoordinatesResult.create();
8504
8599
  function computeBarycentricCoordinates3d(outBarycentric, a3, b3, c3, squaredTolerance = 1e-10) {
8505
- ab$3.subtractVectors(b3, a3);
8600
+ ab$2.subtractVectors(b3, a3);
8506
8601
  ac$2.subtractVectors(c3, a3);
8507
8602
  bc$2.subtractVectors(c3, b3);
8508
- const d00 = ab$3.dot(ab$3);
8603
+ const d00 = ab$2.dot(ab$2);
8509
8604
  const d11 = ac$2.dot(ac$2);
8510
8605
  const d22 = bc$2.dot(bc$2);
8511
8606
  if (d00 <= d22) {
8512
- const d01 = ab$3.dot(ac$2);
8607
+ const d01 = ab$2.dot(ac$2);
8513
8608
  const denominator = d00 * d11 - d01 * d01;
8514
8609
  if (Math.abs(denominator) < 1e-12) {
8515
8610
  if (d00 > d11) {
@@ -8526,7 +8621,7 @@ function computeBarycentricCoordinates3d(outBarycentric, a3, b3, c3, squaredTole
8526
8621
  outBarycentric.isValid = false;
8527
8622
  return;
8528
8623
  } else {
8529
- const a0 = a3.dot(ab$3);
8624
+ const a0 = a3.dot(ab$2);
8530
8625
  const a12 = a3.dot(ac$2);
8531
8626
  outBarycentric.v = (d01 * a12 - d11 * a0) / denominator;
8532
8627
  outBarycentric.w = (d01 * a0 - d00 * a12) / denominator;
@@ -8576,7 +8671,7 @@ function computeClosestPointOnLine(outClosestPoints, a3, b3, squaredTolerance =
8576
8671
  }
8577
8672
  }
8578
8673
  const ac$1 = /* @__PURE__ */ Vec3.create();
8579
- const ab$2 = /* @__PURE__ */ Vec3.create();
8674
+ const ab$1 = /* @__PURE__ */ Vec3.create();
8580
8675
  const bc$1 = /* @__PURE__ */ Vec3.create();
8581
8676
  const a = /* @__PURE__ */ Vec3.create();
8582
8677
  const c = /* @__PURE__ */ Vec3.create();
@@ -8593,9 +8688,9 @@ function computeClosestPointOnTriangle(outClosestPoint, inA, inB, inC, mustInclu
8593
8688
  const swapAC = bc$1.dot(bc$1) < ac$1.dot(ac$1);
8594
8689
  a.copy(swapAC ? inC : inA);
8595
8690
  c.copy(swapAC ? inA : inC);
8596
- ab$2.subtractVectors(inB, a);
8691
+ ab$1.subtractVectors(inB, a);
8597
8692
  ac$1.subtractVectors(c, a);
8598
- n$1.crossVectors(ab$2, ac$1);
8693
+ n$1.crossVectors(ab$1, ac$1);
8599
8694
  const normalLengthSquared = n$1.squaredLength();
8600
8695
  if (normalLengthSquared < 1e-11) {
8601
8696
  let closestSet = 4;
@@ -8639,11 +8734,11 @@ function computeClosestPointOnTriangle(outClosestPoint, inA, inB, inC, mustInclu
8639
8734
  }
8640
8735
  }
8641
8736
  if (!mustIncludeC) {
8642
- ab$2.subtractVectors(inB, inA);
8643
- const abLengthSquared = ab$2.squaredLength();
8737
+ ab$1.subtractVectors(inB, inA);
8738
+ const abLengthSquared = ab$1.squaredLength();
8644
8739
  if (abLengthSquared > squaredTolerance) {
8645
- const v4 = clamp(-inA.dot(ab$2) / abLengthSquared, 0, 1);
8646
- q$2.addScaledToVector(inA, ab$2, v4);
8740
+ const v4 = clamp(-inA.dot(ab$1) / abLengthSquared, 0, 1);
8741
+ q$2.addScaledToVector(inA, ab$1, v4);
8647
8742
  const distanceSquared = q$2.squaredLength();
8648
8743
  if (distanceSquared < bestDistanceSquared) {
8649
8744
  closestSet = 3;
@@ -8657,7 +8752,7 @@ function computeClosestPointOnTriangle(outClosestPoint, inA, inB, inC, mustInclu
8657
8752
  return;
8658
8753
  }
8659
8754
  ap.negateVector(a);
8660
- const d12 = ab$2.dot(ap);
8755
+ const d12 = ab$1.dot(ap);
8661
8756
  const d22 = ac$1.dot(ap);
8662
8757
  if (d12 <= 0 && d22 <= 0) {
8663
8758
  outClosestPoint.pointSet = swapAC ? 4 : 1;
@@ -8665,7 +8760,7 @@ function computeClosestPointOnTriangle(outClosestPoint, inA, inB, inC, mustInclu
8665
8760
  return;
8666
8761
  }
8667
8762
  bp.negateVector(inB);
8668
- const d32 = ab$2.dot(bp);
8763
+ const d32 = ab$1.dot(bp);
8669
8764
  const d42 = ac$1.dot(bp);
8670
8765
  if (d32 >= 0 && d42 <= d32) {
8671
8766
  outClosestPoint.pointSet = 2;
@@ -8675,11 +8770,11 @@ function computeClosestPointOnTriangle(outClosestPoint, inA, inB, inC, mustInclu
8675
8770
  if (d12 * d42 <= d32 * d22 && d12 >= 0 && d32 <= 0) {
8676
8771
  const v4 = d12 / (d12 - d32);
8677
8772
  outClosestPoint.pointSet = swapAC ? 6 : 3;
8678
- outClosestPoint.point.addScaledToVector(a, ab$2, v4);
8773
+ outClosestPoint.point.addScaledToVector(a, ab$1, v4);
8679
8774
  return;
8680
8775
  }
8681
8776
  cp.negateVector(c);
8682
- const d5 = ab$2.dot(cp);
8777
+ const d5 = ab$1.dot(cp);
8683
8778
  const d6 = ac$1.dot(cp);
8684
8779
  if (d6 >= 0 && d5 <= d6) {
8685
8780
  outClosestPoint.pointSet = swapAC ? 1 : 4;
@@ -8714,7 +8809,7 @@ const vec4Props = props({
8714
8809
  });
8715
8810
  class Vec4 extends createClass()(vec4Props) {
8716
8811
  }
8717
- const ab$1 = /* @__PURE__ */ Vec3.create();
8812
+ const ab = /* @__PURE__ */ Vec3.create();
8718
8813
  const ac = /* @__PURE__ */ Vec3.create();
8719
8814
  const ad = /* @__PURE__ */ Vec3.create();
8720
8815
  const bd = /* @__PURE__ */ Vec3.create();
@@ -8726,23 +8821,23 @@ const bd_cross_bc = /* @__PURE__ */ Vec3.create();
8726
8821
  const signP = /* @__PURE__ */ Vec4.create();
8727
8822
  const signD = /* @__PURE__ */ Vec4.create();
8728
8823
  function isOriginOutsideOfTrianglePlanes(outResult, a3, b3, c3, d5, tolerance = 1e-5) {
8729
- ab$1.subtractVectors(b3, a3);
8824
+ ab.subtractVectors(b3, a3);
8730
8825
  ac.subtractVectors(c3, a3);
8731
8826
  ad.subtractVectors(d5, a3);
8732
8827
  bd.subtractVectors(d5, b3);
8733
8828
  bc.subtractVectors(c3, b3);
8734
- ab_cross_ac.crossVectors(ab$1, ac);
8829
+ ab_cross_ac.crossVectors(ab, ac);
8735
8830
  ac_cross_ad.crossVectors(ac, ad);
8736
- ad_cross_ab.crossVectors(ad, ab$1);
8831
+ ad_cross_ab.crossVectors(ad, ab);
8737
8832
  bd_cross_bc.crossVectors(bd, bc);
8738
8833
  signP.x = a3.dot(ab_cross_ac);
8739
8834
  signP.y = a3.dot(ac_cross_ad);
8740
8835
  signP.z = a3.dot(ad_cross_ab);
8741
8836
  signP.w = b3.dot(bd_cross_bc);
8742
8837
  signD.x = ad.dot(ab_cross_ac);
8743
- signD.y = ab$1.dot(ac_cross_ad);
8838
+ signD.y = ab.dot(ac_cross_ad);
8744
8839
  signD.z = ac.dot(ad_cross_ab);
8745
- signD.w = -ab$1.dot(bd_cross_bc);
8840
+ signD.w = -ab.dot(bd_cross_bc);
8746
8841
  const allPositive = signD.x > 0 && signD.y > 0 && signD.z > 0 && signD.w > 0;
8747
8842
  if (allPositive) {
8748
8843
  outResult.x = signP.x >= -tolerance ? 1 : 0;
@@ -9320,94 +9415,6 @@ class GjkModule {
9320
9415
  }
9321
9416
  }
9322
9417
  const v = /* @__PURE__ */ Vec3.create();
9323
- var CollisionStatus = /* @__PURE__ */ ((CollisionStatus2) => {
9324
- CollisionStatus2[CollisionStatus2["NotColliding"] = 0] = "NotColliding";
9325
- CollisionStatus2[CollisionStatus2["Colliding"] = 1] = "Colliding";
9326
- CollisionStatus2[CollisionStatus2["Indeterminate"] = 2] = "Indeterminate";
9327
- return CollisionStatus2;
9328
- })(CollisionStatus || {});
9329
- const collisionResultProps = props({
9330
- status: NumberType(
9331
- 2
9332
- /* Indeterminate */
9333
- ),
9334
- hasContact: BooleanType(false),
9335
- penetration: 0,
9336
- contactPointA: Vec3,
9337
- contactPointB: Vec3,
9338
- normalA: Vec3,
9339
- normalB: Vec3,
9340
- momentArmA: Vec3,
9341
- momentArmB: Vec3,
9342
- surfaceNormalA: Vec3,
9343
- surfaceNormalB: Vec3,
9344
- bodyA: LazyReferenceType((() => Body)),
9345
- bodyB: LazyReferenceType((() => Body)),
9346
- subShapeIdA: 0,
9347
- subShapeIdB: 0,
9348
- isBackFace: BooleanType(false),
9349
- faceA: Face,
9350
- faceB: Face
9351
- });
9352
- class CollisionResult extends createClass()(collisionResultProps) {
9353
- /**
9354
- * swaps the A and B data
9355
- */
9356
- swap() {
9357
- this.contactPointA.swap(this.contactPointB);
9358
- this.normalA.swap(this.normalB);
9359
- this.momentArmA.swap(this.momentArmB);
9360
- this.surfaceNormalA.swap(this.surfaceNormalB);
9361
- const tempBody = this.bodyA;
9362
- this.bodyA = this.bodyB;
9363
- this.bodyB = tempBody;
9364
- const tempSubShapeId = this.subShapeIdA;
9365
- this.subShapeIdA = this.subShapeIdB;
9366
- this.subShapeIdB = tempSubShapeId;
9367
- const tempFace = this.faceA;
9368
- this.faceA = this.faceB;
9369
- this.faceB = tempFace;
9370
- }
9371
- }
9372
- const _CollisionCollector = class _CollisionCollector {
9373
- constructor() {
9374
- this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
9375
- this.body2 = null;
9376
- }
9377
- getEarlyOutFraction() {
9378
- return _CollisionCollector.initialEarlyOutFraction;
9379
- }
9380
- getPositiveEarlyOutFraction() {
9381
- return Math.max(Number.MIN_VALUE, this.earlyOutFraction);
9382
- }
9383
- reset() {
9384
- this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
9385
- this.body2 = null;
9386
- return this;
9387
- }
9388
- addHit(result2) {
9389
- }
9390
- addMiss() {
9391
- }
9392
- };
9393
- _CollisionCollector.initialEarlyOutFraction = Infinity;
9394
- _CollisionCollector.shouldEarlyOutFraction = -Infinity;
9395
- let CollisionCollector = _CollisionCollector;
9396
- var CollectFacesMode = /* @__PURE__ */ ((CollectFacesMode2) => {
9397
- CollectFacesMode2[CollectFacesMode2["CollectFaces"] = 0] = "CollectFaces";
9398
- CollectFacesMode2[CollectFacesMode2["NoFaces"] = 1] = "NoFaces";
9399
- return CollectFacesMode2;
9400
- })(CollectFacesMode || {});
9401
- var ActiveEdgeMode = /* @__PURE__ */ ((ActiveEdgeMode2) => {
9402
- ActiveEdgeMode2[ActiveEdgeMode2["CollideOnlyWithActive"] = 0] = "CollideOnlyWithActive";
9403
- ActiveEdgeMode2[ActiveEdgeMode2["CollideWithAll"] = 1] = "CollideWithAll";
9404
- return ActiveEdgeMode2;
9405
- })(ActiveEdgeMode || {});
9406
- var BackFaceMode = /* @__PURE__ */ ((BackFaceMode2) => {
9407
- BackFaceMode2[BackFaceMode2["IgnoreBackFaces"] = 0] = "IgnoreBackFaces";
9408
- BackFaceMode2[BackFaceMode2["CollideWithBackFaces"] = 1] = "CollideWithBackFaces";
9409
- return BackFaceMode2;
9410
- })(BackFaceMode || {});
9411
9418
  const edgeProps = props({
9412
9419
  neighbourTriangle: LazyReferenceType((() => Triangle2)),
9413
9420
  neighbourEdge: 0,
@@ -10249,47 +10256,6 @@ class PenetrationDepthModule {
10249
10256
  return true;
10250
10257
  }
10251
10258
  }
10252
- const result$9 = CollisionResult.create({
10253
- faceA: {
10254
- numVertices: 0,
10255
- buffer: { pool: new Vec3.Pool(32), maxLength: 32 }
10256
- },
10257
- faceB: {
10258
- numVertices: 0,
10259
- buffer: { pool: new Vec3.Pool(32), maxLength: 32 }
10260
- }
10261
- });
10262
- const positionA$3 = /* @__PURE__ */ Vec3.create();
10263
- const positionB$3 = /* @__PURE__ */ Vec3.create();
10264
- const ab = /* @__PURE__ */ Vec3.create();
10265
- function collideSphereVsSphere(penetrationDepthModule2, collector2, shapeA, shapeB2, isometryA2, isometryB2, settings, bodyA, bodyB, initialDirection, subShapeIdA = 0, subShapeIdB = 0) {
10266
- result$9.reset();
10267
- result$9.bodyA = bodyA;
10268
- result$9.bodyB = bodyB;
10269
- isometryA2.matrix.getTranslation(positionA$3);
10270
- isometryB2.matrix.getTranslation(positionB$3);
10271
- ab.subtractVectors(positionB$3, positionA$3);
10272
- if (ab.squaredLength() > squared(shapeA.radius + shapeB2.radius)) {
10273
- result$9.hasContact = false;
10274
- collector2.addMiss();
10275
- return;
10276
- }
10277
- result$9.hasContact = true;
10278
- result$9.bodyA = bodyA;
10279
- result$9.bodyB = bodyB;
10280
- result$9.subShapeIdA = subShapeIdA;
10281
- result$9.subShapeIdB = subShapeIdB;
10282
- result$9.normalA.normalizeVector(ab);
10283
- result$9.normalB.negateVector(result$9.normalA);
10284
- result$9.contactPointA.addScaledToVector(positionA$3, result$9.normalA, shapeA.radius);
10285
- result$9.contactPointB.addScaledToVector(positionB$3, result$9.normalB, shapeB2.radius);
10286
- result$9.momentArmA.subtractVectors(result$9.contactPointA, positionA$3);
10287
- result$9.momentArmB.subtractVectors(result$9.contactPointB, positionB$3);
10288
- result$9.penetration = shapeA.radius + shapeB2.radius - ab.length();
10289
- result$9.normalA.normalizeVector(result$9.normalA);
10290
- result$9.normalB.normalizeVector(result$9.normalB);
10291
- collector2.addHit(result$9);
10292
- }
10293
10259
  const result$8 = CollisionResult.create({
10294
10260
  faceA: {
10295
10261
  numVertices: 0,
@@ -11290,6 +11256,16 @@ class CollideShapesModule {
11290
11256
  );
11291
11257
  }
11292
11258
  }
11259
+ const lineProps = props({
11260
+ a: Vec3,
11261
+ b: Vec3
11262
+ });
11263
+ class Line extends createClass()(lineProps) {
11264
+ setFromPointAndDirection(point2, direction2, length) {
11265
+ this.a.copy(point2);
11266
+ this.b.addScaledToVector(point2, direction2, length);
11267
+ }
11268
+ }
11293
11269
  const estimateCollisionResponseResultProps = props({
11294
11270
  deltaLinearVelocityA: Vec3,
11295
11271
  deltaAngularVelocityA: Vec3,
@@ -12525,10 +12501,16 @@ class BvhModule {
12525
12501
  }
12526
12502
  return startOffset;
12527
12503
  }
12504
+ markStaticBodyAsDirty(body2) {
12505
+ this.staticTree.markObjectAsDirty(body2);
12506
+ }
12528
12507
  markDynamicBodyAsDirty(body2) {
12529
12508
  this.dynamicTree.markObjectAsDirty(body2);
12530
12509
  }
12531
12510
  updateDirtyBodies() {
12511
+ for (const body2 of this.staticTree.dirtyObjects) {
12512
+ this.staticTree.update(body2, false);
12513
+ }
12532
12514
  for (const body2 of this.dynamicTree.dirtyObjects) {
12533
12515
  this.dynamicTree.update(body2, false);
12534
12516
  }
@@ -16039,17 +16021,18 @@ export {
16039
16021
  CollideShapesModule,
16040
16022
  ColliderType,
16041
16023
  CollisionCollector,
16042
- CollisionFilter,
16043
16024
  CollisionResult,
16044
16025
  CompoundShape,
16045
16026
  ContactManifold,
16046
16027
  ConvexHull,
16047
16028
  ConvexRadiusObject,
16029
+ Cylinder,
16048
16030
  DistanceConstraint,
16049
16031
  Face,
16050
16032
  FixedConstraint,
16051
16033
  GjkCastShapeResult,
16052
16034
  GjkModule,
16035
+ HeightMap,
16053
16036
  HingeConstraint,
16054
16037
  Isometry,
16055
16038
  Line,
@@ -16074,6 +16057,7 @@ export {
16074
16057
  World,
16075
16058
  baseConstraintProps,
16076
16059
  clamp,
16060
+ createBitFlags,
16077
16061
  degreesToRadians,
16078
16062
  destroyAllInstancesInPool,
16079
16063
  squared