@babylonjs/serializers 8.28.1 → 8.28.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.
Files changed (50) hide show
  1. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +9 -1
  2. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +192 -1
  3. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  4. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +1 -1
  5. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +47 -1
  6. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  7. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.d.ts +32 -0
  8. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js +231 -0
  9. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js.map +1 -0
  10. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.d.ts +24 -0
  11. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js +101 -0
  12. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js.map +1 -0
  13. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.d.ts +24 -0
  14. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js +70 -0
  15. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js.map +1 -0
  16. package/glTF/2.0/Extensions/{EXT_materials_diffuse_roughness.d.ts → KHR_materials_diffuse_roughness.d.ts} +3 -3
  17. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js +78 -0
  18. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +1 -0
  19. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +1 -1
  20. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +1 -1
  21. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  22. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +1 -1
  23. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +1 -1
  24. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  25. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +1 -1
  26. package/glTF/2.0/Extensions/KHR_materials_sheen.js +1 -1
  27. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  28. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -1
  29. package/glTF/2.0/Extensions/KHR_materials_specular.js +33 -1
  30. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  31. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +1 -1
  32. package/glTF/2.0/Extensions/KHR_materials_transmission.js +1 -1
  33. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  34. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +1 -1
  35. package/glTF/2.0/Extensions/KHR_materials_volume.js +1 -1
  36. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  37. package/glTF/2.0/Extensions/index.d.ts +4 -1
  38. package/glTF/2.0/Extensions/index.js +4 -1
  39. package/glTF/2.0/Extensions/index.js.map +1 -1
  40. package/glTF/2.0/glTFExporter.d.ts +8 -1
  41. package/glTF/2.0/glTFExporter.js +17 -5
  42. package/glTF/2.0/glTFExporter.js.map +1 -1
  43. package/glTF/2.0/glTFExporterExtension.d.ts +1 -1
  44. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  45. package/glTF/2.0/glTFMaterialExporter.d.ts +9 -1
  46. package/glTF/2.0/glTFMaterialExporter.js +41 -15
  47. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  48. package/package.json +3 -3
  49. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +0 -61
  50. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +0 -1
@@ -15,10 +15,18 @@ export declare class KHR_materials_anisotropy implements IGLTFExporterExtensionV
15
15
  required: boolean;
16
16
  private _exporter;
17
17
  private _wasUsed;
18
+ private _anisoTexturesMap;
18
19
  constructor(exporter: GLTFExporter);
19
20
  dispose(): void;
20
21
  /** @internal */
21
22
  get wasUsed(): boolean;
22
- postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
23
+ /**
24
+ * After exporting a material, deal with the additional textures
25
+ * @param context GLTF context of the material
26
+ * @param node exported GLTF node
27
+ * @param babylonMaterial corresponding babylon material
28
+ * @returns array of additional textures to export
29
+ */
30
+ postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
23
31
  postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
32
  }
@@ -1,6 +1,123 @@
1
1
  import { GLTFExporter } from "../glTFExporter.js";
2
2
  import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
3
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openPbrMaterial.js";
4
+ import { Constants } from "@babylonjs/core/Engines/constants.js";
5
+ import { Effect } from "@babylonjs/core/Materials/effect.js";
6
+ import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
3
7
  const NAME = "KHR_materials_anisotropy";
