mirror of
https://github.com/overte-org/overte.git
synced 2025-07-29 16:20:00 +02:00
Merge pull request #3039 from Atlante45/snapping_model_rotation
Added snapped/smoothed rotation for models + tooltip
This commit is contained in:
commit
a51d2deec6
1 changed files with 127 additions and 21 deletions
|
@ -5,6 +5,19 @@
|
||||||
// Created by Clément Brisset on 4/24/14.
|
// Created by Clément Brisset on 4/24/14.
|
||||||
// Copyright 2014 High Fidelity, Inc.
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
|
// This script allows you to edit models either with the razor hydras or with your mouse
|
||||||
|
//
|
||||||
|
// If using the hydras :
|
||||||
|
// grab grab models with the triggers, you can then move the models around or scale them with both hands.
|
||||||
|
// You can switch mode using the bumpers so that you can move models roud more easily.
|
||||||
|
//
|
||||||
|
// If using the mouse :
|
||||||
|
// - left click lets you move the model in the plane facing you.
|
||||||
|
// If pressing shift, it will move on the horizontale plane it's in.
|
||||||
|
// - right click lets you rotate the model. z and x give you access to more axix of rotation while shift allows for finer control.
|
||||||
|
// - left + right click lets you scale the model.
|
||||||
|
// - you can press r while holding the model to reset its rotation
|
||||||
|
//
|
||||||
// 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
|
||||||
//
|
//
|
||||||
|
@ -653,16 +666,18 @@ function initToolBar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveOverlays() {
|
function moveOverlays() {
|
||||||
|
var newViewPort = Controller.getViewportDimensions();
|
||||||
|
|
||||||
if (typeof(toolBar) === 'undefined') {
|
if (typeof(toolBar) === 'undefined') {
|
||||||
initToolBar();
|
initToolBar();
|
||||||
|
|
||||||
} else if (windowDimensions.x == Controller.getViewportDimensions().x &&
|
} else if (windowDimensions.x == newViewPort.x &&
|
||||||
windowDimensions.y == Controller.getViewportDimensions().y) {
|
windowDimensions.y == newViewPort.y) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
windowDimensions = Controller.getViewportDimensions();
|
windowDimensions = newViewPort;
|
||||||
var toolsX = windowDimensions.x - 8 - toolBar.width;
|
var toolsX = windowDimensions.x - 8 - toolBar.width;
|
||||||
var toolsY = (windowDimensions.y - toolBar.height) / 2;
|
var toolsY = (windowDimensions.y - toolBar.height) / 2;
|
||||||
|
|
||||||
|
@ -680,8 +695,6 @@ var intersection;
|
||||||
|
|
||||||
|
|
||||||
var SCALE_FACTOR = 200.0;
|
var SCALE_FACTOR = 200.0;
|
||||||
var TRANSLATION_FACTOR = 100.0;
|
|
||||||
var ROTATION_FACTOR = 100.0;
|
|
||||||
|
|
||||||
function rayPlaneIntersection(pickRay, point, normal) {
|
function rayPlaneIntersection(pickRay, point, normal) {
|
||||||
var d = -Vec3.dot(point, normal);
|
var d = -Vec3.dot(point, normal);
|
||||||
|
@ -690,8 +703,50 @@ 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 Tooltip() {
|
||||||
|
this.x = 285;
|
||||||
|
this.y = 115;
|
||||||
|
this.width = 110;
|
||||||
|
this.height = 115 ;
|
||||||
|
this.margin = 5;
|
||||||
|
this.decimals = 3;
|
||||||
|
|
||||||
|
this.textOverlay = Overlays.addOverlay("text", {
|
||||||
|
x: this.x,
|
||||||
|
y: this.y,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height,
|
||||||
|
margin: this.margin,
|
||||||
|
text: "",
|
||||||
|
color: { red: 128, green: 128, blue: 128 },
|
||||||
|
alpha: 0.2,
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
this.show = function(doShow) {
|
||||||
|
Overlays.editOverlay(this.textOverlay, { visible: doShow });
|
||||||
|
}
|
||||||
|
this.updateText = function(properties) {
|
||||||
|
var angles = Quat.safeEulerAngles(properties.modelRotation);
|
||||||
|
var text = "Model Properties:\n"
|
||||||
|
text += "x: " + properties.position.x.toFixed(this.decimals) + "\n"
|
||||||
|
text += "y: " + properties.position.y.toFixed(this.decimals) + "\n"
|
||||||
|
text += "z: " + properties.position.z.toFixed(this.decimals) + "\n"
|
||||||
|
text += "pitch: " + angles.x.toFixed(this.decimals) + "\n"
|
||||||
|
text += "yaw: " + angles.y.toFixed(this.decimals) + "\n"
|
||||||
|
text += "roll: " + angles.z.toFixed(this.decimals) + "\n"
|
||||||
|
text += "Scale: " + 2 * properties.radius.toFixed(this.decimals) + "\n"
|
||||||
|
|
||||||
|
Overlays.editOverlay(this.textOverlay, { text: text });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cleanup = function() {
|
||||||
|
Overlays.deleteOverlay(this.textOverlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var tooltip = new Tooltip();
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
if (altIsPressed) {
|
if (event.isAlt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,6 +841,8 @@ function mousePressEvent(event) {
|
||||||
selectedModelProperties.glowLevel = 0.0;
|
selectedModelProperties.glowLevel = 0.0;
|
||||||
|
|
||||||
print("Clicked on " + selectedModelID.id + " " + modelSelected);
|
print("Clicked on " + selectedModelID.id + " " + modelSelected);
|
||||||
|
tooltip.updateText(selectedModelProperties);
|
||||||
|
tooltip.show(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -794,7 +851,7 @@ var oldModifier = 0;
|
||||||
var modifier = 0;
|
var modifier = 0;
|
||||||
var wasShifted = false;
|
var wasShifted = false;
|
||||||
function mouseMoveEvent(event) {
|
function mouseMoveEvent(event) {
|
||||||
if (altIsPressed) {
|
if (event.isAlt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,26 +943,54 @@ function mouseMoveEvent(event) {
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Let's rotate
|
// Let's rotate
|
||||||
var rotation = Quat.fromVec3Degrees({ x: event.y - mouseLastPosition.y, y: event.x - mouseLastPosition.x, z: 0 });
|
if (somethingChanged) {
|
||||||
if (event.isShifted) {
|
selectedModelProperties.oldRotation.x = selectedModelProperties.modelRotation.x;
|
||||||
rotation = Quat.fromVec3Degrees({ x: event.y - mouseLastPosition.y, y: 0, z: mouseLastPosition.x - event.x });
|
selectedModelProperties.oldRotation.y = selectedModelProperties.modelRotation.y;
|
||||||
|
selectedModelProperties.oldRotation.z = selectedModelProperties.modelRotation.z;
|
||||||
|
selectedModelProperties.oldRotation.w = selectedModelProperties.modelRotation.w;
|
||||||
|
mouseLastPosition.x = event.x;
|
||||||
|
mouseLastPosition.y = event.y;
|
||||||
|
somethingChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newRotation = Quat.multiply(orientation, rotation);
|
|
||||||
newRotation = Quat.multiply(newRotation, Quat.inverse(orientation));
|
|
||||||
|
|
||||||
selectedModelProperties.modelRotation = Quat.multiply(newRotation, selectedModelProperties.oldRotation);
|
var pixelPerDegrees = windowDimensions.y / (1 * 360); // the entire height of the window allow you to make 2 full rotations
|
||||||
|
|
||||||
|
var STEP = 15;
|
||||||
|
var delta = Math.floor((event.x - mouseLastPosition.x) / pixelPerDegrees);
|
||||||
|
|
||||||
|
if (!event.isShifted) {
|
||||||
|
delta = Math.floor(delta / STEP) * STEP;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rotation = Quat.fromVec3Degrees({
|
||||||
|
x: (!zIsPressed && xIsPressed) ? delta : 0, // z is pressed
|
||||||
|
y: (!zIsPressed && !xIsPressed) ? delta : 0, // x is pressed
|
||||||
|
z: (zIsPressed && !xIsPressed) ? delta : 0 // neither is pressed
|
||||||
|
});
|
||||||
|
rotation = Quat.multiply(selectedModelProperties.oldRotation, rotation);
|
||||||
|
|
||||||
|
selectedModelProperties.modelRotation.x = rotation.x;
|
||||||
|
selectedModelProperties.modelRotation.y = rotation.y;
|
||||||
|
selectedModelProperties.modelRotation.z = rotation.z;
|
||||||
|
selectedModelProperties.modelRotation.w = rotation.w;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Models.editModel(selectedModelID, selectedModelProperties);
|
Models.editModel(selectedModelID, selectedModelProperties);
|
||||||
|
tooltip.updateText(selectedModelProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
if (altIsPressed) {
|
if (event.isAlt) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modelSelected) {
|
||||||
|
tooltip.show(false);
|
||||||
|
}
|
||||||
|
|
||||||
modelSelected = false;
|
modelSelected = false;
|
||||||
|
|
||||||
glowedModelID.id = -1;
|
glowedModelID.id = -1;
|
||||||
|
@ -943,6 +1028,7 @@ function scriptEnding() {
|
||||||
rightController.cleanup();
|
rightController.cleanup();
|
||||||
toolBar.cleanup();
|
toolBar.cleanup();
|
||||||
cleanupModelMenus();
|
cleanupModelMenus();
|
||||||
|
tooltip.cleanup();
|
||||||
}
|
}
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
|
|
||||||
|
@ -974,16 +1060,36 @@ Menu.menuItemEvent.connect(function(menuItem){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// handling of inspect.js concurrence
|
// handling of inspect.js concurrence
|
||||||
altIsPressed = false;
|
var zIsPressed = false;
|
||||||
|
var xIsPressed = false;
|
||||||
|
var somethingChanged = false;
|
||||||
Controller.keyPressEvent.connect(function(event) {
|
Controller.keyPressEvent.connect(function(event) {
|
||||||
if (event.text == "ALT") {
|
if ((event.text == "z" || event.text == "Z") && !zIsPressed) {
|
||||||
altIsPressed = true;
|
zIsPressed = true;
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
if ((event.text == "x" || event.text == "X") && !xIsPressed) {
|
||||||
|
xIsPressed = true;
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// resets model orientation when holding with mouse
|
||||||
|
if (event.text == "r" && modelSelected) {
|
||||||
|
selectedModelProperties.modelRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 0 });
|
||||||
|
Models.editModel(selectedModelID, selectedModelProperties);
|
||||||
|
tooltip.updateText(selectedModelProperties);
|
||||||
|
somethingChanged = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Controller.keyReleaseEvent.connect(function(event) {
|
Controller.keyReleaseEvent.connect(function(event) {
|
||||||
if (event.text == "ALT") {
|
if (event.text == "z" || event.text == "Z") {
|
||||||
altIsPressed = false;
|
zIsPressed = false;
|
||||||
|
somethingChanged = true;
|
||||||
|
}
|
||||||
|
if (event.text == "x" || event.text == "X") {
|
||||||
|
xIsPressed = false;
|
||||||
|
somethingChanged = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue