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

57 lines
1.9 KiB
JavaScript

"use strict";
const RoomObjectDebug = (function(){
const RoomObjectDebug = function(hollow_bond, model){
const self = this;
this.model = model;
const pad = (model.padding || 0) * 2,
w = Math.max(0.1, model.width - pad),
h = Math.max(0.1, model.height - pad),
d = Math.max(0.1, model.depth - pad);
const geometry = hollow_bond.inspector.geometries.room.get(w, h, d),
face_mat = hollow_bond.inspector.materials.room.get_face_material(0),
edge_mat = hollow_bond.inspector.materials.room.get_edge_material(0);
this.mesh = new THREE.Group();
// 1. Caja translúcida
this.box_mesh = new THREE.Mesh(geometry, face_mat);
this.mesh.add(this.box_mesh);
// 2. Líneas perimetrales nítidas
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 en el centro geométrico del ortoedro
// model.y es el índice del piso en el Chunk, model.height es la altura en unidades de mundo
this.mesh.position.set(
model.x + model.width / 2,
model.y + (model.height / 2),
model.z + model.depth / 2
);
/**
* Actualiza el nivel de visibilidad y opacidad según el piso enfocado.
* @param {number} dist - Distancia en pisos |floor - current_floor|
*/
this.set_layer_distance = dist => {
const mat_factory = hollow_bond.inspector.materials.room;
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 RoomObjectDebug;
})();