Skip to content

Fix box display on re-entry, simplify #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions immersive-hands.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
const leftBoxColor = {r: 1, g: 0, b: 1};
const rightBoxColor = {r: 0, g: 1, b: 1};
let interactionBox = null;
let leftInteractionBox = null;
let rightInteractionBox = null;

// WebGL scene globals.
let gl = null;
Expand Down Expand Up @@ -238,6 +236,7 @@
// In this simple case discard the WebGL context too, since we're not
// rendering anything else to the screen with it.
renderer = null;
interactionBox = null;
}

function updateInputSources(session, frame, refSpace) {
Expand Down Expand Up @@ -325,11 +324,7 @@
return box;
}
interactionBox = AddInteractionBox(defaultBoxColor.r, defaultBoxColor.g, defaultBoxColor.b);
leftInteractionBox = AddInteractionBox(leftBoxColor.r, leftBoxColor.g, leftBoxColor.b);
rightInteractionBox = AddInteractionBox(rightBoxColor.r, rightBoxColor.g, rightBoxColor.b);
scene.addNode(interactionBox);
scene.addNode(leftInteractionBox);
scene.addNode(rightInteractionBox);
}

function Distance(nodeA, nodeB) {
Expand All @@ -341,19 +336,17 @@

// Perform distance check on interactable elements
const interactionDistance = interactionBox.scale[0];
leftInteractionBox.visible = false;
rightInteractionBox.visible = false;
let color = defaultBoxColor;
if (Distance(indexFingerBoxes.left, interactionBox) < interactionDistance) {
leftInteractionBox.visible = true;
color = leftBoxColor;
} else if (Distance(indexFingerBoxes.right, interactionBox) < interactionDistance) {
rightInteractionBox.visible = true;
}
interactionBox.visible = !(leftInteractionBox.visible || rightInteractionBox.visible);

color = rightBoxColor;
}
const uniforms = interactionBox.renderPrimitives[0].uniforms;
uniforms.baseColorFactor.value = [color.r, color.g, color.b, 1];

mat4.rotateX(interactionBox.matrix, interactionBox.matrix, time/1000);
mat4.rotateY(interactionBox.matrix, interactionBox.matrix, time/1500);
leftInteractionBox.matrix = interactionBox.matrix;
rightInteractionBox.matrix = interactionBox.matrix;
}

// Called every time the XRSession requests that a new frame be drawn.
Expand Down