@webxr-jp/mtoon-atlas 0.1.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/LICENSE +21 -0
- package/README.md +300 -0
- package/dist/index.cjs +1675 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +579 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +1635 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { Texture, BufferAttribute, InterleavedBufferAttribute, BufferGeometry, Material, Object3D } from 'three';
|
|
3
|
+
import { Ktx2CompressionOptions } from '@webxr-jp/texture-compression';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* MToonAtlasMaterial 型定義集約
|
|
7
|
+
*
|
|
8
|
+
* パラメータテクスチャ、アトラステクスチャ、スロット属性の型定義
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* パラメータセマンティクス定義
|
|
13
|
+
*
|
|
14
|
+
* パラメータテクスチャの各テクセル・チャンネルに対応するセマンティック情報
|
|
15
|
+
*/
|
|
16
|
+
type ParameterSemanticId = 'baseColor' | 'opacity' | 'shadeColor' | 'emissiveColor' | 'emissiveIntensity' | 'shadingShift' | 'shadingShiftTextureScale' | 'shadingToony' | 'rimLightingMix' | 'matcapColor' | 'outlineWidth' | 'outlineColor' | 'outlineLightingMix' | 'parametricRimColor' | 'parametricRimLift' | 'parametricRimFresnelPower' | 'uvAnimationScrollX' | 'uvAnimationScrollY' | 'uvAnimationRotation' | 'normalScale';
|
|
17
|
+
/**
|
|
18
|
+
* パラメータセマンティック定義
|
|
19
|
+
*
|
|
20
|
+
* パラメータテクスチャのレイアウト情報
|
|
21
|
+
*/
|
|
22
|
+
interface ParameterSemantic {
|
|
23
|
+
id: ParameterSemanticId;
|
|
24
|
+
texel: number;
|
|
25
|
+
channels: readonly ('r' | 'g' | 'b' | 'a')[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* パラメータテクスチャディスクリプタ
|
|
29
|
+
*
|
|
30
|
+
* avatar-optimizer で生成されたパラメータテクスチャの情報
|
|
31
|
+
*/
|
|
32
|
+
interface ParameterTextureDescriptor {
|
|
33
|
+
/** パック済みパラメータテクスチャ */
|
|
34
|
+
texture: THREE.Texture;
|
|
35
|
+
/** スロット数(= 元のマテリアル数) */
|
|
36
|
+
slotCount: number;
|
|
37
|
+
/** スロットあたりのテクセル数(通常8) */
|
|
38
|
+
texelsPerSlot: number;
|
|
39
|
+
/** カスタムレイアウト定義(省略時はデフォルト) */
|
|
40
|
+
semantics?: ParameterSemantic[];
|
|
41
|
+
/** アトラス化されたテクスチャセット */
|
|
42
|
+
atlasedTextures?: AtlasedTextureSet;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* アトラス化テクスチャセット
|
|
46
|
+
*
|
|
47
|
+
* avatar-optimizer で生成されたアトラス化テクスチャの集合
|
|
48
|
+
*/
|
|
49
|
+
interface AtlasedTextureSet {
|
|
50
|
+
/** ベースカラーアトラス(MToonMaterial.map) */
|
|
51
|
+
baseColor?: THREE.Texture;
|
|
52
|
+
/** Shade 乗算テクスチャアトラス(shadeMultiplyTexture) */
|
|
53
|
+
shade?: THREE.Texture;
|
|
54
|
+
/** Shading Shift テクスチャアトラス(shadingShiftTexture) */
|
|
55
|
+
shadingShift?: THREE.Texture;
|
|
56
|
+
/** ノーマルマップアトラス(normalMap) */
|
|
57
|
+
normal?: THREE.Texture;
|
|
58
|
+
/** エミッシブマップアトラス(emissiveMap) */
|
|
59
|
+
emissive?: THREE.Texture;
|
|
60
|
+
/** Matcap テクスチャアトラス(matcapTexture) */
|
|
61
|
+
matcap?: THREE.Texture;
|
|
62
|
+
/** Rim 乗算テクスチャアトラス(rimMultiplyTexture) */
|
|
63
|
+
rim?: THREE.Texture;
|
|
64
|
+
/** UV アニメーションマスクテクスチャアトラス(uvAnimationMaskTexture) */
|
|
65
|
+
uvAnimationMask?: THREE.Texture;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* マテリアルスロット属性設定
|
|
69
|
+
*
|
|
70
|
+
* 頂点属性経由でマテリアルスロットを指定するための設定
|
|
71
|
+
*/
|
|
72
|
+
interface MaterialSlotAttributeConfig {
|
|
73
|
+
/** 属性名(デフォルト: 'mtoonMaterialSlot') */
|
|
74
|
+
name: string;
|
|
75
|
+
/** 説明(オプション) */
|
|
76
|
+
description?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* MToonAtlasMaterial オプション
|
|
80
|
+
*
|
|
81
|
+
* THREE.ShaderMaterialParameters を拡張した、インスタンシング対応オプション
|
|
82
|
+
*/
|
|
83
|
+
interface MToonAtlasOptions extends THREE.ShaderMaterialParameters {
|
|
84
|
+
/** ベースカラー */
|
|
85
|
+
color?: THREE.ColorRepresentation;
|
|
86
|
+
/** エミッシブカラー */
|
|
87
|
+
emissive?: THREE.ColorRepresentation;
|
|
88
|
+
/** エミッシブ強度 */
|
|
89
|
+
emissiveIntensity?: number;
|
|
90
|
+
/** 透明度 */
|
|
91
|
+
transparent?: boolean;
|
|
92
|
+
/** 深度書き込み */
|
|
93
|
+
depthWrite?: boolean;
|
|
94
|
+
/** パラメータテクスチャディスクリプタ */
|
|
95
|
+
parameterTexture?: ParameterTextureDescriptor;
|
|
96
|
+
/** スロット属性設定 */
|
|
97
|
+
slotAttribute?: MaterialSlotAttributeConfig;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* MToonAtlasMaterial
|
|
102
|
+
*
|
|
103
|
+
* avatar-optimizer で生成されたアトラス化テクスチャとパラメータテクスチャを使用して、
|
|
104
|
+
* 複数の MToon マテリアルを 1 つに統合するマテリアルクラス。
|
|
105
|
+
*
|
|
106
|
+
* ShaderMaterial を継承し、パラメータテクスチャからマテリアルパラメータを復元します。
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* デバッグモードの種類
|
|
111
|
+
*
|
|
112
|
+
* - 'none': デバッグなし(通常描画)
|
|
113
|
+
* - 'uv': UV座標を可視化(RG = UV)
|
|
114
|
+
* - 'normal': ワールド法線を可視化
|
|
115
|
+
* - 'shadow': シャドウ座標を可視化(シャドウマップが無効なら黄色)
|
|
116
|
+
* - 'shadowValue': 実際のシャドウ値を可視化(白=影なし、黒=影あり)
|
|
117
|
+
* - 'receiveShadow': receiveShadowフラグの確認(緑=有効、赤=無効)
|
|
118
|
+
* - 'lightDir': ライト方向を可視化
|
|
119
|
+
* - 'dotNL': 法線とライト方向の内積を可視化
|
|
120
|
+
* - 'shading': MToonシェーディング結果を可視化
|
|
121
|
+
* - 'shadingParams': shadingShift/shadingToonyの値を可視化
|
|
122
|
+
* - 'litShadeRate': 明暗のグラデーションを可視化
|
|
123
|
+
* - 'alpha': アルファ値を可視化(R=最終alpha, G=opacity, B=テクスチャalpha)
|
|
124
|
+
*/
|
|
125
|
+
type DebugMode = 'none' | 'uv' | 'normal' | 'shadow' | 'shadowValue' | 'receiveShadow' | 'lightDir' | 'dotNL' | 'shading' | 'shadingParams' | 'paramRaw' | 'litShadeRate' | 'alpha';
|
|
126
|
+
/**
|
|
127
|
+
* MToonAtlasMaterial
|
|
128
|
+
*
|
|
129
|
+
* パラメータテクスチャベースの統合 MToon マテリアル
|
|
130
|
+
*/
|
|
131
|
+
declare class MToonAtlasMaterial extends THREE.ShaderMaterial {
|
|
132
|
+
/**
|
|
133
|
+
* マテリアル識別フラグ
|
|
134
|
+
*/
|
|
135
|
+
readonly isMToonAtlasMaterial: true;
|
|
136
|
+
/**
|
|
137
|
+
* パラメータテクスチャディスクリプタ
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
private _parameterTexture;
|
|
142
|
+
/**
|
|
143
|
+
* スロット属性設定
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
private _slotAttribute;
|
|
148
|
+
/**
|
|
149
|
+
* 現在のデバッグモード
|
|
150
|
+
*
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
private _debugMode;
|
|
154
|
+
/**
|
|
155
|
+
* アウトラインモードフラグ
|
|
156
|
+
*
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
private _isOutline;
|
|
160
|
+
/**
|
|
161
|
+
* アウトライン幅モード
|
|
162
|
+
* - 'none': アウトラインなし
|
|
163
|
+
* - 'worldCoordinates': ワールド座標系での固定幅
|
|
164
|
+
* - 'screenCoordinates': スクリーン座標系での固定幅
|
|
165
|
+
*
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
private _outlineWidthMode;
|
|
169
|
+
/**
|
|
170
|
+
* Uniform インターフェース
|
|
171
|
+
*
|
|
172
|
+
* TODO: 完全な型定義を追加
|
|
173
|
+
*/
|
|
174
|
+
uniforms: {
|
|
175
|
+
[key: string]: THREE.IUniform<any>;
|
|
176
|
+
} & {
|
|
177
|
+
uParameterTexture: THREE.IUniform<THREE.Texture | null>;
|
|
178
|
+
uParameterTextureSize: THREE.IUniform<THREE.Vector2>;
|
|
179
|
+
uTexelsPerSlot: THREE.IUniform<number>;
|
|
180
|
+
map: THREE.IUniform<THREE.Texture | null>;
|
|
181
|
+
shadeMultiplyTexture: THREE.IUniform<THREE.Texture | null>;
|
|
182
|
+
shadingShiftTexture: THREE.IUniform<THREE.Texture | null>;
|
|
183
|
+
normalMap: THREE.IUniform<THREE.Texture | null>;
|
|
184
|
+
emissiveMap: THREE.IUniform<THREE.Texture | null>;
|
|
185
|
+
matcapTexture: THREE.IUniform<THREE.Texture | null>;
|
|
186
|
+
rimMultiplyTexture: THREE.IUniform<THREE.Texture | null>;
|
|
187
|
+
uvAnimationMaskTexture: THREE.IUniform<THREE.Texture | null>;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* コンストラクタ
|
|
191
|
+
*
|
|
192
|
+
* @param parameters オプション
|
|
193
|
+
*/
|
|
194
|
+
constructor(parameters?: MToonAtlasOptions);
|
|
195
|
+
/**
|
|
196
|
+
* パラメータテクスチャを設定
|
|
197
|
+
*
|
|
198
|
+
* @param descriptor パラメータテクスチャディスクリプタ
|
|
199
|
+
* @returns this(チェーン可能)
|
|
200
|
+
*/
|
|
201
|
+
setParameterTexture(descriptor: ParameterTextureDescriptor | null): this;
|
|
202
|
+
/**
|
|
203
|
+
* Definesを更新
|
|
204
|
+
*/
|
|
205
|
+
private _updateDefines;
|
|
206
|
+
/**
|
|
207
|
+
* スロット属性を設定
|
|
208
|
+
*
|
|
209
|
+
* シェーダー内の属性名を動的に変更します。
|
|
210
|
+
* GLTFLoaderはカスタム属性名を小文字に変換するため、
|
|
211
|
+
* ローダーで設定された属性名に合わせてシェーダーを更新します。
|
|
212
|
+
*
|
|
213
|
+
* @param config スロット属性設定
|
|
214
|
+
* @returns this(チェーン可能)
|
|
215
|
+
*/
|
|
216
|
+
setSlotAttribute(config: MaterialSlotAttributeConfig): this;
|
|
217
|
+
/**
|
|
218
|
+
* パラメータテクスチャを取得
|
|
219
|
+
*
|
|
220
|
+
* @returns パラメータテクスチャディスクリプタ
|
|
221
|
+
*/
|
|
222
|
+
get parameterTexture(): ParameterTextureDescriptor | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* スロット属性を取得
|
|
225
|
+
*
|
|
226
|
+
* @returns スロット属性設定
|
|
227
|
+
*/
|
|
228
|
+
get slotAttribute(): MaterialSlotAttributeConfig;
|
|
229
|
+
/**
|
|
230
|
+
* アトラス化テクスチャを設定
|
|
231
|
+
*
|
|
232
|
+
* @param atlases アトラス化テクスチャセット
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
235
|
+
private _setAtlasedTextures;
|
|
236
|
+
/**
|
|
237
|
+
* マテリアルをコピー
|
|
238
|
+
*
|
|
239
|
+
* @param source ソースマテリアル
|
|
240
|
+
* @returns this
|
|
241
|
+
*/
|
|
242
|
+
copy(source: this): this;
|
|
243
|
+
/**
|
|
244
|
+
* マテリアルをクローン
|
|
245
|
+
*
|
|
246
|
+
* @returns クローンされたマテリアル
|
|
247
|
+
*/
|
|
248
|
+
clone(): this;
|
|
249
|
+
/**
|
|
250
|
+
* アウトラインモードを取得
|
|
251
|
+
*
|
|
252
|
+
* @returns アウトラインモードかどうか
|
|
253
|
+
*/
|
|
254
|
+
get isOutline(): boolean;
|
|
255
|
+
/**
|
|
256
|
+
* アウトラインモードを設定
|
|
257
|
+
*
|
|
258
|
+
* @param value アウトラインモードにするかどうか
|
|
259
|
+
*/
|
|
260
|
+
set isOutline(value: boolean);
|
|
261
|
+
/**
|
|
262
|
+
* アウトライン幅モードを取得
|
|
263
|
+
*
|
|
264
|
+
* @returns アウトライン幅モード
|
|
265
|
+
*/
|
|
266
|
+
get outlineWidthMode(): 'none' | 'worldCoordinates' | 'screenCoordinates';
|
|
267
|
+
/**
|
|
268
|
+
* アウトライン幅モードを設定
|
|
269
|
+
*
|
|
270
|
+
* @param value アウトライン幅モード
|
|
271
|
+
*/
|
|
272
|
+
set outlineWidthMode(value: 'none' | 'worldCoordinates' | 'screenCoordinates');
|
|
273
|
+
/**
|
|
274
|
+
* アウトライン用マテリアルを作成
|
|
275
|
+
*
|
|
276
|
+
* このマテリアルをベースに、アウトライン描画用のマテリアルを生成します。
|
|
277
|
+
* 生成されたマテリアルは `isOutline = true` が設定され、
|
|
278
|
+
* `side = BackSide` で裏面を描画します。
|
|
279
|
+
*
|
|
280
|
+
* @param widthMode アウトライン幅モード(デフォルト: 'worldCoordinates')
|
|
281
|
+
* @returns アウトライン用マテリアル
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* const baseMaterial = new MToonAtlasMaterial()
|
|
286
|
+
* baseMaterial.setParameterTexture(descriptor)
|
|
287
|
+
*
|
|
288
|
+
* const outlineMaterial = baseMaterial.createOutlineMaterial()
|
|
289
|
+
* // outlineMaterial.isOutline === true
|
|
290
|
+
* // outlineMaterial.side === THREE.BackSide
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
createOutlineMaterial(widthMode?: 'worldCoordinates' | 'screenCoordinates'): MToonAtlasMaterial;
|
|
294
|
+
/**
|
|
295
|
+
* フレーム更新(アニメーション対応)
|
|
296
|
+
*
|
|
297
|
+
* UV アニメーションやその他の時間依存パラメータを更新
|
|
298
|
+
*
|
|
299
|
+
* @param deltaTime フレーム経過時間(秒)
|
|
300
|
+
*/
|
|
301
|
+
update(_deltaTime: number): void;
|
|
302
|
+
/**
|
|
303
|
+
* デバッグモードを設定
|
|
304
|
+
*
|
|
305
|
+
* シャドウの問題を調査するために、様々なパラメータを可視化できます。
|
|
306
|
+
*
|
|
307
|
+
* @param mode デバッグモード
|
|
308
|
+
* @returns this(チェーン可能)
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* // シャドウ値を可視化(白=影なし、黒=影あり)
|
|
313
|
+
* material.setDebugMode('shadowValue')
|
|
314
|
+
*
|
|
315
|
+
* // 通常描画に戻す
|
|
316
|
+
* material.setDebugMode('none')
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
setDebugMode(mode: DebugMode): this;
|
|
320
|
+
/**
|
|
321
|
+
* 現在のデバッグモードを取得
|
|
322
|
+
*
|
|
323
|
+
* @returns 現在のデバッグモード
|
|
324
|
+
*/
|
|
325
|
+
get debugMode(): DebugMode;
|
|
326
|
+
/**
|
|
327
|
+
* 利用可能なデバッグモードの一覧を取得
|
|
328
|
+
*
|
|
329
|
+
* @returns デバッグモードの配列
|
|
330
|
+
*/
|
|
331
|
+
static getAvailableDebugModes(): DebugMode[];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
declare const MTOON_ATLAS_EXTENSION_NAME = "XRIFT_mtoon_atlas";
|
|
335
|
+
/**
|
|
336
|
+
* GLTF Extension Schema for XRIFT_mtoon_atlas
|
|
337
|
+
*/
|
|
338
|
+
/**
|
|
339
|
+
* アウトライン幅モード
|
|
340
|
+
*/
|
|
341
|
+
type OutlineWidthMode = 'none' | 'worldCoordinates' | 'screenCoordinates';
|
|
342
|
+
interface MToonAtlasExtensionSchema {
|
|
343
|
+
version: string;
|
|
344
|
+
parameterTexture: {
|
|
345
|
+
index: number;
|
|
346
|
+
texelsPerSlot: number;
|
|
347
|
+
slotCount: number;
|
|
348
|
+
};
|
|
349
|
+
slotAttributeName: string;
|
|
350
|
+
atlasedTextures: {
|
|
351
|
+
baseColor?: {
|
|
352
|
+
index: number;
|
|
353
|
+
};
|
|
354
|
+
shade?: {
|
|
355
|
+
index: number;
|
|
356
|
+
};
|
|
357
|
+
shadingShift?: {
|
|
358
|
+
index: number;
|
|
359
|
+
};
|
|
360
|
+
normal?: {
|
|
361
|
+
index: number;
|
|
362
|
+
};
|
|
363
|
+
emissive?: {
|
|
364
|
+
index: number;
|
|
365
|
+
};
|
|
366
|
+
matcap?: {
|
|
367
|
+
index: number;
|
|
368
|
+
};
|
|
369
|
+
rim?: {
|
|
370
|
+
index: number;
|
|
371
|
+
};
|
|
372
|
+
uvAnimationMask?: {
|
|
373
|
+
index: number;
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* アウトラインマテリアルかどうか
|
|
378
|
+
* true の場合、このマテリアルはアウトライン描画用
|
|
379
|
+
*/
|
|
380
|
+
isOutline?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* アウトライン幅モード
|
|
383
|
+
* - 'none': アウトラインなし
|
|
384
|
+
* - 'worldCoordinates': ワールド座標系での固定幅
|
|
385
|
+
* - 'screenCoordinates': スクリーン座標系での固定幅
|
|
386
|
+
*/
|
|
387
|
+
outlineWidthMode?: OutlineWidthMode;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Type definition for GLTF parser/writer context
|
|
391
|
+
* This is a partial definition of GLTFParser/GLTFWriter from three/examples/jsm/loaders/GLTFLoader
|
|
392
|
+
*/
|
|
393
|
+
interface GLTFParser {
|
|
394
|
+
json: any;
|
|
395
|
+
associations: Map<any, any>;
|
|
396
|
+
getDependency: (type: string, index: number) => Promise<any>;
|
|
397
|
+
loadTexture: (index: number) => Promise<Texture>;
|
|
398
|
+
}
|
|
399
|
+
interface GLTFWriter {
|
|
400
|
+
json: any;
|
|
401
|
+
nodeMap: Map<any, number>;
|
|
402
|
+
pending: Promise<void>[];
|
|
403
|
+
byteOffset: number;
|
|
404
|
+
processTexture: (texture: Texture) => number;
|
|
405
|
+
processAccessor: (attribute: BufferAttribute | InterleavedBufferAttribute, geometry?: BufferGeometry, start?: number, count?: number) => number;
|
|
406
|
+
processBuffer: (buffer: ArrayBuffer) => number;
|
|
407
|
+
processBufferViewImage: (blob: Blob) => Promise<number>;
|
|
408
|
+
cache: {
|
|
409
|
+
meshes: Map<any, any>;
|
|
410
|
+
attributes: Map<number, number>;
|
|
411
|
+
attributesNormalized: Map<any, any>;
|
|
412
|
+
materials: Map<any, any>;
|
|
413
|
+
textures: Map<any, any>;
|
|
414
|
+
images: Map<any, any>;
|
|
415
|
+
};
|
|
416
|
+
uids: Map<any, Map<boolean, number>>;
|
|
417
|
+
uid: number;
|
|
418
|
+
getUID: (attribute: BufferAttribute | InterleavedBufferAttribute, isRelativeCopy?: boolean) => number;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
declare class MToonAtlasLoaderPlugin {
|
|
422
|
+
readonly name = "XRIFT_mtoon_atlas";
|
|
423
|
+
private parser;
|
|
424
|
+
constructor(parser: GLTFParser);
|
|
425
|
+
loadMaterial(materialIndex: number): Promise<Material> | null;
|
|
426
|
+
/**
|
|
427
|
+
* パラメータテクスチャを16bit精度で読み込む
|
|
428
|
+
* GLTFLoaderのloadTextureはImageBitmap経由で8bitに変換されるため、
|
|
429
|
+
* 直接PNGデータを取得してfast-pngでデコードする
|
|
430
|
+
*/
|
|
431
|
+
private _loadParameterTexture16bit;
|
|
432
|
+
/**
|
|
433
|
+
* KTX2テクスチャを直接読み込む
|
|
434
|
+
* GLTFLoaderのloadTextureがKTX2を正しく処理できない場合のフォールバック
|
|
435
|
+
*/
|
|
436
|
+
private _loadKtx2Texture;
|
|
437
|
+
private _loadMaterialAsync;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* テクスチャ圧縮オプション
|
|
442
|
+
* エクスポート時にアトラステクスチャを KTX2 形式で圧縮する
|
|
443
|
+
*/
|
|
444
|
+
interface TextureCompressionOptions extends Ktx2CompressionOptions {
|
|
445
|
+
/**
|
|
446
|
+
* WASM ファイルのディレクトリURL(initBasisEncoder に渡す用)
|
|
447
|
+
* 実際の初期化は exportVRM 側で行うため、ここでは使用しない
|
|
448
|
+
*/
|
|
449
|
+
wasmDir?: string;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* GLTFExporter用のMToonAtlasエクスポートプラグイン
|
|
453
|
+
*
|
|
454
|
+
* GLTFExporterはShaderMaterialをサポートしないため、
|
|
455
|
+
* beforeParseでテクスチャを処理し、afterParseでマテリアル定義をJSONに追加します。
|
|
456
|
+
*/
|
|
457
|
+
declare class MToonAtlasExporterPlugin {
|
|
458
|
+
readonly name = "XRIFT_mtoon_atlas";
|
|
459
|
+
private writer;
|
|
460
|
+
private mtoonAtlasMeshes;
|
|
461
|
+
private textureIndices;
|
|
462
|
+
private pendingTextureIndices;
|
|
463
|
+
private textureCache;
|
|
464
|
+
private textureCompressionOptions?;
|
|
465
|
+
constructor(writer: GLTFWriter);
|
|
466
|
+
/**
|
|
467
|
+
* テクスチャ圧縮オプションを設定
|
|
468
|
+
* 設定された場合、アトラステクスチャを KTX2 形式で圧縮してエクスポート
|
|
469
|
+
*
|
|
470
|
+
* @param options - 圧縮オプション
|
|
471
|
+
*/
|
|
472
|
+
setTextureCompressionOptions(options: TextureCompressionOptions): void;
|
|
473
|
+
/**
|
|
474
|
+
* beforeParseでシーン内のMToonAtlasMaterialを収集し、テクスチャを処理
|
|
475
|
+
* また、スロット属性名をGLTFExporterが正しい名前でエクスポートするようにリネーム
|
|
476
|
+
*/
|
|
477
|
+
beforeParse(input: Object3D | Object3D[]): void;
|
|
478
|
+
/**
|
|
479
|
+
* 属性データの重複を検出してアクセサを共有する最適化
|
|
480
|
+
*
|
|
481
|
+
* GLTFExporterには以下の問題がある:
|
|
482
|
+
* 1. morphTarget処理でattribute.clone()を毎回呼び出すため、キャッシュが効かない
|
|
483
|
+
* 2. 同一データを持つ異なる属性オブジェクトが別々にエクスポートされる
|
|
484
|
+
*
|
|
485
|
+
* この問題を回避するため、processAccessorをラップして
|
|
486
|
+
* データ内容のフィンガープリントでキャッシュを行う
|
|
487
|
+
*/
|
|
488
|
+
private optimizeMorphAttributeSharing;
|
|
489
|
+
/**
|
|
490
|
+
* マテリアルのテクスチャを処理してインデックスを保存
|
|
491
|
+
* 非同期でBINチャンクに書き込み、完了後にtextureIndicesに格納
|
|
492
|
+
*/
|
|
493
|
+
private processTexturesForMaterial;
|
|
494
|
+
/**
|
|
495
|
+
* パラメータテクスチャをキャッシュ付きで処理
|
|
496
|
+
* 同じUUIDのテクスチャは1回だけ処理される
|
|
497
|
+
*/
|
|
498
|
+
private processParameterTextureWithCache;
|
|
499
|
+
/**
|
|
500
|
+
* 通常テクスチャをキャッシュ付きで処理
|
|
501
|
+
* 同じUUIDのテクスチャは1回だけ処理される
|
|
502
|
+
*/
|
|
503
|
+
private processTextureWithCache;
|
|
504
|
+
/**
|
|
505
|
+
* パラメータテクスチャを処理(BINチャンクに書き込み)
|
|
506
|
+
* Canvas 2DのPremultiplied Alpha問題を回避するため、
|
|
507
|
+
* 生のRGBAデータから直接PNGを生成してBINチャンクに格納
|
|
508
|
+
*/
|
|
509
|
+
private processParameterTexture;
|
|
510
|
+
/**
|
|
511
|
+
* テクスチャを処理してBINチャンクに書き込む
|
|
512
|
+
* @param texture - 処理するテクスチャ
|
|
513
|
+
*
|
|
514
|
+
* 注: writer.processTextureは使用しない。
|
|
515
|
+
* GLTFExporter内部でテクスチャがキャッシュされないため、
|
|
516
|
+
* 同じテクスチャオブジェクトでも毎回新しいエントリが作成されてしまう。
|
|
517
|
+
* 代わりに手動でテクスチャを登録することで、キャッシュを正しく機能させる。
|
|
518
|
+
*/
|
|
519
|
+
private processTextureWithFallback;
|
|
520
|
+
/**
|
|
521
|
+
* テクスチャを KTX2 形式で処理してBINチャンクに書き込む
|
|
522
|
+
* @param texture - 処理するテクスチャ
|
|
523
|
+
*/
|
|
524
|
+
private processTextureAsKtx2;
|
|
525
|
+
/**
|
|
526
|
+
* テクスチャを KTX2 バイナリに圧縮
|
|
527
|
+
* @param texture - 処理するテクスチャ
|
|
528
|
+
* @returns KTX2 バイナリデータ
|
|
529
|
+
*/
|
|
530
|
+
private compressTextureToKtx2;
|
|
531
|
+
/**
|
|
532
|
+
* 様々な画像形式からRGBAデータを抽出
|
|
533
|
+
* @param image - 画像データ(DataTexture, HTMLImageElement, ImageBitmap, HTMLCanvasElement等)
|
|
534
|
+
* @returns RGBA形式のUint8Array
|
|
535
|
+
*/
|
|
536
|
+
private extractRgbaData;
|
|
537
|
+
/**
|
|
538
|
+
* テクスチャを PNG 形式で処理してBINチャンクに書き込む(従来の処理)
|
|
539
|
+
* @param texture - 処理するテクスチャ
|
|
540
|
+
*/
|
|
541
|
+
private processTextureAsPng;
|
|
542
|
+
/**
|
|
543
|
+
* 画像をBlobに変換する(非同期)
|
|
544
|
+
*/
|
|
545
|
+
private imageToBlobAsync;
|
|
546
|
+
/**
|
|
547
|
+
* 1x1透明プレースホルダーBlob作成
|
|
548
|
+
*/
|
|
549
|
+
private createPlaceholderBlob;
|
|
550
|
+
/**
|
|
551
|
+
* afterParseでマテリアルとメッシュのプリミティブ属性をJSONに追加
|
|
552
|
+
*
|
|
553
|
+
* GLTFExporterはShaderMaterialをスキップするため、
|
|
554
|
+
* ここで手動でマテリアル定義を追加します。
|
|
555
|
+
*
|
|
556
|
+
* 注: テクスチャ処理のPromiseはwriter.pendingに追加済みなので、
|
|
557
|
+
* afterParse完了後にGLTFExporterがawait Promise.all(pending)で待機する。
|
|
558
|
+
* マテリアル定義内のテクスチャインデックスは、pendingのPromise内で更新される。
|
|
559
|
+
*/
|
|
560
|
+
afterParse(_input: Object3D | Object3D[]): void;
|
|
561
|
+
/**
|
|
562
|
+
* 全てのテクスチャインデックスが解決され、textureIndicesに登録されるのを待つ
|
|
563
|
+
*/
|
|
564
|
+
private waitForAllTextureIndices;
|
|
565
|
+
/**
|
|
566
|
+
* MToonAtlasMaterialからGLTFマテリアル定義を作成
|
|
567
|
+
*/
|
|
568
|
+
private createMaterialDef;
|
|
569
|
+
/**
|
|
570
|
+
* メッシュのプリミティブにマテリアルとスロット属性を設定
|
|
571
|
+
*/
|
|
572
|
+
private updateMeshPrimitive;
|
|
573
|
+
/**
|
|
574
|
+
* スロット属性をプリミティブに追加
|
|
575
|
+
*/
|
|
576
|
+
private addSlotAttribute;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export { type AtlasedTextureSet, type DebugMode, MTOON_ATLAS_EXTENSION_NAME, MToonAtlasExporterPlugin, type MToonAtlasExtensionSchema, MToonAtlasLoaderPlugin, MToonAtlasMaterial, type MToonAtlasOptions, type MaterialSlotAttributeConfig, type ParameterSemantic, type ParameterSemanticId, type ParameterTextureDescriptor, type TextureCompressionOptions };
|