@needle-tools/gltf-build-pipeline 1.1.6 → 1.2.1

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,15 @@ 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.2.1] - 2023-07-25
8
+ - change: set reference to materials used by json pointers
9
+
10
+ ## [1.2.0] - 2023-07-21
11
+ - add: resolving of material json pointers
12
+
13
+ ## [1.1.6] - 2023-07-10
14
+ - change: bump gltf-transform dependency to latest 3.4.6
15
+
7
16
  ## [1.1.5] - 2023-06-26
8
17
  - change: bump gltf-transform dependency to latest 3.4.3
9
18
 
@@ -556,16 +556,27 @@ class JsonPointerHandler {
556
556
  console.warn("WARN: failed registering pointer", fullPath, value);
557
557
  }
558
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
559
  if (this.debug)
562
560
  console.log("Read pointer", value);
563
561
  const index = parseInt(value.substring("/materials/".length));
564
562
  const mat = context.materials[index];
565
563
  if (mat) {
564
+ // set a reference to the material to avoid dedup or the material being removed because it MIGHT not be used by any node
565
+ // BUT a component is referencing the material so we don't want it ever to be removed
566
+ // see https://github.com/donmccurdy/glTF-Transform/issues/980#issuecomment-1585748202
566
567
  if (ext) {
567
- ext.setReference(key, mat);
568
+ ext.setReference(value, mat);
568
569
  }
570
+ let pointer = this.map.get(value);
571
+ if (!pointer) {
572
+ const definition = context.jsonDoc.json.materials[index];
573
+ const res = new MaterialPointerResolver(this.document, mat, definition);
574
+ res.init(context); // < init here otherwise the fields defined in the TexturePointer will be undefined (this caused e.g. finding the previous texture filter to fail)
575
+ pointer = new JsonPointer("/materials/", res);
576
+ pointer.debug = this.debug;
577
+ this.map.set(value, pointer);
578
+ }
579
+ pointer?.register(obj, key);
569
580
  }
570
581
  }
571
582
  }
@@ -715,3 +726,10 @@ function findSource(texDef) {
715
726
  }
716
727
  return undefined;
717
728
  }
729
+ class MaterialPointerResolver extends PointerResolver {
730
+ init(context) {
731
+ }
732
+ resolve(context) {
733
+ return context.materialIndexMap.get(this.inputObject);
734
+ }
735
+ }
@@ -2,7 +2,7 @@ import { PropertyType } from "@gltf-transform/core";
2
2
  import { createOpaqueExtension } from "./NEEDLE_opaque.js";
3
3
  export * from "./NEEDLE_opaque.js";
4
4
  const opaqueOptions = {
5
- debug: false,
5
+ debug: process.argv.includes("debug"),
6
6
  };
7
7
  export const ALL_EXTENSIONS = [
8
8
  createOpaqueExtension("KHR_animation_pointer", [PropertyType.ANIMATION, PropertyType.ANIMATION_CHANNEL], { ...opaqueOptions }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.1.6",
3
+ "version": "1.2.1",
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",