[ui] Viewer3D: TransformGizmo - drawing gizmo on top of the object

- Special entity acting as an object container: we can add the entities we want to control with a gizmo inside it.
- Drawing the gizmo always on top of the object to make sure to see it every time.
This commit is contained in:
Julien-Haudegond 2020-07-09 10:56:25 +02:00
parent bdf9d74ec8
commit 85ebbba14f
4 changed files with 55 additions and 7 deletions

View file

@ -23,6 +23,8 @@ Entity {
property alias windowSize: trackball.windowSize property alias windowSize: trackball.windowSize
property alias trackballSize: trackball.trackballSize property alias trackballSize: trackball.trackballSize
property bool loseMouseFocus: false // Must be changed by other entities when they want to take mouse focus
readonly property alias pressed: mouseHandler._pressed readonly property alias pressed: mouseHandler._pressed
signal mousePressed(var mouse) signal mousePressed(var mouse)
signal mouseReleased(var mouse, var moved) signal mouseReleased(var mouse, var moved)
@ -166,6 +168,8 @@ Entity {
components: [ components: [
FrameAction { FrameAction {
onTriggered: { onTriggered: {
if(loseMouseFocus) return
if(panning) { // translate if(panning) { // translate
var d = (root.camera.viewCenter.minus(root.camera.position)).length() * 0.03; var d = (root.camera.viewCenter.minus(root.camera.position)).length() * 0.03;
var tx = axisMX.value * root.translateSpeed * d; var tx = axisMX.value * root.translateSpeed * d;

View file

@ -0,0 +1,32 @@
import Qt3D.Core 2.0
import Qt3D.Render 2.9
import Qt3D.Input 2.0
import Qt3D.Extras 2.10
import QtQuick 2.9
import Qt3D.Logic 2.0
Entity {
id: root
property DefaultCameraController cameraController
property Layer frontLayerComponent
readonly property Camera camera : cameraController.camera
readonly property var windowSize: cameraController.windowSize
readonly property alias objectTransform : transformGizmo.objectTransform // The Transform the object should use
signal pickedChanged(bool pressed)
onPickedChanged: {
cameraController.loseMouseFocus = pressed // Notify the camera if the transform takes/releases the focus
}
TransformGizmo {
id: transformGizmo
camera: root.camera
windowSize: root.windowSize
frontLayerComponent: root.frontLayerComponent
onPickedChanged: {
root.pickedChanged(pressed)
}
}
}

View file

@ -7,14 +7,15 @@ import Qt3D.Logic 2.0
Entity { Entity {
id: root id: root
property real gizmoScale: 0.20 property real gizmoScale: 0.15
property Camera camera property Camera camera
property var windowSize property var windowSize
property var frontLayerComponent
readonly property Transform objectTransform : Transform {} readonly property Transform objectTransform : Transform {}
signal pickedChanged(bool pressed) signal pickedChanged(bool pressed)
components: [gizmoDisplayTransform, mouseHandler] components: [gizmoDisplayTransform, mouseHandler, frontLayerComponent]
/***** ENUMS *****/ /***** ENUMS *****/
@ -194,7 +195,7 @@ Entity {
Entity { Entity {
id: centerSphereEntity id: centerSphereEntity
components: [centerSphereMesh, centerSphereMaterial] components: [centerSphereMesh, centerSphereMaterial, frontLayerComponent]
SphereMesh { SphereMesh {
id: centerSphereMesh id: centerSphereMesh
@ -238,7 +239,7 @@ Entity {
Entity { Entity {
id: axisCylinder id: axisCylinder
components: [cylinderMesh, cylinderTransform, scaleMaterial] components: [cylinderMesh, cylinderTransform, scaleMaterial, frontLayerComponent]
CylinderMesh { CylinderMesh {
id: cylinderMesh id: cylinderMesh
@ -275,7 +276,7 @@ Entity {
Entity { Entity {
id: axisScaleBox id: axisScaleBox
components: [cubeScaleMesh, cubeScaleTransform, scaleMaterial, scalePicker] components: [cubeScaleMesh, cubeScaleTransform, scaleMaterial, scalePicker, frontLayerComponent]
CuboidMesh { CuboidMesh {
id: cubeScaleMesh id: cubeScaleMesh
@ -334,7 +335,7 @@ Entity {
// POSITION ENTITY // POSITION ENTITY
Entity { Entity {
id: positionEntity id: positionEntity
components: [coneMesh, coneTransform, positionMaterial, positionPicker] components: [coneMesh, coneTransform, positionMaterial, positionPicker, frontLayerComponent]
ConeMesh { ConeMesh {
id: coneMesh id: coneMesh
@ -394,7 +395,7 @@ Entity {
// ROTATION ENTITY // ROTATION ENTITY
Entity { Entity {
id: rotationEntity id: rotationEntity
components: [torusMesh, torusTransform, rotationMaterial, rotationPicker] components: [torusMesh, torusTransform, rotationMaterial, rotationPicker, frontLayerComponent]
TorusMesh { TorusMesh {
id: torusMesh id: torusMesh

View file

@ -207,6 +207,17 @@ FocusScope {
] ]
} }
} }
LayerFilter {
filterMode: LayerFilter.DiscardAnyMatchingLayers
layers: Layer {id: drawOnFront}
}
LayerFilter {
filterMode: LayerFilter.AcceptAnyMatchingLayers
layers: [drawOnFront]
RenderStateSet {
renderStates: DepthTest { depthFunction: DepthTest.Equal }
}
}
} }
} }
} }