mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-24 01:24:00 +02:00
Controller and painting code framework
This commit is contained in:
parent
585691f71c
commit
bad57fa03f
1 changed files with 141 additions and 12 deletions
|
@ -12,16 +12,110 @@
|
||||||
var tablet,
|
var tablet,
|
||||||
button,
|
button,
|
||||||
BUTTON_NAME = "PAINT",
|
BUTTON_NAME = "PAINT",
|
||||||
isFingerPainting = false;
|
isFingerPainting = false,
|
||||||
|
leftHand,
|
||||||
|
rightHand,
|
||||||
|
leftBrush,
|
||||||
|
rightBrush,
|
||||||
|
CONTROLLER_MAPPING_NAME = "com.highfidelity.fingerPaint";
|
||||||
|
|
||||||
|
function paintBrush(name) {
|
||||||
|
// Paints in 3D.
|
||||||
|
|
||||||
|
var brushName = name,
|
||||||
|
BRUSH_COLOR = { red: 250, green: 0, blue: 0 },
|
||||||
|
ERASE_SEARCH_DISTANCE = 0.1; // m
|
||||||
|
|
||||||
|
function startLine(position, width) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawLine(position, width) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function finishLine(position, width) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelLine() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function eraseClosestLine(position) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
startLine: startLine,
|
||||||
|
drawLine: drawLine,
|
||||||
|
finishLine: finishLine,
|
||||||
|
cancelLine: cancelLine,
|
||||||
|
eraseClosestLine: eraseClosestLine,
|
||||||
|
tearDown: tearDown
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function handController(name) {
|
||||||
|
// Translates controller data into application events.
|
||||||
|
var handName = name,
|
||||||
|
triggerPressed, // Callback.
|
||||||
|
triggerPressing, // ""
|
||||||
|
triggerReleased, // ""
|
||||||
|
gripPressed, // ""
|
||||||
|
isEnabled = false;
|
||||||
|
|
||||||
|
function setEnabled(enabled) {
|
||||||
|
isEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTriggerPress(value) {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onGripPress(value) {
|
||||||
|
if (!isEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
setEnabled: setEnabled,
|
||||||
|
onTriggerPress: onTriggerPress,
|
||||||
|
onGripPress: onGripPress,
|
||||||
|
triggerPressed: triggerPressed,
|
||||||
|
triggerPressing: triggerPressing,
|
||||||
|
triggerReleased: triggerReleased,
|
||||||
|
gripPressed: gripPressed,
|
||||||
|
tearDown: tearDown
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function onButtonClicked() {
|
function onButtonClicked() {
|
||||||
|
var wasFingerPainting = isFingerPainting;
|
||||||
|
|
||||||
isFingerPainting = !isFingerPainting;
|
isFingerPainting = !isFingerPainting;
|
||||||
button.editProperties({ isActive: isFingerPainting });
|
button.editProperties({ isActive: isFingerPainting });
|
||||||
|
|
||||||
|
leftHand.setEnabled(isFingerPainting);
|
||||||
|
rightHand.setEnabled(isFingerPainting);
|
||||||
|
|
||||||
|
if (wasFingerPainting) {
|
||||||
|
leftBrush.cancelLine();
|
||||||
|
rightBrush.cancelLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
if (tablet) {
|
if (!tablet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tablet button.
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
icon: "icons/tablet-icons/bubble-i.svg",
|
icon: "icons/tablet-icons/bubble-i.svg",
|
||||||
activeIcon: "icons/tablet-icons/bubble-a.svg",
|
activeIcon: "icons/tablet-icons/bubble-a.svg",
|
||||||
|
@ -29,14 +123,49 @@
|
||||||
isActive: isFingerPainting
|
isActive: isFingerPainting
|
||||||
});
|
});
|
||||||
button.clicked.connect(onButtonClicked);
|
button.clicked.connect(onButtonClicked);
|
||||||
}
|
|
||||||
|
// 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.triggerPressed = leftBrush.startLine;
|
||||||
|
leftHand.triggerPressing = leftBrush.drawLine;
|
||||||
|
leftHand.trigerRelease = leftBrush.finishLine;
|
||||||
|
leftHand.gripPressed = leftBrush.eraseLine;
|
||||||
|
rightBrush = paintBrush("right");
|
||||||
|
rightHand.triggerPressed = rightBrush.startLine;
|
||||||
|
rightHand.triggerPressing = rightBrush.drawLine;
|
||||||
|
rightHand.trigerRelease = rightBrush.finishLine;
|
||||||
|
rightHand.gripPressed = rightBrush.eraseLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
if (tablet) {
|
if (!tablet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
button.clicked.disconnect(onButtonClicked);
|
button.clicked.disconnect(onButtonClicked);
|
||||||
tablet.removeButton(button);
|
tablet.removeButton(button);
|
||||||
}
|
|
||||||
|
Controller.disableMapping(CONTROLLER_MAPPING_NAME);
|
||||||
|
|
||||||
|
leftBrush.tearDown();
|
||||||
|
leftBrush = null;
|
||||||
|
leftHand.tearDown();
|
||||||
|
leftHand = null;
|
||||||
|
|
||||||
|
rightBrush.tearDown();
|
||||||
|
rightBrush = null;
|
||||||
|
rightHand.tearDown();
|
||||||
|
rightHand = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setUp();
|
setUp();
|
||||||
|
|
Loading…
Reference in a new issue