@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 +62 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -52
- package/dist/index.mjs.map +1 -1
- package/dist/loader/geometry.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/BlendLoadPlugin.ts +2 -2
- package/src/js-blend/parser/parser.js +31 -33
- package/src/loader/geometry.ts +34 -27
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.
|
|
@@ -412,6 +412,15 @@ function worker_code() {
|
|
|
412
412
|
function toString(buffer, _in, _out) {
|
|
413
413
|
return String.fromCharCode.apply(String, new Uint8Array(buffer, _in, _out - _in));
|
|
414
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
|
+
}
|
|
415
424
|
function readFile() {
|
|
416
425
|
let count = 0;
|
|
417
426
|
let offset2 = 0;
|
|
@@ -462,14 +471,13 @@ function worker_code() {
|
|
|
462
471
|
offset2++;
|
|
463
472
|
curr_count++;
|
|
464
473
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
offset2++;
|
|
469
|
-
}
|
|
474
|
+
for (let j = 0; j < 8; j++) {
|
|
475
|
+
if (seekCheck(data, offset2, "TYPE")) break;
|
|
476
|
+
offset2++;
|
|
470
477
|
}
|
|
471
|
-
if (
|
|
472
|
-
|
|
478
|
+
if (!seekCheck(data, offset2, "TYPE")) {
|
|
479
|
+
ERROR = "Unexpected alignment error in SDNA parsing";
|
|
480
|
+
break;
|
|
473
481
|
}
|
|
474
482
|
offset2 += 4;
|
|
475
483
|
count = data.getUint32(offset2, true);
|
|
@@ -485,14 +493,13 @@ function worker_code() {
|
|
|
485
493
|
offset2++;
|
|
486
494
|
curr_count++;
|
|
487
495
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
offset2++;
|
|
492
|
-
}
|
|
496
|
+
for (let j = 0; j < 8; j++) {
|
|
497
|
+
if (seekCheck(data, offset2, "TLEN")) break;
|
|
498
|
+
offset2++;
|
|
493
499
|
}
|
|
494
|
-
if (
|
|
495
|
-
|
|
500
|
+
if (!seekCheck(data, offset2, "TLEN")) {
|
|
501
|
+
ERROR = "Unexpected alignment error in SDNA parsing";
|
|
502
|
+
break;
|
|
496
503
|
}
|
|
497
504
|
offset2 += 4;
|
|
498
505
|
curr_count = 0;
|
|
@@ -501,14 +508,13 @@ function worker_code() {
|
|
|
501
508
|
offset2 += 2;
|
|
502
509
|
curr_count++;
|
|
503
510
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
offset2++;
|
|
508
|
-
}
|
|
511
|
+
for (let j = 0; j < 8; j++) {
|
|
512
|
+
if (seekCheck(data, offset2, "STRC")) break;
|
|
513
|
+
offset2++;
|
|
509
514
|
}
|
|
510
|
-
if (
|
|
511
|
-
|
|
515
|
+
if (!seekCheck(data, offset2, "STRC")) {
|
|
516
|
+
ERROR = "Unexpected alignment error in SDNA parsing";
|
|
517
|
+
break;
|
|
512
518
|
}
|
|
513
519
|
offset2 += 4;
|
|
514
520
|
const structure_count = data.getInt32(offset2, BIG_ENDIAN);
|
|
@@ -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
|
}
|
|
@@ -2766,8 +2778,6 @@ const _BlendLoadPlugin = class _BlendLoadPlugin extends BaseImporterPlugin {
|
|
|
2766
2778
|
const objects = await createObjects(blend, ctx);
|
|
2767
2779
|
const root = new Object3D();
|
|
2768
2780
|
root.add(...objects);
|
|
2769
|
-
root.userData.autoScaled = true;
|
|
2770
|
-
root.userData.autoCentered = true;
|
|
2771
2781
|
blend.scene = root;
|
|
2772
2782
|
return blend;
|
|
2773
2783
|
}
|