@threepipe/plugin-blend-importer 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  })(this, function(exports2, threepipe, three) {
4
4
  "use strict";/**
5
5
  * @license
6
- * @threepipe/plugin-blend-importer v0.0.6
6
+ * @threepipe/plugin-blend-importer v0.0.7
7
7
  * Copyright 2022-2025 repalash <palash@shaders.app>
8
8
  * Apache-2.0 License
9
9
  * See ./dependencies.txt for any bundled third-party dependencies and licenses.
@@ -414,6 +414,15 @@
414
414
  function toString(buffer, _in, _out) {
415
415
  return String.fromCharCode.apply(String, new Uint8Array(buffer, _in, _out - _in));
416
416
  }
417
+ function seekCheck(buffer, _in, str) {
418
+ const length = str.length;
419
+ for (let i = 0; i < length; i++) {
420
+ if (buffer.getUint8(_in + i) !== str.charCodeAt(i)) {
421
+ return false;
422
+ }
423
+ }
424
+ return true;
425
+ }
417
426
  function readFile() {
418
427
  let count = 0;
419
428
  let offset2 = 0;
@@ -464,14 +473,13 @@
464
473
  offset2++;
465
474
  curr_count++;
466
475
  }
467
- if (toString(_data, offset2, offset2 + 4) !== "TYPE") {
468
- for (let j = 0; j < 8; j++) {
469
- if (toString(_data, offset2, offset2 + 4) === "TYPE") break;
470
- offset2++;
471
- }
476
+ for (let j = 0; j < 8; j++) {
477
+ if (seekCheck(data, offset2, "TYPE")) break;
478
+ offset2++;
472
479
  }
473
- if (toString(_data, offset2, offset2 + 4) !== "TYPE") {
474
- debugger;
480
+ if (!seekCheck(data, offset2, "TYPE")) {
481
+ ERROR = "Unexpected alignment error in SDNA parsing";
482
+ break;
475
483
  }
476
484
  offset2 += 4;
477
485
  count = data.getUint32(offset2, true);
@@ -487,14 +495,13 @@
487
495
  offset2++;
488
496
  curr_count++;
489
497
  }
490
- if (toString(_data, offset2, offset2 + 4) !== "TLEN") {
491
- for (let j = 0; j < 8; j++) {
492
- if (toString(_data, offset2, offset2 + 4) === "TLEN") break;
493
- offset2++;
494
- }
498
+ for (let j = 0; j < 8; j++) {
499
+ if (seekCheck(data, offset2, "TLEN")) break;
500
+ offset2++;
495
501
  }
496
- if (toString(_data, offset2, offset2 + 4) !== "TLEN") {
497
- debugger;
502
+ if (!seekCheck(data, offset2, "TLEN")) {
503
+ ERROR = "Unexpected alignment error in SDNA parsing";
504
+ break;
498
505
  }
499
506
  offset2 += 4;
500
507
  curr_count = 0;
@@ -503,14 +510,13 @@
503
510
  offset2 += 2;
504
511
  curr_count++;
505
512
  }
506
- if (toString(_data, offset2, offset2 + 4) !== "STRC") {
507
- for (let j = 0; j < 8; j++) {
508
- if (toString(_data, offset2, offset2 + 4) === "STRC") break;
509
- offset2++;
510
- }
513
+ for (let j = 0; j < 8; j++) {
514
+ if (seekCheck(data, offset2, "STRC")) break;
515
+ offset2++;
511
516
  }
512
- if (toString(_data, offset2, offset2 + 4) !== "STRC") {
513
- debugger;
517
+ if (!seekCheck(data, offset2, "STRC")) {
518
+ ERROR = "Unexpected alignment error in SDNA parsing";
519
+ break;
514
520
  }
515
521
  offset2 += 4;
516
522
  const structure_count = data.getInt32(offset2, BIG_ENDIAN);
@@ -714,12 +720,13 @@
714
720
  return layers[i];
715
721
  }
716
722
  function createBufferGeometry(meshData, ctx) {
717
- var _a;
718
723
  if (meshData.mpoly) return createBufferGeometryOld(meshData, ctx);
719
724
  const geometry = new ctx.BufferGeometry();
720
725
  geometry.name = meshData.aname || "";
721
726
  let vertices;
727
+ let verticesData;
722
728
  let indices;
729
+ let indicesData;
723
730
  if (meshData.vdata && meshData.vdata.layers && meshData.vdata.totlayer > 0) {
724
731
  for (let i = 0; i < meshData.vdata.totlayer; i++) {
725
732
  const layer = getLayer(meshData.vdata.layers, i);
@@ -729,6 +736,7 @@
729
736
  continue;
730
737
  }
731
738
  vertices = layer;
739
+ verticesData = data;
732
740
  }
733
741
  }
734
742
  }
@@ -741,6 +749,7 @@
741
749
  continue;
742
750
  }
743
751
  indices = layer;
752
+ indicesData = data;
744
753
  }
745
754
  }
746
755
  }
@@ -748,26 +757,26 @@
748
757
  if (meshData.poly_offset_indices && meshData.totpoly > 0) {
749
758
  faceIndices = [...new Int32Array(meshData.poly_offset_indices.__blender_file__.AB, meshData.poly_offset_indices.__data_address__, meshData.totpoly + 1)];
750
759
  }
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];
760
+ if (verticesData && verticesData.length > 0) {
761
+ const positions = new Float32Array(verticesData.length * 3);
762
+ for (let j = 0; j < verticesData.length; j++) {
763
+ const { x, y, z, co } = verticesData[j] || {};
764
+ if (x !== void 0) {
765
+ positions[j * 3] = x;
766
+ positions[j * 3 + 1] = z;
767
+ positions[j * 3 + 2] = -y;
768
+ } else if (co !== void 0) {
769
+ positions[j * 3] = co[0];
770
+ positions[j * 3 + 1] = co[2];
771
+ positions[j * 3 + 2] = -co[1];
763
772
  } else {
764
- console.error("BlendLoader - unknown vertex", vertex);
773
+ console.error("BlendLoader - unknown vertex", verticesData[j]);
765
774
  break;
766
775
  }
767
776
  }
768
777
  geometry.setAttribute("position", new ctx.BufferAttribute(positions, 3));
769
778
  }
770
- if ((indices == null ? void 0 : indices.data) && indices.data.length > 0 && ((_a = vertices == null ? void 0 : vertices.data) == null ? void 0 : _a.length)) {
779
+ if (indicesData && indicesData.length > 0 && (verticesData == null ? void 0 : verticesData.length)) {
771
780
  const faceSize = meshData.totloop / meshData.totpoly;
772
781
  if (faceIndices.length > 0) {
773
782
  let totalTriangles = 0;
@@ -782,11 +791,11 @@
782
791
  const faceEnd = faceIndices[i + 1];
783
792
  const faceVertCount = faceEnd - faceStart;
784
793
  if (faceVertCount >= 3) {
785
- const firstVert = indices.data[faceStart].i;
794
+ const firstVert = indicesData[faceStart].i;
786
795
  for (let k = 1; k < faceVertCount - 1; k++) {
787
796
  indexes[t++] = firstVert;
788
- indexes[t++] = indices.data[faceStart + k].i;
789
- indexes[t++] = indices.data[faceStart + k + 1].i;
797
+ indexes[t++] = indicesData[faceStart + k].i;
798
+ indexes[t++] = indicesData[faceStart + k + 1].i;
790
799
  }
791
800
  }
792
801
  }
@@ -841,21 +850,24 @@
841
850
  if (indexi - 1 + l < len)
842
851
  index += indexi - 1 + l;
843
852
  const loop = loops[index];
844
- const vert = vertices[loop.v];
853
+ const { co, no } = vertices[loop.v] || {};
845
854
  indices[currentIndex] = currentIndex;
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];
855
+ if (co) {
856
+ positions[currentIndex * 3 + 0] = co[0];
857
+ positions[currentIndex * 3 + 1] = co[2];
858
+ positions[currentIndex * 3 + 2] = -co[1];
859
+ }
860
+ if (no) {
861
+ normals[currentIndex * 3 + 0] = no[0];
862
+ normals[currentIndex * 3 + 1] = no[2];
863
+ normals[currentIndex * 3 + 2] = -no[1];
853
864
  } else {
854
865
  computeNormals = true;
855
866
  }
856
867
  if (uv) {
857
- uvs[currentIndex * 2 + 0] = uv[index].uv[0];
858
- uvs[currentIndex * 2 + 1] = uv[index].uv[1];
868
+ const uv1 = uv[index].uv;
869
+ uvs[currentIndex * 2 + 0] = uv1[0];
870
+ uvs[currentIndex * 2 + 1] = uv1[1];
859
871
  }
860
872
  currentIndex++;
861
873
  }
@@ -2768,8 +2780,6 @@
2768
2780
  const objects = await createObjects(blend, ctx);
2769
2781
  const root = new threepipe.Object3D();
2770
2782
  root.add(...objects);
2771
- root.userData.autoScaled = true;
2772
- root.userData.autoCentered = true;
2773
2783
  blend.scene = root;
2774
2784
  return blend;
2775
2785
  }