@babylonjs/loaders 7.25.0 → 7.25.1
Sign up to get free protection for your applications and to get access to all the features.
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +2 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +1 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +1 -0
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +1 -0
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/package.json +3 -3
@@ -54,7 +54,7 @@ export class KHR_materials_clearcoat {
|
|
54
54
|
}
|
55
55
|
if (properties.clearcoatTexture) {
|
56
56
|
promises.push(this._loader.loadTextureInfoAsync(`${context}/clearcoatTexture`, properties.clearcoatTexture, (texture) => {
|
57
|
-
texture.name = `${babylonMaterial.name} (ClearCoat
|
57
|
+
texture.name = `${babylonMaterial.name} (ClearCoat)`;
|
58
58
|
babylonMaterial.clearCoat.texture = texture;
|
59
59
|
}));
|
60
60
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_clearcoat.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,E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CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,yBAAyB,EAAE,UAAU,CAAC,sBAAsB,EAAE,CAAC,OAAO,EAAE,EAAE;gBAClH,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,qBAAqB,CAAC;gBAC5D,eAAe,CAAC,SAAS,CAAC,WAAW,GAAG,OAAO,CAAC;YACpD,CAAC,CAAC,CACL,CAAC;YAEF,eAAe,CAAC,gBAAgB,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,oBAAoB,CAAC;YACpF,eAAe,CAAC,gBAAgB,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC,oBAAoB,CAAC;YACnF,IAAI,UAAU,CAAC,sBAAsB,CAAC,KAAK,IAAI,SAAS,EAAE;gBACtD,eAAe,CAAC,SAAS,CAAC,WAAY,CAAC,KAAK,GAAG,UAAU,CAAC,sBAAsB,CAAC,KAAK,CAAC;aAC1F;SACJ;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,uBAAuB,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 type { IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\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_clearcoat extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_clearcoat\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_clearcoat/README.md)\r\n * [Playground Sample](https://www.babylonjs-playground.com/frame.html#7F7PN6#8)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat 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<IKHRMaterialsClearcoat>(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._loadClearCoatPropertiesAsync(extensionContext, extension, babylonMaterial));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadClearCoatPropertiesAsync(context: string, properties: IKHRMaterialsClearcoat, 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.clearCoat.isEnabled = true;\r\n babylonMaterial.clearCoat.useRoughnessFromMainTexture = false;\r\n babylonMaterial.clearCoat.remapF0OnInterfaceChange = false;\r\n\r\n if (properties.clearcoatFactor != undefined) {\r\n babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;\r\n } else {\r\n babylonMaterial.clearCoat.intensity = 0;\r\n }\r\n\r\n if (properties.clearcoatTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/clearcoatTexture`, properties.clearcoatTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (ClearCoat)`;\r\n babylonMaterial.clearCoat.texture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (properties.clearcoatRoughnessFactor != undefined) {\r\n babylonMaterial.clearCoat.roughness = properties.clearcoatRoughnessFactor;\r\n } else {\r\n babylonMaterial.clearCoat.roughness = 0;\r\n }\r\n\r\n if (properties.clearcoatRoughnessTexture) {\r\n (properties.clearcoatRoughnessTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/clearcoatRoughnessTexture`, properties.clearcoatRoughnessTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (ClearCoat Roughness)`;\r\n babylonMaterial.clearCoat.textureRoughness = texture;\r\n })\r\n );\r\n }\r\n\r\n if (properties.clearcoatNormalTexture) {\r\n (properties.clearcoatNormalTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/clearcoatNormalTexture`, properties.clearcoatNormalTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (ClearCoat Normal)`;\r\n babylonMaterial.clearCoat.bumpTexture = texture;\r\n })\r\n );\r\n\r\n babylonMaterial.invertNormalMapX = !babylonMaterial.getScene().useRightHandedSystem;\r\n babylonMaterial.invertNormalMapY = babylonMaterial.getScene().useRightHandedSystem;\r\n if (properties.clearcoatNormalTexture.scale != undefined) {\r\n babylonMaterial.clearCoat.bumpTexture!.level = properties.clearcoatNormalTexture.scale;\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_clearcoat(loader));\r\n"]}
|
@@ -69,6 +69,7 @@ export class KHR_materials_diffuse_transmission {
|
|
69
69
|
if (extension.diffuseTransmissionTexture) {
|
70
70
|
extension.diffuseTransmissionTexture.nonColorData = true;
|
71
71
|
promises.push(this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionTexture`, extension.diffuseTransmissionTexture).then((texture) => {
|
72
|
+
texture.name = `${babylonMaterial.name} (Diffuse Transmission)`;
|
72
73
|
pbrMaterial.subSurface.translucencyIntensityTexture = texture;
|
73
74
|
}));
|
74
75
|
}
|
@@ -80,6 +81,7 @@ export class KHR_materials_diffuse_transmission {
|
|
80
81
|
}
|
81
82
|
if (extension.diffuseTransmissionColorTexture) {
|
82
83
|
promises.push(this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionColorTexture`, extension.diffuseTransmissionColorTexture).then((texture) => {
|
84
|
+
texture.name = `${babylonMaterial.name} (Diffuse Transmission Color)`;
|
83
85
|
pbrMaterial.subSurface.translucencyColorTexture = texture;
|
84
86
|
}));
|
85
87
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IA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AC;SACL;QAED,IAAI,SAAS,CAAC,8BAA8B,KAAK,SAAS,EAAE;YACxD,WAAW,CAAC,UAAU,CAAC,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;SACzG;aAAM;YACH,WAAW,CAAC,UAAU,CAAC,iBAAiB,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;SAC7D;QAED,IAAI,SAAS,CAAC,+BAA+B,EAAE;YAC3C,QAAQ,CAAC,IAAI,CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,kCAAkC,EAAE,SAAS,CAAC,+BAA+B,CAAC,CAAC,IAAI,CAAC,CAAC,OAAoB,EAAE,EAAE;gBACrJ,WAAW,CAAC,UAAU,CAAC,wBAAwB,GAAG,OAAO,CAAC;YAC9D,CAAC,CAAC,CACL,CAAC;SACL;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kCAAkC,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_diffuse_transmission extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_diffuse_transmission\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 174;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n loader.parent.transparencyAsCoverage = true;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsDiffuseTransmission>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadTranslucentPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsDiffuseTransmission): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n const pbrMaterial = babylonMaterial as PBRMaterial;\r\n\r\n // Enables \"translucency\" texture which represents diffusely-transmitted light.\r\n pbrMaterial.subSurface.isTranslucencyEnabled = true;\r\n\r\n // Since this extension models thin-surface transmission only, we must make the\r\n // internal IOR == 1.0 and set the thickness to 0.\r\n pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;\r\n pbrMaterial.subSurface.minimumThickness = 0.0;\r\n pbrMaterial.subSurface.maximumThickness = 0.0;\r\n\r\n // Tint color will be used for transmission.\r\n pbrMaterial.subSurface.useAlbedoToTintTranslucency = false;\r\n\r\n if (extension.diffuseTransmissionFactor !== undefined) {\r\n pbrMaterial.subSurface.translucencyIntensity = extension.diffuseTransmissionFactor;\r\n } else {\r\n pbrMaterial.subSurface.translucencyIntensity = 0.0;\r\n pbrMaterial.subSurface.isTranslucencyEnabled = false;\r\n return Promise.resolve();\r\n }\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n pbrMaterial.subSurface.useGltfStyleTextures = true;\r\n\r\n if (extension.diffuseTransmissionTexture) {\r\n (extension.diffuseTransmissionTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionTexture`, extension.diffuseTransmissionTexture).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.translucencyIntensityTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (extension.diffuseTransmissionColorFactor !== undefined) {\r\n pbrMaterial.subSurface.translucencyColor = Color3.FromArray(extension.diffuseTransmissionColorFactor);\r\n } else {\r\n pbrMaterial.subSurface.translucencyColor = Color3.White();\r\n }\r\n\r\n if (extension.diffuseTransmissionColorTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionColorTexture`, extension.diffuseTransmissionColorTexture).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.translucencyColorTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_diffuse_transmission(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAalD;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,kCAAkC;IAkB3C;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,MAAM,CAAC,MAAM,CAAC,sBAAsB,GAAG,IAAI,CAAC;SAC/C;IACL,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kBAAkB,CAAmC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,S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;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kCAAkC,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_diffuse_transmission extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_diffuse_transmission\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 174;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n loader.parent.transparencyAsCoverage = true;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsDiffuseTransmission>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadTranslucentPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsDiffuseTransmission): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n const pbrMaterial = babylonMaterial as PBRMaterial;\r\n\r\n // Enables \"translucency\" texture which represents diffusely-transmitted light.\r\n pbrMaterial.subSurface.isTranslucencyEnabled = true;\r\n\r\n // Since this extension models thin-surface transmission only, we must make the\r\n // internal IOR == 1.0 and set the thickness to 0.\r\n pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;\r\n pbrMaterial.subSurface.minimumThickness = 0.0;\r\n pbrMaterial.subSurface.maximumThickness = 0.0;\r\n\r\n // Tint color will be used for transmission.\r\n pbrMaterial.subSurface.useAlbedoToTintTranslucency = false;\r\n\r\n if (extension.diffuseTransmissionFactor !== undefined) {\r\n pbrMaterial.subSurface.translucencyIntensity = extension.diffuseTransmissionFactor;\r\n } else {\r\n pbrMaterial.subSurface.translucencyIntensity = 0.0;\r\n pbrMaterial.subSurface.isTranslucencyEnabled = false;\r\n return Promise.resolve();\r\n }\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n pbrMaterial.subSurface.useGltfStyleTextures = true;\r\n\r\n if (extension.diffuseTransmissionTexture) {\r\n (extension.diffuseTransmissionTexture as ITextureInfo).nonColorData = true;\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionTexture`, extension.diffuseTransmissionTexture).then((texture: BaseTexture) => {\r\n texture.name = `${babylonMaterial.name} (Diffuse Transmission)`;\r\n pbrMaterial.subSurface.translucencyIntensityTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (extension.diffuseTransmissionColorFactor !== undefined) {\r\n pbrMaterial.subSurface.translucencyColor = Color3.FromArray(extension.diffuseTransmissionColorFactor);\r\n } else {\r\n pbrMaterial.subSurface.translucencyColor = Color3.White();\r\n }\r\n\r\n if (extension.diffuseTransmissionColorTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionColorTexture`, extension.diffuseTransmissionColorTexture).then((texture: BaseTexture) => {\r\n texture.name = `${babylonMaterial.name} (Diffuse Transmission Color)`;\r\n pbrMaterial.subSurface.translucencyColorTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_diffuse_transmission(loader));\r\n"]}
|
@@ -49,7 +49,7 @@ export class KHR_materials_iridescence {
|
|
49
49
|
babylonMaterial.iridescence.maximumThickness = properties.iridescenceThicknessMaximum ?? 400;
|
50
50
|
if (properties.iridescenceTexture) {
|
51
51
|
promises.push(this._loader.loadTextureInfoAsync(`${context}/iridescenceTexture`, properties.iridescenceTexture, (texture) => {
|
52
|
-
texture.name = `${babylonMaterial.name} (Iridescence
|
52
|
+
texture.name = `${babylonMaterial.name} (Iridescence)`;
|
53
53
|
babylonMaterial.iridescence.texture = texture;
|
54
54
|
}));
|
55
55
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_iridescence.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_iridescence.ts"],"names":[],"mappings":"AACA,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,2BAA2B,CAAC;AAazC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,yBAAyB;IAkBlC;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kBAAkB,CAA2B,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE;YACzH,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAgB,CAAC;YAC3C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;YAC5F,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,+BAA+B,CA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AAC,CAAC,CACL,CAAC;SACL;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,yBAAyB,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 } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsIridescence } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_iridescence\";\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_iridescence extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_iridescence\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_iridescence/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_iridescence 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 = 195;\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<IKHRMaterialsIridescence>(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._loadIridescencePropertiesAsync(extensionContext, extension, babylonMaterial));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadIridescencePropertiesAsync(context: string, properties: IKHRMaterialsIridescence, 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.iridescence.isEnabled = true;\r\n\r\n babylonMaterial.iridescence.intensity = properties.iridescenceFactor ?? 0;\r\n babylonMaterial.iridescence.indexOfRefraction = properties.iridescenceIor ?? (properties as any).iridescenceIOR ?? 1.3;\r\n babylonMaterial.iridescence.minimumThickness = properties.iridescenceThicknessMinimum ?? 100;\r\n babylonMaterial.iridescence.maximumThickness = properties.iridescenceThicknessMaximum ?? 400;\r\n\r\n if (properties.iridescenceTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/iridescenceTexture`, properties.iridescenceTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Iridescence)`;\r\n babylonMaterial.iridescence.texture = texture;\r\n })\r\n );\r\n }\r\n\r\n if (properties.iridescenceThicknessTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/iridescenceThicknessTexture`, properties.iridescenceThicknessTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Iridescence Thickness)`;\r\n babylonMaterial.iridescence.thicknessTexture = 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_iridescence(loader));\r\n"]}
|
@@ -52,14 +52,14 @@ export class KHR_materials_specular {
|
|
52
52
|
if (properties.specularTexture) {
|
53
53
|
properties.specularTexture.nonColorData = true;
|
54
54
|
promises.push(this._loader.loadTextureInfoAsync(`${context}/specularTexture`, properties.specularTexture, (texture) => {
|
55
|
-
texture.name = `${babylonMaterial.name} (Specular
|
55
|
+
texture.name = `${babylonMaterial.name} (Specular)`;
|
56
56
|
babylonMaterial.metallicReflectanceTexture = texture;
|
57
57
|
babylonMaterial.useOnlyMetallicFromMetallicReflectanceTexture = true;
|
58
58
|
}));
|
59
59
|
}
|
60
60
|
if (properties.specularColorTexture) {
|
61
61
|
promises.push(this._loader.loadTextureInfoAsync(`${context}/specularColorTexture`, properties.specularColorTexture, (texture) => {
|
62
|
-
texture.name = `${babylonMaterial.name} (Specular
|
62
|
+
texture.name = `${babylonMaterial.name} (Specular Color)`;
|
63
63
|
babylonMaterial.reflectanceTexture = texture;
|
64
64
|
}));
|
65
65
|
}
|
@@ -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;AAE/C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAatC;;GAEG;AACH,gEAAgE;AAChE,MAAM,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S,EAAE;YACzC,eAAe,CAAC,gBAAgB,GAAG,UAAU,CAAC,cAAc,CAAC;SAChE;QAED,IAAI,UAAU,CAAC,mBAAmB,KAAK,SAAS,EAAE;YAC9C,eAAe,CAAC,wBAAwB,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;SAC/F;QAED,IAAI,UAAU,CAAC,eAAe,EAAE;YAC3B,UAAU,CAAC,eAAgC,CAAC,YAAY,GAAG,IAAI,CAAC;YACjE,QAAQ,CAAC,IAAI,CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE;gBACpG,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,
|
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;AAE/C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAatC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAkB/B;;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,CA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CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE;gBACpG,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,aAAa,CAAC;gBACpD,eAAe,CAAC,0BAA0B,GAAG,OAAO,CAAC;gBACrD,eAAe,CAAC,6CAA6C,GAAG,IAAI,CAAC;YACzE,CAAC,CAAC,CACL,CAAC;SACL;QAED,IAAI,UAAU,CAAC,oBAAoB,EAAE;YACjC,QAAQ,CAAC,IAAI,CACT,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC9G,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,mBAAmB,CAAC;gBAC1D,eAAe,CAAC,kBAAkB,GAAG,OAAO,CAAC;YACjD,CAAC,CAAC,CACL,CAAC;SACL;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,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)`;\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 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"]}
|
@@ -291,6 +291,7 @@ export class KHR_materials_transmission {
|
|
291
291
|
if (extension.transmissionTexture) {
|
292
292
|
extension.transmissionTexture.nonColorData = true;
|
293
293
|
return this._loader.loadTextureInfoAsync(`${context}/transmissionTexture`, extension.transmissionTexture, undefined).then((texture) => {
|
294
|
+
texture.name = `${babylonMaterial.name} (Transmission)`;
|
294
295
|
pbrMaterial.subSurface.refractionIntensityTexture = texture;
|
295
296
|
pbrMaterial.subSurface.useGltfStyleTextures = true;
|
296
297
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/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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.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadTransparentPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsTransmission): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n const pbrMaterial = babylonMaterial as PBRMaterial;\r\n\r\n // Enables \"refraction\" texture which represents transmitted light.\r\n pbrMaterial.subSurface.isRefractionEnabled = true;\r\n\r\n // Since this extension models thin-surface transmission only, we must make IOR = 1.0\r\n pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;\r\n\r\n // Albedo colour will tint transmission.\r\n pbrMaterial.subSurface.useAlbedoToTintRefraction = true;\r\n\r\n if (extension.transmissionFactor !== undefined) {\r\n pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;\r\n const scene = pbrMaterial.getScene() as unknown as ITransmissionHelperHolder;\r\n if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {\r\n new TransmissionHelper({}, pbrMaterial.getScene());\r\n } else if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper?._isRenderTargetValid()) {\r\n // If the render target is not valid, recreate it.\r\n scene._transmissionHelper?._setupRenderTargets();\r\n }\r\n } else {\r\n pbrMaterial.subSurface.refractionIntensity = 0.0;\r\n pbrMaterial.subSurface.isRefractionEnabled = false;\r\n return Promise.resolve();\r\n }\r\n\r\n pbrMaterial.subSurface.minimumThickness = 0.0;\r\n pbrMaterial.subSurface.maximumThickness = 0.0;\r\n if (extension.transmissionTexture) {\r\n (extension.transmissionTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/transmissionTexture`, extension.transmissionTexture, undefined).then((texture: BaseTexture) => {\r\n pbrMaterial.subSurface.refractionIntensityTexture = texture;\r\n pbrMaterial.subSurface.useGltfStyleTextures = true;\r\n });\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_transmission(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_transmission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,EAAE,mBAAmB,EAAE,kEAAoD;AAElF,OAAO,EAAE,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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AU,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,OAAO,CAAC,IAAI,GAAG,GAAG,eAAe,CAAC,IAAI,iBAAiB,CAAC;gBACxD,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.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 texture.name = `${babylonMaterial.name} (Transmission)`;\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"]}
|
@@ -67,7 +67,7 @@ export class KHR_materials_volume {
|
|
67
67
|
if (extension.thicknessTexture) {
|
68
68
|
extension.thicknessTexture.nonColorData = true;
|
69
69
|
return this._loader.loadTextureInfoAsync(`${context}/thicknessTexture`, extension.thicknessTexture).then((texture) => {
|
70
|
-
texture.name = `${babylonMaterial.name} (
|
70
|
+
texture.name = `${babylonMaterial.name} (Thickness)`;
|
71
71
|
babylonMaterial.subSurface.thicknessTexture = texture;
|
72
72
|
babylonMaterial.subSurface.useGltfStyleTextures = true;
|
73
73
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,sBAAsB,CAAC;AAapC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,oBAAoB;IAkB7B;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,qHAAqH;YACrH,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;IACL,CAAC;IAED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AAE,CAAC;SAC5B;IACL,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_volume extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_volume\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n * @since 5.0.0\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 173;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n // We need to disable instance usage because the attenuation factor depends on the node scale of each individual mesh\r\n this._loader._disableInstancedMesh++;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n if (this.enabled) {\r\n this._loader._disableInstancedMesh--;\r\n }\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsVolume>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadVolumePropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadVolumePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsVolume): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n // If transparency isn't enabled already, this extension shouldn't do anything.\r\n // i.e. it requires either the KHR_materials_transmission or KHR_materials_diffuse_transmission extensions.\r\n if ((!babylonMaterial.subSurface.isRefractionEnabled && !babylonMaterial.subSurface.isTranslucencyEnabled) || !extension.thicknessFactor) {\r\n return Promise.resolve();\r\n }\r\n\r\n // IOR in this extension only affects interior.\r\n babylonMaterial.subSurface.volumeIndexOfRefraction = babylonMaterial.indexOfRefraction;\r\n const attenuationDistance = extension.attenuationDistance !== undefined ? extension.attenuationDistance : Number.MAX_VALUE;\r\n babylonMaterial.subSurface.tintColorAtDistance = attenuationDistance;\r\n if (extension.attenuationColor !== undefined && extension.attenuationColor.length == 3) {\r\n babylonMaterial.subSurface.tintColor.copyFromFloats(extension.attenuationColor[0], extension.attenuationColor[1], extension.attenuationColor[2]);\r\n }\r\n\r\n babylonMaterial.subSurface.minimumThickness = 0.0;\r\n babylonMaterial.subSurface.maximumThickness = extension.thicknessFactor;\r\n babylonMaterial.subSurface.useThicknessAsDepth = true;\r\n if (extension.thicknessTexture) {\r\n (extension.thicknessTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/thicknessTexture`, extension.thicknessTexture).then((texture: BaseTexture) => {\r\n texture.name = `${babylonMaterial.name} (
|
1
|
+
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,sBAAsB,CAAC;AAapC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,oBAAoB;IAkB7B;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,qHAAqH;YACrH,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;IACL,CAAC;IAED,gBAAgB;IACT,OAAO;QACV,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;QACA,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,2BAA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,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the KHR_materials_volume extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"KHR_materials_volume\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n * @since 5.0.0\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 173;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n // We need to disable instance usage because the attenuation factor depends on the node scale of each individual mesh\r\n this._loader._disableInstancedMesh++;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n if (this.enabled) {\r\n this._loader._disableInstancedMesh--;\r\n }\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsVolume>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadVolumePropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadVolumePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsVolume): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n // If transparency isn't enabled already, this extension shouldn't do anything.\r\n // i.e. it requires either the KHR_materials_transmission or KHR_materials_diffuse_transmission extensions.\r\n if ((!babylonMaterial.subSurface.isRefractionEnabled && !babylonMaterial.subSurface.isTranslucencyEnabled) || !extension.thicknessFactor) {\r\n return Promise.resolve();\r\n }\r\n\r\n // IOR in this extension only affects interior.\r\n babylonMaterial.subSurface.volumeIndexOfRefraction = babylonMaterial.indexOfRefraction;\r\n const attenuationDistance = extension.attenuationDistance !== undefined ? extension.attenuationDistance : Number.MAX_VALUE;\r\n babylonMaterial.subSurface.tintColorAtDistance = attenuationDistance;\r\n if (extension.attenuationColor !== undefined && extension.attenuationColor.length == 3) {\r\n babylonMaterial.subSurface.tintColor.copyFromFloats(extension.attenuationColor[0], extension.attenuationColor[1], extension.attenuationColor[2]);\r\n }\r\n\r\n babylonMaterial.subSurface.minimumThickness = 0.0;\r\n babylonMaterial.subSurface.maximumThickness = extension.thicknessFactor;\r\n babylonMaterial.subSurface.useThicknessAsDepth = true;\r\n if (extension.thicknessTexture) {\r\n (extension.thicknessTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/thicknessTexture`, extension.thicknessTexture).then((texture: BaseTexture) => {\r\n texture.name = `${babylonMaterial.name} (Thickness)`;\r\n babylonMaterial.subSurface.thicknessTexture = texture;\r\n babylonMaterial.subSurface.useGltfStyleTextures = true;\r\n });\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new KHR_materials_volume(loader));\r\n"]}
|
@@ -4,6 +4,7 @@ import type { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
|
4
4
|
import type { IScene, INode, IAnimation } from "../glTFLoaderInterfaces";
|
5
5
|
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension";
|
6
6
|
import { GLTFLoader } from "../glTFLoader";
|
7
|
+
import "@babylonjs/core/Audio/audioSceneComponent.js";
|
7
8
|
declare module "../../glTFFileLoader" {
|
8
9
|
interface GLTFLoaderExtensionOptions {
|
9
10
|
/**
|
@@ -5,6 +5,7 @@ import { Sound } from "@babylonjs/core/Audio/sound.js";
|
|
5
5
|
import { WeightedSound } from "@babylonjs/core/Audio/weightedsound.js";
|
6
6
|
import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
|
7
7
|
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
8
|
+
import "@babylonjs/core/Audio/audioSceneComponent.js";
|
8
9
|
const NAME = "MSFT_audio_emitter";
|
9
10
|
/**
|
10
11
|
* [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OA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AC3D,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,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,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { AnimationEvent } from \"core/Animations/animationEvent\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { Sound } from \"core/Audio/sound\";\r\nimport { WeightedSound } from \"core/Audio/weightedsound\";\r\n\r\nimport type { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent } from \"babylonjs-gltf2interface\";\r\nimport { IMSFTAudioEmitter_AnimationEventAction } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"MSFT_audio_emitter\";\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 MSFT_audio_emitter extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"MSFT_audio_emitter\"]: {};\r\n }\r\n}\r\n\r\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\r\n _objectURL?: Promise<string>;\r\n}\r\n\r\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\r\n _babylonData?: {\r\n sound?: WeightedSound;\r\n loaded: Promise<void>;\r\n };\r\n _babylonSounds: Sound[];\r\n}\r\n\r\ninterface IMSFTAudioEmitter {\r\n clips: ILoaderClip[];\r\n emitters: ILoaderEmitter[];\r\n}\r\n\r\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {}\r\n\r\ninterface ILoaderAnimationEvents {\r\n events: ILoaderAnimationEvent[];\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_audio_emitter implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _clips: Array<ILoaderClip>;\r\n private _emitters: Array<ILoaderEmitter>;\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 (this._clips as any) = null;\r\n (this._emitters as any) = 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 IMSFTAudioEmitter;\r\n\r\n this._clips = extension.clips;\r\n this._emitters = extension.emitters;\r\n\r\n ArrayItem.Assign(this._clips);\r\n ArrayItem.Assign(this._emitters);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n if (\r\n emitter.refDistance != undefined ||\r\n emitter.maxDistance != undefined ||\r\n emitter.rolloffFactor != undefined ||\r\n emitter.distanceModel != undefined ||\r\n emitter.innerAngle != undefined ||\r\n emitter.outerAngle != undefined\r\n ) {\r\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\r\n }\r\n\r\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n return this._loader\r\n .loadNodeAsync(extensionContext, node, (babylonMesh) => {\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n promises.push(\r\n this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\r\n for (const sound of emitter._babylonSounds) {\r\n sound.attachToMesh(babylonMesh);\r\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\r\n sound.setLocalDirectionToMesh(Vector3.Forward());\r\n sound.setDirectionalCone(\r\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\r\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\r\n 0\r\n );\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n assign(babylonMesh);\r\n })\r\n .then((babylonMesh) => {\r\n return Promise.all(promises).then(() => {\r\n return babylonMesh;\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\r\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n ArrayItem.Assign(extension.events);\r\n for (const event of extension.events) {\r\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return babylonAnimationGroup;\r\n });\r\n });\r\n });\r\n }\r\n\r\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\r\n if (clip._objectURL) {\r\n return clip._objectURL;\r\n }\r\n\r\n let promise: Promise<ArrayBufferView>;\r\n if (clip.uri) {\r\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\r\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n\r\n clip._objectURL = promise.then((data) => {\r\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\r\n });\r\n\r\n return clip._objectURL;\r\n }\r\n\r\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\r\n emitter._babylonSounds = emitter._babylonSounds || [];\r\n if (!emitter._babylonData) {\r\n const clipPromises = new Array<Promise<any>>();\r\n const name = emitter.name || `emitter${emitter.index}`;\r\n const options = {\r\n loop: false,\r\n autoplay: false,\r\n volume: emitter.volume == undefined ? 1 : emitter.volume,\r\n };\r\n\r\n for (let i = 0; i < emitter.clips.length; i++) {\r\n const clipContext = `/extensions/${this.name}/clips`;\r\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\r\n clipPromises.push(\r\n this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\r\n const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));\r\n sound.refDistance = emitter.refDistance || 1;\r\n sound.maxDistance = emitter.maxDistance || 256;\r\n sound.rolloffFactor = emitter.rolloffFactor || 1;\r\n sound.distanceModel = emitter.distanceModel || \"exponential\";\r\n })\r\n );\r\n }\r\n\r\n const promise = Promise.all(clipPromises).then(() => {\r\n const weights = emitter.clips.map((clip) => {\r\n return clip.weight || 1;\r\n });\r\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\r\n if (emitter.innerAngle) {\r\n weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);\r\n }\r\n if (emitter.outerAngle) {\r\n weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);\r\n }\r\n if (emitter.volume) {\r\n weightedSound.volume = emitter.volume;\r\n }\r\n emitter._babylonData!.sound = weightedSound;\r\n });\r\n\r\n emitter._babylonData = {\r\n loaded: promise,\r\n };\r\n }\r\n\r\n return emitter._babylonData.loaded;\r\n }\r\n\r\n private _getEventAction(\r\n context: string,\r\n sound: WeightedSound,\r\n action: IMSFTAudioEmitter_AnimationEventAction,\r\n time: number,\r\n startOffset?: number\r\n ): (currentFrame: number) => void {\r\n switch (action) {\r\n case IMSFTAudioEmitter_AnimationEventAction.play: {\r\n return (currentFrame: number) => {\r\n const frameOffset = (startOffset || 0) + (currentFrame - time);\r\n sound.play(frameOffset);\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\r\n return () => {\r\n sound.stop();\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\r\n return () => {\r\n sound.pause();\r\n };\r\n }\r\n default: {\r\n throw new Error(`${context}: Unsupported action ${action}`);\r\n }\r\n }\r\n }\r\n\r\n private _loadAnimationEventAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n event: ILoaderAnimationEvent,\r\n babylonAnimationGroup: AnimationGroup\r\n ): Promise<void> {\r\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\r\n return Promise.resolve();\r\n }\r\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\r\n const emitterIndex = event.emitter;\r\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\r\n return this._loadEmitterAsync(context, emitter).then(() => {\r\n const sound = emitter._babylonData!.sound;\r\n if (sound) {\r\n const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\r\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\r\n // Make sure all started audio stops when this animation is terminated.\r\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\r\n sound.stop();\r\n });\r\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\r\n sound.pause();\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new MSFT_audio_emitter(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAEhE,OAAO,EAAE,KAAK,EAAE,uCAAyB;AACzC,OAAO,EAAE,aAAa,EAAE,+CAAiC;AAIzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,O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AAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { AnimationEvent } from \"core/Animations/animationEvent\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { Sound } from \"core/Audio/sound\";\r\nimport { WeightedSound } from \"core/Audio/weightedsound\";\r\n\r\nimport type { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent } from \"babylonjs-gltf2interface\";\r\nimport { IMSFTAudioEmitter_AnimationEventAction } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nimport \"core/Audio/audioSceneComponent\";\r\n\r\nconst NAME = \"MSFT_audio_emitter\";\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 MSFT_audio_emitter extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"MSFT_audio_emitter\"]: {};\r\n }\r\n}\r\n\r\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\r\n _objectURL?: Promise<string>;\r\n}\r\n\r\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\r\n _babylonData?: {\r\n sound?: WeightedSound;\r\n loaded: Promise<void>;\r\n };\r\n _babylonSounds: Sound[];\r\n}\r\n\r\ninterface IMSFTAudioEmitter {\r\n clips: ILoaderClip[];\r\n emitters: ILoaderEmitter[];\r\n}\r\n\r\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {}\r\n\r\ninterface ILoaderAnimationEvents {\r\n events: ILoaderAnimationEvent[];\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_audio_emitter implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _clips: Array<ILoaderClip>;\r\n private _emitters: Array<ILoaderEmitter>;\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 (this._clips as any) = null;\r\n (this._emitters as any) = 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 IMSFTAudioEmitter;\r\n\r\n this._clips = extension.clips;\r\n this._emitters = extension.emitters;\r\n\r\n ArrayItem.Assign(this._clips);\r\n ArrayItem.Assign(this._emitters);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n if (\r\n emitter.refDistance != undefined ||\r\n emitter.maxDistance != undefined ||\r\n emitter.rolloffFactor != undefined ||\r\n emitter.distanceModel != undefined ||\r\n emitter.innerAngle != undefined ||\r\n emitter.outerAngle != undefined\r\n ) {\r\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\r\n }\r\n\r\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n return this._loader\r\n .loadNodeAsync(extensionContext, node, (babylonMesh) => {\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n promises.push(\r\n this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\r\n for (const sound of emitter._babylonSounds) {\r\n sound.attachToMesh(babylonMesh);\r\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\r\n sound.setLocalDirectionToMesh(Vector3.Forward());\r\n sound.setDirectionalCone(\r\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\r\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\r\n 0\r\n );\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n assign(babylonMesh);\r\n })\r\n .then((babylonMesh) => {\r\n return Promise.all(promises).then(() => {\r\n return babylonMesh;\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\r\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n ArrayItem.Assign(extension.events);\r\n for (const event of extension.events) {\r\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return babylonAnimationGroup;\r\n });\r\n });\r\n });\r\n }\r\n\r\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\r\n if (clip._objectURL) {\r\n return clip._objectURL;\r\n }\r\n\r\n let promise: Promise<ArrayBufferView>;\r\n if (clip.uri) {\r\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\r\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n\r\n clip._objectURL = promise.then((data) => {\r\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\r\n });\r\n\r\n return clip._objectURL;\r\n }\r\n\r\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\r\n emitter._babylonSounds = emitter._babylonSounds || [];\r\n if (!emitter._babylonData) {\r\n const clipPromises = new Array<Promise<any>>();\r\n const name = emitter.name || `emitter${emitter.index}`;\r\n const options = {\r\n loop: false,\r\n autoplay: false,\r\n volume: emitter.volume == undefined ? 1 : emitter.volume,\r\n };\r\n\r\n for (let i = 0; i < emitter.clips.length; i++) {\r\n const clipContext = `/extensions/${this.name}/clips`;\r\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\r\n clipPromises.push(\r\n this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\r\n const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));\r\n sound.refDistance = emitter.refDistance || 1;\r\n sound.maxDistance = emitter.maxDistance || 256;\r\n sound.rolloffFactor = emitter.rolloffFactor || 1;\r\n sound.distanceModel = emitter.distanceModel || \"exponential\";\r\n })\r\n );\r\n }\r\n\r\n const promise = Promise.all(clipPromises).then(() => {\r\n const weights = emitter.clips.map((clip) => {\r\n return clip.weight || 1;\r\n });\r\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\r\n if (emitter.innerAngle) {\r\n weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);\r\n }\r\n if (emitter.outerAngle) {\r\n weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);\r\n }\r\n if (emitter.volume) {\r\n weightedSound.volume = emitter.volume;\r\n }\r\n emitter._babylonData!.sound = weightedSound;\r\n });\r\n\r\n emitter._babylonData = {\r\n loaded: promise,\r\n };\r\n }\r\n\r\n return emitter._babylonData.loaded;\r\n }\r\n\r\n private _getEventAction(\r\n context: string,\r\n sound: WeightedSound,\r\n action: IMSFTAudioEmitter_AnimationEventAction,\r\n time: number,\r\n startOffset?: number\r\n ): (currentFrame: number) => void {\r\n switch (action) {\r\n case IMSFTAudioEmitter_AnimationEventAction.play: {\r\n return (currentFrame: number) => {\r\n const frameOffset = (startOffset || 0) + (currentFrame - time);\r\n sound.play(frameOffset);\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\r\n return () => {\r\n sound.stop();\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\r\n return () => {\r\n sound.pause();\r\n };\r\n }\r\n default: {\r\n throw new Error(`${context}: Unsupported action ${action}`);\r\n }\r\n }\r\n }\r\n\r\n private _loadAnimationEventAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n event: ILoaderAnimationEvent,\r\n babylonAnimationGroup: AnimationGroup\r\n ): Promise<void> {\r\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\r\n return Promise.resolve();\r\n }\r\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\r\n const emitterIndex = event.emitter;\r\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\r\n return this._loadEmitterAsync(context, emitter).then(() => {\r\n const sound = emitter._babylonData!.sound;\r\n if (sound) {\r\n const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\r\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\r\n // Make sure all started audio stops when this animation is terminated.\r\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\r\n sound.stop();\r\n });\r\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\r\n sound.pause();\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new MSFT_audio_emitter(loader));\r\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babylonjs/loaders",
|
3
|
-
"version": "7.25.
|
3
|
+
"version": "7.25.1",
|
4
4
|
"main": "index.js",
|
5
5
|
"module": "index.js",
|
6
6
|
"types": "index.d.ts",
|
@@ -18,10 +18,10 @@
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
19
19
|
},
|
20
20
|
"devDependencies": {
|
21
|
-
"@babylonjs/core": "^7.25.
|
21
|
+
"@babylonjs/core": "^7.25.1",
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
23
23
|
"@lts/loaders": "^1.0.0",
|
24
|
-
"babylonjs-gltf2interface": "^7.25.
|
24
|
+
"babylonjs-gltf2interface": "^7.25.1"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
27
27
|
"@babylonjs/core": "^7.0.0",
|