mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 06:24:41 +02:00
Merge pull request #64 from ctrlaltdavid/feature/inspect
inspect.js improvements
This commit is contained in:
commit
2a3b117f5d
2 changed files with 119 additions and 60 deletions
|
@ -5,13 +5,16 @@
|
||||||
// Created by Clément Brisset on March 20, 2014
|
// Created by Clément Brisset on March 20, 2014
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// 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
|
// Your camera stays where it is when you release the Alt key, enabling you to Alt + left - click on another entity or
|
||||||
// orbit mode = hold ALT + CONTROL
|
// avatar to further move your view.
|
||||||
// pan mode = hold ALT + CONTROL + SHIFT
|
//
|
||||||
// Once you are in a mode left click on the object to inspect and hold the click
|
// Press Esc or move your avatar to revert back to your default view.
|
||||||
// Dragging the mouse will move your camera according to the mode you are in.
|
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
@ -25,6 +28,9 @@ var ALTITUDE_RATE = 200.0;
|
||||||
var RADIUS_RATE = 1.0 / 100.0;
|
var RADIUS_RATE = 1.0 / 100.0;
|
||||||
var PAN_RATE = 250.0;
|
var PAN_RATE = 250.0;
|
||||||
|
|
||||||
|
var AVATAR_POSITION_SLOP = 0.1;
|
||||||
|
var AVATAR_ROTATION_SLOP = 0.09; // 5 degrees
|
||||||
|
|
||||||
var Y_AXIS = {
|
var Y_AXIS = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 1,
|
y: 1,
|
||||||
|
@ -36,7 +42,7 @@ var X_AXIS = {
|
||||||
z: 0
|
z: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var LOOK_AT_TIME = 500;
|
var LOOK_AT_TIME = 100; // ms
|
||||||
|
|
||||||
var alt = false;
|
var alt = false;
|
||||||
var shift = false;
|
var shift = false;
|
||||||
|
@ -53,6 +59,29 @@ var detachedMode = 4;
|
||||||
|
|
||||||
var mode = noMode;
|
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,
|
||||||
|
joint: "Mouse",
|
||||||
|
enabled: false
|
||||||
|
});
|
||||||
|
|
||||||
var mouseLastX = 0;
|
var mouseLastX = 0;
|
||||||
var mouseLastY = 0;
|
var mouseLastY = 0;
|
||||||
|
|
||||||
|
@ -144,6 +173,14 @@ function handlePanMode(dx, dy) {
|
||||||
Camera.setOrientation(orientationOf(vector));
|
Camera.setOrientation(orientationOf(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enableAway(enable) {
|
||||||
|
if (enable !== isAwayEnabled) {
|
||||||
|
var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable";
|
||||||
|
Messages.sendMessage(CHANNEL_AWAY_ENABLE, enable ? "enable" : "disable", true);
|
||||||
|
}
|
||||||
|
isAwayEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
function saveCameraState() {
|
function saveCameraState() {
|
||||||
oldMode = Camera.mode;
|
oldMode = Camera.mode;
|
||||||
oldPosition = Camera.getPosition();
|
oldPosition = Camera.getPosition();
|
||||||
|
@ -160,7 +197,11 @@ function restoreCameraState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleModes() {
|
function handleModes() {
|
||||||
var newMode = (mode == noMode) ? noMode : detachedMode;
|
if (isEditUsingCamera) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newMode = (mode === noMode) ? noMode : detachedMode;
|
||||||
if (alt) {
|
if (alt) {
|
||||||
if (control) {
|
if (control) {
|
||||||
if (shift) {
|
if (shift) {
|
||||||
|
@ -174,54 +215,62 @@ function handleModes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if entering detachMode
|
// if entering detachMode
|
||||||
if (newMode == detachedMode && mode != detachedMode) {
|
if (newMode === detachedMode && mode !== detachedMode) {
|
||||||
avatarPosition = MyAvatar.position;
|
avatarPosition = MyAvatar.position;
|
||||||
avatarOrientation = MyAvatar.orientation;
|
avatarOrientation = MyAvatar.orientation;
|
||||||
}
|
}
|
||||||
// if leaving detachMode
|
// if leaving detachMode
|
||||||
if (mode == detachedMode && newMode == detachedMode &&
|
if (mode === detachedMode && newMode === detachedMode && (
|
||||||
(avatarPosition.x != MyAvatar.position.x ||
|
Vec3.length(Vec3.subtract(avatarPosition, MyAvatar.position)) > AVATAR_POSITION_SLOP
|
||||||
avatarPosition.y != MyAvatar.position.y ||
|
|| Vec3.length(Vec3.subtract(Quat.getFront(avatarOrientation), Quat.getFront(MyAvatar.orientation)))
|
||||||
avatarPosition.z != MyAvatar.position.z ||
|
> AVATAR_ROTATION_SLOP)) {
|
||||||
avatarOrientation.x != MyAvatar.orientation.x ||
|
|
||||||
avatarOrientation.y != MyAvatar.orientation.y ||
|
|
||||||
avatarOrientation.z != MyAvatar.orientation.z ||
|
|
||||||
avatarOrientation.w != MyAvatar.orientation.w)) {
|
|
||||||
newMode = noMode;
|
newMode = noMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == noMode && newMode != noMode && Camera.mode == "independent") {
|
if (mode === noMode && newMode !== noMode && Camera.mode === "independent") {
|
||||||
newMode = noMode;
|
newMode = noMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if leaving noMode
|
// if leaving noMode
|
||||||
if (mode == noMode && newMode != noMode) {
|
if (mode === noMode && newMode !== noMode) {
|
||||||
saveCameraState();
|
saveCameraState();
|
||||||
}
|
}
|
||||||
// if entering noMode
|
// if entering noMode
|
||||||
if (newMode == noMode && mode != noMode) {
|
if (newMode === noMode && mode !== noMode) {
|
||||||
restoreCameraState();
|
restoreCameraState();
|
||||||
}
|
}
|
||||||
|
|
||||||
mode = newMode;
|
mode = newMode;
|
||||||
|
|
||||||
|
enableAway(mode === noMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function keyPressEvent(event) {
|
function keyPressEvent(event) {
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
|
||||||
if (event.text == "ALT") {
|
if (event.text === "ALT") {
|
||||||
|
if (isEditUsingCamera) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
alt = true;
|
alt = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
Picks.enablePick(pick);
|
||||||
}
|
}
|
||||||
if (event.text == "CONTROL") {
|
if (event.text === "CONTROL") {
|
||||||
control = true;
|
control = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if (event.text == "SHIFT") {
|
if (event.text === "SHIFT") {
|
||||||
shift = true;
|
shift = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode !== noMode && !alt && !control && !shift && /^ESC|LEFT|RIGHT|UP|DOWN|[wasdWASD]$/.test(event.text)) {
|
||||||
|
mode = noMode;
|
||||||
|
restoreCameraState();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
handleModes();
|
handleModes();
|
||||||
}
|
}
|
||||||
|
@ -230,17 +279,16 @@ function keyPressEvent(event) {
|
||||||
function keyReleaseEvent(event) {
|
function keyReleaseEvent(event) {
|
||||||
var changed = false;
|
var changed = false;
|
||||||
|
|
||||||
if (event.text == "ALT") {
|
if (event.text === "ALT") {
|
||||||
alt = false;
|
alt = false;
|
||||||
changed = true;
|
changed = true;
|
||||||
mode = noMode;
|
Picks.disablePick(pick);
|
||||||
restoreCameraState();
|
|
||||||
}
|
}
|
||||||
if (event.text == "CONTROL") {
|
if (event.text === "CONTROL") {
|
||||||
control = false;
|
control = false;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
if (event.text == "SHIFT") {
|
if (event.text === "SHIFT") {
|
||||||
shift = false;
|
shift = false;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
@ -255,19 +303,18 @@ function mousePressEvent(event) {
|
||||||
mouseLastX = event.x;
|
mouseLastX = event.x;
|
||||||
mouseLastY = event.y;
|
mouseLastY = event.y;
|
||||||
|
|
||||||
// Compute trajectories related values
|
position = Camera.position;
|
||||||
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
|
|
||||||
var modelIntersection = Entities.findRayIntersection(pickRay, true);
|
|
||||||
var avatarIntersection = AvatarList.findRayIntersection(pickRay);
|
|
||||||
|
|
||||||
position = Camera.getPosition();
|
var pickResult = Picks.getPrevPickResult(pick);
|
||||||
|
if (pickResult.intersects) {
|
||||||
if (avatarIntersection.intersects || (modelIntersection.intersects && modelIntersection.accurate)) {
|
// Orbit about intersection.
|
||||||
if (avatarIntersection.intersects) {
|
center = pickResult.intersection;
|
||||||
center = avatarIntersection.intersection;
|
|
||||||
} else {
|
} else {
|
||||||
center = modelIntersection.intersection;
|
// 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
|
// We've selected our target, now orbit towards it automatically
|
||||||
rotatingTowardsTarget = true;
|
rotatingTowardsTarget = true;
|
||||||
// calculate our target cam rotation
|
// calculate our target cam rotation
|
||||||
|
@ -284,7 +331,6 @@ function mousePressEvent(event) {
|
||||||
isActive = true;
|
isActive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
|
@ -293,14 +339,14 @@ function mouseReleaseEvent(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseMoveEvent(event) {
|
function mouseMoveEvent(event) {
|
||||||
if (isActive && mode != noMode && !rotatingTowardsTarget) {
|
if (isActive && mode !== noMode && !rotatingTowardsTarget) {
|
||||||
if (mode == radialMode) {
|
if (mode === radialMode) {
|
||||||
handleRadialMode(event.x - mouseLastX, event.y - mouseLastY);
|
handleRadialMode(event.x - mouseLastX, event.y - mouseLastY);
|
||||||
}
|
}
|
||||||
if (mode == orbitMode) {
|
if (mode === orbitMode) {
|
||||||
handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY);
|
handleOrbitMode(event.x - mouseLastX, event.y - mouseLastY);
|
||||||
}
|
}
|
||||||
if (mode == panningMode) {
|
if (mode === panningMode) {
|
||||||
handlePanMode(event.x - mouseLastX, event.y - mouseLastY);
|
handlePanMode(event.x - mouseLastX, event.y - mouseLastY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,6 +354,11 @@ function mouseMoveEvent(event) {
|
||||||
mouseLastY = event.y;
|
mouseLastY = event.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCameraModeUpdated(newMode) {
|
||||||
|
mode = noMode;
|
||||||
|
handleModes();
|
||||||
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
handleModes();
|
handleModes();
|
||||||
if (rotatingTowardsTarget) {
|
if (rotatingTowardsTarget) {
|
||||||
|
@ -316,13 +367,15 @@ function update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotateTowardsTarget() {
|
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);
|
Camera.setOrientation(newOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scriptEnding() {
|
function scriptEnding() {
|
||||||
if (mode != noMode) {
|
if (mode !== noMode) {
|
||||||
restoreCameraState();
|
restoreCameraState();
|
||||||
|
enableAway(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,5 +386,7 @@ Controller.mousePressEvent.connect(mousePressEvent);
|
||||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||||
|
|
||||||
|
Camera.modeUpdated.connect(onCameraModeUpdated);
|
||||||
|
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
|
|
|
@ -68,6 +68,8 @@ CameraManager = function() {
|
||||||
|
|
||||||
that.enabled = false;
|
that.enabled = false;
|
||||||
that.mode = MODE_INACTIVE;
|
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 = {
|
var actions = {
|
||||||
orbitLeft: 0,
|
orbitLeft: 0,
|
||||||
|
@ -153,6 +155,7 @@ CameraManager = function() {
|
||||||
|
|
||||||
that.enabled = true;
|
that.enabled = true;
|
||||||
that.mode = MODE_INACTIVE;
|
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
|
// Pick a point INITIAL_ZOOM_DISTANCE in front of the camera to use as a focal point
|
||||||
that.zoomDistance = INITIAL_ZOOM_DISTANCE;
|
that.zoomDistance = INITIAL_ZOOM_DISTANCE;
|
||||||
|
@ -193,6 +196,7 @@ CameraManager = function() {
|
||||||
|
|
||||||
that.enabled = false;
|
that.enabled = false;
|
||||||
that.mode = MODE_INACTIVE;
|
that.mode = MODE_INACTIVE;
|
||||||
|
Messages.sendLocalMessage(EDIT_CAMERA_MANAGER_CHANNEL, JSON.stringify({ enabled: false }));
|
||||||
|
|
||||||
if (!ignoreCamera) {
|
if (!ignoreCamera) {
|
||||||
Camera.mode = that.previousCameraMode;
|
Camera.mode = that.previousCameraMode;
|
||||||
|
|
Loading…
Reference in a new issue