diff --git a/web/pose_3d.js b/web/pose_3d.js index d73e19c..5caa248 100644 --- a/web/pose_3d.js +++ b/web/pose_3d.js @@ -241,12 +241,17 @@ function syncGhostsToTargetOrReal() { // ghost segue il target locale (mosso dal gizmo) ghost.visible = true; } else if (side === state.active_side) { - // ghost allineato al reale (preparato per drag) + // ghost allineato al reale (preparato per drag). + // Fallback se /state e' offline: copia dall'arm visibile. const real = state.current[side]; + const arm = state.arms[side]; if (real) { ghost.position.set(real.position[0], real.position[1], real.position[2]); ghost.quaternion.set(real.quaternion[0], real.quaternion[1], real.quaternion[2], real.quaternion[3]); + } else if (arm) { + ghost.position.copy(arm.position); + ghost.quaternion.copy(arm.quaternion); } } else { ghost.visible = false; @@ -350,14 +355,19 @@ function activateSide(side) { } function ensureGhostInit(side) { - // Se non c'è target locale, allinea ghost al reale (preparato per drag) - if (!state.target[side]) { - const real = state.current[side]; - if (real) { - state.ghosts[side].position.set(real.position[0], real.position[1], real.position[2]); - state.ghosts[side].quaternion.set(real.quaternion[0], real.quaternion[1], - real.quaternion[2], real.quaternion[3]); - } + // Se non c'è target locale, allinea ghost al reale (preparato per drag). + // Se /state non e' disponibile (G1 offline), fallback alla posizione + // dell'arm visibile (che usa SHOULDER come default). + if (state.target[side]) return; + const real = state.current[side]; + const arm = state.arms[side]; + if (real) { + state.ghosts[side].position.set(real.position[0], real.position[1], real.position[2]); + state.ghosts[side].quaternion.set(real.quaternion[0], real.quaternion[1], + real.quaternion[2], real.quaternion[3]); + } else if (arm) { + state.ghosts[side].position.copy(arm.position); + state.ghosts[side].quaternion.copy(arm.quaternion); } }