hud-10: the VR pointer follows the hand that is acting or aiming
ADDENDUM 11. With two hands both report a tracked-pointer ray and the runtime's order is not "the hand the user is using". updatePointer() took the first valid source and broke, and pointerDown() called updatePointer(frame) without the select event's inputSource. On device that pinned the guide line/cursor to one hand while the user aimed with the other, and made the other hand's pinch land wherever the pinned hand pointed (left hand controlling the click position, right hand clicking). updatePointer(frame, preferSrc) now builds a candidate per tracked-pointer source and pickPointerCand() chooses: the acting source, else the last-active source while it is on the panel, else any source on the panel, else the last-active source, else the first. pointerDown() passes the event's inputSource, so an action is always evaluated with the acting hand's ray, and the choice sticks afterwards. stats.activeSrc reports it; session end resets it. pickPointerCand is pure and unit-tested against the built bundle (9 cases, including the reported one: guide on the left + right pinch -> hand:right, and it stays). Verified in the headset only up to "no hands tracked at the time"; the live hand switch still needs a worn headset.
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
var NS = window.__JFVR = window.__JFVR || {};
|
||||
|
||||
NS.version = 'hud-9'; // hud-9 = ADDENDUM 10 (native/TextTrack subtitles painted by the HUD; layout override per-session, ADDENDUM 9 rAF broker + auto dual/mono layout)
|
||||
NS.version = 'hud-10'; // hud-10 = ADDENDUM 11 (pointer follows the acting/aiming hand) + ADDENDUM 10 (native subtitles) + 9
|
||||
NS.__core = true;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
|
||||
+63
-10
@@ -850,6 +850,7 @@
|
||||
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 };
|
||||
activeSrcKey = null; // ADDENDUM 11: fresh hand choice every session
|
||||
S.pointer = null;
|
||||
S.session = null;
|
||||
S.refSpace = null;
|
||||
@@ -1036,7 +1037,39 @@
|
||||
// the only mode (an index-finger ray carries fingertip jitter straight into
|
||||
// the cursor, and nobody wants to point with one finger).
|
||||
|
||||
function updatePointer(frame) {
|
||||
// Identity for an input source that survives the runtime re-listing it.
|
||||
function srcKey(src) {
|
||||
if (!src) return null;
|
||||
return (src.hand ? 'hand' : 'ctrl') + ':' + (src.handedness || '?');
|
||||
}
|
||||
|
||||
function candByKey(cands, key) {
|
||||
for (var i = 0; i < cands.length; i++) if (cands[i].key === key) return cands[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
// ADDENDUM 11 — pure: choose which input source owns the pointer.
|
||||
// cands [{ key, onPanel, ... }] in runtime order
|
||||
// preferKey the source that is acting right now (select / gamepad press)
|
||||
// activeKey the source that acted last
|
||||
// Order: acting -> last-active-while-on-panel -> any-on-panel -> last-active -> first.
|
||||
function pickPointerCand(cands, preferKey, activeKey) {
|
||||
if (!cands || !cands.length) return null;
|
||||
var i, c;
|
||||
if (preferKey) { c = candByKey(cands, preferKey); if (c) return 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; }
|
||||
return cands[0];
|
||||
}
|
||||
|
||||
// ADDENDUM 11: which hand owns the pointer.
|
||||
var activeSrcKey = null;
|
||||
|
||||
function updatePointer(frame, preferSrc) {
|
||||
if (!S.session) return;
|
||||
var next = {
|
||||
visible: false, beam: false, source: 'none',
|
||||
@@ -1054,24 +1087,43 @@
|
||||
// platform; an index-finger ray computed from joint poses carries the
|
||||
// per-frame fingertip jitter straight into the cursor, so its landing point
|
||||
// is visibly less steady. Meta's own samples use targetRaySpace too.
|
||||
//
|
||||
// ADDENDUM 11: with two hands BOTH report a tracked-pointer ray, and the
|
||||
// runtime's order is not "the hand the user is using". Taking the first one
|
||||
// pinned the guide line to one hand AND made the OTHER hand's select land
|
||||
// wherever the pinned hand pointed. The pointer now follows, in order:
|
||||
// 1. the source acting right now (select / gamepad press),
|
||||
// 2. the last acting source, while it is aiming at the panel,
|
||||
// 3. any source aiming at the panel,
|
||||
// 4. the last acting source, then the first one.
|
||||
var cands = [];
|
||||
for (var i = 0; i < srcs.length; i++) {
|
||||
var src = srcs[i];
|
||||
if (src.targetRayMode !== 'tracked-pointer') continue;
|
||||
var isHand = !!src.hand;
|
||||
var ray = rayOf(frame, src);
|
||||
if (!ray) continue;
|
||||
var hit = panelHit(frame, ray, layer, 0.25, 0.6);
|
||||
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),
|
||||
onPanel: !!(hit && hit.inBounds)
|
||||
});
|
||||
}
|
||||
|
||||
var pick = pickPointerCand(cands, preferSrc ? srcKey(preferSrc) : null, activeSrcKey);
|
||||
|
||||
if (pick) {
|
||||
activeSrcKey = pick.key;
|
||||
next = {
|
||||
visible: true,
|
||||
beam: true,
|
||||
source: (isHand ? 'hand' : 'controller') + ':' + src.handedness,
|
||||
origin: ray.origin,
|
||||
dir: ray.dir,
|
||||
hit: hit ? { nx: hit.nx, ny: hit.ny } : null,
|
||||
distance: hit ? hit.distance : null,
|
||||
source: (pick.src.hand ? 'hand' : 'controller') + ':' + pick.src.handedness,
|
||||
origin: pick.ray.origin,
|
||||
dir: pick.ray.dir,
|
||||
hit: pick.hit ? { nx: pick.hit.nx, ny: pick.hit.ny } : null,
|
||||
distance: pick.hit ? pick.hit.distance : null,
|
||||
pressed: performance.now() < pressUntil
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
pointer = next;
|
||||
@@ -1080,6 +1132,7 @@
|
||||
if (NS.Controls && NS.Controls.setPointer) {
|
||||
try { NS.Controls.setPointer(next); } catch (e) {}
|
||||
}
|
||||
S.stats.activeSrc = activeSrcKey || '(none)';
|
||||
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) {
|
||||
@@ -1579,7 +1632,7 @@
|
||||
// to the bar, so it must not also yank the subtitles.
|
||||
var barWasShown = NS.Controls && NS.Controls.isVisible ? !!NS.Controls.isVisible() : false;
|
||||
|
||||
if (frame) { try { updatePointer(frame); } catch (e) {} }
|
||||
if (frame) { try { updatePointer(frame, src); } catch (e) {} }
|
||||
|
||||
// 1) grabbing the subtitle strip wins, but only while the bar is down
|
||||
if (frame && !barWasShown) {
|
||||
|
||||
Reference in New Issue
Block a user