summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2019-05-23 13:28:27 +0300
committerAntti Määttä <antti.maatta@qt.io>2019-05-23 13:36:28 +0300
commit87a20071d506485a337340824a91edc6d24f782e (patch)
tree3a4edde86f4f66e2c591cfa60a0f9ee7cbef94e0
parentc5338095a3ff3ae04d447125599d36351a436229 (diff)
Create material container if it doesn't exist
Task-number: QT3DS-3412 Change-Id: I3952e39939f239ba587fc21a1106ddfa2cb59de6 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Pasi Keränen <pasi.keranen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r--src/Runtime/Source/runtime/Qt3DSQmlEngine.cpp23
-rw-r--r--tests/auto/viewer/tst_qt3dsviewer.cpp16
-rw-r--r--tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef2
-rw-r--r--tests/scenes/simple_cube_animation/materials/Basic Green.materialdef2
-rw-r--r--tests/scenes/simple_cube_animation/materials/Basic Red.materialdef2
-rw-r--r--tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip17
6 files changed, 41 insertions, 21 deletions
diff --git a/src/Runtime/Source/runtime/Qt3DSQmlEngine.cpp b/src/Runtime/Source/runtime/Qt3DSQmlEngine.cpp
index 02e5053e..6fd3090c 100644
--- a/src/Runtime/Source/runtime/Qt3DSQmlEngine.cpp
+++ b/src/Runtime/Source/runtime/Qt3DSQmlEngine.cpp
@@ -462,6 +462,7 @@ public:
void Shutdown(qt3ds::NVFoundationBase &inFoundation) override;
private:
+ TElement *createMaterialContainer(TElement *parent, CPresentation *presentation);
void createComponent(QQmlComponent *component, TElement *element);
TElement *getTarget(const char *component);
void listAllElements(TElement *root, QList<TElement *> &elements);
@@ -1252,6 +1253,20 @@ void CQmlEngineImpl::deleteElements(const QStringList &elementPaths,
deleteElements(elements, renderer);
}
+TElement *CQmlEngineImpl::createMaterialContainer(TElement *parent, CPresentation *presentation)
+{
+ TPropertyDescAndValueList prop;
+ auto &strTable = presentation->GetStringTable();
+ const auto matName = strTable.RegisterStr(QStringLiteral("__Container"));
+ const auto matType = strTable.RegisterStr(QStringLiteral("Material"));
+ const auto matClass = CRegisteredString();
+ TElement &element = m_Application->GetElementAllocator().CreateElement(
+ matName, matType, matClass,
+ toConstDataRef(prop.data(), prop.size()),
+ presentation, parent, false);
+ return &element;
+}
+
/**
Creates material into material container of the presentation that owns the specified element.
The materialDefinition parameter can contain a .materialdef file path or
@@ -1322,12 +1337,8 @@ void CQmlEngineImpl::createMaterials(const QString &elementPath,
TElement *rootElement = presentation->GetRoot();
const auto containerName = strTable.RegisterStr("__Container");
TElement *container = rootElement->FindChild(CHash::HashString(containerName.c_str()));
- if (!container) {
- // TODO: Create a material container if it doesn't exist (QT3DS-3412)
- error = QObject::tr("Presentation has no material container");
- handleError();
- return;
- }
+ if (!container)
+ container = createMaterialContainer(rootElement, presentation);
for (auto &materialInfo : materialInfos) {
if (materialInfo->materialName.isEmpty() || materialInfo->materialProps.isEmpty()) {
diff --git a/tests/auto/viewer/tst_qt3dsviewer.cpp b/tests/auto/viewer/tst_qt3dsviewer.cpp
index e0653d7c..a20657af 100644
--- a/tests/auto/viewer/tst_qt3dsviewer.cpp
+++ b/tests/auto/viewer/tst_qt3dsviewer.cpp
@@ -197,8 +197,24 @@ void tst_qt3dsviewer::testCreateElement()
}
});
+ auto loadMatDefFile = [&](const QString &fileName) -> QString {
+ QFile matDefFile(fileName);
+ if (!matDefFile.open(QIODevice::ReadOnly | QIODevice::Text))
+ return {};
+
+ QTextStream in(&matDefFile);
+ return in.readAll();
+ };
+
int animValue = 0;
+ QString md = loadMatDefFile(QStringLiteral(
+ ":/scenes/simple_cube_animation/materials/Basic Red.materialdef"));
+ m_presentation->createMaterial(QStringLiteral("Scene"), md);
+ md = loadMatDefFile(QStringLiteral(
+ ":/scenes/simple_cube_animation/materials/Basic Green.materialdef"));
+ m_presentation->createMaterial(QStringLiteral("Scene"), md);
+
QHash<QString, QVariant> data;
data.insert(QStringLiteral("name"), QStringLiteral("New Cylinder"));
data.insert(QStringLiteral("sourcepath"), QStringLiteral("#Cylinder"));
diff --git a/tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef b/tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef
index 7fdda62b..c35d47b8 100644
--- a/tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef
+++ b/tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef
@@ -21,5 +21,5 @@
<Property name="importfile"></Property>
<Property name="type">Material</Property>
<Property name="name"><![CDATA[materials/Basic Blue]]></Property>
- <Property name="path"><![CDATA[C:/dev/qt/NDD/qt3ds2/tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef]]></Property>
+ <Property name="path"><![CDATA[C:/dev/q3dstudio/qt3dstudio/tests/scenes/simple_cube_animation/materials/Basic Blue.materialdef]]></Property>
</MaterialData> \ No newline at end of file
diff --git a/tests/scenes/simple_cube_animation/materials/Basic Green.materialdef b/tests/scenes/simple_cube_animation/materials/Basic Green.materialdef
index 59a0ae02..273a348c 100644
--- a/tests/scenes/simple_cube_animation/materials/Basic Green.materialdef
+++ b/tests/scenes/simple_cube_animation/materials/Basic Green.materialdef
@@ -21,5 +21,5 @@
<Property name="importfile"></Property>
<Property name="type">Material</Property>
<Property name="name"><![CDATA[materials/Basic Green]]></Property>
- <Property name="path"><![CDATA[C:/dev/qt/NDD/qt3ds2/tests/scenes/simple_cube_animation/materials/Basic Green.materialdef]]></Property>
+ <Property name="path"><![CDATA[C:/dev/q3dstudio/qt3dstudio/tests/scenes/simple_cube_animation/materials/Basic Green.materialdef]]></Property>
</MaterialData> \ No newline at end of file
diff --git a/tests/scenes/simple_cube_animation/materials/Basic Red.materialdef b/tests/scenes/simple_cube_animation/materials/Basic Red.materialdef
index ecb9bb43..38b8eb7b 100644
--- a/tests/scenes/simple_cube_animation/materials/Basic Red.materialdef
+++ b/tests/scenes/simple_cube_animation/materials/Basic Red.materialdef
@@ -21,5 +21,5 @@
<Property name="importfile"></Property>
<Property name="type">Material</Property>
<Property name="name"><![CDATA[materials/Basic Red]]></Property>
- <Property name="path"><![CDATA[C:/dev/qt/NDD/qt3ds2/tests/scenes/simple_cube_animation/materials/Basic Red.materialdef]]></Property>
+ <Property name="path"><![CDATA[C:/dev/q3dstudio/qt3dstudio/tests/scenes/simple_cube_animation/materials/Basic Red.materialdef]]></Property>
</MaterialData> \ No newline at end of file
diff --git a/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip b/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip
index e0de7206..7578fe88 100644
--- a/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip
+++ b/tests/scenes/simple_cube_animation/presentations/simple_cube_animation.uip
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<UIP version="5" >
+<UIP version="6" >
<Project >
<ProjectSettings author="" company="" presentationWidth="600" presentationHeight="600" maintainAspect="False" preferKtx="False" >
<CustomColors count="16" >#7391ff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff</CustomColors>
@@ -10,16 +10,12 @@
<Camera id="Camera" />
<Light id="Light" />
<Model id="Cube" variants="" >
- <ReferencedMaterial id="Basic Green" />
+ <Material id="Basic Green_animatable" />
</Model>
<Model id="Cube2" variants="" >
- <ReferencedMaterial id="Basic Red" />
+ <Material id="Basic Red_animatable" />
</Model>
</Layer>
- <Material id="__Container" >
- <Material id="materials/Basic Red" />
- <Material id="materials/Basic Green" />
- </Material>
</Scene>
</Graph>
<Logic >
@@ -31,9 +27,6 @@
<AnimationTrack property="position.y" type="EaseInOut" >0 0 100 100 5 0 100 100</AnimationTrack>
<AnimationTrack property="position.z" type="EaseInOut" >0 0 100 100 5 0 100 100</AnimationTrack>
</Add>
- <Add ref="#__Container" name="__Container" />
- <Add ref="#materials/Basic Red" name="materials/Basic Red" diffuse="1 0 0.0156863 1" importid="" />
- <Add ref="#materials/Basic Green" name="materials/Basic Green" diffuse="0.180392 1 0 1" importid="" />
<State id="Scene-Slide1" name="Slide1" playmode="Play Through To..." >
<Set ref="#Layer" endtime="5000" />
<Set ref="#Camera" endtime="5000" />
@@ -46,14 +39,14 @@
<AnimationTrack property="scale.y" type="EaseInOut" >0 1 100 100 2 1.5 100 100 3 1.5 100 100 6 2 100 100 7 2 100 100 8 1 100 100 9 1 100 100</AnimationTrack>
<AnimationTrack property="scale.z" type="EaseInOut" >0 1 100 100 2 1 100 100 3 1.5 100 100 6 2 100 100 7 2 100 100 8 2 100 100 9 1 100 100</AnimationTrack>
</Add>
- <Add ref="#Basic Green" name="Basic Green" endtime="5000" referencedmaterial="#materials/Basic Green" sourcepath="../materials/Basic Green.materialdef" />
+ <Add ref="#Basic Green_animatable" name="Basic Green_animatable" blendmode="Normal" bumpamount="0.5" diffuse="0.180392 1 0 1" diffuselightwrap="0" displaceamount="20" emissivecolor="1 1 1 1" emissivepower="0" fresnelPower="0" importfile="" importid="" ior="1.5" opacity="100" shaderlighting="Pixel" sourcepath="" specularamount="0" specularmodel="Default" specularroughness="0" speculartint="1 1 1 1" translucentfalloff="1" type="Material" vertexcolors="False" />
</State>
<State id="Scene-Slide2" name="Slide2" playmode="Play Through To..." playthroughto="Previous" >
<Set ref="#Layer" endtime="5000" />
<Set ref="#Camera" endtime="5000" />
<Set ref="#Light" endtime="5000" />
<Add ref="#Cube2" name="Cube2" endtime="5000" position="-401.836 -18.4752 600" scale="3 3 3" sourcepath="#Cube" />
- <Add ref="#Basic Red" name="Basic Red" endtime="5000" referencedmaterial="#materials/Basic Red" sourcepath="../materials/Basic Red.materialdef" />
+ <Add ref="#Basic Red_animatable" name="Basic Red_animatable" blendmode="Normal" bumpamount="0.5" diffuse="1 0 0.0156863 1" diffuselightwrap="0" displaceamount="20" emissivecolor="1 1 1 1" emissivepower="0" fresnelPower="0" importfile="" importid="" ior="1.5" opacity="100" shaderlighting="Pixel" sourcepath="" specularamount="0" specularmodel="Default" specularroughness="0" speculartint="1 1 1 1" translucentfalloff="1" type="Material" vertexcolors="False" />
</State>
</State>
</Logic>