116 lines
3.7 KiB
JavaScript
116 lines
3.7 KiB
JavaScript
"use strict";
|
|
|
|
const ElevatorMaterialDebug = (function(){
|
|
|
|
const ElevatorMaterialDebug = function(){
|
|
|
|
// Paleta semántica para distinguir columnas de ascensores
|
|
const palette = [
|
|
0xffeb3b, // Amarillo
|
|
0x00e676, // Verde lima
|
|
0x00e5ff, // Cian
|
|
0xff4081, // Rosa/Magenta
|
|
0xff9100, // Naranja
|
|
0x7c4dff, // Violeta
|
|
0x1de9b6 // Turquesa
|
|
];
|
|
|
|
const color_cache = {},
|
|
label_cache = {};
|
|
let edge_mat = null;
|
|
|
|
/**
|
|
* Devuelve un material coloreado determinista según el identificador de la columna/grupo.
|
|
*/
|
|
this.get_cabin_material = group_id => {
|
|
const id_str = String(group_id || 0);
|
|
|
|
if(!color_cache[id_str]){
|
|
// Hash determinista del ID para seleccionar color fijo de la paleta
|
|
let hash = 0;
|
|
for(let i = 0; i < id_str.length; i++){
|
|
hash = (hash << 5) - hash + id_str.charCodeAt(i) | 0;
|
|
}
|
|
const color = palette[Math.abs(hash) % palette.length];
|
|
|
|
color_cache[id_str] = new THREE.MeshBasicMaterial({
|
|
color : color,
|
|
transparent : true,
|
|
opacity : 0.65,
|
|
wireframe : false
|
|
});
|
|
}
|
|
|
|
return color_cache[id_str];
|
|
};
|
|
|
|
/**
|
|
* Genera o recupera un material con el número de piso impreso en canvas para la puerta.
|
|
*/
|
|
this.get_door_label_material = floor_y => {
|
|
const key = String(floor_y);
|
|
|
|
if(!label_cache[key]){
|
|
const canvas = document.createElement("canvas");
|
|
canvas.width = 128;
|
|
canvas.height = 128;
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
// Fondo oscuro translúcido con marco
|
|
ctx.fillStyle = "rgba(10, 12, 16, 0.9)";
|
|
ctx.fillRect(0, 0, 128, 128);
|
|
|
|
ctx.strokeStyle = "#ffffff";
|
|
ctx.lineWidth = 6;
|
|
ctx.strokeRect(6, 6, 116, 116);
|
|
|
|
// Número de piso
|
|
ctx.fillStyle = "#ffffff";
|
|
ctx.font = "bold 52px monospace";
|
|
ctx.textAlign = "center";
|
|
ctx.textBaseline = "middle";
|
|
ctx.fillText(String(floor_y), 64, 56);
|
|
|
|
// Pequeño indicador o icono de ascensor/puerta
|
|
ctx.fillStyle = "#00bcd4";
|
|
ctx.font = "bold 18px monospace";
|
|
ctx.fillText("DOOR", 64, 98);
|
|
|
|
const texture = new THREE.CanvasTexture(canvas);
|
|
label_cache[key] = new THREE.MeshBasicMaterial({
|
|
map : texture,
|
|
transparent : true,
|
|
opacity : 0.95
|
|
});
|
|
}
|
|
|
|
return label_cache[key];
|
|
};
|
|
|
|
this.reset = () => {
|
|
for(const key in color_cache){
|
|
if(color_cache[key]){
|
|
color_cache[key].dispose();
|
|
delete color_cache[key];
|
|
}
|
|
}
|
|
for(const key in label_cache){
|
|
if(label_cache[key]){
|
|
if(label_cache[key].map) label_cache[key].map.dispose();
|
|
label_cache[key].dispose();
|
|
delete label_cache[key];
|
|
}
|
|
}
|
|
if(edge_mat){ edge_mat.dispose(); edge_mat = null; }
|
|
};
|
|
|
|
this.get_edges = () => edge_mat || (edge_mat = new THREE.LineBasicMaterial({
|
|
color : 0xffffff,
|
|
transparent : true,
|
|
opacity : 0.8
|
|
}));
|
|
|
|
};
|
|
|
|
return ElevatorMaterialDebug;
|
|
})(); |