diff --git a/web/pose_3d.js b/web/pose_3d.js index b631d4e..df2c985 100644 --- a/web/pose_3d.js +++ b/web/pose_3d.js @@ -373,6 +373,57 @@ function bindSideControls() { } } +// ----- Editor mode actions ----- +async function onApplyClick() { + if (state.mode !== 'editor') return; // in Jog non c'è Apply + const side = state.active_side; + const tgt = state.target[side]; + if (!tgt) return; + try { + await jsonFetch('/api/pose_3d/apply', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + side, position: tgt.position, quaternion: tgt.quaternion, + dry_run: true, precise: state.precise, + }), + }); + // commit locale: il target diventa il nuovo current (simulato) + state.current[side] = { position: tgt.position, quaternion: tgt.quaternion }; + state.target[side] = null; + updateRealWrists(); + syncGhostsToTargetOrReal(); + updateReadout(); + $('p3Status').textContent = '✓ Editor: target committato (simulato)'; + $('p3Status').className = 'p3-status ok'; + } catch (e) { + showError(e.message); + } +} + +function onCancelClick() { + const side = state.active_side; + state.target[side] = null; + syncGhostsToTargetOrReal(); + updateReadout(); +} + +function showError(msg) { + $('p3ErrorBox').style.display = 'block'; + $('p3ErrorText').textContent = msg; + $('p3Status').textContent = '✗ errore'; + $('p3Status').className = 'p3-status error'; +} + +function clearError() { + $('p3ErrorBox').style.display = 'none'; + $('p3ErrorText').textContent = ''; +} + +function bindEditorButtons() { + $('p3ApplyBtn').addEventListener('click', onApplyClick); + $('p3CancelBtn').addEventListener('click', onCancelClick); +} + // ----- init triggered on first activation ----- let inited = false; function ensureInit() { @@ -384,6 +435,7 @@ function ensureInit() { bindSideControls(); bindGizmoControls(); bindGizmoEvents(); + bindEditorButtons(); pollState(); pollTimer = setInterval(pollState, POLL_MS); }