@webxr-jp/mtoon-atlas 0.2.0 → 0.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/dist/index.d.cts CHANGED
@@ -422,6 +422,28 @@ interface GLTFWriter {
422
422
  getUID: (attribute: BufferAttribute | InterleavedBufferAttribute, isRelativeCopy?: boolean) => number;
423
423
  }
424
424
 
425
+ /**
426
+ * アトラステクスチャの colorSpace を決める
427
+ *
428
+ * KTX2 由来のテクスチャは KTX2Loader が DFD の transferFunction から
429
+ * colorSpace を設定済みなので、それを尊重して何もしない。
430
+ * ここで名前ベースに塗り替えると、KTX2 側のタグが誤っていても結果的に
431
+ * 正しく表示されてしまい、エンコード時のバグを隠してしまう
432
+ * (debug-viewer では問題なく見えるのに、DFD をそのまま使う実環境では
433
+ * 色が破綻する、という食い違いの原因になる)。
434
+ *
435
+ * KTX2 かどうかは呼び出し側から渡す。圧縮テクスチャかどうかでは判定できない:
436
+ * KTX2Loader はトランスコード不要なペイロード(VK_FORMAT_R8G8B8A8_UNORM など)
437
+ * に対して非圧縮の DataTexture を返すことがあり、その場合も colorSpace は
438
+ * DFD から設定されるため。
439
+ *
440
+ * KTX2 以外(PNG など)は DFD を持たないので、従来どおりスロット名から設定する。
441
+ *
442
+ * @param texture - 対象テクスチャ
443
+ * @param slot - アトラススロット名(baseColor / normal など)
444
+ * @param isKtx2 - KTX2 から読み込んだテクスチャかどうか
445
+ */
446
+ declare function applyAtlasTextureColorSpace(texture: Texture, slot: string, isKtx2: boolean): void;
425
447
  /**
426
448
  * MToonAtlasLoaderPlugin のオプション
427
449
  */
