mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01: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,31 +12,160 @@
|
|||
var tablet,
|
||||
button,
|
||||
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() {
|
||||
var wasFingerPainting = isFingerPainting;
|
||||
|
||||
isFingerPainting = !isFingerPainting;
|
||||
button.editProperties({ isActive: isFingerPainting });
|
||||
|
||||
leftHand.setEnabled(isFingerPainting);
|
||||
rightHand.setEnabled(isFingerPainting);
|
||||
|
||||
if (wasFingerPainting) {
|
||||
leftBrush.cancelLine();
|
||||
rightBrush.cancelLine();
|
||||
}
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
if (tablet) {
|
||||
button = tablet.addButton({
|
||||
icon: "icons/tablet-icons/bubble-i.svg",
|
||||
activeIcon: "icons/tablet-icons/bubble-a.svg",
|
||||
text: BUTTON_NAME,
|
||||
isActive: isFingerPainting
|
||||
});
|
||||
button.clicked.connect(onButtonClicked);
|
||||
if (!tablet) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Tablet button.
|
||||
button = tablet.addButton({
|
||||
icon: "icons/tablet-icons/bubble-i.svg",
|
||||
activeIcon: "icons/tablet-icons/bubble-a.svg",
|
||||
text: BUTTON_NAME,
|
||||
isActive: isFingerPainting
|
||||
});
|
||||
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() {
|
||||
if (tablet) {
|
||||
button.clicked.disconnect(onButtonClicked);
|
||||
tablet.removeButton(button);
|
||||
if (!tablet) {
|
||||
return;
|
||||
}
|
||||
|
||||
button.clicked.disconnect(onButtonClicked);
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue