@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
81 lines • 4.5 kB
JavaScript
import { EnvCubeTexture } from "./envCubeTexture.js";
import { GetCubeMapTextureData } from "../../Misc/HighDynamicRange/hdr.js";
import { RegisterClass } from "../../Misc/typeStore.js";
import "../../Materials/Textures/baseTexture.polynomial.js";
/**
* This represents a texture coming from an HDR input.
*
* The supported format is currently panorama picture stored in RGBE format.
* Example of such files can be found on Poly Haven: https://polyhaven.com/hdris
*/
export class HDRCubeTexture extends EnvCubeTexture {
/**
* Instantiates an HDRTexture from the following parameters.
*
* @param url The location of the HDR raw data (Panorama stored in RGBE format)
* @param sceneOrEngine The scene or engine the texture will be used in
* @param size The cubemap desired size (the more it increases the longer the generation will be)
* @param noMipmap Forces to not generate the mipmap if true
* @param generateHarmonics Specifies whether you want to extract the polynomial harmonics during the generation process
* @param gammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)
* @param prefilterOnLoad Prefilters HDR texture to allow use of this texture as a PBR reflection texture.
* @param onLoad on success callback function
* @param onError on error callback function
* @param supersample Defines if texture must be supersampled (default: false)
* @param prefilterIrradianceOnLoad Prefilters HDR texture to allow use of this texture for irradiance lighting.
* @param prefilterUsingCdf Defines if the prefiltering should be done using a CDF instead of the default approach.
* @param sphericalPolynomialTargetSize Target face size for spherical polynomial computation. 0 = full resolution (default).
*/
constructor(url, sceneOrEngine, size, noMipmap = false, generateHarmonics = true, gammaSpace = false, prefilterOnLoad = false, onLoad = null, onError = null, supersample = false, prefilterIrradianceOnLoad = false, prefilterUsingCdf = false, sphericalPolynomialTargetSize = 0) {
super(url, sceneOrEngine, size, noMipmap, generateHarmonics, gammaSpace, prefilterOnLoad, onLoad, onError, supersample, prefilterIrradianceOnLoad, prefilterUsingCdf, sphericalPolynomialTargetSize);
}
/**
* Get the current class name of the texture useful for serialization or dynamic coding.
* @returns "HDRCubeTexture"
*/
getClassName() {
return "HDRCubeTexture";
}
/**
* Convert the raw data from the server into cubemap faces
* @param buffer The buffer containing the texture data
* @param size The cubemap face size
* @param supersample Defines if texture must be supersampled
* @returns The cube map data
*/
async _getCubeMapTextureDataAsync(buffer, size, supersample) {
return GetCubeMapTextureData(buffer, size, supersample);
}
_instantiateClone() {
return new HDRCubeTexture(this.url, this.getScene() || this._getEngine(), this._size, this._noMipmap, this._generateHarmonics, this.gammaSpace);
}
/**
* Serialize the texture to a JSON representation.
* @returns The JSON representation of the texture
*/
serialize() {
const serializationObject = super.serialize();
if (!serializationObject) {
return null;
}
serializationObject.customType = "BABYLON.HDRCubeTexture";
return serializationObject;
}
/**
* Parses a JSON representation of an HDR Texture in order to create the texture
* @param parsedTexture Define the JSON representation
* @param scene Define the scene the texture should be created in
* @param rootUrl Define the root url in case we need to load relative dependencies
* @returns the newly created texture after parsing
*/
static Parse(parsedTexture, scene, rootUrl) {
if (!parsedTexture.name || parsedTexture.isRenderTarget) {
return null;
}
const texture = new HDRCubeTexture(rootUrl + parsedTexture.name, scene, parsedTexture.size, parsedTexture.noMipmap, parsedTexture.generateHarmonics, parsedTexture.useInGammaSpace);
this._Parse(parsedTexture, texture);
return texture;
}
}
RegisterClass("BABYLON.HDRCubeTexture", HDRCubeTexture);
//# sourceMappingURL=hdrCubeTexture.js.map