QmlDesigner: Sync also skybox for scene environment in 3D view

If scene environment sync is specified for the 3D view background, we
now sync also skybox instead of just the clear color.

Fixes: QDS-10775
Change-Id: I3e8bd3b8155a4fbe476ca348761d56955a62f7c4
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-09-28 16:21:38 +03:00
parent dd47104d20
commit 00cef940c0
10 changed files with 206 additions and 99 deletions

View File

@@ -44,7 +44,7 @@ enum class View3DActionType {
ParticlesPlay, ParticlesPlay,
ParticlesRestart, ParticlesRestart,
ParticlesSeek, ParticlesSeek,
SyncBackgroundColor, SyncEnvBackground,
GetNodeAtPos, GetNodeAtPos,
SetBakeLightsView3D SetBakeLightsView3D
}; };

View File

@@ -120,7 +120,7 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState)
const QString cameraFrustumKey = QStringLiteral("showCameraFrustum"); const QString cameraFrustumKey = QStringLiteral("showCameraFrustum");
const QString particleEmitterKey = QStringLiteral("showParticleEmitter"); const QString particleEmitterKey = QStringLiteral("showParticleEmitter");
const QString particlesPlayKey = QStringLiteral("particlePlay"); const QString particlesPlayKey = QStringLiteral("particlePlay");
const QString syncBgColorKey = QStringLiteral("syncBackgroundColor"); const QString syncEnvBgKey = QStringLiteral("syncEnvBackground");
if (sceneState.contains(sceneKey)) { if (sceneState.contains(sceneKey)) {
qint32 newActiveScene = sceneState[sceneKey].value<qint32>(); qint32 newActiveScene = sceneState[sceneKey].value<qint32>();
@@ -195,9 +195,11 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState)
bool syncValue = false; bool syncValue = false;
bool syncEnabled = false; bool syncEnabled = false;
bool desiredSyncValue = false; bool desiredSyncValue = false;
if (sceneState.contains(syncBgColorKey)) if (sceneState.contains(syncEnvBgKey))
desiredSyncValue = sceneState[syncBgColorKey].toBool(); desiredSyncValue = sceneState[syncEnvBgKey].toBool();
ModelNode checkNode = active3DSceneNode(); ModelNode checkNode = active3DSceneNode();
const bool activeSceneValid = checkNode.isValid();
while (checkNode.isValid()) { while (checkNode.isValid()) {
if (checkNode.metaInfo().isQtQuick3DView3D()) { if (checkNode.metaInfo().isQtQuick3DView3D()) {
syncValue = desiredSyncValue; syncValue = desiredSyncValue;
@@ -210,15 +212,15 @@ void Edit3DView::updateActiveScene3D(const QVariantMap &sceneState)
break; break;
} }
if (syncValue != desiredSyncValue) { if (activeSceneValid && syncValue != desiredSyncValue) {
// Update actual toolstate as well if we overrode it. // Update actual toolstate as well if we overrode it.
QTimer::singleShot(0, this, [this, syncValue]() { QTimer::singleShot(0, this, [this, syncValue]() {
emitView3DAction(View3DActionType::SyncBackgroundColor, syncValue); emitView3DAction(View3DActionType::SyncEnvBackground, syncValue);
}); });
} }
m_syncBackgroundColorAction->action()->setChecked(syncValue); m_syncEnvBackgroundAction->action()->setChecked(syncValue);
m_syncBackgroundColorAction->action()->setEnabled(syncEnabled); m_syncEnvBackgroundAction->action()->setEnabled(syncEnabled);
// Selection context change updates visible and enabled states // Selection context change updates visible and enabled states
SelectionContext selectionContext(this); SelectionContext selectionContext(this);
@@ -449,23 +451,23 @@ QSize Edit3DView::canvasSize() const
return {}; return {};
} }
void Edit3DView::createSelectBackgroundColorAction(QAction *syncBackgroundColorAction) void Edit3DView::createSelectBackgroundColorAction(QAction *syncEnvBackgroundAction)
{ {
QString description = QCoreApplication::translate("SelectBackgroundColorAction", QString description = QCoreApplication::translate("SelectBackgroundColorAction",
"Select Background Color"); "Select Background Color");
QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction", QString tooltip = QCoreApplication::translate("SelectBackgroundColorAction",
"Select a color for the background of the 3D view."); "Select a color for the background of the 3D view.");
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { auto operation = [this, syncEnvBackgroundAction](const SelectionContext &) {
BackgroundColorSelection::showBackgroundColorSelectionWidget( BackgroundColorSelection::showBackgroundColorSelectionWidget(
edit3DWidget(), edit3DWidget(),
DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR,
this, this,
edit3dBgColorProperty, edit3dBgColorProperty,
[this, syncBackgroundColorAction]() { [this, syncEnvBackgroundAction]() {
if (syncBackgroundColorAction->isChecked()) { if (syncEnvBackgroundAction->isChecked()) {
emitView3DAction(View3DActionType::SyncBackgroundColor, false); emitView3DAction(View3DActionType::SyncEnvBackground, false);
syncBackgroundColorAction->setChecked(false); syncEnvBackgroundAction->setChecked(false);
} }
}); });
}; };
@@ -510,14 +512,14 @@ void Edit3DView::createGridColorSelectionAction()
tooltip); tooltip);
} }
void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction) void Edit3DView::createResetColorAction(QAction *syncEnvBackgroundAction)
{ {
QString description = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset Colors"); QString description = QCoreApplication::translate("ResetEdit3DColorsAction", "Reset Colors");
QString tooltip = QCoreApplication::translate("ResetEdit3DColorsAction", QString tooltip = QCoreApplication::translate("ResetEdit3DColorsAction",
"Reset the background color and the color of the " "Reset the background color and the color of the "
"grid lines of the 3D view to the default values."); "grid lines of the 3D view to the default values.");
auto operation = [this, syncBackgroundColorAction](const SelectionContext &) { auto operation = [this, syncEnvBackgroundAction](const SelectionContext &) {
QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)}; QList<QColor> bgColors = {QRgb(0x222222), QRgb(0x999999)};
Edit3DViewConfig::setColors(this, edit3dBgColorProperty, bgColors); Edit3DViewConfig::setColors(this, edit3dBgColorProperty, bgColors);
Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_BACKGROUND_COLOR, bgColors);
@@ -526,9 +528,9 @@ void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction)
Edit3DViewConfig::setColors(this, edit3dGridColorProperty, {gridColor}); Edit3DViewConfig::setColors(this, edit3dGridColorProperty, {gridColor});
Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor}); Edit3DViewConfig::saveColors(DesignerSettingsKey::EDIT3DVIEW_GRID_COLOR, {gridColor});
if (syncBackgroundColorAction->isChecked()) { if (syncEnvBackgroundAction->isChecked()) {
emitView3DAction(View3DActionType::SyncBackgroundColor, false); emitView3DAction(View3DActionType::SyncEnvBackground, false);
syncBackgroundColorAction->setChecked(false); syncEnvBackgroundAction->setChecked(false);
} }
}; };
@@ -545,17 +547,17 @@ void Edit3DView::createResetColorAction(QAction *syncBackgroundColorAction)
tooltip); tooltip);
} }
void Edit3DView::createSyncBackgroundColorAction() void Edit3DView::createSyncEnvBackgroundAction()
{ {
QString description = QCoreApplication::translate("SyncEdit3DColorAction", QString description = QCoreApplication::translate("SyncEnvBackgroundAction",
"Use Scene Environment Color"); "Use Scene Environment");
QString tooltip = QCoreApplication::translate("SyncEdit3DColorAction", QString tooltip = QCoreApplication::translate("SyncEnvBackgroundAction",
"Sets the 3D view to use the Scene Environment " "Sets the 3D view to use the Scene Environment "
"color as background color."); "color or skybox as background color.");
m_syncBackgroundColorAction = std::make_unique<Edit3DAction>( m_syncEnvBackgroundAction = std::make_unique<Edit3DAction>(
QmlDesigner::Constants::EDIT3D_EDIT_SYNC_BACKGROUND_COLOR, QmlDesigner::Constants::EDIT3D_EDIT_SYNC_ENV_BACKGROUND,
View3DActionType::SyncBackgroundColor, View3DActionType::SyncEnvBackground,
description, description,
QKeySequence(), QKeySequence(),
true, true,
@@ -1026,14 +1028,14 @@ void Edit3DView::createEdit3DActions()
m_visibilityToggleActions << m_showCameraFrustumAction.get(); m_visibilityToggleActions << m_showCameraFrustumAction.get();
m_visibilityToggleActions << m_showParticleEmitterAction.get(); m_visibilityToggleActions << m_showParticleEmitterAction.get();
createSyncBackgroundColorAction(); createSyncEnvBackgroundAction();
createSelectBackgroundColorAction(m_syncBackgroundColorAction->action()); createSelectBackgroundColorAction(m_syncEnvBackgroundAction->action());
createGridColorSelectionAction(); createGridColorSelectionAction();
createResetColorAction(m_syncBackgroundColorAction->action()); createResetColorAction(m_syncEnvBackgroundAction->action());
m_backgroundColorActions << m_selectBackgroundColorAction.get(); m_backgroundColorActions << m_selectBackgroundColorAction.get();
m_backgroundColorActions << m_selectGridColorAction.get(); m_backgroundColorActions << m_selectGridColorAction.get();
m_backgroundColorActions << m_syncBackgroundColorAction.get(); m_backgroundColorActions << m_syncEnvBackgroundAction.get();
m_backgroundColorActions << m_resetColorAction.get(); m_backgroundColorActions << m_resetColorAction.get();
} }

View File

@@ -101,10 +101,10 @@ private:
void showMaterialPropertiesView(); void showMaterialPropertiesView();
void updateAlignActionStates(); void updateAlignActionStates();
void createSelectBackgroundColorAction(QAction *syncBackgroundColorAction); void createSelectBackgroundColorAction(QAction *syncEnvBackgroundAction);
void createGridColorSelectionAction(); void createGridColorSelectionAction();
void createResetColorAction(QAction *syncBackgroundColorAction); void createResetColorAction(QAction *syncEnvBackgroundAction);
void createSyncBackgroundColorAction(); void createSyncEnvBackgroundAction();
void createSeekerSliderAction(); void createSeekerSliderAction();
QPoint resolveToolbarPopupPos(Edit3DAction *action) const; QPoint resolveToolbarPopupPos(Edit3DAction *action) const;
@@ -135,7 +135,7 @@ private:
std::unique_ptr<Edit3DAction> m_particlesPlayAction; std::unique_ptr<Edit3DAction> m_particlesPlayAction;
std::unique_ptr<Edit3DAction> m_particlesRestartAction; std::unique_ptr<Edit3DAction> m_particlesRestartAction;
std::unique_ptr<Edit3DParticleSeekerAction> m_seekerAction; std::unique_ptr<Edit3DParticleSeekerAction> m_seekerAction;
std::unique_ptr<Edit3DAction> m_syncBackgroundColorAction; std::unique_ptr<Edit3DAction> m_syncEnvBackgroundAction;
std::unique_ptr<Edit3DAction> m_selectBackgroundColorAction; std::unique_ptr<Edit3DAction> m_selectBackgroundColorAction;
std::unique_ptr<Edit3DAction> m_selectGridColorAction; std::unique_ptr<Edit3DAction> m_selectGridColorAction;
std::unique_ptr<Edit3DAction> m_resetColorAction; std::unique_ptr<Edit3DAction> m_resetColorAction;

View File

@@ -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_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.SelectBackgroundColor";
const char EDIT3D_EDIT_SELECT_GRID_COLOR[] = "QmlDesigner.Editor3D.SelectGridColor"; const char EDIT3D_EDIT_SELECT_GRID_COLOR[] = "QmlDesigner.Editor3D.SelectGridColor";
const char EDIT3D_EDIT_RESET_BACKGROUND_COLOR[] = "QmlDesigner.Editor3D.ResetBackgroundColor"; 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_SELECTION_BOX[] = "QmlDesigner.Editor3D.ToggleSelectionBox";
const char EDIT3D_EDIT_SHOW_ICON_GIZMO[] = "QmlDesigner.Editor3D.ToggleIconGizmo"; const char EDIT3D_EDIT_SHOW_ICON_GIZMO[] = "QmlDesigner.Editor3D.ToggleIconGizmo";
const char EDIT3D_EDIT_SHOW_CAMERA_FRUSTUM[] = "QmlDesigner.Editor3D.ToggleCameraFrustum"; const char EDIT3D_EDIT_SHOW_CAMERA_FRUSTUM[] = "QmlDesigner.Editor3D.ToggleCameraFrustum";

View File

@@ -27,7 +27,7 @@ Item {
property color backgroundGradientColorStart: "#222222" property color backgroundGradientColorStart: "#222222"
property color backgroundGradientColorEnd: "#999999" property color backgroundGradientColorEnd: "#999999"
property color gridColor: "#cccccc" property color gridColor: "#cccccc"
property bool syncBackgroundColor: false property bool syncEnvBackground: false
enum SelectionMode { Item, Group } enum SelectionMode { Item, Group }
enum TransformMode { Move, Rotate, Scale } enum TransformMode { Move, Rotate, Scale }
@@ -58,7 +58,7 @@ Item {
onShowEditLightChanged: _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) onShowEditLightChanged: _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight)
onGlobalOrientationChanged: _generalHelper.storeToolState(sceneId, "globalOrientation", globalOrientation) onGlobalOrientationChanged: _generalHelper.storeToolState(sceneId, "globalOrientation", globalOrientation)
onShowGridChanged: _generalHelper.storeToolState(sceneId, "showGrid", showGrid); onShowGridChanged: _generalHelper.storeToolState(sceneId, "showGrid", showGrid);
onSyncBackgroundColorChanged: _generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor); onSyncEnvBackgroundChanged: _generalHelper.storeToolState(sceneId, "syncEnvBackground", syncEnvBackground);
onShowSelectionBoxChanged: _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox); onShowSelectionBoxChanged: _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox);
onShowIconGizmoChanged: _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo); onShowIconGizmoChanged: _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo);
onShowCameraFrustumChanged: _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum); onShowCameraFrustumChanged: _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum);
@@ -136,10 +136,7 @@ Item {
} }
} }
if (syncBackgroundColor) updateEnvBackground();
updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]);
else
updateBackgroundColors(_generalHelper.bgColor);
notifyActiveSceneChange(); 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 // If resetToDefault is true, tool states not specifically set to anything will be reset to
// their default state. // their default state.
function updateToolStates(toolStates, resetToDefault) function updateToolStates(toolStates, resetToDefault)
@@ -220,15 +242,12 @@ Item {
else if (resetToDefault) else if (resetToDefault)
showGrid = true; showGrid = true;
if ("syncBackgroundColor" in toolStates) { if ("syncEnvBackground" in toolStates) {
syncBackgroundColor = toolStates.syncBackgroundColor; syncEnvBackground = toolStates.syncEnvBackground;
if (syncBackgroundColor) updateEnvBackground();
updateBackgroundColors([_generalHelper.sceneEnvironmentColor(sceneId)]);
else
updateBackgroundColors(_generalHelper.bgColor);
} else if (resetToDefault) { } else if (resetToDefault) {
syncBackgroundColor = false; syncEnvBackground = false;
updateBackgroundColors(_generalHelper.bgColor); updateEnvBackground();
} }
if ("showSelectionBox" in toolStates) if ("showSelectionBox" in toolStates)
@@ -281,7 +300,7 @@ Item {
{ {
_generalHelper.storeToolState(sceneId, "showEditLight", showEditLight) _generalHelper.storeToolState(sceneId, "showEditLight", showEditLight)
_generalHelper.storeToolState(sceneId, "showGrid", showGrid) _generalHelper.storeToolState(sceneId, "showGrid", showGrid)
_generalHelper.storeToolState(sceneId, "syncBackgroundColor", syncBackgroundColor) _generalHelper.storeToolState(sceneId, "syncEnvBackground", syncEnvBackground)
_generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox) _generalHelper.storeToolState(sceneId, "showSelectionBox", showSelectionBox)
_generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo) _generalHelper.storeToolState(sceneId, "showIconGizmo", showIconGizmo)
_generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum) _generalHelper.storeToolState(sceneId, "showCameraFrustum", showCameraFrustum)
@@ -697,6 +716,7 @@ Item {
} }
} }
} }
function onHiddenStateChanged(node) function onHiddenStateChanged(node)
{ {
for (var i = 0; i < cameraGizmos.length; ++i) { for (var i = 0; i < cameraGizmos.length; ++i) {
@@ -727,11 +747,16 @@ Item {
} }
} }
} }
function onUpdateDragTooltip() function onUpdateDragTooltip()
{ {
gizmoLabel.updateLabel(); gizmoLabel.updateLabel();
rotateGizmoLabel.updateLabel(); rotateGizmoLabel.updateLabel();
} }
function onSceneEnvDataChanged() {
updateEnvBackground();
}
} }
Node { Node {

View File

@@ -15,6 +15,7 @@ View3D {
property alias sceneHelpers: sceneHelpers property alias sceneHelpers: sceneHelpers
property alias perspectiveCamera: scenePerspectiveCamera property alias perspectiveCamera: scenePerspectiveCamera
property alias orthoCamera: sceneOrthoCamera property alias orthoCamera: sceneOrthoCamera
property alias sceneEnv: sceneEnv
property vector3d cameraLookAt property vector3d cameraLookAt
// Measuring the distance from camera to lookAt plus the distance of lookAt from grid plane // Measuring the distance from camera to lookAt plus the distance of lookAt from grid plane

View File

@@ -57,6 +57,10 @@ GeneralHelper::GeneralHelper()
m_toolStateUpdateTimer.setSingleShot(true); m_toolStateUpdateTimer.setSingleShot(true);
QObject::connect(&m_toolStateUpdateTimer, &QTimer::timeout, QObject::connect(&m_toolStateUpdateTimer, &QTimer::timeout,
this, &GeneralHelper::handlePendingToolStateUpdate); this, &GeneralHelper::handlePendingToolStateUpdate);
QList<QColor> defaultBg;
defaultBg.append(QColor());
m_bgColor = QVariant::fromValue(defaultBg);
} }
void GeneralHelper::requestOverlayUpdate() 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 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) void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates)

