QmlDesigner: Apply root item transform in Node component previews

When generating a preview from a component with a 3D node for a root,
the root Node transform is now applied when calculating camera zoom.

Fixes: QDS-7131
Change-Id: I73054a09b3e82868c999ef6f9797dc941e625b33
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-06-10 15:23:16 +03:00
parent 36dbc62a1d
commit dedbbc75b5
4 changed files with 6 additions and 6 deletions

View File

@@ -37,7 +37,7 @@ View3D {
function fitToViewPort(closeUp)
{
// The magic number is the distance from camera default pos to origin
_generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, sourceModel, root,
_generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, model, root,
1040, closeUp);
}

View File

@@ -37,7 +37,7 @@ View3D {
function fitToViewPort(closeUp)
{
// The magic number is the distance from camera default pos to origin
_generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, sourceModel, root,
_generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, model, root,
1040, closeUp);
}

View File

@@ -812,7 +812,7 @@ QVector3D GeneralHelper::pivotScenePosition(QQuick3DNode *node) const
// Calculate bounds for given node, including all child nodes.
// Returns true if the tree contains at least one Model node.
bool GeneralHelper::getBounds(QQuick3DViewport *view3D, QQuick3DNode *node, QVector3D &minBounds,
QVector3D &maxBounds, bool recursive)
QVector3D &maxBounds)
{
if (!node) {
const float halfExtent = 100.f;
@@ -825,7 +825,7 @@ bool GeneralHelper::getBounds(QQuick3DViewport *view3D, QQuick3DNode *node, QVec
auto nodePriv = QQuick3DObjectPrivate::get(node);
auto renderNode = static_cast<QSSGRenderNode *>(nodePriv->spatialNode);
if (recursive && renderNode) {
if (renderNode) {
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
if (renderNode->flags.testFlag(QSSGRenderNode::Flag::TransformDirty))
renderNode->calculateLocalTransform();
@@ -850,7 +850,7 @@ bool GeneralHelper::getBounds(QQuick3DViewport *view3D, QQuick3DNode *node, QVec
if (auto childNode = qobject_cast<QQuick3DNode *>(child)) {
QVector3D newMinBounds = minBounds;
QVector3D newMaxBounds = maxBounds;
bool childHasModel = getBounds(view3D, childNode, newMinBounds, newMaxBounds, true);
bool childHasModel = getBounds(view3D, childNode, newMinBounds, newMaxBounds);
// Ignore any subtrees that do not have Model in them as we don't need those
// for visual bounds calculations
if (childHasModel) {

View File

@@ -130,7 +130,7 @@ private:
void handlePendingToolStateUpdate();
QVector3D pivotScenePosition(QQuick3DNode *node) const;
bool getBounds(QQuick3DViewport *view3D, QQuick3DNode *node, QVector3D &minBounds,
QVector3D &maxBounds, bool recursive = false);
QVector3D &maxBounds);
QTimer m_overlayUpdateTimer;
QTimer m_toolStateUpdateTimer;