8
+ // Convert OpenPBR anisotropy values to glTF-compatible values
9
+ function OpenpbrAnisotropyStrengthToGltf(baseRoughness, anisotropy) {
10
+ const baseAlpha = baseRoughness * baseRoughness;
11
+ const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));
12
+ const roughnessB = (1 - anisotropy) * roughnessT;
13
+ const newBaseRoughness = Math.sqrt(roughnessB);
14
+ const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);
15
+ return { newBaseRoughness, newAnisotropyStrength };
16
+ }
17
+ function CopyTextureTransform(source, destination) {
18
+ destination.uOffset = source.uOffset;
19
+ destination.vOffset = source.vOffset;
20
+ destination.uScale = source.uScale;
21
+ destination.vScale = source.vScale;
22
+ destination.uAng = source.uAng;
23
+ destination.vAng = source.vAng;
24
+ destination.wAng = source.wAng;
25
+ destination.uRotationCenter = source.uRotationCenter;
26
+ destination.vRotationCenter = source.vRotationCenter;
27
+ }
28
+ // Custom shader for merging anisotropy into tangent texture
29
+ const AnisotropyMergeFragment = `
30
+ precision highp float;
31
+ #ifdef HAS_TANGENT_TEXTURE
32
+ uniform sampler2D tangentTexture;
33
+ #endif
34
+ #ifdef HAS_ANISOTROPY_TEXTURE
35
+ uniform sampler2D anisotropyTexture;
36
+ #endif
37
+ uniform int useRoughnessFromMetallicGreen;
38
+ uniform int useAnisotropyFromTangentBlue;
39
+
40
+ varying vec2 vUV;
41
+
42
+ void main() {
43
+ vec2 tangent = vec2(1.0, 0.0);
44
+ float anisotropy = 1.0;
45
+ #ifdef HAS_TANGENT_TEXTURE
46
+ // Tangent texture is present
47
+ vec4 tangentSample = texture2D(tangentTexture, vUV);
48
+ tangent = tangentSample.rg;
49
+
50
+ if (useAnisotropyFromTangentBlue > 0) {
51
+ anisotropy = tangentSample.b;
52
+ }
53
+ #endif
54
+ #ifdef HAS_ANISOTROPY_TEXTURE
55
+ // Anisotropy texture is present
56
+ vec4 anisotropySample = texture2D(anisotropyTexture, vUV);
57
+ anisotropy = anisotropySample.r;
58
+ #endif
59
+
60
+ // Output: RG = tangent XY, B = anisotropy strength
61
+ vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);
62
+ gl_FragColor = anisotropyData;
63
+ }
64
+ `;
65
+ // In your postExportMaterialAsync method:
66
+ async function CreateMergedAnisotropyTexture(babylonMaterial) {
67
+ const scene = babylonMaterial.getScene();
68
+ // Register the custom shader if not already done
69
+ if (!Effect.ShadersStore["anisotropyMergeFragmentShader"]) {
70
+ Effect.ShadersStore["anisotropyMergeFragmentShader"] = AnisotropyMergeFragment;
71
+ }
72
+ const anisoStrengthTexture = babylonMaterial.specularRoughnessAnisotropyTexture;
73
+ const tangentTexture = babylonMaterial.geometryTangentTexture;
74
+ // If we don't have any textures, we don't need to generate anything.
75
+ if (!(anisoStrengthTexture || tangentTexture)) {
76
+ return null;
77
+ }
78
+ const width = Math.max(anisoStrengthTexture ? anisoStrengthTexture.getSize().width : 1, tangentTexture ? tangentTexture.getSize().width : 1);
79
+ const height = Math.max(anisoStrengthTexture ? anisoStrengthTexture.getSize().height : 1, tangentTexture ? tangentTexture.getSize().height : 1);
80
+ const textureOptions = {
81
+ type: Constants.TEXTURETYPE_UNSIGNED_BYTE,
82
+ format: Constants.TEXTUREFORMAT_RGBA,
83
+ samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,
84
+ generateDepthBuffer: false,
85
+ generateStencilBuffer: false,
86
+ generateMipMaps: false,
87
+ };
88
+ const rtTexture = new ProceduralTexture(babylonMaterial.name + "_anisotropy", {
89
+ width,
90
+ height,
91
+ }, "anisotropyMerge", scene, textureOptions);
92
+ rtTexture.refreshRate = -1;
93
+ // Set uniforms and defines
94
+ let defines = "";
95
+ if (tangentTexture) {
96
+ defines += "#define HAS_TANGENT_TEXTURE\n";
97
+ rtTexture.setTexture("tangentTexture", tangentTexture);
98
+ CopyTextureTransform(tangentTexture, rtTexture);
99
+ }
100
+ rtTexture.setVector2("tangentVector", babylonMaterial.geometryTangent);
101
+ if (anisoStrengthTexture) {
102
+ defines += "#define HAS_ANISOTROPY_TEXTURE\n";
103
+ rtTexture.setTexture("anisotropyTexture", anisoStrengthTexture);
104
+ CopyTextureTransform(anisoStrengthTexture, rtTexture);
105
+ }
106
+ rtTexture.setInt("useAnisotropyFromTangentBlue", babylonMaterial._useSpecularRoughnessAnisotropyFromTangentTexture ? 1 : 0);
107
+ rtTexture.defines = defines;
108
+ return await new Promise((resolve, reject) => {
109
+ // Compile and render
110
+ rtTexture.executeWhenReady(() => {
111
+ try {
112
+ rtTexture.render();
113
+ resolve(rtTexture);
114
+ }
115
+ catch (error) {
116
+ reject(error instanceof Error ? error : new Error(String(error)));
117
+ }
118
+ });
119
+ });
120
+ }
4
121
  /**
5
122
  * @internal
6
123
  */
