hud-11: one pointer owner (dominant hand, press takes over) + hand isolation
ADDENDUM 12. The pointer was symmetric: whoever acted last owned it, and when
neither had acted the first source in runtime order won - the LEFT hand on this
runtime, so a right-handed user's guide line sat on the non-dominant hand.
- state.handPref ('right'|'left', default 'right') is the default owner. Set from the
pre-VR panel (操作 -> 主用手), persisted. pickPointerCand(cands, preferKey,
ownerKey, prefHand): acting source owns the shot (or MISSes), else owner aiming ->
preferred hand aiming -> any hand aiming -> owner -> preferred hand -> first.
- A press takes the pointer over and the owner sticks while it is aiming.
- Hold exclusion: while a grab/viewDrag started by one source is active, a press from
the other source is ignored (pressAt "IGNORED (other hand is holding)").
- Source-matched release: pointerUp(src) only ends the hold src started. It used to be
argument-less, so either hand's release cancelled the other hand's subtitle grab or
picture pan. grab/viewDrag now carry a key; onSelectEnd(ev) and pollGamepads pass
their source.
- dropStaleHolds() runs each frame and ends a hold whose source left
session.inputSources (tracking lost), so nothing sticks.
New diagnostics: stats.handPref, stats.owner.
Verified with injected synthetic input sources:
default (right), both on panel pointer hand:right HIT 0.78,0.50 (was hand:left)
handPref=left, fresh session pointer hand:left HIT 0.22,0.50
left press, release owner hand:left, stays left
right holds picture-pan, left press "IGNORED (other hand is holding)"
right holds picture-pan, LEFT release viewDrag stays armed (drag survives)
right holds picture-pan, RIGHT release viewDrag reset (tap) (drag ends)
This commit is contained in:
Vendored
+71
-23
@@ -19,7 +19,7 @@
|
||||
|
||||
var NS = window.__JFVR = window.__JFVR || {};
|
||||
|
||||
NS.version = 'hud-10'; // hud-10 = ADDENDUM 11 (pointer follows the acting/aiming hand) + ADDENDUM 10 (native subtitles) + 9
|
||||
NS.version = 'hud-11'; // hud-11 = ADDENDUM 12 (single pointer owner: dominant hand by default, press takes over, hold exclusion) + 11/10/9
|
||||
NS.__core = true;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
@@ -75,6 +75,7 @@
|
||||
subAngleDeg: 69.2,
|
||||
|
||||
controls: true,
|
||||
handPref: 'right', // ADDENDUM 12: dominant hand = the pointer's default owner
|
||||
ctlAutoHideMs: 4000, // in-VR control bar auto-hide
|
||||
|
||||
// written every XR frame by 90-main.js, read by modules
|
||||
@@ -4586,6 +4587,7 @@
|
||||
if (o.subAlpha === 'premultiplied' || o.subAlpha === 'straight') S.subAlpha = o.subAlpha;
|
||||
if (o.projection === '180' || o.projection === '360') S.projection = o.projection;
|
||||
if (o.stereo === 'mono' || o.stereo === 'sbs' || o.stereo === 'ou') S.stereo = o.stereo;
|
||||
if (o.handPref === 'right' || o.handPref === 'left') S.handPref = o.handPref;
|
||||
if (typeof o.controls === 'boolean') S.controls = o.controls;
|
||||
// NOTE: `subtitles` is deliberately NOT restored. Persisting it meant a
|
||||
// session where the user toggled subtitles off came back with them off,
|
||||
@@ -4609,6 +4611,7 @@
|
||||
subAlpha: S.subAlpha,
|
||||
projection: S.projection,
|
||||
stereo: S.stereo,
|
||||
handPref: S.handPref,
|
||||
videoRotMode: S.videoRotMode,
|
||||
controls: S.controls,
|
||||
ctlAutoHideMs: S.ctlAutoHideMs
|
||||
@@ -4872,6 +4875,13 @@
|
||||
'字幕的位置 / 距离 / 大小 / 不透明度都在 VR 里用控制条调(控制条最下面一行),' +
|
||||
'调好会自动记住。VR 空间右侧有个锁图标:锁上后面板不会再被唤出。'));
|
||||
|
||||
body.appendChild(NS.makeEl('div', 'jfvr-sec', '操作'));
|
||||
body.appendChild(segRow('主用手', function () { return S.handPref || 'right'; },
|
||||
function (v) { S.handPref = v; saveSettings(); },
|
||||
[{ label: '右手', value: 'right' }, { label: '左手', value: 'left' }]));
|
||||
body.appendChild(NS.makeEl('div', 'jfvr-hint',
|
||||
'引导线/光标默认在主用手上;另一只手按下会立刻接管那一次操作。'));
|
||||
|
||||
// ADDENDUM 8: the picture-pan mechanism. Only touch this if panning does not
|
||||
// move the picture live (see stats.videoRotMode).
|
||||
body.appendChild(segRow('画面旋转', function () { return S.videoRotMode || 'auto'; },
|
||||
@@ -5162,6 +5172,7 @@
|
||||
try {
|
||||
updatePointer(frame);
|
||||
pollGamepads(frame);
|
||||
dropStaleHolds();
|
||||
updatePanelPose(frame, dt);
|
||||
updateGrabFrame(frame);
|
||||
updateViewDrag(frame);
|
||||
@@ -5448,27 +5459,48 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
// ADDENDUM 11 — pure: choose which input source owns the pointer.
|
||||
// cands [{ key, onPanel, ... }] in runtime order
|
||||
function candByHand(cands, hand) {
|
||||
for (var i = 0; i < cands.length; i++) if (cands[i].hand === hand) return cands[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
// ADDENDUM 12 — pure: choose which input source owns the pointer.
|
||||
// cands [{ key, hand, onPanel, ... }] in runtime order
|
||||
// preferKey the source that is acting right now (select / gamepad press)
|
||||
// activeKey the source that acted last
|
||||
// When `preferKey` is given the acting source OWNS the shot: if it is not among
|
||||
// the candidates (no resolvable ray) we return null so the press MISSES rather
|
||||
// than silently reusing another hand's pointer. Otherwise:
|
||||
// last-active-while-on-panel -> any-on-panel -> last-active -> first.
|
||||
function pickPointerCand(cands, preferKey, activeKey) {
|
||||
// ownerKey the source that owns the pointer (last accepted press)
|
||||
// prefHand the dominant hand ('right' | 'left') — the default owner
|
||||
//
|
||||
// The acting source OWNS the shot: if it cannot be resolved the pick is null and
|
||||
// the press MISSES (never another hand's position). Otherwise:
|
||||
// owner aiming -> preferred hand aiming -> any hand aiming -> owner ->
|
||||
// preferred hand -> first.
|
||||
// A mouse-style single cursor: exactly ONE hand ever drives the guide line.
|
||||
function pickPointerCand(cands, preferKey, ownerKey, prefHand) {
|
||||
if (preferKey) return candByKey(cands, preferKey);
|
||||
if (!cands || !cands.length) return null;
|
||||
var i, c;
|
||||
if (activeKey) {
|
||||
c = candByKey(cands, activeKey);
|
||||
if (c && c.onPanel) return c;
|
||||
}
|
||||
for (i = 0; i < cands.length; i++) if (cands[i].onPanel) return cands[i];
|
||||
if (activeKey) { c = candByKey(cands, activeKey); if (c) return c; }
|
||||
var owner = ownerKey ? candByKey(cands, ownerKey) : null;
|
||||
var pref = prefHand ? candByHand(cands, prefHand) : null;
|
||||
if (owner && owner.onPanel) return owner;
|
||||
if (pref && pref.onPanel) return pref;
|
||||
for (var i = 0; i < cands.length; i++) if (cands[i].onPanel) return cands[i];
|
||||
if (owner) return owner;
|
||||
if (pref) return pref;
|
||||
return cands[0];
|
||||
}
|
||||
|
||||
// When the source that started a hold disappears (hand tracking lost), the hold
|
||||
// would otherwise stick forever because no release event ever arrives.
|
||||
function dropStaleHolds() {
|
||||
var srcs = (S.session && S.session.inputSources) ? S.session.inputSources : [];
|
||||
var i;
|
||||
function present(src) {
|
||||
for (i = 0; i < srcs.length; i++) if (srcs[i] === src) return true;
|
||||
return false;
|
||||
}
|
||||
if (grab && !present(grab.src)) endGrab();
|
||||
if (viewDrag && !present(viewDrag.src)) endViewDrag();
|
||||
}
|
||||
|
||||
// ADDENDUM 11: which hand owns the pointer.
|
||||
var activeSrcKey = null;
|
||||
|
||||
@@ -5508,12 +5540,12 @@
|
||||
var hit = null;
|
||||
try { hit = panelHit(frame, ray, layer, 0.25, 0.6); } catch (e) { hit = null; }
|
||||
cands.push({
|
||||
src: src, ray: ray, hit: hit, key: srcKey(src),
|
||||
src: src, ray: ray, hit: hit, key: srcKey(src), hand: src.handedness,
|
||||
onPanel: !!(hit && hit.inBounds)
|
||||
});
|
||||
}
|
||||
|
||||
var pick = pickPointerCand(cands, preferSrc ? srcKey(preferSrc) : null, activeSrcKey);
|
||||
var pick = pickPointerCand(cands, preferSrc ? srcKey(preferSrc) : null, activeSrcKey, S.handPref);
|
||||
|
||||
if (pick) {
|
||||
activeSrcKey = pick.key;
|
||||
@@ -5542,6 +5574,7 @@
|
||||
try { NS.Controls.setPointer(next); } catch (e) {}
|
||||
}
|
||||
S.stats.activeSrc = next.visible ? (activeSrcKey || '(none)') : '(none)';
|
||||
S.stats.handPref = S.handPref || 'right';
|
||||
S.stats.pointer = next.source +
|
||||
(next.hit ? ' HIT ' + next.hit.nx.toFixed(2) + ',' + next.hit.ny.toFixed(2) : ' (no hit)');
|
||||
S.stats.inputSources = srcs.map(function (s) {
|
||||
@@ -5793,7 +5826,7 @@
|
||||
var a = rayAngles(ray);
|
||||
if (!a) { S.stats.viewDrag = 'no ray'; return; }
|
||||
viewDrag = {
|
||||
src: src, t0: performance.now(), armed: false,
|
||||
src: src, key: srcKey(src), t0: performance.now(), armed: false,
|
||||
a0: null, yaw0: S.videoYaw, pitch0: S.videoPitch, moved: false
|
||||
};
|
||||
S.stats.viewDrag = 'pressed (hold ' + VIEW_HOLD_MS + 'ms to pan)';
|
||||
@@ -5934,6 +5967,7 @@
|
||||
if (!p0) { S.stats.grab = 'no source point'; return; }
|
||||
grab = {
|
||||
src: src,
|
||||
key: srcKey(src),
|
||||
p0: p0,
|
||||
place0: { y: S.subPlacement.y, z: S.subPlacement.z, width: S.subPlacement.width },
|
||||
moved: false
|
||||
@@ -6054,6 +6088,13 @@
|
||||
// hand's position.
|
||||
frame = frame || S.lastFrame;
|
||||
if (src) {
|
||||
var excludeKey = srcKey(src);
|
||||
if (excludeKey &&
|
||||
((grab && grab.key && grab.key !== excludeKey) ||
|
||||
(viewDrag && viewDrag.key && viewDrag.key !== excludeKey))) {
|
||||
S.stats.pressAt = 'IGNORED (other hand is holding)';
|
||||
return;
|
||||
}
|
||||
if (frame) { try { updatePointer(frame, src); } catch (e) {} }
|
||||
if (!pointer || !pointer.visible) {
|
||||
S.stats.pressAt = 'MISS (acting source has no ray)';
|
||||
@@ -6121,7 +6162,14 @@
|
||||
|
||||
var pressUntil = 0;
|
||||
|
||||
function pointerUp() {
|
||||
// ADDENDUM 12: only the source that STARTED a hold ends it. A release from the
|
||||
// other hand used to cancel the first hand's drag (subtitle grab / picture pan).
|
||||
function pointerUp(src) {
|
||||
var key = srcKey(src);
|
||||
if (key) {
|
||||
if (grab && grab.key && grab.key !== key) return;
|
||||
if (viewDrag && viewDrag.key && viewDrag.key !== key) return;
|
||||
}
|
||||
endGrab();
|
||||
endViewDrag();
|
||||
}
|
||||
@@ -6141,7 +6189,7 @@
|
||||
var prev = padPrev.get(src) || false;
|
||||
padPrev.set(src, pressed);
|
||||
if (pressed && !prev) pointerDown(src, frame, 'gamepad');
|
||||
else if (!pressed && prev) pointerUp();
|
||||
else if (!pressed && prev) pointerUp(src);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6149,8 +6197,8 @@
|
||||
pointerDown(ev && ev.inputSource, S.lastFrame, 'select');
|
||||
}
|
||||
|
||||
function onSelectEnd() {
|
||||
pointerUp();
|
||||
function onSelectEnd(ev) {
|
||||
pointerUp(ev && ev.inputSource);
|
||||
}
|
||||
/* ---------------- live subtitle setters (single source of truth) ---------------- */
|
||||
// state.subPlacement / subAngleDeg are re-read from the module after every
|
||||
|
||||
Reference in New Issue
Block a user