@threepipe/plugin-blend-importer 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("threepipe")) : typeof define === "function" && define.amd ? define(["exports", "threepipe"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@threepipe/plugin-blend-importer"] = {}, global.threepipe));
3
- })(this, function(exports2, threepipe) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("threepipe"), require("three")) : typeof define === "function" && define.amd ? define(["exports", "threepipe", "three"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@threepipe/plugin-blend-importer"] = {}, global.threepipe, global.threepipe));
3
+ })(this, function(exports2, threepipe, three) {
4
4
  "use strict";/**
5
5
  * @license
6
- * @threepipe/plugin-blend-importer v0.0.5
6
+ * @threepipe/plugin-blend-importer v0.0.7
7
7
  * Copyright 2022-2025 repalash <palash@shaders.app>
8
8
  * Apache-2.0 License
9
9
  * See ./dependencies.txt for any bundled third-party dependencies and licenses.
@@ -414,6 +414,15 @@
414
414
  function toString(buffer, _in, _out) {
415
415
  return String.fromCharCode.apply(String, new Uint8Array(buffer, _in, _out - _in));
416
416
  }
417
+ function seekCheck(buffer, _in, str) {
418
+ const length = str.length;
419
+ for (let i = 0; i < length; i++) {
420
+ if (buffer.getUint8(_in + i) !== str.charCodeAt(i)) {
421
+ return false;
422
+ }
423
+ }
424
+ return true;
425
+ }
417
426
  function readFile() {
418
427
  let count = 0;
419
428
  let offset2 = 0;
@@ -464,14 +473,13 @@
464
473
  offset2++;
465
474
  curr_count++;
466
475
  }
467
- if (toString(_data, offset2, offset2 + 4) !== "TYPE") {
468
- for (let j = 0; j < 8; j++) {
469
- if (toString(_data, offset2, offset2 + 4) === "TYPE") break;
470
- offset2++;
471
- }
476
+ for (let j = 0; j < 8; j++) {
477
+ if (seekCheck(data, offset2, "TYPE")) break;
478
+ offset2++;
472
479
  }
473
- if (toString(_data, offset2, offset2 + 4) !== "TYPE") {
474
- debugger;
480
+ if (!seekCheck(data, offset2, "TYPE")) {
481
+ ERROR = "Unexpected alignment error in SDNA parsing";
482
+ break;
475
483
  }
476
484
  offset2 += 4;
477
485
  count = data.getUint32(offset2, true);
@@ -487,14 +495,13 @@
487
495
  offset2++;
488
496
  curr_count++;
489
497
  }
490
- if (toString(_data, offset2, offset2 + 4) !== "TLEN") {
491
- for (let j = 0; j < 8; j++) {
492
- if (toString(_data, offset2, offset2 + 4) === "TLEN") break;
493
- offset2++;
494
- }
498
+ for (let j = 0; j < 8; j++) {
499
+ if (seekCheck(data, offset2, "TLEN")) break;
500
+ offset2++;
495
501
  }
496
- if (toString(_data, offset2, offset2 + 4) !== "TLEN") {
497
- debugger;
502
+ if (!seekCheck(data, offset2, "TLEN")) {
503
+ ERROR = "Unexpected alignment error in SDNA parsing";
504
+ break;
498
505
  }
499
506
  offset2 += 4;
500
507
  curr_count = 0;
@@ -503,14 +510,13 @@
503
510
  offset2 += 2;
504
511
  curr_count++;
505
512
  }
506
- if (toString(_data, offset2, offset2 + 4) !== "STRC") {
507
- for (let j = 0; j < 8; j++) {
508
- if (toString(_data, offset2, offset2 + 4) === "STRC") break;
509
- offset2++;
510
- }
513
+ for (let j = 0; j < 8; j++) {
514
+ if (seekCheck(data, offset2, "STRC")) break;
515
+ offset2++;
511
516
  }
512
- if (toString(_data, offset2, offset2 + 4) !== "STRC") {
513
- debugger;
517
+ if (!seekCheck(data, offset2, "STRC")) {
518
+ ERROR = "Unexpected alignment error in SDNA parsing";
519
+ break;
514
520
  }
515
521
  offset2 += 4;
516
522
  const structure_count = data.getInt32(offset2, BIG_ENDIAN);
@@ -640,17 +646,17 @@
640
646
  const type = cdata.type;
641
647
  let camera;
642
648
  if (type === 0) {
649
+ const sensorWidth = cdata.sensor_x || 36;
650
+ const sensorHeight = cdata.sensor_y || 24;
651
+ const lens = cdata.lens || 50;
652
+ const fov = 2 * Math.atan(sensorHeight / (2 * lens)) * (180 / Math.PI);
643
653
  camera = new ctx.PerspectiveCamera(
644
- cdata.lens || 50,
645
- // fov or lens
646
- (cdata.sensor_x || 36) / (cdata.sensor_y || 24),
647
- // aspect
654
+ fov,
655
+ sensorWidth / sensorHeight,
648
656
  cdata.clipsta || 0.1,
649
- // near
650
657
  cdata.clipend || 1e3
651
- // far
652
658
  );
653
- camera.position.set(0, 0, 0);
659
+ if ("shiftx" in cdata) camera.userData.shiftX = cdata.shiftx;
654
660
  if ("shiftx" in cdata) camera.userData.shiftX = cdata.shiftx;
655
661
  if ("shifty" in cdata) camera.userData.shiftY = cdata.shifty;
656
662
  } else if (type === 1) {
@@ -668,7 +674,6 @@
668
674
  cdata.clipsta || 0.1,
669
675
  cdata.clipend || 1e3
670
676
  );
671
- camera.position.set(0, 0, 0);
672
677
  if ("shiftx" in cdata) camera.userData.shiftX = cdata.shiftx;
673
678
  if ("shifty" in cdata) camera.userData.shiftY = cdata.shifty;
674
679
  } else {
@@ -715,12 +720,13 @@
715
720
  return layers[i];
716
721
  }
717
722
  function createBufferGeometry(meshData, ctx) {
718
- var _a;
719
723
  if (meshData.mpoly) return createBufferGeometryOld(meshData, ctx);
720
724
  const geometry = new ctx.BufferGeometry();
721
725
  geometry.name = meshData.aname || "";
722
726
  let vertices;
727
+ let verticesData;
723
728
  let indices;
729
+ let indicesData;
724
730
  if (meshData.vdata && meshData.vdata.layers && meshData.vdata.totlayer > 0) {
725
731
  for (let i = 0; i < meshData.vdata.totlayer; i++) {
726
732
  const layer = getLayer(meshData.vdata.layers, i);
@@ -730,6 +736,7 @@
730
736
  continue;
731
737
  }
732
738
  vertices = layer;
739
+ verticesData = data;
733
740
  }
734
741
  }
735
742
  }
@@ -742,6 +749,7 @@
742
749
  continue;
743
750
  }
744
751
  indices = layer;
752
+ indicesData = data;
745
753
  }
746
754
  }
747
755
  }
@@ -749,26 +757,26 @@
749
757
  if (meshData.poly_offset_indices && meshData.totpoly > 0) {
750
758
  faceIndices = [...new Int32Array(meshData.poly_offset_indices.__blender_file__.AB, meshData.poly_offset_indices.__data_address__, meshData.totpoly + 1)];
751
759
  }
752
- if ((vertices == null ? void 0 : vertices.data) && vertices.data.length > 0) {
753
- const positions = new Float32Array(vertices.data.length * 3);
754
- for (let j = 0; j < vertices.data.length; j++) {
755
- const vertex = vertices.data[j];
756
- if (vertex.x !== void 0) {
757
- positions[j * 3] = vertex.x;
758
- positions[j * 3 + 1] = vertex.z;
759
- positions[j * 3 + 2] = -vertex.y;
760
- } else if (vertex.co !== void 0) {
761
- positions[j * 3] = vertex.co[0];
762
- positions[j * 3 + 1] = vertex.co[2];
763
- positions[j * 3 + 2] = -vertex.co[1];
760
+ if (verticesData && verticesData.length > 0) {
761
+ const positions = new Float32Array(verticesData.length * 3);
762
+ for (let j = 0; j < verticesData.length; j++) {
763
+ const { x, y, z, co } = verticesData[j] || {};
764
+ if (x !== void 0) {
765
+ positions[j * 3] = x;
766
+ positions[j * 3 + 1] = z;
767
+ positions[j * 3 + 2] = -y;
768
+ } else if (co !== void 0) {
769
+ positions[j * 3] = co[0];
770
+ positions[j * 3 + 1] = co[2];
771
+ positions[j * 3 + 2] = -co[1];
764
772
  } else {
765
- console.error("BlendLoader - unknown vertex", vertex);
773
+ console.error("BlendLoader - unknown vertex", verticesData[j]);
766
774
  break;
767
775
  }
768
776
  }
769
777
  geometry.setAttribute("position", new ctx.BufferAttribute(positions, 3));
770
778
  }
771
- if ((indices == null ? void 0 : indices.data) && indices.data.length > 0 && ((_a = vertices == null ? void 0 : vertices.data) == null ? void 0 : _a.length)) {
779
+ if (indicesData && indicesData.length > 0 && (verticesData == null ? void 0 : verticesData.length)) {
772
780
  const faceSize = meshData.totloop / meshData.totpoly;
773
781
  if (faceIndices.length > 0) {
774
782
  let totalTriangles = 0;
@@ -783,11 +791,11 @@
783
791
  const faceEnd = faceIndices[i + 1];
784
792
  const faceVertCount = faceEnd - faceStart;
785
793
  if (faceVertCount >= 3) {
786
- const firstVert = indices.data[faceStart].i;
794
+ const firstVert = indicesData[faceStart].i;
787
795
  for (let k = 1; k < faceVertCount - 1; k++) {
788
796
  indexes[t++] = firstVert;
789
- indexes[t++] = indices.data[faceStart + k].i;
790
- indexes[t++] = indices.data[faceStart + k + 1].i;
797
+ indexes[t++] = indicesData[faceStart + k].i;
798
+ indexes[t++] = indicesData[faceStart + k + 1].i;
791
799
  }
792
800
  }
793
801
  }
@@ -842,21 +850,24 @@
842
850
  if (indexi - 1 + l < len)
843
851
  index += indexi - 1 + l;
844
852
  const loop = loops[index];
845
- const vert = vertices[loop.v];
853
+ const { co, no } = vertices[loop.v] || {};
846
854
  indices[currentIndex] = currentIndex;
847
- positions[currentIndex * 3 + 0] = vert.co[0];
848
- positions[currentIndex * 3 + 1] = vert.co[2];
849
- positions[currentIndex * 3 + 2] = -vert.co[1];
850
- if (vert.no) {
851
- normals[currentIndex * 3 + 0] = vert.no[0];
852
- normals[currentIndex * 3 + 1] = vert.no[2];
853
- normals[currentIndex * 3 + 2] = -vert.no[1];
855
+ if (co) {
856
+ positions[currentIndex * 3 + 0] = co[0];
857
+ positions[currentIndex * 3 + 1] = co[2];
858
+ positions[currentIndex * 3 + 2] = -co[1];
859
+ }
860
+ if (no) {
861
+ normals[currentIndex * 3 + 0] = no[0];
862
+ normals[currentIndex * 3 + 1] = no[2];
863
+ normals[currentIndex * 3 + 2] = -no[1];
854
864
  } else {
855
865
  computeNormals = true;
856
866
  }
857
867
  if (uv) {
858
- uvs[currentIndex * 2 + 0] = uv[index].uv[0];
859
- uvs[currentIndex * 2 + 1] = uv[index].uv[1];
868
+ const uv1 = uv[index].uv;
869
+ uvs[currentIndex * 2 + 0] = uv1[0];
870
+ uvs[currentIndex * 2 + 1] = uv1[1];
860
871
  }
861
872
  currentIndex++;
862
873
  }
@@ -881,13 +892,6 @@
881
892
  material.transparent = material.opacity < 1;
882
893
  return material;
883
894
  }
884
- function setCreateTransform(object, obj) {
885
- obj.name = object.aname;
886
- obj.quaternion.set(object.quat[1], object.quat[3], -object.quat[2], object.quat[0]);
887
- obj.scale.set(object.size[0], object.size[1], object.size[2]);
888
- obj.position.set(object.loc[0], object.loc[2], -object.loc[1]);
889
- obj.updateMatrix();
890
- }
891
895
  function createMesh(object, loaded, ctx) {
892
896
  if (!object.data) {
893
897
  return void 0;
@@ -902,6 +906,1765 @@
902
906
  mesh.receiveShadow = true;
903
907
  return mesh;
904
908
  }
909
+ function clamp(value, min, max) {
910
+ return Math.max(min, Math.min(max, value));
911
+ }
912
+ class Quaternion {
913
+ constructor(x = 0, y = 0, z = 0, w = 1) {
914
+ this.isQuaternion = true;
915
+ this._x = x;
916
+ this._y = y;
917
+ this._z = z;
918
+ this._w = w;
919
+ }
920
+ static slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
921
+ let x0 = src0[srcOffset0 + 0], y0 = src0[srcOffset0 + 1], z0 = src0[srcOffset0 + 2], w0 = src0[srcOffset0 + 3];
922
+ const x1 = src1[srcOffset1 + 0], y1 = src1[srcOffset1 + 1], z1 = src1[srcOffset1 + 2], w1 = src1[srcOffset1 + 3];
923
+ if (t === 0) {
924
+ dst[dstOffset + 0] = x0;
925
+ dst[dstOffset + 1] = y0;
926
+ dst[dstOffset + 2] = z0;
927
+ dst[dstOffset + 3] = w0;
928
+ return;
929
+ }
930
+ if (t === 1) {
931
+ dst[dstOffset + 0] = x1;
932
+ dst[dstOffset + 1] = y1;
933
+ dst[dstOffset + 2] = z1;
934
+ dst[dstOffset + 3] = w1;
935
+ return;
936
+ }
937
+ if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
938
+ let s = 1 - t;
939
+ const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, dir = cos >= 0 ? 1 : -1, sqrSin = 1 - cos * cos;
940
+ if (sqrSin > Number.EPSILON) {
941
+ const sin = Math.sqrt(sqrSin), len = Math.atan2(sin, cos * dir);
942
+ s = Math.sin(s * len) / sin;
943
+ t = Math.sin(t * len) / sin;
944
+ }
945
+ const tDir = t * dir;
946
+ x0 = x0 * s + x1 * tDir;
947
+ y0 = y0 * s + y1 * tDir;
948
+ z0 = z0 * s + z1 * tDir;
949
+ w0 = w0 * s + w1 * tDir;
950
+ if (s === 1 - t) {
951
+ const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
952
+ x0 *= f;
953
+ y0 *= f;
954
+ z0 *= f;
955
+ w0 *= f;
956
+ }
957
+ }
958
+ dst[dstOffset] = x0;
959
+ dst[dstOffset + 1] = y0;
960
+ dst[dstOffset + 2] = z0;
961
+ dst[dstOffset + 3] = w0;
962
+ }
963
+ static multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
964
+ const x0 = src0[srcOffset0];
965
+ const y0 = src0[srcOffset0 + 1];
966
+ const z0 = src0[srcOffset0 + 2];
967
+ const w0 = src0[srcOffset0 + 3];
968
+ const x1 = src1[srcOffset1];
969
+ const y1 = src1[srcOffset1 + 1];
970
+ const z1 = src1[srcOffset1 + 2];
971
+ const w1 = src1[srcOffset1 + 3];
972
+ dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
973
+ dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
974
+ dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
975
+ dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
976
+ return dst;
977
+ }
978
+ get x() {
979
+ return this._x;
980
+ }
981
+ set x(value) {
982
+ this._x = value;
983
+ this._onChangeCallback();
984
+ }
985
+ get y() {
986
+ return this._y;
987
+ }
988
+ set y(value) {
989
+ this._y = value;
990
+ this._onChangeCallback();
991
+ }
992
+ get z() {
993
+ return this._z;
994
+ }
995
+ set z(value) {
996
+ this._z = value;
997
+ this._onChangeCallback();
998
+ }
999
+ get w() {
1000
+ return this._w;
1001
+ }
1002
+ set w(value) {
1003
+ this._w = value;
1004
+ this._onChangeCallback();
1005
+ }
1006
+ set(x, y, z, w) {
1007
+ this._x = x;
1008
+ this._y = y;
1009
+ this._z = z;
1010
+ this._w = w;
1011
+ this._onChangeCallback();
1012
+ return this;
1013
+ }
1014
+ clone() {
1015
+ return new this.constructor(this._x, this._y, this._z, this._w);
1016
+ }
1017
+ copy(quaternion) {
1018
+ this._x = quaternion.x;
1019
+ this._y = quaternion.y;
1020
+ this._z = quaternion.z;
1021
+ this._w = quaternion.w;
1022
+ this._onChangeCallback();
1023
+ return this;
1024
+ }
1025
+ setFromEuler(euler, update = true) {
1026
+ const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
1027
+ const cos = Math.cos;
1028
+ const sin = Math.sin;
1029
+ const c1 = cos(x / 2);
1030
+ const c2 = cos(y / 2);
1031
+ const c3 = cos(z / 2);
1032
+ const s1 = sin(x / 2);
1033
+ const s2 = sin(y / 2);
1034
+ const s3 = sin(z / 2);
1035
+ switch (order) {
1036
+ case "XYZ":
1037
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
1038
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
1039
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
1040
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
1041
+ break;
1042
+ case "YXZ":
1043
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
1044
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
1045
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
1046
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
1047
+ break;
1048
+ case "ZXY":
1049
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
1050
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
1051
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
1052
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
1053
+ break;
1054
+ case "ZYX":
1055
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
1056
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
1057
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
1058
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
1059
+ break;
1060
+ case "YZX":
1061
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
1062
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
1063
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
1064
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
1065
+ break;
1066
+ case "XZY":
1067
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
1068
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
1069
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
1070
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
1071
+ break;
1072
+ default:
1073
+ console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + order);
1074
+ }
1075
+ if (update === true) this._onChangeCallback();
1076
+ return this;
1077
+ }
1078
+ setFromAxisAngle(axis, angle) {
1079
+ const halfAngle = angle / 2, s = Math.sin(halfAngle);
1080
+ this._x = axis.x * s;
1081
+ this._y = axis.y * s;
1082
+ this._z = axis.z * s;
1083
+ this._w = Math.cos(halfAngle);
1084
+ this._onChangeCallback();
1085
+ return this;
1086
+ }
1087
+ setFromRotationMatrix(m) {
1088
+ const te = m.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10], trace = m11 + m22 + m33;
1089
+ if (trace > 0) {
1090
+ const s = 0.5 / Math.sqrt(trace + 1);
1091
+ this._w = 0.25 / s;
1092
+ this._x = (m32 - m23) * s;
1093
+ this._y = (m13 - m31) * s;
1094
+ this._z = (m21 - m12) * s;
1095
+ } else if (m11 > m22 && m11 > m33) {
1096
+ const s = 2 * Math.sqrt(1 + m11 - m22 - m33);
1097
+ this._w = (m32 - m23) / s;
1098
+ this._x = 0.25 * s;
1099
+ this._y = (m12 + m21) / s;
1100
+ this._z = (m13 + m31) / s;
1101
+ } else if (m22 > m33) {
1102
+ const s = 2 * Math.sqrt(1 + m22 - m11 - m33);
1103
+ this._w = (m13 - m31) / s;
1104
+ this._x = (m12 + m21) / s;
1105
+ this._y = 0.25 * s;
1106
+ this._z = (m23 + m32) / s;
1107
+ } else {
1108
+ const s = 2 * Math.sqrt(1 + m33 - m11 - m22);
1109
+ this._w = (m21 - m12) / s;
1110
+ this._x = (m13 + m31) / s;
1111
+ this._y = (m23 + m32) / s;
1112
+ this._z = 0.25 * s;
1113
+ }
1114
+ this._onChangeCallback();
1115
+ return this;
1116
+ }
1117
+ setFromUnitVectors(vFrom, vTo) {
1118
+ let r = vFrom.dot(vTo) + 1;
1119
+ if (r < Number.EPSILON) {
1120
+ r = 0;
1121
+ if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
1122
+ this._x = -vFrom.y;
1123
+ this._y = vFrom.x;
1124
+ this._z = 0;
1125
+ this._w = r;
1126
+ } else {
1127
+ this._x = 0;
1128
+ this._y = -vFrom.z;
1129
+ this._z = vFrom.y;
1130
+ this._w = r;
1131
+ }
1132
+ } else {
1133
+ this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
1134
+ this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
1135
+ this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
1136
+ this._w = r;
1137
+ }
1138
+ return this.normalize();
1139
+ }
1140
+ angleTo(q) {
1141
+ return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
1142
+ }
1143
+ rotateTowards(q, step) {
1144
+ const angle = this.angleTo(q);
1145
+ if (angle === 0) return this;
1146
+ const t = Math.min(1, step / angle);
1147
+ this.slerp(q, t);
1148
+ return this;
1149
+ }
1150
+ identity() {
1151
+ return this.set(0, 0, 0, 1);
1152
+ }
1153
+ invert() {
1154
+ return this.conjugate();
1155
+ }
1156
+ conjugate() {
1157
+ this._x *= -1;
1158
+ this._y *= -1;
1159
+ this._z *= -1;
1160
+ this._onChangeCallback();
1161
+ return this;
1162
+ }
1163
+ dot(v) {
1164
+ return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
1165
+ }
1166
+ lengthSq() {
1167
+ return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
1168
+ }
1169
+ length() {
1170
+ return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
1171
+ }
1172
+ normalize() {
1173
+ let l = this.length();
1174
+ if (l === 0) {
1175
+ this._x = 0;
1176
+ this._y = 0;
1177
+ this._z = 0;
1178
+ this._w = 1;
1179
+ } else {
1180
+ l = 1 / l;
1181
+ this._x = this._x * l;
1182
+ this._y = this._y * l;
1183
+ this._z = this._z * l;
1184
+ this._w = this._w * l;
1185
+ }
1186
+ this._onChangeCallback();
1187
+ return this;
1188
+ }
1189
+ multiply(q) {
1190
+ return this.multiplyQuaternions(this, q);
1191
+ }
1192
+ premultiply(q) {
1193
+ return this.multiplyQuaternions(q, this);
1194
+ }
1195
+ multiplyQuaternions(a, b) {
1196
+ const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
1197
+ const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
1198
+ this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
1199
+ this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
1200
+ this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
1201
+ this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
1202
+ this._onChangeCallback();
1203
+ return this;
1204
+ }
1205
+ slerp(qb, t) {
1206
+ if (t === 0) return this;
1207
+ if (t === 1) return this.copy(qb);
1208
+ const x = this._x, y = this._y, z = this._z, w = this._w;
1209
+ let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
1210
+ if (cosHalfTheta < 0) {
1211
+ this._w = -qb._w;
1212
+ this._x = -qb._x;
1213
+ this._y = -qb._y;
1214
+ this._z = -qb._z;
1215
+ cosHalfTheta = -cosHalfTheta;
1216
+ } else {
1217
+ this.copy(qb);
1218
+ }
1219
+ if (cosHalfTheta >= 1) {
1220
+ this._w = w;
1221
+ this._x = x;
1222
+ this._y = y;
1223
+ this._z = z;
1224
+ return this;
1225
+ }
1226
+ const sqrSinHalfTheta = 1 - cosHalfTheta * cosHalfTheta;
1227
+ if (sqrSinHalfTheta <= Number.EPSILON) {
1228
+ const s = 1 - t;
1229
+ this._w = s * w + t * this._w;
1230
+ this._x = s * x + t * this._x;
1231
+ this._y = s * y + t * this._y;
1232
+ this._z = s * z + t * this._z;
1233
+ this.normalize();
1234
+ return this;
1235
+ }
1236
+ const sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
1237
+ const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
1238
+ const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta, ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
1239
+ this._w = w * ratioA + this._w * ratioB;
1240
+ this._x = x * ratioA + this._x * ratioB;
1241
+ this._y = y * ratioA + this._y * ratioB;
1242
+ this._z = z * ratioA + this._z * ratioB;
1243
+ this._onChangeCallback();
1244
+ return this;
1245
+ }
1246
+ slerpQuaternions(qa, qb, t) {
1247
+ return this.copy(qa).slerp(qb, t);
1248
+ }
1249
+ random() {
1250
+ const u1 = Math.random();
1251
+ const sqrt1u1 = Math.sqrt(1 - u1);
1252
+ const sqrtu1 = Math.sqrt(u1);
1253
+ const u2 = 2 * Math.PI * Math.random();
1254
+ const u3 = 2 * Math.PI * Math.random();
1255
+ return this.set(
1256
+ sqrt1u1 * Math.cos(u2),
1257
+ sqrtu1 * Math.sin(u3),
1258
+ sqrtu1 * Math.cos(u3),
1259
+ sqrt1u1 * Math.sin(u2)
1260
+ );
1261
+ }
1262
+ equals(quaternion) {
1263
+ return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
1264
+ }
1265
+ fromArray(array, offset = 0) {
1266
+ this._x = array[offset];
1267
+ this._y = array[offset + 1];
1268
+ this._z = array[offset + 2];
1269
+ this._w = array[offset + 3];
1270
+ this._onChangeCallback();
1271
+ return this;
1272
+ }
1273
+ toArray(array = [], offset = 0) {
1274
+ array[offset] = this._x;
1275
+ array[offset + 1] = this._y;
1276
+ array[offset + 2] = this._z;
1277
+ array[offset + 3] = this._w;
1278
+ return array;
1279
+ }
1280
+ fromBufferAttribute(attribute, index) {
1281
+ this._x = attribute.getX(index);
1282
+ this._y = attribute.getY(index);
1283
+ this._z = attribute.getZ(index);
1284
+ this._w = attribute.getW(index);
1285
+ this._onChangeCallback();
1286
+ return this;
1287
+ }
1288
+ toJSON() {
1289
+ return this.toArray();
1290
+ }
1291
+ _onChange(callback) {
1292
+ this._onChangeCallback = callback;
1293
+ return this;
1294
+ }
1295
+ _onChangeCallback() {
1296
+ }
1297
+ *[Symbol.iterator]() {
1298
+ yield this._x;
1299
+ yield this._y;
1300
+ yield this._z;
1301
+ yield this._w;
1302
+ }
1303
+ }
1304
+ const WebGLCoordinateSystem = 2e3;
1305
+ const WebGPUCoordinateSystem = 2001;
1306
+ class Vector3 {
1307
+ constructor(x = 0, y = 0, z = 0) {
1308
+ Vector3.prototype.isVector3 = true;
1309
+ this.x = x;
1310
+ this.y = y;
1311
+ this.z = z;
1312
+ }
1313
+ set(x, y, z) {
1314
+ if (z === void 0) z = this.z;
1315
+ this.x = x;
1316
+ this.y = y;
1317
+ this.z = z;
1318
+ return this;
1319
+ }
1320
+ setScalar(scalar) {
1321
+ this.x = scalar;
1322
+ this.y = scalar;
1323
+ this.z = scalar;
1324
+ return this;
1325
+ }
1326
+ setX(x) {
1327
+ this.x = x;
1328
+ return this;
1329
+ }
1330
+ setY(y) {
1331
+ this.y = y;
1332
+ return this;
1333
+ }
1334
+ setZ(z) {
1335
+ this.z = z;
1336
+ return this;
1337
+ }
1338
+ setComponent(index, value) {
1339
+ switch (index) {
1340
+ case 0:
1341
+ this.x = value;
1342
+ break;
1343
+ case 1:
1344
+ this.y = value;
1345
+ break;
1346
+ case 2:
1347
+ this.z = value;
1348
+ break;
1349
+ default:
1350
+ throw new Error("index is out of range: " + index);
1351
+ }
1352
+ return this;
1353
+ }
1354
+ getComponent(index) {
1355
+ switch (index) {
1356
+ case 0:
1357
+ return this.x;
1358
+ case 1:
1359
+ return this.y;
1360
+ case 2:
1361
+ return this.z;
1362
+ default:
1363
+ throw new Error("index is out of range: " + index);
1364
+ }
1365
+ }
1366
+ clone() {
1367
+ return new this.constructor(this.x, this.y, this.z);
1368
+ }
1369
+ copy(v) {
1370
+ this.x = v.x;
1371
+ this.y = v.y;
1372
+ this.z = v.z;
1373
+ return this;
1374
+ }
1375
+ add(v) {
1376
+ this.x += v.x;
1377
+ this.y += v.y;
1378
+ this.z += v.z;
1379
+ return this;
1380
+ }
1381
+ addScalar(s) {
1382
+ this.x += s;
1383
+ this.y += s;
1384
+ this.z += s;
1385
+ return this;
1386
+ }
1387
+ addVectors(a, b) {
1388
+ this.x = a.x + b.x;
1389
+ this.y = a.y + b.y;
1390
+ this.z = a.z + b.z;
1391
+ return this;
1392
+ }
1393
+ addScaledVector(v, s) {
1394
+ this.x += v.x * s;
1395
+ this.y += v.y * s;
1396
+ this.z += v.z * s;
1397
+ return this;
1398
+ }
1399
+ sub(v) {
1400
+ this.x -= v.x;
1401
+ this.y -= v.y;
1402
+ this.z -= v.z;
1403
+ return this;
1404
+ }
1405
+ subScalar(s) {
1406
+ this.x -= s;
1407
+ this.y -= s;
1408
+ this.z -= s;
1409
+ return this;
1410
+ }
1411
+ subVectors(a, b) {
1412
+ this.x = a.x - b.x;
1413
+ this.y = a.y - b.y;
1414
+ this.z = a.z - b.z;
1415
+ return this;
1416
+ }
1417
+ multiply(v) {
1418
+ this.x *= v.x;
1419
+ this.y *= v.y;
1420
+ this.z *= v.z;
1421
+ return this;
1422
+ }
1423
+ multiplyScalar(scalar) {
1424
+ this.x *= scalar;
1425
+ this.y *= scalar;
1426
+ this.z *= scalar;
1427
+ return this;
1428
+ }
1429
+ multiplyVectors(a, b) {
1430
+ this.x = a.x * b.x;
1431
+ this.y = a.y * b.y;
1432
+ this.z = a.z * b.z;
1433
+ return this;
1434
+ }
1435
+ applyEuler(euler) {
1436
+ return this.applyQuaternion(_quaternion$1.setFromEuler(euler));
1437
+ }
1438
+ applyAxisAngle(axis, angle) {
1439
+ return this.applyQuaternion(_quaternion$1.setFromAxisAngle(axis, angle));
1440
+ }
1441
+ applyMatrix3(m) {
1442
+ const x = this.x, y = this.y, z = this.z;
1443
+ const e = m.elements;
1444
+ this.x = e[0] * x + e[3] * y + e[6] * z;
1445
+ this.y = e[1] * x + e[4] * y + e[7] * z;
1446
+ this.z = e[2] * x + e[5] * y + e[8] * z;
1447
+ return this;
1448
+ }
1449
+ applyNormalMatrix(m) {
1450
+ return this.applyMatrix3(m).normalize();
1451
+ }
1452
+ applyMatrix4(m) {
1453
+ const x = this.x, y = this.y, z = this.z;
1454
+ const e = m.elements;
1455
+ const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
1456
+ this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
1457
+ this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
1458
+ this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
1459
+ return this;
1460
+ }
1461
+ applyQuaternion(q) {
1462
+ const vx = this.x, vy = this.y, vz = this.z;
1463
+ const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
1464
+ const tx = 2 * (qy * vz - qz * vy);
1465
+ const ty = 2 * (qz * vx - qx * vz);
1466
+ const tz = 2 * (qx * vy - qy * vx);
1467
+ this.x = vx + qw * tx + qy * tz - qz * ty;
1468
+ this.y = vy + qw * ty + qz * tx - qx * tz;
1469
+ this.z = vz + qw * tz + qx * ty - qy * tx;
1470
+ return this;
1471
+ }
1472
+ project(camera) {
1473
+ return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
1474
+ }
1475
+ unproject(camera) {
1476
+ return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
1477
+ }
1478
+ transformDirection(m) {
1479
+ const x = this.x, y = this.y, z = this.z;
1480
+ const e = m.elements;
1481
+ this.x = e[0] * x + e[4] * y + e[8] * z;
1482
+ this.y = e[1] * x + e[5] * y + e[9] * z;
1483
+ this.z = e[2] * x + e[6] * y + e[10] * z;
1484
+ return this.normalize();
1485
+ }
1486
+ divide(v) {
1487
+ this.x /= v.x;
1488
+ this.y /= v.y;
1489
+ this.z /= v.z;
1490
+ return this;
1491
+ }
1492
+ divideScalar(scalar) {
1493
+ return this.multiplyScalar(1 / scalar);
1494
+ }
1495
+ min(v) {
1496
+ this.x = Math.min(this.x, v.x);
1497
+ this.y = Math.min(this.y, v.y);
1498
+ this.z = Math.min(this.z, v.z);
1499
+ return this;
1500
+ }
1501
+ max(v) {
1502
+ this.x = Math.max(this.x, v.x);
1503
+ this.y = Math.max(this.y, v.y);
1504
+ this.z = Math.max(this.z, v.z);
1505
+ return this;
1506
+ }
1507
+ clamp(min, max) {
1508
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1509
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1510
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1511
+ return this;
1512
+ }
1513
+ clampScalar(minVal, maxVal) {
1514
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
1515
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
1516
+ this.z = Math.max(minVal, Math.min(maxVal, this.z));
1517
+ return this;
1518
+ }
1519
+ clampLength(min, max) {
1520
+ const length = this.length();
1521
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1522
+ }
1523
+ floor() {
1524
+ this.x = Math.floor(this.x);
1525
+ this.y = Math.floor(this.y);
1526
+ this.z = Math.floor(this.z);
1527
+ return this;
1528
+ }
1529
+ ceil() {
1530
+ this.x = Math.ceil(this.x);
1531
+ this.y = Math.ceil(this.y);
1532
+ this.z = Math.ceil(this.z);
1533
+ return this;
1534
+ }
1535
+ round() {
1536
+ this.x = Math.round(this.x);
1537
+ this.y = Math.round(this.y);
1538
+ this.z = Math.round(this.z);
1539
+ return this;
1540
+ }
1541
+ roundToZero() {
1542
+ this.x = Math.trunc(this.x);
1543
+ this.y = Math.trunc(this.y);
1544
+ this.z = Math.trunc(this.z);
1545
+ return this;
1546
+ }
1547
+ negate() {
1548
+ this.x = -this.x;
1549
+ this.y = -this.y;
1550
+ this.z = -this.z;
1551
+ return this;
1552
+ }
1553
+ dot(v) {
1554
+ return this.x * v.x + this.y * v.y + this.z * v.z;
1555
+ }
1556
+ // TODO lengthSquared?
1557
+ lengthSq() {
1558
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1559
+ }
1560
+ length() {
1561
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1562
+ }
1563
+ manhattanLength() {
1564
+ return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
1565
+ }
1566
+ normalize() {
1567
+ return this.divideScalar(this.length() || 1);
1568
+ }
1569
+ setLength(length) {
1570
+ return this.normalize().multiplyScalar(length);
1571
+ }
1572
+ lerp(v, alpha) {
1573
+ this.x += (v.x - this.x) * alpha;
1574
+ this.y += (v.y - this.y) * alpha;
1575
+ this.z += (v.z - this.z) * alpha;
1576
+ return this;
1577
+ }
1578
+ lerpVectors(v1, v2, alpha) {
1579
+ this.x = v1.x + (v2.x - v1.x) * alpha;
1580
+ this.y = v1.y + (v2.y - v1.y) * alpha;
1581
+ this.z = v1.z + (v2.z - v1.z) * alpha;
1582
+ return this;
1583
+ }
1584
+ cross(v) {
1585
+ return this.crossVectors(this, v);
1586
+ }
1587
+ crossVectors(a, b) {
1588
+ const ax = a.x, ay = a.y, az = a.z;
1589
+ const bx = b.x, by = b.y, bz = b.z;
1590
+ this.x = ay * bz - az * by;
1591
+ this.y = az * bx - ax * bz;
1592
+ this.z = ax * by - ay * bx;
1593
+ return this;
1594
+ }
1595
+ projectOnVector(v) {
1596
+ const denominator = v.lengthSq();
1597
+ if (denominator === 0) return this.set(0, 0, 0);
1598
+ const scalar = v.dot(this) / denominator;
1599
+ return this.copy(v).multiplyScalar(scalar);
1600
+ }
1601
+ projectOnPlane(planeNormal) {
1602
+ _vector.copy(this).projectOnVector(planeNormal);
1603
+ return this.sub(_vector);
1604
+ }
1605
+ reflect(normal) {
1606
+ return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
1607
+ }
1608
+ angleTo(v) {
1609
+ const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
1610
+ if (denominator === 0) return Math.PI / 2;
1611
+ const theta = this.dot(v) / denominator;
1612
+ return Math.acos(clamp(theta, -1, 1));
1613
+ }
1614
+ distanceTo(v) {
1615
+ return Math.sqrt(this.distanceToSquared(v));
1616
+ }
1617
+ distanceToSquared(v) {
1618
+ const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1619
+ return dx * dx + dy * dy + dz * dz;
1620
+ }
1621
+ manhattanDistanceTo(v) {
1622
+ return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
1623
+ }
1624
+ setFromSpherical(s) {
1625
+ return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
1626
+ }
1627
+ setFromSphericalCoords(radius, phi, theta) {
1628
+ const sinPhiRadius = Math.sin(phi) * radius;
1629
+ this.x = sinPhiRadius * Math.sin(theta);
1630
+ this.y = Math.cos(phi) * radius;
1631
+ this.z = sinPhiRadius * Math.cos(theta);
1632
+ return this;
1633
+ }
1634
+ setFromCylindrical(c) {
1635
+ return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
1636
+ }
1637
+ setFromCylindricalCoords(radius, theta, y) {
1638
+ this.x = radius * Math.sin(theta);
1639
+ this.y = y;
1640
+ this.z = radius * Math.cos(theta);
1641
+ return this;
1642
+ }
1643
+ setFromMatrixPosition(m) {
1644
+ const e = m.elements;
1645
+ this.x = e[12];
1646
+ this.y = e[13];
1647
+ this.z = e[14];
1648
+ return this;
1649
+ }
1650
+ setFromMatrixScale(m) {
1651
+ const sx = this.setFromMatrixColumn(m, 0).length();
1652
+ const sy = this.setFromMatrixColumn(m, 1).length();
1653
+ const sz = this.setFromMatrixColumn(m, 2).length();
1654
+ this.x = sx;
1655
+ this.y = sy;
1656
+ this.z = sz;
1657
+ return this;
1658
+ }
1659
+ setFromMatrixColumn(m, index) {
1660
+ return this.fromArray(m.elements, index * 4);
1661
+ }
1662
+ setFromMatrix3Column(m, index) {
1663
+ return this.fromArray(m.elements, index * 3);
1664
+ }
1665
+ setFromEuler(e) {
1666
+ this.x = e._x;
1667
+ this.y = e._y;
1668
+ this.z = e._z;
1669
+ return this;
1670
+ }
1671
+ setFromColor(c) {
1672
+ this.x = c.r;
1673
+ this.y = c.g;
1674
+ this.z = c.b;
1675
+ return this;
1676
+ }
1677
+ equals(v) {
1678
+ return v.x === this.x && v.y === this.y && v.z === this.z;
1679
+ }
1680
+ fromArray(array, offset = 0) {
1681
+ this.x = array[offset];
1682
+ this.y = array[offset + 1];
1683
+ this.z = array[offset + 2];
1684
+ return this;
1685
+ }
1686
+ toArray(array = [], offset = 0) {
1687
+ array[offset] = this.x;
1688
+ array[offset + 1] = this.y;
1689
+ array[offset + 2] = this.z;
1690
+ return array;
1691
+ }
1692
+ fromBufferAttribute(attribute, index) {
1693
+ this.x = attribute.getX(index);
1694
+ this.y = attribute.getY(index);
1695
+ this.z = attribute.getZ(index);
1696
+ return this;
1697
+ }
1698
+ random() {
1699
+ this.x = Math.random();
1700
+ this.y = Math.random();
1701
+ this.z = Math.random();
1702
+ return this;
1703
+ }
1704
+ randomDirection() {
1705
+ const u = (Math.random() - 0.5) * 2;
1706
+ const t = Math.random() * Math.PI * 2;
1707
+ const f = Math.sqrt(1 - u ** 2);
1708
+ this.x = f * Math.cos(t);
1709
+ this.y = f * Math.sin(t);
1710
+ this.z = u;
1711
+ return this;
1712
+ }
1713
+ *[Symbol.iterator]() {
1714
+ yield this.x;
1715
+ yield this.y;
1716
+ yield this.z;
1717
+ }
1718
+ }
1719
+ const _vector = /* @__PURE__ */ new Vector3();
1720
+ const _quaternion$1 = /* @__PURE__ */ new Quaternion();
1721
+ class Matrix4 {
1722
+ constructor(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
1723
+ Matrix4.prototype.isMatrix4 = true;
1724
+ this.elements = [
1725
+ 1,
1726
+ 0,
1727
+ 0,
1728
+ 0,
1729
+ 0,
1730
+ 1,
1731
+ 0,
1732
+ 0,
1733
+ 0,
1734
+ 0,
1735
+ 1,
1736
+ 0,
1737
+ 0,
1738
+ 0,
1739
+ 0,
1740
+ 1
1741
+ ];
1742
+ if (n11 !== void 0) {
1743
+ this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44);
1744
+ }
1745
+ }
1746
+ set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
1747
+ const te = this.elements;
1748
+ te[0] = n11;
1749
+ te[4] = n12;
1750
+ te[8] = n13;
1751
+ te[12] = n14;
1752
+ te[1] = n21;
1753
+ te[5] = n22;
1754
+ te[9] = n23;
1755
+ te[13] = n24;
1756
+ te[2] = n31;
1757
+ te[6] = n32;
1758
+ te[10] = n33;
1759
+ te[14] = n34;
1760
+ te[3] = n41;
1761
+ te[7] = n42;
1762
+ te[11] = n43;
1763
+ te[15] = n44;
1764
+ return this;
1765
+ }
1766
+ identity() {
1767
+ this.set(
1768
+ 1,
1769
+ 0,
1770
+ 0,
1771
+ 0,
1772
+ 0,
1773
+ 1,
1774
+ 0,
1775
+ 0,
1776
+ 0,
1777
+ 0,
1778
+ 1,
1779
+ 0,
1780
+ 0,
1781
+ 0,
1782
+ 0,
1783
+ 1
1784
+ );
1785
+ return this;
1786
+ }
1787
+ clone() {
1788
+ return new Matrix4().fromArray(this.elements);
1789
+ }
1790
+ copy(m) {
1791
+ const te = this.elements;
1792
+ const me = m.elements;
1793
+ te[0] = me[0];
1794
+ te[1] = me[1];
1795
+ te[2] = me[2];
1796
+ te[3] = me[3];
1797
+ te[4] = me[4];
1798
+ te[5] = me[5];
1799
+ te[6] = me[6];
1800
+ te[7] = me[7];
1801
+ te[8] = me[8];
1802
+ te[9] = me[9];
1803
+ te[10] = me[10];
1804
+ te[11] = me[11];
1805
+ te[12] = me[12];
1806
+ te[13] = me[13];
1807
+ te[14] = me[14];
1808
+ te[15] = me[15];
1809
+ return this;
1810
+ }
1811
+ copyPosition(m) {
1812
+ const te = this.elements, me = m.elements;
1813
+ te[12] = me[12];
1814
+ te[13] = me[13];
1815
+ te[14] = me[14];
1816
+ return this;
1817
+ }
1818
+ setFromMatrix3(m) {
1819
+ const me = m.elements;
1820
+ this.set(
1821
+ me[0],
1822
+ me[3],
1823
+ me[6],
1824
+ 0,
1825
+ me[1],
1826
+ me[4],
1827
+ me[7],
1828
+ 0,
1829
+ me[2],
1830
+ me[5],
1831
+ me[8],
1832
+ 0,
1833
+ 0,
1834
+ 0,
1835
+ 0,
1836
+ 1
1837
+ );
1838
+ return this;
1839
+ }
1840
+ extractBasis(xAxis, yAxis, zAxis) {
1841
+ xAxis.setFromMatrixColumn(this, 0);
1842
+ yAxis.setFromMatrixColumn(this, 1);
1843
+ zAxis.setFromMatrixColumn(this, 2);
1844
+ return this;
1845
+ }
1846
+ makeBasis(xAxis, yAxis, zAxis) {
1847
+ this.set(
1848
+ xAxis.x,
1849
+ yAxis.x,
1850
+ zAxis.x,
1851
+ 0,
1852
+ xAxis.y,
1853
+ yAxis.y,
1854
+ zAxis.y,
1855
+ 0,
1856
+ xAxis.z,
1857
+ yAxis.z,
1858
+ zAxis.z,
1859
+ 0,
1860
+ 0,
1861
+ 0,
1862
+ 0,
1863
+ 1
1864
+ );
1865
+ return this;
1866
+ }
1867
+ extractRotation(m) {
1868
+ const te = this.elements;
1869
+ const me = m.elements;
1870
+ const scaleX = 1 / _v1.setFromMatrixColumn(m, 0).length();
1871
+ const scaleY = 1 / _v1.setFromMatrixColumn(m, 1).length();
1872
+ const scaleZ = 1 / _v1.setFromMatrixColumn(m, 2).length();
1873
+ te[0] = me[0] * scaleX;
1874
+ te[1] = me[1] * scaleX;
1875
+ te[2] = me[2] * scaleX;
1876
+ te[3] = 0;
1877
+ te[4] = me[4] * scaleY;
1878
+ te[5] = me[5] * scaleY;
1879
+ te[6] = me[6] * scaleY;
1880
+ te[7] = 0;
1881
+ te[8] = me[8] * scaleZ;
1882
+ te[9] = me[9] * scaleZ;
1883
+ te[10] = me[10] * scaleZ;
1884
+ te[11] = 0;
1885
+ te[12] = 0;
1886
+ te[13] = 0;
1887
+ te[14] = 0;
1888
+ te[15] = 1;
1889
+ return this;
1890
+ }
1891
+ makeRotationFromEuler(euler) {
1892
+ const te = this.elements;
1893
+ const x = euler.x, y = euler.y, z = euler.z;
1894
+ const a = Math.cos(x), b = Math.sin(x);
1895
+ const c = Math.cos(y), d = Math.sin(y);
1896
+ const e = Math.cos(z), f = Math.sin(z);
1897
+ if (euler.order === "XYZ") {
1898
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
1899
+ te[0] = c * e;
1900
+ te[4] = -c * f;
1901
+ te[8] = d;
1902
+ te[1] = af + be * d;
1903
+ te[5] = ae - bf * d;
1904
+ te[9] = -b * c;
1905
+ te[2] = bf - ae * d;
1906
+ te[6] = be + af * d;
1907
+ te[10] = a * c;
1908
+ } else if (euler.order === "YXZ") {
1909
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
1910
+ te[0] = ce + df * b;
1911
+ te[4] = de * b - cf;
1912
+ te[8] = a * d;
1913
+ te[1] = a * f;
1914
+ te[5] = a * e;
1915
+ te[9] = -b;
1916
+ te[2] = cf * b - de;
1917
+ te[6] = df + ce * b;
1918
+ te[10] = a * c;
1919
+ } else if (euler.order === "ZXY") {
1920
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
1921
+ te[0] = ce - df * b;
1922
+ te[4] = -a * f;
1923
+ te[8] = de + cf * b;
1924
+ te[1] = cf + de * b;
1925
+ te[5] = a * e;
1926
+ te[9] = df - ce * b;
1927
+ te[2] = -a * d;
1928
+ te[6] = b;
1929
+ te[10] = a * c;
1930
+ } else if (euler.order === "ZYX") {
1931
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
1932
+ te[0] = c * e;
1933
+ te[4] = be * d - af;
1934
+ te[8] = ae * d + bf;
1935
+ te[1] = c * f;
1936
+ te[5] = bf * d + ae;
1937
+ te[9] = af * d - be;
1938
+ te[2] = -d;
1939
+ te[6] = b * c;
1940
+ te[10] = a * c;
1941
+ } else if (euler.order === "YZX") {
1942
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
1943
+ te[0] = c * e;
1944
+ te[4] = bd - ac * f;
1945
+ te[8] = bc * f + ad;
1946
+ te[1] = f;
1947
+ te[5] = a * e;
1948
+ te[9] = -b * e;
1949
+ te[2] = -d * e;
1950
+ te[6] = ad * f + bc;
1951
+ te[10] = ac - bd * f;
1952
+ } else if (euler.order === "XZY") {
1953
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
1954
+ te[0] = c * e;
1955
+ te[4] = -f;
1956
+ te[8] = d * e;
1957
+ te[1] = ac * f + bd;
1958
+ te[5] = a * e;
1959
+ te[9] = ad * f - bc;
1960
+ te[2] = bc * f - ad;
1961
+ te[6] = b * e;
1962
+ te[10] = bd * f + ac;
1963
+ }
1964
+ te[3] = 0;
1965
+ te[7] = 0;
1966
+ te[11] = 0;
1967
+ te[12] = 0;
1968
+ te[13] = 0;
1969
+ te[14] = 0;
1970
+ te[15] = 1;
1971
+ return this;
1972
+ }
1973
+ makeRotationFromQuaternion(q) {
1974
+ return this.compose(_zero, q, _one);
1975
+ }
1976
+ lookAt(eye, target, up) {
1977
+ const te = this.elements;
1978
+ _z.subVectors(eye, target);
1979
+ if (_z.lengthSq() === 0) {
1980
+ _z.z = 1;
1981
+ }
1982
+ _z.normalize();
1983
+ _x.crossVectors(up, _z);
1984
+ if (_x.lengthSq() === 0) {
1985
+ if (Math.abs(up.z) === 1) {
1986
+ _z.x += 1e-4;
1987
+ } else {
1988
+ _z.z += 1e-4;
1989
+ }
1990
+ _z.normalize();
1991
+ _x.crossVectors(up, _z);
1992
+ }
1993
+ _x.normalize();
1994
+ _y.crossVectors(_z, _x);
1995
+ te[0] = _x.x;
1996
+ te[4] = _y.x;
1997
+ te[8] = _z.x;
1998
+ te[1] = _x.y;
1999
+ te[5] = _y.y;
2000
+ te[9] = _z.y;
2001
+ te[2] = _x.z;
2002
+ te[6] = _y.z;
2003
+ te[10] = _z.z;
2004
+ return this;
2005
+ }
2006
+ multiply(m) {
2007
+ return this.multiplyMatrices(this, m);
2008
+ }
2009
+ premultiply(m) {
2010
+ return this.multiplyMatrices(m, this);
2011
+ }
2012
+ multiplyMatrices(a, b) {
2013
+ const ae = a.elements;
2014
+ const be = b.elements;
2015
+ const te = this.elements;
2016
+ const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
2017
+ const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
2018
+ const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
2019
+ const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
2020
+ const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
2021
+ const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
2022
+ const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
2023
+ const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
2024
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
2025
+ te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
2026
+ te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
2027
+ te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
2028
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
2029
+ te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
2030
+ te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
2031
+ te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
2032
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
2033
+ te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
2034
+ te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
2035
+ te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
2036
+ te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
2037
+ te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
2038
+ te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
2039
+ te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
2040
+ return this;
2041
+ }
2042
+ multiplyScalar(s) {
2043
+ const te = this.elements;
2044
+ te[0] *= s;
2045
+ te[4] *= s;
2046
+ te[8] *= s;
2047
+ te[12] *= s;
2048
+ te[1] *= s;
2049
+ te[5] *= s;
2050
+ te[9] *= s;
2051
+ te[13] *= s;
2052
+ te[2] *= s;
2053
+ te[6] *= s;
2054
+ te[10] *= s;
2055
+ te[14] *= s;
2056
+ te[3] *= s;
2057
+ te[7] *= s;
2058
+ te[11] *= s;
2059
+ te[15] *= s;
2060
+ return this;
2061
+ }
2062
+ determinant() {
2063
+ const te = this.elements;
2064
+ const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
2065
+ const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
2066
+ const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
2067
+ const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
2068
+ return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
2069
+ }
2070
+ transpose() {
2071
+ const te = this.elements;
2072
+ let tmp;
2073
+ tmp = te[1];
2074
+ te[1] = te[4];
2075
+ te[4] = tmp;
2076
+ tmp = te[2];
2077
+ te[2] = te[8];
2078
+ te[8] = tmp;
2079
+ tmp = te[6];
2080
+ te[6] = te[9];
2081
+ te[9] = tmp;
2082
+ tmp = te[3];
2083
+ te[3] = te[12];
2084
+ te[12] = tmp;
2085
+ tmp = te[7];
2086
+ te[7] = te[13];
2087
+ te[13] = tmp;
2088
+ tmp = te[11];
2089
+ te[11] = te[14];
2090
+ te[14] = tmp;
2091
+ return this;
2092
+ }
2093
+ setPosition(x, y, z) {
2094
+ const te = this.elements;
2095
+ if (x.isVector3) {
2096
+ te[12] = x.x;
2097
+ te[13] = x.y;
2098
+ te[14] = x.z;
2099
+ } else {
2100
+ te[12] = x;
2101
+ te[13] = y;
2102
+ te[14] = z;
2103
+ }
2104
+ return this;
2105
+ }
2106
+ invert() {
2107
+ const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3], n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7], n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11], n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15], t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
2108
+ const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
2109
+ if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2110
+ const detInv = 1 / det;
2111
+ te[0] = t11 * detInv;
2112
+ te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
2113
+ te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
2114
+ te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
2115
+ te[4] = t12 * detInv;
2116
+ te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
2117
+ te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
2118
+ te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
2119
+ te[8] = t13 * detInv;
2120
+ te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
2121
+ te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
2122
+ te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
2123
+ te[12] = t14 * detInv;
2124
+ te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
2125
+ te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
2126
+ te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
2127
+ return this;
2128
+ }
2129
+ scale(v) {
2130
+ const te = this.elements;
2131
+ const x = v.x, y = v.y, z = v.z;
2132
+ te[0] *= x;
2133
+ te[4] *= y;
2134
+ te[8] *= z;
2135
+ te[1] *= x;
2136
+ te[5] *= y;
2137
+ te[9] *= z;
2138
+ te[2] *= x;
2139
+ te[6] *= y;
2140
+ te[10] *= z;
2141
+ te[3] *= x;
2142
+ te[7] *= y;
2143
+ te[11] *= z;
2144
+ return this;
2145
+ }
2146
+ getMaxScaleOnAxis() {
2147
+ const te = this.elements;
2148
+ const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
2149
+ const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
2150
+ const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
2151
+ return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
2152
+ }
2153
+ makeTranslation(x, y, z) {
2154
+ if (x.isVector3) {
2155
+ this.set(
2156
+ 1,
2157
+ 0,
2158
+ 0,
2159
+ x.x,
2160
+ 0,
2161
+ 1,
2162
+ 0,
2163
+ x.y,
2164
+ 0,
2165
+ 0,
2166
+ 1,
2167
+ x.z,
2168
+ 0,
2169
+ 0,
2170
+ 0,
2171
+ 1
2172
+ );
2173
+ } else {
2174
+ this.set(
2175
+ 1,
2176
+ 0,
2177
+ 0,
2178
+ x,
2179
+ 0,
2180
+ 1,
2181
+ 0,
2182
+ y,
2183
+ 0,
2184
+ 0,
2185
+ 1,
2186
+ z,
2187
+ 0,
2188
+ 0,
2189
+ 0,
2190
+ 1
2191
+ );
2192
+ }
2193
+ return this;
2194
+ }
2195
+ makeRotationX(theta) {
2196
+ const c = Math.cos(theta), s = Math.sin(theta);
2197
+ this.set(
2198
+ 1,
2199
+ 0,
2200
+ 0,
2201
+ 0,
2202
+ 0,
2203
+ c,
2204
+ -s,
2205
+ 0,
2206
+ 0,
2207
+ s,
2208
+ c,
2209
+ 0,
2210
+ 0,
2211
+ 0,
2212
+ 0,
2213
+ 1
2214
+ );
2215
+ return this;
2216
+ }
2217
+ makeRotationY(theta) {
2218
+ const c = Math.cos(theta), s = Math.sin(theta);
2219
+ this.set(
2220
+ c,
2221
+ 0,
2222
+ s,
2223
+ 0,
2224
+ 0,
2225
+ 1,
2226
+ 0,
2227
+ 0,
2228
+ -s,
2229
+ 0,
2230
+ c,
2231
+ 0,
2232
+ 0,
2233
+ 0,
2234
+ 0,
2235
+ 1
2236
+ );
2237
+ return this;
2238
+ }
2239
+ makeRotationZ(theta) {
2240
+ const c = Math.cos(theta), s = Math.sin(theta);
2241
+ this.set(
2242
+ c,
2243
+ -s,
2244
+ 0,
2245
+ 0,
2246
+ s,
2247
+ c,
2248
+ 0,
2249
+ 0,
2250
+ 0,
2251
+ 0,
2252
+ 1,
2253
+ 0,
2254
+ 0,
2255
+ 0,
2256
+ 0,
2257
+ 1
2258
+ );
2259
+ return this;
2260
+ }
2261
+ makeRotationAxis(axis, angle) {
2262
+ const c = Math.cos(angle);
2263
+ const s = Math.sin(angle);
2264
+ const t = 1 - c;
2265
+ const x = axis.x, y = axis.y, z = axis.z;
2266
+ const tx = t * x, ty = t * y;
2267
+ this.set(
2268
+ tx * x + c,
2269
+ tx * y - s * z,
2270
+ tx * z + s * y,
2271
+ 0,
2272
+ tx * y + s * z,
2273
+ ty * y + c,
2274
+ ty * z - s * x,
2275
+ 0,
2276
+ tx * z - s * y,
2277
+ ty * z + s * x,
2278
+ t * z * z + c,
2279
+ 0,
2280
+ 0,
2281
+ 0,
2282
+ 0,
2283
+ 1
2284
+ );
2285
+ return this;
2286
+ }
2287
+ makeScale(x, y, z) {
2288
+ this.set(
2289
+ x,
2290
+ 0,
2291
+ 0,
2292
+ 0,
2293
+ 0,
2294
+ y,
2295
+ 0,
2296
+ 0,
2297
+ 0,
2298
+ 0,
2299
+ z,
2300
+ 0,
2301
+ 0,
2302
+ 0,
2303
+ 0,
2304
+ 1
2305
+ );
2306
+ return this;
2307
+ }
2308
+ makeShear(xy, xz, yx, yz, zx, zy) {
2309
+ this.set(
2310
+ 1,
2311
+ yx,
2312
+ zx,
2313
+ 0,
2314
+ xy,
2315
+ 1,
2316
+ zy,
2317
+ 0,
2318
+ xz,
2319
+ yz,
2320
+ 1,
2321
+ 0,
2322
+ 0,
2323
+ 0,
2324
+ 0,
2325
+ 1
2326
+ );
2327
+ return this;
2328
+ }
2329
+ compose(position, quaternion, scale) {
2330
+ const te = this.elements;
2331
+ const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
2332
+ const x2 = x + x, y2 = y + y, z2 = z + z;
2333
+ const xx = x * x2, xy = x * y2, xz = x * z2;
2334
+ const yy = y * y2, yz = y * z2, zz = z * z2;
2335
+ const wx = w * x2, wy = w * y2, wz = w * z2;
2336
+ const sx = scale.x, sy = scale.y, sz = scale.z;
2337
+ te[0] = (1 - (yy + zz)) * sx;
2338
+ te[1] = (xy + wz) * sx;
2339
+ te[2] = (xz - wy) * sx;
2340
+ te[3] = 0;
2341
+ te[4] = (xy - wz) * sy;
2342
+ te[5] = (1 - (xx + zz)) * sy;
2343
+ te[6] = (yz + wx) * sy;
2344
+ te[7] = 0;
2345
+ te[8] = (xz + wy) * sz;
2346
+ te[9] = (yz - wx) * sz;
2347
+ te[10] = (1 - (xx + yy)) * sz;
2348
+ te[11] = 0;
2349
+ te[12] = position.x;
2350
+ te[13] = position.y;
2351
+ te[14] = position.z;
2352
+ te[15] = 1;
2353
+ return this;
2354
+ }
2355
+ decompose(position, quaternion, scale) {
2356
+ const te = this.elements;
2357
+ let sx = _v1.set(te[0], te[1], te[2]).length();
2358
+ const sy = _v1.set(te[4], te[5], te[6]).length();
2359
+ const sz = _v1.set(te[8], te[9], te[10]).length();
2360
+ const det = this.determinant();
2361
+ if (det < 0) sx = -sx;
2362
+ position.x = te[12];
2363
+ position.y = te[13];
2364
+ position.z = te[14];
2365
+ _m1.copy(this);
2366
+ const invSX = 1 / sx;
2367
+ const invSY = 1 / sy;
2368
+ const invSZ = 1 / sz;
2369
+ _m1.elements[0] *= invSX;
2370
+ _m1.elements[1] *= invSX;
2371
+ _m1.elements[2] *= invSX;
2372
+ _m1.elements[4] *= invSY;
2373
+ _m1.elements[5] *= invSY;
2374
+ _m1.elements[6] *= invSY;
2375
+ _m1.elements[8] *= invSZ;
2376
+ _m1.elements[9] *= invSZ;
2377
+ _m1.elements[10] *= invSZ;
2378
+ quaternion.setFromRotationMatrix(_m1);
2379
+ scale.x = sx;
2380
+ scale.y = sy;
2381
+ scale.z = sz;
2382
+ return this;
2383
+ }
2384
+ makePerspective(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
2385
+ const te = this.elements;
2386
+ const x = 2 * near / (right - left);
2387
+ const y = 2 * near / (top - bottom);
2388
+ const a = (right + left) / (right - left);
2389
+ const b = (top + bottom) / (top - bottom);
2390
+ let c, d;
2391
+ if (coordinateSystem === WebGLCoordinateSystem) {
2392
+ c = -(far + near) / (far - near);
2393
+ d = -2 * far * near / (far - near);
2394
+ } else if (coordinateSystem === WebGPUCoordinateSystem) {
2395
+ c = -far / (far - near);
2396
+ d = -far * near / (far - near);
2397
+ } else {
2398
+ throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + coordinateSystem);
2399
+ }
2400
+ te[0] = x;
2401
+ te[4] = 0;
2402
+ te[8] = a;
2403
+ te[12] = 0;
2404
+ te[1] = 0;
2405
+ te[5] = y;
2406
+ te[9] = b;
2407
+ te[13] = 0;
2408
+ te[2] = 0;
2409
+ te[6] = 0;
2410
+ te[10] = c;
2411
+ te[14] = d;
2412
+ te[3] = 0;
2413
+ te[7] = 0;
2414
+ te[11] = -1;
2415
+ te[15] = 0;
2416
+ return this;
2417
+ }
2418
+ makeOrthographic(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
2419
+ const te = this.elements;
2420
+ const w = 1 / (right - left);
2421
+ const h = 1 / (top - bottom);
2422
+ const p = 1 / (far - near);
2423
+ const x = (right + left) * w;
2424
+ const y = (top + bottom) * h;
2425
+ let z, zInv;
2426
+ if (coordinateSystem === WebGLCoordinateSystem) {
2427
+ z = (far + near) * p;
2428
+ zInv = -2 * p;
2429
+ } else if (coordinateSystem === WebGPUCoordinateSystem) {
2430
+ z = near * p;
2431
+ zInv = -1 * p;
2432
+ } else {
2433
+ throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + coordinateSystem);
2434
+ }
2435
+ te[0] = 2 * w;
2436
+ te[4] = 0;
2437
+ te[8] = 0;
2438
+ te[12] = -x;
2439
+ te[1] = 0;
2440
+ te[5] = 2 * h;
2441
+ te[9] = 0;
2442
+ te[13] = -y;
2443
+ te[2] = 0;
2444
+ te[6] = 0;
2445
+ te[10] = zInv;
2446
+ te[14] = -z;
2447
+ te[3] = 0;
2448
+ te[7] = 0;
2449
+ te[11] = 0;
2450
+ te[15] = 1;
2451
+ return this;
2452
+ }
2453
+ equals(matrix) {
2454
+ const te = this.elements;
2455
+ const me = matrix.elements;
2456
+ for (let i = 0; i < 16; i++) {
2457
+ if (te[i] !== me[i]) return false;
2458
+ }
2459
+ return true;
2460
+ }
2461
+ fromArray(array, offset = 0) {
2462
+ for (let i = 0; i < 16; i++) {
2463
+ this.elements[i] = array[i + offset];
2464
+ }
2465
+ return this;
2466
+ }
2467
+ toArray(array = [], offset = 0) {
2468
+ const te = this.elements;
2469
+ array[offset] = te[0];
2470
+ array[offset + 1] = te[1];
2471
+ array[offset + 2] = te[2];
2472
+ array[offset + 3] = te[3];
2473
+ array[offset + 4] = te[4];
2474
+ array[offset + 5] = te[5];
2475
+ array[offset + 6] = te[6];
2476
+ array[offset + 7] = te[7];
2477
+ array[offset + 8] = te[8];
2478
+ array[offset + 9] = te[9];
2479
+ array[offset + 10] = te[10];
2480
+ array[offset + 11] = te[11];
2481
+ array[offset + 12] = te[12];
2482
+ array[offset + 13] = te[13];
2483
+ array[offset + 14] = te[14];
2484
+ array[offset + 15] = te[15];
2485
+ return array;
2486
+ }
2487
+ }
2488
+ const _v1 = /* @__PURE__ */ new Vector3();
2489
+ const _m1 = /* @__PURE__ */ new Matrix4();
2490
+ const _zero = /* @__PURE__ */ new Vector3(0, 0, 0);
2491
+ const _one = /* @__PURE__ */ new Vector3(1, 1, 1);
2492
+ const _x = /* @__PURE__ */ new Vector3();
2493
+ const _y = /* @__PURE__ */ new Vector3();
2494
+ const _z = /* @__PURE__ */ new Vector3();
2495
+ const _matrix = /* @__PURE__ */ new Matrix4();
2496
+ const _quaternion = /* @__PURE__ */ new Quaternion();
2497
+ class Euler {
2498
+ constructor(x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER) {
2499
+ this.isEuler = true;
2500
+ this._x = x;
2501
+ this._y = y;
2502
+ this._z = z;
2503
+ this._order = order;
2504
+ }
2505
+ get x() {
2506
+ return this._x;
2507
+ }
2508
+ set x(value) {
2509
+ this._x = value;
2510
+ this._onChangeCallback();
2511
+ }
2512
+ get y() {
2513
+ return this._y;
2514
+ }
2515
+ set y(value) {
2516
+ this._y = value;
2517
+ this._onChangeCallback();
2518
+ }
2519
+ get z() {
2520
+ return this._z;
2521
+ }
2522
+ set z(value) {
2523
+ this._z = value;
2524
+ this._onChangeCallback();
2525
+ }
2526
+ get order() {
2527
+ return this._order;
2528
+ }
2529
+ set order(value) {
2530
+ this._order = value;
2531
+ this._onChangeCallback();
2532
+ }
2533
+ set(x, y, z, order = this._order) {
2534
+ this._x = x;
2535
+ this._y = y;
2536
+ this._z = z;
2537
+ this._order = order;
2538
+ this._onChangeCallback();
2539
+ return this;
2540
+ }
2541
+ clone() {
2542
+ return new this.constructor(this._x, this._y, this._z, this._order);
2543
+ }
2544
+ copy(euler) {
2545
+ this._x = euler._x;
2546
+ this._y = euler._y;
2547
+ this._z = euler._z;
2548
+ this._order = euler._order;
2549
+ this._onChangeCallback();
2550
+ return this;
2551
+ }
2552
+ setFromRotationMatrix(m, order = this._order, update = true) {
2553
+ const te = m.elements;
2554
+ const m11 = te[0], m12 = te[4], m13 = te[8];
2555
+ const m21 = te[1], m22 = te[5], m23 = te[9];
2556
+ const m31 = te[2], m32 = te[6], m33 = te[10];
2557
+ switch (order) {
2558
+ case "XYZ":
2559
+ this._y = Math.asin(clamp(m13, -1, 1));
2560
+ if (Math.abs(m13) < 0.9999999) {
2561
+ this._x = Math.atan2(-m23, m33);
2562
+ this._z = Math.atan2(-m12, m11);
2563
+ } else {
2564
+ this._x = Math.atan2(m32, m22);
2565
+ this._z = 0;
2566
+ }
2567
+ break;
2568
+ case "YXZ":
2569
+ this._x = Math.asin(-clamp(m23, -1, 1));
2570
+ if (Math.abs(m23) < 0.9999999) {
2571
+ this._y = Math.atan2(m13, m33);
2572
+ this._z = Math.atan2(m21, m22);
2573
+ } else {
2574
+ this._y = Math.atan2(-m31, m11);
2575
+ this._z = 0;
2576
+ }
2577
+ break;
2578
+ case "ZXY":
2579
+ this._x = Math.asin(clamp(m32, -1, 1));
2580
+ if (Math.abs(m32) < 0.9999999) {
2581
+ this._y = Math.atan2(-m31, m33);
2582
+ this._z = Math.atan2(-m12, m22);
2583
+ } else {
2584
+ this._y = 0;
2585
+ this._z = Math.atan2(m21, m11);
2586
+ }
2587
+ break;
2588
+ case "ZYX":
2589
+ this._y = Math.asin(-clamp(m31, -1, 1));
2590
+ if (Math.abs(m31) < 0.9999999) {
2591
+ this._x = Math.atan2(m32, m33);
2592
+ this._z = Math.atan2(m21, m11);
2593
+ } else {
2594
+ this._x = 0;
2595
+ this._z = Math.atan2(-m12, m22);
2596
+ }
2597
+ break;
2598
+ case "YZX":
2599
+ this._z = Math.asin(clamp(m21, -1, 1));
2600
+ if (Math.abs(m21) < 0.9999999) {
2601
+ this._x = Math.atan2(-m23, m22);
2602
+ this._y = Math.atan2(-m31, m11);
2603
+ } else {
2604
+ this._x = 0;
2605
+ this._y = Math.atan2(m13, m33);
2606
+ }
2607
+ break;
2608
+ case "XZY":
2609
+ this._z = Math.asin(-clamp(m12, -1, 1));
2610
+ if (Math.abs(m12) < 0.9999999) {
2611
+ this._x = Math.atan2(m32, m22);
2612
+ this._y = Math.atan2(m13, m11);
2613
+ } else {
2614
+ this._x = Math.atan2(-m23, m33);
2615
+ this._y = 0;
2616
+ }
2617
+ break;
2618
+ default:
2619
+ console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + order);
2620
+ }
2621
+ this._order = order;
2622
+ if (update === true) this._onChangeCallback();
2623
+ return this;
2624
+ }
2625
+ setFromQuaternion(q, order, update) {
2626
+ _matrix.makeRotationFromQuaternion(q);
2627
+ return this.setFromRotationMatrix(_matrix, order, update);
2628
+ }
2629
+ setFromVector3(v, order = this._order) {
2630
+ return this.set(v.x, v.y, v.z, order);
2631
+ }
2632
+ reorder(newOrder) {
2633
+ _quaternion.setFromEuler(this);
2634
+ return this.setFromQuaternion(_quaternion, newOrder);
2635
+ }
2636
+ equals(euler) {
2637
+ return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
2638
+ }
2639
+ fromArray(array) {
2640
+ this._x = array[0];
2641
+ this._y = array[1];
2642
+ this._z = array[2];
2643
+ if (array[3] !== void 0) this._order = array[3];
2644
+ this._onChangeCallback();
2645
+ return this;
2646
+ }
2647
+ toArray(array = [], offset = 0) {
2648
+ array[offset] = this._x;
2649
+ array[offset + 1] = this._y;
2650
+ array[offset + 2] = this._z;
2651
+ array[offset + 3] = this._order;
2652
+ return array;
2653
+ }
2654
+ _onChange(callback) {
2655
+ this._onChangeCallback = callback;
2656
+ return this;
2657
+ }
2658
+ _onChangeCallback() {
2659
+ }
2660
+ *[Symbol.iterator]() {
2661
+ yield this._x;
2662
+ yield this._y;
2663
+ yield this._z;
2664
+ yield this._order;
2665
+ }
2666
+ }
2667
+ Euler.DEFAULT_ORDER = "XYZ";
905
2668
  const blenderObjectTypes = {
906
2669
  empty: 0,
907
2670
  mesh: 1,
@@ -938,7 +2701,7 @@
938
2701
  console.warn("Unsupported object type", object.type, object, obj);
939
2702
  }