@@ -14,6 +131,7 @@ export class KHR_materials_anisotropy {
14
131
  /** Defines whether this extension is required */
15
132
  this.required = false;
16
133
  this._wasUsed = false;
134
+ this._anisoTexturesMap = {};
17
135
  this._exporter = exporter;
18
136
  }
19
137
  dispose() { }
@@ -21,7 +139,14 @@ export class KHR_materials_anisotropy {
21
139
  get wasUsed() {
22
140
  return this._wasUsed;
23
141
  }
24
- postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
142
+ /**
143
+ * After exporting a material, deal with the additional textures
144
+ * @param context GLTF context of the material
145
+ * @param node exported GLTF node
146
+ * @param babylonMaterial corresponding babylon material
147
+ * @returns array of additional textures to export
148
+ */
149
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
25
150
  const additionalTextures = [];
26
151
  if (babylonMaterial instanceof PBRBaseMaterial) {
27
152
  if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {
@@ -31,11 +156,22 @@ export class KHR_materials_anisotropy {
31
156
  return additionalTextures;
32
157
  }
33
158
  }
159
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
160
+ if (babylonMaterial.specularRoughnessAnisotropy > 0) {
161
+ const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);
162
+ if (anisoTexture) {
163
+ additionalTextures.push(anisoTexture);
164
+ this._anisoTexturesMap[babylonMaterial.id] = anisoTexture;
165
+ }
166
+ return additionalTextures;
167
+ }
168
+ }
34
169
  return [];
35
170
  }
36
171
  // eslint-disable-next-line no-restricted-syntax
