diff options
Diffstat (limited to 'src/quick3d')
-rw-r--r-- | src/quick3d/qdeclarativeeffect.cpp | 479 | ||||
-rw-r--r-- | src/quick3d/qdeclarativeeffect.h | 125 | ||||
-rw-r--r-- | src/quick3d/qdeclarativeitem3d.cpp | 1673 | ||||
-rw-r--r-- | src/quick3d/qdeclarativeitem3d.h | 224 | ||||
-rw-r--r-- | src/quick3d/qdeclarativemesh.cpp | 705 | ||||
-rw-r--r-- | src/quick3d/qdeclarativemesh.h | 140 | ||||
-rw-r--r-- | src/quick3d/qdeclarativeviewport.h | 72 | ||||
-rw-r--r-- | src/quick3d/qt3dquickglobal.h | 73 | ||||
-rw-r--r-- | src/quick3d/quick3d.pri | 16 | ||||
-rw-r--r-- | src/quick3d/quick3d.pro | 26 |
10 files changed, 0 insertions, 3533 deletions
diff --git a/src/quick3d/qdeclarativeeffect.cpp b/src/quick3d/qdeclarativeeffect.cpp deleted file mode 100644 index 2fe10ed1..00000000 --- a/src/quick3d/qdeclarativeeffect.cpp +++ /dev/null @@ -1,479 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativeeffect.h" - -#include "qglpainter.h" -#include "qglmaterial.h" - -#include <QtNetwork/QNetworkRequest> -#include <QtNetwork/QNetworkReply> - -#include <QtDeclarative/qdeclarativeengine.h> - -#include <QtDeclarative/qdeclarativeinfo.h> -#include "qglscenenode.h" - -/*! - \qmlclass Effect QDeclarativeEffect - \brief The Effect item defines simple effects within the QML/3D environment. Examples - of such effects include textures, simple material and lighting effects, and so on. - \since 4.8 - \ingroup qt3d::qml3d - - \section1 Defining an Effect - - Effects can be defined within QML using the normal syntax for creating any QML/3d object. To create a - default effect with no extra information, for example, we can simply using the following: - - \code - Effect {} - \endcode - - More complex effects use the usual QML syntax for accessing and updating properties. In order to specify - a texture, for example, the following could be used: - - \code - Effect { - id: myTextureEffect - texture: "texture.png" - } - \endcode -*/ - -QT_BEGIN_NAMESPACE - -class QDeclarativeEffectPrivate -{ -public: - QDeclarativeEffectPrivate() - : color(255, 255, 255, 255), - useLighting(true), - decal(false), - blending(false), - palette(0), - materialIndex(-1), - progress(0.0) - { - } - - ~QDeclarativeEffectPrivate() - { - delete palette; - } - - QColor color; - bool useLighting; - bool decal; - bool blending; - QGLMaterialCollection *palette; - int materialIndex; - qreal progress; - inline void ensureMaterial() { - if (!palette) - { - palette = new QGLMaterialCollection(); - } - if (materialIndex == -1) - { - materialIndex = palette->addMaterial(new QGLMaterial(palette)); - palette->material(materialIndex)->setColor(color); - } - // TODO: decal & blending - } -}; - -/*! - \internal - Constructs the Effect object with \a parent as its parent. -*/ -QDeclarativeEffect::QDeclarativeEffect(QObject *parent) - : QObject(parent) -{ - d = new QDeclarativeEffectPrivate; -} - -/*! - \internal - Destroy the \l Effect object and delete any unneeded data. -*/ -QDeclarativeEffect::~QDeclarativeEffect() -{ - delete d; -} - -/*! - \qmlproperty color Effect::color - - The color of the object for simple non-texture effects. - The default value for this property is white. -*/ - -QColor QDeclarativeEffect::color() const -{ - return d->color; -} - -void QDeclarativeEffect::setColor(const QColor& value) -{ - d->color = value; - d->ensureMaterial(); - material()->setColor(value); - emit effectChanged(); -} - -/*! - \qmlproperty bool Effect::useLighting - - The lighting control parameter; true if this effect should - use lighting or false if this effect should use flat colors and - textures. - - The default value for this property is true. -*/ -bool QDeclarativeEffect::useLighting() const -{ - return d->useLighting; -} - -void QDeclarativeEffect::setUseLighting(bool value) -{ - d->useLighting = value; - emit effectChanged(); -} - -/*! - \qmlproperty bool Effect::decal - - This property should be set to true if the \l texture should be - combined with \l color to decal the texture onto the object. - This property should be set to false to use the texture - directly, combined with the \l material parameters. - - The default value for this property is false. -*/ -bool QDeclarativeEffect::decal() const -{ - return d->decal; -} - -void QDeclarativeEffect::setDecal(bool value) -{ - if (d->decal != value) { - d->decal = value; - emit effectChanged(); - } -} - -/*! - \qmlproperty bool Effect::blending - - This property should be set to true if alpha blending should be - enabled when this effect is active, or false otherwise. The - default is false. - - This property overrides the viewport-specific blending setting - that is specified by Viewport::blending. -*/ -bool QDeclarativeEffect::blending() const -{ - return d->blending; -} - -void QDeclarativeEffect::setBlending(bool value) -{ - if (d->blending != value) { - d->blending = value; - emit effectChanged(); - } -} - -/*! - \qmlproperty url Effect::texture - - Texture effects are defined by this property. A texture is - provided by means of a QUrl which is then used for texturing. - - Textures can also be defined directly as images using the textureImage - property. - - If the value is non-empty, and the texture could not be loaded from - the QUrl for any reason, then the property will not be changed. - - \sa textureImage -*/ -QUrl QDeclarativeEffect::texture() const -{ - if (!material()) - return QUrl(); - return material()->textureUrl(); -} - -void QDeclarativeEffect::setTexture(const QUrl& value) -{ - if (material() && material()->textureUrl() == value) - return; - - if (d->progress != 0.0) - { - d->progress = 0.0; - emit progressChanged(d->progress); - } - - if (value.isEmpty()) - { - if (material()) - { - material()->setTextureUrl(value); - emit effectChanged(); - } - } - else - { - d->ensureMaterial(); - // Warning: This will trigger the deletion of the old texure. - material()->setTextureUrl(value); - emit effectChanged(); - } -} - -/*! - \qmlproperty image Effect::textureImage - - This property directly defines a texture using an existing QImage. - - Textures can also be defined based on a URL using the texture property. - - \sa texture -*/ -QImage QDeclarativeEffect::textureImage() const -{ - return (material() && material()->texture()) ? - material()->texture()->image() : QImage(); -} - -/*! - \internal - Sets this effect to use \value as the image for it's texture. - - OpenGL defaults have been overridden to clamp the texture both horizontally and vertically as per QGL::Clamp. -*/ -void QDeclarativeEffect::setTextureImage(const QImage& value) -{ - QGLTexture2D * tex; - d->ensureMaterial(); - if (!material()->texture()) - { - // Should this texture be parented? - tex = new QGLTexture2D(); - material()->setTexture(tex); - } else - { - tex = material()->texture(); - } - - // Equality test of images can be very expensive, so always assign the - // value and emit effect changed - tex->setImage(value); - - // prevents artifacts due to texture smoothing wrapping around edges of texture - tex->setHorizontalWrap(QGL::Clamp); - tex->setVerticalWrap(QGL::Clamp); - - emit effectChanged(); -} - -/*! - \qmlproperty Material Effect::material - - Defines the material to apply to items that use this effect. -*/ -QGLMaterial *QDeclarativeEffect::material() const -{ - if (!d->palette) - return 0; - return d->palette->material(d->materialIndex); -} - -/*! - \internal - Sets the material for use with this effect. Creates a QGLMaterialCollection - to contain it if necessary. -*/ -void QDeclarativeEffect::setMaterial(QGLMaterial *value) -{ - d->ensureMaterial(); - if (d->materialIndex != -1) - d->palette->material(d->materialIndex)->disconnect(this); - int newIndex = -1; - if (value) - newIndex = d->palette->addMaterial(value); - if (newIndex != d->materialIndex) - { - d->materialIndex = newIndex; - emit effectChanged(); - // TODO: deleting old materials - if (value) - connect(value, SIGNAL(materialChanged()), this, SIGNAL(effectChanged())); - } -} - -/*! - \qmlproperty real Effect::progress - - Tracks how much of a remote resource has been downloaded, where 0.0 - is no progress, and 1.0 is completion. -*/ - -/*! - \internal - Enable the effect on for a given \a painter. -*/ -void QDeclarativeEffect::enableEffect(QGLPainter *painter) -{ - painter->setColor(d->color); - if (d->materialIndex != -1 && d->palette->material(d->materialIndex)) - { - painter->setFaceMaterial(QGL::FrontFaces, material()->front()); - painter->setFaceMaterial(QGL::BackFaces, material()->back()); - } else - painter->setFaceColor(QGL::AllFaces, d->color); - - QGLTexture2D *tex = 0; - if (material()) - tex = material()->texture(); - if (d->useLighting) { - if (tex && !tex->isNull()) { - if (d->decal) - painter->setStandardEffect(QGL::LitDecalTexture2D); - else - painter->setStandardEffect(QGL::LitModulateTexture2D); - tex->bind(); - } else { - painter->setStandardEffect(QGL::LitMaterial); - } - } else { - if (tex && !tex->isNull()) { - if (d->decal) - painter->setStandardEffect(QGL::FlatDecalTexture2D); - else - painter->setStandardEffect(QGL::FlatReplaceTexture2D); -// painter->glActiveTexture(GL_TEXTURE0); - tex->bind(); - } else { - painter->setStandardEffect(QGL::FlatColor); - } - } -} - -/*! - \internal - Disable the effect for a given \a painter. -*/ -void QDeclarativeEffect::disableEffect(QGLPainter *painter) -{ - painter->setStandardEffect(QGL::FlatColor); - painter->setColor(Qt::white); - painter->glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); -} - -/*! - \internal - Set a scenenode's material and effect properties to enact this effect. - - The desired functionality should mirror the Mesh::draw(QGLPainter*) - functionality as closely as possible. - - Subclasses can reimplement this function to set desired effects (e.g. user - effects); -*/ -void QDeclarativeEffect::applyTo(QGLSceneNode *node) -{ - d->ensureMaterial(); - - node->setPalette(d->palette); - node->setMaterialIndex(d->materialIndex); - - Q_ASSERT(node->material()); - - QGLTexture2D *tex = material()->texture(); - if (tex && !tex->isNull()) - node->material()->setTexture(tex); - - // Determine which standard effect to use - if (d->useLighting) { - if (tex && !tex->isNull()) { - if (d->decal) - node->setEffect(QGL::LitDecalTexture2D); - else - node->setEffect(QGL::LitModulateTexture2D); - } else { - node->setEffect(QGL::LitMaterial); - } - } else { - if (tex && !tex->isNull()) { - if (d->decal) - node->setEffect(QGL::FlatDecalTexture2D); - else - node->setEffect(QGL::FlatReplaceTexture2D); - } else { - node->setEffect(QGL::FlatColor); - } - } -} - -QGLTexture2D *QDeclarativeEffect::texture2D() -{ - if (!material()) - return 0; - return material()->texture(); -} - -/*! - Returns the progress of remote resource loading. - */ -qreal QDeclarativeEffect::progress() -{ - return d->progress; -} - -QT_END_NAMESPACE diff --git a/src/quick3d/qdeclarativeeffect.h b/src/quick3d/qdeclarativeeffect.h deleted file mode 100644 index d187952c..00000000 --- a/src/quick3d/qdeclarativeeffect.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEEFFECT_P_H -#define QDECLARATIVEEFFECT_P_H - -#include "qt3dquickglobal.h" - -#include <QtCore/qobject.h> -#include <QtCore/qurl.h> -#include <QtGui/qcolor.h> -#include <QtGui/qimage.h> -#include <QtDeclarative/qdeclarative.h> - -#include "qgltexture2d.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(QtQuick3D) - -class QDeclarativeEffectPrivate; -class QGLPainter; -class QGLMaterial; -class QGLSceneNode; - -class Q_QT3D_QUICK_EXPORT QDeclarativeEffect : public QObject -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY effectChanged) - Q_PROPERTY(bool useLighting READ useLighting WRITE setUseLighting NOTIFY effectChanged) - Q_PROPERTY(bool decal READ decal WRITE setDecal NOTIFY effectChanged) - Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY effectChanged) - Q_PROPERTY(QUrl texture READ texture WRITE setTexture NOTIFY effectChanged) - Q_PROPERTY(QImage textureImage READ textureImage WRITE setTextureImage NOTIFY effectChanged) - Q_PROPERTY(QGLMaterial *material READ material WRITE setMaterial NOTIFY effectChanged) - Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) -public: - QDeclarativeEffect(QObject *parent = 0); - ~QDeclarativeEffect(); - - virtual QColor color() const; - virtual void setColor(const QColor& value); - - virtual bool useLighting() const; - virtual void setUseLighting(bool value); - - virtual bool decal() const; - virtual void setDecal(bool value); - - virtual bool blending() const; - virtual void setBlending(bool value); - - virtual QUrl texture() const; - virtual void setTexture(const QUrl& value); - - virtual QImage textureImage() const; - virtual void setTextureImage(const QImage& value); - - virtual QGLMaterial *material() const; - virtual void setMaterial(QGLMaterial *value); - - virtual void enableEffect(QGLPainter *painter); - virtual void disableEffect(QGLPainter *painter); - virtual void applyTo(QGLSceneNode *node); - - virtual qreal progress(); - -Q_SIGNALS: - void effectChanged(); - void progressChanged(qreal progress); - -protected: - QGLTexture2D *texture2D(); - -private: - QDeclarativeEffectPrivate *d; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeEffect) - -QT_END_HEADER - -#endif diff --git a/src/quick3d/qdeclarativeitem3d.cpp b/src/quick3d/qdeclarativeitem3d.cpp deleted file mode 100644 index 068a6f95..00000000 --- a/src/quick3d/qdeclarativeitem3d.cpp +++ /dev/null @@ -1,1673 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativeitem3d.h" -#include "qdeclarativeviewport.h" -#include "qdeclarativemesh.h" -#include "qdeclarativeeffect.h" - -#include "qgllightparameters.h" -#include "qglabstractscene.h" -#include "qglscenenode.h" -#include "qglview.h" -#include "qgraphicstransform3d.h" - -#include <QtGui/qevent.h> -#include <QtDeclarative/qdeclarativecontext.h> - -/*! - \qmlclass Item3D QDeclarativeItem3D - \brief The Item3D item encapsulates 3D objects and contains all of the properties and methods needed for simple 3D operations. - part of a QML/3d script. - \since 4.8 - \ingroup qt3d::qml3d - - \section1 Simple 3D Object Definition - - The most basic use case for the Item3D class is the creation and display of a - single simple item in the 3D environment. - - Many such items within a 3D environment are defined as a single logical component - mesh which is treated as a stand-alone object for the purposes of rotation, - scaling, and user interaction via "picking". - - Such an object can easily be defined in QML using the following code: - - \code - Item3D { - id: teapot - mesh: Mesh { source: "teapot.bez" } - effect: Effect {} - cullFaces: "CullBackFaces" - } - \endcode - - This simple code will create a 3D item based on the \i teapot.bez mesh using - back-face culling. - - Notice that in this case the effect and mesh are defined within the body of - the item definition. Where there is little complexity, this method of - defining items simplifies the resultant code and makes modification of - the QML easier. - - \section1 Embedding Item3D Objects - - Consider the following: - - \code - Item3D { - id: cup - mesh: Mesh { source: "teacup.bez" } - effect: Effect {} - cullFaces: "CullBackFaces" - - Item3D { - id: saucer - mesh: Mesh { source: "saucer.bez" } - cullFaces: "CullBackFaces" - } - - position: Qt.vector3d(10, -10, -10) - } - \endcode - - This demonstrates the capability of embedding one Item3D within another. In - this case the \i saucer item is a child of the \i cup item. - - All transformations applied to the parent item are also applied to the child, - so in this case both the cup and saucer will be translated based on the - position vector defined in the cup item's definition. - - In this case any additional transformations applied to the child item will not - affect the parent, and are local only to that item (and to its children if any - exist). - - This allows a user to group together items logically so that transformations and - user interactions can be applied to groups of objects as if they were a whole. - - \section1 Using Sub-nodes of 3D Objects - - In more complex applications the user may wish to load a complex mesh - which is made up of a number of components or nodes which may be organised - into a tree like structure. In this case they may wish to interact with, - animate, or otherwise modify individual sub-nodes of a mesh. - - Item3D leverages the existing \bold {Qt Object Model} in order to allow QML/3d users - this type of control over their 3D items. - - Consider the following QML script: - - \code - Item3D { - id: helicoptor - mesh: helicoptorMesh - effect: Effect {} - cullFaces: "CullBackFaces" - - transform: [ - Rotation3D { - id: rotate1 - angle: 5 - axis: Qt.vector3d(1, 0, 0) - }, - Rotation3D { - id: rotate2 - angle: 5 - axis: Qt.vector3d(0, 1, 0) - }, - Rotation3D { - id: rotate3 - angle: 45 - axis: Qt.vector3d(0, 0, 1) - } - ] - - Item3D { - id: rotor - property bool spin: false - meshNode: "rotorBladesNode" - Item3D {meshNode: "rotorHubNode"} - - transform: [ - Rotation3D { - id: rotateBlades - angle: 0 - axis: Qt.vector3d(0, 0, 1) - } - ] - - onClicked: { rotor.spin=true } - - SequentialAnimation { - running: rotor.spin - NumberAnimation { - target: rotateBlades - property: "angle" - to: 360.0 - duration: 750 - easing.type:"OutQuad" - } - onCompleted: rotor.spin = false - } - } - } - - Mesh { - id: helicoptorMesh - source: "bellUH1.3ds" - } - \endcode - - Obviously this example is much more complex both in structure and behaviour. In - this case the mesh describes a \i .3ds file of a helicoptor, which is broken down - discrete sub-components (engine nacelles, rotor, rotor hub, etc), which the user - may wish to modify or animate individually. - - Each child item in this case does not have a mesh explicitly defined, but rather - inherits the mesh from the parent. However each child item does define a mesh node - which is part of the parent mesh. - - All transformations carried out on the parent item will also be applied to the child. - - Child items can, as shown here, have their own \i local transformations and user - interactions applied. These will be applied only to the node of the mesh which - is defined for that item. In cases where the mesh is defined heirarchically as a - tree of nodes, this transformation will therefore be applied to all items in that - tree which are children of the defined node. - - Likewise if the user explicitly declares a child item, such as has been done here with - the \i rotorHubNode, then the transformations will apply to this item as well (and - its children, and so on). - - It should be noted that no support is currently provided for skeleton animation or - kinematic control of items. This is left to the user to implement as required. - - \section1 Using QML Data Models With Item3D - - QDeclarativeItem3D supports standard \l - {http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#qml-data-models} - {QML Data Models} with a few caveats. - - QDeclarativeItem3D derives from QtDeclarativeItem, and interacts with - the \l{http://doc.qt.nokia.com/4.7/qml-component.html}{Component} element - normally. However, there is a delay between between removing an item from - a model and the cleaning up the corresponding Item3D, so it is recommended - that Item3D based delegates hide themselves when their index is - -1 as shown in the photoroom example: - - \snippet quick3d/photoroom/qml/photoroom.qml 1 - - However Item3D does not use the width or height properties, so most - positioners and views will not work. Use a - \l{http://doc.qt.nokia.com/4.7/qml-repeater.html}{Repeater} element to - generate Item3Ds from model data. For example: - - \snippet quick3d/photoroom/qml/photoroom.qml 2 - - Models can be used normally, so -\l{http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#listmodel}{ListModel}, -\l{http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#qstringlist}{QStringList} - etc. work just like they would with two dimensional Items. For example: - - \snippet quick3d/photoroom/qml/photoroom.qml 0 - - \sa{http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#qml-data-models}{QML Data Models} -*/ - - - -QT_BEGIN_NAMESPACE - -class QDeclarativeItem3DPrivate -{ -public: - QDeclarativeItem3DPrivate(QDeclarativeItem3D *_item) - : item(_item) - , viewport(0) - , position(0.0f, 0.0f, 0.0f) - , pivot(0.0f,0.0f,0.0f) - , usePivot(false) - , scale(1.0f) - , mesh(0) - , effect(0) - , requireBlockingEffectsCheck(false) - , light(0) - , objectPickId(-1) - , cullFaces(QDeclarativeItem3D::CullDisabled) - , sortChildren(QDeclarativeItem3D::DefaultSorting) - , inheritEvents(false) - , isEnabled(true) - , isInitialized(false) - , mainBranchId(0) - , componentComplete(false) - { - } - ~QDeclarativeItem3DPrivate(); - - QDeclarativeItem3D *item; - QDeclarativeViewport *viewport; - QVector3D position; - QVector3D pivot; - bool usePivot; - qreal scale; - QDeclarativeMesh *mesh; - QDeclarativeEffect *effect; - bool requireBlockingEffectsCheck; - QGLLightParameters *light; - int objectPickId; - QDeclarativeItem3D::CullFaces cullFaces; - QDeclarativeItem3D::SortMode sortChildren; - - bool inheritEvents; - bool isEnabled; - bool isInitialized; - int mainBranchId; - QString meshNode; - - // data property - static void data_append(QDeclarativeListProperty<QObject> *, QObject *); - - // resources property - static QObject *resources_at(QDeclarativeListProperty<QObject> *, int); - static void resources_append(QDeclarativeListProperty<QObject> *, QObject *); - static int resources_count(QDeclarativeListProperty<QObject> *); - - // transform property - static int transform_count(QDeclarativeListProperty<QGraphicsTransform3D> *list); - static void transform_append(QDeclarativeListProperty<QGraphicsTransform3D> *list, QGraphicsTransform3D *); - static QGraphicsTransform3D *transform_at(QDeclarativeListProperty<QGraphicsTransform3D> *list, int); - static void transform_clear(QDeclarativeListProperty<QGraphicsTransform3D> *list); - QList<QGraphicsTransform3D *> transforms; - - - // pretransform property - static int pretransform_count(QDeclarativeListProperty<QGraphicsTransform3D> *list); - static void pretransform_append(QDeclarativeListProperty<QGraphicsTransform3D> *list, QGraphicsTransform3D *); - static QGraphicsTransform3D *pretransform_at(QDeclarativeListProperty<QGraphicsTransform3D> *list, int); - static void pretransform_clear(QDeclarativeListProperty<QGraphicsTransform3D> *list); - QList<QGraphicsTransform3D *> pretransforms; - - // transform convenience functions - QMatrix4x4 localTransforms() const; - QMatrix4x4 localToWorldMatrix() const; - QMatrix4x4 worldToLocalMatrix() const; - bool componentComplete; -}; - -QDeclarativeItem3DPrivate::~QDeclarativeItem3DPrivate() -{ -} - -int QDeclarativeItem3DPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform3D> *list) -{ - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - if (object) { - return object->d->transforms.count(); - } else { - qWarning()<<"Warning: could not find Item3D to query for transformation count."; - return 0; - } -} - -void QDeclarativeItem3DPrivate::transform_append(QDeclarativeListProperty<QGraphicsTransform3D> *list, QGraphicsTransform3D *item) -{ - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - QList<QGraphicsTransform3D *> *ptrans; - if (object) - { - ptrans = &object->d->transforms; - - //We now need to connect the underlying transform so that any change will update the graphical item. - if (!ptrans->contains(item)) { - ptrans->append(item); - QObject::connect(item, SIGNAL(transformChanged()), - object, SLOT(update())); - } - } - else - qWarning()<<"Warning: could not find Item3D to add transformation to."; -} - -QGraphicsTransform3D *QDeclarativeItem3DPrivate::transform_at(QDeclarativeListProperty<QGraphicsTransform3D> *list, int idx) -{ - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - if (object) { - return object->d->transforms.at(idx); - } else { - qWarning()<<"Warning: could not find Item3D to query for transformations"; - return 0; - } - return 0; -} - -void QDeclarativeItem3DPrivate::transform_clear(QDeclarativeListProperty<QGraphicsTransform3D> *list) -{ - - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - if (object) { - object->d->transforms.clear(); - object->update(); - } - else - qWarning()<<"Warning: could not find Item3D to clear of transformations"; -} - -int QDeclarativeItem3DPrivate::pretransform_count(QDeclarativeListProperty<QGraphicsTransform3D> *list) -{ - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - if (object) { - return object->d->pretransforms.count(); - } else { - qWarning()<<"Warning: could not find Item3D to query for transformation count."; - return 0; - } -} - -void QDeclarativeItem3DPrivate::pretransform_append(QDeclarativeListProperty<QGraphicsTransform3D> *list, QGraphicsTransform3D *item) -{ - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - QList<QGraphicsTransform3D *> *ptrans; - if (object) - { - ptrans = &object->d->pretransforms; - - //We now need to connect the underlying transform so that any change will update the graphical item. - if (!ptrans->contains(item)) { - ptrans->append(item); - QObject::connect(item, SIGNAL(transformChanged()), - object, SLOT(update())); - } - } - else - qWarning()<<"Warning: could not find Item3D to add transformation to."; -} - -QGraphicsTransform3D *QDeclarativeItem3DPrivate::pretransform_at(QDeclarativeListProperty<QGraphicsTransform3D> *list, int idx) -{ - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - if (object) { - return object->d->pretransforms.at(idx); - } else { - qWarning()<<"Warning: could not find Item3D to query for transformations"; - return 0; - } - return 0; -} - -void QDeclarativeItem3DPrivate::pretransform_clear(QDeclarativeListProperty<QGraphicsTransform3D> *list) -{ - - QDeclarativeItem3D *object = qobject_cast<QDeclarativeItem3D *>(list->object); - if (object) { - object->d->pretransforms.clear(); - object->update(); - } - else - qWarning()<<"Warning: could not find Item3D to clear of transformations"; -} - - - -void QDeclarativeItem3DPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o) -{ - // This function is called by the QML runtime to assign children to - // an item3d. The object 'o' is the new child, and prop->object is the - // Item3d that is to be the parent. - - // Either way we're going to call something like setParent(prop->object) - // we're just determining whether to use the QQuickItem or QObject version. - - // The primary purpose of this function is to divide new children into - // renderable qml Items and non-renderable QObject derived resources. - // We want to accept all Items, and and simply ignore non-3d items - // during drawing. - - // It is important that we imitate this behaviour of non-3d QQuickItems so - // view items will assign dynamically created objects to the Item3d and - // make them available for drawing. - - QQuickItem *i = qobject_cast<QQuickItem *>(o); - if (i) - i->setParentItem(static_cast<QDeclarativeItem3D *>(prop->object)); - else - o->setParent(static_cast<QDeclarativeItem3D *>(prop->object)); -} - - -QObject *QDeclarativeItem3DPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index) -{ - QObjectList children = prop->object->children(); - if (index < children.count()) - return children.at(index); - else - return 0; -} - -void QDeclarativeItem3DPrivate::resources_append(QDeclarativeListProperty<QObject> *prop, QObject *o) -{ - o->setParent(prop->object); -} - -int QDeclarativeItem3DPrivate::resources_count(QDeclarativeListProperty<QObject> *prop) -{ - return prop->object->children().count(); -} - -/*! - \internal - Applies position, scale and rotation transforms for this item3d to matrix - \a m -*/ -QMatrix4x4 QDeclarativeItem3DPrivate::localTransforms() const -{ - QMatrix4x4 m; - m.translate(position); - int transformCount = transforms.count(); - if (transformCount>0) { - // The transformations are applied in reverse order of their - // lexical appearance in the QML file. - for (int index = transformCount - 1; index >= 0; --index) { - transforms.at(index)->applyTo(&m); - } - } - if (scale != 1.0f) - m.scale(scale); - transformCount = pretransforms.count(); - if (transformCount>0) { - // Pre-transforms for orienting the model. - for (int index = transformCount - 1; index >= 0; --index) { - pretransforms.at(index)->applyTo(&m); - } - } - return m; -} - - -/*! - \internal -*/ -QDeclarativeItem3D::QDeclarativeItem3D(QObject *parent) - : QQuickItem(0) -{ - d = new QDeclarativeItem3DPrivate(this); - - QDeclarativeItem3D *itemParent = qobject_cast<QDeclarativeItem3D *>(parent); - if (itemParent) { - setParentItem(itemParent); - } else { - setParent(parent); - } - - // TODO: Handle QDeclarativeItem3D case -} - -/*! - \internal -*/ -QDeclarativeItem3D::~QDeclarativeItem3D() -{ - delete d; -} - - - -/*! - \qmlproperty vector3D Item3D::position - - The position in 3D space of this item. The default value for this - property is (0, 0, 0). - - \sa x, y, z -*/ - -QVector3D QDeclarativeItem3D::position() const -{ - return d->position; -} - -void QDeclarativeItem3D::setPosition(const QVector3D& value) -{ - d->position = value; - emit positionChanged(); - update(); -} - -/*! - \qmlproperty real Item3D::x - - The x position of this item in 3D space. The default value for this - property is 0. - - \sa position, y, z -*/ - -qreal QDeclarativeItem3D::x() const -{ - return d->position.x(); -} - -void QDeclarativeItem3D::setX(qreal value) -{ - d->position.setX(value); - emit positionChanged(); - update(); -} - -/*! - \qmlproperty real Item3D::y - - The y position of this item in 3D space. The default value for this - property is 0. - - \sa position, x, z -*/ - -qreal QDeclarativeItem3D::y() const -{ - return d->position.y(); -} - -void QDeclarativeItem3D::setY(qreal value) -{ - d->position.setY(value); - emit positionChanged(); - update(); -} - -/*! - \qmlproperty real Item3D::z - - The z position of this item in 3D space. The default value for - this property is 0. - - \sa position, x, y -*/ - -qreal QDeclarativeItem3D::z() const -{ - return d->position.z(); -} - -void QDeclarativeItem3D::setZ(qreal value) -{ - d->position.setZ(value); - emit positionChanged(); - update(); -} - -/*! - \qmlproperty real Item3D::scale - - The scaling factor to apply to the item after the transformations - from the Item3D::transform property. The default value for this - property is 1. - - \sa transform -*/ - -qreal QDeclarativeItem3D::scale() const -{ - return d->scale; -} - -void QDeclarativeItem3D::setScale(qreal value) -{ - d->scale = value; - emit scaleChanged(); - update(); -} - -/*! - \qmlproperty list<Transform> Item3D::transform - - Generally objects in 3D space will have undergone some number - of 3D transformation prior to display. Examples of such transformations - include rotations about the x, y, and z axes, translation, and so on. - - Each Item3D maintains a list of transforms to apply to it through this - property. In scripting terms a transform can be applied as follows: - - \code - Item3D { - id: teapot - mesh: Mesh { source: "teapot.bez" } - transform: [ - Rotation3D { - id: teapot_rotate1 - angle: 0 - axis: Qt.vector3d(0, 1, 0) - }, - Rotation3D { - id: teapot_rotate2 - angle: 0 - axis: Qt.vector3d(0, 0, 1) - } - ] - } - \endcode - - In this example we have two transformations in our list - a rotation around - the y axis (\c {teapot_rotate1}), and a rotation about the z axis (\c {teapot_rotate2}). - - These transformations can be accessed via standard QML scripting methods to achieve - animations and other effects. - - By default this list of transformations is empty. - - \sa Rotation3D, Scale3D, Translation3D, scale, position, pretransform -*/ - - -QDeclarativeListProperty<QGraphicsTransform3D> QDeclarativeItem3D::transform() -{ - return QDeclarativeListProperty<QGraphicsTransform3D>(this, 0, d->transform_append, d->transform_count, - d->transform_at, d->transform_clear); -} - -/*! - \qmlproperty list<Transform> Item3D::pretransform - - The transformations to apply before all others. - - When a model is loaded from an external source such as a 3D - modeling package, it is usually in an unconventional orientation - and position. The first step is to rotate, scale, and translate - it to make it suitable for use as a QML object. - - The purpose of the \c pretransform property is to perform such - "model correction" transformations before \c scale, \c transform, - and \c position are applied to place the model in its final - orientation and position in the QML application. - - By default this list of transformations is empty. - - \sa transform, scale, position -*/ - -QDeclarativeListProperty<QGraphicsTransform3D> QDeclarativeItem3D::pretransform() -{ - return QDeclarativeListProperty<QGraphicsTransform3D>(this, 0, d->pretransform_append, d->pretransform_count, - d->pretransform_at, d->pretransform_clear); -} - -/*! - \qmlproperty bool Item3D::inheritEvents - - Users are able to interact with 3d items in a scene through (for example) the - use of the mouse. These, and other, Qt events can be captured by an \l Item3D using the - same underlying QObject architecture shared by all of Qt. - - Often a user will only want an item to capture mouse events for itself, leaving - child items to handle their mouse events locally. Under many circumstances, however, it - is necessary for a parent object to collect all mouse events for itself and its child - items. Usually this inheritance of events is only defined at initialisation for an \l Item3D - - The inheritEvents property, however, is a simple boolean property which provides a mechanism - for both initialisation time and programmatic modification of this. - - Setting the property to true connects the signals for all child items to the appropriate - signals for the item itself. Conversely setting the property to false disconnects the - events. - - The default value for this property is false. -*/ -bool QDeclarativeItem3D::inheritEvents() const -{ - return d->inheritEvents; -} - -void QDeclarativeItem3D::setInheritEvents(bool inherit) -{ - d->inheritEvents = inherit; - - //Generally we would only want to - if (inherit) - { - for (int index = 0; index < children().size(); ++index) { - QDeclarativeItem3D *subItem = qobject_cast<QDeclarativeItem3D *>(children().at(index)); - if (subItem) - { - // Proxy the mouse event signals to the parent so that - // the parent can trap the signal for a group of children. - QObject::connect(subItem, SIGNAL(clicked()), this, SIGNAL(clicked())); - QObject::connect(subItem, SIGNAL(doubleClicked()), this, SIGNAL(doubleClicked())); - QObject::connect(subItem, SIGNAL(pressed()), this, SIGNAL(pressed())); - QObject::connect(subItem, SIGNAL(released()), this, SIGNAL(released())); - QObject::connect(subItem, SIGNAL(hoverEnter()), this, SIGNAL(hoverEnter())); - QObject::connect(subItem, SIGNAL(hoverLeave()), this, SIGNAL(hoverLeave())); - } - } - } - else - { - for (int index = 0; index < children().size(); ++index) { - QDeclarativeItem3D *subItem = qobject_cast<QDeclarativeItem3D *>(children().at(index)); - if (subItem) - { - // Proxy the mouse event signals to the parent so that - // the parent can trap the signal for a group of children. - QObject::disconnect(subItem, SIGNAL(clicked()), this, SIGNAL(clicked())); - QObject::disconnect(subItem, SIGNAL(doubleClicked()), this, SIGNAL(doubleClicked())); - QObject::disconnect(subItem, SIGNAL(pressed()), this, SIGNAL(pressed())); - QObject::disconnect(subItem, SIGNAL(released()), this, SIGNAL(released())); - QObject::disconnect(subItem, SIGNAL(hoverEnter()), this, SIGNAL(hoverEnter())); - QObject::disconnect(subItem, SIGNAL(hoverLeave()), this, SIGNAL(hoverLeave())); - } - } - } -} - -/*! - \qmlproperty Mesh Item3D::mesh - - Objects in most 3D environments are almost invariably defined as meshes - sets of - vertices which when linked as polygons form a recognisable 3D object. QtQuick3D currently - supports a number of these \i {scene formats}, including \i {.obj} file, bezier patches - \i {(.bez)}, and \i {.3ds} files. - - These meshes are abstracted into the \l Mesh class, which is defined for - an \l Item3D through this property. - - The default value for this property is null, so a mesh must be defined in - order for the item to be displayed - - \sa effect -*/ - -QDeclarativeMesh *QDeclarativeItem3D::mesh() const -{ - return d->mesh; -} - -void QDeclarativeItem3D::setMesh(QDeclarativeMesh *value) -{ - if (d->mesh != value) - { - if (d->mesh) { - if (!d->mesh->deref()) - delete d->mesh; - } - - d->mesh = value; - //always start off pointing to the default scene mesh object. - d->mainBranchId = 0; - - if (value) { - d->mesh->ref(); - connect(value, SIGNAL(dataChanged()), this, SIGNAL(meshChanged())); - connect(value, SIGNAL(dataChanged()), this, SLOT(update())); - d->requireBlockingEffectsCheck = true; - } - - emit meshChanged(); - - update(); - } -} - -/*! - \qmlproperty Effect Item3D::effect - - QML 3D items support the use of effects for modifying the display - of items - texture effects, fog effects, material effects, and so on. - - The exact effects correlated with an item are set using this property. - - The default value for this propertly is null, and so an effect - even an - empty one - must be defined if the mesh does not contain its own effects. - - \sa Effect, mesh -*/ -QDeclarativeEffect *QDeclarativeItem3D::effect() const -{ - return d->effect; -} - -void QDeclarativeItem3D::setEffect(QDeclarativeEffect *value) -{ - if (d->effect == value) - return; - if (d->effect) - disconnect(d->effect, SIGNAL(effectChanged()), this, SLOT(handleEffectChanged())); - d->effect = value; - if (d->effect) - { - connect(d->effect, SIGNAL(effectChanged()), this, SLOT(handleEffectChanged())); - d->requireBlockingEffectsCheck = true; - } - emit effectChanged(); - update(); -} - -/*! - \qmlproperty Light Item3D::light - - This property defines an item-specific light that will be used - intead of Viewport::light for rendering this item and its children - if the value is not null. - - \sa Viewport::light -*/ - -QGLLightParameters *QDeclarativeItem3D::light() const -{ - return d->light; -} - -void QDeclarativeItem3D::setLight(QGLLightParameters *value) -{ - if (d->light != value) { - if (d->light) { - disconnect(d->light, SIGNAL(lightChanged()), - this, SLOT(update())); - } - d->light = value; - if (d->light) { - connect(d->light, SIGNAL(lightChanged()), - this, SLOT(update())); - } - emit lightChanged(); - update(); - } -} - -/*! - \qmlproperty list<Item3D> Item3D::children - \qmlproperty list<Object> Item3D::resources - - The children property contains a list of all QQuickItem derived - child items for this item. This provides logical grouping of items in a - scene. Transformations that are applied to this item will also affect - child items. Note that children that are not derived from - QDeclarativeItem3D will not be rendered at draw time, but will interact - normally otherwise (e.g. parenting, signal passing etc). Use a - qobject_cast if you need to check whether a child is an Item3D. - - The resources property holds all other children that do not - directly inherit from QQuickItem, such as effects, meshes, and - other supporting objects. - - Normally it isn't necessary to assign to the children or resources - properties directly as the QML syntax will take care of the - assignment depending upon the object's type. - - \sa transform -*/ - -QDeclarativeListProperty<QObject> QDeclarativeItem3D::resources() -{ - return QDeclarativeListProperty<QObject>(this, 0, QDeclarativeItem3DPrivate::resources_append, - QDeclarativeItem3DPrivate::resources_count, - QDeclarativeItem3DPrivate::resources_at); -} - - - -/*! - \qmlproperty list<Object> Item3D::data - - This property exists to allow future expansion of the Item3D class to - include additional data and resources. Currently there is no underlying - implementation for this. -*/ -QDeclarativeListProperty<QObject> QDeclarativeItem3D::data() -{ - return QDeclarativeListProperty<QObject>(this, 0, QDeclarativeItem3DPrivate::data_append); -} - -/*! - \qmlproperty enumeration Item3D::cullFaces - - This property defines the culling method to be use on fragments - within the item's mesh. Culling of an item in 3D space can be - carried out in a number of ways: - - \list - \o CullDisabled Do not use culling. This is the default value. - \o CullFrontFaces Cull the front faces of the object. - \o CullBackFaces Cull the back faces of the object. - \o CullAllFaces Cull all faces of the object. - \o CullClockwise Cull faces based on clockwise winding of vertices. - \endlist -*/ -QDeclarativeItem3D::CullFaces QDeclarativeItem3D::cullFaces() const -{ - return d->cullFaces; -} - -void QDeclarativeItem3D::setCullFaces(QDeclarativeItem3D::CullFaces value) -{ - if (d->cullFaces != value) { - d->cullFaces = value; - emit meshChanged(); - } -} - -/*! - \qmlproperty enumeration Item3D::sortChildren - - This property defines the sorting mode to apply to child \l Item3D - elements when they are drawn. - - \list - \o DefaultSorting No explicit sorting of the children - draw them in - whatever order is convenient for the system. The system may apply - its own sorting, grouping similar materials to improve performance. - This is the default. - \o BackToFront Sort the children to draw them in back-to-front - order of their \l position, overriding any system-supplied sorting. - BackToFront is useful when the children are partially transparent - and must be drawn in back-to-front order for correct rendering. - \endlist -*/ -QDeclarativeItem3D::SortMode QDeclarativeItem3D::sortChildren() const -{ - return d->sortChildren; -} - -void QDeclarativeItem3D::setSortChildren(QDeclarativeItem3D::SortMode mode) -{ - if (d->sortChildren != mode) { - d->sortChildren = mode; - emit sortChildrenChanged(); - } -} - -/*! - \internal - Sets the lighting conditions for this item on the \a painter. The parameters \a currentLight and \a currentLightTransform - are used to store the current lighting parameters and transforms so that they can be reset on cleanup. - - After drawing has finished the drawLightingCleanup() function should be called to restore previous settings. - - \sa drawLightingCleanup(), draw() -*/ -void QDeclarativeItem3D::drawLightingSetup(QGLPainter *painter, const QGLLightParameters *currentLight, QMatrix4x4 ¤tLightTransform) -{ - //Lighting - Q_UNUSED(currentLight) - if (d->light) { - currentLight = painter->mainLight(); - currentLightTransform = painter->mainLightTransform(); - painter->setMainLight(d->light); - } -} - -/*! - \internal - Restores the lighting conditions for \a painter to the \a currentLight and \a currentLightTransform. These values are usually - provided by an earlier call to drawLightingSetup(). - - \sa drawLightingSetup(), draw() -*/ -void QDeclarativeItem3D::drawLightingCleanup(QGLPainter *painter, const QGLLightParameters *currentLight, QMatrix4x4 ¤tLightTransform) -{ - if (d->light) - painter->setMainLight(currentLight, currentLightTransform); -} - -/*! - \internal - Sets the effects for this item on the \a painter. The parameters \a viewportBlend and \a effectBlend - are used to store the current blending parameters so that they can be reset on cleanup. - - After drawing has finished the drawEffectCleanup() function should be called to restore previous settings. - - \sa drawLightingCleanup(), draw() -*/ -void QDeclarativeItem3D::drawEffectSetup(QGLPainter *painter, bool &viewportBlend, bool &effectBlend) -{ - // Blending change for the effect. - viewportBlend = d->viewport ? d->viewport->blending() : false; - effectBlend = d->effect ? d->effect->blending() : viewportBlend; - if (viewportBlend != effectBlend) { - if (effectBlend) - glEnable(GL_BLEND); - else - glDisable(GL_BLEND); - } - - //Effects - if (d->effect) - d->effect->enableEffect(painter); -} - -/*! - \internal - Restores the blending settings for \a painter to the \a viewportBlend and \a effectBlend. These values are usually - provided by an earlier call to drawEffectSetup(). - - \sa drawEffectSetup(), draw() -*/ -void QDeclarativeItem3D::drawEffectCleanup(QGLPainter *painter, bool &viewportBlend, bool &effectBlend) -{ - if (d->effect) - d->effect->disableEffect(painter); - if (viewportBlend != effectBlend) { - if (effectBlend) - glDisable(GL_BLEND); - else - glEnable(GL_BLEND); - } -} - -/*! - \internal - Sets the culling settings for this item. - - After drawing has finished the drawCullCleanup() function should be called to restore previous settings. - - \sa drawCullCleanup(), draw() -*/ -void QDeclarativeItem3D::drawCullSetup() -{ - //Culling - if ((d->cullFaces & ~CullClockwise) == CullDisabled) { - glDisable(GL_CULL_FACE); - } else if (d->cullFaces & CullClockwise) { - glFrontFace(GL_CW); - glCullFace(GLenum(d->cullFaces & ~CullClockwise)); - glEnable(GL_CULL_FACE); - } else { - glFrontFace(GL_CCW); - glCullFace(GLenum(d->cullFaces)); - glEnable(GL_CULL_FACE); - } -} - -/*! - \internal - Restores the culling settings after an earlier call to drawCullSetup(). - - \sa drawCullSetup(), draw() -*/ -void QDeclarativeItem3D::drawCullCleanup() -{ - if (d->cullFaces != CullDisabled) - glDisable(GL_CULL_FACE); -} - -/*! - \internal - Applies the transforms for this item on the \a painter. - - After drawing has finished the drawTransformCleanup() function should be called to restore previous settings. - - \sa drawTransformCleanup(), draw() -*/ -void QDeclarativeItem3D::drawTransformSetup(QGLPainter *painter) -{ - //Local and Global transforms - painter->modelViewMatrix().push(); - painter->modelViewMatrix() *= d->localTransforms(); -} - -/*! - \internal - Restores the previous model-view matrix settings for \a painter after an earlier call to drawTransformSetup(). - - \sa drawTransformSetup(), draw() -*/ -void QDeclarativeItem3D::drawTransformCleanup(QGLPainter *painter) -{ - //Unset parameters for transforms, effects etc. - painter->modelViewMatrix().pop(); -} - -/*! - \internal - Iterate through all of the child items for the current item and call their drawing functions. Children will - be drawn in the order specified unless specified by sortChildren(), in which case they will be drawn in the - order specified (usually this will be back-to-front, to allow for transparency of objects). - - \sa sortMode(), draw() -*/ -void QDeclarativeItem3D::drawChildren(QGLPainter *painter) -{ - // Find all 3d children for drawing - QList<QDeclarativeItem3D *> list;; - foreach (QObject* o, children()) - { - if (QDeclarativeItem3D *item3d = qobject_cast<QDeclarativeItem3D*>(o)) - { - list.append(item3d); - } - } - - if (d->sortChildren == QDeclarativeItem3D::BackToFront) { - // Collect up the transformed z positions of all children. - QList<qreal> zlist; - QMatrix4x4 mv = painter->modelViewMatrix(); - for (int index = 0; index < list.size(); ++index) { - QVector3D position = list.at(index)->position(); - zlist.append(mv.map(position).z()); - } - - // Sort the item list (Caution: really dumb sort algorithm). - for (int i = 0; i < list.size() - 1; ++i) { - for (int j = i + 1; j < list.size(); ++j) { - if (zlist.at(i) > zlist.at(j)) { - qSwap(list[i], list[j]); - qSwap(zlist[i], zlist[j]); - } - } - } - } - for (int index = 0; index < list.size(); ++index) - list.at(index)->draw(painter); -} - -/*! - \internal - Performs the actual drawing of the Item3D using \a painter. - - If the item is set to object picking mode this includes all of the infrastructure needed - to support picking of objects. - - The basic premise of the draw function should be familiar to users of OpenGL or similar - graphics libraries. Essentially it is a stepwise progress through the following stages: - - \list - \i 1. Iterate through the child objects of the item and set all lighting parameters found. - \i 2. Set up culling mode in the painter. - \i 3. Set effects if they exist. - \i 4. Set all local model view transformations for this item. - \i 5. Draw this item. - \i 6. Iterate through the child objects of the item and draw all child items. - \i 7. Unset the appropriate parameters and states. - \endlist - - - - \sa drawItem(), drawLightingSetup(), drawCullSetup(), drawEffectSetup(), drawChildren(), drawTransformSetup() -*/ -void QDeclarativeItem3D::draw(QGLPainter *painter) -{ - // Bail out if this item and its children have been disabled. - if (!d->isEnabled) - return; - if (!d->isInitialized) - initialize(painter); - - //Setup picking - int prevId = painter->objectPickId(); - painter->setObjectPickId(d->objectPickId); - - //Setup effect (lighting, culling, effects etc) - const QGLLightParameters *currentLight = 0; - QMatrix4x4 currentLightTransform; - drawLightingSetup(painter, currentLight, currentLightTransform); - bool viewportBlend, effectBlend; - drawEffectSetup(painter, viewportBlend, effectBlend); - drawCullSetup(); - - //Local and Global transforms - drawTransformSetup(painter); - - //Drawing - drawItem(painter); - drawChildren(painter); - - //Cleanup - drawTransformCleanup(painter); - drawLightingCleanup(painter, currentLight, currentLightTransform); - drawEffectCleanup(painter, viewportBlend, effectBlend); - drawCullCleanup(); - - //Reset pick id. - painter->setObjectPickId(prevId); -} - -/*! - \internal -*/ -void QDeclarativeViewport::setItemViewport(QDeclarativeItem3D *item) -{ - item->d->viewport = this; -} - -/*! - \internal - The process of initialising an /l Object3d is a critical step, particularly in - complex scenes. This function initialises the item in \a viewport, and using \a painter. - - During the initialisation process objects are registered as being \i pickable (ie. able - to be clicked on with the mouse. - - Additionally, in the case of \l Item3D objects which refer to sub-nodes of a mesh, this - function performs all of the splitting of meshes into sub-branches ready for local - control by the item. -*/ -void QDeclarativeItem3D::initialize(QGLPainter *painter) -{ - if (d->isInitialized) return; - - if (!d->viewport) - { - if (QDeclarativeItem3D* parentItem = - qobject_cast<QDeclarativeItem3D*>(parent())) - { - d->viewport = parentItem->d->viewport; - Q_ASSERT(d->viewport); - } - } - - d->objectPickId = d->viewport->registerPickableObject(this); - - for (int index = 0; index < children().size(); ++index) { - QDeclarativeItem3D *item = qobject_cast<QDeclarativeItem3D *>(children().at(index)); - if (item) { - //Event inheritance is generally only declared at initialization, but can also be done at runtime - //if the user wishes (though not recommended). - if (inheritEvents()) { - // Proxy the mouse event signals to the parent so that - // the parent can trap the signal for its children. - QObject::connect(item, SIGNAL(clicked()), this, SIGNAL(clicked())); - QObject::connect(item, SIGNAL(doubleClicked()), this, SIGNAL(doubleClicked())); - QObject::connect(item, SIGNAL(pressed()), this, SIGNAL(pressed())); - QObject::connect(item, SIGNAL(released()), this, SIGNAL(released())); - QObject::connect(item, SIGNAL(hoverEnter()), this, SIGNAL(hoverEnter())); - QObject::connect(item, SIGNAL(hoverLeave()), this, SIGNAL(hoverLeave())); - } - //if the item has no mesh of its own and no meshnode is declared we give it the mesh from the current item. - if (!item->mesh() && !item->meshNode().isEmpty()) { - item->setMesh(mesh()); - } - - d->viewport->setItemViewport(item); - item->initialize(painter); - } - } - d->isInitialized = true; -} - -/*! - Returns true if the initialize() has been called, returns false otherwise. - - \sa initialize() -*/ -bool QDeclarativeItem3D::isInitialized() const -{ - return d->isInitialized; -} - -void QDeclarativeItem3D::componentComplete() -{ - QQuickItem::componentComplete(); - d->componentComplete = true; - - // Now that we have all the mesh and subnode information we need, it's time to setup the mesh scene objects. - if (mesh() && !meshNode().isEmpty()) { - int branchNumber = mesh()->createSceneBranch(meshNode()); - if (branchNumber>=0) { - d->mainBranchId = branchNumber; - } - else { - qWarning()<< "3D item initialization failed: unable to find the specified mesh-node. Defaulting to default node."; - d->mainBranchId = 0; - } - } - - QDeclarativeItem3D *parentItem3D = qobject_cast<QDeclarativeItem3D*>(parentItem()); - if (!parentItem3D) - { - if (!d->viewport) - { - QDeclarativeContext *ctx = QDeclarativeEngine::contextForObject(this); - QDeclarativeEngine *engine = ctx->engine(); - QDeclarativeComponent vp(engine); - vp.setData(QByteArray( - "import QtQuick 2.0\n" - "import Qt3D 1.0\n" - "Viewport{ objectName: \"vp\" }\n"), QUrl()); - QObject *implicitViewport = vp.create(); - QQuickItem *parentViewport = qobject_cast<QQuickItem*>(implicitViewport); - parentViewport->setWidth(width()); - parentViewport->setHeight(height()); - Q_ASSERT(parentViewport); - Q_ASSERT(parentViewport->objectName() == QLatin1String("vp")); - QQuickItem *prevParent = parentItem(); - parentViewport->setParentItem(prevParent); - setParent(parentViewport); - setParentItem(parentViewport); - } - } - update(); -} - -/*! - \internal - The \c drawItem function performs the actual drawing of the mesh branch which corresponds - to the section of the mesh being drawn by the \l Item3D to a specific \a painter. -*/ -void QDeclarativeItem3D::drawItem(QGLPainter *painter) -{ - if (d->mesh) - { - d->mesh->draw(painter, d->mainBranchId); - } -} - -/*! - \relates QDeclarativeItem3D - Print a description of \a item to the console. - - If \a detailed is true (which it is by default) then all the properties - of each node are printed. - - If \a detailed is false, then just one line is printed with the name and - some identifying information including a unique id for the node. - - The \a indent argument is used internally. -*/ -void qDumpItem(QDeclarativeItem3D *item, bool detailed, int indent) -{ - if (item) - { - QDeclarativeMesh *mesh = item->mesh(); - QString ind; - ind.fill(QLatin1Char(' '), indent * 4); - if (mesh) - { - QGLSceneNode *node = mesh->getSceneObject(); - if (node) - qDumpScene(node, detailed, indent + 1); - else - qDebug("%sMesh %p - %s (no node)", qPrintable(ind), mesh, qPrintable(mesh->objectName())); - } - else - { - qDebug("%sItem %p - %s (no mesh)", qPrintable(ind), item, qPrintable(item->objectName())); - } - QObjectList kids = item->children(); - for (int i = 0; i < kids.size(); ++i) - { - QDeclarativeItem3D *it = qobject_cast<QDeclarativeItem3D*>(kids.at(i)); - qDumpItem(it, detailed, indent + 1); - } - } -} - -/*! - Calculates and returns a matrix that transforms local coordinates into - world coordinates (i.e. coordinates untransformed by any item3d's - transforms). -*/ -QMatrix4x4 QDeclarativeItem3DPrivate::localToWorldMatrix() const -{ - QMatrix4x4 result; - - result = localTransforms() * result; - QDeclarativeItem3D *anscestor = qobject_cast<QDeclarativeItem3D *>(item->parent()); - while (anscestor) - { - result = anscestor->d->localTransforms() * result; - anscestor = qobject_cast<QDeclarativeItem3D *>(anscestor->parent()); - } - return result; -} - -/*! - Calculates and returns a matrix that transforms world coordinates into - coordinates relative to this Item3D. -*/ -QMatrix4x4 QDeclarativeItem3DPrivate::worldToLocalMatrix() const -{ - bool inversionSuccessful; - QMatrix4x4 result = localToWorldMatrix().inverted(&inversionSuccessful); - if (inversionSuccessful) - return result; - qWarning() << "QDeclarativeItem3D - matrix inversion failed trying to generate worldToLocal Matrix"; - return QMatrix4x4(); -} - -/*! - Returns the position of a local \a point in world space (i.e. not - transformed by this item, it's parents, the camera etc). -*/ -QVector3D QDeclarativeItem3D::localToWorld(const QVector3D &point) const -{ - return d->localToWorldMatrix() * point; -} - -/*! - Returns the position of a point in world space in local coordinates. -*/ -QVector3D QDeclarativeItem3D::worldToLocal(const QVector3D &point) const -{ - return d->worldToLocalMatrix() * point; -} - -/*! - \internal - This function handles the standard mouse events for the item as contained in \a e. - - Returns the boolean value of the regular QObject::event() function.oo -*/ - -bool QDeclarativeItem3D::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) { - emit hoverEnter(); - } else if (e->type() == QEvent::Leave) { - emit hoverLeave(); - } - return QObject::event(e); -} - -void QDeclarativeItem3D::handleEffectChanged() -{ - d->requireBlockingEffectsCheck = true; - update(); -} - -/*! - \qmlproperty string Item3D::meshNode - - This property is a simple string which refers to the node in the \l Mesh object which - is associated with this \l Item3D. - - \sa mesh -*/ -QString QDeclarativeItem3D::meshNode() const -{ - return d->meshNode; -} - -void QDeclarativeItem3D::setMeshNode(const QString &node) -{ - //the actual instantiation of the node as the mesh itself is undertaken in the initialize function. - d->meshNode = node; -} - -/*! - \internal - Update the \l Viewport with which this item is associated. -*/ -void QDeclarativeItem3D::update() -{ - if (d->requireBlockingEffectsCheck && d->effect && d->mesh && d->componentComplete) - { - QGLSceneNode *n = 0; - if (!meshNode().isEmpty()) - n = d->mesh->getSceneObject(meshNode()); - if (!n) - n = d->mesh->getSceneBranch(d->mainBranchId); - if (!n) - { - n = d->mesh->getSceneObject(); - } - if (n) - { - QList<QGLSceneNode*> k = n->allChildren(); - k.prepend(n); - for (int i = 0; i < k.size(); ++i) - { - // If the effect has a texture, make sure the mesh does too - bool hasTexture = (!d->effect->texture().isEmpty() || - (!d->effect->textureImage().isNull())); - bool missingTextureCoordinates = - k.at(i)->geometry().hasField(QGL::Position) && - !k.at(i)->geometry().hasField(QGL::TextureCoord0); - if ( hasTexture && missingTextureCoordinates ) - { - qWarning() << "QGLSceneNode" << k.at(i)->objectName() << "from" << d->mesh->source() << "is missing texture coordinates. Dummy coordinates are being generated, which may take some time."; - k.at(i)->geometry().generateTextureCoordinates(); - } - - QGLSceneNode* sceneObject; - if (!this->meshNode().isEmpty()) - { - sceneObject = d->mesh->getSceneObject(meshNode()); - } else - sceneObject = d->mesh->getSceneObject(); - - if (sceneObject) - { - QList<QGLSceneNode*> k = n->allChildren(); - k.prepend(n); - if (this->effect()) - { - for (int i = 0; i < k.size(); ++i) - { - this->effect()->applyTo(k.at(i)); - } - } - } - } - } - d->requireBlockingEffectsCheck = false; - } - if (d->viewport) - d->viewport->update3d(); -} - -/*! - \qmlproperty bool Item3D::enabled - - This property should be set to true to enable the drawing - of this item and its children. Set this property to false - to disable drawing. The default value is true. - - \sa mesh -*/ -bool QDeclarativeItem3D::isEnabled() const -{ - return d->isEnabled; -} - -void QDeclarativeItem3D::setEnabled(bool value) -{ - if (d->isEnabled != value) { - d->isEnabled = value; - emit enabledChanged(); - } -} - -/*! - Returns the unique pick ID for this item. -*/ -int QDeclarativeItem3D::objectPickId() const -{ - return d->objectPickId; -} - -/*! - \qmlsignal Item3D::onClicked() - - This signal is emitted when the item is clicked. Picking must be enabled for this to have any effect. -*/ - - -/*! - \qmlsignal Item3D::onDoubleClicked() - - This signal is emitted when the item is double clicked. Picking must be enabled for this to have any effect. - -*/ - - -/*! - \qmlsignal Item3D::onPressed() - - This signal is emitted when the item detects a mouse-button-down event. Picking must be enabled - for this to have any effect. -*/ - - -/*! - \qmlsignal Item3D::onReleased() - - This signal is emitted when the item detects a mouse-button-released event. Picking must be enabled - for this to have any effect. -*/ - - -/*! - \qmlsignal Item3D::onHoverEnter() - - This signal is emitted when a mouseover of the item is detected. It relies on object picking to be - of use. -*/ - - -/*! - \qmlsignal Item3D::onHoverLeave() - - This signal is emitted when the mouseover of the item ceases. It relies on object picking to be - used. -*/ - -QT_END_NAMESPACE diff --git a/src/quick3d/qdeclarativeitem3d.h b/src/quick3d/qdeclarativeitem3d.h deleted file mode 100644 index 814914ea..00000000 --- a/src/quick3d/qdeclarativeitem3d.h +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEITEM3D_H -#define QDECLARATIVEITEM3D_H - -#include "qt3dquickglobal.h" - -#include <QtCore/qobject.h> -#include <QtCore/qvariant.h> -#include <QtGui/qvector3d.h> - -#include <QtQuick/qquickitem.h> - -#include "qglscenenode.h" -#include "qglpainter.h" -#include "qgraphicstransform3d.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QDeclarativeItem3DPrivate; -class QDeclarativeMesh; -class QDeclarativeEffect; -class QDeclarativeViewport; - -class Q_QT3D_QUICK_EXPORT QDeclarativeItem3D : public QQuickItem -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - Q_ENUMS(SortMode) - Q_ENUMS(CullFace) - Q_FLAGS(CullFaces) - Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY positionChanged) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY positionChanged) - Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY positionChanged) - Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged) - Q_PROPERTY(QDeclarativeListProperty<QGraphicsTransform3D> transform READ transform DESIGNABLE false FINAL) - Q_PROPERTY(QDeclarativeListProperty<QGraphicsTransform3D> pretransform READ pretransform DESIGNABLE false FINAL) - Q_PROPERTY(QDeclarativeMesh *mesh READ mesh WRITE setMesh NOTIFY meshChanged) - Q_PROPERTY(QDeclarativeEffect *effect READ effect WRITE setEffect NOTIFY effectChanged) - Q_PROPERTY(QGLLightParameters *light READ light WRITE setLight NOTIFY lightChanged) - Q_PROPERTY(QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false) - Q_PROPERTY(QDeclarativeListProperty<QObject> data READ data DESIGNABLE false) - Q_PROPERTY(CullFaces cullFaces READ cullFaces WRITE setCullFaces NOTIFY meshChanged) - Q_PROPERTY(SortMode sortChildren READ sortChildren WRITE setSortChildren NOTIFY sortChildrenChanged) - Q_PROPERTY(QString meshNode READ meshNode WRITE setMeshNode NOTIFY meshNodeChanged) - Q_PROPERTY(bool inheritEvents READ inheritEvents WRITE setInheritEvents NOTIFY inheritEventsChanged) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) - Q_CLASSINFO("DefaultProperty", "data") -public: - QDeclarativeItem3D(QObject *parent = 0); - ~QDeclarativeItem3D(); - - enum CullFace - { - CullDisabled = 0, - CullFrontFaces = 0x0404, // GL_FRONT - CullBackFaces = 0x0405, // GL_BACK - CullAllFaces = 0x0408, // GL_FRONT_AND_BACK - CullClockwise = 0x10000 - }; - Q_DECLARE_FLAGS(CullFaces, CullFace) - - enum SortMode - { - DefaultSorting, - BackToFront - }; - - QVector3D position() const; - void setPosition(const QVector3D& value); - - qreal x() const; - void setX(qreal value); - qreal y() const; - void setY(qreal value); - qreal z() const; - void setZ(qreal value); - - qreal scale() const; - void setScale(qreal value); - - QDeclarativeMesh *mesh() const; - void setMesh(QDeclarativeMesh* value); - - bool inheritEvents() const; - void setInheritEvents(bool inherit); - - QDeclarativeEffect *effect() const; - void setEffect(QDeclarativeEffect *value); - - QGLLightParameters *light() const; - void setLight(QGLLightParameters *value); - - QDeclarativeListProperty<QObject> data(); - QDeclarativeListProperty<QObject> resources(); - - QDeclarativeListProperty<QGraphicsTransform3D> transform(); - QDeclarativeListProperty<QGraphicsTransform3D> pretransform(); - - CullFaces cullFaces() const; - void setCullFaces(CullFaces value); - - SortMode sortChildren() const; - void setSortChildren(SortMode mode); - - QString meshNode() const; - void setMeshNode(const QString &); - - bool isEnabled() const; - void setEnabled(bool value); - - virtual void draw(QGLPainter *painter); - virtual void initialize(QGLPainter *painter); - bool isInitialized() const; - - Q_INVOKABLE QVector3D localToWorld(const QVector3D &point = QVector3D()) const; - Q_INVOKABLE QVector3D worldToLocal(const QVector3D &point = QVector3D()) const; - - void componentComplete(); - - int objectPickId() const; - -public Q_SLOTS: - void update(); - -protected: - virtual void drawLightingSetup(QGLPainter *painter, const QGLLightParameters *currentLight, QMatrix4x4 ¤tLightTransform); - virtual void drawLightingCleanup(QGLPainter *painter, const QGLLightParameters *currentLight, QMatrix4x4 ¤tLightTransform); - - virtual void drawCullSetup(); - virtual void drawCullCleanup(); - - virtual void drawEffectSetup(QGLPainter *painter, bool &viewportBlend, bool &effectBlend); - virtual void drawEffectCleanup(QGLPainter *painter, bool &viewportBlend, bool &effectBlend); - - virtual void drawChildren(QGLPainter *painter); - virtual void drawItem(QGLPainter *painter); - - virtual void drawTransformSetup(QGLPainter *painter); - virtual void drawTransformCleanup(QGLPainter *painter); - - bool event(QEvent *e); - -private Q_SLOTS: - void handleEffectChanged(); - -Q_SIGNALS: - void positionChanged(); - void scaleChanged(); - void rotationChanged(); - void meshChanged(); - void meshNodeChanged(); - void effectChanged(); - void lightChanged(); - void clicked(); - void doubleClicked(); - void pressed(); - void released(); - void hoverEnter(); - void hoverLeave(); - void inheritEventsChanged(); - void enabledChanged(); - void sortChildrenChanged(); - -private: - QDeclarativeItem3DPrivate *d; - - friend class QDeclarativeItem3DPrivate; - friend class QDeclarativeViewport; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeItem3D::CullFaces) - -Q_QT3D_QUICK_EXPORT void qDumpItem(QDeclarativeItem3D *item, bool detailed = true, int indent = 0); - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeItem3D) - -QT_END_HEADER - -#endif diff --git a/src/quick3d/qdeclarativemesh.cpp b/src/quick3d/qdeclarativemesh.cpp deleted file mode 100644 index 6f0536d8..00000000 --- a/src/quick3d/qdeclarativemesh.cpp +++ /dev/null @@ -1,705 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativemesh.h" - -#include "qglabstractscene.h" -#include "qglscenenode.h" -#include "qglmaterial.h" -#include "qglmaterialcollection.h" - -#include <QNetworkRequest> -#include <QNetworkReply> -#include <QtDeclarative/qdeclarativeengine.h> -#include <QtCore/qlist.h> - -/*! - \qmlclass Mesh QDeclarativeMesh - \brief The Mesh item provides a means of abstracting 3D mesh and geometry representations in - a way that can be used in QML. The Mesh class contains necessary properties and methods for - display and manipulation of 3d objects of this type. - \since 4.8 - \ingroup qt3d::qml3d - - \section1 Underlying Architecture - - QML/3d Mesh objects are a QML enabled means of representing any scene class based - on the \l QGLAbstractScene class. - - In cases where the scene is composed of multiple nodes (for example, in a \i .3ds file) - the mesh allows users to split away branches of the tree and manipulate them in - isolation from the original scene graph. - - In order to achieve this the mesh object contains a map correlating numeric identifiers - for individual branches with specific \l QGLSceneNode objects which are taken from - the original scene. - - More details on achieving this can be found in the \l Item3D class. - - \section1 Specifying Simple Mesh Objects - - Like other objects in QML/3d, Mesh objects are created by the standard QML syntax for - objects. Meshes should always specify an appropriate file containing the data for - the Mesh, - - \code - Effect {} - \endcode - - More complex effects use the usual QML syntax for accessing and updating properties. In order to specify - a texture, for example, the following could be used: - - \code - Effect { - id: myTextureEffect - texture: "texture.png" - } - \endcode -*/ - -QT_BEGIN_NAMESPACE - -class QDeclarativeMeshPrivate -{ -public: - QDeclarativeMeshPrivate() - : dataReply(0) - , scene(0) - , nextSceneBranchId(0) - , mainSceneObject(NULL) - , refCount(1) - , completed(false) - , loaded(false) - , dumpInfo(false) - {} - ~QDeclarativeMeshPrivate() - { - delete scene; - } - - struct branchObject { - QObject *previousParent; - QGLSceneNode *rootSceneObject; - }; - - QUrl data; - QString meshName; - QDeclarativeMesh *parentMesh; - QNetworkReply *dataReply; - QGLAbstractScene *scene; - int nextSceneBranchId; - QMap<int, branchObject> sceneBranches; - QList<QGLSceneNode *>sceneObjects; - QGLSceneNode *mainSceneObject; - QList<QGLMaterial *> connected; - int refCount; - bool completed; - bool loaded; - QString options; - bool dumpInfo; -}; - -/*! - \internal - Construct a \l Mesh object with \a parent as its parent. -*/ -QDeclarativeMesh::QDeclarativeMesh(QObject *parent) - : QObject(parent) -{ - d = new QDeclarativeMeshPrivate(); -} - -/*! - \internal - Destroy the \l Mesh object and free any unneeded memory. -*/ -QDeclarativeMesh::~QDeclarativeMesh() -{ - delete d; -} - -/*! - \qmlproperty url Mesh::source - - Each mesh requires a set of data that describes (among other things) vertices - transformations, textures, and so on. This data is generally stored in files and - specified via the source property. - - Source files can be of any type supported by QtQuick3D. The types of file currently - supported can be found in the \c sceneFormat plugins, with \i .3ds, \i .bez, \i. obj - files currently being supported. - - Meshes can also be stored within QRC files and loaded via the standard resource - mechanisms, however there may be issues with some esoteric remote resource loading - requirements within the different file types. -*/ - -QUrl QDeclarativeMesh::source() const -{ - return d->data; -} - -void QDeclarativeMesh::setSource(const QUrl& value) -{ - if (d->data == value) - return; - d->data = value; -//#define QT_NO_LOCALFILE_OPTIMIZED_QML -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (d->data.scheme() == QLatin1String("file")) { - QGLAbstractScene *s = QGLAbstractScene::loadScene(d->data.toLocalFile(), - QString(), d->options); - setScene(s); - } else if (d->data.scheme().toLower() == QLatin1String("qrc")) { - // strips off any qrc: prefix and any excess slashes and replaces it with :/ - d->data.setScheme(QString()); - QGLAbstractScene *s = QGLAbstractScene::loadScene( - QLatin1Char(':')+d->data.toString(), - QString(), d->options); - setScene(s); - } else -#endif - { - if (d->dataReply) - d->dataReply->deleteLater(); - QNetworkRequest req(d->data); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - d->dataReply = qmlEngine(this)->networkAccessManager()->get(req); - QObject::connect(d->dataReply, SIGNAL(finished()), - this, SLOT(dataRequestFinished())); - } -} - -/*! - \qmlproperty string Mesh::meshName - - Users can associate a name with a mesh to facilitate easy finding or - description of a mesh. -*/ -QString QDeclarativeMesh::meshName() const -{ - return d->meshName; -} - -void QDeclarativeMesh::setMeshName(const QString& value) -{ - bool emitDataChanged = false; - if (d->meshName != value) - { - d->meshName = value; - emitDataChanged = true; - } - if (d->loaded && d->scene) { - QGLSceneNode *insertObject; - if (value.isEmpty()) - insertObject = getSceneObject(); - else - insertObject = getSceneObject(value); - if (!insertObject && !value.isEmpty()) { - qWarning() << "could not find" << value << "available:" << getSceneObjectNames(); - } else if (!insertObject) { - qWarning() << "could not find main object in scene!"; - } - - //Add the object: if null it will make the object non-drawable, but still able - //to run. - addSceneBranch(insertObject); - emitDataChanged = true; - } - if (emitDataChanged) - emit dataChanged(); -} - -/*! - \qmlproperty string Mesh::options - - The behaviour of the underlying file loader can be controlled by - string encoded options. Consult the documentation for each loader for - the options available. - - Specifies the current options for loading this mesh. The default value - is the null string, meaning no options are applied. -*/ -QString QDeclarativeMesh::options() const -{ - return d->options; -} - -void QDeclarativeMesh::setOptions(const QString &options) -{ - if (options != d->options) - { - d->options = options; - emit optionsChanged(); - } -} - -/*! - \internal - Once the request for data has been finished the \l Mesh class is now free to load - the scene. -*/ -void QDeclarativeMesh::dataRequestFinished() -{ - setScene(QGLAbstractScene::loadScene(d->dataReply, d->data, d->options)); - d->dataReply->deleteLater(); - d->dataReply = 0; -} - -/*! - \internal - Because the branches of the overall scene are essentially /i moveable, and the - standard methods of getting objects/names from a scene rely on a single tree, - the \l Mesh class supports its own list of mesh objects in the scene which is - taken on startup from the normal \l QGLAbstractScene based class for the current - mesh. - - This means that object lookup can be performed at any time without having to - reconstitute the original scene or maintain logical links between split branches. - - As an added advantage it also eliminates the (minor) additional cost of having - to traverse the scene-graph/tree in order to locate objects. - - \sa QGLAbstractScene -*/ -void QDeclarativeMesh::initSceneObjectList() -{ - d->sceneObjects.clear(); - if (d->scene) { - QList<QObject *> objs = d->scene->objects(); - for (int index = 0; index < objs.count(); ++index) { - QGLSceneNode *node = qobject_cast<QGLSceneNode *>(objs.at(index)); - if (node) - d->sceneObjects.append(node); - } - QGLSceneNode *old = d->mainSceneObject; - d->mainSceneObject = d->scene->mainNode(); - if (old != d->mainSceneObject) - emit nodeChanged(); - } -} - -/*! - \qmlproperty QGLSceneNode Mesh::getSceneObject - - Get the main scene node for the \l QGLAbstractScene associated with this mesh. -*/ -QGLSceneNode *QDeclarativeMesh::getSceneObject() -{ - //This variant of the function gets the main scene object for the scene - if (!d->mainSceneObject) - initSceneObjectList(); - - return d->mainSceneObject; -} - -/*! - \internal - Get the scene object called \a name, specified as a QString, and retrieve the - scene object in this mesh which corresponds to it. -*/ -QGLSceneNode *QDeclarativeMesh::getSceneObject(const QString &name) -{ - //This variant of the function gets the mesh scene object for a scene - //based on the name of the object. - if (d->sceneObjects.empty()) - initSceneObjectList(); - - foreach (QGLSceneNode *object, d->sceneObjects) { - if (object && object->objectName().startsWith(name)) - { - return object; - } - } - - return NULL; -} - -/*! - \internal - Used mainly for diagnostic purposes this function returns a QStringList containing - all of the object names for the given mesh. -*/ -QStringList QDeclarativeMesh::getSceneObjectNames() -{ - //Get a string list of all mesh object names in the scene. - if (d->sceneObjects.empty()) - initSceneObjectList(); - - QStringList names; - foreach (QGLSceneNode *object, d->sceneObjects) { - if (object) { - QString name = object->objectName(); - if (!name.isEmpty()) - names += name; - } - } - return names; -} - -/*! - \qmlproperty bool Mesh::dumpInfo - - Flag set to true if the description of the item will be dumped to the console. - - When this flag is true, useful debugging and diagnostic information, for example the - names of all the subnodes of the mesh, materials and geometry parameters, will be - dumped to the console during the loading of the model. -*/ -bool QDeclarativeMesh::dumpInfo() const -{ - return d->dumpInfo; -} - -void QDeclarativeMesh::setDumpInfo(bool enable) -{ - if (enable != d->dumpInfo) - { - d->dumpInfo = enable; - emit dumpInfoChanged(); - } -} - -/*! - \internal - Set the \a scene associated with this mesh. - - The function attempts to load a meaningful scene if one exists, and will attempt to - locate the section of the scene to which this mesh applies based on mesh-name. - - Failure to find an appropriate scene will generate the warning messages. - - It should be noted that for successful operation of this function, the appropriate plugin - file reader should be built and installed. Failure to do so will result in a warning and - failure to display the scene. - - \sa QGLAbstractScene -*/ -void QDeclarativeMesh::setScene(QGLAbstractScene *scene) -{ - delete d->scene; - resetSceneBranches(); - d->scene = scene; - if (!d->scene) { - qWarning("Could not load %s (possibly plugin could not be found)", - d->data.toString().toLatin1().constData()); - } - else { - QGLSceneNode *insertObject; - initSceneObjectList(); - if (d->meshName.isEmpty()) - insertObject = getSceneObject(); - else - insertObject = getSceneObject(d->meshName); - //check if we found a valid/useful object to use based on the node name, - //otherwise just output a list of valid names - if (!insertObject && !d->meshName.isEmpty()) { - qWarning() << "could not find" << d->meshName << "available:" - << getSceneObjectNames(); - } else if (!insertObject) { - qWarning() << "could not find main object in scene!"; - } - //in either case we still need to add an object to the scene, so if we fail - //we simply add a null value to indicate that this object is non-drawable - addSceneBranch(insertObject); - -#ifndef QT_NO_DEBUG_STREAM - if (insertObject && d->dumpInfo) - { - QGLSceneNode *node = qobject_cast<QGLSceneNode*>(insertObject); - if (node) - qDumpScene(node); - } -#endif - } - emit dataChanged(); - d->loaded = true; - if (d->completed) - emit loaded(); -} - -/*! - \internal - When a scene has been deconstructed into several branches, each one being a separately - manipulated sub-branch of the whole, the branches taken are identified numerically. This - function returns the next scene branch ID number -*/ -int QDeclarativeMesh::nextSceneBranchId() const -{ - //Retrieve the next unused scene branch ID - return d->nextSceneBranchId; -} - -/*! - \internal - This function "prunes" a specific branch away from the main scene-tree/graph and adds it to the - list of independent branches drawn by the mesh. This facilitates animation & picking of specific - sub-branches of the larger tree. - - The user specifies a sceneobject/node \a nodeName, which will form the "root" of the new branch, - as well as a \a parent to which this branch shall be attached. Normally the branch will simply - be given the original scene as its parent, so that all standard object hierarchy manipulation/ - destruction rules apply, however this \a parent parameter gives the user extra flexibility if - required. -*/ -int QDeclarativeMesh::createSceneBranch(QString nodeName, QObject *parent) -{ - if (!d->scene) { - qWarning() << "Unable to split mesh: no scene initialised - attempt to add scene object failed."; - return -1; - } - else { - int branchId = nextSceneBranchId(); - QGLSceneNode *sceneNode = getSceneObject(nodeName); -#ifndef QT_NO_DEBUG_STREAM - if (d->dumpInfo) - qDumpScene(sceneNode); -#endif - if (sceneNode) { - QGLSceneNode *parentNode = qobject_cast<QGLSceneNode *>(sceneNode->parent()); - QObject *prevParent=parentNode; - if (parentNode) - parentNode->removeNode(sceneNode); //this becomes irrelevant. - - //sceneNode->setParent(d->scene); //TODO: currently this fails as sceneNode changes make problems. - //If no specific parent is nominated, use the scene specified by the mesh - parent ? sceneNode->setParent(parent) : sceneNode->setParent(d->scene); - addSceneBranch(sceneNode, prevParent); - - return branchId; - } - else { - qWarning() << "Warning: Unable to find node " << nodeName << " in given mesh. Available nodes:" - << getSceneObjectNames(); - return -1; - } - } -} - -/*! - \internal - Given a scene object \a rootSceneObject, this function adds a pointer to the object to an internally - maintained map of scene branches. - - The \a previousParent of \a rootSceneObject is also stored so that the object can be restored to its - previous parent if necessary. -*/ -int QDeclarativeMesh::addSceneBranch(QGLSceneNode *rootSceneObject, QObject *previousParent) -{ - //when adding a new object to a mesh we also store the previous parent information - //in case we wish to 'reattach' it to the parent at a later stage. - QDeclarativeMeshPrivate::branchObject newBranch; - newBranch.previousParent=previousParent; - newBranch.rootSceneObject = rootSceneObject; - - d->sceneBranches.insert(d->nextSceneBranchId, newBranch); - - return ++d->nextSceneBranchId; -} - -/*! - \internal - When an object is deleted or the user otherwise calls this function, the scene branch identified by - \a branchId is reattached to the parent node from which it was originally pruned. - - If a problem occurs or the parent node is undefined (eg. null), an attempt is made to reattach it instead - to the primary/default scene object/node, which corresponds to item 0 in the map. - - If the item selected is already the default item, and no parent can be found, it is deleted. -*/ -void QDeclarativeMesh::restoreSceneBranch(int branchId) -{ - - if (d->sceneBranches.contains(branchId)) { - qWarning() <<"Mesh does not contain branch " << branchId<<". Ignoring.\n"; - return; - } - - QDeclarativeMeshPrivate::branchObject targetBranch = d->sceneBranches.value(branchId); - - if (!targetBranch.previousParent && branchId!=0) { - targetBranch.rootSceneObject->setParent(getSceneObject()); - } - else if (!targetBranch.previousParent){ - qWarning() << "Unable to find a parent to reattach default scene object to. Skipping."; - targetBranch.rootSceneObject->setParent(d->scene); - } else { - targetBranch.rootSceneObject->setParent(targetBranch.previousParent); - } - - if (!d->sceneBranches.remove(branchId)) { - qWarning() << "Unable to remove branch "<<branchId<<" from Mesh. Ignoring."; - } -} - -/*! - \internal - Return a pointer to the scene branch identified by \a branchId. -*/ -QGLSceneNode *QDeclarativeMesh::getSceneBranch(int branchId) const -{ - if (!d->sceneBranches.contains(branchId)) return NULL; - QDeclarativeMeshPrivate::branchObject targetBranch = d->sceneBranches.value(branchId); - return targetBranch.rootSceneObject; -} - - -/*! - \internal - This function iterates through the list of scene branches in the internal map and attempts to - restore them to their original position in the object hierarchy of the scene. It then clears the - map ready for reuse. -*/ -void QDeclarativeMesh::resetSceneBranches() -{ - //Delete all "hanging" object entries in the scene branches list and return them - //to their rightful place in their parent scene if possible. - for (int i=1; i<d->nextSceneBranchId; i++) { - restoreSceneBranch(i); - } - - d->sceneBranches.clear(); - d->nextSceneBranchId = 0; -} - -/*! - \internal - Core "draw" function for the mesh draws scene branch \a branchId using \a painter. -*/ -void QDeclarativeMesh::draw(QGLPainter *painter, int branchId) -{ - if (!d->sceneBranches.contains(branchId)) { - qWarning() << "No scene object with ID: " << branchId << "for" << this; - } else { - QDeclarativeMeshPrivate::branchObject targetBranch = d->sceneBranches.value(branchId); - targetBranch.rootSceneObject->draw(painter); - } -} - -/*! - \internal - Reference counting increment. -*/ -void QDeclarativeMesh::ref() -{ - ++(d->refCount); -} - -/*! - \internal - Reference counting decrement; returns true if there are still outstanding references - to the class. -*/ -bool QDeclarativeMesh::deref() -{ - --(d->refCount); - return d->refCount > 0; -} - - -/*! - Assign the mesh the material \a materialName from the \l QGLMaterialCollection class, - and bind to the node identified by \a nodeName. - - Returns a pointer to the QGLMaterial material object \a materialName; or NULL if - either there is no current scene, or if the scene does not contain such a material. -*/ -QObject *QDeclarativeMesh::material(const QString& nodeName, const QString& materialName) -{ - if (!d->scene) - return 0; - - QGLSceneNode *sceneObject; - - if (nodeName.isEmpty()) - sceneObject = getSceneObject(); - else - sceneObject = getSceneObject(nodeName); - - if (!sceneObject || materialName.isEmpty()) { - qWarning() << "Attempt to get material data " <<materialName << " from scene node " - << nodeName <<" failed."; - return NULL; - } - - QGLSceneNode *node = qobject_cast<QGLSceneNode *>(sceneObject); - - QGLMaterialCollection *p = node->palette(); - - QGLMaterial *params = p->material(materialName); - if (params && !d->connected.contains(params)) { - d->connected.append(params); - connect(params, SIGNAL(materialChanged()), this, SIGNAL(dataChanged())); - } - return params; -} - -/*! - \internal -*/ -void QDeclarativeMesh::classBegin() -{ -} - -/*! - \internal - Checks that all loading and initialisation has been finished, and emits the loaded() signal if - the component is complete. - - \sa loaded() -*/ -void QDeclarativeMesh::componentComplete() -{ - d->completed = true; - if (d->loaded) - { - emit loaded(); - emit nodeChanged(); - } -} - -/*! - \qmlsignal Mesh::onLoaded() - - This handler is called when mesh loading is complete. -*/ - -QT_END_NAMESPACE diff --git a/src/quick3d/qdeclarativemesh.h b/src/quick3d/qdeclarativemesh.h deleted file mode 100644 index d7eea5da..00000000 --- a/src/quick3d/qdeclarativemesh.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEMESH_H -#define QDECLARATIVEMESH_H - -#include "qt3dquickglobal.h" - -#include <QtCore/qobject.h> -#include <QtCore/qurl.h> -#include <QtDeclarative/qdeclarative.h> -#include <QtDeclarative/qdeclarativeengine.h> -#include <QtDeclarative/qdeclarativeparserstatus.h> - -#include "qglscenenode.h" -#include "qglpainter.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(QtQuick3D) - -class QDeclarativeMeshPrivate; -class QGLAbstractScene; -class QGLMaterial; - -class Q_QT3D_QUICK_EXPORT QDeclarativeMesh : public QObject, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY dataChanged) - Q_PROPERTY(QString meshName READ meshName WRITE setMeshName NOTIFY dataChanged) - Q_PROPERTY(QString options READ options WRITE setOptions NOTIFY optionsChanged) - Q_PROPERTY(QGLSceneNode *node READ getSceneObject NOTIFY nodeChanged) - Q_PROPERTY(bool dumpInfo READ dumpInfo WRITE setDumpInfo NOTIFY dumpInfoChanged) - -public: - QDeclarativeMesh(QObject *parent = 0); - ~QDeclarativeMesh(); - - QUrl source() const; - void setSource(const QUrl& value); - - QString meshName() const; - void setMeshName(const QString& value); - - QString options() const; - void setOptions(const QString &); - - bool dumpInfo() const; - void setDumpInfo(bool); - - virtual void draw(QGLPainter *painter, int branchId); - - //The following functions relate to allocating the scene and its - //respective objects, and acessing these nodes. - void setScene(QGLAbstractScene *scene); - void initSceneObjectList(); - QStringList getSceneObjectNames(); - QGLSceneNode *getSceneObject(); - QGLSceneNode *getSceneObject(const QString &name); - - //The following functions relate to splitting the main scene into sub-branches - int nextSceneBranchId() const; - int createSceneBranch(QString nodeName, QObject *parent = 0); - int addSceneBranch(QGLSceneNode *rootSceneObject, QObject *previousParent=NULL); - void restoreSceneBranch(int branchId); - void resetSceneBranches(); - QGLSceneNode *getSceneBranch(int branchId) const; - - void ref(); - bool deref(); - - Q_INVOKABLE QObject *material(const QString& nodeName, const QString& materialName); - - void classBegin(); - void componentComplete(); - - -Q_SIGNALS: - void dataChanged(); - void loaded(); - void optionsChanged(); - void dumpInfoChanged(); - void nodeChanged(); - -private Q_SLOTS: - void dataRequestFinished(); - -private: - QDeclarativeMeshPrivate *d; - -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativeMesh) - -QT_END_HEADER - -#endif diff --git a/src/quick3d/qdeclarativeviewport.h b/src/quick3d/qdeclarativeviewport.h deleted file mode 100644 index 8dc501aa..00000000 --- a/src/quick3d/qdeclarativeviewport.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEVIEWPORT_H -#define QDECLARATIVEVIEWPORT_H - -#include "qt3dquickglobal.h" -#include <QtCore/qobject.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(QtQuick3D) - -class QDeclarativeItem3D; - -// Abstract interface for "Item3D" getting access to the "Viewport" -// item in the QML/3D plugin. -class Q_QT3D_QUICK_EXPORT QDeclarativeViewport -{ -public: - virtual int registerPickableObject(QObject *obj) = 0; - virtual void update3d() = 0; - virtual bool blending() const = 0; - - void setItemViewport(QDeclarativeItem3D *item); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/quick3d/qt3dquickglobal.h b/src/quick3d/qt3dquickglobal.h deleted file mode 100644 index 50c12a05..00000000 --- a/src/quick3d/qt3dquickglobal.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 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$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT3DQUICKGLOBAL_H -#define QT3DQUICKGLOBAL_H - -#include <QtCore/qglobal.h> - -QT_LICENSED_MODULE(QtQuick3D) -#if defined(Q_OS_WIN) -# if defined(QT_NODLL) -# undef QT_MAKEDLL -# undef QT_DLL -# elif defined(QT_MAKEDLL) /* create a Qt DLL library */ -# if defined(QT_DLL) -# undef QT_DLL -# endif -# if defined(QT_BUILD_QT3D_QUICK_LIB) -# define Q_QT3D_QUICK_EXPORT Q_DECL_EXPORT -# else -# define Q_QT3D_QUICK_EXPORT Q_DECL_IMPORT -# endif -# elif defined(QT_DLL) /* use a Qt DLL library */ -# define Q_QT3D_QUICK_EXPORT Q_DECL_IMPORT -# endif -#endif -#if !defined(Q_QT3D_QUICK_EXPORT) -# if defined(QT_SHARED) -# define Q_QT3D_QUICK_EXPORT Q_DECL_EXPORT -# else -# define Q_QT3D_QUICK_EXPORT -# endif -#endif - -#endif diff --git a/src/quick3d/quick3d.pri b/src/quick3d/quick3d.pri deleted file mode 100644 index da70634d..00000000 --- a/src/quick3d/quick3d.pri +++ /dev/null @@ -1,16 +0,0 @@ -INCLUDEPATH += $$PWD -VPATH += $$PWD - -HEADERS += \ - qt3dquickglobal.h \ - qdeclarativeitem3d.h \ - qdeclarativeeffect.h \ - qdeclarativemesh.h \ - qdeclarativeviewport.h - - -SOURCES += \ - qdeclarativeeffect.cpp \ - qdeclarativeitem3d.cpp \ - qdeclarativemesh.cpp - diff --git a/src/quick3d/quick3d.pro b/src/quick3d/quick3d.pro deleted file mode 100644 index 99a476af..00000000 --- a/src/quick3d/quick3d.pro +++ /dev/null @@ -1,26 +0,0 @@ -load(qt_module) - -TARGET = Qt3DQuick -MODULE = quick3d -QT = core gui network declarative quick qt3d - -CONFIG += module -MODULE_PRI = ../../modules/qt_qt3dquick.pri - -load(qt_module_config) - -gcov { - CONFIG += staticlib warn_on - QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage - QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage -} else { - CONFIG += dll warn_on -} - -include(quick3d.pri) - -PUBLIC_HEADERS = $$HEADERS -HEADERS += $$PRIVATE_HEADERS -DEFINES += QT_BUILD_QT3D_QUICK_LIB - -!contains(QT_CONFIG, egl):DEFINES += QT_NO_EGL |