diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-06-27 14:18:17 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-08-07 13:56:43 +0000 |
commit | 71f0a11f0adbdf226f0821e2b79abaa370360748 (patch) | |
tree | 27d97e139c72f297d320f75e7a60b8da5234ca44 /src/core/transforms | |
parent | 8227e3c9f1d72e34fdf2c6427c6d278d0eeb32cd (diff) |
Add QJoint frontend type
Represents a joint within a skeleton. For now we limit the scale to
a uniform scale represented by a single float. If there is demand
we can extend this to support non-uniform scales for joints using a
QVector3D.
Change-Id: Ib65e45d14c5e40227801c0a70ac5b68557c7e8e9
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/transforms')
-rw-r--r-- | src/core/transforms/qjoint.cpp | 252 | ||||
-rw-r--r-- | src/core/transforms/qjoint.h | 93 | ||||
-rw-r--r-- | src/core/transforms/qjoint_p.h | 87 | ||||
-rw-r--r-- | src/core/transforms/transforms.pri | 11 |
4 files changed, 439 insertions, 4 deletions
diff --git a/src/core/transforms/qjoint.cpp b/src/core/transforms/qjoint.cpp new file mode 100644 index 000000000..0601ac02f --- /dev/null +++ b/src/core/transforms/qjoint.cpp @@ -0,0 +1,252 @@ +/**************************************************************************** +** +** 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 "qjoint.h" +#include "qjoint_p.h" + +#include <Qt3DCore/qnodecreatedchange.h> +#include <Qt3DCore/qpropertynodeaddedchange.h> +#include <Qt3DCore/qpropertynoderemovedchange.h> +#include <Qt3DCore/qpropertyupdatedchange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +QJointPrivate::QJointPrivate() + : QNodePrivate() + , m_rotation() + , m_translation() + , m_scale(1.0f) +{ +} + +/*! + \qmltype Joint + \inqmlmodule Qt3D.Core + \inherits Node + \instantiates Qt3DCore::QJoint + \since 5.10 + \brief Used to transforms parts of skinned meshes + + The Joint node is used to build skeletons as part of the skinned mesh + support in Qt 3D. A joint can be transformed by way of its scale, rotation + and translation properties. Any mesh vertices that are bound to the joint + will have their transformations updated accordingly. +*/ + +/*! + \qmlproperty real Joint::scale + + Holds the uniform scale of the joint. +*/ + +/*! + \qmlproperty quaternion Joint::rotation + + Holds the rotation of the joint as quaternion. +*/ + +/*! + \qmlproperty vector3d Joint::translation + + Holds the translation of the joint as vector3d. +*/ + +/*! + \class Qt3DCore::QJoint + \inmodule Qt3DCore + \inherits Qt3DCore::QNode + \since 5.10 + \brief Used to transforms parts of skinned meshes + + The QJoint node is used to build skeletons as part of the skinned mesh + support in Qt 3D. A joint can be transformed by way of its scale, rotation + and translation properties. Any mesh vertices that are bound to the joint + will have their transformations updated accordingly. +*/ + +/*! + Constructs a new QJoint with \a parent. +*/ +QJoint::QJoint(Qt3DCore::QNode *parent) + : QNode(*new QJointPrivate, parent) +{ +} + +/*! \internal */ +QJoint::~QJoint() +{ +} + +/*! + \property Qt3DCore::QJoint::scale + + Holds the uniform scale of the joint. +*/ +float QJoint::scale() const +{ + Q_D(const QJoint); + return d->m_scale; +} + +/*! + \property Qt3DCore::QJoint::rotation + + Holds the rotation of the joint as QQuaternion. +*/ +QQuaternion QJoint::rotation() const +{ + Q_D(const QJoint); + return d->m_rotation; +} + +/*! + \property Qt3DCore::QJoint::translation + + Holds the translation of the joint as QVector3D. +*/ +QVector3D QJoint::translation() const +{ + Q_D(const QJoint); + return d->m_translation; +} + +void QJoint::setScale(float scale) +{ + Q_D(QJoint); + if (scale == d->m_scale) + return; + + d->m_scale = scale; + emit scaleChanged(scale); +} + +void QJoint::setRotation(const QQuaternion &rotation) +{ + Q_D(QJoint); + if (rotation == d->m_rotation) + return; + + d->m_rotation = rotation; + emit rotationChanged(rotation); +} + +void QJoint::setTranslation(const QVector3D &translation) +{ + Q_D(QJoint); + if (translation == d->m_translation) + return; + + d->m_translation = translation; + emit translationChanged(translation); +} + +/*! + Adds \a joint as a child of this joint. If \a joint has no parent, then + this joint takes ownership of it. Child joints are in the coordinate system + of their parent joint. +*/ +void QJoint::addChildJoint(QJoint *joint) +{ + Q_D(QJoint); + if (!d->m_childJoints.contains(joint)) { + d->m_childJoints.push_back(joint); + // Force creation in backend by setting parent + if (!joint->parent()) + joint->setParent(this); + + // Ensures proper bookkeeping + d->registerDestructionHelper(joint, &QJoint::removeChildJoint, d->m_childJoints); + + if (d->m_changeArbiter != nullptr) { + const auto change = QPropertyNodeAddedChangePtr::create(id(), joint); + change->setPropertyName("childJoint"); + d->notifyObservers(change); + } + } +} + +/*! + Removes \a joint from this joint's list of children. The child joint is not + destroyed. +*/ +void QJoint::removeChildJoint(QJoint *joint) +{ + Q_D(QJoint); + if (d->m_childJoints.contains(joint)) { + + if (d->m_changeArbiter != nullptr) { + const auto change = QPropertyNodeRemovedChangePtr::create(id(), joint); + change->setPropertyName("childJoint"); + d->notifyObservers(change); + } + + d->m_childJoints.removeOne(joint); + + // Remove bookkeeping connection + d->unregisterDestructionHelper(joint); + } +} + +/*! + The vector of joints this joint has as children. +*/ +QVector<QJoint *> QJoint::childJoints() const +{ + Q_D(const QJoint); + return d->m_childJoints; +} + +/*! \internal */ +Qt3DCore::QNodeCreatedChangeBasePtr QJoint::createNodeCreationChange() const +{ + auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QJointData>::create(this); + auto &data = creationChange->data; + Q_D(const QJoint); + data.childJointIds = qIdsForNodes(d->m_childJoints); + data.rotation = d->m_rotation; + data.scale = d->m_scale; + data.translation = d->m_translation; + return creationChange; +} + +} // namespace Qt3DCore + +QT_END_NAMESPACE diff --git a/src/core/transforms/qjoint.h b/src/core/transforms/qjoint.h new file mode 100644 index 000000000..913716380 --- /dev/null +++ b/src/core/transforms/qjoint.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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_QJOINT_H +#define QT3DCORE_QJOINT_H + +#include <Qt3DCore/qnode.h> +#include <Qt3DCore/qt3dcore_global.h> + +#include <QtGui/qquaternion.h> +#include <QtGui/qvector3d.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class QJointPrivate; + +class QT3DCORESHARED_EXPORT QJoint : public QNode +{ + Q_OBJECT + Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged) + Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged) + Q_PROPERTY(QVector3D translation READ translation WRITE setTranslation NOTIFY translationChanged) + +public: + explicit QJoint(Qt3DCore::QNode *parent = nullptr); + ~QJoint(); + + float scale() const; + QQuaternion rotation() const; + QVector3D translation() const; + + void addChildJoint(QJoint *joint); + void removeChildJoint(QJoint *joint); + QVector<QJoint *> childJoints() const; + +public Q_SLOTS: + void setScale(float scale); + void setRotation(const QQuaternion &rotation); + void setTranslation(const QVector3D &translation); + +Q_SIGNALS: + void scaleChanged(float scale); + void rotationChanged(const QQuaternion &rotation); + void translationChanged(const QVector3D &translation); + +private: + Q_DECLARE_PRIVATE(QJoint) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QJOINT_H diff --git a/src/core/transforms/qjoint_p.h b/src/core/transforms/qjoint_p.h new file mode 100644 index 000000000..021824b28 --- /dev/null +++ b/src/core/transforms/qjoint_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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_QJOINT_P_H +#define QT3DCORE_QJOINT_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/qnode_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class QJoint; + +class QJointPrivate : public QNodePrivate +{ +public: + QJointPrivate(); + + Q_DECLARE_PUBLIC(QJoint) + + QVector<QJoint *> m_childJoints; + QQuaternion m_rotation; + QVector3D m_translation; + float m_scale; +}; + +struct QJointData +{ + QNodeIdVector childJointIds; + QQuaternion rotation; + QVector3D translation; + float scale; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QJOINT_P_H diff --git a/src/core/transforms/transforms.pri b/src/core/transforms/transforms.pri index 75ae7c7a9..aa214c693 100644 --- a/src/core/transforms/transforms.pri +++ b/src/core/transforms/transforms.pri @@ -1,10 +1,13 @@ SOURCES += \ - $$PWD/qtransform.cpp + $$PWD/qtransform.cpp \ + $$PWD/qjoint.cpp HEADERS += \ - $$PWD/qtransform.h \ - $$PWD/qtransform_p.h \ - $$PWD/qmath3d_p.h + $$PWD/qtransform.h \ + $$PWD/qtransform_p.h \ + $$PWD/qmath3d_p.h \ + $$PWD/qjoint.h \ + $$PWD/qjoint_p.h INCLUDEPATH += $$PWD |