@threepipe/plugin-blend-importer 0.0.4 → 0.0.6

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.
Files changed (38) hide show
  1. package/dist/BlendLoadPlugin.d.ts +1 -1
  2. package/dist/BlendLoadPlugin.d.ts.map +1 -1
  3. package/dist/dependencies.txt +32 -1
  4. package/dist/index.js +2179 -82
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +2179 -81
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/loader/bakeGetters.d.ts +2 -0
  9. package/dist/loader/bakeGetters.d.ts.map +1 -0
  10. package/dist/loader/camera.d.ts +4 -0
  11. package/dist/loader/camera.d.ts.map +1 -0
  12. package/dist/loader/ctx.d.ts +16 -0
  13. package/dist/loader/ctx.d.ts.map +1 -0
  14. package/dist/loader/geometry.d.ts +3 -2
  15. package/dist/loader/geometry.d.ts.map +1 -1
  16. package/dist/loader/index.d.ts +2 -1
  17. package/dist/loader/index.d.ts.map +1 -1
  18. package/dist/loader/light.d.ts +3 -2
  19. package/dist/loader/light.d.ts.map +1 -1
  20. package/dist/loader/material.d.ts +2 -2
  21. package/dist/loader/material.d.ts.map +1 -1
  22. package/dist/loader/mesh.d.ts +2 -2
  23. package/dist/loader/mesh.d.ts.map +1 -1
  24. package/package.json +2 -2
  25. package/src/BlendLoadPlugin.ts +42 -3
  26. package/src/js-blend/main.js +3 -2
  27. package/src/js-blend/parser/parser.js +152 -24
  28. package/src/js-blend/threejs/blend_three.js +1 -1
  29. package/src/js-blend/threejs/light.js +1 -1
  30. package/src/js-blend/threejs/material.js +1 -1
  31. package/src/loader/bakeGetters.ts +63 -0
  32. package/src/loader/camera.ts +55 -0
  33. package/src/loader/ctx.ts +29 -0
  34. package/src/loader/geometry.ts +236 -13
  35. package/src/loader/index.ts +95 -6
  36. package/src/loader/light.ts +18 -13
  37. package/src/loader/material.ts +7 -5
  38. package/src/loader/mesh.ts +14 -13
package/dist/index.js CHANGED
@@ -1,16 +1,14 @@
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.4
6
+ * @threepipe/plugin-blend-importer v0.0.6
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.
10
10
  */
11
11
 
12
- const DNA1 = 826363460;
13
- const ENDB = 1111772741;
14
12
  let worker = null;
15
13
  const return_object = {
16
14
  loadBlendFromArrayBuffer: function(array_buffer) {
@@ -51,7 +49,7 @@
51
49
  self2.postMessage(FILE, ERROR);
52
50
  }
53
51
  }
54
- var BLENDER_FILE = function(AB2) {
52
+ const BLENDER_FILE = function(AB2) {
55
53
  this.AB = AB2;
56
54
  this.byte = new Uint8Array(AB2);
57
55
  this.dv = new DataView(AB2);
@@ -90,7 +88,9 @@
90
88
  else {
91
89
  this.__blender_file__.dv.setFloat64(this.__data_address__ + offset2, float, this.__blender_file__.template.endianess);
92
90
  }
93
- }
91
+ },
92
+ enumerable: true,
93
+ configurable: true
94
94
  };
95
95
  }
96
96
  function floatProp(offset2, Blender_Array_Length, length) {
@@ -103,7 +103,9 @@
103
103
  else {
104
104
  this.__blender_file__.dv.setFloat32(this.__data_address__ + offset2, float, this.__blender_file__.template.endianess);
105
105
  }
106
- }
106
+ },
107
+ enumerable: true,
108
+ configurable: true
107
109
  };
108
110
  }
109
111
  function intProp(offset2, Blender_Array_Length, length) {
@@ -116,7 +118,9 @@
116
118
  else {
117
119
  this.__blender_file__.dv.setInt32(this.__data_address__ + offset2, float, this.__blender_file__.template.endianess);
118
120
  }
119
- }
121
+ },
122
+ enumerable: true,
123
+ configurable: true
120
124
  };
121
125
  }
122
126
  function shortProp(offset2, Blender_Array_Length, length) {
@@ -129,9 +133,26 @@
129
133
  else {
130
134
  this.__blender_file__.dv.setInt16(this.__data_address__ + offset2, float, this.__blender_file__.template.endianess);
131
135
  }
132
- }
136
+ },
137
+ enumerable: true,
138
+ configurable: true
133
139
  };
134
140
  }
141
+ const uShortProp = (offset2, Blender_Array_Length, length) => {
142
+ return {
143
+ get: function() {
144
+ return Blender_Array_Length > 1 ? new Uint16Array(this.__blender_file__.AB, this.__data_address__ + offset2, length) : this.__blender_file__.dv.getUint16(this.__data_address__ + offset2, this.__blender_file__.template.endianess);
145
+ },
146
+ set: function(float) {
147
+ if (Blender_Array_Length > 1) ;
148
+ else {
149
+ this.__blender_file__.dv.setUint16(this.__data_address__ + offset2, float, this.__blender_file__.template.endianess);
150
+ }
151
+ },
152
+ enumerable: true,
153
+ configurable: true
154
+ };
155
+ };
135
156
  function charProp(offset2, Blender_Array_Length, length) {
136
157
  return {
137
158
  get: function() {
@@ -160,7 +181,9 @@
160
181
  } else {
161
182
  this.__blender_file__.byte[this.__data_address__ + offset2] = byte | 0;
162
183
  }
163
- }
184
+ },
185
+ enumerable: true,
186
+ configurable: true
164
187
  };
165
188
  }
166
189
  function pointerProp2(offset2) {
@@ -183,7 +206,9 @@
183
206
  return results;
184
207
  },
185
208
  set: function() {
186
- }
209
+ },
210
+ enumerable: true,
211
+ configurable: true
187
212
  };
188
213
  }
189
214
  function pointerProp(offset2, Blender_Array_Length, length) {
@@ -206,7 +231,9 @@
206
231
  }
207
232
  },
208
233
  set: function() {
209
- }
234
+ },
235
+ enumerable: true,
236
+ configurable: true
210
237
  };
211
238
  }
212
239
  function compileProp(obj, name, type, offset2, array_size, IS_POINTER, pointer_size2, length) {
@@ -222,9 +249,11 @@
222
249
  Object.defineProperty(obj, name, intProp(offset2, array_size, length >> 2));
223
250
  break;
224
251
  case "short":
225
- case "ushort":
226
252
  Object.defineProperty(obj, name, shortProp(offset2, array_size, length >> 1));
227
253
  break;
254
+ case "ushort":
255
+ Object.defineProperty(obj, name, uShortProp(offset2, array_size, length >> 1));
256
+ break;
228
257
  case "char":
229
258
  case "uchar":
230
259
  Object.defineProperty(obj, name, charProp(offset2, array_size, length));
@@ -237,6 +266,7 @@
237
266
  offset2 += length;
238
267
  } else {
239
268
  Object.defineProperty(obj, name, pointerProp(offset2, array_size, pointer_size2));
269
+ obj._length += pointer_size2 * array_size;
240
270
  offset2 += pointer_size2 * array_size;
241
271
  }
242
272
  return offset2;
@@ -253,19 +283,20 @@
253
283
  MASTER_SDNA_SCHEMA.prototype = {
254
284
  getSDNAStructureConstructor: function(name, struct) {
255
285
  if (struct) {
256
- const blen_struct = Function("function " + name + "(){}; return " + name)();
286
+ const jsName = name === "void" ? "void_" : name;
287
+ const blen_struct = Function("function " + jsName + "(){}; return " + jsName)();
257
288
  blen_struct.prototype = new BLENDER_STRUCTURE();
258
289
  blen_struct.prototype.blender_name = name;
259
290
  blen_struct.prototype.__pointers = [];
260
291
  blen_struct.prototype.__list__ = [];
292
+ const DNA = this.SDNA[name] = {
293
+ constructor: blen_struct
294
+ };
261
295
  let offset2 = 0;
262
296
  for (let i = 0; i < struct.length; i += 3) {
263
297
  let _name = struct[i];
264
298
  const n = _name, type = struct[i + 1];
265
299
  let length = struct[i + 2], array_length = 0, match = null, Blender_Array_Length = 1, Suparray_match = 1, PointerToArray = false, Pointer_Match = 0;
266
- const DNA = this.SDNA[name] = {
267
- constructor: blen_struct
268
- };
269
300
  if (match = _name.match(/(\*?)(\*?)(\w+)(\[(\w*)\])?(\[(\w*)\])?/)) {
270
301
  _name = match[3];
271
302
  if (match[1]) {
@@ -310,7 +341,9 @@
310
341
  }
311
342
  return array;
312
343
  };
313
- }(array_names)
344
+ }(array_names),
345
+ enumerable: true,
346
+ configurable: true
314
347
  });
315
348
  } else {
316
349
  offset2 = compileProp(blen_struct.prototype, _name, type, offset2, Blender_Array_Length, Pointer_Match, pointer_size, length);
@@ -325,7 +358,7 @@
325
358
  }
326
359
  }
327
360
  };
328
- var BLENDER_STRUCTURE = function() {
361
+ const BLENDER_STRUCTURE = function() {
329
362
  this.__blender_file__ = null;
330
363
  this.__list__ = null;
331
364
  this.__super_array_list__ = null;
@@ -393,7 +426,8 @@
393
426
  FILE.memory_lookup = {};
394
427
  struct_names = [];
395
428
  offset = 0;
396
- if (toString(_data, offset, 7) !== "BLENDER") return ERROR = "File supplied is not a .blend compatible Blender file.";
429
+ const magic = toString(_data, offset, 7);
430
+ if (magic !== "BLENDER") return ERROR = "File supplied is not a .blend compatible Blender file.";
397
431
  offset += 7;
398
432
  pointer_size = toString(_data, offset++, offset) == "_" ? 4 : 8;
399
433
  BIG_ENDIAN = toString(_data, offset++, offset) !== "V";
@@ -430,9 +464,17 @@
430
464
  offset2++;
431
465
  curr_count++;
432
466
  }
433
- if (offset2 % 4 > 0) offset2 = 4 - offset2 % 4 + offset2;
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
+ }
472
+ }
473
+ if (toString(_data, offset2, offset2 + 4) !== "TYPE") {
474
+ debugger;
475
+ }
434
476
  offset2 += 4;
435
- count = data.getInt32(offset2, true);
477
+ count = data.getUint32(offset2, true);
436
478
  offset2 += 4;
437
479
  curr_count = 0;
438
480
  while (curr_count < count) {
@@ -445,7 +487,15 @@
445
487
  offset2++;
446
488
  curr_count++;
447
489
  }
448
- if (offset2 % 4 > 0) offset2 = 4 - offset2 % 4 + offset2;
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
+ }
495
+ }
496
+ if (toString(_data, offset2, offset2 + 4) !== "TLEN") {
497
+ debugger;
498
+ }
449
499
  offset2 += 4;
450
500
  curr_count = 0;
451
501
  while (curr_count < count) {
@@ -453,7 +503,15 @@
453
503
  offset2 += 2;
454
504
  curr_count++;
455
505
  }
456
- if (offset2 % 4 > 0) offset2 = 4 - offset2 % 4 + offset2;
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
+ }
511
+ }
512
+ if (toString(_data, offset2, offset2 + 4) !== "STRC") {
513
+ debugger;
514
+ }
457
515
  offset2 += 4;
458
516
  const structure_count = data.getInt32(offset2, BIG_ENDIAN);
459
517
  offset2 += 4;
@@ -482,22 +540,56 @@
482
540
  }
483
541
  }
