mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 13:00:12 +02:00
Merge branch 'spectator-camera' of https://github.com/highfidelity/hifi into spectatorCamera_setInterval
This commit is contained in:
commit
604bb58987
2 changed files with 74 additions and 162 deletions
|
@ -39,7 +39,7 @@ void SecondaryCameraRenderTaskConfig::resetSizeSpectatorCamera(int width, int he
|
|||
resetSize(width, height);
|
||||
}
|
||||
|
||||
class BeginSecondaryCameraFrame { // Changes renderContext for our framebuffer and and view.
|
||||
class BeginSecondaryCameraFrame { // Changes renderContext for our framebuffer and view.
|
||||
glm::vec3 _position{};
|
||||
glm::quat _orientation{};
|
||||
float _vFoV{};
|
||||
|
|
|
@ -14,43 +14,36 @@
|
|||
|
||||
(function () { // BEGIN LOCAL_SCOPE
|
||||
|
||||
//
|
||||
// FUNCTION VAR DECLARATIONS
|
||||
//
|
||||
var sendToQml, addOrRemoveButton, onTabletScreenChanged, fromQml,
|
||||
onTabletButtonClicked, wireEventBridge, startup, shutdown, registerButtonMappings;
|
||||
|
||||
//
|
||||
// Function Name: inFrontOf()
|
||||
//
|
||||
// Description:
|
||||
// Spectator camera utility functions and variables.
|
||||
//
|
||||
// -Returns the position in front of the given "position" argument, where the forward vector is based off
|
||||
// the "orientation" argument and the amount in front is based off the "distance" argument.
|
||||
function inFrontOf(distance, position, orientation) {
|
||||
return Vec3.sum(position || MyAvatar.position,
|
||||
Vec3.multiply(distance, Quat.getForward(orientation || MyAvatar.orientation)));
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: updateRenderFromCamera()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// spectatorFrameRenderConfig: The render configuration of the spectator camera
|
||||
// render job. Controls size.
|
||||
// beginSpectatorFrameRenderConfig: The render configuration of the spectator camera
|
||||
// render job. Controls position and orientation.
|
||||
// viewFinderOverlay: The in-world overlay that displays the spectator camera's view.
|
||||
// camera: The in-world entity that corresponds to the spectator camera.
|
||||
// cameraIsDynamic: "false" for now while we figure out why dynamic, parented overlays
|
||||
// drift with respect to their parent
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// The update function for the spectator camera. Modifies the camera's position
|
||||
// and orientation.
|
||||
// -The update function for the spectator camera. Modifies the camera's position
|
||||
// and orientation.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -spectatorFrameRenderConfig: The render configuration of the spectator camera
|
||||
// render job. It controls the rendered texture size of the spectator camera.
|
||||
// -beginSpectatorFrameRenderConfig: The render configuration of the spectator camera
|
||||
// render job. It controls the orientation and position of the secondary camera whose viewport is rendered to
|
||||
// the texture.
|
||||
// -viewFinderOverlay: The in-world overlay that displays the spectator camera's view.
|
||||
// -camera: The in-world entity that corresponds to the spectator camera.
|
||||
// -cameraIsDynamic: "false" for now while we figure out why dynamic, parented overlays
|
||||
// drift with respect to their parent.
|
||||
var spectatorFrameRenderConfig = Render.getConfig("SecondaryCameraFrame");
|
||||
var beginSpectatorFrameRenderConfig = Render.getConfig("BeginSecondaryCamera");
|
||||
var viewFinderOverlay = false;
|
||||
|
@ -62,36 +55,33 @@
|
|||
beginSpectatorFrameRenderConfig.position = cameraData.position;
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: spectatorCameraOn()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// vFoV: The vertical field of view of the spectator camera
|
||||
// nearClipPlaneDistance: The near clip plane distance of the spectator camera (aka "camera")
|
||||
// farClipPlaneDistance: The far clip plane distance of the spectator camera
|
||||
// cameraRotation: The rotation of the spectator camera
|
||||
// cameraPosition: The position of the spectator camera
|
||||
// glassPaneWidth: The width of the glass pane above the spectator camera that holds the viewFinderOverlay
|
||||
// viewFinderOverlayDim: The x, y, and z dimensions of the viewFinderOverlay
|
||||
// cameraUpdateInterval: Used when setting Script.setInterval()
|
||||
// CAMERA_UPDATE_INTERVAL_MS: Defines the time between calls to updateRenderFromCamera()
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// Call this function to set up the spectator camera and
|
||||
// spawn the camera entity.
|
||||
// -Call this function to set up the spectator camera and
|
||||
// spawn the camera entity.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -vFoV: The vertical field of view of the spectator camera.
|
||||
// -nearClipPlaneDistance: The near clip plane distance of the spectator camera (aka "camera").
|
||||
// -farClipPlaneDistance: The far clip plane distance of the spectator camera.
|
||||
// -cameraRotation: The rotation of the spectator camera.
|
||||
// -cameraPosition: The position of the spectator camera.
|
||||
// -glassPaneWidth: The width of the glass pane above the spectator camera that holds the viewFinderOverlay.
|
||||
// -viewFinderOverlayDim: The x, y, and z dimensions of the viewFinderOverlay.
|
||||
// -camera: The camera model which is grabbable.
|
||||
// -viewFinderOverlay: The preview of what the spectator camera is viewing, placed inside the glass pane.
|
||||
// -cameraUpdateInterval: Used when setting Script.setInterval()
|
||||
// -CAMERA_UPDATE_INTERVAL_MS: Defines the time between calls to updateRenderFromCamera()
|
||||
var vFoV = 45.0;
|
||||
var nearClipPlaneDistance = 0.1;
|
||||
var farClipPlaneDistance = 100.0;
|
||||
var cameraRotation;
|
||||
var cameraPosition;
|
||||
//The negative y dimension for viewFinderOverlay is necessary for now due to the way Image3DOverlay
|
||||
// draws textures, but should be looked into at some point. Also the z dimension shouldn't affect
|
||||
// the overlay since it is an Image3DOverlay so it is set to 0
|
||||
var glassPaneWidth = 0.16;
|
||||
// The negative y dimension for viewFinderOverlay is necessary for now due to the way Image3DOverlay
|
||||
// draws textures, but should be looked into at some point. Also the z dimension shouldn't affect
|
||||
// the overlay since it is an Image3DOverlay so it is set to 0.
|
||||
var viewFinderOverlayDim = { x: glassPaneWidth, y: -glassPaneWidth, z: 0 };
|
||||
var cameraUpdateInterval;
|
||||
var CAMERA_UPDATE_INTERVAL_MS = 11; // Result of (1000 (ms/s)) / (90 (hz)) rounded down
|
||||
|
@ -122,24 +112,15 @@
|
|||
"type": "Model",
|
||||
"userData": "{\"grabbableKey\":{\"grabbable\":true}}"
|
||||
}, true);
|
||||
// This image3d overlay acts as the camera's preview screen.
|
||||
updateOverlay();
|
||||
setDisplay(monitorShowsCameraView);
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: spectatorCameraOff()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// None
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// Call this function to shut down the spectator camera and
|
||||
// destroy the camera entity.
|
||||
//
|
||||
// -Call this function to shut down the spectator camera and
|
||||
// destroy the camera entity.
|
||||
function spectatorCameraOff() {
|
||||
spectatorFrameRenderConfig.enabled = beginSpectatorFrameRenderConfig.enabled = false;
|
||||
cameraUpdateInterval = Script.clearInterval(cameraUpdateInterval);
|
||||
|
@ -154,21 +135,17 @@
|
|||
setDisplay(monitorShowsCameraView);
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: addOrRemoveButton()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// button: The tablet button.
|
||||
// buttonName: The name of the button.
|
||||
// showInDesktop: Set to "true" to show the "SPECTATOR" app in desktop mode
|
||||
//
|
||||
// Arguments:
|
||||
// isShuttingDown: Set to "true" if you're calling this function upon script shutdown
|
||||
// isHMDMode: "true" if user is in HMD; false otherwise
|
||||
//
|
||||
// Description:
|
||||
// Used to add or remove the "SPECTATOR" app button from the HUD/tablet
|
||||
// -Used to add or remove the "SPECTATOR" app button from the HUD/tablet. Set the "isShuttingDown" argument
|
||||
// to true if you're calling this function upon script shutdown. Set the "isHMDmode" to true if the user is
|
||||
// in HMD; otherwise set to false.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -button: The tablet button.
|
||||
// -buttonName: The name of the button.
|
||||
// -showInDesktop: Set to "true" to show the "SPECTATOR" app in desktop mode.
|
||||
var button = false;
|
||||
var buttonName = "SPECTATOR";
|
||||
var showSpectatorInDesktop = true;
|
||||
|
@ -185,7 +162,7 @@
|
|||
button.clicked.connect(onTabletButtonClicked);
|
||||
}
|
||||
} else if (button) {
|
||||
if ((!showSpectatorInDesktop || isShuttingDown)) {
|
||||
if ((!showSpectatorInDesktop || isShuttingDown) && !isHMDMode) {
|
||||
button.clicked.disconnect(onTabletButtonClicked);
|
||||
tablet.removeButton(button);
|
||||
button = false;
|
||||
|
@ -195,18 +172,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: startup()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// tablet: The tablet instance to be modified.
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// startup() will be called when the script is loaded.
|
||||
// -startup() will be called when the script is loaded.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -tablet: The tablet instance to be modified.
|
||||
var tablet = null;
|
||||
function startup() {
|
||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
|
@ -221,18 +193,14 @@
|
|||
registerButtonMappings();
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: wireEventBridge()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// hasEventBridge: true/false depending on whether we've already connected the event bridge
|
||||
//
|
||||
// Arguments:
|
||||
// on: Enable or disable the event bridge
|
||||
//
|
||||
// Description:
|
||||
// Used to connect/disconnect the script's response to the tablet's "fromQml" signal.
|
||||
// -Used to connect/disconnect the script's response to the tablet's "fromQml" signal. Set the "on" argument to enable or
|
||||
// disable to event bridge.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -hasEventBridge: true/false depending on whether we've already connected the event bridge.
|
||||
var hasEventBridge = false;
|
||||
function wireEventBridge(on) {
|
||||
if (!tablet) {
|
||||
|
@ -293,22 +261,18 @@
|
|||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: resizeViewFinderOverlay()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// glassPaneRatio: The aspect ratio of the glass pane, currently set as a 16:9 aspect ratio (change if model changes)
|
||||
// verticalScale: The amount the viewFinderOverlay should be scaled if the window size is vertical
|
||||
// squareScale: The amount the viewFinderOverlay should be scaled if the window size is not vertical but is more square than the
|
||||
// glass pane's aspect ratio
|
||||
//
|
||||
// Arguments:
|
||||
// geometryChanged: The signal argument that gives information on how the window changed, including x, y, width, and height
|
||||
//
|
||||
// Description:
|
||||
// A function called when the window is moved/resized, which changes the viewFinderOverlay's texture and dimensions to be
|
||||
// appropriately altered to fit inside the glass pane while not distorting the texture
|
||||
// -A function called when the window is moved/resized, which changes the viewFinderOverlay's texture and dimensions to be
|
||||
// appropriately altered to fit inside the glass pane while not distorting the texture. The "geometryChanged" argument gives information
|
||||
// on how the window changed, including x, y, width, and height.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -glassPaneRatio: The aspect ratio of the glass pane, currently set as a 16:9 aspect ratio (change if model changes).
|
||||
// -verticalScale: The amount the viewFinderOverlay should be scaled if the window size is vertical.
|
||||
// -squareScale: The amount the viewFinderOverlay should be scaled if the window size is not vertical but is more square than the
|
||||
// glass pane's aspect ratio.
|
||||
function resizeViewFinderOverlay(geometryChanged) {
|
||||
var glassPaneRatio = 16 / 9;
|
||||
var verticalScale = 1 / glassPaneRatio;
|
||||
|
@ -344,20 +308,15 @@
|
|||
Settings.setValue('spectatorCamera/switchViewFromController', setting);
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: registerButtonMappings()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// controllerMappingName: The name of the controller mapping
|
||||
// controllerMapping: The controller mapping itself
|
||||
// controllerType: "OculusTouch", "Vive", "Other"
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// Updates controller button mappings for Spectator Camera.
|
||||
// -Updates controller button mappings for Spectator Camera.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -controllerMappingName: The name of the controller mapping.
|
||||
// -controllerMapping: The controller mapping itself.
|
||||
// -controllerType: "OculusTouch", "Vive", "Other".
|
||||
var controllerMappingName;
|
||||
var controllerMapping;
|
||||
var controllerType = "Other";
|
||||
|
@ -390,19 +349,14 @@
|
|||
sendToQml({ method: 'updateControllerMappingCheckbox', setting: switchViewFromController, controller: controllerType });
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: onTabletButtonClicked()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// SPECTATOR_CAMERA_QML_SOURCE: The path to the SpectatorCamera QML
|
||||
// onSpectatorCameraScreen: true/false depending on whether we're looking at the spectator camera app
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// Fired when the Spectator Camera app button is pressed.
|
||||
// -Fired when the Spectator Camera app button is pressed.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -SPECTATOR_CAMERA_QML_SOURCE: The path to the SpectatorCamera QML
|
||||
// -onSpectatorCameraScreen: true/false depending on whether we're looking at the spectator camera app.
|
||||
var SPECTATOR_CAMERA_QML_SOURCE = "../SpectatorCamera.qml";
|
||||
var onSpectatorCameraScreen = false;
|
||||
function onTabletButtonClicked() {
|
||||
|
@ -422,19 +376,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: onTabletScreenChanged()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// None
|
||||
//
|
||||
// Arguments:
|
||||
// type: "Home", "Web", "Menu", "QML", "Closed"
|
||||
// url: Only valid for Web and QML.
|
||||
//
|
||||
// Description:
|
||||
// Called when the TabletScriptingInterface::screenChanged() signal is emitted.
|
||||
//
|
||||
// -Called when the TabletScriptingInterface::screenChanged() signal is emitted. The "type" argument can be either the string
|
||||
// value of "Home", "Web", "Menu", "QML", or "Closed". The "url" argument is only valid for Web and QML.
|
||||
function onTabletScreenChanged(type, url) {
|
||||
onSpectatorCameraScreen = (type === "QML" && url === SPECTATOR_CAMERA_QML_SOURCE);
|
||||
wireEventBridge(onSpectatorCameraScreen);
|
||||
|
@ -444,36 +390,20 @@
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: sendToQml()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// None
|
||||
//
|
||||
// Arguments:
|
||||
// message: The message to send to the SpectatorCamera QML.
|
||||
// Messages are in format "{method, params}", like json-rpc. See also fromQml().
|
||||
//
|
||||
// Description:
|
||||
// Use this function to send a message to the QML (i.e. to change appearances).
|
||||
//
|
||||
// -Use this function to send a message to the QML (i.e. to change appearances). The "message" argument is what is sent to
|
||||
// SpectatorCamera QML in the format "{method, params}", like json-rpc. See also fromQml().
|
||||
function sendToQml(message) {
|
||||
tablet.sendToQml(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: fromQml()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// None
|
||||
//
|
||||
// Arguments:
|
||||
// message: The message sent from the SpectatorCamera QML.
|
||||
// Messages are in format "{method, params}", like json-rpc. See also sendToQml().
|
||||
//
|
||||
// Description:
|
||||
// Called when a message is received from SpectatorCamera.qml.
|
||||
//
|
||||
// -Called when a message is received from SpectatorCamera.qml. The "message" argument is what is sent from the SpectatorCamera QML
|
||||
// in the format "{method, params}", like json-rpc. See also sendToQml().
|
||||
function fromQml(message) {
|
||||
switch (message.method) {
|
||||
case 'spectatorCameraOn':
|
||||
|
@ -493,18 +423,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: onHMDChanged()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// None
|
||||
//
|
||||
// Arguments:
|
||||
// isHMDMode: "true" if HMD is on; "false" otherwise
|
||||
//
|
||||
// Description:
|
||||
// Called from C++ when HMD mode is changed
|
||||
//
|
||||
// -Called from C++ when HMD mode is changed. The argument "isHMDMode" should be true if HMD is on; false otherwise.
|
||||
function onHMDChanged(isHMDMode) {
|
||||
setDisplay(monitorShowsCameraView);
|
||||
addOrRemoveButton(false, isHMDMode);
|
||||
|
@ -513,18 +435,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Function Name: shutdown()
|
||||
//
|
||||
// Relevant Variables:
|
||||
// None
|
||||
//
|
||||
// Arguments:
|
||||
// None
|
||||
//
|
||||
// Description:
|
||||
// shutdown() will be called when the script ends (i.e. is stopped).
|
||||
//
|
||||
// -shutdown() will be called when the script ends (i.e. is stopped).
|
||||
function shutdown() {
|
||||
spectatorCameraOff();
|
||||
Window.domainChanged.disconnect(spectatorCameraOff);
|
||||
|
@ -541,9 +455,7 @@
|
|||
controllerMapping.disable();
|
||||
}
|
||||
|
||||
//
|
||||
// These functions will be called when the script is loaded.
|
||||
//
|
||||
startup();
|
||||
Script.scriptEnding.connect(shutdown);
|
||||
|
||||
|
|
Loading…
Reference in a new issue