From fcc1f928a125be4371b797378fd7e11cc5d577b4 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 10:58:49 +1300 Subject: [PATCH 01/13] Lint --- scripts/system/inspect.js | 51 ++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 18b26ab709..233517dd64 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -160,7 +160,7 @@ function restoreCameraState() { } function handleModes() { - var newMode = (mode == noMode) ? noMode : detachedMode; + var newMode = (mode === noMode) ? noMode : detachedMode; if (alt) { if (control) { if (shift) { @@ -174,32 +174,32 @@ function handleModes() { } // if entering detachMode - if (newMode == detachedMode && mode != detachedMode) { + if (newMode === detachedMode && mode !== detachedMode) { avatarPosition = MyAvatar.position; avatarOrientation = MyAvatar.orientation; } // if leaving detachMode - if (mode == detachedMode && newMode == detachedMode && - (avatarPosition.x != MyAvatar.position.x || - avatarPosition.y != MyAvatar.position.y || - avatarPosition.z != MyAvatar.position.z || - avatarOrientation.x != MyAvatar.orientation.x || - avatarOrientation.y != MyAvatar.orientation.y || - avatarOrientation.z != MyAvatar.orientation.z || - avatarOrientation.w != MyAvatar.orientation.w)) { + if (mode === detachedMode && newMode === detachedMode && + (avatarPosition.x !== MyAvatar.position.x || + avatarPosition.y !== MyAvatar.position.y || + avatarPosition.z !== MyAvatar.position.z || + avatarOrientation.x !== MyAvatar.orientation.x || + avatarOrientation.y !== MyAvatar.orientation.y || + avatarOrientation.z !== MyAvatar.orientation.z || + avatarOrientation.w !== MyAvatar.orientation.w)) { newMode = noMode; } - if (mode == noMode && newMode != noMode && Camera.mode == "independent") { + if (mode === noMode && newMode !== noMode && Camera.mode === "independent") { newMode = noMode; } // if leaving noMode - if (mode == noMode && newMode != noMode) { + if (mode === noMode && newMode !== noMode) { saveCameraState(); } // if entering noMode - if (newMode == noMode && mode != noMode) { + if (newMode === noMode && mode !== noMode) { restoreCameraState(); } @@ -209,15 +209,15 @@ function handleModes() { function keyPressEvent(event) { var changed = false; - if (event.text == "ALT") { + if (event.text === "ALT") { alt = true; changed = true; } - if (event.text == "CONTROL") { + if (event.text === "CONTROL") { control = true; changed = true; } - if (event.text == "SHIFT") { + if (event.text === "SHIFT") { shift = true; changed = true; } @@ -230,17 +230,17 @@ function keyPressEvent(event) { function keyReleaseEvent(event) { var changed = false; - if (event.text == "ALT") { + if (event.text === "ALT") { alt = false; changed = true; mode = noMode; restoreCameraState(); } - if (event.text == "CONTROL") { + if (event.text === "CONTROL") { control = false; changed = true; } - if (event.text == "SHIFT") { + if (event.text === "SHIFT") { shift = false; changed = true; } @@ -293,14 +293,14 @@ function mouseReleaseEvent(event) { } function mouseMoveEvent(event) { - if (isActive && mode != noMode && !rotatingTowardsTarget) { - if (mode == radialMode) { + if (isActive && mode !== noMode && !rotatingTowardsTarget) { + if (mode === radialMode) { handleRadialMode(event.x - mouseLastX, event.y - mouseLastY); } - if (mode == orbitMode) { + if (mode === orbitMode) { handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY); } - if (mode == panningMode) { + if (mode === panningMode) { handlePanMode(event.x - mouseLastX, event.y - mouseLastY); } } @@ -316,12 +316,13 @@ function update() { } function rotateTowardsTarget() { - var newOrientation = Quat.mix(Camera.getOrientation(), targetCamOrientation, 0.1); + var MIX_FACTOR = 0.1; + var newOrientation = Quat.mix(Camera.getOrientation(), targetCamOrientation, MIX_FACTOR); Camera.setOrientation(newOrientation); } function scriptEnding() { - if (mode != noMode) { + if (mode !== noMode) { restoreCameraState(); } } From ac34d49c1b50e8936e638bfeca9ac442b76a8078 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:04:23 +1300 Subject: [PATCH 02/13] Leave camera where it is after releasing Alt key --- scripts/system/inspect.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 233517dd64..b7ed987acd 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -233,8 +233,6 @@ function keyReleaseEvent(event) { if (event.text === "ALT") { alt = false; changed = true; - mode = noMode; - restoreCameraState(); } if (event.text === "CONTROL") { control = false; From 81e1dd4d6a1babdf6649a9a55fb6aa02043a1b96 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:10:10 +1300 Subject: [PATCH 03/13] Exit inspect mode when press Esc or move avatar --- scripts/system/inspect.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index b7ed987acd..90a84c514b 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -222,6 +222,12 @@ function keyPressEvent(event) { changed = true; } + if (mode !== noMode && !alt && !control && !shift && /^ESC|LEFT|RIGHT|UP|DOWN|[wasdWASD]$/.test(event.text)) { + mode = noMode; + restoreCameraState(); + changed = true; + } + if (changed) { handleModes(); } From a1056f34ed540a9ad9b6ff4f3fb21a3ccd436741 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:14:12 +1300 Subject: [PATCH 04/13] Cope with slight avatar position and orientation jitter when stationary --- scripts/system/inspect.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 90a84c514b..c84cdef5c3 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -25,6 +25,9 @@ var ALTITUDE_RATE = 200.0; var RADIUS_RATE = 1.0 / 100.0; var PAN_RATE = 250.0; +var AVATAR_POSITION_SLOP = 0.1; +var AVATAR_ROTATION_SLOP = 0.09; // 5 degrees + var Y_AXIS = { x: 0, y: 1, @@ -179,14 +182,10 @@ function handleModes() { avatarOrientation = MyAvatar.orientation; } // if leaving detachMode - if (mode === detachedMode && newMode === detachedMode && - (avatarPosition.x !== MyAvatar.position.x || - avatarPosition.y !== MyAvatar.position.y || - avatarPosition.z !== MyAvatar.position.z || - avatarOrientation.x !== MyAvatar.orientation.x || - avatarOrientation.y !== MyAvatar.orientation.y || - avatarOrientation.z !== MyAvatar.orientation.z || - avatarOrientation.w !== MyAvatar.orientation.w)) { + if (mode === detachedMode && newMode === detachedMode && ( + Vec3.length(Vec3.subtract(avatarPosition, MyAvatar.position)) > AVATAR_POSITION_SLOP + || Vec3.length(Vec3.subtract(Quat.getFront(avatarOrientation), Quat.getFront(MyAvatar.orientation))) + > AVATAR_ROTATION_SLOP)) { newMode = noMode; } From 31b76a0a22d1200439cccef3383b4f926f0dddaf Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:25:39 +1300 Subject: [PATCH 05/13] Don't go "away" when press Esc key while inspecting --- scripts/system/inspect.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index c84cdef5c3..30f9e1c2df 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -203,6 +203,10 @@ function handleModes() { } mode = newMode; + + // Don't go "away" when press Esc key while inspecting. + var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; + Messages.sendMessage(CHANNEL_AWAY_ENABLE, mode === noMode ? "enable" : "disable" , true); } function keyPressEvent(event) { From 6749239e4e87061c95922b143af506fe6101c311 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:27:39 +1300 Subject: [PATCH 06/13] Reduce the duration of the initial look-at time --- scripts/system/inspect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 30f9e1c2df..64c46addb5 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -39,7 +39,7 @@ var X_AXIS = { z: 0 }; -var LOOK_AT_TIME = 500; +var LOOK_AT_TIME = 100; // ms var alt = false; var shift = false; From 3857fa1a4d7858f9dd70a4ee98d2fa566cfbd967 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:35:53 +1300 Subject: [PATCH 07/13] Restore "away" behavior when restart script --- scripts/system/inspect.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 64c46addb5..0e4be4320f 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -147,6 +147,11 @@ function handlePanMode(dx, dy) { Camera.setOrientation(orientationOf(vector)); } +function enableAway(enable) { + var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; + Messages.sendMessage(CHANNEL_AWAY_ENABLE, enable ? "enable" : "disable", true); +} + function saveCameraState() { oldMode = Camera.mode; oldPosition = Camera.getPosition(); @@ -204,9 +209,7 @@ function handleModes() { mode = newMode; - // Don't go "away" when press Esc key while inspecting. - var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; - Messages.sendMessage(CHANNEL_AWAY_ENABLE, mode === noMode ? "enable" : "disable" , true); + enableAway(mode === noMode); } function keyPressEvent(event) { @@ -331,6 +334,7 @@ function rotateTowardsTarget() { function scriptEnding() { if (mode !== noMode) { restoreCameraState(); + enableAway(true); } } From 32848ef8c6775f7a115bdaaf8811e0d50ec20009 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 6 Jan 2020 11:41:05 +1300 Subject: [PATCH 08/13] Update description of operation --- scripts/system/inspect.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 0e4be4320f..fc37d70331 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -5,13 +5,16 @@ // Created by Clément Brisset on March 20, 2014 // Copyright 2014 High Fidelity, Inc. // -// Allows you to inspect non moving objects (Voxels or Avatars) using Atl, Control (Command on Mac) and Shift +// Enables you to inspect entities and avatars using Alt and key combinations: +// - Alt + mouse up/down zooms in/out. +// - Alt + mouse left/right orbits left/right. +// - Alt + Ctrl + mouse up/down/left/right: orbits over / under / left / right. +// - Alt + Ctrl + Shift + mouse up/down/left/right: pans down / up / right / left. // -// radial mode = hold ALT -// orbit mode = hold ALT + CONTROL -// pan mode = hold ALT + CONTROL + SHIFT -// Once you are in a mode left click on the object to inspect and hold the click -// Dragging the mouse will move your camera according to the mode you are in. +// Your camera stays where it is when you release the Alt key, enabling you to Alt + left - click on another entity or +// avatar to further move your view. +// +// Press Esc or move your avatar to revert back to your default view. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html From 37b7a9c5f45d393d071cc76f9471d12691de4707 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 12 Jan 2020 16:26:23 +1300 Subject: [PATCH 09/13] Use Picks API and orbit about point in space if no intersection --- scripts/system/inspect.js | 59 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index fc37d70331..980444d247 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -59,6 +59,13 @@ var detachedMode = 4; var mode = noMode; +var pick = Picks.createPick(PickType.Ray, { + filter: Picks.PICK_DOMAIN_ENTITIES | Picks.PICK_AVATAR_ENTITIES | Picks.PICK_AVATARS + | Picks.PICK_INCLUDE_COLLIDABLE | Picks.PICK_INCLUDE_NONCOLLIDABLE | Picks.PICK_PRECISE, + joint: "Mouse", + enabled: false +}); + var mouseLastX = 0; var mouseLastY = 0; @@ -221,6 +228,7 @@ function keyPressEvent(event) { if (event.text === "ALT") { alt = true; changed = true; + Picks.enablePick(pick); } if (event.text === "CONTROL") { control = true; @@ -248,6 +256,7 @@ function keyReleaseEvent(event) { if (event.text === "ALT") { alt = false; changed = true; + Picks.disablePick(pick); } if (event.text === "CONTROL") { control = false; @@ -268,34 +277,32 @@ function mousePressEvent(event) { mouseLastX = event.x; mouseLastY = event.y; - // Compute trajectories related values - var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); - var modelIntersection = Entities.findRayIntersection(pickRay, true); - var avatarIntersection = AvatarList.findRayIntersection(pickRay); + position = Camera.position; - position = Camera.getPosition(); - - if (avatarIntersection.intersects || (modelIntersection.intersects && modelIntersection.accurate)) { - if (avatarIntersection.intersects) { - center = avatarIntersection.intersection; - } else { - center = modelIntersection.intersection; - } - // We've selected our target, now orbit towards it automatically - rotatingTowardsTarget = true; - // calculate our target cam rotation - Script.setTimeout(function () { - rotatingTowardsTarget = false; - }, LOOK_AT_TIME); - - vector = Vec3.subtract(position, center); - targetCamOrientation = orientationOf(vector); - radius = Vec3.length(vector); - azimuth = Math.atan2(vector.z, vector.x); - altitude = Math.asin(vector.y / Vec3.length(vector)); - - isActive = true; + var pickResult = Picks.getPrevPickResult(pick); + if (pickResult.intersects) { + // Orbit about intersection. + center = pickResult.intersection; + } else { + // Orbit about point in space. + var ORBIT_DISTANCE = 10.0; + center = Vec3.sum(position, Vec3.multiply(ORBIT_DISTANCE, pickResult.searchRay.direction)); } + + // We've selected our target, now orbit towards it automatically + rotatingTowardsTarget = true; + // calculate our target cam rotation + Script.setTimeout(function () { + rotatingTowardsTarget = false; + }, LOOK_AT_TIME); + + vector = Vec3.subtract(position, center); + targetCamOrientation = orientationOf(vector); + radius = Vec3.length(vector); + azimuth = Math.atan2(vector.z, vector.x); + altitude = Math.asin(vector.y / Vec3.length(vector)); + + isActive = true; } } From 4ebf4e5cfd5c0e1eed9751a0c46bb0fcd8e06dd2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 12 Jan 2020 16:27:03 +1300 Subject: [PATCH 10/13] Ignore invisible --- scripts/system/inspect.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 980444d247..db98211d9f 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -60,7 +60,7 @@ var detachedMode = 4; var mode = noMode; var pick = Picks.createPick(PickType.Ray, { - filter: Picks.PICK_DOMAIN_ENTITIES | Picks.PICK_AVATAR_ENTITIES | Picks.PICK_AVATARS + filter: Picks.PICK_DOMAIN_ENTITIES | Picks.PICK_AVATAR_ENTITIES | Picks.PICK_AVATARS | Picks.INCLUDE_VISIBLE | Picks.PICK_INCLUDE_COLLIDABLE | Picks.PICK_INCLUDE_NONCOLLIDABLE | Picks.PICK_PRECISE, joint: "Mouse", enabled: false From 2abbdfbfe9742f4fc9d88126c751cf0d6d989785 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 12 Jan 2020 16:32:20 +1300 Subject: [PATCH 11/13] Fix unnecessary "away" enabling and disabling --- scripts/system/inspect.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index db98211d9f..6f21e7e8ba 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -59,6 +59,8 @@ var detachedMode = 4; var mode = noMode; +var isAwayEnabled = true; + var pick = Picks.createPick(PickType.Ray, { filter: Picks.PICK_DOMAIN_ENTITIES | Picks.PICK_AVATAR_ENTITIES | Picks.PICK_AVATARS | Picks.INCLUDE_VISIBLE | Picks.PICK_INCLUDE_COLLIDABLE | Picks.PICK_INCLUDE_NONCOLLIDABLE | Picks.PICK_PRECISE, @@ -158,8 +160,11 @@ function handlePanMode(dx, dy) { } function enableAway(enable) { - var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; - Messages.sendMessage(CHANNEL_AWAY_ENABLE, enable ? "enable" : "disable", true); + if (enable !== isAwayEnabled) { + var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; + Messages.sendMessage(CHANNEL_AWAY_ENABLE, enable ? "enable" : "disable", true); + } + isAwayEnabled = enable; } function saveCameraState() { From 316abaeedc743110335a98ab49bcd901f70f493b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 12 Jan 2020 17:37:58 +1300 Subject: [PATCH 12/13] Fix jitter when start moving camera in edit mode focused on entity --- scripts/system/inspect.js | 21 ++++++++++++++++++++ scripts/system/libraries/entityCameraTool.js | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index 6f21e7e8ba..e00dd5f3c2 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -61,6 +61,20 @@ var mode = noMode; var isAwayEnabled = true; +var EDIT_CAMERA_MANAGER_CHANNEL = "Edit-Camera-Manager-Channel"; +var isEditUsingCamera = false; +Messages.messageReceived.connect(function (channel, data, senderID, localOnly) { + if (channel === EDIT_CAMERA_MANAGER_CHANNEL && senderID === MyAvatar.sessionUUID && localOnly) { + var message; + try { + message = JSON.parse(data); + isEditUsingCamera = message.enabled; + } catch (e) { + // Ignore. + } + } +}); + var pick = Picks.createPick(PickType.Ray, { filter: Picks.PICK_DOMAIN_ENTITIES | Picks.PICK_AVATAR_ENTITIES | Picks.PICK_AVATARS | Picks.INCLUDE_VISIBLE | Picks.PICK_INCLUDE_COLLIDABLE | Picks.PICK_INCLUDE_NONCOLLIDABLE | Picks.PICK_PRECISE, @@ -183,6 +197,10 @@ function restoreCameraState() { } function handleModes() { + if (isEditUsingCamera) { + return; + } + var newMode = (mode === noMode) ? noMode : detachedMode; if (alt) { if (control) { @@ -231,6 +249,9 @@ function keyPressEvent(event) { var changed = false; if (event.text === "ALT") { + if (isEditUsingCamera) { + return; + } alt = true; changed = true; Picks.enablePick(pick); diff --git a/scripts/system/libraries/entityCameraTool.js b/scripts/system/libraries/entityCameraTool.js index 2968b8e903..b93879d8e1 100644 --- a/scripts/system/libraries/entityCameraTool.js +++ b/scripts/system/libraries/entityCameraTool.js @@ -68,6 +68,8 @@ CameraManager = function() { that.enabled = false; that.mode = MODE_INACTIVE; + var EDIT_CAMERA_MANAGER_CHANNEL = "Edit-Camera-Manager-Channel"; + Messages.sendLocalMessage(EDIT_CAMERA_MANAGER_CHANNEL, JSON.stringify({ enabled: false })); var actions = { orbitLeft: 0, @@ -153,6 +155,7 @@ CameraManager = function() { that.enabled = true; that.mode = MODE_INACTIVE; + Messages.sendLocalMessage(EDIT_CAMERA_MANAGER_CHANNEL, JSON.stringify({ enabled: true })); // Pick a point INITIAL_ZOOM_DISTANCE in front of the camera to use as a focal point that.zoomDistance = INITIAL_ZOOM_DISTANCE; @@ -193,6 +196,7 @@ CameraManager = function() { that.enabled = false; that.mode = MODE_INACTIVE; + Messages.sendLocalMessage(EDIT_CAMERA_MANAGER_CHANNEL, JSON.stringify({ enabled: false })); if (!ignoreCamera) { Camera.mode = that.previousCameraMode; From 681bd3cb1ec35db96de1d185f406d6002813e99b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 14 Jan 2020 11:34:16 +1300 Subject: [PATCH 13/13] Fix inspect not working after change camera mode --- scripts/system/inspect.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/system/inspect.js b/scripts/system/inspect.js index e00dd5f3c2..17260a4358 100644 --- a/scripts/system/inspect.js +++ b/scripts/system/inspect.js @@ -354,6 +354,11 @@ function mouseMoveEvent(event) { mouseLastY = event.y; } +function onCameraModeUpdated(newMode) { + mode = noMode; + handleModes(); +} + function update() { handleModes(); if (rotatingTowardsTarget) { @@ -381,5 +386,7 @@ Controller.mousePressEvent.connect(mousePressEvent); Controller.mouseReleaseEvent.connect(mouseReleaseEvent); Controller.mouseMoveEvent.connect(mouseMoveEvent); +Camera.modeUpdated.connect(onCameraModeUpdated); + Script.update.connect(update); Script.scriptEnding.connect(scriptEnding);