View File

@@ -15,7 +15,10 @@
#include <QUrl> #include <QUrl>
#include <QVariant> #include <QVariant>
#include <QVector3D> #include <QVector3D>
#include <QtQuick3D/private/qquick3dcubemaptexture_p.h>
#include <QtQuick3D/private/qquick3dpickresult_p.h> #include <QtQuick3D/private/qquick3dpickresult_p.h>
#include <QtQuick3D/private/qquick3dsceneenvironment_p.h>
#include <QtQuick3D/private/qquick3dtexture_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QQuick3DCamera; class QQuick3DCamera;
@@ -92,9 +95,13 @@ public:
Q_INVOKABLE void scaleMultiSelection(bool commit); Q_INVOKABLE void scaleMultiSelection(bool commit);
Q_INVOKABLE void rotateMultiSelection(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; 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; bool isMacOS() const;
@@ -137,6 +144,7 @@ signals:
void bgColorChanged(); void bgColorChanged();
void minGridStepChanged(); void minGridStepChanged();
void updateDragTooltip(); void updateDragTooltip();
void sceneEnvDataChanged();
private: private:
void handlePendingToolStateUpdate(); void handlePendingToolStateUpdate();
@@ -150,9 +158,16 @@ private:
QTimer m_toolStateUpdateTimer; QTimer m_toolStateUpdateTimer;
QHash<QString, QVariantMap> m_toolStates; QHash<QString, QVariantMap> m_toolStates;
QHash<QString, QVariantMap> m_toolStatesPending; QHash<QString, QVariantMap> m_toolStatesPending;
QHash<QString, QColor> m_sceneEnvironmentColor;
QSet<QQuick3DNode *> m_rotationBlockedNodes; QSet<QQuick3DNode *> m_rotationBlockedNodes;
struct SceneEnvData {
QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes backgroundMode;
QColor clearColor;
QPointer<QQuick3DTexture> lightProbe;
QPointer<QQuick3DCubeMapTexture> skyBoxCubeMap;
};
QHash<QString, SceneEnvData> m_sceneEnvironmentData;
struct MultiSelData { struct MultiSelData {
QVector3D startScenePos; QVector3D startScenePos;
QVector3D startScale; QVector3D startScale;

View File

@@ -385,10 +385,9 @@ void Qt5InformationNodeInstanceServer::updateColorSettings(
QQmlProperty gridProp(m_editView3DData.rootItem, "gridColor", context()); QQmlProperty gridProp(m_editView3DData.rootItem, "gridColor", context());
gridProp.write(container.value()); gridProp.write(container.value());
} else if (container.name() == "edit3dBgColor") { } else if (container.name() == "edit3dBgColor") {
QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors",
Q_ARG(QVariant, container.value()));
if (auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper)) if (auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper))
helper->setBgColor(container.value()); helper->setBgColor(container.value());
QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateEnvBackground");
} }
} }
} }
@@ -1066,7 +1065,7 @@ void Qt5InformationNodeInstanceServer::resolveSceneRoots()
++it; ++it;
} }
updateSceneEnvColorsToHelper(); updateSceneEnvToHelper();
if (updateActiveScene) { if (updateActiveScene) {
m_active3DView = findView3DForSceneRoot(m_active3DScene); m_active3DView = findView3DForSceneRoot(m_active3DScene);
@@ -1912,7 +1911,7 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(
m_editView3DSetupDone = true; m_editView3DSetupDone = true;
updateSceneEnvColorsToHelper(); updateSceneEnvToHelper();
if (toolStates.contains({})) { if (toolStates.contains({})) {
// Update tool state to an existing no-scene state before updating the active scene to // 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); render3DEditView(2);
} }
void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor( void Qt5InformationNodeInstanceServer::setSceneEnvironmentData(
[[maybe_unused]] const PropertyValueContainer &container) [[maybe_unused]] qint32 instanceId)
{ {
#ifdef QUICK3D_MODULE #ifdef QUICK3D_MODULE
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper); auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
if (!helper || !hasInstanceForId(container.instanceId()) || !m_active3DView) if (!helper || !hasInstanceForId(instanceId) || !m_active3DView)
return; return;
ServerNodeInstance sceneEnvInstance = instanceForId(container.instanceId()); ServerNodeInstance sceneEnvInstance = instanceForId(instanceId);
if (!sceneEnvInstance.isSubclassOf("QQuick3DSceneEnvironment")) if (!sceneEnvInstance.isSubclassOf("QQuick3DSceneEnvironment"))
return; return;
@@ -2255,17 +2254,14 @@ void Qt5InformationNodeInstanceServer::setSceneEnvironmentColor(
ServerNodeInstance activeSceneInstance = active3DSceneInstance(); ServerNodeInstance activeSceneInstance = active3DSceneInstance();
const QString sceneId = activeSceneInstance.id(); const QString sceneId = activeSceneInstance.id();
QColor color = container.value().value<QColor>(); helper->setSceneEnvironmentData(sceneId, activeEnv);
helper->setSceneEnvironmentColor(sceneId, color);
QVariantMap toolStates = helper->getToolStates(sceneId); QVariantMap toolStates = helper->getToolStates(sceneId);
if (toolStates.contains("syncBackgroundColor")) { if (toolStates.contains("syncEnvBackground")) {
bool sync = toolStates["syncBackgroundColor"].toBool(); bool sync = toolStates["syncEnvBackground"].toBool();
if (sync) { if (sync)
QList<QColor> colors{color}; QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateEnvBackground");
QMetaObject::invokeMethod(m_editView3DData.rootItem, "updateBackgroundColors",
Q_ARG(QVariant, QVariant::fromValue(colors)));
}
} }
#endif #endif
} }
@@ -2308,15 +2304,15 @@ QVariantList Qt5InformationNodeInstanceServer::alignCameraList() const
return cameras; return cameras;
} }
void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper() void Qt5InformationNodeInstanceServer::updateSceneEnvToHelper()
{ {
#ifdef QUICK3D_MODULE #ifdef QUICK3D_MODULE
// Update stored scene environment colors for all scenes // Update stored scene environment backgrounds for all scenes
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper); auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
if (!helper) if (!helper)
return; return;
helper->clearSceneEnvironmentColors(); helper->clearSceneEnvironmentData();
const auto sceneRoots = m_3DSceneMap.uniqueKeys(); const auto sceneRoots = m_3DSceneMap.uniqueKeys();
for (QObject *sceneRoot : sceneRoots) { for (QObject *sceneRoot : sceneRoots) {
@@ -2328,8 +2324,6 @@ void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper()
if (!env) if (!env)
continue; continue;
QColor clearColor = env->clearColor();
if (clearColor.isValid() && helper) {
ServerNodeInstance sceneInstance; ServerNodeInstance sceneInstance;
if (hasInstanceForObject(sceneRoot)) if (hasInstanceForObject(sceneRoot))
sceneInstance = instanceForObject(sceneRoot); sceneInstance = instanceForObject(sceneRoot);
@@ -2338,22 +2332,28 @@ void Qt5InformationNodeInstanceServer::updateSceneEnvColorsToHelper()
const QString sceneId = sceneInstance.id(); const QString sceneId = sceneInstance.id();
helper->setSceneEnvironmentColor(sceneId, clearColor); helper->setSceneEnvironmentData(sceneId, env);
}
} }
#endif #endif
} }
bool Qt5InformationNodeInstanceServer::isSceneEnvironmentBgProperty(const PropertyName &name) const
{
return name == "backgroundMode" || name == "clearColor"
|| name == "lightProbe" || name == "skyBoxCubeMap";
}
void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command)
{ {
bool hasDynamicProperties = false; bool hasDynamicProperties = false;
const QVector<PropertyValueContainer> values = command.valueChanges(); const QVector<PropertyValueContainer> values = command.valueChanges();
QSet<qint32> sceneEnvs;
for (const PropertyValueContainer &container : values) { for (const PropertyValueContainer &container : values) {
if (!container.isReflected()) { if (!container.isReflected()) {
hasDynamicProperties |= container.isDynamic(); hasDynamicProperties |= container.isDynamic();
if (container.name() == "clearColor") if (isSceneEnvironmentBgProperty(container.name()))
setSceneEnvironmentColor(container); sceneEnvs.insert(container.instanceId());
setInstancePropertyVariant(container); setInstancePropertyVariant(container);
} }
@@ -2362,6 +2362,9 @@ void Qt5InformationNodeInstanceServer::changePropertyValues(const ChangeValuesCo
if (hasDynamicProperties) if (hasDynamicProperties)
refreshBindings(); refreshBindings();
for (const qint32 id : std::as_const(sceneEnvs))
setSceneEnvironmentData(id);
startRenderTimer(); startRenderTimer();
render3DEditView(); render3DEditView();
@@ -2455,8 +2458,8 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c
case View3DActionType::ShowCameraFrustum: case View3DActionType::ShowCameraFrustum:
updatedToolState.insert("showCameraFrustum", command.isEnabled()); updatedToolState.insert("showCameraFrustum", command.isEnabled());
break; break;
case View3DActionType::SyncBackgroundColor: case View3DActionType::SyncEnvBackground:
updatedToolState.insert("syncBackgroundColor", command.isEnabled()); updatedToolState.insert("syncEnvBackground", command.isEnabled());
break; break;
#ifdef QUICK3D_PARTICLES_MODULE #ifdef QUICK3D_PARTICLES_MODULE
case View3DActionType::ShowParticleEmitter: case View3DActionType::ShowParticleEmitter:
@@ -2530,6 +2533,16 @@ void Qt5InformationNodeInstanceServer::changeAuxiliaryValues(const ChangeAuxilia
void Qt5InformationNodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command) void Qt5InformationNodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command)
{ {
Qt5NodeInstanceServer::changePropertyBindings(command); Qt5NodeInstanceServer::changePropertyBindings(command);
QSet<qint32> 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(); render3DEditView();
} }
@@ -2570,15 +2583,18 @@ void Qt5InformationNodeInstanceServer::changeState(const ChangeStateCommand &com
void Qt5InformationNodeInstanceServer::removeProperties(const RemovePropertiesCommand &command) void Qt5InformationNodeInstanceServer::removeProperties(const RemovePropertiesCommand &command)
{ {
const QVector<PropertyAbstractContainer> props = command.properties(); const QVector<PropertyAbstractContainer> props = command.properties();
QSet<qint32> sceneEnvs;
for (const PropertyAbstractContainer &container : props) { for (const PropertyAbstractContainer &container : props) {
if (container.name() == "clearColor") { if (isSceneEnvironmentBgProperty(container.name()))
setSceneEnvironmentColor(PropertyValueContainer(container.instanceId(), sceneEnvs.insert(container.instanceId());
container.name(), {}, {}));
}
} }
Qt5NodeInstanceServer::removeProperties(command); Qt5NodeInstanceServer::removeProperties(command);
for (const qint32 id : std::as_const(sceneEnvs))
setSceneEnvironmentData(id);
render3DEditView(); render3DEditView();
} }

View File

@@ -136,9 +136,10 @@ private:
void resetParticleSystem(); void resetParticleSystem();
void handleParticleSystemDeselected(); void handleParticleSystemDeselected();
#endif #endif
void setSceneEnvironmentColor(const PropertyValueContainer &container); void setSceneEnvironmentData(qint32 instanceId);
QVariantList alignCameraList() const; QVariantList alignCameraList() const;
void updateSceneEnvColorsToHelper(); void updateSceneEnvToHelper();
bool isSceneEnvironmentBgProperty(const PropertyName &name) const;
RenderViewData m_editView3DData; RenderViewData m_editView3DData;
RenderViewData m_modelNode3DImageViewData; RenderViewData m_modelNode3DImageViewData;