@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
@@ -0,0 +1,231 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openPbrMaterial.js";
3
+ import { Constants } from "@babylonjs/core/Engines/constants.js";
4
+ import { Effect } from "@babylonjs/core/Materials/effect.js";
5
+ import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
6
+ const NAME = "KHR_materials_clearcoat_anisotropy";
7
+ // Convert OpenPBR anisotropy values to glTF-compatible values
8
+ function OpenpbrAnisotropyStrengthToGltf(baseRoughness, anisotropy) {
9
+ const baseAlpha = baseRoughness * baseRoughness;
10
+ const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));
11
+ const roughnessB = (1 - anisotropy) * roughnessT;
12
+ const newBaseRoughness = Math.sqrt(roughnessB);
13
+ const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);
14
+ return { newBaseRoughness, newAnisotropyStrength };
15
+ }
16
+ function CopyTextureTransform(source, destination) {
17
+ destination.uOffset = source.uOffset;
18
+ destination.vOffset = source.vOffset;
19
+ destination.uScale = source.uScale;
20
+ destination.vScale = source.vScale;
21
+ destination.uAng = source.uAng;
22
+ destination.vAng = source.vAng;
23
+ destination.wAng = source.wAng;
24
+ destination.uRotationCenter = source.uRotationCenter;
25
+ destination.vRotationCenter = source.vRotationCenter;
26
+ }
27
+ // Custom shader for merging anisotropy into tangent texture
28
+ const AnisotropyMergeFragment = `
29
+ precision highp float;
30
+ #ifdef HAS_TANGENT_TEXTURE
31
+ uniform sampler2D tangentTexture;
32
+ #endif
33
+ #ifdef HAS_ANISOTROPY_TEXTURE
34
+ uniform sampler2D anisotropyTexture;
35
+ #endif
36
+ uniform int useRoughnessFromMetallicGreen;
37
+ uniform int useAnisotropyFromTangentBlue;
38
+
39
+ varying vec2 vUV;
40
+
41
+ void main() {
42
+ vec2 tangent = vec2(1.0, 0.0);
43
+ float anisotropy = 1.0;
44
+ #ifdef HAS_TANGENT_TEXTURE
45
+ // Tangent texture is present
46
+ vec4 tangentSample = texture2D(tangentTexture, vUV);
47
+ tangent = tangentSample.rg;
48
+
49
+ if (useAnisotropyFromTangentBlue > 0) {
50
+ anisotropy = tangentSample.b;
51
+ }
52
+ #endif
53
+ #ifdef HAS_ANISOTROPY_TEXTURE
54
+ // Anisotropy texture is present
55
+ vec4 anisotropySample = texture2D(anisotropyTexture, vUV);
56
+ anisotropy = anisotropySample.r;
57
+ #endif
58
+
59
+ // Output: RG = tangent XY, B = anisotropy strength
60
+ vec4 anisotropyData = vec4(tangent.x, tangent.y, anisotropy, 1.0);
61
+ gl_FragColor = anisotropyData;
62
+ }
63
+ `;
64
+ // In your postExportMaterialAsync method:
65
+ async function CreateMergedAnisotropyTexture(babylonMaterial) {
66
+ const scene = babylonMaterial.getScene();
67
+ // Register the custom shader if not already done
68
+ if (!Effect.ShadersStore["anisotropyMergeFragmentShader"]) {
69
+ Effect.ShadersStore["anisotropyMergeFragmentShader"] = AnisotropyMergeFragment;
70
+ }
71
+ const anisoStrengthTexture = babylonMaterial.coatRoughnessAnisotropyTexture;
72
+ const tangentTexture = babylonMaterial.geometryCoatTangentTexture;
73
+ // If we don't have any textures, we don't need to generate anything.
74
+ if (!(anisoStrengthTexture || tangentTexture)) {
75
+ return null;
76
+ }
77
+ const width = Math.max(anisoStrengthTexture ? anisoStrengthTexture.getSize().width : 1, tangentTexture ? tangentTexture.getSize().width : 1);
78
+ const height = Math.max(anisoStrengthTexture ? anisoStrengthTexture.getSize().height : 1, tangentTexture ? tangentTexture.getSize().height : 1);
79
+ const textureOptions = {
80
+ type: Constants.TEXTURETYPE_UNSIGNED_BYTE,
81
+ format: Constants.TEXTUREFORMAT_RGBA,
82
+ samplingMode: Constants.TEXTURE_BILINEAR_SAMPLINGMODE,
83
+ generateDepthBuffer: false,
84
+ generateStencilBuffer: false,
85
+ generateMipMaps: false,
86
+ };
87
+ const rtTexture = new ProceduralTexture(babylonMaterial.name + "_anisotropy", {
88
+ width,
89
+ height,
90
+ }, "anisotropyMerge", scene, textureOptions);
91
+ rtTexture.refreshRate = -1;
92
+ // Set uniforms and defines
93
+ let defines = "";
94
+ if (tangentTexture) {
95
+ defines += "#define HAS_TANGENT_TEXTURE\n";
96
+ rtTexture.setTexture("tangentTexture", tangentTexture);
97
+ CopyTextureTransform(tangentTexture, rtTexture);
98
+ }
99
+ rtTexture.setVector2("tangentVector", babylonMaterial.geometryTangent);
100
+ if (anisoStrengthTexture) {
101
+ defines += "#define HAS_ANISOTROPY_TEXTURE\n";
102
+ rtTexture.setTexture("anisotropyTexture", anisoStrengthTexture);
103
+ CopyTextureTransform(anisoStrengthTexture, rtTexture);
104
+ }
105
+ rtTexture.setInt("useAnisotropyFromTangentBlue", babylonMaterial._useCoatRoughnessAnisotropyFromTangentTexture ? 1 : 0);
106
+ rtTexture.defines = defines;
107
+ return await new Promise((resolve, reject) => {
108
+ // Compile and render
109
+ rtTexture.executeWhenReady(() => {
110
+ try {
111
+ rtTexture.render();
112
+ resolve(rtTexture);
113
+ }
114
+ catch (error) {
115
+ reject(error instanceof Error ? error : new Error(String(error)));
116
+ }
117
+ });
118
+ });
119
+ }
120
+ /**
121
+ * @internal
122
+ */
123
+ // eslint-disable-next-line @typescript-eslint/naming-convention
124
+ export class KHR_materials_clearcoat_anisotropy {
125
+ constructor(exporter) {
126
+ /** Name of this extension */
127
+ this.name = NAME;
128
+ /** Defines whether this extension is enabled */
129
+ this.enabled = true;
130
+ /** Defines whether this extension is required */
131
+ this.required = false;
132
+ this._wasUsed = false;
133
+ this._anisoTexturesMap = {};
134
+ this._exporter = exporter;
135
+ }
136
+ dispose() { }
137
+ /** @internal */
138
+ get wasUsed() {
139
+ return this._wasUsed;
140
+ }
141
+ /**
142
+ * After exporting a material, deal with the additional textures
143
+ * @param context GLTF context of the material
144
+ * @param node exported GLTF node
145
+ * @param babylonMaterial corresponding babylon material
146
+ * @returns array of additional textures to export
147
+ */
148
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
149
+ const additionalTextures = [];
150
+ if (babylonMaterial instanceof OpenPBRMaterial) {
151
+ if (babylonMaterial.coatRoughnessAnisotropy > 0) {
152
+ const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);
153
+ if (anisoTexture) {
154
+ additionalTextures.push(anisoTexture);
155
+ this._anisoTexturesMap[babylonMaterial.id] = anisoTexture;
156
+ }
157
+ return additionalTextures;
158
+ }
159
+ }
160
+ return [];
161
+ }
162
+ // eslint-disable-next-line no-restricted-syntax
163
+ postExportMaterialAsync(context, node, babylonMaterial) {
164
+ return new Promise((resolve) => {
165
+ var _a;
166
+ if (babylonMaterial instanceof OpenPBRMaterial) {
167
+ if (babylonMaterial.coatRoughnessAnisotropy > 0) {
168
+ // This material must have the clearcoat extension already before
169
+ // we can add the clearcoat anisotropy sub-extension
170
+ node.extensions = node.extensions || {};
171
+ const parentExt = node.extensions ? node.extensions["KHR_materials_clearcoat"] : null;
172
+ if (!parentExt) {
173
+ return resolve(node);
174
+ }
175
+ this._wasUsed = true;
176
+ // Check if we can convert from OpenPBR anisotropy to glTF anisotropy
177
+ // Conversion involves both specular roughness and anisotropic roughness changes so,
178
+ // if there are textures for either, we can't reliably convert due to there potentially
179
+ // being different mappings between the textures.
180
+ const roughnessTexture = babylonMaterial.coatRoughnessTexture;
181
+ const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];
182
+ // If no textures are being used, we'll always output glTF-style anisotropy.
183
+ // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.
184
+ if (!roughnessTexture && !mergedAnisoTexture) {
185
+ // Convert constants
186
+ let newBaseRoughness = babylonMaterial.coatRoughness;
187
+ let newAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;
188
+ if (!babylonMaterial._useGltfStyleAnisotropy) {
189
+ const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.coatRoughness, babylonMaterial.coatRoughnessAnisotropy);
190
+ newBaseRoughness = newParams.newBaseRoughness;
191
+ newAnisotropyStrength = newParams.newAnisotropyStrength;
192
+ }
193
+ if (node.pbrMetallicRoughness) {
194
+ node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;
195
+ }
196
+ const anisotropyInfo = {
197
+ clearcoatAnisotropyStrength: newAnisotropyStrength,
198
+ clearcoatAnisotropyRotation: babylonMaterial.geometryCoatTangentAngle + Math.PI * 0.5,
199
+ clearcoatAnisotropyTexture: undefined,
200
+ };
201
+ parentExt.extensions = parentExt.extensions || {};
202
+ parentExt.extensions[NAME] = anisotropyInfo;
203
+ return resolve(node);
204
+ }
205
+ const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;
206
+ const anisotropyInfo = {
207
+ clearcoatAnisotropyStrength: babylonMaterial.coatRoughnessAnisotropy,
208
+ clearcoatAnisotropyRotation: babylonMaterial.geometryCoatTangentAngle,
209
+ clearcoatAnisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,
210
+ extensions: {},
211
+ };
212
+ if (!babylonMaterial._useGltfStyleAnisotropy) {
213
+ anisotropyInfo.extensions["EXT_materials_anisotropy_openpbr"] = {
214
+ openPbrAnisotropyEnabled: true,
215
+ };
216
+ (_a = this._exporter._glTF).extensionsUsed || (_a.extensionsUsed = []);
217
+ if (this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr") === -1) {
218
+ this._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr");
219
+ }
220
+ }
221
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
222
+ parentExt.extensions = parentExt.extensions || {};
223
+ parentExt.extensions[NAME] = anisotropyInfo;
224
+ }
225
+ }
226
+ resolve(node);
227
+ });
228
+ }
229
+ }
230
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat_anisotropy(exporter));
231
+ //# sourceMappingURL=KHR_materials_clearcoat_anisotropy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_materials_clearcoat_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AACrE,OAAO,EAAE,SAAS,EAAE,6CAA+B;AACnD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,iBAAiB,EAAE,4EAA8D;AAG1F,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAElD,8DAA8D;AAC9D,SAAS,+BAA+B,CAAC,aAAqB,EAAE,UAAkB;IAC9E,MAAM,SAAS,GAAG,aAAa,GAAG,aAAa,CAAC;IAChD,MAAM,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5F,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;IACjD,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAErH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAe,EAAE,WAAoB;IAC/D,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,O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BACjB,CAAC;oBAEF,IAAI,CAAC,eAAe,CAAC,uBAAuB,EAAE,CAAC;wBAC3C,cAAc,CAAC,UAAW,CAAC,kCAAkC,CAAC,GAAG;4BAC7D,wBAAwB,EAAE,IAAI;yBACjC,CAAC;wBACF,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,EAAC,cAAc,QAAd,cAAc,GAAK,EAAE,EAAC;wBAC3C,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,kCAAkC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;4BACzF,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;wBACjF,CAAC;oBACL,CAAC;oBAED,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;oBAEzD,SAAS,CAAC,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC;oBAClD,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;gBAChD,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,kCAAkC,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoatAnisotropy } 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 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_clearcoat_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.coatRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryCoatTangentTexture;\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._useCoatRoughnessAnisotropyFromTangentTexture ? 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_clearcoat_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 OpenPBRMaterial) {\r\n if (babylonMaterial.coatRoughnessAnisotropy > 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 OpenPBRMaterial) {\r\n if (babylonMaterial.coatRoughnessAnisotropy > 0) {\r\n // This material must have the clearcoat extension already before\r\n // we can add the clearcoat anisotropy sub-extension\r\n node.extensions = node.extensions || {};\r\n const parentExt = node.extensions ? node.extensions[\"KHR_materials_clearcoat\"] : null;\r\n if (!parentExt) {\r\n return resolve(node);\r\n }\r\n this._wasUsed = true;\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 const roughnessTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessTexture;\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.coatRoughness;\r\n let newAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.coatRoughness, babylonMaterial.coatRoughnessAnisotropy);\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: IKHRMaterialsClearcoatAnisotropy = {\r\n clearcoatAnisotropyStrength: newAnisotropyStrength,\r\n clearcoatAnisotropyRotation: babylonMaterial.geometryCoatTangentAngle + Math.PI * 0.5,\r\n clearcoatAnisotropyTexture: undefined,\r\n };\r\n parentExt.extensions = parentExt.extensions || {};\r\n parentExt.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: IKHRMaterialsClearcoatAnisotropy = {\r\n clearcoatAnisotropyStrength: babylonMaterial.coatRoughnessAnisotropy,\r\n clearcoatAnisotropyRotation: babylonMaterial.geometryCoatTangentAngle,\r\n clearcoatAnisotropyTexture: 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 parentExt.extensions = parentExt.extensions || {};\r\n parentExt.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_clearcoat_anisotropy(exporter));\r\n"]}
@@ -0,0 +1,24 @@
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_color implements IGLTFExporterExtensionV2 {
10
+ /** Name of this extension */
11
+ readonly name = "KHR_materials_clearcoat_color";
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
+ constructor(exporter: GLTFExporter);
19
+ dispose(): void;
20
+ /** @internal */
21
+ get wasUsed(): boolean;
22
+ postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
23
+ postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
+ }
@@ -0,0 +1,101 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
3
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openPbrMaterial.js";
4
+ const NAME = "KHR_materials_clearcoat_color";
5
+ /**
6
+ * @internal
7
+ */
8
+ // eslint-disable-next-line @typescript-eslint/naming-convention
9
+ export class KHR_materials_clearcoat_color {
10
+ constructor(exporter) {
11
+ /** Name of this extension */
12
+ this.name = NAME;
13
+ /** Defines whether this extension is enabled */
14
+ this.enabled = true;
15
+ /** Defines whether this extension is required */
16
+ this.required = false;
17
+ this._wasUsed = false;
18
+ this._exporter = exporter;
19
+ }
20
+ dispose() { }
21
+ /** @internal */
22
+ get wasUsed() {
23
+ return this._wasUsed;
24
+ }
25
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
26
+ const additionalTextures = [];
27
+ if (babylonMaterial instanceof PBRBaseMaterial) {
28
+ if (babylonMaterial.clearCoat.isEnabled) {
29
+ if (babylonMaterial.clearCoat.tintTexture) {
30
+ additionalTextures.push(babylonMaterial.clearCoat.tintTexture);
31
+ }
32
+ return additionalTextures;
33
+ }
34
+ }
35
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
36
+ if (babylonMaterial.coatWeight > 0) {
37
+ if (babylonMaterial.coatColorTexture) {
38
+ additionalTextures.push(babylonMaterial.coatColorTexture);
39
+ }
40
+ return additionalTextures;
41
+ }
42
+ }
43
+ return [];
44
+ }
45
+ // eslint-disable-next-line no-restricted-syntax
46
+ postExportMaterialAsync(context, node, babylonMaterial) {
47
+ return new Promise((resolve) => {
48
+ if (babylonMaterial instanceof PBRBaseMaterial) {
49
+ if (!babylonMaterial.clearCoat.isEnabled) {
50
+ resolve(node);
51
+ return;
52
+ }
53
+ this._wasUsed = true;
54
+ // This material must have the clearcoat extension already before
55
+ // we can add the clearcoat color sub-extension
56
+ const parentExt = node.extensions ? node.extensions["KHR_materials_clearcoat"] : null;
57
+ if (!parentExt) {
58
+ resolve(node);
59
+ return;
60
+ }
61
+ const coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.tintTexture);
62
+ const clearCoatInfo = {
63
+ clearcoatColorFactor: babylonMaterial.clearCoat.tintColor.asArray(),
64
+ clearcoatColorTexture: coatColorTextureInfo ?? undefined,
65
+ };
66
+ if (clearCoatInfo.clearcoatColorTexture !== null) {
67
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
68
+ }
69
+ parentExt.extensions = parentExt.extensions || {};
70
+ parentExt.extensions[NAME] = clearCoatInfo;
71
+ }
72
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
73
+ if (babylonMaterial.coatWeight == 0.0) {
74
+ resolve(node);
75
+ return;
76
+ }
77
+ this._wasUsed = true;
78
+ // This material must have the clearcoat extension already before
79
+ // we can add the clearcoat color sub-extension
80
+ const parentExt = node.extensions ? node.extensions["KHR_materials_clearcoat"] : null;
81
+ if (!parentExt) {
82
+ resolve(node);
83
+ return;
84
+ }
85
+ const coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);
86
+ const clearCoatInfo = {
87
+ clearcoatColorFactor: babylonMaterial.coatColor.asArray(),
88
+ clearcoatColorTexture: coatColorTextureInfo ?? undefined,
89
+ };
90
+ if (clearCoatInfo.clearcoatColorTexture !== null) {
91
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
92
+ }
93
+ parentExt.extensions = parentExt.extensions || {};
94
+ parentExt.extensions[NAME] = clearCoatInfo;
95
+ }
96
+ resolve(node);
97
+ });
98
+ }
99
+ }
100
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat_color(exporter));
101
+ //# sourceMappingURL=KHR_materials_clearcoat_color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_materials_clearcoat_color.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat_color.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAErE,MAAM,IAAI,GAAG,+BAA+B,CAAC;AAE7C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,6BAA6B;IActC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,i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tF,IAAI,CAAC,SAAS,EAAE,CAAC;oBACb,OAAO,CAAC,IAAI,CAAC,CAAC;oBACd,OAAO;gBACX,CAAC;gBAED,MAAM,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;gBAChH,MAAM,aAAa,GAAgC;oBAC/C,oBAAoB,EAAE,eAAe,CAAC,SAAS,CAAC,OAAO,EAAE;oBACzD,qBAAqB,EAAE,oBAAoB,IAAI,SAAS;iBAC3D,CAAC;gBAEF,IAAI,aAAa,CAAC,qBAAqB,KAAK,IAAI,EAAE,CAAC;oBAC/C,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBACD,SAAS,CAAC,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC;gBAClD,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;YAC/C,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,6BAA6B,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoatColor } 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 { OpenPBRMaterial } from \"core/Materials/PBR/openPbrMaterial\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat_color\";\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_color 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.tintTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.tintTexture);\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.coatColorTexture) {\r\n additionalTextures.push(babylonMaterial.coatColorTexture);\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 // This material must have the clearcoat extension already before\r\n // we can add the clearcoat color sub-extension\r\n const parentExt = node.extensions ? node.extensions[\"KHR_materials_clearcoat\"] : null;\r\n if (!parentExt) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n const coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.tintTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoatColor = {\r\n clearcoatColorFactor: babylonMaterial.clearCoat.tintColor.asArray(),\r\n clearcoatColorTexture: coatColorTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatColorTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n parentExt.extensions = parentExt.extensions || {};\r\n parentExt.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 // This material must have the clearcoat extension already before\r\n // we can add the clearcoat color sub-extension\r\n const parentExt = node.extensions ? node.extensions[\"KHR_materials_clearcoat\"] : null;\r\n if (!parentExt) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n const coatColorTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.coatWeightTexture);\r\n const clearCoatInfo: IKHRMaterialsClearcoatColor = {\r\n clearcoatColorFactor: babylonMaterial.coatColor.asArray(),\r\n clearcoatColorTexture: coatColorTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatColorTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n parentExt.extensions = parentExt.extensions || {};\r\n parentExt.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_color(exporter));\r\n"]}
@@ -0,0 +1,24 @@
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_darkening implements IGLTFExporterExtensionV2 {
10
+ /** Name of this extension */
11
+ readonly name = "KHR_materials_clearcoat_darkening";
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
+ constructor(exporter: GLTFExporter);
19
+ dispose(): void;
20
+ /** @internal */
21
+ get wasUsed(): boolean;
22
+ postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
23
+ postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
+ }
@@ -0,0 +1,70 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openPbrMaterial.js";
3
+ const NAME = "KHR_materials_clearcoat_darkening";
4
+ /**
5
+ * @internal
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ export class KHR_materials_clearcoat_darkening {
9
+ constructor(exporter) {
10
+ /** Name of this extension */
11
+ this.name = NAME;
12
+ /** Defines whether this extension is enabled */
13
+ this.enabled = true;
14
+ /** Defines whether this extension is required */
15
+ this.required = false;
16
+ this._wasUsed = false;
17
+ this._exporter = exporter;
18
+ }
19
+ dispose() { }
20
+ /** @internal */
21
+ get wasUsed() {
22
+ return this._wasUsed;
23
+ }
24
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
25
+ const additionalTextures = [];
26
+ if (babylonMaterial instanceof OpenPBRMaterial) {
27
+ if (babylonMaterial.coatDarkening) {
28
+ if (babylonMaterial.coatDarkeningTexture) {
29
+ additionalTextures.push(babylonMaterial.coatDarkeningTexture);
30
+ }
31
+ return additionalTextures;
32
+ }
33
+ }
34
+ return [];
35
+ }
36
+ // eslint-disable-next-line no-restricted-syntax
37
+ postExportMaterialAsync(context, node, babylonMaterial) {
38
+ return new Promise((resolve) => {
39
+ let coatDarkeningFactor = null;
40
+ let coatDarkeningTexture = null;
41
+ if (babylonMaterial instanceof OpenPBRMaterial) {
42
+ coatDarkeningFactor = babylonMaterial.coatDarkening;
43
+ coatDarkeningTexture = babylonMaterial.coatDarkeningTexture;
44
+ }
45
+ if (coatDarkeningFactor === null || (coatDarkeningFactor === 1.0 && coatDarkeningTexture === null)) {
46
+ return resolve(node);
47
+ }
48
+ // This material must have the clearcoat extension already before
49
+ // we can add the clearcoat darkening sub-extension
50
+ const parentExt = node.extensions ? node.extensions["KHR_materials_clearcoat"] : null;
51
+ if (!parentExt) {
52
+ return resolve(node);
53
+ }
54
+ this._wasUsed = true;
55
+ const coatDarkeningTextureInfo = this._exporter._materialExporter.getTextureInfo(coatDarkeningTexture);
56
+ const coatDarkeningInfo = {
57
+ clearcoatDarkeningFactor: coatDarkeningFactor,
58
+ clearcoatDarkeningTexture: coatDarkeningTextureInfo ?? undefined,
59
+ };
60
+ if (coatDarkeningInfo.clearcoatDarkeningTexture !== null) {
61
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
62
+ }
63
+ parentExt.extensions = parentExt.extensions || {};
64
+ parentExt.extensions[NAME] = coatDarkeningInfo;
65
+ return resolve(node);
66
+ });
67
+ }
68
+ }
69
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat_darkening(exporter));
70
+ //# sourceMappingURL=KHR_materials_clearcoat_darkening.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_materials_clearcoat_darkening.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,MAAM,IAAI,GAAG,mCAAmC,CAAC;AAEjD;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,i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OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YAED,iEAAiE;YACjE,mDAAmD;YACnD,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACtF,IAAI,CAAC,SAAS,EAAE,CAAC;gBACb,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YAErB,MAAM,wBAAwB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;YAEvG,MAAM,iBAAiB,GAAoC;gBACvD,wBAAwB,EAAE,mBAAmB;gBAC7C,yBAAyB,EAAE,wBAAwB,IAAI,SAAS;aACnE,CAAC;YAEF,IAAI,iBAAiB,CAAC,yBAAyB,KAAK,IAAI,EAAE,CAAC;gBACvD,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YAC7D,CAAC;YAED,SAAS,CAAC,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC;YAClD,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC;YAE/C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,iCAAiC,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoatDarkening } 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 { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openPbrMaterial\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat_darkening\";\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_darkening 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 OpenPBRMaterial) {\r\n if (babylonMaterial.coatDarkening) {\r\n if (babylonMaterial.coatDarkeningTexture) {\r\n additionalTextures.push(babylonMaterial.coatDarkeningTexture);\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 let coatDarkeningFactor: Nullable<number> = null;\r\n let coatDarkeningTexture: Nullable<BaseTexture> = null;\r\n if (babylonMaterial instanceof OpenPBRMaterial) {\r\n coatDarkeningFactor = babylonMaterial.coatDarkening;\r\n coatDarkeningTexture = babylonMaterial.coatDarkeningTexture;\r\n }\r\n if (coatDarkeningFactor === null || (coatDarkeningFactor === 1.0 && coatDarkeningTexture === null)) {\r\n return resolve(node);\r\n }\r\n\r\n // This material must have the clearcoat extension already before\r\n // we can add the clearcoat darkening sub-extension\r\n const parentExt = node.extensions ? node.extensions[\"KHR_materials_clearcoat\"] : null;\r\n if (!parentExt) {\r\n return resolve(node);\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n const coatDarkeningTextureInfo = this._exporter._materialExporter.getTextureInfo(coatDarkeningTexture);\r\n\r\n const coatDarkeningInfo: IKHRMaterialsClearcoatDarkening = {\r\n clearcoatDarkeningFactor: coatDarkeningFactor,\r\n clearcoatDarkeningTexture: coatDarkeningTextureInfo ?? undefined,\r\n };\r\n\r\n if (coatDarkeningInfo.clearcoatDarkeningTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n parentExt.extensions = parentExt.extensions || {};\r\n parentExt.extensions[NAME] = coatDarkeningInfo;\r\n\r\n return resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat_darkening(exporter));\r\n"]}
@@ -6,9 +6,9 @@ import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture
6
6
  /**
7
7
  * @internal
8
8
  */
