Skip to content

Commit

Permalink
Merge branch 'story-tour-tool' into viewport-and-ui-flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
benptc committed Sep 16, 2024
2 parents ceab8bf + 1ae8567 commit 38c6fd9
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions libraries/objectDefaultFiles/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,9 @@
this.stopVirtualizerRecording = makeSendStub('stopVirtualizerRecording');
this.getScreenshotBase64 = makeSendStub('getScreenshotBase64');
this.captureSpatialSnapshot = makeSendStub('captureSpatialSnapshot');
this.requestCameraPerspective = makeSendStub('requestCameraPerspective');
this.requestSetCameraPerspective = makeSendStub('requestSetCameraPerspective');
this.requestTextInput = makeSendStub('requestTextInput');
this.openKeyboard = makeSendStub('openKeyboard');
this.closeKeyboard = makeSendStub('closeKeyboard');
this.onKeyboardClosed = makeSendStub('onKeyboardClosed');
Expand Down Expand Up @@ -1951,6 +1954,89 @@
});
};

/**
* Asks the client for the { position, direction } of the viewer in world coordinates
* @return {Promise<{position: number[], direction: number[]}>}
*/
this.requestCameraPerspective = function() {
postDataToParent({
requestCameraPerspective: true
});
return new Promise((resolve, reject) => {
spatialObject.messageCallBacks.requestCameraPerspectiveResult = function (msgContent) {
if (typeof msgContent.cameraPerspectiveData !== 'undefined') {
resolve(msgContent.cameraPerspectiveData);
delete spatialObject.messageCallBacks.requestCameraPerspectiveResult; // only trigger it once
}
if (typeof msgContent.cameraPerspectiveError !== 'undefined') {
reject(msgContent.cameraPerspectiveError);
delete spatialObject.messageCallBacks.requestCameraPerspectiveResult;
}
};
});
}

Check warning on line 1977 in libraries/objectDefaultFiles/object.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

Check warning on line 1977 in libraries/objectDefaultFiles/object.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Missing semicolon

/**
* Asks the parent client to move the virtual camera position/direction to the provided arrays.
* The client can choose to deny this request and provide an error, for example if multiple tools
* attempt to control the position, or the client is already following the position of another user.
* This is meant to pair with requestCameraPerspective, to save and restore camera perspectives.
* @param {number[]} position - in world coordinates
* @param {number[]} direction - in world coordinates
* @return {Promise<{success: boolean}>}
*/
this.requestSetCameraPerspective = function(position, direction) {
postDataToParent({
requestSetCameraPerspective: {
position: position,
direction: direction
}
});
return new Promise((resolve, reject) => {
spatialObject.messageCallBacks.requestSetCameraPerspectiveResult = function (msgContent) {
if (typeof msgContent.setCameraPerspectiveData !== 'undefined') {
resolve(msgContent.setCameraPerspectiveData);
delete spatialObject.messageCallBacks.requestSetCameraPerspectiveResult; // only trigger it once
}
if (typeof msgContent.setCameraPerspectiveError !== 'undefined') {
reject(msgContent.setCameraPerspectiveError);
delete spatialObject.messageCallBacks.requestSetCameraPerspectiveResult;
}
};
});
}

Check warning on line 2007 in libraries/objectDefaultFiles/object.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

Check warning on line 2007 in libraries/objectDefaultFiles/object.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Missing semicolon

/**
* Asks the parent client to present the user with a text input modal, and to resolve with the input text
* when the user clicks "confirm". Provides an error if they click "cancel" or if the client cannot present a
* text input modal for this tool right now (e.g. there is already another modal on the screen).
* This is useful to enable a native-like typing experience for necessary text inputs in a non-full2D iframe
* that is covered by the iframe cover div, without doing hacky focus/event manipulation within the tool iframe.
* @param {string} modalTitle - what text to display in the title of the input modal
* @param {string} modalDescription - what text to display in the input modal description/body
* @return {Promise<{string}>} - resolves directly with the text string
*/
this.requestTextInput = function(modalTitle, modalDescription) {
postDataToParent({
requestTextInput: {
modalTitle,
modalDescription
}
});
return new Promise((resolve, reject) => {
spatialObject.messageCallBacks.requestTextInputResult = function (msgContent) {
if (typeof msgContent.textInputData !== 'undefined') {
resolve(msgContent.textInputData);
delete spatialObject.messageCallBacks.requestTextInputResult; // only trigger it once
}
if (typeof msgContent.textInputError !== 'undefined') {
reject(msgContent.textInputError);
delete spatialObject.messageCallBacks.requestTextInputResult;
}
};
});
}

Check warning on line 2038 in libraries/objectDefaultFiles/object.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

Check warning on line 2038 in libraries/objectDefaultFiles/object.js

View workflow job for this annotation

GitHub Actions / build-insecure (18.x)

Missing semicolon

/**
* Programmatically opens device keyboard.
* This is preferred compared to directly opening keyboard by focusing on a frame element, because there is
Expand Down

0 comments on commit 38c6fd9

Please sign in to comment.