From 8e4f387eb9bb0e54f7fa6689e4fe56fc29ae63e7 Mon Sep 17 00:00:00 2001 From: Noeri Huisman <8823461+mrxz@users.noreply.github.com> Date: Tue, 19 Dec 2023 23:33:40 +0100 Subject: [PATCH] Fix fog removal from scene (#5418) * Remove fog object from scene when removing `fog` component * No need to update materials when scene fog changes --------- Co-authored-by: Noeri Huisman --- src/components/scene/fog.js | 6 +++--- src/systems/material.js | 10 ---------- tests/components/scene/fog.test.js | 16 +--------------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/components/scene/fog.js b/src/components/scene/fog.js index 3b4ce8e3d38..15e0d07ff67 100644 --- a/src/components/scene/fog.js +++ b/src/components/scene/fog.js @@ -30,7 +30,6 @@ module.exports.Component = register('fog', { // (Re)create fog if fog doesn't exist or fog type changed. if (!fog || data.type !== fog.name) { el.object3D.fog = getFog(data); - el.systems.material.updateMaterials(); return; } @@ -46,10 +45,11 @@ module.exports.Component = register('fog', { * Remove fog on remove (callback). */ remove: function () { + var el = this.el; var fog = this.el.object3D.fog; if (!fog) { return; } - fog.far = 0; - fog.near = 0.1; + + el.object3D.fog = null; } }); diff --git a/src/systems/material.js b/src/systems/material.js index a142f68d79a..6c2634e65cc 100755 --- a/src/systems/material.js +++ b/src/systems/material.js @@ -222,16 +222,6 @@ module.exports.System = registerSystem('material', { }); }, - /** - * Trigger update to all registered materials. - */ - updateMaterials: function (material) { - var materials = this.materials; - Object.keys(materials).forEach(function (uuid) { - materials[uuid].needsUpdate = true; - }); - }, - /** * Track textures used by material components, so that they can be safely * disposed when no longer in use. Textures must be registered here, and not diff --git a/tests/components/scene/fog.test.js b/tests/components/scene/fog.test.js index f770c5621b0..41a97d6d1ab 100644 --- a/tests/components/scene/fog.test.js +++ b/tests/components/scene/fog.test.js @@ -8,7 +8,6 @@ suite('fog', function () { var self = this; el.addEventListener('loaded', function () { - self.updateMaterialsSpy = self.sinon.spy(el.systems.material, 'updateMaterials'); // Stub scene load to avoid WebGL code. el.hasLoaded = true; el.setAttribute('fog', ''); @@ -28,10 +27,6 @@ suite('fog', function () { assert.ok(this.el.object3D.fog); }); - test('triggers material update when adding fog', function () { - assert.ok(this.updateMaterialsSpy.called); - }); - test('updates fog', function () { var el = this.el; el.setAttribute('fog', 'color: #F0F'); @@ -67,16 +62,7 @@ suite('fog', function () { test('removes fog when detaching fog', function () { var el = this.el; el.removeAttribute('fog'); - assert.equal(el.object3D.fog.far, 0); - assert.equal(el.object3D.fog.near, 0.1); - }); - - test('removes exp. fog when detaching fog', function () { - var el = this.el; - el.setAttribute('fog', 'type: exponential'); - el.removeAttribute('fog'); - assert.equal(el.object3D.fog.far, 0); - assert.equal(el.object3D.fog.near, 0.1); + assert.equal(el.object3D.fog, null); }); }); });