@babylonjs/serializers 8.34.0 → 8.34.1

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 (25) hide show
  1. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +11 -5
  2. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  3. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +8 -0
  4. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +136 -13
  5. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  6. package/glTF/2.0/Extensions/{KHR_materials_clearcoat_darkening.d.ts → KHR_materials_coat.d.ts} +10 -2
  7. package/glTF/2.0/Extensions/KHR_materials_coat.js +383 -0
  8. package/glTF/2.0/Extensions/KHR_materials_coat.js.map +1 -0
  9. package/glTF/2.0/Extensions/{KHR_materials_clearcoat_color.d.ts → KHR_materials_fuzz.d.ts} +13 -5
  10. package/glTF/2.0/Extensions/KHR_materials_fuzz.js +194 -0
  11. package/glTF/2.0/Extensions/KHR_materials_fuzz.js.map +1 -0
  12. package/glTF/2.0/Extensions/index.d.ts +2 -4
  13. package/glTF/2.0/Extensions/index.js +2 -4
  14. package/glTF/2.0/Extensions/index.js.map +1 -1
  15. package/package.json +3 -3
  16. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.d.ts +0 -32
  17. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js +0 -152
  18. package/glTF/2.0/Extensions/KHR_materials_clearcoat_anisotropy.js.map +0 -1
  19. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js +0 -101
  20. package/glTF/2.0/Extensions/KHR_materials_clearcoat_color.js.map +0 -1
  21. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js +0 -70
  22. package/glTF/2.0/Extensions/KHR_materials_clearcoat_darkening.js.map +0 -1
  23. package/glTF/2.0/Extensions/KHR_materials_clearcoat_ior.d.ts +0 -26
  24. package/glTF/2.0/Extensions/KHR_materials_clearcoat_ior.js +0 -60
  25. package/glTF/2.0/Extensions/KHR_materials_clearcoat_ior.js.map +0 -1