940
2703
  if (obj) {
941
- setCreateTransform(object, obj);
2704
+ setTransform(object, obj);
942
2705
  const exChildren = childMap.get(object);
943
2706
  if (exChildren) {
944
2707
  for (const exChild of exChildren) {
@@ -948,7 +2711,7 @@
948
2711
  }
949
2712
  objMap.set(object, obj);
950
2713
  if (object.parent === object) {
951
- console.error("invalid, parent same as object, adding to root", object);
2714
+ console.error("BlendLoader - invalid, parent same as object, adding to root", object);
952
2715
  objects.push(obj);
953
2716
  } else if (!object.parent) {
954
2717
  objects.push(obj);
@@ -967,11 +2730,35 @@
967
2730
  }
968
2731
  if (childMap.size) {
969
2732
  const vals = [...childMap.values()].flat();
970
- console.warn("unknown objects with parents, adding to root", vals, childMap);
2733
+ console.warn("BlendLoader - unknown objects with parents, adding to root", vals, childMap);
971
2734
  objects.push(...vals);
972
2735
  }
973
2736
  return objects.filter((o) => !!o);
974
2737
  }
2738
+ const eulerModes = {
2739
+ [1]: "XYZ",
2740
+ [2]: "XZY",
2741
+ [3]: "YXZ",
2742
+ [4]: "YZX",
2743
+ [5]: "ZXY",
2744
+ [6]: "ZYX"
2745
+ };
2746
+ function setTransform(object, obj) {
2747
+ obj.name = object.aname;
2748
+ obj.scale.set(object.size[0], object.size[2], object.size[1]);
2749
+ obj.position.set(object.loc[0], object.loc[2], -object.loc[1]);
2750
+ if (!object.rotmode || object.rotmode === 0) {
2751
+ obj.quaternion.set(object.quat[1], object.quat[3], -object.quat[2], object.quat[0]);
2752
+ } else {
2753
+ const order = eulerModes[object.rotmode] ?? "XYZ";
2754
+ const quat = new three.Quaternion().setFromEuler(new Euler(object.rot[0], object.rot[1], object.rot[2], order.split("").reverse().join("")));
2755
+ obj.quaternion.set(quat.x, quat.z, -quat.y, quat.w);
2756
+ }
2757
+ if (object.type === blenderObjectTypes.camera)
2758
+ obj.quaternion.multiply(new three.Quaternion().setFromAxisAngle(new three.Vector3(1, 0, 0), -Math.PI / 2));
2759
+ obj.updateMatrix();
2760
+ if (obj.setDirty) obj.setDirty();
2761
+ }
975
2762
  const _BlendLoadPlugin = class _BlendLoadPlugin extends threepipe.BaseImporterPlugin {
976
2763
  constructor() {
977
2764
  super();