summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-06-04 15:22:54 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-06-05 11:34:54 +0300
commit8b8ad9d1245e6ce1f97effa82ee44bd5fca416a0 (patch)
tree4d1209397e4649b7cff27f117b91b9adc0a0cb64
parentf5819c8149ecef193619cbd33589a5652fd79ee6 (diff)
Clarify material creation/deletion API
Replaced element path with presentation ID in createMaterial, as that is what we are actually interested in. Removed element path from deleteMaterial, the presentation ID is expected in the name. The materialsCreated signal will now include the presentation ID in the material name if the material is in a subpresentation. Task-number: QT3DS-3623 Change-Id: I0c38c0eb52f85005256c3bf3dee45be384d66d37 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Jari Karppinen <jari.karppinen@qt.io> Reviewed-by: Janne Kangas <janne.kangas@qt.io> Reviewed-by: Antti Määttä <antti.maatta@qt.io>
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/q3dscommandqueue.cpp2
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp52
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h8
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsrenderer.cpp2
-rw-r--r--src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.cpp12
-rw-r--r--src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.h4
-rw-r--r--src/Runtime/ogl-runtime/src/runtime/Qt3DSIScriptBridge.h4
-rw-r--r--src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp123
-rw-r--r--src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.cpp8
-rw-r--r--src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.h4
-rw-r--r--tests/auto/viewer/tst_qt3dsviewer.cpp13
11 files changed, 141 insertions, 91 deletions
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dscommandqueue.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dscommandqueue.cpp
index 550dc24f..c6071aa9 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dscommandqueue.cpp
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dscommandqueue.cpp
@@ -268,13 +268,13 @@ void CommandQueue::copyCommands(CommandQueue &fromQueue)
fromQueue.commandAt(i).m_data = nullptr; // This queue takes ownership of data
break;
case CommandType_DeleteElements:
+ case CommandType_DeleteMaterials:
case CommandType_DeleteMeshes:
case CommandType_CreateMeshes:
queueCommand(source.m_commandType, source.m_data);
fromQueue.commandAt(i).m_data = nullptr; // This queue takes ownership of data
break;
case CommandType_CreateMaterials:
- case CommandType_DeleteMaterials:
queueCommand(source.m_elementPath, source.m_commandType, source.m_data);
fromQueue.commandAt(i).m_data = nullptr; // This queue takes ownership of data
break;
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp
index 59bd91a4..2f63efda 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.cpp
@@ -764,7 +764,7 @@ void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &va
A referenced material element is also created for the new model element. The source material
name can be specified with custom "material" attribute in the \a attributes hash.
- The source material must exist in the presentation.
+ The source material must exist in the same presentation where the element is created.
The mesh for a model is specified with the \c sourcepath property. This can be a local file
path to \c .mesh file, a studio mesh primitive (e.g. \c{#Cube}), or the name of a mesh created
@@ -842,8 +842,9 @@ void Q3DSPresentation::deleteElements(const QStringList &elementPaths)
}
/*!
- Creates a material specified by the \a materialDefinition parameter into the presentation
- that owns the element specified by the \a elementPath parameter.
+ Creates a material specified by the \a materialDefinition parameter into the subpresentation
+ specified by the \a subPresId parameter. If \a subPresId is empty, the material
+ is created into the main presentation.
The \a materialDefinition parameter can contain either the file path to a Qt 3D Studio
material definition file or the actual material definition in the
@@ -870,68 +871,73 @@ void Q3DSPresentation::deleteElements(const QStringList &elementPaths)
\sa createElement
\sa materialsCreated
*/
-void Q3DSPresentation::createMaterial(const QString &elementPath,
- const QString &materialDefinition)
+void Q3DSPresentation::createMaterial(const QString &materialDefinition,
+ const QString &subPresId)
{
QStringList materialDefinitions;
materialDefinitions << materialDefinition;
- createMaterials(elementPath, materialDefinitions);
+ createMaterials(materialDefinitions, subPresId);
}
/*!
Creates multiple materials specified by the \a materialDefinitions parameter into the
- presentation that owns the element specified by the \a elementPath parameter.
+ subpresentation specified by the \a subPresId parameter. If \a subPresId is empty,
+ the materials are created into the main presentation.
+
For more details, see createMaterial().
\sa createMaterial
\sa materialsCreated
*/
-void Q3DSPresentation::createMaterials(const QString &elementPath,
- const QStringList &materialDefinitions)
+void Q3DSPresentation::createMaterials(const QStringList &materialDefinitions,
+ const QString &subPresId)
{
if (d_ptr->m_viewerApp) {
- d_ptr->m_viewerApp->createMaterials(elementPath, materialDefinitions);
+ d_ptr->m_viewerApp->createMaterials(subPresId, materialDefinitions);
} else if (d_ptr->m_commandQueue) {
// We need to copy the list as queue takes ownership of it
QStringList *theMaterialDefinitions = new QStringList(materialDefinitions);
- d_ptr->m_commandQueue->queueCommand(elementPath, CommandType_CreateMaterials,
+ d_ptr->m_commandQueue->queueCommand(subPresId, CommandType_CreateMaterials,
theMaterialDefinitions);
}
}
/*!
- Deletes the material specified by \a materialName from the
- presentation that owns the element specified by the \a elementPath parameter.
+ Deletes the material specified by \a materialName from the presentation.
+ To delete material from a subpresentation, prefix \a materialName with the subpresentation ID
+ similarly to the element paths. For example: \c{"SubPresentationOne:MyMaterial"}.
+
Deleting materials is supported only for materials that have been dynamically created with
createMaterial() or createMaterials().
\sa deleteMaterials
\sa createMaterial
*/
-void Q3DSPresentation::deleteMaterial(const QString &elementPath, const QString &materialName)
+void Q3DSPresentation::deleteMaterial(const QString &materialName)
{
QStringList materialNames;
materialNames << materialName;
- deleteMaterials(elementPath, materialNames);
+ deleteMaterials(materialNames);
}
/*!
- Deletes materials specified by \a materialNames from the
- presentation that owns the element specified by the \a elementPath parameter.
+ Deletes materials specified by \a materialNames from the presentation.
+ To delete material from a subpresentation, prefix the material name with the subpresentation ID
+ similarly to the element paths. For example: \c{"SubPresentationOne:MyMaterial"}.
+
Deleting materials is supported only for materials that have been dynamically created with
createMaterial() or createMaterials().
\sa deleteMaterial
*/
-void Q3DSPresentation::deleteMaterials(const QString &elementPath, const QStringList &materialNames)
+void Q3DSPresentation::deleteMaterials(const QStringList &materialNames)
{
if (d_ptr->m_viewerApp) {
- d_ptr->m_viewerApp->deleteMaterials(elementPath, materialNames);
+ d_ptr->m_viewerApp->deleteMaterials(materialNames);
} else if (d_ptr->m_commandQueue) {
// We need to copy the list as queue takes ownership of it
QStringList *theMaterialNames = new QStringList(materialNames);
- d_ptr->m_commandQueue->queueCommand(elementPath, CommandType_DeleteMaterials,
- theMaterialNames);
+ d_ptr->m_commandQueue->queueCommand(CommandType_DeleteMaterials, theMaterialNames);
}
}
@@ -1193,7 +1199,9 @@ void Q3DSPresentation::keyReleaseEvent(QKeyEvent *e)
\qmlsignal Presentation::materialsCreated
Emitted when one or more materials have been created in response to createMaterial()
or createMaterials() calls. The \a materialNames list contains the names of the created
- materials. If creation failed, \a error string indicates the reason.
+ materials. If the material is created into a subpresentation, the name is prefixed with
+ subpresentation ID followed by a colon.
+ If creation failed, \a error string indicates the reason.
\sa createMaterial
\sa createMaterials
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h
index 4566443d..03283a9e 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dspresentation.h
@@ -101,10 +101,10 @@ public:
const QVector<QHash<QString, QVariant>> &properties);
void deleteElement(const QString &elementPath);
void deleteElements(const QStringList &elementPaths);
- void createMaterial(const QString &elementPath, const QString &materialDefinition);
- void createMaterials(const QString &elementPath, const QStringList &materialDefinitions);
- void deleteMaterial(const QString &elementPath, const QString &materialName);
- void deleteMaterials(const QString &elementPath, const QStringList &materialNames);
+ void createMaterial(const QString &materialDefinition, const QString &subPresId = {});
+ void createMaterials(const QStringList &materialDefinitions, const QString &subPresId = {});
+ void deleteMaterial(const QString &materialName);
+ void deleteMaterials(const QStringList &materialNames);
void createMesh(const QString &meshName, const Q3DSGeometry &geometry);
void createMeshes(const QHash<QString, const Q3DSGeometry *> &meshData);
void deleteMesh(const QString &meshName);
diff --git a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsrenderer.cpp b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsrenderer.cpp
index 4bd8ed0a..7366d6a6 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsrenderer.cpp
+++ b/src/Runtime/ogl-runtime/src/api/studio3dqml/q3dsrenderer.cpp
@@ -369,7 +369,7 @@ void Q3DSRenderer::processCommands()
break;
}
case CommandType_DeleteMaterials: {
- m_runtime->deleteMaterials(cmd.m_elementPath, *static_cast<QStringList *>(cmd.m_data));
+ m_runtime->deleteMaterials(*static_cast<QStringList *>(cmd.m_data));
// Runtime makes copy of the data in its own format, so we can delete it now
auto &command = m_commands.commandAt(i);
delete reinterpret_cast<QStringList *>(command.m_data);
diff --git a/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.cpp b/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.cpp
index 5b79234c..c1f3b3d0 100644
--- a/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.cpp
+++ b/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.cpp
@@ -217,9 +217,9 @@ public:
void createElements(const QString &parentElementPath, const QString &slideName,
const QVector<QHash<QString, QVariant>> &properties) override;
void deleteElements(const QStringList &elementPaths) override;
- void createMaterials(const QString &elementPath,
+ void createMaterials(const QString &subPresId,
const QStringList &materialDefinitions) override;
- void deleteMaterials(const QString &elementPath, const QStringList &materialNames) override;
+ void deleteMaterials(const QStringList &materialNames) override;
void createMesh(const QString &name, qt3dsimp::Mesh *mesh) override;
void deleteMeshes(const QStringList &meshNames) override;
void SetAttribute(const char *elementPath, const char *attributeName,
@@ -667,26 +667,26 @@ void CRuntimeView::deleteElements(const QStringList &elementPaths)
}
}
-void CRuntimeView::createMaterials(const QString &elementPath,
+void CRuntimeView::createMaterials(const QString &subPresId,
const QStringList &materialDefinitions)
{
if (m_Application) {
Q3DStudio::CQmlEngine &theBridgeEngine
= static_cast<Q3DStudio::CQmlEngine &>(m_RuntimeFactoryCore->GetScriptEngineQml());
theBridgeEngine.createMaterials(
- elementPath, materialDefinitions,
+ subPresId, materialDefinitions,
&m_RuntimeFactory->GetQt3DSRenderContext().GetCustomMaterialSystem(),
&m_RuntimeFactory->GetQt3DSRenderContext().GetDynamicObjectSystem(),
&m_RuntimeFactory->GetQt3DSRenderContext().GetRenderer());
}
}
-void CRuntimeView::deleteMaterials(const QString &elementPath, const QStringList &materialNames)
+void CRuntimeView::deleteMaterials(const QStringList &materialNames)
{
if (m_Application) {
Q3DStudio::CQmlEngine &theBridgeEngine
= static_cast<Q3DStudio::CQmlEngine &>(m_RuntimeFactoryCore->GetScriptEngineQml());
- theBridgeEngine.deleteMaterials(elementPath, materialNames,
+ theBridgeEngine.deleteMaterials(materialNames,
&m_RuntimeFactory->GetQt3DSRenderContext().GetRenderer());
}
}
diff --git a/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.h b/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.h
index 6d0e45cb..22d8cba7 100644
--- a/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.h
+++ b/src/Runtime/ogl-runtime/src/engine/Qt3DSRuntimeView.h
@@ -204,9 +204,9 @@ public:
virtual void createElements(const QString &parentElementPath, const QString &slideName,
const QVector<QHash<QString, QVariant>> &properties) = 0;
virtual void deleteElements(const QStringList &elementPaths) = 0;
- virtual void createMaterials(const QString &elementPath,
+ virtual void createMaterials(const QString &subPresId,
const QStringList &materialDefinitions) = 0;
- virtual void deleteMaterials(const QString &elementPath, const QStringList &materialNames) = 0;
+ virtual void deleteMaterials(const QStringList &materialNames) = 0;
virtual void createMesh(const QString &name, qt3dsimp::Mesh *mesh) = 0;
virtual void deleteMeshes(const QStringList &meshNames) = 0;
virtual void SetAttribute(const char *elementPath, const char *attributeName,
diff --git a/src/Runtime/ogl-runtime/src/runtime/Qt3DSIScriptBridge.h b/src/Runtime/ogl-runtime/src/runtime/Qt3DSIScriptBridge.h
index abbfcd5b..889968d3 100644
--- a/src/Runtime/ogl-runtime/src/runtime/Qt3DSIScriptBridge.h
+++ b/src/Runtime/ogl-runtime/src/runtime/Qt3DSIScriptBridge.h
@@ -173,11 +173,11 @@ public: // Elements
qt3ds::render::IQt3DSRenderer *renderer) = 0;
virtual void deleteElements(const QStringList &elementPath,
qt3ds::render::IQt3DSRenderer *renderer) = 0;
- virtual void createMaterials(const QString &elementPath, const QStringList &materialDefinitions,
+ virtual void createMaterials(const QString &subPresId, const QStringList &materialDefinitions,
qt3ds::render::ICustomMaterialSystem *customMaterialSystem,
qt3ds::render::IDynamicObjectSystem *dynamicObjectSystem,
qt3ds::render::IQt3DSRenderer *renderer) = 0;
- virtual void deleteMaterials(const QString &elementPath, const QStringList &materialNames,
+ virtual void deleteMaterials(const QStringList &materialNames,
qt3ds::render::IQt3DSRenderer *renderer) = 0;
virtual void createMesh(const QString &name, qt3dsimp::Mesh *mesh,
qt3ds::render::IBufferManager *bufferManager) = 0;
diff --git a/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp b/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp
index e5aecc74..3e741b39 100644
--- a/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp
+++ b/src/Runtime/ogl-runtime/src/runtime/Qt3DSQmlEngine.cpp
@@ -433,11 +433,11 @@ public:
qt3ds::render::IQt3DSRenderer *renderer) override;
void deleteElements(const QStringList &elementPaths,
qt3ds::render::IQt3DSRenderer *renderer) override;
- void createMaterials(const QString &elementPath, const QStringList &materialDefinitions,
+ void createMaterials(const QString &subPresId, const QStringList &materialDefinitions,
qt3ds::render::ICustomMaterialSystem *customMaterialSystem,
IDynamicObjectSystem *dynamicObjectSystem,
qt3ds::render::IQt3DSRenderer *renderer) override;
- void deleteMaterials(const QString &elementPath, const QStringList &materialNames,
+ void deleteMaterials(const QStringList &materialNames,
qt3ds::render::IQt3DSRenderer *renderer) override;
void createMesh(const QString &name, qt3dsimp::Mesh *mesh,
qt3ds::render::IBufferManager *bufferManager) override;
@@ -1021,6 +1021,9 @@ void CQmlEngineImpl::createElements(const QString &parentElementPath, const QStr
QByteArray newElementNameBa = newElementName.toUtf8();
QString refMatName = fixedProps.take(QStringLiteral("material")).toString();
+ int colonIndex = refMatName.indexOf(QLatin1Char(':'));
+ if (colonIndex != -1)
+ refMatName = refMatName.mid(colonIndex + 1);
if (refMatName.startsWith(QLatin1Char('#'))) // Absolute reference
refMatName = refMatName.mid(1);
else if (!refMatName.isEmpty() && !refMatName.contains(QLatin1Char('/')))
@@ -1108,7 +1111,7 @@ void CQmlEngineImpl::createElements(const QString &parentElementPath, const QStr
// Create new element
QString localElementPath = elementPaths[elementIndex];
- int colonIndex = localElementPath.indexOf(QLatin1Char(':'));
+ colonIndex = localElementPath.indexOf(QLatin1Char(':'));
if (colonIndex != -1)
localElementPath = localElementPath.mid(colonIndex + 1);
TElement &newElem = m_Application->GetElementAllocator().CreateElement(
@@ -1282,11 +1285,11 @@ TElement *CQmlEngineImpl::createMaterialContainer(TElement *parent, CPresentatio
}
/**
- Creates material into material container of the presentation that owns the specified element.
+ Creates material into material container of the specified subpresentation.
The materialDefinition parameter can contain a .materialdef file path or
the entire material definition in the .materialdef format.
*/
-void CQmlEngineImpl::createMaterials(const QString &elementPath,
+void CQmlEngineImpl::createMaterials(const QString &subPresId,
const QStringList &materialDefinitions,
ICustomMaterialSystem *customMaterialSystem,
IDynamicObjectSystem *dynamicObjectSystem,
@@ -1309,8 +1312,11 @@ void CQmlEngineImpl::createMaterials(const QString &elementPath,
if (!error.isEmpty())
deleteElements(createdElements, renderer);
QStringList materialNames;
+ QString prefix;
+ if (!subPresId.isEmpty())
+ prefix = subPresId + QLatin1Char(':');
for (auto &materialInfo : materialInfos)
- materialNames << materialInfo->materialName;
+ materialNames << prefix + materialInfo->materialName;
qDeleteAll(materialInfos);
notifyMaterialCreation(materialNames, error);
};
@@ -1326,11 +1332,14 @@ void CQmlEngineImpl::createMaterials(const QString &elementPath,
}
};
- QByteArray thePath = elementPath.toUtf8();
- TElement *element = getTarget(thePath.constData());
+ QByteArray theSubPresId = subPresId.toUtf8();
+ if (theSubPresId.isEmpty())
+ presentation = m_Application->GetPrimaryPresentation();
+ else
+ presentation = m_Application->GetPresentationById(theSubPresId.constData());
- if (!element) {
- error = QObject::tr("Invalid element: '%1'").arg(elementPath);
+ if (!presentation) {
+ error = QObject::tr("Invalid presentation ID: '%1'").arg(subPresId);
presentation = m_Application->GetPrimaryPresentation();
presPath = QFileInfo(presentation->GetFilePath()).absolutePath();
projPath = presentation->getProjectPath();
@@ -1339,7 +1348,6 @@ void CQmlEngineImpl::createMaterials(const QString &elementPath,
return;
}
- presentation = static_cast<CPresentation *>(element->GetBelongedPresentation());
presPath = QFileInfo(presentation->GetFilePath()).absolutePath();
projPath = presentation->getProjectPath();
getMaterialInfos();
@@ -1652,42 +1660,77 @@ void CQmlEngineImpl::createMaterials(const QString &elementPath,
handleError();
}
-void CQmlEngineImpl::deleteMaterials(const QString &elementPath,
- const QStringList &materialNames,
- IQt3DSRenderer *renderer)
+void CQmlEngineImpl::deleteMaterials(const QStringList &materialNames, IQt3DSRenderer *renderer)
{
// Material class (i.e. the shader) is not deleted as those can be shared between materials,
// so we just delete the material elements from the container and the related render objects
- QByteArray thePath = elementPath.toUtf8();
- TElement *element = getTarget(thePath.constData());
- Q_ASSERT_X(element, __FUNCTION__, QStringLiteral("Invalid element path: '%1'")
- .arg(elementPath).toUtf8());
- CPresentation *presentation = static_cast<CPresentation *>(element->GetBelongedPresentation());
-
- // Find material container
- auto &strTable = presentation->GetStringTable();
- TElement *rootElement = presentation->GetRoot();
- const auto containerName = strTable.RegisterStr("__Container");
- TElement *container = rootElement->FindChild(CHash::HashString(containerName.c_str()));
- Q_ASSERT_X(container, __FUNCTION__,
- QStringLiteral("No material container found for element: '%1'")
- .arg(elementPath).toUtf8());
-
- QVector<TElement *> elementsToDelete;
- for (const auto &materialName : materialNames) {
- TElement *firstChild = nullptr;
- TElement *nextChild = container->GetChild();
- firstChild = nextChild;
- while (nextChild) {
- QString childName = QString::fromUtf8(nextChild->m_Name);
- if (childName == materialName)
- elementsToDelete << nextChild;
- nextChild = nextChild->GetSibling();
+ // Sort materials to presentations
+ QMultiHash<QString, QString> presMaterialMap;
+ QSet<QString> presIds;
+ for (const auto &matName : materialNames) {
+ QString presId;
+ QString localName = matName;
+ int index = matName.indexOf(QLatin1Char(':'));
+ if (index != -1) {
+ presId = matName.left(index);
+ localName = matName.mid(index + 1);
}
+ presMaterialMap.insert(presId, localName);
+ presIds.insert(presId);
}
+ for (const auto &presId : qAsConst(presIds)) {
+ QByteArray theId = presId.toUtf8();
+ CPresentation *presentation = nullptr;
+ if (presId.isEmpty())
+ presentation = m_Application->GetPrimaryPresentation();
+ else
+ presentation = m_Application->GetPresentationById(theId.constData());
- deleteElements(elementsToDelete, renderer);
+ if (presentation) {
+ // Find material container
+ auto &strTable = presentation->GetStringTable();
+ TElement *rootElement = presentation->GetRoot();
+ const auto containerName = strTable.RegisterStr("__Container");
+ TElement *container = rootElement->FindChild(CHash::HashString(containerName.c_str()));
+ Q_ASSERT_X(container, __FUNCTION__,
+ QStringLiteral("No material container found for presentation: '%1'")
+ .arg(presId).toUtf8());
+
+ QVector<TElement *> elementsToDelete;
+ const QList<QString> matNames = presMaterialMap.values(presId);
+ for (const auto &materialName : matNames) {
+ TElement *firstChild = nullptr;
+ TElement *nextChild = container->GetChild();
+ firstChild = nextChild;
+ bool added = false;
+ while (nextChild) {
+ QString childName = QString::fromUtf8(nextChild->m_Name);
+ if (childName == materialName) {
+ elementsToDelete << nextChild;
+ added = true;
+ break;
+ }
+ nextChild = nextChild->GetSibling();
+ }
+ if (!added) {
+ if (presId.isEmpty()) {
+ qWarning() << __FUNCTION__
+ << QStringLiteral("Could not find material '%1'")
+ .arg(materialName);
+ } else {
+ qWarning() << __FUNCTION__
+ << QStringLiteral("Could not find material '%1' in '%2'")
+ .arg(materialName).arg(presId);
+ }
+ }
+ }
+ deleteElements(elementsToDelete, renderer);
+ } else {
+ qWarning() << __FUNCTION__ << "Warning: Presentation ID could not be resolved:"
+ << presId;
+ }
+ }
}
void CQmlEngineImpl::createMesh(const QString &name, qt3dsimp::Mesh *mesh,
diff --git a/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.cpp b/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.cpp
index 4c7be294..31991243 100644
--- a/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.cpp
+++ b/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.cpp
@@ -935,21 +935,21 @@ void Q3DSViewerApp::deleteElements(const QStringList &elementPaths)
m_Impl.m_view->deleteElements(elementPaths);
}
-void Q3DSViewerApp::createMaterials(const QString &elementPath,
+void Q3DSViewerApp::createMaterials(const QString &subPresId,
const QStringList &materialDefinitions)
{
if (!m_Impl.m_view)
return;
- m_Impl.m_view->createMaterials(elementPath, materialDefinitions);
+ m_Impl.m_view->createMaterials(subPresId, materialDefinitions);
}
-void Q3DSViewerApp::deleteMaterials(const QString &elementPath, const QStringList &materialNames)
+void Q3DSViewerApp::deleteMaterials(const QStringList &materialNames)
{
if (!m_Impl.m_view)
return;
- m_Impl.m_view->deleteMaterials(elementPath, materialNames);
+ m_Impl.m_view->deleteMaterials(materialNames);
}
void Q3DSViewerApp::createMeshes(const QHash<QString, Q3DSViewer::MeshData> &meshData)
diff --git a/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.h b/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.h
index 7a9299f2..06fdeef0 100644
--- a/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.h
+++ b/src/Runtime/ogl-runtime/src/viewer/Qt3DSViewerApp.h
@@ -466,8 +466,8 @@ public:
void createElements(const QString &parentElementPath, const QString &slideName,
const QVector<QHash<QString, QVariant>> &properties);
void deleteElements(const QStringList &elementPaths);
- void createMaterials(const QString &elementPath, const QStringList &materialDefinitions);
- void deleteMaterials(const QString &elementPath, const QStringList &materialNames);
+ void createMaterials(const QString &subPresId, const QStringList &materialDefinitions);
+ void deleteMaterials(const QStringList &materialNames);
void createMeshes(const QHash<QString, Q3DSViewer::MeshData> &meshData);
void deleteMeshes(const QStringList &meshNames);
diff --git a/tests/auto/viewer/tst_qt3dsviewer.cpp b/tests/auto/viewer/tst_qt3dsviewer.cpp
index 9424612e..6f8be09c 100644
--- a/tests/auto/viewer/tst_qt3dsviewer.cpp
+++ b/tests/auto/viewer/tst_qt3dsviewer.cpp
@@ -211,10 +211,10 @@ void tst_qt3dsviewer::testCreateElement()
QString md = loadMatDefFile(QStringLiteral(
":/scenes/simple_cube_animation/materials/Basic Red.materialdef"));
- m_presentation->createMaterial(QStringLiteral("Scene"), md);
+ m_presentation->createMaterial(md);
md = loadMatDefFile(QStringLiteral(
":/scenes/simple_cube_animation/materials/Basic Green.materialdef"));
- m_presentation->createMaterial(QStringLiteral("Scene"), md);
+ m_presentation->createMaterial(md);
QHash<QString, QVariant> data;
data.insert(QStringLiteral("name"), QStringLiteral("New Cylinder"));
@@ -429,7 +429,7 @@ void tst_qt3dsviewer::testCreateMaterial()
QVERIFY(!matDef.isEmpty());
materialDefinitions << matDef;
- m_presentation->createMaterials(QStringLiteral("Scene"), materialDefinitions);
+ m_presentation->createMaterials(materialDefinitions);
m_createdMaterials << QStringLiteral("materials/Basic Blue")
<< QStringLiteral("materials/Basic Texture")
<< QStringLiteral("materials/Copper");
@@ -482,7 +482,7 @@ void tst_qt3dsviewer::testCreateMaterial()
md.replace(QStringLiteral("Basic Blue"), QStringLiteral("Just Yellow"));
md.replace(QRegularExpression(QStringLiteral("\"diffuse\">.*<")),
QStringLiteral("\"diffuse\">1 1 0 1<"));
- m_presentation->createMaterial(QStringLiteral("Scene"), md);
+ m_presentation->createMaterial(md);
m_createdMaterials << QStringLiteral("materials/Just Yellow");
});
@@ -491,7 +491,7 @@ void tst_qt3dsviewer::testCreateMaterial()
// Material not removed from m_createdMaterials purposefully to ensure deleting already
// deleted material is handled properly later
m_presentation->deleteElement(QStringLiteral("Scene.Layer.Textured Cone"));
- m_presentation->deleteMaterial(QStringLiteral("Scene"), "materials/Basic Texture");
+ m_presentation->deleteMaterial("materials/Basic Texture");
// Try to use the deleted material - should find a fallback material
QHash<QString, QVariant> data;
@@ -542,7 +542,6 @@ void tst_qt3dsviewer::testCreateMesh()
});
m_presentation->createMaterial(
- QStringLiteral("Scene"),
QStringLiteral(":/scenes/simple_cube_animation/materials/Basic Texture.materialdef"));
m_presentation->createMesh(QStringLiteral("Pyramid"), pyramid);
m_createdMeshes << QStringLiteral("Pyramid");
@@ -626,7 +625,7 @@ void tst_qt3dsviewer::testMouseEvents()
void tst_qt3dsviewer::deleteCreated()
{
m_presentation->deleteElements(m_createdElements);
- m_presentation->deleteMaterials(QStringLiteral("Scene"), m_createdMaterials);
+ m_presentation->deleteMaterials(m_createdMaterials);
m_presentation->deleteMeshes(m_createdMeshes);
m_createdElements.clear();
m_createdMaterials.clear();