@webxr-jp/mtoon-atlas 0.1.5 → 0.2.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/README.md CHANGED
@@ -156,6 +156,60 @@ void main() {
156
156
  }
157
157
  ```
158
158
 
159
+ ## KTX2 トランスコーダーの配信元
160
+
161
+ KTX2 テクスチャの読み込みには Basis Universal のトランスコーダー
162
+ (`basis_transcoder.js` / `.wasm`) が必要です。既定では jsdelivr の CDN から
163
+ 取得しますが、以下の理由で差し替えたいことがあります。
164
+
165
+ - CDN 障害や CORS 事故の影響を受けたくない(自己ホストしたい)
166
+ - アプリ側がインストールしている three とバージョンを揃えたい
167
+
168
+ ### アプリ全体で切り替える(推奨)
169
+
170
+ 起動時に一度呼びます。`MToonAtlasLoaderPlugin` を複数箇所で生成している場合でも、
171
+ 呼び出しごとにオプションを渡す必要がありません。
172
+
173
+ ```typescript
174
+ import { setKtx2TranscoderPath } from '@webxr-jp/mtoon-atlas'
175
+
176
+ // public/basis/ に basis_transcoder.js / .wasm を置いて同一オリジンで配信する
177
+ setKtx2TranscoderPath('/basis/')
178
+ ```
179
+
180
+ VRM を読み込む前に呼んでください。生成済みのローダーには影響しません。
181
+
182
+ トランスコーダーの実体は three が同梱しています。ビルド時に
183
+ `node_modules/three/examples/jsm/libs/basis/` からコピーすれば、
184
+ three を更新してもバージョンがずれません。
185
+
186
+ ### KTX2Loader を共有する
187
+
188
+ GLTFLoader 側で設定済みのインスタンスを渡すと、二重生成(初期化用の
189
+ 一時 WebGLRenderer が 2 つ作られる)も避けられます。
190
+
191
+ ```typescript
192
+ import { MToonAtlasLoaderPlugin } from '@webxr-jp/mtoon-atlas'
193
+
194
+ loader.register((parser) => new MToonAtlasLoaderPlugin(parser, { ktx2Loader }))
195
+ ```
196
+
197
+ ### プラグイン単位でパスを指定する
198
+
199
+ ```typescript
200
+ loader.register(
201
+ (parser) => new MToonAtlasLoaderPlugin(parser, { ktx2TranscoderPath: '/basis/' }),
202
+ )
203
+ ```
204
+
205
+ 優先順位は `ktx2Loader` > `ktx2TranscoderPath` > `setKtx2TranscoderPath()` の既定値 > CDN です。
206
+
207
+ `@webxr-jp/avatar-optimizer` の `loadVRM()` も同じオプションを受け取ります。
208
+
209
+ ```typescript
210
+ const result = await loadVRM(file, { ktx2TranscoderPath: '/basis/' })
211
+ ```
212
+
159
213
  ## API Reference
160
214
 
161
215
  ### MToonAtlasMaterial
package/dist/index.cjs CHANGED
@@ -30,10 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ DEFAULT_KTX2_TRANSCODER_PATH: () => DEFAULT_KTX2_TRANSCODER_PATH,
33
34
  MTOON_ATLAS_EXTENSION_NAME: () => MTOON_ATLAS_EXTENSION_NAME,
34
35
  MToonAtlasExporterPlugin: () => MToonAtlasExporterPlugin,
35
36
  MToonAtlasLoaderPlugin: () => MToonAtlasLoaderPlugin,
36
- MToonAtlasMaterial: () => MToonAtlasMaterial
37
+ MToonAtlasMaterial: () => MToonAtlasMaterial,
38
+ clearKtx2LoaderCache: () => clearKtx2LoaderCache,
39
+ getKtx2TranscoderPath: () => getKtx2TranscoderPath,
40
+ rememberKtx2Source: () => rememberKtx2Source,
41
+ resolveKtx2Loader: () => resolveKtx2Loader,
42
+ setKtx2TranscoderPath: () => setKtx2TranscoderPath
37
43
  });
38
44
  module.exports = __toCommonJS(index_exports);
39
45
 
@@ -63,7 +69,11 @@ var MToonAtlasMaterial = class _MToonAtlasMaterial extends THREE.ShaderMaterial
63
69
  lights: true,
64
70
  clipping: true,
65
71
  defines: {
66
- THREE_VRM_THREE_REVISION: parseInt(THREE.REVISION).toString()
72
+ THREE_VRM_THREE_REVISION: parseInt(THREE.REVISION).toString(),
73
+ // 上流three-vrmのMToonMaterialはignoreVertexColor=trueが既定。
74
+ // このdefineが無いとCOLOR_0(VEC4)を持つモデルでUSE_COLOR_ALPHAが立ち、
75
+ // `diffuseColor.rgb *= vColor`(vec3 *= vec4)がコンパイル不能になる
76
+ IGNORE_VERTEX_COLOR: ""
67
77
  }
68
78
  });
69
79
  /**
@@ -500,22 +510,53 @@ var MToonAtlasMaterial = class _MToonAtlasMaterial extends THREE.ShaderMaterial
500
510
  };
501
511
 
502
512
  // src/extensions/MToonAtlasLoaderPlugin.ts
503
- var import_three = require("three");
513
+ var import_three2 = require("three");
504
514
  var import_fast_png = require("fast-png");
505
- var import_KTX2Loader = require("three/examples/jsm/loaders/KTX2Loader.js");
506
515
 
507
- // src/extensions/types.ts
508
- var MTOON_ATLAS_EXTENSION_NAME = "XRIFT_mtoon_atlas";
516
+ // src/extensions/ktx2-source-cache.ts
517
+ var ktx2SourceByTextureSource = /* @__PURE__ */ new WeakMap();
518
+ function rememberKtx2Source(texture, data) {
519
+ if (!texture.source) {
520
+ return;
521
+ }
522
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
523
+ ktx2SourceByTextureSource.set(texture.source, bytes);
524
+ }
525
+ function getKtx2Source(texture) {
526
+ if (!texture.source) {
527
+ return void 0;
528
+ }
529
+ return ktx2SourceByTextureSource.get(texture.source);
530
+ }
531
+ function isCompressedTexture(texture) {
532
+ return texture.isCompressedTexture === true;
533
+ }
509
534
 
510
- // src/extensions/MToonAtlasLoaderPlugin.ts
511
- var ktx2LoaderInstance = null;
512
- function getKTX2Loader() {
513
- if (ktx2LoaderInstance) {
514
- return ktx2LoaderInstance;
535
+ // src/extensions/ktx2-loader.ts
536
+ var import_three = require("three");
537
+ var import_KTX2Loader = require("three/examples/jsm/loaders/KTX2Loader.js");
538
+ var DEFAULT_KTX2_TRANSCODER_PATH = "https://cdn.jsdelivr.net/npm/three@0.181.1/examples/jsm/libs/basis/";
539
+ function normalizeTranscoderPath(path) {
540
+ return path.endsWith("/") ? path : `${path}/`;
541
+ }
542
+ var defaultTranscoderPath = DEFAULT_KTX2_TRANSCODER_PATH;
543
+ var loaderCache = /* @__PURE__ */ new Map();
544
+ function setKtx2TranscoderPath(path) {
545
+ defaultTranscoderPath = normalizeTranscoderPath(path);
546
+ }
547
+ function getKtx2TranscoderPath() {
548
+ return defaultTranscoderPath;
549
+ }
550
+ function resolveKtx2Loader(transcoderPath) {
551
+ const path = transcoderPath === void 0 ? defaultTranscoderPath : normalizeTranscoderPath(transcoderPath);
552
+ const cached = loaderCache.get(path);
553
+ if (cached) {
554
+ return cached;
515
555
  }
516
556
  if (typeof document === "undefined" || typeof WebGLRenderingContext === "undefined") {
517
557
  return null;
518
558
  }
559
+ let renderer;
519
560
  try {
520
561
  const canvas = document.createElement("canvas");
521
562
  const gl = canvas.getContext("webgl2");
@@ -523,23 +564,71 @@ function getKTX2Loader() {
523
564
  console.warn("MToonAtlasLoaderPlugin: WebGL2\u304C\u30B5\u30DD\u30FC\u30C8\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
524
565
  return null;
525
566
  }
526
- const renderer = new import_three.WebGLRenderer({ canvas, context: gl });
527
- ktx2LoaderInstance = new import_KTX2Loader.KTX2Loader();
528
- ktx2LoaderInstance.setTranscoderPath(
529
- "https://cdn.jsdelivr.net/npm/three@0.175.0/examples/jsm/libs/basis/"
530
- );
531
- ktx2LoaderInstance.detectSupport(renderer);
532
- renderer.dispose();
533
- return ktx2LoaderInstance;
567
+ renderer = new import_three.WebGLRenderer({ canvas, context: gl });
568
+ const loader = new import_KTX2Loader.KTX2Loader();
569
+ loader.setTranscoderPath(path);
570
+ loader.detectSupport(renderer);
571
+ loaderCache.set(path, loader);
572
+ return loader;
534
573
  } catch (error) {
535
574
  console.warn("MToonAtlasLoaderPlugin: KTX2Loader\u306E\u521D\u671F\u5316\u306B\u5931\u6557:", error);
536
575
  return null;
576
+ } finally {
577
+ renderer?.dispose();
537
578
  }
538
579
  }
580
+ function clearKtx2LoaderCache() {
581
+ for (const loader of loaderCache.values()) {
582
+ loader.dispose();
583
+ }
584
+ loaderCache.clear();
585
+ }
586
+
587
+ // src/extensions/types.ts
588
+ var MTOON_ATLAS_EXTENSION_NAME = "XRIFT_mtoon_atlas";
589
+
590
+ // src/extensions/MToonAtlasLoaderPlugin.ts
539
591
  var MToonAtlasLoaderPlugin = class {
540
- constructor(parser) {
592
+ constructor(parser, options = {}) {
541
593
  this.name = MTOON_ATLAS_EXTENSION_NAME;
594
+ // 画像インデックス -> 元 KTX2 バイナリの複製(再エクスポート用、issue #39)
595
+ // 同じアトラス画像が複数マテリアルから参照されるため、画像単位でメモ化する
596
+ this.ktx2SourceByImageIndex = /* @__PURE__ */ new Map();
542
597
  this.parser = parser;
598
+ this.injectedKtx2Loader = options.ktx2Loader;
599
+ this.ktx2TranscoderPath = options.ktx2TranscoderPath;
600
+ }
601
+ /**
602
+ * このプラグインが使う KTX2Loader を取得する
603
+ * 注入されたインスタンス > 指定パス > アプリ全体の既定値 の順に解決する
604
+ */
605
+ getKtx2Loader() {
606
+ return this.injectedKtx2Loader ?? resolveKtx2Loader(this.ktx2TranscoderPath);
607
+ }
608
+ /**
609
+ * 再エクスポート用に元の KTX2 バイナリの複製を取得する(画像単位でメモ化)
610
+ *
611
+ * GLTFParser は bufferView を同一の ArrayBuffer でキャッシュして返し、
612
+ * KTX2Loader.parse はその ArrayBuffer をワーカーへ transfer して detach する。
613
+ * 通常は同一マイクロタスク内に全マテリアル分の複製が終わるため detach 前に間に合うが、
614
+ * 呼び出しが後続タイミングにずれた場合に備えて detach 済みかどうかを確認する。
615
+ * (複製済みならメモ化した方を返すので、実質ここで取りこぼすことはない)
616
+ *
617
+ * @param imageIndex - glTF の画像インデックス
618
+ * @param ktx2Data - bufferView から取得した KTX2 バイナリ
619
+ * @returns 複製。detach 済みで複製できなかった場合は undefined
620
+ */
621
+ getOrCreateKtx2SourceCopy(imageIndex, ktx2Data) {
622
+ const cached = this.ktx2SourceByImageIndex.get(imageIndex);
623
+ if (cached) {
624
+ return cached;
625
+ }
626
+ if (ktx2Data.byteLength === 0) {
627
+ return void 0;
628
+ }
629
+ const copy = new Uint8Array(ktx2Data.slice(0));
630
+ this.ktx2SourceByImageIndex.set(imageIndex, copy);
631
+ return copy;
543
632
  }
544
633
  loadMaterial(materialIndex) {
545
634
  const materialDef = this.parser.json.materials[materialIndex];
@@ -620,11 +709,11 @@ var MToonAtlasLoaderPlugin = class {
620
709
  }
621
710
  }
622
711
  }
623
- const texture = new import_three.DataTexture(floatData, width, height, import_three.RGBAFormat, import_three.FloatType);
712
+ const texture = new import_three2.DataTexture(floatData, width, height, import_three2.RGBAFormat, import_three2.FloatType);
624
713
  texture.flipY = false;
625
- texture.colorSpace = import_three.NoColorSpace;
626
- texture.minFilter = import_three.NearestFilter;
627
- texture.magFilter = import_three.NearestFilter;
714
+ texture.colorSpace = import_three2.NoColorSpace;
715
+ texture.minFilter = import_three2.NearestFilter;
716
+ texture.magFilter = import_three2.NearestFilter;
628
717
  texture.needsUpdate = true;
629
718
  return texture;
630
719
  }
@@ -667,21 +756,25 @@ var MToonAtlasLoaderPlugin = class {
667
756
  console.warn("MToonAtlasLoaderPlugin: \u7121\u52B9\u306A\u753B\u50CF\u5B9A\u7FA9\uFF08uri/bufferView\u306A\u3057\uFF09");
668
757
  return null;
669
758
  }
670
- const ktx2Loader = getKTX2Loader();
759
+ const ktx2Loader = this.getKtx2Loader();
671
760
  if (!ktx2Loader) {
672
761
  console.warn("MToonAtlasLoaderPlugin: KTX2Loader\u304C\u5229\u7528\u3067\u304D\u307E\u305B\u3093");
673
762
  return null;
674
763
  }
764
+ const ktx2SourceCopy = this.getOrCreateKtx2SourceCopy(imageIndex, ktx2Data);
675
765
  return new Promise((resolve, reject) => {
676
766
  ktx2Loader.parse(
677
767
  ktx2Data,
678
768
  (texture) => {
679
769
  texture.flipY = false;
680
- texture.minFilter = import_three.LinearMipmapLinearFilter;
681
- texture.magFilter = import_three.LinearFilter;
682
- texture.wrapS = import_three.RepeatWrapping;
683
- texture.wrapT = import_three.RepeatWrapping;
770
+ texture.minFilter = import_three2.LinearMipmapLinearFilter;
771
+ texture.magFilter = import_three2.LinearFilter;
772
+ texture.wrapS = import_three2.RepeatWrapping;
773
+ texture.wrapT = import_three2.RepeatWrapping;
684
774
  texture.needsUpdate = true;
775
+ if (ktx2SourceCopy) {
776
+ rememberKtx2Source(texture, ktx2SourceCopy);
777
+ }
685
778
  resolve(texture);
686
779
  },
687
780
  (error) => {
@@ -721,9 +814,9 @@ var MToonAtlasLoaderPlugin = class {
721
814
  texture.flipY = false;
722
815
  const srgbTextures = ["baseColor", "shade", "emissive", "matcap", "rim"];
723
816
  if (srgbTextures.includes(key)) {
724
- texture.colorSpace = import_three.SRGBColorSpace;
817
+ texture.colorSpace = import_three2.SRGBColorSpace;
725
818
  } else {
726
- texture.colorSpace = import_three.NoColorSpace;
819
+ texture.colorSpace = import_three2.NoColorSpace;
727
820
  }
728
821
  atlasedTextures[key] = texture;
729
822
  } catch (error) {
@@ -747,11 +840,11 @@ var MToonAtlasLoaderPlugin = class {
747
840
  await Promise.all(pending);
748
841
  if (!parameterTexture) {
749
842
  const dummyData = new Float32Array(4).fill(0);
750
- parameterTexture = new import_three.DataTexture(dummyData, 1, 1, import_three.RGBAFormat, import_three.FloatType);
843
+ parameterTexture = new import_three2.DataTexture(dummyData, 1, 1, import_three2.RGBAFormat, import_three2.FloatType);
751
844
  parameterTexture.flipY = false;
752
- parameterTexture.colorSpace = import_three.NoColorSpace;
753
- parameterTexture.minFilter = import_three.NearestFilter;
754
- parameterTexture.magFilter = import_three.NearestFilter;
845
+ parameterTexture.colorSpace = import_three2.NoColorSpace;
846
+ parameterTexture.minFilter = import_three2.NearestFilter;
847
+ parameterTexture.magFilter = import_three2.NearestFilter;
755
848
  parameterTexture.needsUpdate = true;
756
849
  }
757
850
  const slotAttributeName = extension.slotAttributeName.toLowerCase();
@@ -768,9 +861,9 @@ var MToonAtlasLoaderPlugin = class {
768
861
  name: materialDef.name
769
862
  });
770
863
  if (materialDef.doubleSided) {
771
- material.side = import_three.DoubleSide;
864
+ material.side = import_three2.DoubleSide;
772
865
  } else {
773
- material.side = import_three.FrontSide;
866
+ material.side = import_three2.FrontSide;
774
867
  }
775
868
  if (materialDef.alphaMode === "BLEND") {
776
869
  material.transparent = true;
@@ -795,7 +888,7 @@ var MToonAtlasLoaderPlugin = class {
795
888
  };
796
889
 
797
890
  // src/extensions/MToonAtlasExporterPlugin.ts
798
- var import_three2 = require("three");
891
+ var import_three3 = require("three");
799
892
  var import_fast_png2 = require("fast-png");
800
893
  var import_texture_compression = require("@webxr-jp/texture-compression");
801
894
  var MToonAtlasExporterPlugin = class {
@@ -807,9 +900,10 @@ var MToonAtlasExporterPlugin = class {
807
900
  this.textureIndices = /* @__PURE__ */ new Map();
808
901
  // beforeParseで処理中のテクスチャインデックス(Promise)
809
902
  this.pendingTextureIndices = /* @__PURE__ */ new Map();
810
- // テクスチャUUIDからインデックスへのキャッシュ(重複登録防止)
903
+ // 画像ソースのUUIDからインデックスへのキャッシュ(重複登録防止)
811
904
  // Three.jsのShaderMaterial.copyがuniformsをディープクローンするため、
812
- // オブジェクト参照ではなくUUIDでキャッシュする必要がある
905
+ // オブジェクト参照ではキャッシュできない。
906
+ // キーの選び方は processTextureWithCache のコメントを参照
813
907
  this.textureCache = /* @__PURE__ */ new Map();
814
908
  this.writer = writer;
815
909
  }
@@ -834,7 +928,7 @@ var MToonAtlasExporterPlugin = class {
834
928
  const roots = Array.isArray(input) ? input : [input];
835
929
  for (const root of roots) {
836
930
  root.traverse((obj) => {
837
- if (obj instanceof import_three2.Mesh) {
931
+ if (obj instanceof import_three3.Mesh) {
838
932
  const materials = Array.isArray(obj.material) ? obj.material : [obj.material];
839
933
  const mtoonMaterials = [];
840
934
  for (const material of materials) {
@@ -980,16 +1074,25 @@ var MToonAtlasExporterPlugin = class {
980
1074
  }
981
1075
  /**
982
1076
  * 通常テクスチャをキャッシュ付きで処理
983
- * 同じUUIDのテクスチャは1回だけ処理される
1077
+ * 同じ画像ソースを指すテクスチャは1回だけ処理される
1078
+ *
1079
+ * キャッシュキーに texture.uuid ではなく texture.source.uuid を使う理由:
1080
+ * MToonAtlasLoaderPlugin は GLTFLoader のキャッシュを汚さないようマテリアルごとに
1081
+ * clone() するため、同じアトラス画像でもマテリアル数だけ別 UUID のテクスチャになる。
1082
+ * uuid でキャッシュすると同一画像がマテリアル数ぶん重複して書き込まれ、
1083
+ * 再エクスポートのたびにファイルサイズが膨らむ。
1084
+ * clone 間で共有される Source を見ることで、画像単位で1回に揃う。
1085
+ * (このプラグインが出力する sampler は常に LINEAR/REPEAT 固定のため、
1086
+ * 同一ソースなら glTF 上の texture 定義も必ず一致する)
984
1087
  */
985
1088
  processTextureWithCache(texture) {
986
- const uuid = texture.uuid;
987
- const cached = this.textureCache.get(uuid);
1089
+ const cacheKey = texture.source?.uuid ?? texture.uuid;
1090
+ const cached = this.textureCache.get(cacheKey);
988
1091
  if (cached) {
989
1092
  return cached;
990
1093
  }
991
1094
  const promise = this.processTextureWithFallback(texture);
992
- this.textureCache.set(uuid, promise);
1095
+ this.textureCache.set(cacheKey, promise);
993
1096
  return promise;
994
1097
  }
995
1098
  /**
@@ -1148,16 +1251,49 @@ var MToonAtlasExporterPlugin = class {
1148
1251
  * 代わりに手動でテクスチャを登録することで、キャッシュを正しく機能させる。
1149
1252
  */
1150
1253
  processTextureWithFallback(texture) {
1254
+ const ktx2Source = getKtx2Source(texture);
1255
+ if (ktx2Source) {
1256
+ return this.processTextureAsKtx2Passthrough(texture, ktx2Source);
1257
+ }
1258
+ if (isCompressedTexture(texture)) {
1259
+ return Promise.reject(new Error(
1260
+ `\u5727\u7E2E\u30C6\u30AF\u30B9\u30C1\u30E3 "${texture.name || "unnamed"}" \u306F\u5143\u306E KTX2 \u30D0\u30A4\u30CA\u30EA\u304C\u4E0D\u660E\u306A\u305F\u3081\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u3067\u304D\u307E\u305B\u3093\u3002MToonAtlasLoaderPlugin \u7D4C\u7531\u3067\u8AAD\u307F\u8FBC\u307E\u308C\u305F\u30C6\u30AF\u30B9\u30C1\u30E3\u306E\u307F\u518D\u30A8\u30AF\u30B9\u30DD\u30FC\u30C8\u306B\u5BFE\u5FDC\u3057\u3066\u3044\u307E\u3059\u3002`
1261
+ ));
1262
+ }
1151
1263
  if (this.textureCompressionOptions) {
1152
1264
  return this.processTextureAsKtx2(texture);
1153
1265
  }
1154
1266
  return this.processTextureAsPng(texture);
1155
1267
  }
1156
1268
  /**
1157
- * テクスチャを KTX2 形式で処理してBINチャンクに書き込む
1269
+ * KTX2 由来のテクスチャを再エンコードせずそのまま書き出す
1270
+ *
1158
1271
  * @param texture - 処理するテクスチャ
1272
+ * @param ktx2Data - ロード時に記録した元の KTX2 バイナリ
1273
+ * @returns 登録されたテクスチャインデックス
1159
1274
  */
1160
- processTextureAsKtx2(texture) {
1275
+ processTextureAsKtx2Passthrough(texture, ktx2Data) {
1276
+ const { textureIndex, imageDef } = this.registerKtx2TextureDef(texture);
1277
+ const arrayCopy = new Uint8Array(ktx2Data).buffer;
1278
+ const blob = new Blob([arrayCopy], { type: "image/ktx2" });
1279
+ const bufferViewPromise = this.writer.processBufferViewImage(blob).then((bufferViewIndex) => {
1280
+ imageDef.bufferView = bufferViewIndex;
1281
+ return textureIndex;
1282
+ });
1283
+ this.writer.pending.push(bufferViewPromise.then(() => {
1284
+ }));
1285
+ return bufferViewPromise;
1286
+ }
1287
+ /**
1288
+ * KTX2 テクスチャの glTF 定義(image / texture / sampler / extensionsUsed)を登録する
1289
+ *
1290
+ * バイナリの書き込みは呼び出し側が非同期に行い、確定した bufferView を
1291
+ * 返却された imageDef に差し込む。
1292
+ *
1293
+ * @param texture - 処理するテクスチャ
1294
+ * @returns 確定したテクスチャインデックスと、bufferView 差し込み先の画像定義
1295
+ */
1296
+ registerKtx2TextureDef(texture) {
1161
1297
  const json = this.writer.json;
1162
1298
  json.textures = json.textures || [];
1163
1299
  json.images = json.images || [];
@@ -1199,6 +1335,14 @@ var MToonAtlasExporterPlugin = class {
1199
1335
  if (!json.extensionsUsed.includes("KHR_texture_basisu")) {
1200
1336
  json.extensionsUsed.push("KHR_texture_basisu");
1201
1337
  }
1338
+ return { textureIndex, imageDef };
1339
+ }
1340
+ /**
1341
+ * テクスチャを KTX2 形式で処理してBINチャンクに書き込む
1342
+ * @param texture - 処理するテクスチャ
1343
+ */
1344
+ processTextureAsKtx2(texture) {
1345
+ const { textureIndex, imageDef } = this.registerKtx2TextureDef(texture);
1202
1346
  const bufferViewPromise = this.compressTextureToKtx2(texture).then(async (ktx2Data) => {
1203
1347
  const arrayCopy = new Uint8Array(ktx2Data).buffer;
1204
1348
  const blob = new Blob([arrayCopy], { type: "image/ktx2" });
@@ -1235,7 +1379,7 @@ var MToonAtlasExporterPlugin = class {
1235
1379
  compressionLevel: this.textureCompressionOptions?.compressionLevel,
1236
1380
  generateMipmaps: this.textureCompressionOptions?.generateMipmaps,
1237
1381
  supercompression: this.textureCompressionOptions?.supercompression,
1238
- srgb: texture.colorSpace === import_three2.SRGBColorSpace
1382
+ srgb: texture.colorSpace === import_three3.SRGBColorSpace
1239
1383
  };
1240
1384
  const result = await (0, import_texture_compression.compressToKtx2)(
1241
1385
  rgbaData,
@@ -1371,7 +1515,7 @@ var MToonAtlasExporterPlugin = class {
1371
1515
  }, "image/png");
1372
1516
  });
1373
1517
  }
1374
- if (image instanceof ImageBitmap || image instanceof HTMLImageElement) {
1518
+ if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap || image instanceof HTMLImageElement) {
1375
1519
  const canvas = document.createElement("canvas");
1376
1520
  canvas.width = image.width;
1377
1521
  canvas.height = image.height;
@@ -1676,9 +1820,15 @@ var MToonAtlasExporterPlugin = class {
1676
1820
  };
1677
1821
  // Annotate the CommonJS export names for ESM import in node:
1678
1822
  0 && (module.exports = {
1823
+ DEFAULT_KTX2_TRANSCODER_PATH,
1679
1824
  MTOON_ATLAS_EXTENSION_NAME,
1680
1825
  MToonAtlasExporterPlugin,
1681
1826
  MToonAtlasLoaderPlugin,
1682
- MToonAtlasMaterial
1827
+ MToonAtlasMaterial,
1828
+ clearKtx2LoaderCache,
1829
+ getKtx2TranscoderPath,
1830
+ rememberKtx2Source,
1831
+ resolveKtx2Loader,
1832
+ setKtx2TranscoderPath
1683
1833
  });
1684
1834
  //# sourceMappingURL=index.cjs.map