mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 06:58:56 +02:00
Process controller and script updates only when finger painting is on
This commit is contained in:
parent
05c63e16ca
commit
71ba38afb0
1 changed files with 68 additions and 66 deletions
|
@ -13,10 +13,10 @@
|
||||||
button,
|
button,
|
||||||
BUTTON_NAME = "PAINT",
|
BUTTON_NAME = "PAINT",
|
||||||
isFingerPainting = false,
|
isFingerPainting = false,
|
||||||
leftHand,
|
leftHand = null,
|
||||||
rightHand,
|
rightHand = null,
|
||||||
leftBrush,
|
leftBrush = null,
|
||||||
rightBrush,
|
rightBrush = null,
|
||||||
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_POINT_INDEX_MESSAGE_CHANNEL = "Hifi-Point-Index",
|
||||||
|
@ -186,7 +186,6 @@
|
||||||
function handController(name) {
|
function handController(name) {
|
||||||
// Translates controller data into application events.
|
// Translates controller data into application events.
|
||||||
var handName = name,
|
var handName = name,
|
||||||
isEnabled = false,
|
|
||||||
|
|
||||||
triggerPressedCallback,
|
triggerPressedCallback,
|
||||||
triggerPressingCallback,
|
triggerPressingCallback,
|
||||||
|
@ -213,10 +212,6 @@
|
||||||
GRIP_OFF = 0.05,
|
GRIP_OFF = 0.05,
|
||||||
GRIP_ON = 0.1;
|
GRIP_ON = 0.1;
|
||||||
|
|
||||||
function setEnabled(enabled) {
|
|
||||||
isEnabled = enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTriggerPress(value) {
|
function onTriggerPress(value) {
|
||||||
// Controller values are only updated when they change so store latest for use in update.
|
// Controller values are only updated when they change so store latest for use in update.
|
||||||
rawTriggerValue = value;
|
rawTriggerValue = value;
|
||||||
|
@ -227,10 +222,6 @@
|
||||||
fingerTipPosition,
|
fingerTipPosition,
|
||||||
lineWidth;
|
lineWidth;
|
||||||
|
|
||||||
if (!isEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerValue = triggerValue * TRIGGER_SMOOTH_RATIO + rawTriggerValue * (1.0 - TRIGGER_SMOOTH_RATIO);
|
triggerValue = triggerValue * TRIGGER_SMOOTH_RATIO + rawTriggerValue * (1.0 - TRIGGER_SMOOTH_RATIO);
|
||||||
|
|
||||||
wasTriggerPressed = isTriggerPressed;
|
wasTriggerPressed = isTriggerPressed;
|
||||||
|
@ -267,10 +258,6 @@
|
||||||
function updateGripPress() {
|
function updateGripPress() {
|
||||||
var fingerTipPosition;
|
var fingerTipPosition;
|
||||||
|
|
||||||
if (!isEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gripValue = gripValue * GRIP_SMOOTH_RATIO + rawGripValue * (1.0 - GRIP_SMOOTH_RATIO);
|
gripValue = gripValue * GRIP_SMOOTH_RATIO + rawGripValue * (1.0 - GRIP_SMOOTH_RATIO);
|
||||||
|
|
||||||
if (isGripPressed) {
|
if (isGripPressed) {
|
||||||
|
@ -301,7 +288,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setEnabled: setEnabled,
|
|
||||||
onTriggerPress: onTriggerPress,
|
onTriggerPress: onTriggerPress,
|
||||||
onGripPress: onGripPress,
|
onGripPress: onGripPress,
|
||||||
onUpdate: onUpdate,
|
onUpdate: onUpdate,
|
||||||
|
@ -327,21 +313,76 @@
|
||||||
}), true);
|
}), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableProcessing() {
|
||||||
|
// Connect controller API to handController objects.
|
||||||
|
leftHand = handController("left");
|
||||||
|
rightHand = handController("right");
|
||||||
|
var controllerMapping = Controller.newMapping(CONTROLLER_MAPPING_NAME);
|
||||||
|
controllerMapping.from(Controller.Standard.LT).to(leftHand.onTriggerPress);
|
||||||
|
controllerMapping.from(Controller.Standard.LeftGrip).to(leftHand.onGripPress);
|
||||||
|
controllerMapping.from(Controller.Standard.RT).to(rightHand.onTriggerPress);
|
||||||
|
controllerMapping.from(Controller.Standard.RightGrip).to(rightHand.onGripPress);
|
||||||
|
Controller.enableMapping(CONTROLLER_MAPPING_NAME);
|
||||||
|
|
||||||
|
// Connect handController outputs to paintBrush objects.
|
||||||
|
leftBrush = paintBrush("left");
|
||||||
|
leftHand.setUp(leftBrush.startLine, leftBrush.drawLine, leftBrush.finishLine, leftBrush.eraseClosestLine);
|
||||||
|
rightBrush = paintBrush("right");
|
||||||
|
rightHand.setUp(rightBrush.startLine, rightBrush.drawLine, rightBrush.finishLine, rightBrush.eraseClosestLine);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Update hand controls.
|
||||||
|
Script.update.connect(leftHand.onUpdate);
|
||||||
|
Script.update.connect(rightHand.onUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
function disableProcessing() {
|
||||||
|
Script.update.disconnect(leftHand.onUpdate);
|
||||||
|
Script.update.disconnect(rightHand.onUpdate);
|
||||||
|
|
||||||
|
Controller.disableMapping(CONTROLLER_MAPPING_NAME);
|
||||||
|
|
||||||
|
leftBrush.tearDown();
|
||||||
|
leftBrush = null;
|
||||||
|
leftHand.tearDown();
|
||||||
|
leftHand = null;
|
||||||
|
|
||||||
|
rightBrush.tearDown();
|
||||||
|
rightBrush = null;
|
||||||
|
rightHand.tearDown();
|
||||||
|
rightHand = null;
|
||||||
|
|
||||||
|
Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
|
||||||
|
Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
|
||||||
|
Messages.unsubscribe(HIFI_POINTER_DISABLE_MESSAGE_CHANNEL);
|
||||||
|
}
|
||||||
|
|
||||||
function onButtonClicked() {
|
function onButtonClicked() {
|
||||||
var wasFingerPainting = isFingerPainting;
|
var wasFingerPainting = isFingerPainting;
|
||||||
|
|
||||||
isFingerPainting = !isFingerPainting;
|
isFingerPainting = !isFingerPainting;
|
||||||
button.editProperties({ isActive: isFingerPainting });
|
button.editProperties({ isActive: isFingerPainting });
|
||||||
|
|
||||||
leftHand.setEnabled(isFingerPainting);
|
print("Finger painting: " + isFingerPainting ? "on" : "off");
|
||||||
rightHand.setEnabled(isFingerPainting);
|
|
||||||
|
|
||||||
if (wasFingerPainting) {
|
if (wasFingerPainting) {
|
||||||
leftBrush.cancelLine();
|
leftBrush.cancelLine();
|
||||||
rightBrush.cancelLine();
|
rightBrush.cancelLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isFingerPainting) {
|
||||||
|
enableProcessing();
|
||||||
|
}
|
||||||
|
|
||||||
updateHandFunctions();
|
updateHandFunctions();
|
||||||
|
|
||||||
|
if (!isFingerPainting) {
|
||||||
|
disableProcessing();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTabletScreenChanged(type, url) {
|
function onTabletScreenChanged(type, url) {
|
||||||
|
@ -368,29 +409,6 @@
|
||||||
|
|
||||||
// Track whether tablet is displayed or not.
|
// Track whether tablet is displayed or not.
|
||||||
tablet.screenChanged.connect(onTabletScreenChanged);
|
tablet.screenChanged.connect(onTabletScreenChanged);
|
||||||
|
|
||||||
// Connect controller API to handController objects.
|
|
||||||
leftHand = handController("left");
|
|
||||||
rightHand = handController("right");
|
|
||||||
var controllerMapping = Controller.newMapping(CONTROLLER_MAPPING_NAME);
|
|
||||||
controllerMapping.from(Controller.Standard.LT).to(leftHand.onTriggerPress);
|
|
||||||
controllerMapping.from(Controller.Standard.LeftGrip).to(leftHand.onGripPress);
|
|
||||||
controllerMapping.from(Controller.Standard.RT).to(rightHand.onTriggerPress);
|
|
||||||
controllerMapping.from(Controller.Standard.RightGrip).to(rightHand.onGripPress);
|
|
||||||
Controller.enableMapping(CONTROLLER_MAPPING_NAME);
|
|
||||||
Script.update.connect(leftHand.onUpdate);
|
|
||||||
Script.update.connect(rightHand.onUpdate);
|
|
||||||
|
|
||||||
// Connect handController outputs to paintBrush objects.
|
|
||||||
leftBrush = paintBrush("left");
|
|
||||||
leftHand.setUp(leftBrush.startLine, leftBrush.drawLine, leftBrush.finishLine, leftBrush.eraseClosestLine);
|
|
||||||
rightBrush = paintBrush("right");
|
|
||||||
rightHand.setUp(rightBrush.startLine, rightBrush.drawLine, rightBrush.finishLine, rightBrush.eraseClosestLine);
|
|
||||||
|
|
||||||
// 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 tearDown() {
|
function tearDown() {
|
||||||
|
@ -398,32 +416,16 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.update.disconnect(leftHand.onUpdate);
|
if (isFingerPainting) {
|
||||||
Script.update.disconnect(rightHand.onUpdate);
|
isFingerPainting = false;
|
||||||
|
updateHandFunctions();
|
||||||
isFingerPainting = false;
|
disableProcessing();
|
||||||
updateHandFunctions();
|
}
|
||||||
|
|
||||||
button.clicked.disconnect(onButtonClicked);
|
|
||||||
tablet.removeButton(button);
|
|
||||||
|
|
||||||
tablet.screenChanged.disconnect(onTabletScreenChanged);
|
tablet.screenChanged.disconnect(onTabletScreenChanged);
|
||||||
|
|
||||||
Controller.disableMapping(CONTROLLER_MAPPING_NAME);
|
button.clicked.disconnect(onButtonClicked);
|
||||||
|
tablet.removeButton(button);
|
||||||
leftBrush.tearDown();
|
|
||||||
leftBrush = null;
|
|
||||||
leftHand.tearDown();
|
|
||||||
leftHand = null;
|
|
||||||
|
|
||||||
rightBrush.tearDown();
|
|
||||||
rightBrush = null;
|
|
||||||
rightHand.tearDown();
|
|
||||||
rightHand = null;
|
|
||||||
|
|
||||||
Messages.unsubscribe(HIFI_POINT_INDEX_MESSAGE_CHANNEL);
|
|
||||||
Messages.unsubscribe(HIFI_GRAB_DISABLE_MESSAGE_CHANNEL);
|
|
||||||
Messages.unssubscribe(HIFI_POINTER_DISABLE_MESSAGE_CHANNEL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setUp();
|
setUp();
|
||||||
|
|
Loading…
Reference in a new issue