"use strict"; const StairObjectDebug = (function(){ const StairObjectDebug = function(hollow_bond, model){ const self = this; this.model = model; const floor_height = hollow_bond.room_height || 3, width = Math.max(1, (model.xt || (model.xf + 1)) - model.xf), depth = Math.max(1, (model.zt || (model.zf + 1)) - model.zf); // 1. Detección de la orientación de la pared: // Si depth >= width, la escalera corre a lo largo de Z; de lo contrario corre a lo largo de X. const is_z_axis = depth >= width, run_axis = is_z_axis ? depth : width, lateral_axis = is_z_axis ? width : depth; // 2. Sentido de subida: 1 (hacia coordenadas crecientes) o -1 (decrecientes) const direction = typeof model.direction === "number" ? model.direction : 1; this.mesh = new THREE.Group(); // 3. Geometría y materiales desde el Inspector const geo_set = hollow_bond.inspector.geometries.stair.get(lateral_axis, run_axis), landing_mat = hollow_bond.inspector.materials.stair.get_landing(), ramp_mat = hollow_bond.inspector.materials.stair.get_ramp(), s = geo_set.specs; // 4. Descansillo inferior (a cota base y = 0, extremo inicial local) const bottom_mesh = new THREE.Mesh(geo_set.landing_bottom, landing_mat); bottom_mesh.position.set(0, s.landing_thickness / 2, -run_axis / 2 + s.landing_length / 2); this.mesh.add(bottom_mesh); // 5. Descansillo superior (enrasado en y = floor_height, extremo final local) const top_mesh = new THREE.Mesh(geo_set.landing_top, landing_mat); top_mesh.position.set(0, floor_height + (s.landing_thickness / 2), run_axis / 2 - s.landing_length / 2); this.mesh.add(top_mesh); // 6. Rampa inclinada central const ramp_mesh = new THREE.Mesh(geo_set.ramp, ramp_mat); ramp_mesh.position.set(0, floor_height / 2 + (s.landing_thickness / 2), 0); ramp_mesh.rotation.x = -s.angle; this.mesh.add(ramp_mesh); // 7. Rotación en Y según el eje y el sentido (+1 o -1) if(is_z_axis){ // Subida a lo largo del eje Z this.mesh.rotation.y = (direction >= 0) ? 0 : Math.PI; } else { // Subida a lo largo del eje X this.mesh.rotation.y = (direction >= 0) ? -Math.PI / 2 : Math.PI / 2; } // 8. Posicionado central en las coordenadas del mundo this.mesh.position.set( model.xf + width / 2, model.yf * floor_height, model.zf + depth / 2 ); this.destroy = () => { // Geometrías y materiales compartidos se liberan centralmente en reset() }; }; return StairObjectDebug; })();