@onerjs/serializers 8.26.3 → 8.26.4

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_diffuse_roughness.d.ts → EXT_materials_diffuse_roughness.d.ts} +3 -3
  2. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +61 -0
  3. package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +1 -0
  4. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +1 -9
  5. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +1 -192
  6. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  7. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +1 -1
  8. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +1 -47
  9. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  10. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +1 -1
  11. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +1 -1
  12. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  13. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +1 -1
  14. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +1 -1
  15. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  16. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +1 -1
  17. package/glTF/2.0/Extensions/KHR_materials_sheen.js +1 -1
  18. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  19. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +1 -1
  20. package/glTF/2.0/Extensions/KHR_materials_specular.js +1 -33
  21. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  22. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +1 -1
  23. package/glTF/2.0/Extensions/KHR_materials_transmission.js +1 -1
  24. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  25. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +1 -1
  26. package/glTF/2.0/Extensions/KHR_materials_volume.js +1 -1
  27. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  28. package/glTF/2.0/Extensions/index.d.ts +1 -4
  29. package/glTF/2.0/Extensions/index.js +1 -4
  30. package/glTF/2.0/Extensions/index.js.map +1 -1
  31. package/glTF/2.0/glTFExporter.d.ts +1 -8
  32. package/glTF/2.0/glTFExporter.js +5 -17
  33. package/glTF/2.0/glTFExporter.js.map +1 -1
  34. package/glTF/2.0/glTFExporterExtension.d.ts +1 -1
  35. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  36. package/glTF/2.0/glTFMaterialExporter.d.ts +1 -9
  37. package/glTF/2.0/glTFMaterialExporter.js +15 -41
  38. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  39. package/package.json +3 -3
  40. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.d.ts +0 -32
  41. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js +0 -231
  42. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js.map +0 -1
  43. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.d.ts +0 -24
  44. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js +0 -101
  45. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js.map +0 -1
  46. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.d.ts +0 -24
  47. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js +0 -70
  48. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js.map +0 -1
  49. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js +0 -78
  50. package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +0 -1
@@ -6,9 +6,9 @@ import type { BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js
6
6
  /**
7
7
  * @internal
8
8
  */
9
- export declare class KHR_materials_diffuse_roughness implements IGLTFExporterExtensionV2 {
9
+ export declare class EXT_materials_diffuse_roughness implements IGLTFExporterExtensionV2 {
10
10
  /** Name of this extension */
11
- readonly name = "KHR_materials_diffuse_roughness";
11
+ readonly name = "EXT_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 KHR_materials_diffuse_roughness implements IGLTFExporterExt
19
19
  dispose(): void;
20
20
  /** @internal */
21
21
  get wasUsed(): boolean;
22
- postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
22
+ postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
23
23
  postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
24
  }
@@ -0,0 +1,61 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { PBRBaseMaterial } from "@onerjs/core/Materials/PBR/pbrBaseMaterial.js";
3
+ const NAME = "EXT_materials_diffuse_roughness";
4
+ /**
5
+ * @internal
6
+ */
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ export class EXT_materials_diffuse_roughness {
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
+ postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
25
+ const additionalTextures = [];
26
+ if (babylonMaterial instanceof PBRBaseMaterial) {
27
+ if (babylonMaterial._baseDiffuseRoughness) {
28
+ if (babylonMaterial._baseDiffuseRoughnessTexture) {
29
+ additionalTextures.push(babylonMaterial._baseDiffuseRoughnessTexture);
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
+ if (babylonMaterial instanceof PBRBaseMaterial) {
40
+ if (!babylonMaterial._baseDiffuseRoughness) {
41
+ resolve(node);
42
+ return;
43
+ }
44
+ this._wasUsed = true;
45
+ node.extensions = node.extensions || {};
46
+ const diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial._baseDiffuseRoughnessTexture);
47
+ const diffuseRoughnessInfo = {
48
+ diffuseRoughnessFactor: babylonMaterial._baseDiffuseRoughness,
49
+ diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,
50
+ };
51
+ if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {
52
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
53
+ }
54
+ node.extensions[NAME] = diffuseRoughnessInfo;
55
+ }
56
+ resolve(node);
57
+ });
58
+ }
59
+ }
60
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_materials_diffuse_roughness(exporter));
61
+ //# sourceMappingURL=EXT_materials_diffuse_roughness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EXT_materials_diffuse_roughness.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,sDAA2C;AAGrE,MAAM,IAAI,GAAG,iCAAiC,CAAC;AAE/C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,+BAA+B;IAcxC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAA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D,uBAAuB,EAAE,2BAA2B,IAAI,SAAS;iBACpE,CAAC;gBAEF,IAAI,oBAAoB,CAAC,uBAAuB,KAAK,IAAI,EAAE,CAAC;oBACxD,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC;YACjD,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,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IEXTMaterialsDiffuseRoughness } 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 = \"EXT_materials_diffuse_roughness\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_materials_diffuse_roughness 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._baseDiffuseRoughness) {\r\n if (babylonMaterial._baseDiffuseRoughnessTexture) {\r\n additionalTextures.push(babylonMaterial._baseDiffuseRoughnessTexture);\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._baseDiffuseRoughness) {\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 diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial._baseDiffuseRoughnessTexture);\r\n\r\n const diffuseRoughnessInfo: IEXTMaterialsDiffuseRoughness = {\r\n diffuseRoughnessFactor: babylonMaterial._baseDiffuseRoughness,\r\n diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,\r\n };\r\n\r\n if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = diffuseRoughnessInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_materials_diffuse_roughness(exporter));\r\n"]}
@@ -15,18 +15,10 @@ export declare class KHR_materials_anisotropy implements IGLTFExporterExtensionV
15
15
  required: boolean;
