@needle-tools/gltf-build-pipeline 1.1.3 → 1.1.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.1.5] - 2023-06-26
8
+ - change: bump gltf-transform dependency to latest 3.4.3
9
+
10
+ ## [1.1.4] - 2023-06-09
11
+ - fix: progressive texture transform didnt pass mesh compression setting through
12
+
7
13
  ## [1.1.3] - 2023-05-24
8
14
  - minor change adding info about reduced size after processing gltf files
9
15
 
@@ -10,6 +10,10 @@ export interface IOpaqueExtension {
10
10
  export interface IOpaqueProperty {
11
11
  /** used by progressive texture extension to pass an extension between documents */
12
12
  getExtensionDefinition(): object;
13
+ /** register a reference so gltf-transform will not remove it in e.g. dedup
14
+ * https://github.com/donmccurdy/glTF-Transform/issues/980#issuecomment-1585748202
15
+ */
16
+ setReference(name: string, value: any): any;
13
17
  }
14
18
  export interface IExtensionWriter {
15
19
  /** used by progressive texture extension to pass an extension between documents */
@@ -199,7 +199,7 @@ export function createOpaqueExtension(name, types, opts) {
199
199
  // attach the property
200
200
  target[index].setExtension(EXTENSION_NAME, prop);
201
201
  // capture all the json pointers in the extension
202
- this.jsonPointerHandler.read(context, target[index], ext);
202
+ this.jsonPointerHandler.read(context, target[index], ext, prop);
203
203
  // make sure we write our extension back to the gltf
204
204
  prop.add(new OpaqueWriter(map, gltfField, ext));
205
205
  });
@@ -293,7 +293,11 @@ export function createOpaqueExtension(name, types, opts) {
293
293
  extensionName = typeof EXTENSION_NAME;
294
294
  parentTypes = ExtensionPropertyTypes;
295
295
  propertyType = "NEEDLE_opaque_property";
296
- init() { }
296
+ setReference(name, value) {
297
+ this.setRef(name, value, { modifyChild: true });
298
+ }
299
+ init() {
300
+ }
297
301
  writers = [];
298
302
  add(writer) {
299
303
  if (typeof writer === "function") {
@@ -495,7 +499,7 @@ class JsonPointerHandler {
495
499
  this.document = document;
496
500
  this.id = id;
497
501
  }
498
- read(context, prop, obj, key, fullPath) {
502
+ read(context, prop, obj, ext, key, fullPath) {
499
503
  const value = key !== undefined ? obj[key] : obj;
500
504
  // the pointer path contains the full path from the root object to the json pointer
501
505
  if (key !== undefined) {
@@ -506,7 +510,7 @@ class JsonPointerHandler {
506
510
  case 'object':
507
511
  if (value !== null && value !== undefined) {
508
512
  for (const key of Object.keys(value)) {
509
- this.read(context, prop, value, key, fullPath);
513
+ this.read(context, prop, value, ext, key, fullPath);
510
514
  }
511
515
  }
512
516
  break;
@@ -551,6 +555,19 @@ class JsonPointerHandler {
551
555
  else
552
556
  console.warn("WARN: failed registering pointer", fullPath, value);
553
557
  }
558
+ if (value.startsWith("/materials/")) {
559
+ // set a reference to the material to avoid dedup
560
+ // see https://github.com/donmccurdy/glTF-Transform/issues/980#issuecomment-1585748202
561
+ if (this.debug)
562
+ console.log("Read pointer", value);
563
+ const index = parseInt(value.substring("/materials/".length));
564
+ const mat = context.materials[index];
565
+ if (mat) {
566
+ if (ext) {
567
+ ext.setReference(key, mat);
568
+ }
569
+ }
570
+ }
554
571
  }
555
572
  break;
556
573
  }
@@ -1,22 +1,11 @@
1
1
  import { createTransform } from '@gltf-transform/functions';
2
- import { existsSync, readFileSync } from 'fs';
3
- let version = undefined;
2
+ import { getVersion } from '../index.js';
4
3
  export function needle_asset() {
5
4
  return createTransform("needle_asset_transform", (document) => {
6
5
  const root = document.getRoot();
7
6
  const asset = root.getAsset();
8
7
  if (asset) {
9
- if (version === undefined) {
10
- version = null;
11
- const path = process.cwd() + "/package.json";
12
- if (existsSync(path)) {
13
- const packageJson = readFileSync(path, "utf8");
14
- const packageVersion = JSON.parse(packageJson).version;
15
- version = packageVersion ?? null;
16
- }
17
- else
18
- console.log("Could not find package.json at " + path);
19
- }
8
+ const version = getVersion();
20
9
  if (!asset.generator.startsWith("Needle glTF Build Pipeline")) {
21
10
  asset.generator = "Needle glTF Build Pipeline";
22
11
  if (version?.length > 0) {
@@ -30,6 +30,7 @@ async function applyMeshCompression(document, _context) {
30
30
  }
31
31
  }
32
32
  // by default we still want to run draco if the root doesnt have a compression model configured
33
+ console.log(`[${NAME}]: No compression model configured → will apply draco mesh compression`);
33
34
  return draco()(document, _context);
34
35
  }
35
36
  async function simplifierTransform(document, _context, _options) {
@@ -17,7 +17,7 @@ function registerExtensions(io) {
17
17
  //@ts-ignore
18
18
  createOpaqueExtension(NEEDLE_compression_texture.EXTENSION_NAME, PropertyType.TEXTURE),
19
19
  //@ts-ignore
20
- createOpaqueExtension(NEEDLE_mesh_compression.EXTENSION_NAME, [PropertyType.MESH, PropertyType.PRIMITIVE])
20
+ createOpaqueExtension(NEEDLE_mesh_compression.EXTENSION_NAME, [PropertyType.ROOT, PropertyType.MESH, PropertyType.PRIMITIVE])
21
21
  ]);
22
22
  }
23
23
  export async function make_progressive(opts) {
@@ -1 +1,2 @@
1
1
  export * from "./fileutils.js";
2
+ export * from "./version.js";
@@ -1 +1,2 @@
1
1
  export * from "./fileutils.js";
2
+ export * from "./version.js";
@@ -0,0 +1 @@
1
+ export declare function getVersion(marklocal?: boolean): string;
@@ -0,0 +1,21 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ let version = undefined;
3
+ let isLocal = false;
4
+ export function getVersion(marklocal = true) {
5
+ if (version === undefined) {
6
+ version = null;
7
+ const path = process.cwd() + "/package.json";
8
+ isLocal = !path.includes("node_modules");
9
+ if (existsSync(path)) {
10
+ const packageJson = readFileSync(path, "utf8");
11
+ const packageVersion = JSON.parse(packageJson).version;
12
+ version = packageVersion ?? null;
13
+ }
14
+ else
15
+ console.log("Could not find package.json at " + path);
16
+ }
17
+ let res = version;
18
+ if (marklocal && isLocal)
19
+ res += " (local)";
20
+ return res;
21
+ }
@@ -1,7 +1,10 @@
1
+ import { getVersion } from './dist/index.js';
1
2
  import { make_progressive } from './dist/transforms/needle_progressive.js';
2
3
 
3
4
  const args = process.argv;
4
5
 
6
+ console.log(`[Needle Build Pipeline] transform to progressive — version ${getVersion()}`)
7
+
5
8
  make_progressive({
6
9
  path: args,
7
10
  debug: args.includes("debug"),
package/pack-gltf.mjs CHANGED
@@ -14,6 +14,9 @@ import { needle_animation_transform } from "./dist/transforms/needle_animation_t
14
14
  import { foreachGLTF } from './fileutils.mjs';
15
15
  import { needle_asset } from './dist/transforms/needle_asset.js';
16
16
  import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
17
+ import { getVersion } from './dist/index.js';
18
+
19
+ console.log(`[Needle Build Pipeline] pack glTF — version ${getVersion()}`)
17
20
 
18
21
  const args = process.argv;
19
22
  const showHelp = args.includes("help");
@@ -139,11 +142,13 @@ async function packFile(file) {
139
142
  }
140
143
  }
141
144
 
145
+
146
+
142
147
  let startTime = Date.now();
143
148
  foreachGLTF(process.argv, async (file) => {
144
149
  await packFile(file);
145
150
  }).then(() => {
146
151
  const duration = Date.now() - startTime;
147
152
  const durationInMinutes = duration / 1000 / 60;
148
- console.log(`Finished packing ${totalFilesProcessed} files in ${durationInMinutes.toFixed(1)} minutes; total size ${totalFileSizeInMBBefore.toFixed(1)} MB → ${totalFileSizeInMB.toFixed(1)} MB, total GPU memory: ${totalGPUMemoryInMB.toFixed(1)} MB`);
153
+ console.log(`[Needle Build Pipeline] v${getVersion()} — Finished packing ${totalFilesProcessed} files in ${durationInMinutes.toFixed(1)} minutes; total size ${totalFileSizeInMBBefore.toFixed(1)} MB → ${totalFileSizeInMB.toFixed(1)} MB, total GPU memory: ${totalGPUMemoryInMB.toFixed(1)} MB`);
149
154
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.1.3",
3
+ "version": "1.1.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",
@@ -16,9 +16,9 @@
16
16
  "compile": "tsc || exit 1"
17
17
  },
18
18
  "dependencies": {
19
- "@gltf-transform/core": "^3.1.4",
20
- "@gltf-transform/extensions": "^3.1.4",
21
- "@gltf-transform/functions": "^3.1.4",
19
+ "@gltf-transform/core": "^3.4.3",
20
+ "@gltf-transform/extensions": "^3.4.3",
21
+ "@gltf-transform/functions": "^3.4.3",
22
22
  "@squoosh/lib": "^0.4.0",
23
23
  "command-exists": "^1.2.9",
24
24
  "command-line-args": "^5.2.1",