Add edit camera controls for 3D edit view

Add edit camera controls and grid helper to 3D edit view.

Task-number: QDS-1127
Change-Id: Ice5ea0fcca18d59dc8a2907710e16c6688b90628
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Pasi Keränen
2019-10-15 14:54:20 +03:00
committed by Pasi Keränen
parent 3ee870a3d8
commit c2c8b9a5d6
8 changed files with 204 additions and 52 deletions

View File

@@ -23,79 +23,98 @@
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.0 import QtQuick 2.12
import QtQuick.Window 2.0 import QtQuick.Window 2.0
import QtQuick3D 1.0 import QtQuick3D 1.0
import QtQuick3D.Helpers 1.0
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
import QtGraphicalEffects 1.0
Window { Window {
id: viewWindow
width: 1024 width: 1024
height: 768 height: 768
visible: true visible: true
title: "3D" title: "3D"
flags: Qt.WindowStaysOnTopHint | Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint flags: Qt.WindowStaysOnTopHint | Qt.Window | Qt.WindowTitleHint | Qt.WindowCloseButtonHint
property alias scene: editView.scene
property alias showEditLight: editLightCheckbox.checked
property alias usePerspective: usePerspectiveCheckbox.checked
Rectangle { Rectangle {
color: "black" id: sceneBg
color: "#FFFFFF"
anchors.fill: parent anchors.fill: parent
} focus: true
Column { View3D {
y: 32 id: editView
Slider { anchors.fill: parent
id: slider enableWireframeMode: true
camera: editCamera
value: -600 AxisHelper {
from: -1200 id: axisGrid
to: 600 enableXZGrid: true
enableAxisLines: false
}
Light {
id: directionalLight
visible: showEditLight
}
Camera {
id: editCamera
y: 200
z: -300
clipFar: 100000
projectionMode: usePerspective ? Camera.Perspective : Camera.Orthographic
}
Component.onCompleted: {
directionalLight.setParentItem(editView.scene);
editCamera.setParentItem(editView.scene);
}
} }
Slider {
id: slider2
value: 0 WasdController {
from: -360 id: cameraControl
to: 360 controlledObject: editView.camera
} acceptedButtons: Qt.RightButton
CheckBox {
id: checkBox onInputsNeedProcessingChanged: designStudioNativeCameraControlHelper.enabled
text: "Light" = cameraControl.inputsNeedProcessing
Rectangle {
anchors.fill: parent // Use separate native timer as QML timers don't work inside Qt Design Studio
z: -1 Connections {
target: designStudioNativeCameraControlHelper
onUpdateInputs: cameraControl.processInputs()
} }
} }
} }
Binding { Column {
target: view.scene y: 8
property: "rotation.y" CheckBox {
value: slider2.value id: editLightCheckbox
checked: false
text: qsTr("Use Edit View Light")
onCheckedChanged: cameraControl.forceActiveFocus()
}
CheckBox {
id: usePerspectiveCheckbox
checked: true
text: qsTr("Use Perspective Projection")
onCheckedChanged: cameraControl.forceActiveFocus()
}
} }
property alias scene: view.scene Text {
property alias showLight: checkBox.checked id: helpText
text: qsTr("Camera: W,A,S,D,R,F,right mouse drag")
id: viewWindow anchors.bottom: parent.bottom
View3D {
id: view
anchors.fill: parent
enableWireframeMode: true
camera: camera01
Light {
id: directionalLight
visible: checkBox.checked
}
Camera {
id: camera01
z: slider.value
}
Component.onCompleted: {
directionalLight.setParentItem(view.scene)
camera01.setParentItem(view.scene)
}
} }
} }

View File

@@ -0,0 +1,59 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "cameracontrolhelper.h"
namespace QmlDesigner {
namespace Internal {
CameraControlHelper::CameraControlHelper()
: QObject()
{
m_timer.setInterval(16);
m_timer.setSingleShot(false);
QObject::connect(&m_timer, &QTimer::timeout,
this, &CameraControlHelper::handleUpdateTimer);
}
bool CameraControlHelper::enabled()
{
return m_enabled;
}
void CameraControlHelper::handleUpdateTimer()
{
emit updateInputs();
}
void CameraControlHelper::setEnabled(bool enabled)
{
if (enabled)
m_timer.start();
else
m_timer.stop();
m_enabled = enabled;
}
}
}

