summaryrefslogtreecommitdiffstats
path: root/demos/qt3d/teaservice
diff options
context:
space:
mode:
Diffstat (limited to 'demos/qt3d/teaservice')
-rw-r--r--demos/qt3d/teaservice/README7
-rw-r--r--demos/qt3d/teaservice/meshobject.cpp155
-rw-r--r--demos/qt3d/teaservice/meshobject.h115
-rw-r--r--demos/qt3d/teaservice/per_pixel_lighting.fsh112
-rw-r--r--demos/qt3d/teaservice/per_pixel_lighting.vsh96
-rw-r--r--demos/qt3d/teaservice/perpixeleffect.cpp56
-rw-r--r--demos/qt3d/teaservice/perpixeleffect.h58
-rw-r--r--demos/qt3d/teaservice/sceneobject.cpp72
-rw-r--r--demos/qt3d/teaservice/sceneobject.h61
-rw-r--r--demos/qt3d/teaservice/teacup.txt280
-rw-r--r--demos/qt3d/teaservice/teaservice.cpp379
-rw-r--r--demos/qt3d/teaservice/teaservice.pro7
-rw-r--r--demos/qt3d/teaservice/teaservice.qrc8
-rw-r--r--demos/qt3d/teaservice/teaspoon.txt275
14 files changed, 1681 insertions, 0 deletions
diff --git a/demos/qt3d/teaservice/README b/demos/qt3d/teaservice/README
new file mode 100644
index 000000000..d7d71a617
--- /dev/null
+++ b/demos/qt3d/teaservice/README
@@ -0,0 +1,7 @@
+
+This example demonstrates a view with multiple scene objects, plus material
+parameters. It shows a teapot, two teacups, and two teaspoons.
+
+The model source data came from "http://www.sjbaker.org/teapot/teaset.tgz".
+
+Note: the teacups have no bottoms in the original source data.
diff --git a/demos/qt3d/teaservice/meshobject.cpp b/demos/qt3d/teaservice/meshobject.cpp
new file mode 100644
index 000000000..1ff49d30b
--- /dev/null
+++ b/demos/qt3d/teaservice/meshobject.cpp
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "meshobject.h"
+#include "qglview.h"
+
+MeshObject::MeshObject(QGLSceneNode *meshObject, QObject *parent)
+ : QObject(parent)
+{
+ m_mesh = 0;
+ m_meshObject = meshObject;
+ m_scale = 1.0f;
+ m_rotationAngle = 0.0f;
+ m_effect = 0;
+ m_objectId = -1;
+ m_hovering = false;
+ m_material = 0;
+ m_hoverMaterial = 0;
+}
+
+MeshObject::MeshObject(QGLAbstractScene *scene, QObject *parent)
+ : QObject(parent)
+{
+ scene->setParent(this);
+ m_mesh = 0;
+ m_meshObject = scene->mainNode();
+ m_scale = 1.0f;
+ m_rotationAngle = 0.0f;
+ m_effect = 0;
+ m_objectId = -1;
+ m_hovering = false;
+ m_material = 0;
+ m_hoverMaterial = 0;
+}
+
+MeshObject::~MeshObject()
+{
+ delete m_mesh;
+}
+
+void MeshObject::initialize(QGLView *view, QGLPainter *painter)
+{
+ Q_UNUSED(painter);
+ if (m_objectId != -1)
+ view->registerObject(m_objectId, this);
+}
+
+void MeshObject::draw(QGLPainter *painter)
+{
+ // Position the model at its designated position, scale, and orientation.
+ painter->modelViewMatrix().push();
+ painter->modelViewMatrix().translate(m_position);
+ if (m_scale != 1.0f)
+ painter->modelViewMatrix().scale(m_scale);
+ if (m_rotationAngle != 0.0f)
+ painter->modelViewMatrix().rotate(m_rotationAngle, m_rotationVector);
+
+ // Apply the material and effect to the painter.
+ QGLMaterial *material;
+ if (m_hovering)
+ material = m_hoverMaterial;
+ else
+ material = m_material;
+ painter->setColor(material->diffuseColor());
+ painter->setFaceMaterial(QGL::AllFaces, material);
+ if (m_effect)
+ painter->setUserEffect(m_effect);
+ else
+ painter->setStandardEffect(QGL::LitMaterial);
+
+ // Mark the object for object picking purposes.
+ int prevObjectId = painter->objectPickId();
+ if (m_objectId != -1)
+ painter->setObjectPickId(m_objectId);
+
+ // Draw the geometry mesh.
+ if (m_meshObject)
+ m_meshObject->draw(painter);
+ else
+ m_mesh->draw(painter);
+
+ // Turn off the user effect, if present.
+ if (m_effect)
+ painter->setStandardEffect(QGL::LitMaterial);
+
+ // Revert to the previous object identifier.
+ painter->setObjectPickId(prevObjectId);
+
+ // Restore the modelview matrix.
+ painter->modelViewMatrix().pop();
+}
+
+bool MeshObject::event(QEvent *e)
+{
+ // Convert the raw event into a signal representing the user's action.
+ if (e->type() == QEvent::MouseButtonPress) {
+ QMouseEvent *me = (QMouseEvent *)e;
+ if (me->button() == Qt::LeftButton)
+ emit pressed();
+ } else if (e->type() == QEvent::MouseButtonRelease) {
+ QMouseEvent *me = (QMouseEvent *)e;
+ if (me->button() == Qt::LeftButton) {
+ emit released();
+ if (me->x() >= 0) // Positive: inside object, Negative: outside.
+ emit clicked();
+ }
+ } else if (e->type() == QEvent::MouseButtonDblClick) {
+ emit doubleClicked();
+ } else if (e->type() == QEvent::Enter) {
+ m_hovering = true;
+ emit hoverChanged();
+ } else if (e->type() == QEvent::Leave) {
+ m_hovering = false;
+ emit hoverChanged();
+ }
+ return QObject::event(e);
+}
diff --git a/demos/qt3d/teaservice/meshobject.h b/demos/qt3d/teaservice/meshobject.h
new file mode 100644
index 000000000..c0abb8813
--- /dev/null
+++ b/demos/qt3d/teaservice/meshobject.h
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MESHOBJECT_H
+#define MESHOBJECT_H
+
+#include <QtCore/qobject.h>
+#include <QtGui/qevent.h>
+
+#include "qglpainter.h"
+#include "qglabstractscene.h"
+
+class QGLView;
+class QGLSceneNode;
+
+class MeshObject : public QObject
+{
+ Q_OBJECT
+public:
+ explicit MeshObject(QGLSceneNode *meshObject, QObject *parent=0);
+ explicit MeshObject(QGLAbstractScene *scene, QObject *parent=0);
+ virtual ~MeshObject();
+
+ QVector3D position() const { return m_position; }
+ void setPosition(const QVector3D& value) { m_position = value; }
+
+ qreal scale() const { return m_scale; }
+ void setScale(qreal value) { m_scale = value; }
+
+ qreal rotationAngle() const { return m_rotationAngle; }
+ void setRotationAngle(qreal value) { m_rotationAngle = value; }
+
+ QVector3D rotationVector() const { return m_rotationVector; }
+ void setRotationVector(const QVector3D& value) { m_rotationVector = value; }
+
+ QGLMaterial *material() const { return m_material; }
+ void setMaterial(QGLMaterial *value)
+ { m_material = value; m_hoverMaterial = value; }
+
+ QGLMaterial *hoverMaterial() const { return m_hoverMaterial; }
+ void setHoverMaterial(QGLMaterial *value) { m_hoverMaterial = value; }
+
+ QGLAbstractEffect *effect() const { return m_effect; }
+ void setEffect(QGLAbstractEffect *value) { m_effect = value; }
+
+ int objectId() const { return m_objectId; }
+ void setObjectId(int id) { m_objectId = id; }
+
+ void initialize(QGLView *view, QGLPainter *painter);
+ void draw(QGLPainter *painter);
+
+signals:
+ void pressed();
+ void released();
+ void clicked();
+ void doubleClicked();
+ void hoverChanged();
+
+protected:
+ bool event(QEvent *e);
+
+private:
+ QGLSceneNode *m_mesh;
+ QGLSceneNode *m_meshObject;
+ QGLAbstractScene *m_scene;
+ QVector3D m_position;
+ qreal m_scale;
+ qreal m_rotationAngle;
+ QVector3D m_rotationVector;
+ QGLMaterial *m_material;
+ QGLMaterial *m_hoverMaterial;
+ QGLAbstractEffect *m_effect;
+ int m_objectId;
+ bool m_hovering;
+};
+
+#endif
diff --git a/demos/qt3d/teaservice/per_pixel_lighting.fsh b/demos/qt3d/teaservice/per_pixel_lighting.fsh
new file mode 100644
index 000000000..166c4d44b
--- /dev/null
+++ b/demos/qt3d/teaservice/per_pixel_lighting.fsh
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Per-pixel lighting - fragment shader side.
+
+struct qt_MaterialParameters {
+ mediump vec4 emission;
+ mediump vec4 ambient;
+ mediump vec4 diffuse;
+ mediump vec4 specular;
+ mediump float shininess;
+};
+uniform qt_MaterialParameters qt_Material;
+
+struct qt_SingleLightParameters {
+ mediump vec4 position;
+ mediump vec3 spotDirection;
+ mediump float spotExponent;
+ mediump float spotCutoff;
+ mediump float spotCosCutoff;
+ mediump float constantAttenuation;
+ mediump float linearAttenuation;
+ mediump float quadraticAttenuation;
+};
+uniform qt_SingleLightParameters qt_Light;
+
+varying mediump vec3 qNormal;
+varying mediump vec3 qLightDirection;
+varying mediump vec3 qHalfVector;
+varying mediump vec3 qVertexToLight;
+varying mediump vec4 qAmbient;
+varying mediump vec4 qDiffuse;
+
+vec4 qLightPixel(vec4 ambient, vec4 diffuse)
+{
+ float angle, spot;
+ vec4 color;
+ vec4 component;
+ vec3 normal = normalize(qNormal);
+
+ // Start with the ambient color.
+ color = ambient;
+
+ // Determine the cosine of the angle between the normal and the
+ // vector from the vertex to the light.
+ angle = max(dot(normal, qLightDirection), 0.0);
+
+ // Calculate the diffuse light components.
+ component = angle * diffuse;
+
+ // Calculate the specular light components.
+ if (angle != 0.0) {
+ angle = max(dot(normal, qHalfVector), 0.0);
+ component += pow(angle, qt_Material.shininess) * qt_Material.specular;
+ }
+
+ // Apply the spotlight angle and exponent.
+ if (qt_Light.spotCutoff != 180.0) {
+ spot = max(dot(normalize(qVertexToLight),
+ normalize(qt_Light.spotDirection)), 0.0);
+ if (spot < qt_Light.spotCosCutoff)
+ spot = 0.0;
+ else
+ spot = pow(spot, qt_Light.spotExponent);
+ component *= spot;
+ }
+
+ return clamp(color + component, 0.0, 1.0);
+}
+
+void main(void)
+{
+ gl_FragColor = qLightPixel(qAmbient, qDiffuse);
+}
diff --git a/demos/qt3d/teaservice/per_pixel_lighting.vsh b/demos/qt3d/teaservice/per_pixel_lighting.vsh
new file mode 100644
index 000000000..c437652ef
--- /dev/null
+++ b/demos/qt3d/teaservice/per_pixel_lighting.vsh
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Per-pixel lighting - vertex shader side.
+
+attribute highp vec4 qt_Vertex;
+attribute mediump vec3 qt_Normal;
+uniform mediump mat4 qt_ModelViewMatrix;
+uniform mediump mat4 qt_ModelViewProjectionMatrix;
+uniform mediump mat3 qt_NormalMatrix;
+
+struct qt_MaterialParameters {
+ mediump vec4 emission;
+ mediump vec4 ambient;
+ mediump vec4 diffuse;
+ mediump vec4 specular;
+ mediump float shininess;
+};
+uniform qt_MaterialParameters qt_Material;
+
+struct qt_SingleLightParameters {
+ mediump vec4 position;
+ mediump vec3 spotDirection;
+ mediump float spotExponent;
+ mediump float spotCutoff;
+ mediump float spotCosCutoff;
+ mediump float constantAttenuation;
+ mediump float linearAttenuation;
+ mediump float quadraticAttenuation;
+};
+uniform qt_SingleLightParameters qt_Light;
+
+varying mediump vec4 qAmbient;
+varying mediump vec4 qDiffuse;
+varying mediump vec3 qNormal;
+varying mediump vec3 qLightDirection;
+varying mediump vec3 qHalfVector;
+varying mediump vec3 qVertexToLight;
+
+void qLightVertex(vec4 vertex, vec3 normal)
+{
+ vec3 toEye;
+ qNormal = normal;
+ qAmbient = qt_Material.emission + qt_Material.ambient;
+ qDiffuse = qt_Material.diffuse;
+ qLightDirection = normalize(qt_Light.position.xyz);
+ toEye = vec3(0, 0, 1);
+ qHalfVector = normalize(qLightDirection + toEye);
+ qVertexToLight = vertex.xyz - qt_Light.position.xyz;
+}
+
+void main(void)
+{
+ gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
+ vec4 vertex = qt_ModelViewMatrix * qt_Vertex;
+ vec3 normal = normalize(qt_NormalMatrix * qt_Normal);
+ qLightVertex(vertex, normal);
+}
diff --git a/demos/qt3d/teaservice/perpixeleffect.cpp b/demos/qt3d/teaservice/perpixeleffect.cpp
new file mode 100644
index 000000000..450f21396
--- /dev/null
+++ b/demos/qt3d/teaservice/perpixeleffect.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "perpixeleffect.h"
+
+QT_BEGIN_NAMESPACE
+
+PerPixelEffect::PerPixelEffect()
+{
+ setVertexShaderFromFile(":per_pixel_lighting.vsh");
+ setFragmentShaderFromFile(":per_pixel_lighting.fsh");
+}
+
+PerPixelEffect::~PerPixelEffect()
+{
+}
+
+QT_END_NAMESPACE
diff --git a/demos/qt3d/teaservice/perpixeleffect.h b/demos/qt3d/teaservice/perpixeleffect.h
new file mode 100644
index 000000000..cf015abdf
--- /dev/null
+++ b/demos/qt3d/teaservice/perpixeleffect.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PERPIXELEFFECT_H
+#define PERPIXELEFFECT_H
+
+#include "qglshaderprogrameffect.h"
+
+class PerPixelEffectPrivate;
+class QGLShader;
+
+class PerPixelEffect : public QGLShaderProgramEffect
+{
+ Q_DISABLE_COPY(PerPixelEffect);
+public:
+ PerPixelEffect();
+ virtual ~PerPixelEffect();
+};
+
+#endif
diff --git a/demos/qt3d/teaservice/sceneobject.cpp b/demos/qt3d/teaservice/sceneobject.cpp
new file mode 100644
index 000000000..438b6fa19
--- /dev/null
+++ b/demos/qt3d/teaservice/sceneobject.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "sceneobject.h"
+#include "meshobject.h"
+
+SceneObject::SceneObject(QObject *parent)
+ : QObject(parent)
+{
+}
+
+SceneObject::~SceneObject()
+{
+}
+
+void SceneObject::initialize(QGLView *view, QGLPainter *painter)
+{
+ // Initialize all of the mesh objects that we have as children.
+ foreach (QObject *obj, children()) {
+ MeshObject *meshobj = qobject_cast<MeshObject *>(obj);
+ if (meshobj)
+ meshobj->initialize(view, painter);
+ }
+}
+
+void SceneObject::draw(QGLPainter *painter)
+{
+ // Draw all of the mesh objects that we have as children.
+ foreach (QObject *obj, children()) {
+ MeshObject *meshobj = qobject_cast<MeshObject *>(obj);
+ if (meshobj)
+ meshobj->draw(painter);
+ }
+}
diff --git a/demos/qt3d/teaservice/sceneobject.h b/demos/qt3d/teaservice/sceneobject.h
new file mode 100644
index 000000000..edfaa82a6
--- /dev/null
+++ b/demos/qt3d/teaservice/sceneobject.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCENEOBJECT_H
+#define SCENEOBJECT_H
+
+#include <QtCore/qobject.h>
+#include "qglpainter.h"
+
+class QGLView;
+
+class SceneObject : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SceneObject(QObject *parent=0);
+ virtual ~SceneObject();
+
+ virtual void initialize(QGLView *view, QGLPainter *painter);
+ virtual void draw(QGLPainter *painter);
+};
+
+#endif
diff --git a/demos/qt3d/teaservice/teacup.txt b/demos/qt3d/teaservice/teacup.txt
new file mode 100644
index 000000000..f4dde3efd
--- /dev/null
+++ b/demos/qt3d/teaservice/teacup.txt
@@ -0,0 +1,280 @@
+26
+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
+4,17,18,19,8,20,21,22,12,23,24,25,16,26,27,28
+19,29,30,31,22,32,33,34,25,35,36,37,28,38,39,40
+31,41,42,1,34,43,44,5,37,45,46,9,40,47,48,13
+13,14,15,16,49,50,51,52,53,54,55,56,57,58,59,60
+16,26,27,28,52,61,62,63,56,64,65,66,60,67,68,69
+28,38,39,40,63,70,71,72,66,73,74,75,69,76,77,78
+40,47,48,13,72,79,80,49,75,81,82,53,78,83,84,57
+193,194,195,196,197,198,199,200,201,202,203,204,1,2,3,4
+196,205,206,207,200,208,209,210,204,211,212,213,4,17,18,19
+207,214,215,216,210,217,218,219,213,220,221,222,19,29,30,31
+216,223,224,193,219,225,226,197,222,227,228,201,31,41,42,1
+229,230,231,28,232,233,234,235,236,237,238,239,240,241,242,243
+28,244,245,229,235,246,247,232,239,248,249,236,243,250,251,240
+57,58,59,60,85,86,87,88,89,90,91,92,93,94,95,96
+60,67,68,69,88,97,98,99,92,100,101,102,96,103,104,105
+69,76,77,78,99,106,107,108,102,109,110,111,105,112,113,114
+78,83,84,57,108,115,116,85,111,117,118,89,114,119,120,93
+93,94,95,96,121,122,123,124,125,126,127,128,129,130,131,132
+96,103,104,105,124,133,134,135,128,136,137,138,132,139,140,141
+105,112,113,114,135,142,143,144,138,145,146,147,141,148,149,150
+114,119,120,93,144,151,152,121,147,153,154,125,150,155,156,129
+129,130,131,132,157,158,159,160,161,162,163,164,165,166,167,168
+132,139,140,141,160,169,170,171,164,172,173,174,168,175,176,177
+141,148,149,150,171,178,179,180,174,181,182,183,177,184,185,186
+150,155,156,129,180,187,188,157,183,189,190,161,186,191,192,165
+251
+0.409091,0.772727,0.0
+0.409091,0.772727,-0.229091
+0.229091,0.772727,-0.409091
+0.0,0.772727,-0.409091
+0.409091,0.886364,0.0
+0.409091,0.886364,-0.229091
+0.229091,0.886364,-0.409091
+0.0,0.886364,-0.409091
+0.454545,0.886364,0.0
+0.454545,0.886364,-0.254545
+0.254545,0.886364,-0.454545
+0.0,0.886364,-0.454545
+0.454545,0.772727,0.0
+0.454545,0.772727,-0.254545
+0.254545,0.772727,-0.454545
+0.0,0.772727,-0.454545
+-0.229091,0.772727,-0.409091
+-0.409091,0.772727,-0.229091
+-0.409091,0.772727,0.0
+-0.229091,0.886364,-0.409091
+-0.409091,0.886364,-0.229091
+-0.409091,0.886364,0.0
+-0.254545,0.886364,-0.454545
+-0.454545,0.886364,-0.254545
+-0.454545,0.886364,0.0
+-0.254545,0.772727,-0.454545
+-0.454545,0.772727,-0.254545
+-0.454545,0.772727,0.0
+-0.409091,0.772727,0.229091
+-0.229091,0.772727,0.409091
+0.0,0.772727,0.409091
+-0.409091,0.886364,0.229091
+-0.229091,0.886364,0.409091
+0.0,0.886364,0.409091
+-0.454545,0.886364,0.254545
+-0.254545,0.886364,0.454545
+0.0,0.886364,0.454545
+-0.454545,0.772727,0.254545
+-0.254545,0.772727,0.454545
+0.0,0.772727,0.454545
+0.229091,0.772727,0.409091
+0.409091,0.772727,0.229091
+0.229091,0.886364,0.409091
+0.409091,0.886364,0.229091
+0.254545,0.886364,0.454545
+0.454545,0.886364,0.254545
+0.254545,0.772727,0.454545
+0.454545,0.772727,0.254545
+0.454545,0.545455,0.0
+0.454545,0.545455,-0.254545
+0.254545,0.545455,-0.454545
+0.0,0.545455,-0.454545
+0.454545,0.272727,0.0
+0.454545,0.272727,-0.254545
+0.254545,0.272727,-0.454545
+0.0,0.272727,-0.454545
+0.318182,0.0454545,0.0
+0.318182,0.0454545,-0.178182
+0.178182,0.0454545,-0.318182
+0.0,0.0454545,-0.318182
+-0.254545,0.545455,-0.454545
+-0.454545,0.545455,-0.254545
+-0.454545,0.545455,0.0
+-0.254545,0.272727,-0.454545
+-0.454545,0.272727,-0.254545
+-0.454545,0.272727,0.0
+-0.178182,0.0454545,-0.318182
+-0.318182,0.0454545,-0.178182
+-0.318182,0.0454545,0.0
+-0.454545,0.545455,0.254545
+-0.254545,0.545455,0.454545
+0.0,0.545455,0.454545
+-0.454545,0.272727,0.254545
+-0.254545,0.272727,0.454545
+0.0,0.272727,0.454545
+-0.318182,0.0454545,0.178182
+-0.178182,0.0454545,0.318182
+0.0,0.0454545,0.318182
+0.254545,0.545455,0.454545
+0.454545,0.545455,0.254545
+0.254545,0.272727,0.454545
+0.454545,0.272727,0.254545
+0.178182,0.0454545,0.318182
+0.318182,0.0454545,0.178182
+0.545455,0.0454545,0.0
+0.545455,0.0454545,-0.305455
+0.305455,0.0454545,-0.545455
+0.0,0.0454545,-0.545455
+0.727273,0.136364,0.0
+0.727273,0.136364,-0.407273
+0.407273,0.136364,-0.727273
+0.0,0.136364,-0.727273
+0.909091,0.136364,0.0
+0.909091,0.136364,-0.509091
+0.509091,0.136364,-0.909091
+0.0,0.136364,-0.909091
+-0.305455,0.0454545,-0.545455
+-0.545455,0.0454545,-0.305455
+-0.545455,0.0454545,0.0
+-0.407273,0.136364,-0.727273
+-0.727273,0.136364,-0.407273
+-0.727273,0.136364,0.0
+-0.509091,0.136364,-0.909091
+-0.909091,0.136364,-0.509091
+-0.909091,0.136364,0.0
+-0.545455,0.0454545,0.305455
+-0.305455,0.0454545,0.545455
+0.0,0.0454545,0.545455
+-0.727273,0.136364,0.407273
+-0.407273,0.136364,0.727273
+0.0,0.136364,0.727273
+-0.909091,0.136364,0.509091
+-0.509091,0.136364,0.909091
+0.0,0.136364,0.909091
+0.305455,0.0454545,0.545455
+0.545455,0.0454545,0.305455
+0.407273,0.136364,0.727273
+0.727273,0.136364,0.407273
+0.509091,0.136364,0.909091
+0.909091,0.136364,0.509091
+1.0,0.136364,0.0
+1.0,0.136364,-0.56
+0.56,0.136364,-1.0
+0.0,0.136364,-1.0
+1.0,0.0909091,0.0
+1.0,0.0909091,-0.56
+0.56,0.0909091,-1.0
+0.0,0.0909091,-1.0
+0.909091,0.0909091,0.0
+0.909091,0.0909091,-0.509091
+0.509091,0.0909091,-0.909091
+0.0,0.0909091,-0.909091
+-0.56,0.136364,-1.0
+-1.0,0.136364,-0.56
+-1.0,0.136364,0.0
+-0.56,0.0909091,-1.0
+-1.0,0.0909091,-0.56
+-1.0,0.0909091,0.0
+-0.509091,0.0909091,-0.909091
+-0.909091,0.0909091,-0.509091
+-0.909091,0.0909091,0.0
+-1.0,0.136364,0.56
+-0.56,0.136364,1.0
+0.0,0.136364,1.0
+-1.0,0.0909091,0.56
+-0.56,0.0909091,1.0
+0.0,0.0909091,1.0
+-0.909091,0.0909091,0.509091
+-0.509091,0.0909091,0.909091
+0.0,0.0909091,0.909091
+0.56,0.136364,1.0
+1.0,0.136364,0.56
+0.56,0.0909091,1.0
+1.0,0.0909091,0.56
+0.509091,0.0909091,0.909091
+0.909091,0.0909091,0.509091
+0.727273,0.0909091,0.0
+0.727273,0.0909091,-0.407273
+0.407273,0.0909091,-0.727273
+0.0,0.0909091,-0.727273
+0.545455,0.0,0.0
+0.545455,0.0,-0.305455
+0.305455,0.0,-0.545455
+0.0,0.0,-0.545455
+0.318182,0.0,0.0
+0.318182,0.0,-0.178182
+0.178182,0.0,-0.318182
+0.0,0.0,-0.318182
+-0.407273,0.0909091,-0.727273
+-0.727273,0.0909091,-0.407273
+-0.727273,0.0909091,0.0
+-0.305455,0.0,-0.545455
+-0.545455,0.0,-0.305455
+-0.545455,0.0,0.0
+-0.178182,0.0,-0.318182
+-0.318182,0.0,-0.178182
+-0.318182,0.0,0.0
+-0.727273,0.0909091,0.407273
+-0.407273,0.0909091,0.727273
+0.0,0.0909091,0.727273
+-0.545455,0.0,0.305455
+-0.305455,0.0,0.545455
+0.0,0.0,0.545455
+-0.318182,0.0,0.178182
+-0.178182,0.0,0.318182
+0.0,0.0,0.318182
+0.407273,0.0909091,0.727273
+0.727273,0.0909091,0.407273
+0.305455,0.0,0.545455
+0.545455,0.0,0.305455
+0.178182,0.0,0.318182
+0.318182,0.0,0.178182
+0.272727,0.0454545,0.0
+0.272727,0.0454545,-0.152727
+0.152727,0.0454545,-0.272727
+0.0,0.0454545,-0.272727
+0.409091,0.272727,0.0
+0.409091,0.272727,-0.229091
+0.229091,0.272727,-0.409091
+0.0,0.272727,-0.409091
+0.409091,0.545455,0.0
+0.409091,0.545455,-0.229091
+0.229091,0.545455,-0.409091
+0.0,0.545455,-0.409091
+-0.152727,0.0454545,-0.272727
+-0.272727,0.0454545,-0.152727
+-0.272727,0.0454545,0.0
+-0.229091,0.272727,-0.409091
+-0.409091,0.272727,-0.229091
+-0.409091,0.272727,0.0
+-0.229091,0.545455,-0.409091
+-0.409091,0.545455,-0.229091
+-0.409091,0.545455,0.0
+-0.272727,0.0454545,0.152727
+-0.152727,0.0454545,0.272727
+0.0,0.0454545,0.272727
+-0.409091,0.272727,0.229091
+-0.229091,0.272727,0.409091
+0.0,0.272727,0.409091
+-0.409091,0.545455,0.229091
+-0.229091,0.545455,0.409091
+0.0,0.545455,0.409091
+0.152727,0.0454545,0.272727
+0.272727,0.0454545,0.152727
+0.229091,0.272727,0.409091
+0.409091,0.272727,0.229091
+0.229091,0.545455,0.409091
+0.409091,0.545455,0.229091
+-0.454545,0.704545,0.0
+-0.454545,0.704545,-0.0454545
+-0.454545,0.772727,-0.0454545
+-0.772727,0.863636,0.0
+-0.772727,0.863636,-0.0454545
+-0.818182,0.954545,-0.0454545
+-0.818182,0.954545,0.0
+-0.772727,0.522727,0.0
+-0.772727,0.522727,-0.0454545
+-0.909091,0.477273,-0.0454545
+-0.909091,0.477273,0.0
+-0.409091,0.363636,0.0
+-0.409091,0.363636,-0.0454545
+-0.409091,0.295455,-0.0454545
+-0.409091,0.295455,0.0
+-0.454545,0.772727,0.0454545
+-0.454545,0.704545,0.0454545
+-0.818182,0.954545,0.0454545
+-0.772727,0.863636,0.0454545
+-0.909091,0.477273,0.0454545
+-0.772727,0.522727,0.0454545
+-0.409091,0.295455,0.0454545
+-0.409091,0.363636,0.0454545
+# reverse-patches
diff --git a/demos/qt3d/teaservice/teaservice.cpp b/demos/qt3d/teaservice/teaservice.cpp
new file mode 100644
index 000000000..8923fb3ae
--- /dev/null
+++ b/demos/qt3d/teaservice/teaservice.cpp
@@ -0,0 +1,379 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMainWindow>
+#include <QMenu>
+#include <QMenuBar>
+#include <QKeyEvent>
+#include <QAction>
+#include <QDebug>
+#include "qglview.h"
+#include "meshobject.h"
+#include "sceneobject.h"
+#include "qglteapot.h"
+#include "qglbuilder.h"
+#include "perpixeleffect.h"
+
+enum {
+ ObjTeapot,
+ ObjTeacup1,
+ ObjTeacup2,
+ ObjTeaspoon1,
+ ObjTeaspoon2
+};
+
+class Teapot : public MeshObject
+{
+ Q_OBJECT
+public:
+ Teapot(QObject *parent=0);
+ ~Teapot() {}
+};
+
+static QGLSceneNode *createTeapot(QObject *parent)
+{
+ QGLBuilder builder;
+ builder << QGLTeapot();
+ QGLSceneNode *n = builder.finalizedSceneNode();
+ n->setParent(parent);
+ return n;
+}
+
+Teapot::Teapot(QObject *parent)
+ : MeshObject(createTeapot(parent), parent)
+{
+}
+
+class Teacup : public MeshObject
+{
+ Q_OBJECT
+public:
+ Teacup(QObject *parent=0);
+ ~Teacup() {}
+};
+
+static QGLAbstractScene *loadBezier(const QString& fileName)
+{
+ QGLAbstractScene *scene;
+ scene = QGLAbstractScene::loadScene(fileName, QLatin1String("bezier"));
+ if (!scene)
+ qFatal("Could not load %s, probably plugin could not be found",
+ fileName.toLatin1().constData());
+ return scene;
+}
+
+Teacup::Teacup(QObject *parent)
+ : MeshObject(loadBezier(QLatin1String(":/teacup.txt")), parent)
+{
+}
+
+class Teaspoon : public MeshObject
+{
+ Q_OBJECT
+public:
+ Teaspoon(QObject *parent=0);
+ ~Teaspoon() {}
+};
+
+Teaspoon::Teaspoon(QObject *parent)
+ : MeshObject(loadBezier(QLatin1String(":/teaspoon.txt")), parent)
+{
+}
+
+class TeaService : public QObject
+{
+ Q_OBJECT
+public:
+ TeaService(QObject *parent=0);
+ ~TeaService();
+
+ SceneObject *service;
+
+ Teapot *teapot;
+ Teacup *teacup1;
+ Teacup *teacup2;
+ Teaspoon *teaspoon1;
+ Teaspoon *teaspoon2;
+ PerPixelEffect *lighting;
+
+ void changeMaterials(bool perPixel);
+
+signals:
+ void changed();
+
+private slots:
+ void teapotClicked();
+ void teacup1Clicked();
+ void teacup2Clicked();
+ void teaspoon1Clicked();
+ void teaspoon2Clicked();
+
+private:
+ QGLMaterial *china;
+ QGLMaterial *chinaHighlight;
+ QGLMaterial *metal;
+ QGLMaterial *metalHighlight;
+};
+
+TeaService::TeaService(QObject *parent)
+ : QObject(parent)
+{
+ china = new QGLMaterial(this);
+ china->setAmbientColor(QColor(192, 150, 128));
+ china->setSpecularColor(QColor(60, 60, 60));
+ china->setShininess(128);
+
+ chinaHighlight = new QGLMaterial(this);
+ chinaHighlight->setAmbientColor(QColor(255, 192, 0));
+ chinaHighlight->setSpecularColor(QColor(60, 60, 0));
+ chinaHighlight->setShininess(128);
+
+ metal = new QGLMaterial(this);
+ metal->setAmbientColor(QColor(255, 255, 255));
+ metal->setDiffuseColor(QColor(150, 150, 150));
+ metal->setSpecularColor(QColor(255, 255, 255));
+ metal->setShininess(128);
+
+ metalHighlight = new QGLMaterial(this);
+ metalHighlight->setAmbientColor(QColor(255, 255, 96));
+ metalHighlight->setDiffuseColor(QColor(150, 150, 96));
+ metalHighlight->setSpecularColor(QColor(255, 255, 255));
+ metalHighlight->setShininess(128);
+
+ service = new SceneObject(this);
+ teapot = new Teapot(service);
+ teacup1 = new Teacup(service);
+ teacup2 = new Teacup(service);
+ teacup1->setPosition(QVector3D(-2.3f, -0.75f, 0.0f));
+ teacup2->setRotationAngle(180);
+ teacup2->setRotationVector(QVector3D(0, 1, 0));
+ teacup2->setPosition(QVector3D(2.3f, -0.75f, 0.0f));
+ teaspoon1 = new Teaspoon(service);
+ teaspoon2 = new Teaspoon(service);
+ teaspoon1->setRotationAngle(275);
+ teaspoon1->setRotationVector(QVector3D(1, 0, 0));
+ teaspoon1->setPosition(QVector3D(-1.7f, -0.58f, 0.0f));
+ teaspoon2->setRotationAngle(275);
+ teaspoon2->setRotationVector(QVector3D(1, 0, 0));
+ teaspoon2->setPosition(QVector3D(1.7f, -0.58f, 0.0f));
+
+ teapot->setObjectId(ObjTeapot);
+ teacup1->setObjectId(ObjTeacup1);
+ teacup2->setObjectId(ObjTeacup2);
+ teaspoon1->setObjectId(ObjTeaspoon1);
+ teaspoon2->setObjectId(ObjTeaspoon2);
+
+ lighting = new PerPixelEffect();
+ changeMaterials(false);
+
+ connect(teapot, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
+ connect(teacup1, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
+ connect(teacup2, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
+ connect(teaspoon1, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
+ connect(teaspoon2, SIGNAL(hoverChanged()), this, SIGNAL(changed()));
+
+ connect(teapot, SIGNAL(clicked()), this, SLOT(teapotClicked()));
+ connect(teacup1, SIGNAL(clicked()), this, SLOT(teacup1Clicked()));
+ connect(teacup2, SIGNAL(clicked()), this, SLOT(teacup2Clicked()));
+ connect(teaspoon1, SIGNAL(clicked()), this, SLOT(teaspoon1Clicked()));
+ connect(teaspoon2, SIGNAL(clicked()), this, SLOT(teaspoon2Clicked()));
+}
+
+TeaService::~TeaService()
+{
+ delete lighting;
+}
+
+void TeaService::changeMaterials(bool perPixel)
+{
+ teapot->setMaterial(china);
+ teapot->setHoverMaterial(chinaHighlight);
+ teacup1->setMaterial(china);
+ teacup1->setHoverMaterial(chinaHighlight);
+ teacup2->setMaterial(china);
+ teacup2->setHoverMaterial(chinaHighlight);
+ if (perPixel) {
+ teapot->setEffect(lighting);
+ teacup1->setEffect(lighting);
+ teacup2->setEffect(lighting);
+ } else
+ {
+ teapot->setEffect(0);
+ teacup1->setEffect(0);
+ teacup2->setEffect(0);
+ }
+
+ teaspoon1->setMaterial(metal);
+ teaspoon1->setHoverMaterial(metalHighlight);
+ teaspoon2->setMaterial(metal);
+ teaspoon2->setHoverMaterial(metalHighlight);
+ if (perPixel) {
+ teaspoon1->setEffect(lighting);
+ teaspoon2->setEffect(lighting);
+ } else
+ {
+ teaspoon1->setEffect(0);
+ teaspoon2->setEffect(0);
+ }
+}
+
+void TeaService::teapotClicked()
+{
+ qDebug("teapot clicked");
+}
+
+void TeaService::teacup1Clicked()
+{
+ qDebug("teacup1 clicked");
+}
+
+void TeaService::teacup2Clicked()
+{
+ qDebug("teacup2 clicked");
+}
+
+void TeaService::teaspoon1Clicked()
+{
+ qDebug("teaspoon1 clicked");
+}
+
+void TeaService::teaspoon2Clicked()
+{
+ qDebug("teaspoon2 clicked");
+}
+
+class TeaServiceView : public QGLView
+{
+ Q_OBJECT
+public:
+ TeaServiceView(QWidget *parent=0);
+
+public slots:
+ void standardLighting();
+ void perPixelLighting();
+
+protected:
+ void initializeGL(QGLPainter *painter);
+ void paintGL(QGLPainter *painter);
+ void keyPressEvent(QKeyEvent *e);
+
+private:
+ TeaService *teaService;
+};
+
+TeaServiceView::TeaServiceView(QWidget *parent)
+ : QGLView(parent)
+{
+ teaService = new TeaService(this);
+
+ setOption(QGLView::ObjectPicking, true);
+
+ connect(teaService, SIGNAL(changed()), this, SLOT(updateGL()));
+}
+
+void TeaServiceView::initializeGL(QGLPainter *painter)
+{
+ teaService->service->initialize(this, painter);
+}
+
+void TeaServiceView::paintGL(QGLPainter *painter)
+{
+ teaService->service->draw(painter);
+}
+
+void TeaServiceView::standardLighting()
+{
+ teaService->changeMaterials(false);
+ updateGL();
+}
+
+void TeaServiceView::perPixelLighting()
+{
+ teaService->changeMaterials(true);
+ updateGL();
+}
+
+void TeaServiceView::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Tab) {
+ // The Tab key turns the ShowPicking option on and off,
+ // which helps show what the pick buffer looks like.
+ setOption(QGLView::ShowPicking, ((options() & QGLView::ShowPicking) == 0));
+ updateGL();
+ }
+ QGLView::keyPressEvent(e);
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QMainWindow mainw;
+ mainw.setMinimumSize(850, 480);
+ mainw.setWindowTitle(QLatin1String("Tea Service"));
+
+ TeaServiceView view;
+ mainw.setCentralWidget(&view);
+ view.setFocus();
+
+ view.camera()->setEye(QVector3D(0, 3, 10));
+
+ QMenu *menu = mainw.menuBar()->addMenu(QLatin1String("Effects"));
+
+ QAction *standardLighting = new QAction(QLatin1String("Standard lighting"), &mainw);
+ menu->addAction(standardLighting);
+ QObject::connect(standardLighting, SIGNAL(triggered()), &view, SLOT(standardLighting()));
+
+ QAction *perPixelLighting = new QAction(QLatin1String("Per-pixel lighting"), &mainw);
+ menu->addAction(perPixelLighting);
+ QObject::connect(perPixelLighting, SIGNAL(triggered()), &view, SLOT(perPixelLighting()));
+
+ menu->addSeparator();
+
+ QAction *exitAction = new QAction(QLatin1String("E&xit"), &mainw);
+ menu->addAction(exitAction);
+ QObject::connect(exitAction, SIGNAL(triggered()), &app, SLOT(quit()));
+
+ mainw.show();
+ return app.exec();
+}
+
+#include "teaservice.moc"
diff --git a/demos/qt3d/teaservice/teaservice.pro b/demos/qt3d/teaservice/teaservice.pro
new file mode 100644
index 000000000..e08325de1
--- /dev/null
+++ b/demos/qt3d/teaservice/teaservice.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+TARGET = teaservice
+CONFIG += qt warn_on qt3d
+SOURCES = teaservice.cpp meshobject.cpp sceneobject.cpp perpixeleffect.cpp
+HEADERS = meshobject.h sceneobject.h perpixeleffect.h
+RESOURCES = teaservice.qrc
+DESTDIR = ../../bin
diff --git a/demos/qt3d/teaservice/teaservice.qrc b/demos/qt3d/teaservice/teaservice.qrc
new file mode 100644
index 000000000..ab55d88c0
--- /dev/null
+++ b/demos/qt3d/teaservice/teaservice.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>per_pixel_lighting.vsh</file>
+ <file>per_pixel_lighting.fsh</file>
+ <file>teacup.txt</file>
+ <file>teaspoon.txt</file>
+</qresource>
+</RCC>
diff --git a/demos/qt3d/teaservice/teaspoon.txt b/demos/qt3d/teaservice/teaspoon.txt
new file mode 100644
index 000000000..3c6a1b74b
--- /dev/null
+++ b/demos/qt3d/teaservice/teaspoon.txt
@@ -0,0 +1,275 @@
+16
+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
+17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
+33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48
+49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64
+65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80
+81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96
+97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112
+113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128
+129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144
+145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160
+161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176
+177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192
+193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208
+209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224
+225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240
+241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256
+256
+-0.000107143,0.205357,0.0
+0.0,0.196429,-0.0178571
+0.0,0.196429,-0.0178571
+0.000107143,0.205357,0.0
+-0.0535714,0.205357,0.0
+-0.0222714,0.178571,-0.0534286
+0.0222714,0.178571,-0.0534286
+0.0535714,0.205357,0.0
+-0.107143,0.0952429,-0.0178571
+-0.0446429,0.0952429,-0.0892857
+0.0446429,0.0952429,-0.0892857
+0.107143,0.0952429,-0.0178571
+-0.107143,0.0,-0.0178571
+-0.0446429,0.0,-0.0892857
+0.0446429,0.0,-0.0892857
+0.107143,0.0,-0.0178571
+0.000107143,0.205357,0.0
+0.000135714,0.207589,0.00446429
+0.000157143,0.216518,0.00446429
+0.000125,0.214286,0.0
+0.0535714,0.205357,0.0
+0.0613964,0.212054,0.0133571
+0.0714286,0.220982,0.015625
+0.0625,0.214286,0.0
+0.107143,0.0952429,-0.0178571
+0.122768,0.0952429,0.0
+0.142857,0.0952429,0.00446429
+0.125,0.0952429,-0.0178571
+0.107143,0.0,-0.0178571
+0.122768,0.0,0.0
+0.142857,0.0,0.00446429
+0.125,0.0,-0.0178571
+0.000125,0.214286,0.0
+0.0,0.205357,-0.0178571
+0.0,0.205357,-0.0178571
+-0.000125,0.214286,0.0
+0.0625,0.214286,0.0
+0.0267857,0.1875,-0.0625
+-0.0267857,0.1875,-0.0625
+-0.0625,0.214286,0.0
+0.125,0.0952429,-0.0178571
+0.0535714,0.0952429,-0.107143
+-0.0535714,0.0952429,-0.107143
+-0.125,0.0952429,-0.0178571
+0.125,0.0,-0.0178571
+0.0535714,0.0,-0.107143
+-0.0535714,0.0,-0.107143
+-0.125,0.0,-0.0178571
+-0.000125,0.214286,0.0
+-0.000157143,0.216518,0.00446429
+-0.000135714,0.207589,0.00446429
+-0.000107143,0.205357,0.0
+-0.0625,0.214286,0.0
+-0.0714286,0.220982,0.015625
+-0.0613964,0.212054,0.0133571
+-0.0535714,0.205357,0.0
+-0.125,0.0952429,-0.0178571
+-0.142857,0.0952429,0.00446429
+-0.122768,0.0952429,0.0
+-0.107143,0.0952429,-0.0178571
+-0.125,0.0,-0.0178571
+-0.142857,0.0,0.00446429
+-0.122768,0.0,0.0
+-0.107143,0.0,-0.0178571
+-0.107143,0.0,-0.0178571
+-0.0446429,0.0,-0.0892857
+0.0446429,0.0,-0.0892857
+0.107143,0.0,-0.0178571
+-0.107143,-0.142857,-0.0178571
+-0.0446429,-0.142857,-0.0892857
+0.0446429,-0.142857,-0.0892857
+0.107143,-0.142857,-0.0178571
+-0.0133929,-0.160714,0.0386893
+-0.00557857,-0.160714,0.0386893
+0.00557857,-0.160714,0.0386893
+0.0133929,-0.160714,0.0386893
+-0.0133929,-0.25,0.0535714
+-0.00557857,-0.25,0.0535714
+0.00557857,-0.25,0.0535714
+0.0133929,-0.25,0.0535714
+0.107143,0.0,-0.0178571
+0.122768,0.0,0.0
+0.142857,0.0,0.00446429
+0.125,0.0,-0.0178571
+0.107143,-0.142857,-0.0178571
+0.122768,-0.142857,0.0
+0.142857,-0.142857,0.00446429
+0.125,-0.142857,-0.0178571
+0.0133929,-0.160714,0.0386893
+0.0153464,-0.160714,0.0386893
+0.0178571,-0.160714,0.0314357
+0.015625,-0.160714,0.0297607
+0.0133929,-0.25,0.0535714
+0.0153464,-0.25,0.0535714
+0.0178571,-0.25,0.0463179
+0.015625,-0.25,0.0446429
+0.125,0.0,-0.0178571
+0.0535714,0.0,-0.107143
+-0.0535714,0.0,-0.107143
+-0.125,0.0,-0.0178571
+0.125,-0.142857,-0.0178571
+0.0535714,-0.142857,-0.107143
+-0.0535714,-0.142857,-0.107143
+-0.125,-0.142857,-0.0178571
+0.015625,-0.160714,0.0297607
+0.00669643,-0.160714,0.0230643
+-0.00781071,-0.160714,0.0208321
+-0.015625,-0.160714,0.0297607
+0.015625,-0.25,0.0446429
+0.00669643,-0.25,0.0379464
+-0.00781071,-0.25,0.0357143
+-0.015625,-0.25,0.0446429
+-0.125,0.0,-0.0178571
+-0.142857,0.0,0.00446429
+-0.122768,0.0,0.0
+-0.107143,0.0,-0.0178571
+-0.125,-0.142857,-0.0178571
+-0.142857,-0.142857,0.00446429
+-0.122768,-0.142857,0.0
+-0.107143,-0.142857,-0.0178571
+-0.015625,-0.160714,0.0297607
+-0.0175786,-0.160714,0.0319929
+-0.0153464,-0.160714,0.0386893
+-0.0133929,-0.160714,0.0386893
+-0.015625,-0.25,0.0446429
+-0.0175786,-0.25,0.046875
+-0.0153464,-0.25,0.0535714
+-0.0133929,-0.25,0.0535714
+-0.0133929,-0.25,0.0535714
+-0.00557857,-0.25,0.0535714
+0.00557857,-0.25,0.0535714
+0.0133929,-0.25,0.0535714
+-0.0133929,-0.46425,0.0892857
+-0.00557857,-0.46425,0.0892857
+0.00557857,-0.46425,0.0892857
+0.0133929,-0.46425,0.0892857
+-0.0446429,-0.678571,0.0535714
+-0.00892857,-0.678571,0.0625
+0.00892857,-0.678571,0.0625
+0.0446429,-0.678571,0.0535714
+-0.0446429,-0.857143,0.0357143
+-0.00892857,-0.857143,0.0446429
+0.00892857,-0.857143,0.0446429
+0.0446429,-0.857143,0.0357143
+0.0133929,-0.25,0.0535714
+0.0153464,-0.25,0.0535714
+0.0178571,-0.25,0.0463179
+0.015625,-0.25,0.0446429
+0.0133929,-0.46425,0.0892857
+0.0153464,-0.464286,0.0892857
+0.0178571,-0.46425,0.0820321
+0.015625,-0.46425,0.0803571
+0.0446429,-0.678571,0.0535714
+0.0535714,-0.678571,0.0513393
+0.0535714,-0.678571,0.0334821
+0.0446429,-0.678571,0.0357143
+0.0446429,-0.857143,0.0357143
+0.0535714,-0.857143,0.0334821
+0.0535714,-0.857143,0.015625
+0.0446429,-0.857143,0.0178571
+0.015625,-0.25,0.0446429
+0.00669643,-0.25,0.0379464
+-0.00781071,-0.25,0.0357143
+-0.015625,-0.25,0.0446429
+0.015625,-0.46425,0.0803571
+0.00669643,-0.464286,0.0736607
+-0.00781071,-0.46425,0.0714286
+-0.015625,-0.46425,0.0803571
+0.0446429,-0.678571,0.0357143
+0.00892857,-0.678571,0.0446429
+-0.00892857,-0.678571,0.0446429
+-0.0446429,-0.678571,0.0357143
+0.0446429,-0.857143,0.0178571
+0.00892857,-0.857143,0.0267857
+-0.00892857,-0.857143,0.0267857
+-0.0446429,-0.857143,0.0178571
+-0.015625,-0.25,0.0446429
+-0.0175786,-0.25,0.046875
+-0.0153464,-0.25,0.0535714
+-0.0133929,-0.25,0.0535714
+-0.015625,-0.46425,0.0803571
+-0.0175786,-0.464286,0.0825893
+-0.0153464,-0.464286,0.0892857
+-0.0133929,-0.46425,0.0892857
+-0.0446429,-0.678571,0.0357143
+-0.0535714,-0.678571,0.0334821
+-0.0535714,-0.678571,0.0513393
+-0.0446429,-0.678571,0.0535714
+-0.0446429,-0.857143,0.0178571
+-0.0535714,-0.857143,0.015625
+-0.0535714,-0.857143,0.0334821
+-0.0446429,-0.857143,0.0357143
+-0.0446429,-0.857143,0.0357143
+-0.00892857,-0.857143,0.0446429
+0.00892857,-0.857143,0.0446429
+0.0446429,-0.857143,0.0357143
+-0.0446429,-0.928571,0.0285714
+-0.00892857,-0.928571,0.0375
+0.00892857,-0.928571,0.0375
+0.0446429,-0.928571,0.0285714
+-0.0539286,-0.999643,0.0178571
+0.000357143,-0.999643,0.0178571
+0.0,-0.999643,0.0178571
+0.0535714,-0.999643,0.0178571
+-0.000357143,-1,0.0178571
+0.000357143,-1,0.0178571
+0.0,-1,0.0178571
+0.0,-1,0.0178571
+0.0446429,-0.857143,0.0357143
+0.0535714,-0.857143,0.0334821
+0.0535714,-0.857143,0.015625
+0.0446429,-0.857143,0.0178571
+0.0446429,-0.928571,0.0285714
+0.0535714,-0.928571,0.0263393
+0.0535714,-0.928571,0.00848214
+0.0446429,-0.928571,0.0107143
+0.0535714,-0.999643,0.0178571
+0.0669643,-0.999643,0.0178571
+0.0673214,-0.999643,0.0
+0.0539286,-0.999643,0.0
+0.0,-1,0.0178571
+0.0,-1,0.0178571
+0.000357143,-1,0.0
+0.000357143,-1,0.0
+0.0446429,-0.857143,0.0178571
+0.00892857,-0.857143,0.0267857
+-0.00892857,-0.857143,0.0267857
+-0.0446429,-0.857143,0.0178571
+0.0446429,-0.928571,0.0107143
+0.00892857,-0.928571,0.0196429
+-0.00892857,-0.928571,0.0196429
+-0.0446429,-0.928571,0.0107143
+0.0539286,-0.999643,0.0
+0.000357143,-0.999643,0.0
+-0.000357143,-0.999643,0.0
+-0.0539286,-0.999643,0.0
+0.000357143,-1,0.0
+0.000357143,-1,0.0
+-0.000357143,-1,0.0
+-0.000357143,-1,0.0
+-0.0446429,-0.857143,0.0178571
+-0.0535714,-0.857143,0.015625
+-0.0535714,-0.857143,0.0334821
+-0.0446429,-0.857143,0.0357143
+-0.0446429,-0.928571,0.0107143
+-0.0535714,-0.928571,0.00848214
+-0.0535714,-0.928571,0.0263393
+-0.0446429,-0.928571,0.0285714
+-0.0539286,-0.999643,0.0
+-0.0673214,-0.999643,0.0
+-0.0675,-0.999643,0.0178571
+-0.0539286,-0.999643,0.0178571
+-0.000357143,-1,0.0
+-0.000357143,-1,0.0
+-0.000535714,-1,0.0178571
+-0.000357143,-1,0.0178571
+# reverse-patches