mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 10:17:27 +02:00
[ui] Viewer3D: TransformGizmo - preparing for the bounding box
This commit is contained in:
parent
d0a78d96ab
commit
7663a6a44b
2 changed files with 31 additions and 34 deletions
|
@ -7,33 +7,22 @@ import Qt3D.Logic 2.0
|
|||
|
||||
Entity {
|
||||
id: root
|
||||
property DefaultCameraController cameraController
|
||||
property DefaultCameraController sceneCameraController
|
||||
property Layer frontLayerComponent
|
||||
property var window
|
||||
|
||||
readonly property Camera camera : cameraController.camera
|
||||
readonly property var windowSize: cameraController.windowSize
|
||||
readonly property alias objectTransform : transformGizmo.objectTransform // The Transform the object should use
|
||||
readonly property alias updateTransformations: transformGizmo.updateTransformations // Function to update the transformations
|
||||
|
||||
signal pickedChanged(bool pressed)
|
||||
signal gizmoChanged(var translation, var rotation, var scale)
|
||||
|
||||
onPickedChanged: {
|
||||
cameraController.loseMouseFocus = pressed // Notify the camera if the transform takes/releases the focus
|
||||
}
|
||||
|
||||
TransformGizmo {
|
||||
property TransformGizmo transformGizmo: TransformGizmo {
|
||||
id: transformGizmo
|
||||
camera: root.camera
|
||||
windowSize: root.windowSize
|
||||
frontLayerComponent: root.frontLayerComponent
|
||||
window: root.window
|
||||
|
||||
onPickedChanged: {
|
||||
root.pickedChanged(pressed)
|
||||
}
|
||||
onGizmoChanged: {
|
||||
root.gizmoChanged(translation, rotation, scale)
|
||||
sceneCameraController.loseMouseFocus = pressed // Notify the camera if the transform takes/releases the focus
|
||||
}
|
||||
}
|
||||
|
||||
readonly property Camera camera : sceneCameraController.camera
|
||||
readonly property var windowSize: sceneCameraController.windowSize
|
||||
readonly property alias objectTransform : transformGizmo.objectTransform // The Transform the object should use
|
||||
}
|
|
@ -14,17 +14,16 @@ Entity {
|
|||
property var windowSize
|
||||
property var frontLayerComponent
|
||||
property var window
|
||||
|
||||
readonly property Transform objectTransform : Transform {
|
||||
property bool focusGizmoPriority: false // If true, it is used to give the priority to the current transformation (and not to a upper-level binding)
|
||||
property Transform gizmoDisplayTransform: Transform {
|
||||
id: gizmoDisplayTransform
|
||||
scale: root.gizmoScale * (camera.position.minus(gizmoDisplayTransform.translation)).length()
|
||||
}
|
||||
property Transform objectTransform : Transform {
|
||||
translation: gizmoDisplayTransform.translation
|
||||
rotation: gizmoDisplayTransform.rotation
|
||||
scale3D: Qt.vector3d(1,1,1)
|
||||
}
|
||||
readonly property var updateTransformations: function updateTransformations(translation, rotation, scale) {
|
||||
const gizmoModelMat = Transformations3DHelper.computeModelMatrixWithEuler(translation, rotation, Qt.vector3d(1,1,1))
|
||||
gizmoDisplayTransform.setMatrix(gizmoModelMat) // Update gizmo matrix and translation/rotation of the object (with binding)
|
||||
objectTransform.scale3D = scale // Update the scale of the object
|
||||
}
|
||||
|
||||
signal pickedChanged(bool pressed)
|
||||
signal gizmoChanged(var translation, var rotation, var scale)
|
||||
|
@ -34,8 +33,8 @@ Entity {
|
|||
const rotation = Qt.vector3d(gizmoDisplayTransform.rotationX, gizmoDisplayTransform.rotationY, gizmoDisplayTransform.rotationZ) // Euler angles
|
||||
const scale = objectTransform.scale3D // Scale of the object
|
||||
|
||||
updateTransformations(translation, rotation, scale) // Optional: just to make sure the absolute values work well
|
||||
gizmoChanged(translation, rotation, scale)
|
||||
root.focusGizmoPriority = false
|
||||
}
|
||||
|
||||
components: [gizmoDisplayTransform, mouseHandler, frontLayerComponent]
|
||||
|
@ -70,15 +69,26 @@ Entity {
|
|||
}
|
||||
|
||||
function resetTranslation() {
|
||||
gizmoDisplayTransform.translation = Qt.vector3d(0,0,0) // Reset gizmo matrix and object matrix with binding
|
||||
// We have to make the opposite translation because we cannot override gizmoDisplayTransform.translation (because it can be used in upper-level binding)
|
||||
// The object translation will also be updated because of the binding
|
||||
const modelMat = Transformations3DHelper.modelMatrixToMatrices(gizmoDisplayTransform.matrix)
|
||||
doRelativeTranslation(modelMat, gizmoDisplayTransform.translation.times(-1))
|
||||
}
|
||||
|
||||
function resetRotation() {
|
||||
// Here, we can change the rotation property (but not rotationX, rotationY and rotationZ because they can be used in upper-level bindings)
|
||||
gizmoDisplayTransform.rotation = Qt.quaternion(1,0,0,0) // Reset gizmo matrix and object matrix with binding
|
||||
}
|
||||
|
||||
function resetScale() {
|
||||
objectTransform.scale3D = Qt.vector3d(1,1,1) // Reset only object matrix
|
||||
// We have to make the difference scale to 1 because we cannot override objectTransform.scale3D (because it can be used in upper-level binding)
|
||||
const modelMat = Transformations3DHelper.modelMatrixToMatrices(objectTransform.matrix)
|
||||
const scaleDiff = Qt.vector3d(
|
||||
-(objectTransform.scale3D.x - 1),
|
||||
-(objectTransform.scale3D.y - 1),
|
||||
-(objectTransform.scale3D.z - 1)
|
||||
)
|
||||
doRelativeScale(modelMat, scaleDiff)
|
||||
}
|
||||
|
||||
function resetATransformType(transformType) {
|
||||
|
@ -102,6 +112,8 @@ Entity {
|
|||
|
||||
onPositionChanged: {
|
||||
if (objectPicker && objectPicker.button === Qt.LeftButton) {
|
||||
root.focusGizmoPriority = true
|
||||
|
||||
// Get the selected axis
|
||||
let pickedAxis
|
||||
switch(objectPicker.gizmoAxis) {
|
||||
|
@ -188,6 +200,7 @@ Entity {
|
|||
}
|
||||
onReleased: {
|
||||
if(objectPicker && mouse.button === Qt.LeftButton) {
|
||||
objectPicker = null // To prevent going again in the onPositionChanged
|
||||
emitGizmoChanged()
|
||||
}
|
||||
}
|
||||
|
@ -215,11 +228,6 @@ Entity {
|
|||
|
||||
/***** GIZMO'S BASIC COMPONENTS *****/
|
||||
|
||||
Transform {
|
||||
id: gizmoDisplayTransform
|
||||
scale: root.gizmoScale * (camera.position.minus(gizmoDisplayTransform.translation)).length()
|
||||
}
|
||||
|
||||
Entity {
|
||||
id: centerSphereEntity
|
||||
components: [centerSphereMesh, centerSphereMaterial, frontLayerComponent]
|
||||
|
|
Loading…
Add table
Reference in a new issue