From a21f06e3ea196f717d990c4ac1f7bcbb4899089c Mon Sep 17 00:00:00 2001 From: Paul Graffam Date: Fri, 7 Oct 2016 14:53:11 -0400 Subject: [PATCH] Refactored gui functions to static helper functions --- src/js/app/managers/datGUI.js | 34 +--------------------------------- src/js/utils/helpers.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/js/app/managers/datGUI.js b/src/js/app/managers/datGUI.js index 001d0c7..cd7d430 100644 --- a/src/js/app/managers/datGUI.js +++ b/src/js/app/managers/datGUI.js @@ -1,5 +1,6 @@ import Config from '../../data/config'; +// Manages all dat.GUI interactions export default class DatGUI { constructor(main, mesh) { const gui = new dat.GUI(); @@ -333,37 +334,4 @@ export default class DatGUI { this.controls.enableRotate = true; }); } - - handleColorChange(color) { - return (value) => { - if(typeof value === 'string') { - value = value.replace('#', '0x'); - } - - color.setHex(value); - }; - } - - needsUpdate(material, geometry) { - return function() { - material.shading = +material.shading; //Ensure number - material.vertexColors = +material.vertexColors; //Ensure number - material.side = +material.side; //Ensure number - material.needsUpdate = true; - geometry.verticesNeedUpdate = true; - geometry.normalsNeedUpdate = true; - geometry.colorsNeedUpdate = true; - }; - } - - updateTexture(material, materialKey, textures) { - return function(key) { - material[materialKey] = textures[key]; - material.needsUpdate = true; - }; - } - - update(mesh) { - this.needsUpdate(mesh.material, mesh.geometry); - } } diff --git a/src/js/utils/helpers.js b/src/js/utils/helpers.js index a1fda3c..c4a0a38 100644 --- a/src/js/utils/helpers.js +++ b/src/js/utils/helpers.js @@ -1,3 +1,4 @@ +// Provides simple static functions that are used multiple times in the app export default class Helpers { static throttle(fn, threshhold, scope) { threshhold || (threshhold = 250); @@ -38,4 +39,37 @@ export default class Helpers { console.error(xhr); } } + + static handleColorChange(color) { + return (value) => { + if(typeof value === 'string') { + value = value.replace('#', '0x'); + } + + color.setHex(value); + }; + } + + static update(mesh) { + this.needsUpdate(mesh.material, mesh.geometry); + } + + static needsUpdate(material, geometry) { + return function() { + material.shading = +material.shading; //Ensure number + material.vertexColors = +material.vertexColors; //Ensure number + material.side = +material.side; //Ensure number + material.needsUpdate = true; + geometry.verticesNeedUpdate = true; + geometry.normalsNeedUpdate = true; + geometry.colorsNeedUpdate = true; + }; + } + + static updateTexture(material, materialKey, textures) { + return function(key) { + material[materialKey] = textures[key]; + material.needsUpdate = true; + }; + } }