summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-06-28 14:22:33 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-08-08 09:12:16 +0000
commit80cde984ff8d8eb180bf94a64176da4e9d727a30 (patch)
treec1aab72addc2147807531efd4b8c664420d69ae5 /src
parentc402164bd09f4ab06db6173f490a036b60f83084 (diff)
Add QArmature component
This will be used by the renderer to perform skinning of the mesh passed to QGeometryRenderer when coupled with a suitable vertex shader via QMaterial. Change-Id: I54f414313ba04aea5f2f1777244cb93cd1bfd688 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/transforms/qarmature.cpp172
-rw-r--r--src/core/transforms/qarmature.h82
-rw-r--r--src/core/transforms/qarmature_p.h83
-rw-r--r--src/core/transforms/transforms.pri7
4 files changed, 342 insertions, 2 deletions
diff --git a/src/core/transforms/qarmature.cpp b/src/core/transforms/qarmature.cpp
new file mode 100644
index 000000000..65a13b262
--- /dev/null
+++ b/src/core/transforms/qarmature.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** 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 "qarmature.h"
+#include "qarmature_p.h"
+#include <Qt3DCore/qabstractskeleton.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+
+QArmaturePrivate::QArmaturePrivate()
+ : Qt3DCore::QComponentPrivate()
+ , m_skeleton(nullptr)
+{
+}
+
+/*!
+ \qmltype Armature
+ \inqmlmodule Qt3D.Core
+ \inherits Component3D
+ \instantiates Qt3DCore::QArmature
+ \since 5.10
+ \brief Used to calculate skinning transform matrices and set them on shaders
+
+ The Armature component is aggregated by entities to give them the ability to
+ calculate the palette of skinning transform matrices needed to properly
+ render skinned meshes.
+
+ Each vertex in a skinned mesh is associated (bound) to up to 4 joints in a
+ skeleton. For each joint affecting a vertex the mesh also provides a weight
+ which determines the level of influence of the corresponding joint. The
+ skinning palette used for performing the transformation of skinned vertices
+ is provided by the Armature and is calculated from the joints contained in
+ the referenced skeleton.
+
+ Updating the local transform of a joint results in the skinning matrices
+ being recalculated and the skinned mesh vertices bound to that joint moving
+ accordingly.
+*/
+
+/*!
+ \qmlproperty AbstractSkeleton Armature::skeleton
+
+ Holds the skeleton used to calculate the skinning transform matrix palette.
+*/
+
+/*!
+ \class Qt3DCore::QArmature
+ \inmodule Qt3DCore
+ \inherits Qt3DCore::QComponent
+ \since 5.10
+ \brief Used to calculate skinning transform matrices and set them on shaders
+
+ The Armature component is aggregated by entities to give them the ability to
+ calculate the palette of skinning transform matrices needed to properly
+ render skinned meshes.
+
+ Each vertex in a skinned mesh is associated (bound) to up to 4 joints in a
+ skeleton. For each joint affecting a vertex the mesh also provides a weight
+ which determines the level of influence of the corresponding joint. The
+ skinning palette used for performing the transformation of skinned vertices
+ is provided by the Armature and is calculated from the joints contained in
+ the referenced skeleton.
+
+ Updating the local transform of a joint results in the skinning matrices
+ being recalculated and the skinned mesh vertices bound to that joint moving
+ accordingly.
+*/
+
+/*!
+ Constructs a new QArmature with \a parent.
+*/
+QArmature::QArmature(Qt3DCore::QNode *parent)
+ : Qt3DCore::QComponent(*new QArmaturePrivate, parent)
+{
+}
+
+/*! \internal */
+QArmature::QArmature(QArmaturePrivate &dd, Qt3DCore::QNode *parent)
+ : Qt3DCore::QComponent(dd, parent)
+{
+}
+
+/*! \internal */
+QArmature::~QArmature()
+{
+}
+
+/*!
+ \property Qt3DCore::QArmature::skeleton
+
+ Holds the skeleton used to calculate the skinning transform matrix palette.
+*/
+Qt3DCore::QAbstractSkeleton *QArmature::skeleton() const
+{
+ Q_D(const QArmature);
+ return d->m_skeleton;
+}
+
+void QArmature::setSkeleton(Qt3DCore::QAbstractSkeleton *skeleton)
+{
+ Q_D(QArmature);
+ if (d->m_skeleton != skeleton) {
+ if (d->m_skeleton)
+ d->unregisterDestructionHelper(d->m_skeleton);
+
+ // We need to add it as a child of the current node if it has been declared inline
+ // Or not previously added as a child of the current node so that
+ // 1) The backend gets notified about it's creation
+ // 2) When the current node is destroyed, it gets destroyed as well
+ if (skeleton && !skeleton->parent())
+ skeleton->setParent(this);
+ d->m_skeleton = skeleton;
+
+ // Ensures proper bookkeeping
+ if (d->m_skeleton)
+ d->registerDestructionHelper(d->m_skeleton, &QArmature::setSkeleton, d->m_skeleton);
+
+ emit skeletonChanged(skeleton);
+ }
+}
+
+/*! \internal */
+Qt3DCore::QNodeCreatedChangeBasePtr QArmature::createNodeCreationChange() const
+{
+ auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QArmatureData>::create(this);
+ auto &data = creationChange->data;
+ Q_D(const QArmature);
+ data.skeletonId = qIdForNode(d->m_skeleton);
+ return creationChange;
+}
+
+} // namespace Qt3DCore
+
+QT_END_NAMESPACE
diff --git a/src/core/transforms/qarmature.h b/src/core/transforms/qarmature.h
new file mode 100644
index 000000000..a5ccc9d28
--- /dev/null
+++ b/src/core/transforms/qarmature.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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 QT3DCORE_QARMATURE_H
+#define QT3DCORE_QARMATURE_H
+
+#include <Qt3DCore/qcomponent.h>
+#include <Qt3DCore/qt3dcore_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+
+class QArmaturePrivate;
+class QAbstractSkeleton;
+
+class QT3DCORESHARED_EXPORT QArmature : public Qt3DCore::QComponent
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3DCore::QAbstractSkeleton* skeleton READ skeleton WRITE setSkeleton NOTIFY skeletonChanged)
+
+public:
+ explicit QArmature(Qt3DCore::QNode *parent = nullptr);
+ ~QArmature();
+
+ QAbstractSkeleton* skeleton() const;
+
+public Q_SLOTS:
+ void setSkeleton(Qt3DCore::QAbstractSkeleton* skeleton);
+
+Q_SIGNALS:
+ void skeletonChanged(Qt3DCore::QAbstractSkeleton* skeleton);
+
+protected:
+ QArmature(QArmaturePrivate &dd, Qt3DCore::QNode *parent = nullptr);
+
+private:
+ Q_DECLARE_PRIVATE(QArmature)
+ Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override;
+};
+
+} // namespace Qt3DCore
+
+QT_END_NAMESPACE
+
+#endif // QT3DCORE_QARMATURE_H
diff --git a/src/core/transforms/qarmature_p.h b/src/core/transforms/qarmature_p.h
new file mode 100644
index 000000000..1fc241dc2
--- /dev/null
+++ b/src/core/transforms/qarmature_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 QT3DCORE_QARMATURE_P_H
+#define QT3DCORE_QARMATURE_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 <Qt3DCore/private/qcomponent_p.h>
+#include <Qt3DCore/qarmature.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+
+class QAbstractSkeleton;
+
+class QArmaturePrivate : public Qt3DCore::QComponentPrivate
+{
+public:
+ QArmaturePrivate();
+
+ Q_DECLARE_PUBLIC(QArmature)
+
+ QAbstractSkeleton *m_skeleton;
+};
+
+struct QArmatureData
+{
+ QNodeId skeletonId;
+};
+
+} // namespace Qt3DCore
+
+
+QT_END_NAMESPACE
+
+#endif // QT3DCORE_QARMATURE_P_H
diff --git a/src/core/transforms/transforms.pri b/src/core/transforms/transforms.pri
index d5eb965ae..f76cdd289 100644
--- a/src/core/transforms/transforms.pri
+++ b/src/core/transforms/transforms.pri
@@ -4,7 +4,8 @@ SOURCES += \
$$PWD/qjoint.cpp \
$$PWD/qabstractskeleton.cpp \
$$PWD/qskeleton.cpp \
- $$PWD/qskeletonloader.cpp
+ $$PWD/qskeletonloader.cpp \
+ $$PWD/qarmature.cpp
HEADERS += \
$$PWD/qtransform.h \
@@ -17,6 +18,8 @@ HEADERS += \
$$PWD/qskeleton.h \
$$PWD/qskeleton_p.h \
$$PWD/qskeletonloader.h \
- $$PWD/qskeletonloader_p.h
+ $$PWD/qskeletonloader_p.h \
+ $$PWD/qarmature.h \
+ $$PWD/qarmature_p.h
INCLUDEPATH += $$PWD