Scale rootNode by 100

Also adds support for rootNode scaling

Fixes: QTBUG-132925
Change-Id: If9be83def9532779762da2aab89d411705bfba7d
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
(cherry picked from commit f318db38b7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Sakaria Pouke 2025-01-29 14:13:07 +02:00 committed by Qt Cherry-pick Bot
parent 9d6edfb25b
commit 9e93bf6e81
16 changed files with 28 additions and 13 deletions

View File

@ -20,7 +20,7 @@ void MAIN()
if (valueColoring) if (valueColoring)
gradientUV = vec2(heightValue, 0); gradientUV = vec2(heightValue, 0);
else else
gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0);
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
break; break;
} }

View File

@ -28,7 +28,7 @@ void MAIN()
if (valueColoring) if (valueColoring)
gradientUV = vec2(heightValue, 0); gradientUV = vec2(heightValue, 0);
else else
gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0);
color = texture(custex, gradientUV).xyz; color = texture(custex, gradientUV).xyz;
alpha = texture(custex, gradientUV).w; alpha = texture(custex, gradientUV).w;
break; break;

View File

@ -23,7 +23,7 @@ void MAIN()
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
break; break;
case 2: // Range gradient case 2: // Range gradient
vec2 gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); vec2 gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0);
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
break; break;
} }

View File

@ -24,7 +24,7 @@ void MAIN()
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
break; break;
case 2: // Range gradient case 2: // Range gradient
vec2 gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); vec2 gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0);
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
if (!usePoint) if (!usePoint)
color = vColor; color = vColor;

View File

@ -6,7 +6,7 @@ VARYING vec2 UV;
void MAIN() void MAIN()
{ {
if (any(greaterThan(UV, vec2(1.01))) || abs(VAR_WORLD_POSITION.y) > graphHeight) if (any(greaterThan(UV, vec2(1.01))) || abs(pos.y) > graphHeight)
discard; discard;
vec4 color; vec4 color;
vec2 gradientUV; vec2 gradientUV;
@ -16,7 +16,7 @@ void MAIN()
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
break; break;
case 1: //Range gradient case 1: //Range gradient
gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0);
color = texture(custex, gradientUV); color = texture(custex, gradientUV);
break; break;
case 2: // Uniform color case 2: // Uniform color

View File

@ -1,7 +1,8 @@
vec4 color; vec4 color;
VARYING vec3 pos;
void MAIN() void MAIN()
{ {
if (abs(VAR_WORLD_POSITION.y) > graphHeight) if (abs(pos.y) > graphHeight)
discard; discard;
color = gridColor; color = gridColor;
} }

View File

@ -1,6 +1,8 @@
VARYING vec3 pos;
void MAIN() void MAIN()
{ {
vec2 UV = UV0 * (vertices / range); vec2 UV = UV0 * (vertices / range);
VERTEX = texture(height, UV).rgb; VERTEX = texture(height, UV).rgb;
pos = VERTEX;
POSITION = MODELVIEWPROJECTION_MATRIX * vec4(VERTEX, 1.0); POSITION = MODELVIEWPROJECTION_MATRIX * vec4(VERTEX, 1.0);
} }

View File

@ -1796,6 +1796,7 @@ void QQuickGraphsBars::updateBarVisuals(QBar3DSeries *series)
QQmlListReference materialsRef(barList.at(i)->model, "materials"); QQmlListReference materialsRef(barList.at(i)->model, "materials");
auto customMaterial = qobject_cast<QQuick3DCustomMaterial *>(materialsRef.at(0)); auto customMaterial = qobject_cast<QQuick3DCustomMaterial *>(materialsRef.at(0));
customMaterial->setProperty("valueColoring", series->isValueColoringEnabled()); customMaterial->setProperty("valueColoring", series->isValueColoringEnabled());
customMaterial->setProperty("rootScale", rootNode()->scale().y());
} }
} }
} }
@ -1861,6 +1862,7 @@ void QQuickGraphsBars::updateMaterialProperties(QQuick3DModel *item,
customMaterial->setProperty("isHighlight", isHighlight || isMultiHighlight); customMaterial->setProperty("isHighlight", isHighlight || isMultiHighlight);
} }
customMaterial->setProperty("specularBrightness", lightStrength() * 0.05); customMaterial->setProperty("specularBrightness", lightStrength() * 0.05);
customMaterial->setProperty("rootScale", rootNode()->scale().y());
} }
void QQuickGraphsBars::removeBarModels() void QQuickGraphsBars::removeBarModels()

