@needle-tools/gltf-build-pipeline 1.0.4 → 1.0.6

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.6] - 2023-05-06
8
+ - fix: dont add textures to cache when toktx is not installed
9
+
10
+ ## [1.0.5] - 2023-05-06
11
+ - fix: catch exception in cases where toktx is not installed (e.g. in CI environment) and log warning instead
12
+
7
13
  ## [1.0.4] - 2023-04-24
8
14
  - fix: error caused by missing simplifier
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";
@@ -6,7 +6,7 @@ export interface NeedleTransformContext {
6
6
  noToktx: boolean;
7
7
  }
8
8
  export interface INeedleTextureTransformContext {
9
- prepare(document: Document): Promise<void>;
9
+ prepare(document: Document): Promise<void | boolean>;
10
10
  process(index: number, texture: Texture, settings: NEEDLE_compression_texture_schema): Promise<boolean>;
11
11
  finalize(document: Document): Promise<void>;
12
12
  }
@@ -131,8 +131,8 @@ async function processTexture(texture, index, document, logger, context) {
131
131
  if (canRunToktx) {
132
132
  // if no specific compression settings are provided we just use the toktx default settings
133
133
  // if we ever change what is used for default compression we need to teach the cache to save the mime type
134
- await context.toktxContext.process(index, texture, null);
135
- successFullyProcessed = true;
134
+ successFullyProcessed = await context.toktxContext.process(index, texture, null);
135
+ // don't add textures to the cache when toktx doesnt run
136
136
  }
137
137
  else {
138
138
  console.log("toktx is disallowed. Skipping texture compression.");
@@ -19,7 +19,7 @@ export declare class NeedleToktxContext implements INeedleTextureTransformContex
19
19
  numTextures: number;
20
20
  private _prepareFailed;
21
21
  constructor(options: NeedleToktxOptions);
22
- prepare(document: Document): Promise<void>;
22
+ prepare(document: Document): Promise<boolean>;
23
23
  process(index: number, texture: Texture, settings: NEEDLE_compression_texture_schema | null): Promise<boolean>;
24
24
  finalize(document: Document): Promise<void>;
25
25
  }
@@ -65,6 +65,11 @@ 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
+ console.log("Will not run toktx transform");
70
+ this._prepareFailed = true;
71
+ return false;
72
+ }
68
73
  this.basisuExtension = document.createExtension(KHRTextureBasisu).setRequired(true);
69
74
  const tmpDir = `${tmp.tmpdir}/gltf-transform`;
70
75
  if (!(existsSync(tmpDir)))
@@ -74,8 +79,11 @@ export class NeedleToktxContext {
74
79
  }
75
80
  catch (e) {
76
81
  console.error(e);
82
+ console.log("Error preparing toktx transform");
77
83
  this._prepareFailed = true;
84
+ return false;
78
85
  }
86
+ return true;
79
87
  }
80
88
  async process(index, texture, settings) {
81
89
  const task = async () => {
@@ -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.4",
3
+ "version": "1.0.6",
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",