37
172
  postExportMaterialAsync(context, node, babylonMaterial) {
38
173
  return new Promise((resolve) => {
174
+ var _a;
39
175
  if (babylonMaterial instanceof PBRBaseMaterial) {
40
176
  if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {
41
177
  resolve(node);
@@ -54,6 +190,61 @@ export class KHR_materials_anisotropy {
54
190
  }
55
191
  node.extensions[NAME] = anisotropyInfo;
56
192
  }
193
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
194
+ if (babylonMaterial.specularRoughnessAnisotropy > 0) {
195
+ this._wasUsed = true;
196
+ node.extensions = node.extensions || {};
197
+ // Check if we can convert from OpenPBR anisotropy to glTF anisotropy
198
+ // Conversion involves both specular roughness and anisotropic roughness changes so,
199
+ // if there are textures for either, we can't reliably convert due to there potentially
200
+ // being different mappings between the textures.
201
+ let roughnessTexture = babylonMaterial.specularRoughnessTexture;
202
+ if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {
203
+ roughnessTexture = babylonMaterial.baseMetalnessTexture;
204
+ }
205
+ const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];
206
+ // If no textures are being used, we'll always output glTF-style anisotropy.
207
+ // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.
208
+ if (!roughnessTexture && !mergedAnisoTexture) {
209
+ // Convert constants
210
+ let newBaseRoughness = babylonMaterial.specularRoughness;
211
+ let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;
212
+ if (!babylonMaterial._useGltfStyleAnisotropy) {
213
+ const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);
214
+ newBaseRoughness = newParams.newBaseRoughness;
215
+ newAnisotropyStrength = newParams.newAnisotropyStrength;
216
+ }
217
+ if (node.pbrMetallicRoughness) {
218
+ node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;
219
+ }
220
+ const anisotropyInfo = {
221
+ anisotropyStrength: newAnisotropyStrength,
222
+ anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,
223
+ anisotropyTexture: undefined,
224
+ };
225
+ node.extensions[NAME] = anisotropyInfo;
226
+ return resolve(node);
227
+ }
228
+ const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;
229
+ const anisotropyInfo = {
230
+ anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,
231
+ anisotropyRotation: babylonMaterial.geometryTangentAngle,
232
+ anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,
233
+ extensions: {},
234
+ };
235
+ if (!babylonMaterial._useGltfStyleAnisotropy) {
236
+ anisotropyInfo.extensions["EXT_materials_anisotropy_openpbr"] = {
237
+ openPbrAnisotropyEnabled: true,
238
+ };
239
+ (_a = this._exporter._glTF).extensionsUsed || (_a.extensionsUsed = []);
240
+ if (this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr") === -1) {
241
+ this._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr");
242
+ }
243
+ }
244
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
245
+ node.extensions[NAME] = anisotropyInfo;
246
+ }
247
+ }
57
248
  resolve(node);
58
249
  });
