[SOLVED] Cubemap gives null when accessing its resource

Hi @Saad_Haider,

I should have mentioned at the time, but the solution I gave you before was not public API and we changed the internal properties on the material.

It is actually still possible to set the prefilteredCubemaps, but using material.prefilteredCubemaps array property instead of the individual 128/64/32 etc sized textures.

However, the following code will do the job you’re after and is much more efficient:

const modelName = "Runtime Cubemap Character";

this.cubemap.once('load', () => {
    // generate environment atlas
    const envAtlas = pc.EnvLighting.generatePrefilteredAtlas(this.cubemap.resources.slice(1));

    // apply to mesh instances
    const meshInstances = this.app.root.findByName(modelName).model.meshInstances;
    meshInstances.forEach((mi) => {
        mi.material.envAtlas = envAtlas;
        mi.material.update();
    });
});
this.app.assets.load(this.cubemap);
2 Likes