Refactored gui functions to static helper functions

This commit is contained in:
Paul Graffam 2016-10-07 14:53:11 -04:00
parent 3737462bd5
commit a21f06e3ea
2 changed files with 35 additions and 33 deletions

View File

@ -1,5 +1,6 @@
import Config from '../../data/config'; import Config from '../../data/config';
// Manages all dat.GUI interactions
export default class DatGUI { export default class DatGUI {
constructor(main, mesh) { constructor(main, mesh) {
const gui = new dat.GUI(); const gui = new dat.GUI();
@ -333,37 +334,4 @@ export default class DatGUI {
this.controls.enableRotate = true; 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);
}
} }

View File

@ -1,3 +1,4 @@
// Provides simple static functions that are used multiple times in the app
export default class Helpers { export default class Helpers {
static throttle(fn, threshhold, scope) { static throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250); threshhold || (threshhold = 250);
@ -38,4 +39,37 @@ export default class Helpers {
console.error(xhr); 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;
};
}
} }