Switch between stylus and fingerpaint mode when not painting and hand

hovers the tablet.
Replace OK button in color picker with Add button (allows user to add custom
colors, and enables user to pick color just by pressing on top of the
color picker);
This commit is contained in:
Artur Gomes 2017-07-05 10:04:16 +01:00
parent 9309f5137a
commit b6beb2033f
2 changed files with 76 additions and 1 deletions

View file

@ -16,6 +16,8 @@
UNDO_STACK_SIZE = 5, UNDO_STACK_SIZE = 5,
undoStack = []; undoStack = [];
isFingerPainting = false, isFingerPainting = false,
isTabletFocused = false,
tabletDebugFocusLine = null,
//dynamic brush vars //dynamic brush vars
/*9isDynamicBrushEnabled = false, /*9isDynamicBrushEnabled = false,
isDynamicBrushRunning = false, isDynamicBrushRunning = false,
@ -42,6 +44,7 @@
// Set up the qml ui // Set up the qml ui
var qml = Script.resolvePath('PaintWindow.qml'); var qml = Script.resolvePath('PaintWindow.qml');
Script.include("../libraries/controllers.js");
var window = null; var window = null;
//var inkSource = null; //var inkSource = null;
@ -418,6 +421,43 @@
} }
} }
function checkTabletHasFocus() {
var controllerPose = getControllerWorldLocation(Controller.Standard.RightHand, true); // note: this will return head pose if hand pose is invalid (third eye)
var fingerTipRotation = controllerPose.rotation;//Quat.inverse(MyAvatar.orientation);
var fingerTipPosition = controllerPose.position;//MyAvatar.getJointPosition(handName === "left" ? "LeftHandIndex4" : "RightHandIndex4");
var pickRay = {
origin: fingerTipPosition,
direction: Quat.getUp(fingerTipRotation)
}
var overlays = Overlays.findRayIntersection(pickRay, false, [HMD.tabletID], [inkSourceOverlay.overlayID]);
print(JSON.stringify(overlays));
if (overlays.intersects && HMD.tabletID == overlays.overlayID) {
if (!isTabletFocused) {
isTabletFocused = true;
//isFingerPainting = false;
Overlays.editOverlay(inkSourceOverlay, {visible: false});
updateHandAnimations();
pauseProcessing();
print("Hovering tablet!");
}
} else {
if (isTabletFocused) {
print("Unhovering tablet!");
isTabletFocused = false;
//isFingerPainting = true;
Overlays.editOverlay(inkSourceOverlay, {visible: true});
resumeProcessing();
updateHandFunctions();
//updateHandAnimations();
print("Current hand " + handName);
print("isFingerPainting " + isFingerPainting);
print("inkSourceOverlay " + JSON.stringify(inkSourceOverlay));
print("inkSourceOverlay " + JSON.stringify(inkSourceOverlay));
}
};
}
/*function runDynamicBrush() { /*function runDynamicBrush() {
if (isDynamicBrushRunning) { if (isDynamicBrushRunning) {
var currentBrush = isLeftHandDominant ? leftBrush : rightBrush; var currentBrush = isLeftHandDominant ? leftBrush : rightBrush;
@ -474,7 +514,11 @@
// } // }
/*frameDeltaSeconds = Date.now() - lastFrameTime; /*frameDeltaSeconds = Date.now() - lastFrameTime;
lastFrameTime = Date.now(); lastFrameTime = Date.now();
runDynamicBrush(); */ runDynamicBrush(); */
if (((!leftBrush || !rightBrush) || !leftBrush.isDrawingLine && !rightBrush.isDrawingLine)) {
checkTabletHasFocus();
}
updateTriggerPress(); updateTriggerPress();
updateGripPress(); updateGripPress();
} }
@ -715,6 +759,33 @@
}
function pauseProcessing() {
//Script.update.disconnect(leftHand.onUpdate);
//Script.update.disconnect(rightHand.onUpdate);
//Controller.disableMapping(CONTROLLER_MAPPING_NAME);
Messages.sendLocalMessage("Hifi-Hand-Disabler", "none");
Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
Messages.unsubscribe(HIFI_POINTER_DISABLE_MESSAGE_CHANNEL);
//Restores and clears hand animations
restoreAllHandAnimations();
}
function resumeProcessing() {
//Change to finger paint hand animation
updateHandAnimations();
// 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_POINTER_DISABLE_MESSAGE_CHANNEL);
} }
function disableProcessing() { function disableProcessing() {

View file

@ -33,6 +33,10 @@
flat:true, flat:true,
layout:'hex', layout:'hex',
colorScheme:'dark', colorScheme:'dark',
submitText: 'Add custom color',
onChange: function(hsb, hex, rgb, el) {
update([rgb.r, rgb.g, rgb.b])
},
onSubmit: function(hsb, hex, rgb, el) { onSubmit: function(hsb, hex, rgb, el) {
updateColorFromCustomPicker(rgb) updateColorFromCustomPicker(rgb)
} }