mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 09:45:23 +02:00
Use dominant hand setting and handle setting changes
This commit is contained in:
parent
19fc8b2ed0
commit
1d500dd3aa
4 changed files with 92 additions and 62 deletions
|
@ -22,16 +22,14 @@ CreatePalette = function (side, leftInputs, rightInputs) {
|
|||
|
||||
LEFT_HAND = 0,
|
||||
AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}",
|
||||
ZERO_ROTATION = Quat.fromVec3Radians(Vec3.ZERO),
|
||||
|
||||
HAND_JOINT_NAME = side === LEFT_HAND ? "LeftHand" : "RightHand",
|
||||
controlJointName,
|
||||
|
||||
CANVAS_SIZE = { x: 0.21, y: 0.13 },
|
||||
LATERAL_OFFSET = side === LEFT_HAND ? -0.01 : 0.01,
|
||||
|
||||
PALETTE_ROOT_POSITION = { x: -CANVAS_SIZE.x / 2 + LATERAL_OFFSET, y: 0.15, z: 0.09 },
|
||||
PALETTE_ROOT_POSITION = { x: -CANVAS_SIZE.x / 2, y: 0.15, z: 0.09 },
|
||||
PALETTE_ROOT_ROTATION = Quat.fromVec3Degrees({ x: 0, y: 180, z: 180 }),
|
||||
|
||||
ZERO_ROTATION = Quat.fromVec3Radians(Vec3.ZERO),
|
||||
lateralOffset,
|
||||
|
||||
PALETTE_ORIGIN_PROPERTIES = {
|
||||
dimensions: { x: 0.005, y: 0.005, z: 0.005 },
|
||||
|
@ -97,17 +95,16 @@ CreatePalette = function (side, leftInputs, rightInputs) {
|
|||
return new CreatePalette();
|
||||
}
|
||||
|
||||
controlHand = side === LEFT_HAND ? rightInputs.hand() : leftInputs.hand();
|
||||
|
||||
function setHand(uiSide) {
|
||||
side = uiSide;
|
||||
function setHand(hand) {
|
||||
// Assumes UI is not displaying.
|
||||
side = hand;
|
||||
controlHand = side === LEFT_HAND ? rightInputs.hand() : leftInputs.hand();
|
||||
|
||||
if (isDisplaying) {
|
||||
// TODO: Move UI to other hand.
|
||||
}
|
||||
controlJointName = side === LEFT_HAND ? "LeftHand" : "RightHand";
|
||||
lateralOffset = side === LEFT_HAND ? -0.01 : 0.01;
|
||||
}
|
||||
|
||||
setHand(side);
|
||||
|
||||
function getEntityIDs() {
|
||||
return [palettePanelOverlay, cubeOverlay];
|
||||
}
|
||||
|
@ -141,14 +138,15 @@ CreatePalette = function (side, leftInputs, rightInputs) {
|
|||
|
||||
function display() {
|
||||
// Creates and shows menu entities.
|
||||
var handJointIndex;
|
||||
var handJointIndex,
|
||||
properties;
|
||||
|
||||
if (isDisplaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Joint index.
|
||||
handJointIndex = MyAvatar.getJointIndex(HAND_JOINT_NAME);
|
||||
handJointIndex = MyAvatar.getJointIndex(controlJointName);
|
||||
if (handJointIndex === -1) {
|
||||
// Don't display if joint isn't available (yet) to attach to.
|
||||
// User can clear this condition by toggling the app off and back on once avatar finishes loading.
|
||||
|
@ -157,18 +155,23 @@ CreatePalette = function (side, leftInputs, rightInputs) {
|
|||
}
|
||||
|
||||
// Calculate position to put palette.
|
||||
PALETTE_ORIGIN_PROPERTIES.parentJointIndex = handJointIndex;
|
||||
paletteOriginOverlay = Overlays.addOverlay("sphere", PALETTE_ORIGIN_PROPERTIES);
|
||||
properties = Object.clone(PALETTE_ORIGIN_PROPERTIES);
|
||||
properties.parentJointIndex = handJointIndex;
|
||||
properties.localPosition = Vec3.sum(PALETTE_ROOT_POSITION, { x: lateralOffset, y: 0, z: 0 });
|
||||
paletteOriginOverlay = Overlays.addOverlay("sphere", properties);
|
||||
|
||||
// Create palette items.
|
||||
PALETTE_PANEL_PROPERTIES.parentID = paletteOriginOverlay;
|
||||
palettePanelOverlay = Overlays.addOverlay("cube", PALETTE_PANEL_PROPERTIES);
|
||||
CUBE_PROPERTIES.parentID = paletteOriginOverlay;
|
||||
cubeOverlay = Overlays.addOverlay("cube", CUBE_PROPERTIES);
|
||||
properties = Object.clone(PALETTE_PANEL_PROPERTIES);
|
||||
properties.parentID = paletteOriginOverlay;
|
||||
palettePanelOverlay = Overlays.addOverlay("cube", properties);
|
||||
properties = Object.clone(CUBE_PROPERTIES);
|
||||
properties.parentID = paletteOriginOverlay;
|
||||
cubeOverlay = Overlays.addOverlay("cube", properties);
|
||||
|
||||
// Prepare cube highlight overlay.
|
||||
CUBE_HIGHLIGHT_PROPERTIES.parentID = paletteOriginOverlay;
|
||||
cubeHighlightOverlay = Overlays.addOverlay("cube", CUBE_HIGHLIGHT_PROPERTIES);
|
||||
properties = Object.clone(CUBE_HIGHLIGHT_PROPERTIES);
|
||||
properties.parentID = paletteOriginOverlay;
|
||||
cubeHighlightOverlay = Overlays.addOverlay("cube", properties);
|
||||
|
||||
isDisplaying = true;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ ToolIcon = function (side) {
|
|||
visible: true
|
||||
},
|
||||
|
||||
HAND_JOINT_NAME = side === LEFT_HAND ? "LeftHand" : "RightHand",
|
||||
handJointName,
|
||||
|
||||
iconOverlay = null;
|
||||
|
||||
|
@ -50,6 +50,13 @@ ToolIcon = function (side) {
|
|||
return new ToolIcon();
|
||||
}
|
||||
|
||||
function setHand(side) {
|
||||
// Assumes UI is not displaying.
|
||||
handJointName = side === LEFT_HAND ? "LeftHand" : "RightHand";
|
||||
}
|
||||
|
||||
setHand(side);
|
||||
|
||||
function update() {
|
||||
// TODO: Display icon animation.
|
||||
// TODO: Clear icon animation.
|
||||
|
@ -60,7 +67,7 @@ ToolIcon = function (side) {
|
|||
var handJointIndex,
|
||||
iconProperties;
|
||||
|
||||
handJointIndex = MyAvatar.getJointIndex(HAND_JOINT_NAME);
|
||||
handJointIndex = MyAvatar.getJointIndex(handJointName);
|
||||
if (handJointIndex === -1) {
|
||||
// Don't display if joint isn't available (yet) to attach to.
|
||||
// User can clear this condition by toggling the app off and back on once avatar finishes loading.
|
||||
|
@ -93,6 +100,7 @@ ToolIcon = function (side) {
|
|||
return {
|
||||
NONE: NONE,
|
||||
SCALE_HANDLES: SCALE_HANDLES,
|
||||
setHand: setHand,
|
||||
update: update,
|
||||
display: display,
|
||||
clear: clear,
|
||||
|
|
|
@ -22,16 +22,14 @@ ToolMenu = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallba
|
|||
|
||||
LEFT_HAND = 0,
|
||||
AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}",
|
||||
ZERO_ROTATION = Quat.fromVec3Radians(Vec3.ZERO),
|
||||
|
||||
HAND_JOINT_NAME = side === LEFT_HAND ? "LeftHand" : "RightHand",
|
||||
controlJointName,
|
||||
|
||||
CANVAS_SIZE = { x: 0.21, y: 0.13 },
|
||||
LATERAL_OFFSET = side === LEFT_HAND ? -0.01 : 0.01,
|
||||
|
||||
PANEL_ROOT_POSITION = { x: CANVAS_SIZE.x / 2 + LATERAL_OFFSET, y: 0.15, z: -0.04 },
|
||||
PANEL_ROOT_POSITION = { x: CANVAS_SIZE.x / 2, y: 0.15, z: -0.04 },
|
||||
PANEL_ROOT_ROTATION = Quat.fromVec3Degrees({ x: 0, y: 0, z: 180 }),
|
||||
|
||||
ZERO_ROTATION = Quat.fromVec3Radians(Vec3.ZERO),
|
||||
lateralOffset,
|
||||
|
||||
PANEL_ORIGIN_PROPERTIES = {
|
||||
dimensions: { x: 0.005, y: 0.005, z: 0.005 },
|
||||
|
@ -93,15 +91,16 @@ ToolMenu = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallba
|
|||
|
||||
controlHand = side === LEFT_HAND ? rightInputs.hand() : leftInputs.hand();
|
||||
|
||||
function setHand(uiSide) {
|
||||
side = uiSide;
|
||||
function setHand(hand) {
|
||||
// Assumes UI is not displaying.
|
||||
side = hand;
|
||||
controlHand = side === LEFT_HAND ? rightInputs.hand() : leftInputs.hand();
|
||||
|
||||
if (isDisplaying) {
|
||||
// TODO: Move UI to other hand.
|
||||
}
|
||||
controlJointName = side === LEFT_HAND ? "LeftHand" : "RightHand";
|
||||
lateralOffset = side === LEFT_HAND ? -0.01 : 0.01;
|
||||
}
|
||||
|
||||
setHand(side);
|
||||
|
||||
function getEntityIDs() {
|
||||
return [menuPanelOverlay, buttonOverlay];
|
||||
}
|
||||
|
@ -131,14 +130,15 @@ ToolMenu = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallba
|
|||
|
||||
function display() {
|
||||
// Creates and shows menu entities.
|
||||
var handJointIndex;
|
||||
var handJointIndex,
|
||||
properties;
|
||||
|
||||
if (isDisplaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Joint index.
|
||||
handJointIndex = MyAvatar.getJointIndex(HAND_JOINT_NAME);
|
||||
handJointIndex = MyAvatar.getJointIndex(controlJointName);
|
||||
if (handJointIndex === -1) {
|
||||
// Don't display if joint isn't available (yet) to attach to.
|
||||
// User can clear this condition by toggling the app off and back on once avatar finishes loading.
|
||||
|
@ -147,18 +147,23 @@ ToolMenu = function (side, leftInputs, rightInputs, setAppScaleWithHandlesCallba
|
|||
}
|
||||
|
||||
// Calculate position to put menu.
|
||||
PANEL_ORIGIN_PROPERTIES.parentJointIndex = handJointIndex;
|
||||
menuOriginOverlay = Overlays.addOverlay("sphere", PANEL_ORIGIN_PROPERTIES);
|
||||
properties = Object.clone(PANEL_ORIGIN_PROPERTIES);
|
||||
properties.parentJointIndex = handJointIndex;
|
||||
properties.localPosition = Vec3.sum(PANEL_ROOT_POSITION, { x: lateralOffset, y: 0, z: 0 });
|
||||
menuOriginOverlay = Overlays.addOverlay("sphere", properties);
|
||||
|
||||
// Create menu items.
|
||||
MENU_PANEL_PROPERTIES.parentID = menuOriginOverlay;
|
||||
menuPanelOverlay = Overlays.addOverlay("cube", MENU_PANEL_PROPERTIES);
|
||||
BUTTON_PROPERTIES.parentID = menuOriginOverlay;
|
||||
buttonOverlay = Overlays.addOverlay("cube", BUTTON_PROPERTIES);
|
||||
properties = Object.clone(MENU_PANEL_PROPERTIES);
|
||||
properties.parentID = menuOriginOverlay;
|
||||
menuPanelOverlay = Overlays.addOverlay("cube", properties);
|
||||
properties = Object.clone(BUTTON_PROPERTIES);
|
||||
properties.parentID = menuOriginOverlay;
|
||||
buttonOverlay = Overlays.addOverlay("cube", properties);
|
||||
|
||||
// Prepare button highlight overlay.
|
||||
BUTTON_HIGHLIGHT_PROPERTIES.parentID = menuOriginOverlay;
|
||||
buttonHighlightOverlay = Overlays.addOverlay("cube", BUTTON_HIGHLIGHT_PROPERTIES);
|
||||
properties = Object.clone(BUTTON_HIGHLIGHT_PROPERTIES);
|
||||
properties.parentID = menuOriginOverlay;
|
||||
buttonHighlightOverlay = Overlays.addOverlay("cube", properties);
|
||||
|
||||
isDisplaying = true;
|
||||
}
|
||||
|
|
|
@ -190,6 +190,7 @@
|
|||
|
||||
|
||||
function setHand(side) {
|
||||
toolIcon.setHand(otherHand(side));
|
||||
toolMenu.setHand(side);
|
||||
createPalette.setHand(side);
|
||||
getIntersection = side === LEFT_HAND ? rightInputs.intersection : leftInputs.intersection;
|
||||
|
@ -1034,12 +1035,31 @@
|
|||
}
|
||||
}
|
||||
|
||||
function onDominantHandChanged() {
|
||||
/*
|
||||
// TODO: API coming.
|
||||
dominantHand = TODO;
|
||||
*/
|
||||
function onDominantHandChanged(hand) {
|
||||
dominantHand = hand === "left" ? LEFT_HAND : RIGHT_HAND;
|
||||
|
||||
if (isAppActive) {
|
||||
// Stop operations.
|
||||
Script.clearTimeout(updateTimer);
|
||||
updateTimer = null;
|
||||
inputs[LEFT_HAND].clear();
|
||||
inputs[RIGHT_HAND].clear();
|
||||
ui.clear();
|
||||
editors[LEFT_HAND].clear();
|
||||
editors[RIGHT_HAND].clear();
|
||||
}
|
||||
|
||||
// Swap UI hands.
|
||||
ui.setHand(otherHand(dominantHand));
|
||||
if (isAppScaleWithHandles) {
|
||||
ui.setToolIcon(ui.SCALE_HANDLES);
|
||||
}
|
||||
|
||||
if (isAppActive) {
|
||||
// Resume operations.
|
||||
ui.display();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1052,11 +1072,7 @@
|
|||
}
|
||||
|
||||
// Settings values.
|
||||
// TODO: API coming.
|
||||
dominantHand = RIGHT_HAND;
|
||||
/*
|
||||
dominantHand = TODO;
|
||||
*/
|
||||
dominantHand = MyAvatar.getDominantHand() === "left" ? LEFT_HAND : RIGHT_HAND;
|
||||
|
||||
// Tablet/toolbar button.
|
||||
button = tablet.addButton({
|
||||
|
@ -1083,11 +1099,9 @@
|
|||
editors[RIGHT_HAND].setReferences(inputs[RIGHT_HAND], editors[LEFT_HAND]);
|
||||
|
||||
// Settings changes.
|
||||
/*
|
||||
// TODO: API coming.
|
||||
TODO.change.connect(onDominantHandChanged);
|
||||
*/
|
||||
MyAvatar.dominantHandChanged.connect(onDominantHandChanged);
|
||||
|
||||
// Start main update loop.
|
||||
if (isAppActive) {
|
||||
update();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue