@needle-tools/gltf-build-pipeline 1.0.3 → 1.0.5

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,12 @@ 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
+ ## [1.0.5] - 2023-05-06
8
+ - fix: catch exception in cases where toktx is not installed (e.g. in CI environment) and log warning instead
9
+
10
+ ## [1.0.4] - 2023-04-24
11
+ - fix: error caused by missing simplifier
12
+
7
13
  ## [1.0.3] - 2023-04-24
8
14
  - fix: webp quality setting not being rounded resulting in compression to fail
9
15
 
@@ -0,0 +1 @@
1
+ export declare function gzipFile(filepath: string): Promise<string>;
@@ -0,0 +1,16 @@
1
+ import { promises as fs, existsSync } from 'fs';
2
+ import { gzip } from 'node-gzip';
3
+ export async function gzipFile(filepath) {
4
+ if (filepath.endsWith('.gz')) {
5
+ return filepath;
6
+ }
7
+ if (!existsSync(filepath)) {
8
+ console.log("File not found: " + filepath);
9
+ return filepath;
10
+ }
11
+ const inBuffer = await fs.readFile(filepath);
12
+ const outBuffer = await gzip(inBuffer);
13
+ const outPath = filepath;
14
+ await fs.writeFile(outPath, outBuffer);
15
+ return outPath;
16
+ }
@@ -0,0 +1 @@
1
+ export * from "./gzip.js";
@@ -0,0 +1 @@
1
+ export * from "./gzip.js";
@@ -11,6 +11,8 @@ export const needle_mesh_transform = function (_options) {
11
11
  return (document, _context) => {
12
12
  const logger = document.getLogger();
13
13
  const options = { ...SIMPLIFY_DEFAULTS, ..._options };
14
+ if (!options.simplifier)
15
+ options.simplifier = simplifier;
14
16
  const weldOptions = {
15
17
  ...WELD_DEFAULTS,
16
18
  tolerance: 0.00000000001,
@@ -65,6 +65,10 @@ export class NeedleToktxContext {
65
65
  this.document = document;
66
66
  const logger = document.getLogger();
67
67
  this.version = await checkKTXSoftware(logger, this.env);
68
+ if (this.version === null) {
69
+ this._prepareFailed = true;
70
+ return;
71
+ }
68
72
  this.basisuExtension = document.createExtension(KHRTextureBasisu).setRequired(true);
69
73
  const tmpDir = `${tmp.tmpdir}/gltf-transform`;
70
74
  if (!(existsSync(tmpDir)))
@@ -74,6 +78,7 @@ export class NeedleToktxContext {
74
78
  }
75
79
  catch (e) {
76
80
  console.error(e);
81
+ console.log("Error preparing toktx transform");
77
82
  this._prepareFailed = true;
78
83
  }
79
84
  }
@@ -74,4 +74,4 @@ export declare const UASTC_DEFAULTS: Omit<UASTCOptions, 'mode'>;
74
74
  */
75
75
  /** Create CLI parameters from the given options. Attempts to write only non-default options. */
76
76
  export declare function createParams(slots: string[], channels: number, size: vec2, logger: ILogger, numTextures: number, options: ETC1SOptions | UASTCOptions, version: string): (string | number)[];
77
- export declare function checkKTXSoftware(logger: ILogger, env?: any): Promise<string>;
77
+ export declare function checkKTXSoftware(logger: ILogger, env?: any): Promise<string | null>;
@@ -169,7 +169,18 @@ export function createParams(slots, channels, size, logger, numTextures, options
169
169
  }
170
170
  let didLogToktxVersion = false;
171
171
  export async function checkKTXSoftware(logger, env) {
172
- const [status, stdout, stderr] = await waitExit(spawn('toktx', ['--version'], { env: env }));
172
+ let failedFindingToktx = false;
173
+ const proc = spawn('toktx', ['--version'], { env: env });
174
+ proc.on('error', (err) => {
175
+ if (err.message.endsWith("ENOENT")) {
176
+ failedFindingToktx = true;
177
+ }
178
+ });
179
+ const [status, stdout, stderr] = await waitExit(proc);
180
+ if (failedFindingToktx) {
181
+ console.log(`WARN: Unable to find "toktx". Confirm KTX-Software is installed from: https://github.com/KhronosGroup/KTX-Software.`);
182
+ return null;
183
+ }
173
184
  const version = (stdout || stderr)
174
185
  .replace(/toktx\s+/, '')
175
186
  .replace(/~\d+/, '')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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",