summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire.ecortex@kdab.com>2014-12-29 16:10:48 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-12-31 11:23:49 +0100
commitbee25daf9efaa688a6954a5b31a07c51db49b8ba (patch)
tree5bc3f2982689c8908c9fbe440eff36cd1d15f6a1 /examples
parent2be97a74b23c66d385b1dd89df106c9be7be7696 (diff)
Default cpp materials + material-cpp example
QDiffuseMapMaterial QDiffuseSpecularMapMaterial QNormalDiffuseMapMaterial QNormalDiffuseAlphaMapMaterial QNormalDiffuseSpecularMapMaterial material-cpp is mostly inspired from materials (QML) but nicer :). Note: there seems to be an issue with qrc and QUrl. The behavior is different between QML and C++. -In C++ we need to prefix with have qrc:/ and convert that to :/ (passing :/ directly returns "" when QUrl toString is called) -From QML no prefix is needed. -For QImage path, :/ should be used. Change-Id: Ib56fb9546c95c2872686a46ed048a290ab4a5b6f Task-number: QTBUG-41548 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.pro3
-rw-r--r--examples/materials-cpp/barrel.cpp169
-rw-r--r--examples/materials-cpp/barrel.h101
-rw-r--r--examples/materials-cpp/forwardrenderer.cpp65
-rw-r--r--examples/materials-cpp/forwardrenderer.h64
-rw-r--r--examples/materials-cpp/houseplant.cpp209
-rw-r--r--examples/materials-cpp/houseplant.h104
-rw-r--r--examples/materials-cpp/main.cpp213
-rw-r--r--examples/materials-cpp/materials-cpp.pro24
-rw-r--r--examples/materials-cpp/planeentity.cpp80
-rw-r--r--examples/materials-cpp/planeentity.h68
-rw-r--r--examples/materials-cpp/renderableentity.cpp82
-rw-r--r--examples/materials-cpp/renderableentity.h71
-rw-r--r--examples/materials-cpp/rotatingtrefoilknot.cpp68
-rw-r--r--examples/materials-cpp/rotatingtrefoilknot.h60
-rw-r--r--examples/materials-cpp/trefoilknot.cpp88
-rw-r--r--examples/materials-cpp/trefoilknot.h72
-rw-r--r--examples/materials/Barrel.qml2
-rw-r--r--examples/materials/Chest.qml2
-rw-r--r--examples/materials/HousePlant.qml6
-rw-r--r--examples/materials/TrefoilKnot.qml2
21 files changed, 1546 insertions, 7 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
index b94e16331..359b38eab 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -23,7 +23,8 @@ SUBDIRS += \
materials \
keyboardinput-qml \
loader-qml \
- wave
+ wave \
+ materials-cpp
# TODO Port the old examples to new APIs
#SUBDIRS += qt3d
diff --git a/examples/materials-cpp/barrel.cpp b/examples/materials-cpp/barrel.cpp
new file mode 100644
index 000000000..3af8bac89
--- /dev/null
+++ b/examples/materials-cpp/barrel.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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())
+{
+ mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/metalbarrel/metal_barrel.obj")));
+ scaleTransform()->setScale(0.03f);
+ 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()
+{
+ QImage img;
+ if (img.load(QStringLiteral(":/assets/metalbarrel/normal_") + bumpsName[m_bumps] + QStringLiteral(".webp"))) {
+ m_normalTexture->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_normalTexture->setFromQImage(img);
+ }
+}
+
+void Barrel::setDiffuseTextureSource()
+{
+ QImage img;
+ if (img.load(QStringLiteral(":/assets/metalbarrel/diffus_") + diffuseColorsName[m_diffuseColor] + QStringLiteral(".webp"))) {
+ m_diffuseTexture->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_diffuseTexture->setFromQImage(img);
+ }
+}
+
+void Barrel::setSpecularTextureSource()
+{
+ QImage img;
+ if (img.load(QStringLiteral(":/assets/metalbarrel/specular") + specularColorsName[m_specularColor] + QStringLiteral(".webp"))) {
+ m_specularTexture->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_specularTexture->setFromQImage(img);
+ }
+}
diff --git a/examples/materials-cpp/barrel.h b/examples/materials-cpp/barrel.h
new file mode 100644
index 000000000..6fcdb434b
--- /dev/null
+++ b/examples/materials-cpp/barrel.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BARREL_H
+#define BARREL_H
+
+#include <Qt3DRenderer/QNormalDiffuseSpecularMapMaterial>
+#include <Qt3DRenderer/QTexture>
+#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::QTexture *m_diffuseTexture;
+ Qt3D::QTexture *m_normalTexture;
+ Qt3D::QTexture *m_specularTexture;
+
+ void setNormalTextureSource();
+ void setDiffuseTextureSource();
+ void setSpecularTextureSource();
+
+};
+
+#endif // BARREL_H
diff --git a/examples/materials-cpp/forwardrenderer.cpp b/examples/materials-cpp/forwardrenderer.cpp
new file mode 100644
index 000000000..0731f2904
--- /dev/null
+++ b/examples/materials-cpp/forwardrenderer.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "forwardrenderer.h"
+
+ForwardRenderer::ForwardRenderer(Qt3D::QNode *parent)
+ : Qt3D::QFrameGraph(parent)
+ , m_viewport(new Qt3D::QViewport())
+ , m_cameraSelector(new Qt3D::QCameraSelector())
+ , m_clearBuffer(new Qt3D::QClearBuffer())
+{
+ m_viewport->setRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f));
+ m_viewport->setClearColor(Qt::white);
+ m_clearBuffer->setBuffers(Qt3D::QClearBuffer::ColorDepthBuffer);
+ m_cameraSelector->setParent(m_viewport);
+ m_clearBuffer->setParent(m_cameraSelector);
+ setActiveFrameGraph(m_viewport);
+}
+
+ForwardRenderer::~ForwardRenderer()
+{
+}
+
+void ForwardRenderer::setCamera(Qt3D::QEntity *camera)
+{
+ m_cameraSelector->setCamera(camera);
+}
diff --git a/examples/materials-cpp/forwardrenderer.h b/examples/materials-cpp/forwardrenderer.h
new file mode 100644
index 000000000..b45070416
--- /dev/null
+++ b/examples/materials-cpp/forwardrenderer.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FORWARDRENDERER_H
+#define FORWARDRENDERER_H
+
+#include <Qt3DRenderer/QFrameGraph>
+#include <Qt3DRenderer/QViewport>
+#include <Qt3DRenderer/QCameraSelector>
+#include <Qt3DRenderer/QClearBuffer>
+
+class ForwardRenderer : public Qt3D::QFrameGraph
+{
+public:
+ ForwardRenderer(Qt3D::QNode *parent);
+ ~ForwardRenderer();
+
+ void setCamera(Qt3D::QEntity *camera);
+
+private:
+ Qt3D::QViewport *m_viewport;
+ Qt3D::QCameraSelector *m_cameraSelector;
+ Qt3D::QClearBuffer *m_clearBuffer;
+};
+
+#endif // FORWARDRENDERER_H
diff --git a/examples/materials-cpp/houseplant.cpp b/examples/materials-cpp/houseplant.cpp
new file mode 100644
index 000000000..5b6b66857
--- /dev/null
+++ b/examples/materials-cpp/houseplant.cpp
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "houseplant.h"
+#include <Qt3DRenderer/QTexture>
+
+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_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);
+
+ updatePlantType();
+ updatePotShape();
+
+ QImage img;
+
+ if (img.load(QStringLiteral(":/assets/houseplants/cover.webp"))) {
+ m_coverMaterial->diffuse()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_coverMaterial->diffuse()->setFromQImage(img);
+ }
+ if (img.load(QStringLiteral(":/assets/houseplants/cover_normal.webp"))) {
+ m_coverMaterial->normal()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_coverMaterial->normal()->setFromQImage(img);
+ }
+ if (img.load(QStringLiteral(":/assets/houseplants/pot.webp"))) {
+ m_potMaterial->diffuse()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_potMaterial->diffuse()->setFromQImage(img);
+ }
+ if (img.load(QStringLiteral(":/assets/houseplants/pot_normal.webp"))) {
+ m_potMaterial->normal()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_potMaterial->normal()->setFromQImage(img);
+ }
+
+ 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")));
+ QImage img;
+ if (img.load(QStringLiteral(":/assets/houseplants/") + plantNames[m_plantType] + QStringLiteral(".webp"))) {
+ m_plantMaterial->diffuse()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_plantMaterial->diffuse()->setFromQImage(img);
+ }
+ if (img.load(QStringLiteral(":/assets/houseplants/") + plantNames[m_plantType] + QStringLiteral("_normal.webp"))) {
+ m_plantMaterial->normal()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ m_plantMaterial->normal()->setFromQImage(img);
+ }
+}
+
diff --git a/examples/materials-cpp/houseplant.h b/examples/materials-cpp/houseplant.h
new file mode 100644
index 000000000..a8e821691
--- /dev/null
+++ b/examples/materials-cpp/houseplant.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HOUSEPLANT_H
+#define HOUSEPLANT_H
+
+#include "renderableentity.h"
+#include <QEntity>
+#include <QNormalDiffuseMapAlphaMaterial>
+#include <QNormalDiffuseMapMaterial>
+
+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;
+
+ Plant m_plantType;
+ PotShape m_potShape;
+
+ void updatePotShape();
+ void updatePlantType();
+};
+
+#endif // HOUSEPLANT_H
diff --git a/examples/materials-cpp/main.cpp b/examples/materials-cpp/main.cpp
new file mode 100644
index 000000000..fe3ee426d
--- /dev/null
+++ b/examples/materials-cpp/main.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGuiApplication>
+
+#include <Qt3DCore/QEntity>
+#include <Qt3DCore/Window>
+#include <Qt3DCore/QAspectEngine>
+#include <Qt3DCore/QCamera>
+
+#include <Qt3DRenderer/QRenderAspect>
+#include <Qt3DRenderer/QPhongMaterial>
+#include <Qt3DRenderer/QDiffuseMapMaterial>
+
+#include "planeentity.h"
+#include "forwardrenderer.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());
+ engine.initialize();
+ QVariantMap data;
+ data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view)));
+ data.insert(QStringLiteral("window"), 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
+ view.setCamera(basicCamera);
+
+ // Forward Renderer FrameGraph
+ ForwardRenderer *forwardRenderer = new ForwardRenderer(sceneRoot);
+ forwardRenderer->setCamera(basicCamera);
+ sceneRoot->addComponent(forwardRenderer);
+
+ // 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));
+
+ QImage img;
+ // Providing image loaders for textures would make sense
+ if (img.load(QStringLiteral(":/assets/textures/pattern_09/diffuse.webp"))) {
+ normalDiffuseSpecularMapMaterial->diffuse()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ normalDiffuseSpecularMapMaterial->diffuse()->setFromQImage(img);
+ }
+
+ if (img.load(QStringLiteral(":/assets/textures/pattern_09/specular.webp"))) {
+ normalDiffuseSpecularMapMaterial->specular()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ normalDiffuseSpecularMapMaterial->specular()->setFromQImage(img);
+ }
+
+ if (img.load(QStringLiteral(":/assets/textures/pattern_09/normal.webp"))) {
+ normalDiffuseSpecularMapMaterial->normal()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ normalDiffuseSpecularMapMaterial->normal()->setFromQImage(img);
+ }
+ 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);
+
+ if (img.load(QStringLiteral(":/assets/chest/diffuse.webp"))) {
+ diffuseMapMaterial->diffuse()->setFormat(img.hasAlphaChannel() ?
+ Qt3D::QTexture::RGBA8_UNorm :
+ Qt3D::QTexture::RGB8_UNorm);
+ diffuseMapMaterial->diffuse()->setFromQImage(img);
+ }
+ 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/materials-cpp/materials-cpp.pro b/examples/materials-cpp/materials-cpp.pro
new file mode 100644
index 000000000..e4d5939bc
--- /dev/null
+++ b/examples/materials-cpp/materials-cpp.pro
@@ -0,0 +1,24 @@
+TEMPLATE = app
+
+QT += 3dcore 3drenderer
+
+include("../exampleresources/exampleresources.pri")
+
+HEADERS += \
+ planeentity.h \
+ forwardrenderer.h \
+ renderableentity.h \
+ trefoilknot.h \
+ barrel.h \
+ rotatingtrefoilknot.h \
+ houseplant.h
+
+SOURCES += \
+ main.cpp \
+ planeentity.cpp \
+ forwardrenderer.cpp \
+ renderableentity.cpp \
+ trefoilknot.cpp \
+ barrel.cpp \
+ rotatingtrefoilknot.cpp \
+ houseplant.cpp
diff --git a/examples/materials-cpp/planeentity.cpp b/examples/materials-cpp/planeentity.cpp
new file mode 100644
index 000000000..0996fdd96
--- /dev/null
+++ b/examples/materials-cpp/planeentity.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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/materials-cpp/planeentity.h b/examples/materials-cpp/planeentity.h
new file mode 100644
index 000000000..b221b7edc
--- /dev/null
+++ b/examples/materials-cpp/planeentity.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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/materials-cpp/renderableentity.cpp b/examples/materials-cpp/renderableentity.cpp
new file mode 100644
index 000000000..266d9a7cc
--- /dev/null
+++ b/examples/materials-cpp/renderableentity.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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/materials-cpp/renderableentity.h b/examples/materials-cpp/renderableentity.h
new file mode 100644
index 000000000..e95c6b131
--- /dev/null
+++ b/examples/materials-cpp/renderableentity.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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/materials-cpp/rotatingtrefoilknot.cpp b/examples/materials-cpp/rotatingtrefoilknot.cpp
new file mode 100644
index 000000000..4ddf10c12
--- /dev/null
+++ b/examples/materials-cpp/rotatingtrefoilknot.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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(QByteArrayLiteral("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(QByteArrayLiteral("angle"));
+ m_phiAnimation->start();
+}
+
+RotatingTrefoilKnot::~RotatingTrefoilKnot()
+{
+}
diff --git a/examples/materials-cpp/rotatingtrefoilknot.h b/examples/materials-cpp/rotatingtrefoilknot.h
new file mode 100644
index 000000000..c3fea0c64
--- /dev/null
+++ b/examples/materials-cpp/rotatingtrefoilknot.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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/materials-cpp/trefoilknot.cpp b/examples/materials-cpp/trefoilknot.cpp
new file mode 100644
index 000000000..be028d26f
--- /dev/null
+++ b/examples/materials-cpp/trefoilknot.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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/materials-cpp/trefoilknot.h b/examples/materials-cpp/trefoilknot.h
new file mode 100644
index 000000000..d55939a91
--- /dev/null
+++ b/examples/materials-cpp/trefoilknot.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.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
diff --git a/examples/materials/Barrel.qml b/examples/materials/Barrel.qml
index 8545f1f07..a31f6f595 100644
--- a/examples/materials/Barrel.qml
+++ b/examples/materials/Barrel.qml
@@ -59,7 +59,7 @@ Entity {
RenderableEntity {
id: barrel
- source: ":/assets/metalbarrel/metal_barrel.obj"
+ source: "assets/metalbarrel/metal_barrel.obj"
scale: 0.03
material: NormalDiffuseSpecularMapMaterial {
diff --git a/examples/materials/Chest.qml b/examples/materials/Chest.qml
index b01754be6..0d2813fd4 100644
--- a/examples/materials/Chest.qml
+++ b/examples/materials/Chest.qml
@@ -54,7 +54,7 @@ Entity {
RenderableEntity {
id: chest
- source: ":/assets/chest/Chest.obj"
+ source: "assets/chest/Chest.obj"
scale: 0.03
material: DiffuseMapMaterial {
diff --git a/examples/materials/HousePlant.qml b/examples/materials/HousePlant.qml
index 704749820..6e5d39c7e 100644
--- a/examples/materials/HousePlant.qml
+++ b/examples/materials/HousePlant.qml
@@ -58,7 +58,7 @@ Entity {
RenderableEntity {
id: pot
- source: ":/assets/houseplants/" + root.potShape + "-pot.obj"
+ source: "assets/houseplants/" + root.potShape + "-pot.obj"
scale: 0.03
material: NormalDiffuseMapMaterial {
@@ -70,7 +70,7 @@ Entity {
}
RenderableEntity {
- source: ":/assets/houseplants/" + root.potShape + "-" + root.plantType + ".obj"
+ source: "assets/houseplants/" + root.potShape + "-" + root.plantType + ".obj"
material: NormalDiffuseMapMaterial {
effect: root.normalDiffuseMapAlphaEffect
diffuse: "assets/houseplants/" + root.plantType + ".webp"
@@ -80,7 +80,7 @@ Entity {
}
RenderableEntity {
- source: ":/assets/houseplants/" + root.potShape + "-pot-cover.obj"
+ source: "assets/houseplants/" + root.potShape + "-pot-cover.obj"
material: NormalDiffuseMapMaterial {
effect: root.normalDiffuseMapEffect
diffuse: "assets/houseplants/cover.webp"
diff --git a/examples/materials/TrefoilKnot.qml b/examples/materials/TrefoilKnot.qml
index 42367099b..71e9ec11f 100644
--- a/examples/materials/TrefoilKnot.qml
+++ b/examples/materials/TrefoilKnot.qml
@@ -65,6 +65,6 @@ Entity {
Mesh {
id: mesh
- source: ":/assets/obj/trefoil.obj"
+ source: "assets/obj/trefoil.obj"
}
}