HollowBond/Public/ecma/Objects/Debug/ElevatorObjectDebug.ecma.js

95 lines
4.0 KiB
JavaScript

"use strict";
const ElevatorObjectDebug = (function(){
const ElevatorObjectDebug = function(hollow_bond, model){
const self = this;
this.model = model;
const floor_height = hollow_bond.room_height || 3,
size = hollow_bond.elevator_size || 2,
height = floor_height * 0.9,
center_x = model.x + size / 2,
center_y = (model.y * floor_height) + (floor_height * 0.45),
center_z = model.z + size / 2;
this.mesh = new THREE.Group();
// 1. Malla de la cabina coloreada por columna
const column_id = model.shaft_id || model.group_id || model.column_id || `${model.x}_${model.z}`,
cabin_geo = hollow_bond.inspector.geometries.elevator.get(),
cabin_mat = hollow_bond.inspector.materials.elevator.get_cabin_material(column_id),
cabin_mesh = new THREE.Mesh(cabin_geo, cabin_mat);
// Perfilado de bordes/vértices de la cabina
const cabin_edges_geo = new THREE.EdgesGeometry(cabin_geo),
cabin_edge_mat = hollow_bond.inspector.materials.elevator.get_edges(),
cabin_edges_mesh = new THREE.LineSegments(cabin_edges_geo, cabin_edge_mat);
this.mesh.add(cabin_mesh);
this.mesh.add(cabin_edges_mesh);
// 2. Extracción de la orientación de la puerta
// Normalizamos comprobando door, direction, orientation, side o facing
const raw_dir = String(
model.door ||
model.door_direction ||
model.direction ||
model.orientation ||
model.side ||
model.facing ||
""
).trim().toLowerCase();
// const label_mat = hollow_bond.inspector.materials.elevator.get_door_label_material(model.y),
const label_mat = hollow_bond.inspector.materials.elevator.get_door_label_material(model.floor),
label_geo = new THREE.PlaneGeometry(size * 0.75, height * 0.75),
label_mesh = new THREE.Mesh(label_geo, label_mat),
offset = size / 2 + 0.02;
// Comprobación por cardinales o ejes relativos
if(raw_dir === "north" || raw_dir === "-z" || raw_dir === "top" || raw_dir === "up"){
label_mesh.position.set(0, 0, -offset);
label_mesh.rotation.y = Math.PI;
} else if(raw_dir === "south" || raw_dir === "+z" || raw_dir === "bottom" || raw_dir === "down"){
label_mesh.position.set(0, 0, offset);
label_mesh.rotation.y = 0;
} else if(raw_dir === "east" || raw_dir === "+x" || raw_dir === "right"){
label_mesh.position.set(offset, 0, 0);
label_mesh.rotation.y = Math.PI / 2;
} else if(raw_dir === "west" || raw_dir === "-x" || raw_dir === "left"){
label_mesh.position.set(-offset, 0, 0);
label_mesh.rotation.y = -Math.PI / 2;
} else if(typeof model.dx === "number" || typeof model.dz === "number"){
// Si viene guardado como vector de dirección relativo (dx, dz)
if(model.dz < 0){
label_mesh.position.set(0, 0, -offset);
label_mesh.rotation.y = Math.PI;
} else if(model.dz > 0){
label_mesh.position.set(0, 0, offset);
label_mesh.rotation.y = 0;
} else if(model.dx > 0){
label_mesh.position.set(offset, 0, 0);
label_mesh.rotation.y = Math.PI / 2;
} else {
label_mesh.position.set(-offset, 0, 0);
label_mesh.rotation.y = -Math.PI / 2;
}
} else {
// Fallback por defecto si no viniera nada definido
label_mesh.position.set(0, 0, offset);
label_mesh.rotation.y = 0;
}
this.mesh.add(label_mesh);
this.mesh.position.set(center_x, center_y, center_z);
this.destroy = () => {
if(label_geo) label_geo.dispose();
if(cabin_edges_geo) cabin_edges_geo.dispose();
};
};
return ElevatorObjectDebug;
})();