diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml index 5ca9ab8f9fb..9db9d0c8a83 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml @@ -194,10 +194,10 @@ Window { Node { id: mainSceneHelpers - AxisHelper { - id: axisGrid - enableXZGrid: true - enableAxisLines: false + HelperGrid { + id: helperGrid + lines: 50 + step: 50 } PointLight { @@ -211,16 +211,18 @@ Window { PerspectiveCamera { id: editPerspectiveCamera + z: -600 y: 200 - z: -300 + rotation.x: 30 clipFar: 100000 clipNear: 1 } OrthographicCamera { id: editOrthoCamera + z: -600 y: 200 - z: -300 + rotation.x: 30 clipFar: 100000 clipNear: 1 } @@ -301,7 +303,7 @@ Window { property var group: [btnSelectItem, btnSelectGroup, btnMove, btnRotate, btnScale] - ToolbarButton { + ToolBarButton { id: btnSelectItem selected: true tooltip: qsTr("Select Item") @@ -311,7 +313,7 @@ Window { buttonsGroup: col.group } - ToolbarButton { + ToolBarButton { id: btnSelectGroup tooltip: qsTr("Select Group") shortcut: "Q" @@ -327,7 +329,7 @@ Window { anchors.horizontalCenter: parent.horizontalCenter } - ToolbarButton { + ToolBarButton { id: btnMove tooltip: qsTr("Move current selection") shortcut: "M" @@ -336,7 +338,7 @@ Window { buttonsGroup: col.group } - ToolbarButton { + ToolBarButton { id: btnRotate tooltip: qsTr("Rotate current selection") shortcut: "E" @@ -345,7 +347,7 @@ Window { buttonsGroup: col.group } - ToolbarButton { + ToolBarButton { id: btnScale tooltip: qsTr("Scale current selection") shortcut: "T" diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/HelperGrid.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/HelperGrid.qml new file mode 100644 index 00000000000..54af572a7ba --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/HelperGrid.qml @@ -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 + } + ] + } +} diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri index 4e39a4cba9a..e8f546e8187 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri @@ -1,7 +1,9 @@ HEADERS += $$PWD/cameracontrolhelper.h \ $$PWD/mousearea3d.h \ - $$PWD/camerageometry.h + $$PWD/camerageometry.h \ + $$PWD/gridgeometry.h SOURCES += $$PWD/cameracontrolhelper.cpp \ $$PWD/mousearea3d.cpp \ - $$PWD/camerageometry.cpp + $$PWD/camerageometry.cpp \ + $$PWD/gridgeometry.cpp diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/gridgeometry.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/gridgeometry.cpp new file mode 100644 index 00000000000..55158180819 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/gridgeometry.cpp @@ -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 + +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(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(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(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 diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/gridgeometry.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/gridgeometry.h new file mode 100644 index 00000000000..41b83abca6e --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/gridgeometry.h @@ -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 + +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 diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 546593ca828..2cd59af4607 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -65,6 +65,7 @@ #include "../editor3d/cameracontrolhelper.h" #include "../editor3d/mousearea3d.h" #include "../editor3d/camerageometry.h" +#include "../editor3d/gridgeometry.h" #include @@ -109,6 +110,7 @@ QObject *Qt5InformationNodeInstanceServer::createEditView3D(QQmlEngine *engine) #ifdef QUICK3D_MODULE qmlRegisterType("MouseArea3D", 1, 0, "MouseArea3D"); qmlRegisterType("CameraGeometry", 1, 0, "CameraGeometry"); + qmlRegisterType("GridGeometry", 1, 0, "GridGeometry"); #endif QQmlComponent component(engine, QUrl("qrc:/qtquickplugin/mockfiles/EditView3D.qml")); diff --git a/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc b/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc index 7cb9e7913e0..f818f23fd52 100644 --- a/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc +++ b/share/qtcreator/qml/qmlpuppet/qmlpuppet.qrc @@ -15,6 +15,7 @@ mockfiles/LightGizmo.qml mockfiles/IconGizmo.qml mockfiles/Overlay2D.qml + mockfiles/HelperGrid.qml mockfiles/DirectionalDraggable.qml mockfiles/PlanarDraggable.qml mockfiles/PlanarMoveHandle.qml diff --git a/src/tools/qml2puppet/CMakeLists.txt b/src/tools/qml2puppet/CMakeLists.txt index 920d984bd4d..3f8987ee60f 100644 --- a/src/tools/qml2puppet/CMakeLists.txt +++ b/src/tools/qml2puppet/CMakeLists.txt @@ -111,6 +111,7 @@ extend_qtc_executable(qml2puppet cameracontrolhelper.cpp cameracontrolhelper.h mousearea3d.cpp mousearea3d.h camerageometry.cpp camerageometry.h + gridgeometry.cpp gridgeometry.h ) extend_qtc_executable(qml2puppet diff --git a/src/tools/qml2puppet/qml2puppet.qbs b/src/tools/qml2puppet/qml2puppet.qbs index 2d083714525..ca1c3654fbe 100644 --- a/src/tools/qml2puppet/qml2puppet.qbs +++ b/src/tools/qml2puppet/qml2puppet.qbs @@ -203,6 +203,8 @@ QtcTool { "editor3d/mousearea3d.h", "editor3d/camerageometry.cpp", "editor3d/camerageometry.h", + "editor3d/gridgeometry.cpp", + "editor3d/gridgeometry.h", "qml2puppetmain.cpp", ] }