From 5e9a1798cc697136aae4125a157e654d7e49530a Mon Sep 17 00:00:00 2001 From: Jere Tuliniemi Date: Thu, 10 Jan 2019 15:58:37 +0200 Subject: Support custom materials created from a QByteArray MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow a QByteArray to be used to create a custom material instead reading it from a file. Task-number: QT3DS-2906 Change-Id: I2718240186b62c0ff2bf36e5313bed6754472066 Reviewed-by: Miikka Heikkinen Reviewed-by: Tomi Korpipää Reviewed-by: Antti Määttä --- src/runtime/q3dscustommaterial.cpp | 14 ++++++++++++++ src/runtime/q3dscustommaterial_p.h | 3 +++ src/runtime/q3dsuippresentation.cpp | 13 +++++++++++++ src/runtime/q3dsuippresentation_p.h | 1 + 4 files changed, 31 insertions(+) diff --git a/src/runtime/q3dscustommaterial.cpp b/src/runtime/q3dscustommaterial.cpp index 77b8cb3..592c19f 100644 --- a/src/runtime/q3dscustommaterial.cpp +++ b/src/runtime/q3dscustommaterial.cpp @@ -176,7 +176,21 @@ Q3DSCustomMaterial Q3DSCustomMaterialParser::parse(const QString &filename, bool *ok = false; return Q3DSCustomMaterial(); } + return parse(ok); +} +Q3DSCustomMaterial Q3DSCustomMaterialParser::parse(const QByteArray &data, bool *ok) +{ + if (!setSourceData(data)) { + if (ok != nullptr) + *ok = false; + return Q3DSCustomMaterial(); + } + return parse(ok); +} + +Q3DSCustomMaterial Q3DSCustomMaterialParser::parse(bool *ok) +{ m_material = Q3DSCustomMaterial(); QXmlStreamReader *r = reader(); diff --git a/src/runtime/q3dscustommaterial_p.h b/src/runtime/q3dscustommaterial_p.h index 8c3cfbb..11eca98 100644 --- a/src/runtime/q3dscustommaterial_p.h +++ b/src/runtime/q3dscustommaterial_p.h @@ -138,8 +138,11 @@ class Q3DSV_PRIVATE_EXPORT Q3DSCustomMaterialParser : public Q3DSAbstractXmlPars { public: Q3DSCustomMaterial parse(const QString &filename, bool *ok = nullptr); + Q3DSCustomMaterial parse(const QByteArray &data, bool *ok = nullptr); private: + Q3DSCustomMaterial parse(bool *ok = nullptr); + void parseMaterial(); void parseMetaData(); void parseShaders(); diff --git a/src/runtime/q3dsuippresentation.cpp b/src/runtime/q3dsuippresentation.cpp index bafb313..260f4c4 100644 --- a/src/runtime/q3dsuippresentation.cpp +++ b/src/runtime/q3dsuippresentation.cpp @@ -4279,6 +4279,19 @@ Q3DSCustomMaterial Q3DSUipPresentation::customMaterial(const QString &idOrFilena return d->customMaterials.value(key); } +Q3DSCustomMaterial Q3DSUipPresentation::customMaterial(const QByteArray &id, const QByteArray &data) +{ + Q3DSCustomMaterialParser p; + bool ok = false; + Q3DSCustomMaterial mat = p.parse(data, &ok); + if (!ok) { + qWarning("Failed to parse metadata %s", id.constData()); + return Q3DSCustomMaterial(); + } + d->customMaterials.insert(id, mat); + return mat; +} + bool Q3DSUipPresentation::loadEffect(const QByteArray &id, const QString &assetFilename) { return loadMeta(id, assetFilename, &d->effects); diff --git a/src/runtime/q3dsuippresentation_p.h b/src/runtime/q3dsuippresentation_p.h index 2e89a22..064456b 100644 --- a/src/runtime/q3dsuippresentation_p.h +++ b/src/runtime/q3dsuippresentation_p.h @@ -2120,6 +2120,7 @@ public: void registerImageBuffer(const QString &sourcePath, bool hasTransparency); Q3DSCustomMaterial customMaterial(const QString &idOrFilename); + Q3DSCustomMaterial customMaterial(const QByteArray &id, const QByteArray &data); Q3DSEffect effect(const QString &idOrFilename); Q3DSBehavior behavior(const QString &idOrFilename); MeshList mesh(const QString &assetFilename, int part = 1); -- cgit v1.2.3