9
- export declare class EXT_materials_diffuse_roughness implements IGLTFExporterExtensionV2 {
9
+ export declare class KHR_materials_diffuse_roughness implements IGLTFExporterExtensionV2 {
10
10
  /** Name of this extension */
11
- readonly name = "EXT_materials_diffuse_roughness";
11
+ readonly name = "KHR_materials_diffuse_roughness";
12
12
  /** Defines whether this extension is enabled */
13
13
  enabled: boolean;
14
14
  /** Defines whether this extension is required */
@@ -19,6 +19,6 @@ export declare class EXT_materials_diffuse_roughness implements IGLTFExporterExt
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
  }
@@ -0,0 +1,78 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
3
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openPbrMaterial.js";
4
+ const NAME = "KHR_materials_diffuse_roughness";
5
+ /**
6
+ * @internal
7
+ */
8
+ // eslint-disable-next-line @typescript-eslint/naming-convention
9
+ export class KHR_materials_diffuse_roughness {
10
+ constructor(exporter) {
11
+ /** Name of this extension */
12
+ this.name = NAME;
13
+ /** Defines whether this extension is enabled */
14
+ this.enabled = true;
15
+ /** Defines whether this extension is required */
16
+ this.required = false;
17
+ this._wasUsed = false;
18
+ this._exporter = exporter;
19
+ }
20
+ dispose() { }
21
+ /** @internal */
22
+ get wasUsed() {
23
+ return this._wasUsed;
24
+ }
25
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
26
+ const additionalTextures = [];
27
+ if (babylonMaterial instanceof PBRBaseMaterial) {
28
+ if (babylonMaterial._baseDiffuseRoughness) {
29
+ if (babylonMaterial._baseDiffuseRoughnessTexture) {
30
+ additionalTextures.push(babylonMaterial._baseDiffuseRoughnessTexture);
31
+ }
32
+ return additionalTextures;
33
+ }
34
+ }
35
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
36
+ if (babylonMaterial.baseDiffuseRoughness) {
37
+ if (babylonMaterial.baseDiffuseRoughnessTexture) {
38
+ additionalTextures.push(babylonMaterial.baseDiffuseRoughnessTexture);
39
+ }
40
+ return additionalTextures;
41
+ }
42
+ }
43
+ return [];
44
+ }
45
+ // eslint-disable-next-line no-restricted-syntax
46
+ postExportMaterialAsync(context, node, babylonMaterial) {
47
+ return new Promise((resolve) => {
48
+ let diffuseRoughnessFactor = null;
49
+ let diffuseRoughnessTexture = null;
50
+ if (babylonMaterial instanceof PBRBaseMaterial) {
51
+ diffuseRoughnessFactor = babylonMaterial._baseDiffuseRoughness;
52
+ diffuseRoughnessTexture = babylonMaterial._baseDiffuseRoughnessTexture;
53
+ }
54
+ else if (babylonMaterial instanceof OpenPBRMaterial) {
55
+ diffuseRoughnessFactor = babylonMaterial.baseDiffuseRoughness;
56
+ diffuseRoughnessTexture = babylonMaterial.baseDiffuseRoughnessTexture;
57
+ }
58
+ if (!diffuseRoughnessFactor) {
59
+ resolve(node);
60
+ return;
61
+ }
62
+ this._wasUsed = true;
63
+ node.extensions = node.extensions || {};
64
+ const diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(diffuseRoughnessTexture);
65
+ const diffuseRoughnessInfo = {
66
+ diffuseRoughnessFactor: diffuseRoughnessFactor,
67
+ diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,
68
+ };
69
+ if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {
70
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
71
+ }
72
+ node.extensions[NAME] = diffuseRoughnessInfo;
73
+ resolve(node);
74
+ });
75
+ }
76
+ }
77
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_roughness(exporter));
78
+ //# sourceMappingURL=KHR_materials_diffuse_roughness.js.map