mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 07:53:08 +02:00
Point index finger while painting if tablet not displayed
This commit is contained in:
parent
867e24762b
commit
7b36669d80
2 changed files with 44 additions and 5 deletions
|
@ -25,6 +25,11 @@ var OVERLAY_RAMP_RATE = 8.0;
|
||||||
|
|
||||||
var animStateHandlerID;
|
var animStateHandlerID;
|
||||||
|
|
||||||
|
var isPointingIndex = false;
|
||||||
|
var HIFI_POINT_INDEX_MESSAGE_CHANNEL = "Hifi-Point-Index";
|
||||||
|
|
||||||
|
var indexfingerJointNames = ["LeftHandIndex1", "LeftHandIndex2", "LeftHandIndex3", "RightHandIndex1", "RightHandIndex2", "RightHandIndex3"];
|
||||||
|
|
||||||
function clamp(val, min, max) {
|
function clamp(val, min, max) {
|
||||||
return Math.min(Math.max(val, min), max);
|
return Math.min(Math.max(val, min), max);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +48,8 @@ function init() {
|
||||||
animStateHandler,
|
animStateHandler,
|
||||||
["leftHandOverlayAlpha", "rightHandOverlayAlpha", "leftHandGraspAlpha", "rightHandGraspAlpha"]
|
["leftHandOverlayAlpha", "rightHandOverlayAlpha", "leftHandGraspAlpha", "rightHandGraspAlpha"]
|
||||||
);
|
);
|
||||||
|
Messages.subscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
|
||||||
|
Messages.messageReceived.connect(handleMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
function animStateHandler(props) {
|
function animStateHandler(props) {
|
||||||
|
@ -76,11 +83,37 @@ function update(dt) {
|
||||||
} else {
|
} else {
|
||||||
rightHandOverlayAlpha = clamp(rightHandOverlayAlpha - OVERLAY_RAMP_RATE * dt, 0, 1);
|
rightHandOverlayAlpha = clamp(rightHandOverlayAlpha - OVERLAY_RAMP_RATE * dt, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Point index finger.
|
||||||
|
if (isPointingIndex) {
|
||||||
|
var zeroRotation = { x: 0, y: 0, z: 0, w: 1 };
|
||||||
|
for (var i = 0; i < indexfingerJointNames.length; i++) {
|
||||||
|
MyAvatar.setJointRotation(indexfingerJointNames[i], zeroRotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMessages(channel, message, sender) {
|
||||||
|
if (sender === MyAvatar.sessionUUID && channel === HIFI_POINT_INDEX_MESSAGE_CHANNEL) {
|
||||||
|
var data = JSON.parse(message);
|
||||||
|
if (data.pointIndex !== undefined) {
|
||||||
|
print("pointIndex: " + data.pointIndex);
|
||||||
|
isPointingIndex = data.pointIndex;
|
||||||
|
|
||||||
|
if (!isPointingIndex) {
|
||||||
|
for (var i = 0; i < indexfingerJointNames.length; i++) {
|
||||||
|
MyAvatar.clearJointData(indexfingerJointNames[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shutdown() {
|
function shutdown() {
|
||||||
Script.update.disconnect(update);
|
Script.update.disconnect(update);
|
||||||
MyAvatar.removeAnimationStateHandler(animStateHandlerID);
|
MyAvatar.removeAnimationStateHandler(animStateHandlerID);
|
||||||
|
Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
|
||||||
|
Messages.messageReceived.disconnect(handleMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(shutdown);
|
Script.scriptEnding.connect(shutdown);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
rightBrush,
|
rightBrush,
|
||||||
CONTROLLER_MAPPING_NAME = "com.highfidelity.fingerPaint",
|
CONTROLLER_MAPPING_NAME = "com.highfidelity.fingerPaint",
|
||||||
isTabletDisplayed = false,
|
isTabletDisplayed = false,
|
||||||
|
HIFI_POINT_INDEX_MESSAGE_CHANNEL = "Hifi-Point-Index",
|
||||||
HIFI_GRAB_DISABLE_MESSAGE_CHANNEL = "Hifi-Grab-Disable";
|
HIFI_GRAB_DISABLE_MESSAGE_CHANNEL = "Hifi-Grab-Disable";
|
||||||
|
|
||||||
function paintBrush(name) {
|
function paintBrush(name) {
|
||||||
|
@ -96,8 +97,8 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateHandControllerGrab() {
|
function updateHandFunctions() {
|
||||||
// Send message to handControllerGrab.js to handle.
|
// Update other scripts' hand functions.
|
||||||
var enabled = !isFingerPainting || isTabletDisplayed;
|
var enabled = !isFingerPainting || isTabletDisplayed;
|
||||||
|
|
||||||
Messages.sendMessage(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL, JSON.stringify({
|
Messages.sendMessage(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL, JSON.stringify({
|
||||||
|
@ -105,6 +106,9 @@
|
||||||
nearGrabEnabled: enabled,
|
nearGrabEnabled: enabled,
|
||||||
farGrabEnabled: enabled
|
farGrabEnabled: enabled
|
||||||
}));
|
}));
|
||||||
|
Messages.sendMessage(HIFI_POINT_INDEX_MESSAGE_CHANNEL, JSON.stringify({
|
||||||
|
pointIndex: !enabled
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onButtonClicked() {
|
function onButtonClicked() {
|
||||||
|
@ -121,14 +125,14 @@
|
||||||
rightBrush.cancelLine();
|
rightBrush.cancelLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHandControllerGrab();
|
updateHandFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTabletScreenChanged(type, url) {
|
function onTabletScreenChanged(type, url) {
|
||||||
var TABLET_SCREEN_CLOSED = "Closed";
|
var TABLET_SCREEN_CLOSED = "Closed";
|
||||||
|
|
||||||
isTabletDisplayed = type !== TABLET_SCREEN_CLOSED;
|
isTabletDisplayed = type !== TABLET_SCREEN_CLOSED;
|
||||||
updateHandControllerGrab();
|
updateHandFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
|
@ -171,7 +175,8 @@
|
||||||
rightHand.trigerRelease = rightBrush.finishLine;
|
rightHand.trigerRelease = rightBrush.finishLine;
|
||||||
rightHand.gripPressed = rightBrush.eraseLine;
|
rightHand.gripPressed = rightBrush.eraseLine;
|
||||||
|
|
||||||
// Messages channel for disabling/enabling laser pointers and grabbing.
|
// Messages channels for enabling/disabling other scripts' functions.
|
||||||
|
Messages.subscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
|
||||||
Messages.subscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
|
Messages.subscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,6 +202,7 @@
|
||||||
rightHand.tearDown();
|
rightHand.tearDown();
|
||||||
rightHand = null;
|
rightHand = null;
|
||||||
|
|
||||||
|
Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
|
||||||
Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
|
Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue