@babylonjs/loaders 7.23.0 → 7.24.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/objFileLoader.d.ts +4 -5
- package/OBJ/objFileLoader.js +3 -4
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.metadata.d.ts +4 -0
- package/OBJ/objFileLoader.metadata.js +5 -0
- package/OBJ/objFileLoader.metadata.js.map +1 -0
- package/SPLAT/index.d.ts +1 -0
- package/SPLAT/index.js +1 -0
- package/SPLAT/index.js.map +1 -1
- package/SPLAT/splatFileLoader.d.ts +36 -29
- package/SPLAT/splatFileLoader.js +354 -52
- package/SPLAT/splatFileLoader.js.map +1 -1
- package/SPLAT/splatFileLoader.metadata.d.ts +11 -0
- package/SPLAT/splatFileLoader.metadata.js +10 -0
- package/SPLAT/splatFileLoader.metadata.js.map +1 -0
- package/SPLAT/splatLoadingOptions.d.ts +9 -0
- package/SPLAT/splatLoadingOptions.js +2 -0
- package/SPLAT/splatLoadingOptions.js.map +1 -0
- package/STL/stlFileLoader.d.ts +3 -4
- package/STL/stlFileLoader.js +3 -5
- package/STL/stlFileLoader.js.map +1 -1
- package/STL/stlFileLoader.metadata.d.ts +8 -0
- package/STL/stlFileLoader.metadata.js +8 -0
- package/STL/stlFileLoader.metadata.js.map +1 -0
- package/dynamic.d.ts +5 -0
- package/dynamic.js +48 -0
- package/dynamic.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +3 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +3 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +3 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_avif.js +3 -1
- package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +3 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +3 -2
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +3 -2
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +3 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_interactivity.d.ts +1 -1
- package/glTF/2.0/Extensions/KHR_interactivity.js +3 -2
- package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +3 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +3 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +3 -2
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +3 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +3 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +3 -2
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +3 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +3 -1
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +3 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +3 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/dynamic.d.ts +4 -0
- package/glTF/2.0/Extensions/dynamic.js +136 -0
- package/glTF/2.0/Extensions/dynamic.js.map +1 -0
- package/glTF/2.0/glTFLoader.d.ts +6 -6
- package/glTF/2.0/glTFLoader.js +24 -28
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtensionRegistry.d.ts +25 -0
- package/glTF/2.0/glTFLoaderExtensionRegistry.js +30 -0
- package/glTF/2.0/glTFLoaderExtensionRegistry.js.map +1 -0
- package/glTF/glTFFileLoader.d.ts +4 -6
- package/glTF/glTFFileLoader.js +9 -17
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFFileLoader.metadata.d.ts +13 -0
- package/glTF/glTFFileLoader.metadata.js +18 -0
- package/glTF/glTFFileLoader.metadata.js.map +1 -0
- package/package.json +3 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_pbrSpecularGlossiness.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"KHR_materials_pbrSpecularGlossiness.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAA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IAAI,CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,4BAA4B,EAAE,UAAU,CAAC,yBAAyB,EAAE,CAAC,OAAO,EAAE,EAAE;gBACxH,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,wBAAwB,CAAC;gBAC/D,eAAe,CAAC,mBAAmB,GAAG,OAAO,CAAC;gBAC9C,eAAe,CAAC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAC;YACxD,CAAC,CAAC,CACL,CAAC;YAEF,eAAe,CAAC,uCAAuC,GAAG,IAAI,CAAC;SAClE;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,mCAAmC,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\n\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsPbrSpecularGlossiness } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_pbrSpecularGlossiness\";\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_pbrSpecularGlossiness extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_pbrSpecularGlossiness\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_pbrSpecularGlossiness 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 = 200;\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<IKHRMaterialsPbrSpecularGlossiness>(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._loadSpecularGlossinessPropertiesAsync(extensionContext, extension, babylonMaterial));\r\n this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadSpecularGlossinessPropertiesAsync(context: string, properties: IKHRMaterialsPbrSpecularGlossiness, babylonMaterial: Material): 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 promises = new Array<Promise<any>>();\r\n\r\n babylonMaterial.metallic = null;\r\n babylonMaterial.roughness = null;\r\n\r\n if (properties.diffuseFactor) {\r\n babylonMaterial.albedoColor = Color3.FromArray(properties.diffuseFactor);\r\n babylonMaterial.alpha = properties.diffuseFactor[3];\r\n } else {\r\n babylonMaterial.albedoColor = Color3.White();\r\n }\r\n\r\n babylonMaterial.reflectivityColor = properties.specularFactor ? Color3.FromArray(properties.specularFactor) : Color3.White();\r\n babylonMaterial.microSurface = properties.glossinessFactor == undefined ? 1 : properties.glossinessFactor;\r\n\r\n if (properties.diffuseTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTexture`, properties.diffuseTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Diffuse)`;\r\n babylonMaterial.albedoTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (properties.specularGlossinessTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/specularGlossinessTexture`, properties.specularGlossinessTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Specular Glossiness)`;\r\n babylonMaterial.reflectivityTexture = texture;\r\n babylonMaterial.reflectivityTexture.hasAlpha = true;\r\n })\r\n );\r\n\r\n babylonMaterial.useMicroSurfaceFromReflectivityMapAlpha = true;\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_pbrSpecularGlossiness(loader));\r\n"]}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
2
2
|
import { GLTFLoader } from "../glTFLoader.js";
|
3
3
|
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
4
5
|
const NAME = "KHR_materials_sheen";
|
5
6
|
/**
|
6
7
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_sheen/README.md)
|
@@ -75,5 +76,6 @@ export class KHR_materials_sheen {
|
|
75
76
|
return Promise.all(promises).then(() => { });
|
76
77
|
}
|
77
78
|
}
|
78
|
-
|
79
|
+
unregisterGLTFExtension(NAME);
|
80
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_materials_sheen(loader));
|
79
81
|
//# sourceMappingURL=KHR_materials_sheen.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_sheen.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_sheen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,4CAA8B;
|
1
|
+
{"version":3,"file":"KHR_materials_sheen.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_sheen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAE/C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAanC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAkB5B;;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,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AE,EAAE,CAAC,IAAI,mBAAmB,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\n\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport type { IKHRMaterialsSheen } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_sheen\";\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_sheen extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_sheen\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_sheen/README.md)\r\n * [Playground Sample](https://www.babylonjs-playground.com/frame.html#BNIZX6#4)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_sheen 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 = 190;\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<IKHRMaterialsSheen>(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._loadSheenPropertiesAsync(extensionContext, extension, babylonMaterial));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadSheenPropertiesAsync(context: string, properties: IKHRMaterialsSheen, babylonMaterial: Material): 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 promises = new Array<Promise<any>>();\r\n\r\n babylonMaterial.sheen.isEnabled = true;\r\n babylonMaterial.sheen.intensity = 1;\r\n\r\n if (properties.sheenColorFactor != undefined) {\r\n babylonMaterial.sheen.color = Color3.FromArray(properties.sheenColorFactor);\r\n } else {\r\n babylonMaterial.sheen.color = Color3.Black();\r\n }\r\n\r\n if (properties.sheenColorTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/sheenColorTexture`, properties.sheenColorTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Sheen Color)`;\r\n babylonMaterial.sheen.texture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (properties.sheenRoughnessFactor !== undefined) {\r\n babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;\r\n } else {\r\n babylonMaterial.sheen.roughness = 0;\r\n }\r\n\r\n if (properties.sheenRoughnessTexture) {\r\n (properties.sheenRoughnessTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/sheenRoughnessTexture`, properties.sheenRoughnessTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Sheen Roughness)`;\r\n babylonMaterial.sheen.textureRoughness = texture;\r\n })\r\n );\r\n }\r\n\r\n babylonMaterial.sheen.albedoScaling = true;\r\n babylonMaterial.sheen.useRoughnessFromMainTexture = false;\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_sheen(loader));\r\n"]}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
2
2
|
import { GLTFLoader } from "../glTFLoader.js";
|
3
3
|
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
4
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
4
5
|
const NAME = "KHR_materials_specular";
|
5
6
|
/**
|
6
7
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md)
|
@@ -65,5 +66,6 @@ export class KHR_materials_specular {
|
|
65
66
|
return Promise.all(promises).then(() => { });
|
66
67
|
}
|
67
68
|
}
|
68
|
-
|
69
|
+
unregisterGLTFExtension(NAME);
|
70
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_materials_specular(loader));
|
69
71
|
//# sourceMappingURL=KHR_materials_specular.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_specular.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_specular.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,4CAA8B;
|
1
|
+
{"version":3,"file":"KHR_materials_specular.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_specular.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MA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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,sBAAsB,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\n\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport type { IKHRMaterialsSpecular } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_specular\";\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_specular extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_specular\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_specular 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 = 190;\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<IKHRMaterialsSpecular>(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._loadSpecularPropertiesAsync(extensionContext, extension, babylonMaterial));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadSpecularPropertiesAsync(context: string, properties: IKHRMaterialsSpecular, babylonMaterial: Material): 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 promises = new Array<Promise<any>>();\r\n\r\n if (properties.specularFactor !== undefined) {\r\n babylonMaterial.metallicF0Factor = properties.specularFactor;\r\n }\r\n\r\n if (properties.specularColorFactor !== undefined) {\r\n babylonMaterial.metallicReflectanceColor = Color3.FromArray(properties.specularColorFactor);\r\n }\r\n\r\n if (properties.specularTexture) {\r\n (properties.specularTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/specularTexture`, properties.specularTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Specular F0 Strength)`;\r\n babylonMaterial.metallicReflectanceTexture = texture;\r\n babylonMaterial.useOnlyMetallicFromMetallicReflectanceTexture = true;\r\n })\r\n );\r\n }\r\n\r\n if (properties.specularColorTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/specularColorTexture`, properties.specularColorTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Specular F0 Color)`;\r\n babylonMaterial.reflectanceTexture = 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_specular(loader));\r\n"]}
|
@@ -4,6 +4,7 @@ import { RenderTargetTexture } from "@babylonjs/core/Materials/Textures/renderTa
|
|
4
4
|
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
5
5
|
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
6
6
|
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
7
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
7
8
|
/**
|
8
9
|
* A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.
|
9
10
|
*/
|
@@ -300,5 +301,6 @@ export class KHR_materials_transmission {
|
|
300
301
|
}
|
301
302
|
}
|
302
303
|
}
|
303
|
-
|
304
|
+
unregisterGLTFExtension(NAME);
|
305
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_materials_transmission(loader));
|
304
306
|
//# sourceMappingURL=KHR_materials_transmission.js.map
|
@@ -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;AAgDxC;;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,EAA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AkD;gBAClD,KAAK,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,CAAC;aACpD;SACJ;aAAM;YACH,WAAW,CAAC,UAAU,CAAC,mBAAmB,GAAG,GAAG,CAAC;YACjD,WAAW,CAAC,UAAU,CAAC,mBAAmB,GAAG,KAAK,CAAC;YACnD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC5B;QAED,WAAW,CAAC,UAAU,CAAC,gBAAgB,GAAG,GAAG,CAAC;QAC9C,WAAW,CAAC,UAAU,CAAC,gBAAgB,GAAG,GAAG,CAAC;QAC9C,IAAI,SAAS,CAAC,mBAAmB,EAAE;YAC9B,SAAS,CAAC,mBAAoC,CAAC,YAAY,GAAG,IAAI,CAAC;YACpE,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,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,UAAU,CAAC,iBAAiB,CAAC,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\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\nGLTFLoader.RegisterExtension(NAME, (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,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,C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,OAAO,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,6 +1,7 @@
|
|
1
1
|
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
2
2
|
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
3
3
|
import { GLTFLoader } from "../glTFLoader.js";
|
4
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
4
5
|
const NAME = "KHR_materials_unlit";
|
5
6
|
/**
|
6
7
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_unlit/README.md)
|
@@ -64,5 +65,6 @@ export class KHR_materials_unlit {
|
|
64
65
|
return Promise.all(promises).then(() => { });
|
65
66
|
}
|
66
67
|
}
|
67
|
-
|
68
|
+
unregisterGLTFExtension(NAME);
|
69
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_materials_unlit(loader));
|
68
70
|
//# sourceMappingURL=KHR_materials_unlit.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_unlit.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_unlit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"KHR_materials_unlit.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_unlit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAanC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAkB5B;;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,CA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AC,IAAI,eAAe,CAAC;oBACtD,eAAe,CAAC,aAAa,GAAG,OAAO,CAAC;gBAC5C,CAAC,CAAC,CACL,CAAC;aACL;SACJ;QAED,IAAI,QAAQ,CAAC,WAAW,EAAE;YACtB,eAAe,CAAC,eAAe,GAAG,KAAK,CAAC;YACxC,eAAe,CAAC,gBAAgB,GAAG,IAAI,CAAC;SAC3C;QAED,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QAE7E,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,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\n\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_unlit\";\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_unlit extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_unlit\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_unlit/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_unlit 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 = 210;\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(context, material, this.name, () => {\r\n return this._loadUnlitPropertiesAsync(context, material, babylonMaterial);\r\n });\r\n }\r\n\r\n private _loadUnlitPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): 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 promises = new Array<Promise<any>>();\r\n babylonMaterial.unlit = true;\r\n\r\n const properties = material.pbrMetallicRoughness;\r\n if (properties) {\r\n if (properties.baseColorFactor) {\r\n babylonMaterial.albedoColor = Color3.FromArray(properties.baseColorFactor);\r\n babylonMaterial.alpha = properties.baseColorFactor[3];\r\n } else {\r\n babylonMaterial.albedoColor = Color3.White();\r\n }\r\n\r\n if (properties.baseColorTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/baseColorTexture`, properties.baseColorTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Base Color)`;\r\n babylonMaterial.albedoTexture = texture;\r\n })\r\n );\r\n }\r\n }\r\n\r\n if (material.doubleSided) {\r\n babylonMaterial.backFaceCulling = false;\r\n babylonMaterial.twoSidedLighting = true;\r\n }\r\n\r\n this._loader.loadMaterialAlphaProperties(context, material, babylonMaterial);\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_unlit(loader));\r\n"]}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
|
2
2
|
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
3
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
3
4
|
const NAME = "KHR_materials_variants";
|
4
5
|
/**
|
5
6
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_variants/README.md)
|
@@ -227,5 +228,6 @@ export class KHR_materials_variants {
|
|
227
228
|
});
|
228
229
|
}
|
229
230
|
}
|
230
|
-
|
231
|
+
unregisterGLTFExtension(NAME);
|
232
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_materials_variants(loader));
|
231
233
|
//# sourceMappingURL=KHR_materials_variants.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_variants.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_variants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAOxC,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAuBtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAe/B;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAA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CACJ;oCACD,KAAK,MAAM,MAAM,IAAI,QAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;wCACnD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;4CAC7B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;yCACzB;qCACJ;gCACL,CAAC,CAAC,CAAC;6BACN;wBACL,CAAC,CAAC,CACL,CAAC;qBACL;iBACJ;YACL,CAAC,CAAC,CACL,CAAC;YACF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;gBAChD,OAAO,WAAW,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Node } from \"core/node\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { INode, IMeshPrimitive, IMesh } from \"../glTFLoaderInterfaces\";\r\nimport type { IKHRMaterialVariants_Mapping, IKHRMaterialVariants_Variant, IKHRMaterialVariants_Variants } from \"babylonjs-gltf2interface\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\n\r\nconst NAME = \"KHR_materials_variants\";\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_variants extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_variants\"]: {};\r\n }\r\n}\r\n\r\ninterface IVariantsMap {\r\n [key: string]: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n}\r\n\r\ninterface IExtensionMetadata {\r\n lastSelected: Nullable<string | Array<string>>;\r\n original: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n variants: IVariantsMap;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_variants/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_variants 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\r\n private _variants?: Array<IKHRMaterialVariants_Variant>;\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 * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public static GetAvailableVariants(rootMesh: Mesh): string[] {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n return [];\r\n }\r\n\r\n return Object.keys(extensionMetadata.variants);\r\n }\r\n\r\n /**\r\n * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public getAvailableVariants(rootMesh: Mesh): string[] {\r\n return KHR_materials_variants.GetAvailableVariants(rootMesh);\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot select variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n const select = (variantName: string): void => {\r\n const entries = extensionMetadata.variants[variantName];\r\n if (entries) {\r\n for (const entry of entries) {\r\n entry.mesh.material = entry.material;\r\n }\r\n }\r\n };\r\n\r\n if (variantName instanceof Array) {\r\n for (const name of variantName) {\r\n select(name);\r\n }\r\n } else {\r\n select(variantName);\r\n }\r\n\r\n extensionMetadata.lastSelected = variantName;\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public selectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n KHR_materials_variants.SelectVariant(rootMesh, variantName);\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public static Reset(rootMesh: Mesh): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot reset on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n for (const entry of extensionMetadata.original) {\r\n entry.mesh.material = entry.material;\r\n }\r\n\r\n extensionMetadata.lastSelected = null;\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public reset(rootMesh: Mesh): void {\r\n KHR_materials_variants.Reset(rootMesh);\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot get the last selected variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n return extensionMetadata.lastSelected;\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n return KHR_materials_variants.GetLastSelectedVariant(rootMesh);\r\n }\r\n\r\n private static _GetExtensionMetadata(rootMesh: Nullable<TransformNode>): Nullable<IExtensionMetadata> {\r\n return rootMesh?._internalMetadata?.gltf?.[NAME] || null;\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 IKHRMaterialVariants_Variants;\r\n this._variants = extension.variants;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMeshPrimitiveAsync(\r\n context: string,\r\n name: string,\r\n node: INode,\r\n mesh: IMesh,\r\n primitive: IMeshPrimitive,\r\n assign: (babylonMesh: AbstractMesh) => void\r\n ): Nullable<Promise<AbstractMesh>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(\r\n this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, (babylonMesh) => {\r\n assign(babylonMesh);\r\n\r\n if (babylonMesh instanceof Mesh) {\r\n const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);\r\n\r\n const root = this._loader.rootBabylonMesh;\r\n const metadata = root ? (root._internalMetadata = root._internalMetadata || {}) : {};\r\n const gltf = (metadata.gltf = metadata.gltf || {});\r\n const extensionMetadata: IExtensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });\r\n\r\n // Store the original material.\r\n extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });\r\n\r\n // For each mapping, look at the variants and make a new entry for them.\r\n for (let mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {\r\n const mapping = extension.mappings[mappingIndex];\r\n const material = ArrayItem.Get(`${extensionContext}/mappings/${mappingIndex}/material`, this._loader.gltf.materials, mapping.material);\r\n promises.push(\r\n this._loader._loadMaterialAsync(`#/materials/${mapping.material}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n for (let mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {\r\n const variantIndex = mapping.variants[mappingVariantIndex];\r\n const variant = ArrayItem.Get(`/extensions/${NAME}/variants/${variantIndex}`, this._variants, variantIndex);\r\n extensionMetadata.variants[variant.name] = extensionMetadata.variants[variant.name] || [];\r\n extensionMetadata.variants[variant.name].push({\r\n mesh: babylonMesh,\r\n material: babylonMaterial,\r\n });\r\n\r\n // Replace the target when original mesh is cloned\r\n babylonMesh.onClonedObservable.add((newOne: Node) => {\r\n const newMesh = newOne as Mesh;\r\n let metadata: Nullable<IExtensionMetadata> = null;\r\n let newRoot: Nullable<Node> = newMesh;\r\n\r\n // Find root to get medata\r\n do {\r\n newRoot = newRoot!.parent;\r\n if (!newRoot) {\r\n return;\r\n }\r\n metadata = KHR_materials_variants._GetExtensionMetadata(newRoot as Mesh);\r\n } while (metadata === null);\r\n\r\n // Need to clone the metadata on the root (first time only)\r\n if (root && metadata === KHR_materials_variants._GetExtensionMetadata(root)) {\r\n // Copy main metadata\r\n newRoot._internalMetadata = {};\r\n for (const key in root._internalMetadata) {\r\n newRoot._internalMetadata[key] = root._internalMetadata[key];\r\n }\r\n\r\n // Copy the gltf metadata\r\n newRoot._internalMetadata.gltf = [];\r\n for (const key in root._internalMetadata.gltf) {\r\n newRoot._internalMetadata.gltf[key] = root._internalMetadata.gltf[key];\r\n }\r\n\r\n // Duplicate the extension specific metadata\r\n newRoot._internalMetadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };\r\n for (const original of metadata.original) {\r\n newRoot._internalMetadata.gltf[NAME].original.push({\r\n mesh: original.mesh,\r\n material: original.material,\r\n });\r\n }\r\n for (const key in metadata.variants) {\r\n if (Object.prototype.hasOwnProperty.call(metadata.variants, key)) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key] = [];\r\n for (const variantEntry of metadata.variants[key]) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key].push({\r\n mesh: variantEntry.mesh,\r\n material: variantEntry.material,\r\n });\r\n }\r\n }\r\n }\r\n\r\n metadata = newRoot._internalMetadata.gltf[NAME];\r\n }\r\n\r\n // Relocate\r\n for (const target of metadata!.original) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n for (const target of metadata!.variants[variant.name]) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n });\r\n }\r\n })\r\n );\r\n }\r\n }\r\n })\r\n );\r\n return Promise.all(promises).then(([babylonMesh]) => {\r\n return babylonMesh;\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_variants(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_materials_variants.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_variants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,IAAI,EAAE,uCAAyB;AAMxC,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAuBtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAe/B;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OA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AAC;yCACzB;qCACJ;oCACD,KAAK,MAAM,MAAM,IAAI,QAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;wCACnD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;4CAC7B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;yCACzB;qCACJ;gCACL,CAAC,CAAC,CAAC;6BACN;wBACL,CAAC,CAAC,CACL,CAAC;qBACL;iBACJ;YACL,CAAC,CAAC,CACL,CAAC;YACF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;gBAChD,OAAO,WAAW,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,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 type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Node } from \"core/node\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { INode, IMeshPrimitive, IMesh } from \"../glTFLoaderInterfaces\";\r\nimport type { IKHRMaterialVariants_Mapping, IKHRMaterialVariants_Variant, IKHRMaterialVariants_Variants } from \"babylonjs-gltf2interface\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_variants\";\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_variants extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_variants\"]: {};\r\n }\r\n}\r\n\r\ninterface IVariantsMap {\r\n [key: string]: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n}\r\n\r\ninterface IExtensionMetadata {\r\n lastSelected: Nullable<string | Array<string>>;\r\n original: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n variants: IVariantsMap;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_variants/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_variants 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\r\n private _variants?: Array<IKHRMaterialVariants_Variant>;\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 * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public static GetAvailableVariants(rootMesh: Mesh): string[] {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n return [];\r\n }\r\n\r\n return Object.keys(extensionMetadata.variants);\r\n }\r\n\r\n /**\r\n * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public getAvailableVariants(rootMesh: Mesh): string[] {\r\n return KHR_materials_variants.GetAvailableVariants(rootMesh);\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot select variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n const select = (variantName: string): void => {\r\n const entries = extensionMetadata.variants[variantName];\r\n if (entries) {\r\n for (const entry of entries) {\r\n entry.mesh.material = entry.material;\r\n }\r\n }\r\n };\r\n\r\n if (variantName instanceof Array) {\r\n for (const name of variantName) {\r\n select(name);\r\n }\r\n } else {\r\n select(variantName);\r\n }\r\n\r\n extensionMetadata.lastSelected = variantName;\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public selectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n KHR_materials_variants.SelectVariant(rootMesh, variantName);\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public static Reset(rootMesh: Mesh): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot reset on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n for (const entry of extensionMetadata.original) {\r\n entry.mesh.material = entry.material;\r\n }\r\n\r\n extensionMetadata.lastSelected = null;\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public reset(rootMesh: Mesh): void {\r\n KHR_materials_variants.Reset(rootMesh);\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot get the last selected variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n return extensionMetadata.lastSelected;\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n return KHR_materials_variants.GetLastSelectedVariant(rootMesh);\r\n }\r\n\r\n private static _GetExtensionMetadata(rootMesh: Nullable<TransformNode>): Nullable<IExtensionMetadata> {\r\n return rootMesh?._internalMetadata?.gltf?.[NAME] || null;\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 IKHRMaterialVariants_Variants;\r\n this._variants = extension.variants;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMeshPrimitiveAsync(\r\n context: string,\r\n name: string,\r\n node: INode,\r\n mesh: IMesh,\r\n primitive: IMeshPrimitive,\r\n assign: (babylonMesh: AbstractMesh) => void\r\n ): Nullable<Promise<AbstractMesh>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(\r\n this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, (babylonMesh) => {\r\n assign(babylonMesh);\r\n\r\n if (babylonMesh instanceof Mesh) {\r\n const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);\r\n\r\n const root = this._loader.rootBabylonMesh;\r\n const metadata = root ? (root._internalMetadata = root._internalMetadata || {}) : {};\r\n const gltf = (metadata.gltf = metadata.gltf || {});\r\n const extensionMetadata: IExtensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });\r\n\r\n // Store the original material.\r\n extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });\r\n\r\n // For each mapping, look at the variants and make a new entry for them.\r\n for (let mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {\r\n const mapping = extension.mappings[mappingIndex];\r\n const material = ArrayItem.Get(`${extensionContext}/mappings/${mappingIndex}/material`, this._loader.gltf.materials, mapping.material);\r\n promises.push(\r\n this._loader._loadMaterialAsync(`#/materials/${mapping.material}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n for (let mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {\r\n const variantIndex = mapping.variants[mappingVariantIndex];\r\n const variant = ArrayItem.Get(`/extensions/${NAME}/variants/${variantIndex}`, this._variants, variantIndex);\r\n extensionMetadata.variants[variant.name] = extensionMetadata.variants[variant.name] || [];\r\n extensionMetadata.variants[variant.name].push({\r\n mesh: babylonMesh,\r\n material: babylonMaterial,\r\n });\r\n\r\n // Replace the target when original mesh is cloned\r\n babylonMesh.onClonedObservable.add((newOne: Node) => {\r\n const newMesh = newOne as Mesh;\r\n let metadata: Nullable<IExtensionMetadata> = null;\r\n let newRoot: Nullable<Node> = newMesh;\r\n\r\n // Find root to get medata\r\n do {\r\n newRoot = newRoot!.parent;\r\n if (!newRoot) {\r\n return;\r\n }\r\n metadata = KHR_materials_variants._GetExtensionMetadata(newRoot as Mesh);\r\n } while (metadata === null);\r\n\r\n // Need to clone the metadata on the root (first time only)\r\n if (root && metadata === KHR_materials_variants._GetExtensionMetadata(root)) {\r\n // Copy main metadata\r\n newRoot._internalMetadata = {};\r\n for (const key in root._internalMetadata) {\r\n newRoot._internalMetadata[key] = root._internalMetadata[key];\r\n }\r\n\r\n // Copy the gltf metadata\r\n newRoot._internalMetadata.gltf = [];\r\n for (const key in root._internalMetadata.gltf) {\r\n newRoot._internalMetadata.gltf[key] = root._internalMetadata.gltf[key];\r\n }\r\n\r\n // Duplicate the extension specific metadata\r\n newRoot._internalMetadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };\r\n for (const original of metadata.original) {\r\n newRoot._internalMetadata.gltf[NAME].original.push({\r\n mesh: original.mesh,\r\n material: original.material,\r\n });\r\n }\r\n for (const key in metadata.variants) {\r\n if (Object.prototype.hasOwnProperty.call(metadata.variants, key)) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key] = [];\r\n for (const variantEntry of metadata.variants[key]) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key].push({\r\n mesh: variantEntry.mesh,\r\n material: variantEntry.material,\r\n });\r\n }\r\n }\r\n }\r\n\r\n metadata = newRoot._internalMetadata.gltf[NAME];\r\n }\r\n\r\n // Relocate\r\n for (const target of metadata!.original) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n for (const target of metadata!.variants[variant.name]) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n });\r\n }\r\n })\r\n );\r\n }\r\n }\r\n })\r\n );\r\n return Promise.all(promises).then(([babylonMesh]) => {\r\n return babylonMesh;\r\n });\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_variants(loader));\r\n"]}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
2
2
|
import { GLTFLoader } from "../glTFLoader.js";
|
3
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
3
4
|
const NAME = "KHR_materials_volume";
|
4
5
|
/**
|
5
6
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)
|
@@ -77,5 +78,6 @@ export class KHR_materials_volume {
|
|
77
78
|
}
|
78
79
|
}
|
79
80
|
}
|
80
|
-
|
81
|
+
unregisterGLTFExtension(NAME);
|
82
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_materials_volume(loader));
|
81
83
|
//# sourceMappingURL=KHR_materials_volume.js.map
|
@@ -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;
|
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;;O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C,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.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));\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"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
2
2
|
const NAME = "KHR_mesh_quantization";
|
3
3
|
/**
|
4
4
|
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
|
@@ -18,5 +18,6 @@ export class KHR_mesh_quantization {
|
|
18
18
|
/** @internal */
|
19
19
|
dispose() { }
|
20
20
|
}
|
21
|
-
|
21
|
+
unregisterGLTFExtension(NAME);
|
22
|
+
registerGLTFExtension(NAME, true, (loader) => new KHR_mesh_quantization(loader));
|
22
23
|
//# sourceMappingURL=KHR_mesh_quantization.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_mesh_quantization.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_mesh_quantization.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"KHR_mesh_quantization.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_mesh_quantization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAarC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAW9B;;OAEG;IACH,YAAY,MAAkB;QAb9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAWxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,gBAAgB;IACT,OAAO,KAAI,CAAC;CACtB;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport type { GLTFLoader } from \"../glTFLoader\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_mesh_quantization\";\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_mesh_quantization extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_mesh_quantization\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_mesh_quantization 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 * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this.enabled = loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {}\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_mesh_quantization(loader));\r\n"]}
|