View File

@@ -0,0 +1,57 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QtCore/QObject>
#include <QtCore/QTimer>
namespace QmlDesigner {
namespace Internal {
class CameraControlHelper : public QObject
{
Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public:
CameraControlHelper();
bool enabled();
void setEnabled(bool enabled);
public slots:
void handleUpdateTimer();
signals:
void updateInputs();
void enabledChanged(bool enabled);
private:
bool m_enabled = false;
QTimer m_timer;
};
}
}

View File

@@ -0,0 +1,2 @@
HEADERS += $$PWD/cameracontrolhelper.h
SOURCES += $$PWD/cameracontrolhelper.cpp

View File

@@ -58,12 +58,15 @@
#include "changeselectioncommand.h" #include "changeselectioncommand.h"
#include "dummycontextobject.h" #include "dummycontextobject.h"
#include "../editor3d/cameracontrolhelper.h"
#include <designersupportdelegate.h> #include <designersupportdelegate.h>
#include <QQmlProperty> #include <QQmlProperty>
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QQuickView> #include <QQuickView>
#include <QQmlContext>
#include <QQmlEngine>
namespace QmlDesigner { namespace QmlDesigner {
@@ -74,8 +77,10 @@ static QVariant objectToVariant(QObject *object)
static QObject *createEditView3D(QQmlEngine *engine) static QObject *createEditView3D(QQmlEngine *engine)
{ {
QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml")); QmlDesigner::Internal::CameraControlHelper *helper = new QmlDesigner::Internal::CameraControlHelper();
engine->rootContext()->setContextProperty("designStudioNativeCameraControlHelper", helper);
QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml"));
QWindow *window = qobject_cast<QWindow *>(component.create()); QWindow *window = qobject_cast<QWindow *>(component.create());
@@ -84,6 +89,7 @@ static QObject *createEditView3D(QQmlEngine *engine)
surfaceFormat.setVersion(4, 1); surfaceFormat.setVersion(4, 1);
surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
window->setFormat(surfaceFormat); window->setFormat(surfaceFormat);
helper->setParent(window);
return window; return window;
} }

View File

@@ -5,6 +5,7 @@ CONFIG += c++11
DEFINES -= QT_CREATOR DEFINES -= QT_CREATOR
include (editor3d/editor3d.pri)
include (../instances/instances.pri) include (../instances/instances.pri)
include (instances/instances.pri) include (instances/instances.pri)
include (../commands/commands.pri) include (../commands/commands.pri)

View File

@@ -96,6 +96,12 @@ extend_qtc_executable(qml2puppet
nodeinstanceserverinterface.cpp nodeinstanceserverinterface.h nodeinstanceserverinterface.cpp nodeinstanceserverinterface.h
) )
extend_qtc_executable(qml2puppet
SOURCES_PREFIX "${SRCDIR}/qml2puppet/editor3d"
SOURCES
cameracontrolhelper.cpp cameracontrolhelper.h
}
extend_qtc_executable(qml2puppet extend_qtc_executable(qml2puppet
SOURCES_PREFIX "${SRCDIR}/qml2puppet/instances" SOURCES_PREFIX "${SRCDIR}/qml2puppet/instances"
SOURCES SOURCES

View File

@@ -193,6 +193,8 @@ QtcTool {
"instances/qt5testnodeinstanceserver.h", "instances/qt5testnodeinstanceserver.h",
"instances/servernodeinstance.cpp", "instances/servernodeinstance.cpp",
"instances/servernodeinstance.h", "instances/servernodeinstance.h",
"editor3d/cameracontrolhelper.cpp",
"editor3d/cameracontrolhelper.h",
"qml2puppetmain.cpp", "qml2puppetmain.cpp",
] ]
} }