Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNAP App: support for Thumbstick of the right controller to capture picture and gif in HMD only. #1090

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 75 additions & 4 deletions scripts/system/snapshot.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//
// snapshot.js
//
// Created by David Kelly on 1 August 2016
// Copyright 2016 High Fidelity, Inc
// Created by David Kelly on August 1st, 2016
// Copyright 2016 High Fidelity, Inc.
// Copyright 2024 Overte e.V.
//
// Distributed under the Apache License, Version 2.0
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
Expand Down Expand Up @@ -373,6 +374,7 @@ function fillImageDataFromPrevious() {
errorPath: Script.resourcesPath() + 'snapshot/img/no-image.jpg'
});
}
setTakePhotoControllerMappingStatus(true);
}

function snapshotUploaded(isError, reply) {
Expand Down Expand Up @@ -474,6 +476,8 @@ function takeSnapshot() {
volume: 1.0
});
HMD.closeTablet();
setTakePhotoControllerMappingStatus(false);

var DOUBLE_RENDER_TIME_TO_MS = 2000; // If rendering is bogged down, allow double the render time to close the tablet.
Script.setTimeout(function () {
Window.takeSnapshot(false, includeAnimated, 1.91);
Expand Down Expand Up @@ -530,7 +534,11 @@ function stillSnapshotTaken(pathStillSnapshot, notify) {
Settings.setValue("previousStillSnapPath", pathStillSnapshot);

HMD.openTablet();

var includeAnimated = Settings.getValue("alsoTakeAnimatedSnapshot", true);
if (!includeAnimated) {
setTakePhotoControllerMappingStatus(true);
}

isDomainOpen(snapshotDomainID, function (canShare) {
snapshotOptions = {
containsGif: false,
Expand Down Expand Up @@ -614,6 +622,7 @@ function processingGifCompleted(pathAnimatedSnapshot) {
image_data: imageData
});
});
setTakePhotoControllerMappingStatus(true);
}
function maybeDeleteSnapshotStories() {
storyIDsToMaybeDelete.forEach(function (element, idx, array) {
Expand Down Expand Up @@ -703,20 +712,81 @@ function processRezPermissionChange(canRez) {
});
}

function setTakePhotoControllerMappingStatus(status) {
if (!takePhotoControllerMapping) {
return;
}
if (status) {
takePhotoControllerMapping.enable();
} else {
takePhotoControllerMapping.disable();
}
}

var takePhotoControllerMapping;
var takePhotoControllerMappingName = 'Hifi-SnapshotApp-Mapping-TakePhoto';
function registerTakePhotoControllerMapping() {
takePhotoControllerMapping = Controller.newMapping(takePhotoControllerMappingName);
if (controllerType === "OculusTouch") {
takePhotoControllerMapping.from(Controller.Standard.RS).to(function (value) {
if (value === 1.0) {
takeSnapshot();
}
return;
});
} else if (controllerType === "Vive") {
takePhotoControllerMapping.from(Controller.Standard.RightPrimaryThumb).to(function (value) {
if (value === 1.0) {
takeSnapshot();
}
return;
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be some sort of fallback for an unrecognized controller. At least log something, so that there's some clue as to what is wrong, but preferably an user-visible error message.

Also, the XBox controller has been used for VR, so it's also a possibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 things about it...
1- Fact: I simply bring the code from other camera app supporting the right thumb stick. This means that the same issue exists in those app too.

2- Xbox Controller: I don't have the hardware so I wouldn't be able to test it. I have honestly not consider support larger than that for that simple reason. If you have the "controllerType" string and which Controller.Standard.### it uses, then yes, I can add it.

3- Unrecognized controller: Currently, if a controller is not recognized, it simply do nothing. (No error, just not supported). The existence of this feature is not even written anywhere. This is not on the UI (a bit intentional). So people are currently find out accidentally or by learning from someone else. If a user has an unsupported controller, it won't tell him that the feature that he has never heard about before, is not working for him. He will be then as happy as all of us before this new implementation. In my opinion, It would be a bit mistake to advise directly the user that his controller is not taking change of this feature. It just cause the deception even before the need appears... It will just look clunkier as system for that user after that.
Instead, I would add a notice in the UI, but only if the controller is supporting it.

I didn't went there cause the cost in time was a bit too much for actually just a "shortcut".
Which means: changes in the Ui and what it needs between the app and the UI to hide/show the notice.
I can do it. Let me know what you think about this approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that adding a notice in the UI for supported controllers would be a really good idea.
Could you also add a TODO comment in the code telling to update this once OpenXR is merged?

}

var controllerType = "Other";
function registerButtonMappings() {
var VRDevices = Controller.getDeviceNames().toString();
if (VRDevices) {
if (VRDevices.indexOf("Vive") !== -1) {
controllerType = "Vive";
} else if (VRDevices.indexOf("OculusTouch") !== -1) {
controllerType = "OculusTouch";
} else {
return; // Neither Vive nor Touch detected
}
}

if (!takePhotoControllerMapping) {
registerTakePhotoControllerMapping();
}
}

function onHMDChanged(isHMDMode) {
registerButtonMappings();
}

function onClosingWindow () {
setTakePhotoControllerMappingStatus(false);
}

function startup() {
ui = new AppUi({
buttonName: "SNAP",
sortOrder: 5,
home: Script.resolvePath("html/SnapshotReview.html"),
onOpened: fillImageDataFromPrevious,
onMessage: onMessage
onMessage: onMessage,
onClosed: onClosingWindow
});

HMD.displayModeChanged.connect(onHMDChanged);
Entities.canRezChanged.connect(updatePrintPermissions);
Entities.canRezTmpChanged.connect(updatePrintPermissions);
GlobalServices.myUsernameChanged.connect(onUsernameChanged);
Snapshot.snapshotLocationSet.connect(snapshotLocationSet);
Window.snapshotShared.connect(snapshotUploaded);
registerButtonMappings();
}
startup();

Expand All @@ -726,6 +796,7 @@ function shutdown() {
GlobalServices.myUsernameChanged.disconnect(onUsernameChanged);
Entities.canRezChanged.disconnect(updatePrintPermissions);
Entities.canRezTmpChanged.disconnect(updatePrintPermissions);
HMD.displayModeChanged.disconnect(onHMDChanged);
}
Script.scriptEnding.connect(shutdown);

Expand Down
Loading