62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const RoomMaterialGame = (function(){
|
|
|
|
const RoomMaterialGame = 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_materials = (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){
|
|
throw new Error(`[RoomMaterialGame] Theme "${key}" no encontrado o sin shaders.`);
|
|
}
|
|
|
|
// Cambiamos a THREE.DoubleSide para que renderice tanto interior como exterior
|
|
const floor_mat = new THREE.ShaderMaterial({
|
|
vertexShader: theme.shaders.floor.vertex,
|
|
fragmentShader: theme.shaders.floor.fragment,
|
|
side: THREE.DoubleSide
|
|
});
|
|
|
|
const ceiling_mat = new THREE.ShaderMaterial({
|
|
vertexShader: theme.shaders.ceiling.vertex,
|
|
fragmentShader: theme.shaders.ceiling.fragment,
|
|
side: THREE.DoubleSide
|
|
});
|
|
|
|
const walls_mat = new THREE.ShaderMaterial({
|
|
vertexShader: theme.shaders.walls.vertex,
|
|
fragmentShader: theme.shaders.walls.fragment,
|
|
side: THREE.DoubleSide
|
|
});
|
|
|
|
cache[key] = [floor_mat, ceiling_mat, walls_mat];
|
|
|
|
return cache[key];
|
|
};
|
|
|
|
this.reset = () => {
|
|
for(const key in cache){
|
|
if(Array.isArray(cache[key])){
|
|
cache[key].forEach(mat => mat.dispose && mat.dispose());
|
|
}
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
return RoomMaterialGame;
|
|
})(); |