summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2017-06-28 23:13:41 +0200
committerSean Harmer <sean.harmer@kdab.com>2017-07-08 09:08:40 +0000
commita61bc1bd653559637146d9e0ba0884de3e3f1a12 (patch)
tree1e08702bfc4aaa779c26bc1e0d25703818ddcb44
parent55844801dc09da2d05e6f581ce7ad3d4d334b5c1 (diff)
Introduce QSpriteSheet
a generalised non-regular grid sprite sheet. Sprites are defined by a list of QSpriteSheetItem, essentially QRect for now (may introduce rotation later) Uses wrapper class to expose qml property list. Change-Id: I5a8d6804c32d59c27e1dc823c61d56bb169ca498 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/extras/defaults/defaults.pri12
-rw-r--r--src/extras/defaults/qspritegrid.h6
-rw-r--r--src/extras/defaults/qspritesheet.cpp173
-rw-r--r--src/extras/defaults/qspritesheet.h81
-rw-r--r--src/extras/defaults/qspritesheet_p.h83
-rw-r--r--src/extras/defaults/qspritesheetitem.cpp127
-rw-r--r--src/extras/defaults/qspritesheetitem.h86
-rw-r--r--src/extras/defaults/qspritesheetitem_p.h81
-rw-r--r--src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp5
-rw-r--r--src/quick3d/quick3dextras/items/items.pri6
-rw-r--r--src/quick3d/quick3dextras/items/quick3dspritesheet.cpp100
-rw-r--r--src/quick3d/quick3dextras/items/quick3dspritesheet_p.h89
-rw-r--r--src/quick3d/quick3dextras/qt3dquickextras_global.cpp63
-rw-r--r--src/quick3d/quick3dextras/qt3dquickextras_global_p.h16
-rw-r--r--src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp76
-rw-r--r--src/quick3d/quick3dextras/qt3dquickextrasnodefactory_p.h89
-rw-r--r--src/quick3d/quick3dextras/quick3dextras.pro3
-rw-r--r--tests/manual/spritegrid/main.qml84
18 files changed, 1153 insertions, 27 deletions
diff --git a/src/extras/defaults/defaults.pri b/src/extras/defaults/defaults.pri
index fc16557eb..a97497197 100644
--- a/src/extras/defaults/defaults.pri
+++ b/src/extras/defaults/defaults.pri
@@ -29,10 +29,14 @@ HEADERS += \
$$PWD/qfirstpersoncameracontroller_p.h \
$$PWD/qorbitcameracontroller.h \
$$PWD/qorbitcameracontroller_p.h \
- $$PWD/qspritegrid.h \
- $$PWD/qspritegrid_p.h \
$$PWD/qabstractspritesheet.h \
$$PWD/qabstractspritesheet_p.h \
+ $$PWD/qspritegrid.h \
+ $$PWD/qspritegrid_p.h \
+ $$PWD/qspritesheet.h \
+ $$PWD/qspritesheet_p.h \
+ $$PWD/qspritesheetitem.h \
+ $$PWD/qspritesheetitem_p.h \
$$PWD/qtexturematerial.h \
$$PWD/qtexturematerial_p.h \
$$PWD/qmetalroughmaterial.h \
@@ -57,8 +61,10 @@ SOURCES += \
$$PWD/qt3dwindow.cpp \
$$PWD/qfirstpersoncameracontroller.cpp \
$$PWD/qorbitcameracontroller.cpp \
- $$PWD/qspritegrid.cpp \
$$PWD/qabstractspritesheet.cpp \
+ $$PWD/qspritegrid.cpp \
+ $$PWD/qspritesheet.cpp \
+ $$PWD/qspritesheetitem.cpp \
$$PWD/qtexturematerial.cpp \
$$PWD/qmetalroughmaterial.cpp \
$$PWD/qtexturedmetalroughmaterial.cpp \
diff --git a/src/extras/defaults/qspritegrid.h b/src/extras/defaults/qspritegrid.h
index 47080a786..3b6a7005a 100644
--- a/src/extras/defaults/qspritegrid.h
+++ b/src/extras/defaults/qspritegrid.h
@@ -47,12 +47,6 @@
QT_BEGIN_NAMESPACE
-namespace Qt3DRender {
-
-class QAbstractTexture;
-
-} // namespace Qt3DRender
-
namespace Qt3DExtras {
class QSpriteGridPrivate;
diff --git a/src/extras/defaults/qspritesheet.cpp b/src/extras/defaults/qspritesheet.cpp
new file mode 100644
index 000000000..87f664ce4
--- /dev/null
+++ b/src/extras/defaults/qspritesheet.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qspritesheet.h"
+#include "qspritesheetitem.h"
+#include "qspritesheet_p.h"
+
+#include <Qt3DRender/qabstracttexture.h>
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt3DCore;
+
+namespace Qt3DExtras {
+
+QSpriteSheetPrivate::QSpriteSheetPrivate()
+ : QAbstractSpriteSheetPrivate()
+{
+}
+
+int QSpriteSheetPrivate::maxIndex() const
+{
+ return m_sprites.count();
+}
+
+void QSpriteSheetPrivate::updateSizes()
+{
+ Q_Q(QSpriteSheet);
+ if (m_texture)
+ m_textureSize = QSize(m_texture->width(), m_texture->height());
+ else
+ m_textureSize = QSize();
+
+ if (m_textureSize.isEmpty() || m_sprites.isEmpty()) {
+ if (m_currentIndex != -1) {
+ m_currentIndex = -1;
+ emit q->currentIndexChanged(m_currentIndex);
+ }
+ m_textureTransform.setToIdentity();
+ emit q->textureTransformChanged(m_textureTransform);
+ return;
+ }
+
+ if (m_currentIndex < 0 || m_currentIndex > m_sprites.size()) {
+ m_currentIndex = 0;
+ emit q->currentIndexChanged(m_currentIndex);
+ }
+ updateTransform();
+}
+
+void QSpriteSheetPrivate::updateTransform()
+{
+ Q_Q(QSpriteSheet);
+ if (m_currentIndex < 0 || m_currentIndex >= m_sprites.size())
+ return;
+
+ const QSpriteSheetItem *r = m_sprites.at(m_currentIndex);
+ const float xScale = static_cast<float>(r->width()) / static_cast<float>(m_textureSize.width());
+ const float yScale = static_cast<float>(r->height()) / static_cast<float>(m_textureSize.height());
+
+ const float xTranslate = static_cast<float>(r->x()) / static_cast<float>(m_textureSize.width());
+ const float yTranslate = static_cast<float>(r->y()) / static_cast<float>(m_textureSize.height());
+
+ m_textureTransform.setToIdentity();
+ m_textureTransform(0, 0) = xScale;
+ m_textureTransform(1, 1) = yScale;
+ m_textureTransform(0, 2) = xTranslate;
+ m_textureTransform(1, 2) = yTranslate;
+ emit q->textureTransformChanged(m_textureTransform);
+}
+
+/*!
+ Constructs a new QSpriteSheet instance with parent object \a parent.
+ */
+QSpriteSheet::QSpriteSheet(QNode *parent)
+ : QAbstractSpriteSheet(*new QSpriteSheetPrivate, parent)
+{
+}
+
+QSpriteSheet::~QSpriteSheet()
+{
+}
+
+QVector<QSpriteSheetItem *> QSpriteSheet::sprites() const
+{
+ Q_D(const QSpriteSheet);
+ return d->m_sprites;
+}
+
+QSpriteSheetItem *QSpriteSheet::addSprite(int x, int y, int width, int height)
+{
+ QSpriteSheetItem *item = new QSpriteSheetItem(this);
+ item->setX(x);
+ item->setX(y);
+ item->setWidth(width);
+ item->setHeight(height);
+ addSprite(item);
+ return item;
+}
+
+void QSpriteSheet::addSprite(QSpriteSheetItem *sprite)
+{
+ Q_ASSERT(sprite);
+ Q_D(QSpriteSheet);
+ if (!d->m_sprites.contains(sprite)) {
+ d->m_sprites << sprite;
+
+ // Ensures proper bookkeeping
+ d->registerDestructionHelper(sprite, &QSpriteSheet::removeSprite, d->m_sprites);
+ if (!sprite->parent())
+ sprite->setParent(this);
+
+ emit spritesChanged(d->m_sprites);
+ d->updateSizes();
+ }
+}
+
+void QSpriteSheet::removeSprite(QSpriteSheetItem *sprite)
+{
+ Q_ASSERT(sprite);
+ Q_D(QSpriteSheet);
+ d->m_sprites.removeOne(sprite);
+ // Remove bookkeeping connection
+ d->unregisterDestructionHelper(sprite);
+}
+
+void QSpriteSheet::setSprites(QVector<QSpriteSheetItem *> sprites)
+{
+ Q_D(QSpriteSheet);
+ d->m_sprites = sprites;
+ emit spritesChanged(sprites);
+ d->updateSizes();
+}
+
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
diff --git a/src/extras/defaults/qspritesheet.h b/src/extras/defaults/qspritesheet.h
new file mode 100644
index 000000000..00fd293c3
--- /dev/null
+++ b/src/extras/defaults/qspritesheet.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_QSPRITESHEET_H
+#define QT3DEXTRAS_QSPRITESHEET_H
+
+#include <Qt3DExtras/qabstractspritesheet.h>
+#include <QRect>
+#include <QVector>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+class QSpriteSheetItem;
+class QSpriteSheetPrivate;
+
+class QT3DEXTRASSHARED_EXPORT QSpriteSheet : public QAbstractSpriteSheet
+{
+ Q_OBJECT
+ Q_PROPERTY(QVector<QSpriteSheetItem *> sprites READ sprites WRITE setSprites NOTIFY spritesChanged)
+public:
+ explicit QSpriteSheet(Qt3DCore::QNode *parent = nullptr);
+ ~QSpriteSheet();
+
+ QVector<QSpriteSheetItem *> sprites() const;
+ QSpriteSheetItem *addSprite(int x, int y, int width, int height);
+ void addSprite(QSpriteSheetItem *sprite);
+ void removeSprite(QSpriteSheetItem *sprite);
+
+public Q_SLOTS:
+ void setSprites(QVector<QSpriteSheetItem *> sprites);
+
+Q_SIGNALS:
+ void spritesChanged(QVector<QSpriteSheetItem *> sprites);
+
+private:
+ Q_DECLARE_PRIVATE(QSpriteSheet)
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QSPRITESHEET_H
diff --git a/src/extras/defaults/qspritesheet_p.h b/src/extras/defaults/qspritesheet_p.h
new file mode 100644
index 000000000..5091800fe
--- /dev/null
+++ b/src/extras/defaults/qspritesheet_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_QSPRITESHEET_P_H
+#define QT3DEXTRAS_QSPRITESHEET_P_H
+#include <QRect>
+#include <QVector>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DExtras/private/qabstractspritesheet_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+class QSpriteSheetItem;
+class QSpriteSheet;
+
+class QSpriteSheetPrivate : public QAbstractSpriteSheetPrivate
+{
+ QSpriteSheetPrivate();
+
+ int maxIndex() const override;
+ void updateSizes() override;
+ void updateTransform() override;
+
+ QVector<QSpriteSheetItem *> m_sprites;
+
+ Q_DECLARE_PUBLIC(QSpriteSheet)
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QSPRITESHEET_P_H
+
diff --git a/src/extras/defaults/qspritesheetitem.cpp b/src/extras/defaults/qspritesheetitem.cpp
new file mode 100644
index 000000000..b4e096ae9
--- /dev/null
+++ b/src/extras/defaults/qspritesheetitem.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qspritesheetitem.h"
+#include "qspritesheetitem_p.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt3DCore;
+
+namespace Qt3DExtras {
+
+QSpriteSheetItemPrivate::QSpriteSheetItemPrivate()
+ : QNodePrivate()
+ , m_x(0)
+ , m_y(0)
+ , m_width(0)
+ , m_height(0)
+{
+
+}
+
+QSpriteSheetItem::QSpriteSheetItem(QNode *parent)
+ : Qt3DCore::QNode(* new QSpriteSheetItemPrivate(), parent)
+{
+
+}
+
+int QSpriteSheetItem::x() const
+{
+ Q_D(const QSpriteSheetItem);
+ return d->m_x;
+}
+
+void QSpriteSheetItem::setX(int x)
+{
+ Q_D(QSpriteSheetItem);
+ if (x != d->m_x) {
+ d->m_x = x;
+ emit xChanged(x);
+ }
+}
+
+int QSpriteSheetItem::y() const
+{
+ Q_D(const QSpriteSheetItem);
+ return d->m_y;
+}
+
+void QSpriteSheetItem::setY(int y)
+{
+ Q_D(QSpriteSheetItem);
+ if (y != d->m_y) {
+ d->m_y = y;
+ emit yChanged(y);
+ }
+}
+
+int QSpriteSheetItem::width() const
+{
+ Q_D(const QSpriteSheetItem);
+ return d->m_width;
+}
+
+void QSpriteSheetItem::setWidth(int width)
+{
+ Q_D(QSpriteSheetItem);
+ if (width != d->m_width) {
+ d->m_width = width;
+ emit widthChanged(width);
+ }
+}
+
+int QSpriteSheetItem::height() const
+{
+ Q_D(const QSpriteSheetItem);
+ return d->m_height;
+}
+
+void QSpriteSheetItem::setHeight(int height)
+{
+ Q_D(QSpriteSheetItem);
+ if (height != d->m_height) {
+ d->m_height = height;
+ emit heightChanged(height);
+ }
+}
+
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
diff --git a/src/extras/defaults/qspritesheetitem.h b/src/extras/defaults/qspritesheetitem.h
new file mode 100644
index 000000000..f47846071
--- /dev/null
+++ b/src/extras/defaults/qspritesheetitem.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_QSPRITESHEETITEM_H
+#define QT3DEXTRAS_QSPRITESHEETITEM_H
+
+#include <Qt3DExtras/qabstractspritesheet.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+class QSpriteSheetItemPrivate;
+
+class QT3DEXTRASSHARED_EXPORT QSpriteSheetItem : public Qt3DCore::QNode
+{
+ Q_OBJECT
+ Q_PROPERTY(int x READ x WRITE setX NOTIFY xChanged)
+ Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
+ Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
+ Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
+public:
+ explicit QSpriteSheetItem(Qt3DCore::QNode *parent = nullptr);
+
+ int x() const;
+ int y() const;
+ int width() const;
+ int height() const;
+
+public Q_SLOTS:
+ void setX(int x);
+ void setY(int y);
+ void setWidth(int width);
+ void setHeight(int height);
+
+Q_SIGNALS:
+ void xChanged(int x);
+ void yChanged(int y);
+ void widthChanged(int width);
+ void heightChanged(int height);
+
+private:
+ Q_DECLARE_PRIVATE(QSpriteSheetItem)
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QSPRITESHEETITEM_H
diff --git a/src/extras/defaults/qspritesheetitem_p.h b/src/extras/defaults/qspritesheetitem_p.h
new file mode 100644
index 000000000..f23d71cd7
--- /dev/null
+++ b/src/extras/defaults/qspritesheetitem_p.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_QSPRITESHEET_P_H
+#define QT3DEXTRAS_QSPRITESHEET_P_H
+#include <QRect>
+#include <QVector>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DCore/private/qnode_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+class QSpriteSheetItem;
+
+class QSpriteSheetItemPrivate: public Qt3DCore::QNodePrivate
+{
+ QSpriteSheetItemPrivate();
+
+ int m_x;
+ int m_y;
+ int m_width;
+ int m_height;
+
+ Q_DECLARE_PUBLIC(QSpriteSheetItem)
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QSPRITESHEET_P_H
+
diff --git a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp
index 125a087ab..bdafca64c 100644
--- a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp
+++ b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp
@@ -67,6 +67,7 @@
#include <Qt3DExtras/qspheregeometry.h>
#include <Qt3DExtras/qspheremesh.h>
#include <Qt3DExtras/qspritegrid.h>
+#include <Qt3DExtras/qspritesheetitem.h>
#include <Qt3DExtras/qtext2dentity.h>
#include <Qt3DExtras/qtexturedmetalroughmaterial.h>
#include <Qt3DExtras/qtexturematerial.h>
@@ -74,6 +75,7 @@
#include <Qt3DExtras/qtorusmesh.h>
#include <Qt3DQuickExtras/private/quick3dlevelofdetailloader_p.h>
+#include <Qt3DQuickExtras/private/quick3dspritesheet_p.h>
#include <QtQml/qqml.h>
@@ -105,11 +107,14 @@ void Qt3DQuick3DExtrasPlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3DExtras::QPerVertexColorMaterial>(uri, 2, 0, "PerVertexColorMaterial");
qmlRegisterType<Qt3DExtras::QGoochMaterial>(uri, 2, 0, "GoochMaterial");
qmlRegisterType<Qt3DExtras::QTextureMaterial>(uri, 2, 0, "TextureMaterial");
+ qmlRegisterRevision<Qt3DExtras::QTextureMaterial, 10>(uri, 2, 10);
qmlRegisterType<Qt3DExtras::QMetalRoughMaterial>(uri, 2, 9, "MetalRoughMaterial");
qmlRegisterType<Qt3DExtras::QTexturedMetalRoughMaterial>(uri, 2, 9, "TexturedMetalRoughMaterial");
qmlRegisterType<Qt3DExtras::QMorphPhongMaterial>(uri, 2, 9, "MorphPhongMaterial");
qmlRegisterType<Qt3DExtras::QSpriteGrid>(uri, 2, 10, "SpriteGrid");
+ qmlRegisterType<Qt3DExtras::QSpriteSheetItem>(uri, 2, 10, "SpriteItem");
+ Qt3DExtras::Quick::registerExtendedType<Qt3DExtras::QSpriteSheet, Qt3DExtras::Extras::Quick::Quick3DSpriteSheet>("QSpriteSheet", "Qt3D.Extras/SpriteSheet", uri, 2, 10, "SpriteSheet");
// Meshes
qmlRegisterType<Qt3DExtras::QConeMesh>(uri, 2, 0, "ConeMesh");
diff --git a/src/quick3d/quick3dextras/items/items.pri b/src/quick3d/quick3dextras/items/items.pri
index b6f5d1877..f2fe09dcb 100644
--- a/src/quick3d/quick3dextras/items/items.pri
+++ b/src/quick3d/quick3dextras/items/items.pri
@@ -1,8 +1,10 @@
HEADERS += \
$$PWD/quick3dlevelofdetailloader_p.h \
- $$PWD/quick3dlevelofdetailloader_p_p.h
+ $$PWD/quick3dlevelofdetailloader_p_p.h \
+ $$PWD/quick3dspritesheet_p.h
SOURCES += \
- $$PWD/quick3dlevelofdetailloader.cpp
+ $$PWD/quick3dlevelofdetailloader.cpp \
+ $$PWD/quick3dspritesheet.cpp
INCLUDEPATH += $$PWD
diff --git a/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp b/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp
new file mode 100644
index 000000000..a38581cc7
--- /dev/null
+++ b/src/quick3d/quick3dextras/items/quick3dspritesheet.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "quick3dspritesheet_p.h"
+#include <Qt3DExtras/qspritesheetitem.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+namespace Extras {
+namespace Quick {
+
+Quick3DSpriteSheet::Quick3DSpriteSheet(QObject *parent)
+ : QObject(parent)
+{
+}
+
+Quick3DSpriteSheet::~Quick3DSpriteSheet()
+{
+}
+
+QQmlListProperty<Qt3DExtras::QSpriteSheetItem> Quick3DSpriteSheet::sprites()
+{
+ return QQmlListProperty<Qt3DExtras::QSpriteSheetItem>(this, 0,
+ &Quick3DSpriteSheet::appendSprite,
+ &Quick3DSpriteSheet::spriteCount,
+ &Quick3DSpriteSheet::spriteAt,
+ &Quick3DSpriteSheet::clearSprites);
+
+}
+
+void Quick3DSpriteSheet::appendSprite(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list,
+ Qt3DExtras::QSpriteSheetItem *sprite)
+{
+ Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object);
+ spritesheet->parentSpriteSheet()->addSprite(sprite);
+}
+
+Qt3DExtras::QSpriteSheetItem *Quick3DSpriteSheet::spriteAt(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, int index)
+{
+ Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object);
+ return spritesheet->parentSpriteSheet()->sprites().at(index);
+}
+
+int Quick3DSpriteSheet::spriteCount(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list)
+{
+ Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object);
+ return spritesheet->parentSpriteSheet()->sprites().count();
+}
+
+void Quick3DSpriteSheet::clearSprites(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list)
+{
+ Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(list->object);
+ const auto sprites = spritesheet->parentSpriteSheet()->sprites();
+ for (QSpriteSheetItem *sprite : sprites)
+ spritesheet->parentSpriteSheet()->removeSprite(sprite);
+}
+
+} // namespace Quick
+} // namespace Extras
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
+
diff --git a/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h b/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h
new file mode 100644
index 000000000..38a92dd2a
--- /dev/null
+++ b/src/quick3d/quick3dextras/items/quick3dspritesheet_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DEXTRAS_EXTRAS_QUICK_QUICK3DSPRITESHEET_P_H
+#define QT3DEXTRAS_EXTRAS_QUICK_QUICK3DSPRITESHEET_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DQuickExtras/qt3dquickextras_global.h>
+#include <Qt3DExtras/qspritesheet.h>
+#include <QtQml/QQmlListProperty>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+namespace Extras {
+namespace Quick {
+
+class QT3DQUICKEXTRASSHARED_EXPORT Quick3DSpriteSheet : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> sprites READ sprites CONSTANT)
+ Q_CLASSINFO("DefaultProperty", "sprites")
+public:
+ explicit Quick3DSpriteSheet(QObject *parent = 0);
+ ~Quick3DSpriteSheet();
+
+ QQmlListProperty<Qt3DExtras::QSpriteSheetItem> sprites();
+ inline QSpriteSheet *parentSpriteSheet() const { return qobject_cast<QSpriteSheet *>(parent()); }
+
+private:
+ static void appendSprite(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, Qt3DExtras::QSpriteSheetItem *state);
+ static Qt3DExtras::QSpriteSheetItem *spriteAt(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list, int index);
+ static int spriteCount(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list);
+ static void clearSprites(QQmlListProperty<Qt3DExtras::QSpriteSheetItem> *list);
+};
+
+} // namespace Quick
+} // namespace Extras
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_EXTRAS_QUICK_QUICK3DSPRITESHEET_P_H
diff --git a/src/quick3d/quick3dextras/qt3dquickextras_global.cpp b/src/quick3d/quick3dextras/qt3dquickextras_global.cpp
new file mode 100644
index 000000000..e9b71e081
--- /dev/null
+++ b/src/quick3d/quick3dextras/qt3dquickextras_global.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qt3dquickextras_global_p.h"
+
+#include <Qt3DQuickExtras/private/qt3dquickextrasnodefactory_p.h>
+#include <QtQml/private/qqmlglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+namespace Quick {
+
+void Quick3DExtras_initialize()
+{
+ Qt3DCore::QAbstractNodeFactory::registerNodeFactory(QuickExtrasNodeFactory::instance());
+}
+
+void Quick3DExtras_registerType(const char *className, const char *quickName, int major, int minor)
+{
+ QuickExtrasNodeFactory::instance()->registerType(className, quickName, major, minor);
+}
+
+} // namespace Quick
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quick3dextras/qt3dquickextras_global_p.h b/src/quick3d/quick3dextras/qt3dquickextras_global_p.h
index 524393743..a27533517 100644
--- a/src/quick3d/quick3dextras/qt3dquickextras_global_p.h
+++ b/src/quick3d/quick3dextras/qt3dquickextras_global_p.h
@@ -58,6 +58,22 @@
QT_BEGIN_NAMESPACE
+namespace Qt3DExtras {
+namespace Quick {
+
+QT3DQUICKEXTRASSHARED_PRIVATE_EXPORT void Quick3DExtras_initialize();
+QT3DQUICKEXTRASSHARED_PRIVATE_EXPORT void Quick3DExtras_registerType(const char *className, const char *quickName, int major, int minor);
+
+template<class T, class E> void registerExtendedType(const char *className, const char *quickName,
+ const char *uri, int major, int minor, const char *name)
+{
+ qmlRegisterExtendedType<T, E>(uri, major, minor, name);
+ Quick3DExtras_registerType(className, quickName, major, minor);
+}
+
+} // Quick
+} // Qt3DExtras
+
QT_END_NAMESPACE
#endif // QT3DQUICKEXTRAS_GLOBAL_P_H
diff --git a/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp b/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp
new file mode 100644
index 000000000..073a3ec44
--- /dev/null
+++ b/src/quick3d/quick3dextras/qt3dquickextrasnodefactory.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qt3dquickextrasnodefactory_p.h"
+#include <private/qqmlmetatype_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+Q_GLOBAL_STATIC(QuickExtrasNodeFactory, quick_extras_node_factory)
+
+QuickExtrasNodeFactory *QuickExtrasNodeFactory::instance()
+{
+ return quick_extras_node_factory();
+}
+
+void QuickExtrasNodeFactory::registerType(const char *className, const char *quickName, int major, int minor)
+{
+ m_types.insert(className, Type(quickName, major, minor));
+}
+
+Qt3DCore::QNode *QuickExtrasNodeFactory::createNode(const char *type)
+{
+ if (!m_types.contains(type))
+ return nullptr;
+
+ Type &typeInfo(m_types[type]);
+
+ if (!typeInfo.resolved) {
+ typeInfo.resolved = true;
+ typeInfo.t = QQmlMetaType::qmlType(QString::fromLatin1(typeInfo.quickName), typeInfo.version.first, typeInfo.version.second);
+ }
+
+ return typeInfo.t ? qobject_cast<Qt3DCore::QNode *>(typeInfo.t->create()) : nullptr;
+}
+
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quick3dextras/qt3dquickextrasnodefactory_p.h b/src/quick3d/quick3dextras/qt3dquickextrasnodefactory_p.h
new file mode 100644
index 000000000..03769c397
--- /dev/null
+++ b/src/quick3d/quick3dextras/qt3dquickextrasnodefactory_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QUICKEXTRASERNODEFACTORY_H
+#define QUICKEXTRASERNODEFACTORY_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qabstractnodefactory_p.h>
+#include <QtCore/qhash.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQmlType;
+
+namespace Qt3DExtras {
+
+class QuickExtrasNodeFactory : public Qt3DCore::QAbstractNodeFactory
+{
+public:
+ Qt3DCore::QNode *createNode(const char *type) Q_DECL_OVERRIDE;
+
+ void registerType(const char *className, const char *quickName, int major, int minor);
+
+ static QuickExtrasNodeFactory *instance();
+
+private:
+ struct Type {
+ Type() : t(nullptr), resolved(false) { }
+ Type(const char *quickName, int major, int minor)
+ : quickName(quickName), version(major, minor), t(nullptr), resolved(false) { }
+ QByteArray quickName;
+ QPair<int, int> version;
+ QQmlType *t;
+ bool resolved;
+ };
+ QHash<QByteArray, Type> m_types;
+};
+
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QUICKEXTRASERNODEFACTORY_H
diff --git a/src/quick3d/quick3dextras/quick3dextras.pro b/src/quick3d/quick3dextras/quick3dextras.pro
index 976430eba..f89a93e8e 100644
--- a/src/quick3d/quick3dextras/quick3dextras.pro
+++ b/src/quick3d/quick3dextras/quick3dextras.pro
@@ -14,12 +14,15 @@ gcov {
}
SOURCES += \
+ qt3dquickextras_global.cpp \
+ qt3dquickextrasnodefactory.cpp \
qt3dquickwindow.cpp \
qt3dquickwindowlogging.cpp
HEADERS += \
qt3dquickextras_global.h \
qt3dquickextras_global_p.h \
+ qt3dquickextrasnodefactory_p.h \
qt3dquickwindow.h \
qt3dquickwindow_p.h \
qt3dquickwindowlogging_p.h
diff --git a/tests/manual/spritegrid/main.qml b/tests/manual/spritegrid/main.qml
index d5ff7f259..ca3d7fd92 100644
--- a/tests/manual/spritegrid/main.qml
+++ b/tests/manual/spritegrid/main.qml
@@ -75,7 +75,7 @@ Entity {
id : external_forward_renderer
activeFrameGraph : ForwardRenderer {
camera: camera
- clearColor: "white"
+ clearColor: "lightgrey"
}
}
@@ -88,43 +88,95 @@ Entity {
id: mesh
}
- Transform {
- id: transform
- scale: 8
- rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
- }
-
SpriteGrid {
- id: sprites
+ id: spriteGrid
rows: 2
columns: 6
texture: textureLoader
}
+ SpriteSheet {
+ id:spriteSheet
+ texture: textureLoader
+
+ SpriteItem { x: 0; y: 0; width: 250; height: 172 }
+ SpriteItem { x: 276; y: 0; width: 250; height: 172 }
+ SpriteItem { x: 550; y: 0; width: 250; height: 172 }
+ SpriteItem { x: 826; y: 0; width: 250; height: 172 }
+ SpriteItem { x: 1100; y: 0; width: 250; height: 172 }
+ SpriteItem { x: 1376; y: 0; width: 250; height: 172 }
+ SpriteItem { x: 0; y: 198; width: 250; height: 172 }
+ SpriteItem { x: 276; y: 198; width: 250; height: 172 }
+ SpriteItem { x: 550; y: 198; width: 250; height: 172 }
+ SpriteItem { x: 826; y: 198; width: 250; height: 172 }
+ SpriteItem { x: 1100; y: 198; width: 250; height: 172 }
+ SpriteItem { x: 1376; y: 198; width: 250; height: 172 }
+ }
+
+ Transform {
+ id: transform1
+ scale: 8
+ rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
+ translation: Qt.vector3d(-6, 0, 0)
+ }
+
TextureMaterial {
- id: material
+ id: material1
texture: TextureLoader {
id: textureLoader
source: "spritegrid.png"
mirrored: false
}
- textureTransform: sprites.textureTransform
+ textureTransform: spriteGrid.textureTransform
}
Entity {
- id: mainEntity
- objectName: "mainEntity"
- components: [ mesh, material, transform ]
+ components: [ mesh, material1, transform1 ]
}
+
+ Transform {
+ id: transform2
+ scale: 8
+ rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
+ translation: Qt.vector3d(6, 0, 0)
+ }
+
+ TextureMaterial {
+ id: material2
+ texture: material1.texture
+ textureTransform: spriteSheet.textureTransform
+ }
+
+ Entity {
+ components: [ mesh, material2, transform2 ]
+ }
+
+
+ Transform {
+ id: transform3
+ scale3D: Qt.vector3d(12, 4, 4)
+ rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 90)
+ translation: Qt.vector3d(0, -6, 0)
+ }
+
+ TextureMaterial {
+ id: material3
+ texture: material1.texture
+ }
+
+ Entity {
+ components: [ mesh, material3, transform3 ]
+ }
+
+
Timer {
interval: 1000
repeat: true
running: true
onTriggered: {
- var n = sprites.currentIndex + 1
- n = (n >= sprites.rows * sprites.columns) ? 0 : n
- sprites.currentIndex = n
+ spriteGrid.currentIndex = (spriteGrid.currentIndex + 1) % (spriteGrid.rows * spriteGrid.columns)
+ spriteSheet.currentIndex = (spriteSheet.currentIndex + 1) % (spriteSheet.sprites.length)
}
}
}