16
16
  private _exporter;
17
17
  private _wasUsed;
18
- private _anisoTexturesMap;
19
18
  constructor(exporter: GLTFExporter);
20
19
  dispose(): void;
21
20
  /** @internal */
22
21
  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[]>;
22
+ postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
31
23
  postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
32
24
  }
@@ -1,123 +1,6 @@
1
1
  import { GLTFExporter } from "../glTFExporter.js";
2
2
  import { PBRBaseMaterial } from "@onerjs/core/Materials/PBR/pbrBaseMaterial.js";
3
- import { OpenPBRMaterial } from "@onerjs/core/Materials/PBR/openPbrMaterial.js";
4
- import { Constants } from "@onerjs/core/Engines/constants.js";
5
- import { Effect } from "@onerjs/core/Materials/effect.js";
6
- import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
7
3
  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
- }
121
4
  /**
122
5
  * @internal
123
6
  */
@@ -131,7 +14,6 @@ export class KHR_materials_anisotropy {
131
14
  /** Defines whether this extension is required */
132
15
  this.required = false;
133
16
  this._wasUsed = false;
134
- this._anisoTexturesMap = {};
135
17
  this._exporter = exporter;
136
18
  }
137
19
  dispose() { }
@@ -139,14 +21,7 @@ export class KHR_materials_anisotropy {
139
21
  get wasUsed() {
140
22
  return this._wasUsed;
141
23
  }
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) {
24
+ postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
150
25
  const additionalTextures = [];
151
26
  if (babylonMaterial instanceof PBRBaseMaterial) {
152
27
  if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {
@@ -156,22 +31,11 @@ export class KHR_materials_anisotropy {
156
31
  return additionalTextures;
157
32
  }
158
33
  }
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
- }
169
34
  return [];
170
35
  }
171
36
  // eslint-disable-next-line no-restricted-syntax
172
37
  postExportMaterialAsync(context, node, babylonMaterial) {
173
38
  return new Promise((resolve) => {
174
- var _a;
175
39
  if (babylonMaterial instanceof PBRBaseMaterial) {
176
40
  if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {
177
41
  resolve(node);
@@ -190,61 +54,6 @@ export class KHR_materials_anisotropy {
190
54
  }
191
55
  node.extensions[NAME] = anisotropyInfo;
192
56
  }
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
- }
248
57
  resolve(node);
249
58
  });
250
59
  }
@@ -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;AAG/C,OAAO,EAAE,eAAe,EAAE,sDAA2C;AAGrE,OAAO,EAAE,eAAe,EAAE,sDAA2C;AACrE,OAAO,EAAE,SAAS,EAAE,0CAA+B;AACnD,OAAO,EAAE,MAAM,EAAE,yCAA8B;AAC/C,OAAO,EAAE,iBAAiB,EAAE,yEAA8D;AAG1F,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC,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,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,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,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"]}
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,sDAA2C;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,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,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EF,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"]}
@@ -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
- postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
22
+ postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
23
23
  postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
24
  }
@@ -1,7 +1,6 @@
1
1
  import { GLTFExporter } from "../glTFExporter.js";
2
2
  import { PBRBaseMaterial } from "@onerjs/core/Materials/PBR/pbrBaseMaterial.js";
3
3
  import { Tools } from "@onerjs/core/Misc/tools.js";
4
- import { OpenPBRMaterial } from "@onerjs/core/Materials/PBR/openPbrMaterial.js";
5
4
  const NAME = "KHR_materials_clearcoat";
6
5
  /**
7
6
  * @internal
@@ -23,7 +22,7 @@ export class KHR_materials_clearcoat {
23
22
  get wasUsed() {
24
23
  return this._wasUsed;
25
24
  }
26
- async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
25
+ postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
27
26
  const additionalTextures = [];
28
27
  if (babylonMaterial instanceof PBRBaseMaterial) {
29
28
  if (babylonMaterial.clearCoat.isEnabled) {
@@ -39,20 +38,6 @@ export class KHR_materials_clearcoat {
39
38
  return additionalTextures;
40
39
  }
41
40
  }
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
- }
56
41
  return [];
57
42
  }
58
43
  // eslint-disable-next-line no-restricted-syntax
@@ -92,37 +77,6 @@ export class KHR_materials_clearcoat {
92
77
  }
93
78
  node.extensions[NAME] = clearCoatInfo;
94
79
  }
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
- }
126
80
  resolve(node);
127
81
  });
128
82
  }
@@ -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,sDAA2C;AAGrE,OAAO,EAAE,KAAK,EAAE,mCAAwB;AACxC,OAAO,EAAE,eAAe,EAAE,sDAA2C;AAErE,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;IAchC,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AC,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"]}
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,sDAA2C;AAGrE,OAAO,EAAE,KAAK,EAAE,mCAAwB;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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,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\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"]}
@@ -27,7 +27,7 @@ export declare class KHR_materials_diffuse_transmission implements IGLTFExporter
27
27
  * @param babylonMaterial corresponding babylon material
28
28
  * @returns array of additional textures to export
29
29
  */