@@ -0,0 +1,194 @@
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
+ import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openpbrMaterial.js";
3
+ import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@babylonjs/core/Materials/Textures/textureMerger.js";
4
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
5
+ const NAME = "KHR_materials_fuzz";
6
+ /**
7
+ * Generate a unique ID for the merged coat textures based on the internal texture data.
8
+ * This is used for caching merged textures.
9
+ * @param babylonMaterial Source OpenPBR material
10
+ * @returns A unique ID string for the merged coat textures
11
+ * @internal
12
+ */
13
+ function GetFuzzColorTextureId(babylonMaterial) {
14
+ const fuzzColorTexture = babylonMaterial.fuzzColorTexture;
15
+ const fuzzColorId = fuzzColorTexture && fuzzColorTexture.getInternalTexture() ? fuzzColorTexture.getInternalTexture().uniqueId : "NoFuzzColor";
16
+ const fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;
17
+ const fuzzRoughnessId = fuzzRoughnessTexture && fuzzRoughnessTexture.getInternalTexture() ? fuzzRoughnessTexture.getInternalTexture().uniqueId : "NoFuzzRoughness";
18
+ return `FuzzColor_${fuzzColorId}_FuzzRoughness_${fuzzRoughnessId}`;
19
+ }
20
+ /**
21
+ * Using the coat weight and coat roughness textures, create a merged internal texture that can be used
22
+ * for multiple textures (with potentially different transforms) on export.
23
+ * @param babylonMaterial The source OpenPBR material
24
+ * @returns A new, internal texture with the coat weight in the red channel and coat roughness in the green channel
25
+ * @internal
26
+ */
27
+ async function CreateMergedFuzzInternalTexture(babylonMaterial) {
28
+ const scene = babylonMaterial.getScene();
29
+ const fuzzColorTexture = babylonMaterial.fuzzColorTexture;
30
+ const fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;
31
+ // If we don't have any textures, we don't need to generate anything.
32
+ if (!(fuzzColorTexture || fuzzRoughnessTexture)) {
33
+ return null;
34
+ }
35
+ const texture = await MergeTexturesAsync("FuzzTexture", CreateRGBAConfiguration(fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 0) : CreateConstantInput(1.0), // fuzz color from red channel
36
+ fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 1) : CreateConstantInput(1.0), // fuzz color from green channel
37
+ fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 2) : CreateConstantInput(1.0), // fuzz color from blue channel
38
+ // fuzz roughness goes in the alpha channel but may come from red or alpha channels in the source
39
+ fuzzRoughnessTexture ? CreateTextureInput(fuzzRoughnessTexture, babylonMaterial._useFuzzRoughnessFromTextureAlpha ? 3 : 0) : CreateConstantInput(1.0)), scene);
40
+ return texture.getInternalTexture();
41
+ }
42
+ /**
43
+ * Creates a temporary texture based on the source texture.
44
+ * @param internalTexture The source internal texture
45
+ * @param sourceTexture The source of the new texture's name, and sampler info
46
+ * @returns The new texture
47
+ */
48
+ function CreateTempTexture(internalTexture, sourceTexture) {
49
+ const tempTexture = new Texture(sourceTexture.name, sourceTexture.getScene());
50
+ tempTexture._texture = internalTexture;
51
+ tempTexture.coordinatesIndex = sourceTexture.coordinatesIndex;
52
+ if (sourceTexture instanceof Texture) {
53
+ tempTexture.uOffset = sourceTexture.uOffset;
54
+ tempTexture.vOffset = sourceTexture.vOffset;
55
+ tempTexture.uScale = sourceTexture.uScale;
56
+ tempTexture.vScale = sourceTexture.vScale;
57
+ tempTexture.wAng = sourceTexture.wAng;
58
+ }
59
+ tempTexture.wrapU = sourceTexture.wrapU;
60
+ tempTexture.wrapV = sourceTexture.wrapV;
61
+ return tempTexture;
62
+ }
63
+ /**
64
+ * @internal
65
+ */
66
+ // eslint-disable-next-line @typescript-eslint/naming-convention
67
+ export class KHR_materials_fuzz {
68
+ constructor(exporter) {
69
+ /** Name of this extension */
70
+ this.name = NAME;
71
+ /** Defines whether this extension is enabled */
72
+ this.enabled = true;
73
+ /** Defines whether this extension is required */
74
+ this.required = false;
75
+ this._wasUsed = false;
76
+ /**
77
+ * Cache that holds temporary merged textures created during export
78
+ */
79
+ this._mergedTexturesMap = {};
80
+ /**
81
+ * Cache that holds internal textures of merged textures created during export
82
+ */
83
+ this._cachedInternalTexturesMap = {};
84
+ this._exporter = exporter;
85
+ }
86
+ dispose() {
87
+ for (const key of Object.keys(this._mergedTexturesMap)) {
88
+ const texture = this._mergedTexturesMap[key];
89
+ texture.dispose();
90
+ }
91
+ this._mergedTexturesMap = {};
92
+ for (const key of Object.keys(this._cachedInternalTexturesMap)) {
93
+ const internalTexture = this._cachedInternalTexturesMap[key];
94
+ internalTexture.dispose();
95
+ }
96
+ this._cachedInternalTexturesMap = {};
97
+ }
98
+ /** @internal */
99
+ get wasUsed() {
100
+ return this._wasUsed;
101
+ }
102
+ async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
103
+ if (babylonMaterial instanceof OpenPBRMaterial) {
104
+ const additionalTextures = [];
105
+ if (babylonMaterial.fuzzWeight > 0.0) {
106
+ if (babylonMaterial.fuzzWeightTexture) {
107
+ additionalTextures.push(babylonMaterial.fuzzWeightTexture);
108
+ }
109
+ let fuzzTexturesNeedMerge = false;
110
+ if (babylonMaterial.fuzzRoughnessTexture) {
111
+ if (babylonMaterial._useFuzzRoughnessFromTextureAlpha) {
112
+ additionalTextures.push(babylonMaterial.fuzzRoughnessTexture);
113
+ }
114
+ else {
115
+ fuzzTexturesNeedMerge = true;
116
+ }
117
+ }
118
+ if (babylonMaterial.fuzzColorTexture && !fuzzTexturesNeedMerge) {
119
+ additionalTextures.push(babylonMaterial.fuzzColorTexture);
120
+ }
121
+ if (fuzzTexturesNeedMerge) {
122
+ const texId = GetFuzzColorTextureId(babylonMaterial);
123
+ if (!this._cachedInternalTexturesMap[texId]) {
124
+ const mergedInternalTexture = await CreateMergedFuzzInternalTexture(babylonMaterial);
125
+ if (mergedInternalTexture) {
126
+ this._cachedInternalTexturesMap[texId] = mergedInternalTexture;
127
+ }
128
+ }
129
+ if (this._cachedInternalTexturesMap[texId]) {
130
+ if (babylonMaterial.fuzzColorTexture) {
131
+ this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId] = CreateTempTexture(this._cachedInternalTexturesMap[texId], babylonMaterial.fuzzColorTexture);
132
+ additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]);
133
+ }
134
+ if (babylonMaterial.fuzzRoughnessTexture) {
135
+ this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId] = CreateTempTexture(this._cachedInternalTexturesMap[texId], babylonMaterial.fuzzRoughnessTexture);
136
+ additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ return additionalTextures;
142
+ }
143
+ return [];
144
+ }
145
+ async postExportMaterialAsync(context, node, babylonMaterial) {
146
+ return await new Promise((resolve) => {
147
+ if (babylonMaterial instanceof OpenPBRMaterial) {
148
+ if (babylonMaterial.fuzzWeight == 0.0) {
149
+ resolve(node);
150
+ return;
151
+ }
152
+ this._wasUsed = true;
153
+ if (node.extensions == null) {
154
+ node.extensions = {};
155
+ }
156
+ const fuzzInfo = {
157
+ fuzzFactor: babylonMaterial.fuzzWeight,
158
+ fuzzColorFactor: babylonMaterial.fuzzColor.asArray(),
159
+ fuzzRoughnessFactor: babylonMaterial.fuzzRoughness,
160
+ };
161
+ if (babylonMaterial.fuzzWeightTexture) {
162
+ fuzzInfo.fuzzTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.fuzzWeightTexture) ?? undefined;
163
+ }
164
+ let fuzzColorTexture = null;
165
+ if (babylonMaterial.fuzzColorTexture) {
166
+ if (this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]) {
167
+ fuzzColorTexture = this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId];
168
+ }
169
+ else {
170
+ fuzzColorTexture = babylonMaterial.fuzzColorTexture;
171
+ }
172
+ fuzzInfo.fuzzColorTexture = this._exporter._materialExporter.getTextureInfo(fuzzColorTexture) ?? undefined;
173
+ }
174
+ let fuzzRoughnessTexture = null;
175
+ if (babylonMaterial.fuzzRoughnessTexture) {
176
+ if (this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]) {
177
+ fuzzRoughnessTexture = this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId];
178
+ }
179
+ else {
180
+ fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;
181
+ }
182
+ fuzzInfo.fuzzRoughnessTexture = this._exporter._materialExporter.getTextureInfo(fuzzRoughnessTexture) ?? undefined;
183
+ }
184
+ if (fuzzInfo.fuzzColorTexture !== null || fuzzInfo.fuzzRoughnessTexture !== null) {
185
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
186
+ }
187
+ node.extensions[NAME] = fuzzInfo;
188
+ }
189
+ resolve(node);
190
+ });
191
+ }
192
+ }
193
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_fuzz(exporter));
194
+ //# sourceMappingURL=KHR_materials_fuzz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KHR_materials_fuzz.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_fuzz.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AACrE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,4DAA8C;AAI7I,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAE1D,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,eAAgC;IAC3D,MAAM,gBAAgB,GAA0B,eAAe,CAAC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I,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsFuzz } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\n\r\nconst NAME = \"KHR_materials_fuzz\";\r\n\r\n/**\r\n * Generate a unique ID for the merged coat textures based on the internal texture data.\r\n * This is used for caching merged textures.\r\n * @param babylonMaterial Source OpenPBR material\r\n * @returns A unique ID string for the merged coat textures\r\n * @internal\r\n */\r\nfunction GetFuzzColorTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const fuzzColorTexture: Nullable<BaseTexture> = babylonMaterial.fuzzColorTexture;\r\n const fuzzColorId = fuzzColorTexture && fuzzColorTexture.getInternalTexture() ? fuzzColorTexture!.getInternalTexture()!.uniqueId : \"NoFuzzColor\";\r\n const fuzzRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.fuzzRoughnessTexture;\r\n const fuzzRoughnessId = fuzzRoughnessTexture && fuzzRoughnessTexture.getInternalTexture() ? fuzzRoughnessTexture!.getInternalTexture()!.uniqueId : \"NoFuzzRoughness\";\r\n return `FuzzColor_${fuzzColorId}_FuzzRoughness_${fuzzRoughnessId}`;\r\n}\r\n\r\n/**\r\n * Using the coat weight and coat roughness textures, create a merged internal texture that can be used\r\n * for multiple textures (with potentially different transforms) on export.\r\n * @param babylonMaterial The source OpenPBR material\r\n * @returns A new, internal texture with the coat weight in the red channel and coat roughness in the green channel\r\n * @internal\r\n */\r\nasync function CreateMergedFuzzInternalTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<InternalTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n const fuzzColorTexture: Nullable<BaseTexture> = babylonMaterial.fuzzColorTexture;\r\n const fuzzRoughnessTexture: Nullable<BaseTexture> = babylonMaterial.fuzzRoughnessTexture;\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(fuzzColorTexture || fuzzRoughnessTexture)) {\r\n return null;\r\n }\r\n\r\n const texture = await MergeTexturesAsync(\r\n \"FuzzTexture\",\r\n CreateRGBAConfiguration(\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 0) : CreateConstantInput(1.0), // fuzz color from red channel\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 1) : CreateConstantInput(1.0), // fuzz color from green channel\r\n fuzzColorTexture ? CreateTextureInput(fuzzColorTexture, 2) : CreateConstantInput(1.0), // fuzz color from blue channel\r\n // fuzz roughness goes in the alpha channel but may come from red or alpha channels in the source\r\n fuzzRoughnessTexture ? CreateTextureInput(fuzzRoughnessTexture, babylonMaterial._useFuzzRoughnessFromTextureAlpha ? 3 : 0) : CreateConstantInput(1.0)\r\n ),\r\n scene\r\n );\r\n\r\n return texture.getInternalTexture();\r\n}\r\n\r\n/**\r\n * Creates a temporary texture based on the source texture.\r\n * @param internalTexture The source internal texture\r\n * @param sourceTexture The source of the new texture's name, and sampler info\r\n * @returns The new texture\r\n */\r\nfunction CreateTempTexture(internalTexture: InternalTexture, sourceTexture: BaseTexture): Texture {\r\n const tempTexture = new Texture(sourceTexture.name, sourceTexture.getScene());\r\n tempTexture._texture = internalTexture;\r\n tempTexture.coordinatesIndex = sourceTexture.coordinatesIndex;\r\n if (sourceTexture instanceof Texture) {\r\n tempTexture.uOffset = sourceTexture.uOffset;\r\n tempTexture.vOffset = sourceTexture.vOffset;\r\n tempTexture.uScale = sourceTexture.uScale;\r\n tempTexture.vScale = sourceTexture.vScale;\r\n tempTexture.wAng = sourceTexture.wAng;\r\n }\r\n tempTexture.wrapU = sourceTexture.wrapU;\r\n tempTexture.wrapV = sourceTexture.wrapV;\r\n return tempTexture;\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_fuzz 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 _wasUsed = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /**\r\n * Cache that holds temporary merged textures created during export\r\n */\r\n private _mergedTexturesMap: Record<string, BaseTexture> = {};\r\n\r\n /**\r\n * Cache that holds internal textures of merged textures created during export\r\n */\r\n private _cachedInternalTexturesMap: Record<string, InternalTexture> = {};\r\n\r\n public dispose() {\r\n for (const key of Object.keys(this._mergedTexturesMap)) {\r\n const texture = this._mergedTexturesMap[key];\r\n texture.dispose();\r\n }\r\n this._mergedTexturesMap = {};\r\n for (const key of Object.keys(this._cachedInternalTexturesMap)) {\r\n const internalTexture = this._cachedInternalTexturesMap[key];\r\n internalTexture.dispose();\r\n }\r\n this._cachedInternalTexturesMap = {};\r\n }\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 if (babylonMaterial instanceof OpenPBRMaterial) {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial.fuzzWeight > 0.0) {\r\n if (babylonMaterial.fuzzWeightTexture) {\r\n additionalTextures.push(babylonMaterial.fuzzWeightTexture);\r\n }\r\n let fuzzTexturesNeedMerge = false;\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n if (babylonMaterial._useFuzzRoughnessFromTextureAlpha) {\r\n additionalTextures.push(babylonMaterial.fuzzRoughnessTexture);\r\n } else {\r\n fuzzTexturesNeedMerge = true;\r\n }\r\n }\r\n if (babylonMaterial.fuzzColorTexture && !fuzzTexturesNeedMerge) {\r\n additionalTextures.push(babylonMaterial.fuzzColorTexture);\r\n }\r\n if (fuzzTexturesNeedMerge) {\r\n const texId = GetFuzzColorTextureId(babylonMaterial);\r\n if (!this._cachedInternalTexturesMap[texId]) {\r\n const mergedInternalTexture = await CreateMergedFuzzInternalTexture(babylonMaterial);\r\n if (mergedInternalTexture) {\r\n this._cachedInternalTexturesMap[texId] = mergedInternalTexture;\r\n }\r\n }\r\n if (this._cachedInternalTexturesMap[texId]) {\r\n if (babylonMaterial.fuzzColorTexture) {\r\n this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.fuzzColorTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]);\r\n }\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId] = CreateTempTexture(\r\n this._cachedInternalTexturesMap[texId],\r\n babylonMaterial.fuzzRoughnessTexture\r\n );\r\n additionalTextures.push(this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]);\r\n }\r\n }\r\n }\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public async postExportMaterialAsync(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return await new Promise((resolve) => {\r\n if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.fuzzWeight == 0.0) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n const fuzzInfo: IKHRMaterialsFuzz = {\r\n fuzzFactor: babylonMaterial.fuzzWeight,\r\n fuzzColorFactor: babylonMaterial.fuzzColor.asArray(),\r\n fuzzRoughnessFactor: babylonMaterial.fuzzRoughness,\r\n };\r\n\r\n if (babylonMaterial.fuzzWeightTexture) {\r\n fuzzInfo.fuzzTexture = this._exporter._materialExporter.getTextureInfo(babylonMaterial.fuzzWeightTexture) ?? undefined;\r\n }\r\n\r\n let fuzzColorTexture: Nullable<BaseTexture> = null;\r\n if (babylonMaterial.fuzzColorTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId]) {\r\n fuzzColorTexture = this._mergedTexturesMap[babylonMaterial.fuzzColorTexture.uniqueId];\r\n } else {\r\n fuzzColorTexture = babylonMaterial.fuzzColorTexture;\r\n }\r\n fuzzInfo.fuzzColorTexture = this._exporter._materialExporter.getTextureInfo(fuzzColorTexture) ?? undefined;\r\n }\r\n\r\n let fuzzRoughnessTexture: Nullable<BaseTexture> = null;\r\n if (babylonMaterial.fuzzRoughnessTexture) {\r\n if (this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId]) {\r\n fuzzRoughnessTexture = this._mergedTexturesMap[babylonMaterial.fuzzRoughnessTexture.uniqueId];\r\n } else {\r\n fuzzRoughnessTexture = babylonMaterial.fuzzRoughnessTexture;\r\n }\r\n fuzzInfo.fuzzRoughnessTexture = this._exporter._materialExporter.getTextureInfo(fuzzRoughnessTexture) ?? undefined;\r\n }\r\n\r\n if (fuzzInfo.fuzzColorTexture !== null || fuzzInfo.fuzzRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = fuzzInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_fuzz(exporter));\r\n"]}
@@ -4,16 +4,14 @@ export * from "./KHR_lights_punctual.js";
4
4
  export * from "./EXT_lights_area.js";
