mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-17 04:32:29 +02:00
Display placeholder for tool icon on dominant hand
This commit is contained in:
parent
2a654b3657
commit
c201e7b65a
3 changed files with 136 additions and 5 deletions
100
scripts/vr-edit/modules/toolIcon.js
Normal file
100
scripts/vr-edit/modules/toolIcon.js
Normal file
|
@ -0,0 +1,100 @@
|
|||
//
|
||||
// toolIcon.js
|
||||
//
|
||||
// Created by David Rowe on 28 Jul 2017.
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
/* global ToolIcon */
|
||||
|
||||
ToolIcon = function (side) {
|
||||
// Tool icon displayed on non-dominant hand.
|
||||
|
||||
"use strict";
|
||||
|
||||
var NONE = 0,
|
||||
SCALE_HANDLES = 1,
|
||||
|
||||
ICON_COLORS = [
|
||||
{ red: 0, green: 0, blue: 0 }, // Unused entry for NONE.
|
||||
{ red: 0, green: 240, blue: 240 }
|
||||
],
|
||||
|
||||
LEFT_HAND = 0,
|
||||
AVATAR_SELF_ID = "{00000000-0000-0000-0000-000000000001}",
|
||||
|
||||
ICON_DIMENSIONS = { x: 0.1, y: 0.01, z: 0.1 },
|
||||
ICON_POSITION = { x: 0, y: 0.01, z: 0 },
|
||||
ICON_ROTATION = Quat.fromVec3Degrees({ x: 0, y: 0, z: 0 }),
|
||||
|
||||
ICON_TYPE = "sphere",
|
||||
ICON_PROPERTIES = {
|
||||
dimensions: ICON_DIMENSIONS,
|
||||
localPosition: ICON_POSITION,
|
||||
localRotation: ICON_ROTATION,
|
||||
solid: true,
|
||||
alpha: 1.0,
|
||||
parentID: AVATAR_SELF_ID,
|
||||
ignoreRayIntersection: false,
|
||||
visible: true
|
||||
},
|
||||
|
||||
HAND_JOINT_NAME = side === LEFT_HAND ? "LeftHand" : "RightHand",
|
||||
|
||||
iconOverlay = null;
|
||||
|
||||
if (!this instanceof ToolIcon) {
|
||||
return new ToolIcon();
|
||||
}
|
||||
|
||||
function update() {
|
||||
// TODO: Display icon animation.
|
||||
// TODO: Clear icon animation.
|
||||
}
|
||||
|
||||
function display(icon) {
|
||||
// Displays icon on hand.
|
||||
var handJointIndex,
|
||||
iconProperties;
|
||||
|
||||
// Joint index.
|
||||
handJointIndex = MyAvatar.getJointIndex(HAND_JOINT_NAME);
|
||||
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.
|
||||
// TODO: Log error.
|
||||
return;
|
||||
}
|
||||
|
||||
iconProperties = Object.clone(ICON_PROPERTIES);
|
||||
iconProperties.parentJointIndex = handJointIndex;
|
||||
iconProperties.color = ICON_COLORS[icon];
|
||||
iconOverlay = Overlays.addOverlay(ICON_TYPE, iconProperties);
|
||||
}
|
||||
|
||||
function clear() {
|
||||
// Deletes current icon.
|
||||
if (iconOverlay) {
|
||||
Overlays.deleteOverlay(iconOverlay);
|
||||
iconOverlay = null;
|
||||
}
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
clear();
|
||||
}
|
||||
|
||||
return {
|
||||
NONE: NONE,
|
||||
SCALE_HANDLES: SCALE_HANDLES,
|
||||
update: update,
|
||||
display: display,
|
||||
clear: clear,
|
||||
destroy: destroy
|
||||
};
|
||||
};
|
||||
|
||||
ToolIcon.prototype = {};
|
|
@ -49,3 +49,9 @@ if (typeof Entities.hasEditableRoot !== "function") {
|
|||
return properties.visible && !properties.locked && NONEDITABLE_ENTITY_TYPES.indexOf(properties.type) === -1;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof Object.clone !== "function") {
|
||||
Object.clone = function (object) {
|
||||
return JSON.parse(JSON.stringify(object));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -33,13 +33,14 @@
|
|||
RIGHT_HAND = 1,
|
||||
|
||||
// Modules
|
||||
CreatePalette,
|
||||
Hand,
|
||||
Handles,
|
||||
Highlights,
|
||||
Laser,
|
||||
Selection,
|
||||
ToolIcon,
|
||||
ToolMenu,
|
||||
CreatePalette,
|
||||
|
||||
// Miscellaneous
|
||||
UPDATE_LOOP_TIMEOUT = 16,
|
||||
|
@ -59,6 +60,7 @@
|
|||
Script.include("./modules/highlights.js");
|
||||
Script.include("./modules/laser.js");
|
||||
Script.include("./modules/selection.js");
|
||||
Script.include("./modules/toolIcon.js");
|
||||
Script.include("./modules/toolMenu.js");
|
||||
|
||||
|
||||
|
@ -80,6 +82,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
function otherHand(hand) {
|
||||
return (hand + 1) % 2;
|
||||
}
|
||||
|
||||
|
||||
Inputs = function (side) {
|
||||
// A hand plus a laser.
|
||||
|
@ -164,6 +170,7 @@
|
|||
|
||||
var // Primary objects.
|
||||
toolMenu,
|
||||
toolIcon,
|
||||
createPalette,
|
||||
|
||||
isDisplaying = false,
|
||||
|
@ -175,6 +182,7 @@
|
|||
return new UI();
|
||||
}
|
||||
|
||||
toolIcon = new ToolIcon(otherHand(side));
|
||||
toolMenu = new ToolMenu(side, leftInputs, rightInputs, setAppScaleWithHandlesCallback);
|
||||
createPalette = new CreatePalette(side, leftInputs, rightInputs);
|
||||
|
||||
|
@ -187,6 +195,14 @@
|
|||
getIntersection = side === LEFT_HAND ? rightInputs.intersection : leftInputs.intersection;
|
||||
}
|
||||
|
||||
function setToolIcon(icon) {
|
||||
toolIcon.display(icon);
|
||||
}
|
||||
|
||||
function clearToolIcon() {
|
||||
toolIcon.clear();
|
||||
}
|
||||
|
||||
function display() {
|
||||
var uiEntityIDs;
|
||||
|
||||
|
@ -204,6 +220,7 @@
|
|||
if (isDisplaying) {
|
||||
toolMenu.update(getIntersection().overlayID);
|
||||
createPalette.update(getIntersection().overlayID);
|
||||
toolIcon.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,10 +242,17 @@
|
|||
toolMenu.destroy();
|
||||
toolMenu = null;
|
||||
}
|
||||
if (toolIcon) {
|
||||
toolIcon.destroy();
|
||||
toolIcon = null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
setHand: setHand,
|
||||
setToolIcon: setToolIcon,
|
||||
clearToolIcon: clearToolIcon,
|
||||
SCALE_HANDLES: toolIcon.SCALE_HANDLES,
|
||||
display: display,
|
||||
update: update,
|
||||
clear: clear,
|
||||
|
@ -972,6 +996,11 @@
|
|||
|
||||
function setAppScaleWithHandles(appScaleWithHandles) {
|
||||
isAppScaleWithHandles = appScaleWithHandles;
|
||||
if (isAppScaleWithHandles) {
|
||||
ui.setToolIcon(ui.SCALE_HANDLES);
|
||||
} else {
|
||||
ui.clearToolIcon();
|
||||
}
|
||||
}
|
||||
|
||||
function onAppButtonClicked() {
|
||||
|
@ -994,10 +1023,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
function otherHand(hand) {
|
||||
return (hand + 1) % 2;
|
||||
}
|
||||
|
||||
function onDominantHandChanged() {
|
||||
/*
|
||||
// TODO: API coming.
|
||||
|
|
Loading…
Reference in a new issue