From 7b36669d8026ebbd9befb52c8ad2194a0171102a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 17 Feb 2017 10:20:13 +1300 Subject: [PATCH] Point index finger while painting if tablet not displayed --- scripts/system/controllers/squeezeHands.js | 33 ++++++++++++++++++++++ scripts/system/fingerPaint.js | 16 +++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/scripts/system/controllers/squeezeHands.js b/scripts/system/controllers/squeezeHands.js index 1e94c29521..3f1d21b46c 100644 --- a/scripts/system/controllers/squeezeHands.js +++ b/scripts/system/controllers/squeezeHands.js @@ -25,6 +25,11 @@ var OVERLAY_RAMP_RATE = 8.0; 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) { return Math.min(Math.max(val, min), max); } @@ -43,6 +48,8 @@ function init() { animStateHandler, ["leftHandOverlayAlpha", "rightHandOverlayAlpha", "leftHandGraspAlpha", "rightHandGraspAlpha"] ); + Messages.subscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL); + Messages.messageReceived.connect(handleMessages); } function animStateHandler(props) { @@ -76,11 +83,37 @@ function update(dt) { } else { 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() { Script.update.disconnect(update); MyAvatar.removeAnimationStateHandler(animStateHandlerID); + Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL); + Messages.messageReceived.disconnect(handleMessages); } Script.scriptEnding.connect(shutdown); diff --git a/scripts/system/fingerPaint.js b/scripts/system/fingerPaint.js index d35e053d6b..7dbcc4c370 100644 --- a/scripts/system/fingerPaint.js +++ b/scripts/system/fingerPaint.js @@ -19,6 +19,7 @@ rightBrush, CONTROLLER_MAPPING_NAME = "com.highfidelity.fingerPaint", isTabletDisplayed = false, + HIFI_POINT_INDEX_MESSAGE_CHANNEL = "Hifi-Point-Index", HIFI_GRAB_DISABLE_MESSAGE_CHANNEL = "Hifi-Grab-Disable"; function paintBrush(name) { @@ -96,8 +97,8 @@ }; } - function updateHandControllerGrab() { - // Send message to handControllerGrab.js to handle. + function updateHandFunctions() { + // Update other scripts' hand functions. var enabled = !isFingerPainting || isTabletDisplayed; Messages.sendMessage(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL, JSON.stringify({ @@ -105,6 +106,9 @@ nearGrabEnabled: enabled, farGrabEnabled: enabled })); + Messages.sendMessage(HIFI_POINT_INDEX_MESSAGE_CHANNEL, JSON.stringify({ + pointIndex: !enabled + })); } function onButtonClicked() { @@ -121,14 +125,14 @@ rightBrush.cancelLine(); } - updateHandControllerGrab(); + updateHandFunctions(); } function onTabletScreenChanged(type, url) { var TABLET_SCREEN_CLOSED = "Closed"; isTabletDisplayed = type !== TABLET_SCREEN_CLOSED; - updateHandControllerGrab(); + updateHandFunctions(); } function setUp() { @@ -171,7 +175,8 @@ rightHand.trigerRelease = rightBrush.finishLine; 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); } @@ -197,6 +202,7 @@ rightHand.tearDown(); rightHand = null; + Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL); Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL); }