diff --git a/src/tools/qml2puppet/mockfiles/qt6/HelperGrid.qml b/src/tools/qml2puppet/mockfiles/qt6/HelperGrid.qml index 2a7f921ffe2..e9d94b54c18 100644 --- a/src/tools/qml2puppet/mockfiles/qt6/HelperGrid.qml +++ b/src/tools/qml2puppet/mockfiles/qt6/HelperGrid.qml @@ -13,9 +13,8 @@ Node { property bool orthoMode: false property double distance: 500 - readonly property int minGridStep: 50 - readonly property int maxGridStep: 32 * minGridStep - readonly property int gridArea: minGridStep * 512 + readonly property int maxGridStep: 32 * _generalHelper.minGridStep + readonly property int gridArea: _generalHelper.minGridStep * 512 // Step of the main lines of the grid, between those is always one subdiv line property int gridStep: 100 @@ -32,12 +31,13 @@ Node { return Math.atan(step / distance) } - onDistanceChanged: { + function calcStep() + { if (distance === 0) return // Calculate new grid step - let newStep = gridStep + let newStep = _generalHelper.minGridStep let gridRad = calcRad(newStep) while (gridRad < minGridRad && newStep < maxGridStep) { newStep *= 2 @@ -45,16 +45,13 @@ Node { newStep = maxGridStep gridRad = calcRad(newStep) } - while (gridRad > minGridRad * 2 && newStep > minGridStep) { - newStep /= 2 - if (newStep < minGridStep) - newStep = minGridStep - gridRad = calcRad(newStep) - } gridStep = newStep subGridMaterial.generalAlpha = Math.min(1, 2 * (1 - (minGridRad / gridRad))) } + onMaxGridStepChanged: calcStep() + onDistanceChanged: calcStep() + // Note: Only one instance of HelperGrid is supported, as the geometry names are fixed Model { // Main grid lines diff --git a/src/tools/qml2puppet/mockfiles/shaders/gridmaterial.frag b/src/tools/qml2puppet/mockfiles/shaders/gridmaterial.frag index 6ec50859028..a1ec3bffff2 100644 --- a/src/tools/qml2puppet/mockfiles/shaders/gridmaterial.frag +++ b/src/tools/qml2puppet/mockfiles/shaders/gridmaterial.frag @@ -14,6 +14,11 @@ void MAIN() float cosAngle = dot(normalize(camDir), normalize(camLevel)); float angleDepth = density * pow(cosAngle, 8); float alpha = generalAlpha * clamp((1.0 - ((angleDepth * depth - alphaStartDepth) / (alphaEndDepth - alphaStartDepth))), 0, 1); + + // Force additional alpha when approaching the far clip of edit camera + if (depth > 90000.0) + alpha *= clamp((100000.0 - depth) / 10000.0, 0, 1); + if (alpha > 0.01) FRAGCOLOR = vec4(color.x * alpha, color.y * alpha, color.z * alpha, alpha); else diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp index 47f176b4219..e39113d774b 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp @@ -954,6 +954,20 @@ QVector3D GeneralHelper::adjustScaleForSnap(const QVector3D &newScale) return adjScale; } +void GeneralHelper::setSnapPositionInterval(double interval) +{ + if (m_snapPositionInterval != interval) { + m_snapPositionInterval = interval; + emit minGridStepChanged(); + } +} + +double GeneralHelper::minGridStep() const +{ + // Minimum grid step is a multiple of snap interval, as the last step is divided to subgrid + return 2. * m_snapPositionInterval; +} + void GeneralHelper::setBgColor(const QVariant &colors) { if (m_bgColor != colors) { diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h index a80ab516ae2..8daa10d2ce6 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h @@ -33,6 +33,7 @@ class GeneralHelper : public QObject Q_OBJECT Q_PROPERTY(bool isMacOS READ isMacOS CONSTANT) Q_PROPERTY(QVariant bgColor READ bgColor NOTIFY bgColorChanged FINAL) + Q_PROPERTY(double minGridStep READ minGridStep NOTIFY minGridStepChanged FINAL) public: GeneralHelper(); @@ -114,10 +115,12 @@ public: void setSnapPosition(bool enable) { m_snapPosition = enable; } void setSnapRotation(bool enable) { m_snapRotation = enable; } void setSnapScale(bool enable) { m_snapScale = enable; } - void setSnapPositionInterval(double interval) { m_snapPositionInterval = interval; } + void setSnapPositionInterval(double interval); void setSnapRotationInterval(double interval) { m_snapRotationInterval = interval; } void setSnapScaleInterval(double interval) { m_snapScaleInterval = interval / 100.; } + double minGridStep() const; + void setBgColor(const QVariant &colors); QVariant bgColor() const { return m_bgColor; } @@ -128,6 +131,8 @@ signals: void lockedStateChanged(QQuick3DNode *node); void rotationBlocksChanged(); void bgColorChanged(); + void minGridStepChanged(); + private: void handlePendingToolStateUpdate(); QVector3D pivotScenePosition(QQuick3DNode *node) const;