2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2019-11-20 18:01:34 +02:00
|
|
|
|
|
|
|
|
import QtQuick 2.0
|
2020-02-25 14:37:45 +02:00
|
|
|
import QtQuick3D 1.15
|
2019-11-20 18:01:34 +02:00
|
|
|
|
|
|
|
|
View3D {
|
|
|
|
|
id: axisHelperView
|
|
|
|
|
|
|
|
|
|
property var editCameraCtrl
|
|
|
|
|
property Node selectedNode
|
|
|
|
|
|
|
|
|
|
camera: axisHelperCamera
|
|
|
|
|
|
|
|
|
|
Node {
|
|
|
|
|
OrthographicCamera {
|
|
|
|
|
id: axisHelperCamera
|
2020-02-25 14:37:45 +02:00
|
|
|
rotation: editCameraCtrl.camera ? editCameraCtrl.camera.rotation : Qt.quaternion(1, 0, 0, 0)
|
2020-01-28 10:40:44 +02:00
|
|
|
position: editCameraCtrl.camera ? editCameraCtrl.camera.position.minus(editCameraCtrl._lookAtPoint)
|
|
|
|
|
.normalized().times(600) : Qt.vector3d(0, 0, 0)
|
2019-11-20 18:01:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AutoScaleHelper {
|
|
|
|
|
id: autoScale
|
|
|
|
|
view3D: axisHelperView
|
|
|
|
|
position: axisHelperGizmo.scenePosition
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node {
|
|
|
|
|
id: axisHelperGizmo
|
|
|
|
|
scale: autoScale.getScale(Qt.vector3d(4, 4, 4))
|
|
|
|
|
|
|
|
|
|
AxisHelperArm {
|
|
|
|
|
id: armX
|
2020-02-25 14:37:45 +02:00
|
|
|
eulerRotation: Qt.vector3d(0, 0, -90)
|
2019-11-20 18:01:34 +02:00
|
|
|
color: Qt.rgba(1, 0, 0, 1)
|
|
|
|
|
hoverColor: Qt.lighter(Qt.rgba(1, 0, 0, 1))
|
|
|
|
|
view3D: axisHelperView
|
|
|
|
|
camRotPos: Qt.vector3d(0, 90, 0)
|
|
|
|
|
camRotNeg: Qt.vector3d(0, -90, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AxisHelperArm {
|
|
|
|
|
id: armY
|
2020-02-25 14:37:45 +02:00
|
|
|
eulerRotation: Qt.vector3d(0, 0, 0)
|
2019-11-20 18:01:34 +02:00
|
|
|
color: Qt.rgba(0, 0.6, 0, 1)
|
|
|
|
|
hoverColor: Qt.lighter(Qt.rgba(0, 0.6, 0, 1))
|
|
|
|
|
view3D: axisHelperView
|
|
|
|
|
camRotPos: Qt.vector3d(-90, 0, 0)
|
|
|
|
|
camRotNeg: Qt.vector3d(90, 0, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AxisHelperArm {
|
|
|
|
|
id: armZ
|
2020-02-25 14:37:45 +02:00
|
|
|
eulerRotation: Qt.vector3d(90, 0, 0)
|
2019-11-20 18:01:34 +02:00
|
|
|
color: Qt.rgba(0, 0, 1, 1)
|
|
|
|
|
hoverColor: Qt.lighter(Qt.rgba(0, 0, 1, 1))
|
|
|
|
|
view3D: axisHelperView
|
|
|
|
|
camRotPos: Qt.vector3d(0, 0, 0)
|
|
|
|
|
camRotNeg: Qt.vector3d(0, 180, 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
|
|
|
|
|
|
property var pickObj: null
|
|
|
|
|
|
|
|
|
|
function cancelHover()
|
|
|
|
|
{
|
|
|
|
|
if (pickObj) {
|
|
|
|
|
pickObj.hovering = false;
|
|
|
|
|
pickObj = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function pick(mouse)
|
|
|
|
|
{
|
|
|
|
|
var result = axisHelperView.pick(mouse.x, mouse.y);
|
|
|
|
|
if (result.objectHit) {
|
|
|
|
|
if (result.objectHit !== pickObj) {
|
|
|
|
|
cancelHover();
|
|
|
|
|
pickObj = result.objectHit;
|
|
|
|
|
pickObj.hovering = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cancelHover();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 16:13:18 +03:00
|
|
|
onPositionChanged: (mouse)=> {
|
2019-11-20 18:01:34 +02:00
|
|
|
pick(mouse);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 16:13:18 +03:00
|
|
|
onPressed: (mouse)=> {
|
2019-11-20 18:01:34 +02:00
|
|
|
pick(mouse);
|
|
|
|
|
if (pickObj) {
|
2019-11-27 15:48:51 +02:00
|
|
|
axisHelperView.editCameraCtrl.focusObject(axisHelperView.selectedNode,
|
2020-04-23 15:40:41 +03:00
|
|
|
pickObj.cameraRotation, false, false);
|
2019-11-20 18:01:34 +02:00
|
|
|
} else {
|
|
|
|
|
mouse.accepted = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onExited: cancelHover()
|
|
|
|
|
onCanceled: cancelHover()
|
|
|
|
|
}
|
|
|
|
|
}
|