diff options
Diffstat (limited to 'examples/qt3d/materials-cpp')
-rw-r--r-- | examples/qt3d/materials-cpp/barrel.cpp | 154 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/barrel.h | 99 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/houseplant.cpp | 186 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/houseplant.h | 107 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/main.cpp | 204 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/materials-cpp.pro | 22 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/planeentity.cpp | 75 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/planeentity.h | 63 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/renderableentity.cpp | 77 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/renderableentity.h | 66 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp | 63 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/rotatingtrefoilknot.h | 55 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/trefoilknot.cpp | 83 | ||||
-rw-r--r-- | examples/qt3d/materials-cpp/trefoilknot.h | 67 |
14 files changed, 1321 insertions, 0 deletions
diff --git a/examples/qt3d/materials-cpp/barrel.cpp b/examples/qt3d/materials-cpp/barrel.cpp new file mode 100644 index 000000000..069732254 --- /dev/null +++ b/examples/qt3d/materials-cpp/barrel.cpp @@ -0,0 +1,154 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "barrel.h" + +const char *diffuseColorsName[] = { + "red", + "blue", + "green", + "rust", + "stainless_steel" +}; + +const char *specularColorsName[] = { + "_rust", + "_stainless_steel", + "" +}; + +const char *bumpsName[] = { + "no_bumps", + "soft_bumps", + "middle_bumps", + "hard_bumps" +}; + +Barrel::Barrel(Qt3D::QNode *parent) + : RenderableEntity(parent) + , m_bumps(NoBumps) + , m_diffuseColor(Red) + , m_specularColor(None) + , m_material(new Qt3D::QNormalDiffuseSpecularMapMaterial()) + , m_diffuseTexture(m_material->diffuse()) + , m_normalTexture(m_material->normal()) + , m_specularTexture(m_material->specular()) + , m_diffuseTextureImage(new Qt3D::QTextureImage()) + , m_normalTextureImage(new Qt3D::QTextureImage()) + , m_specularTextureImage(new Qt3D::QTextureImage()) +{ + mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/metalbarrel/metal_barrel.obj"))); + scaleTransform()->setScale(0.03f); + + m_diffuseTexture->addTextureImage(m_diffuseTextureImage); + m_normalTexture->addTextureImage(m_normalTextureImage); + m_specularTexture->addTextureImage(m_specularTextureImage); + + setNormalTextureSource(); + setDiffuseTextureSource(); + setSpecularTextureSource(); + m_material->setShininess(10.0f); + addComponent(m_material); +} + +Barrel::~Barrel() +{ +} + +void Barrel::setDiffuse(Barrel::DiffuseColor diffuse) +{ + if (diffuse != m_diffuseColor) { + m_diffuseColor = diffuse; + setDiffuseTextureSource(); + } +} + +void Barrel::setSpecular(Barrel::SpecularColor specular) +{ + if (specular != m_specularColor) { + m_specularColor = specular; + setSpecularTextureSource(); + } +} + +void Barrel::setBumps(Barrel::Bumps bumps) +{ + if (bumps != m_bumps) { + m_bumps = bumps; + setNormalTextureSource(); + } +} + +void Barrel::setShininess(float shininess) +{ + if (shininess != m_material->shininess()) + m_material->setShininess(shininess); +} + +Barrel::DiffuseColor Barrel::diffuse() const +{ + return m_diffuseColor; +} + +Barrel::SpecularColor Barrel::specular() const +{ + return m_specularColor; +} + +Barrel::Bumps Barrel::bumps() const +{ + return m_bumps; +} + +float Barrel::shininess() const +{ + return m_material->shininess(); +} + +void Barrel::setNormalTextureSource() +{ + m_normalTextureImage->setSource(QUrl(QStringLiteral("qrc:/assets/metalbarrel/normal_") + bumpsName[m_bumps] + QStringLiteral(".webp"))); +} + +void Barrel::setDiffuseTextureSource() +{ + m_diffuseTextureImage->setSource(QUrl(QStringLiteral("qrc:/assets/metalbarrel/diffus_") + diffuseColorsName[m_diffuseColor] + QStringLiteral(".webp"))); +} + +void Barrel::setSpecularTextureSource() +{ + m_specularTextureImage->setSource(QUrl(QStringLiteral("qrc:/assets/metalbarrel/specular") + specularColorsName[m_specularColor] + QStringLiteral(".webp"))); +} diff --git a/examples/qt3d/materials-cpp/barrel.h b/examples/qt3d/materials-cpp/barrel.h new file mode 100644 index 000000000..8ff1c32df --- /dev/null +++ b/examples/qt3d/materials-cpp/barrel.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BARREL_H +#define BARREL_H + +#include <Qt3DRenderer/QNormalDiffuseSpecularMapMaterial> +#include <Qt3DRenderer/qtexture.h> +#include "renderableentity.h" + +class Barrel : public RenderableEntity +{ +public: + Barrel(Qt3D::QNode *parent = 0); + ~Barrel(); + + enum DiffuseColor { + Red = 0, + Blue, + Green, + RustDiffuse, + StainlessSteelDiffuse + }; + + enum SpecularColor { + RustSpecular = 0, + StainlessSteelSpecular, + None + }; + + enum Bumps { + NoBumps = 0, + SoftBumps, + MiddleBumps, + HardBumps + }; + + void setDiffuse(DiffuseColor diffuse); + void setSpecular(SpecularColor specular); + void setBumps(Bumps bumps); + void setShininess(float shininess); + + DiffuseColor diffuse() const; + SpecularColor specular() const; + Bumps bumps() const; + float shininess() const; + +private: + Bumps m_bumps; + DiffuseColor m_diffuseColor; + SpecularColor m_specularColor; + Qt3D::QNormalDiffuseSpecularMapMaterial *m_material; + Qt3D::QAbstractTextureProvider *m_diffuseTexture; + Qt3D::QAbstractTextureProvider *m_normalTexture; + Qt3D::QAbstractTextureProvider *m_specularTexture; + Qt3D::QTextureImage *m_diffuseTextureImage; + Qt3D::QTextureImage *m_normalTextureImage; + Qt3D::QTextureImage *m_specularTextureImage; + + void setNormalTextureSource(); + void setDiffuseTextureSource(); + void setSpecularTextureSource(); + +}; + +#endif // BARREL_H diff --git a/examples/qt3d/materials-cpp/houseplant.cpp b/examples/qt3d/materials-cpp/houseplant.cpp new file mode 100644 index 000000000..c1bea7ecd --- /dev/null +++ b/examples/qt3d/materials-cpp/houseplant.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "houseplant.h" +#include <Qt3DRenderer/qtexture.h> + +const char *potNames[] = { + "cross", + "square", + "triangle", + "sphere" +}; + +const char *plantNames[] = { + "bamboo", + "palm", + "pine", + "spikes", + "shrub" +}; + + +HousePlant::HousePlant(Qt3D::QNode *parent) + : Qt3D::QEntity(parent) + , m_pot(new RenderableEntity(this)) + , m_plant(new RenderableEntity(m_pot)) + , m_cover(new RenderableEntity(m_pot)) + , m_potMaterial(new Qt3D::QNormalDiffuseMapMaterial()) + , m_plantMaterial(new Qt3D::QNormalDiffuseMapAlphaMaterial()) + , m_coverMaterial(new Qt3D::QNormalDiffuseMapMaterial()) + , m_potImage(new Qt3D::QTextureImage()) + + , m_potNormalImage(new Qt3D::QTextureImage()) + , m_plantImage(new Qt3D::QTextureImage()) + , m_plantNormalImage(new Qt3D::QTextureImage()) + , m_coverImage(new Qt3D::QTextureImage()) + , m_coverNormalImage(new Qt3D::QTextureImage()) + , m_plantType(Bamboo) + , m_potShape(Cross) +{ + m_pot->scaleTransform()->setScale(0.03f); + m_pot->addComponent(m_potMaterial); + m_plant->addComponent(m_plantMaterial); + m_cover->addComponent(m_coverMaterial); + + m_potMaterial->diffuse()->addTextureImage(m_potImage); + m_potMaterial->normal()->addTextureImage(m_potNormalImage); + m_plantMaterial->diffuse()->addTextureImage(m_plantImage); + m_plantMaterial->normal()->addTextureImage(m_plantNormalImage); + m_coverMaterial->diffuse()->addTextureImage(m_coverImage); + m_coverMaterial->normal()->addTextureImage(m_coverNormalImage); + + updatePlantType(); + updatePotShape(); + + m_coverImage->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/cover.webp"))); + m_coverNormalImage->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/cover_normal.webp"))); + m_potImage->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/pot.webp"))); + m_potNormalImage->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/pot_normal.webp"))); + + m_potMaterial->setShininess(10.0f); + m_potMaterial->setSpecular(QColor::fromRgbF(0.75f, 0.75f, 0.75f, 1.0f)); + + m_plantMaterial->setShininess(10.0f); + + m_coverMaterial->setSpecular(QColor::fromRgbF(0.05f, 0.05f, 0.05f, 1.0f)); + m_coverMaterial->setShininess(5.0f); +} + +HousePlant::~HousePlant() +{ +} + +void HousePlant::setPotShape(HousePlant::PotShape shape) +{ + if (shape != m_potShape) { + m_potShape = shape; + updatePotShape(); + } +} + +void HousePlant::setPlantType(HousePlant::Plant plant) +{ + if (plant != m_plantType) { + m_plantType = plant; + updatePlantType(); + } +} + +HousePlant::PotShape HousePlant::potShape() const +{ + return m_potShape; +} + +HousePlant::Plant HousePlant::plantType() const +{ + return m_plantType; +} + +void HousePlant::setX(float x) +{ + m_pot->translateTransform()->setDx(x); +} + +void HousePlant::setY(float y) +{ + m_pot->translateTransform()->setDy(y); +} + +void HousePlant::setZ(float z) +{ + m_pot->translateTransform()->setDz(z); +} + +void HousePlant::setScale(float scale) +{ + m_pot->scaleTransform()->setScale(scale); +} + +float HousePlant::x() const +{ + return m_pot->translateTransform()->dx(); +} + +float HousePlant::y() const +{ + return m_pot->translateTransform()->dy(); +} + +float HousePlant::z() const +{ + return m_pot->translateTransform()->dz(); +} + +float HousePlant::scale() const +{ + return m_pot->scaleTransform()->scale(); +} + +void HousePlant::updatePotShape() +{ + m_pot->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/") + potNames[m_potShape] + QStringLiteral("-pot.obj"))); + m_plant->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/") + potNames[m_potShape] + QStringLiteral("-") + plantNames[m_plantType] + QStringLiteral(".obj"))); +} + +void HousePlant::updatePlantType() +{ + m_plant->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/") + potNames[m_potShape] + QStringLiteral("-") + plantNames[m_plantType] + QStringLiteral(".obj"))); + + m_plantImage->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/") + plantNames[m_plantType] + QStringLiteral(".webp"))); + m_plantNormalImage->setSource(QUrl(QStringLiteral("qrc:/assets/houseplants/") + plantNames[m_plantType] + QStringLiteral("_normal.webp"))); +} + diff --git a/examples/qt3d/materials-cpp/houseplant.h b/examples/qt3d/materials-cpp/houseplant.h new file mode 100644 index 000000000..150984f59 --- /dev/null +++ b/examples/qt3d/materials-cpp/houseplant.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HOUSEPLANT_H +#define HOUSEPLANT_H + +#include "renderableentity.h" +#include <QEntity> +#include <QNormalDiffuseMapAlphaMaterial> +#include <QNormalDiffuseMapMaterial> +#include <QTextureImage> + +class HousePlant : public Qt3D::QEntity +{ + Q_OBJECT +public: + explicit HousePlant(Qt3D::QNode *parent = 0); + ~HousePlant(); + + enum PotShape { + Cross = 0, + Square, + Triangle, + Sphere + }; + + enum Plant { + Bamboo = 0, + Palm, + Pine, + Spikes, + Shrub + }; + + void setPotShape(PotShape shape); + void setPlantType(Plant plant); + + PotShape potShape() const; + Plant plantType() const; + + void setX(float x); + void setY(float y); + void setZ(float z); + void setScale(float scale); + + float x() const; + float y() const; + float z() const; + float scale() const; + +private: + RenderableEntity *m_pot; + RenderableEntity *m_plant; + RenderableEntity *m_cover; + + Qt3D::QNormalDiffuseMapMaterial *m_potMaterial; + Qt3D::QNormalDiffuseMapAlphaMaterial *m_plantMaterial; + Qt3D::QNormalDiffuseMapMaterial *m_coverMaterial; + + Qt3D::QTextureImage *m_potImage; + Qt3D::QTextureImage *m_potNormalImage; + Qt3D::QTextureImage *m_plantImage; + Qt3D::QTextureImage *m_plantNormalImage; + Qt3D::QTextureImage *m_coverImage; + Qt3D::QTextureImage *m_coverNormalImage; + + Plant m_plantType; + PotShape m_potShape; + + void updatePotShape(); + void updatePlantType(); +}; + +#endif // HOUSEPLANT_H diff --git a/examples/qt3d/materials-cpp/main.cpp b/examples/qt3d/materials-cpp/main.cpp new file mode 100644 index 000000000..3704ffcdf --- /dev/null +++ b/examples/qt3d/materials-cpp/main.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> + +#include <Qt3DCore/QEntity> +#include <Qt3DCore/Window> +#include <Qt3DCore/QAspectEngine> +#include <Qt3DCore/QCamera> + +#include <Qt3DInput/QInputAspect> + +#include <Qt3DRenderer/QRenderAspect> +#include <Qt3DRenderer/QPhongMaterial> +#include <Qt3DRenderer/QDiffuseMapMaterial> +#include <Qt3DRenderer/QForwardRenderer> +#include <Qt3DRenderer/QFrameGraph> +#include <Qt3DRenderer/QTextureImage> + +#include "planeentity.h" +#include "rotatingtrefoilknot.h" +#include "barrel.h" +#include "exampleresources.h" +#include "houseplant.h" + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + initializeAssetResources("../exampleresources/example-assets.qrb"); + + Qt3D::Window view; + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::QInputAspect *input = new Qt3D::QInputAspect; + engine.registerAspect(input); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view)); + engine.setData(data); + + // Scene Root + Qt3D::QEntity *sceneRoot = new Qt3D::QEntity(); + + // Scene Camera + Qt3D::QCamera *basicCamera = new Qt3D::QCamera(sceneRoot); + basicCamera->setProjectionType(Qt3D::QCameraLens::PerspectiveProjection); + basicCamera->setAspectRatio(view.width() / view.height()); + basicCamera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f)); + basicCamera->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f)); + basicCamera->setPosition(QVector3D(0.0f, 3.5f, 25.0f)); + // For camera controls + input->setCamera(basicCamera); + + // Forward Renderer FrameGraph + Qt3D::QFrameGraph *frameGraphComponent = new Qt3D::QFrameGraph(sceneRoot); + Qt3D::QForwardRenderer *forwardRenderer = new Qt3D::QForwardRenderer(); + forwardRenderer->setCamera(basicCamera); + frameGraphComponent->setActiveFrameGraph(forwardRenderer); + sceneRoot->addComponent(frameGraphComponent); + + // Scene floor + PlaneEntity *planeEntity = new PlaneEntity(sceneRoot); + planeEntity->mesh()->setHeight(100.0f); + planeEntity->mesh()->setWidth(100.0f); + planeEntity->mesh()->setMeshResolution(QSize(20, 20)); + + Qt3D::QNormalDiffuseSpecularMapMaterial *normalDiffuseSpecularMapMaterial = new Qt3D::QNormalDiffuseSpecularMapMaterial(); + normalDiffuseSpecularMapMaterial->setTextureScale(10.0f); + normalDiffuseSpecularMapMaterial->setShininess(80.0f); + normalDiffuseSpecularMapMaterial->setAmbient(QColor::fromRgbF(0.2f, 0.2f, 0.2f, 1.0f)); + + Qt3D::QTextureImage *diffuseImage = new Qt3D::QTextureImage(); + diffuseImage->setSource(QUrl(QStringLiteral("qrc:/assets/textures/pattern_09/diffuse.webp"))); + normalDiffuseSpecularMapMaterial->diffuse()->addTextureImage(diffuseImage); + + Qt3D::QTextureImage *specularImage = new Qt3D::QTextureImage(); + specularImage->setSource(QUrl(QStringLiteral("qrc:/assets/textures/pattern_09/specular.webp"))); + normalDiffuseSpecularMapMaterial->specular()->addTextureImage(specularImage); + + Qt3D::QTextureImage *normalImage = new Qt3D::QTextureImage(); + normalImage->setSource(QUrl((QStringLiteral("qrc:/assets/textures/pattern_09/normal.webp")))); + normalDiffuseSpecularMapMaterial->normal()->addTextureImage(normalImage); + + planeEntity->addComponent(normalDiffuseSpecularMapMaterial); + + // Chest + RenderableEntity *chest = new RenderableEntity(sceneRoot); + chest->scaleTransform()->setScale(0.03f); + chest->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/chest/Chest.obj"))); + Qt3D::QDiffuseMapMaterial *diffuseMapMaterial = new Qt3D::QDiffuseMapMaterial(); + diffuseMapMaterial->setSpecular(QColor::fromRgbF(0.2f, 0.2f, 0.2f, 1.0f)); + diffuseMapMaterial->setShininess(2.0f); + + Qt3D::QTextureImage *chestDiffuseImage = new Qt3D::QTextureImage(); + chestDiffuseImage->setSource(QUrl(QStringLiteral("qrc:/assets/chest/diffuse.webp"))); + diffuseMapMaterial->diffuse()->addTextureImage(chestDiffuseImage); + + chest->addComponent(diffuseMapMaterial); + + + // TrefoilKnot + RotatingTrefoilKnot *trefoil = new RotatingTrefoilKnot(sceneRoot); + trefoil->translateTransform()->setDy(3.5); + trefoil->scaleTransform()->setScale(0.5f); + Qt3D::QPhongMaterial *phongMaterial = new Qt3D::QPhongMaterial(); + phongMaterial->setDiffuse(QColor(204, 205, 75)); // Safari Yellow #cccd4b + phongMaterial->setSpecular(Qt::white); + trefoil->addComponent(phongMaterial); + + // Barrels + Barrel *basicBarrel = new Barrel(sceneRoot); + basicBarrel->translateTransform()->setDx(8.0f); + + Barrel *rustyBarrel = new Barrel(sceneRoot); + rustyBarrel->setDiffuse(Barrel::RustDiffuse); + rustyBarrel->setSpecular(Barrel::RustSpecular); + rustyBarrel->setBumps(Barrel::HardBumps); + rustyBarrel->translateTransform()->setDx(10.0f); + + Barrel *blueBarrel = new Barrel(sceneRoot); + blueBarrel->setDiffuse(Barrel::Blue); + blueBarrel->setBumps(Barrel::MiddleBumps); + blueBarrel->translateTransform()->setDx(12.0f); + + Barrel *greenBarrel = new Barrel(sceneRoot); + greenBarrel->setDiffuse(Barrel::Green); + greenBarrel->setBumps(Barrel::SoftBumps); + greenBarrel->translateTransform()->setDx(14.0f); + + Barrel *stainlessBarrel = new Barrel(sceneRoot); + stainlessBarrel->setDiffuse(Barrel::StainlessSteelDiffuse); + stainlessBarrel->setBumps(Barrel::NoBumps); + stainlessBarrel->setSpecular(Barrel::StainlessSteelSpecular); + stainlessBarrel->setShininess(150.0f); + stainlessBarrel->translateTransform()->setDx(16); + + // Plants + HousePlant *squareBamboo = new HousePlant(sceneRoot); + squareBamboo->setPotShape(HousePlant::Square); + squareBamboo->setX(4.0f); + + HousePlant *trianglePalm = new HousePlant(sceneRoot); + trianglePalm->setPlantType(HousePlant::Palm); + trianglePalm->setPotShape(HousePlant::Triangle); + trianglePalm->setZ(4.0f); + + HousePlant *spherePine = new HousePlant(sceneRoot); + spherePine->setPlantType(HousePlant::Pine); + spherePine->setPotShape(HousePlant::Sphere); + spherePine->setX(-4.0f); + + HousePlant *crossSpikes = new HousePlant(sceneRoot); + crossSpikes->setPlantType(HousePlant::Spikes); + crossSpikes->setZ(-4.0f); + + HousePlant *crossPalm = new HousePlant(sceneRoot); + crossPalm->setPlantType(HousePlant::Palm); + crossPalm->setZ(-8.0f); + crossPalm->setScale(0.05f); + + HousePlant *crossShrub = new HousePlant(sceneRoot); + crossShrub->setPlantType(HousePlant::Shrub); + crossShrub->setZ(8.0f); + crossShrub->setScale(0.05f); + + engine.setRootEntity(sceneRoot); + view.show(); + + return app.exec(); +} diff --git a/examples/qt3d/materials-cpp/materials-cpp.pro b/examples/qt3d/materials-cpp/materials-cpp.pro new file mode 100644 index 000000000..351ed82f8 --- /dev/null +++ b/examples/qt3d/materials-cpp/materials-cpp.pro @@ -0,0 +1,22 @@ +TEMPLATE = app + +QT += 3dcore 3drenderer 3dinput + +include("../exampleresources/exampleresources.pri") + +HEADERS += \ + planeentity.h \ + renderableentity.h \ + trefoilknot.h \ + barrel.h \ + rotatingtrefoilknot.h \ + houseplant.h + +SOURCES += \ + main.cpp \ + planeentity.cpp \ + renderableentity.cpp \ + trefoilknot.cpp \ + barrel.cpp \ + rotatingtrefoilknot.cpp \ + houseplant.cpp diff --git a/examples/qt3d/materials-cpp/planeentity.cpp b/examples/qt3d/materials-cpp/planeentity.cpp new file mode 100644 index 000000000..9854e8ace --- /dev/null +++ b/examples/qt3d/materials-cpp/planeentity.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "planeentity.h" + +#include <Qt3DRenderer/QPlaneMesh> +#include <Qt3DCore/QTransform> +#include <Qt3DCore/QScaleTransform> +#include <Qt3DCore/QTranslateTransform> + +PlaneEntity::PlaneEntity(Qt3D::QNode *parent) + : Qt3D::QEntity(new Qt3D::QEntity(parent)) + , m_mesh(new Qt3D::QPlaneMesh()) + , m_transform(new Qt3D::QTransform()) + , m_scaleTransform(new Qt3D::QScaleTransform()) + , m_translateTransform(new Qt3D::QTranslateTransform()) +{ + m_transform->addTransform(m_translateTransform); + m_transform->addTransform(m_scaleTransform); + addComponent(m_mesh); + addComponent(m_transform); +} + +PlaneEntity::~PlaneEntity() +{ +} + +Qt3D::QScaleTransform *PlaneEntity::scaleTransform() const +{ + return m_scaleTransform; +} + +Qt3D::QTranslateTransform *PlaneEntity::translateTransform() const +{ + return m_translateTransform; +} + +Qt3D::QPlaneMesh *PlaneEntity::mesh() const +{ + return m_mesh; +} + diff --git a/examples/qt3d/materials-cpp/planeentity.h b/examples/qt3d/materials-cpp/planeentity.h new file mode 100644 index 000000000..418f3c698 --- /dev/null +++ b/examples/qt3d/materials-cpp/planeentity.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLANEENTITY_H +#define PLANEENTITY_H + +#include <Qt3DCore/QEntity> +#include <Qt3DCore/QTransform> +#include <Qt3DCore/QScaleTransform> +#include <Qt3DCore/QTranslateTransform> +#include <Qt3DRenderer/QPlaneMesh> + +class PlaneEntity : public Qt3D::QEntity +{ +public: + PlaneEntity(Qt3D::QNode *parent = 0); + ~PlaneEntity(); + + Qt3D::QScaleTransform *scaleTransform() const; + Qt3D::QTranslateTransform *translateTransform() const; + Qt3D::QPlaneMesh *mesh() const; + +private: + Qt3D::QPlaneMesh *m_mesh; + Qt3D::QTransform *m_transform; + Qt3D::QScaleTransform *m_scaleTransform; + Qt3D::QTranslateTransform *m_translateTransform; +}; + +#endif // PLANEENTITY_H diff --git a/examples/qt3d/materials-cpp/renderableentity.cpp b/examples/qt3d/materials-cpp/renderableentity.cpp new file mode 100644 index 000000000..0acbdcc00 --- /dev/null +++ b/examples/qt3d/materials-cpp/renderableentity.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "renderableentity.h" + +RenderableEntity::RenderableEntity(Qt3D::QNode *parent) + : Qt3D::QEntity(parent) + , m_mesh(new Qt3D::QMesh()) + , m_transform(new Qt3D::QTransform()) + , m_rotateTransform(new Qt3D::QRotateTransform()) + , m_scaleTransform(new Qt3D::QScaleTransform()) + , m_translateTransform(new Qt3D::QTranslateTransform()) +{ + m_transform->addTransform(m_rotateTransform); + m_transform->addTransform(m_scaleTransform); + m_transform->addTransform(m_translateTransform); + addComponent(m_mesh); + addComponent(m_transform); +} + +RenderableEntity::~RenderableEntity() +{ + +} + +Qt3D::QMesh *RenderableEntity::mesh() const +{ + return m_mesh; +} + +Qt3D::QScaleTransform *RenderableEntity::scaleTransform() const +{ + return m_scaleTransform; +} + +Qt3D::QTranslateTransform *RenderableEntity::translateTransform() const +{ + return m_translateTransform; +} + +Qt3D::QRotateTransform *RenderableEntity::rotateTransform() const +{ + return m_rotateTransform; +} diff --git a/examples/qt3d/materials-cpp/renderableentity.h b/examples/qt3d/materials-cpp/renderableentity.h new file mode 100644 index 000000000..c467ffb5c --- /dev/null +++ b/examples/qt3d/materials-cpp/renderableentity.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RENDERABLEENTITY_H +#define RENDERABLEENTITY_H + +#include <Qt3DCore/QEntity> +#include <Qt3DCore/QTransform> +#include <Qt3DCore/QScaleTransform> +#include <Qt3DCore/QRotateTransform> +#include <Qt3DCore/QTranslateTransform> +#include <Qt3DRenderer/QMesh> + +class RenderableEntity : public Qt3D::QEntity +{ +public: + RenderableEntity(Qt3D::QNode *parent = 0); + ~RenderableEntity(); + + Qt3D::QMesh *mesh() const; + Qt3D::QScaleTransform *scaleTransform() const; + Qt3D::QTranslateTransform *translateTransform() const; + Qt3D::QRotateTransform *rotateTransform() const; + +private: + Qt3D::QMesh *m_mesh; + Qt3D::QTransform *m_transform; + Qt3D::QRotateTransform *m_rotateTransform; + Qt3D::QScaleTransform *m_scaleTransform; + Qt3D::QTranslateTransform *m_translateTransform; +}; + +#endif // RENDERABLEENTITY_H diff --git a/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp b/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp new file mode 100644 index 000000000..833d82d37 --- /dev/null +++ b/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "rotatingtrefoilknot.h" + +RotatingTrefoilKnot::RotatingTrefoilKnot(Qt3D::QNode *parent) + : TrefoilKnot(parent) + , m_thetaAnimation(new QPropertyAnimation(this)) + , m_phiAnimation(new QPropertyAnimation(this)) +{ + m_thetaAnimation->setDuration(2000); + m_thetaAnimation->setStartValue(0.0f); + m_thetaAnimation->setEndValue(360.0f); + m_thetaAnimation->setLoopCount(-1); + m_thetaAnimation->setTargetObject(xaxisRotateTransform()); + m_thetaAnimation->setPropertyName("angle"); + m_thetaAnimation->start(); + + m_phiAnimation->setDuration(2000); + m_phiAnimation->setStartValue(0.0f); + m_phiAnimation->setEndValue(360.0f); + m_phiAnimation->setLoopCount(-1); + m_phiAnimation->setTargetObject(yaxisRotateTransform()); + m_phiAnimation->setPropertyName("angle"); + m_phiAnimation->start(); +} + +RotatingTrefoilKnot::~RotatingTrefoilKnot() +{ +} diff --git a/examples/qt3d/materials-cpp/rotatingtrefoilknot.h b/examples/qt3d/materials-cpp/rotatingtrefoilknot.h new file mode 100644 index 000000000..231ce5270 --- /dev/null +++ b/examples/qt3d/materials-cpp/rotatingtrefoilknot.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ROTATINGTREFOILKNOT_H +#define ROTATINGTREFOILKNOT_H + +#include "trefoilknot.h" +#include <QPropertyAnimation> + +class RotatingTrefoilKnot : public TrefoilKnot +{ +public: + explicit RotatingTrefoilKnot(Qt3D::QNode *parent = 0); + ~RotatingTrefoilKnot(); + +private: + QPropertyAnimation *m_thetaAnimation; + QPropertyAnimation *m_phiAnimation; + +}; + +#endif // ROTATINGTREFOILKNOT_H diff --git a/examples/qt3d/materials-cpp/trefoilknot.cpp b/examples/qt3d/materials-cpp/trefoilknot.cpp new file mode 100644 index 000000000..b99c090ea --- /dev/null +++ b/examples/qt3d/materials-cpp/trefoilknot.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "trefoilknot.h" + +TrefoilKnot::TrefoilKnot(Qt3D::QNode *parent) + : Qt3D::QEntity(parent) + , m_mesh(new Qt3D::QMesh()) + , m_transform(new Qt3D::QTransform()) + , m_scaleTransform(new Qt3D::QScaleTransform()) + , m_xaxisRotation(new Qt3D::QRotateTransform()) + , m_yaxisRotation(new Qt3D::QRotateTransform()) + , m_translateTransform(new Qt3D::QTranslateTransform()) +{ + m_mesh->setSource(QUrl("qrc:/assets/obj/trefoil.obj")); + m_xaxisRotation->setAxis(QVector3D(1.0f, 0.0f, 0.0f)); + m_yaxisRotation->setAxis(QVector3D(0.0f, 1.0f, 0.0f)); + + m_transform->addTransform(m_scaleTransform); + m_transform->addTransform(m_xaxisRotation); + m_transform->addTransform(m_yaxisRotation); + m_transform->addTransform(m_translateTransform); + + addComponent(m_mesh); + addComponent(m_transform); +} + +TrefoilKnot::~TrefoilKnot() +{ +} + +Qt3D::QScaleTransform *TrefoilKnot::scaleTransform() const +{ + return m_scaleTransform; +} + +Qt3D::QRotateTransform *TrefoilKnot::xaxisRotateTransform() const +{ + return m_xaxisRotation; +} + +Qt3D::QRotateTransform *TrefoilKnot::yaxisRotateTransform() const +{ + return m_yaxisRotation; +} + +Qt3D::QTranslateTransform *TrefoilKnot::translateTransform() const +{ + return m_translateTransform; +} diff --git a/examples/qt3d/materials-cpp/trefoilknot.h b/examples/qt3d/materials-cpp/trefoilknot.h new file mode 100644 index 000000000..a625c874e --- /dev/null +++ b/examples/qt3d/materials-cpp/trefoilknot.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TREFOILKNOT_H +#define TREFOILKNOT_H + +#include <Qt3DCore/QEntity> +#include <Qt3DCore/QTransform> +#include <Qt3DCore/QScaleTransform> +#include <Qt3DCore/QRotateTransform> +#include <Qt3DCore/QTranslateTransform> +#include <Qt3DRenderer/QMesh> + +class TrefoilKnot : public Qt3D::QEntity +{ +public: + explicit TrefoilKnot(Qt3D::QNode *parent = 0); + ~TrefoilKnot(); + + Qt3D::QScaleTransform *scaleTransform() const; + Qt3D::QRotateTransform *xaxisRotateTransform() const; + Qt3D::QRotateTransform *yaxisRotateTransform() const; + Qt3D::QTranslateTransform *translateTransform() const; + +private: + Qt3D::QMesh *m_mesh; + Qt3D::QTransform *m_transform; + Qt3D::QScaleTransform *m_scaleTransform; + Qt3D::QRotateTransform *m_xaxisRotation; + Qt3D::QRotateTransform *m_yaxisRotation; + Qt3D::QTranslateTransform *m_translateTransform; +}; + +#endif // TREFOILKNOT_H |