@needle-tools/gltf-build-pipeline 1.4.1-beta.6 → 1.4.1-beta.8

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.
@@ -109,37 +109,37 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
109
109
  const uri = texture.getURI();
110
110
  const match = !options.pattern || options.pattern.test(name) || options.pattern.test(uri);
111
111
  if (!match) {
112
- logger.debug(`${NAME}: Skipping, excluded by "pattern" parameter. ${textureIndex}`);
112
+ logger.debug(`[${NAME}] Skipping, excluded by "pattern" parameter. ${textureIndex}`);
113
113
  continue;
114
114
  }
115
115
  if (texture.getMimeType() !== 'image/png' && texture.getMimeType() !== 'image/jpeg') {
116
- logger.warn(`${NAME}: Skipping, unsupported texture type "${texture.getMimeType()} at ${textureIndex}".`);
116
+ logger.warn(`[${NAME}] Skipping, unsupported texture type "${texture.getMimeType()} at ${textureIndex}".`);
117
117
  continue;
118
118
  }
119
119
  const slots = listTextureSlots(texture);
120
120
  if (options.slots && !slots.some((slot) => options.slots?.test(slot))) {
121
- logger.debug(`${NAME}: Skipping, [${slots.join(', ')}] excluded by "slots" parameter. ${textureIndex}`);
121
+ logger.debug(`[${NAME}] Skipping, [${slots.join(', ')}] excluded by "slots" parameter. ${textureIndex}`);
122
122
  continue;
123
123
  }
124
124
  const settings = texture.getExtension(NEEDLE_progressive_texture_settings.EXTENSION_NAME);
125
125
  if (!settings) {
126
- logger.warn(`${NAME}: Skipping, no settings found ${textureIndex}`);
126
+ logger.warn(`[${NAME}] Skipping, no settings found ${textureIndex}`);
127
127
  continue;
128
128
  }
129
129
  if (!settings.isValid) {
130
- logger.warn(`${NAME}: Skipping, settings are invalid ${textureIndex}`);
130
+ logger.warn(`[${NAME}] Skipping, settings are invalid ${textureIndex}`);
131
131
  continue;
132
132
  }
133
133
  options.size[0] = settings.maxSize;
134
134
  options.size[1] = settings.maxSize;
135
135
  const existingExtension = texture.getExtension(NEEDLE_PROGRESSIVE_EXTENSION_NAME);
136
136
  if (existingExtension !== undefined && existingExtension !== null) {
137
- logger.debug(`${NAME}: Skipping, texture is already progressive ${textureIndex}`);
137
+ logger.debug(`[${NAME}] Skipping, texture is already progressive ${textureIndex}`);
138
138
  continue;
139
139
  }
140
140
  const progressiveExt = doc.createExtension(NEEDLE_progressive);
141
141
  if (!progressiveExt || !progressiveExt.create) {
142
- logger.debug(`${NAME}: Skipping because progressive extension is not available. ${textureIndex}`);
142
+ logger.debug(`[${NAME}] Skipping because progressive extension is not available. ${textureIndex}`);
143
143
  continue;
144
144
  }
145
145
  const textureGuid = settings.guid?.length ? settings.guid : generateGuid();
