From 42bb242180a16e6ee8d1f8f4d92694004e72d24f Mon Sep 17 00:00:00 2001 From: Noeri Huisman <8823461+mrxz@users.noreply.github.com> Date: Mon, 18 Nov 2024 18:23:17 +0100 Subject: [PATCH] Avoid attempting to load cubemap when envMap is not set for probe light --- src/components/light.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/components/light.js b/src/components/light.js index b74f1833c48..87df1415071 100644 --- a/src/components/light.js +++ b/src/components/light.js @@ -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) {