Hello everyone,
I’m new to Three and am currently working on a project where I want to use an HDRI file for environment mapping for lighting and reflections purposes. I’ve been trying to load HDRI files using HDRCubeTextureLoader
and RGBELoader
, but I can’t seem to get it to work. Specifically, I am 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 line in question that it’s referencing in main.js
is the line with .load(hdrPath, function (texture) {
in:
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 made sure that the .hdr
s in question are valid and have even attempted to replicate loader / texture / hdr using the same HDR to no avail.
I have ensured that the .hdr
files are valid and have even attempted to replicate the HDR texture loader example using the same HDR files, but I still encounter the same error.
For additional context, I am using Webpack for my build setup, along with NPX and Vite.
Any guidance on how to resolve this issue would be greatly appreciated.
Thanks in advance!