@@ -262,7 +262,7 @@ async function resizeTexture(options, texture, logger, uri, slots) {
262
262
  const [maxWidth, maxHeight] = options.size;
263
263
  const [srcWidth, srcHeight] = texture.getSize();
264
264
  if (srcWidth <= maxWidth && srcHeight <= maxHeight) {
265
- logger.debug(`${NAME}: Skipping, the texture is already smaller than the requested size ${maxWidth}x${maxHeight}}`);
265
+ logger.debug(`[${NAME}] Skipping, the texture is already smaller than the requested size ${maxWidth}x${maxHeight}}`);
266
266
  return;
267
267
  }
268
268
  if (maxWidth <= 0 || maxHeight <= 0) {
@@ -331,12 +331,12 @@ export function make_progressive_meshes(filePath, _options, opts) {
331
331
  // TODO: skip meshes that are already below a certain threshold (E.g. just 4 vertices)
332
332
  const settings = mesh.getExtension(NEEDLE_progressive_mesh_settings.EXTENSION_NAME);
333
333
  if (!settings) {
334
- logger.debug(`${NAME}: no ${NEEDLE_progressive_mesh_settings.EXTENSION_NAME} found for mesh at index ${index++}`);
334
+ logger.debug(`[${NAME}] no ${NEEDLE_progressive_mesh_settings.EXTENSION_NAME} found for mesh at index ${index++}`);
335
335
  continue;
336
336
  }
337
337
  const progressiveExt = doc.createExtension(NEEDLE_progressive);
338
338
  if (!progressiveExt || !progressiveExt.create) {
339
- logger.debug(`${NAME}: Skipping because progressive extension is not available. ${index++}`);
339
+ logger.debug(`[${NAME}] Skipping because progressive extension is not available. ${index++}`);
340
340
  continue;
341
341
  }
342
342
  // check if we have already produced LODs for this mesh
@@ -344,7 +344,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
344
344
  const generatedLODs = new Array();
345
345
  if (visited.has(settings.guid)) {
346
346
  // we can not just set the extension here...
347
- logger.debug(`${NAME}: Mesh has already been processed ${index} - will use previously generated LODs`);
347
+ logger.debug(`[${NAME}] Mesh has already been processed ${index} - will use previously generated LODs`);
348
348
  needsToGenerateLODs = false;
349
349
  const existingPaths = visited.get(settings.guid).paths;
350
350
  generatedLODs.push(...existingPaths);
@@ -370,21 +370,25 @@ export function make_progressive_meshes(filePath, _options, opts) {
370
370
  tasks.length = 0;
371
371
  }
372
372
  // compare LOD results and ignore if the mesh did not change
373
- let prevSize = -1;
374
- for (let i = 1; i < generatedLODs.length; i++) {
375
- const path = generatedLODs[i];
376
- if (!path) {
377
- console.log(`${NAME}: LOD ${i} was not generated for ${mesh.getName()}`);
373
+ // TODO: this should actually check mesh semantics (perhaps hash the mesh using the caching system?)
374
+ let prevSize = -Infinity;
375
+ let omittedLevelsIndex = -1;
376
+ for (let i = 0; i < generatedLODs.length; i++) {
377
+ const filename = generatedLODs[i];
378
+ if (!filename) {
379
+ console.log(`[${NAME}] LOD ${i} doesnt exist`);
378
380
  continue;
379
381
  }
380
- const fullPath = outputDirectory + path;
382
+ const fullPath = outputDirectory + filename;
381
383
  if (existsSync(fullPath)) {
382
384
  const lastSize = prevSize;
383
385
  const sizeOnDisc = statSync(fullPath).size;
384
- prevSize = sizeOnDisc;
385
386
  const diff = lastSize - sizeOnDisc;
386
- if (diff < 100) {
387
- console.log(`${NAME}: LOD ${i} did not change for ${mesh.getName()} - ignore it`);
387
+ prevSize = sizeOnDisc;
388
+ if (diff == 0) {
389
+ if (omittedLevelsIndex == -1)
390
+ omittedLevelsIndex = i;
391
+ console.log(`[${NAME}] LOD ${omittedLevelsIndex++} did not change mesh (${diff.toFixed(0)}) - level will be omitted \"${filename}\"`);
388
392
  generatedLODs.splice(i, 1);
389
393
  rmSync(fullPath);
390
394
  i--;
@@ -395,7 +399,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
395
399
  for (const prim of mesh.listPrimitives()) {
396
400
  const lodsCount = generatedLODs.length;
397
401
  const lastLod = LODS[lodsCount];
398
- console.log(`${NAME}: ${mesh.getName()} LOD ${LODS.length - 1}`);
402
+ console.log(`[${NAME}] ${mesh.getName()} LOD ${LODS.length - 1}`);
399
403
  const density = calculateMeshDensity(prim);
400
404
  maxDensity = Math.max(maxDensity, density);
401
405
  const task = simplifyMesh(doc, mesh, prim, lastLod);
@@ -445,7 +449,7 @@ async function createMeshLod(doc, basePath, level, mesh, guid, lodLevel, opts) {
445
449
  cacheKey = `mesh_lod_${level}_${hash}`;
446
450
  const cachedValue = tryGetFromCache(cacheKey);
447
451
  if (cachedValue) {
448
- console.log(`${NAME}: ${mesh.getName()} LOD ${level} loaded ${(cachedValue.length / 1024).toFixed()} KB from cache`);
452
+ console.log(`[${NAME}] LOD ${level} loaded ${(cachedValue.length / 1024).toFixed()} KB from cache for \"${mesh.getName()}\"`);
449
453
  writeFileSync(outPath, cachedValue);
450
454
  return { path: fileName, success: true };
451
455
  }
@@ -492,7 +496,6 @@ async function createMeshLod(doc, basePath, level, mesh, guid, lodLevel, opts) {
492
496
  const newProp = new PropertyClass(newDoc.getGraph());
493
497
  const copy = newProp.copy(ext);
494
498
  const name = ext.extensionName;
495
- console.log(`${NAME}: Copy primitive ${name} extension`);
496
499
  newPrim.setExtension(name, copy);
497
500
  }
498
501
  }
@@ -529,12 +532,12 @@ async function createMeshLod(doc, basePath, level, mesh, guid, lodLevel, opts) {
529
532
  if (compressionExt) {
530
533
  const newExt = newDoc.createExtension(NEEDLE_mesh_compression);
531
534
  const newProp = newExt.create(compressionExt.model);
532
- console.log(`${NAME}: Pass compression format to mesh LOD ${level} → ${JSON.stringify(compressionExt.model)}`);
535
+ console.log(`[${NAME}] Pass compression format to mesh LOD ${level} → ${JSON.stringify(compressionExt.model)}`);
533
536
  newDoc.getRoot().setExtension(NEEDLE_mesh_compression.EXTENSION_NAME, newProp);
534
537
  }
535
538
  const newIo = new NodeIO();
536
539
  registerExtensions(newIo);
537
- console.log(`${NAME}: Write mesh LOD ${level} to \"${fileName}\" with: ${JSON.stringify(lodLevel)}`);
540
+ console.log(`[${NAME}] Write mesh LOD ${level} with: ${JSON.stringify(lodLevel)} to \"${fileName}\"`);
538
541
  await newIo.write(outPath, newDoc);
539
542
  // add to cache
540
543
  if (cacheKey != undefined) {
package/index.mjs CHANGED
@@ -34,7 +34,7 @@ try {
34
34
  runWithArgs("node make-progressive.mjs");
35
35
  runWithArgs("node pack-gltf.mjs");
36
36
  const durationInMinutes = ((Date.now() - startTime) / 1000 / 60).toFixed(1);
37
- console.log(`[Needle Build Pipeline] v${getVersion()} — Finished progressive transform and optimization in ${durationInMinutes} minutes.`)
37
+ console.log(`[Needle Build Pipeline] v${getVersion()} — Finished progressive transform and optimization in ${durationInMinutes} minutes.`);
38
38
  }
39
39
  catch (err) {
40
40
  console.error("Failed running commandline args:", err.message);
package/pack-gltf.mjs CHANGED
@@ -97,7 +97,7 @@ async function packFile(file) {
97
97
  cacheKey = "packed-" + hash;
98
98
  const cached = tryGetFromCache(cacheKey);
99
99
  if (cached) {
100
- console.log("→ Skip packing (loaded from cache): " + path.basename(file));
100
+ console.log(`→ Loaded compressed file from cache: \"${path.basename(file)}\"`);
101
101
  writeFileSync(file, cached);
102
102
  return;
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.4.1-beta.6",
3
+ "version": "1.4.1-beta.8",
4
4
  "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
5
  "main": "index.mjs",
6
6
  "type": "module",