61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
"use strict";
|
|
|
|
const FrameObjectDebug = (function(){
|
|
|
|
const FrameObjectDebug = function(hollow_bond, model){
|
|
|
|
const self = this;
|
|
this.model = model;
|
|
|
|
const w = model.size.x,
|
|
h = model.height,
|
|
d = model.size.z,
|
|
is_horizontal = model.axis === "horizontal";
|
|
|
|
const geometry = hollow_bond.inspector.geometries.frame.get(w, h, d),
|
|
face_mat = hollow_bond.inspector.materials.frame.get_face_material(0),
|
|
edge_mat = hollow_bond.inspector.materials.frame.get_edge_material(0);
|
|
|
|
this.mesh = new THREE.Group();
|
|
|
|
// 1. Malla translúcida del volumen
|
|
this.box_mesh = new THREE.Mesh(geometry, face_mat);
|
|
this.mesh.add(this.box_mesh);
|
|
|
|
// 2. Líneas perimetrales
|
|
this.edges_geometry = new THREE.EdgesGeometry(geometry);
|
|
this.edges_mesh = new THREE.LineSegments(this.edges_geometry, edge_mat);
|
|
this.mesh.add(this.edges_mesh);
|
|
|
|
// 3. Posicionamiento centrado en la pared divisoria
|
|
// Base de suelo según la altura de planta del juego
|
|
const floor_h = hollow_bond.room_height || model.height,
|
|
base_y = model.y * floor_h;
|
|
|
|
// Centrado: el eje de paso avanza la mitad de su ancho; el eje de grosor se centra en la línea divisoria
|
|
const center_x = is_horizontal ? (model.x + w / 2) : model.x,
|
|
center_y = base_y + h / 2,
|
|
center_z = is_horizontal ? model.z : (model.z + d / 2);
|
|
|
|
this.mesh.position.set(center_x, center_y, center_z);
|
|
|
|
/**
|
|
* Actualiza el material según la distancia al piso enfocado en el Inspector.
|
|
* @param {number} dist - Distancia en pisos |model.y - current_floor|
|
|
*/
|
|
this.set_layer_distance = dist => {
|
|
const mat_factory = hollow_bond.inspector.materials.frame;
|
|
self.box_mesh.material = mat_factory.get_face_material(dist);
|
|
self.edges_mesh.material = mat_factory.get_edge_material(dist);
|
|
};
|
|
|
|
this.destroy = () => {
|
|
if(self.edges_geometry){
|
|
self.edges_geometry.dispose();
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
return FrameObjectDebug;
|
|
})(); |