59
250
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,wBAAwB;IAcjC,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,gB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iB,EAAE,qBAAqB,IAAI,SAAS;iBACxD,CAAC;gBAEF,IAAI,cAAc,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;oBAC5C,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy 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 public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\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 PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,OAAO,EAAE,eAAe,EAAE,yDAA2C;AACrE,OAAO,EAAE,SAAS,EAAE,6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,CAAC,eAAe,CAAC,CAAC;oBAEzD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;gBAC3C,CAAC;YACL,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openPbrMaterial\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { IProceduralTextureCreationOptions } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n// Convert OpenPBR anisotropy values to glTF-compatible values\r\nfunction OpenpbrAnisotropyStrengthToGltf(baseRoughness: number, anisotropy: number) {\r\n const baseAlpha = baseRoughness * baseRoughness;\r\n const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));\r\n const roughnessB = (1 - anisotropy) * roughnessT;\r\n const newBaseRoughness = Math.sqrt(roughnessB);\r\n const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);\r\n\r\n return { newBaseRoughness, newAnisotropyStrength };\r\n}\r\n\r\nfunction CopyTextureTransform(source: Texture, destination: Texture) {\r\n destination.uOffset = source.uOffset;\r\n destination.vOffset = source.vOffset;\r\n destination.uScale = source.uScale;\r\n destination.vScale = source.vScale;\r\n destination.uAng = source.uAng;\r\n destination.vAng = source.vAng;\r\n destination.wAng = source.wAng;\r\n destination.uRotationCenter = source.uRotationCenter;\r\n destination.vRotationCenter = source.vRotationCenter;\r\n}\r\n\r\n// Custom shader for merging anisotropy into tangent texture\r\nconst AnisotropyMergeFragment = `\r\n precision highp float;\r\n#ifdef HAS_TANGENT_TEXTURE\r\n uniform sampler2D tangentTexture;\r\n#endif\r\n#ifdef HAS_ANISOTROPY_TEXTURE\r\n uniform sampler2D anisotropyTexture;\r\n#endif\r\n uniform int useRoughnessFromMetallicGreen;\r\n uniform int useAnisotropyFromTangentBlue;\r\n\r\n varying vec2 vUV;\r\n\r\n void main() {\r\n vec2 tangent = vec2(1.0, 0.0);\r\n float anisotropy = 1.0;\r\n #ifdef HAS_TANGENT_TEXTURE\r\n // Tangent texture is present\r\n vec4 tangentSample = texture2D(tangentTexture, vUV);\r\n tangent = tangentSample.rg;\r\n\r\n if (useAnisotropyFromTangentBlue > 0) {\r\n anisotropy = tangentSample.b;\r\n }\r\n #endif\r\n #ifdef HAS_ANISOTROPY_TEXTURE\r\n // Anisotropy texture is present\r\n vec4 anisotropySample = texture2D(anisotropyTexture, vUV);\r\n anisotropy = anisotropySample.r;\r\n #endif\r\n \r\n // Output: RG = tangent XY, B = anisotropy strength\r\n vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);\r\n gl_FragColor = anisotropyData;\r\n }\r\n`;\r\n\r\n// In your postExportMaterialAsync method:\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<ProceduralTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n // Register the custom shader if not already done\r\n if (!Effect.ShadersStore[\"anisotropyMergeFragmentShader\"]) {\r\n Effect.ShadersStore[\"anisotropyMergeFragmentShader\"] = AnisotropyMergeFragment;\r\n }\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(anisoStrengthTexture || tangentTexture)) {\r\n return null;\r\n }\r\n\r\n const width = Math.max(anisoStrengthTexture ? anisoStrengthTexture.getSize().width : 1, tangentTexture ? tangentTexture.getSize().width : 1);\r\n const height = Math.max(anisoStrengthTexture ? anisoStrengthTexture.getSize().height : 1, tangentTexture ? tangentTexture.getSize().height : 1);\r\n const textureOptions: IProceduralTextureCreationOptions = {\r\n type: Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n generateDepthBuffer: false,\r\n generateStencilBuffer: false,\r\n generateMipMaps: false,\r\n };\r\n const rtTexture = new ProceduralTexture(\r\n babylonMaterial.name + \"_anisotropy\",\r\n {\r\n width,\r\n height,\r\n },\r\n \"anisotropyMerge\",\r\n scene,\r\n textureOptions\r\n );\r\n rtTexture.refreshRate = -1;\r\n\r\n // Set uniforms and defines\r\n let defines = \"\";\r\n if (tangentTexture) {\r\n defines += \"#define HAS_TANGENT_TEXTURE\\n\";\r\n rtTexture.setTexture(\"tangentTexture\", tangentTexture);\r\n CopyTextureTransform(tangentTexture as Texture, rtTexture);\r\n }\r\n rtTexture.setVector2(\"tangentVector\", babylonMaterial.geometryTangent);\r\n if (anisoStrengthTexture) {\r\n defines += \"#define HAS_ANISOTROPY_TEXTURE\\n\";\r\n rtTexture.setTexture(\"anisotropyTexture\", anisoStrengthTexture);\r\n CopyTextureTransform(anisoStrengthTexture as Texture, rtTexture);\r\n }\r\n rtTexture.setInt(\"useAnisotropyFromTangentBlue\", babylonMaterial._useSpecularRoughnessAnisotropyFromTangentTexture ? 1 : 0);\r\n rtTexture.defines = defines;\r\n\r\n return await new Promise<ProceduralTexture>((resolve, reject) => {\r\n // Compile and render\r\n rtTexture.executeWhenReady(() => {\r\n try {\r\n rtTexture.render();\r\n resolve(rtTexture);\r\n } catch (error) {\r\n reject(error instanceof Error ? error : new Error(String(error)));\r\n }\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy 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 private _anisoTexturesMap: Record<string, ProceduralTexture> = {};\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 the 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 if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._anisoTexturesMap[babylonMaterial.id] = anisoTexture;\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\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 PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n // Check if we can convert from OpenPBR anisotropy to glTF anisotropy\r\n // Conversion involves both specular roughness and anisotropic roughness changes so,\r\n // if there are textures for either, we can't reliably convert due to there potentially\r\n // being different mappings between the textures.\r\n let roughnessTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessTexture;\r\n if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {\r\n roughnessTexture = babylonMaterial.baseMetalnessTexture;\r\n }\r\n const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];\r\n\r\n // If no textures are being used, we'll always output glTF-style anisotropy.\r\n // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.\r\n if (!roughnessTexture && !mergedAnisoTexture) {\r\n // Convert constants\r\n let newBaseRoughness = babylonMaterial.specularRoughness;\r\n let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);\r\n newBaseRoughness = newParams.newBaseRoughness;\r\n newAnisotropyStrength = newParams.newAnisotropyStrength;\r\n }\r\n if (node.pbrMetallicRoughness) {\r\n node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;\r\n }\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: newAnisotropyStrength,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,\r\n anisotropyTexture: undefined,\r\n };\r\n node.extensions[NAME] = anisotropyInfo;\r\n return resolve(node);\r\n }\r\n\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle,\r\n anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,\r\n extensions: {},\r\n };\r\n\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n anisotropyInfo.extensions![\"EXT_materials_anisotropy_openpbr\"] = {\r\n openPbrAnisotropyEnabled: true,\r\n };\r\n this._exporter._glTF.extensionsUsed ||= [];\r\n if (this._exporter._glTF.extensionsUsed.indexOf(\"EXT_materials_anisotropy_openpbr\") === -1) {\r\n this._exporter._glTF.extensionsUsed.push(\"EXT_materials_anisotropy_openpbr\");\r\n }\r\n }\r\n\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
@@ -19,6 +19,6 @@ export declare class KHR_materials_clearcoat implements IGLTFExporterExtensionV2
19
19
  dispose(): void;