View File

@ -1796,6 +1796,8 @@ void QQuickGraphsItem::componentComplete()
{ {
QQuick3DViewport::componentComplete(); QQuick3DViewport::componentComplete();
rootNode()->setScale(QVector3D(100,100,100));
auto url = QUrl(QStringLiteral("defaultMeshes/backgroundMesh")); auto url = QUrl(QStringLiteral("defaultMeshes/backgroundMesh"));
m_background = new QQuick3DModel(); m_background = new QQuick3DModel();
m_backgroundScale = new QQuick3DNode(); m_backgroundScale = new QQuick3DNode();
@ -4234,9 +4236,10 @@ void QQuickGraphsItem::updateItemLabel(QVector3D position)
{ {
if (m_labelPosition != position) if (m_labelPosition != position)
m_labelPosition = position; m_labelPosition = position;
QVector3D pos2d = mapFrom3DScene(m_labelPosition);
QVector3D pos2d = mapFrom3DScene(m_labelPosition * rootNode()->scale().z());
int pointSize = theme()->labelFont().pointSize(); int pointSize = theme()->labelFont().pointSize();
float scale = m_labelScale.x() * ((-10.0f * pointSize) + 650.0f) / pos2d.z(); float scale = m_labelScale.x() * ((-10.0f * pointSize) + 650.0f) / (pos2d.z() / rootNode()->scale().z());
scale = scale < 0 ? -scale : scale; scale = scale < 0 ? -scale : scale;
if (m_sliceView && m_sliceView->isVisible()) if (m_sliceView && m_sliceView->isVisible())
m_itemLabel->setScale(scale * .2f); m_itemLabel->setScale(scale * .2f);
@ -4986,7 +4989,7 @@ void QQuickGraphsItem::updateCamera()
const float scale = qMin(width(), height() * 1.6f); const float scale = qMin(width(), height() * 1.6f);
const float magnificationScaleFactor = 1.0f / 640.0f; const float magnificationScaleFactor = 1.0f / 640.0f;
const float magnification = scale * magnificationScaleFactor; const float magnification = scale * magnificationScaleFactor / rootNode()->scale().x();
auto useOrtho = isOrthoProjection(); auto useOrtho = isOrthoProjection();
if (useOrtho) { if (useOrtho) {
@ -6746,10 +6749,10 @@ void QQuickGraphsItem::setUpCamera()
// By default we could get away with a value of 10 or 15, but as camera zoom is implemented // By default we could get away with a value of 10 or 15, but as camera zoom is implemented
// by moving it, we have to take into account the maximum zoom out level. The other // by moving it, we have to take into account the maximum zoom out level. The other
// option would be to adjust far clip whenever zoom level changes. // option would be to adjust far clip whenever zoom level changes.
const float farclip = 700.f; const float farclip = 7000.f;
m_pCamera = new QQuick3DPerspectiveCamera(rootNode()); m_pCamera = new QQuick3DPerspectiveCamera(rootNode());
m_pCamera->setClipNear(0.001f); m_pCamera->setClipNear(0.1f);
m_pCamera->setClipFar(farclip); m_pCamera->setClipFar(farclip);
m_pCamera->setFieldOfView(45.0f); m_pCamera->setFieldOfView(45.0f);
m_pCamera->setPosition(QVector3D(.0f, .0f, 5.f)); m_pCamera->setPosition(QVector3D(.0f, .0f, 5.f));
@ -6790,7 +6793,6 @@ void QQuickGraphsItem::setUpLight()
*QQuick3DObjectPrivate::get(rootNode())->sceneManager); *QQuick3DObjectPrivate::get(rootNode())->sceneManager);
light->setParent(camera()); light->setParent(camera());
light->setParentItem(camera()); light->setParentItem(camera());
light->setShadowBias(0.1f);
light->setSoftShadowQuality(QQuick3DAbstractLight::QSSGSoftShadowQuality::Hard); light->setSoftShadowQuality(QQuick3DAbstractLight::QSSGSoftShadowQuality::Hard);
m_light = light; m_light = light;
} }

View File

@ -616,6 +616,7 @@ void QQuickGraphsScatter::updateItemMaterial(QQuick3DModel *item,
material->setProperty("colorStyle", 2); material->setProperty("colorStyle", 2);
material->setProperty("usePoint", usePoint); material->setProperty("usePoint", usePoint);
material->setProperty("rootScale", rootNode()->scale().y());
} }
void QQuickGraphsScatter::updateInstancedMaterialProperties(ScatterModel *graphModel, void QQuickGraphsScatter::updateInstancedMaterialProperties(ScatterModel *graphModel,
@ -659,6 +660,7 @@ void QQuickGraphsScatter::updateMaterialProperties(QQuick3DModel *item,
QQmlListReference materialsRef(item, "materials"); QQmlListReference materialsRef(item, "materials");
auto customMaterial = static_cast<QQuick3DCustomMaterial *>(materialsRef.at(0)); auto customMaterial = static_cast<QQuick3DCustomMaterial *>(materialsRef.at(0));
customMaterial->setProperty("transparency", transparency); customMaterial->setProperty("transparency", transparency);
customMaterial->setProperty("rootScale", rootNode()->scale().y());
int style = customMaterial->property("colorStyle").value<int>(); int style = customMaterial->property("colorStyle").value<int>();
if (style == 0) { if (style == 0) {

View File

@ -1776,6 +1776,7 @@ void QQuickGraphsSurface::updateMaterial(SurfaceModel *model)
texInput->texture()->setSource(QUrl()); texInput->texture()->setSource(QUrl());
} }
} }
material->setProperty("rootScale", rootNode()->scale().y());
material->setProperty("hasTransparency", hasTransparency); material->setProperty("hasTransparency", hasTransparency);
material->update(); material->update();
} }

