@needle-tools/gltf-build-pipeline 2.10.2 → 2.11.0-next.0ac327c
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.
|
@@ -20,13 +20,13 @@ export type ProgressiveTextureModel = ProgressiveLoadingInfo & {
|
|
|
20
20
|
lods?: Array<ProgressiveTextureLodEntry>;
|
|
21
21
|
};
|
|
22
22
|
export type ProgressiveMeshModel = ProgressiveLoadingInfo & {
|
|
23
|
-
/** LOD0 vertex density. TODO: remove this since we now have a LODs array. This is just for supporting older engine versions */
|
|
24
|
-
density: number;
|
|
25
23
|
lods?: Array<LodInfo & {
|
|
26
|
-
/** Mesh vertex density */
|
|
24
|
+
/** @deprecated Mesh vertex density TODO: remove in the future */
|
|
27
25
|
density: number;
|
|
28
26
|
vertexCount: number;
|
|
29
27
|
indexCount: number;
|
|
28
|
+
/** Densities per primitive */
|
|
29
|
+
densities?: Array<number>;
|
|
30
30
|
}>;
|
|
31
31
|
};
|
|
32
32
|
export declare class NEEDLE_progressive extends Extension {
|
|
@@ -549,7 +549,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
549
549
|
// const t = l / MAX_LODS;
|
|
550
550
|
const latest = LODS[LODS.length - 1];
|
|
551
551
|
const ratio = latest.ratio * .5;
|
|
552
|
-
let error =
|
|
552
|
+
let error = 0.003;
|
|
553
553
|
if (opts.config.usecase === "product") {
|
|
554
554
|
error *= .5;
|
|
555
555
|
}
|
|
@@ -688,7 +688,8 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
688
688
|
let primitiveIndex = 0;
|
|
689
689
|
const lodLevelInFile = generatedLODInfos.length;
|
|
690
690
|
const clonedData = { primitives: [], weights: [...mesh.getWeights()] };
|
|
691
|
-
|
|
691
|
+
// const primitiveDensities = new Array<number>(mesh.listPrimitives().length);
|
|
692
|
+
mesh.listPrimitives().forEach((prim, index) => {
|
|
692
693
|
const data = clonePrimitiveData(prim, logger);
|
|
693
694
|
if (data != null) {
|
|
694
695
|
clonedData.primitives.push(data);
|
|
@@ -697,10 +698,11 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
697
698
|
const lastLod = LODS[lodLevelInFile];
|
|
698
699
|
// TODO: this should be run after simplification but then we need to change the runtime to use the LOD 0 density
|
|
699
700
|
const density = calculateMeshDensity(prim);
|
|
701
|
+
// primitiveDensities[index] = density;
|
|
700
702
|
maxDensity = Math.max(maxDensity, density);
|
|
701
703
|
const task = simplifyMesh(doc, mesh, prim, primitiveIndex++, lastLod);
|
|
702
704
|
tasks.push(task);
|
|
703
|
-
}
|
|
705
|
+
});
|
|
704
706
|
await Promise.all(tasks);
|
|
705
707
|
tasks.length = 0;
|
|
706
708
|
const { totalVertexCount: totalVertexCountAfter } = getMeshInformation(mesh);
|
|
@@ -741,11 +743,11 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
741
743
|
path: l.path,
|
|
742
744
|
hash: l.content_hash.toString(),
|
|
743
745
|
density: l.density,
|
|
746
|
+
densities: l.densities,
|
|
744
747
|
vertexCount: l.lodMeshInfo?.totalVertexCount,
|
|
745
748
|
indexCount: l.lodMeshInfo?.totalIndexCount,
|
|
746
749
|
};
|
|
747
750
|
}),
|
|
748
|
-
density: maxDensity,
|
|
749
751
|
});
|
|
750
752
|
mesh.setExtension(NEEDLE_PROGRESSIVE_EXTENSION_NAME, model);
|
|
751
753
|
index++;
|
|
@@ -825,7 +827,7 @@ async function createMeshLod(inputFileName, doc, basePath, level, mesh, meshInfo
|
|
|
825
827
|
if (cachedValue && meta) {
|
|
826
828
|
logger.info(`[${NAME}] LOD ${level} loaded from cache for \"${mesh.getName()}\"`);
|
|
827
829
|
writeFileSync(outPath, cachedValue);
|
|
828
|
-
return { level, path: fileName, success: true, cacheKey, content_hash: hash, lodMeshInfo: meta.meshInfo, density: meta.density };
|
|
830
|
+
return { level, path: fileName, success: true, cacheKey, content_hash: hash, lodMeshInfo: meta.meshInfo, density: meta.density, densities: meta.densities };
|
|
829
831
|
}
|
|
830
832
|
}
|
|
831
833
|
const newDoc = new Document();
|
|
@@ -939,13 +941,15 @@ async function createMeshLod(inputFileName, doc, basePath, level, mesh, meshInfo
|
|
|
939
941
|
const newMeshInformation = getMeshInformation(newMesh);
|
|
940
942
|
if (newMeshInformation.totalVertexCount < 4) {
|
|
941
943
|
logger.error(`[${NAME}] mesh LOD ${level} is has less than 4 vertices → skipping`);
|
|
942
|
-
return { level, path: fileName, success: false, cacheKey: cacheKey, content_hash: hash, lodMeshInfo: null, density: null, };
|
|
944
|
+
return { level, path: fileName, success: false, cacheKey: cacheKey, content_hash: hash, lodMeshInfo: null, density: null, densities: null };
|
|
943
945
|
}
|
|
944
946
|
let density = 0;
|
|
945
|
-
|
|
947
|
+
const densities = new Array(newMesh.listPrimitives().length);
|
|
948
|
+
newMesh.listPrimitives().forEach((prim, index) => {
|
|
946
949
|
const d = calculateMeshDensity(prim);
|
|
947
950
|
density = Math.max(density, d);
|
|
948
|
-
|
|
951
|
+
densities[index] = d;
|
|
952
|
+
});
|
|
949
953
|
const progressiveExt = newDoc.createExtension(NEEDLE_progressive);
|
|
950
954
|
if (!progressiveExt || !progressiveExt.createMesh) {
|
|
951
955
|
logger.error("Failed to create progressive extension");
|
|
@@ -953,7 +957,6 @@ async function createMeshLod(inputFileName, doc, basePath, level, mesh, meshInfo
|
|
|
953
957
|
}
|
|
954
958
|
newMesh.setExtension(NEEDLE_PROGRESSIVE_EXTENSION_NAME, progressiveExt.createMesh({
|
|
955
959
|
guid: guid,
|
|
956
|
-
density: density,
|
|
957
960
|
}));
|
|
958
961
|
// we need to compress the mesh with the same compression method as the original file
|
|
959
962
|
const model = determineMeshCompression(doc, fileName);
|
|
@@ -977,7 +980,16 @@ async function createMeshLod(inputFileName, doc, basePath, level, mesh, meshInfo
|
|
|
977
980
|
addToCache(cacheKey, bytes);
|
|
978
981
|
addMetaToCache(cacheKey, { meshInfo: newMeshInformation, density: density });
|
|
979
982
|
}
|
|
980
|
-
return {
|
|
983
|
+
return {
|
|
984
|
+
level,
|
|
985
|
+
path: fileName,
|
|
986
|
+
success: true,
|
|
987
|
+
lodMeshInfo: newMeshInformation,
|
|
988
|
+
cacheKey: cacheKey,
|
|
989
|
+
content_hash: hash,
|
|
990
|
+
density: density,
|
|
991
|
+
densities: densities
|
|
992
|
+
};
|
|
981
993
|
}
|
|
982
994
|
async function simplifyMesh(doc, mesh, prim, index, lodinfo) {
|
|
983
995
|
const weldOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.11.0-next.0ac327c";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.
|
|
1
|
+
export const version = "2.11.0-next.0ac327c";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-build-pipeline",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0-next.0ac327c",
|
|
4
4
|
"description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|