Archived
- Load V2.5.1 AAA ENSAMBLE CABINET MAIN 3D visualizer.glb - Fix door not animating: update setupHingePivot to match new door node name (V2.5.1 PPP PUERTA copy:1) via pattern instead of exact match - Fix hinge color inconsistency: remove runtime material override on fixed hinge halves so all 8 hinge meshes keep their uniform original GLB color - Add HUELLERO/LECTOR/BIOMETRICO patterns for new fingerprint reader mesh - Update GUI screen material match to also target PANTALLANUEVA node - Add annotations-content.json backup of all annotation and panel text Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1736 lines
67 KiB
HTML
1736 lines
67 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Bitua 3D Explorer - Interactive</title>
|
||
<style>
|
||
:root {
|
||
--primary: #007aff;
|
||
--bg: #f5f5f7;
|
||
--card-bg: #ffffff;
|
||
--text: #1d1d1f;
|
||
}
|
||
|
||
@keyframes glow-pulse {
|
||
0%, 100% { box-shadow: 0 4px 10px rgba(0, 122, 255, 0.25); }
|
||
50% { box-shadow: 0 4px 22px rgba(0, 122, 255, 0.6), 0 0 14px rgba(0, 122, 255, 0.28); }
|
||
}
|
||
|
||
@keyframes glow-pulse-pill {
|
||
0%, 100% { box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1), 0 0 8px rgba(0, 122, 255, 0.2); }
|
||
50% { box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 18px rgba(0, 122, 255, 0.5); }
|
||
}
|
||
|
||
body {
|
||
margin: 0;
|
||
font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
|
||
background-color: var(--bg);
|
||
color: var(--text);
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100vh;
|
||
}
|
||
|
||
header {
|
||
padding: 20px;
|
||
text-align: center;
|
||
background: rgba(255, 255, 255, 0.8);
|
||
backdrop-filter: blur(20px);
|
||
z-index: 10;
|
||
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
|
||
}
|
||
|
||
header h1 {
|
||
margin: 0;
|
||
font-size: 24px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
header p {
|
||
margin: 5px 0 0;
|
||
opacity: 0.6;
|
||
font-size: 14px;
|
||
}
|
||
|
||
#container {
|
||
flex: 1;
|
||
position: relative;
|
||
width: 100%;
|
||
}
|
||
|
||
#three-canvas {
|
||
width: 100%;
|
||
height: 100%;
|
||
display: block;
|
||
}
|
||
|
||
/* Loading UI */
|
||
#loader {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
background: var(--bg);
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
align-items: center;
|
||
z-index: 100;
|
||
transition: opacity 0.5s ease;
|
||
}
|
||
|
||
.progress-bar {
|
||
width: 200px;
|
||
height: 4px;
|
||
background: #e0e0e0;
|
||
border-radius: 2px;
|
||
overflow: hidden;
|
||
margin-top: 20px;
|
||
}
|
||
|
||
#progress {
|
||
width: 0%;
|
||
height: 100%;
|
||
background: var(--primary);
|
||
transition: width 0.3s ease;
|
||
}
|
||
|
||
/* Info Overlay */
|
||
.info-panel {
|
||
position: absolute;
|
||
bottom: 30px;
|
||
left: 50%;
|
||
transform: translateX(-50%);
|
||
background: rgba(0, 0, 0, 0.7);
|
||
color: white;
|
||
padding: 12px 24px;
|
||
border-radius: 30px;
|
||
font-size: 14px;
|
||
pointer-events: none;
|
||
backdrop-filter: blur(10px);
|
||
text-align: center;
|
||
z-index: 5;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 15px;
|
||
}
|
||
|
||
#btn-home {
|
||
background: var(--primary);
|
||
color: white;
|
||
border: none;
|
||
padding: 8px 16px;
|
||
border-radius: 20px;
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
transition: background 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||
pointer-events: auto;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
animation: glow-pulse 2.5s ease-in-out infinite;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
#btn-home:hover {
|
||
background: #005bb7;
|
||
transform: translateY(-2px);
|
||
animation-play-state: paused;
|
||
box-shadow: 0 6px 18px rgba(0, 122, 255, 0.55);
|
||
}
|
||
|
||
#btn-home:active {
|
||
transform: translateY(0);
|
||
}
|
||
|
||
/* Interaction Tooltip (Click to open) */
|
||
#tooltip {
|
||
position: absolute;
|
||
background: white;
|
||
padding: 8px 16px;
|
||
border-radius: 8px;
|
||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||
display: none;
|
||
pointer-events: none;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
z-index: 20;
|
||
}
|
||
|
||
#sidebar {
|
||
position: absolute;
|
||
top: 100px;
|
||
right: 20px;
|
||
width: 280px;
|
||
background: rgba(255, 255, 255, 0.9);
|
||
backdrop-filter: blur(20px);
|
||
padding: 0;
|
||
border-radius: 20px;
|
||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||
z-index: 10;
|
||
display: flex;
|
||
flex-direction: column;
|
||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||
overflow: hidden;
|
||
}
|
||
|
||
#sidebar.collapsed {
|
||
width: 60px;
|
||
height: 60px;
|
||
border-radius: 30px;
|
||
cursor: pointer;
|
||
animation: glow-pulse-pill 3s ease-in-out infinite;
|
||
}
|
||
|
||
#sidebar-header {
|
||
padding: 20px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
border-radius: 20px 20px 0 0;
|
||
transition: background 0.2s;
|
||
}
|
||
|
||
#sidebar:not(.collapsed) #sidebar-header:hover {
|
||
background: rgba(0, 122, 255, 0.05);
|
||
}
|
||
|
||
#btn-simulate {
|
||
background: var(--primary);
|
||
color: white;
|
||
border: none;
|
||
padding: 10px 18px;
|
||
border-radius: 14px;
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
width: 100%;
|
||
animation: glow-pulse 2.8s ease-in-out infinite;
|
||
transition: background 0.2s, transform 0.15s;
|
||
}
|
||
|
||
#btn-simulate:hover {
|
||
background: #005bb7;
|
||
animation-play-state: paused;
|
||
box-shadow: 0 6px 18px rgba(0, 122, 255, 0.55);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
#btn-simulate:active {
|
||
transform: translateY(0);
|
||
}
|
||
|
||
#sidebar-header h2 {
|
||
margin: 0;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
#sidebar-content {
|
||
padding: 0 24px 24px 24px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 15px;
|
||
transition: opacity 0.2s;
|
||
}
|
||
|
||
#sidebar.collapsed #sidebar-content {
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
}
|
||
|
||
#sidebar.collapsed #sidebar-header h2 {
|
||
display: none;
|
||
}
|
||
|
||
#sidebar-toggle-icon {
|
||
font-size: 20px;
|
||
transition: transform 0.3s;
|
||
}
|
||
|
||
#sidebar.collapsed #sidebar-toggle-icon {
|
||
transform: rotate(0deg);
|
||
}
|
||
|
||
#sidebar:not(.collapsed) #sidebar-toggle-icon {
|
||
transform: rotate(180deg);
|
||
}
|
||
|
||
/* Lock Annotation Styles */
|
||
#lock-annotation {
|
||
position: absolute;
|
||
background: rgba(255, 255, 255, 0.95);
|
||
padding: 12px 20px;
|
||
border-radius: 12px;
|
||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
|
||
display: none;
|
||
pointer-events: auto;
|
||
font-size: 16px;
|
||
font-weight: 400;
|
||
z-index: 100;
|
||
border-left: 4px solid var(--primary);
|
||
backdrop-filter: blur(10px);
|
||
color: var(--text);
|
||
max-width: 250px;
|
||
}
|
||
|
||
#leader-line {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
pointer-events: none;
|
||
z-index: 99;
|
||
display: none;
|
||
}
|
||
|
||
#leader-line path {
|
||
fill: none;
|
||
stroke: #444444; /* Dark gray */
|
||
stroke-width: 2;
|
||
opacity: 0.8;
|
||
}
|
||
|
||
/* Debug Overlay */
|
||
#camera-debug {
|
||
position: absolute;
|
||
top: 20px;
|
||
left: 20px;
|
||
background: rgba(0, 0, 0, 0.8);
|
||
color: #00ff00;
|
||
padding: 15px;
|
||
border-radius: 10px;
|
||
font-family: 'Courier New', Courier, monospace;
|
||
font-size: 12px;
|
||
pointer-events: none;
|
||
z-index: 1000;
|
||
display: none;
|
||
border: 1px solid #00ff00;
|
||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
|
||
pointer-events: auto; /* Enable interaction for the button */
|
||
}
|
||
|
||
#camera-debug h3 {
|
||
margin: 0 0 10px 0;
|
||
font-size: 14px;
|
||
border-bottom: 1px solid #00ff00;
|
||
padding-bottom: 5px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
}
|
||
|
||
#btn-copy-debug {
|
||
background: #00ff00;
|
||
color: black;
|
||
border: none;
|
||
padding: 2px 8px;
|
||
border-radius: 4px;
|
||
font-size: 10px;
|
||
font-weight: bold;
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
#btn-copy-debug:hover {
|
||
background: #00cc00;
|
||
transform: scale(1.05);
|
||
}
|
||
|
||
#btn-copy-debug:active {
|
||
transform: scale(0.95);
|
||
}
|
||
|
||
#debug-last-clicked {
|
||
margin-top: 6px;
|
||
color: #aaffaa;
|
||
font-size: 10px;
|
||
}
|
||
|
||
#debug-last-clicked span {
|
||
color: #ffff00;
|
||
}
|
||
|
||
#debug-paragraph-input {
|
||
width: 100%;
|
||
margin-top: 6px;
|
||
background: rgba(0, 0, 0, 0.6);
|
||
border: 1px solid #00aa00;
|
||
color: #00ff00;
|
||
font-family: 'Courier New', Courier, monospace;
|
||
font-size: 10px;
|
||
padding: 4px 6px;
|
||
border-radius: 4px;
|
||
outline: none;
|
||
resize: vertical;
|
||
min-height: 48px;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
#debug-paragraph-input::placeholder { color: #006600; }
|
||
|
||
#debug-save-row {
|
||
display: flex;
|
||
gap: 6px;
|
||
margin-top: 10px;
|
||
padding-top: 10px;
|
||
border-top: 1px solid #004400;
|
||
}
|
||
|
||
#debug-label-input {
|
||
flex: 1;
|
||
background: rgba(0, 0, 0, 0.6);
|
||
border: 1px solid #00aa00;
|
||
color: #00ff00;
|
||
font-family: 'Courier New', Courier, monospace;
|
||
font-size: 10px;
|
||
padding: 3px 6px;
|
||
border-radius: 4px;
|
||
outline: none;
|
||
}
|
||
|
||
#debug-label-input::placeholder {
|
||
color: #006600;
|
||
}
|
||
|
||
#btn-save-view {
|
||
background: #00aa00;
|
||
color: black;
|
||
border: none;
|
||
padding: 3px 8px;
|
||
border-radius: 4px;
|
||
font-size: 10px;
|
||
font-weight: bold;
|
||
cursor: pointer;
|
||
white-space: nowrap;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
#btn-save-view:hover { background: #00cc00; }
|
||
#btn-save-view:active { transform: scale(0.95); }
|
||
|
||
#debug-viewpoints-list {
|
||
max-height: 160px;
|
||
overflow-y: auto;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
margin-top: 6px;
|
||
}
|
||
|
||
.debug-vp-entry {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: flex-start;
|
||
background: rgba(0, 80, 0, 0.3);
|
||
border: 1px solid #004400;
|
||
border-radius: 4px;
|
||
padding: 4px 6px;
|
||
gap: 6px;
|
||
}
|
||
|
||
.debug-vp-label {
|
||
font-weight: bold;
|
||
color: #aaffaa;
|
||
font-size: 10px;
|
||
flex: 1;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.debug-vp-coords {
|
||
color: #007700;
|
||
font-size: 9px;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.debug-vp-del {
|
||
background: none;
|
||
border: none;
|
||
color: #ff4444;
|
||
cursor: pointer;
|
||
font-size: 11px;
|
||
padding: 0 2px;
|
||
line-height: 1;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.debug-vp-del:hover { color: #ff0000; }
|
||
|
||
#debug-export-row {
|
||
display: none;
|
||
gap: 6px;
|
||
margin-top: 8px;
|
||
}
|
||
|
||
#debug-export-row button {
|
||
flex: 1;
|
||
border: none;
|
||
padding: 4px 8px;
|
||
border-radius: 4px;
|
||
font-size: 10px;
|
||
font-weight: bold;
|
||
cursor: pointer;
|
||
font-family: 'Courier New', Courier, monospace;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
#btn-copy-json { background: #00ff00; color: black; }
|
||
#btn-copy-json:hover { background: #00cc00; }
|
||
|
||
#btn-export-views { background: #0055ff; color: white; }
|
||
#btn-export-views:hover { background: #0044cc; }
|
||
|
||
#debug-export-row button:active { transform: scale(0.95); }
|
||
|
||
#debug-toggle-hint {
|
||
position: absolute;
|
||
bottom: 80px;
|
||
left: 20px;
|
||
background: rgba(255, 255, 255, 0.2);
|
||
padding: 5px 10px;
|
||
border-radius: 5px;
|
||
font-size: 10px;
|
||
color: #666;
|
||
pointer-events: none;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<div id="loader">
|
||
<div style="font-weight: 600;">Initializing Experience...</div>
|
||
<div class="progress-bar">
|
||
<div id="progress"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<header>
|
||
<h1>Bitua</h1>
|
||
<p>Smart Cabinet Series (Updated)</p>
|
||
</header>
|
||
|
||
|
||
<div id="sidebar" class="collapsed">
|
||
<div id="sidebar-header">
|
||
<h2 id="sidebar-title">Capacity Simulator</h2>
|
||
<span id="sidebar-toggle-icon">📦</span>
|
||
</div>
|
||
<div id="sidebar-content">
|
||
<div class="input-group">
|
||
<label>Product Width (cm)</label>
|
||
<input type="number" id="prod-w" value="10" min="1">
|
||
</div>
|
||
<div class="input-group">
|
||
<label>Product Height (cm)</label>
|
||
<input type="number" id="prod-h" value="15" min="1">
|
||
</div>
|
||
<div class="input-group">
|
||
<label>Product Depth (cm)</label>
|
||
<input type="number" id="prod-d" value="10" min="1">
|
||
</div>
|
||
<button id="btn-simulate">Run Simulation</button>
|
||
|
||
<div id="result-panel">
|
||
Capacity Estimation: <br>
|
||
<span id="result-count">0</span> units fit inside.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="container">
|
||
<canvas id="three-canvas"></canvas>
|
||
<div id="tooltip">Click to interact</div>
|
||
<div id="lock-annotation">Abiri con llave</div>
|
||
<svg id="leader-line">
|
||
<path id="line-path" d=""></path>
|
||
</svg>
|
||
</div>
|
||
|
||
<div class="info-panel">
|
||
<span id="info-content">🖱️ Click to interact | Right-click to pan | Simulator on the right</span>
|
||
<button id="btn-home">🏠 Home</button>
|
||
</div>
|
||
|
||
<div id="camera-debug">
|
||
<h3>
|
||
<span>Camera Debug</span>
|
||
<button id="btn-copy-debug">COPY</button>
|
||
</h3>
|
||
<div>POS: <span id="cam-pos">0, 0, 0</span></div>
|
||
<div>TGT: <span id="cam-tgt">0, 0, 0</span></div>
|
||
<div id="debug-last-clicked">Part: <span id="debug-part-name">none</span></div>
|
||
<div id="debug-save-row">
|
||
<input id="debug-label-input" type="text" placeholder="Label this view..." />
|
||
<button id="btn-save-view">SAVE VIEW</button>
|
||
</div>
|
||
<textarea id="debug-paragraph-input" placeholder="Description / notes for this viewpoint..."></textarea>
|
||
<div id="debug-viewpoints-list"></div>
|
||
<div id="debug-export-row">
|
||
<button id="btn-copy-json">COPY JSON</button>
|
||
<button id="btn-export-views">EXPORT FILE</button>
|
||
</div>
|
||
</div>
|
||
<div id="debug-toggle-hint">Press 'D' for Camera Coordinates</div>
|
||
|
||
<!-- Scripts -->
|
||
<script type="importmap">
|
||
{
|
||
"imports": {
|
||
"three": "https://unpkg.com/three@0.162.0/build/three.module.js",
|
||
"three/addons/": "https://unpkg.com/three@0.162.0/examples/jsm/",
|
||
"gsap": "https://cdn.skypack.dev/gsap"
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<script type="module">
|
||
import * as THREE from 'three';
|
||
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
|
||
import { RectAreaLightUniformsLib } from 'three/addons/lights/RectAreaLightUniformsLib.js';
|
||
import gsap from 'gsap';
|
||
|
||
// Initialize RectAreaLight support
|
||
RectAreaLightUniformsLib.init();
|
||
console.log("🚀 Bitua 3D Explorer - GREEN V2.1 script started");
|
||
|
||
// --- Setup ---
|
||
const canvas = document.querySelector('#three-canvas');
|
||
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
|
||
let internalLight = null; // Global reference for the cabinet light
|
||
renderer.setPixelRatio(window.devicePixelRatio);
|
||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||
renderer.shadowMap.enabled = true;
|
||
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||
renderer.toneMappingExposure = 1.0;
|
||
|
||
const scene = new THREE.Scene();
|
||
scene.background = new THREE.Color(0xf5f5f7); // Light grey background
|
||
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100);
|
||
camera.position.set(3, 1.5, 5); // Improved side-front view
|
||
|
||
const controls = new OrbitControls(camera, renderer.domElement);
|
||
controls.enableDamping = true;
|
||
controls.dampingFactor = 0.05;
|
||
|
||
// --- Lighting ---
|
||
const ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
|
||
scene.add(ambientLight);
|
||
|
||
const spotLight = new THREE.SpotLight(0xffffff, 60);
|
||
spotLight.position.set(5, 5, 5);
|
||
spotLight.castShadow = true;
|
||
scene.add(spotLight);
|
||
|
||
const fillLight = new THREE.DirectionalLight(0xffffff, 0.8);
|
||
fillLight.position.set(-5, 2, -5);
|
||
scene.add(fillLight);
|
||
|
||
// Add a basic environment map for reflections (makes metal/glass look real)
|
||
const pmremGenerator = new THREE.PMREMGenerator(renderer);
|
||
pmremGenerator.compileEquirectangularShader();
|
||
const envScene = new THREE.Scene();
|
||
|
||
// Add multiple lights to the environment to create rich reflections
|
||
const envLight1 = new THREE.PointLight(0xffffff, 100);
|
||
envLight1.position.set(5, 10, 5);
|
||
envScene.add(envLight1);
|
||
|
||
const envLight2 = new THREE.PointLight(0xffffff, 80);
|
||
envLight2.position.set(-5, 5, -5);
|
||
envScene.add(envLight2);
|
||
|
||
const envLight3 = new THREE.RectAreaLight(0xffffff, 50, 10, 10);
|
||
envLight3.position.set(0, 10, 0);
|
||
envLight3.lookAt(0, 0, 0);
|
||
envScene.add(envLight3);
|
||
|
||
const renderTarget = pmremGenerator.fromScene(envScene);
|
||
scene.environment = renderTarget.texture;
|
||
|
||
// (Internal lighting is now handled by Barra LED in setupLEDBarLighting)
|
||
|
||
// --- Model Management ---
|
||
const loader = new GLTFLoader();
|
||
const dracoLoader = new DRACOLoader();
|
||
dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.6/');
|
||
loader.setDRACOLoader(dracoLoader);
|
||
|
||
// --- Texture Loading ---
|
||
const textureLoader = new THREE.TextureLoader();
|
||
const standbyTexture = textureLoader.load('GUI_Standby.png');
|
||
standbyTexture.colorSpace = THREE.SRGBColorSpace;
|
||
standbyTexture.flipY = false; // GLTF standard
|
||
|
||
let model = null;
|
||
let isDoorOpen = false;
|
||
let hingePivot = null; // THREE.Group at the hinge axis
|
||
let centerOffset = null;
|
||
|
||
// Hinge parameters (derived from model comparison data)
|
||
// The door rotates -120° on Y-axis around the hinge pin
|
||
const DOOR_OPEN_ANGLE = -(Math.PI * 120) / 180; // -120 degrees
|
||
|
||
function setupShadows(m) {
|
||
m.traverse((child) => {
|
||
if (child.isMesh) {
|
||
child.castShadow = true;
|
||
child.receiveShadow = true;
|
||
|
||
// Ensure smooth shading
|
||
if (child.geometry) {
|
||
child.geometry.computeVertexNormals();
|
||
}
|
||
if (child.material) {
|
||
child.material.flatShading = false;
|
||
child.material.needsUpdate = true;
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function setupGlassMaterials(m) {
|
||
// Polycarbonate Material (Realistic transparent plastic)
|
||
const polycarbonateMaterial = new THREE.MeshPhysicalMaterial({
|
||
color: 0x4caf50, // Green tint
|
||
transmission: 0.95, // Highly transmissive
|
||
opacity: 1, // Solid presence, let transmission handle transparency
|
||
thickness: 0.05, // Material thickness for refraction
|
||
roughness: 0.1,
|
||
metalness: 0,
|
||
ior: 1.58, // Index of Refraction for PC
|
||
depthWrite: true, // Better for Physical materials in many cases
|
||
envMapIntensity: 2.5, // Stronger reflections
|
||
side: THREE.DoubleSide,
|
||
flatShading: false
|
||
});
|
||
|
||
// Highly transparent glass material (Clear)
|
||
const glassMaterial = new THREE.MeshPhysicalMaterial({
|
||
color: 0xffffff,
|
||
transmission: 1.0,
|
||
opacity: 1,
|
||
thickness: 0.02,
|
||
roughness: 0,
|
||
metalness: 0,
|
||
ior: 1.5, // Index of Refraction for Class
|
||
depthWrite: true,
|
||
envMapIntensity: 3.0,
|
||
side: THREE.DoubleSide,
|
||
flatShading: false
|
||
});
|
||
|
||
// White non-transparent acrylic material
|
||
const acrylicMaterial = new THREE.MeshStandardMaterial({
|
||
color: 0xffffff, // White
|
||
roughness: 0.3, // Slightly rough plastic look
|
||
metalness: 0.0,
|
||
transparent: false,
|
||
envMapIntensity: 0.8,
|
||
side: THREE.DoubleSide,
|
||
flatShading: false
|
||
});
|
||
|
||
// Aluminum material for the lock
|
||
const aluminumMaterial = new THREE.MeshStandardMaterial({
|
||
color: 0xe5e5e5, // Lighter, typical of aluminum
|
||
metalness: 1.0,
|
||
roughness: 0.4, // Slightly more matte than stainless steel
|
||
envMapIntensity: 1.5,
|
||
flatShading: false
|
||
});
|
||
|
||
const acrylicTargetNames = [
|
||
'A INTERIOR SEPARADOR IZQUIERDO:1',
|
||
'A INTERIOR SEPARADOR ATRAS:1',
|
||
'A INTERIOR SEPARADOR:1',
|
||
'V2.5 A INTERIOR SEPARADOR SUPERIOR:1',
|
||
'V2.5 A TAPA DE REGISTRO INFERIOR:1'
|
||
];
|
||
|
||
try {
|
||
const meshList = [];
|
||
console.log("🔍 Starting deep hierarchy traversal...");
|
||
|
||
let consoleMaterial = null;
|
||
const meshToUpdate = [];
|
||
|
||
m.traverse((child) => {
|
||
const meshName = child.name || "UNNAMED";
|
||
const parentName = (child.parent && child.parent.name) ? child.parent.name : "";
|
||
|
||
const normMesh = meshName.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
||
const normParent = parentName.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
||
|
||
// Combine names for matching: if it's in the hierarchy, we want it
|
||
const combinedNorm = normMesh + "_" + normParent;
|
||
|
||
if (child.isMesh) {
|
||
meshList.push({
|
||
mesh: meshName,
|
||
parent: parentName,
|
||
matched: false,
|
||
visible: child.visible
|
||
});
|
||
const lastEntry = meshList[meshList.length - 1];
|
||
|
||
// 0. GUI STANDBY (Specific Screen Mesh)
|
||
if (normMesh.includes('SOLID1_61') || normMesh.includes('PANTALLANUEVA')) {
|
||
child.material = new THREE.MeshBasicMaterial({
|
||
map: standbyTexture,
|
||
transparent: true,
|
||
side: THREE.DoubleSide
|
||
});
|
||
lastEntry.matched = "📺 GUI STANDBY";
|
||
console.log(`📺 [HIERARCHY MATCH] Applied GUI_Standby.png to: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
|
||
// Capture Console Material for synchronization
|
||
if (combinedNorm.includes('LADODERECHOCONSOLA')) {
|
||
consoleMaterial = child.material;
|
||
}
|
||
|
||
// Collect Soporte Lector for later update once consoleMaterial is found
|
||
if (combinedNorm.includes('SOPORTELECTORBIOMETRICO')) {
|
||
meshToUpdate.push(child);
|
||
}
|
||
|
||
// 1. HIDE THE DOOR: High priority
|
||
const isDoor = combinedNorm.includes('V251PPPVIDRIO') ||
|
||
(combinedNorm.includes('PUERTA') && combinedNorm.includes('VIDRIO')) ||
|
||
(combinedNorm.includes('GLASS') && combinedNorm.includes('DOOR'));
|
||
|
||
if (isDoor) {
|
||
child.visible = false;
|
||
lastEntry.matched = "👻 HIDDEN DOOR";
|
||
console.log(`👻 [HIERARCHY MATCH] Hiding: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
|
||
// 2. WHITE SUPPORTS for Trays
|
||
if (combinedNorm.includes('SOPORTE')) {
|
||
child.material = acrylicMaterial;
|
||
lastEntry.matched = "⚪ TRAY SUPPORT";
|
||
console.log(`⚪ [HIERARCHY MATCH] White Support: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
// 3. CLEAR GLASS for Glass Trays (Prioritize over green poly)
|
||
else if (combinedNorm.includes('BANDEJA') && (combinedNorm.includes('VIDRIO') || combinedNorm.includes('GLASS'))) {
|
||
child.material = glassMaterial;
|
||
lastEntry.matched = "💎 GLASS TRAY";
|
||
console.log(`💎 [HIERARCHY MATCH] Clear Glass Tray: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
// 4. GREEN POLYCARBONATE for other Trays
|
||
else if (combinedNorm.includes('BANDEJA')) {
|
||
child.material = polycarbonateMaterial;
|
||
lastEntry.matched = "🧪 GREEN TRAY";
|
||
console.log(`🧪 [HIERARCHY MATCH] Green Polycarbonate: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
// 3. TRANSPARENT GLASS for other glass parts
|
||
else if (combinedNorm.includes('VIDRIO') || combinedNorm.includes('GLASS')) {
|
||
if (child.visible) {
|
||
child.material = glassMaterial;
|
||
lastEntry.matched = "💎 GLASS";
|
||
console.log(`💎 [HIERARCHY MATCH] Glass: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
}
|
||
// 4. WHITE ACRYLIC for separators
|
||
else if (combinedNorm.includes('SEPARADOR') || acrylicTargetNames.includes(parentName.trim()) || acrylicTargetNames.includes(meshName.trim())) {
|
||
child.material = acrylicMaterial;
|
||
lastEntry.matched = "⚪ ACRYLIC";
|
||
console.log(`⚪ [HIERARCHY MATCH] White Acrylic: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
// 5. ALUMINUM for Lock
|
||
else if (combinedNorm.includes('CILINDRO') || combinedNorm.includes('CERRADURA') || normMesh.includes('SOLID1102')) {
|
||
child.material = aluminumMaterial;
|
||
lastEntry.matched = "🔑 LOCK";
|
||
console.log(`🔑 [HIERARCHY MATCH] Aluminum Lock: Mesh="${meshName}" Parent="${parentName}"`);
|
||
}
|
||
}
|
||
});
|
||
|
||
// Apply captured material for synchronization
|
||
if (consoleMaterial && meshToUpdate.length > 0) {
|
||
console.log(`🎨 Synchronizing ${meshToUpdate.length} meshes to Console Material`);
|
||
meshToUpdate.forEach(mesh => {
|
||
mesh.material = consoleMaterial;
|
||
});
|
||
}
|
||
|
||
console.log("📊 Model Mesh Inventory (Deep traversal):");
|
||
console.table(meshList);
|
||
|
||
} catch (error) {
|
||
console.error("❌ Critical error in setupGlassMaterials:", error);
|
||
}
|
||
}
|
||
|
||
function setupLEDBarLighting(m) {
|
||
let ledBarMesh = null;
|
||
console.log('--- 🔍 Scanning Model for LED Parts ---');
|
||
|
||
// Flexible name matching
|
||
const isLEDBar = (name) => {
|
||
if (!name) return false;
|
||
const normalized = name.toLowerCase().replace(/\s+/g, '');
|
||
return normalized.includes('barraled') ||
|
||
(normalized.includes('barra') && normalized.includes('led'));
|
||
};
|
||
|
||
m.traverse((child) => {
|
||
if (isLEDBar(child.name)) {
|
||
console.log(' Found Match:', child.name, child.isMesh ? '(Mesh)' : '(Group)');
|
||
|
||
// If it's a group, try to find a mesh inside it
|
||
if (child.isMesh) {
|
||
ledBarMesh = child;
|
||
} else if (child.children.length > 0) {
|
||
// Find the first mesh in the group
|
||
child.traverse((subChild) => {
|
||
if (subChild.isMesh && !ledBarMesh) {
|
||
ledBarMesh = subChild;
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
if (ledBarMesh) {
|
||
console.log('💡 Found Barra LED Mesh:', ledBarMesh.name, 'Applying emissive "ON" effect.');
|
||
|
||
// Set to a bright emissive material to look "ON"
|
||
ledBarMesh.material = new THREE.MeshStandardMaterial({
|
||
color: 0xffffff,
|
||
emissive: 0xffffff,
|
||
emissiveIntensity: 10, // High intensity to simulate glow
|
||
metalness: 0.1,
|
||
roughness: 0.1,
|
||
flatShading: false
|
||
});
|
||
|
||
// Add an actual interior light source to simulate light coming from the LED bar
|
||
const box = new THREE.Box3().setFromObject(ledBarMesh);
|
||
const size = new THREE.Vector3();
|
||
box.getSize(size);
|
||
|
||
const width = Math.max(size.x, 0.05);
|
||
const height = Math.max(size.z, 0.05);
|
||
|
||
const center = new THREE.Vector3();
|
||
box.getCenter(center);
|
||
|
||
// The door rotation logic depends on matrices not being preemptively updated globally.
|
||
// Convert center to local by directly subtracting the model's position since the model has no rotation.
|
||
const localPos = center.clone().sub(m.position);
|
||
|
||
// Use RectAreaLight for a realistic bar light effect
|
||
const rectLight = new THREE.RectAreaLight(0xffffff, 5, width, height);
|
||
rectLight.position.set(localPos.x, localPos.y - 0.02, localPos.z);
|
||
rectLight.rotation.x = -Math.PI / 2; // Point the light downward
|
||
m.add(rectLight);
|
||
|
||
// Add a PointLight for broader interior illumination
|
||
const pointLight = new THREE.PointLight(0xffffff, 3, 5); // Color, Intensity, Distance
|
||
pointLight.position.set(localPos.x, localPos.y - 0.05, localPos.z);
|
||
m.add(pointLight);
|
||
|
||
console.log('💡 Added interior lights at the LED bar position.');
|
||
} else {
|
||
console.warn('⚠️ Could not find "Barra LED" in the model');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Hinge Pivot Logic:
|
||
*
|
||
* From the CAD reference:
|
||
* - Blue side (left) = fixed to cabinet body, NEVER moves
|
||
* - Green side (right) = fixed to the door, moves WITH the door
|
||
* - Red dashed line = rotation axis (vertical, thru center of cylindrical pin)
|
||
*
|
||
* The door + door-side hinge parts rotate together around the
|
||
* hinge pin axis. We create a pivot group at that axis and
|
||
* re-parent the moving nodes into it.
|
||
*/
|
||
function setupHingePivot() {
|
||
// 1. Collect nodes to find the pivot axis position and separation logic
|
||
const hingeAssemblies = [];
|
||
const doorNodes = [];
|
||
let ejeRotacionNode = null;
|
||
let leftPanelNode = null;
|
||
|
||
model.traverse((child) => {
|
||
if (!child.name) return;
|
||
|
||
// Hinge assemblies
|
||
if (child.name.includes('BISAGRA')) {
|
||
// Only push the top-level assembly groups
|
||
if (child.parent && !child.parent.name.includes('BISAGRA')) {
|
||
hingeAssemblies.push(child);
|
||
}
|
||
}
|
||
// Door assembly (top level) — match both old and new model names
|
||
const normChildDoor = child.name.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
||
const parentNameUpper = (child.parent && child.parent.name) ? child.parent.name.toUpperCase() : '';
|
||
if (child.name === 'V251_PPP_PUERTA1' ||
|
||
(normChildDoor.includes('PUERTA') && !parentNameUpper.includes('PUERTA'))) {
|
||
doorNodes.push(child);
|
||
}
|
||
// Check for explicit rotation axis part
|
||
if (child.name.toLowerCase().includes('eje') && child.name.toLowerCase().includes('rotaci')) {
|
||
ejeRotacionNode = child;
|
||
} else if (child.name.includes('Eje') && child.name.includes('rotaci')) {
|
||
ejeRotacionNode = child;
|
||
}
|
||
// Match left panel for proximity testing
|
||
if (child.name.toUpperCase().includes('PANEL IZQUIERDO')) {
|
||
leftPanelNode = child;
|
||
}
|
||
});
|
||
|
||
if (hingeAssemblies.length === 0 && doorNodes.length === 0 && !ejeRotacionNode) {
|
||
console.warn('⚠️ Could not find door/hinge nodes by name. Listing all node names:');
|
||
model.traverse((c) => { if (c.name) console.log(' Node:', c.name, '| Type:', c.type); });
|
||
return;
|
||
}
|
||
|
||
console.log(`🔧 Found ${hingeAssemblies.length} hinge assemblies, ${doorNodes.length} door nodes, Left Panel: ${!!leftPanelNode}`);
|
||
|
||
// 1.5 Extract only the moving hinge parts
|
||
const hingeNodes = [];
|
||
let leftPanelBox = new THREE.Box3();
|
||
let doorBox = new THREE.Box3();
|
||
|
||
if (leftPanelNode) leftPanelBox.setFromObject(leftPanelNode);
|
||
if (doorNodes.length > 0) doorBox.setFromObject(doorNodes[0]);
|
||
|
||
hingeAssemblies.forEach(assembly => {
|
||
const allMeshes = [];
|
||
assembly.traverse((child) => {
|
||
if (child.isMesh) {
|
||
allMeshes.push(child);
|
||
}
|
||
});
|
||
|
||
if (allMeshes.length > 0) {
|
||
const centers = new Map();
|
||
let minX = Infinity;
|
||
let maxX = -Infinity;
|
||
|
||
allMeshes.forEach(mesh => {
|
||
const box = new THREE.Box3().setFromObject(mesh);
|
||
const center = new THREE.Vector3();
|
||
box.getCenter(center);
|
||
centers.set(mesh, center);
|
||
if (center.x < minX) minX = center.x;
|
||
if (center.x > maxX) maxX = center.x;
|
||
});
|
||
|
||
// Define the separation line between left (fixed) and right (moving)
|
||
// If minX and maxX are very close, ensure some difference
|
||
const thresholdX = (minX + Math.max(minX + 0.001, maxX)) / 2;
|
||
|
||
let movingCount = 0;
|
||
let fixedCount = 0;
|
||
|
||
allMeshes.forEach(mesh => {
|
||
const center = centers.get(mesh);
|
||
if (center.x > thresholdX) {
|
||
// Right side -> Moving
|
||
hingeNodes.push(mesh);
|
||
movingCount++;
|
||
} else {
|
||
// Left side -> Fixed (keep original GLB color for uniform appearance)
|
||
fixedCount++;
|
||
}
|
||
});
|
||
|
||
console.log(` - Assembly split: ${fixedCount} fixed, ${movingCount} moving`);
|
||
} else {
|
||
console.warn('⚠️ Hinge assembly has no meshes:', assembly.name);
|
||
hingeNodes.push(assembly);
|
||
}
|
||
});
|
||
|
||
// 2. Compute the hinge pivot position in world space
|
||
// The pivot is at the center of the "Eje rotación" part, or average X/Z of hinge assemblies.
|
||
let pivotWorldPos = new THREE.Vector3();
|
||
|
||
if (ejeRotacionNode) {
|
||
console.log(`🎯 Using explicit axis part '${ejeRotacionNode.name}'`);
|
||
const box = new THREE.Box3().setFromObject(ejeRotacionNode);
|
||
box.getCenter(pivotWorldPos);
|
||
// Hide the axis part from view
|
||
ejeRotacionNode.visible = false;
|
||
} else if (hingeNodes.length > 0) {
|
||
// Use the world position of hinge nodes to find the axis
|
||
hingeNodes.forEach(h => {
|
||
const worldPos = new THREE.Vector3();
|
||
h.getWorldPosition(worldPos);
|
||
pivotWorldPos.add(worldPos);
|
||
});
|
||
pivotWorldPos.divideScalar(hingeNodes.length);
|
||
} else {
|
||
// Fallback: use the door's left edge
|
||
const doorNode = doorNodes[0];
|
||
const box = new THREE.Box3().setFromObject(doorNode);
|
||
pivotWorldPos.set(box.min.x, (box.min.y + box.max.y) / 2, box.min.z);
|
||
}
|
||
|
||
// We only care about X and Z for the pivot — Y is the rotation axis
|
||
// Set Y to 0 (the pivot group's Y doesn't matter since we rotate around Y)
|
||
pivotWorldPos.y = 0;
|
||
|
||
console.log('📍 Hinge pivot world position:', pivotWorldPos);
|
||
|
||
// 3. Create pivot group in the model's parent coordinate space
|
||
hingePivot = new THREE.Group();
|
||
hingePivot.name = 'HingePivot';
|
||
|
||
// Position the pivot in the model's local space
|
||
// Since model has been offset by centerOffset, we need to account for that
|
||
const pivotLocalPos = pivotWorldPos.clone();
|
||
// The model's world transform is just the position offset we applied
|
||
// So local pos relative to model = worldPos (since model is at scene root level)
|
||
hingePivot.position.copy(pivotLocalPos);
|
||
model.add(hingePivot);
|
||
|
||
// 4. Re-parent door and hinge nodes into the pivot group
|
||
// We must adjust their position so their world position stays the same
|
||
const nodesToReparent = [...doorNodes, ...hingeNodes];
|
||
|
||
nodesToReparent.forEach(node => {
|
||
// Get the node's current world position and quaternion
|
||
const worldPos = new THREE.Vector3();
|
||
const worldQuat = new THREE.Quaternion();
|
||
const worldScale = new THREE.Vector3();
|
||
node.getWorldPosition(worldPos);
|
||
node.getWorldQuaternion(worldQuat);
|
||
node.getWorldScale(worldScale);
|
||
|
||
// Remove from current parent
|
||
const oldParent = node.parent;
|
||
if (oldParent) oldParent.remove(node);
|
||
|
||
// Add to pivot group
|
||
hingePivot.add(node);
|
||
|
||
// Compute new local position relative to pivot
|
||
// newLocalPos = inversePivotWorldMatrix * worldPos
|
||
const pivotWorldMatrix = new THREE.Matrix4();
|
||
hingePivot.updateWorldMatrix(true, false);
|
||
pivotWorldMatrix.copy(hingePivot.matrixWorld).invert();
|
||
|
||
const newWorldMatrix = new THREE.Matrix4().compose(worldPos, worldQuat, worldScale);
|
||
const newLocalMatrix = pivotWorldMatrix.multiply(newWorldMatrix);
|
||
|
||
// Decompose back into position/quaternion/scale
|
||
const newPos = new THREE.Vector3();
|
||
const newQuat = new THREE.Quaternion();
|
||
const newScale = new THREE.Vector3();
|
||
newLocalMatrix.decompose(newPos, newQuat, newScale);
|
||
|
||
node.position.copy(newPos);
|
||
node.quaternion.copy(newQuat);
|
||
node.scale.copy(newScale);
|
||
|
||
console.log(` ↳ Re-parented "${node.name}" into pivot group`);
|
||
});
|
||
|
||
console.log('✅ Hinge pivot setup complete!');
|
||
}
|
||
|
||
// Load the model
|
||
loader.load(
|
||
'V2.5.1 AAA ENSAMBLE CABINET MAIN 3D visualizer.glb',
|
||
(gltf) => {
|
||
model = gltf.scene;
|
||
|
||
// Center using bounding box
|
||
const box = new THREE.Box3().setFromObject(model);
|
||
centerOffset = box.getCenter(new THREE.Vector3());
|
||
model.position.sub(centerOffset);
|
||
|
||
setupShadows(model);
|
||
setupGlassMaterials(model);
|
||
setupLEDBarLighting(model);
|
||
scene.add(model);
|
||
|
||
// Set up hinge pivot after model is in the scene
|
||
setupHingePivot();
|
||
|
||
// Hide loader
|
||
document.getElementById('progress').style.width = '100%';
|
||
document.getElementById('loader').style.opacity = '0';
|
||
setTimeout(() => document.getElementById('loader').style.display = 'none', 500);
|
||
|
||
console.log('✅ Model loaded and hinge pivot configured');
|
||
console.log('Model World Position:', model.position);
|
||
const bBox = new THREE.Box3().setFromObject(model);
|
||
console.log('Model Bounding Box Size:', bBox.getSize(new THREE.Vector3()));
|
||
console.log('Model Bounding Box Center:', bBox.getCenter(new THREE.Vector3()));
|
||
},
|
||
(progress) => {
|
||
if (progress.total > 0) {
|
||
const percent = (progress.loaded / progress.total) * 100;
|
||
document.getElementById('progress').style.width = percent + '%';
|
||
}
|
||
},
|
||
(error) => console.error('Error loading model:', error)
|
||
);
|
||
|
||
// --- Interaction ---
|
||
const raycaster = new THREE.Raycaster();
|
||
const mouse = new THREE.Vector2();
|
||
let hoveredMesh = null;
|
||
|
||
function isInteractiveMesh(object) {
|
||
if (!object) return false;
|
||
const norm = object.name.toUpperCase();
|
||
if (norm.includes('CILINDRO') || norm.includes('CERRADURA') || norm.includes('SOLID1_102')) return true;
|
||
if (norm.includes('SOLID1_114') || norm.includes('SOLID1_37') || norm.includes('SOLID1_41') ||
|
||
norm.includes('SOLID1_40') || norm.includes('SOLID1_39') ||
|
||
norm.includes('HUELLERO') || norm.includes('LECTOR') || norm.includes('BIOMETRICO')) return true;
|
||
if (norm.includes('SOLID1_103')) return true;
|
||
if (norm.includes('MESHFEATURE1') || norm.includes('SOLID1_105')) return true;
|
||
let isDoor = false;
|
||
object.traverseAncestors((ancestor) => {
|
||
if (ancestor.name && (
|
||
ancestor.name.includes('PUERTA') ||
|
||
ancestor.name.includes('BISAGRA') ||
|
||
ancestor.name === 'HingePivot'
|
||
)) isDoor = true;
|
||
});
|
||
if (isDoor) return true;
|
||
if (norm.includes('PUERTA') || norm.includes('BISAGRA')) return true;
|
||
return false;
|
||
}
|
||
|
||
function applyHoverGlow(mesh) {
|
||
if (!mesh.userData.glowCloned) {
|
||
const origMat = mesh.material;
|
||
mesh.material = origMat.clone();
|
||
if (mesh.material.emissive) {
|
||
mesh.material.emissive = mesh.material.emissive.clone();
|
||
mesh.userData.origEmissive = mesh.material.emissive.getHex();
|
||
} else {
|
||
mesh.userData.origEmissive = 0x000000;
|
||
}
|
||
mesh.userData.origEmissiveIntensity = mesh.material.emissiveIntensity || 0;
|
||
mesh.userData.glowCloned = true;
|
||
}
|
||
if (mesh.material.emissive) {
|
||
mesh.material.emissive.setHex(0x88bbff);
|
||
mesh.material.emissiveIntensity = 0.22;
|
||
}
|
||
}
|
||
|
||
function removeHoverGlow(mesh) {
|
||
if (!mesh || !mesh.userData.glowCloned) return;
|
||
if (mesh.material.emissive) {
|
||
mesh.material.emissive.setHex(mesh.userData.origEmissive);
|
||
mesh.material.emissiveIntensity = mesh.userData.origEmissiveIntensity;
|
||
}
|
||
}
|
||
|
||
function handleHover(hitObject) {
|
||
const interactive = hitObject && isInteractiveMesh(hitObject) ? hitObject : null;
|
||
if (interactive === hoveredMesh) return;
|
||
|
||
// Restore previous
|
||
if (hoveredMesh) {
|
||
removeHoverGlow(hoveredMesh);
|
||
hoveredMesh = null;
|
||
}
|
||
|
||
if (interactive) {
|
||
applyHoverGlow(interactive);
|
||
hoveredMesh = interactive;
|
||
canvas.style.cursor = 'pointer';
|
||
} else {
|
||
canvas.style.cursor = 'default';
|
||
}
|
||
}
|
||
|
||
window.addEventListener('click', (event) => {
|
||
if (event.target.closest('#sidebar') || event.target.closest('#dev-sidebar')) return;
|
||
|
||
const rect = canvas.getBoundingClientRect();
|
||
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
||
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
||
|
||
raycaster.setFromCamera(mouse, camera);
|
||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||
|
||
if (intersects.length > 0) {
|
||
const object = intersects[0].object;
|
||
|
||
console.log('Clicked:', object.name);
|
||
lastClickedPart = object.name;
|
||
if (debugPartName) debugPartName.textContent = object.name || 'unnamed';
|
||
const normName = object.name.toUpperCase();
|
||
|
||
// Check if clicking door or hinge area (traverse ancestors including pivot)
|
||
let isDoorClick = false;
|
||
object.traverseAncestors((ancestor) => {
|
||
if (ancestor.name && (
|
||
ancestor.name.includes('PUERTA') ||
|
||
ancestor.name.includes('BISAGRA') ||
|
||
ancestor.name === 'HingePivot'
|
||
)) {
|
||
isDoorClick = true;
|
||
}
|
||
});
|
||
|
||
if (normName.includes('CILINDRO') || normName.includes('CERRADURA') || normName.includes('SOLID1_102')) {
|
||
zoomToLock(object);
|
||
showAnnotation(object, "<strong>Abrir con llave.</strong><br>Ante cortes de energía, la maquina permanece cerrada");
|
||
} else if (normName.includes('SOLID1_114') || normName.includes('SOLID1_37') || normName.includes('SOLID1_41') || normName.includes('SOLID1_40') || normName.includes('SOLID1_39') || normName.includes('HUELLERO') || normName.includes('LECTOR') || normName.includes('BIOMETRICO')) {
|
||
zoomToBiometric(object);
|
||
showAnnotation(object, `
|
||
<strong>Apertura biométrica</strong><br>
|
||
<span style="font-size: 14px; opacity: 0.8;">Funcionalidades acorde a rol del usuario</span>
|
||
<div style="margin-top: 10px; font-size: 13px; font-weight: 400; line-height: 1.4;">
|
||
<strong>Usuarios clínicos:</strong> Uso diario, consumen insumos<br>
|
||
<strong>Operador:</strong> Repone inventario.
|
||
</div>
|
||
`);
|
||
if (!isDoorOpen) toggleDoor();
|
||
} else if (normName.includes('SOLID1_103')) {
|
||
zoomToBiometric(object);
|
||
showAnnotation(object, "<strong>Reconocimiento facial (Opcional)</strong><br>Apertura de puerta con reconocimiento facial");
|
||
} else if (normName.includes('MESHFEATURE1') || normName.includes('SOLID1_105')) {
|
||
zoomToCamera(object);
|
||
showAnnotation(object, "<strong>Cámara (Opcional)</strong><br>Grabación de sesión cuando se abre la puerta.");
|
||
} else if (object.name.includes('PUERTA') || object.name.includes('BISAGRA') || isDoorClick) {
|
||
toggleDoor();
|
||
hideAnnotation();
|
||
} else if (object.name.includes('LECTOR') || object.name.includes('BIOMETRICO')) {
|
||
showInfo("Face Recognition Security", "Our AI-powered volumetric face recognition identifies users in under 0.5 seconds, ensuring hands-free, high-security access.");
|
||
hideAnnotation();
|
||
} else {
|
||
showInfo("Interactive Display & Navigation", "Navigate through stored inventory, track usage logs, and manage permissions directly from this integrated touchscreen.");
|
||
hideAnnotation();
|
||
}
|
||
} else {
|
||
hideInfo();
|
||
hideAnnotation();
|
||
}
|
||
});
|
||
|
||
window.addEventListener('mousemove', (event) => {
|
||
if (!model) return;
|
||
if (event.target.closest('#sidebar') || event.target.closest('#dev-sidebar')) {
|
||
handleHover(null);
|
||
return;
|
||
}
|
||
const rect = canvas.getBoundingClientRect();
|
||
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
||
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
||
|
||
raycaster.setFromCamera(mouse, camera);
|
||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||
handleHover(intersects.length > 0 ? intersects[0].object : null);
|
||
});
|
||
|
||
// --- Specialized Lock Interaction Functions ---
|
||
let currentLockTarget = null;
|
||
|
||
function smoothCameraTransition(newPos, newTarget, duration = 1.5) {
|
||
// Animate camera position
|
||
gsap.to(camera.position, {
|
||
x: newPos.x,
|
||
y: newPos.y,
|
||
z: newPos.z,
|
||
duration: duration,
|
||
ease: "power2.inOut",
|
||
overwrite: "auto"
|
||
});
|
||
|
||
// Animate orbital controls target (focal point)
|
||
gsap.to(controls.target, {
|
||
x: newTarget.x,
|
||
y: newTarget.y,
|
||
z: newTarget.z,
|
||
duration: duration,
|
||
ease: "power2.inOut",
|
||
overwrite: "auto",
|
||
onUpdate: () => {
|
||
camera.lookAt(controls.target);
|
||
}
|
||
});
|
||
}
|
||
|
||
function zoomToLock(target) {
|
||
const worldPos = new THREE.Vector3();
|
||
target.getWorldPosition(worldPos);
|
||
|
||
const zoomTarget = worldPos.clone();
|
||
const cameraTargetPos = worldPos.clone().add(new THREE.Vector3(0.45, 0.15, 0.75));
|
||
|
||
smoothCameraTransition(cameraTargetPos, zoomTarget);
|
||
}
|
||
|
||
function zoomToBiometric(target) {
|
||
const cameraFrontalPos = new THREE.Vector3(0.048, 0.720, 4.001);
|
||
const lookAtTarget = new THREE.Vector3(-0.033, -0.279, 0.108);
|
||
|
||
smoothCameraTransition(cameraFrontalPos, lookAtTarget);
|
||
}
|
||
|
||
function zoomToCamera(target) {
|
||
// Using user-provided coordinates for exact perspective
|
||
const cameraTargetPos = new THREE.Vector3(1.333, 0.388, 1.915);
|
||
const focusTarget = new THREE.Vector3(0.094, 0.287, 0.417);
|
||
|
||
smoothCameraTransition(cameraTargetPos, focusTarget);
|
||
}
|
||
|
||
function showAnnotation(target, text) {
|
||
currentLockTarget = target;
|
||
const annotation = document.getElementById('lock-annotation');
|
||
const svg = document.getElementById('leader-line');
|
||
|
||
annotation.innerHTML = text;
|
||
annotation.style.display = 'block';
|
||
svg.style.display = 'block';
|
||
|
||
updateAnnotationPosition();
|
||
}
|
||
|
||
function hideAnnotation() {
|
||
currentLockTarget = null;
|
||
document.getElementById('lock-annotation').style.display = 'none';
|
||
document.getElementById('leader-line').style.display = 'none';
|
||
}
|
||
|
||
function updateAnnotationPosition() {
|
||
if (!currentLockTarget) return;
|
||
|
||
const worldPos = new THREE.Vector3();
|
||
currentLockTarget.getWorldPosition(worldPos);
|
||
|
||
// Project to screen
|
||
const vector = worldPos.clone().project(camera);
|
||
|
||
const x = (vector.x * 0.5 + 0.5) * canvas.clientWidth;
|
||
const y = (1 - (vector.y * 0.5 + 0.5)) * canvas.clientHeight;
|
||
|
||
const annotation = document.getElementById('lock-annotation');
|
||
const path = document.getElementById('line-path');
|
||
|
||
// Position annotation box offset from the lock
|
||
const boxX = x + 100;
|
||
const boxY = y - 50;
|
||
|
||
annotation.style.left = `${boxX}px`;
|
||
annotation.style.top = `${boxY}px`;
|
||
|
||
// Update SVG line
|
||
// Start at the center of the box, end at the lock position
|
||
const boxRect = annotation.getBoundingClientRect();
|
||
const startX = boxX; // Left side of box
|
||
const startY = boxY + boxRect.height / 2;
|
||
|
||
path.setAttribute('d', `M ${startX} ${startY} L ${x} ${y}`);
|
||
}
|
||
|
||
// Add hover effect
|
||
window.addEventListener('mousemove', (event) => {
|
||
const rect = canvas.getBoundingClientRect();
|
||
mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
|
||
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
||
|
||
raycaster.setFromCamera(mouse, camera);
|
||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||
|
||
if (intersects.length > 0) {
|
||
const name = intersects[0].object.name.toLowerCase();
|
||
if (name.includes('puerta') || name.includes('bisagra') || name.includes('lector') || name.includes('solid') || name.includes('cilindro') || name.includes('cerradura') || name.includes('solid1_102') || name.includes('solid1_103')) {
|
||
canvas.style.cursor = 'pointer';
|
||
return;
|
||
}
|
||
}
|
||
canvas.style.cursor = 'default';
|
||
});
|
||
|
||
function showInfo(title, text) {
|
||
const content = document.getElementById('info-content');
|
||
const panel = document.querySelector('.info-panel');
|
||
content.innerHTML = `<strong>${title}</strong><br>${text}`;
|
||
panel.style.background = 'rgba(0, 122, 255, 0.9)';
|
||
}
|
||
|
||
function hideInfo() {
|
||
const content = document.getElementById('info-content');
|
||
const panel = document.querySelector('.info-panel');
|
||
content.innerHTML = '🖱️ Click components to explore | Right-click to pan | Scroll to zoom';
|
||
panel.style.background = 'rgba(0, 0, 0, 0.7)';
|
||
}
|
||
|
||
function resetView() {
|
||
const defaultPos = new THREE.Vector3(3.000, 1.500, 5.000);
|
||
const defaultTarget = new THREE.Vector3(0.000, 0.000, 0.000);
|
||
smoothCameraTransition(defaultPos, defaultTarget);
|
||
}
|
||
|
||
document.getElementById('btn-home').addEventListener('click', (e) => {
|
||
e.stopPropagation();
|
||
resetView();
|
||
});
|
||
|
||
function toggleDoor() {
|
||
if (!hingePivot) return;
|
||
isDoorOpen = !isDoorOpen;
|
||
|
||
// Rotate the entire pivot group around Y-axis
|
||
// This swings the door + hinge parts around the hinge pin
|
||
const targetAngle = isDoorOpen ? DOOR_OPEN_ANGLE : 0;
|
||
|
||
gsap.to(hingePivot.rotation, {
|
||
y: targetAngle,
|
||
duration: 1.2,
|
||
ease: "power2.inOut"
|
||
});
|
||
|
||
console.log('🚪 Door animating to:', isDoorOpen ? 'OPEN (−120°)' : 'CLOSED (0°)');
|
||
}
|
||
|
||
// --- UI Logic ---
|
||
const sidebar = document.getElementById('sidebar');
|
||
const sidebarHeader = document.getElementById('sidebar-header');
|
||
|
||
sidebarHeader.addEventListener('click', () => {
|
||
sidebar.classList.toggle('collapsed');
|
||
const icon = document.getElementById('sidebar-toggle-icon');
|
||
icon.textContent = sidebar.classList.contains('collapsed') ? '📦' : '✕';
|
||
});
|
||
|
||
// --- Simulator Logic ---
|
||
let simBoxes = [];
|
||
// Approximate interior dimensions (to be refined after model analysis)
|
||
const INTERIOR_SIZE = { x: 0.8, y: 1.6, z: 0.5 }; // meters
|
||
const INTERIOR_OFFSET = { x: 0, y: 0.5, z: 0 };
|
||
|
||
document.getElementById('btn-simulate').addEventListener('click', runSimulation);
|
||
|
||
function runSimulation() {
|
||
// 1. Clear previous simulation
|
||
simBoxes.forEach(box => scene.remove(box));
|
||
simBoxes = [];
|
||
|
||
// 2. Get inputs (convert cm to m)
|
||
const pw = parseFloat(document.getElementById('prod-w').value) / 100;
|
||
const ph = parseFloat(document.getElementById('prod-h').value) / 100;
|
||
const pd = parseFloat(document.getElementById('prod-d').value) / 100;
|
||
|
||
if (isNaN(pw) || isNaN(ph) || isNaN(pd) || pw <= 0 || ph <= 0 || pd <= 0) return;
|
||
|
||
// 3. Simple Packing (Grid based)
|
||
const gap = 0.005; // 5mm gap between items
|
||
|
||
const nx = Math.floor(INTERIOR_SIZE.x / (pw + gap));
|
||
const ny = Math.floor(INTERIOR_SIZE.y / (ph + gap));
|
||
const nz = Math.floor(INTERIOR_SIZE.z / (pd + gap));
|
||
|
||
const totalCapacity = nx * ny * nz;
|
||
|
||
// 4. Update UI
|
||
document.getElementById('result-panel').style.display = 'block';
|
||
document.getElementById('result-count').innerText = totalCapacity;
|
||
|
||
// 5. Spawn Preview (Limited to max 500 visual boxes)
|
||
const visualLimit = Math.min(totalCapacity, 500);
|
||
|
||
const boxGeo = new THREE.BoxGeometry(pw, ph, pd);
|
||
const boxMat = new THREE.MeshPhongMaterial({
|
||
color: 0x007aff,
|
||
transparent: true,
|
||
opacity: 0.7,
|
||
shininess: 50
|
||
});
|
||
|
||
let spawned = 0;
|
||
for (let z = 0; z < nz; z++) {
|
||
for (let y = 0; y < ny; y++) {
|
||
for (let x = 0; x < nx; x++) {
|
||
if (spawned >= visualLimit) break;
|
||
|
||
const mesh = new THREE.Mesh(boxGeo, boxMat);
|
||
|
||
mesh.position.x = (x * (pw + gap)) - (INTERIOR_SIZE.x / 2) + (pw / 2);
|
||
mesh.position.y = (y * (ph + gap)) - (INTERIOR_SIZE.y / 2) + (ph / 2) + INTERIOR_OFFSET.y;
|
||
mesh.position.z = (z * (pd + gap)) - (INTERIOR_SIZE.z / 2) + (pd / 2);
|
||
|
||
scene.add(mesh);
|
||
simBoxes.push(mesh);
|
||
spawned++;
|
||
}
|
||
if (spawned >= visualLimit) break;
|
||
}
|
||
if (spawned >= visualLimit) break;
|
||
}
|
||
|
||
// Animate boxes appearing
|
||
if (simBoxes.length > 0) {
|
||
gsap.from(simBoxes.map(b => b.scale), {
|
||
x: 0, y: 0, z: 0,
|
||
duration: 0.5,
|
||
stagger: 0.01,
|
||
ease: "back.out(1.7)"
|
||
});
|
||
}
|
||
|
||
// If door is closed, open it to show the interior
|
||
if (!isDoorOpen) toggleDoor();
|
||
}
|
||
|
||
// --- Camera Debug logic ---
|
||
const debugOverlay = document.getElementById('camera-debug');
|
||
const camPosEl = document.getElementById('cam-pos');
|
||
const camTgtEl = document.getElementById('cam-tgt');
|
||
const btnCopyDebug = document.getElementById('btn-copy-debug');
|
||
const btnSaveView = document.getElementById('btn-save-view');
|
||
const debugLabelInput = document.getElementById('debug-label-input');
|
||
const debugViewpointsList = document.getElementById('debug-viewpoints-list');
|
||
const btnExportViews = document.getElementById('btn-export-views');
|
||
const btnCopyJson = document.getElementById('btn-copy-json');
|
||
const debugExportRow = document.getElementById('debug-export-row');
|
||
const debugParagraphInput = document.getElementById('debug-paragraph-input');
|
||
const debugPartName = document.getElementById('debug-part-name');
|
||
const savedViewpoints = [];
|
||
let lastClickedPart = null;
|
||
let debugEnabled = false;
|
||
|
||
window.addEventListener('keydown', (e) => {
|
||
if (e.key.toLowerCase() === 'd') {
|
||
debugEnabled = !debugEnabled;
|
||
debugOverlay.style.display = debugEnabled ? 'block' : 'none';
|
||
console.log('🐞 Camera debug toggled:', debugEnabled);
|
||
}
|
||
});
|
||
|
||
btnCopyDebug.addEventListener('click', () => {
|
||
const p = camera.position;
|
||
const t = controls.target;
|
||
const text = `POS: ${p.x.toFixed(3)}, ${p.y.toFixed(3)}, ${p.z.toFixed(3)}\nTGT: ${t.x.toFixed(3)}, ${t.y.toFixed(3)}, ${t.z.toFixed(3)}`;
|
||
|
||
navigator.clipboard.writeText(text).then(() => {
|
||
const originalText = btnCopyDebug.textContent;
|
||
btnCopyDebug.textContent = 'COPIED!';
|
||
btnCopyDebug.style.background = '#ffffff';
|
||
setTimeout(() => {
|
||
btnCopyDebug.textContent = originalText;
|
||
btnCopyDebug.style.background = '#00ff00';
|
||
}, 1500);
|
||
});
|
||
});
|
||
|
||
function renderViewpointsList() {
|
||
debugViewpointsList.innerHTML = '';
|
||
savedViewpoints.forEach((vp, i) => {
|
||
const entry = document.createElement('div');
|
||
entry.className = 'debug-vp-entry';
|
||
entry.innerHTML = `
|
||
<div style="flex:1;min-width:0">
|
||
<div class="debug-vp-label">${vp.label}</div>
|
||
${vp.part ? `<div class="debug-vp-coords" style="color:#ffff00">Part: ${vp.part}</div>` : ''}
|
||
${vp.paragraph ? `<div class="debug-vp-coords" style="color:#aaaaff;white-space:pre-wrap">${vp.paragraph}</div>` : ''}
|
||
<div class="debug-vp-coords">P: ${vp.position.x}, ${vp.position.y}, ${vp.position.z}</div>
|
||
<div class="debug-vp-coords">T: ${vp.target.x}, ${vp.target.y}, ${vp.target.z}</div>
|
||
</div>
|
||
<button class="debug-vp-del" data-index="${i}" title="Delete">✕</button>
|
||
`;
|
||
debugViewpointsList.appendChild(entry);
|
||
});
|
||
debugViewpointsList.querySelectorAll('.debug-vp-del').forEach(btn => {
|
||
btn.addEventListener('click', () => {
|
||
savedViewpoints.splice(parseInt(btn.dataset.index), 1);
|
||
renderViewpointsList();
|
||
});
|
||
});
|
||
debugExportRow.style.display = savedViewpoints.length > 0 ? 'flex' : 'none';
|
||
}
|
||
|
||
btnSaveView.addEventListener('click', () => {
|
||
const label = debugLabelInput.value.trim() || `View ${savedViewpoints.length + 1}`;
|
||
const p = camera.position;
|
||
const t = controls.target;
|
||
savedViewpoints.push({
|
||
label,
|
||
paragraph: debugParagraphInput.value.trim(),
|
||
part: lastClickedPart || null,
|
||
position: { x: +p.x.toFixed(4), y: +p.y.toFixed(4), z: +p.z.toFixed(4) },
|
||
target: { x: +t.x.toFixed(4), y: +t.y.toFixed(4), z: +t.z.toFixed(4) }
|
||
});
|
||
debugLabelInput.value = '';
|
||
debugParagraphInput.value = '';
|
||
renderViewpointsList();
|
||
});
|
||
|
||
debugLabelInput.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Enter') btnSaveView.click();
|
||
e.stopPropagation();
|
||
});
|
||
|
||
debugParagraphInput.addEventListener('keydown', (e) => { e.stopPropagation(); });
|
||
|
||
btnExportViews.addEventListener('click', () => {
|
||
const blob = new Blob([JSON.stringify(savedViewpoints, null, 2)], { type: 'application/json' });
|
||
const url = URL.createObjectURL(blob);
|
||
const a = document.createElement('a');
|
||
a.href = url; a.download = 'viewpoints.json'; a.click();
|
||
URL.revokeObjectURL(url);
|
||
});
|
||
|
||
btnCopyJson.addEventListener('click', () => {
|
||
navigator.clipboard.writeText(JSON.stringify(savedViewpoints, null, 2)).then(() => {
|
||
btnCopyJson.textContent = 'COPIED!';
|
||
btnCopyJson.style.background = '#ffffff';
|
||
setTimeout(() => {
|
||
btnCopyJson.textContent = 'COPY JSON';
|
||
btnCopyJson.style.background = '#00ff00';
|
||
}, 1500);
|
||
});
|
||
});
|
||
|
||
function updateDebugOverlay() {
|
||
if (!debugEnabled) return;
|
||
const p = camera.position;
|
||
const t = controls.target;
|
||
camPosEl.textContent = `${p.x.toFixed(3)}, ${p.y.toFixed(3)}, ${p.z.toFixed(3)}`;
|
||
camTgtEl.textContent = `${t.x.toFixed(3)}, ${t.y.toFixed(3)}, ${t.z.toFixed(3)}`;
|
||
}
|
||
|
||
// --- Render Loop ---
|
||
function animate() {
|
||
requestAnimationFrame(animate);
|
||
controls.update();
|
||
updateAnnotationPosition();
|
||
updateDebugOverlay();
|
||
renderer.render(scene, camera);
|
||
}
|
||
|
||
animate();
|
||
|
||
// --- Resize ---
|
||
window.addEventListener('resize', () => {
|
||
camera.aspect = window.innerWidth / window.innerHeight;
|
||
camera.updateProjectionMatrix();
|
||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||
});
|
||
|
||
</script>
|
||
</body>
|
||
|
||
</html> |