5
5
  export * from "./KHR_materials_anisotropy.js";
6
6
  export * from "./KHR_materials_clearcoat.js";
7
- export * from "./KHR_materials_clearcoat_darkening.js";
8
- export * from "./KHR_materials_clearcoat_ior.js";
9
- export * from "./KHR_materials_clearcoat_color.js";
10
- export * from "./KHR_materials_clearcoat_anisotropy.js";
7
+ export * from "./KHR_materials_coat.js";
11
8
  export * from "./KHR_materials_diffuse_transmission.js";
12
9
  export * from "./KHR_materials_dispersion.js";
13
10
  export * from "./KHR_materials_emissive_strength.js";
14
11
  export * from "./KHR_materials_ior.js";
15
12
  export * from "./KHR_materials_iridescence.js";
16
13
  export * from "./KHR_materials_sheen.js";
14
+ export * from "./KHR_materials_fuzz.js";
17
15
  export * from "./KHR_materials_specular.js";
18
16
  export * from "./KHR_materials_transmission.js";
19
17
  export * from "./KHR_materials_unlit.js";
@@ -4,16 +4,14 @@ export * from "./KHR_lights_punctual.js";
4
4
  export * from "./EXT_lights_area.js";
5
5
  export * from "./KHR_materials_anisotropy.js";
