mirror of
https://github.com/lubosz/overte.git
synced 2025-04-29 22:23:10 +02:00
Merge pull request #3729 from huffman/inspect-tool
Add inspect tool functionality to newEditModels.js
This commit is contained in:
commit
1707025bd0
2 changed files with 178 additions and 112 deletions
|
@ -34,6 +34,13 @@ var EASING_MULTIPLIER = 8;
|
||||||
var INITIAL_ZOOM_DISTANCE = 2;
|
var INITIAL_ZOOM_DISTANCE = 2;
|
||||||
var INITIAL_ZOOM_DISTANCE_FIRST_PERSON = 3;
|
var INITIAL_ZOOM_DISTANCE_FIRST_PERSON = 3;
|
||||||
|
|
||||||
|
var easeOutCubic = function(t) {
|
||||||
|
t--;
|
||||||
|
return t * t * t + 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
EASE_TIME = 0.5;
|
||||||
|
|
||||||
CameraManager = function() {
|
CameraManager = function() {
|
||||||
var that = {};
|
var that = {};
|
||||||
|
|
||||||
|
@ -51,6 +58,10 @@ CameraManager = function() {
|
||||||
that.focalPoint = { x: 0, y: 0, z: 0 };
|
that.focalPoint = { x: 0, y: 0, z: 0 };
|
||||||
that.targetFocalPoint = { x: 0, y: 0, z: 0 };
|
that.targetFocalPoint = { x: 0, y: 0, z: 0 };
|
||||||
|
|
||||||
|
easing = false;
|
||||||
|
easingTime = 0;
|
||||||
|
startOrientation = Quat.fromPitchYawRollDegrees(0, 0, 0);
|
||||||
|
|
||||||
that.previousCameraMode = null;
|
that.previousCameraMode = null;
|
||||||
|
|
||||||
that.lastMousePosition = { x: 0, y: 0 };
|
that.lastMousePosition = { x: 0, y: 0 };
|
||||||
|
@ -66,10 +77,6 @@ CameraManager = function() {
|
||||||
var focalPoint = Vec3.sum(Camera.getPosition(),
|
var focalPoint = Vec3.sum(Camera.getPosition(),
|
||||||
Vec3.multiply(that.zoomDistance, Quat.getFront(Camera.getOrientation())));
|
Vec3.multiply(that.zoomDistance, Quat.getFront(Camera.getOrientation())));
|
||||||
|
|
||||||
if (Camera.getMode() == 'first person') {
|
|
||||||
that.targetZoomDistance = INITIAL_ZOOM_DISTANCE_FIRST_PERSON;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine the correct yaw and pitch to keep the camera in the same location
|
// Determine the correct yaw and pitch to keep the camera in the same location
|
||||||
var dPos = Vec3.subtract(focalPoint, Camera.getPosition());
|
var dPos = Vec3.subtract(focalPoint, Camera.getPosition());
|
||||||
var xzDist = Math.sqrt(dPos.x * dPos.x + dPos.z * dPos.z);
|
var xzDist = Math.sqrt(dPos.x * dPos.x + dPos.z * dPos.z);
|
||||||
|
@ -100,13 +107,35 @@ CameraManager = function() {
|
||||||
cameraTool.setVisible(false);
|
cameraTool.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
that.focus = function() {
|
that.focus = function(position, dimensions, easeOrientation) {
|
||||||
var dim = SelectionManager.worldDimensions;
|
if (dimensions) {
|
||||||
var size = Math.max(dim.x, Math.max(dim.y, dim.z));
|
var size = Math.max(dimensions.x, Math.max(dimensions.y, dimensions.z));
|
||||||
|
|
||||||
that.targetZoomDistance = Math.max(size * FOCUS_ZOOM_SCALE, FOCUS_MIN_ZOOM);
|
that.targetZoomDistance = Math.max(size * FOCUS_ZOOM_SCALE, FOCUS_MIN_ZOOM);
|
||||||
|
} else {
|
||||||
|
that.targetZoomDistance = Vec3.length(Vec3.subtract(Camera.getPosition(), position));
|
||||||
|
}
|
||||||
|
|
||||||
that.setFocalPoint(SelectionManager.worldPosition);
|
if (easeOrientation) {
|
||||||
|
// Do eased turning towards target
|
||||||
|
that.focalPoint = that.targetFocalPoint = position;
|
||||||
|
|
||||||
|
that.zoomDistance = that.targetZoomDistance = Vec3.length(Vec3.subtract(Camera.getPosition(), position));
|
||||||
|
|
||||||
|
var dPos = Vec3.subtract(that.focalPoint, Camera.getPosition());
|
||||||
|
var xzDist = Math.sqrt(dPos.x * dPos.x + dPos.z * dPos.z);
|
||||||
|
|
||||||
|
that.targetPitch = -Math.atan2(dPos.y, xzDist) * 180 / Math.PI;
|
||||||
|
that.targetYaw = Math.atan2(dPos.x, dPos.z) * 180 / Math.PI;
|
||||||
|
that.pitch = that.targetPitch;
|
||||||
|
that.yaw = that.targetYaw;
|
||||||
|
|
||||||
|
startOrientation = Camera.getOrientation();
|
||||||
|
|
||||||
|
easing = true;
|
||||||
|
easingTime = 0;
|
||||||
|
} else {
|
||||||
|
that.setFocalPoint(position);
|
||||||
|
}
|
||||||
|
|
||||||
that.updateCamera();
|
that.updateCamera();
|
||||||
}
|
}
|
||||||
|
@ -255,6 +284,11 @@ CameraManager = function() {
|
||||||
xRot = Quat.angleAxis(-that.pitch, { x: 1, y: 0, z: 0 });
|
xRot = Quat.angleAxis(-that.pitch, { x: 1, y: 0, z: 0 });
|
||||||
q = Quat.multiply(yRot, xRot);
|
q = Quat.multiply(yRot, xRot);
|
||||||
|
|
||||||
|
if (easing) {
|
||||||
|
var t = easeOutCubic(easingTime / EASE_TIME);
|
||||||
|
q = Quat.slerp(startOrientation, q, t);
|
||||||
|
}
|
||||||
|
|
||||||
Camera.setOrientation(q);
|
Camera.setOrientation(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +304,10 @@ CameraManager = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (easing) {
|
||||||
|
easingTime = Math.min(EASE_TIME, easingTime + dt);
|
||||||
|
}
|
||||||
|
|
||||||
var scale = Math.min(dt * EASING_MULTIPLIER, 1.0);
|
var scale = Math.min(dt * EASING_MULTIPLIER, 1.0);
|
||||||
|
|
||||||
var dYaw = that.targetYaw - that.yaw;
|
var dYaw = that.targetYaw - that.yaw;
|
||||||
|
@ -292,6 +330,10 @@ CameraManager = function() {
|
||||||
that.zoomDistance += scale * dZoom;
|
that.zoomDistance += scale * dZoom;
|
||||||
|
|
||||||
that.updateCamera();
|
that.updateCamera();
|
||||||
|
|
||||||
|
if (easingTime >= 1) {
|
||||||
|
easing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last mode that was first or third person
|
// Last mode that was first or third person
|
||||||
|
|
|
@ -51,6 +51,9 @@ var wantEntityGlow = false;
|
||||||
var SPAWN_DISTANCE = 1;
|
var SPAWN_DISTANCE = 1;
|
||||||
var DEFAULT_DIMENSION = 0.20;
|
var DEFAULT_DIMENSION = 0.20;
|
||||||
|
|
||||||
|
var MENU_INSPECT_TOOL_ENABLED = 'Inspect Tool';
|
||||||
|
var MENU_EASE_ON_FOCUS = 'Ease Orientation on Focus';
|
||||||
|
|
||||||
var modelURLs = [
|
var modelURLs = [
|
||||||
HIFI_PUBLIC_BUCKET + "meshes/Feisar_Ship.FBX",
|
HIFI_PUBLIC_BUCKET + "meshes/Feisar_Ship.FBX",
|
||||||
HIFI_PUBLIC_BUCKET + "meshes/birarda/birarda_head.fbx",
|
HIFI_PUBLIC_BUCKET + "meshes/birarda/birarda_head.fbx",
|
||||||
|
@ -387,7 +390,6 @@ function isLocked(properties) {
|
||||||
|
|
||||||
|
|
||||||
var selectedEntityID;
|
var selectedEntityID;
|
||||||
var mouseLastPosition;
|
|
||||||
var orientation;
|
var orientation;
|
||||||
var intersection;
|
var intersection;
|
||||||
|
|
||||||
|
@ -401,30 +403,13 @@ function rayPlaneIntersection(pickRay, point, normal) {
|
||||||
return Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, t));
|
return Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findClickedEntity(event) {
|
||||||
function mousePressEvent(event) {
|
|
||||||
mouseLastPosition = { x: event.x, y: event.y };
|
|
||||||
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
|
||||||
|
|
||||||
var entitySelected = false;
|
|
||||||
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)
|
|
||||||
|| cameraManager.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) {
|
|
||||||
// Event handled; do nothing.
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// If we aren't active and didn't click on an overlay: quit
|
|
||||||
if (!isActive) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
Vec3.print("[Mouse] Looking at: ", pickRay.origin);
|
|
||||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
var foundIntersection = Entities.findRayIntersection(pickRay);
|
||||||
|
|
||||||
if (!foundIntersection.accurate) {
|
if (!foundIntersection.accurate) {
|
||||||
selectionManager.clearSelections();
|
return null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
var foundEntity = foundIntersection.entityID;
|
var foundEntity = foundIntersection.entityID;
|
||||||
|
|
||||||
|
@ -433,11 +418,33 @@ function mousePressEvent(event) {
|
||||||
if (!identify.isKnownID) {
|
if (!identify.isKnownID) {
|
||||||
print("Unknown ID " + identify.id + " (update loop " + foundEntity.id + ")");
|
print("Unknown ID " + identify.id + " (update loop " + foundEntity.id + ")");
|
||||||
selectionManager.clearSelections();
|
selectionManager.clearSelections();
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
foundEntity = identify;
|
foundEntity = identify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { pickRay: pickRay, entityID: foundEntity };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function mousePressEvent(event) {
|
||||||
|
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isActive) {
|
||||||
|
var entitySelected = false;
|
||||||
|
if (cameraManager.mousePressEvent(event) || selectionDisplay.mousePressEvent(event)) {
|
||||||
|
// Event handled; do nothing.
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
var result = findClickedEntity(event);
|
||||||
|
if (result === null) {
|
||||||
|
selectionManager.clearSelections();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pickRay = result.pickRay;
|
||||||
|
var foundEntity = result.entityID;
|
||||||
|
|
||||||
var properties = Entities.getEntityProperties(foundEntity);
|
var properties = Entities.getEntityProperties(foundEntity);
|
||||||
if (isLocked(properties)) {
|
if (isLocked(properties)) {
|
||||||
print("Model locked " + properties.id);
|
print("Model locked " + properties.id);
|
||||||
|
@ -488,15 +495,21 @@ function mousePressEvent(event) {
|
||||||
if (entitySelected) {
|
if (entitySelected) {
|
||||||
selectionDisplay.select(selectedEntityID, event);
|
selectionDisplay.select(selectedEntityID, event);
|
||||||
}
|
}
|
||||||
|
} else if (Menu.isOptionChecked(MENU_INSPECT_TOOL_ENABLED)) {
|
||||||
|
var result = findClickedEntity(event);
|
||||||
|
if (result !== null && event.isRightButton) {
|
||||||
|
var currentProperties = Entities.getEntityProperties(result.entityID);
|
||||||
|
cameraManager.enable();
|
||||||
|
cameraManager.focus(currentProperties.position, null, Menu.isOptionChecked(MENU_EASE_ON_FOCUS));
|
||||||
|
cameraManager.mousePressEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var highlightedEntityID = { isKnownID: false };
|
var highlightedEntityID = { isKnownID: false };
|
||||||
|
|
||||||
function mouseMoveEvent(event) {
|
function mouseMoveEvent(event) {
|
||||||
if (!isActive) {
|
if (isActive) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
|
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
|
||||||
if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) {
|
if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) {
|
||||||
return;
|
return;
|
||||||
|
@ -527,16 +540,17 @@ function mouseMoveEvent(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cameraManager.mouseMoveEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
if (!isActive) {
|
if (isActive && selectionManager.hasSelection()) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (selectionManager.hasSelection()) {
|
|
||||||
tooltip.show(false);
|
tooltip.show(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
cameraManager.mouseReleaseEvent(event);
|
cameraManager.mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,6 +589,9 @@ function setupModelMenus() {
|
||||||
Menu.addMenuItem({ menuName: "File", menuItemName: "Export Models", shortcutKey: "CTRL+META+E", afterItem: "Models" });
|
Menu.addMenuItem({ menuName: "File", menuItemName: "Export Models", shortcutKey: "CTRL+META+E", afterItem: "Models" });
|
||||||
Menu.addMenuItem({ menuName: "File", menuItemName: "Import Models", shortcutKey: "CTRL+META+I", afterItem: "Export Models" });
|
Menu.addMenuItem({ menuName: "File", menuItemName: "Import Models", shortcutKey: "CTRL+META+I", afterItem: "Export Models" });
|
||||||
Menu.addMenuItem({ menuName: "Developer", menuItemName: "Debug Ryans Rotation Problems", isCheckable: true });
|
Menu.addMenuItem({ menuName: "Developer", menuItemName: "Debug Ryans Rotation Problems", isCheckable: true });
|
||||||
|
|
||||||
|
Menu.addMenuItem({ menuName: "View", menuItemName: MENU_INSPECT_TOOL_ENABLED, afterItem: "Edit Entities Help...", isCheckable: true });
|
||||||
|
Menu.addMenuItem({ menuName: "View", menuItemName: MENU_EASE_ON_FOCUS, afterItem: MENU_INSPECT_TOOL_ENABLED, isCheckable: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
setupModelMenus(); // do this when first running our script.
|
setupModelMenus(); // do this when first running our script.
|
||||||
|
@ -596,6 +613,9 @@ function cleanupModelMenus() {
|
||||||
Menu.removeMenuItem("File", "Export Models");
|
Menu.removeMenuItem("File", "Export Models");
|
||||||
Menu.removeMenuItem("File", "Import Models");
|
Menu.removeMenuItem("File", "Import Models");
|
||||||
Menu.removeMenuItem("Developer", "Debug Ryans Rotation Problems");
|
Menu.removeMenuItem("Developer", "Debug Ryans Rotation Problems");
|
||||||
|
|
||||||
|
Menu.removeMenuItem("View", MENU_INSPECT_TOOL_ENABLED);
|
||||||
|
Menu.removeMenuItem("View", MENU_EASE_ON_FOCUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(function() {
|
Script.scriptEnding.connect(function() {
|
||||||
|
@ -718,7 +738,11 @@ Controller.keyReleaseEvent.connect(function (event) {
|
||||||
} else if (event.text == "TAB") {
|
} else if (event.text == "TAB") {
|
||||||
selectionDisplay.toggleSpaceMode();
|
selectionDisplay.toggleSpaceMode();
|
||||||
} else if (event.text == "f") {
|
} else if (event.text == "f") {
|
||||||
cameraManager.focus();
|
if (isActive) {
|
||||||
|
cameraManager.focus(selectionManager.worldPosition,
|
||||||
|
selectionManager.worldDimensions,
|
||||||
|
Menu.isOptionChecked(MENU_EASE_ON_FOCUS));
|
||||||
|
}
|
||||||
} else if (event.text == '[') {
|
} else if (event.text == '[') {
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
cameraManager.enable();
|
cameraManager.enable();
|
||||||
|
|
Loading…
Reference in a new issue