@needle-tools/gltf-build-pipeline 1.2.3 → 1.3.0

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,13 @@ 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.3.0] - 2023-10-20
8
+ - fix: meshopt with khr_animation_2 extension was not correctly processed: animated node and target were not passed to gltf-transform which caused a wrong processing of meshopt. We now pass this information to the gltf-transform AnimationChannel object
9
+ - change: bump gltf-transform to 3.7.3
10
+
11
+ ## [1.2.4] - 2023-09-30
12
+ - fix: bug in progressive texture transform where extension wasnt added correctly (NE-3627)
13
+
7
14
  ## [1.2.3] - 2023-09-29
8
15
  - fix: bug in progressive texture transform where texture wasnt found
9
16
 
@@ -33,12 +33,23 @@ export function createOpaqueExtension(name, types, opts) {
33
33
  case PropertyType.ANIMATION_CHANNEL:
34
34
  if (EXTENSION_NAME === "KHR_animation_pointer") {
35
35
  context.jsonDoc.json.animations?.forEach((animDef, animIndex) => {
36
+ const anim = context.animations[animIndex];
37
+ const channels = anim.listChannels();
36
38
  animDef.channels?.forEach((channel, channelIndex) => {
37
39
  const jsonTarget = channel.target;
38
40
  const khr_animation = jsonTarget.extensions && jsonTarget.extensions[EXTENSION_NAME];
39
41
  if (!khr_animation)
40
42
  return;
41
- const anim = context.animations[animIndex];
43
+ const pointer = khr_animation.pointer;
44
+ if (pointer) {
45
+ const sections = pointer.split("/");
46
+ const nodeIndex = parseInt(sections[2]);
47
+ const targetName = sections[3];
48
+ if (targetName === "scale" || targetName === "translation" || targetName === "rotation") {
49
+ channels[channelIndex].setTargetNode(context.nodes[nodeIndex]);
50
+ channels[channelIndex].setTargetPath(targetName);
51
+ }
52
+ }
42
53
  const existing = anim.getExtension(EXTENSION_NAME);
43
54
  if (debugLog)
44
55
  console.log(">>>", EXTENSION_NAME, "animation", animIndex, "channel", channelIndex, khr_animation);
@@ -10,17 +10,40 @@ export class NEEDLE_progressive_texture_settings extends Extension {
10
10
  return this;
11
11
  const root = this.document.getRoot();
12
12
  const textures = root.listTextures();
13
+ /**
14
+ * If a texture is used in multiple slots it only appears once in the gltf-transform list
15
+ * So we have to store the key and the index of the texture in the list
16
+ */
17
+ const textureMap = new Map();
18
+ let offset = 0;
13
19
  for (let i = 0; i < textureDefinitions.length; i++) {
14
20
  const texDef = textureDefinitions[i];
15
21
  if (texDef.extensions && texDef.extensions[EXTENSION_NAME]) {
16
22
  const ext = texDef.extensions[EXTENSION_NAME];
17
23
  const prop = new NEEDLE_progressive_texture_settings_property(this.document.getGraph(), "");
18
24
  Object.assign(prop, ext);
19
- const tex = textures[i];
25
+ let textureIndex = i - offset;
26
+ const key = ext.guid;
27
+ if (textureMap.has(key)) {
28
+ // we keep a track of the index offset assuming gltf-transform textures order is the same as the texture definition order. This is by no means *not* bullet-proof but I'm not sure how to do it properly right now
29
+ // Perhaps we could try to find the texture with the same image source binary array as defined in the texture definition but this would also not be perfect I think...
30
+ // TODO: find a better way to handle texture definition count and texture count mismatch due to a texture being used in multiple slots (where gltf-transform optimizes the texture list and removes duplicates)
31
+ offset += 1;
32
+ // textureIndex = textureMap.get(key);
33
+ console.log(`INFO: Progressive texture extension was ${i} already found...`);
34
+ continue;
35
+ }
36
+ else {
37
+ textureMap.set(key, textureIndex);
38
+ }
39
+ const tex = textures[textureIndex];
20
40
  if (tex)
21
41
  tex.setExtension(EXTENSION_NAME, prop);
22
42
  else {
23
- console.warn("Texture not found for texture index " + i);
43
+ // console.log(textureDefinitions)
44
+ console.warn(`WARN: Progressive texture at index ${i} was not found in the glTF file. This might result in falsely loaded textures for ${ext.guid} / name \"${texDef.name}\"`);
45
+ // if(debug)
46
+ // throw new Error(`Progressive texture at index ${i} was not found in the glTF file.`)
24
47
  }
25
48
  }
26
49
  }
@@ -101,37 +101,37 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
101
101
  const uri = texture.getURI();
102
102
  const match = !options.pattern || options.pattern.test(name) || options.pattern.test(uri);
103
103
  if (!match) {
104
- logger.debug(`${NAME}: Skipping, excluded by "pattern" parameter.`);
104
+ logger.debug(`${NAME}: Skipping, excluded by "pattern" parameter. ${textureIndex}`);
105
105
  continue;
106
106
  }
107
107
  if (texture.getMimeType() !== 'image/png' && texture.getMimeType() !== 'image/jpeg') {
108
- logger.warn(`${NAME}: Skipping, unsupported texture type "${texture.getMimeType()}".`);
108
+ logger.warn(`${NAME}: Skipping, unsupported texture type "${texture.getMimeType()} at ${textureIndex}".`);
109
109
  continue;
110
110
  }
111
111
  const slots = listTextureSlots(texture);
112
112
  if (options.slots && !slots.some((slot) => options.slots?.test(slot))) {
113
- logger.debug(`${NAME}: Skipping, [${slots.join(', ')}] excluded by "slots" parameter.`);
113
+ logger.debug(`${NAME}: Skipping, [${slots.join(', ')}] excluded by "slots" parameter. ${textureIndex}`);
114
114
  continue;
115
115
  }
116
116
  const settings = texture.getExtension(NEEDLE_progressive_texture_settings.EXTENSION_NAME);
117
117
  if (!settings) {
118
- logger.warn(`${NAME}: Skipping, no settings found`);
118
+ logger.warn(`${NAME}: Skipping, no settings found ${textureIndex}`);
119
119
  continue;
120
120
  }
121
121
  if (!settings.isValid) {
122
- logger.warn(`${NAME}: Skipping, settings are invalid`);
122
+ logger.warn(`${NAME}: Skipping, settings are invalid ${textureIndex}`);
123
123
  continue;
124
124
  }
125
125
  options.size[0] = settings.maxSize;
126
126
  options.size[1] = settings.maxSize;
127
127
  const existingExtension = texture.getExtension(NEEDLE_PROGRESSIVE_TEXTURE_EXTENSION_NAME);
128
128
  if (existingExtension !== undefined && existingExtension !== null) {
129
- logger.debug(`${NAME}: Skipping, texture is already progressive`);
129
+ logger.debug(`${NAME}: Skipping, texture is already progressive ${textureIndex}`);
130
130
  continue;
131
131
  }
132
132
  const progressiveExt = doc.createExtension(NEEDLE_progressive);
133
133
  if (!progressiveExt || !progressiveExt.create) {
134
- logger.debug(`${NAME}: Skipping because progressive extension is not available.`);
134
+ logger.debug(`${NAME}: Skipping because progressive extension is not available. ${textureIndex}`);
135
135
  continue;
136
136
  }
137
137
  const textureGuid = settings.guid?.length ? settings.guid : generateGuid();
@@ -253,7 +253,7 @@ async function resizeTexture(options, texture, logger, uri, slots) {
253
253
  const [maxWidth, maxHeight] = options.size;
254
254
  const [srcWidth, srcHeight] = texture.getSize();
255
255
  if (srcWidth <= maxWidth && srcHeight <= maxHeight) {
256
- logger.debug(`${NAME}: Skipping, not within size range.`);
256
+ logger.debug(`${NAME}: Skipping, the texture is already smaller than the requested size ${maxWidth}x${maxHeight}}`);
257
257
  return;
258
258
  }
259
259
  if (maxWidth <= 0 || maxHeight <= 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
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.4.6",
20
- "@gltf-transform/extensions": "^3.4.6",
21
- "@gltf-transform/functions": "^3.4.6",
19
+ "@gltf-transform/core": "^3.7.3",
20
+ "@gltf-transform/extensions": "^3.7.3",
21
+ "@gltf-transform/functions": "^3.7.3",
22
22
  "command-exists": "^1.2.9",
23
23
  "command-line-args": "^5.2.1",
24
24
  "draco3dgltf": "^1.5.3",