6
6
  export * from "./KHR_materials_clearcoat.js";
7
- export * from "./KHR_materials_clearcoat_darkening.js";
8
- export * from "./KHR_materials_clearcoat_ior.js";
9
- export * from "./KHR_materials_clearcoat_color.js";
10
- export * from "./KHR_materials_clearcoat_anisotropy.js";
7
+ export * from "./KHR_materials_coat.js";
11
8
  export * from "./KHR_materials_diffuse_transmission.js";
12
9
  export * from "./KHR_materials_dispersion.js";
13
10
  export * from "./KHR_materials_emissive_strength.js";
14
11
  export * from "./KHR_materials_ior.js";
15
12
  export * from "./KHR_materials_iridescence.js";
16
13
  export * from "./KHR_materials_sheen.js";
14
+ export * from "./KHR_materials_fuzz.js";
17
15
  export * from "./KHR_materials_specular.js";
18
16
  export * from "./KHR_materials_transmission.js";
19
17
  export * from "./KHR_materials_unlit.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./EXT_lights_area\";\r\nexport * from \"./KHR_materials_anisotropy\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_clearcoat_darkening\";\r\nexport * from \"./KHR_materials_clearcoat_ior\";\r\nexport * from \"./KHR_materials_clearcoat_color\";\r\nexport * from \"./KHR_materials_clearcoat_anisotropy\";\r\nexport * from \"./KHR_materials_diffuse_transmission\";\r\nexport * from \"./KHR_materials_dispersion\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_materials_diffuse_roughness\";\r\nexport * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_texture_basisu\";\r\nexport * from \"./EXT_texture_webp\";\r\nexport * from \"./EXT_texture_avif\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./EXT_lights_area\";\r\nexport * from \"./KHR_materials_anisotropy\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_coat\";\r\nexport * from \"./KHR_materials_diffuse_transmission\";\r\nexport * from \"./KHR_materials_dispersion\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_fuzz\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_materials_diffuse_roughness\";\r\nexport * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_texture_basisu\";\r\nexport * from \"./EXT_texture_webp\";\r\nexport * from \"./EXT_texture_avif\";\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/serializers",