View File

@ -13,6 +13,7 @@ CustomMaterial {
property bool valueColoring property bool valueColoring
property real heightValue property real heightValue
property real rootScale
property real specularBrightness: 0.25 property real specularBrightness: 0.25
readonly property real shininess: (1.0 - specularBrightness) * 100 readonly property real shininess: (1.0 - specularBrightness) * 100

View File

@ -11,6 +11,7 @@ CustomMaterial {
property bool isHighlight property bool isHighlight
property bool instancing property bool instancing
property bool transparency: false property bool transparency: false
property real rootScale
property bool valueColoring property bool valueColoring

View File

@ -11,6 +11,7 @@ CustomMaterial {
property color uColor property color uColor
property bool usePoint property bool usePoint
property bool transparency: false property bool transparency: false
property real rootScale
property real specularBrightness: 0.25 property real specularBrightness: 0.25
readonly property real shininess: (1.0 - specularBrightness) * 100 readonly property real shininess: (1.0 - specularBrightness) * 100

View File

@ -11,6 +11,7 @@ CustomMaterial {
property color uColor property color uColor
property bool usePoint property bool usePoint
property bool transparency: false property bool transparency: false
property real rootScale
property real specularBrightness: 0.25 property real specularBrightness: 0.25
readonly property real shininess: (1.0 - specularBrightness) * 100 readonly property real shininess: (1.0 - specularBrightness) * 100

View File

@ -15,6 +15,7 @@ CustomMaterial {
property vector2d uvOffset property vector2d uvOffset
property vector2d size property vector2d size
property vector2d vertCount property vector2d vertCount
property real rootScale
property real gradientMin property real gradientMin
property real gradientHeight property real gradientHeight