@needle-tools/gltf-build-pipeline 2.4.0-alpha.3 → 2.4.0-alpha.4

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/CHANGELOG.md CHANGED
@@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.4.0-beta] - 2023-08-13
8
+ - fix: issue where a mesh lod is removed during second processing of a directory that contains existing mesh lods
9
+
7
10
  ## [2.4.0-alpha.3] - 2023-08-11
8
11
  - fix: issue where files would not correctly be overriden in subdirectories when no output directory was specified
9
12
 
package/dist/cli/index.js CHANGED
@@ -4,8 +4,9 @@ import { calculateStats, packGLTF } from "../scripts/index.js";
4
4
  import { printStats, writeFileStatsToFile } from '../utils/stats.js';
5
5
  import { getVersion } from '../utils/version.js';
6
6
  import { UsecaseOptions, createConfig, getConfig } from '../config/index.js';
7
- import { make_progressive } from '../transforms/needle_progressive.js';
7
+ import { isLOD, make_progressive } from '../transforms/needle_progressive.js';
8
8
  import { cacheSizeLimit, clearCache, limitCacheSize } from '../cache/cache.js';
9
+ import { existsSync } from 'fs';
9
10
  import { ensureIsDirectory, foreachGLTF, isDirectory } from '../utils/fileutils.js';
10
11
  import path, { resolve } from 'path';
11
12
  import { ERROR_CODES } from '../constants.js';
@@ -112,6 +113,20 @@ Each version will be compressed and written to the output directory.
112
113
  const debug = options.debug === true;
113
114
  const verbose = options.verbose === true;
114
115
  await foreachGLTF(input, async (file) => {
116
+ if (!existsSync(file)) {
117
+ // Safeguard if we run compression in a souce directory that already has progressive assets
118
+ // Here it can happen that a LOD file is generated with the same GUID at the moment
119
+ // And then later removed because simplification is too small.
120
+ // See https://linear.app/needle/issue/NE-5518
121
+ if (isLOD(file)) {
122
+ logger.warn(`WARN: Ignore previously found file that does not exist anymore: \"${file}\"`);
123
+ return;
124
+ }
125
+ else {
126
+ logger.error(`ERR: Previously found file is now missing: \"${file}\"`);
127
+ process.exit(ERROR_CODES.LOST_FILE);
128
+ }
129
+ }
115
130
  logger.info("→ Transform " + file);
116
131
  const progressive_results = new Array();
117
132
  if (options.progressive === true) {
@@ -121,6 +136,7 @@ Each version will be compressed and written to the output directory.
121
136
  results: progressive_results,
122
137
  config,
123
138
  debug,
139
+ verbose,
124
140
  useCache,
125
141
  }).catch(err => {
126
142
  logger.error(err);
@@ -128,6 +144,9 @@ Each version will be compressed and written to the output directory.
128
144
  }) === false) {
129
145
  process.exit(ERROR_CODES.PROGRESSIVE_FAILED);
130
146
  }
147
+ if (verbose) {
148
+ console.log("Progressive results:\n", progressive_results);
149
+ }
131
150
  }
132
151
  if (options.compress === true) {
133
152
  const opts = {
@@ -3,4 +3,5 @@ export declare const ERROR_CODES: {
3
3
  PACKING_FAILED: number;
4
4
  PROGRESSIVE_FAILED: number;
5
5
  INVALID_ARGS: number;
6
+ LOST_FILE: number;
6
7
  };
package/dist/constants.js CHANGED
@@ -3,4 +3,5 @@ export const ERROR_CODES = {
3
3
  PACKING_FAILED: 2,
4
4
  PROGRESSIVE_FAILED: 3,
5
5
  INVALID_ARGS: 4,
6
+ LOST_FILE: 5,
6
7
  };
@@ -17,7 +17,7 @@ export async function packGLTF(inputFile, outputFile, options) {
17
17
  }
18
18
  const { debug, stats, packedFiles, useCache, logger } = options;
19
19
  if (!existsSync(inputFile)) {
20
- logger.error("WARN: can not pack, file does not exist: " + inputFile);
20
+ logger.error(`WARN: can not pack, file does not exist: \"${inputFile}\"`);
21
21
  return false;
22
22
  }
23
23
  // check if it's in the cache.
@@ -65,7 +65,7 @@ async function onProcess(file, opts) {
65
65
  if (document) {
66
66
  const logger = document.getLogger();
67
67
  //@ts-ignore
68
- logger.verbosity = opts.debug || opts.verbose ? Verbosity.DEBUG : Verbosity.WARN;
68
+ logger.verbosity = (opts.debug || opts.verbose) ? Verbosity.DEBUG : Verbosity.WARN;
69
69
  let smallesTextureSize = 128;
70
70
  if (opts.config.usecase === "product") {
71
71
  smallesTextureSize = 512;
@@ -652,6 +652,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
652
652
  }
653
653
  }
654
654
  if (shouldOmitLevel) {
655
+ logger.debug(`[${NAME}] Omitting LOD ${level} for \"${mesh.getName()}\" at \"${lodInfo.path}\"`);
655
656
  generatedLODInfos.splice(i, 1);
656
657
  rmSync(fullPath);
657
658
  i--;
@@ -77,7 +77,7 @@ export async function foreachGLTF(args, callback) {
77
77
  }
78
78
  }
79
79
  if (context.files.length <= 0) {
80
- console.log("WARN: No glTF files found. Make sure to invoke with a valid path to a glTF file or directory. This path may be relative to \"" + initDir + "\"");
80
+ console.log(`WARN: No glTF files found. Make sure to invoke with a valid path to a glTF file or directory.\nBase Directory: ${context.baseDirectory}\nPaths can be relative to \"${initDir}\"`);
81
81
  }
82
82
  else {
83
83
  for (const file of context.files) {
@@ -99,13 +99,13 @@ async function testEntry(entry, context) {
99
99
  // If no base directory is defined we cannot try to resolve the path
100
100
  if (context.baseDirectory === undefined) {
101
101
  console.log("WARN: Path does not exist: " + entry);
102
- return;
102
+ return false;
103
103
  }
104
104
  // Try resolve potential relative path
105
105
  const newPath = context.baseDirectory + "/" + entry;
106
106
  if (existsSync(newPath) === false) {
107
107
  console.log(`INFO: Resolved path failed: \"${entry}\" -> ${newPath} (doesnt exist or is locked by another process)`);
108
- return;
108
+ return false;
109
109
  }
110
110
  else {
111
111
  console.log(`INFO: Resolved path: ${entry} -> ${newPath}`);
@@ -122,7 +122,7 @@ async function testEntry(entry, context) {
122
122
  console.log(`INFO: Resolved path: ${entry} -> ${newPath}`);
123
123
  entry = newPath;
124
124
  if (!existsSync(entry)) {
125
- return;
125
+ return false;
126
126
  }
127
127
  }
128
128
  }
@@ -135,7 +135,7 @@ async function testEntry(entry, context) {
135
135
  if (stat.isDirectory()) {
136
136
  // Don't traverse node_modules
137
137
  if (entry.endsWith("node_modules")) {
138
- return;
138
+ return false;
139
139
  }
140
140
  const files = readdirSync(entry);
141
141
  for (const file of files) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "2.4.0-alpha.3",
3
+ "version": "2.4.0-alpha.4",
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",