I recently started using Three.js and am currently tackling a project that involves utilizing an HDRI file for environmental mapping for lighting and reflection purposes. I've been experimenting with loading HDRI files using the HDRCubeTextureLoader
and RGBELoader
, but unfortunately, I have been encountering difficulties. Specifically, I keep getting a "bad file format" error in the Chrome console:
main.js:214 Error: THREE.RGBELoader: Bad File Format: bad initial token
at rgbe_error (RGBELoader.js:39:36)
at RGBE_ReadHeader (RGBELoader.js:139:6)
at RGBELoader.parse (RGBELoader.js:354:28)
at Object.onLoad (three.module.js:44430:21)
The error points to the line in main.js
where
.load(hdrPath, function (texture) {
is located:
const hdrPath = '/Users/.../ocean_hdri/royal_esplanade_1k.hdr';
...
function loadHDRI() {
new RGBELoader()
.setDataType(THREE.UnsignedByteType)
.load(hdrPath, function (texture) {
const hdrRenderTarget = pmremGenerator.fromEquirectangular(texture);
scene.environment = hdrRenderTarget.texture;
scene.background = hdrRenderTarget.texture;
textMeshes.forEach(mesh => {
mesh.material.envMap = hdrRenderTarget.texture;
mesh.material.needsUpdate = true;
});
texture.dispose();
pmremGenerator.dispose();
console.log("HDRI environment loaded");
});
}
I have double-checked that the .hdr
files are valid and even tried replicating the HDR texture loader example using the same HDR files, but the error persists.
Just to provide more context, I am using Webpack for my build setup, alongside NPX and Vite.
I would greatly appreciate any suggestions or guidance on how to resolve this issue.
Thank you in advance!