@babylonjs/serializers 7.25.2 → 7.26.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,6 @@ import type { _Exporter } from "./glTFExporter";
6
6
  import type { Material } from "@babylonjs/core/Materials/material.js";
7
7
  import type { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
8
8
  import type { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
9
- import "@babylonjs/core/Engines/Extensions/engine.readTexture.js";
10
9
  /**
11
10
  * Utility methods for working with glTF material conversion properties. This class should only be used internally
12
11
  * @internal
@@ -7,7 +7,6 @@ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
7
7
  import { RawTexture } from "@babylonjs/core/Materials/Textures/rawTexture.js";
8
8
  import { Constants } from "@babylonjs/core/Engines/constants.js";
9
9
  import { DumpTools } from "@babylonjs/core/Misc/dumpTools.js";
10
- import "@babylonjs/core/Engines/Extensions/engine.readTexture.js";
11
10
  function getFileExtensionFromMimeType(mimeType) {
12
11
  switch (mimeType) {
13
12
  case "image/jpeg" /* ImageMimeType.JPEG */:
@@ -1 +1 @@
1
- {"version":3,"file":"glTFMaterialExporter.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,6CAA+B;AAEtD,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,UAAU,EAAE,yDAA2C;AAKhE,OAAO,EAAE,SAAS,EAAE,6CAA+B;AACnD,OAAO,EAAE,SAAS,EAAE,0CAA4B;AAOhD,kEAAoD;AAkDpD,SAAS,4BAA4B,CAAC,QAAuB;IACzD,QAAQ,QAAQ,EAAE;QACd;YACI,OAA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,CAAC,SAAS,CACnC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAC1I,CAAC;QACF,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE;YACrB,OAAO,YAAY,CAAC;SACvB;QAED,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC;;AAzkCD;;GAEG;AACqB,yCAAmB,GAAW,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,AAAvC,CAAwC;AAEnF;;GAEG;AACqB,uCAAiB,GAAG,IAAI,AAAP,CAAQ;AAUjD;;GAEG;AACqB,8BAAQ,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import type { ITextureInfo, IMaterial, IMaterialPbrMetallicRoughness, IMaterialOcclusionTextureInfo, ISampler, IMaterialExtension } from \"babylonjs-gltf2interface\";\r\nimport { ImageMimeType, MaterialAlphaMode, TextureMagFilter, TextureMinFilter, TextureWrapMode } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { TextureTools } from \"core/Misc/textureTools\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RawTexture } from \"core/Materials/Textures/rawTexture\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\n\r\nimport type { _Exporter } from \"./glTFExporter\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { DumpTools } from \"core/Misc/dumpTools\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\nimport \"core/Engines/Extensions/engine.readTexture\";\r\n\r\n/**\r\n * Interface for storing specular glossiness factors\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IPBRSpecularGlossiness {\r\n /**\r\n * Represents the linear diffuse factors of the material\r\n */\r\n diffuseColor: Color3;\r\n /**\r\n * Represents the linear specular factors of the material\r\n */\r\n specularColor: Color3;\r\n /**\r\n * Represents the smoothness of the material\r\n */\r\n glossiness: number;\r\n}\r\n\r\n/**\r\n * Interface for storing metallic roughness factors\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IPBRMetallicRoughness {\r\n /**\r\n * Represents the albedo color of the material\r\n */\r\n baseColor: Color3;\r\n /**\r\n * Represents the metalness of the material\r\n */\r\n metallic: Nullable<number>;\r\n /**\r\n * Represents the roughness of the material\r\n */\r\n roughness: Nullable<number>;\r\n /**\r\n * The metallic roughness texture data\r\n */\r\n metallicRoughnessTextureData?: Nullable<ArrayBuffer>;\r\n /**\r\n * The base color texture data\r\n */\r\n baseColorTextureData?: Nullable<ArrayBuffer>;\r\n}\r\n\r\nfunction getFileExtensionFromMimeType(mimeType: ImageMimeType): string {\r\n switch (mimeType) {\r\n case ImageMimeType.JPEG:\r\n return \".jpg\";\r\n case ImageMimeType.PNG:\r\n return \".png\";\r\n case ImageMimeType.WEBP:\r\n return \".webp\";\r\n case ImageMimeType.AVIF:\r\n return \".avif\";\r\n }\r\n}\r\n\r\n/**\r\n * Utility methods for working with glTF material conversion properties. This class should only be used internally\r\n * @internal\r\n */\r\nexport class _GLTFMaterialExporter {\r\n /**\r\n * Represents the dielectric specular values for R, G and B\r\n */\r\n private static readonly _DielectricSpecular: Color3 = new Color3(0.04, 0.04, 0.04);\r\n\r\n /**\r\n * Allows the maximum specular power to be defined for material calculations\r\n */\r\n private static readonly _MaxSpecularPower = 1024;\r\n\r\n /**\r\n * Mapping to store textures\r\n */\r\n private _textureMap: { [textureId: string]: ITextureInfo } = {};\r\n\r\n // Mapping of internal textures to images to avoid exporting duplicate images.\r\n private _internalTextureToImage: { [uniqueId: number]: { [mimeType: string]: Promise<number> } } = {};\r\n\r\n /**\r\n * Numeric tolerance value\r\n */\r\n private static readonly _Epsilon = 1e-6;\r\n\r\n /**\r\n * Reference to the glTF Exporter\r\n */\r\n private _exporter: _Exporter;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._textureMap = {};\r\n this._exporter = exporter;\r\n }\r\n\r\n /**\r\n * Specifies if two colors are approximately equal in value\r\n * @param color1 first color to compare to\r\n * @param color2 second color to compare to\r\n * @param epsilon threshold value\r\n * @returns boolean specifying if the colors are approximately equal in value\r\n */\r\n private static _FuzzyEquals(color1: Color3, color2: Color3, epsilon: number): boolean {\r\n return Scalar.WithinEpsilon(color1.r, color2.r, epsilon) && Scalar.WithinEpsilon(color1.g, color2.g, epsilon) && Scalar.WithinEpsilon(color1.b, color2.b, epsilon);\r\n }\r\n\r\n /**\r\n * Gets the materials from a Babylon scene and converts them to glTF materials\r\n * @param exportMaterials\r\n * @param mimeType texture mime type\r\n * @param hasTextureCoords specifies if texture coordinates are present on the material\r\n * @returns promise that resolves after all materials have been converted\r\n */\r\n public _convertMaterialsToGLTFAsync(exportMaterials: Set<Material>, mimeType: ImageMimeType, hasTextureCoords: boolean) {\r\n const promises: Promise<IMaterial>[] = [];\r\n exportMaterials.forEach((material) => {\r\n if (material.getClassName() === \"StandardMaterial\") {\r\n promises.push(this._convertStandardMaterialAsync(material as StandardMaterial, mimeType, hasTextureCoords));\r\n } else if (material.getClassName().indexOf(\"PBR\") !== -1) {\r\n promises.push(this._convertPBRMaterialAsync(material as PBRMaterial, mimeType, hasTextureCoords));\r\n } else {\r\n Tools.Warn(`Unsupported material type: ${material.name}`);\r\n }\r\n });\r\n\r\n return Promise.all(promises).then(() => {\r\n /* do nothing */\r\n });\r\n }\r\n\r\n /**\r\n * Makes a copy of the glTF material without the texture parameters\r\n * @param originalMaterial original glTF material\r\n * @returns glTF material without texture parameters\r\n */\r\n public _stripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial {\r\n const newMaterial: IMaterial = {};\r\n if (originalMaterial) {\r\n newMaterial.name = originalMaterial.name;\r\n newMaterial.doubleSided = originalMaterial.doubleSided;\r\n newMaterial.alphaMode = originalMaterial.alphaMode;\r\n newMaterial.alphaCutoff = originalMaterial.alphaCutoff;\r\n newMaterial.emissiveFactor = originalMaterial.emissiveFactor;\r\n const originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;\r\n if (originalPBRMetallicRoughness) {\r\n newMaterial.pbrMetallicRoughness = {};\r\n newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;\r\n newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;\r\n newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;\r\n }\r\n }\r\n return newMaterial;\r\n }\r\n\r\n /**\r\n * Specifies if the material has any texture parameters present\r\n * @param material glTF Material\r\n * @returns boolean specifying if texture parameters are present\r\n */\r\n public _hasTexturesPresent(material: IMaterial): boolean {\r\n if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {\r\n return true;\r\n }\r\n const pbrMat = material.pbrMetallicRoughness;\r\n if (pbrMat) {\r\n if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {\r\n return true;\r\n }\r\n }\r\n\r\n if (material.extensions) {\r\n for (const extension in material.extensions) {\r\n const extensionObject = material.extensions[extension];\r\n if (extensionObject as IMaterialExtension) {\r\n return extensionObject.hasTextures?.();\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public _getTextureInfo(babylonTexture: Nullable<BaseTexture>): Nullable<ITextureInfo> {\r\n if (babylonTexture) {\r\n const textureUid = babylonTexture.uid;\r\n if (textureUid in this._textureMap) {\r\n return this._textureMap[textureUid];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material\r\n * @param babylonStandardMaterial\r\n * @returns glTF Metallic Roughness Material representation\r\n */\r\n public _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness {\r\n // Defines a cubic bezier curve where x is specular power and y is roughness\r\n const P0 = new Vector2(0, 1);\r\n const P1 = new Vector2(0, 0.1);\r\n const P2 = new Vector2(0, 0.1);\r\n const P3 = new Vector2(1300, 0.1);\r\n\r\n /**\r\n * Given the control points, solve for x based on a given t for a cubic bezier curve\r\n * @param t a value between 0 and 1\r\n * @param p0 first control point\r\n * @param p1 second control point\r\n * @param p2 third control point\r\n * @param p3 fourth control point\r\n * @returns number result of cubic bezier curve at the specified t\r\n */\r\n function cubicBezierCurve(t: number, p0: number, p1: number, p2: number, p3: number): number {\r\n return (1 - t) * (1 - t) * (1 - t) * p0 + 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t * p3;\r\n }\r\n\r\n /**\r\n * Evaluates a specified specular power value to determine the appropriate roughness value,\r\n * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)\r\n * and roughness on the ordinant axis (y-axis)\r\n * @param specularPower specular power of standard material\r\n * @returns Number representing the roughness value\r\n */\r\n function solveForRoughness(specularPower: number): number {\r\n // Given P0.x = 0, P1.x = 0, P2.x = 0\r\n // x = t * t * t * P3.x\r\n // t = (x / P3.x)^(1/3)\r\n const t = Math.pow(specularPower / P3.x, 0.333333);\r\n return cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);\r\n }\r\n\r\n const diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace(babylonStandardMaterial.getScene().getEngine().useExactSrgbConversions).scale(0.5);\r\n const opacity = babylonStandardMaterial.alpha;\r\n const specularPower = Scalar.Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);\r\n\r\n const roughness = solveForRoughness(specularPower);\r\n\r\n const glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness = {\r\n baseColorFactor: [diffuse.r, diffuse.g, diffuse.b, opacity],\r\n metallicFactor: 0,\r\n roughnessFactor: roughness,\r\n };\r\n\r\n return glTFPbrMetallicRoughness;\r\n }\r\n\r\n /**\r\n * Computes the metallic factor\r\n * @param diffuse diffused value\r\n * @param specular specular value\r\n * @param oneMinusSpecularStrength one minus the specular strength\r\n * @returns metallic value\r\n */\r\n public static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number {\r\n if (specular < this._DielectricSpecular.r) {\r\n this._DielectricSpecular;\r\n return 0;\r\n }\r\n\r\n const a = this._DielectricSpecular.r;\r\n const b = (diffuse * oneMinusSpecularStrength) / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;\r\n const c = this._DielectricSpecular.r - specular;\r\n const D = b * b - 4.0 * a * c;\r\n return Scalar.Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);\r\n }\r\n\r\n /**\r\n * Sets the glTF alpha mode to a glTF material from the Babylon Material\r\n * @param glTFMaterial glTF material\r\n * @param babylonMaterial Babylon material\r\n */\r\n private static _SetAlphaMode(glTFMaterial: IMaterial, babylonMaterial: Material & { alphaCutOff: number }): void {\r\n if (babylonMaterial.needAlphaBlending()) {\r\n glTFMaterial.alphaMode = MaterialAlphaMode.BLEND;\r\n } else if (babylonMaterial.needAlphaTesting()) {\r\n glTFMaterial.alphaMode = MaterialAlphaMode.MASK;\r\n glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;\r\n }\r\n }\r\n\r\n /**\r\n * Converts a Babylon Standard Material to a glTF Material\r\n * @param babylonStandardMaterial BJS Standard Material\r\n * @param mimeType mime type to use for the textures\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns promise, resolved with the material\r\n */\r\n public _convertStandardMaterialAsync(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial> {\r\n const materialMap = this._exporter._materialMap;\r\n const materials = this._exporter._materials;\r\n const promises = [];\r\n const pbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);\r\n\r\n const material: IMaterial = { name: babylonStandardMaterial.name };\r\n if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {\r\n if (!babylonStandardMaterial.twoSidedLighting) {\r\n Tools.Warn(babylonStandardMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\r\n }\r\n material.doubleSided = true;\r\n }\r\n if (hasTextureCoords) {\r\n if (babylonStandardMaterial.diffuseTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n pbrMetallicRoughness.baseColorTexture = textureInfo;\r\n }\r\n })\r\n );\r\n }\r\n const bumpTexture = babylonStandardMaterial.bumpTexture;\r\n if (bumpTexture) {\r\n promises.push(\r\n this._exportTextureAsync(bumpTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n material.normalTexture = textureInfo;\r\n if (bumpTexture.level !== 1) {\r\n material.normalTexture.scale = bumpTexture.level;\r\n }\r\n }\r\n })\r\n );\r\n }\r\n if (babylonStandardMaterial.emissiveTexture) {\r\n material.emissiveFactor = [1.0, 1.0, 1.0];\r\n\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n material.emissiveTexture = textureInfo;\r\n }\r\n })\r\n );\r\n }\r\n if (babylonStandardMaterial.ambientTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n const occlusionTexture: IMaterialOcclusionTextureInfo = {\r\n index: textureInfo.index,\r\n };\r\n material.occlusionTexture = occlusionTexture;\r\n }\r\n })\r\n );\r\n }\r\n }\r\n\r\n if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {\r\n if (babylonStandardMaterial.alphaMode === Constants.ALPHA_COMBINE) {\r\n material.alphaMode = MaterialAlphaMode.BLEND;\r\n } else {\r\n Tools.Warn(babylonStandardMaterial.name + \": glTF 2.0 does not support alpha mode: \" + babylonStandardMaterial.alphaMode.toString());\r\n }\r\n }\r\n if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter._FuzzyEquals(babylonStandardMaterial.emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\r\n material.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();\r\n }\r\n\r\n material.pbrMetallicRoughness = pbrMetallicRoughness;\r\n _GLTFMaterialExporter._SetAlphaMode(material, babylonStandardMaterial);\r\n\r\n materials.push(material);\r\n materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;\r\n\r\n return this._finishMaterial(promises, material, babylonStandardMaterial, mimeType);\r\n }\r\n\r\n private _finishMaterial<T>(promises: Promise<T>[], glTFMaterial: IMaterial, babylonMaterial: Material, mimeType: ImageMimeType) {\r\n return Promise.all(promises).then(() => {\r\n const textures = this._exporter._extensionsPostExportMaterialAdditionalTextures(\"exportMaterial\", glTFMaterial, babylonMaterial);\r\n let tasks: Nullable<Promise<Nullable<ITextureInfo>>[]> = null;\r\n\r\n for (const texture of textures) {\r\n if (!tasks) {\r\n tasks = [];\r\n }\r\n tasks.push(this._exportTextureAsync(texture, mimeType));\r\n }\r\n\r\n if (!tasks) {\r\n tasks = [Promise.resolve(null)];\r\n }\r\n\r\n return Promise.all(tasks).then(() => {\r\n const extensionWork = this._exporter._extensionsPostExportMaterialAsync(\"exportMaterial\", glTFMaterial, babylonMaterial);\r\n if (!extensionWork) {\r\n return glTFMaterial;\r\n }\r\n return extensionWork.then(() => glTFMaterial);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Converts an image typed array buffer to a base64 image\r\n * @param buffer typed array buffer\r\n * @param width width of the image\r\n * @param height height of the image\r\n * @param mimeType mimetype of the image\r\n * @returns base64 image string\r\n */\r\n private async _getImageDataAsync(buffer: Uint8Array | Float32Array, width: number, height: number, mimeType: ImageMimeType): Promise<ArrayBuffer> {\r\n const textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n\r\n const hostingScene = this._exporter._babylonScene;\r\n const engine = hostingScene.getEngine();\r\n\r\n // Create a temporary texture with the texture buffer data\r\n const tempTexture = engine.createRawTexture(buffer, width, height, Constants.TEXTUREFORMAT_RGBA, false, true, Texture.NEAREST_SAMPLINGMODE, null, textureType);\r\n\r\n await TextureTools.ApplyPostProcess(\"pass\", tempTexture, hostingScene, textureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\r\n\r\n const data = await engine._readTexturePixels(tempTexture, width, height);\r\n\r\n return (await DumpTools.DumpDataAsync(width, height, data, mimeType, undefined, true, true)) as ArrayBuffer;\r\n }\r\n\r\n /**\r\n * Generates a white texture based on the specified width and height\r\n * @param width width of the texture in pixels\r\n * @param height height of the texture in pixels\r\n * @param scene babylonjs scene\r\n * @returns white texture\r\n */\r\n private _createWhiteTexture(width: number, height: number, scene: Scene): Texture {\r\n const data = new Uint8Array(width * height * 4);\r\n\r\n for (let i = 0; i < data.length; i = i + 4) {\r\n data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xff;\r\n }\r\n\r\n const rawTexture = RawTexture.CreateRGBATexture(data, width, height, scene);\r\n\r\n return rawTexture;\r\n }\r\n\r\n /**\r\n * Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null\r\n * @param texture1 first texture to resize\r\n * @param texture2 second texture to resize\r\n * @param scene babylonjs scene\r\n * @returns resized textures or null\r\n */\r\n private _resizeTexturesToSameDimensions(texture1: Nullable<BaseTexture>, texture2: Nullable<BaseTexture>, scene: Scene): { texture1: BaseTexture; texture2: BaseTexture } {\r\n const texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };\r\n const texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };\r\n let resizedTexture1: BaseTexture;\r\n let resizedTexture2: BaseTexture;\r\n\r\n if (texture1Size.width < texture2Size.width) {\r\n if (texture1 && texture1 instanceof Texture) {\r\n resizedTexture1 = TextureTools.CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);\r\n } else {\r\n resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);\r\n }\r\n resizedTexture2 = texture2!;\r\n } else if (texture1Size.width > texture2Size.width) {\r\n if (texture2 && texture2 instanceof Texture) {\r\n resizedTexture2 = TextureTools.CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);\r\n } else {\r\n resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);\r\n }\r\n resizedTexture1 = texture1!;\r\n } else {\r\n resizedTexture1 = texture1!;\r\n resizedTexture2 = texture2!;\r\n }\r\n\r\n return {\r\n texture1: resizedTexture1!,\r\n texture2: resizedTexture2!,\r\n };\r\n }\r\n\r\n /**\r\n * Converts an array of pixels to a Float32Array\r\n * Throws an error if the pixel format is not supported\r\n * @param pixels - array buffer containing pixel values\r\n * @returns Float32 of pixels\r\n */\r\n private _convertPixelArrayToFloat32(pixels: ArrayBufferView): Float32Array {\r\n if (pixels instanceof Uint8Array) {\r\n const length = pixels.length;\r\n const buffer = new Float32Array(pixels.length);\r\n for (let i = 0; i < length; ++i) {\r\n buffer[i] = pixels[i] / 255;\r\n }\r\n return buffer;\r\n } else if (pixels instanceof Float32Array) {\r\n return pixels;\r\n } else {\r\n throw new Error(\"Unsupported pixel format!\");\r\n }\r\n }\r\n\r\n /**\r\n * Convert Specular Glossiness Textures to Metallic Roughness\r\n * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness\r\n * @link https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js\r\n * @param diffuseTexture texture used to store diffuse information\r\n * @param specularGlossinessTexture texture used to store specular and glossiness information\r\n * @param factors specular glossiness material factors\r\n * @param mimeType the mime type to use for the texture\r\n * @returns pbr metallic roughness interface or null\r\n */\r\n private async _convertSpecularGlossinessTexturesToMetallicRoughnessAsync(\r\n diffuseTexture: Nullable<BaseTexture>,\r\n specularGlossinessTexture: Nullable<BaseTexture>,\r\n factors: _IPBRSpecularGlossiness,\r\n mimeType: ImageMimeType\r\n ): Promise<_IPBRMetallicRoughness> {\r\n const promises = new Array<Promise<void>>();\r\n if (!(diffuseTexture || specularGlossinessTexture)) {\r\n return Promise.reject(\"_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!\");\r\n }\r\n\r\n const scene: Nullable<Scene> = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;\r\n if (scene) {\r\n const resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);\r\n\r\n const diffuseSize = resizedTextures.texture1?.getSize();\r\n\r\n let diffuseBuffer: Float32Array;\r\n let specularGlossinessBuffer: Float32Array;\r\n\r\n const width = diffuseSize.width;\r\n const height = diffuseSize.height;\r\n\r\n const diffusePixels = await resizedTextures.texture1.readPixels();\r\n const specularPixels = await resizedTextures.texture2.readPixels();\r\n\r\n if (diffusePixels) {\r\n diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);\r\n } else {\r\n return Promise.reject(\"Failed to retrieve pixels from diffuse texture!\");\r\n }\r\n if (specularPixels) {\r\n specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);\r\n } else {\r\n return Promise.reject(\"Failed to retrieve pixels from specular glossiness texture!\");\r\n }\r\n\r\n const byteLength = specularGlossinessBuffer.byteLength;\r\n\r\n const metallicRoughnessBuffer = new Uint8Array(byteLength);\r\n const baseColorBuffer = new Uint8Array(byteLength);\r\n\r\n const strideSize = 4;\r\n const maxBaseColor = Color3.Black();\r\n let maxMetallic = 0;\r\n let maxRoughness = 0;\r\n\r\n for (let h = 0; h < height; ++h) {\r\n for (let w = 0; w < width; ++w) {\r\n const offset = (width * h + w) * strideSize;\r\n\r\n const diffuseColor = new Color3(diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2])\r\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\r\n .multiply(factors.diffuseColor);\r\n const specularColor = new Color3(specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2])\r\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\r\n .multiply(factors.specularColor);\r\n const glossiness = specularGlossinessBuffer[offset + 3] * factors.glossiness;\r\n\r\n const specularGlossiness: _IPBRSpecularGlossiness = {\r\n diffuseColor: diffuseColor,\r\n specularColor: specularColor,\r\n glossiness: glossiness,\r\n };\r\n\r\n const metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);\r\n maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);\r\n maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);\r\n maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);\r\n maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic!);\r\n maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness!);\r\n\r\n baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;\r\n baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;\r\n baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;\r\n baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;\r\n\r\n metallicRoughnessBuffer[offset] = 0;\r\n metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness! * 255;\r\n metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic! * 255;\r\n metallicRoughnessBuffer[offset + 3] = 255;\r\n }\r\n }\r\n\r\n // Retrieves the metallic roughness factors from the maximum texture values.\r\n const metallicRoughnessFactors: _IPBRMetallicRoughness = {\r\n baseColor: maxBaseColor,\r\n metallic: maxMetallic,\r\n roughness: maxRoughness,\r\n };\r\n\r\n let writeOutMetallicRoughnessTexture = false;\r\n let writeOutBaseColorTexture = false;\r\n\r\n for (let h = 0; h < height; ++h) {\r\n for (let w = 0; w < width; ++w) {\r\n const destinationOffset = (width * h + w) * strideSize;\r\n\r\n baseColorBuffer[destinationOffset] /= metallicRoughnessFactors.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.r : 1;\r\n baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.g : 1;\r\n baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.b : 1;\r\n\r\n const linearBaseColorPixel = Color3.FromInts(\r\n baseColorBuffer[destinationOffset],\r\n baseColorBuffer[destinationOffset + 1],\r\n baseColorBuffer[destinationOffset + 2]\r\n );\r\n const sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace(scene.getEngine().useExactSrgbConversions);\r\n baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;\r\n baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;\r\n baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;\r\n\r\n if (!_GLTFMaterialExporter._FuzzyEquals(sRGBBaseColorPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\r\n writeOutBaseColorTexture = true;\r\n }\r\n\r\n metallicRoughnessBuffer[destinationOffset + 1] /=\r\n metallicRoughnessFactors.roughness! > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.roughness! : 1;\r\n metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors.metallic! > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.metallic! : 1;\r\n\r\n const metallicRoughnessPixel = Color3.FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);\r\n\r\n if (!_GLTFMaterialExporter._FuzzyEquals(metallicRoughnessPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\r\n writeOutMetallicRoughnessTexture = true;\r\n }\r\n }\r\n }\r\n\r\n if (writeOutMetallicRoughnessTexture) {\r\n promises.push(\r\n this._getImageDataAsync(metallicRoughnessBuffer, width, height, mimeType).then((data) => {\r\n metallicRoughnessFactors.metallicRoughnessTextureData = data;\r\n })\r\n );\r\n }\r\n if (writeOutBaseColorTexture) {\r\n promises.push(\r\n this._getImageDataAsync(baseColorBuffer, width, height, mimeType).then((data) => {\r\n metallicRoughnessFactors.baseColorTextureData = data;\r\n })\r\n );\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return metallicRoughnessFactors;\r\n });\r\n } else {\r\n return Promise.reject(\"_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!\");\r\n }\r\n }\r\n\r\n /**\r\n * Converts specular glossiness material properties to metallic roughness\r\n * @param specularGlossiness interface with specular glossiness material properties\r\n * @returns interface with metallic roughness material properties\r\n */\r\n private _convertSpecularGlossinessToMetallicRoughness(specularGlossiness: _IPBRSpecularGlossiness): _IPBRMetallicRoughness {\r\n const diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);\r\n const specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);\r\n const oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);\r\n const metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);\r\n const baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(\r\n oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon)\r\n );\r\n const baseColorFromSpecular = specularGlossiness.specularColor\r\n .subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic))\r\n .scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));\r\n let baseColor = Color3.Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);\r\n baseColor = baseColor.clampToRef(0, 1, baseColor);\r\n\r\n const metallicRoughness: _IPBRMetallicRoughness = {\r\n baseColor: baseColor,\r\n metallic: metallic,\r\n roughness: 1 - specularGlossiness.glossiness,\r\n };\r\n\r\n return metallicRoughness;\r\n }\r\n\r\n /**\r\n * Calculates the surface reflectance, independent of lighting conditions\r\n * @param color Color source to calculate brightness from\r\n * @returns number representing the perceived brightness, or zero if color is undefined\r\n */\r\n private _getPerceivedBrightness(color: Color3): number {\r\n if (color) {\r\n return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);\r\n }\r\n return 0;\r\n }\r\n\r\n /**\r\n * Returns the maximum color component value\r\n * @param color\r\n * @returns maximum color component value, or zero if color is null or undefined\r\n */\r\n private _getMaxComponent(color: Color3): number {\r\n if (color) {\r\n return Math.max(color.r, Math.max(color.g, color.b));\r\n }\r\n return 0;\r\n }\r\n\r\n /**\r\n * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors\r\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\r\n * @param mimeType mime type to use for the textures\r\n * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns glTF PBR Metallic Roughness factors\r\n */\r\n private _convertMetalRoughFactorsToMetallicRoughnessAsync(\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n mimeType: ImageMimeType,\r\n glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n hasTextureCoords: boolean\r\n ): Promise<_IPBRMetallicRoughness> {\r\n const promises = [];\r\n const baseColor = babylonPBRMaterial._albedoColor;\r\n const metallic = babylonPBRMaterial._metallic;\r\n const roughness = babylonPBRMaterial._roughness;\r\n const metallicRoughness: _IPBRMetallicRoughness = {\r\n baseColor: baseColor,\r\n metallic: metallic,\r\n roughness: roughness,\r\n };\r\n\r\n if (hasTextureCoords) {\r\n const albedoTexture = babylonPBRMaterial._albedoTexture;\r\n if (albedoTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonPBRMaterial._albedoTexture!, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;\r\n }\r\n })\r\n );\r\n }\r\n const metallicTexture = babylonPBRMaterial._metallicTexture;\r\n if (metallicTexture) {\r\n promises.push(\r\n this._exportTextureAsync(metallicTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;\r\n }\r\n })\r\n );\r\n }\r\n }\r\n return Promise.all(promises).then(() => {\r\n return metallicRoughness;\r\n });\r\n }\r\n\r\n private _getTextureSampler(texture: Nullable<BaseTexture>): ISampler {\r\n const sampler: ISampler = {};\r\n if (!texture || !(texture instanceof Texture)) {\r\n return sampler;\r\n }\r\n\r\n const wrapS = this._getGLTFTextureWrapMode(texture.wrapU);\r\n if (wrapS !== TextureWrapMode.REPEAT) {\r\n sampler.wrapS = wrapS;\r\n }\r\n\r\n const wrapT = this._getGLTFTextureWrapMode(texture.wrapV);\r\n if (wrapT !== TextureWrapMode.REPEAT) {\r\n sampler.wrapT = wrapT;\r\n }\r\n\r\n switch (texture.samplingMode) {\r\n case Texture.LINEAR_LINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_LINEAR_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_LINEAR_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_NEAREST;\r\n break;\r\n }\r\n }\r\n\r\n return sampler;\r\n }\r\n\r\n private _getGLTFTextureWrapMode(wrapMode: number): TextureWrapMode {\r\n switch (wrapMode) {\r\n case Texture.WRAP_ADDRESSMODE: {\r\n return TextureWrapMode.REPEAT;\r\n }\r\n case Texture.CLAMP_ADDRESSMODE: {\r\n return TextureWrapMode.CLAMP_TO_EDGE;\r\n }\r\n case Texture.MIRROR_ADDRESSMODE: {\r\n return TextureWrapMode.MIRRORED_REPEAT;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported Texture Wrap Mode ${wrapMode}!`);\r\n return TextureWrapMode.REPEAT;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors\r\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\r\n * @param mimeType mime type to use for the textures\r\n * @param pbrMetallicRoughness glTF PBR Metallic Roughness interface\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns glTF PBR Metallic Roughness factors\r\n */\r\n private _convertSpecGlossFactorsToMetallicRoughnessAsync(\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n mimeType: ImageMimeType,\r\n pbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n hasTextureCoords: boolean\r\n ): Promise<_IPBRMetallicRoughness> {\r\n return Promise.resolve().then(() => {\r\n const specGloss: _IPBRSpecularGlossiness = {\r\n diffuseColor: babylonPBRMaterial._albedoColor,\r\n specularColor: babylonPBRMaterial._reflectivityColor,\r\n glossiness: babylonPBRMaterial._microSurface,\r\n };\r\n const albedoTexture = babylonPBRMaterial._albedoTexture;\r\n const reflectivityTexture = babylonPBRMaterial._reflectivityTexture;\r\n const useMicrosurfaceFromReflectivityMapAlpha = babylonPBRMaterial._useMicroSurfaceFromReflectivityMapAlpha;\r\n if (reflectivityTexture && !useMicrosurfaceFromReflectivityMapAlpha) {\r\n return Promise.reject(\"_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported\");\r\n }\r\n if ((albedoTexture || reflectivityTexture) && hasTextureCoords) {\r\n const samplerIndex = this._exportTextureSampler(albedoTexture || reflectivityTexture);\r\n return this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(albedoTexture, reflectivityTexture, specGloss, mimeType).then((metallicRoughnessFactors) => {\r\n const textures = this._exporter._textures;\r\n if (metallicRoughnessFactors.baseColorTextureData) {\r\n const imageIndex = this._exportImage(`baseColor${textures.length}`, mimeType, metallicRoughnessFactors.baseColorTextureData);\r\n pbrMetallicRoughness.baseColorTexture = this._exportTextureInfo(imageIndex, samplerIndex, albedoTexture?.coordinatesIndex);\r\n }\r\n if (metallicRoughnessFactors.metallicRoughnessTextureData) {\r\n const imageIndex = this._exportImage(`metallicRoughness${textures.length}`, mimeType, metallicRoughnessFactors.metallicRoughnessTextureData);\r\n pbrMetallicRoughness.metallicRoughnessTexture = this._exportTextureInfo(imageIndex, samplerIndex, reflectivityTexture?.coordinatesIndex);\r\n }\r\n\r\n return metallicRoughnessFactors;\r\n });\r\n } else {\r\n return this._convertSpecularGlossinessToMetallicRoughness(specGloss);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Converts a Babylon PBR Base Material to a glTF Material\r\n * @param babylonPBRMaterial BJS PBR Base Material\r\n * @param mimeType mime type to use for the textures\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns async glTF Material representation\r\n */\r\n public _convertPBRMaterialAsync(babylonPBRMaterial: PBRBaseMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial> {\r\n const glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness = {};\r\n const glTFMaterial: IMaterial = {\r\n name: babylonPBRMaterial.name,\r\n };\r\n const useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();\r\n\r\n if (useMetallicRoughness) {\r\n const albedoColor = babylonPBRMaterial._albedoColor;\r\n const alpha = babylonPBRMaterial.alpha;\r\n if (albedoColor) {\r\n glTFPbrMetallicRoughness.baseColorFactor = [albedoColor.r, albedoColor.g, albedoColor.b, alpha];\r\n }\r\n return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\r\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\r\n });\r\n } else {\r\n return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\r\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\r\n });\r\n }\r\n }\r\n\r\n private _setMetallicRoughnessPbrMaterial(\r\n metallicRoughness: Nullable<_IPBRMetallicRoughness>,\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n glTFMaterial: IMaterial,\r\n glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n mimeType: ImageMimeType,\r\n hasTextureCoords: boolean\r\n ): Promise<IMaterial> {\r\n const materialMap = this._exporter._materialMap;\r\n const materials = this._exporter._materials;\r\n const promises = [];\r\n if (metallicRoughness) {\r\n _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial as PBRMaterial);\r\n if (\r\n !(\r\n _GLTFMaterialExporter._FuzzyEquals(metallicRoughness.baseColor, Color3.White(), _GLTFMaterialExporter._Epsilon) &&\r\n babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon\r\n )\r\n ) {\r\n glTFPbrMetallicRoughness.baseColorFactor = [metallicRoughness.baseColor.r, metallicRoughness.baseColor.g, metallicRoughness.baseColor.b, babylonPBRMaterial.alpha];\r\n }\r\n\r\n if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {\r\n glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;\r\n }\r\n if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {\r\n glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;\r\n }\r\n\r\n if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {\r\n if (!babylonPBRMaterial._twoSidedLighting) {\r\n Tools.Warn(babylonPBRMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\r\n }\r\n glTFMaterial.doubleSided = true;\r\n }\r\n\r\n if (hasTextureCoords) {\r\n const bumpTexture = babylonPBRMaterial._bumpTexture;\r\n if (bumpTexture) {\r\n const promise = this._exportTextureAsync(bumpTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFMaterial.normalTexture = glTFTexture;\r\n if (bumpTexture.level !== 1) {\r\n glTFMaterial.normalTexture.scale = bumpTexture.level;\r\n }\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n const ambientTexture = babylonPBRMaterial._ambientTexture;\r\n if (ambientTexture) {\r\n const promise = this._exportTextureAsync(ambientTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n const occlusionTexture: IMaterialOcclusionTextureInfo = {\r\n index: glTFTexture.index,\r\n texCoord: glTFTexture.texCoord,\r\n extensions: glTFTexture.extensions,\r\n };\r\n\r\n glTFMaterial.occlusionTexture = occlusionTexture;\r\n const ambientTextureStrength = babylonPBRMaterial._ambientTextureStrength;\r\n if (ambientTextureStrength) {\r\n occlusionTexture.strength = ambientTextureStrength;\r\n }\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n const emissiveTexture = babylonPBRMaterial._emissiveTexture;\r\n if (emissiveTexture) {\r\n const promise = this._exportTextureAsync(emissiveTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFMaterial.emissiveTexture = glTFTexture;\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n }\r\n const emissiveColor = babylonPBRMaterial._emissiveColor;\r\n if (!_GLTFMaterialExporter._FuzzyEquals(emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\r\n glTFMaterial.emissiveFactor = emissiveColor.asArray();\r\n }\r\n\r\n glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;\r\n materials.push(glTFMaterial);\r\n materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;\r\n }\r\n\r\n return this._finishMaterial(promises, glTFMaterial, babylonPBRMaterial, mimeType);\r\n }\r\n\r\n private _getPixelsFromTexture(babylonTexture: BaseTexture): Promise<Nullable<Uint8Array | Float32Array>> {\r\n const pixels =\r\n babylonTexture.textureType === Constants.TEXTURETYPE_UNSIGNED_INT\r\n ? (babylonTexture.readPixels() as Promise<Uint8Array>)\r\n : (babylonTexture.readPixels() as Promise<Float32Array>);\r\n return pixels;\r\n }\r\n\r\n /**\r\n * Extracts a texture from a Babylon texture into file data and glTF data\r\n * @param babylonTexture Babylon texture to extract\r\n * @param mimeType Mime Type of the babylonTexture\r\n * @returns glTF texture info, or null if the texture format is not supported\r\n */\r\n public _exportTextureAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>> {\r\n const extensionPromise = this._exporter._extensionsPreExportTextureAsync(\"exporter\", babylonTexture as Texture, mimeType);\r\n if (!extensionPromise) {\r\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\r\n }\r\n\r\n return extensionPromise.then((texture) => {\r\n if (!texture) {\r\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\r\n }\r\n return this._exportTextureInfoAsync(texture, mimeType);\r\n });\r\n }\r\n\r\n public async _exportTextureInfoAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>> {\r\n const textureUid = babylonTexture.uid;\r\n if (!(textureUid in this._textureMap)) {\r\n const pixels = await this._getPixelsFromTexture(babylonTexture);\r\n if (!pixels) {\r\n return null;\r\n }\r\n\r\n const samplerIndex = this._exportTextureSampler(babylonTexture);\r\n\r\n // Preserve texture mime type if defined\r\n const textureMimeType = (babylonTexture as Texture).mimeType;\r\n if (textureMimeType) {\r\n switch (textureMimeType) {\r\n case \"image/jpeg\":\r\n case \"image/png\":\r\n case \"image/webp\":\r\n mimeType = textureMimeType as ImageMimeType;\r\n break;\r\n default:\r\n Tools.Warn(`Unsupported media type: ${textureMimeType}`);\r\n break;\r\n }\r\n }\r\n\r\n const internalTextureToImage = this._internalTextureToImage;\r\n const internalTextureUniqueId = babylonTexture.getInternalTexture()!.uniqueId;\r\n internalTextureToImage[internalTextureUniqueId] ||= {};\r\n let imageIndexPromise = internalTextureToImage[internalTextureUniqueId][mimeType];\r\n if (imageIndexPromise === undefined) {\r\n const size = babylonTexture.getSize();\r\n imageIndexPromise = (async () => {\r\n const data = await this._getImageDataAsync(pixels, size.width, size.height, mimeType);\r\n return this._exportImage(babylonTexture.name, mimeType, data);\r\n })();\r\n internalTextureToImage[internalTextureUniqueId][mimeType] = imageIndexPromise;\r\n }\r\n\r\n const textureInfo = this._exportTextureInfo(await imageIndexPromise, samplerIndex, babylonTexture.coordinatesIndex);\r\n this._textureMap[textureUid] = textureInfo;\r\n this._exporter._extensionsPostExportTextures(\"exporter\", this._textureMap[textureUid], babylonTexture);\r\n }\r\n\r\n return this._textureMap[textureUid];\r\n }\r\n\r\n private _exportImage(name: string, mimeType: ImageMimeType, data: ArrayBuffer): number {\r\n const imageData = this._exporter._imageData;\r\n\r\n const baseName = name.replace(/\\.\\/|\\/|\\.\\\\|\\\\/g, \"_\");\r\n const extension = getFileExtensionFromMimeType(mimeType);\r\n let fileName = baseName + extension;\r\n if (fileName in imageData) {\r\n fileName = `${baseName}_${Tools.RandomId()}${extension}`;\r\n }\r\n\r\n imageData[fileName] = {\r\n data: data,\r\n mimeType: mimeType,\r\n };\r\n\r\n const images = this._exporter._images;\r\n images.push({\r\n name: name,\r\n uri: fileName,\r\n });\r\n\r\n return images.length - 1;\r\n }\r\n\r\n private _exportTextureInfo(imageIndex: number, samplerIndex: number, coordinatesIndex?: number): ITextureInfo {\r\n const textures = this._exporter._textures;\r\n let textureIndex = textures.findIndex((t) => t.sampler == samplerIndex && t.source === imageIndex);\r\n if (textureIndex === -1) {\r\n textureIndex = textures.length;\r\n textures.push({\r\n source: imageIndex,\r\n sampler: samplerIndex,\r\n });\r\n }\r\n\r\n const textureInfo: ITextureInfo = { index: textureIndex };\r\n if (coordinatesIndex) {\r\n textureInfo.texCoord = coordinatesIndex;\r\n }\r\n return textureInfo;\r\n }\r\n\r\n private _exportTextureSampler(texture: Nullable<BaseTexture>): number {\r\n const sampler = this._getTextureSampler(texture);\r\n\r\n // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler\r\n const samplers = this._exporter._samplers;\r\n const samplerIndex = samplers.findIndex(\r\n (s) => s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter && s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT\r\n );\r\n if (samplerIndex !== -1) {\r\n return samplerIndex;\r\n }\r\n\r\n samplers.push(sampler);\r\n return samplers.length - 1;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"glTFMaterialExporter.js","sourceRoot":"","sources":["../../../../../dev/serializers/src/glTF/2.0/glTFMaterialExporter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AACxC,OAAO,EAAE,YAAY,EAAE,6CAA+B;AAEtD,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,UA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MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEjD,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;QAC1C,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,CACnC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAC1I,CAAC;QACF,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE;YACrB,OAAO,YAAY,CAAC;SACvB;QAED,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC;;AAzkCD;;GAEG;AACqB,yCAAmB,GAAW,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,AAAvC,CAAwC;AAEnF;;GAEG;AACqB,uCAAiB,GAAG,IAAI,AAAP,CAAQ;AAUjD;;GAEG;AACqB,8BAAQ,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import type { ITextureInfo, IMaterial, IMaterialPbrMetallicRoughness, IMaterialOcclusionTextureInfo, ISampler, IMaterialExtension } from \"babylonjs-gltf2interface\";\r\nimport { ImageMimeType, MaterialAlphaMode, TextureMagFilter, TextureMinFilter, TextureWrapMode } from \"babylonjs-gltf2interface\";\r\n\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector2 } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { TextureTools } from \"core/Misc/textureTools\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RawTexture } from \"core/Materials/Textures/rawTexture\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\n\r\nimport type { _Exporter } from \"./glTFExporter\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { DumpTools } from \"core/Misc/dumpTools\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { StandardMaterial } from \"core/Materials/standardMaterial\";\r\nimport type { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\n/**\r\n * Interface for storing specular glossiness factors\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IPBRSpecularGlossiness {\r\n /**\r\n * Represents the linear diffuse factors of the material\r\n */\r\n diffuseColor: Color3;\r\n /**\r\n * Represents the linear specular factors of the material\r\n */\r\n specularColor: Color3;\r\n /**\r\n * Represents the smoothness of the material\r\n */\r\n glossiness: number;\r\n}\r\n\r\n/**\r\n * Interface for storing metallic roughness factors\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ninterface _IPBRMetallicRoughness {\r\n /**\r\n * Represents the albedo color of the material\r\n */\r\n baseColor: Color3;\r\n /**\r\n * Represents the metalness of the material\r\n */\r\n metallic: Nullable<number>;\r\n /**\r\n * Represents the roughness of the material\r\n */\r\n roughness: Nullable<number>;\r\n /**\r\n * The metallic roughness texture data\r\n */\r\n metallicRoughnessTextureData?: Nullable<ArrayBuffer>;\r\n /**\r\n * The base color texture data\r\n */\r\n baseColorTextureData?: Nullable<ArrayBuffer>;\r\n}\r\n\r\nfunction getFileExtensionFromMimeType(mimeType: ImageMimeType): string {\r\n switch (mimeType) {\r\n case ImageMimeType.JPEG:\r\n return \".jpg\";\r\n case ImageMimeType.PNG:\r\n return \".png\";\r\n case ImageMimeType.WEBP:\r\n return \".webp\";\r\n case ImageMimeType.AVIF:\r\n return \".avif\";\r\n }\r\n}\r\n\r\n/**\r\n * Utility methods for working with glTF material conversion properties. This class should only be used internally\r\n * @internal\r\n */\r\nexport class _GLTFMaterialExporter {\r\n /**\r\n * Represents the dielectric specular values for R, G and B\r\n */\r\n private static readonly _DielectricSpecular: Color3 = new Color3(0.04, 0.04, 0.04);\r\n\r\n /**\r\n * Allows the maximum specular power to be defined for material calculations\r\n */\r\n private static readonly _MaxSpecularPower = 1024;\r\n\r\n /**\r\n * Mapping to store textures\r\n */\r\n private _textureMap: { [textureId: string]: ITextureInfo } = {};\r\n\r\n // Mapping of internal textures to images to avoid exporting duplicate images.\r\n private _internalTextureToImage: { [uniqueId: number]: { [mimeType: string]: Promise<number> } } = {};\r\n\r\n /**\r\n * Numeric tolerance value\r\n */\r\n private static readonly _Epsilon = 1e-6;\r\n\r\n /**\r\n * Reference to the glTF Exporter\r\n */\r\n private _exporter: _Exporter;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._textureMap = {};\r\n this._exporter = exporter;\r\n }\r\n\r\n /**\r\n * Specifies if two colors are approximately equal in value\r\n * @param color1 first color to compare to\r\n * @param color2 second color to compare to\r\n * @param epsilon threshold value\r\n * @returns boolean specifying if the colors are approximately equal in value\r\n */\r\n private static _FuzzyEquals(color1: Color3, color2: Color3, epsilon: number): boolean {\r\n return Scalar.WithinEpsilon(color1.r, color2.r, epsilon) && Scalar.WithinEpsilon(color1.g, color2.g, epsilon) && Scalar.WithinEpsilon(color1.b, color2.b, epsilon);\r\n }\r\n\r\n /**\r\n * Gets the materials from a Babylon scene and converts them to glTF materials\r\n * @param exportMaterials\r\n * @param mimeType texture mime type\r\n * @param hasTextureCoords specifies if texture coordinates are present on the material\r\n * @returns promise that resolves after all materials have been converted\r\n */\r\n public _convertMaterialsToGLTFAsync(exportMaterials: Set<Material>, mimeType: ImageMimeType, hasTextureCoords: boolean) {\r\n const promises: Promise<IMaterial>[] = [];\r\n exportMaterials.forEach((material) => {\r\n if (material.getClassName() === \"StandardMaterial\") {\r\n promises.push(this._convertStandardMaterialAsync(material as StandardMaterial, mimeType, hasTextureCoords));\r\n } else if (material.getClassName().indexOf(\"PBR\") !== -1) {\r\n promises.push(this._convertPBRMaterialAsync(material as PBRMaterial, mimeType, hasTextureCoords));\r\n } else {\r\n Tools.Warn(`Unsupported material type: ${material.name}`);\r\n }\r\n });\r\n\r\n return Promise.all(promises).then(() => {\r\n /* do nothing */\r\n });\r\n }\r\n\r\n /**\r\n * Makes a copy of the glTF material without the texture parameters\r\n * @param originalMaterial original glTF material\r\n * @returns glTF material without texture parameters\r\n */\r\n public _stripTexturesFromMaterial(originalMaterial: IMaterial): IMaterial {\r\n const newMaterial: IMaterial = {};\r\n if (originalMaterial) {\r\n newMaterial.name = originalMaterial.name;\r\n newMaterial.doubleSided = originalMaterial.doubleSided;\r\n newMaterial.alphaMode = originalMaterial.alphaMode;\r\n newMaterial.alphaCutoff = originalMaterial.alphaCutoff;\r\n newMaterial.emissiveFactor = originalMaterial.emissiveFactor;\r\n const originalPBRMetallicRoughness = originalMaterial.pbrMetallicRoughness;\r\n if (originalPBRMetallicRoughness) {\r\n newMaterial.pbrMetallicRoughness = {};\r\n newMaterial.pbrMetallicRoughness.baseColorFactor = originalPBRMetallicRoughness.baseColorFactor;\r\n newMaterial.pbrMetallicRoughness.metallicFactor = originalPBRMetallicRoughness.metallicFactor;\r\n newMaterial.pbrMetallicRoughness.roughnessFactor = originalPBRMetallicRoughness.roughnessFactor;\r\n }\r\n }\r\n return newMaterial;\r\n }\r\n\r\n /**\r\n * Specifies if the material has any texture parameters present\r\n * @param material glTF Material\r\n * @returns boolean specifying if texture parameters are present\r\n */\r\n public _hasTexturesPresent(material: IMaterial): boolean {\r\n if (material.emissiveTexture || material.normalTexture || material.occlusionTexture) {\r\n return true;\r\n }\r\n const pbrMat = material.pbrMetallicRoughness;\r\n if (pbrMat) {\r\n if (pbrMat.baseColorTexture || pbrMat.metallicRoughnessTexture) {\r\n return true;\r\n }\r\n }\r\n\r\n if (material.extensions) {\r\n for (const extension in material.extensions) {\r\n const extensionObject = material.extensions[extension];\r\n if (extensionObject as IMaterialExtension) {\r\n return extensionObject.hasTextures?.();\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n public _getTextureInfo(babylonTexture: Nullable<BaseTexture>): Nullable<ITextureInfo> {\r\n if (babylonTexture) {\r\n const textureUid = babylonTexture.uid;\r\n if (textureUid in this._textureMap) {\r\n return this._textureMap[textureUid];\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material\r\n * @param babylonStandardMaterial\r\n * @returns glTF Metallic Roughness Material representation\r\n */\r\n public _convertToGLTFPBRMetallicRoughness(babylonStandardMaterial: StandardMaterial): IMaterialPbrMetallicRoughness {\r\n // Defines a cubic bezier curve where x is specular power and y is roughness\r\n const P0 = new Vector2(0, 1);\r\n const P1 = new Vector2(0, 0.1);\r\n const P2 = new Vector2(0, 0.1);\r\n const P3 = new Vector2(1300, 0.1);\r\n\r\n /**\r\n * Given the control points, solve for x based on a given t for a cubic bezier curve\r\n * @param t a value between 0 and 1\r\n * @param p0 first control point\r\n * @param p1 second control point\r\n * @param p2 third control point\r\n * @param p3 fourth control point\r\n * @returns number result of cubic bezier curve at the specified t\r\n */\r\n function cubicBezierCurve(t: number, p0: number, p1: number, p2: number, p3: number): number {\r\n return (1 - t) * (1 - t) * (1 - t) * p0 + 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t * p3;\r\n }\r\n\r\n /**\r\n * Evaluates a specified specular power value to determine the appropriate roughness value,\r\n * based on a pre-defined cubic bezier curve with specular on the abscissa axis (x-axis)\r\n * and roughness on the ordinant axis (y-axis)\r\n * @param specularPower specular power of standard material\r\n * @returns Number representing the roughness value\r\n */\r\n function solveForRoughness(specularPower: number): number {\r\n // Given P0.x = 0, P1.x = 0, P2.x = 0\r\n // x = t * t * t * P3.x\r\n // t = (x / P3.x)^(1/3)\r\n const t = Math.pow(specularPower / P3.x, 0.333333);\r\n return cubicBezierCurve(t, P0.y, P1.y, P2.y, P3.y);\r\n }\r\n\r\n const diffuse = babylonStandardMaterial.diffuseColor.toLinearSpace(babylonStandardMaterial.getScene().getEngine().useExactSrgbConversions).scale(0.5);\r\n const opacity = babylonStandardMaterial.alpha;\r\n const specularPower = Scalar.Clamp(babylonStandardMaterial.specularPower, 0, _GLTFMaterialExporter._MaxSpecularPower);\r\n\r\n const roughness = solveForRoughness(specularPower);\r\n\r\n const glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness = {\r\n baseColorFactor: [diffuse.r, diffuse.g, diffuse.b, opacity],\r\n metallicFactor: 0,\r\n roughnessFactor: roughness,\r\n };\r\n\r\n return glTFPbrMetallicRoughness;\r\n }\r\n\r\n /**\r\n * Computes the metallic factor\r\n * @param diffuse diffused value\r\n * @param specular specular value\r\n * @param oneMinusSpecularStrength one minus the specular strength\r\n * @returns metallic value\r\n */\r\n public static _SolveMetallic(diffuse: number, specular: number, oneMinusSpecularStrength: number): number {\r\n if (specular < this._DielectricSpecular.r) {\r\n this._DielectricSpecular;\r\n return 0;\r\n }\r\n\r\n const a = this._DielectricSpecular.r;\r\n const b = (diffuse * oneMinusSpecularStrength) / (1.0 - this._DielectricSpecular.r) + specular - 2.0 * this._DielectricSpecular.r;\r\n const c = this._DielectricSpecular.r - specular;\r\n const D = b * b - 4.0 * a * c;\r\n return Scalar.Clamp((-b + Math.sqrt(D)) / (2.0 * a), 0, 1);\r\n }\r\n\r\n /**\r\n * Sets the glTF alpha mode to a glTF material from the Babylon Material\r\n * @param glTFMaterial glTF material\r\n * @param babylonMaterial Babylon material\r\n */\r\n private static _SetAlphaMode(glTFMaterial: IMaterial, babylonMaterial: Material & { alphaCutOff: number }): void {\r\n if (babylonMaterial.needAlphaBlending()) {\r\n glTFMaterial.alphaMode = MaterialAlphaMode.BLEND;\r\n } else if (babylonMaterial.needAlphaTesting()) {\r\n glTFMaterial.alphaMode = MaterialAlphaMode.MASK;\r\n glTFMaterial.alphaCutoff = babylonMaterial.alphaCutOff;\r\n }\r\n }\r\n\r\n /**\r\n * Converts a Babylon Standard Material to a glTF Material\r\n * @param babylonStandardMaterial BJS Standard Material\r\n * @param mimeType mime type to use for the textures\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns promise, resolved with the material\r\n */\r\n public _convertStandardMaterialAsync(babylonStandardMaterial: StandardMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial> {\r\n const materialMap = this._exporter._materialMap;\r\n const materials = this._exporter._materials;\r\n const promises = [];\r\n const pbrMetallicRoughness = this._convertToGLTFPBRMetallicRoughness(babylonStandardMaterial);\r\n\r\n const material: IMaterial = { name: babylonStandardMaterial.name };\r\n if (babylonStandardMaterial.backFaceCulling != null && !babylonStandardMaterial.backFaceCulling) {\r\n if (!babylonStandardMaterial.twoSidedLighting) {\r\n Tools.Warn(babylonStandardMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\r\n }\r\n material.doubleSided = true;\r\n }\r\n if (hasTextureCoords) {\r\n if (babylonStandardMaterial.diffuseTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.diffuseTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n pbrMetallicRoughness.baseColorTexture = textureInfo;\r\n }\r\n })\r\n );\r\n }\r\n const bumpTexture = babylonStandardMaterial.bumpTexture;\r\n if (bumpTexture) {\r\n promises.push(\r\n this._exportTextureAsync(bumpTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n material.normalTexture = textureInfo;\r\n if (bumpTexture.level !== 1) {\r\n material.normalTexture.scale = bumpTexture.level;\r\n }\r\n }\r\n })\r\n );\r\n }\r\n if (babylonStandardMaterial.emissiveTexture) {\r\n material.emissiveFactor = [1.0, 1.0, 1.0];\r\n\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.emissiveTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n material.emissiveTexture = textureInfo;\r\n }\r\n })\r\n );\r\n }\r\n if (babylonStandardMaterial.ambientTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonStandardMaterial.ambientTexture, mimeType).then((textureInfo) => {\r\n if (textureInfo) {\r\n const occlusionTexture: IMaterialOcclusionTextureInfo = {\r\n index: textureInfo.index,\r\n };\r\n material.occlusionTexture = occlusionTexture;\r\n }\r\n })\r\n );\r\n }\r\n }\r\n\r\n if (babylonStandardMaterial.alpha < 1.0 || babylonStandardMaterial.opacityTexture) {\r\n if (babylonStandardMaterial.alphaMode === Constants.ALPHA_COMBINE) {\r\n material.alphaMode = MaterialAlphaMode.BLEND;\r\n } else {\r\n Tools.Warn(babylonStandardMaterial.name + \": glTF 2.0 does not support alpha mode: \" + babylonStandardMaterial.alphaMode.toString());\r\n }\r\n }\r\n if (babylonStandardMaterial.emissiveColor && !_GLTFMaterialExporter._FuzzyEquals(babylonStandardMaterial.emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\r\n material.emissiveFactor = babylonStandardMaterial.emissiveColor.asArray();\r\n }\r\n\r\n material.pbrMetallicRoughness = pbrMetallicRoughness;\r\n _GLTFMaterialExporter._SetAlphaMode(material, babylonStandardMaterial);\r\n\r\n materials.push(material);\r\n materialMap[babylonStandardMaterial.uniqueId] = materials.length - 1;\r\n\r\n return this._finishMaterial(promises, material, babylonStandardMaterial, mimeType);\r\n }\r\n\r\n private _finishMaterial<T>(promises: Promise<T>[], glTFMaterial: IMaterial, babylonMaterial: Material, mimeType: ImageMimeType) {\r\n return Promise.all(promises).then(() => {\r\n const textures = this._exporter._extensionsPostExportMaterialAdditionalTextures(\"exportMaterial\", glTFMaterial, babylonMaterial);\r\n let tasks: Nullable<Promise<Nullable<ITextureInfo>>[]> = null;\r\n\r\n for (const texture of textures) {\r\n if (!tasks) {\r\n tasks = [];\r\n }\r\n tasks.push(this._exportTextureAsync(texture, mimeType));\r\n }\r\n\r\n if (!tasks) {\r\n tasks = [Promise.resolve(null)];\r\n }\r\n\r\n return Promise.all(tasks).then(() => {\r\n const extensionWork = this._exporter._extensionsPostExportMaterialAsync(\"exportMaterial\", glTFMaterial, babylonMaterial);\r\n if (!extensionWork) {\r\n return glTFMaterial;\r\n }\r\n return extensionWork.then(() => glTFMaterial);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Converts an image typed array buffer to a base64 image\r\n * @param buffer typed array buffer\r\n * @param width width of the image\r\n * @param height height of the image\r\n * @param mimeType mimetype of the image\r\n * @returns base64 image string\r\n */\r\n private async _getImageDataAsync(buffer: Uint8Array | Float32Array, width: number, height: number, mimeType: ImageMimeType): Promise<ArrayBuffer> {\r\n const textureType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n\r\n const hostingScene = this._exporter._babylonScene;\r\n const engine = hostingScene.getEngine();\r\n\r\n // Create a temporary texture with the texture buffer data\r\n const tempTexture = engine.createRawTexture(buffer, width, height, Constants.TEXTUREFORMAT_RGBA, false, true, Texture.NEAREST_SAMPLINGMODE, null, textureType);\r\n\r\n await TextureTools.ApplyPostProcess(\"pass\", tempTexture, hostingScene, textureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\r\n\r\n const data = await engine._readTexturePixels(tempTexture, width, height);\r\n\r\n return (await DumpTools.DumpDataAsync(width, height, data, mimeType, undefined, true, true)) as ArrayBuffer;\r\n }\r\n\r\n /**\r\n * Generates a white texture based on the specified width and height\r\n * @param width width of the texture in pixels\r\n * @param height height of the texture in pixels\r\n * @param scene babylonjs scene\r\n * @returns white texture\r\n */\r\n private _createWhiteTexture(width: number, height: number, scene: Scene): Texture {\r\n const data = new Uint8Array(width * height * 4);\r\n\r\n for (let i = 0; i < data.length; i = i + 4) {\r\n data[i] = data[i + 1] = data[i + 2] = data[i + 3] = 0xff;\r\n }\r\n\r\n const rawTexture = RawTexture.CreateRGBATexture(data, width, height, scene);\r\n\r\n return rawTexture;\r\n }\r\n\r\n /**\r\n * Resizes the two source textures to the same dimensions. If a texture is null, a default white texture is generated. If both textures are null, returns null\r\n * @param texture1 first texture to resize\r\n * @param texture2 second texture to resize\r\n * @param scene babylonjs scene\r\n * @returns resized textures or null\r\n */\r\n private _resizeTexturesToSameDimensions(texture1: Nullable<BaseTexture>, texture2: Nullable<BaseTexture>, scene: Scene): { texture1: BaseTexture; texture2: BaseTexture } {\r\n const texture1Size = texture1 ? texture1.getSize() : { width: 0, height: 0 };\r\n const texture2Size = texture2 ? texture2.getSize() : { width: 0, height: 0 };\r\n let resizedTexture1: BaseTexture;\r\n let resizedTexture2: BaseTexture;\r\n\r\n if (texture1Size.width < texture2Size.width) {\r\n if (texture1 && texture1 instanceof Texture) {\r\n resizedTexture1 = TextureTools.CreateResizedCopy(texture1, texture2Size.width, texture2Size.height, true);\r\n } else {\r\n resizedTexture1 = this._createWhiteTexture(texture2Size.width, texture2Size.height, scene);\r\n }\r\n resizedTexture2 = texture2!;\r\n } else if (texture1Size.width > texture2Size.width) {\r\n if (texture2 && texture2 instanceof Texture) {\r\n resizedTexture2 = TextureTools.CreateResizedCopy(texture2, texture1Size.width, texture1Size.height, true);\r\n } else {\r\n resizedTexture2 = this._createWhiteTexture(texture1Size.width, texture1Size.height, scene);\r\n }\r\n resizedTexture1 = texture1!;\r\n } else {\r\n resizedTexture1 = texture1!;\r\n resizedTexture2 = texture2!;\r\n }\r\n\r\n return {\r\n texture1: resizedTexture1!,\r\n texture2: resizedTexture2!,\r\n };\r\n }\r\n\r\n /**\r\n * Converts an array of pixels to a Float32Array\r\n * Throws an error if the pixel format is not supported\r\n * @param pixels - array buffer containing pixel values\r\n * @returns Float32 of pixels\r\n */\r\n private _convertPixelArrayToFloat32(pixels: ArrayBufferView): Float32Array {\r\n if (pixels instanceof Uint8Array) {\r\n const length = pixels.length;\r\n const buffer = new Float32Array(pixels.length);\r\n for (let i = 0; i < length; ++i) {\r\n buffer[i] = pixels[i] / 255;\r\n }\r\n return buffer;\r\n } else if (pixels instanceof Float32Array) {\r\n return pixels;\r\n } else {\r\n throw new Error(\"Unsupported pixel format!\");\r\n }\r\n }\r\n\r\n /**\r\n * Convert Specular Glossiness Textures to Metallic Roughness\r\n * See link below for info on the material conversions from PBR Metallic/Roughness and Specular/Glossiness\r\n * @link https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/examples/convert-between-workflows-bjs/js/babylon.pbrUtilities.js\r\n * @param diffuseTexture texture used to store diffuse information\r\n * @param specularGlossinessTexture texture used to store specular and glossiness information\r\n * @param factors specular glossiness material factors\r\n * @param mimeType the mime type to use for the texture\r\n * @returns pbr metallic roughness interface or null\r\n */\r\n private async _convertSpecularGlossinessTexturesToMetallicRoughnessAsync(\r\n diffuseTexture: Nullable<BaseTexture>,\r\n specularGlossinessTexture: Nullable<BaseTexture>,\r\n factors: _IPBRSpecularGlossiness,\r\n mimeType: ImageMimeType\r\n ): Promise<_IPBRMetallicRoughness> {\r\n const promises = new Array<Promise<void>>();\r\n if (!(diffuseTexture || specularGlossinessTexture)) {\r\n return Promise.reject(\"_ConvertSpecularGlosinessTexturesToMetallicRoughness: diffuse and specular glossiness textures are not defined!\");\r\n }\r\n\r\n const scene: Nullable<Scene> = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture ? specularGlossinessTexture.getScene() : null;\r\n if (scene) {\r\n const resizedTextures = this._resizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);\r\n\r\n const diffuseSize = resizedTextures.texture1?.getSize();\r\n\r\n let diffuseBuffer: Float32Array;\r\n let specularGlossinessBuffer: Float32Array;\r\n\r\n const width = diffuseSize.width;\r\n const height = diffuseSize.height;\r\n\r\n const diffusePixels = await resizedTextures.texture1.readPixels();\r\n const specularPixels = await resizedTextures.texture2.readPixels();\r\n\r\n if (diffusePixels) {\r\n diffuseBuffer = this._convertPixelArrayToFloat32(diffusePixels);\r\n } else {\r\n return Promise.reject(\"Failed to retrieve pixels from diffuse texture!\");\r\n }\r\n if (specularPixels) {\r\n specularGlossinessBuffer = this._convertPixelArrayToFloat32(specularPixels);\r\n } else {\r\n return Promise.reject(\"Failed to retrieve pixels from specular glossiness texture!\");\r\n }\r\n\r\n const byteLength = specularGlossinessBuffer.byteLength;\r\n\r\n const metallicRoughnessBuffer = new Uint8Array(byteLength);\r\n const baseColorBuffer = new Uint8Array(byteLength);\r\n\r\n const strideSize = 4;\r\n const maxBaseColor = Color3.Black();\r\n let maxMetallic = 0;\r\n let maxRoughness = 0;\r\n\r\n for (let h = 0; h < height; ++h) {\r\n for (let w = 0; w < width; ++w) {\r\n const offset = (width * h + w) * strideSize;\r\n\r\n const diffuseColor = new Color3(diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2])\r\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\r\n .multiply(factors.diffuseColor);\r\n const specularColor = new Color3(specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2])\r\n .toLinearSpace(scene.getEngine().useExactSrgbConversions)\r\n .multiply(factors.specularColor);\r\n const glossiness = specularGlossinessBuffer[offset + 3] * factors.glossiness;\r\n\r\n const specularGlossiness: _IPBRSpecularGlossiness = {\r\n diffuseColor: diffuseColor,\r\n specularColor: specularColor,\r\n glossiness: glossiness,\r\n };\r\n\r\n const metallicRoughness = this._convertSpecularGlossinessToMetallicRoughness(specularGlossiness);\r\n maxBaseColor.r = Math.max(maxBaseColor.r, metallicRoughness.baseColor.r);\r\n maxBaseColor.g = Math.max(maxBaseColor.g, metallicRoughness.baseColor.g);\r\n maxBaseColor.b = Math.max(maxBaseColor.b, metallicRoughness.baseColor.b);\r\n maxMetallic = Math.max(maxMetallic, metallicRoughness.metallic!);\r\n maxRoughness = Math.max(maxRoughness, metallicRoughness.roughness!);\r\n\r\n baseColorBuffer[offset] = metallicRoughness.baseColor.r * 255;\r\n baseColorBuffer[offset + 1] = metallicRoughness.baseColor.g * 255;\r\n baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;\r\n baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] * 255 : 255;\r\n\r\n metallicRoughnessBuffer[offset] = 0;\r\n metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness! * 255;\r\n metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic! * 255;\r\n metallicRoughnessBuffer[offset + 3] = 255;\r\n }\r\n }\r\n\r\n // Retrieves the metallic roughness factors from the maximum texture values.\r\n const metallicRoughnessFactors: _IPBRMetallicRoughness = {\r\n baseColor: maxBaseColor,\r\n metallic: maxMetallic,\r\n roughness: maxRoughness,\r\n };\r\n\r\n let writeOutMetallicRoughnessTexture = false;\r\n let writeOutBaseColorTexture = false;\r\n\r\n for (let h = 0; h < height; ++h) {\r\n for (let w = 0; w < width; ++w) {\r\n const destinationOffset = (width * h + w) * strideSize;\r\n\r\n baseColorBuffer[destinationOffset] /= metallicRoughnessFactors.baseColor.r > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.r : 1;\r\n baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors.baseColor.g > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.g : 1;\r\n baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors.baseColor.b > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.baseColor.b : 1;\r\n\r\n const linearBaseColorPixel = Color3.FromInts(\r\n baseColorBuffer[destinationOffset],\r\n baseColorBuffer[destinationOffset + 1],\r\n baseColorBuffer[destinationOffset + 2]\r\n );\r\n const sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace(scene.getEngine().useExactSrgbConversions);\r\n baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;\r\n baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;\r\n baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;\r\n\r\n if (!_GLTFMaterialExporter._FuzzyEquals(sRGBBaseColorPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\r\n writeOutBaseColorTexture = true;\r\n }\r\n\r\n metallicRoughnessBuffer[destinationOffset + 1] /=\r\n metallicRoughnessFactors.roughness! > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.roughness! : 1;\r\n metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors.metallic! > _GLTFMaterialExporter._Epsilon ? metallicRoughnessFactors.metallic! : 1;\r\n\r\n const metallicRoughnessPixel = Color3.FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);\r\n\r\n if (!_GLTFMaterialExporter._FuzzyEquals(metallicRoughnessPixel, Color3.White(), _GLTFMaterialExporter._Epsilon)) {\r\n writeOutMetallicRoughnessTexture = true;\r\n }\r\n }\r\n }\r\n\r\n if (writeOutMetallicRoughnessTexture) {\r\n promises.push(\r\n this._getImageDataAsync(metallicRoughnessBuffer, width, height, mimeType).then((data) => {\r\n metallicRoughnessFactors.metallicRoughnessTextureData = data;\r\n })\r\n );\r\n }\r\n if (writeOutBaseColorTexture) {\r\n promises.push(\r\n this._getImageDataAsync(baseColorBuffer, width, height, mimeType).then((data) => {\r\n metallicRoughnessFactors.baseColorTextureData = data;\r\n })\r\n );\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return metallicRoughnessFactors;\r\n });\r\n } else {\r\n return Promise.reject(\"_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!\");\r\n }\r\n }\r\n\r\n /**\r\n * Converts specular glossiness material properties to metallic roughness\r\n * @param specularGlossiness interface with specular glossiness material properties\r\n * @returns interface with metallic roughness material properties\r\n */\r\n private _convertSpecularGlossinessToMetallicRoughness(specularGlossiness: _IPBRSpecularGlossiness): _IPBRMetallicRoughness {\r\n const diffusePerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.diffuseColor);\r\n const specularPerceivedBrightness = this._getPerceivedBrightness(specularGlossiness.specularColor);\r\n const oneMinusSpecularStrength = 1 - this._getMaxComponent(specularGlossiness.specularColor);\r\n const metallic = _GLTFMaterialExporter._SolveMetallic(diffusePerceivedBrightness, specularPerceivedBrightness, oneMinusSpecularStrength);\r\n const baseColorFromDiffuse = specularGlossiness.diffuseColor.scale(\r\n oneMinusSpecularStrength / (1.0 - _GLTFMaterialExporter._DielectricSpecular.r) / Math.max(1 - metallic, _GLTFMaterialExporter._Epsilon)\r\n );\r\n const baseColorFromSpecular = specularGlossiness.specularColor\r\n .subtract(_GLTFMaterialExporter._DielectricSpecular.scale(1 - metallic))\r\n .scale(1 / Math.max(metallic, _GLTFMaterialExporter._Epsilon));\r\n let baseColor = Color3.Lerp(baseColorFromDiffuse, baseColorFromSpecular, metallic * metallic);\r\n baseColor = baseColor.clampToRef(0, 1, baseColor);\r\n\r\n const metallicRoughness: _IPBRMetallicRoughness = {\r\n baseColor: baseColor,\r\n metallic: metallic,\r\n roughness: 1 - specularGlossiness.glossiness,\r\n };\r\n\r\n return metallicRoughness;\r\n }\r\n\r\n /**\r\n * Calculates the surface reflectance, independent of lighting conditions\r\n * @param color Color source to calculate brightness from\r\n * @returns number representing the perceived brightness, or zero if color is undefined\r\n */\r\n private _getPerceivedBrightness(color: Color3): number {\r\n if (color) {\r\n return Math.sqrt(0.299 * color.r * color.r + 0.587 * color.g * color.g + 0.114 * color.b * color.b);\r\n }\r\n return 0;\r\n }\r\n\r\n /**\r\n * Returns the maximum color component value\r\n * @param color\r\n * @returns maximum color component value, or zero if color is null or undefined\r\n */\r\n private _getMaxComponent(color: Color3): number {\r\n if (color) {\r\n return Math.max(color.r, Math.max(color.g, color.b));\r\n }\r\n return 0;\r\n }\r\n\r\n /**\r\n * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors\r\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\r\n * @param mimeType mime type to use for the textures\r\n * @param glTFPbrMetallicRoughness glTF PBR Metallic Roughness interface\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns glTF PBR Metallic Roughness factors\r\n */\r\n private _convertMetalRoughFactorsToMetallicRoughnessAsync(\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n mimeType: ImageMimeType,\r\n glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n hasTextureCoords: boolean\r\n ): Promise<_IPBRMetallicRoughness> {\r\n const promises = [];\r\n const baseColor = babylonPBRMaterial._albedoColor;\r\n const metallic = babylonPBRMaterial._metallic;\r\n const roughness = babylonPBRMaterial._roughness;\r\n const metallicRoughness: _IPBRMetallicRoughness = {\r\n baseColor: baseColor,\r\n metallic: metallic,\r\n roughness: roughness,\r\n };\r\n\r\n if (hasTextureCoords) {\r\n const albedoTexture = babylonPBRMaterial._albedoTexture;\r\n if (albedoTexture) {\r\n promises.push(\r\n this._exportTextureAsync(babylonPBRMaterial._albedoTexture!, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;\r\n }\r\n })\r\n );\r\n }\r\n const metallicTexture = babylonPBRMaterial._metallicTexture;\r\n if (metallicTexture) {\r\n promises.push(\r\n this._exportTextureAsync(metallicTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;\r\n }\r\n })\r\n );\r\n }\r\n }\r\n return Promise.all(promises).then(() => {\r\n return metallicRoughness;\r\n });\r\n }\r\n\r\n private _getTextureSampler(texture: Nullable<BaseTexture>): ISampler {\r\n const sampler: ISampler = {};\r\n if (!texture || !(texture instanceof Texture)) {\r\n return sampler;\r\n }\r\n\r\n const wrapS = this._getGLTFTextureWrapMode(texture.wrapU);\r\n if (wrapS !== TextureWrapMode.REPEAT) {\r\n sampler.wrapS = wrapS;\r\n }\r\n\r\n const wrapT = this._getGLTFTextureWrapMode(texture.wrapV);\r\n if (wrapT !== TextureWrapMode.REPEAT) {\r\n sampler.wrapT = wrapT;\r\n }\r\n\r\n switch (texture.samplingMode) {\r\n case Texture.LINEAR_LINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_LINEAR_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.LINEAR_NEAREST_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_LINEAR_MIPLINEAR: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_LINEAR;\r\n break;\r\n }\r\n case Texture.LINEAR_LINEAR_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.LINEAR;\r\n sampler.minFilter = TextureMinFilter.LINEAR_MIPMAP_NEAREST;\r\n break;\r\n }\r\n case Texture.NEAREST_NEAREST_MIPNEAREST: {\r\n sampler.magFilter = TextureMagFilter.NEAREST;\r\n sampler.minFilter = TextureMinFilter.NEAREST_MIPMAP_NEAREST;\r\n break;\r\n }\r\n }\r\n\r\n return sampler;\r\n }\r\n\r\n private _getGLTFTextureWrapMode(wrapMode: number): TextureWrapMode {\r\n switch (wrapMode) {\r\n case Texture.WRAP_ADDRESSMODE: {\r\n return TextureWrapMode.REPEAT;\r\n }\r\n case Texture.CLAMP_ADDRESSMODE: {\r\n return TextureWrapMode.CLAMP_TO_EDGE;\r\n }\r\n case Texture.MIRROR_ADDRESSMODE: {\r\n return TextureWrapMode.MIRRORED_REPEAT;\r\n }\r\n default: {\r\n Tools.Error(`Unsupported Texture Wrap Mode ${wrapMode}!`);\r\n return TextureWrapMode.REPEAT;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors\r\n * @param babylonPBRMaterial BJS PBR Metallic Roughness Material\r\n * @param mimeType mime type to use for the textures\r\n * @param pbrMetallicRoughness glTF PBR Metallic Roughness interface\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns glTF PBR Metallic Roughness factors\r\n */\r\n private _convertSpecGlossFactorsToMetallicRoughnessAsync(\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n mimeType: ImageMimeType,\r\n pbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n hasTextureCoords: boolean\r\n ): Promise<_IPBRMetallicRoughness> {\r\n return Promise.resolve().then(() => {\r\n const specGloss: _IPBRSpecularGlossiness = {\r\n diffuseColor: babylonPBRMaterial._albedoColor,\r\n specularColor: babylonPBRMaterial._reflectivityColor,\r\n glossiness: babylonPBRMaterial._microSurface,\r\n };\r\n const albedoTexture = babylonPBRMaterial._albedoTexture;\r\n const reflectivityTexture = babylonPBRMaterial._reflectivityTexture;\r\n const useMicrosurfaceFromReflectivityMapAlpha = babylonPBRMaterial._useMicroSurfaceFromReflectivityMapAlpha;\r\n if (reflectivityTexture && !useMicrosurfaceFromReflectivityMapAlpha) {\r\n return Promise.reject(\"_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture are currently not supported\");\r\n }\r\n if ((albedoTexture || reflectivityTexture) && hasTextureCoords) {\r\n const samplerIndex = this._exportTextureSampler(albedoTexture || reflectivityTexture);\r\n return this._convertSpecularGlossinessTexturesToMetallicRoughnessAsync(albedoTexture, reflectivityTexture, specGloss, mimeType).then((metallicRoughnessFactors) => {\r\n const textures = this._exporter._textures;\r\n if (metallicRoughnessFactors.baseColorTextureData) {\r\n const imageIndex = this._exportImage(`baseColor${textures.length}`, mimeType, metallicRoughnessFactors.baseColorTextureData);\r\n pbrMetallicRoughness.baseColorTexture = this._exportTextureInfo(imageIndex, samplerIndex, albedoTexture?.coordinatesIndex);\r\n }\r\n if (metallicRoughnessFactors.metallicRoughnessTextureData) {\r\n const imageIndex = this._exportImage(`metallicRoughness${textures.length}`, mimeType, metallicRoughnessFactors.metallicRoughnessTextureData);\r\n pbrMetallicRoughness.metallicRoughnessTexture = this._exportTextureInfo(imageIndex, samplerIndex, reflectivityTexture?.coordinatesIndex);\r\n }\r\n\r\n return metallicRoughnessFactors;\r\n });\r\n } else {\r\n return this._convertSpecularGlossinessToMetallicRoughness(specGloss);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Converts a Babylon PBR Base Material to a glTF Material\r\n * @param babylonPBRMaterial BJS PBR Base Material\r\n * @param mimeType mime type to use for the textures\r\n * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied\r\n * @returns async glTF Material representation\r\n */\r\n public _convertPBRMaterialAsync(babylonPBRMaterial: PBRBaseMaterial, mimeType: ImageMimeType, hasTextureCoords: boolean): Promise<IMaterial> {\r\n const glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness = {};\r\n const glTFMaterial: IMaterial = {\r\n name: babylonPBRMaterial.name,\r\n };\r\n const useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();\r\n\r\n if (useMetallicRoughness) {\r\n const albedoColor = babylonPBRMaterial._albedoColor;\r\n const alpha = babylonPBRMaterial.alpha;\r\n if (albedoColor) {\r\n glTFPbrMetallicRoughness.baseColorFactor = [albedoColor.r, albedoColor.g, albedoColor.b, alpha];\r\n }\r\n return this._convertMetalRoughFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\r\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\r\n });\r\n } else {\r\n return this._convertSpecGlossFactorsToMetallicRoughnessAsync(babylonPBRMaterial, mimeType, glTFPbrMetallicRoughness, hasTextureCoords).then((metallicRoughness) => {\r\n return this._setMetallicRoughnessPbrMaterial(metallicRoughness, babylonPBRMaterial, glTFMaterial, glTFPbrMetallicRoughness, mimeType, hasTextureCoords);\r\n });\r\n }\r\n }\r\n\r\n private _setMetallicRoughnessPbrMaterial(\r\n metallicRoughness: Nullable<_IPBRMetallicRoughness>,\r\n babylonPBRMaterial: PBRBaseMaterial,\r\n glTFMaterial: IMaterial,\r\n glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness,\r\n mimeType: ImageMimeType,\r\n hasTextureCoords: boolean\r\n ): Promise<IMaterial> {\r\n const materialMap = this._exporter._materialMap;\r\n const materials = this._exporter._materials;\r\n const promises = [];\r\n if (metallicRoughness) {\r\n _GLTFMaterialExporter._SetAlphaMode(glTFMaterial, babylonPBRMaterial as PBRMaterial);\r\n if (\r\n !(\r\n _GLTFMaterialExporter._FuzzyEquals(metallicRoughness.baseColor, Color3.White(), _GLTFMaterialExporter._Epsilon) &&\r\n babylonPBRMaterial.alpha >= _GLTFMaterialExporter._Epsilon\r\n )\r\n ) {\r\n glTFPbrMetallicRoughness.baseColorFactor = [metallicRoughness.baseColor.r, metallicRoughness.baseColor.g, metallicRoughness.baseColor.b, babylonPBRMaterial.alpha];\r\n }\r\n\r\n if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {\r\n glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;\r\n }\r\n if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {\r\n glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;\r\n }\r\n\r\n if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {\r\n if (!babylonPBRMaterial._twoSidedLighting) {\r\n Tools.Warn(babylonPBRMaterial.name + \": Back-face culling disabled and two-sided lighting disabled is not supported in glTF.\");\r\n }\r\n glTFMaterial.doubleSided = true;\r\n }\r\n\r\n if (hasTextureCoords) {\r\n const bumpTexture = babylonPBRMaterial._bumpTexture;\r\n if (bumpTexture) {\r\n const promise = this._exportTextureAsync(bumpTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFMaterial.normalTexture = glTFTexture;\r\n if (bumpTexture.level !== 1) {\r\n glTFMaterial.normalTexture.scale = bumpTexture.level;\r\n }\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n const ambientTexture = babylonPBRMaterial._ambientTexture;\r\n if (ambientTexture) {\r\n const promise = this._exportTextureAsync(ambientTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n const occlusionTexture: IMaterialOcclusionTextureInfo = {\r\n index: glTFTexture.index,\r\n texCoord: glTFTexture.texCoord,\r\n extensions: glTFTexture.extensions,\r\n };\r\n\r\n glTFMaterial.occlusionTexture = occlusionTexture;\r\n const ambientTextureStrength = babylonPBRMaterial._ambientTextureStrength;\r\n if (ambientTextureStrength) {\r\n occlusionTexture.strength = ambientTextureStrength;\r\n }\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n const emissiveTexture = babylonPBRMaterial._emissiveTexture;\r\n if (emissiveTexture) {\r\n const promise = this._exportTextureAsync(emissiveTexture, mimeType).then((glTFTexture) => {\r\n if (glTFTexture) {\r\n glTFMaterial.emissiveTexture = glTFTexture;\r\n }\r\n });\r\n promises.push(promise);\r\n }\r\n }\r\n const emissiveColor = babylonPBRMaterial._emissiveColor;\r\n if (!_GLTFMaterialExporter._FuzzyEquals(emissiveColor, Color3.Black(), _GLTFMaterialExporter._Epsilon)) {\r\n glTFMaterial.emissiveFactor = emissiveColor.asArray();\r\n }\r\n\r\n glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;\r\n materials.push(glTFMaterial);\r\n materialMap[babylonPBRMaterial.uniqueId] = materials.length - 1;\r\n }\r\n\r\n return this._finishMaterial(promises, glTFMaterial, babylonPBRMaterial, mimeType);\r\n }\r\n\r\n private _getPixelsFromTexture(babylonTexture: BaseTexture): Promise<Nullable<Uint8Array | Float32Array>> {\r\n const pixels =\r\n babylonTexture.textureType === Constants.TEXTURETYPE_UNSIGNED_INT\r\n ? (babylonTexture.readPixels() as Promise<Uint8Array>)\r\n : (babylonTexture.readPixels() as Promise<Float32Array>);\r\n return pixels;\r\n }\r\n\r\n /**\r\n * Extracts a texture from a Babylon texture into file data and glTF data\r\n * @param babylonTexture Babylon texture to extract\r\n * @param mimeType Mime Type of the babylonTexture\r\n * @returns glTF texture info, or null if the texture format is not supported\r\n */\r\n public _exportTextureAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>> {\r\n const extensionPromise = this._exporter._extensionsPreExportTextureAsync(\"exporter\", babylonTexture as Texture, mimeType);\r\n if (!extensionPromise) {\r\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\r\n }\r\n\r\n return extensionPromise.then((texture) => {\r\n if (!texture) {\r\n return this._exportTextureInfoAsync(babylonTexture, mimeType);\r\n }\r\n return this._exportTextureInfoAsync(texture, mimeType);\r\n });\r\n }\r\n\r\n public async _exportTextureInfoAsync(babylonTexture: BaseTexture, mimeType: ImageMimeType): Promise<Nullable<ITextureInfo>> {\r\n const textureUid = babylonTexture.uid;\r\n if (!(textureUid in this._textureMap)) {\r\n const pixels = await this._getPixelsFromTexture(babylonTexture);\r\n if (!pixels) {\r\n return null;\r\n }\r\n\r\n const samplerIndex = this._exportTextureSampler(babylonTexture);\r\n\r\n // Preserve texture mime type if defined\r\n const textureMimeType = (babylonTexture as Texture).mimeType;\r\n if (textureMimeType) {\r\n switch (textureMimeType) {\r\n case \"image/jpeg\":\r\n case \"image/png\":\r\n case \"image/webp\":\r\n mimeType = textureMimeType as ImageMimeType;\r\n break;\r\n default:\r\n Tools.Warn(`Unsupported media type: ${textureMimeType}`);\r\n break;\r\n }\r\n }\r\n\r\n const internalTextureToImage = this._internalTextureToImage;\r\n const internalTextureUniqueId = babylonTexture.getInternalTexture()!.uniqueId;\r\n internalTextureToImage[internalTextureUniqueId] ||= {};\r\n let imageIndexPromise = internalTextureToImage[internalTextureUniqueId][mimeType];\r\n if (imageIndexPromise === undefined) {\r\n const size = babylonTexture.getSize();\r\n imageIndexPromise = (async () => {\r\n const data = await this._getImageDataAsync(pixels, size.width, size.height, mimeType);\r\n return this._exportImage(babylonTexture.name, mimeType, data);\r\n })();\r\n internalTextureToImage[internalTextureUniqueId][mimeType] = imageIndexPromise;\r\n }\r\n\r\n const textureInfo = this._exportTextureInfo(await imageIndexPromise, samplerIndex, babylonTexture.coordinatesIndex);\r\n this._textureMap[textureUid] = textureInfo;\r\n this._exporter._extensionsPostExportTextures(\"exporter\", this._textureMap[textureUid], babylonTexture);\r\n }\r\n\r\n return this._textureMap[textureUid];\r\n }\r\n\r\n private _exportImage(name: string, mimeType: ImageMimeType, data: ArrayBuffer): number {\r\n const imageData = this._exporter._imageData;\r\n\r\n const baseName = name.replace(/\\.\\/|\\/|\\.\\\\|\\\\/g, \"_\");\r\n const extension = getFileExtensionFromMimeType(mimeType);\r\n let fileName = baseName + extension;\r\n if (fileName in imageData) {\r\n fileName = `${baseName}_${Tools.RandomId()}${extension}`;\r\n }\r\n\r\n imageData[fileName] = {\r\n data: data,\r\n mimeType: mimeType,\r\n };\r\n\r\n const images = this._exporter._images;\r\n images.push({\r\n name: name,\r\n uri: fileName,\r\n });\r\n\r\n return images.length - 1;\r\n }\r\n\r\n private _exportTextureInfo(imageIndex: number, samplerIndex: number, coordinatesIndex?: number): ITextureInfo {\r\n const textures = this._exporter._textures;\r\n let textureIndex = textures.findIndex((t) => t.sampler == samplerIndex && t.source === imageIndex);\r\n if (textureIndex === -1) {\r\n textureIndex = textures.length;\r\n textures.push({\r\n source: imageIndex,\r\n sampler: samplerIndex,\r\n });\r\n }\r\n\r\n const textureInfo: ITextureInfo = { index: textureIndex };\r\n if (coordinatesIndex) {\r\n textureInfo.texCoord = coordinatesIndex;\r\n }\r\n return textureInfo;\r\n }\r\n\r\n private _exportTextureSampler(texture: Nullable<BaseTexture>): number {\r\n const sampler = this._getTextureSampler(texture);\r\n\r\n // if a pre-existing sampler with identical parameters exists, then reuse the previous sampler\r\n const samplers = this._exporter._samplers;\r\n const samplerIndex = samplers.findIndex(\r\n (s) => s.minFilter === sampler.minFilter && s.magFilter === sampler.magFilter && s.wrapS === sampler.wrapS && s.wrapT === sampler.wrapT\r\n );\r\n if (samplerIndex !== -1) {\r\n return samplerIndex;\r\n }\r\n\r\n samplers.push(sampler);\r\n return samplers.length - 1;\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/serializers",
3
- "version": "7.25.2",
3
+ "version": "7.26.0",
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": "^7.25.2",
21
+ "@babylonjs/core": "^7.26.0",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "^7.25.2"
24
+ "babylonjs-gltf2interface": "^7.26.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^7.0.0",