HollowBond/Public/ecma/Geometries/Debug/HoleGeometryDebug.ecma.js

42 lines
1.1 KiB
JavaScript

"use strict";
const HoleGeometryDebug = (function(){
const HoleGeometryDebug = function(hollow_bond){
const cache = {};
const floor_height = hollow_bond.room_height || 3;
/**
* Obtiene o genera la caja 3D correspondiente al vano del hueco.
* @param {number} width - Ancho en X (xt - xf)
* @param {number} floors - Pisos perforados (yt - yf)
* @param {number} depth - Fondo en Z (zt - zf)
*/
this.get = (width, floors, depth) => {
const height = floors * floor_height,
key = `${width}_${height}_${depth}`;
if(!cache[key]){
cache[key] = new THREE.BoxGeometry(width, height, depth);
}
return cache[key];
};
/**
* Libera todas las geometrías de huecos cacheadas en la GPU.
*/
this.reset = () => {
for(const key in cache){
if(cache[key]){
cache[key].dispose();
delete cache[key];
}
}
};
};
return HoleGeometryDebug;
})();