Skip to content

Commit

Permalink
Avoid attempting to load cubemap when envMap is not set for probe light
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxz committed Nov 18, 2024
1 parent c3b5363 commit 42bb242
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/components/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,25 +345,30 @@ module.exports.Component = registerComponent('light', {
if (!data.envMap) {
// reset parameters if no map
light.copy(new THREE.LightProbe());
return;
}

// Populate the cache if not done for this envMap yet
if (probeCache[data.envMap] === undefined) {
probeCache[data.envMap] = new window.Promise(function (resolve) {
utils.srcLoader.validateCubemapSrc(data.envMap, function loadEnvMap (urls) {
CubeLoader.load(urls, function (cube) {
var tempLightProbe = THREE.LightProbeGenerator.fromCubeTexture(cube);
probeCache[data.envMap] = tempLightProbe;
resolve(tempLightProbe);
});
});
});
}

// Copy over light probe properties
if (probeCache[data.envMap] instanceof window.Promise) {
probeCache[data.envMap].then(function (tempLightProbe) {
light.copy(tempLightProbe);
});
}
if (probeCache[data.envMap] instanceof THREE.LightProbe) {
} else if (probeCache[data.envMap] instanceof THREE.LightProbe) {
light.copy(probeCache[data.envMap]);
}
probeCache[data.envMap] = new window.Promise(function (resolve) {
utils.srcLoader.validateCubemapSrc(data.envMap, function loadEnvMap (urls) {
CubeLoader.load(urls, function (cube) {
var tempLightProbe = THREE.LightProbeGenerator.fromCubeTexture(cube);
probeCache[data.envMap] = tempLightProbe;
light.copy(tempLightProbe);
});
});
});
},

onSetTarget: function (targetEl, light) {
Expand Down

0 comments on commit 42bb242

Please sign in to comment.