@onerjs/serializers 9.0.2 → 9.0.3
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/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js +12 -10
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_coat.pure.js +11 -9
- package/glTF/2.0/Extensions/KHR_materials_coat.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_scatter.d.ts +5 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.js +8 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.pure.d.ts +120 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.pure.js +396 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.pure.d.ts +2 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js +141 -39
- package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.pure.js +2 -48
- package/glTF/2.0/Extensions/KHR_materials_volume.pure.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +1 -1
- package/glTF/2.0/Extensions/index.js +1 -1
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/Extensions/pure.d.ts +1 -1
- package/glTF/2.0/Extensions/pure.js +1 -1
- package/glTF/2.0/Extensions/pure.js.map +1 -1
- package/glTF/2.0/glTFExporter.d.ts +6 -0
- package/glTF/2.0/glTFExporter.js +9 -0
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +2 -1
- package/glTF/2.0/glTFMaterialExporter.js +68 -31
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/glTF/2.0/glTFUtilities.d.ts +37 -1
- package/glTF/2.0/glTFUtilities.js +99 -0
- package/glTF/2.0/glTFUtilities.js.map +1 -1
- package/package.json +2 -2
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.d.ts +0 -5
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js +0 -8
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js.map +0 -1
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.d.ts +0 -45
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js +0 -145
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js.map +0 -1
|
@@ -2,7 +2,9 @@ import { GLTFExporter } from "../glTFExporter.js";
|
|
|
2
2
|
import { PBRMaterial } from "@onerjs/core/Materials/PBR/pbrMaterial.pure.js";
|
|
3
3
|
import { Logger } from "@onerjs/core/Misc/logger.js";
|
|
4
4
|
import { OpenPBRMaterial } from "@onerjs/core/Materials/PBR/openpbrMaterial.pure.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Color4 } from "@onerjs/core/Maths/math.color.pure.js";
|
|
6
|
+
import { LerpTexturesAsync, MultiplyTexturesAsync, InvertTextureAsync, CreateTextureWithFactorOperand, CreateFactorOperand, TextureChannel, TextureColorSpace, ChannelMask, } from "@onerjs/core/Materials/Textures/textureProcessor.js";
|
|
7
|
+
import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@onerjs/core/Materials/Textures/textureMerger.js";
|
|
6
8
|
const NAME = "KHR_materials_transmission";
|
|
7
9
|
/**
|
|
8
10
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
|
|
@@ -17,10 +19,27 @@ export class KHR_materials_transmission {
|
|
|
17
19
|
/** Defines whether this extension is required */
|
|
18
20
|
this.required = false;
|
|
19
21
|
this._wasUsed = false;
|
|
22
|
+
// Caches the lerp result per material (computed in postExportMaterialAdditionalTexturesAsync,
|
|
23
|
+
// consumed in postExportMaterialAsync). Texture is disposed in dispose().
|
|
24
|
+
this._transmissionOperands = new Map();
|
|
25
|
+
// ownsTexture is false when the texture is the material's own base color texture (UV mismatch path),
|
|
26
|
+
// which must not be disposed.
|
|
27
|
+
this._baseColorOperands = new Map();
|
|
20
28
|
this._exporter = exporter;
|
|
21
29
|
}
|
|
22
30
|
/** Dispose */
|
|
23
|
-
dispose() {
|
|
31
|
+
dispose() {
|
|
32
|
+
for (const operand of this._transmissionOperands.values()) {
|
|
33
|
+
operand.texture?.dispose();
|
|
34
|
+
}
|
|
35
|
+
this._transmissionOperands.clear();
|
|
36
|
+
for (const operand of this._baseColorOperands.values()) {
|
|
37
|
+
if (operand.ownsTexture) {
|
|
38
|
+
operand.texture?.dispose();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
this._baseColorOperands.clear();
|
|
42
|
+
}
|
|
24
43
|
/** @internal */
|
|
25
44
|
get wasUsed() {
|
|
26
45
|
return this._wasUsed;
|
|
@@ -43,14 +62,110 @@ export class KHR_materials_transmission {
|
|
|
43
62
|
}
|
|
44
63
|
}
|
|
45
64
|
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
if (this._isExtensionEnabled(babylonMaterial)) {
|
|
66
|
+
const subsurfaceWeight = babylonMaterial.subsurfaceWeight;
|
|
67
|
+
const transmissionWeight = babylonMaterial.transmissionWeight;
|
|
68
|
+
const subsurfaceChannel = babylonMaterial._useSubsurfaceWeightFromTextureAlpha ? TextureChannel.A : TextureChannel.R;
|
|
69
|
+
// The weight bake below can only sample one UV set. If the two weight textures use different
|
|
70
|
+
// UV sets, the texture processor would otherwise silently keep whichever comes first. Keep the
|
|
71
|
+
// transmission weight mask instead (it is the lerp weight, so dropping it changes the result
|
|
72
|
+
// the most) and fall back to the subsurface weight factor, logging an error since the exported
|
|
73
|
+
// material will differ.
|
|
74
|
+
const transmissionWeightTexture = babylonMaterial.transmissionWeightTexture;
|
|
75
|
+
let subsurfaceWeightTexture = babylonMaterial.subsurfaceWeightTexture;
|
|
76
|
+
if (subsurfaceWeightTexture && transmissionWeightTexture && subsurfaceWeightTexture.coordinatesIndex !== transmissionWeightTexture.coordinatesIndex) {
|
|
77
|
+
Logger.Error(`${context}: subsurfaceWeightTexture (UV${subsurfaceWeightTexture.coordinatesIndex}) and transmissionWeightTexture (UV${transmissionWeightTexture.coordinatesIndex}) of material '${babylonMaterial.name}' use different UV sets and cannot be combined into a single KHR_materials_transmission texture. Ignoring subsurfaceWeightTexture.`);
|
|
78
|
+
subsurfaceWeightTexture = null;
|
|
79
|
+
}
|
|
80
|
+
// OpenPBR can have surface transmission in either transmission_weight or subsurface_weight,
|
|
81
|
+
// and we need to combine them into a single transmission weight for glTF.
|
|
82
|
+
// The final transmission weight is computed as a linear interpolation of the two weights.
|
|
83
|
+
// lerp(subsurface_weight, 1, transmission_weight)
|
|
84
|
+
const sOp = CreateTextureWithFactorOperand(subsurfaceWeightTexture, new Color4(subsurfaceWeight, subsurfaceWeight, subsurfaceWeight, 1.0), subsurfaceChannel);
|
|
85
|
+
const tOp = CreateTextureWithFactorOperand(babylonMaterial.transmissionWeightTexture, new Color4(transmissionWeight, transmissionWeight, transmissionWeight, 1.0), TextureChannel.R);
|
|
86
|
+
const transWeightResult = await LerpTexturesAsync(`transmission weight (${babylonMaterial.name})`, sOp, CreateFactorOperand(new Color4(1, 1, 1, 1)), tOp, babylonMaterial.getScene());
|
|
87
|
+
this._transmissionOperands.set(babylonMaterial, { factor: transWeightResult.factor ?? null, texture: transWeightResult.texture ?? null });
|
|
88
|
+
if (transWeightResult.texture) {
|
|
89
|
+
additionalTextures.push(transWeightResult.texture);
|
|
90
|
+
}
|
|
91
|
+
// glTF applies the base color as a tint on transmission while OpenPBR does not, so we lerp
|
|
92
|
+
// the base color toward the transmission tint by the transmission weight (see below). The
|
|
93
|
+
// material exporter skips the base color texture when this extension is enabled, so the base
|
|
94
|
+
// color is always written from here, and geometryOpacity has to be packed the same way that
|
|
95
|
+
// exporter does: the scalar opacity goes into the base color factor alpha, and the opacity
|
|
96
|
+
// texture is packed into the base color texture alpha. This is done on the lerp's input
|
|
97
|
+
// rather than its output; the lerp weight's alpha is 0, so the input alpha passes through
|
|
98
|
+
// unchanged into the exported base color.
|
|
99
|
+
const geometryOpacity = babylonMaterial.geometryOpacity;
|
|
100
|
+
let baseColorTexture = babylonMaterial.baseColorTexture;
|
|
101
|
+
if (babylonMaterial.geometryOpacityTexture) {
|
|
102
|
+
// Pack base color RGB and the opacity texture into a single RGBA texture (mirrors GLTFMaterialExporter).
|
|
103
|
+
baseColorTexture = await MergeTexturesAsync(`base color opacity (${babylonMaterial.name})`, {
|
|
104
|
+
...CreateRGBAConfiguration(babylonMaterial.baseColorTexture ? CreateTextureInput(babylonMaterial.baseColorTexture, 0) : CreateConstantInput(1.0), babylonMaterial.baseColorTexture ? CreateTextureInput(babylonMaterial.baseColorTexture, 1) : CreateConstantInput(1.0), babylonMaterial.baseColorTexture ? CreateTextureInput(babylonMaterial.baseColorTexture, 2) : CreateConstantInput(1.0), CreateTextureInput(babylonMaterial.geometryOpacityTexture, 0)),
|
|
105
|
+
sharedSampling: true,
|
|
106
|
+
}, babylonMaterial.getScene());
|
|
107
|
+
}
|
|
108
|
+
// The lerp combines the base color with the transmission weight (and the metalness and
|
|
109
|
+
// transmission color textures). If any of those use a different UV set from the base color,
|
|
110
|
+
// the texture processor would have to drop one of them, which can wash out the base color
|
|
111
|
+
// entirely. In that case, export the base color (with opacity packed) without the lerp.
|
|
112
|
+
const metalness = babylonMaterial.baseMetalness;
|
|
113
|
+
const metalnessTexture = babylonMaterial.baseMetalnessTexture;
|
|
114
|
+
const usesVolume = !babylonMaterial.geometryThinWalled && babylonMaterial.transmissionDepth > 0;
|
|
115
|
+
if (baseColorTexture) {
|
|
116
|
+
const otherTextures = [transWeightResult.texture, metalness > 0 ? metalnessTexture : null, usesVolume ? null : babylonMaterial.transmissionColorTexture];
|
|
117
|
+
if (otherTextures.some((texture) => texture && texture.coordinatesIndex !== baseColorTexture.coordinatesIndex)) {
|
|
118
|
+
Logger.Warn(`${context}: The base color and transmission textures of material '${babylonMaterial.name}' use different UV sets; the base color will not be adjusted for KHR_materials_transmission.`);
|
|
119
|
+
this._baseColorOperands.set(babylonMaterial, {
|
|
120
|
+
factor: new Color4(babylonMaterial.baseColor.r, babylonMaterial.baseColor.g, babylonMaterial.baseColor.b, geometryOpacity),
|
|
121
|
+
texture: baseColorTexture,
|
|
122
|
+
ownsTexture: !!babylonMaterial.geometryOpacityTexture,
|
|
123
|
+
});
|
|
124
|
+
additionalTextures.push(baseColorTexture);
|
|
125
|
+
return additionalTextures;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Choose the color space from the source base color texture rather than baseColorTexture: the merged
|
|
129
|
+
// texture copies the sampled values unchanged, so it keeps the source's encoding (linear when the
|
|
130
|
+
// source uses a hardware sRGB buffer) even though its own gammaSpace flag does not reflect that.
|
|
131
|
+
const baseColorSpace = babylonMaterial.baseColorTexture?.gammaSpace ? TextureColorSpace.SRGB : TextureColorSpace.Linear;
|
|
132
|
+
const colorOp = CreateTextureWithFactorOperand(baseColorTexture, new Color4(babylonMaterial.baseColor.r, babylonMaterial.baseColor.g, babylonMaterial.baseColor.b, geometryOpacity), TextureChannel.RGBA, baseColorSpace);
|
|
133
|
+
let transOp = CreateTextureWithFactorOperand(transWeightResult.texture ?? null, new Color4(transWeightResult.factor?.r ?? 1, transWeightResult.factor?.g ?? 1, transWeightResult.factor?.b ?? 1, 0.0), // alpha is 0 because we don't want to modify the base color alpha channel
|
|
134
|
+
TextureChannel.R);
|
|
135
|
+
// The metal lobe sits on top of the dielectric (and its transmission) in both glTF and OpenPBR,
|
|
136
|
+
// and uses the base color as its F0. Only the dielectric fraction (1 - metalness) of the
|
|
137
|
+
// transmission should pull the base color toward the transmission tint, so scale the lerp
|
|
138
|
+
// weight by (1 - metalness). Fully metallic regions then keep their original base color.
|
|
139
|
+
if (metalness >= 1 && !metalnessTexture) {
|
|
140
|
+
transOp = CreateFactorOperand(new Color4(0, 0, 0, 0));
|
|
141
|
+
}
|
|
142
|
+
else if (metalness > 0) {
|
|
143
|
+
const dielectricOp = await InvertTextureAsync(`dielectric weight (${babylonMaterial.name})`, CreateTextureWithFactorOperand(metalnessTexture, new Color4(metalness, metalness, metalness, 1.0), babylonMaterial._useMetallicFromMetallicTextureBlue ? TextureChannel.B : TextureChannel.R), babylonMaterial.getScene(), ChannelMask.RGB);
|
|
144
|
+
// transOp has no dispose, so the cached transmission weight texture survives this pass.
|
|
145
|
+
transOp = await MultiplyTexturesAsync(`base color tint weight (${babylonMaterial.name})`, transOp, dielectricOp, babylonMaterial.getScene());
|
|
146
|
+
}
|
|
147
|
+
// glTF factors base color out of BOTH the diffuse and the transmission term, so the
|
|
148
|
+
// exported base color must lerp from base_color toward the transmission tint by the
|
|
149
|
+
// transmission weight (lerping toward a hardcoded white is only correct when that tint is
|
|
150
|
+
// white, and otherwise washes base_color out for 0 < T < 1).
|
|
151
|
+
// - Volumetric transmission (KHR_materials_volume active): the tint is carried by the
|
|
152
|
+
// volume attenuationColor, so neutralize the surface tint toward white to avoid
|
|
153
|
+
// double-tinting.
|
|
154
|
+
// - Thin-walled / no depth: the surface base color IS the transmission tint, so lerp
|
|
155
|
+
// toward transmission_color (which equals base_color for a thin-walled round-trip,
|
|
156
|
+
// leaving the base color unchanged).
|
|
157
|
+
const tintTargetOp = usesVolume
|
|
158
|
+
? CreateFactorOperand(new Color4(1, 1, 1, 1))
|
|
159
|
+
: CreateTextureWithFactorOperand(babylonMaterial.transmissionColorTexture, new Color4(babylonMaterial.transmissionColor.r, babylonMaterial.transmissionColor.g, babylonMaterial.transmissionColor.b, 1.0), TextureChannel.RGBA, babylonMaterial.transmissionColorTexture?.gammaSpace ? TextureColorSpace.SRGB : TextureColorSpace.Linear);
|
|
160
|
+
const baseColorResult = await LerpTexturesAsync(`base color (${babylonMaterial.name})`, colorOp, tintTargetOp, transOp, babylonMaterial.getScene(), TextureColorSpace.SRGB);
|
|
161
|
+
// Dispose the intermediate merged texture; LerpTexturesAsync does not own raw operand textures.
|
|
162
|
+
if (babylonMaterial.geometryOpacityTexture && baseColorTexture) {
|
|
163
|
+
baseColorTexture.dispose();
|
|
164
|
+
}
|
|
165
|
+
this._baseColorOperands.set(babylonMaterial, { factor: baseColorResult.factor ?? null, texture: baseColorResult.texture ?? null, ownsTexture: true });
|
|
166
|
+
if (baseColorResult.texture) {
|
|
167
|
+
additionalTextures.push(baseColorResult.texture);
|
|
50
168
|
}
|
|
51
|
-
}
|
|
52
|
-
if (babylonMaterial.subsurfaceWeight > 0 && babylonMaterial.subsurfaceWeightTexture) {
|
|
53
|
-
additionalTextures.push(babylonMaterial.subsurfaceWeightTexture);
|
|
54
169
|
}
|
|
55
170
|
}
|
|
56
171
|
return additionalTextures;
|
|
@@ -102,41 +217,28 @@ export class KHR_materials_transmission {
|
|
|
102
217
|
}
|
|
103
218
|
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
104
219
|
this._wasUsed = true;
|
|
105
|
-
const
|
|
106
|
-
const
|
|
220
|
+
const operand = this._transmissionOperands.get(babylonMaterial);
|
|
221
|
+
const bakedTexture = this._exporter._materialExporter.getTextureInfo(operand?.texture ?? null);
|
|
222
|
+
const bakedFactor = operand?.factor ?? null;
|
|
107
223
|
const transmissionInfo = {
|
|
108
|
-
transmissionFactor:
|
|
224
|
+
transmissionFactor: bakedTexture ? 1.0 : (bakedFactor?.r ?? 0.0),
|
|
109
225
|
};
|
|
110
|
-
if (
|
|
226
|
+
if (bakedTexture) {
|
|
111
227
|
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
112
|
-
|
|
113
|
-
if (transmissionTexture) {
|
|
114
|
-
transmissionInfo.transmissionTexture = transmissionTexture;
|
|
115
|
-
}
|
|
228
|
+
transmissionInfo.transmissionTexture = bakedTexture;
|
|
116
229
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
230
|
+
const baseColorOperand = this._baseColorOperands.get(babylonMaterial);
|
|
231
|
+
const baseColorBakedTexture = this._exporter._materialExporter.getTextureInfo(baseColorOperand?.texture ?? null);
|
|
232
|
+
const baseColorBakedFactor = baseColorOperand?.factor ?? null;
|
|
233
|
+
if (!node.pbrMetallicRoughness) {
|
|
234
|
+
node.pbrMetallicRoughness = {};
|
|
123
235
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
node.pbrMetallicRoughness.baseColorFactor[1] *= babylonMaterial.transmissionColor.g;
|
|
131
|
-
node.pbrMetallicRoughness.baseColorFactor[2] *= babylonMaterial.transmissionColor.b;
|
|
132
|
-
if (babylonMaterial.transmissionColorTexture && !node.pbrMetallicRoughness.baseColorTexture) {
|
|
133
|
-
const transmissionColorTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.transmissionColorTexture);
|
|
134
|
-
if (transmissionColorTexture) {
|
|
135
|
-
node.pbrMetallicRoughness.baseColorTexture = transmissionColorTexture;
|
|
136
|
-
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
236
|
+
node.pbrMetallicRoughness.baseColorFactor = baseColorBakedFactor
|
|
237
|
+
? [baseColorBakedFactor.r, baseColorBakedFactor.g, baseColorBakedFactor.b, baseColorBakedFactor.a]
|
|
238
|
+
: [1, 1, 1, 1];
|
|
239
|
+
if (baseColorBakedTexture) {
|
|
240
|
+
node.pbrMetallicRoughness.baseColorTexture = baseColorBakedTexture;
|
|
241
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
140
242
|
}
|
|
141
243
|
node.extensions || (node.extensions = {});
|
|
142
244
|
node.extensions[NAME] = transmissionInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_transmission.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,0BAA0B;IAcnC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,cAAc;IACP,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,yCAAyC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;QAC/G,MAAM,kBAAkB,GAAkB,EAAE,CAAC;QAE7C,IAAI,eAAe,YAAY,WAAW,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,EAAE,CAAC;gBAC5C,IAAI,eAAe,CAAC,UAAU,CAAC,0BAA0B,IAAI,eAAe,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC;oBAC3G,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,0BAA0B,CAAC,CAAC;gBACnF,CA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BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC;AACjG,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsTransmission } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial.pure\";\r\nimport { Color3 } from \"core/Maths/math.color.pure\";\r\n\r\nconst NAME = \"KHR_materials_transmission\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** Dispose */\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.refractionIntensityTexture && babylonMaterial.subSurface.useGltfStyleTextures) {\r\n additionalTextures.push(babylonMaterial.subSurface.refractionIntensityTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.transmissionWeight > 0 && babylonMaterial.transmissionWeightTexture) {\r\n additionalTextures.push(babylonMaterial.transmissionWeightTexture);\r\n if (babylonMaterial.transmissionColorTexture) {\r\n additionalTextures.push(babylonMaterial.transmissionColorTexture);\r\n }\r\n }\r\n if (babylonMaterial.subsurfaceWeight > 0 && babylonMaterial.subsurfaceWeightTexture) {\r\n additionalTextures.push(babylonMaterial.subsurfaceWeightTexture);\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: Material): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat instanceof OpenPBRMaterial && !mat.unlit) {\r\n return mat.transmissionWeight > 0 || mat.subsurfaceWeight > 0;\r\n } else if (mat instanceof PBRMaterial && !mat.unlit) {\r\n const subs = mat.subSurface;\r\n return (\r\n (subs.isRefractionEnabled && subs.refractionIntensity != undefined && subs.refractionIntensity != 0) ||\r\n (subs.refractionIntensityTexture != null && subs.useGltfStyleTextures)\r\n );\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns true if successful\r\n */\r\n public async postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n if (!this._isExtensionEnabled(babylonMaterial)) {\r\n return node;\r\n }\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n this._wasUsed = true;\r\n\r\n const subSurface = babylonMaterial.subSurface;\r\n const transmissionFactor = subSurface.refractionIntensity === 0 ? undefined : subSurface.refractionIntensity;\r\n\r\n const transmissionInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: transmissionFactor,\r\n };\r\n\r\n if (subSurface.refractionIntensityTexture) {\r\n if (subSurface.useGltfStyleTextures) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n const transmissionTexture = this._exporter._materialExporter.getTextureInfo(subSurface.refractionIntensityTexture);\r\n if (transmissionTexture) {\r\n transmissionInfo.transmissionTexture = transmissionTexture;\r\n }\r\n } else {\r\n Logger.Warn(`${context}: Exporting a subsurface refraction intensity texture without \\`useGltfStyleTextures\\` is not supported`);\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = transmissionInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n this._wasUsed = true;\r\n\r\n const subsurfaceFractionOfDielectric = (1.0 - babylonMaterial.transmissionWeight) * babylonMaterial.subsurfaceWeight;\r\n const transmissionFactor = subsurfaceFractionOfDielectric + babylonMaterial.transmissionWeight;\r\n\r\n const transmissionInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: transmissionFactor,\r\n };\r\n\r\n if (babylonMaterial.transmissionWeightTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n const transmissionTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.transmissionWeightTexture);\r\n if (transmissionTexture) {\r\n transmissionInfo.transmissionTexture = transmissionTexture;\r\n }\r\n } else if (babylonMaterial.subsurfaceWeightTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n const subsurfaceTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.subsurfaceWeightTexture);\r\n if (subsurfaceTexture) {\r\n transmissionInfo.transmissionTexture = subsurfaceTexture;\r\n }\r\n }\r\n\r\n if (babylonMaterial.transmissionDepth == 0.0 && (!babylonMaterial.transmissionColor.equals(Color3.White()) || babylonMaterial.transmissionColorTexture)) {\r\n if (node.pbrMetallicRoughness) {\r\n if (!node.pbrMetallicRoughness.baseColorFactor) {\r\n node.pbrMetallicRoughness.baseColorFactor = [1, 1, 1, 1];\r\n }\r\n node.pbrMetallicRoughness.baseColorFactor[0] *= babylonMaterial.transmissionColor.r;\r\n node.pbrMetallicRoughness.baseColorFactor[1] *= babylonMaterial.transmissionColor.g;\r\n node.pbrMetallicRoughness.baseColorFactor[2] *= babylonMaterial.transmissionColor.b;\r\n if (babylonMaterial.transmissionColorTexture && !node.pbrMetallicRoughness.baseColorTexture) {\r\n const transmissionColorTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.transmissionColorTexture);\r\n if (transmissionColorTexture) {\r\n node.pbrMetallicRoughness.baseColorTexture = transmissionColorTexture;\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n }\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = transmissionInfo;\r\n }\r\n\r\n return node;\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_transmission glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_transmission(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_materials_transmission.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EACH,iBAAiB,EACjB,qBAAqB,EACrB,kB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gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial.pure\";\r\nimport { Color4 } from \"core/Maths/math.color.pure\";\r\nimport { type Nullable } from \"core/types\";\r\nimport {\r\n LerpTexturesAsync,\r\n MultiplyTexturesAsync,\r\n InvertTextureAsync,\r\n CreateTextureWithFactorOperand,\r\n CreateFactorOperand,\r\n TextureChannel,\r\n TextureColorSpace,\r\n ChannelMask,\r\n type ITextureProcessOperand,\r\n} from \"core/Materials/Textures/textureProcessor\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\n\r\nconst NAME = \"KHR_materials_transmission\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n // Caches the lerp result per material (computed in postExportMaterialAdditionalTexturesAsync,\r\n // consumed in postExportMaterialAsync). Texture is disposed in dispose().\r\n private _transmissionOperands = new Map<Material, { factor: Nullable<Color4>; texture: Nullable<BaseTexture> }>();\r\n\r\n // ownsTexture is false when the texture is the material's own base color texture (UV mismatch path),\r\n // which must not be disposed.\r\n private _baseColorOperands = new Map<Material, { factor: Nullable<Color4>; texture: Nullable<BaseTexture>; ownsTexture: boolean }>();\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** Dispose */\r\n public dispose() {\r\n for (const operand of this._transmissionOperands.values()) {\r\n operand.texture?.dispose();\r\n }\r\n this._transmissionOperands.clear();\r\n for (const operand of this._baseColorOperands.values()) {\r\n if (operand.ownsTexture) {\r\n operand.texture?.dispose();\r\n }\r\n }\r\n this._baseColorOperands.clear();\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.refractionIntensityTexture && babylonMaterial.subSurface.useGltfStyleTextures) {\r\n additionalTextures.push(babylonMaterial.subSurface.refractionIntensityTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n const subsurfaceWeight = babylonMaterial.subsurfaceWeight;\r\n const transmissionWeight = babylonMaterial.transmissionWeight;\r\n const subsurfaceChannel = babylonMaterial._useSubsurfaceWeightFromTextureAlpha ? TextureChannel.A : TextureChannel.R;\r\n\r\n // The weight bake below can only sample one UV set. If the two weight textures use different\r\n // UV sets, the texture processor would otherwise silently keep whichever comes first. Keep the\r\n // transmission weight mask instead (it is the lerp weight, so dropping it changes the result\r\n // the most) and fall back to the subsurface weight factor, logging an error since the exported\r\n // material will differ.\r\n const transmissionWeightTexture = babylonMaterial.transmissionWeightTexture;\r\n let subsurfaceWeightTexture = babylonMaterial.subsurfaceWeightTexture;\r\n if (subsurfaceWeightTexture && transmissionWeightTexture && subsurfaceWeightTexture.coordinatesIndex !== transmissionWeightTexture.coordinatesIndex) {\r\n Logger.Error(\r\n `${context}: subsurfaceWeightTexture (UV${subsurfaceWeightTexture.coordinatesIndex}) and transmissionWeightTexture (UV${transmissionWeightTexture.coordinatesIndex}) of material '${babylonMaterial.name}' use different UV sets and cannot be combined into a single KHR_materials_transmission texture. Ignoring subsurfaceWeightTexture.`\r\n );\r\n subsurfaceWeightTexture = null;\r\n }\r\n\r\n // OpenPBR can have surface transmission in either transmission_weight or subsurface_weight,\r\n // and we need to combine them into a single transmission weight for glTF.\r\n // The final transmission weight is computed as a linear interpolation of the two weights.\r\n // lerp(subsurface_weight, 1, transmission_weight)\r\n const sOp = CreateTextureWithFactorOperand(subsurfaceWeightTexture, new Color4(subsurfaceWeight, subsurfaceWeight, subsurfaceWeight, 1.0), subsurfaceChannel);\r\n const tOp = CreateTextureWithFactorOperand(\r\n babylonMaterial.transmissionWeightTexture,\r\n new Color4(transmissionWeight, transmissionWeight, transmissionWeight, 1.0),\r\n TextureChannel.R\r\n );\r\n const transWeightResult = await LerpTexturesAsync(\r\n `transmission weight (${babylonMaterial.name})`,\r\n sOp,\r\n CreateFactorOperand(new Color4(1, 1, 1, 1)),\r\n tOp,\r\n babylonMaterial.getScene()\r\n );\r\n this._transmissionOperands.set(babylonMaterial, { factor: transWeightResult.factor ?? null, texture: transWeightResult.texture ?? null });\r\n\r\n if (transWeightResult.texture) {\r\n additionalTextures.push(transWeightResult.texture);\r\n }\r\n\r\n // glTF applies the base color as a tint on transmission while OpenPBR does not, so we lerp\r\n // the base color toward the transmission tint by the transmission weight (see below). The\r\n // material exporter skips the base color texture when this extension is enabled, so the base\r\n // color is always written from here, and geometryOpacity has to be packed the same way that\r\n // exporter does: the scalar opacity goes into the base color factor alpha, and the opacity\r\n // texture is packed into the base color texture alpha. This is done on the lerp's input\r\n // rather than its output; the lerp weight's alpha is 0, so the input alpha passes through\r\n // unchanged into the exported base color.\r\n const geometryOpacity = babylonMaterial.geometryOpacity;\r\n let baseColorTexture = babylonMaterial.baseColorTexture;\r\n if (babylonMaterial.geometryOpacityTexture) {\r\n // Pack base color RGB and the opacity texture into a single RGBA texture (mirrors GLTFMaterialExporter).\r\n baseColorTexture = await MergeTexturesAsync(\r\n `base color opacity (${babylonMaterial.name})`,\r\n {\r\n ...CreateRGBAConfiguration(\r\n babylonMaterial.baseColorTexture ? CreateTextureInput(babylonMaterial.baseColorTexture, 0) : CreateConstantInput(1.0),\r\n babylonMaterial.baseColorTexture ? CreateTextureInput(babylonMaterial.baseColorTexture, 1) : CreateConstantInput(1.0),\r\n babylonMaterial.baseColorTexture ? CreateTextureInput(babylonMaterial.baseColorTexture, 2) : CreateConstantInput(1.0),\r\n CreateTextureInput(babylonMaterial.geometryOpacityTexture, 0)\r\n ),\r\n sharedSampling: true,\r\n },\r\n babylonMaterial.getScene()\r\n );\r\n }\r\n\r\n // The lerp combines the base color with the transmission weight (and the metalness and\r\n // transmission color textures). If any of those use a different UV set from the base color,\r\n // the texture processor would have to drop one of them, which can wash out the base color\r\n // entirely. In that case, export the base color (with opacity packed) without the lerp.\r\n const metalness = babylonMaterial.baseMetalness;\r\n const metalnessTexture = babylonMaterial.baseMetalnessTexture;\r\n const usesVolume = !babylonMaterial.geometryThinWalled && babylonMaterial.transmissionDepth > 0;\r\n if (baseColorTexture) {\r\n const otherTextures = [transWeightResult.texture, metalness > 0 ? metalnessTexture : null, usesVolume ? null : babylonMaterial.transmissionColorTexture];\r\n if (otherTextures.some((texture) => texture && texture.coordinatesIndex !== baseColorTexture!.coordinatesIndex)) {\r\n Logger.Warn(\r\n `${context}: The base color and transmission textures of material '${babylonMaterial.name}' use different UV sets; the base color will not be adjusted for KHR_materials_transmission.`\r\n );\r\n this._baseColorOperands.set(babylonMaterial, {\r\n factor: new Color4(babylonMaterial.baseColor.r, babylonMaterial.baseColor.g, babylonMaterial.baseColor.b, geometryOpacity),\r\n texture: baseColorTexture,\r\n ownsTexture: !!babylonMaterial.geometryOpacityTexture,\r\n });\r\n additionalTextures.push(baseColorTexture);\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n // Choose the color space from the source base color texture rather than baseColorTexture: the merged\r\n // texture copies the sampled values unchanged, so it keeps the source's encoding (linear when the\r\n // source uses a hardware sRGB buffer) even though its own gammaSpace flag does not reflect that.\r\n const baseColorSpace = babylonMaterial.baseColorTexture?.gammaSpace ? TextureColorSpace.SRGB : TextureColorSpace.Linear;\r\n const colorOp = CreateTextureWithFactorOperand(\r\n baseColorTexture,\r\n new Color4(babylonMaterial.baseColor.r, babylonMaterial.baseColor.g, babylonMaterial.baseColor.b, geometryOpacity),\r\n TextureChannel.RGBA,\r\n baseColorSpace\r\n );\r\n let transOp: ITextureProcessOperand = CreateTextureWithFactorOperand(\r\n transWeightResult.texture ?? null,\r\n new Color4(transWeightResult.factor?.r ?? 1, transWeightResult.factor?.g ?? 1, transWeightResult.factor?.b ?? 1, 0.0), // alpha is 0 because we don't want to modify the base color alpha channel\r\n TextureChannel.R\r\n );\r\n // The metal lobe sits on top of the dielectric (and its transmission) in both glTF and OpenPBR,\r\n // and uses the base color as its F0. Only the dielectric fraction (1 - metalness) of the\r\n // transmission should pull the base color toward the transmission tint, so scale the lerp\r\n // weight by (1 - metalness). Fully metallic regions then keep their original base color.\r\n if (metalness >= 1 && !metalnessTexture) {\r\n transOp = CreateFactorOperand(new Color4(0, 0, 0, 0));\r\n } else if (metalness > 0) {\r\n const dielectricOp = await InvertTextureAsync(\r\n `dielectric weight (${babylonMaterial.name})`,\r\n CreateTextureWithFactorOperand(\r\n metalnessTexture,\r\n new Color4(metalness, metalness, metalness, 1.0),\r\n babylonMaterial._useMetallicFromMetallicTextureBlue ? TextureChannel.B : TextureChannel.R\r\n ),\r\n babylonMaterial.getScene(),\r\n ChannelMask.RGB\r\n );\r\n // transOp has no dispose, so the cached transmission weight texture survives this pass.\r\n transOp = await MultiplyTexturesAsync(`base color tint weight (${babylonMaterial.name})`, transOp, dielectricOp, babylonMaterial.getScene());\r\n }\r\n // glTF factors base color out of BOTH the diffuse and the transmission term, so the\r\n // exported base color must lerp from base_color toward the transmission tint by the\r\n // transmission weight (lerping toward a hardcoded white is only correct when that tint is\r\n // white, and otherwise washes base_color out for 0 < T < 1).\r\n // - Volumetric transmission (KHR_materials_volume active): the tint is carried by the\r\n // volume attenuationColor, so neutralize the surface tint toward white to avoid\r\n // double-tinting.\r\n // - Thin-walled / no depth: the surface base color IS the transmission tint, so lerp\r\n // toward transmission_color (which equals base_color for a thin-walled round-trip,\r\n // leaving the base color unchanged).\r\n const tintTargetOp = usesVolume\r\n ? CreateFactorOperand(new Color4(1, 1, 1, 1))\r\n : CreateTextureWithFactorOperand(\r\n babylonMaterial.transmissionColorTexture,\r\n new Color4(babylonMaterial.transmissionColor.r, babylonMaterial.transmissionColor.g, babylonMaterial.transmissionColor.b, 1.0),\r\n TextureChannel.RGBA,\r\n babylonMaterial.transmissionColorTexture?.gammaSpace ? TextureColorSpace.SRGB : TextureColorSpace.Linear\r\n );\r\n const baseColorResult = await LerpTexturesAsync(\r\n `base color (${babylonMaterial.name})`,\r\n colorOp,\r\n tintTargetOp,\r\n transOp,\r\n babylonMaterial.getScene(),\r\n TextureColorSpace.SRGB\r\n );\r\n\r\n // Dispose the intermediate merged texture; LerpTexturesAsync does not own raw operand textures.\r\n if (babylonMaterial.geometryOpacityTexture && baseColorTexture) {\r\n baseColorTexture.dispose();\r\n }\r\n\r\n this._baseColorOperands.set(babylonMaterial, { factor: baseColorResult.factor ?? null, texture: baseColorResult.texture ?? null, ownsTexture: true });\r\n if (baseColorResult.texture) {\r\n additionalTextures.push(baseColorResult.texture);\r\n }\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: Material): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat instanceof OpenPBRMaterial && !mat.unlit) {\r\n return mat.transmissionWeight > 0 || mat.subsurfaceWeight > 0;\r\n } else if (mat instanceof PBRMaterial && !mat.unlit) {\r\n const subs = mat.subSurface;\r\n return (\r\n (subs.isRefractionEnabled && subs.refractionIntensity != undefined && subs.refractionIntensity != 0) ||\r\n (subs.refractionIntensityTexture != null && subs.useGltfStyleTextures)\r\n );\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns true if successful\r\n */\r\n public async postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n if (!this._isExtensionEnabled(babylonMaterial)) {\r\n return node;\r\n }\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n this._wasUsed = true;\r\n\r\n const subSurface = babylonMaterial.subSurface;\r\n const transmissionFactor = subSurface.refractionIntensity === 0 ? undefined : subSurface.refractionIntensity;\r\n\r\n const transmissionInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: transmissionFactor,\r\n };\r\n\r\n if (subSurface.refractionIntensityTexture) {\r\n if (subSurface.useGltfStyleTextures) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n const transmissionTexture = this._exporter._materialExporter.getTextureInfo(subSurface.refractionIntensityTexture);\r\n if (transmissionTexture) {\r\n transmissionInfo.transmissionTexture = transmissionTexture;\r\n }\r\n } else {\r\n Logger.Warn(`${context}: Exporting a subsurface refraction intensity texture without \\`useGltfStyleTextures\\` is not supported`);\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = transmissionInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n this._wasUsed = true;\r\n\r\n const operand = this._transmissionOperands.get(babylonMaterial);\r\n const bakedTexture = this._exporter._materialExporter.getTextureInfo(operand?.texture ?? null);\r\n const bakedFactor = operand?.factor ?? null;\r\n\r\n const transmissionInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: bakedTexture ? 1.0 : (bakedFactor?.r ?? 0.0),\r\n };\r\n\r\n if (bakedTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n transmissionInfo.transmissionTexture = bakedTexture;\r\n }\r\n\r\n const baseColorOperand = this._baseColorOperands.get(babylonMaterial);\r\n const baseColorBakedTexture = this._exporter._materialExporter.getTextureInfo(baseColorOperand?.texture ?? null);\r\n const baseColorBakedFactor = baseColorOperand?.factor ?? null;\r\n\r\n if (!node.pbrMetallicRoughness) {\r\n node.pbrMetallicRoughness = {};\r\n }\r\n node.pbrMetallicRoughness.baseColorFactor = baseColorBakedFactor\r\n ? [baseColorBakedFactor.r, baseColorBakedFactor.g, baseColorBakedFactor.b, baseColorBakedFactor.a]\r\n : [1, 1, 1, 1];\r\n\r\n if (baseColorBakedTexture) {\r\n node.pbrMetallicRoughness.baseColorTexture = baseColorBakedTexture;\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = transmissionInfo;\r\n }\r\n\r\n return node;\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_transmission glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_transmission(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));\r\n}\r\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
2
|
import { PBRMaterial } from "@onerjs/core/Materials/PBR/pbrMaterial.pure.js";
|
|
3
3
|
import { Color3 } from "@onerjs/core/Maths/math.color.pure.js";
|
|
4
|
-
import { Vector3 } from "@onerjs/core/Maths/math.vector.pure.js";
|
|
5
4
|
import { OpenPBRMaterial } from "@onerjs/core/Materials/PBR/openpbrMaterial.pure.js";
|
|
5
|
+
import { GetOpenPBRVolumeAttenuation } from "../glTFUtilities.js";
|
|
6
6
|
const NAME = "KHR_materials_volume";
|
|
7
7
|
/**
|
|
8
8
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)
|
|
@@ -107,53 +107,7 @@ export class KHR_materials_volume {
|
|
|
107
107
|
if (thicknessTexture) {
|
|
108
108
|
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
const transmissionAttenuationColor = Color3.White().asArray();
|
|
112
|
-
if (transmissionVolume && babylonMaterial.transmissionDepth > 0) {
|
|
113
|
-
const invDepth = 1.0 / babylonMaterial.transmissionDepth;
|
|
114
|
-
let transmissionExtinctionCoefficient = new Vector3(-Math.log(babylonMaterial.transmissionColor.r) * invDepth, -Math.log(babylonMaterial.transmissionColor.g) * invDepth, -Math.log(babylonMaterial.transmissionColor.b) * invDepth);
|
|
115
|
-
const transmissionScatteringCoefficient = new Vector3(babylonMaterial.transmissionScatter.r * invDepth, babylonMaterial.transmissionScatter.g * invDepth, babylonMaterial.transmissionScatter.b * invDepth);
|
|
116
|
-
const transmissionAbsorptionCoefficient = transmissionExtinctionCoefficient.subtract(transmissionScatteringCoefficient);
|
|
117
|
-
const minCoeff = Math.min(transmissionAbsorptionCoefficient.x, transmissionAbsorptionCoefficient.y, transmissionAbsorptionCoefficient.z);
|
|
118
|
-
if (minCoeff < 0) {
|
|
119
|
-
transmissionAbsorptionCoefficient.x = transmissionAbsorptionCoefficient.x - minCoeff;
|
|
120
|
-
transmissionAbsorptionCoefficient.y = transmissionAbsorptionCoefficient.y - minCoeff;
|
|
121
|
-
transmissionAbsorptionCoefficient.z = transmissionAbsorptionCoefficient.z - minCoeff;
|
|
122
|
-
}
|
|
123
|
-
transmissionExtinctionCoefficient = transmissionAbsorptionCoefficient.add(transmissionScatteringCoefficient);
|
|
124
|
-
const maxCoeff = Math.max(transmissionExtinctionCoefficient.x, transmissionExtinctionCoefficient.y, transmissionExtinctionCoefficient.z);
|
|
125
|
-
transmissionAttenuationDistance = 1.0 / maxCoeff;
|
|
126
|
-
transmissionAttenuationColor[0] = Math.exp(-transmissionExtinctionCoefficient.x * transmissionAttenuationDistance);
|
|
127
|
-
transmissionAttenuationColor[1] = Math.exp(-transmissionExtinctionCoefficient.y * transmissionAttenuationDistance);
|
|
128
|
-
transmissionAttenuationColor[2] = Math.exp(-transmissionExtinctionCoefficient.z * transmissionAttenuationDistance);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
// transmissionDepth == 0
|
|
132
|
-
transmissionAttenuationDistance = Number.MAX_VALUE;
|
|
133
|
-
transmissionAttenuationColor[0] = 1.0;
|
|
134
|
-
transmissionAttenuationColor[1] = 1.0;
|
|
135
|
-
transmissionAttenuationColor[2] = 1.0;
|
|
136
|
-
}
|
|
137
|
-
let subsurfaceAttenuationDistance = 1;
|
|
138
|
-
const subsurfaceAttenuationColor = Color3.White().asArray();
|
|
139
|
-
if (subsurfaceVolume) {
|
|
140
|
-
const r = babylonMaterial.subsurfaceRadius;
|
|
141
|
-
const radiusScale = babylonMaterial.subsurfaceRadiusScale;
|
|
142
|
-
const mfp = new Vector3(radiusScale.r, radiusScale.g, radiusScale.b).multiplyByFloats(r, r, r);
|
|
143
|
-
const extinctionCoeff = new Vector3(1.0 / Math.max(mfp.x, 1e-6), 1.0 / Math.max(mfp.y, 1e-6), 1.0 / Math.max(mfp.z, 1e-6));
|
|
144
|
-
const maxCoeff = Math.max(extinctionCoeff.x, extinctionCoeff.y, extinctionCoeff.z);
|
|
145
|
-
subsurfaceAttenuationDistance = 1.0 / maxCoeff;
|
|
146
|
-
subsurfaceAttenuationColor[0] = Math.exp(-extinctionCoeff.x * subsurfaceAttenuationDistance);
|
|
147
|
-
subsurfaceAttenuationColor[1] = Math.exp(-extinctionCoeff.y * subsurfaceAttenuationDistance);
|
|
148
|
-
subsurfaceAttenuationColor[2] = Math.exp(-extinctionCoeff.z * subsurfaceAttenuationDistance);
|
|
149
|
-
}
|
|
150
|
-
const subsurfaceFractionOfDielectric = (1.0 - babylonMaterial.transmissionWeight) * babylonMaterial.subsurfaceWeight;
|
|
151
|
-
const subsurfaceAndTransmissionFractionOfDielectric = subsurfaceFractionOfDielectric + babylonMaterial.transmissionWeight;
|
|
152
|
-
const reciprocalOfSubsurfaceAndTransmissionFractionOfDielectric = 1.0 / Math.max(subsurfaceAndTransmissionFractionOfDielectric, 1e-6);
|
|
153
|
-
const transWeight = babylonMaterial.transmissionWeight * reciprocalOfSubsurfaceAndTransmissionFractionOfDielectric;
|
|
154
|
-
const subsurfWeight = subsurfaceFractionOfDielectric * reciprocalOfSubsurfaceAndTransmissionFractionOfDielectric;
|
|
155
|
-
const attenuationColor = transmissionAttenuationColor.map((c, i) => c * transWeight + subsurfaceAttenuationColor[i] * subsurfWeight);
|
|
156
|
-
const attenuationDistance = transmissionAttenuationDistance * transWeight + subsurfaceAttenuationDistance * subsurfWeight;
|
|
110
|
+
const { attenuationColor, attenuationDistance } = GetOpenPBRVolumeAttenuation(babylonMaterial, transmissionVolume, subsurfaceVolume);
|
|
157
111
|
const volumeInfo = {
|
|
158
112
|
thicknessFactor: thicknessFactor,
|
|
159
113
|
thicknessTexture: thicknessTexture,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_volume.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_volume.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC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Q,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Color3 } from \"core/Maths/math.color.pure\";\r\nimport { Vector3 } from \"core/Maths/math.vector.pure\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial.pure\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.thicknessTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.transmissionWeight > 0 || babylonMaterial.subsurfaceWeight > 0) {\r\n if (babylonMaterial.geometryThicknessTexture) {\r\n additionalTextures.push(babylonMaterial.geometryThicknessTexture);\r\n }\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n // this extension requires either the KHR_materials_transmission or KHR_materials_diffuse_transmission extensions.\r\n if (!subs.isRefractionEnabled && !subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n return (\r\n (subs.maximumThickness != undefined && subs.maximumThickness != 0) ||\r\n (subs.tintColorAtDistance != undefined && subs.tintColorAtDistance != Number.POSITIVE_INFINITY) ||\r\n (subs.tintColor != undefined && subs.tintColor != Color3.White()) ||\r\n this._hasTexturesExtension(mat)\r\n );\r\n }\r\n\r\n private _hasTexturesExtension(mat: PBRMaterial): boolean {\r\n return mat.subSurface.thicknessTexture != null;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise that resolves with the updated node\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const thicknessFactor = subs.maximumThickness == 0 ? undefined : subs.maximumThickness;\r\n const thicknessTexture = this._exporter._materialExporter.getTextureInfo(subs.thicknessTexture) ?? undefined;\r\n const attenuationDistance = subs.tintColorAtDistance == Number.POSITIVE_INFINITY ? undefined : subs.tintColorAtDistance;\r\n const attenuationColor = subs.tintColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.tintColor.asArray();\r\n\r\n const volumeInfo: IKHRMaterialsVolume = {\r\n thicknessFactor: thicknessFactor,\r\n thicknessTexture: thicknessTexture,\r\n attenuationDistance: attenuationDistance,\r\n attenuationColor: attenuationColor,\r\n };\r\n\r\n if (this._hasTexturesExtension(babylonMaterial)) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n const transmissionVolume = babylonMaterial.transmissionWeight > 0 && !babylonMaterial.geometryThinWalled;\r\n const subsurfaceVolume = babylonMaterial.subsurfaceWeight > 0 && !babylonMaterial.geometryThinWalled;\r\n if (transmissionVolume || subsurfaceVolume) {\r\n this._wasUsed = true;\r\n\r\n const thicknessFactor = babylonMaterial.geometryThickness;\r\n const thicknessTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryThicknessTexture) ?? undefined;\r\n if (thicknessTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n let transmissionAttenuationDistance;\r\n const transmissionAttenuationColor = Color3.White().asArray();\r\n if (transmissionVolume && babylonMaterial.transmissionDepth > 0) {\r\n const invDepth = 1.0 / babylonMaterial.transmissionDepth;\r\n let transmissionExtinctionCoefficient = new Vector3(\r\n -Math.log(babylonMaterial.transmissionColor.r) * invDepth,\r\n -Math.log(babylonMaterial.transmissionColor.g) * invDepth,\r\n -Math.log(babylonMaterial.transmissionColor.b) * invDepth\r\n );\r\n const transmissionScatteringCoefficient = new Vector3(\r\n babylonMaterial.transmissionScatter.r * invDepth,\r\n babylonMaterial.transmissionScatter.g * invDepth,\r\n babylonMaterial.transmissionScatter.b * invDepth\r\n );\r\n const transmissionAbsorptionCoefficient = transmissionExtinctionCoefficient.subtract(transmissionScatteringCoefficient);\r\n const minCoeff = Math.min(transmissionAbsorptionCoefficient.x, transmissionAbsorptionCoefficient.y, transmissionAbsorptionCoefficient.z);\r\n if (minCoeff < 0) {\r\n transmissionAbsorptionCoefficient.x = transmissionAbsorptionCoefficient.x - minCoeff;\r\n transmissionAbsorptionCoefficient.y = transmissionAbsorptionCoefficient.y - minCoeff;\r\n transmissionAbsorptionCoefficient.z = transmissionAbsorptionCoefficient.z - minCoeff;\r\n }\r\n transmissionExtinctionCoefficient = transmissionAbsorptionCoefficient.add(transmissionScatteringCoefficient);\r\n const maxCoeff = Math.max(transmissionExtinctionCoefficient.x, transmissionExtinctionCoefficient.y, transmissionExtinctionCoefficient.z);\r\n transmissionAttenuationDistance = 1.0 / maxCoeff;\r\n transmissionAttenuationColor[0] = Math.exp(-transmissionExtinctionCoefficient.x * transmissionAttenuationDistance);\r\n transmissionAttenuationColor[1] = Math.exp(-transmissionExtinctionCoefficient.y * transmissionAttenuationDistance);\r\n transmissionAttenuationColor[2] = Math.exp(-transmissionExtinctionCoefficient.z * transmissionAttenuationDistance);\r\n } else {\r\n // transmissionDepth == 0\r\n transmissionAttenuationDistance = Number.MAX_VALUE;\r\n transmissionAttenuationColor[0] = 1.0;\r\n transmissionAttenuationColor[1] = 1.0;\r\n transmissionAttenuationColor[2] = 1.0;\r\n }\r\n let subsurfaceAttenuationDistance = 1;\r\n const subsurfaceAttenuationColor = Color3.White().asArray();\r\n if (subsurfaceVolume) {\r\n const r = babylonMaterial.subsurfaceRadius;\r\n const radiusScale = babylonMaterial.subsurfaceRadiusScale;\r\n const mfp = new Vector3(radiusScale.r, radiusScale.g, radiusScale.b).multiplyByFloats(r, r, r);\r\n const extinctionCoeff = new Vector3(1.0 / Math.max(mfp.x, 1e-6), 1.0 / Math.max(mfp.y, 1e-6), 1.0 / Math.max(mfp.z, 1e-6));\r\n const maxCoeff = Math.max(extinctionCoeff.x, extinctionCoeff.y, extinctionCoeff.z);\r\n subsurfaceAttenuationDistance = 1.0 / maxCoeff;\r\n subsurfaceAttenuationColor[0] = Math.exp(-extinctionCoeff.x * subsurfaceAttenuationDistance);\r\n subsurfaceAttenuationColor[1] = Math.exp(-extinctionCoeff.y * subsurfaceAttenuationDistance);\r\n subsurfaceAttenuationColor[2] = Math.exp(-extinctionCoeff.z * subsurfaceAttenuationDistance);\r\n }\r\n\r\n const subsurfaceFractionOfDielectric = (1.0 - babylonMaterial.transmissionWeight) * babylonMaterial.subsurfaceWeight;\r\n const subsurfaceAndTransmissionFractionOfDielectric = subsurfaceFractionOfDielectric + babylonMaterial.transmissionWeight;\r\n const reciprocalOfSubsurfaceAndTransmissionFractionOfDielectric = 1.0 / Math.max(subsurfaceAndTransmissionFractionOfDielectric, 1e-6);\r\n const transWeight = babylonMaterial.transmissionWeight * reciprocalOfSubsurfaceAndTransmissionFractionOfDielectric;\r\n const subsurfWeight = subsurfaceFractionOfDielectric * reciprocalOfSubsurfaceAndTransmissionFractionOfDielectric;\r\n\r\n const attenuationColor = transmissionAttenuationColor.map((c, i) => c * transWeight + subsurfaceAttenuationColor[i] * subsurfWeight);\r\n const attenuationDistance = transmissionAttenuationDistance * transWeight + subsurfaceAttenuationDistance * subsurfWeight;\r\n\r\n const volumeInfo: IKHRMaterialsVolume = {\r\n thicknessFactor: thicknessFactor,\r\n thicknessTexture: thicknessTexture,\r\n attenuationDistance: attenuationDistance,\r\n attenuationColor: attenuationColor,\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_volume glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_volume(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_volume(exporter));\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_materials_volume.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_volume.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,IAAI,GAAG,sBAAsB,CAAC;AAEpC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,oBAAoB;IAc7B,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,yCAAyC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;QAC/G,MAAM,kBAAkB,GAAkB,EAAE,CAAC;QAE7C,IAAI,eAAe,YAAY,WAAW,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,EAAE,CAAC;gBAC5C,IAAI,eAAe,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;oBAC9C,kBAAkB,CAA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CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,4BAA4B;IACxC,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3F,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Color3 } from \"core/Maths/math.color.pure\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial.pure\";\r\nimport { GetOpenPBRVolumeAttenuation } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.thicknessTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.transmissionWeight > 0 || babylonMaterial.subsurfaceWeight > 0) {\r\n if (babylonMaterial.geometryThicknessTexture) {\r\n additionalTextures.push(babylonMaterial.geometryThicknessTexture);\r\n }\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n // this extension requires either the KHR_materials_transmission or KHR_materials_diffuse_transmission extensions.\r\n if (!subs.isRefractionEnabled && !subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n return (\r\n (subs.maximumThickness != undefined && subs.maximumThickness != 0) ||\r\n (subs.tintColorAtDistance != undefined && subs.tintColorAtDistance != Number.POSITIVE_INFINITY) ||\r\n (subs.tintColor != undefined && subs.tintColor != Color3.White()) ||\r\n this._hasTexturesExtension(mat)\r\n );\r\n }\r\n\r\n private _hasTexturesExtension(mat: PBRMaterial): boolean {\r\n return mat.subSurface.thicknessTexture != null;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise that resolves with the updated node\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const thicknessFactor = subs.maximumThickness == 0 ? undefined : subs.maximumThickness;\r\n const thicknessTexture = this._exporter._materialExporter.getTextureInfo(subs.thicknessTexture) ?? undefined;\r\n const attenuationDistance = subs.tintColorAtDistance == Number.POSITIVE_INFINITY ? undefined : subs.tintColorAtDistance;\r\n const attenuationColor = subs.tintColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.tintColor.asArray();\r\n\r\n const volumeInfo: IKHRMaterialsVolume = {\r\n thicknessFactor: thicknessFactor,\r\n thicknessTexture: thicknessTexture,\r\n attenuationDistance: attenuationDistance,\r\n attenuationColor: attenuationColor,\r\n };\r\n\r\n if (this._hasTexturesExtension(babylonMaterial)) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n const transmissionVolume = babylonMaterial.transmissionWeight > 0 && !babylonMaterial.geometryThinWalled;\r\n const subsurfaceVolume = babylonMaterial.subsurfaceWeight > 0 && !babylonMaterial.geometryThinWalled;\r\n if (transmissionVolume || subsurfaceVolume) {\r\n this._wasUsed = true;\r\n\r\n const thicknessFactor = babylonMaterial.geometryThickness;\r\n const thicknessTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryThicknessTexture) ?? undefined;\r\n if (thicknessTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n const { attenuationColor, attenuationDistance } = GetOpenPBRVolumeAttenuation(babylonMaterial, transmissionVolume, subsurfaceVolume);\r\n const volumeInfo: IKHRMaterialsVolume = {\r\n thicknessFactor: thicknessFactor,\r\n thicknessTexture: thicknessTexture,\r\n attenuationDistance: attenuationDistance,\r\n attenuationColor: attenuationColor,\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_volume glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_volume(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_volume(exporter));\r\n}\r\n"]}
|
|
@@ -17,7 +17,7 @@ export * from "./KHR_materials_specular.js";
|
|
|
17
17
|
export * from "./KHR_materials_transmission.js";
|
|
18
18
|
export * from "./KHR_materials_unlit.js";
|
|
19
19
|
export * from "./KHR_materials_volume.js";
|
|
20
|
-
export * from "./
|
|
20
|
+
export * from "./KHR_materials_scatter.js";
|
|
21
21
|
export * from "./KHR_materials_diffuse_roughness.js";
|
|
22
22
|
export * from "./KHR_materials_openpbr.js";
|
|
23
23
|
export * from "./KHR_texture_transform.js";
|
|
@@ -17,7 +17,7 @@ export * from "./KHR_materials_specular.js";
|
|
|
17
17
|
export * from "./KHR_materials_transmission.js";
|
|
18
18
|
export * from "./KHR_materials_unlit.js";
|
|
19
19
|
export * from "./KHR_materials_volume.js";
|
|
20
|
-
export * from "./
|
|
20
|
+
export * from "./KHR_materials_scatter.js";
|
|
21
21
|
export * from "./KHR_materials_diffuse_roughness.js";
|
|
22
22
|
export * from "./KHR_materials_openpbr.js";
|
|
23
23
|
export * from "./KHR_texture_transform.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_interactivity\";\r\nexport * from \"./EXT_lights_area\";\r\nexport * from \"./KHR_materials_anisotropy\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_coat\";\r\nexport * from \"./KHR_materials_diffuse_transmission\";\r\nexport * from \"./KHR_materials_dispersion\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_fuzz\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_materials_scatter\";\r\nexport * from \"./KHR_materials_diffuse_roughness\";\r\nexport * from \"./KHR_materials_openpbr\";\r\nexport * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_texture_basisu\";\r\nexport * from \"./EXT_texture_webp\";\r\nexport * from \"./EXT_texture_avif\";\r\n"]}
|
|
@@ -18,7 +18,7 @@ export * from "./KHR_materials_specular.pure.js";
|
|
|
18
18
|
export * from "./KHR_materials_transmission.pure.js";
|
|
19
19
|
export * from "./KHR_materials_unlit.pure.js";
|
|
20
20
|
export * from "./KHR_materials_volume.pure.js";
|
|
21
|
-
export * from "./
|
|
21
|
+
export * from "./KHR_materials_scatter.pure.js";
|
|
22
22
|
export * from "./KHR_materials_diffuse_roughness.pure.js";
|
|
23
23
|
export * from "./KHR_materials_openpbr.pure.js";
|
|
24
24
|
export * from "./KHR_texture_transform.pure.js";
|
|
@@ -18,7 +18,7 @@ export * from "./KHR_materials_specular.pure.js";
|
|
|
18
18
|
export * from "./KHR_materials_transmission.pure.js";
|
|
19
19
|
export * from "./KHR_materials_unlit.pure.js";
|
|
20
20
|
export * from "./KHR_materials_volume.pure.js";
|
|
21
|
-
export * from "./
|
|
21
|
+
export * from "./KHR_materials_scatter.pure.js";
|
|
22
22
|
export * from "./KHR_materials_diffuse_roughness.pure.js";
|
|
23
23
|
export * from "./KHR_materials_openpbr.pure.js";
|
|
24
24
|
export * from "./KHR_texture_transform.pure.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iCAAiC,CAAC;AAChD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,
|
|
1
|
+
{"version":3,"file":"pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,iCAAiC,CAAC;AAChD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wCAAwC,CAAC;AACvD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC","sourcesContent":["/** Pure barrel — re-exports only side-effect-free modules */\nexport * from \"./EXT_mesh_gpu_instancing.pure\";\nexport * from \"./KHR_draco_mesh_compression.pure\";\nexport * from \"./KHR_lights_punctual.pure\";\nexport * from \"./KHR_interactivity.pure\";\nexport * from \"./EXT_lights_area.pure\";\nexport * from \"./KHR_materials_anisotropy.pure\";\nexport * from \"./KHR_materials_clearcoat.pure\";\nexport * from \"./KHR_materials_coat.pure\";\nexport * from \"./KHR_materials_diffuse_transmission.pure\";\nexport * from \"./KHR_materials_dispersion.pure\";\nexport * from \"./KHR_materials_emissive_strength.pure\";\nexport * from \"./KHR_materials_ior.pure\";\nexport * from \"./KHR_materials_iridescence.pure\";\nexport * from \"./KHR_materials_sheen.pure\";\nexport * from \"./KHR_materials_fuzz.pure\";\nexport * from \"./KHR_materials_specular.pure\";\nexport * from \"./KHR_materials_transmission.pure\";\nexport * from \"./KHR_materials_unlit.pure\";\nexport * from \"./KHR_materials_volume.pure\";\nexport * from \"./KHR_materials_scatter.pure\";\nexport * from \"./KHR_materials_diffuse_roughness.pure\";\nexport * from \"./KHR_materials_openpbr.pure\";\nexport * from \"./KHR_texture_transform.pure\";\nexport * from \"./KHR_texture_basisu.pure\";\nexport * from \"./EXT_texture_webp.pure\";\nexport * from \"./EXT_texture_avif.pure\";\n"]}
|
|
@@ -57,6 +57,12 @@ export declare class GLTFExporter {
|
|
|
57
57
|
private _ApplyExtensions;
|
|
58
58
|
_extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>>;
|
|
59
59
|
_extensionsPostExportMaterialAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns whether a glTF exporter extension is both registered and enabled.
|
|
62
|
+
* @param name The extension name (e.g. "KHR_materials_transmission")
|
|
63
|
+
* @returns true if the extension is registered and its `enabled` flag is set
|
|
64
|
+
*/
|
|
65
|
+
isExtensionEnabled(name: string): boolean;
|
|
60
66
|
/**
|
|
61
67
|
* Get additional textures for a material
|
|
62
68
|
* @param context The context when loading the asset
|
package/glTF/2.0/glTFExporter.js
CHANGED
|
@@ -175,6 +175,15 @@ export class GLTFExporter {
|
|
|
175
175
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
176
176
|
return this._ApplyExtensions(material, (extension, node) => extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial));
|
|
177
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Returns whether a glTF exporter extension is both registered and enabled.
|
|
180
|
+
* @param name The extension name (e.g. "KHR_materials_transmission")
|
|
181
|
+
* @returns true if the extension is registered and its `enabled` flag is set
|
|
182
|
+
*/
|
|
183
|
+
isExtensionEnabled(name) {
|
|
184
|
+
const extension = this._extensions[name];
|
|
185
|
+
return !!extension && extension.enabled;
|
|
186
|
+
}
|
|
178
187
|
/**
|
|
179
188
|
* Get additional textures for a material
|
|
180
189
|
* @param context The context when loading the asset
|