Generating a PMREM texture offline?

I currently create a PMREM environment map from a cubemap at runtime with the following code but it crashes on iPhone:

const pmremGenerator = new THREE.PMREMGenerator(renderer);
pmremGenerator.compileCubemapShader();
const cubeTextureLoader = new THREE.CubeTextureLoader();
cubeTextureLoader.load([
  '/assets/env-sky-cube-posx.jpg',
  '/assets/env-sky-cube-negx.jpg',
  '/assets/env-sky-cube-posy.jpg',
  '/assets/env-sky-cube-negy.jpg',
  '/assets/env-sky-cube-posz.jpg',
  '/assets/env-sky-cube-negz.jpg',
], texture => {
  const environmentMap = pmremGenerator.fromCubemap(texture).texture;
  texture.dispose();
  pmremGenerator.dispose();
  scene.environment = environmentMap;
  scene.background = environmentMap;
});

In Babylon.js I can create a .env file offline using CubeMapGen and .DDS to .ENV utility and load it with:

const environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData('/assets/env-sky-cube.env', scene);
scene.createDefaultSkybox(environmentTexture);

Is there a way to do something similar in Three.js? Can PMREMGenerator save to a .env or .dds file?

It’s possible to export the PMREM texture to a .exr file as shown in the EXRExporter example. Or alternatively, a .ktx2 file after this PR.

I’m not really familiar with .env files, and three.js does not provide a .dds exporter, but it is of course also possible to write the PMREM texture to a DataTexture and then do something directly with the typed array of pixel values.

Thanks for the link to the example. Looking at the image generated it seems to allocate very few pixels to incrementally blurring the image (16x16 pixels).

The blur used in the PMREM textures is optimized for use in lighting of rough surfaces, and not for high-res display as the background of the scene. For that purpose you might want to use scene.backgroundBlurriness, though I’m not sure how/if that can be exported.