mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01: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 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue