summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJere Tuliniemi <jere.tuliniemi@qt.io>2019-10-07 14:56:25 +0300
committerJere Tuliniemi <jere.tuliniemi@qt.io>2019-10-08 09:45:20 +0300
commitc46fd2238ebcf79caf63b659301ae5c10c3e551f (patch)
tree73214fbb87d18d91c1f12d4b3bc88fa11fefc0ee
parent84a2c0597a41bba0a60f05360f85cb571e5153a7 (diff)
Fix material duplication behavior
Disable copying of referenced material properties and if somehow the user is able to duplicate a referenced material that points to a referenced material, do a recursive lookup for the original material. If an animatable material is duplicated, it's type is changed to referenced material which points to the duplicated material in the container. Or in other words it is changed to a basic material. Task-number: QT3DS-3679 Task-number: QT3DS-3973 Change-Id: Ic09bb897d24f7c10984c5cc2f80556be844d9c51 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp8
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp61
-rw-r--r--src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h2
3 files changed, 40 insertions, 31 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp
index 3b23d034..0324aa20 100644
--- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp
+++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp
@@ -2499,12 +2499,14 @@ public:
void copyMaterialProperties(Qt3DSDMInstanceHandle src, Qt3DSDMInstanceHandle dst) override
{
- const Q3DStudio::CString matType = GetObjectTypeName(src);
+ const EStudioObjectType matType = m_Bridge.GetObjectType(src);
QString materialTypeString;
- if (matType == "CustomMaterial")
+ if (matType == OBJTYPE_CUSTOMMATERIAL)
materialTypeString = m_Bridge.GetSourcePath(src);
- else
+ else if (matType == OBJTYPE_MATERIAL)
materialTypeString = QStringLiteral("Standard Material");
+ else
+ return;
SetMaterialType(dst, materialTypeString);
const auto srcSlide = m_SlideSystem.GetApplicableSlide(src);
diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp
index e3e08467..ee6e09c0 100644
--- a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp
+++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.cpp
@@ -128,7 +128,7 @@ CInspectableBase *InspectorControlModel::inspectable() const
}
qt3dsdm::Qt3DSDMInstanceHandle InspectorControlModel::getReferenceMaterial(
- CInspectableBase *inspectable) const
+ CInspectableBase *inspectable) const
{
if (inspectable)
return getBridge()->getMaterialReference(inspectable->getInstance());
@@ -136,6 +136,23 @@ qt3dsdm::Qt3DSDMInstanceHandle InspectorControlModel::getReferenceMaterial(
return 0;
}
+qt3dsdm::Qt3DSDMInstanceHandle InspectorControlModel::getReferenceMaterialRecursively(
+ CInspectableBase *inspectable) const
+{
+ if (inspectable) {
+ auto bridge = getBridge();
+ auto refMaterial = bridge->getMaterialReference(inspectable->getInstance());
+ auto type = bridge->GetObjectType(refMaterial);
+ while (type == OBJTYPE_REFERENCEDMATERIAL) {
+ refMaterial = bridge->getMaterialReference(refMaterial);
+ type = bridge->GetObjectType(refMaterial);
+ }
+ return refMaterial;
+ }
+
+ return 0;
+}
+
void InspectorControlModel::notifyPropertyChanged(qt3dsdm::Qt3DSDMInstanceHandle inInstance,
qt3dsdm::Qt3DSDMPropertyHandle inProperty)
{
@@ -279,19 +296,13 @@ void InspectorControlModel::addMaterial()
doc->SelectDataModelObject(newMaterial);
const auto type = getBridge()->GetObjectType(instance);
- if (type == OBJTYPE_REFERENCEDMATERIAL) {
- sceneEditor->setMaterialReferenceByPath(instance, absPath);
- sceneEditor->SetName(instance, getBridge()->GetName(newMaterial, true));
- sceneEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(relPath));
- doc->GetStudioSystem()->GetFullSystemSignalSender()->SendInstancePropertyValue(
- instance, getBridge()->GetNameProperty());
- } else {
- sceneEditor->SetName(instance, getBridge()->GetName(newMaterial, true));
- sceneEditor->SetMaterialType(instance, QStringLiteral("Standard Material"));
- sceneEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(relPath));
- doc->GetStudioSystem()->GetFullSystemSignalSender()->SendInstancePropertyValue(
- instance, getBridge()->GetNameProperty());
- }
+ if (type != OBJTYPE_REFERENCEDMATERIAL)
+ sceneEditor->SetMaterialType(instance, QStringLiteral("Referenced Material"));
+ sceneEditor->setMaterialReferenceByPath(instance, absPath);
+ sceneEditor->SetName(instance, getBridge()->GetName(newMaterial, true));
+ sceneEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(relPath));
+ doc->GetStudioSystem()->GetFullSystemSignalSender()->SendInstancePropertyValue(
+ instance, getBridge()->GetNameProperty());
}
void InspectorControlModel::duplicateMaterial()
@@ -308,7 +319,7 @@ void InspectorControlModel::duplicateMaterial()
auto material = instance;
if (type == OBJTYPE_REFERENCEDMATERIAL)
- material = getReferenceMaterial(m_inspectableBase);
+ material = getReferenceMaterialRecursively(m_inspectableBase);
if (material.Valid()) {
const auto sceneEditor = doc->getSceneEditor();
@@ -347,19 +358,13 @@ void InspectorControlModel::duplicateMaterial()
Q3DStudio::SCOPED_DOCUMENT_EDITOR(*doc, tr("Set Material Type")));
doc->SelectDataModelObject(duplicate);
- if (type == OBJTYPE_REFERENCEDMATERIAL) {
- scopedEditor->setMaterialReferenceByPath(instance, absPath);
- scopedEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(relPath));
- scopedEditor->SetName(instance, getBridge()->GetName(duplicate, true));
- doc->GetStudioSystem()->GetFullSystemSignalSender()->SendInstancePropertyValue(
- instance, getBridge()->GetNameProperty());
- } else if (type != OBJTYPE_CUSTOMMATERIAL) {
- sceneEditor->SetName(instance, getBridge()->GetName(duplicate, true));
- sceneEditor->SetMaterialType(instance, QStringLiteral("Standard Material"));
- sceneEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(relPath));
- doc->GetStudioSystem()->GetFullSystemSignalSender()->SendInstancePropertyValue(
- instance, getBridge()->GetNameProperty());
- }
+ if (type != OBJTYPE_REFERENCEDMATERIAL)
+ sceneEditor->SetMaterialType(instance, QStringLiteral("Referenced Material"));
+ scopedEditor->setMaterialReferenceByPath(instance, absPath);
+ scopedEditor->setMaterialSourcePath(instance, Q3DStudio::CString::fromQString(relPath));
+ scopedEditor->SetName(instance, getBridge()->GetName(duplicate, true));
+ doc->GetStudioSystem()->GetFullSystemSignalSender()->SendInstancePropertyValue(
+ instance, getBridge()->GetNameProperty());
}
}
diff --git a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h
index b1c13240..79e6613a 100644
--- a/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h
+++ b/src/Authoring/Qt3DStudio/Palettes/Inspector/InspectorControlModel.h
@@ -204,6 +204,8 @@ private:
void updateMaterialValues(const QStringList &values, int elementIndex,
bool updatingShaders = false);
qt3dsdm::Qt3DSDMInstanceHandle getReferenceMaterial(CInspectableBase *inspectable) const;
+ qt3dsdm::Qt3DSDMInstanceHandle getReferenceMaterialRecursively(
+ CInspectableBase *inspectable) const;
void updateShaderValues();
void updateMatDataValues();
void updatePropertyValue(InspectorControlBase *element) const;