30
- postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
30
+ postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
31
31
  private _isExtensionEnabled;
32
32
  /**
33
33
  * After exporting a material
@@ -50,7 +50,7 @@ export class KHR_materials_diffuse_transmission {
50
50
  * @param babylonMaterial corresponding babylon material
51
51
  * @returns array of additional textures to export
52
52
  */
53
- async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
53
+ postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
54
54
  const additionalTextures = [];
55
55
  if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
56
56
  const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/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D,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, IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\n/**\r\n * Get the appropriate translucency intensity texture for the material.\r\n * @internal\r\n */\r\nfunction GetTranslucencyIntensityTexture(context: string, babylonMaterial: PBRMaterial): Nullable<BaseTexture> {\r\n const subs = babylonMaterial.subSurface;\r\n let texture = null;\r\n\r\n // Check if translucency intensity texture is available or can be derived from thickness texture\r\n if (subs.translucencyIntensityTexture) {\r\n texture = subs.translucencyIntensityTexture;\r\n } else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {\r\n texture = subs.thicknessTexture;\r\n }\r\n\r\n if (texture && !subs.useGltfStyleTextures) {\r\n Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);\r\n return null;\r\n }\r\n\r\n return texture;\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n if (translucencyIntensityTexture) {\r\n additionalTextures.push(translucencyIntensityTexture);\r\n }\r\n if (babylonMaterial.subSurface.translucencyColorTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n if (!subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n\r\n return (\r\n !mat.unlit &&\r\n !subs.useAlbedoToTintTranslucency &&\r\n subs.useGltfStyleTextures &&\r\n subs.volumeIndexOfRefraction === 1 &&\r\n subs.minimumThickness === 0 &&\r\n subs.maximumThickness === 0\r\n );\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise that resolves with the updated node\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n\r\n const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;\r\n const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;\r\n const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();\r\n const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;\r\n\r\n const diffuseTransmissionInfo: IKHRMaterialsDiffuseTransmission = {\r\n diffuseTransmissionFactor,\r\n diffuseTransmissionTexture,\r\n diffuseTransmissionColorFactor,\r\n diffuseTransmissionColorTexture,\r\n };\r\n\r\n if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = diffuseTransmissionInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,kDAAuC;AAE7D,OAAO,EAAE,MAAM,EA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AAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\n/**\r\n * Get the appropriate translucency intensity texture for the material.\r\n * @internal\r\n */\r\nfunction GetTranslucencyIntensityTexture(context: string, babylonMaterial: PBRMaterial): Nullable<BaseTexture> {\r\n const subs = babylonMaterial.subSurface;\r\n let texture = null;\r\n\r\n // Check if translucency intensity texture is available or can be derived from thickness texture\r\n if (subs.translucencyIntensityTexture) {\r\n texture = subs.translucencyIntensityTexture;\r\n } else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {\r\n texture = subs.thicknessTexture;\r\n }\r\n\r\n if (texture && !subs.useGltfStyleTextures) {\r\n Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);\r\n return null;\r\n }\r\n\r\n return texture;\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n if (translucencyIntensityTexture) {\r\n additionalTextures.push(translucencyIntensityTexture);\r\n }\r\n if (babylonMaterial.subSurface.translucencyColorTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n if (!subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n\r\n return (\r\n !mat.unlit &&\r\n !subs.useAlbedoToTintTranslucency &&\r\n subs.useGltfStyleTextures &&\r\n subs.volumeIndexOfRefraction === 1 &&\r\n subs.minimumThickness === 0 &&\r\n subs.maximumThickness === 0\r\n );\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise that resolves with the updated node\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n\r\n const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;\r\n const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;\r\n const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();\r\n const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;\r\n\r\n const diffuseTransmissionInfo: IKHRMaterialsDiffuseTransmission = {\r\n diffuseTransmissionFactor,\r\n diffuseTransmissionTexture,\r\n diffuseTransmissionColorFactor,\r\n diffuseTransmissionColorTexture,\r\n };\r\n\r\n if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = diffuseTransmissionInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));\r\n"]}
@@ -19,6 +19,6 @@ export declare class KHR_materials_iridescence implements IGLTFExporterExtension
19
19
  dispose(): void;
20
20
  /** @internal */
21
21
  get wasUsed(): boolean;
22
- postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
22
+ postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
23
23
  postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
24
  }