@needle-tools/gltf-build-pipeline 2.15.0-next.a25e7ea → 2.15.0-next.a6f6798
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/dist/cli/index.js
CHANGED
|
File without changes
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Extension, ExtensionProperty, PropertyType, Node, TextureChannel } from '@gltf-transform/core';
|
|
2
2
|
import { getTexture, tryGetInArray, writeExtension } from '../utils.js';
|
|
3
3
|
import { isLightmap } from '../../utils/texture.js';
|
|
4
|
-
import { NEEDLE_progressive_texture_settings } from '../NEEDLE_progressive_texture_settings/index.js';
|
|
5
4
|
const ALL_PROPERTY_TYPES = [];
|
|
6
5
|
for (const key in PropertyType) {
|
|
7
6
|
ALL_PROPERTY_TYPES.push(PropertyType[key]);
|
|
@@ -124,11 +123,8 @@ export function createOpaqueExtension(name, types, opts) {
|
|
|
124
123
|
const prop = this.createExtension();
|
|
125
124
|
this.jsonPointerHandler.read(context, texture, ext, prop);
|
|
126
125
|
texture.setExtension(EXTENSION_NAME, prop);
|
|
127
|
-
const handler = new TextureHandler(this.document, textureDefinition, EXTENSION_NAME, ext, debugLog
|
|
126
|
+
const handler = new TextureHandler(this.document, textureDefinition, EXTENSION_NAME, ext, debugLog);
|
|
128
127
|
prop.add(handler);
|
|
129
|
-
const sourceIndex = textureDefinition.source;
|
|
130
|
-
if (debugLog)
|
|
131
|
-
console.log("Found texture with extension", EXTENSION_NAME, "at index", index, "source image index", sourceIndex, "name", texture.getName() || "<unnamed>");
|
|
132
128
|
});
|
|
133
129
|
break;
|
|
134
130
|
case PropertyType.NODE:
|
|
@@ -192,11 +188,11 @@ export function createOpaqueExtension(name, types, opts) {
|
|
|
192
188
|
const textures = this.document.getRoot().listTextures();
|
|
193
189
|
for (let i = 0; i < textures.length; i++) {
|
|
194
190
|
const tex = textures[i];
|
|
191
|
+
const texDef = textureDefinitions[i];
|
|
192
|
+
const name = texDef?.name;
|
|
195
193
|
if (isLightmap(tex) && tex.getMimeType() !== "image/exr") {
|
|
196
194
|
prop.setReference("lightmapTexture", tex, { channels: TextureChannel.R | TextureChannel.G | TextureChannel.B | TextureChannel.A });
|
|
197
|
-
|
|
198
|
-
const name = tex.getName() || texDef?.name;
|
|
199
|
-
logger.info(`Found lightmap texture \"${name}\" (${tex.getMimeType()}) in ${EXTENSION_NAME}`);
|
|
195
|
+
logger.info(`Found lightmap texture ${name}: ${tex.getMimeType()} in ${EXTENSION_NAME}`);
|
|
200
196
|
}
|
|
201
197
|
}
|
|
202
198
|
}
|
|
@@ -393,38 +389,30 @@ class GenericWriter {
|
|
|
393
389
|
class TextureHandler {
|
|
394
390
|
document;
|
|
395
391
|
textureDefinition;
|
|
392
|
+
index;
|
|
396
393
|
key;
|
|
397
394
|
ext;
|
|
398
395
|
debug = false;
|
|
399
|
-
/** Reference to the gltf-transform Texture object, used to resolve the current image index at write time via imageIndexMap */
|
|
400
|
-
textureRef;
|
|
401
396
|
assignTo(obj) {
|
|
402
397
|
Object.assign(obj, this.ext);
|
|
403
398
|
}
|
|
404
|
-
constructor(doc, def, key, ext, debug
|
|
399
|
+
constructor(doc, def, key, ext, debug) {
|
|
405
400
|
this.document = doc;
|
|
406
401
|
this.textureDefinition = def;
|
|
407
402
|
this.key = key;
|
|
408
403
|
this.ext = ext;
|
|
409
404
|
this.debug = debug;
|
|
410
|
-
this.
|
|
411
|
-
if (debug)
|
|
412
|
-
|
|
413
|
-
console.log(index, this.textureDefinition);
|
|
414
|
-
}
|
|
405
|
+
this.index = this.tryGetSourceIndex(this.textureDefinition);
|
|
406
|
+
if (debug)
|
|
407
|
+
console.log(def);
|
|
415
408
|
}
|
|
416
409
|
write(ctx) {
|
|
417
|
-
// Resolve the current image index from the gltf-transform graph reference.
|
|
418
|
-
// This is stable even after dedup/prune operations that re-index images.
|
|
419
|
-
const imageIndex = ctx.imageIndexMap.get(this.textureRef);
|
|
420
|
-
if (imageIndex === undefined) {
|
|
421
|
-
if (this.key !== "EXT_texture_exr" && this.debug) {
|
|
422
|
-
console.warn("WARN: failed to resolve image index for texture via imageIndexMap:", this.key, this.textureRef.getName() || "<unnamed>");
|
|
423
|
-
}
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
410
|
let foundTexture = false;
|
|
427
411
|
const textureDefs = ctx.jsonDoc.json.textures || [];
|
|
412
|
+
const imageIndex = this.index !== undefined ? this.index : this.tryGetSourceIndex(this.textureDefinition);
|
|
413
|
+
if (imageIndex === undefined) {
|
|
414
|
+
console.warn("WARN: no source index found for texture", this.key);
|
|
415
|
+
}
|
|
428
416
|
textureDefs?.forEach((textureDef, i) => {
|
|
429
417
|
if (foundTexture)
|
|
430
418
|
return;
|
|
@@ -444,10 +432,17 @@ class TextureHandler {
|
|
|
444
432
|
}
|
|
445
433
|
});
|
|
446
434
|
if (foundTexture === false) {
|
|
447
|
-
if (this.key !== "EXT_texture_exr" && this.debug)
|
|
448
|
-
console.warn("WARN: failed to re-assign extension:", this.key,
|
|
449
|
-
|
|
450
|
-
|
|
435
|
+
if (this.key !== "EXT_texture_exr" && this.debug)
|
|
436
|
+
console.warn("WARN: failed to re-assign extension:", this.key, this.index, this.tryGetSourceIndex(this.textureDefinition), textureDefs.length);
|
|
437
|
+
}
|
|
438
|
+
// this.document
|
|
439
|
+
// .getRoot()
|
|
440
|
+
// .listTextures()
|
|
441
|
+
// .forEach((texture, index) => {
|
|
442
|
+
// if (foundTexture) return;
|
|
443
|
+
// if (!texture.getExtension(this.key)) return;
|
|
444
|
+
// const imageIndex = ctx.imageIndexMap.get(texture);
|
|
445
|
+
// });
|
|
451
446
|
}
|
|
452
447
|
tryGetSourceIndex(def) {
|
|
453
448
|
let index = def.source;
|
|
@@ -883,18 +878,11 @@ class TextureIndexResolver extends PointerResolver {
|
|
|
883
878
|
// create a new texture def entry
|
|
884
879
|
if (this.debug)
|
|
885
880
|
console.log("Could not find texture, creating a new one: " + this._debugName);
|
|
886
|
-
|
|
887
|
-
let extensions = this.inputDefinition.extensions ? { ...this.inputDefinition.extensions } : undefined;
|
|
888
|
-
if (extensions) {
|
|
889
|
-
delete extensions[NEEDLE_progressive_texture_settings.EXTENSION_NAME];
|
|
890
|
-
if (Object.keys(extensions).length === 0)
|
|
891
|
-
extensions = undefined;
|
|
892
|
-
}
|
|
893
|
-
const hasExtensionWithSource = extensions && Object.keys(extensions).some(key => extensions[key]?.["source"] !== undefined);
|
|
881
|
+
const hasExtensionWithSource = this.inputDefinition.extensions && Object.keys(this.inputDefinition.extensions).some(key => this.inputDefinition.extensions[key]["source"] !== undefined);
|
|
894
882
|
const textureDef = {
|
|
895
883
|
source: hasExtensionWithSource ? undefined : imgIndex,
|
|
896
884
|
sampler: this.findOrCreateSampler(context.jsonDoc.json),
|
|
897
|
-
extensions: extensions,
|
|
885
|
+
extensions: this.inputDefinition.extensions,
|
|
898
886
|
extras: this.inputDefinition.extras,
|
|
899
887
|
};
|
|
900
888
|
context.jsonDoc.json.textures.push(textureDef);
|
|
@@ -399,7 +399,7 @@ async function createTextureLod(args, opts) {
|
|
|
399
399
|
logger.info("> Pass compression extension to new texture");
|
|
400
400
|
const newExt = newDoc.createExtension(NEEDLE_compression_texture);
|
|
401
401
|
const compressionSettings = compressionSettingsExt.getExtensionDefinition();
|
|
402
|
-
if (compressionSettings?.mode === "none") {
|
|
402
|
+
if (compressionSettings?.mode === "none" || compressionSettings?.mode === "webp" || compressionSettings?.mode === "UASTC" || compressionSettings?.mode === "ETC1S") {
|
|
403
403
|
// if the mode is set to None then we keep that setting for the new texture
|
|
404
404
|
}
|
|
405
405
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.15.0-next.
|
|
1
|
+
export declare const version = "2.15.0-next.a6f6798";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.15.0-next.
|
|
1
|
+
export const version = "2.15.0-next.a6f6798";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-build-pipeline",
|
|
3
|
-
"version": "2.15.0-next.
|
|
3
|
+
"version": "2.15.0-next.a6f6798",
|
|
4
4
|
"description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|