UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

102 lines (99 loc) 4.76 kB
import { bM as PBRMaterial, aH as Color3, bJ as unregisterGLTFExtension, bI as registerGLTFExtension } from './index-FzOfPXLV.esm.js'; import { GLTFLoader } from './glTFLoader-VVyk3AwX.esm.js'; import './bone--mL3H5cQ.esm.js'; import './skeleton-B7-ffRm_.esm.js'; import './rawTexture-B2DimmQ5.esm.js'; import './assetContainer-8JZnoDWQ.esm.js'; import './objectModelMapping-CJnQ6at_.esm.js'; const NAME = "KHR_materials_diffuse_transmission"; /** * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825) * !!! Experimental Extension Subject to Changes !!! */ // eslint-disable-next-line @typescript-eslint/naming-convention class KHR_materials_diffuse_transmission { /** * @internal */ constructor(loader) { /** * The name of this extension. */ this.name = NAME; /** * Defines a number that determines the order the extensions are applied. */ this.order = 174; this._loader = loader; this.enabled = this._loader.isExtensionUsed(NAME); if (this.enabled) { loader.parent.transparencyAsCoverage = true; } } /** @internal */ dispose() { this._loader = null; } /** * @internal */ // eslint-disable-next-line no-restricted-syntax loadMaterialPropertiesAsync(context, material, babylonMaterial) { return GLTFLoader.LoadExtensionAsync(context, material, this.name, async (extensionContext, extension) => { const promises = new Array(); promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial)); promises.push(this._loadTranslucentPropertiesAsync(extensionContext, material, babylonMaterial, extension)); return await Promise.all(promises).then(() => { }); }); } // eslint-disable-next-line no-restricted-syntax, @typescript-eslint/promise-function-async _loadTranslucentPropertiesAsync(context, material, babylonMaterial, extension) { if (!(babylonMaterial instanceof PBRMaterial)) { throw new Error(`${context}: Material type not supported`); } const pbrMaterial = babylonMaterial; // Enables "translucency" texture which represents diffusely-transmitted light. pbrMaterial.subSurface.isTranslucencyEnabled = true; // Since this extension models thin-surface transmission only, we must make the // internal IOR == 1.0 and set the thickness to 0. pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0; pbrMaterial.subSurface.minimumThickness = 0.0; pbrMaterial.subSurface.maximumThickness = 0.0; // Tint color will be used for transmission. pbrMaterial.subSurface.useAlbedoToTintTranslucency = false; if (extension.diffuseTransmissionFactor !== undefined) { pbrMaterial.subSurface.translucencyIntensity = extension.diffuseTransmissionFactor; } else { pbrMaterial.subSurface.translucencyIntensity = 0.0; pbrMaterial.subSurface.isTranslucencyEnabled = false; return Promise.resolve(); } const promises = new Array(); pbrMaterial.subSurface.useGltfStyleTextures = true; if (extension.diffuseTransmissionTexture) { extension.diffuseTransmissionTexture.nonColorData = true; promises.push(this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionTexture`, extension.diffuseTransmissionTexture).then((texture) => { texture.name = `${babylonMaterial.name} (Diffuse Transmission)`; pbrMaterial.subSurface.translucencyIntensityTexture = texture; })); } if (extension.diffuseTransmissionColorFactor !== undefined) { pbrMaterial.subSurface.translucencyColor = Color3.FromArray(extension.diffuseTransmissionColorFactor); } else { pbrMaterial.subSurface.translucencyColor = Color3.White(); } if (extension.diffuseTransmissionColorTexture) { promises.push(this._loader.loadTextureInfoAsync(`${context}/diffuseTransmissionColorTexture`, extension.diffuseTransmissionColorTexture).then((texture) => { texture.name = `${babylonMaterial.name} (Diffuse Transmission Color)`; pbrMaterial.subSurface.translucencyColorTexture = texture; })); } return Promise.all(promises).then(() => { }); } } unregisterGLTFExtension(NAME); registerGLTFExtension(NAME, true, (loader) => new KHR_materials_diffuse_transmission(loader)); export { KHR_materials_diffuse_transmission }; //# sourceMappingURL=KHR_materials_diffuse_transmission-CnZ9De2T.esm.js.map