fix(pose_3d): ghost fallback alla posa dell'arm quando /state e' offline

This commit is contained in:
Adriano Dal Pastro committed 2026-05-21 16:44:57 +02:00
1 parent fd506dff9b
commit d4cd82551e
1 file changed
+19 -9
+19 -9
View File
@@ -241,12 +241,17 @@ function syncGhostsToTargetOrReal() {
// ghost segue il target locale (mosso dal gizmo) // ghost segue il target locale (mosso dal gizmo)
ghost.visible = true; ghost.visible = true;
} else if (side === state.active_side) { } 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 real = state.current[side];
const arm = state.arms[side];
if (real) { if (real) {
ghost.position.set(real.position[0], real.position[1], real.position[2]); ghost.position.set(real.position[0], real.position[1], real.position[2]);
ghost.quaternion.set(real.quaternion[0], real.quaternion[1], ghost.quaternion.set(real.quaternion[0], real.quaternion[1],
real.quaternion[2], real.quaternion[3]); real.quaternion[2], real.quaternion[3]);
} else if (arm) {
ghost.position.copy(arm.position);
ghost.quaternion.copy(arm.quaternion);
} }
} else { } else {
ghost.visible = false; ghost.visible = false;
@@ -350,14 +355,19 @@ function activateSide(side) {
} }
function ensureGhostInit(side) { function ensureGhostInit(side) {
// Se non c'è target locale, allinea ghost al reale (preparato per drag) // Se non c'è target locale, allinea ghost al reale (preparato per drag).
if (!state.target[side]) { // Se /state non e' disponibile (G1 offline), fallback alla posizione
const real = state.current[side]; // dell'arm visibile (che usa SHOULDER come default).
if (real) { if (state.target[side]) return;
state.ghosts[side].position.set(real.position[0], real.position[1], real.position[2]); const real = state.current[side];
state.ghosts[side].quaternion.set(real.quaternion[0], real.quaternion[1], const arm = state.arms[side];
real.quaternion[2], real.quaternion[3]); 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);
} }
} }