forked from qt-creator/qt-creator
Allow scene environment as background for non-View3D scenes
For non-View3D scenes, the environment from the previous View3D is used. Fixes: QDS-12398 Change-Id: I6adc82cd0205ebe443b5834d9bb0f4906e2cd009 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -166,7 +166,7 @@ Item {
|
||||
break;
|
||||
}
|
||||
}
|
||||
showEditLight = !hasSceneLight;
|
||||
showEditLight = !hasSceneLight && !_generalHelper.sceneHasLightProbe(sceneId);
|
||||
|
||||
// Don't inherit camera angles from the previous scene
|
||||
for (let i = 0; i < 4; ++i)
|
||||
@@ -265,16 +265,22 @@ Item {
|
||||
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
if (syncEnvBackground) {
|
||||
let bgMode = _generalHelper.sceneEnvironmentBgMode(sceneId);
|
||||
if ((!_generalHelper.sceneEnvironmentLightProbe(sceneId) && bgMode === SceneEnvironment.SkyBox)
|
||||
|| (!_generalHelper.sceneEnvironmentSkyBoxCubeMap(sceneId) && bgMode === SceneEnvironment.SkyBoxCubeMap)) {
|
||||
editViews[i].sceneEnv.backgroundMode = SceneEnvironment.Color;
|
||||
} else {
|
||||
editViews[i].sceneEnv.backgroundMode = bgMode;
|
||||
if (_generalHelper.hasSceneEnvironmentData(sceneId)) {
|
||||
let bgMode = _generalHelper.sceneEnvironmentBgMode(sceneId);
|
||||
if ((!_generalHelper.sceneEnvironmentLightProbe(sceneId) && bgMode === SceneEnvironment.SkyBox)
|
||||
|| (!_generalHelper.sceneEnvironmentSkyBoxCubeMap(sceneId) && bgMode === SceneEnvironment.SkyBoxCubeMap)) {
|
||||
editViews[i].sceneEnv.backgroundMode = SceneEnvironment.Color;
|
||||
} else {
|
||||
editViews[i].sceneEnv.backgroundMode = bgMode;
|
||||
}
|
||||
editViews[i].sceneEnv.lightProbe = _generalHelper.sceneEnvironmentLightProbe(sceneId);
|
||||
editViews[i].sceneEnv.skyBoxCubeMap = _generalHelper.sceneEnvironmentSkyBoxCubeMap(sceneId);
|
||||
editViews[i].sceneEnv.clearColor = _generalHelper.sceneEnvironmentColor(sceneId);
|
||||
} else if (activeScene) {
|
||||
_generalHelper.updateSceneEnvToLast(editViews[i].sceneEnv,
|
||||
editViews[i].defaultLightProbe,
|
||||
editViews[i].defaultCubeMap);
|
||||
}
|
||||
editViews[i].sceneEnv.lightProbe = _generalHelper.sceneEnvironmentLightProbe(sceneId);
|
||||
editViews[i].sceneEnv.skyBoxCubeMap = _generalHelper.sceneEnvironmentSkyBoxCubeMap(sceneId);
|
||||
editViews[i].sceneEnv.clearColor = _generalHelper.sceneEnvironmentColor(sceneId);
|
||||
} else {
|
||||
editViews[i].sceneEnv.backgroundMode = SceneEnvironment.Transparent;
|
||||
editViews[i].sceneEnv.lightProbe = null;
|
||||
|
||||
@@ -15,6 +15,8 @@ View3D {
|
||||
property alias perspectiveCamera: scenePerspectiveCamera
|
||||
property alias orthoCamera: sceneOrthoCamera
|
||||
property alias sceneEnv: sceneEnv
|
||||
property alias defaultLightProbe: defaultLightProbe
|
||||
property alias defaultCubeMap: defaultCubeMap
|
||||
property vector3d cameraLookAt
|
||||
property var selectionBoxes: []
|
||||
property Node selectedNode
|
||||
@@ -61,6 +63,14 @@ View3D {
|
||||
id: sceneEnv
|
||||
antialiasingMode: SceneEnvironment.MSAA
|
||||
antialiasingQuality: SceneEnvironment.High
|
||||
|
||||
Texture {
|
||||
id: defaultLightProbe
|
||||
}
|
||||
|
||||
CubeMapTexture {
|
||||
id: defaultCubeMap
|
||||
}
|
||||
}
|
||||
|
||||
Node {
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "selectionboxgeometry.h"
|
||||
|
||||
#include <enumeration.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QtQuick3D/qquick3dobject.h>
|
||||
#include <QtQuick3D/private/qquick3dorthographiccamera_p.h>
|
||||
@@ -42,9 +44,17 @@
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
const QString _globalStateId = QStringLiteral("@GTS"); // global tool state
|
||||
const QString _globalStateId = QStringLiteral("@GTS"); // global tool state (within document)
|
||||
const QString _projectStateId = QStringLiteral("@PTS"); // project wide tool state
|
||||
const QString _lastSceneIdKey = QStringLiteral("lastSceneId");
|
||||
const QString _rootSizeKey = QStringLiteral("rootSize");
|
||||
const QString _lastSceneEnvKey = QStringLiteral("lastSceneEnv");
|
||||
|
||||
const QString _lightProbeProp = QStringLiteral("lightProbe");
|
||||
const QString _sourceProp = QStringLiteral("source");
|
||||
const QString _cubeProp = QStringLiteral("skyBoxCubeMap");
|
||||
const QString _bgProp = QStringLiteral("backgroundMode");
|
||||
const QString _colorProp = QStringLiteral("clearColor");
|
||||
|
||||
static const float floatMin = std::numeric_limits<float>::lowest();
|
||||
static const float floatMax = std::numeric_limits<float>::max();
|
||||
@@ -739,6 +749,11 @@ void GeneralHelper::setSceneEnvironmentData(const QString &sceneId,
|
||||
}
|
||||
}
|
||||
|
||||
bool GeneralHelper::hasSceneEnvironmentData(const QString &sceneId) const
|
||||
{
|
||||
return m_sceneEnvironmentData.contains(sceneId);
|
||||
}
|
||||
|
||||
QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes GeneralHelper::sceneEnvironmentBgMode(
|
||||
const QString &sceneId) const
|
||||
{
|
||||
@@ -760,6 +775,69 @@ QQuick3DCubeMapTexture *GeneralHelper::sceneEnvironmentSkyBoxCubeMap(const QStri
|
||||
return m_sceneEnvironmentData[sceneId].skyBoxCubeMap.data();
|
||||
}
|
||||
|
||||
void GeneralHelper::updateSceneEnvToLast(QQuick3DSceneEnvironment *env, QQuick3DTexture *lightProbe,
|
||||
QQuick3DCubeMapTexture *cubeMap)
|
||||
{
|
||||
if (!env)
|
||||
return;
|
||||
|
||||
if (m_lastSceneEnvData.contains(_bgProp)) {
|
||||
Enumeration enumeration = m_lastSceneEnvData[_bgProp].value<Enumeration>();
|
||||
QMetaEnum me = QMetaEnum::fromType<QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes>();
|
||||
int intValue = me.keyToValue(enumeration.toName());
|
||||
env->setBackgroundMode(QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes(intValue));
|
||||
} else {
|
||||
env->setBackgroundMode(QQuick3DSceneEnvironment::Transparent);
|
||||
}
|
||||
|
||||
if (m_lastSceneEnvData.contains(_colorProp))
|
||||
env->setClearColor(m_lastSceneEnvData[_colorProp].value<QColor>());
|
||||
else
|
||||
env->setClearColor(Qt::transparent);
|
||||
|
||||
if (lightProbe) {
|
||||
if (m_lastSceneEnvData.contains(_lightProbeProp)) {
|
||||
QVariantMap props = m_lastSceneEnvData[_lightProbeProp].toMap();
|
||||
if (props.contains(_sourceProp))
|
||||
lightProbe->setSource(props[_sourceProp].toUrl());
|
||||
else
|
||||
lightProbe->setSource({});
|
||||
env->setLightProbe(lightProbe);
|
||||
} else {
|
||||
env->setLightProbe(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (cubeMap) {
|
||||
if (m_lastSceneEnvData.contains(_cubeProp)) {
|
||||
QVariantMap props = m_lastSceneEnvData[_cubeProp].toMap();
|
||||
if (props.contains(_sourceProp))
|
||||
cubeMap->setSource(props[_sourceProp].toUrl());
|
||||
else
|
||||
cubeMap->setSource({});
|
||||
env->setSkyBoxCubeMap(cubeMap);
|
||||
} else {
|
||||
env->setSkyBoxCubeMap(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GeneralHelper::sceneHasLightProbe(const QString &sceneId)
|
||||
{
|
||||
// From editor perspective, a scene is considered to have a light probe if scene itself
|
||||
// has a light probe or scene has no env data and last scene had a light probe
|
||||
if (m_sceneEnvironmentData.contains(sceneId)) {
|
||||
return bool(m_sceneEnvironmentData[sceneId].lightProbe);
|
||||
} else {
|
||||
if (m_lastSceneEnvData.contains(_lightProbeProp)) {
|
||||
QVariantMap props = m_lastSceneEnvData[_sourceProp].toMap();
|
||||
if (props.contains(_sourceProp))
|
||||
return !props[_sourceProp].toUrl().isEmpty();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GeneralHelper::clearSceneEnvironmentData()
|
||||
{
|
||||
for (const SceneEnvData &data : std::as_const(m_sceneEnvironmentData)) {
|
||||
@@ -773,6 +851,12 @@ void GeneralHelper::clearSceneEnvironmentData()
|
||||
emit sceneEnvDataChanged();
|
||||
}
|
||||
|
||||
void GeneralHelper::setLastSceneEnvironmentData(const QVariantMap &data)
|
||||
{
|
||||
m_lastSceneEnvData = data;
|
||||
storeToolState(_projectStateId, _lastSceneEnvKey, m_lastSceneEnvData);
|
||||
}
|
||||
|
||||
void GeneralHelper::initToolStates(const QString &sceneId, const QVariantMap &toolStates)
|
||||
{
|
||||
m_toolStates[sceneId] = toolStates;
|
||||
@@ -797,11 +881,21 @@ QString GeneralHelper::globalStateId() const
|
||||
return _globalStateId;
|
||||
}
|
||||
|
||||
QString GeneralHelper::projectStateId() const
|
||||
{
|
||||
return _projectStateId;
|
||||
}
|
||||
|
||||
QString GeneralHelper::lastSceneIdKey() const
|
||||
{
|
||||
return _lastSceneIdKey;
|
||||
}
|
||||
|
||||
QString GeneralHelper::lastSceneEnvKey() const
|
||||
{
|
||||
return _lastSceneEnvKey;
|
||||
}
|
||||
|
||||
QString GeneralHelper::rootSizeKey() const
|
||||
{
|
||||
return _rootSizeKey;
|
||||
|
||||
@@ -96,7 +96,9 @@ public:
|
||||
Q_INVOKABLE void enableItemUpdate(QQuickItem *item, bool enable);
|
||||
Q_INVOKABLE QVariantMap getToolStates(const QString &sceneId);
|
||||
QString globalStateId() const;
|
||||
QString projectStateId() const;
|
||||
QString lastSceneIdKey() const;
|
||||
QString lastSceneEnvKey() const;
|
||||
QString rootSizeKey() const;
|
||||
|
||||
Q_INVOKABLE void setMultiSelectionTargets(QQuick3DNode *multiSelectRootNode,
|
||||
@@ -109,12 +111,18 @@ public:
|
||||
Q_INVOKABLE void rotateMultiSelection(bool commit);
|
||||
|
||||
void setSceneEnvironmentData(const QString &sceneId, QQuick3DSceneEnvironment *env);
|
||||
Q_INVOKABLE bool hasSceneEnvironmentData(const QString &sceneId) const;
|
||||
Q_INVOKABLE QQuick3DSceneEnvironment::QQuick3DEnvironmentBackgroundTypes sceneEnvironmentBgMode(
|
||||
const QString &sceneId) const;
|
||||
Q_INVOKABLE QColor sceneEnvironmentColor(const QString &sceneId) const;
|
||||
Q_INVOKABLE QQuick3DTexture *sceneEnvironmentLightProbe(const QString &sceneId) const;
|
||||
Q_INVOKABLE QQuick3DCubeMapTexture *sceneEnvironmentSkyBoxCubeMap(const QString &sceneId) const;
|
||||
Q_INVOKABLE void updateSceneEnvToLast(QQuick3DSceneEnvironment *env, QQuick3DTexture *lightProbe,
|
||||
QQuick3DCubeMapTexture *cubeMap);
|
||||
Q_INVOKABLE bool sceneHasLightProbe(const QString &sceneId);
|
||||
|
||||
void clearSceneEnvironmentData();
|
||||
void setLastSceneEnvironmentData(const QVariantMap &data);
|
||||
|
||||
bool isMacOS() const;
|
||||
|
||||
@@ -202,6 +210,7 @@ private:
|
||||
QPointer<QQuick3DCubeMapTexture> skyBoxCubeMap;
|
||||
};
|
||||
QHash<QString, SceneEnvData> m_sceneEnvironmentData;
|
||||
QVariantMap m_lastSceneEnvData;
|
||||
|
||||
struct MultiSelData {
|
||||
QVector3D startScenePos;
|
||||
|
||||
@@ -1963,6 +1963,8 @@ void Qt5InformationNodeInstanceServer::setup3DEditView(
|
||||
if (toolStates[helper->globalStateId()].contains(helper->lastSceneIdKey()))
|
||||
lastSceneId = toolStates[helper->globalStateId()][helper->lastSceneIdKey()].toString();
|
||||
}
|
||||
if (toolStates.contains(helper->projectStateId()))
|
||||
helper->setLastSceneEnvironmentData(toolStates[helper->projectStateId()][helper->lastSceneEnvKey()].toMap());
|
||||
}
|
||||
|
||||
// Find a scene to show
|
||||
@@ -2607,6 +2609,12 @@ void Qt5InformationNodeInstanceServer::view3DAction(const View3DActionCommand &c
|
||||
case View3DActionType::MaterialOverride:
|
||||
updatedToolState.insert("matOverride", command.value().toList());
|
||||
break;
|
||||
case View3DActionType::SetLastSceneEnvData: {
|
||||
auto helper = qobject_cast<QmlDesigner::Internal::GeneralHelper *>(m_3dHelper);
|
||||
if (helper)
|
||||
helper->setLastSceneEnvironmentData(command.value().toMap());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user