@@ -729,4 +751,4 @@ declare class MToonAtlasExporterPlugin {
729
751
  */
730
752
  declare function rememberKtx2Source(texture: Texture, data: ArrayBuffer | Uint8Array): void;
731
753
 
732
- export { type AtlasedTextureSet, DEFAULT_KTX2_TRANSCODER_PATH, type DebugMode, MTOON_ATLAS_EXTENSION_NAME, MToonAtlasExporterPlugin, type MToonAtlasExtensionSchema, MToonAtlasLoaderPlugin, type MToonAtlasLoaderPluginOptions, MToonAtlasMaterial, type MToonAtlasOptions, type MaterialSlotAttributeConfig, type ParameterSemantic, type ParameterSemanticId, type ParameterTextureDescriptor, type TextureCompressionOptions, clearKtx2LoaderCache, getKtx2TranscoderPath, rememberKtx2Source, resolveKtx2Loader, setKtx2TranscoderPath };
754
+ export { type AtlasedTextureSet, DEFAULT_KTX2_TRANSCODER_PATH, type DebugMode, MTOON_ATLAS_EXTENSION_NAME, MToonAtlasExporterPlugin, type MToonAtlasExtensionSchema, MToonAtlasLoaderPlugin, type MToonAtlasLoaderPluginOptions, MToonAtlasMaterial, type MToonAtlasOptions, type MaterialSlotAttributeConfig, type ParameterSemantic, type ParameterSemanticId, type ParameterTextureDescriptor, type TextureCompressionOptions, applyAtlasTextureColorSpace, clearKtx2LoaderCache, getKtx2TranscoderPath, rememberKtx2Source, resolveKtx2Loader, setKtx2TranscoderPath };
package/dist/index.d.ts CHANGED
@@ -422,6 +422,28 @@ interface GLTFWriter {
422
422
  getUID: (attribute: BufferAttribute | InterleavedBufferAttribute, isRelativeCopy?: boolean) => number;
423
423
  }
424
424
 
425
+ /**
426
+ * アトラステクスチャの colorSpace を決める
427
+ *
428
+ * KTX2 由来のテクスチャは KTX2Loader が DFD の transferFunction から
429
+ * colorSpace を設定済みなので、それを尊重して何もしない。
430
+ * ここで名前ベースに塗り替えると、KTX2 側のタグが誤っていても結果的に
431
+ * 正しく表示されてしまい、エンコード時のバグを隠してしまう
432
+ * (debug-viewer では問題なく見えるのに、DFD をそのまま使う実環境では
433
+ * 色が破綻する、という食い違いの原因になる)。
434
+ *
435
+ * KTX2 かどうかは呼び出し側から渡す。圧縮テクスチャかどうかでは判定できない:
436
+ * KTX2Loader はトランスコード不要なペイロード(VK_FORMAT_R8G8B8A8_UNORM など)
437
+ * に対して非圧縮の DataTexture を返すことがあり、その場合も colorSpace は
438
+ * DFD から設定されるため。
439
+ *
440
+ * KTX2 以外(PNG など)は DFD を持たないので、従来どおりスロット名から設定する。
441
+ *
442
+ * @param texture - 対象テクスチャ
443
+ * @param slot - アトラススロット名(baseColor / normal など)
444
+ * @param isKtx2 - KTX2 から読み込んだテクスチャかどうか
445
+ */
446
+ declare function applyAtlasTextureColorSpace(texture: Texture, slot: string, isKtx2: boolean): void;
425
447
  /**
426
448
  * MToonAtlasLoaderPlugin のオプション
427
449
  */
@@ -729,4 +751,4 @@ declare class MToonAtlasExporterPlugin {
729
751
  */
730
752
  declare function rememberKtx2Source(texture: Texture, data: ArrayBuffer | Uint8Array): void;
731
753
 
732
- export { type AtlasedTextureSet, DEFAULT_KTX2_TRANSCODER_PATH, type DebugMode, MTOON_ATLAS_EXTENSION_NAME, MToonAtlasExporterPlugin, type MToonAtlasExtensionSchema, MToonAtlasLoaderPlugin, type MToonAtlasLoaderPluginOptions, MToonAtlasMaterial, type MToonAtlasOptions, type MaterialSlotAttributeConfig, type ParameterSemantic, type ParameterSemanticId, type ParameterTextureDescriptor, type TextureCompressionOptions, clearKtx2LoaderCache, getKtx2TranscoderPath, rememberKtx2Source, resolveKtx2Loader, setKtx2TranscoderPath };
754
+ export { type AtlasedTextureSet, DEFAULT_KTX2_TRANSCODER_PATH, type DebugMode, MTOON_ATLAS_EXTENSION_NAME, MToonAtlasExporterPlugin, type MToonAtlasExtensionSchema, MToonAtlasLoaderPlugin, type MToonAtlasLoaderPluginOptions, MToonAtlasMaterial, type MToonAtlasOptions, type MaterialSlotAttributeConfig, type ParameterSemantic, type ParameterSemanticId, type ParameterTextureDescriptor, type TextureCompressionOptions, applyAtlasTextureColorSpace, clearKtx2LoaderCache, getKtx2TranscoderPath, rememberKtx2Source, resolveKtx2Loader, setKtx2TranscoderPath };
package/dist/index.js CHANGED
@@ -543,6 +543,13 @@ function clearKtx2LoaderCache() {
543
543
  var MTOON_ATLAS_EXTENSION_NAME = "XRIFT_mtoon_atlas";
544
544
 
545
545
  // src/extensions/MToonAtlasLoaderPlugin.ts
546
+ var SRGB_ATLAS_SLOTS = ["baseColor", "shade", "emissive", "matcap", "rim"];
547
+ function applyAtlasTextureColorSpace(texture, slot, isKtx2) {
548
+ if (isKtx2) {
549
+ return;
550
+ }
551
+ texture.colorSpace = SRGB_ATLAS_SLOTS.includes(slot) ? SRGBColorSpace : NoColorSpace;
552
+ }
546
553
  var MToonAtlasLoaderPlugin = class {
547
554
  constructor(parser, options = {}) {
548
555
  this.name = MTOON_ATLAS_EXTENSION_NAME;
@@ -767,12 +774,7 @@ var MToonAtlasLoaderPlugin = class {
767
774
  texture.source = loadedTexture.source;
768
775
  }
769
776
  texture.flipY = false;
770
- const srgbTextures = ["baseColor", "shade", "emissive", "matcap", "rim"];
771
- if (srgbTextures.includes(key)) {
772
- texture.colorSpace = SRGBColorSpace;
773
- } else {
774
- texture.colorSpace = NoColorSpace;
775
- }
777
+ applyAtlasTextureColorSpace(texture, key, isKtx2);
776
778
  atlasedTextures[key] = texture;
777
779
  } catch (error) {
778
780
  console.warn(`MToonAtlasLoaderPlugin: \u30C6\u30AF\u30B9\u30C1\u30E3 ${key} (index: ${textureInfo.index}) \u306E\u8AAD\u307F\u8FBC\u307F\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F:`, error);
@@ -1779,6 +1781,7 @@ export {
1779
1781
  MToonAtlasExporterPlugin,
1780
1782
  MToonAtlasLoaderPlugin,
1781
1783
  MToonAtlasMaterial,
1784
+ applyAtlasTextureColorSpace,
1782
1785
  clearKtx2LoaderCache,
1783
1786
  getKtx2TranscoderPath,
1784
1787
  rememberKtx2Source,