@babylonjs/loaders 7.24.0 → 7.25.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/mtlFileLoader.js +1 -1
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +1 -2
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +0 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js +0 -1
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +0 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +0 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/glTFLoader.js +1 -1
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/index.d.ts +1 -0
- package/glTF/2.0/index.js +1 -0
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.js +1 -1
- package/glTF/glTFFileLoader.js.map +1 -1
- package/package.json +4 -4
package/OBJ/mtlFileLoader.js
CHANGED
package/OBJ/mtlFileLoader.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAInE;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IA+M9C,CAAC;IA7MG;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,KAAY,EAAE,IAA0B,EAAE,OA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CAAC;IAC1E,CAAC;;AAtND;;GAEG;AACW,8BAAgB,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === \"#\") {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n const pos = line.indexOf(\" \");\r\n let key = pos >= 0 ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n const value: string = pos >= 0 ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf(\"-bm\");\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(\" \"), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the texture from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @param scene\r\n * @returns The Texture\r\n */\r\n private static _GetTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substr(lastDelimiter + 1);\r\n } else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"mtlFileLoader.js","sourceRoot":"","sources":["../../../../dev/loaders/src/OBJ/mtlFileLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,sDAAwC;AAInE;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QAMI;;WAEG;QACI,cAAS,GAAuB,EAAE,CAAC;IA+M9C,CAAC;IA7MG;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,KAAY,EAAE,IAA0B,EAAE,OAAe,EAAE,cAAwC;QAC/G,IAA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GAEG;AACW,8BAAgB,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { StandardMaterial } from \"core/Materials/standardMaterial\";\r\n\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AssetContainer } from \"core/assetContainer\";\r\n/**\r\n * Class reading and parsing the MTL file bundled with the obj file.\r\n */\r\nexport class MTLFileLoader {\r\n /**\r\n * Invert Y-Axis of referenced textures on load\r\n */\r\n public static INVERT_TEXTURE_Y = true;\r\n\r\n /**\r\n * All material loaded from the mtl will be set here\r\n */\r\n public materials: StandardMaterial[] = [];\r\n\r\n /**\r\n * This function will read the mtl file and create each material described inside\r\n * This function could be improve by adding :\r\n * -some component missing (Ni, Tf...)\r\n * -including the specific options available\r\n *\r\n * @param scene defines the scene the material will be created in\r\n * @param data defines the mtl data to parse\r\n * @param rootUrl defines the rooturl to use in order to load relative dependencies\r\n * @param assetContainer defines the asset container to store the material in (can be null)\r\n */\r\n public parseMTL(scene: Scene, data: string | ArrayBuffer, rootUrl: string, assetContainer: Nullable<AssetContainer>): void {\r\n if (data instanceof ArrayBuffer) {\r\n return;\r\n }\r\n\r\n //Split the lines from the file\r\n const lines = data.split(\"\\n\");\r\n // whitespace char ie: [ \\t\\r\\n\\f]\r\n const delimiter_pattern = /\\s+/;\r\n //Array with RGB colors\r\n let color: number[];\r\n //New material\r\n let material: Nullable<StandardMaterial> = null;\r\n\r\n //Look at each line\r\n for (let i = 0; i < lines.length; i++) {\r\n const line = lines[i].trim();\r\n\r\n // Blank line or comment\r\n if (line.length === 0 || line.charAt(0) === \"#\") {\r\n continue;\r\n }\r\n\r\n //Get the first parameter (keyword)\r\n const pos = line.indexOf(\" \");\r\n let key = pos >= 0 ? line.substring(0, pos) : line;\r\n key = key.toLowerCase();\r\n\r\n //Get the data following the key\r\n const value: string = pos >= 0 ? line.substring(pos + 1).trim() : \"\";\r\n\r\n //This mtl keyword will create the new material\r\n if (key === \"newmtl\") {\r\n //Check if it is the first material.\r\n // Materials specifications are described after this keyword.\r\n if (material) {\r\n //Add the previous material in the material array.\r\n this.materials.push(material);\r\n }\r\n //Create a new material.\r\n // value is the name of the material read in the mtl file\r\n\r\n scene._blockEntityCollection = !!assetContainer;\r\n material = new StandardMaterial(value, scene);\r\n material._parentContainer = assetContainer;\r\n scene._blockEntityCollection = false;\r\n } else if (key === \"kd\" && material) {\r\n // Diffuse color (color under white light) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.diffuseColor = Color3.FromArray(color);\r\n } else if (key === \"ka\" && material) {\r\n // Ambient color (color under shadow) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set tghe color into the material\r\n material.ambientColor = Color3.FromArray(color);\r\n } else if (key === \"ks\" && material) {\r\n // Specular color (color when light is reflected from shiny surface) using RGB values\r\n\r\n //value = \"r g b\"\r\n color = <number[]>value.split(delimiter_pattern, 3).map(parseFloat);\r\n //color = [r,g,b]\r\n //Set the color into the material\r\n material.specularColor = Color3.FromArray(color);\r\n } else if (key === \"ke\" && material) {\r\n // Emissive color using RGB values\r\n color = value.split(delimiter_pattern, 3).map(parseFloat);\r\n material.emissiveColor = Color3.FromArray(color);\r\n } else if (key === \"ns\" && material) {\r\n //value = \"Integer\"\r\n material.specularPower = parseFloat(value);\r\n } else if (key === \"d\" && material) {\r\n //d is dissolve for current material. It mean alpha for BABYLON\r\n material.alpha = parseFloat(value);\r\n\r\n //Texture\r\n //This part can be improved by adding the possible options of texture\r\n } else if (key === \"map_ka\" && material) {\r\n // ambient texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.ambientTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_kd\" && material) {\r\n // Diffuse texture map with a loaded image\r\n material.diffuseTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ks\" && material) {\r\n // Specular texture map with a loaded image\r\n //We must first get the folder of the image\r\n material.specularTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n } else if (key === \"map_ns\") {\r\n //Specular\r\n //Specular highlight component\r\n //We must first get the folder of the image\r\n //\r\n //Not supported by BABYLON\r\n //\r\n // continue;\r\n } else if (key === \"map_bump\" && material) {\r\n //The bump texture\r\n const values = value.split(delimiter_pattern);\r\n const bumpMultiplierIndex = values.indexOf(\"-bm\");\r\n let bumpMultiplier: Nullable<string> = null;\r\n\r\n if (bumpMultiplierIndex >= 0) {\r\n bumpMultiplier = values[bumpMultiplierIndex + 1];\r\n values.splice(bumpMultiplierIndex, 2); // remove\r\n }\r\n\r\n material.bumpTexture = MTLFileLoader._GetTexture(rootUrl, values.join(\" \"), scene);\r\n if (material.bumpTexture && bumpMultiplier !== null) {\r\n material.bumpTexture.level = parseFloat(bumpMultiplier);\r\n }\r\n } else if (key === \"map_d\" && material) {\r\n // The dissolve of the material\r\n material.opacityTexture = MTLFileLoader._GetTexture(rootUrl, value, scene);\r\n\r\n //Options for illumination\r\n } else if (key === \"illum\") {\r\n //Illumination\r\n if (value === \"0\") {\r\n //That mean Kd == Kd\r\n } else if (value === \"1\") {\r\n //Color on and Ambient on\r\n } else if (value === \"2\") {\r\n //Highlight on\r\n } else if (value === \"3\") {\r\n //Reflection on and Ray trace on\r\n } else if (value === \"4\") {\r\n //Transparency: Glass on, Reflection: Ray trace on\r\n } else if (value === \"5\") {\r\n //Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"6\") {\r\n //Transparency: Refraction on, Reflection: Fresnel off and Ray trace on\r\n } else if (value === \"7\") {\r\n //Transparency: Refraction on, Reflection: Fresnel on and Ray trace on\r\n } else if (value === \"8\") {\r\n //Reflection on and Ray trace off\r\n } else if (value === \"9\") {\r\n //Transparency: Glass on, Reflection: Ray trace off\r\n } else if (value === \"10\") {\r\n //Casts shadows onto invisible surfaces\r\n }\r\n } else {\r\n // console.log(\"Unhandled expression at line : \" + i +'\\n' + \"with value : \" + line);\r\n }\r\n }\r\n //At the end of the file, add the last material\r\n if (material) {\r\n this.materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the texture for the material.\r\n *\r\n * If the material is imported from input file,\r\n * We sanitize the url to ensure it takes the texture from aside the material.\r\n *\r\n * @param rootUrl The root url to load from\r\n * @param value The value stored in the mtl\r\n * @param scene\r\n * @returns The Texture\r\n */\r\n private static _GetTexture(rootUrl: string, value: string, scene: Scene): Nullable<Texture> {\r\n if (!value) {\r\n return null;\r\n }\r\n\r\n let url = rootUrl;\r\n // Load from input file.\r\n if (rootUrl === \"file:\") {\r\n let lastDelimiter = value.lastIndexOf(\"\\\\\");\r\n if (lastDelimiter === -1) {\r\n lastDelimiter = value.lastIndexOf(\"/\");\r\n }\r\n\r\n if (lastDelimiter > -1) {\r\n url += value.substring(lastDelimiter + 1);\r\n } else {\r\n url += value;\r\n }\r\n }\r\n // Not from input file.\r\n else {\r\n url += value;\r\n }\r\n\r\n return new Texture(url, scene, false, MTLFileLoader.INVERT_TEXTURE_Y);\r\n }\r\n}\r\n"]}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { Scalar } from "@babylonjs/core/Maths/math.scalar.js";
|
2
1
|
import { SphericalHarmonics, SphericalPolynomial } from "@babylonjs/core/Maths/sphericalPolynomial.js";
|
3
2
|
import { Quaternion, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
4
3
|
import { RawCubeTexture } from "@babylonjs/core/Materials/Textures/rawCubeTexture.js";
|
@@ -94,7 +93,7 @@ export class EXT_lights_image_based {
|
|
94
93
|
sphericalHarmonics.convertIrradianceToLambertianRadiance();
|
95
94
|
const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);
|
96
95
|
// Compute the lod generation scale to fit exactly to the number of levels available.
|
97
|
-
const lodGenerationScale = (imageData.length - 1) /
|
96
|
+
const lodGenerationScale = (imageData.length - 1) / Math.log2(light.specularImageSize);
|
98
97
|
return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);
|
99
98
|
});
|
100
99
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAChD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qDAAuC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AAE5D,OAAO,EAAE,cAAc,EAAE,6DAA+C;AAKxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAsBtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAc/B;;OAEG;IACH,YAAY,MAAkB;QAhB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAcxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,gBAAgB;IACT,SAAS;QACZ,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,MAAM,SAAS,GAAG,UAAU,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BAAkB,CAAC,CAAC;gBAElF,qFAAqF;gBACrF,MAAM,kBAAkB,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACzF,OAAO,cAAc,CAAC,eAAe,CAAC,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Scalar } from \"core/Maths/math.scalar\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"core/Maths/math.vector\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport type { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport type { IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the EXT_lights_image_based extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"EXT_lights_image_based\"]: {};\r\n }\r\n}\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @internal */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(\r\n this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(\r\n this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Scalar.Log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new EXT_lights_image_based(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qDAAuC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AAE5D,OAAO,EAAE,cAAc,EAAE,6DAA+C;AAKxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAsBtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAc/B;;OAEG;IACH,YAAY,MAAkB;QAhB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAcxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC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AAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,uCAAuC,CAAC,CAAC;iBACtE;gBAED,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBACtF,kBAAkB,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBAEjD,kBAAkB,CAAC,qCAAqC,EAAE,CAAC;gBAC3D,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAElF,qFAAqF;gBACrF,MAAM,kBAAkB,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;gBACvF,OAAO,cAAc,CAAC,eAAe,CAAC,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;YAC9F,CAAC,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,OAAO,KAAK,CAAC,eAAgB,CAAC;QAClC,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"core/Maths/math.vector\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport type { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport type { IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the EXT_lights_image_based extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"EXT_lights_image_based\"]: {};\r\n }\r\n}\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @internal */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_image_based implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _lights?: IEXTLightsImageBased_LightImageBased[];\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n delete this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(\r\n this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(\r\n this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n light._loaded = Promise.all(promises).then(() => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Math.log2(light.specularImageSize);\r\n return babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new EXT_lights_image_based(loader));\r\n"]}
|
@@ -37,7 +37,6 @@ export class KHR_materials_diffuse_transmission {
|
|
37
37
|
loadMaterialPropertiesAsync(context, material, babylonMaterial) {
|
38
38
|
return GLTFLoader.LoadExtensionAsync(context, material, this.name, (extensionContext, extension) => {
|
39
39
|
const promises = new Array();
|
40
|
-
promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
41
40
|
promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
42
41
|
promises.push(this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
|
43
42
|
return Promise.all(promises).then(() => { });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAalD;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,kCAAkC;IAkB3C;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,MAAM,CAAC,MAAM,CAAC,sBAAsB,GAAG,IAAI,CAAC;SAC/C;IACL,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kBAAkB,CAAmC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE;YACjI,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAgB,CAAC;YAC3C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC
|
1
|
+
{"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF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AI,CAAC;YAC3E,QAAQ,CAAC,IAAI,CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,6BAA6B,EAAE,SAAS,CAAC,0BAA0B,CAAC,CAAC,IAAI,CAAC,CAAC,OAAoB,EAAE,EAAE;gBAC3I,WAAW,CAAC,UAAU,CAAC,4BAA4B,GAAG,OAAO,CAAC;YAClE,CAAC,CAAC,CACL,CAAC;SACL;QAED,IAAI,SAAS,CAAC,8BAA8B,KAAK,SAAS,EAAE;YACxD,WAAW,CAAC,UAAU,CAAC,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;SACzG;aAAM;YACH,WAAW,CAAC,UAAU,CAAC,iBAAiB,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;SAC7D;QAED,IAAI,SAAS,CAAC,+BAA+B,EAAE;YAC3C,QAAQ,CAAC,IAAI,CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,kCAAkC,EAAE,SAAS,CAAC,+BAA+B,CAAC,CAAC,IAAI,CAAC,CAAC,OAAoB,EAAE,EAAE;gBACrJ,WAAW,CAAC,UAAU,CAAC,wBAAwB,GAAG,OAAO,CAAC;YAC9D,CAAC,CAAC,CACL,CAAC;SACL;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kCAAkC,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_diffuse_transmission extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_diffuse_transmission\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 174;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n loader.parent.transparencyAsCoverage = true;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsDiffuseTransmission>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadTranslucentPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsDiffuseTransmission): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n const pbrMaterial = babylonMaterial as PBRMaterial;\r\n\r\n // Enables \"translucency\" texture which represents diffusely-transmitted light.\r\n pbrMaterial.subSurface.isTranslucencyEnabled = true;\r\n\r\n // Since this extension models thin-surface transmission only, we must make the\r\n // internal IOR == 1.0 and set the thickness to 0.\r\n pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;\r\n pbrMaterial.subSurface.minimumThickness = 0.0;\r\n pbrMaterial.subSurface.maximumThickness = 0.0;\r\n\r\n // Tint color will be used for transmission.\r\n pbrMaterial.subSurface.useAlbedoToTintTranslucency = false;\r\n\r\n if (extension.diffuseTransmissionFactor !== undefined) {\r\n pbrMaterial.subSurface.translucencyIntensity = extension.diffuseTransmissionFactor;\r\n } else {\r\n pbrMaterial.subSurface.translucencyIntensity = 0.0;\r\n pbrMaterial.subSurface.isTranslucencyEnabled = false;\r\n return Promise.resolve();\r\n }\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n pbrMaterial.subSurface.useGltfStyleTextures = true;\r\n\r\n if (extension.diffuseTransmissionTexture) {\r\n (extension.diffuseTransmissionTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionTexture`, extension.diffuseTransmissionTexture).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.translucencyIntensityTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (extension.diffuseTransmissionColorFactor !== undefined) {\r\n pbrMaterial.subSurface.translucencyColor = Color3.FromArray(extension.diffuseTransmissionColorFactor);\r\n } else {\r\n pbrMaterial.subSurface.translucencyColor = Color3.White();\r\n }\r\n\r\n if (extension.diffuseTransmissionColorTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionColorTexture`, extension.diffuseTransmissionColorTexture).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.translucencyColorTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_diffuse_transmission(loader));\r\n"]}
|
@@ -33,7 +33,6 @@ export class KHR_materials_dispersion {
|
|
33
33
|
loadMaterialPropertiesAsync(context, material, babylonMaterial) {
|
34
34
|
return GLTFLoader.LoadExtensionAsync(context, material, this.name, (extensionContext, extension) => {
|
35
35
|
const promises = new Array();
|
36
|
-
promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
37
36
|
promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
38
37
|
promises.push(this._loadDispersionPropertiesAsync(extensionContext, material, babylonMaterial, extension));
|
39
38
|
return Promise.all(promises).then(() => { });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_dispersion.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAI7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAaxC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,wBAAwB;IAkBjC;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kBAAkB,CAA0B,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE;YACxH,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAgB,CAAC;YAC3C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC
|
1
|
+
{"version":3,"file":"KHR_materials_dispersion.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_dispersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAI7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAaxC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,wBAAwB;IAkBjC;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAA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C,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsDispersion } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_dispersion\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_dispersion extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_dispersion\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/87bd64a7f5e23c84b6aef2e6082069583ed0ddb4/extensions/2.0/Khronos/KHR_materials_dispersion/README.md)\r\n * @experimental\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_dispersion implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 174;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsDispersion>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadDispersionPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadDispersionPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsDispersion): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n // If transparency isn't enabled already, this extension shouldn't do anything.\r\n // i.e. it requires either the KHR_materials_transmission or KHR_materials_diffuse_transmission extensions.\r\n if (!babylonMaterial.subSurface.isRefractionEnabled || !extension.dispersion) {\r\n return Promise.resolve();\r\n }\r\n babylonMaterial.subSurface.isDispersionEnabled = true;\r\n babylonMaterial.subSurface.dispersion = extension.dispersion;\r\n return Promise.resolve();\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_dispersion(loader));\r\n"]}
|
@@ -254,7 +254,6 @@ export class KHR_materials_transmission {
|
|
254
254
|
loadMaterialPropertiesAsync(context, material, babylonMaterial) {
|
255
255
|
return GLTFLoader.LoadExtensionAsync(context, material, this.name, (extensionContext, extension) => {
|
256
256
|
const promises = new Array();
|
257
|
-
promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
258
257
|
promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
259
258
|
promises.push(this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
|
260
259
|
return Promise.all(promises).then(() => { });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_transmission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,EAAE,mBAAmB,EAAE,kEAAoD;AAElF,OAAO,EAAE,UAAU,EAAE,2CAA6B;AAClD,OAAO,EAAE,SAAS,EAAE,6CAA+B;AACnD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AA+ChG;;GAEG;AACH,MAAM,kBAAkB;IACpB;;;OAGG;IACK,MAAM,CAAC,kBAAkB;QAC7B,OAAO;YACH,UAAU,EAAE,IAAI;YAChB,OAAO,EAAE,CAAC;YACV,kBAAkB,EAAE,CAAC;YACrB,mBAAmB,EAAE,CAAC,CAAC;YACvB,uBAAuB,EAAE,SAAS,CAAC,sBAAsB;YACzD,eAAe,EAAE,IAAI;SACxB,CAAC;IACN,CAAC;IAoBD;;;;OAIG;IACH,YAAY,OAA4C,EAAE,KAAY;QAhB9D,wBAAmB,GAAkC,IAAI,CAAC;QAC1D,uBAAkB,GAAmB,EAAE,CAAC;QACxC,4BAAuB,GAAmB,EAAE,CAAC;QAC7C,uBAAkB,GAAuD,EAAE,CAAC;QAchF,IAAI,CAAC,QAAQ,GAAG;YACZ,GAAG,kBAAkB,CAAC,kBAAkB,EAAE;YAC1C,GAAG,OAAO;SACb,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,KAAY,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAEvC,IAAI,CAA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AAO,sBAAsB,EAAE,SAAS,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,OAAoB,EAAE,EAAE;gBAC/I,WAAW,CAAC,UAAU,CAAC,0BAA0B,GAAG,OAAO,CAAC;gBAC5D,WAAW,CAAC,UAAU,CAAC,oBAAoB,GAAG,IAAI,CAAC;YACvD,CAAC,CAAC,CAAC;SACN;aAAM;YACH,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC5B;IACL,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsTransmission } from \"babylonjs-gltf2interface\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Color4 } from \"core/Maths/math.color\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\ninterface ITransmissionHelperHolder {\r\n /**\r\n * @internal\r\n */\r\n _transmissionHelper: TransmissionHelper | undefined;\r\n}\r\n\r\ninterface ITransmissionHelperOptions {\r\n /**\r\n * The size of the render buffers (default: 1024)\r\n */\r\n renderSize: number;\r\n\r\n /**\r\n * The number of samples to use when generating the render target texture for opaque meshes (default: 4)\r\n */\r\n samples: number;\r\n\r\n /**\r\n * Scale to apply when selecting the LOD level to sample the refraction texture (default: 1)\r\n */\r\n lodGenerationScale: number;\r\n\r\n /**\r\n * Offset to apply when selecting the LOD level to sample the refraction texture (default: -4)\r\n */\r\n lodGenerationOffset: number;\r\n\r\n /**\r\n * Type of the refraction render target texture (default: TEXTURETYPE_HALF_FLOAT)\r\n */\r\n renderTargetTextureType: number;\r\n\r\n /**\r\n * Defines if the mipmaps for the refraction render target texture must be generated (default: true)\r\n */\r\n generateMipmaps: boolean;\r\n\r\n /**\r\n * Clear color of the opaque texture. If not provided, use the scene clear color (which will be converted to linear space).\r\n * If provided, should be in linear space\r\n */\r\n clearColor?: Color4;\r\n}\r\n\r\n/**\r\n * A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.\r\n */\r\nclass TransmissionHelper {\r\n /**\r\n * Creates the default options for the helper.\r\n * @returns the default options\r\n */\r\n private static _GetDefaultOptions(): ITransmissionHelperOptions {\r\n return {\r\n renderSize: 1024,\r\n samples: 4,\r\n lodGenerationScale: 1,\r\n lodGenerationOffset: -4,\r\n renderTargetTextureType: Constants.TEXTURETYPE_HALF_FLOAT,\r\n generateMipmaps: true,\r\n };\r\n }\r\n\r\n /**\r\n * Stores the creation options.\r\n */\r\n private readonly _scene: Scene & ITransmissionHelperHolder;\r\n\r\n private _options: ITransmissionHelperOptions;\r\n\r\n private _opaqueRenderTarget: Nullable<RenderTargetTexture> = null;\r\n private _opaqueMeshesCache: AbstractMesh[] = [];\r\n private _transparentMeshesCache: AbstractMesh[] = [];\r\n private _materialObservers: { [id: string]: Nullable<Observer<AbstractMesh>> } = {};\r\n\r\n /**\r\n * This observable will be notified with any error during the creation of the environment,\r\n * mainly texture creation errors.\r\n */\r\n public onErrorObservable: Observable<{ message?: string; exception?: any }>;\r\n\r\n /**\r\n * constructor\r\n * @param options Defines the options we want to customize the helper\r\n * @param scene The scene to add the material to\r\n */\r\n constructor(options: Partial<ITransmissionHelperOptions>, scene: Scene) {\r\n this._options = {\r\n ...TransmissionHelper._GetDefaultOptions(),\r\n ...options,\r\n };\r\n this._scene = scene as any;\r\n this._scene._transmissionHelper = this;\r\n\r\n this.onErrorObservable = new Observable();\r\n this._scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n\r\n this._parseScene();\r\n this._setupRenderTargets();\r\n }\r\n\r\n /**\r\n * Updates the background according to the new options\r\n * @param options\r\n */\r\n public updateOptions(options: Partial<ITransmissionHelperOptions>) {\r\n // First check if any options are actually being changed. If not, exit.\r\n const newValues = Object.keys(options).filter((key: string) => (this._options as any)[key] !== (options as any)[key]);\r\n if (!newValues.length) {\r\n return;\r\n }\r\n\r\n const newOptions = {\r\n ...this._options,\r\n ...options,\r\n };\r\n\r\n const oldOptions = this._options;\r\n this._options = newOptions;\r\n\r\n // If size changes, recreate everything\r\n if (\r\n newOptions.renderSize !== oldOptions.renderSize ||\r\n newOptions.renderTargetTextureType !== oldOptions.renderTargetTextureType ||\r\n newOptions.generateMipmaps !== oldOptions.generateMipmaps ||\r\n !this._opaqueRenderTarget\r\n ) {\r\n this._setupRenderTargets();\r\n } else {\r\n this._opaqueRenderTarget.samples = newOptions.samples;\r\n this._opaqueRenderTarget.lodGenerationScale = newOptions.lodGenerationScale;\r\n this._opaqueRenderTarget.lodGenerationOffset = newOptions.lodGenerationOffset;\r\n }\r\n }\r\n\r\n /**\r\n * @returns the opaque render target texture or null if not available.\r\n */\r\n public getOpaqueTarget(): Nullable<Texture> {\r\n return this._opaqueRenderTarget;\r\n }\r\n\r\n private _shouldRenderAsTransmission(material: Nullable<Material>): boolean {\r\n if (!material) {\r\n return false;\r\n }\r\n if (material instanceof PBRMaterial && material.subSurface.isRefractionEnabled) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private _addMesh(mesh: AbstractMesh): void {\r\n this._materialObservers[mesh.uniqueId] = mesh.onMaterialChangedObservable.add(this._onMeshMaterialChanged.bind(this));\r\n\r\n // we need to defer the processing because _addMesh may be called as part as an instance mesh creation, in which case some\r\n // internal properties are not setup yet, like _sourceMesh (needed when doing mesh.material below)\r\n Tools.SetImmediate(() => {\r\n if (this._shouldRenderAsTransmission(mesh.material)) {\r\n (mesh.material as PBRMaterial).refractionTexture = this._opaqueRenderTarget;\r\n if (this._transparentMeshesCache.indexOf(mesh) === -1) {\r\n this._transparentMeshesCache.push(mesh);\r\n }\r\n } else {\r\n if (this._opaqueMeshesCache.indexOf(mesh) === -1) {\r\n this._opaqueMeshesCache.push(mesh);\r\n }\r\n }\r\n });\r\n }\r\n\r\n private _removeMesh(mesh: AbstractMesh): void {\r\n mesh.onMaterialChangedObservable.remove(this._materialObservers[mesh.uniqueId]);\r\n delete this._materialObservers[mesh.uniqueId];\r\n let idx = this._transparentMeshesCache.indexOf(mesh);\r\n if (idx !== -1) {\r\n this._transparentMeshesCache.splice(idx, 1);\r\n }\r\n idx = this._opaqueMeshesCache.indexOf(mesh);\r\n if (idx !== -1) {\r\n this._opaqueMeshesCache.splice(idx, 1);\r\n }\r\n }\r\n\r\n private _parseScene(): void {\r\n this._scene.meshes.forEach(this._addMesh.bind(this));\r\n // Listen for when a mesh is added to the scene and add it to our cache lists.\r\n this._scene.onNewMeshAddedObservable.add(this._addMesh.bind(this));\r\n // Listen for when a mesh is removed from to the scene and remove it from our cache lists.\r\n this._scene.onMeshRemovedObservable.add(this._removeMesh.bind(this));\r\n }\r\n\r\n // When one of the meshes in the scene has its material changed, make sure that it's in the correct cache list.\r\n private _onMeshMaterialChanged(mesh: AbstractMesh) {\r\n const transparentIdx = this._transparentMeshesCache.indexOf(mesh);\r\n const opaqueIdx = this._opaqueMeshesCache.indexOf(mesh);\r\n\r\n // If the material is transparent, make sure that it's added to the transparent list and removed from the opaque list\r\n const useTransmission = this._shouldRenderAsTransmission(mesh.material);\r\n if (useTransmission) {\r\n if (mesh.material instanceof PBRMaterial) {\r\n mesh.material.subSurface.refractionTexture = this._opaqueRenderTarget;\r\n }\r\n if (opaqueIdx !== -1) {\r\n this._opaqueMeshesCache.splice(opaqueIdx, 1);\r\n this._transparentMeshesCache.push(mesh);\r\n } else if (transparentIdx === -1) {\r\n this._transparentMeshesCache.push(mesh);\r\n }\r\n // If the material is opaque, make sure that it's added to the opaque list and removed from the transparent list\r\n } else {\r\n if (transparentIdx !== -1) {\r\n this._transparentMeshesCache.splice(transparentIdx, 1);\r\n this._opaqueMeshesCache.push(mesh);\r\n } else if (opaqueIdx === -1) {\r\n this._opaqueMeshesCache.push(mesh);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Check if the opaque render target has not been disposed and can still be used.\r\n * @returns\r\n */\r\n public _isRenderTargetValid() {\r\n return this._opaqueRenderTarget?.getInternalTexture() !== null;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Setup the render targets according to the specified options.\r\n */\r\n public _setupRenderTargets(): void {\r\n if (this._opaqueRenderTarget) {\r\n this._opaqueRenderTarget.dispose();\r\n }\r\n this._opaqueRenderTarget = new RenderTargetTexture(\r\n \"opaqueSceneTexture\",\r\n this._options.renderSize,\r\n this._scene,\r\n this._options.generateMipmaps,\r\n undefined,\r\n this._options.renderTargetTextureType\r\n );\r\n this._opaqueRenderTarget.ignoreCameraViewport = true;\r\n this._opaqueRenderTarget.renderList = this._opaqueMeshesCache;\r\n this._opaqueRenderTarget.clearColor = this._options.clearColor?.clone() ?? this._scene.clearColor.clone();\r\n this._opaqueRenderTarget.gammaSpace = false;\r\n this._opaqueRenderTarget.lodGenerationScale = this._options.lodGenerationScale;\r\n this._opaqueRenderTarget.lodGenerationOffset = this._options.lodGenerationOffset;\r\n this._opaqueRenderTarget.samples = this._options.samples;\r\n this._opaqueRenderTarget.renderSprites = true;\r\n this._opaqueRenderTarget.renderParticles = true;\r\n\r\n let sceneImageProcessingapplyByPostProcess: boolean;\r\n\r\n let saveSceneEnvIntensity: number;\r\n this._opaqueRenderTarget.onBeforeBindObservable.add((opaqueRenderTarget) => {\r\n saveSceneEnvIntensity = this._scene.environmentIntensity;\r\n this._scene.environmentIntensity = 1.0;\r\n sceneImageProcessingapplyByPostProcess = this._scene.imageProcessingConfiguration.applyByPostProcess;\r\n if (!this._options.clearColor) {\r\n this._scene.clearColor.toLinearSpaceToRef(opaqueRenderTarget.clearColor, this._scene.getEngine().useExactSrgbConversions);\r\n } else {\r\n opaqueRenderTarget.clearColor.copyFrom(this._options.clearColor);\r\n }\r\n // we do not use the applyByPostProcess setter to avoid flagging all the materials as \"image processing dirty\"!\r\n this._scene.imageProcessingConfiguration._applyByPostProcess = true;\r\n });\r\n this._opaqueRenderTarget.onAfterUnbindObservable.add(() => {\r\n this._scene.environmentIntensity = saveSceneEnvIntensity;\r\n this._scene.imageProcessingConfiguration._applyByPostProcess = sceneImageProcessingapplyByPostProcess;\r\n });\r\n\r\n this._transparentMeshesCache.forEach((mesh: AbstractMesh) => {\r\n if (this._shouldRenderAsTransmission(mesh.material)) {\r\n (mesh.material as PBRMaterial).refractionTexture = this._opaqueRenderTarget;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Dispose all the elements created by the Helper.\r\n */\r\n public dispose(): void {\r\n this._scene._transmissionHelper = undefined;\r\n if (this._opaqueRenderTarget) {\r\n this._opaqueRenderTarget.dispose();\r\n this._opaqueRenderTarget = null;\r\n }\r\n this._transparentMeshesCache = [];\r\n this._opaqueMeshesCache = [];\r\n }\r\n}\r\n\r\nconst NAME = \"KHR_materials_transmission\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_transmission extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_transmission\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_transmission implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 175;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n loader.parent.transparencyAsCoverage = true;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsTransmission>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadTransparentPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsTransmission): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n const pbrMaterial = babylonMaterial as PBRMaterial;\r\n\r\n // Enables \"refraction\" texture which represents transmitted light.\r\n pbrMaterial.subSurface.isRefractionEnabled = true;\r\n\r\n // Since this extension models thin-surface transmission only, we must make IOR = 1.0\r\n pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;\r\n\r\n // Albedo colour will tint transmission.\r\n pbrMaterial.subSurface.useAlbedoToTintRefraction = true;\r\n\r\n if (extension.transmissionFactor !== undefined) {\r\n pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;\r\n const scene = pbrMaterial.getScene() as unknown as ITransmissionHelperHolder;\r\n if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {\r\n new TransmissionHelper({}, pbrMaterial.getScene());\r\n } else if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper?._isRenderTargetValid()) {\r\n // If the render target is not valid, recreate it.\r\n scene._transmissionHelper?._setupRenderTargets();\r\n }\r\n } else {\r\n pbrMaterial.subSurface.refractionIntensity = 0.0;\r\n pbrMaterial.subSurface.isRefractionEnabled = false;\r\n return Promise.resolve();\r\n }\r\n\r\n pbrMaterial.subSurface.minimumThickness = 0.0;\r\n pbrMaterial.subSurface.maximumThickness = 0.0;\r\n if (extension.transmissionTexture) {\r\n (extension.transmissionTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/transmissionTexture`, extension.transmissionTexture, undefined).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.refractionIntensityTexture = texture;\r\n pbrMaterial.subSurface.useGltfStyleTextures = true;\r\n });\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_transmission(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_transmission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,EAAE,mBAAmB,EAAE,kEAAoD;AAElF,OAAO,EAAE,U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\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsTransmission } from \"babylonjs-gltf2interface\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Color4 } from \"core/Maths/math.color\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\ninterface ITransmissionHelperHolder {\r\n /**\r\n * @internal\r\n */\r\n _transmissionHelper: TransmissionHelper | undefined;\r\n}\r\n\r\ninterface ITransmissionHelperOptions {\r\n /**\r\n * The size of the render buffers (default: 1024)\r\n */\r\n renderSize: number;\r\n\r\n /**\r\n * The number of samples to use when generating the render target texture for opaque meshes (default: 4)\r\n */\r\n samples: number;\r\n\r\n /**\r\n * Scale to apply when selecting the LOD level to sample the refraction texture (default: 1)\r\n */\r\n lodGenerationScale: number;\r\n\r\n /**\r\n * Offset to apply when selecting the LOD level to sample the refraction texture (default: -4)\r\n */\r\n lodGenerationOffset: number;\r\n\r\n /**\r\n * Type of the refraction render target texture (default: TEXTURETYPE_HALF_FLOAT)\r\n */\r\n renderTargetTextureType: number;\r\n\r\n /**\r\n * Defines if the mipmaps for the refraction render target texture must be generated (default: true)\r\n */\r\n generateMipmaps: boolean;\r\n\r\n /**\r\n * Clear color of the opaque texture. If not provided, use the scene clear color (which will be converted to linear space).\r\n * If provided, should be in linear space\r\n */\r\n clearColor?: Color4;\r\n}\r\n\r\n/**\r\n * A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.\r\n */\r\nclass TransmissionHelper {\r\n /**\r\n * Creates the default options for the helper.\r\n * @returns the default options\r\n */\r\n private static _GetDefaultOptions(): ITransmissionHelperOptions {\r\n return {\r\n renderSize: 1024,\r\n samples: 4,\r\n lodGenerationScale: 1,\r\n lodGenerationOffset: -4,\r\n renderTargetTextureType: Constants.TEXTURETYPE_HALF_FLOAT,\r\n generateMipmaps: true,\r\n };\r\n }\r\n\r\n /**\r\n * Stores the creation options.\r\n */\r\n private readonly _scene: Scene & ITransmissionHelperHolder;\r\n\r\n private _options: ITransmissionHelperOptions;\r\n\r\n private _opaqueRenderTarget: Nullable<RenderTargetTexture> = null;\r\n private _opaqueMeshesCache: AbstractMesh[] = [];\r\n private _transparentMeshesCache: AbstractMesh[] = [];\r\n private _materialObservers: { [id: string]: Nullable<Observer<AbstractMesh>> } = {};\r\n\r\n /**\r\n * This observable will be notified with any error during the creation of the environment,\r\n * mainly texture creation errors.\r\n */\r\n public onErrorObservable: Observable<{ message?: string; exception?: any }>;\r\n\r\n /**\r\n * constructor\r\n * @param options Defines the options we want to customize the helper\r\n * @param scene The scene to add the material to\r\n */\r\n constructor(options: Partial<ITransmissionHelperOptions>, scene: Scene) {\r\n this._options = {\r\n ...TransmissionHelper._GetDefaultOptions(),\r\n ...options,\r\n };\r\n this._scene = scene as any;\r\n this._scene._transmissionHelper = this;\r\n\r\n this.onErrorObservable = new Observable();\r\n this._scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n\r\n this._parseScene();\r\n this._setupRenderTargets();\r\n }\r\n\r\n /**\r\n * Updates the background according to the new options\r\n * @param options\r\n */\r\n public updateOptions(options: Partial<ITransmissionHelperOptions>) {\r\n // First check if any options are actually being changed. If not, exit.\r\n const newValues = Object.keys(options).filter((key: string) => (this._options as any)[key] !== (options as any)[key]);\r\n if (!newValues.length) {\r\n return;\r\n }\r\n\r\n const newOptions = {\r\n ...this._options,\r\n ...options,\r\n };\r\n\r\n const oldOptions = this._options;\r\n this._options = newOptions;\r\n\r\n // If size changes, recreate everything\r\n if (\r\n newOptions.renderSize !== oldOptions.renderSize ||\r\n newOptions.renderTargetTextureType !== oldOptions.renderTargetTextureType ||\r\n newOptions.generateMipmaps !== oldOptions.generateMipmaps ||\r\n !this._opaqueRenderTarget\r\n ) {\r\n this._setupRenderTargets();\r\n } else {\r\n this._opaqueRenderTarget.samples = newOptions.samples;\r\n this._opaqueRenderTarget.lodGenerationScale = newOptions.lodGenerationScale;\r\n this._opaqueRenderTarget.lodGenerationOffset = newOptions.lodGenerationOffset;\r\n }\r\n }\r\n\r\n /**\r\n * @returns the opaque render target texture or null if not available.\r\n */\r\n public getOpaqueTarget(): Nullable<Texture> {\r\n return this._opaqueRenderTarget;\r\n }\r\n\r\n private _shouldRenderAsTransmission(material: Nullable<Material>): boolean {\r\n if (!material) {\r\n return false;\r\n }\r\n if (material instanceof PBRMaterial && material.subSurface.isRefractionEnabled) {\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private _addMesh(mesh: AbstractMesh): void {\r\n this._materialObservers[mesh.uniqueId] = mesh.onMaterialChangedObservable.add(this._onMeshMaterialChanged.bind(this));\r\n\r\n // we need to defer the processing because _addMesh may be called as part as an instance mesh creation, in which case some\r\n // internal properties are not setup yet, like _sourceMesh (needed when doing mesh.material below)\r\n Tools.SetImmediate(() => {\r\n if (this._shouldRenderAsTransmission(mesh.material)) {\r\n (mesh.material as PBRMaterial).refractionTexture = this._opaqueRenderTarget;\r\n if (this._transparentMeshesCache.indexOf(mesh) === -1) {\r\n this._transparentMeshesCache.push(mesh);\r\n }\r\n } else {\r\n if (this._opaqueMeshesCache.indexOf(mesh) === -1) {\r\n this._opaqueMeshesCache.push(mesh);\r\n }\r\n }\r\n });\r\n }\r\n\r\n private _removeMesh(mesh: AbstractMesh): void {\r\n mesh.onMaterialChangedObservable.remove(this._materialObservers[mesh.uniqueId]);\r\n delete this._materialObservers[mesh.uniqueId];\r\n let idx = this._transparentMeshesCache.indexOf(mesh);\r\n if (idx !== -1) {\r\n this._transparentMeshesCache.splice(idx, 1);\r\n }\r\n idx = this._opaqueMeshesCache.indexOf(mesh);\r\n if (idx !== -1) {\r\n this._opaqueMeshesCache.splice(idx, 1);\r\n }\r\n }\r\n\r\n private _parseScene(): void {\r\n this._scene.meshes.forEach(this._addMesh.bind(this));\r\n // Listen for when a mesh is added to the scene and add it to our cache lists.\r\n this._scene.onNewMeshAddedObservable.add(this._addMesh.bind(this));\r\n // Listen for when a mesh is removed from to the scene and remove it from our cache lists.\r\n this._scene.onMeshRemovedObservable.add(this._removeMesh.bind(this));\r\n }\r\n\r\n // When one of the meshes in the scene has its material changed, make sure that it's in the correct cache list.\r\n private _onMeshMaterialChanged(mesh: AbstractMesh) {\r\n const transparentIdx = this._transparentMeshesCache.indexOf(mesh);\r\n const opaqueIdx = this._opaqueMeshesCache.indexOf(mesh);\r\n\r\n // If the material is transparent, make sure that it's added to the transparent list and removed from the opaque list\r\n const useTransmission = this._shouldRenderAsTransmission(mesh.material);\r\n if (useTransmission) {\r\n if (mesh.material instanceof PBRMaterial) {\r\n mesh.material.subSurface.refractionTexture = this._opaqueRenderTarget;\r\n }\r\n if (opaqueIdx !== -1) {\r\n this._opaqueMeshesCache.splice(opaqueIdx, 1);\r\n this._transparentMeshesCache.push(mesh);\r\n } else if (transparentIdx === -1) {\r\n this._transparentMeshesCache.push(mesh);\r\n }\r\n // If the material is opaque, make sure that it's added to the opaque list and removed from the transparent list\r\n } else {\r\n if (transparentIdx !== -1) {\r\n this._transparentMeshesCache.splice(transparentIdx, 1);\r\n this._opaqueMeshesCache.push(mesh);\r\n } else if (opaqueIdx === -1) {\r\n this._opaqueMeshesCache.push(mesh);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Check if the opaque render target has not been disposed and can still be used.\r\n * @returns\r\n */\r\n public _isRenderTargetValid() {\r\n return this._opaqueRenderTarget?.getInternalTexture() !== null;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Setup the render targets according to the specified options.\r\n */\r\n public _setupRenderTargets(): void {\r\n if (this._opaqueRenderTarget) {\r\n this._opaqueRenderTarget.dispose();\r\n }\r\n this._opaqueRenderTarget = new RenderTargetTexture(\r\n \"opaqueSceneTexture\",\r\n this._options.renderSize,\r\n this._scene,\r\n this._options.generateMipmaps,\r\n undefined,\r\n this._options.renderTargetTextureType\r\n );\r\n this._opaqueRenderTarget.ignoreCameraViewport = true;\r\n this._opaqueRenderTarget.renderList = this._opaqueMeshesCache;\r\n this._opaqueRenderTarget.clearColor = this._options.clearColor?.clone() ?? this._scene.clearColor.clone();\r\n this._opaqueRenderTarget.gammaSpace = false;\r\n this._opaqueRenderTarget.lodGenerationScale = this._options.lodGenerationScale;\r\n this._opaqueRenderTarget.lodGenerationOffset = this._options.lodGenerationOffset;\r\n this._opaqueRenderTarget.samples = this._options.samples;\r\n this._opaqueRenderTarget.renderSprites = true;\r\n this._opaqueRenderTarget.renderParticles = true;\r\n\r\n let sceneImageProcessingapplyByPostProcess: boolean;\r\n\r\n let saveSceneEnvIntensity: number;\r\n this._opaqueRenderTarget.onBeforeBindObservable.add((opaqueRenderTarget) => {\r\n saveSceneEnvIntensity = this._scene.environmentIntensity;\r\n this._scene.environmentIntensity = 1.0;\r\n sceneImageProcessingapplyByPostProcess = this._scene.imageProcessingConfiguration.applyByPostProcess;\r\n if (!this._options.clearColor) {\r\n this._scene.clearColor.toLinearSpaceToRef(opaqueRenderTarget.clearColor, this._scene.getEngine().useExactSrgbConversions);\r\n } else {\r\n opaqueRenderTarget.clearColor.copyFrom(this._options.clearColor);\r\n }\r\n // we do not use the applyByPostProcess setter to avoid flagging all the materials as \"image processing dirty\"!\r\n this._scene.imageProcessingConfiguration._applyByPostProcess = true;\r\n });\r\n this._opaqueRenderTarget.onAfterUnbindObservable.add(() => {\r\n this._scene.environmentIntensity = saveSceneEnvIntensity;\r\n this._scene.imageProcessingConfiguration._applyByPostProcess = sceneImageProcessingapplyByPostProcess;\r\n });\r\n\r\n this._transparentMeshesCache.forEach((mesh: AbstractMesh) => {\r\n if (this._shouldRenderAsTransmission(mesh.material)) {\r\n (mesh.material as PBRMaterial).refractionTexture = this._opaqueRenderTarget;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Dispose all the elements created by the Helper.\r\n */\r\n public dispose(): void {\r\n this._scene._transmissionHelper = undefined;\r\n if (this._opaqueRenderTarget) {\r\n this._opaqueRenderTarget.dispose();\r\n this._opaqueRenderTarget = null;\r\n }\r\n this._transparentMeshesCache = [];\r\n this._opaqueMeshesCache = [];\r\n }\r\n}\r\n\r\nconst NAME = \"KHR_materials_transmission\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_transmission extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_transmission\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_transmission implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 175;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n loader.parent.transparencyAsCoverage = true;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsTransmission>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadTransparentPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsTransmission): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n const pbrMaterial = babylonMaterial as PBRMaterial;\r\n\r\n // Enables \"refraction\" texture which represents transmitted light.\r\n pbrMaterial.subSurface.isRefractionEnabled = true;\r\n\r\n // Since this extension models thin-surface transmission only, we must make IOR = 1.0\r\n pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;\r\n\r\n // Albedo colour will tint transmission.\r\n pbrMaterial.subSurface.useAlbedoToTintRefraction = true;\r\n\r\n if (extension.transmissionFactor !== undefined) {\r\n pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;\r\n const scene = pbrMaterial.getScene() as unknown as ITransmissionHelperHolder;\r\n if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {\r\n new TransmissionHelper({}, pbrMaterial.getScene());\r\n } else if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper?._isRenderTargetValid()) {\r\n // If the render target is not valid, recreate it.\r\n scene._transmissionHelper?._setupRenderTargets();\r\n }\r\n } else {\r\n pbrMaterial.subSurface.refractionIntensity = 0.0;\r\n pbrMaterial.subSurface.isRefractionEnabled = false;\r\n return Promise.resolve();\r\n }\r\n\r\n pbrMaterial.subSurface.minimumThickness = 0.0;\r\n pbrMaterial.subSurface.maximumThickness = 0.0;\r\n if (extension.transmissionTexture) {\r\n (extension.transmissionTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/transmissionTexture`, extension.transmissionTexture, undefined).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.refractionIntensityTexture = texture;\r\n pbrMaterial.subSurface.useGltfStyleTextures = true;\r\n });\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_transmission(loader));\r\n"]}
|
@@ -40,7 +40,6 @@ export class KHR_materials_volume {
|
|
40
40
|
loadMaterialPropertiesAsync(context, material, babylonMaterial) {
|
41
41
|
return GLTFLoader.LoadExtensionAsync(context, material, this.name, (extensionContext, extension) => {
|
42
42
|
const promises = new Array();
|
43
|
-
promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
44
43
|
promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
45
44
|
promises.push(this._loadVolumePropertiesAsync(extensionContext, material, babylonMaterial, extension));
|
46
45
|
return Promise.all(promises).then(() => { });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,sBAAsB,CAAC;AAapC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,oBAAoB;IAkB7B;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,qHAAqH;YACrH,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;IACL,CAAC;IAED,gBAAgB;IACT,OAAO;QACV,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;QACA,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kBAAkB,CAAsB,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE;YACpH,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAgB,CAAC;YAC3C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC
|
1
|
+
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,sBAAsB,CAAC;AAapC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,oBAAoB;IAkB7B;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAA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AAE,EAAE;gBAC9H,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,cAAc,CAAC;gBACrD,eAAe,CAAC,UAAU,CAAC,gBAAgB,GAAG,OAAO,CAAC;gBACtD,eAAe,CAAC,UAAU,CAAC,oBAAoB,GAAG,IAAI,CAAC;YAC3D,CAAC,CAAC,CAAC;SACN;aAAM;YACH,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC5B;IACL,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_volume extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_volume\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n * @since 5.0.0\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 173;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n // We need to disable instance usage because the attenuation factor depends on the node scale of each individual mesh\r\n this._loader._disableInstancedMesh++;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n if (this.enabled) {\r\n this._loader._disableInstancedMesh--;\r\n }\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsVolume>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadVolumePropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadVolumePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsVolume): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n // If transparency isn't enabled already, this extension shouldn't do anything.\r\n // i.e. it requires either the KHR_materials_transmission or KHR_materials_diffuse_transmission extensions.\r\n if ((!babylonMaterial.subSurface.isRefractionEnabled && !babylonMaterial.subSurface.isTranslucencyEnabled) || !extension.thicknessFactor) {\r\n return Promise.resolve();\r\n }\r\n\r\n // IOR in this extension only affects interior.\r\n babylonMaterial.subSurface.volumeIndexOfRefraction = babylonMaterial.indexOfRefraction;\r\n const attenuationDistance = extension.attenuationDistance !== undefined ? extension.attenuationDistance : Number.MAX_VALUE;\r\n babylonMaterial.subSurface.tintColorAtDistance = attenuationDistance;\r\n if (extension.attenuationColor !== undefined && extension.attenuationColor.length == 3) {\r\n babylonMaterial.subSurface.tintColor.copyFromFloats(extension.attenuationColor[0], extension.attenuationColor[1], extension.attenuationColor[2]);\r\n }\r\n\r\n babylonMaterial.subSurface.minimumThickness = 0.0;\r\n babylonMaterial.subSurface.maximumThickness = extension.thicknessFactor;\r\n babylonMaterial.subSurface.useThicknessAsDepth = true;\r\n if (extension.thicknessTexture) {\r\n (extension.thicknessTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/thicknessTexture`, extension.thicknessTexture).then((texture: BaseTexture) => {\r\n texture.name = `${babylonMaterial.name} (thickness)`;\r\n babylonMaterial.subSurface.thicknessTexture = texture;\r\n babylonMaterial.subSurface.useGltfStyleTextures = true;\r\n });\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_volume(loader));\r\n"]}
|
package/glTF/2.0/glTFLoader.js
CHANGED
@@ -1952,7 +1952,7 @@ export class GLTFLoader {
|
|
1952
1952
|
}
|
1953
1953
|
if (IsBase64DataUrl(uri)) {
|
1954
1954
|
const data = new Uint8Array(DecodeBase64UrlToBinary(uri));
|
1955
|
-
this.log(`${context}: Decoded ${uri.
|
1955
|
+
this.log(`${context}: Decoded ${uri.substring(0, 64)}... (${data.length} bytes)`);
|
1956
1956
|
return Promise.resolve(data);
|
1957
1957
|
}
|
1958
1958
|
this.log(`${context}: Loading ${uri}`);
|