diff --git a/examples/quick3d/simple/main.qml b/examples/quick3d/simple/main.qml index caf45623c11de8ea3f4290fdd19d2363814867e1..2a27405f69026f1238c75793f04fc3fa1de6db2f 100644 --- a/examples/quick3d/simple/main.qml +++ b/examples/quick3d/simple/main.qml @@ -30,7 +30,7 @@ Window { clearColor: "green" backgroundMode: DemonSceneEnvironment.Color lightProbe: DemonImage { - source: ":/maps/OpenfootageNET_garage-1024.hdr" + source: "maps/OpenfootageNET_garage-1024.hdr" } } diff --git a/src/imports/materiallib/plugin.pro b/src/imports/materiallib/plugin.pro index 75e50e77506097d038fb7a53241b09b2eac1ebb3..585ef1b922550c55a4f2b32a0ff2ad02100e26e6 100644 --- a/src/imports/materiallib/plugin.pro +++ b/src/imports/materiallib/plugin.pro @@ -40,7 +40,51 @@ QML_FILES = \ FrostedGlassSinglePassMaterial.qml \ WalnutMatteMaterial.qml -# !static: CONFIG += qmlcache +MATERIAL_IMAGE_FILES += \ + maps/randomGradient1D.png \ + maps/randomGradient2D.png \ + maps/randomGradient3D.png \ + maps/randomGradient4D.png \ + maps/art_paper_normal.jpg \ + maps/art_paper_trans.jpg \ + maps/asphalt.jpg \ + maps/asphalt_bump.jpg \ + maps/bamboo_natural.jpg \ + maps/bamboo_natural_bump.jpg \ + maps/bamboo_natural_spec.jpg \ + maps/brushed_a.jpg \ + maps/brushed_full_contrast.jpg \ + maps/carbon_fiber.jpg \ + maps/carbon_fiber_aniso.jpg \ + maps/carbon_fiber_bump.jpg \ + maps/carbon_fiber_spec.jpg \ + maps/concentric_milled_steel.jpg \ + maps/concentric_milled_steel_aniso.jpg \ + maps/concrete_plain.jpg \ + maps/concrete_plain_bump.jpg \ + maps/cyclone_mesh_fencing.jpg \ + maps/cyclone_mesh_fencing_normal.jpg \ + maps/emissive.jpg \ + maps/emissive_mask.jpg \ + maps/grunge_b.jpg \ + maps/grunge_d.jpg \ + maps/metal_mesh.jpg \ + maps/metal_mesh_bump.jpg \ + maps/metal_mesh_spec.jpg \ + maps/paper_diffuse.jpg \ + maps/paper_trans.jpg \ + maps/powdercoat_bump_01.jpg \ + maps/shadow.jpg \ + maps/smooth_black_leather.jpg \ + maps/smooth_black_leather_bump.jpg \ + maps/smooth_black_leather_spec.jpg \ + maps/spherical_checker.jpg \ + maps/studded_rubber_bump.jpg \ + maps/walnut.jpg \ + maps/walnut_bump.jpg \ + maps/walnut_spec.jpg + +QML_FILES += $$MATERIAL_IMAGE_FILES OTHER_FILES += $$QML_FILES diff --git a/src/imports/materiallib/qtmateriallibrary.qrc b/src/imports/materiallib/qtmateriallibrary.qrc index ed1489490c306f37862084a328ab4b8963e5bdbf..abd9e443cf7249d3081cec39c9ca3003b6aa7f9c 100644 --- a/src/imports/materiallib/qtmateriallibrary.qrc +++ b/src/imports/materiallib/qtmateriallibrary.qrc @@ -10,48 +10,6 @@ <file>shaders/simpleGlass.frag</file> <file>shaders/meshFence.frag</file> <file>shaders/metalFenceFine.frag</file> - <file>maps/randomGradient1D.png</file> - <file>maps/randomGradient2D.png</file> - <file>maps/randomGradient3D.png</file> - <file>maps/randomGradient4D.png</file> - <file>maps/art_paper_normal.jpg</file> - <file>maps/art_paper_trans.jpg</file> - <file>maps/asphalt.jpg</file> - <file>maps/asphalt_bump.jpg</file> - <file>maps/bamboo_natural.jpg</file> - <file>maps/bamboo_natural_bump.jpg</file> - <file>maps/bamboo_natural_spec.jpg</file> - <file>maps/brushed_a.jpg</file> - <file>maps/brushed_full_contrast.jpg</file> - <file>maps/carbon_fiber.jpg</file> - <file>maps/carbon_fiber_aniso.jpg</file> - <file>maps/carbon_fiber_bump.jpg</file> - <file>maps/carbon_fiber_spec.jpg</file> - <file>maps/concentric_milled_steel.jpg</file> - <file>maps/concentric_milled_steel_aniso.jpg</file> - <file>maps/concrete_plain.jpg</file> - <file>maps/concrete_plain_bump.jpg</file> - <file>maps/cyclone_mesh_fencing.jpg</file> - <file>maps/cyclone_mesh_fencing_normal.jpg</file> - <file>maps/emissive.jpg</file> - <file>maps/emissive_mask.jpg</file> - <file>maps/grunge_b.jpg</file> - <file>maps/grunge_d.jpg</file> - <file>maps/metal_mesh.jpg</file> - <file>maps/metal_mesh_bump.jpg</file> - <file>maps/metal_mesh_spec.jpg</file> - <file>maps/paper_diffuse.jpg</file> - <file>maps/paper_trans.jpg</file> - <file>maps/powdercoat_bump_01.jpg</file> - <file>maps/shadow.jpg</file> - <file>maps/smooth_black_leather.jpg</file> - <file>maps/smooth_black_leather_bump.jpg</file> - <file>maps/smooth_black_leather_spec.jpg</file> - <file>maps/spherical_checker.jpg</file> - <file>maps/studded_rubber_bump.jpg</file> - <file>maps/walnut.jpg</file> - <file>maps/walnut_bump.jpg</file> - <file>maps/walnut_spec.jpg</file> <file>shaders/aluminum.frag</file> <file>shaders/aluminumAnodizedEmissive.frag</file> <file>shaders/aluminumAnodized.frag</file> diff --git a/src/quick3d/qdemonimage.cpp b/src/quick3d/qdemonimage.cpp index 6a7b08f6c7a01ca74e7f0b7542b603ed78efe1dc..6364dfa044fd7538ac9b0a0131391db8f51089a9 100644 --- a/src/quick3d/qdemonimage.cpp +++ b/src/quick3d/qdemonimage.cpp @@ -1,5 +1,6 @@ #include "qdemonimage.h" #include <QtDemonRuntimeRender/qdemonrenderimage.h> +#include <QtQml/QQmlFile> #include "qdemonobject_p.h" @@ -9,7 +10,7 @@ QDemonImage::QDemonImage() {} QDemonImage::~QDemonImage() {} -QString QDemonImage::source() const +QUrl QDemonImage::source() const { return m_source; } @@ -69,7 +70,7 @@ QDemonObject::Type QDemonImage::type() const return QDemonObject::Image; } -void QDemonImage::setSource(QString source) +void QDemonImage::setSource(const QUrl &source) { if (m_source == source) return; @@ -186,7 +187,7 @@ QDemonRenderGraphObject *QDemonImage::updateSpatialNode(QDemonRenderGraphObject auto imageNode = static_cast<QDemonRenderImage *>(node); - imageNode->m_imagePath = m_source; + imageNode->m_imagePath = QQmlFile::urlToLocalFileOrQrc(m_source); imageNode->m_scale = QVector2D(m_scaleu, m_scalev); imageNode->m_pivot = QVector2D(m_pivotu, m_pivotv); imageNode->m_rotation = m_rotationuv; diff --git a/src/quick3d/qdemonimage.h b/src/quick3d/qdemonimage.h index 8c401820f6538cd8fd76fe339e5529970c2d50fe..c71cfd339d674ba27a7db59d6ff460dba88591f0 100644 --- a/src/quick3d/qdemonimage.h +++ b/src/quick3d/qdemonimage.h @@ -2,6 +2,7 @@ #define QDEMONIMAGE_H #include <QtQuick3d/qdemonobject.h> +#include <QtCore/QUrl> QT_BEGIN_NAMESPACE @@ -9,7 +10,7 @@ struct QDemonRenderImage; class Q_QUICK3D_EXPORT QDemonImage : public QDemonObject { Q_OBJECT - Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(float scaleu READ scaleU WRITE setScaleU NOTIFY scaleUChanged) Q_PROPERTY(float scalev READ scaleV WRITE setScaleV NOTIFY scaleVChanged) Q_PROPERTY(MappingMode mappingmode READ mappingMode WRITE setMappingMode NOTIFY mappingModeChanged) @@ -42,7 +43,7 @@ public: QDemonImage(); ~QDemonImage() override; - QString source() const; + QUrl source() const; float scaleU() const; float scaleV() const; MappingMode mappingMode() const; @@ -58,7 +59,7 @@ public: QDemonRenderImage *getRenderImage(); public Q_SLOTS: - void setSource(QString source); + void setSource(const QUrl &source); void setScaleU(float scaleu); void setScaleV(float scalev); void setMappingMode(MappingMode mappingmode); @@ -71,7 +72,7 @@ public Q_SLOTS: void setPivotV(float pivotv); Q_SIGNALS: - void sourceChanged(QString source); + void sourceChanged(const QUrl &source); void scaleUChanged(float scaleu); void scaleVChanged(float scalev); void mappingModeChanged(MappingMode mappingmode); @@ -87,7 +88,7 @@ protected: QDemonRenderGraphObject *updateSpatialNode(QDemonRenderGraphObject *node) override; private: - QString m_source; + QUrl m_source; float m_scaleu = 1.0f; float m_scalev = 1.0f; MappingMode m_mappingmode = Normal; diff --git a/src/quick3d/qdemonmodel.cpp b/src/quick3d/qdemonmodel.cpp index 392aab48432662c119d3e8d638e28855564b7ae2..f7f43de355a012876d66c36e28994ae8e61f0223 100644 --- a/src/quick3d/qdemonmodel.cpp +++ b/src/quick3d/qdemonmodel.cpp @@ -7,6 +7,7 @@ #include <QtDemonRuntimeRender/qdemonrenderdefaultmaterial.h> #include <QtDemonRuntimeRender/qdemonrendermodel.h> +#include <QtQml/QQmlFile> QT_BEGIN_NAMESPACE @@ -19,7 +20,7 @@ QDemonObject::Type QDemonModel::type() const return QDemonObject::Model; } -QString QDemonModel::source() const +QUrl QDemonModel::source() const { return m_source; } @@ -59,7 +60,7 @@ QQmlListProperty<QDemonMaterial> QDemonModel::materials() QDemonModel::qmlClearMaterials); } -void QDemonModel::setSource(QString source) +void QDemonModel::setSource(const QUrl &source) { if (m_source == source) return; @@ -133,8 +134,7 @@ QDemonRenderGraphObject *QDemonModel::updateSpatialNode(QDemonRenderGraphObject QDemonNode::updateSpatialNode(node); auto modelNode = static_cast<QDemonRenderModel *>(node); - - modelNode->meshPath = m_source; + modelNode->meshPath = translateSource(); modelNode->skeletonRoot = m_skeletonRoot; modelNode->tessellationMode = TessModeValues(m_tesselationMode); modelNode->edgeTess = m_edgeTess; @@ -189,6 +189,26 @@ QDemonRenderGraphObject *QDemonModel::updateSpatialNode(QDemonRenderGraphObject return modelNode; } +// Source URL's need a bit of translation for the engine because of the +// use of fragment syntax for specifiying primitives and sub-meshes +// So we need to check for the fragment before translating to a qmlfile + +QString QDemonModel::translateSource() +{ + QString fragment; + if (m_source.hasFragment()) { + // Check if this is an index, or primative + bool isNumber = false; + m_source.fragment().toInt(&isNumber); + fragment = QStringLiteral("#") + m_source.fragment(); + // If it wasn't an index, then it was a primative + if (!isNumber) + return fragment; + } + + return QQmlFile::urlToLocalFileOrQrc(m_source) + fragment; +} + void QDemonModel::qmlAppendMaterial(QQmlListProperty<QDemonMaterial> *list, QDemonMaterial *material) { if (material == nullptr) diff --git a/src/quick3d/qdemonmodel.h b/src/quick3d/qdemonmodel.h index 307883ca4d41917d46355f4a27f4eb6b09998fd7..328fe5a34ef613b2e3b9bcfa41a2383963f04c10 100644 --- a/src/quick3d/qdemonmodel.h +++ b/src/quick3d/qdemonmodel.h @@ -5,13 +5,14 @@ #include <QtQml/QQmlListProperty> #include <QtQuick3d/QDemonMaterial> #include <QtCore/QVector> +#include <QtCore/QUrl> QT_BEGIN_NAMESPACE class Q_QUICK3D_EXPORT QDemonModel : public QDemonNode { Q_OBJECT - Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(int skeletonRoot READ skeletonRoot WRITE setSkeletonRoot NOTIFY skeletonRootChanged) Q_PROPERTY(QDemonTessModeValues tesselationMode READ tesselationMode WRITE setTesselationMode NOTIFY tesselationModeChanged) Q_PROPERTY(float edgeTess READ edgeTess WRITE setEdgeTess NOTIFY edgeTessChanged) @@ -33,7 +34,7 @@ public: QDemonObject::Type type() const override; - QString source() const; + QUrl source() const; int skeletonRoot() const; QDemonTessModeValues tesselationMode() const; float edgeTess() const; @@ -43,7 +44,7 @@ public: QQmlListProperty<QDemonMaterial> materials(); public Q_SLOTS: - void setSource(QString source); + void setSource(const QUrl &source); void setSkeletonRoot(int skeletonRoot); void setTesselationMode(QDemonTessModeValues tesselationMode); void setEdgeTess(float edgeTess); @@ -51,7 +52,7 @@ public Q_SLOTS: void setIsWireframeMode(bool isWireframeMode); Q_SIGNALS: - void sourceChanged(QString source); + void sourceChanged(const QUrl &source); void skeletonRootChanged(int skeletonRoot); void tesselationModeChanged(QDemonTessModeValues tesselationMode); void edgeTessChanged(float edgeTess); @@ -62,7 +63,8 @@ protected: QDemonRenderGraphObject *updateSpatialNode(QDemonRenderGraphObject *node) override; private: - QString m_source; + QString translateSource(); + QUrl m_source; int m_skeletonRoot = -1; QDemonTessModeValues m_tesselationMode = QDemonTessModeValues::NoTess; float m_edgeTess = 1.0f;