@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.
54 lines (51 loc) • 2.2 kB
JavaScript
import { R as RGBE_ReadHeader, a as RGBE_ReadPixels } from './hdr-2oFTOfLl.esm.js';
import { C as Constants } from './index-FzOfPXLV.esm.js';
/**
* Implementation of the HDR Texture Loader.
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
class _HDRTextureLoader {
constructor() {
/**
* Defines whether the loader supports cascade loading the different faces.
*/
this.supportCascades = false;
}
/**
* Uploads the cube texture data to the WebGL texture. It has already been bound.
* Cube texture are not supported by .hdr files
*/
loadCubeData() {
// eslint-disable-next-line no-throw-literal
throw ".hdr not supported in Cube.";
}
/**
* Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback.
* @param data contains the texture data
* @param texture defines the BabylonJS internal texture
* @param callback defines the method to call once ready to upload
*/
loadData(data, texture, callback) {
const uint8array = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
const hdrInfo = RGBE_ReadHeader(uint8array);
const pixelsDataRGB32 = RGBE_ReadPixels(uint8array, hdrInfo);
const pixels = hdrInfo.width * hdrInfo.height;
const pixelsDataRGBA32 = new Float32Array(pixels * 4);
for (let i = 0; i < pixels; i += 1) {
pixelsDataRGBA32[i * 4] = pixelsDataRGB32[i * 3];
pixelsDataRGBA32[i * 4 + 1] = pixelsDataRGB32[i * 3 + 1];
pixelsDataRGBA32[i * 4 + 2] = pixelsDataRGB32[i * 3 + 2];
pixelsDataRGBA32[i * 4 + 3] = 1;
}
callback(hdrInfo.width, hdrInfo.height, texture.generateMipMaps, false, () => {
const engine = texture.getEngine();
texture.type = Constants.TEXTURETYPE_FLOAT;
texture.format = Constants.TEXTUREFORMAT_RGBA;
texture._gammaSpace = false;
engine._uploadDataToTextureDirectly(texture, pixelsDataRGBA32);
});
}
}
export { _HDRTextureLoader };
//# sourceMappingURL=hdrTextureLoader-tSpT_2Xi.esm.js.map