hud-6: pan the 180° video window about the eye; padlock as a panel button
ADDENDUM 8 — panning the video window (yaw/pitch about the eye)
The 180° window was hard-wired dead ahead, so scenes staged below the horizon
could only be watched by physically lowering the head. The video layer is an
XREquirectLayer with radius 0, i.e. the content sits at infinity: only its
ORIENTATION is visible and translating it does nothing. So panning is purely
layer.transform's rotation, which rotates the content about the eye point — no
parallax, no swim when the head moves, and no decode/upload cost (8K HEVC
DirectPlay untouched). Only the video rotates; the panel (refSpace, fixed pose)
and the subtitles (viewer space, head-locked) stay in front of the user.
state.videoYaw (+ = picture moved RIGHT)
state.videoPitch (+ = picture moved UP)
q = qy(-yaw) * qx(pitch) -> aim = (cos p·sin yaw, sin p, -cos p·cos yaw)
Interaction is one affordance in the panel, above the progress bar (the owner's
requested placement): a drag strip. Pinch and drag -> the picture follows the
hand 1:1; three taps within 1.6 s reset it (taps counted on RELEASE, so a drag
cannot be mistaken for one); the live angles are printed on the strip. The drag
is driven by the RAY's own direction delta rather than a cursor position on the
panel: a panel-space cursor leaves the panel after a few degrees, while ray
rotation has no range limit and keeps the content point under the cursor.
Controls.hold() freezes the panel auto-hide for the drag's duration.
Pitch is limited only by a gimbal guard (±(π/2 - 0.02)) per "不限"; yaw wraps to
[-π, π]. Both reset to 0 on every VR session — not persisted.
Runtime risk: XREquirectLayer.transform is settable per spec but a runtime may
ignore the write, so it is probed once per session (write a known rotation, read
it back) -> stats.videoRotMode = 'live' (transform write per frame) or
'rebuild' (recreate the media layer, but only on creation/release/reset, never
per frame). THIS PROBE NEEDS A REAL XR SESSION — it is the one thing not
verifiable offline.
ADDENDUM 7b (previous pass, in this commit's tree) — the padlock
The padlock had been given its own quad layer parked 0.45 m to the right of the
panel. On device it could not be selected while the panel was shown but could
when it was hidden. Aiming is the binding constraint: with hands the only
pointing device is a ray, and the cursor's acceptance window reaches the panel's
own right edge, so the badge was outside every reachable ray; its hit test also
used the panel's layer geometry, which is why the behaviour flipped with panel
visibility. It is now an ordinary panel button (media row, fifth slot) using the
same hitTest/handleSelect path as every other button, and "locked" is a third
panel mode (0.26 × 0.10 m) that draws and hit-tests ONLY the padlock. Locking
swaps the panel in place and lets it auto-hide; the next summon shows the padlock
alone; unlocking restores the full panel and ignores presses for 500 ms.
handleSelect() no longer falls back to pressing the panel centre when no ray hit
exists.
Panel: expanded grew 0.72 × 0.21 m -> 0.72 × 0.26 m (canvas 1440 × 520) for the
drag strip; every row re-proportioned.
Verified offline against the real bundle: quaternion/drag maths (aim direction
for ±yaw/±pitch, unit norm, azimuth/elevation recovery, yaw wrap, pitch clamp,
"aimed point ends up under the cursor"), panel hit bands on the new canvas
(strip 0..0.20, inert readout 0.20..0.30, seek 0.30..0.52, media 0.52..0.74,
subtitle 0.84..1.0, no dead column), the strip's drawn readout, and hold().
build.py --check passes; deployed as mvp-2e32e6 and confirmed live on the Quest
(hud-6, videoYaw/videoPitch 0, errors empty).
This commit is contained in:
+11
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
var NS = window.__JFVR = window.__JFVR || {};
|
||||
|
||||
NS.version = 'hud-5'; // hud-4 = ADDENDUM 7; hud-5 = ADDENDUM 7b (padlock in the panel + locked mode)
|
||||
NS.version = 'hud-6'; // hud-6 = ADDENDUM 8 (drag the picture window: yaw/pitch about the eye)
|
||||
NS.__core = true;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
@@ -38,6 +38,16 @@
|
||||
projection: '180', // '180' | '360'
|
||||
stereo: 'sbs', // 'mono' | 'sbs' | 'ou'
|
||||
|
||||
// ADDENDUM 8 — where the 180/360 window points. The video layer is an
|
||||
// equirect sphere with radius 0 (content "at infinity"), so rotating its
|
||||
// transform rotates the CONTENT about the eye point without any parallax:
|
||||
// exactly "pan the picture so I do not have to crane my neck". Only the video
|
||||
// rotates — the panel (refSpace, fixed pose) and the subtitles (viewer space,
|
||||
// head-locked) stay in front of the user. Radians. NOT persisted: the owner
|
||||
// wants a fresh forward-facing view every time VR starts.
|
||||
videoYaw: 0, // + = the picture has been moved to the RIGHT
|
||||
videoPitch: 0, // + = the picture has been moved UP
|
||||
|
||||
subtitles: true,
|
||||
ctlLock: false, // ADDENDUM 7: control-bar lock badge (per VR session)
|
||||
subMode: 'hud', // 'hud' | 'sphere' | 'off'
|
||||
|
||||
+175
-37
@@ -55,7 +55,7 @@
|
||||
// 0.60 m x 0.05 m collapsed.
|
||||
var PANEL_M = {
|
||||
collapsed: { w: 0.60, h: 0.05 },
|
||||
expanded: { w: 0.72, h: 0.21 },
|
||||
expanded: { w: 0.72, h: 0.26 },
|
||||
// ADDENDUM 7b: the minimal panel shown while the controls are LOCKED. It
|
||||
// carries only the padlock, so nothing adjustable is reachable.
|
||||
locked: { w: 0.26, h: 0.10 }
|
||||
@@ -65,14 +65,14 @@
|
||||
// ratio of (w, h), so pass these (or any matching ratio).
|
||||
var PANEL_PX = {
|
||||
collapsed: { w: 1200, h: 100 },
|
||||
expanded: { w: 1440, h: 420 },
|
||||
expanded: { w: 1440, h: 520 },
|
||||
locked: { w: 520, h: 200 }
|
||||
};
|
||||
// Layer placement in viewer space (head-locked, centred, lower part of view).
|
||||
var PANEL_Y = -0.28;
|
||||
var PANEL_Z = 1.4;
|
||||
|
||||
// hitTest mode threshold: collapsed ratio 12.0, expanded ratio 3.43.
|
||||
// hitTest mode threshold: collapsed ratio 12.0, expanded 2.77, locked 2.6.
|
||||
var COLLAPSED_RATIO = 8;
|
||||
|
||||
// Pointer beam (ADDENDUM 2): a separate thin quad layer running from the
|
||||
@@ -178,53 +178,68 @@
|
||||
trackHitY0: 0.0, // full strip height is a generous seek band
|
||||
trackHitY1: 1.0
|
||||
},
|
||||
// Vertical bands of the 420 px (= 0.21 m) expanded panel, top to bottom:
|
||||
// time readout, progress track, media buttons, subtitle caption, subtitle
|
||||
// buttons. The three hit bands are contiguous and never overlap, so the seek
|
||||
// band is untouched by the button rows (hitTest still tests every button
|
||||
// first). Every offset is a fraction of the panel, so draw() and hitTest()
|
||||
// scale with whatever w/h they are handed.
|
||||
// Vertical bands of the 520 px (= 0.26 m) expanded panel, top to bottom:
|
||||
// the ADDENDUM 8 drag strip, time readout, progress track, media buttons,
|
||||
// subtitle caption, subtitle buttons. The hit bands are contiguous and never
|
||||
// overlap, so the seek band is untouched by the button rows (hitTest still
|
||||
// tests every button first). Every offset is a fraction of the panel, so
|
||||
// draw() and hitTest() scale with whatever w/h they are handed.
|
||||
expanded: {
|
||||
trackCy: 0.32, // 134 px
|
||||
trackVisH: 0.04, // 17 px, ~8 mm of a 21 cm panel
|
||||
trackHitY0: 0.20, // 84 px band 84..185 px, far larger than the bar
|
||||
trackHitY1: 0.44, // 185 px
|
||||
textBaseline: 0.165, // 69 px
|
||||
textFont: 0.095, // 40 px
|
||||
btnY: 0.58, // 244 px
|
||||
// ADDENDUM 8: the picture-pan drag strip sits ABOVE the progress bar (the
|
||||
// owner's requested place). It is the whole picture-pan affordance: pinch it
|
||||
// and drag, and the video content rotates with your hand. Three taps on it
|
||||
// within VIEW_TAP_MS reset the view to dead ahead.
|
||||
viewStripX0: 0.02,
|
||||
viewStripX1: 0.98,
|
||||
viewStripY0: 0.03,
|
||||
viewStripY1: 0.17,
|
||||
viewHitY0: 0.0, // 0 px band 0..104 px
|
||||
viewHitY1: 0.20, // 104 px
|
||||
viewLabelFont: 0.040,
|
||||
viewValueFont: 0.046,
|
||||
viewHintFont: 0.030,
|
||||
viewLabelDy: 0.075, // 39 px first line baseline
|
||||
viewHintDy: 0.155, // 81 px second (hint) baseline
|
||||
trackCy: 0.42, // 218 px
|
||||
trackVisH: 0.030, // 16 px, ~8 mm of a 26 cm panel
|
||||
trackHitY0: 0.30, // 156 px band 156..270 px, far larger than the bar
|
||||
trackHitY1: 0.52, // 270 px
|
||||
textBaseline: 0.275, // 143 px
|
||||
textFont: 0.075, // 39 px
|
||||
btnY: 0.62, // 322 px
|
||||
btnVisualW: 0.105, // 151 px
|
||||
btnVisualH: 0.155, // 65 px
|
||||
btnHitY0: 0.44, // 185 px band 185..302 px
|
||||
btnHitY1: 0.72, // 302 px
|
||||
// ADDENDUM 7b: five buttons now — the padlock joined the row at the far
|
||||
// right (centres 0.18 / 0.36 / 0.54 / 0.72 / 0.90, pills 0.088..0.992).
|
||||
btnVisualH: 0.125, // 65 px
|
||||
btnHitY0: 0.52, // 270 px band 270..385 px
|
||||
btnHitY1: 0.74, // 385 px
|
||||
// Five buttons - the padlock joined the row at the far right (centres
|
||||
// 0.18 / 0.36 / 0.54 / 0.72 / 0.90, pills 0.088..0.992).
|
||||
btnHitHalfW: 0.092,
|
||||
btnSpacing: 0.18,
|
||||
btnFirstCx: 0.18,
|
||||
// Icon over label inside each media button: the label says what the
|
||||
// button does, the icon keeps the quick visual cue.
|
||||
btnIconDy: -0.032, // -13.4 px, icon centre above the button centre
|
||||
btnIconSize: 0.080, // 34 px icon box
|
||||
btnLabelFont: 0.050, // 21 px label
|
||||
btnLabelDy: 0.050, // 21 px label baseline below the button centre
|
||||
btnIconDy: -0.026, // -13.5 px, icon centre above the button centre
|
||||
btnIconSize: 0.065, // 34 px icon box
|
||||
btnLabelFont: 0.040, // 21 px label
|
||||
btnLabelDy: 0.041, // 21 px label baseline below the button centre
|
||||
// ADDENDUM 4 subtitle row (ADDENDUM 6: nine buttons), tiling the full
|
||||
// width (centres 0.10 .. 0.90, pitch 0.10, symmetric). The hit pills are
|
||||
// 0.104 wide on a 0.10 pitch, so adjacent hit regions overlap by a hair
|
||||
// instead of leaving a dead zone between.
|
||||
subLabelBaseline: 0.757, // 318 px caption baseline
|
||||
subCaptionFont: 0.048, // 20 px caption (distance + size + opacity readout)
|
||||
subBtnY: 0.90, // 378 px button centre
|
||||
subLabelBaseline: 0.795, // 413 px caption baseline
|
||||
subCaptionFont: 0.040, // 21 px caption (distance + size + opacity readout)
|
||||
subBtnY: 0.925, // 481 px button centre
|
||||
subVisualW: 0.092, // 132 px
|
||||
subVisualH: 0.145, // 61 px
|
||||
subHitY0: 0.80, // 336 px band 336..420 px (below the caption)
|
||||
subHitY1: 1.0, // 420 px
|
||||
subVisualH: 0.120, // 62 px
|
||||
subHitY0: 0.84, // 437 px band 437..520 px (below the caption)
|
||||
subHitY1: 1.0, // 520 px
|
||||
subHitHalfW: 0.052,
|
||||
subSpacing: 0.10,
|
||||
subFirstCx: 0.10,
|
||||
subIconDy: -0.024, // -10.1 px icon centre above the button centre
|
||||
subIconSize: 0.058, // 24.4 px icon box
|
||||
subLabelFont: 0.040, // 16.8 px label
|
||||
subLabelDy: 0.044 // 18.5 px label baseline below the button centre
|
||||
subIconDy: -0.020, // -10.4 px icon centre above the button centre
|
||||
subIconSize: 0.046, // 24 px icon box
|
||||
subLabelFont: 0.034, // 17.7 px label
|
||||
subLabelDy: 0.036 // 18.7 px label baseline below the button centre
|
||||
},
|
||||
// ADDENDUM 7b: the locked panel. ONE target — the padlock — centred, with a
|
||||
// label that says what pressing it does. Nothing else is drawn or hit-tested,
|
||||
@@ -401,6 +416,7 @@
|
||||
ctx.fill();
|
||||
|
||||
if (mode === 'expanded') {
|
||||
drawViewStrip(ctx, w, h, view, lay);
|
||||
drawExpanded(ctx, w, h, view, lay, dur, cur);
|
||||
}
|
||||
|
||||
@@ -450,6 +466,79 @@
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// ADDENDUM 8 — the picture-pan drag strip, ABOVE the progress bar.
|
||||
// It is one self-contained affordance: the grip says "grab me", the values say
|
||||
// where the picture currently points, and the hint says how to reset. Pure like
|
||||
// the rest of draw(): no state, no timers.
|
||||
function drawViewStrip(ctx, w, h, view, lay) {
|
||||
var v = view.view || {};
|
||||
var yaw = num(v.yawDeg);
|
||||
var pitch = num(v.pitchDeg);
|
||||
if (yaw == null) yaw = 0;
|
||||
if (pitch == null) pitch = 0;
|
||||
|
||||
var x0 = num(lay.viewStripX0) * w;
|
||||
var x1 = num(lay.viewStripX1) * w;
|
||||
var y0 = num(lay.viewStripY0) * h;
|
||||
var y1 = num(lay.viewStripY1) * h;
|
||||
var sw = x1 - x0, sh = y1 - y0;
|
||||
if (sw <= 0 || sh <= 0) return;
|
||||
|
||||
var dragging = view.hover === 'view_drag';
|
||||
ctx.fillStyle = dragging ? 'rgba(78,161,255,0.26)' : 'rgba(255,255,255,0.10)';
|
||||
rr(ctx, x0, y0, sw, sh, sh * 0.30);
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = dragging ? ACCENT : 'rgba(255,255,255,0.26)';
|
||||
ctx.lineWidth = Math.max(1.5, sh * 0.035);
|
||||
if (typeof ctx.setLineDash === 'function') ctx.setLineDash([sh * 0.22, sh * 0.16]);
|
||||
rr(ctx, x0, y0, sw, sh, sh * 0.30);
|
||||
ctx.stroke();
|
||||
if (typeof ctx.setLineDash === 'function') ctx.setLineDash([]);
|
||||
|
||||
// Grip: a 2x3 dot pad, the universal "this is draggable" mark.
|
||||
var gy = (y0 + y1) / 2;
|
||||
var gx = x0 + sh * 0.72;
|
||||
var dot = Math.max(1.5, sh * 0.075);
|
||||
var dx = sh * 0.30, dy = sh * 0.20;
|
||||
ctx.fillStyle = dragging ? '#ffffff' : 'rgba(255,255,255,0.75)';
|
||||
for (var r = -1; r <= 1; r++) {
|
||||
for (var c = -1; c <= 1; c += 2) {
|
||||
ctx.beginPath();
|
||||
ctx.arc(gx + c * dx * 0.5, gy + r * dy, dot, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
var textX = gx + sh * 0.60;
|
||||
ctx.textBaseline = 'alphabetic';
|
||||
var f1 = Math.max(10, Math.round(num(lay.viewLabelFont) * h));
|
||||
ctx.textAlign = 'left';
|
||||
ctx.fillStyle = '#ffffff';
|
||||
ctx.font = '600 ' + f1 + 'px ' + FONT;
|
||||
ctx.fillText('拖动调整画面', textX, num(lay.viewLabelDy) * h);
|
||||
ctx.font = Math.max(9, Math.round(num(lay.viewHintFont) * h)) + 'px ' + FONT;
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.70)';
|
||||
ctx.fillText('连点 3 次复位', textX, num(lay.viewHintDy) * h);
|
||||
|
||||
// Current angles, right-aligned: the numbers to watch while dragging.
|
||||
var f2 = Math.max(10, Math.round(num(lay.viewValueFont) * h));
|
||||
ctx.textAlign = 'right';
|
||||
ctx.font = '700 ' + f2 + 'px ' + FONT;
|
||||
ctx.fillStyle = dragging ? ACCENT : '#ffffff';
|
||||
ctx.fillText('偏航 ' + fmtSigned(yaw) + '\u00b0 俯仰 ' + fmtSigned(pitch) + '\u00b0',
|
||||
x1 - sh * 0.30, num(lay.viewLabelDy) * h);
|
||||
ctx.font = Math.max(9, Math.round(num(lay.viewHintFont) * h)) + 'px ' + FONT;
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.60)';
|
||||
ctx.fillText('0\u00b0 / 0\u00b0 = 正前方', x1 - sh * 0.30, num(lay.viewHintDy) * h);
|
||||
}
|
||||
|
||||
// Signed degree readout for the drag strip: "+12" / "-8" / "0".
|
||||
function fmtSigned(deg) {
|
||||
var r = Math.round(deg);
|
||||
if (r > 0) return '+' + r;
|
||||
return String(r);
|
||||
}
|
||||
|
||||
function drawExpanded(ctx, w, h, view, lay, dur, cur) {
|
||||
var fontSize = Math.max(10, Math.round(lay.textFont * h));
|
||||
|
||||
@@ -975,6 +1064,12 @@
|
||||
}
|
||||
|
||||
if (mode === 'expanded') {
|
||||
// ADDENDUM 8: the drag strip first. Its band (0..0.20) does not overlap the
|
||||
// seek band (0.30..0.52) or the button bands (0.52+), so order is cosmetic.
|
||||
if (ny >= lay.viewHitY0 && ny <= lay.viewHitY1 &&
|
||||
nx >= lay.viewStripX0 && nx <= lay.viewStripX1) {
|
||||
return { type: 'view_drag' };
|
||||
}
|
||||
var i, cx, y0 = lay.btnHitY0, y1 = lay.btnHitY1;
|
||||
for (i = 0; i < BUTTONS.length; i++) {
|
||||
cx = lay.btnFirstCx + i * lay.btnSpacing;
|
||||
@@ -1032,6 +1127,7 @@
|
||||
beamTex: null,
|
||||
// padlock (ADDENDUM 7b) — panel state only, no own layer
|
||||
lockOn: false,
|
||||
hold: false, // ADDENDUM 8: drag in progress -> freeze auto-hide
|
||||
// XR resources
|
||||
canvas: null,
|
||||
ctx2d: null,
|
||||
@@ -1169,6 +1265,19 @@
|
||||
// pointer position was already reduced to a hitTest() action by the draw path,
|
||||
// so this is just that lookup - and it means hover feedback needs no extra
|
||||
// plumbing from 90-main.js.
|
||||
// ADDENDUM 8: current video-window angles in DEGREES, read from the shared
|
||||
// state that 90-main.js owns (it owns the video layer's transform).
|
||||
function readViewAngles() {
|
||||
var n = ns();
|
||||
var st = (n && n.state) || {};
|
||||
var yaw = num(st.videoYaw);
|
||||
var pitch = num(st.videoPitch);
|
||||
return {
|
||||
yawDeg: yaw == null ? 0 : yaw * 180 / Math.PI,
|
||||
pitchDeg: pitch == null ? 0 : pitch * 180 / Math.PI
|
||||
};
|
||||
}
|
||||
|
||||
function readHover() {
|
||||
var extra = reader(S.getExtra, 'hover');
|
||||
if (typeof extra === 'string') return extra;
|
||||
@@ -1220,6 +1329,8 @@
|
||||
hover: readHover(),
|
||||
pointer: viewPointer(),
|
||||
lock: !!S.lockOn,
|
||||
// ADDENDUM 8: the video window's angles, in degrees, for the drag strip.
|
||||
view: readViewAngles(),
|
||||
sub: readSubValues()
|
||||
};
|
||||
// Diagnostics: what the bar actually rendered, so the CC state can be checked
|
||||
@@ -1250,7 +1361,9 @@
|
||||
Math.round(v.sub.opacity * 100),
|
||||
Math.round(v.sub.angleDeg),
|
||||
v.sub.lock ? 1 : 0,
|
||||
Math.round(v.sub.dist * 100)
|
||||
Math.round(v.sub.dist * 100),
|
||||
Math.round(v.view.yawDeg),
|
||||
Math.round(v.view.pitchDeg)
|
||||
].join('|');
|
||||
}
|
||||
|
||||
@@ -1769,7 +1882,13 @@
|
||||
S.beamSig = null; // re-place the beam for this show
|
||||
applyBeamVisible();
|
||||
if (S.beamOn) updateBeamTransform();
|
||||
restartAutoHide(autoHideMs);
|
||||
updateVisibilityStats();
|
||||
}
|
||||
|
||||
function restartAutoHide(autoHideMs) {
|
||||
if (S.autoHideTimer != null) { clearTimeout(S.autoHideTimer); S.autoHideTimer = null; }
|
||||
if (S.hold) return; // a drag is in progress: stay up
|
||||
var n = ns();
|
||||
var def = (n && n.state && typeof n.state.ctlAutoHideMs === 'number')
|
||||
? n.state.ctlAutoHideMs
|
||||
@@ -1779,7 +1898,22 @@
|
||||
S.autoHideTimer = null;
|
||||
hide();
|
||||
}, ms);
|
||||
updateVisibilityStats();
|
||||
}
|
||||
|
||||
// ADDENDUM 8: pause the auto-hide while a hold-style interaction (the picture
|
||||
// drag) is running. Without this the panel would disappear mid-drag, because
|
||||
// the timer that show() armed keeps running.
|
||||
function hold(on) {
|
||||
var v = !!on;
|
||||
if (v === S.hold) return;
|
||||
S.hold = v;
|
||||
if (v) {
|
||||
if (S.autoHideTimer != null) { clearTimeout(S.autoHideTimer); S.autoHideTimer = null; }
|
||||
} else if (S.shown) {
|
||||
restartAutoHide();
|
||||
}
|
||||
var s = stats();
|
||||
if (s) s.ctlHold = v;
|
||||
}
|
||||
|
||||
// Fully hidden: no bar, no beam, no cursor, and no further drawing/uploading
|
||||
@@ -1789,6 +1923,9 @@
|
||||
function hide() {
|
||||
if (S.autoHideTimer != null) { clearTimeout(S.autoHideTimer); S.autoHideTimer = null; }
|
||||
S.shown = false;
|
||||
S.hold = false;
|
||||
var hs = stats();
|
||||
if (hs) hs.ctlHold = false;
|
||||
applyBarVisible();
|
||||
applyBeamVisible();
|
||||
updateVisibilityStats();
|
||||
@@ -1918,6 +2055,7 @@
|
||||
show: show,
|
||||
hide: hide,
|
||||
isVisible: isVisible,
|
||||
hold: hold,
|
||||
setOpacity: setOpacity,
|
||||
getOpacity: getOpacity,
|
||||
setLock: setLock,
|
||||
|
||||
+231
-2
@@ -615,7 +615,18 @@
|
||||
// video (bottom) -> hands -> subtitles -> controls (top)
|
||||
try {
|
||||
var vlayer = createVideoLayer(session);
|
||||
if (vlayer) { NS.addLayer(vlayer); made.push('video'); }
|
||||
if (vlayer) {
|
||||
NS.addLayer(vlayer);
|
||||
S.videoLayer = vlayer;
|
||||
made.push('video');
|
||||
// ADDENDUM 8: angles start dead ahead every session (never restored),
|
||||
// then the transform is applied so probe + apply see the real layer.
|
||||
S.videoYaw = 0;
|
||||
S.videoPitch = 0;
|
||||
probeVideoAngleMutable(vlayer);
|
||||
applyVideoAngle(false); // undo the probe's test rotation
|
||||
updateVideoAngleStats();
|
||||
}
|
||||
} catch (e) { NS.recordError('video layer', e); made.push('video:err'); }
|
||||
|
||||
// System hand models (WebXR Input Profiles 'generic-hand'), rendered into
|
||||
@@ -670,6 +681,7 @@
|
||||
pollGamepads(frame);
|
||||
updatePanelPose(frame, dt);
|
||||
updateGrabFrame(frame);
|
||||
updateViewDrag(frame);
|
||||
NS.runFrameHooks(frame, time, session);
|
||||
}
|
||||
session.requestAnimationFrame(loop);
|
||||
@@ -701,8 +713,15 @@
|
||||
upperVerticalAngle: Math.PI / 2,
|
||||
lowerVerticalAngle: -Math.PI / 2
|
||||
};
|
||||
// ADDENDUM 8: the transform is the picture's aim. radius stays 0 (content at
|
||||
// infinity) so this is a pure rotation about the eye point. The transform is
|
||||
// what makes a rebuild-based runtime possible, and what makes the very first
|
||||
// frame already point where the user left it (a mid-session rebuild).
|
||||
var t = videoAngleTransform();
|
||||
if (t) opts.transform = t;
|
||||
var layer = new XRMediaBinding(session).createEquirectLayer(video, opts);
|
||||
log('video layer', JSON.stringify({ layout: opts.layout, central: opts.centralHorizontalAngle }));
|
||||
log('video layer', JSON.stringify({ layout: opts.layout, central: opts.centralHorizontalAngle,
|
||||
yaw: Math.round(S.videoYaw * 180 / Math.PI), pitch: Math.round(S.videoPitch * 180 / Math.PI) }));
|
||||
return layer;
|
||||
}
|
||||
|
||||
@@ -724,6 +743,13 @@
|
||||
S.lastFrame = null;
|
||||
grab = null;
|
||||
S.stats.grab = 'reset';
|
||||
viewDrag = null;
|
||||
viewTaps = [];
|
||||
S.videoLayer = null;
|
||||
S.videoAngleLive = false;
|
||||
S.videoYaw = 0;
|
||||
S.videoPitch = 0;
|
||||
if (NS.Controls && NS.Controls.hold) { try { NS.Controls.hold(false); } catch (e) {} }
|
||||
S.ctlLock = false;
|
||||
panelPose = null;
|
||||
pointer = { visible: false, beam: false, source: 'none', origin: { x: 0, y: 0, z: 0 }, dir: { x: 0, y: 0, z: -1 }, hit: null };
|
||||
@@ -973,6 +999,200 @@
|
||||
}).join(' ') || '(none)';
|
||||
}
|
||||
|
||||
/* ================================================================== *
|
||||
* ADDENDUM 8 — panning the video window
|
||||
*
|
||||
* The video layer is an equirect sphere with radius 0, i.e. the content sits at
|
||||
* infinity. That has an important consequence: only the sphere's ORIENTATION
|
||||
* decides which direction you see, and translating it does nothing. So panning
|
||||
* the picture is purely `layer.transform`'s rotation, which rotates the content
|
||||
* about the eye point — no parallax, no swimming when the head moves, and no
|
||||
* decode/upload cost (8K HEVC DirectPlay is untouched).
|
||||
*
|
||||
* Only the video rotates. The control panel lives at a fixed pose in refSpace
|
||||
* and the subtitles are head-locked in viewer space, so the UI stays in front of
|
||||
* the user while the picture moves.
|
||||
* ================================================================== */
|
||||
var VIDEO_PITCH_LIMIT = Math.PI / 2 - 0.02; // "unlimited", minus a gimbal guard
|
||||
|
||||
function wrapYaw(a) {
|
||||
while (a > Math.PI) a -= Math.PI * 2;
|
||||
while (a < -Math.PI) a += Math.PI * 2;
|
||||
return a;
|
||||
}
|
||||
|
||||
function clampPitch(p) { return NS.clamp(p, -VIDEO_PITCH_LIMIT, VIDEO_PITCH_LIMIT); }
|
||||
|
||||
// q = qy(-yaw) * qx(pitch): pitch about the content's own X first, then yaw about
|
||||
// the world Y — the standard look-around composition. The yaw sign is flipped so
|
||||
// the STATE reads the way the user thinks about it: +yaw = the picture has been
|
||||
// moved to the RIGHT, +pitch = UP (so a scene that used to need a physical
|
||||
// head-down is brought up to eye level).
|
||||
//
|
||||
// The window's aim direction (the layer's local -Z) then works out to
|
||||
// (cos p · sin yaw, sin p, -cos p · cos yaw)
|
||||
// and the drag adds the ray's own yaw/pitch deltas directly, so the content point
|
||||
// under the cursor stays under the cursor.
|
||||
function videoQuat(yaw, pitch) {
|
||||
var qy = { x: 0, y: Math.sin(-yaw / 2), z: 0, w: Math.cos(-yaw / 2) };
|
||||
var qx = { x: Math.sin(pitch / 2), y: 0, z: 0, w: Math.cos(pitch / 2) };
|
||||
return qMul(qy, qx);
|
||||
}
|
||||
|
||||
function videoOrigin() { return { x: 0, y: 0, z: 0 }; }
|
||||
|
||||
function videoAngleTransform() {
|
||||
if (typeof XRRigidTransform === 'undefined') return undefined;
|
||||
return new XRRigidTransform(videoOrigin(), videoQuat(S.videoYaw, S.videoPitch));
|
||||
}
|
||||
|
||||
function updateVideoAngleStats() {
|
||||
S.stats.videoYaw = Math.round(S.videoYaw * 180 / Math.PI);
|
||||
S.stats.videoPitch = Math.round(S.videoPitch * 180 / Math.PI);
|
||||
S.stats.videoAngleLive = !!S.videoAngleLive;
|
||||
}
|
||||
|
||||
// XREquirectLayer.transform is settable in the spec, but a runtime is free to
|
||||
// ignore the write, so probe it once: write a known rotation and read it back.
|
||||
function probeVideoAngleMutable(layer) {
|
||||
S.videoAngleLive = false;
|
||||
if (!layer || typeof XRRigidTransform === 'undefined') return;
|
||||
try {
|
||||
var q = videoQuat(0.05, 0.05);
|
||||
layer.transform = new XRRigidTransform(videoOrigin(), q);
|
||||
var o = layer.transform && layer.transform.orientation;
|
||||
S.videoAngleLive = !!(o && Math.abs(o.y - q.y) < 1e-4 && Math.abs(o.w - q.w) < 1e-4);
|
||||
} catch (e) {
|
||||
S.videoAngleLive = false;
|
||||
}
|
||||
S.stats.videoRotMode = S.videoAngleLive ? 'live' : 'rebuild';
|
||||
if (!S.videoAngleLive) {
|
||||
log('video layer transform is read-only -> rebuilding the layer on changes');
|
||||
}
|
||||
}
|
||||
|
||||
// Push the current angles into the layer. On a live runtime this is just a
|
||||
// transform write. On a runtime that ignores the write we must REBUILD the media
|
||||
// layer — which is far too expensive to do once per drag frame, so rebuilds
|
||||
// happen only when `force` is set (creation, release, reset).
|
||||
function applyVideoAngle(force) {
|
||||
var layer = S.videoLayer;
|
||||
if (!layer || !S.session) return;
|
||||
if (S.videoAngleLive) {
|
||||
try {
|
||||
layer.transform = videoAngleTransform();
|
||||
if ('needsRedraw' in layer) layer.needsRedraw = true;
|
||||
} catch (e) {
|
||||
S.videoAngleLive = false;
|
||||
S.stats.videoRotMode = 'rebuild';
|
||||
}
|
||||
}
|
||||
if (!S.videoAngleLive && force) rebuildVideoLayer();
|
||||
updateVideoAngleStats();
|
||||
}
|
||||
|
||||
function rebuildVideoLayer() {
|
||||
var session = S.session;
|
||||
if (!session || !S.video) return;
|
||||
try {
|
||||
var fresh = createVideoLayer(session);
|
||||
if (!fresh) return;
|
||||
var old = S.videoLayer;
|
||||
S.videoLayer = fresh;
|
||||
NS.addLayer(fresh);
|
||||
if (old) {
|
||||
NS.removeLayer(old);
|
||||
try { if (typeof old.destroy === 'function') old.destroy(); } catch (e) {}
|
||||
}
|
||||
S.stats.videoRebuilds = (S.stats.videoRebuilds || 0) + 1;
|
||||
} catch (e) {
|
||||
NS.recordError('videoRebuild', e);
|
||||
}
|
||||
}
|
||||
|
||||
function resetVideoAngle(why) {
|
||||
S.videoYaw = 0;
|
||||
S.videoPitch = 0;
|
||||
if (S.session) { try { applyVideoAngle(true); } catch (e) {} }
|
||||
S.stats.videoReset = why || 'reset';
|
||||
updateVideoAngleStats();
|
||||
}
|
||||
|
||||
/* ---------------- drag the picture (ADDENDUM 8) ----------------
|
||||
* The pointer ray's own direction is the drag handle: rotating the aiming ray by
|
||||
* δ rotates the picture by the same δ, so the content follows the hand 1:1 with
|
||||
* no range limit (a panel-space cursor would run off the panel's edge).
|
||||
* -------------------------------------------------------------- */
|
||||
var viewDrag = null;
|
||||
var VIEW_TAP_MS = 1600; // three taps inside this window reset the view
|
||||
var viewTaps = [];
|
||||
var lastPressSrc = null; // source / frame of the last accepted press, for
|
||||
var lastPressFrame = null; // hold-style actions (the picture drag)
|
||||
|
||||
function rayAngles(ray) {
|
||||
if (!ray || !ray.dir) return null;
|
||||
var d = ray.dir;
|
||||
var len = Math.sqrt(d.x * d.x + d.y * d.y + d.z * d.z) || 1;
|
||||
var dx = d.x / len, dy = d.y / len, dz = d.z / len;
|
||||
return {
|
||||
yaw: Math.atan2(dx, -dz),
|
||||
pitch: Math.asin(NS.clamp(dy, -1, 1))
|
||||
};
|
||||
}
|
||||
|
||||
function beginViewDrag(src, frame) {
|
||||
var ray = rayOf(frame, src);
|
||||
var a = rayAngles(ray);
|
||||
if (!a) { S.stats.viewDrag = 'no ray'; return; }
|
||||
viewDrag = { src: src, a0: a, yaw0: S.videoYaw, pitch0: S.videoPitch, moved: false };
|
||||
S.stats.viewDrag = 'started';
|
||||
if (NS.Controls && NS.Controls.hold) { try { NS.Controls.hold(true); } catch (e) {} }
|
||||
}
|
||||
|
||||
function updateViewDrag(frame) {
|
||||
if (!viewDrag || !frame) return;
|
||||
var ray = rayOf(frame, viewDrag.src);
|
||||
if (!ray) return;
|
||||
var a = rayAngles(ray);
|
||||
if (!a) return;
|
||||
var dyaw = wrapYaw(a.yaw - viewDrag.a0.yaw);
|
||||
var dpitch = a.pitch - viewDrag.a0.pitch;
|
||||
var ny = wrapYaw(viewDrag.yaw0 + dyaw);
|
||||
var np = clampPitch(viewDrag.pitch0 + dpitch);
|
||||
if (Math.abs(ny - S.videoYaw) < 1e-4 && Math.abs(np - S.videoPitch) < 1e-4) return;
|
||||
viewDrag.moved = true;
|
||||
S.videoYaw = ny;
|
||||
S.videoPitch = np;
|
||||
applyVideoAngle(false);
|
||||
}
|
||||
|
||||
// Release. A press that never moved counts as a TAP: three taps inside
|
||||
// VIEW_TAP_MS reset the view (the owner's "连点 3 次复位"). Counting taps on
|
||||
// RELEASE rather than on press means a real drag cannot be mistaken for one.
|
||||
function endViewDrag() {
|
||||
if (!viewDrag) return;
|
||||
var moved = viewDrag.moved;
|
||||
viewDrag = null;
|
||||
if (NS.Controls && NS.Controls.hold) { try { NS.Controls.hold(false); } catch (e) {} }
|
||||
if (!S.videoAngleLive) applyVideoAngle(true); // pay the rebuild once, on release
|
||||
if (moved) {
|
||||
viewTaps = [];
|
||||
S.stats.viewDrag = 'ended (moved)';
|
||||
return;
|
||||
}
|
||||
var now = performance.now();
|
||||
viewTaps = viewTaps.filter(function (t) { return now - t < VIEW_TAP_MS; });
|
||||
viewTaps.push(now);
|
||||
S.stats.viewTaps = viewTaps.length;
|
||||
if (viewTaps.length >= 3) {
|
||||
viewTaps = [];
|
||||
resetVideoAngle('triple-tap');
|
||||
S.stats.viewDrag = 'reset (triple tap)';
|
||||
return;
|
||||
}
|
||||
S.stats.viewDrag = 'tap ' + viewTaps.length + '/3';
|
||||
}
|
||||
|
||||
/* ================================================================== *
|
||||
* Fixed panel pose
|
||||
*
|
||||
@@ -1207,6 +1427,10 @@
|
||||
if (NS.Controls && NS.Controls.show) { try { NS.Controls.show(); } catch (e) {} } // extend auto-hide
|
||||
pressUntil = now + 300;
|
||||
S.stats.pressAt = pointer.hit.nx.toFixed(2) + ',' + pointer.hit.ny.toFixed(2);
|
||||
// Remembered for hold-style actions (the ADDENDUM 8 picture drag), which need
|
||||
// the input source and frame that started them.
|
||||
lastPressSrc = src;
|
||||
lastPressFrame = frame;
|
||||
try { NS.Controls.handleSelect(src, frame); }
|
||||
catch (e) { NS.recordError('handleSelect', e); }
|
||||
return;
|
||||
@@ -1224,6 +1448,7 @@
|
||||
|
||||
function pointerUp() {
|
||||
endGrab();
|
||||
endViewDrag();
|
||||
}
|
||||
|
||||
function pollGamepads(frame) {
|
||||
@@ -1307,6 +1532,10 @@
|
||||
// The padlock and the subtitle actions do not need a <video>.
|
||||
switch (action.type) {
|
||||
case 'lock': toggleControlsLock(); break;
|
||||
case 'view_drag':
|
||||
if (lastPressSrc && lastPressFrame) beginViewDrag(lastPressSrc, lastPressFrame);
|
||||
else S.stats.viewDrag = 'no press context';
|
||||
break;
|
||||
case 'sub_up': setSubPlacementLive({ y: S.subPlacement.y + 0.04 }); break;
|
||||
case 'sub_down': setSubPlacementLive({ y: S.subPlacement.y - 0.04 }); break;
|
||||
case 'sub_near': setSubPlacementLive({ z: S.subPlacement.z + 0.15 }); break;
|
||||
|
||||
Reference in New Issue
Block a user