3
- "version": "8.34.0",
3
+ "version": "8.34.1",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,10 +18,10 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@babylonjs/core": "^8.34.0",
21
+ "@babylonjs/core": "^8.34.1",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "^8.34.0"
24
+ "babylonjs-gltf2interface": "^8.34.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^8.0.0",
@@ -1,32 +0,0 @@
1
- import type { IMaterial } from "babylonjs-gltf2interface";
2
- import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
3
- import { GLTFExporter } from "../glTFExporter.js";
4
- import type { Material } from "@babylonjs/core/Materials/material.js";
5
- import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
6
- /**
7
- * @internal
8
- */
9
- export declare class KHR_materials_clearcoat_anisotropy implements IGLTFExporterExtensionV2 {
10
- /** Name of this extension */
11
- readonly name = "KHR_materials_clearcoat_anisotropy";
12
- /** Defines whether this extension is enabled */
13
- enabled: boolean;
14
- /** Defines whether this extension is required */
15
- required: boolean;
16
- private _exporter;
17
- private _wasUsed;
18
- private _anisoTexturesMap;
19
- constructor(exporter: GLTFExporter);
20
- dispose(): void;
21
- /** @internal */
22
- get wasUsed(): boolean;
23
- /**
24
- * After exporting a material, deal with the additional textures
25
- * @param context GLTF context of the material
26
- * @param node exported GLTF node
27
- * @param babylonMaterial corresponding babylon material
28
- * @returns array of additional textures to export
29
- */
30
- postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
31
- postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
32
- }
@@ -1,152 +0,0 @@
1
- import { GLTFExporter } from "../glTFExporter.js";
2
- import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openpbrMaterial.js";
3
- import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@babylonjs/core/Materials/Textures/textureMerger.js";
4
- const NAME = "KHR_materials_clearcoat_anisotropy";
5
- // Convert OpenPBR anisotropy values to glTF-compatible values
6
- function OpenpbrAnisotropyStrengthToGltf(baseRoughness, anisotropy) {
7
- const baseAlpha = baseRoughness * baseRoughness;
8
- const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));
9
- const roughnessB = (1 - anisotropy) * roughnessT;
10
- const newBaseRoughness = Math.sqrt(roughnessB);
11
- const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);
12
- return { newBaseRoughness, newAnisotropyStrength };
13
- }
14
- function GetAnisoTextureId(babylonMaterial) {
15
- const anisoStrengthTexture = babylonMaterial.coatRoughnessAnisotropyTexture;
16
- const tangentTexture = babylonMaterial.geometryCoatTangentTexture;
17
- const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture.getInternalTexture().uniqueId : "NoStrength";
18
- const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture.getInternalTexture().uniqueId : "NoTangent";
19
- return `${strengthId}_${tangentId}`;
20
- }
21
- // In your postExportMaterialAsync method:
22
- async function CreateMergedAnisotropyTexture(babylonMaterial) {
23
- const scene = babylonMaterial.getScene();
24
- const anisoStrengthTexture = babylonMaterial.coatRoughnessAnisotropyTexture;
25
- const tangentTexture = babylonMaterial.geometryCoatTangentTexture;
26
- // If we don't have any textures, we don't need to generate anything.
27
- if (!(anisoStrengthTexture || tangentTexture)) {
28
- return null;
29
- }
30
- return await MergeTexturesAsync("AnisotropyTexture", CreateRGBAConfiguration(tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel
31
- tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel
32
- anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel
33
- ), scene);
34
- }
35
- /**
36
- * @internal
37
- */
38
- // eslint-disable-next-line @typescript-eslint/naming-convention
39
- export class KHR_materials_clearcoat_anisotropy {
40
- constructor(exporter) {
41
- /** Name of this extension */
42
- this.name = NAME;
43
- /** Defines whether this extension is enabled */
44
- this.enabled = true;
45
- /** Defines whether this extension is required */
46
- this.required = false;
47
- this._wasUsed = false;
48
- this._anisoTexturesMap = {};
49
- this._exporter = exporter;
50
- }
51
- dispose() { }
52
- /** @internal */
53
- get wasUsed() {
54
- return this._wasUsed;
55
- }
56
- /**
57
- * After exporting a material, deal with the additional textures
58
- * @param context GLTF context of the material
59
- * @param node exported GLTF node
60
- * @param babylonMaterial corresponding babylon material
61
- * @returns array of additional textures to export
62
- */
63
- async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
64
- const additionalTextures = [];
65
- if (babylonMaterial instanceof OpenPBRMaterial) {
66
- if (babylonMaterial.coatRoughnessAnisotropy > 0) {
67
- const texId = GetAnisoTextureId(babylonMaterial);
68
- if (this._anisoTexturesMap[texId]) {
69
- additionalTextures.push(this._anisoTexturesMap[texId]);
70
- }
71
- else {
72
- const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);
73
- if (anisoTexture) {
74
- additionalTextures.push(anisoTexture);
75
- this._anisoTexturesMap[texId] = anisoTexture;
76
- }
77
- }
78
- return additionalTextures;
79
- }
80
- }
81
- return [];
82
- }
83
- // eslint-disable-next-line no-restricted-syntax
84
- postExportMaterialAsync(context, node, babylonMaterial) {
85
- return new Promise((resolve) => {
86
- var _a;
87
- if (babylonMaterial instanceof OpenPBRMaterial) {
88
- if (babylonMaterial.coatRoughnessAnisotropy > 0) {
89
- // This material must have the clearcoat extension already before
90
- // we can add the clearcoat anisotropy sub-extension
91
- node.extensions = node.extensions || {};
92
- const parentExt = node.extensions ? node.extensions["KHR_materials_clearcoat"] : null;
93
- if (!parentExt) {
94
- return resolve(node);
95
- }
96
- this._wasUsed = true;
97
- // Check if we can convert from OpenPBR anisotropy to glTF anisotropy
98
- // Conversion involves both specular roughness and anisotropic roughness changes so,
99
- // if there are textures for either, we can't reliably convert due to there potentially
100
- // being different mappings between the textures.
101
- const roughnessTexture = babylonMaterial.coatRoughnessTexture;
102
- const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];
103
- // If no textures are being used, we'll always output glTF-style anisotropy.
104
- // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.
105
- if (!roughnessTexture && !mergedAnisoTexture) {
106
- // Convert constants
107
- let newBaseRoughness = babylonMaterial.coatRoughness;
108
- let newAnisotropyStrength = babylonMaterial.coatRoughnessAnisotropy;
109
- if (!babylonMaterial._useGltfStyleAnisotropy) {
110
- const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.coatRoughness, babylonMaterial.coatRoughnessAnisotropy);
111
- newBaseRoughness = newParams.newBaseRoughness;
112
- newAnisotropyStrength = newParams.newAnisotropyStrength;
113
- }
114
- if (node.pbrMetallicRoughness) {
115
- node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;
116
- }
117
- const anisotropyInfo = {
118
- clearcoatAnisotropyStrength: newAnisotropyStrength,
119
- clearcoatAnisotropyRotation: babylonMaterial.geometryCoatTangentAngle + Math.PI * 0.5,
120
- clearcoatAnisotropyTexture: undefined,
121
- };
122
- parentExt.extensions = parentExt.extensions || {};
123
- parentExt.extensions[NAME] = anisotropyInfo;
124
- return resolve(node);
125
- }
126
- const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;
127
- const anisotropyInfo = {
128
- clearcoatAnisotropyStrength: babylonMaterial.coatRoughnessAnisotropy,
129
- clearcoatAnisotropyRotation: babylonMaterial.geometryCoatTangentAngle,
130
- clearcoatAnisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,
131
- extensions: {},
132
- };
133
- if (!babylonMaterial._useGltfStyleAnisotropy) {
134
- anisotropyInfo.extensions["EXT_materials_anisotropy_openpbr"] = {
135
- openPbrAnisotropyEnabled: true,
136
- };
137
- (_a = this._exporter._glTF).extensionsUsed || (_a.extensionsUsed = []);
138
- if (this._exporter._glTF.extensionsUsed.indexOf("EXT_materials_anisotropy_openpbr") === -1) {
139
- this._exporter._glTF.extensionsUsed.push("EXT_materials_anisotropy_openpbr");
140
- }
141
- }
142
- this._exporter._materialNeedsUVsSet.add(babylonMaterial);
143
- parentExt.extensions = parentExt.extensions || {};
144
- parentExt.extensions[NAME] = anisotropyInfo;
145
- }
146
- }
147
- resolve(node);
148
- });
149
- }
150
- }
151
- GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat_anisotropy(exporter), 105);
152
- //# sourceMappingURL=KHR_materials_clearcoat_anisotropy.js.map
@@ -1 +0,0 @@
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,Y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;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,EAAE,GAAG,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 { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport type { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\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 GetAnisoTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.coatRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryCoatTangentTexture;\r\n const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture!.getInternalTexture()!.uniqueId : \"NoStrength\";\r\n const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture!.getInternalTexture()!.uniqueId : \"NoTangent\";\r\n return `${strengthId}_${tangentId}`;\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 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 return await MergeTexturesAsync(\r\n \"AnisotropyTexture\",\r\n CreateRGBAConfiguration(\r\n tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel\r\n tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel\r\n anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel\r\n ),\r\n scene\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 texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._anisoTexturesMap[texId]) {\r\n additionalTextures.push(this._anisoTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._anisoTexturesMap[texId] = anisoTexture;\r\n }\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), 105);\r\n"]}
@@ -1,101 +0,0 @@
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), 105);
101
- //# sourceMappingURL=KHR_materials_clearcoat_color.js.map