From 5b90b60e501aef2a912529f871c5dd892e54b3b2 Mon Sep 17 00:00:00 2001 From: Noeri Huisman Date: Tue, 19 Dec 2023 14:30:49 +0100 Subject: [PATCH 1/2] Remove fog object from scene when removing `fog` component --- src/components/scene/fog.js | 6 ++++-- tests/components/scene/fog.test.js | 11 +---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/components/scene/fog.js b/src/components/scene/fog.js index 3b4ce8e3d38..309ef5a2444 100644 --- a/src/components/scene/fog.js +++ b/src/components/scene/fog.js @@ -46,10 +46,12 @@ 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; + el.systems.material.updateMaterials(); } }); diff --git a/tests/components/scene/fog.test.js b/tests/components/scene/fog.test.js index f770c5621b0..84935d8b7b6 100644 --- a/tests/components/scene/fog.test.js +++ b/tests/components/scene/fog.test.js @@ -67,16 +67,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); }); }); }); From 20e19d09337b4bc474cdecf3b171db54434348f9 Mon Sep 17 00:00:00 2001 From: Noeri Huisman Date: Tue, 19 Dec 2023 15:35:40 +0100 Subject: [PATCH 2/2] No need to update materials when scene fog changes --- src/components/scene/fog.js | 2 -- src/systems/material.js | 10 ---------- tests/components/scene/fog.test.js | 5 ----- 3 files changed, 17 deletions(-) diff --git a/src/components/scene/fog.js b/src/components/scene/fog.js index 309ef5a2444..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; } @@ -51,7 +50,6 @@ module.exports.Component = register('fog', { if (!fog) { return; } el.object3D.fog = null; - el.systems.material.updateMaterials(); } }); 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 84935d8b7b6..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');