QmlDesigner: Implement proper helper grid for 3D edit view

Change-Id: I9e33218d4b1528610155c5fb9bf94a9597ee23df
Fixes: QDS-1204
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2019-11-13 17:02:52 +02:00
parent db54919798
commit 49f7cfb7a1
9 changed files with 349 additions and 13 deletions

View File

@@ -194,10 +194,10 @@ Window {
Node { Node {
id: mainSceneHelpers id: mainSceneHelpers
AxisHelper { HelperGrid {
id: axisGrid id: helperGrid
enableXZGrid: true lines: 50
enableAxisLines: false step: 50
} }
PointLight { PointLight {
@@ -211,16 +211,18 @@ Window {
PerspectiveCamera { PerspectiveCamera {
id: editPerspectiveCamera id: editPerspectiveCamera
z: -600
y: 200 y: 200
z: -300 rotation.x: 30
clipFar: 100000 clipFar: 100000
clipNear: 1 clipNear: 1
} }
OrthographicCamera { OrthographicCamera {
id: editOrthoCamera id: editOrthoCamera
z: -600
y: 200 y: 200
z: -300 rotation.x: 30
clipFar: 100000 clipFar: 100000
clipNear: 1 clipNear: 1
} }
@@ -301,7 +303,7 @@ Window {
property var group: [btnSelectItem, btnSelectGroup, btnMove, btnRotate, btnScale] property var group: [btnSelectItem, btnSelectGroup, btnMove, btnRotate, btnScale]
ToolbarButton { ToolBarButton {
id: btnSelectItem id: btnSelectItem
selected: true selected: true
tooltip: qsTr("Select Item") tooltip: qsTr("Select Item")
@@ -311,7 +313,7 @@ Window {
buttonsGroup: col.group buttonsGroup: col.group
} }
ToolbarButton { ToolBarButton {
id: btnSelectGroup id: btnSelectGroup
tooltip: qsTr("Select Group") tooltip: qsTr("Select Group")
shortcut: "Q" shortcut: "Q"
@@ -327,7 +329,7 @@ Window {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
ToolbarButton { ToolBarButton {
id: btnMove id: btnMove
tooltip: qsTr("Move current selection") tooltip: qsTr("Move current selection")
shortcut: "M" shortcut: "M"
@@ -336,7 +338,7 @@ Window {
buttonsGroup: col.group buttonsGroup: col.group
} }
ToolbarButton { ToolBarButton {
id: btnRotate id: btnRotate
tooltip: qsTr("Rotate current selection") tooltip: qsTr("Rotate current selection")
shortcut: "E" shortcut: "E"
@@ -345,7 +347,7 @@ Window {
buttonsGroup: col.group buttonsGroup: col.group
} }
ToolbarButton { ToolBarButton {
id: btnScale id: btnScale
tooltip: qsTr("Scale current selection") tooltip: qsTr("Scale current selection")
shortcut: "T" shortcut: "T"

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** 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.
**
****************************************************************************/
import QtQuick 2.0
import QtQuick3D 1.0
import GridGeometry 1.0
Node {
id: grid
property alias lines: gridGeometry.lines
property alias step: gridGeometry.step
rotation.x: 90
// Note: Only one instance of HelperGrid is supported, as the geometry names are fixed
Model {
geometry: GridGeometry {
id: gridGeometry
name: "3D Edit View Helper Grid"
}
materials: [
DefaultMaterial {
id: mainGridMaterial
emissiveColor: "#e6e6e6"
lighting: DefaultMaterial.NoLighting
cullingMode: Material.DisableCulling
}
]
}
Model {
geometry: GridGeometry {
lines: gridGeometry.lines
step: gridGeometry.step
isCenterLine: true
name: "3D Edit View Helper Grid Z Axis"
}
materials: [
DefaultMaterial {
id: vCenterLineMaterial
emissiveColor: "#00a1d2"
lighting: DefaultMaterial.NoLighting
cullingMode: Material.DisableCulling
}
]
}
Model {
rotation.z: 90
geometry: GridGeometry {
lines: gridGeometry.lines
step: gridGeometry.step
isCenterLine: true
name: "3D Edit View Helper Grid X Axis"
}
materials: [
DefaultMaterial {
id: hCenterLineMaterial
emissiveColor: "#cb211a"
lighting: DefaultMaterial.NoLighting
cullingMode: Material.DisableCulling
}
]
}
}

View File

@@ -1,7 +1,9 @@
HEADERS += $$PWD/cameracontrolhelper.h \ HEADERS += $$PWD/cameracontrolhelper.h \
$$PWD/mousearea3d.h \ $$PWD/mousearea3d.h \
$$PWD/camerageometry.h $$PWD/camerageometry.h \
$$PWD/gridgeometry.h
SOURCES += $$PWD/cameracontrolhelper.cpp \ SOURCES += $$PWD/cameracontrolhelper.cpp \
$$PWD/mousearea3d.cpp \ $$PWD/mousearea3d.cpp \
$$PWD/camerageometry.cpp $$PWD/camerageometry.cpp \
$$PWD/gridgeometry.cpp

View File

@@ -0,0 +1,163 @@
/****************************************************************************
**
** 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.
**
****************************************************************************/
#ifdef QUICK3D_MODULE
#include "gridgeometry.h"
#include <QtQuick3DRuntimeRender/private/qssgrendergeometry_p.h>
namespace QmlDesigner {
namespace Internal {
GridGeometry::GridGeometry()
: QQuick3DGeometry()
{
}
GridGeometry::~GridGeometry()
{
}
int GridGeometry::lines() const
{
return m_lines;
}
float GridGeometry::step() const
{
return m_step;
}
bool GridGeometry::isCenterLine() const
{
return m_isCenterLine;
}
// Number of lines on each side of the center lines.
// These lines are not drawn if m_isCenterLine is true; lines and step are simply used to calculate
// the length of the center line in that case.
void GridGeometry::setLines(int count)
{
count = qMax(count, 1);
if (m_lines == count)
return;
m_lines = qMax(count, 1);
emit linesChanged();
update();
}
// Space between lines
void GridGeometry::setStep(float step)
{
step = qMax(step, 0.0f);
if (qFuzzyCompare(m_step, step))
return;
m_step = step;
emit stepChanged();
update();
}
void GridGeometry::setIsCenterLine(bool enabled)
{
if (m_isCenterLine == enabled)
return;
m_isCenterLine = enabled;
emit isCenterLineChanged();
update();
}
QSSGRenderGraphObject *GridGeometry::updateSpatialNode(QSSGRenderGraphObject *node)
{
node = QQuick3DGeometry::updateSpatialNode(node);
QSSGRenderGeometry *geometry = static_cast<QSSGRenderGeometry *>(node);
geometry->clear();
QByteArray vertexData;
fillVertexData(vertexData);
geometry->addAttribute(QSSGRenderGeometry::Attribute::PositionSemantic, 0,
QSSGRenderGeometry::Attribute::ComponentType::F32Type);
geometry->setStride(12);
geometry->setVertexData(vertexData);
geometry->setPrimitiveType(QSSGRenderGeometry::Lines);
int lastIndex = (vertexData.size() - 1) / int(sizeof(QVector3D));
auto vertexPtr = reinterpret_cast<QVector3D *>(vertexData.data());
geometry->setBounds(QVector3D(vertexPtr[0][0], vertexPtr[0][1], 0.0),
QVector3D(vertexPtr[lastIndex][0], vertexPtr[lastIndex][1], 0.0));
return node;
}
void GridGeometry::fillVertexData(QByteArray &vertexData)
{
const int size = m_isCenterLine
? int(sizeof(float)) * 3 * 2
: 4 * m_lines * int(sizeof(float)) * 3 * 2;
vertexData.resize(size);
float *dataPtr = reinterpret_cast<float *>(vertexData.data());
float y0 = -float(m_lines) * m_step;
float x0 = -float(m_lines) * m_step;
float y1 = -y0;
float x1 = -x0;
if (m_isCenterLine) {
// start position
dataPtr[0] = 0.f;
dataPtr[1] = y0;
dataPtr[2] = 0.f;
// end position
dataPtr[3] = 0.f;
dataPtr[4] = y1;
dataPtr[5] = 0.f;
} else {
auto generateLines = [this, &dataPtr](float x0, float y0, float x1, float y1, bool vertical) {
for (int i = 0; i < m_lines; ++i) {
// start position
dataPtr[0] = vertical ? x0 + i * m_step : x0;
dataPtr[1] = vertical ? y0 : y0 + i * m_step;
dataPtr[2] = .0f;
// end position
dataPtr[3] = vertical ? x0 + i * m_step : x1;
dataPtr[4] = vertical ? y1 : y0 + i * m_step;
dataPtr[5] = .0f;
dataPtr += 6;
}
};
// Lines are created so that bounding box can later be calculated from first and last vertex
generateLines(x0, y0, x1, y1, true);
generateLines(x0, y0, x1, y1, false);
generateLines(x0, m_step, x1, y1, false);
generateLines(m_step, y0, x1, y1, true);
}
}
}
}
#endif // QUICK3D_MODULE

View File

@@ -0,0 +1,76 @@
/****************************************************************************
**
** 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
#ifdef QUICK3D_MODULE
#include <QtQuick3D/private/qquick3dgeometry_p.h>
namespace QmlDesigner {
namespace Internal {
class GridGeometry : public QQuick3DGeometry
{
Q_OBJECT
Q_PROPERTY(int lines READ lines WRITE setLines NOTIFY linesChanged)
Q_PROPERTY(float step READ step WRITE setStep NOTIFY stepChanged)
Q_PROPERTY(bool isCenterLine READ isCenterLine WRITE setIsCenterLine NOTIFY isCenterLineChanged)
public:
GridGeometry();
~GridGeometry() override;
int lines() const;
float step() const;
bool isCenterLine() const;
public Q_SLOTS:
void setLines(int count);
void setStep(float step);
void setIsCenterLine(bool enabled);
Q_SIGNALS:
void linesChanged();
void stepChanged();
void isCenterLineChanged();
protected:
QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
private:
void fillVertexData(QByteArray &vertexData);
int m_lines = 1000;
float m_step = .1f;
bool m_isCenterLine = false;
};
}
}
QML_DECLARE_TYPE(QmlDesigner::Internal::GridGeometry)
#endif // QUICK3D_MODULE

View File

@@ -65,6 +65,7 @@
#include "../editor3d/cameracontrolhelper.h" #include "../editor3d/cameracontrolhelper.h"
#include "../editor3d/mousearea3d.h" #include "../editor3d/mousearea3d.h"
#include "../editor3d/camerageometry.h" #include "../editor3d/camerageometry.h"
#include "../editor3d/gridgeometry.h"
#include <designersupportdelegate.h> #include <designersupportdelegate.h>
@@ -109,6 +110,7 @@ QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine)
#ifdef QUICK3D_MODULE #ifdef QUICK3D_MODULE
qmlRegisterType<QmlDesigner::Internal::MouseArea3D>("MouseArea3D", 1, 0, "MouseArea3D"); qmlRegisterType<QmlDesigner::Internal::MouseArea3D>("MouseArea3D", 1, 0, "MouseArea3D");
qmlRegisterType<QmlDesigner::Internal::CameraGeometry>("CameraGeometry", 1, 0, "CameraGeometry"); qmlRegisterType<QmlDesigner::Internal::CameraGeometry>("CameraGeometry", 1, 0, "CameraGeometry");
qmlRegisterType<QmlDesigner::Internal::GridGeometry>("GridGeometry", 1, 0, "GridGeometry");
#endif #endif
QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml")); QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml"));

View File

@@ -15,6 +15,7 @@
<file>mockfiles/LightGizmo.qml</file> <file>mockfiles/LightGizmo.qml</file>
<file>mockfiles/IconGizmo.qml</file> <file>mockfiles/IconGizmo.qml</file>
<file>mockfiles/Overlay2D.qml</file> <file>mockfiles/Overlay2D.qml</file>
<file>mockfiles/HelperGrid.qml</file>
<file>mockfiles/DirectionalDraggable.qml</file> <file>mockfiles/DirectionalDraggable.qml</file>
<file>mockfiles/PlanarDraggable.qml</file> <file>mockfiles/PlanarDraggable.qml</file>
<file>mockfiles/PlanarMoveHandle.qml</file> <file>mockfiles/PlanarMoveHandle.qml</file>

View File

@@ -111,6 +111,7 @@ extend_qtc_executable(qml2puppet
cameracontrolhelper.cpp cameracontrolhelper.h cameracontrolhelper.cpp cameracontrolhelper.h
mousearea3d.cpp mousearea3d.h mousearea3d.cpp mousearea3d.h
camerageometry.cpp camerageometry.h camerageometry.cpp camerageometry.h
gridgeometry.cpp gridgeometry.h
) )
extend_qtc_executable(qml2puppet extend_qtc_executable(qml2puppet

View File

@@ -203,6 +203,8 @@ QtcTool {
"editor3d/mousearea3d.h", "editor3d/mousearea3d.h",
"editor3d/camerageometry.cpp", "editor3d/camerageometry.cpp",
"editor3d/camerageometry.h", "editor3d/camerageometry.h",
"editor3d/gridgeometry.cpp",
"editor3d/gridgeometry.h",
"qml2puppetmain.cpp", "qml2puppetmain.cpp",
] ]
} }