diff --git a/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h b/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h index 6e25b3b419c..58166516c80 100644 --- a/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h +++ b/src/libs/qmlpuppetcommunication/interfaces/nodeinstanceglobal.h @@ -44,7 +44,7 @@ enum class View3DActionType { ParticlesPlay, ParticlesRestart, ParticlesSeek, - SyncBackgroundColor, + SyncEnvBackground, GetNodeAtPos, SetBakeLightsView3D }; diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp index bb1b3e74985..fc81eef4797 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.cpp @@ -120,7 +120,7 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState) const QString cameraFrustumKey = QStringLiteral("showCameraFrustum"); const QString particleEmitterKey = QStringLiteral("showParticleEmitter"); const QString particlesPlayKey = QStringLiteral("particlePlay"); - const QString syncBgColorKey = QStringLiteral("syncBackgroundColor"); + const QString syncEnvBgKey = QStringLiteral("syncEnvBackground"); if (sceneState.contains(sceneKey)) { qint32 newActiveScene = sceneState[sceneKey].value(); @@ -195,9 +195,11 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState) bool syncValue = false; bool syncEnabled = false; bool desiredSyncValue = false; - if (sceneState.contains(syncBgColorKey)) - desiredSyncValue = sceneState[syncBgColorKey].toBool(); + if (sceneState.contains(syncEnvBgKey)) + desiredSyncValue = sceneState[syncEnvBgKey].toBool(); ModelNode checkNode = active3DSceneNode(); + const bool activeSceneValid = checkNode.isValid(); + while (checkNode.isValid()) { if (checkNode.metaInfo().isQtQuick3DView3D()) { syncValue = desiredSyncValue; @@ -210,15 +212,15 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState) break; } - if (syncValue != desiredSyncValue) { + if (activeSceneValid && syncValue != desiredSyncValue) { // Update actual toolstate as well if we overrode it. QTimer::singleShot(0, this, [this, syncValue]() { - emitView3DAction(View3DActionType::SyncBackgroundColor, syncValue); + emitView3DAction(View3DActionType::SyncEnvBackground, syncValue); }); } - m_syncBackgroundColorAction->action()->setChecked(syncValue); - m_syncBackgroundColorAction->action()->setEnabled(syncEnabled); + m_syncEnvBackgroundAction->action()->setChecked(syncValue); + m_syncEnvBackgroundAction->action()->setEnabled(syncEnabled); // Selection context change updates visible and enabled states SelectionContext selectionContext(this); @@ -449,23 +451,23 @@ QSize Edit3DView::canvasSize() const return {}; } -void Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorAction) +void Edit3DView::createSelectBackgroundColorAction(QAction *syncEnvBackgroundAction) { QString description = QCoreApplication::translate("SelectBackgroundColorAction", "Select Background Color"); QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction", "Select a color for the background of the 3D view."); - auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { + auto operation = [this, syncEnvBackgroundAction](const SelectionContext &) { BackgroundColorSelection::showBackgroundColorSelectionWidget( edit3DWidget(), DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, this, edit3dBgColorProperty, - [this, syncBackgroundColorAction]() { - if (syncBackgroundColorAction->isChecked()) { - emitView3DAction(View3DActionType::SyncBackgroundColor, false); - syncBackgroundColorAction->setChecked(false); + [this, syncEnvBackgroundAction]() { + if (syncEnvBackgroundAction->isChecked()) { + emitView3DAction(View3DActionType::SyncEnvBackground, false); + syncEnvBackgroundAction->setChecked(false); } }); }; @@ -510,14 +512,14 @@ void Edit3DView::createGridColorSelectionAction() tooltip); } -void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction) +void Edit3DView::createResetColorAction(QAction *syncEnvBackgroundAction) { QString description = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset Colors"); QString tooltip = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset the background color and the color of the " "grid lines of the 3D view to the default values."); - auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { + auto operation = [this, syncEnvBackgroundAction](const SelectionContext &) { QList bgColors = {QRgb(0x222222), QRgb(0x999999)}; Edit3DViewConfig::setColors(this, edit3dBgColorProperty, bgColors); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors); @@ -526,9 +528,9 @@ void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction) Edit3DViewConfig::setColors(this, edit3dGridColorProperty, {gridColor}); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor}); - if (syncBackgroundColorAction->isChecked()) { - emitView3DAction(View3DActionType::SyncBackgroundColor, false); - syncBackgroundColorAction->setChecked(false); + if (syncEnvBackgroundAction->isChecked()) { + emitView3DAction(View3DActionType::SyncEnvBackground, false); + syncEnvBackgroundAction->setChecked(false); } }; @@ -545,17 +547,17 @@ void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction) tooltip); } -void Edit3DView::createSyncBackgroundColorAction() +void Edit3DView::createSyncEnvBackgroundAction() { - QString description = QCoreApplication::translate("SyncEdit3DColorAction", - "Use Scene Environment Color"); - QString tooltip = QCoreApplication::translate("SyncEdit3DColorAction", + QString description = QCoreApplication::translate("SyncEnvBackgroundAction", + "Use Scene Environment"); + QString tooltip = QCoreApplication::translate("SyncEnvBackgroundAction", "Sets the 3D view to use the Scene Environment " - "color as background color."); + "color or skybox as background color."); - m_syncBackgroundColorAction = std::make_unique( - QmlDesigner::Constants::EDIT3D_EDIT_SYNC_BACKGROUND_COLOR, - View3DActionType::SyncBackgroundColor, + m_syncEnvBackgroundAction = std::make_unique( + QmlDesigner::Constants::EDIT3D_EDIT_SYNC_ENV_BACKGROUND, + View3DActionType::SyncEnvBackground, description, QKeySequence(), true, @@ -1026,14 +1028,14 @@ void Edit3DView::createEdit3DActions() m_visibilityToggleActions << m_showCameraFrustumAction.get(); m_visibilityToggleActions << m_showParticleEmitterAction.get(); - createSyncBackgroundColorAction(); - createSelectBackgroundColorAction(m_syncBackgroundColorAction->action()); + createSyncEnvBackgroundAction(); + createSelectBackgroundColorAction(m_syncEnvBackgroundAction->action()); createGridColorSelectionAction(); - createResetColorAction(m_syncBackgroundColorAction->action()); + createResetColorAction(m_syncEnvBackgroundAction->action()); m_backgroundColorActions << m_selectBackgroundColorAction.get(); m_backgroundColorActions << m_selectGridColorAction.get(); - m_backgroundColorActions << m_syncBackgroundColorAction.get(); + m_backgroundColorActions << m_syncEnvBackgroundAction.get(); m_backgroundColorActions << m_resetColorAction.get(); } diff --git a/src/plugins/qmldesigner/components/edit3d/edit3dview.h b/src/plugins/qmldesigner/components/edit3d/edit3dview.h index 2b2bd57d93f..2fb1e0451cd 100644 --- a/src/plugins/qmldesigner/components/edit3d/edit3dview.h +++ b/src/plugins/qmldesigner/components/edit3d/edit3dview.h @@ -101,10 +101,10 @@ private: void showMaterialPropertiesView(); void updateAlignActionStates(); - void createSelectBackgroundColorAction(QAction *syncBackgroundColorAction); + void createSelectBackgroundColorAction(QAction *syncEnvBackgroundAction); void createGridColorSelectionAction(); - void createResetColorAction(QAction *syncBackgroundColorAction); - void createSyncBackgroundColorAction(); + void createResetColorAction(QAction *syncEnvBackgroundAction); + void createSyncEnvBackgroundAction(); void createSeekerSliderAction(); QPoint resolveToolbarPopupPos(Edit3DAction *action) const; @@ -135,7 +135,7 @@ private: std::unique_ptr m_particlesPlayAction; std::unique_ptr m_particlesRestartAction; std::unique_ptr m_seekerAction; - std::unique_ptr m_syncBackgroundColorAction; + std::unique_ptr m_syncEnvBackgroundAction; std::unique_ptr m_selectBackgroundColorAction; std::unique_ptr m_selectGridColorAction; std::unique_ptr m_resetColorAction; diff --git a/src/plugins/qmldesigner/qmldesignerconstants.h b/src/plugins/qmldesigner/qmldesignerconstants.h index ec29c3726a9..4ca8b1ea923 100644 --- a/src/plugins/qmldesigner/qmldesignerconstants.h +++ b/src/plugins/qmldesigner/qmldesignerconstants.h @@ -52,7 +52,7 @@ const char EDIT3D_EDIT_SHOW_GRID[] = "QmlDesigner.Editor3D.ToggleGrid"; const char EDIT3D_EDIT_SELECT_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.SelectBackgroundColor"; const char EDIT3D_EDIT_SELECT_GRID_COLOR[] = "QmlDesigner.Editor3D.SelectGridColor"; const char EDIT3D_EDIT_RESET_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.ResetBackgroundColor"; -const char EDIT3D_EDIT_SYNC_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.SyncBackgroundColor"; +const char EDIT3D_EDIT_SYNC_ENV_BACKGROUND[] = "QmlDesigner.Editor3D.SyncEnvBackground"; const char EDIT3D_EDIT_SHOW_SELECTION_BOX[] = "QmlDesigner.Editor3D.ToggleSelectionBox"; const char EDIT3D_EDIT_SHOW_ICON_GIZMO[] = "QmlDesigner.Editor3D.ToggleIconGizmo"; const char EDIT3D_EDIT_SHOW_CAMERA_FRUSTUM[] = "QmlDesigner.Editor3D.ToggleCameraFrustum"; diff --git a/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml b/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml index 71c5e4d81e7..a44a2a75d2d 100644 --- a/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml +++ b/src/tools/qml2puppet/mockfiles/qt6/EditView3D.qml @@ -27,7 +27,7 @@ Item { property color backgroundGradientColorStart: "#222222" property color backgroundGradientColorEnd: "#999999" property color gridColor: "#cccccc" - property bool syncBackgroundColor: false + property bool syncEnvBackground: false enum SelectionMode { Item, Group } enum TransformMode { Move, Rotate, Scale } @@ -58,7 +58,7 @@ Item { onShowEditLightChanged: _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) onGlobalOrientationChanged: _generalHelper.storeToolState(sceneId, "globalOrientation", globalOrientation) onShowGridChanged: _generalHelper.storeToolState(sceneId, "showGrid", showGrid); - onSyncBackgroundColorChanged: _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor); + onSyncEnvBackgroundChanged: _generalHelper.storeToolState(sceneId, "syncEnvBackground", syncEnvBackground); onShowSelectionBoxChanged: _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox); onShowIconGizmoChanged: _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo); onShowCameraFrustumChanged: _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum); @@ -136,10 +136,7 @@ Item { } } - if (syncBackgroundColor) - updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]); - else - updateBackgroundColors(_generalHelper.bgColor); + updateEnvBackground(); notifyActiveSceneChange(); } @@ -206,6 +203,31 @@ Item { } } + function updateEnvBackground() { + updateBackgroundColors(_generalHelper.bgColor); + + if (!editView) + return; + + if (syncEnvBackground) { + let bgMode = _generalHelper.sceneEnvironmentBgMode(sceneId); + if ((!_generalHelper.sceneEnvironmentLightProbe(sceneId) && bgMode === SceneEnvironment.SkyBox) + || (!_generalHelper.sceneEnvironmentSkyBoxCubeMap(sceneId) && bgMode === SceneEnvironment.SkyBoxCubeMap)) { + editView.sceneEnv.backgroundMode = SceneEnvironment.Color; + } else { + editView.sceneEnv.backgroundMode = bgMode; + } + editView.sceneEnv.lightProbe = _generalHelper.sceneEnvironmentLightProbe(sceneId); + editView.sceneEnv.skyBoxCubeMap = _generalHelper.sceneEnvironmentSkyBoxCubeMap(sceneId); + editView.sceneEnv.clearColor = _generalHelper.sceneEnvironmentColor(sceneId); + } else { + editView.sceneEnv.backgroundMode = SceneEnvironment.Transparent; + editView.sceneEnv.lightProbe = null; + editView.sceneEnv.skyBoxCubeMap = null; + editView.sceneEnv.clearColor = "transparent"; + } + } + // If resetToDefault is true, tool states not specifically set to anything will be reset to // their default state. function updateToolStates(toolStates, resetToDefault) @@ -220,15 +242,12 @@ Item { else if (resetToDefault) showGrid = true; - if ("syncBackgroundColor" in toolStates) { - syncBackgroundColor = toolStates.syncBackgroundColor; - if (syncBackgroundColor) - updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]); - else - updateBackgroundColors(_generalHelper.bgColor); + if ("syncEnvBackground" in toolStates) { + syncEnvBackground = toolStates.syncEnvBackground; + updateEnvBackground(); } else if (resetToDefault) { - syncBackgroundColor = false; - updateBackgroundColors(_generalHelper.bgColor); + syncEnvBackground = false; + updateEnvBackground(); } if ("showSelectionBox" in toolStates) @@ -281,7 +300,7 @@ Item { { _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) _generalHelper.storeToolState(sceneId, "showGrid", showGrid) - _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor) + _generalHelper.storeToolState(sceneId, "syncEnvBackground", syncEnvBackground) _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox) _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo) _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum) @@ -697,6 +716,7 @@ Item { } } } + function onHiddenStateChanged(node) { for (var i = 0; i < cameraGizmos.length; ++i) { @@ -727,11 +747,16 @@ Item { } } } + function onUpdateDragTooltip() { gizmoLabel.updateLabel(); rotateGizmoLabel.updateLabel(); } + + function onSceneEnvDataChanged() { + updateEnvBackground(); + } } Node { diff --git a/src/tools/qml2puppet/mockfiles/qt6/SceneView3D.qml b/src/tools/qml2puppet/mockfiles/qt6/SceneView3D.qml index e3f585de545..0eafeeb816e 100644 --- a/src/tools/qml2puppet/mockfiles/qt6/SceneView3D.qml +++ b/src/tools/qml2puppet/mockfiles/qt6/SceneView3D.qml @@ -15,6 +15,7 @@ View3D { property alias sceneHelpers: sceneHelpers property alias perspectiveCamera: scenePerspectiveCamera property alias orthoCamera: sceneOrthoCamera + property alias sceneEnv: sceneEnv property vector3d cameraLookAt // Measuring the distance from camera to lookAt plus the distance of lookAt from grid plane diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp index 86267874110..6f419fdf410 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.cpp @@ -57,6 +57,10 @@ GeneralHelper::GeneralHelper() m_toolStateUpdateTimer.setSingleShot(true); QObject::connect(&m_toolStateUpdateTimer, &QTimer::timeout, this, &GeneralHelper::handlePendingToolStateUpdate); + + QList defaultBg; + defaultBg.append(QColor()); + m_bgColor = QVariant::fromValue(defaultBg); } void GeneralHelper::requestOverlayUpdate() @@ -540,19 +544,62 @@ void GeneralHelper::storeToolState(const QString &sceneId, const QString &tool, } } -void GeneralHelper::setSceneEnvironmentColor(const QString &sceneId, const QColor &color) +void GeneralHelper::setSceneEnvironmentData(const QString &sceneId, + QQuick3DSceneEnvironment *env) { - m_sceneEnvironmentColor[sceneId] = color; + if (env) { + SceneEnvData &data = m_sceneEnvironmentData[sceneId]; + data.backgroundMode = env->backgroundMode(); + data.clearColor = env->clearColor(); + + if (data.lightProbe) + disconnect(data.lightProbe, &QObject::destroyed, this, &GeneralHelper::sceneEnvDataChanged); + data.lightProbe = env->lightProbe(); + if (env->lightProbe()) + connect(env->lightProbe(), &QObject::destroyed, this, &GeneralHelper::sceneEnvDataChanged, Qt::DirectConnection); + + if (data.skyBoxCubeMap) + disconnect(data.skyBoxCubeMap, &QObject::destroyed, this, &GeneralHelper::sceneEnvDataChanged); + data.skyBoxCubeMap = env->skyBoxCubeMap(); + if (env->skyBoxCubeMap()) + connect(env->skyBoxCubeMap(), &QObject::destroyed, this, &GeneralHelper::sceneEnvDataChanged, Qt::DirectConnection); + + emit sceneEnvDataChanged(); + } +} + +QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes GeneralHelper::sceneEnvironmentBgMode( + const QString &sceneId) const +{ + return m_sceneEnvironmentData[sceneId].backgroundMode; } QColor GeneralHelper::sceneEnvironmentColor(const QString &sceneId) const { - return m_sceneEnvironmentColor[sceneId]; + return m_sceneEnvironmentData[sceneId].clearColor; } -void GeneralHelper::clearSceneEnvironmentColors() +QQuick3DTexture *GeneralHelper::sceneEnvironmentLightProbe(const QString &sceneId) const { - m_sceneEnvironmentColor.clear(); + return m_sceneEnvironmentData[sceneId].lightProbe.data(); +} + +QQuick3DCubeMapTexture *GeneralHelper::sceneEnvironmentSkyBoxCubeMap(const QString &sceneId) const +{ + return m_sceneEnvironmentData[sceneId].skyBoxCubeMap.data(); +} + +void GeneralHelper::clearSceneEnvironmentData() +{ + for (const SceneEnvData &data : std::as_const(m_sceneEnvironmentData)) { + if (data.lightProbe) + disconnect(data.lightProbe, &QObject::destroyed, this, &GeneralHelper::sceneEnvDataChanged); + if (data.skyBoxCubeMap) + disconnect(data.skyBoxCubeMap, &QObject::destroyed, this, &GeneralHelper::sceneEnvDataChanged); + } + + m_sceneEnvironmentData.clear(); + emit sceneEnvDataChanged(); } void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates) diff --git a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h index e44c2c60ce9..9e54250201a 100644 --- a/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h +++ b/src/tools/qml2puppet/qml2puppet/editor3d/generalhelper.h @@ -15,7 +15,10 @@ #include #include #include +#include #include +#include +#include QT_BEGIN_NAMESPACE class QQuick3DCamera; @@ -92,9 +95,13 @@ public: Q_INVOKABLE void scaleMultiSelection(bool commit); Q_INVOKABLE void rotateMultiSelection(bool commit); - void setSceneEnvironmentColor(const QString &sceneId, const QColor &color); + void setSceneEnvironmentData(const QString &sceneId, QQuick3DSceneEnvironment *env); + Q_INVOKABLE QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes sceneEnvironmentBgMode( + const QString &sceneId) const; Q_INVOKABLE QColor sceneEnvironmentColor(const QString &sceneId) const; - void clearSceneEnvironmentColors(); + Q_INVOKABLE QQuick3DTexture *sceneEnvironmentLightProbe(const QString &sceneId) const; + Q_INVOKABLE QQuick3DCubeMapTexture *sceneEnvironmentSkyBoxCubeMap(const QString &sceneId) const; + void clearSceneEnvironmentData(); bool isMacOS() const; @@ -137,6 +144,7 @@ signals: void bgColorChanged(); void minGridStepChanged(); void updateDragTooltip(); + void sceneEnvDataChanged(); private: void handlePendingToolStateUpdate(); @@ -150,9 +158,16 @@ private: QTimer m_toolStateUpdateTimer; QHash m_toolStates; QHash m_toolStatesPending; - QHash m_sceneEnvironmentColor; QSet m_rotationBlockedNodes; + struct SceneEnvData { + QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes backgroundMode; + QColor clearColor; + QPointer lightProbe; + QPointer skyBoxCubeMap; + }; + QHash m_sceneEnvironmentData; + struct MultiSelData { QVector3D startScenePos; QVector3D startScale; diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index ea052aa426c..d05de5635b0 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -385,10 +385,9 @@ void Qt5InformationNodeInstanceServer::updateColorSettings( QQmlProperty gridProp(m_editView3DData.rootItem, "gridColor", context()); gridProp.write(container.value()); } else if (container.name() == "edit3dBgColor") { - QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors", - Q_ARG(QVariant, container.value())); if (auto helper = qobject_cast(m_3dHelper)) helper->setBgColor(container.value()); + QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateEnvBackground"); } } } @@ -1066,7 +1065,7 @@ void Qt5InformationNodeInstanceServer::resolveSceneRoots() ++it; } - updateSceneEnvColorsToHelper(); + updateSceneEnvToHelper(); if (updateActiveScene) { m_active3DView = findView3DForSceneRoot(m_active3DScene); @@ -1912,7 +1911,7 @@ void Qt5InformationNodeInstanceServer::setup3DEditView( m_editView3DSetupDone = true; - updateSceneEnvColorsToHelper(); + updateSceneEnvToHelper(); if (toolStates.contains({})) { // Update tool state to an existing no-scene state before updating the active scene to @@ -2232,15 +2231,15 @@ void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionComm render3DEditView(2); } -void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor( - [[maybe_unused]] const PropertyValueContainer &container) +void Qt5InformationNodeInstanceServer::setSceneEnvironmentData( + [[maybe_unused]] qint32 instanceId) { #ifdef QUICK3D_MODULE auto helper = qobject_cast(m_3dHelper); - if (!helper || !hasInstanceForId(container.instanceId()) || !m_active3DView) + if (!helper || !hasInstanceForId(instanceId) || !m_active3DView) return; - ServerNodeInstance sceneEnvInstance = instanceForId(container.instanceId()); + ServerNodeInstance sceneEnvInstance = instanceForId(instanceId); if (!sceneEnvInstance.isSubclassOf("QQuick3DSceneEnvironment")) return; @@ -2255,17 +2254,14 @@ void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor( ServerNodeInstance activeSceneInstance = active3DSceneInstance(); const QString sceneId = activeSceneInstance.id(); - QColor color = container.value().value(); - helper->setSceneEnvironmentColor(sceneId, color); + helper->setSceneEnvironmentData(sceneId, activeEnv); + QVariantMap toolStates = helper->getToolStates(sceneId); - if (toolStates.contains("syncBackgroundColor")) { - bool sync = toolStates["syncBackgroundColor"].toBool(); - if (sync) { - QList colors{color}; - QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors", - Q_ARG(QVariant, QVariant::fromValue(colors))); - } + if (toolStates.contains("syncEnvBackground")) { + bool sync = toolStates["syncEnvBackground"].toBool(); + if (sync) + QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateEnvBackground"); } #endif } @@ -2308,15 +2304,15 @@ QVariantList Qt5InformationNodeInstanceServer::alignCameraList() const return cameras; } -void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper() +void Qt5InformationNodeInstanceServer::updateSceneEnvToHelper() { #ifdef QUICK3D_MODULE - // Update stored scene environment colors for all scenes + // Update stored scene environment backgrounds for all scenes auto helper = qobject_cast(m_3dHelper); if (!helper) return; - helper->clearSceneEnvironmentColors(); + helper->clearSceneEnvironmentData(); const auto sceneRoots = m_3DSceneMap.uniqueKeys(); for (QObject *sceneRoot : sceneRoots) { @@ -2328,32 +2324,36 @@ void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper() if (!env) continue; - QColor clearColor = env->clearColor(); - if (clearColor.isValid() && helper) { - ServerNodeInstance sceneInstance; - if (hasInstanceForObject(sceneRoot)) - sceneInstance = instanceForObject(sceneRoot); - else if (hasInstanceForObject(view3D)) - sceneInstance = instanceForObject(view3D); + ServerNodeInstance sceneInstance; + if (hasInstanceForObject(sceneRoot)) + sceneInstance = instanceForObject(sceneRoot); + else if (hasInstanceForObject(view3D)) + sceneInstance = instanceForObject(view3D); - const QString sceneId = sceneInstance.id(); + const QString sceneId = sceneInstance.id(); - helper->setSceneEnvironmentColor(sceneId, clearColor); - } + helper->setSceneEnvironmentData(sceneId, env); } #endif } +bool Qt5InformationNodeInstanceServer::isSceneEnvironmentBgProperty(const PropertyName &name) const +{ + return name == "backgroundMode" || name == "clearColor" + || name == "lightProbe" || name == "skyBoxCubeMap"; +} + void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) { bool hasDynamicProperties = false; const QVector values = command.valueChanges(); + QSet sceneEnvs; for (const PropertyValueContainer &container : values) { if (!container.isReflected()) { hasDynamicProperties |= container.isDynamic(); - if (container.name() == "clearColor") - setSceneEnvironmentColor(container); + if (isSceneEnvironmentBgProperty(container.name())) + sceneEnvs.insert(container.instanceId()); setInstancePropertyVariant(container); } @@ -2362,6 +2362,9 @@ void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCo if (hasDynamicProperties) refreshBindings(); + for (const qint32 id : std::as_const(sceneEnvs)) + setSceneEnvironmentData(id); + startRenderTimer(); render3DEditView(); @@ -2455,8 +2458,8 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c case View3DActionType::ShowCameraFrustum: updatedToolState.insert("showCameraFrustum", command.isEnabled()); break; - case View3DActionType::SyncBackgroundColor: - updatedToolState.insert("syncBackgroundColor", command.isEnabled()); + case View3DActionType::SyncEnvBackground: + updatedToolState.insert("syncEnvBackground", command.isEnabled()); break; #ifdef QUICK3D_PARTICLES_MODULE case View3DActionType::ShowParticleEmitter: @@ -2530,6 +2533,16 @@ void Qt5InformationNodeInstanceServer::changeAuxiliaryValues(const ChangeAuxilia void Qt5InformationNodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command) { Qt5NodeInstanceServer::changePropertyBindings(command); + + QSet sceneEnvs; + for (const PropertyBindingContainer &container : std::as_const(command.bindingChanges)) { + if (isSceneEnvironmentBgProperty(container.name())) + sceneEnvs.insert(container.instanceId()); + } + + for (const qint32 id : std::as_const(sceneEnvs)) + setSceneEnvironmentData(id); + render3DEditView(); } @@ -2570,15 +2583,18 @@ void Qt5InformationNodeInstanceServer::changeState(const ChangeStateCommand &com void Qt5InformationNodeInstanceServer::removeProperties(const RemovePropertiesCommand &command) { const QVector props = command.properties(); + QSet sceneEnvs; + for (const PropertyAbstractContainer &container : props) { - if (container.name() == "clearColor") { - setSceneEnvironmentColor(PropertyValueContainer(container.instanceId(), - container.name(), {}, {})); - } + if (isSceneEnvironmentBgProperty(container.name())) + sceneEnvs.insert(container.instanceId()); } Qt5NodeInstanceServer::removeProperties(command); + for (const qint32 id : std::as_const(sceneEnvs)) + setSceneEnvironmentData(id); + render3DEditView(); } diff --git a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index c774bc8f33f..3ac044cbace 100644 --- a/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/src/tools/qml2puppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -136,9 +136,10 @@ private: void resetParticleSystem(); void handleParticleSystemDeselected(); #endif - void setSceneEnvironmentColor(const PropertyValueContainer &container); + void setSceneEnvironmentData(qint32 instanceId); QVariantList alignCameraList() const; - void updateSceneEnvColorsToHelper(); + void updateSceneEnvToHelper(); + bool isSceneEnvironmentBgProperty(const PropertyName &name) const; RenderViewData m_editView3DData; RenderViewData m_modelNode3DImageViewData;