484
542
  while (true) {
485
- if (offset % 4 > 0) {
486
- offset = 4 - offset % 4 + offset;
543
+ for (let j = 0; j < 8; j++) {
544
+ if (data.getInt8(offset) === 0) {
545
+ offset++;
546
+ continue;
547
+ }
548
+ break;
549
+ }
550
+ if (data.getInt8(offset) === 0) {
551
+ debugger;
487
552
  }
488
553
  data_offset = offset;
554
+ if (offset + pointer_size + 12 >= data.byteLength) {
555
+ ERROR = "Unexpected end of file while parsing";
556
+ break;
557
+ }
489
558
  sdna_index = data.getInt32(offset + pointer_size + 8, BIG_ENDIAN);
490
- let code_uint = data.getUint32(offset, BIG_ENDIAN);
559
+ const code_str = toString(_data, offset, offset + 4);
491
560
  offset2 = offset + 16 + pointer_size;
492
- offset += data.getInt32(offset + 4, true) + 16 + pointer_size;
493
- if (code_uint === DNA1) ;
494
- else if (code_uint === ENDB) break;
495
- else {
561
+ const blockLength = data.getInt32(offset + 4, true);
562
+ if (blockLength < 0 || offset + blockLength + 16 + pointer_size > data.byteLength) {
563
+ ERROR = "Invalid block length detected";
564
+ break;
565
+ }
566
+ offset += blockLength + 16 + pointer_size;
567
+ if (code_str === "DNA1") ;
568
+ else if (code_str === "ENDB") break;
569
+ else if (code_str === "TEST") {
570
+ const data_start = data_offset + pointer_size + 16;
571
+ const width = data.getInt32(data_start, BIG_ENDIAN);
572
+ const height = data.getInt32(data_start + 4, BIG_ENDIAN);
573
+ if (width * height > 0) {
574
+ const data_len = width * height * 4;
575
+ if (blockLength < data_len + 8) {
576
+ ERROR = "Invalid TEST block length detected";
577
+ break;
578
+ }
579
+ const image_data = new Uint32Array(_data, data_start + 8, data_len >> 2);
580
+ const image = {
581
+ width,
582
+ height,
583
+ data: image_data
584
+ };
585
+ FILE.thumbnail = image;
586
+ }
587
+ } else {
496
588
  const data_start = data_offset + pointer_size + 16;
497
589
  const constructor = current_SDNA_template.getSDNAStructureConstructor(current_SDNA_template.SDNA_NAMES[sdna_index]);
498
590
  const size = data.getInt32(data_offset + 4, BIG_ENDIAN);
499
591
  count = data.getInt32(data_offset + 12 + pointer_size, BIG_ENDIAN);
500
- if (count > 0) {
592
+ if (count > 0 && constructor) {
501
593
  let obj = new constructor();
502
594
  const length = constructor.prototype._length;
503
595
  const address = FILE.getPointer(data_offset + 8);
@@ -521,8 +613,8 @@
521
613
  }
522
614
  }
523
615
  worker = new worker_code();
524
- worker.postMessage = function(message) {
525
- return_object.onParseReady(message);
616
+ worker.postMessage = function(message, err) {
617
+ return_object.onParseReady(message, err);
526
618
  };
527
619
  /**
528
620
  * JS.Blend
@@ -536,49 +628,200 @@
536
628
  async function parseBlend(buffer, name = "") {
537
629
  return new Promise((res, rej) => {
538
630
  return_object.onParseReady = (file, error) => {
539
- if (error) rej(error);
540
- else res(file);
631
+ if (error) console.error(error);
632
+ res(file);
541
633
  };
542
634
  return_object.loadBlendFromArrayBuffer(buffer, name);
543
635
  });
544
636
  }
637
+ function createCamera(object, ctx) {
638
+ const cdata = object.data;
639
+ if (!cdata) return void 0;
640
+ const type = cdata.type;
641
+ let camera;
642
+ if (type === 0) {
643
+ const sensorWidth = cdata.sensor_x || 36;
644
+ const sensorHeight = cdata.sensor_y || 24;
645
+ const lens = cdata.lens || 50;
646
+ const fov = 2 * Math.atan(sensorHeight / (2 * lens)) * (180 / Math.PI);
647
+ camera = new ctx.PerspectiveCamera(
648
+ fov,
649
+ sensorWidth / sensorHeight,
650
+ cdata.clipsta || 0.1,
651
+ cdata.clipend || 1e3
652
+ );
653
+ if ("shiftx" in cdata) camera.userData.shiftX = cdata.shiftx;
654
+ if ("shiftx" in cdata) camera.userData.shiftX = cdata.shiftx;
655
+ if ("shifty" in cdata) camera.userData.shiftY = cdata.shifty;
656
+ } else if (type === 1) {
657
+ const scale = cdata.ortho_scale || 1;
658
+ const aspect = (cdata.sensor_x || 36) / (cdata.sensor_y || 24);
659
+ const left = -scale * aspect / 2;
660
+ const right = scale * aspect / 2;
661
+ const top = scale / 2;
662
+ const bottom = -scale / 2;
663
+ camera = new ctx.OrthographicCamera(
664
+ left,
665
+ right,
666
+ top,
667
+ bottom,
668
+ cdata.clipsta || 0.1,
669
+ cdata.clipend || 1e3
670
+ );
671
+ if ("shiftx" in cdata) camera.userData.shiftX = cdata.shiftx;
672
+ if ("shifty" in cdata) camera.userData.shiftY = cdata.shifty;
673
+ } else {
674
+ camera = new ctx.PerspectiveCamera();
675
+ console.warn("Unsupported camera type", type);
676
+ }
677
+ return camera;
678
+ }
545
679
  const blenderLightTypes = {
546
680
  point: 0,
547
- sun: 1,
548
- spot: 0,
549
- hemi: 0,
550
- area: 0
681
+ sun: 1
551
682
  };
552
- function createLight(lamp) {
683
+ function createLight(lamp, ctx) {
553
684
  const ldata = lamp.data;
554
685
  const position = [lamp.loc[0], lamp.loc[2], -lamp.loc[1]];
555
686
  const color = ldata.r * 255 << 16 | ldata.g * 255 << 8 | ldata.b * 255 << 0;
556
687
  const intensity = ldata.energy;
557
688
  const distance = 0;
558
- let light = null;
689
+ let light = void 0;
559
690
  switch (ldata.type) {
560
691
  case blenderLightTypes.point:
561
- light = new threepipe.PointLight(color, intensity, distance);
692
+ light = new ctx.PointLight(color, intensity, distance);
562
693
  light.position.fromArray(position, 0);
563
694
  light.castShadow = true;
564
695
  break;
565
696
  case blenderLightTypes.sun:
566
- light = new threepipe.PointLight(color, intensity, distance);
697
+ light = new ctx.PointLight(color, intensity, distance);
567
698
  light.position.fromArray(position, 0);
568
699
  light.castShadow = true;
569
- light.shadow.mapSize.width = 1024;
570
- light.shadow.mapSize.height = 1024;
571
- light.shadow.camera.near = 0.01;
572
- light.shadow.camera.far = 500;
700
+ if (light.shadow) {
701
+ light.shadow.mapSize.width = 1024;
702
+ light.shadow.mapSize.height = 1024;
703
+ light.shadow.camera.near = 0.01;
704
+ light.shadow.camera.far = 500;
705
+ }
573
706
  break;
574
707
  default:
575
708
  console.warn("Unsupported light type", ldata.type);
576
709
  }
577
710
  return light;
578
711
  }
579
- function createBufferGeometry(mesh, origin) {
712
+ function getLayer(layers, i) {
713
+ if (!Array.isArray(layers)) return layers;
714
+ return layers[i];
715
+ }
716
+ function createBufferGeometry(meshData, ctx) {
717
+ var _a;
718
+ if (meshData.mpoly) return createBufferGeometryOld(meshData, ctx);
719
+ const geometry = new ctx.BufferGeometry();
720
+ geometry.name = meshData.aname || "";
721
+ let vertices;
722
+ let indices;
723
+ if (meshData.vdata && meshData.vdata.layers && meshData.vdata.totlayer > 0) {
724
+ for (let i = 0; i < meshData.vdata.totlayer; i++) {
725
+ const layer = getLayer(meshData.vdata.layers, i);
726
+ const data = layer.data || [];
727
+ if (data.length === meshData.totvert) {
728
+ if (vertices && (layer.name !== "position" || vertices.name === "position")) {
729
+ continue;
730
+ }
731
+ vertices = layer;
732
+ }
733
+ }
734
+ }
735
+ if (meshData.ldata && meshData.ldata.layers) {
736
+ for (let i = 0; i < meshData.ldata.totlayer; i++) {
737
+ const layer = getLayer(meshData.ldata.layers, i);
738
+ const data = layer.data || [];
739
+ if (data.length === meshData.totloop) {
740
+ if (indices && (layer.name !== ".corner_vert" || indices.name === ".corner_vert")) {
741
+ continue;
742
+ }
743
+ indices = layer;
744
+ }
745
+ }
746
+ }
747
+ let faceIndices = [];
748
+ if (meshData.poly_offset_indices && meshData.totpoly > 0) {
749
+ faceIndices = [...new Int32Array(meshData.poly_offset_indices.__blender_file__.AB, meshData.poly_offset_indices.__data_address__, meshData.totpoly + 1)];
750
+ }
751
+ if ((vertices == null ? void 0 : vertices.data) && vertices.data.length > 0) {
752
+ const positions = new Float32Array(vertices.data.length * 3);
753
+ for (let j = 0; j < vertices.data.length; j++) {
754
+ const vertex = vertices.data[j];
755
+ if (vertex.x !== void 0) {
756
+ positions[j * 3] = vertex.x;
757
+ positions[j * 3 + 1] = vertex.z;
758
+ positions[j * 3 + 2] = -vertex.y;
759
+ } else if (vertex.co !== void 0) {
760
+ positions[j * 3] = vertex.co[0];
761
+ positions[j * 3 + 1] = vertex.co[2];
762
+ positions[j * 3 + 2] = -vertex.co[1];
763
+ } else {
764
+ console.error("BlendLoader - unknown vertex", vertex);
765
+ break;
766
+ }
767
+ }
768
+ geometry.setAttribute("position", new ctx.BufferAttribute(positions, 3));
769
+ }
770
+ if ((indices == null ? void 0 : indices.data) && indices.data.length > 0 && ((_a = vertices == null ? void 0 : vertices.data) == null ? void 0 : _a.length)) {
771
+ const faceSize = meshData.totloop / meshData.totpoly;
772
+ if (faceIndices.length > 0) {
773
+ let totalTriangles = 0;
774
+ for (let i = 0; i < faceIndices.length - 1; i++) {
775
+ const faceVertCount = faceIndices[i + 1] - faceIndices[i];
776
+ totalTriangles += Math.max(0, faceVertCount - 2);
777
+ }
778
+ const indexes = new Uint32Array(totalTriangles * 3);
779
+ let t = 0;
780
+ for (let i = 0; i < faceIndices.length - 1; i++) {
781
+ const faceStart = faceIndices[i];
782
+ const faceEnd = faceIndices[i + 1];
783
+ const faceVertCount = faceEnd - faceStart;
784
+ if (faceVertCount >= 3) {
785
+ const firstVert = indices.data[faceStart].i;
786
+ for (let k = 1; k < faceVertCount - 1; k++) {
787
+ indexes[t++] = firstVert;
788
+ indexes[t++] = indices.data[faceStart + k].i;
789
+ indexes[t++] = indices.data[faceStart + k + 1].i;
790
+ }
791
+ }
792
+ }
793
+ geometry.setIndex(new ctx.BufferAttribute(indexes, 1));
794
+ } else if (faceSize === 3 || faceSize === 4) {
795
+ const isQuad = faceSize === 4;
796
+ const faceCount = indices.length / faceSize;
797
+ const indexes = new Uint32Array(faceCount * 3 * (isQuad ? 2 : 1));
798
+ if (faceSize !== 3 && faceSize !== 4) return geometry;
799
+ for (let j = 0, t = 0; j < indices.length; j += faceSize) {
800
+ const a = indices[j].i;
801
+ const b = indices[j + 1].i;
802
+ const c = indices[j + 2].i;
803
+ indexes[t++] = a;
804
+ indexes[t++] = b;
805
+ indexes[t++] = c;
806
+ if (isQuad) {
807
+ const d = indices[j + 3].i;
808
+ indexes[t++] = a;
809
+ indexes[t++] = c;
810
+ indexes[t++] = d;
811
+ }
812
+ }
813
+ geometry.setIndex(new ctx.BufferAttribute(indexes, 1));
814
+ }
815
+ } else if (faceIndices) {
816
+ console.error("BlendLoader - no indices data found, but face indices are present", faceIndices);
817
+ }
818
+ if (geometry.attributes.position && !geometry.attributes.normal)
819
+ geometry.computeVertexNormals();
820
+ return geometry;
821
+ }
822
+ function createBufferGeometryOld(mesh, ctx) {
580
823
  const faces = Array.isArray(mesh.mpoly) ? mesh.mpoly : [mesh.mpoly], loops = mesh.mloop, uv = mesh.mloopuv, vertices = mesh.mvert;
581
- const geometry = new threepipe.BufferGeometry();
824
+ const geometry = new ctx.BufferGeometry();
582
825
  if (!faces) return geometry;
583
826
  const size = faces.reduce((acc, face) => acc + Math.floor(face.totloop * 3 / 2), 0);
584
827
  const indices = new Uint32Array(size);
@@ -586,6 +829,7 @@
586
829
  const normals = new Float32Array(size * 3);
587
830
  const positions = new Float32Array(size * 3);
588
831
  let currentIndex = 0;
832
+ let computeNormals = false;
589
833
  for (const face of faces) {
590
834
  const len = face.totloop;
591
835
  const start = face.loopstart;
@@ -599,12 +843,16 @@
599
843
  const loop = loops[index];
600
844
  const vert = vertices[loop.v];
601
845
  indices[currentIndex] = currentIndex;
602
- positions[currentIndex * 3 + 0] = vert.co[0] + origin[0];
603
- positions[currentIndex * 3 + 1] = vert.co[2] + origin[2];
604
- positions[currentIndex * 3 + 2] = -vert.co[1] + -0;
605
- normals[currentIndex * 3 + 0] = vert.no[0];
606
- normals[currentIndex * 3 + 1] = vert.no[2];
607
- normals[currentIndex * 3 + 2] = -vert.no[1];
846
+ positions[currentIndex * 3 + 0] = vert.co[0];
847
+ positions[currentIndex * 3 + 1] = vert.co[2];
848
+ positions[currentIndex * 3 + 2] = -vert.co[1];
849
+ if (vert.no) {
850
+ normals[currentIndex * 3 + 0] = vert.no[0];
851
+ normals[currentIndex * 3 + 1] = vert.no[2];
852
+ normals[currentIndex * 3 + 2] = -vert.no[1];
853
+ } else {
854
+ computeNormals = true;
855
+ }
608
856
  if (uv) {
609
857
  uvs[currentIndex * 2 + 0] = uv[index].uv[0];
610
858
  uvs[currentIndex * 2 + 1] = uv[index].uv[1];
@@ -614,57 +862,1891 @@
614
862
  indexi += 2;
615
863
  }
616
864
  }
617
- geometry.setAttribute("position", new threepipe.BufferAttribute(positions, 3));
618
- geometry.setIndex(new threepipe.BufferAttribute(indices, 1));
619
- geometry.setAttribute("normal", new threepipe.BufferAttribute(normals, 3));
620
- geometry.setAttribute("uv", new threepipe.BufferAttribute(uvs, 2));
865
+ geometry.setAttribute("position", new ctx.BufferAttribute(positions, 3));
866
+ geometry.setIndex(new ctx.BufferAttribute(indices, 1));
867
+ geometry.setAttribute("normal", new ctx.BufferAttribute(normals, 3));
868
+ geometry.setAttribute("uv", new ctx.BufferAttribute(uvs, 2));
869
+ if (computeNormals) {
870
+ geometry.computeVertexNormals();
871
+ }
621
872
  return geometry;
622
873
  }
623
- function createMaterial(mat) {
624
- const material = new threepipe.MeshPhysicalMaterial();
874
+ function createMaterial(mat, ctx) {
875
+ const material = new ctx.MeshPhysicalMaterial();
625
876
  material.color.setRGB(mat.r, mat.g, mat.b);
626
877
  material.roughness = mat.roughness !== void 0 ? mat.roughness : 0.4;
627
878
  material.metalness = mat.metallic !== void 0 ? mat.metallic : 0;
628
- material.opacity = mat.alpha !== void 0 ? mat.alpha : 0;
879
+ material.opacity = 1;
629
880
  material.transparent = material.opacity < 1;
630
881
  return material;
631
882
  }
632
- function createMesh(object) {
633
- if (!object.data) return null;
634
- const geometry = createBufferGeometry(object.data, [0, 0, 0]);
883
+ function createMesh(object, loaded, ctx) {
884
+ if (!object.data) {
885
+ return void 0;
886
+ }
887
+ const geometry = loaded.get(object.data) ?? createBufferGeometry(object.data, ctx);
888
+ loaded.set(object.data, geometry);
635
889
  const mat = object.data.mat[0];
636
- const material = mat ? createMaterial(mat) : void 0;
637
- const mesh = new threepipe.Mesh(geometry, material);
890
+ const material = mat ? loaded.get(mat) ?? createMaterial(mat, ctx) : new ctx.MeshPhysicalMaterial();
891
+ if (mat) loaded.set(mat, material);
892
+ const mesh = new ctx.Mesh(geometry, material);
638
893
  mesh.castShadow = true;
639
894
  mesh.receiveShadow = true;
640
- mesh.rotateZ(object.rot[2]);
641
- mesh.rotateY(object.rot[1]);
642
- mesh.rotateX(object.rot[0]);
643
- mesh.scale.fromArray(object.size, 0);
644
- mesh.position.fromArray([object.loc[0], object.loc[2], -object.loc[1]], 0);
645
895
  return mesh;
646
896
  }
897
+ function clamp(value, min, max) {
898
+ return Math.max(min, Math.min(max, value));
899
+ }
900
+ class Quaternion {
901
+ constructor(x = 0, y = 0, z = 0, w = 1) {
902
+ this.isQuaternion = true;
903
+ this._x = x;
904
+ this._y = y;
905
+ this._z = z;
906
+ this._w = w;
907
+ }
908
+ static slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
909
+ let x0 = src0[srcOffset0 + 0], y0 = src0[srcOffset0 + 1], z0 = src0[srcOffset0 + 2], w0 = src0[srcOffset0 + 3];
910
+ const x1 = src1[srcOffset1 + 0], y1 = src1[srcOffset1 + 1], z1 = src1[srcOffset1 + 2], w1 = src1[srcOffset1 + 3];
911
+ if (t === 0) {
912
+ dst[dstOffset + 0] = x0;
913
+ dst[dstOffset + 1] = y0;
914
+ dst[dstOffset + 2] = z0;
915
+ dst[dstOffset + 3] = w0;
916
+ return;
917
+ }
918
+ if (t === 1) {
919
+ dst[dstOffset + 0] = x1;
920
+ dst[dstOffset + 1] = y1;
921
+ dst[dstOffset + 2] = z1;
922
+ dst[dstOffset + 3] = w1;
923
+ return;
924
+ }
925
+ if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
926
+ let s = 1 - t;
927
+ const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, dir = cos >= 0 ? 1 : -1, sqrSin = 1 - cos * cos;
928
+ if (sqrSin > Number.EPSILON) {
929
+ const sin = Math.sqrt(sqrSin), len = Math.atan2(sin, cos * dir);
930
+ s = Math.sin(s * len) / sin;
931
+ t = Math.sin(t * len) / sin;
932
+ }
933
+ const tDir = t * dir;
934
+ x0 = x0 * s + x1 * tDir;
935
+ y0 = y0 * s + y1 * tDir;
936
+ z0 = z0 * s + z1 * tDir;
937
+ w0 = w0 * s + w1 * tDir;
938
+ if (s === 1 - t) {
939
+ const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
940
+ x0 *= f;
941
+ y0 *= f;
942
+ z0 *= f;
943
+ w0 *= f;
944
+ }
945
+ }
946
+ dst[dstOffset] = x0;
947
+ dst[dstOffset + 1] = y0;
948
+ dst[dstOffset + 2] = z0;
949
+ dst[dstOffset + 3] = w0;
950
+ }
951
+ static multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
952
+ const x0 = src0[srcOffset0];
953
+ const y0 = src0[srcOffset0 + 1];
954
+ const z0 = src0[srcOffset0 + 2];
955
+ const w0 = src0[srcOffset0 + 3];
956
+ const x1 = src1[srcOffset1];
957
+ const y1 = src1[srcOffset1 + 1];
958
+ const z1 = src1[srcOffset1 + 2];
959
+ const w1 = src1[srcOffset1 + 3];
960
+ dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
961
+ dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
962
+ dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
963
+ dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
964
+ return dst;
965
+ }
966
+ get x() {
967
+ return this._x;
968
+ }
969
+ set x(value) {
970
+ this._x = value;
971
+ this._onChangeCallback();
972
+ }
973
+ get y() {
974
+ return this._y;
975
+ }
976
+ set y(value) {
977
+ this._y = value;
978
+ this._onChangeCallback();
979
+ }
980
+ get z() {
981
+ return this._z;
982
+ }
983
+ set z(value) {
984
+ this._z = value;
985
+ this._onChangeCallback();
986
+ }
987
+ get w() {
988
+ return this._w;
989
+ }
990
+ set w(value) {
991
+ this._w = value;
992
+ this._onChangeCallback();
993
+ }
994
+ set(x, y, z, w) {
995
+ this._x = x;
996
+ this._y = y;
997
+ this._z = z;
998
+ this._w = w;
999
+ this._onChangeCallback();
1000
+ return this;
1001
+ }
1002
+ clone() {
1003
+ return new this.constructor(this._x, this._y, this._z, this._w);
1004
+ }
1005
+ copy(quaternion) {
1006
+ this._x = quaternion.x;
1007
+ this._y = quaternion.y;
1008
+ this._z = quaternion.z;
1009
+ this._w = quaternion.w;
1010
+ this._onChangeCallback();
1011
+ return this;
1012
+ }
1013
+ setFromEuler(euler, update = true) {
1014
+ const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
1015
+ const cos = Math.cos;
1016
+ const sin = Math.sin;
1017
+ const c1 = cos(x / 2);
1018
+ const c2 = cos(y / 2);
1019
+ const c3 = cos(z / 2);
1020
+ const s1 = sin(x / 2);
1021
+ const s2 = sin(y / 2);
1022
+ const s3 = sin(z / 2);
1023
+ switch (order) {
1024
+ case "XYZ":
1025
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
1026
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
1027
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
1028
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
1029
+ break;
1030
+ case "YXZ":
1031
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
1032
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
1033
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
1034
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
1035
+ break;
1036
+ case "ZXY":
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 "ZYX":
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 "YZX":
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 "XZY":
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
+ default:
1061
+ console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + order);
1062
+ }
1063
+ if (update === true) this._onChangeCallback();
1064
+ return this;
1065
+ }
1066
+ setFromAxisAngle(axis, angle) {
1067
+ const halfAngle = angle / 2, s = Math.sin(halfAngle);
1068
+ this._x = axis.x * s;
1069
+ this._y = axis.y * s;
1070
+ this._z = axis.z * s;
1071
+ this._w = Math.cos(halfAngle);
1072
+ this._onChangeCallback();
1073
+ return this;
1074
+ }
1075
+ setFromRotationMatrix(m) {
1076
+ 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;
1077
+ if (trace > 0) {
1078
+ const s = 0.5 / Math.sqrt(trace + 1);
1079
+ this._w = 0.25 / s;
1080
+ this._x = (m32 - m23) * s;
1081
+ this._y = (m13 - m31) * s;
1082
+ this._z = (m21 - m12) * s;
1083
+ } else if (m11 > m22 && m11 > m33) {
1084
+ const s = 2 * Math.sqrt(1 + m11 - m22 - m33);
1085
+ this._w = (m32 - m23) / s;
1086
+ this._x = 0.25 * s;
1087
+ this._y = (m12 + m21) / s;
1088
+ this._z = (m13 + m31) / s;
1089
+ } else if (m22 > m33) {
1090
+ const s = 2 * Math.sqrt(1 + m22 - m11 - m33);
1091
+ this._w = (m13 - m31) / s;
1092
+ this._x = (m12 + m21) / s;
1093
+ this._y = 0.25 * s;
1094
+ this._z = (m23 + m32) / s;
1095
+ } else {
1096
+ const s = 2 * Math.sqrt(1 + m33 - m11 - m22);
1097
+ this._w = (m21 - m12) / s;
1098
+ this._x = (m13 + m31) / s;
1099
+ this._y = (m23 + m32) / s;
1100
+ this._z = 0.25 * s;
1101
+ }
1102
+ this._onChangeCallback();
1103
+ return this;
1104
+ }
1105
+ setFromUnitVectors(vFrom, vTo) {
1106
+ let r = vFrom.dot(vTo) + 1;
1107
+ if (r < Number.EPSILON) {
1108
+ r = 0;
1109
+ if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
1110
+ this._x = -vFrom.y;
1111
+ this._y = vFrom.x;
1112
+ this._z = 0;
1113
+ this._w = r;
1114
+ } else {
1115
+ this._x = 0;
1116
+ this._y = -vFrom.z;
1117
+ this._z = vFrom.y;
1118
+ this._w = r;
1119
+ }
1120
+ } else {
1121
+ this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
1122
+ this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
1123
+ this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
1124
+ this._w = r;
1125
+ }
1126
+ return this.normalize();
1127
+ }
1128
+ angleTo(q) {
1129
+ return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
1130
+ }
1131
+ rotateTowards(q, step) {
1132
+ const angle = this.angleTo(q);
1133
+ if (angle === 0) return this;
1134
+ const t = Math.min(1, step / angle);
1135
+ this.slerp(q, t);
1136
+ return this;
1137
+ }
1138
+ identity() {
1139
+ return this.set(0, 0, 0, 1);
1140
+ }
1141
+ invert() {
1142
+ return this.conjugate();
1143
+ }
1144
+ conjugate() {
1145
+ this._x *= -1;
1146
+ this._y *= -1;
1147
+ this._z *= -1;
1148
+ this._onChangeCallback();
1149
+ return this;
1150
+ }
1151
+ dot(v) {
1152
+ return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
1153
+ }
1154
+ lengthSq() {
1155
+ return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
1156
+ }
1157
+ length() {
1158
+ return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
1159
+ }
1160
+ normalize() {
1161
+ let l = this.length();
1162
+ if (l === 0) {
1163
+ this._x = 0;
1164
+ this._y = 0;
1165
+ this._z = 0;
1166
+ this._w = 1;
1167
+ } else {
1168
+ l = 1 / l;
1169
+ this._x = this._x * l;
1170
+ this._y = this._y * l;
1171
+ this._z = this._z * l;
1172
+ this._w = this._w * l;
1173
+ }
1174
+ this._onChangeCallback();
1175
+ return this;
1176
+ }
1177
+ multiply(q) {
1178
+ return this.multiplyQuaternions(this, q);
1179
+ }
1180
+ premultiply(q) {
1181
+ return this.multiplyQuaternions(q, this);
1182
+ }
1183
+ multiplyQuaternions(a, b) {
1184
+ const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
1185
+ const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
1186
+ this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
1187
+ this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
1188
+ this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
1189
+ this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
1190
+ this._onChangeCallback();
1191
+ return this;
1192
+ }
1193
+ slerp(qb, t) {
1194
+ if (t === 0) return this;
1195
+ if (t === 1) return this.copy(qb);
1196
+ const x = this._x, y = this._y, z = this._z, w = this._w;
1197
+ let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
1198
+ if (cosHalfTheta < 0) {
1199
+ this._w = -qb._w;
1200
+ this._x = -qb._x;
1201
+ this._y = -qb._y;
1202
+ this._z = -qb._z;
1203
+ cosHalfTheta = -cosHalfTheta;
1204
+ } else {
1205
+ this.copy(qb);
1206
+ }
1207
+ if (cosHalfTheta >= 1) {
1208
+ this._w = w;
1209
+ this._x = x;
1210
+ this._y = y;
1211
+ this._z = z;
1212
+ return this;
1213
+ }
1214
+ const sqrSinHalfTheta = 1 - cosHalfTheta * cosHalfTheta;
1215
+ if (sqrSinHalfTheta <= Number.EPSILON) {
1216
+ const s = 1 - t;
1217
+ this._w = s * w + t * this._w;
1218
+ this._x = s * x + t * this._x;
1219
+ this._y = s * y + t * this._y;
1220
+ this._z = s * z + t * this._z;
1221
+ this.normalize();
1222
+ return this;
1223
+ }
1224
+ const sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
1225
+ const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
1226
+ const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta, ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
1227
+ this._w = w * ratioA + this._w * ratioB;
1228
+ this._x = x * ratioA + this._x * ratioB;
1229
+ this._y = y * ratioA + this._y * ratioB;
1230
+ this._z = z * ratioA + this._z * ratioB;
1231
+ this._onChangeCallback();
1232
+ return this;
1233
+ }
1234
+ slerpQuaternions(qa, qb, t) {
1235
+ return this.copy(qa).slerp(qb, t);
1236
+ }
1237
+ random() {
1238
+ const u1 = Math.random();
1239
+ const sqrt1u1 = Math.sqrt(1 - u1);
1240
+ const sqrtu1 = Math.sqrt(u1);
1241
+ const u2 = 2 * Math.PI * Math.random();
1242
+ const u3 = 2 * Math.PI * Math.random();
1243
+ return this.set(
1244
+ sqrt1u1 * Math.cos(u2),
1245
+ sqrtu1 * Math.sin(u3),
1246
+ sqrtu1 * Math.cos(u3),
1247
+ sqrt1u1 * Math.sin(u2)
1248
+ );
1249
+ }
1250
+ equals(quaternion) {
1251
+ return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
1252
+ }
1253
+ fromArray(array, offset = 0) {
1254
+ this._x = array[offset];
1255
+ this._y = array[offset + 1];
1256
+ this._z = array[offset + 2];
1257
+ this._w = array[offset + 3];
1258
+ this._onChangeCallback();
1259
+ return this;
1260
+ }
1261
+ toArray(array = [], offset = 0) {
1262
+ array[offset] = this._x;
1263
+ array[offset + 1] = this._y;
1264
+ array[offset + 2] = this._z;
1265
+ array[offset + 3] = this._w;
1266
+ return array;
1267
+ }
1268
+ fromBufferAttribute(attribute, index) {
1269
+ this._x = attribute.getX(index);
1270
+ this._y = attribute.getY(index);
1271
+ this._z = attribute.getZ(index);
1272
+ this._w = attribute.getW(index);
1273
+ this._onChangeCallback();
1274
+ return this;
1275
+ }
1276
+ toJSON() {
1277
+ return this.toArray();
1278
+ }
1279
+ _onChange(callback) {
1280
+ this._onChangeCallback = callback;
1281
+ return this;
1282
+ }
1283
+ _onChangeCallback() {
1284
+ }
1285
+ *[Symbol.iterator]() {
1286
+ yield this._x;
1287
+ yield this._y;
1288
+ yield this._z;
1289
+ yield this._w;
1290
+ }
1291
+ }
1292
+ const WebGLCoordinateSystem = 2e3;
1293
+ const WebGPUCoordinateSystem = 2001;
1294
+ class Vector3 {
1295
+ constructor(x = 0, y = 0, z = 0) {
1296
+ Vector3.prototype.isVector3 = true;
1297
+ this.x = x;
1298
+ this.y = y;
1299
+ this.z = z;
1300
+ }
1301
+ set(x, y, z) {
1302
+ if (z === void 0) z = this.z;
1303
+ this.x = x;
1304
+ this.y = y;
1305
+ this.z = z;
1306
+ return this;
1307
+ }
1308
+ setScalar(scalar) {
1309
+ this.x = scalar;
1310
+ this.y = scalar;
1311
+ this.z = scalar;
1312
+ return this;
1313
+ }
1314
+ setX(x) {
1315
+ this.x = x;
1316
+ return this;
1317
+ }
1318
+ setY(y) {
1319
+ this.y = y;
1320
+ return this;
1321
+ }
1322
+ setZ(z) {
1323
+ this.z = z;
1324
+ return this;
1325
+ }
1326
+ setComponent(index, value) {
1327
+ switch (index) {
1328
+ case 0:
1329
+ this.x = value;
1330
+ break;
1331
+ case 1:
1332
+ this.y = value;
1333
+ break;
1334
+ case 2:
1335
+ this.z = value;
1336
+ break;
1337
+ default:
1338
+ throw new Error("index is out of range: " + index);
1339
+ }
1340
+ return this;
1341
+ }
1342
+ getComponent(index) {
1343
+ switch (index) {
1344
+ case 0:
1345
+ return this.x;
1346
+ case 1:
1347
+ return this.y;
1348
+ case 2:
1349
+ return this.z;
1350
+ default:
1351
+ throw new Error("index is out of range: " + index);
1352
+ }
1353
+ }
1354
+ clone() {
1355
+ return new this.constructor(this.x, this.y, this.z);
1356
+ }
1357
+ copy(v) {
1358
+ this.x = v.x;
1359
+ this.y = v.y;
1360
+ this.z = v.z;
1361
+ return this;
1362
+ }
1363
+ add(v) {
1364
+ this.x += v.x;
1365
+ this.y += v.y;
1366
+ this.z += v.z;
1367
+ return this;
1368
+ }
1369
+ addScalar(s) {
1370
+ this.x += s;
1371
+ this.y += s;
1372
+ this.z += s;
1373
+ return this;
1374
+ }
1375
+ addVectors(a, b) {
1376
+ this.x = a.x + b.x;
1377
+ this.y = a.y + b.y;
1378
+ this.z = a.z + b.z;
1379
+ return this;
1380
+ }
1381
+ addScaledVector(v, s) {
1382
+ this.x += v.x * s;
1383
+ this.y += v.y * s;
1384
+ this.z += v.z * s;
1385
+ return this;
1386
+ }
1387
+ sub(v) {
1388
+ this.x -= v.x;
1389
+ this.y -= v.y;
1390
+ this.z -= v.z;
1391
+ return this;
1392
+ }
1393
+ subScalar(s) {
1394
+ this.x -= s;
1395
+ this.y -= s;
1396
+ this.z -= s;
1397
+ return this;
1398
+ }
1399
+ subVectors(a, b) {
1400
+ this.x = a.x - b.x;
1401
+ this.y = a.y - b.y;
1402
+ this.z = a.z - b.z;
1403
+ return this;
1404
+ }
1405
+ multiply(v) {
1406
+ this.x *= v.x;
1407
+ this.y *= v.y;
1408
+ this.z *= v.z;
1409
+ return this;
1410
+ }
1411
+ multiplyScalar(scalar) {
1412
+ this.x *= scalar;
1413
+ this.y *= scalar;
1414
+ this.z *= scalar;
1415
+ return this;
1416
+ }
1417
+ multiplyVectors(a, b) {
1418
+ this.x = a.x * b.x;
1419
+ this.y = a.y * b.y;
1420
+ this.z = a.z * b.z;
1421
+ return this;
1422
+ }
1423
+ applyEuler(euler) {
1424
+ return this.applyQuaternion(_quaternion$1.setFromEuler(euler));
1425
+ }
1426
+ applyAxisAngle(axis, angle) {
1427
+ return this.applyQuaternion(_quaternion$1.setFromAxisAngle(axis, angle));
1428
+ }
1429
+ applyMatrix3(m) {
1430
+ const x = this.x, y = this.y, z = this.z;
1431
+ const e = m.elements;
1432
+ this.x = e[0] * x + e[3] * y + e[6] * z;
1433
+ this.y = e[1] * x + e[4] * y + e[7] * z;
1434
+ this.z = e[2] * x + e[5] * y + e[8] * z;
1435
+ return this;
1436
+ }
1437
+ applyNormalMatrix(m) {
1438
+ return this.applyMatrix3(m).normalize();
1439
+ }
1440
+ applyMatrix4(m) {
1441
+ const x = this.x, y = this.y, z = this.z;
1442
+ const e = m.elements;
1443
+ const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
1444
+ this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
1445
+ this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
1446
+ this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
1447
+ return this;
1448
+ }
1449
+ applyQuaternion(q) {
1450
+ const vx = this.x, vy = this.y, vz = this.z;
1451
+ const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
1452
+ const tx = 2 * (qy * vz - qz * vy);
1453
+ const ty = 2 * (qz * vx - qx * vz);
1454
+ const tz = 2 * (qx * vy - qy * vx);
1455
+ this.x = vx + qw * tx + qy * tz - qz * ty;
1456
+ this.y = vy + qw * ty + qz * tx - qx * tz;
1457
+ this.z = vz + qw * tz + qx * ty - qy * tx;
1458
+ return this;
1459
+ }
1460
+ project(camera) {
1461
+ return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
1462
+ }
1463
+ unproject(camera) {
1464
+ return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
1465
+ }
1466
+ transformDirection(m) {
1467
+ const x = this.x, y = this.y, z = this.z;
1468
+ const e = m.elements;
1469
+ this.x = e[0] * x + e[4] * y + e[8] * z;
1470
+ this.y = e[1] * x + e[5] * y + e[9] * z;
1471
+ this.z = e[2] * x + e[6] * y + e[10] * z;
1472
+ return this.normalize();
1473
+ }
1474
+ divide(v) {
1475
+ this.x /= v.x;
1476
+ this.y /= v.y;
1477
+ this.z /= v.z;
1478
+ return this;
1479
+ }
1480
+ divideScalar(scalar) {
1481
+ return this.multiplyScalar(1 / scalar);
1482
+ }
1483
+ min(v) {
1484
+ this.x = Math.min(this.x, v.x);
1485
+ this.y = Math.min(this.y, v.y);
1486
+ this.z = Math.min(this.z, v.z);
1487
+ return this;
1488
+ }
1489
+ max(v) {
1490
+ this.x = Math.max(this.x, v.x);
1491
+ this.y = Math.max(this.y, v.y);
1492
+ this.z = Math.max(this.z, v.z);
1493
+ return this;
1494
+ }
1495
+ clamp(min, max) {
1496
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1497
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1498
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1499
+ return this;
1500
+ }
1501
+ clampScalar(minVal, maxVal) {
1502
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
1503
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
1504
+ this.z = Math.max(minVal, Math.min(maxVal, this.z));
1505
+ return this;
1506
+ }
1507
+ clampLength(min, max) {
1508
+ const length = this.length();
1509
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1510
+ }
1511
+ floor() {
1512
+ this.x = Math.floor(this.x);
1513
+ this.y = Math.floor(this.y);
1514
+ this.z = Math.floor(this.z);
1515
+ return this;
1516
+ }
1517
+ ceil() {
1518
+ this.x = Math.ceil(this.x);
1519
+ this.y = Math.ceil(this.y);
1520
+ this.z = Math.ceil(this.z);
1521
+ return this;
1522
+ }
1523
+ round() {
1524
+ this.x = Math.round(this.x);
1525
+ this.y = Math.round(this.y);
1526
+ this.z = Math.round(this.z);
1527
+ return this;
1528
+ }
1529
+ roundToZero() {
1530
+ this.x = Math.trunc(this.x);
1531
+ this.y = Math.trunc(this.y);
1532
+ this.z = Math.trunc(this.z);
1533
+ return this;
1534
+ }
1535
+ negate() {
1536
+ this.x = -this.x;
1537
+ this.y = -this.y;
1538
+ this.z = -this.z;
1539
+ return this;
1540
+ }
1541
+ dot(v) {
1542
+ return this.x * v.x + this.y * v.y + this.z * v.z;
1543
+ }
1544
+ // TODO lengthSquared?
1545
+ lengthSq() {
1546
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1547
+ }
1548
+ length() {
1549
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1550
+ }
1551
+ manhattanLength() {
1552
+ return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
1553
+ }
1554
+ normalize() {
1555
+ return this.divideScalar(this.length() || 1);
1556
+ }
1557
+ setLength(length) {
1558
+ return this.normalize().multiplyScalar(length);
1559
+ }
1560
+ lerp(v, alpha) {
1561
+ this.x += (v.x - this.x) * alpha;
1562
+ this.y += (v.y - this.y) * alpha;
1563
+ this.z += (v.z - this.z) * alpha;
1564
+ return this;
1565
+ }
1566
+ lerpVectors(v1, v2, alpha) {
1567
+ this.x = v1.x + (v2.x - v1.x) * alpha;
1568
+ this.y = v1.y + (v2.y - v1.y) * alpha;
1569
+ this.z = v1.z + (v2.z - v1.z) * alpha;
1570
+ return this;
1571
+ }
1572
+ cross(v) {
1573
+ return this.crossVectors(this, v);
1574
+ }
1575
+ crossVectors(a, b) {
1576
+ const ax = a.x, ay = a.y, az = a.z;
1577
+ const bx = b.x, by = b.y, bz = b.z;
1578
+ this.x = ay * bz - az * by;
1579
+ this.y = az * bx - ax * bz;
1580
+ this.z = ax * by - ay * bx;
1581
+ return this;
1582
+ }
1583
+ projectOnVector(v) {
1584
+ const denominator = v.lengthSq();
1585
+ if (denominator === 0) return this.set(0, 0, 0);
1586
+ const scalar = v.dot(this) / denominator;
1587
+ return this.copy(v).multiplyScalar(scalar);
1588
+ }
1589
+ projectOnPlane(planeNormal) {
1590
+ _vector.copy(this).projectOnVector(planeNormal);
1591
+ return this.sub(_vector);
1592
+ }
1593
+ reflect(normal) {
1594
+ return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
1595
+ }
1596
+ angleTo(v) {
1597
+ const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
1598
+ if (denominator === 0) return Math.PI / 2;
1599
+ const theta = this.dot(v) / denominator;
1600
+ return Math.acos(clamp(theta, -1, 1));
1601
+ }
1602
+ distanceTo(v) {
1603
+ return Math.sqrt(this.distanceToSquared(v));
1604
+ }
1605
+ distanceToSquared(v) {
1606
+ const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1607
+ return dx * dx + dy * dy + dz * dz;
1608
+ }
1609
+ manhattanDistanceTo(v) {
1610
+ return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
1611
+ }
1612
+ setFromSpherical(s) {
1613
+ return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
1614
+ }
1615
+ setFromSphericalCoords(radius, phi, theta) {
1616
+ const sinPhiRadius = Math.sin(phi) * radius;
1617
+ this.x = sinPhiRadius * Math.sin(theta);
1618
+ this.y = Math.cos(phi) * radius;
1619
+ this.z = sinPhiRadius * Math.cos(theta);
1620
+ return this;
1621
+ }
1622
+ setFromCylindrical(c) {
1623
+ return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
1624
+ }
1625
+ setFromCylindricalCoords(radius, theta, y) {
1626
+ this.x = radius * Math.sin(theta);
1627
+ this.y = y;
1628
+ this.z = radius * Math.cos(theta);
1629
+ return this;
1630
+ }
1631
+ setFromMatrixPosition(m) {
1632
+ const e = m.elements;
1633
+ this.x = e[12];
1634
+ this.y = e[13];
1635
+ this.z = e[14];
1636
+ return this;
1637
+ }
1638
+ setFromMatrixScale(m) {
1639
+ const sx = this.setFromMatrixColumn(m, 0).length();
1640
+ const sy = this.setFromMatrixColumn(m, 1).length();
1641
+ const sz = this.setFromMatrixColumn(m, 2).length();
1642
+ this.x = sx;
1643
+ this.y = sy;
1644
+ this.z = sz;
1645
+ return this;
1646
+ }
1647
+ setFromMatrixColumn(m, index) {
1648
+ return this.fromArray(m.elements, index * 4);
1649
+ }
1650
+ setFromMatrix3Column(m, index) {
1651
+ return this.fromArray(m.elements, index * 3);
1652
+ }
1653
+ setFromEuler(e) {
1654
+ this.x = e._x;
1655
+ this.y = e._y;
1656
+ this.z = e._z;
1657
+ return this;
1658
+ }
1659
+ setFromColor(c) {
1660
+ this.x = c.r;
1661
+ this.y = c.g;
1662
+ this.z = c.b;
1663
+ return this;
1664
+ }
1665
+ equals(v) {
1666
+ return v.x === this.x && v.y === this.y && v.z === this.z;
1667
+ }
1668
+ fromArray(array, offset = 0) {
1669
+ this.x = array[offset];
1670
+ this.y = array[offset + 1];
1671
+ this.z = array[offset + 2];
1672
+ return this;
1673
+ }
1674
+ toArray(array = [], offset = 0) {
1675
+ array[offset] = this.x;
1676
+ array[offset + 1] = this.y;
1677
+ array[offset + 2] = this.z;
1678
+ return array;
1679
+ }
1680
+ fromBufferAttribute(attribute, index) {
1681
+ this.x = attribute.getX(index);
1682
+ this.y = attribute.getY(index);
1683
+ this.z = attribute.getZ(index);
1684
+ return this;
1685
+ }
1686
+ random() {
1687
+ this.x = Math.random();
1688
+ this.y = Math.random();
1689
+ this.z = Math.random();
1690
+ return this;
1691
+ }
1692
+ randomDirection() {
1693
+ const u = (Math.random() - 0.5) * 2;
1694
+ const t = Math.random() * Math.PI * 2;
1695
+ const f = Math.sqrt(1 - u ** 2);
1696
+ this.x = f * Math.cos(t);
1697
+ this.y = f * Math.sin(t);
1698
+ this.z = u;
1699
+ return this;
1700
+ }
1701
+ *[Symbol.iterator]() {
1702
+ yield this.x;
1703
+ yield this.y;
1704
+ yield this.z;
1705
+ }
1706
+ }
1707
+ const _vector = /* @__PURE__ */ new Vector3();
1708
+ const _quaternion$1 = /* @__PURE__ */ new Quaternion();
1709
+ class Matrix4 {
1710
+ constructor(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
1711
+ Matrix4.prototype.isMatrix4 = true;
1712
+ this.elements = [
1713
+ 1,
1714
+ 0,
1715
+ 0,
1716
+ 0,
1717
+ 0,
1718
+ 1,
1719
+ 0,
1720
+ 0,
1721
+ 0,
1722
+ 0,
1723
+ 1,
1724
+ 0,
1725
+ 0,
1726
+ 0,
1727
+ 0,
1728
+ 1
1729
+ ];
1730
+ if (n11 !== void 0) {
1731
+ this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44);
1732
+ }
1733
+ }
1734
+ set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
1735
+ const te = this.elements;
1736
+ te[0] = n11;
1737
+ te[4] = n12;
1738
+ te[8] = n13;
1739
+ te[12] = n14;
1740
+ te[1] = n21;
1741
+ te[5] = n22;
1742
+ te[9] = n23;
1743
+ te[13] = n24;
1744
+ te[2] = n31;
1745
+ te[6] = n32;
1746
+ te[10] = n33;
1747
+ te[14] = n34;
1748
+ te[3] = n41;
1749
+ te[7] = n42;
1750
+ te[11] = n43;
1751
+ te[15] = n44;
1752
+ return this;
1753
+ }
1754
+ identity() {
1755
+ this.set(
1756
+ 1,
1757
+ 0,
1758
+ 0,
1759
+ 0,
1760
+ 0,
1761
+ 1,
1762
+ 0,
1763
+ 0,
1764
+ 0,
1765
+ 0,
1766
+ 1,
1767
+ 0,
1768
+ 0,
1769
+ 0,
1770
+ 0,
1771
+ 1
1772
+ );
1773
+ return this;
1774
+ }
1775
+ clone() {
1776
+ return new Matrix4().fromArray(this.elements);
1777
+ }
1778
+ copy(m) {
1779
+ const te = this.elements;
1780
+ const me = m.elements;
1781
+ te[0] = me[0];
1782
+ te[1] = me[1];
1783
+ te[2] = me[2];
1784
+ te[3] = me[3];
1785
+ te[4] = me[4];
1786
+ te[5] = me[5];
1787
+ te[6] = me[6];
1788
+ te[7] = me[7];
1789
+ te[8] = me[8];
1790
+ te[9] = me[9];
1791
+ te[10] = me[10];
1792
+ te[11] = me[11];
1793
+ te[12] = me[12];
1794
+ te[13] = me[13];
1795
+ te[14] = me[14];
1796
+ te[15] = me[15];
1797
+ return this;
1798
+ }
1799
+ copyPosition(m) {
1800
+ const te = this.elements, me = m.elements;
1801
+ te[12] = me[12];
1802
+ te[13] = me[13];
1803
+ te[14] = me[14];
1804
+ return this;
1805
+ }
1806
+ setFromMatrix3(m) {
1807
+ const me = m.elements;
1808
+ this.set(
1809
+ me[0],
1810
+ me[3],
1811
+ me[6],
1812
+ 0,
1813
+ me[1],
1814
+ me[4],
1815
+ me[7],
1816
+ 0,
1817
+ me[2],
1818
+ me[5],
1819
+ me[8],
1820
+ 0,
1821
+ 0,
1822
+ 0,
1823
+ 0,
1824
+ 1
1825
+ );
1826
+ return this;
1827
+ }
1828
+ extractBasis(xAxis, yAxis, zAxis) {
1829
+ xAxis.setFromMatrixColumn(this, 0);
1830
+ yAxis.setFromMatrixColumn(this, 1);
1831
+ zAxis.setFromMatrixColumn(this, 2);
1832
+ return this;
1833
+ }
1834
+ makeBasis(xAxis, yAxis, zAxis) {
1835
+ this.set(
1836
+ xAxis.x,
1837
+ yAxis.x,
1838
+ zAxis.x,
1839
+ 0,
1840
+ xAxis.y,
1841
+ yAxis.y,
1842
+ zAxis.y,
1843
+ 0,
1844
+ xAxis.z,
1845
+ yAxis.z,
1846
+ zAxis.z,
1847
+ 0,
1848
+ 0,
1849
+ 0,
1850
+ 0,
1851
+ 1
1852
+ );
1853
+ return this;
1854
+ }
1855
+ extractRotation(m) {
1856
+ const te = this.elements;
1857
+ const me = m.elements;
1858
+ const scaleX = 1 / _v1.setFromMatrixColumn(m, 0).length();
1859
+ const scaleY = 1 / _v1.setFromMatrixColumn(m, 1).length();
1860
+ const scaleZ = 1 / _v1.setFromMatrixColumn(m, 2).length();
1861
+ te[0] = me[0] * scaleX;
1862
+ te[1] = me[1] * scaleX;
1863
+ te[2] = me[2] * scaleX;
1864
+ te[3] = 0;
1865
+ te[4] = me[4] * scaleY;
1866
+ te[5] = me[5] * scaleY;
1867
+ te[6] = me[6] * scaleY;
1868
+ te[7] = 0;
1869
+ te[8] = me[8] * scaleZ;
1870
+ te[9] = me[9] * scaleZ;
1871
+ te[10] = me[10] * scaleZ;
1872
+ te[11] = 0;
1873
+ te[12] = 0;
1874
+ te[13] = 0;
1875
+ te[14] = 0;
1876
+ te[15] = 1;
1877
+ return this;
1878
+ }
1879
+ makeRotationFromEuler(euler) {
1880
+ const te = this.elements;
1881
+ const x = euler.x, y = euler.y, z = euler.z;
1882
+ const a = Math.cos(x), b = Math.sin(x);
1883
+ const c = Math.cos(y), d = Math.sin(y);
1884
+ const e = Math.cos(z), f = Math.sin(z);
1885
+ if (euler.order === "XYZ") {
1886
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
1887
+ te[0] = c * e;
1888
+ te[4] = -c * f;
1889
+ te[8] = d;
1890
+ te[1] = af + be * d;
1891
+ te[5] = ae - bf * d;
1892
+ te[9] = -b * c;
1893
+ te[2] = bf - ae * d;
1894
+ te[6] = be + af * d;
1895
+ te[10] = a * c;
1896
+ } else if (euler.order === "YXZ") {
1897
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
1898
+ te[0] = ce + df * b;
1899
+ te[4] = de * b - cf;
1900
+ te[8] = a * d;
1901
+ te[1] = a * f;
1902
+ te[5] = a * e;
1903
+ te[9] = -b;
1904
+ te[2] = cf * b - de;
1905
+ te[6] = df + ce * b;
1906
+ te[10] = a * c;
1907
+ } else if (euler.order === "ZXY") {
1908
+ const ce = c * e, cf = c * f, de = d * e, df = d * f;
1909
+ te[0] = ce - df * b;
1910
+ te[4] = -a * f;
1911
+ te[8] = de + cf * b;
1912
+ te[1] = cf + de * b;
1913
+ te[5] = a * e;
1914
+ te[9] = df - ce * b;
1915
+ te[2] = -a * d;
1916
+ te[6] = b;
1917
+ te[10] = a * c;
1918
+ } else if (euler.order === "ZYX") {
1919
+ const ae = a * e, af = a * f, be = b * e, bf = b * f;
1920
+ te[0] = c * e;
1921
+ te[4] = be * d - af;
1922
+ te[8] = ae * d + bf;
1923
+ te[1] = c * f;
1924
+ te[5] = bf * d + ae;
1925
+ te[9] = af * d - be;
1926
+ te[2] = -d;
1927
+ te[6] = b * c;
1928
+ te[10] = a * c;
1929
+ } else if (euler.order === "YZX") {
1930
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
1931
+ te[0] = c * e;
1932
+ te[4] = bd - ac * f;
1933
+ te[8] = bc * f + ad;
1934
+ te[1] = f;
1935
+ te[5] = a * e;
1936
+ te[9] = -b * e;
1937
+ te[2] = -d * e;
1938
+ te[6] = ad * f + bc;
1939
+ te[10] = ac - bd * f;
1940
+ } else if (euler.order === "XZY") {
1941
+ const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
1942
+ te[0] = c * e;
1943
+ te[4] = -f;
1944
+ te[8] = d * e;
1945
+ te[1] = ac * f + bd;
1946
+ te[5] = a * e;
1947
+ te[9] = ad * f - bc;
1948
+ te[2] = bc * f - ad;
1949
+ te[6] = b * e;
1950
+ te[10] = bd * f + ac;
1951
+ }
1952
+ te[3] = 0;
1953
+ te[7] = 0;
1954
+ te[11] = 0;
1955
+ te[12] = 0;
1956
+ te[13] = 0;
1957
+ te[14] = 0;
1958
+ te[15] = 1;
1959
+ return this;
1960
+ }
1961
+ makeRotationFromQuaternion(q) {
1962
+ return this.compose(_zero, q, _one);
1963
+ }
1964
+ lookAt(eye, target, up) {
1965
+ const te = this.elements;
1966
+ _z.subVectors(eye, target);
1967
+ if (_z.lengthSq() === 0) {
1968
+ _z.z = 1;
1969
+ }
1970
+ _z.normalize();
1971
+ _x.crossVectors(up, _z);
1972
+ if (_x.lengthSq() === 0) {
1973
+ if (Math.abs(up.z) === 1) {
1974
+ _z.x += 1e-4;
1975
+ } else {
1976
+ _z.z += 1e-4;
1977
+ }
1978
+ _z.normalize();
1979
+ _x.crossVectors(up, _z);
1980
+ }
1981
+ _x.normalize();
1982
+ _y.crossVectors(_z, _x);
1983
+ te[0] = _x.x;
1984
+ te[4] = _y.x;
1985
+ te[8] = _z.x;
1986
+ te[1] = _x.y;
1987
+ te[5] = _y.y;
1988
+ te[9] = _z.y;
1989
+ te[2] = _x.z;
1990
+ te[6] = _y.z;
1991
+ te[10] = _z.z;
1992
+ return this;
1993
+ }
1994
+ multiply(m) {
1995
+ return this.multiplyMatrices(this, m);
1996
+ }
1997
+ premultiply(m) {
1998
+ return this.multiplyMatrices(m, this);
1999
+ }
2000
+ multiplyMatrices(a, b) {
2001
+ const ae = a.elements;
2002
+ const be = b.elements;
2003
+ const te = this.elements;
2004
+ const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
2005
+ const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
2006
+ const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
2007
+ const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
2008
+ const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
2009
+ const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
2010
+ const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
2011
+ const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
2012
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
2013
+ te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
2014
+ te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
2015
+ te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
2016
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
2017
+ te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
2018
+ te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
2019
+ te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
2020
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
2021
+ te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
2022
+ te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
2023
+ te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
2024
+ te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
2025
+ te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
2026
+ te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
2027
+ te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
2028
+ return this;
2029
+ }
2030
+ multiplyScalar(s) {
2031
+ const te = this.elements;
2032
+ te[0] *= s;
2033
+ te[4] *= s;
2034
+ te[8] *= s;
2035
+ te[12] *= s;
2036
+ te[1] *= s;
2037
+ te[5] *= s;
2038
+ te[9] *= s;
2039
+ te[13] *= s;
2040
+ te[2] *= s;
2041
+ te[6] *= s;
2042
+ te[10] *= s;
2043
+ te[14] *= s;
2044
+ te[3] *= s;
2045
+ te[7] *= s;
2046
+ te[11] *= s;
2047
+ te[15] *= s;
2048
+ return this;
2049
+ }
2050
+ determinant() {
2051
+ const te = this.elements;
2052
+ const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
2053
+ const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
2054
+ const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
2055
+ const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
2056
+ 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);
2057
+ }
2058
+ transpose() {
2059
+ const te = this.elements;
2060
+ let tmp;
2061
+ tmp = te[1];
2062
+ te[1] = te[4];
2063
+ te[4] = tmp;
2064
+ tmp = te[2];
2065
+ te[2] = te[8];
2066
+ te[8] = tmp;
2067
+ tmp = te[6];
2068
+ te[6] = te[9];
2069
+ te[9] = tmp;
2070
+ tmp = te[3];
2071
+ te[3] = te[12];
2072
+ te[12] = tmp;
2073
+ tmp = te[7];
2074
+ te[7] = te[13];
2075
+ te[13] = tmp;
2076
+ tmp = te[11];
2077
+ te[11] = te[14];
2078
+ te[14] = tmp;
2079
+ return this;
2080
+ }
2081
+ setPosition(x, y, z) {
2082
+ const te = this.elements;
2083
+ if (x.isVector3) {
2084
+ te[12] = x.x;
2085
+ te[13] = x.y;
2086
+ te[14] = x.z;
2087
+ } else {
2088
+ te[12] = x;
2089
+ te[13] = y;
2090
+ te[14] = z;
2091
+ }
2092
+ return this;
2093
+ }
2094
+ invert() {
2095
+ 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;
2096
+ const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
2097
+ if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2098
+ const detInv = 1 / det;
2099
+ te[0] = t11 * detInv;
2100
+ te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
2101
+ te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
2102
+ te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
2103
+ te[4] = t12 * detInv;
2104
+ te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
2105
+ te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
2106
+ te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
2107
+ te[8] = t13 * detInv;
2108
+ te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
2109
+ te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
2110
+ te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
2111
+ te[12] = t14 * detInv;
2112
+ te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
2113
+ te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
2114
+ te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
2115
+ return this;
2116
+ }
2117
+ scale(v) {
2118
+ const te = this.elements;
2119
+ const x = v.x, y = v.y, z = v.z;
2120
+ te[0] *= x;
2121
+ te[4] *= y;
2122
+ te[8] *= z;
2123
+ te[1] *= x;
2124
+ te[5] *= y;
2125
+ te[9] *= z;
2126
+ te[2] *= x;
2127
+ te[6] *= y;
2128
+ te[10] *= z;
2129
+ te[3] *= x;
2130
+ te[7] *= y;
2131
+ te[11] *= z;
2132
+ return this;
2133
+ }
2134
+ getMaxScaleOnAxis() {
2135
+ const te = this.elements;
2136
+ const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
2137
+ const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
2138
+ const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
2139
+ return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
2140
+ }
2141
+ makeTranslation(x, y, z) {
2142
+ if (x.isVector3) {
2143
+ this.set(
2144
+ 1,
2145
+ 0,
2146
+ 0,
2147
+ x.x,
2148
+ 0,
2149
+ 1,
2150
+ 0,
2151
+ x.y,
2152
+ 0,
2153
+ 0,
2154
+ 1,
2155
+ x.z,
2156
+ 0,
2157
+ 0,
2158
+ 0,
2159
+ 1
2160
+ );
2161
+ } else {
2162
+ this.set(
2163
+ 1,
2164
+ 0,
2165
+ 0,
2166
+ x,
2167
+ 0,
2168
+ 1,
2169
+ 0,
2170
+ y,
2171
+ 0,
2172
+ 0,
2173
+ 1,
2174
+ z,
2175
+ 0,
2176
+ 0,
2177
+ 0,
2178
+ 1
2179
+ );
2180
+ }
2181
+ return this;
2182
+ }
2183
+ makeRotationX(theta) {
2184
+ const c = Math.cos(theta), s = Math.sin(theta);
2185
+ this.set(
2186
+ 1,
2187
+ 0,
2188
+ 0,
2189
+ 0,
2190
+ 0,
2191
+ c,
2192
+ -s,
2193
+ 0,
2194
+ 0,
2195
+ s,
2196
+ c,
2197
+ 0,
2198
+ 0,
2199
+ 0,
2200
+ 0,
2201
+ 1
2202
+ );
2203
+ return this;
2204
+ }
2205
+ makeRotationY(theta) {
2206
+ const c = Math.cos(theta), s = Math.sin(theta);
2207
+ this.set(
2208
+ c,
2209
+ 0,
2210
+ s,
2211
+ 0,
2212
+ 0,
2213
+ 1,
2214
+ 0,
2215
+ 0,
2216
+ -s,
2217
+ 0,
2218
+ c,
2219
+ 0,
2220
+ 0,
2221
+ 0,
2222
+ 0,
2223
+ 1
2224
+ );
2225
+ return this;
2226
+ }
2227
+ makeRotationZ(theta) {
2228
+ const c = Math.cos(theta), s = Math.sin(theta);
2229
+ this.set(
2230
+ c,
2231
+ -s,
2232
+ 0,
2233
+ 0,
2234
+ s,
2235
+ c,
2236
+ 0,
2237
+ 0,
2238
+ 0,
2239
+ 0,
2240
+ 1,
2241
+ 0,
2242
+ 0,
2243
+ 0,
2244
+ 0,
2245
+ 1
2246
+ );
2247
+ return this;
2248
+ }
2249
+ makeRotationAxis(axis, angle) {
2250
+ const c = Math.cos(angle);
2251
+ const s = Math.sin(angle);
2252
+ const t = 1 - c;
2253
+ const x = axis.x, y = axis.y, z = axis.z;
2254
+ const tx = t * x, ty = t * y;
2255
+ this.set(
2256
+ tx * x + c,
2257
+ tx * y - s * z,
2258
+ tx * z + s * y,
2259
+ 0,
2260
+ tx * y + s * z,
2261
+ ty * y + c,
2262
+ ty * z - s * x,
2263
+ 0,
2264
+ tx * z - s * y,
2265
+ ty * z + s * x,
2266
+ t * z * z + c,
2267
+ 0,
2268
+ 0,
2269
+ 0,
2270
+ 0,
2271
+ 1
2272
+ );
2273
+ return this;
2274
+ }
2275
+ makeScale(x, y, z) {
2276
+ this.set(
2277
+ x,
2278
+ 0,
2279
+ 0,
2280
+ 0,
2281
+ 0,
2282
+ y,
2283
+ 0,
2284
+ 0,
2285
+ 0,
2286
+ 0,
2287
+ z,
2288
+ 0,
2289
+ 0,
2290
+ 0,
2291
+ 0,
2292
+ 1
2293
+ );
2294
+ return this;
2295
+ }
2296
+ makeShear(xy, xz, yx, yz, zx, zy) {
2297
+ this.set(
2298
+ 1,
2299
+ yx,
2300
+ zx,
2301
+ 0,
2302
+ xy,
2303
+ 1,
2304
+ zy,
2305
+ 0,
2306
+ xz,
2307
+ yz,
2308
+ 1,
2309
+ 0,
2310
+ 0,
2311
+ 0,
2312
+ 0,
2313
+ 1
2314
+ );
2315
+ return this;
2316
+ }
2317
+ compose(position, quaternion, scale) {
2318
+ const te = this.elements;
2319
+ const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
2320
+ const x2 = x + x, y2 = y + y, z2 = z + z;
2321
+ const xx = x * x2, xy = x * y2, xz = x * z2;
2322
+ const yy = y * y2, yz = y * z2, zz = z * z2;
2323
+ const wx = w * x2, wy = w * y2, wz = w * z2;
2324
+ const sx = scale.x, sy = scale.y, sz = scale.z;
2325
+ te[0] = (1 - (yy + zz)) * sx;
2326
+ te[1] = (xy + wz) * sx;
2327
+ te[2] = (xz - wy) * sx;
2328
+ te[3] = 0;
2329
+ te[4] = (xy - wz) * sy;
2330
+ te[5] = (1 - (xx + zz)) * sy;
2331
+ te[6] = (yz + wx) * sy;
2332
+ te[7] = 0;
2333
+ te[8] = (xz + wy) * sz;
2334
+ te[9] = (yz - wx) * sz;
2335
+ te[10] = (1 - (xx + yy)) * sz;
2336
+ te[11] = 0;
2337
+ te[12] = position.x;
2338
+ te[13] = position.y;
2339
+ te[14] = position.z;
2340
+ te[15] = 1;
2341
+ return this;
2342
+ }
2343
+ decompose(position, quaternion, scale) {
2344
+ const te = this.elements;
2345
+ let sx = _v1.set(te[0], te[1], te[2]).length();
2346
+ const sy = _v1.set(te[4], te[5], te[6]).length();
2347
+ const sz = _v1.set(te[8], te[9], te[10]).length();
2348
+ const det = this.determinant();
2349
+ if (det < 0) sx = -sx;
2350
+ position.x = te[12];
2351
+ position.y = te[13];
2352
+ position.z = te[14];
2353
+ _m1.copy(this);
2354
+ const invSX = 1 / sx;
2355
+ const invSY = 1 / sy;
2356
+ const invSZ = 1 / sz;
2357
+ _m1.elements[0] *= invSX;
2358
+ _m1.elements[1] *= invSX;
2359
+ _m1.elements[2] *= invSX;
2360
+ _m1.elements[4] *= invSY;
2361
+ _m1.elements[5] *= invSY;
2362
+ _m1.elements[6] *= invSY;
2363
+ _m1.elements[8] *= invSZ;
2364
+ _m1.elements[9] *= invSZ;
2365
+ _m1.elements[10] *= invSZ;
2366
+ quaternion.setFromRotationMatrix(_m1);
2367
+ scale.x = sx;
2368
+ scale.y = sy;
2369
+ scale.z = sz;
2370
+ return this;
2371
+ }
2372
+ makePerspective(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
2373
+ const te = this.elements;
2374
+ const x = 2 * near / (right - left);
2375
+ const y = 2 * near / (top - bottom);
2376
+ const a = (right + left) / (right - left);
2377
+ const b = (top + bottom) / (top - bottom);
2378
+ let c, d;
2379
+ if (coordinateSystem === WebGLCoordinateSystem) {
2380
+ c = -(far + near) / (far - near);
2381
+ d = -2 * far * near / (far - near);
2382
+ } else if (coordinateSystem === WebGPUCoordinateSystem) {
2383
+ c = -far / (far - near);
2384
+ d = -far * near / (far - near);
2385
+ } else {
2386
+ throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + coordinateSystem);
2387
+ }
2388
+ te[0] = x;
2389
+ te[4] = 0;
2390
+ te[8] = a;
2391
+ te[12] = 0;
2392
+ te[1] = 0;
2393
+ te[5] = y;
2394
+ te[9] = b;
2395
+ te[13] = 0;
2396
+ te[2] = 0;
2397
+ te[6] = 0;
2398
+ te[10] = c;
2399
+ te[14] = d;
2400
+ te[3] = 0;
2401
+ te[7] = 0;
2402
+ te[11] = -1;
2403
+ te[15] = 0;
2404
+ return this;
2405
+ }
2406
+ makeOrthographic(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
2407
+ const te = this.elements;
2408
+ const w = 1 / (right - left);
2409
+ const h = 1 / (top - bottom);
2410
+ const p = 1 / (far - near);
2411
+ const x = (right + left) * w;
2412
+ const y = (top + bottom) * h;
2413
+ let z, zInv;
2414
+ if (coordinateSystem === WebGLCoordinateSystem) {
2415
+ z = (far + near) * p;
2416
+ zInv = -2 * p;
2417
+ } else if (coordinateSystem === WebGPUCoordinateSystem) {
2418
+ z = near * p;
2419
+ zInv = -1 * p;
2420
+ } else {
2421
+ throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + coordinateSystem);
2422
+ }
2423
+ te[0] = 2 * w;
2424
+ te[4] = 0;
2425
+ te[8] = 0;
2426
+ te[12] = -x;
2427
+ te[1] = 0;
2428
+ te[5] = 2 * h;
2429
+ te[9] = 0;
2430
+ te[13] = -y;
2431
+ te[2] = 0;
2432
+ te[6] = 0;
2433
+ te[10] = zInv;
2434
+ te[14] = -z;
2435
+ te[3] = 0;
2436
+ te[7] = 0;
2437
+ te[11] = 0;
2438
+ te[15] = 1;
2439
+ return this;
2440
+ }
2441
+ equals(matrix) {
2442
+ const te = this.elements;
2443
+ const me = matrix.elements;
2444
+ for (let i = 0; i < 16; i++) {
2445
+ if (te[i] !== me[i]) return false;
2446
+ }
2447
+ return true;
2448
+ }
2449
+ fromArray(array, offset = 0) {
2450
+ for (let i = 0; i < 16; i++) {
2451
+ this.elements[i] = array[i + offset];
2452
+ }
2453
+ return this;
2454
+ }
2455
+ toArray(array = [], offset = 0) {
2456
+ const te = this.elements;
2457
+ array[offset] = te[0];
2458
+ array[offset + 1] = te[1];
2459
+ array[offset + 2] = te[2];
2460
+ array[offset + 3] = te[3];
2461
+ array[offset + 4] = te[4];
2462
+ array[offset + 5] = te[5];
2463
+ array[offset + 6] = te[6];
2464
+ array[offset + 7] = te[7];
2465
+ array[offset + 8] = te[8];
2466
+ array[offset + 9] = te[9];
2467
+ array[offset + 10] = te[10];
2468
+ array[offset + 11] = te[11];
2469
+ array[offset + 12] = te[12];
2470
+ array[offset + 13] = te[13];
2471
+ array[offset + 14] = te[14];
2472
+ array[offset + 15] = te[15];
2473
+ return array;
2474
+ }
2475
+ }
2476
+ const _v1 = /* @__PURE__ */ new Vector3();
2477
+ const _m1 = /* @__PURE__ */ new Matrix4();
2478
+ const _zero = /* @__PURE__ */ new Vector3(0, 0, 0);
2479
+ const _one = /* @__PURE__ */ new Vector3(1, 1, 1);
2480
+ const _x = /* @__PURE__ */ new Vector3();
2481
+ const _y = /* @__PURE__ */ new Vector3();
2482
+ const _z = /* @__PURE__ */ new Vector3();
2483
+ const _matrix = /* @__PURE__ */ new Matrix4();
2484
+ const _quaternion = /* @__PURE__ */ new Quaternion();
2485
+ class Euler {
2486
+ constructor(x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER) {
2487
+ this.isEuler = true;
2488
+ this._x = x;
2489
+ this._y = y;
2490
+ this._z = z;
2491
+ this._order = order;
2492
+ }
2493
+ get x() {
2494
+ return this._x;
2495
+ }
2496
+ set x(value) {
2497
+ this._x = value;
2498
+ this._onChangeCallback();
2499
+ }
2500
+ get y() {
2501
+ return this._y;
2502
+ }
2503
+ set y(value) {
2504
+ this._y = value;
2505
+ this._onChangeCallback();
2506
+ }
2507
+ get z() {
2508
+ return this._z;
2509
+ }
2510
+ set z(value) {
2511
+ this._z = value;
2512
+ this._onChangeCallback();
2513
+ }
2514
+ get order() {
2515
+ return this._order;
2516
+ }
2517
+ set order(value) {
2518
+ this._order = value;
2519
+ this._onChangeCallback();
2520
+ }
2521
+ set(x, y, z, order = this._order) {
2522
+ this._x = x;
2523
+ this._y = y;
2524
+ this._z = z;
2525
+ this._order = order;
2526
+ this._onChangeCallback();
2527
+ return this;
2528
+ }
2529
+ clone() {
2530
+ return new this.constructor(this._x, this._y, this._z, this._order);
2531
+ }
2532
+ copy(euler) {
2533
+ this._x = euler._x;
2534
+ this._y = euler._y;
2535
+ this._z = euler._z;
2536
+ this._order = euler._order;
2537
+ this._onChangeCallback();
2538
+ return this;
2539
+ }
2540
+ setFromRotationMatrix(m, order = this._order, update = true) {
2541
+ const te = m.elements;
2542
+ const m11 = te[0], m12 = te[4], m13 = te[8];
2543
+ const m21 = te[1], m22 = te[5], m23 = te[9];
2544
+ const m31 = te[2], m32 = te[6], m33 = te[10];
2545
+ switch (order) {
2546
+ case "XYZ":
2547
+ this._y = Math.asin(clamp(m13, -1, 1));
2548
+ if (Math.abs(m13) < 0.9999999) {
2549
+ this._x = Math.atan2(-m23, m33);
2550
+ this._z = Math.atan2(-m12, m11);
2551
+ } else {
2552
+ this._x = Math.atan2(m32, m22);
2553
+ this._z = 0;
2554
+ }
2555
+ break;
2556
+ case "YXZ":
2557
+ this._x = Math.asin(-clamp(m23, -1, 1));
2558
+ if (Math.abs(m23) < 0.9999999) {
2559
+ this._y = Math.atan2(m13, m33);
2560
+ this._z = Math.atan2(m21, m22);
2561
+ } else {
2562
+ this._y = Math.atan2(-m31, m11);
2563
+ this._z = 0;
2564
+ }
2565
+ break;
2566
+ case "ZXY":
2567
+ this._x = Math.asin(clamp(m32, -1, 1));
2568
+ if (Math.abs(m32) < 0.9999999) {
2569
+ this._y = Math.atan2(-m31, m33);
2570
+ this._z = Math.atan2(-m12, m22);
2571
+ } else {
2572
+ this._y = 0;
2573
+ this._z = Math.atan2(m21, m11);
2574
+ }
2575
+ break;
2576
+ case "ZYX":
2577
+ this._y = Math.asin(-clamp(m31, -1, 1));
2578
+ if (Math.abs(m31) < 0.9999999) {
2579
+ this._x = Math.atan2(m32, m33);
2580
+ this._z = Math.atan2(m21, m11);
2581
+ } else {
2582
+ this._x = 0;
2583
+ this._z = Math.atan2(-m12, m22);
2584
+ }
2585
+ break;
2586
+ case "YZX":
2587
+ this._z = Math.asin(clamp(m21, -1, 1));
2588
+ if (Math.abs(m21) < 0.9999999) {
2589
+ this._x = Math.atan2(-m23, m22);
2590
+ this._y = Math.atan2(-m31, m11);
2591
+ } else {
2592
+ this._x = 0;
2593
+ this._y = Math.atan2(m13, m33);
2594
+ }
2595
+ break;
2596
+ case "XZY":
2597
+ this._z = Math.asin(-clamp(m12, -1, 1));
2598
+ if (Math.abs(m12) < 0.9999999) {
2599
+ this._x = Math.atan2(m32, m22);
2600
+ this._y = Math.atan2(m13, m11);
2601
+ } else {
2602
+ this._x = Math.atan2(-m23, m33);
2603
+ this._y = 0;
2604
+ }
2605
+ break;
2606
+ default:
2607
+ console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + order);
2608
+ }
2609
+ this._order = order;
2610
+ if (update === true) this._onChangeCallback();
2611
+ return this;
2612
+ }
2613
+ setFromQuaternion(q, order, update) {
2614
+ _matrix.makeRotationFromQuaternion(q);
2615
+ return this.setFromRotationMatrix(_matrix, order, update);
2616
+ }
2617
+ setFromVector3(v, order = this._order) {
2618
+ return this.set(v.x, v.y, v.z, order);
2619
+ }
2620
+ reorder(newOrder) {
2621
+ _quaternion.setFromEuler(this);
2622
+ return this.setFromQuaternion(_quaternion, newOrder);
2623
+ }
2624
+ equals(euler) {
2625
+ return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
2626
+ }
2627
+ fromArray(array) {
2628
+ this._x = array[0];
2629
+ this._y = array[1];
2630
+ this._z = array[2];
2631
+ if (array[3] !== void 0) this._order = array[3];
2632
+ this._onChangeCallback();
2633
+ return this;
2634
+ }
2635
+ toArray(array = [], offset = 0) {
2636
+ array[offset] = this._x;
2637
+ array[offset + 1] = this._y;
2638
+ array[offset + 2] = this._z;
2639
+ array[offset + 3] = this._order;
2640
+ return array;
2641
+ }
2642
+ _onChange(callback) {
2643
+ this._onChangeCallback = callback;
2644
+ return this;
2645
+ }
2646
+ _onChangeCallback() {
2647
+ }
2648
+ *[Symbol.iterator]() {
2649
+ yield this._x;
2650
+ yield this._y;
2651
+ yield this._z;
2652
+ yield this._order;
2653
+ }
2654
+ }
2655
+ Euler.DEFAULT_ORDER = "XYZ";
647
2656
  const blenderObjectTypes = {
2657
+ empty: 0,
648
2658
  mesh: 1,
649
- lamp: 10
2659
+ lamp: 10,
2660
+ camera: 11
650
2661
  };
