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