20
20
  /** @internal */
21
21
  get wasUsed(): boolean;
22
- postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
22
+ postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
23
23
  postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
24
  }
@@ -1,6 +1,7 @@
1
1
  import { GLTFExporter } from "../glTFExporter.js";
2
2
  import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
3
3
  import { Tools } from "@babylonjs/core/Misc/tools.js";
4
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openPbrMaterial.js";
4
5
  const NAME = "KHR_materials_clearcoat";
5
6
  /**
6
7
  * @internal
@@ -22,7 +23,7 @@ export class KHR_materials_clearcoat {
22
23
  get wasUsed() {
23
24
  return this._wasUsed;
24
25
  }
25
- postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
26
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
26
27
  const additionalTextures = [];
27
28
  if (babylonMaterial instanceof PBRBaseMaterial) {
28
29
  if (babylonMaterial.clearCoat.isEnabled) {
@@ -38,6 +39,20 @@ export class KHR_materials_clearcoat {
38
39
  return additionalTextures;
39
40
  }
40
41
  }
42
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
43
+ if (babylonMaterial.coatWeight > 0) {
44
+ if (babylonMaterial.coatWeightTexture) {
45
+ additionalTextures.push(babylonMaterial.coatWeightTexture);
46
+ }
47
+ if (babylonMaterial.geometryCoatNormalTexture) {
48
+ additionalTextures.push(babylonMaterial.geometryCoatNormalTexture);
49
+ }
50
+ if (babylonMaterial.coatRoughnessTexture) {
51
+ additionalTextures.push(babylonMaterial.coatRoughnessTexture);
52
+ }
53
+ return additionalTextures;
54
+ }
55
+ }
41
56
  return [];
42
57
  }
43
58
  // eslint-disable-next-line no-restricted-syntax
@@ -77,6 +92,37 @@ export class KHR_materials_clearcoat {
77
92
  }
78
93
  node.extensions[NAME] = clearCoatInfo;
79
94
  }
95
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
96
+ if (babylonMaterial.coatWeight == 0.0) {
97
+ resolve(node);
98
+ return;
99
+ }
100
+ this._wasUsed = true;
101
+ node.extensions = node.extensions || {};
102
+ const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);
103
+ let clearCoatTextureRoughnessInfo;
104
+ if (babylonMaterial.useCoatRoughnessFromWeightTexture) {
105
+ clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);
106
+ }
107
+ else {
108
+ clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatRoughnessTexture);
109
+ }
110
+ if (babylonMaterial.coatColorTexture) {
111
+ Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);
112
+ }
113
+ const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);
114
+ const clearCoatInfo = {
115
+ clearcoatFactor: babylonMaterial.coatWeight,
116
+ clearcoatTexture: clearCoatTextureInfo ?? undefined,
117
+ clearcoatRoughnessFactor: babylonMaterial.coatRoughness,
118
+ clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,
119
+ clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,
120
+ };
121
+ if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {
122
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
123
+ }
124
+ node.extensions[NAME] = clearCoatInfo;
125
+ }
80
126
  resolve(node);
81
127
  });
82
128
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_clearcoat.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;IAchC,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;IAEM,oCAAoC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;QACpG,MAAM,kBAAkB,GAAkB,EAAE,CAAC;QAC7C,IAAI,eAAe,YAAY,eAAe,EAAE,CAAC;YAC7C,IAAI,eAAe,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;gBACtC,IAAI,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;oBACpC,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC/D,CAAC;gBACD,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,2BAA2B,IAAI,eAAe,CAAC,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nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat 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 public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\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 PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_clearcoat.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;IAchC,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;IAEM,KAAK,CAAC,yCAAyC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;QAC/G,MAAM,kBAAkB,GAAkB,EAAE,CAAC;QAC7C,IAAI,eAAe,YAAY,eAAe,EAAE,CAAC;YAC7C,IAAI,eAAe,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;gBACtC,IAAI,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;oBACpC,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC/D,CAAC;gBACD,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,2BAA2B,IAAI,eAAe,CAAC,SAAS,CA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oBAC1C,eAAe,EAAE,eAAe,CAAC,UAAU;oBAC3C,gBAAgB,EAAE,oBAAoB,IAAI,SAAS;oBACnD,wBAAwB,EAAE,eAAe,CAAC,aAAa;oBACvD,yBAAyB,EAAE,6BAA6B,IAAI,SAAS;oBACrE,sBAAsB,EAAE,0BAA0B,IAAI,SAAS;iBAClE,CAAC;gBAEF,IAAI,aAAa,CAAC,gBAAgB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,EAAE,CAAC;oBAClJ,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;YAC1C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openPbrMaterial\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat 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 public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.coatWeight > 0) {\r\n if (babylonMaterial.coatWeightTexture) {\r\n additionalTextures.push(babylonMaterial.coatWeightTexture);\r\n }\r\n if (babylonMaterial.geometryCoatNormalTexture) {\r\n additionalTextures.push(babylonMaterial.geometryCoatNormalTexture);\r\n }\r\n if (babylonMaterial.coatRoughnessTexture) {\r\n additionalTextures.push(babylonMaterial.coatRoughnessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\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 PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.coatWeight == 0.0) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.useCoatRoughnessFromWeightTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatRoughnessTexture);\r\n }\r\n\r\n if (babylonMaterial.coatColorTexture) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.geometryCoatNormalTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.coatWeight,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.coatRoughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n"]}
@@ -0,0 +1,32 @@
1
+ import type { IMaterial } from "babylonjs-gltf2interface";
2
+ import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
3
+ import { GLTFExporter } from "../glTFExporter.js";
4
+ import type { Material } from "@babylonjs/core/Materials/material.js";
5
+ import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
6
+ /**
7
+ * @internal
8
+ */
9
+ export declare class KHR_materials_clearcoat_anisotropy implements IGLTFExporterExtensionV2 {
10
+ /** Name of this extension */
11
+ readonly name = "KHR_materials_clearcoat_anisotropy";
12
+ /** Defines whether this extension is enabled */
13
+ enabled: boolean;
14
+ /** Defines whether this extension is required */
15
+ required: boolean;
16
+ private _exporter;
17
+ private _wasUsed;
18
+ private _anisoTexturesMap;
19
+ constructor(exporter: GLTFExporter);
20
+ dispose(): void;
21
+ /** @internal */
22
+ get wasUsed(): boolean;
23
+ /**
24
+ * After exporting a material, deal with the additional textures
25
+ * @param context GLTF context of the material
26
+ * @param node exported GLTF node
27
+ * @param babylonMaterial corresponding babylon material
28
+ * @returns array of additional textures to export
29
+ */
30
+ postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
31
+ postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
32
+ }