651
- async function createObjects(file) {
2662
+ async function createObjects(file, ctx) {
652
2663
  const objects = [];
653
- const blendObjects = file.objects.Object;
2664
+ const childMap = /* @__PURE__ */ new Map();
2665
+ const objMap = /* @__PURE__ */ new Map();
2666
+ const blendObjects = file.objects.Object ?? [];
2667
+ const loaded = /* @__PURE__ */ new WeakMap();
654
2668
  for (const object of blendObjects) {
2669
+ if (loaded.has(object)) {
2670
+ console.warn("BlendLoader - duplicate object");
2671
+ continue;
2672
+ }
2673
+ let obj = void 0;
655
2674
  switch (object.type) {
2675
+ case blenderObjectTypes.empty:
2676
+ obj = new ctx.Object3D();
2677
+ break;
656
2678
  case blenderObjectTypes.mesh:
657
- objects.push(createMesh(object));
2679
+ obj = createMesh(object, loaded, ctx);
658
2680
  break;
659
2681
  case blenderObjectTypes.lamp:
660
- objects.push(createLight(object));
2682
+ obj = createLight(object, ctx);
2683
+ break;
2684
+ case blenderObjectTypes.camera:
2685
+ obj = createCamera(object, ctx);
661
2686
  break;
662
2687
  default:
663
- console.warn("Unsupported object type", object.type);
2688
+ obj = new ctx.Object3D();
2689
+ console.warn("Unsupported object type", object.type, object, obj);
2690
+ }
2691
+ if (obj) {
2692
+ setTransform(object, obj);
2693
+ const exChildren = childMap.get(object);
2694
+ if (exChildren) {
2695
+ for (const exChild of exChildren) {
2696
+ obj.add(exChild);
2697
+ }
2698
+ childMap.delete(object);
2699
+ }
2700
+ objMap.set(object, obj);
2701
+ if (object.parent === object) {
2702
+ console.error("BlendLoader - invalid, parent same as object, adding to root", object);
2703
+ objects.push(obj);
2704
+ } else if (!object.parent) {
2705
+ objects.push(obj);
2706
+ } else {
2707
+ const parent = objMap.get(object.parent);
2708
+ if (!parent) {
2709
+ const chi = childMap.get(object.parent) ?? [];
2710
+ chi.push(obj);
2711
+ childMap.set(object, chi);
2712
+ } else {
2713
+ parent.add(obj);
2714
+ }
2715
+ }
2716
+ loaded.set(object, obj);
664
2717
  }
665
2718
  }
2719
+ if (childMap.size) {
2720
+ const vals = [...childMap.values()].flat();
2721
+ console.warn("BlendLoader - unknown objects with parents, adding to root", vals, childMap);
2722
+ objects.push(...vals);
2723
+ }
666
2724
  return objects.filter((o) => !!o);
667
2725
  }
2726
+ const eulerModes = {
2727
+ [1]: "XYZ",
2728
+ [2]: "XZY",
2729
+ [3]: "YXZ",
2730
+ [4]: "YZX",
2731
+ [5]: "ZXY",
2732
+ [6]: "ZYX"
2733
+ };
2734
+ function setTransform(object, obj) {
2735
+ obj.name = object.aname;
2736
+ obj.scale.set(object.size[0], object.size[2], object.size[1]);
2737
+ obj.position.set(object.loc[0], object.loc[2], -object.loc[1]);
2738
+ if (!object.rotmode || object.rotmode === 0) {
2739
+ obj.quaternion.set(object.quat[1], object.quat[3], -object.quat[2], object.quat[0]);
2740
+ } else {
2741
+ const order = eulerModes[object.rotmode] ?? "XYZ";
2742
+ const quat = new three.Quaternion().setFromEuler(new Euler(object.rot[0], object.rot[1], object.rot[2], order.split("").reverse().join("")));
2743
+ obj.quaternion.set(quat.x, quat.z, -quat.y, quat.w);
2744
+ }
2745
+ if (object.type === blenderObjectTypes.camera)
2746
+ obj.quaternion.multiply(new three.Quaternion().setFromAxisAngle(new three.Vector3(1, 0, 0), -Math.PI / 2));
2747
+ obj.updateMatrix();
2748
+ if (obj.setDirty) obj.setDirty();
2749
+ }
668
2750
  const _BlendLoadPlugin = class _BlendLoadPlugin extends threepipe.BaseImporterPlugin {
669
2751
  constructor() {
670
2752
  super();
@@ -673,13 +2755,28 @@
673
2755
  this.setResponseType("arraybuffer");
674
2756
  const res = await super.loadAsync(url, onProgress);
675
2757
  const blend = await parseBlend(res);
676
- const objects = await createObjects(blend);
2758
+ const ctx = {
2759
+ Object3D: threepipe.Object3D2,
2760
+ Mesh: threepipe.Mesh2,
2761
+ MeshPhysicalMaterial: threepipe.PhysicalMaterial,
2762
+ PerspectiveCamera: threepipe.PerspectiveCamera0,
2763
+ OrthographicCamera: threepipe.OrthographicCamera0,
2764
+ PointLight: threepipe.PointLight2,
2765
+ BufferGeometry: threepipe.BufferGeometry2,
2766
+ BufferAttribute: threepipe.BufferAttribute
2767
+ };
2768
+ const objects = await createObjects(blend, ctx);
677
2769
  const root = new threepipe.Object3D();
678
2770
  root.add(...objects);
2771
+ root.userData.autoScaled = true;
2772
+ root.userData.autoCentered = true;
679
2773
  blend.scene = root;
680
2774
  return blend;
681
2775
  }
682
- transform(res, _) {
2776
+ transform(res, options) {
2777
+ if (typeof options.onBlendLoad === "function") {
2778
+ options.onBlendLoad(res);
2779
+ }
683
2780
  return res.scene;
684
2781
  }
685
2782
  }, ["blend"], ["application/x-blender"], true);