HollowBond/Public/ecma/Materials/Game/FrameMaterialGame.ecma.js

47 lines
1.2 KiB
JavaScript

"use strict";
const FrameMaterialGame = (function(){
const FrameMaterialGame = function(hollow_bond){
const self = this;
const cache = {};
const themes_source = (hollow_bond && hollow_bond.themes)
? hollow_bond.themes
: new ThemeManager(hollow_bond);
this.get_material = (theme_key = null) => {
const key = theme_key || themes_source.current_theme || "level_0";
if(cache[key]){
return cache[key];
}
const theme = themes_source.get(key);
if(!theme || !theme.shaders || !theme.shaders.frame){
throw new Error(`[FrameMaterialGame] Shader de frame no definido en tema "${key}".`);
}
cache[key] = new THREE.ShaderMaterial({
vertexShader: theme.shaders.frame.vertex,
fragmentShader: theme.shaders.frame.fragment,
side: THREE.DoubleSide
});
return cache[key];
};
this.reset = () => {
for(const key in cache){
if(cache[key] && cache[key].dispose){
cache[key].dispose();
}
}
};
};
return FrameMaterialGame;
})();