diff options
author | Antti Määttä <antti.maatta@qt.io> | 2016-09-16 14:10:01 +0300 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-01-31 11:41:59 +0000 |
commit | 59f8fec8a41606b3185fe3a4e276978e3e1ed5ef (patch) | |
tree | f939c83813794a78157bf488a459ac57fe9ab1c2 /src/quick3d | |
parent | 79ec93e56d9067674c108544ef3af041644318d7 (diff) |
Animation support for Qt3D
Modded assimp loader to load animations and to load submeshes into child
entities. Added keyframeanimation for node animations and morphing mesh.
Also added animation group for controlling multiple nodes as one animation
and animation controller to select and play animations.
Assimp loader adds QKeyFrameAnimations targeting an entity as child
objects of that entity, the QAnimationController finds them when the entity
is set and creates QAnimationGroups from based on the animation name.
Change-Id: I7e2e7a4479af49f8023b4a359b2b3118efdaa0da
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d')
15 files changed, 994 insertions, 2 deletions
diff --git a/src/quick3d/imports/extras/defaults.qrc b/src/quick3d/imports/extras/defaults.qrc new file mode 100644 index 000000000..7b07aafab --- /dev/null +++ b/src/quick3d/imports/extras/defaults.qrc @@ -0,0 +1,21 @@ +<RCC> +<qresource prefix="/qt-project.org/imports/Qt3D/Extras/"> +<file alias="defaults/qml/DefaultEffect.qml">defaults/qml/DefaultEffect.qml</file> +<file alias="defaults/qml/DefaultAlphaEffect.qml">defaults/qml/DefaultAlphaEffect.qml</file> +<file alias="defaults/qml/PhongMaterial.qml">defaults/qml/PhongMaterial.qml</file> +<file alias="defaults/qml/DiffuseMapMaterial.qml">defaults/qml/DiffuseMapMaterial.qml</file> +<file alias="defaults/qml/DiffuseSpecularMapMaterial.qml">defaults/qml/DiffuseSpecularMapMaterial.qml</file> +<file alias="defaults/qml/NormalDiffuseMapMaterial.qml">defaults/qml/NormalDiffuseMapMaterial.qml</file> +<file alias="defaults/qml/NormalDiffuseMapAlphaMaterial.qml">defaults/qml/NormalDiffuseMapAlphaMaterial.qml</file> +<file alias="defaults/qml/NormalDiffuseSpecularMapMaterial.qml">defaults/qml/NormalDiffuseSpecularMapMaterial.qml</file> +<file alias="defaults/qml/ForwardRenderer.qml">defaults/qml/ForwardRenderer.qml</file> +<file alias="defaults/qml/PerVertexColorMaterial.qml">defaults/qml/PerVertexColorMaterial.qml</file> +<file alias="defaults/qml/SkyboxEntity.qml">defaults/qml/SkyboxEntity.qml</file> +<file alias="defaults/qml/GoochMaterial.qml">defaults/qml/GoochMaterial.qml</file> +<file alias="defaults/qml/PhongAlphaMaterial.qml">defaults/qml/PhongAlphaMaterial.qml</file> +<file alias="defaults/qml/TextureMaterial.qml">defaults/qml/TextureMaterial.qml</file> +<file alias="defaults/qml/OrbitCameraController.qml">defaults/qml/OrbitCameraController.qml</file> +<file alias="defaults/qml/FirstPersonCameraController.qml">defaults/qml/FirstPersonCameraController.qml</file> +<file alias="defaults/qml/NormalDiffuseMapAlphaEffect.qml">defaults/qml/NormalDiffuseMapAlphaEffect.qml</file> +</qresource> +</RCC> diff --git a/src/quick3d/imports/extras/importsextras.pro b/src/quick3d/imports/extras/importsextras.pro index acc993fa7..6a70238f4 100644 --- a/src/quick3d/imports/extras/importsextras.pro +++ b/src/quick3d/imports/extras/importsextras.pro @@ -3,7 +3,7 @@ TARGET = quick3dextrasplugin TARGETPATH = Qt3D/Extras IMPORT_VERSION = 2.0 -QT += core-private qml qml-private quick quick-private 3dcore 3dcore-private 3dquick 3dquick-private 3dextras 3dlogic +QT += core-private qml qml-private quick quick-private 3dcore 3dcore-private 3dquick 3dquick-private 3dextras 3dlogic 3dquickextras 3dquickextras-private # Qt3D is free of Q_FOREACH - make sure it stays that way: DEFINES += QT_NO_FOREACH diff --git a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp index 7d695ea5b..55af6432b 100644 --- a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp +++ b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp @@ -52,6 +52,19 @@ #include <Qt3DExtras/qcylindergeometry.h> #include <Qt3DExtras/qtext3dgeometry.h> #include <Qt3DExtras/qtext3dmesh.h> +#include <Qt3DExtras/qkeyframeanimation.h> +#include <Qt3DExtras/qanimationcontroller.h> +#include <Qt3DExtras/qabstractanimation.h> +#include <Qt3DExtras/qmorphinganimation.h> +#include <Qt3DExtras/qanimationgroup.h> +#include <Qt3DExtras/qmorphtarget.h> + +#include <Qt3DQuickExtras/private/quick3dkeyframeanimation_p.h> +#include <Qt3DQuickExtras/private/quick3danimationgroup_p.h> +#include <Qt3DQuickExtras/private/quick3danimationcontroller_p.h> +#include <Qt3DQuickExtras/private/quick3dmorphtarget_p.h> +#include <Qt3DQuickExtras/private/quick3dmorphinganimation_p.h> + #include <QtQml/qqml.h> QT_BEGIN_NAMESPACE @@ -106,6 +119,13 @@ void Qt3DQuick3DExtrasPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3DExtras::QText3DGeometry>(uri, 2, 2, "Text3DGeometry"); qmlRegisterType<Qt3DExtras::QText3DMesh>(uri, 2, 2, "Text3DMesh"); + qmlRegisterUncreatableType<Qt3DExtras::QAbstractAnimation>(uri, 2, 0, "AbstractAnimation", QStringLiteral("AbstractAnimation is abstract")); + qmlRegisterExtendedType<Qt3DExtras::QKeyframeAnimation, Qt3DExtras::Quick::QQuick3DKeyframeAnimation>(uri, 2, 2, "KeyframeAnimation"); + qmlRegisterExtendedType<Qt3DExtras::QAnimationGroup, Qt3DExtras::Quick::QQuick3DAnimationGroup>(uri, 2, 2, "AnimationGroup"); + qmlRegisterExtendedType<Qt3DExtras::QAnimationController, Qt3DExtras::Quick::QQuick3DAnimationController>(uri, 2, 2, "AnimationController"); + qmlRegisterExtendedType<Qt3DExtras::QMorphingAnimation, Qt3DExtras::Quick::QQuick3DMorphingAnimation>(uri, 2, 2, "MorphingAnimation"); + qmlRegisterExtendedType<Qt3DExtras::QMorphTarget, Qt3DExtras::Quick::QQuick3DMorphTarget>(uri, 2, 2, "MorphTarget"); + // Register types provided as QML files compiled into the plugin for (int i = 0; i < int(sizeof(qmldir) / sizeof(qmldir[0])); i++) { auto path = QLatin1String("qrc:/qt-project.org/imports/Qt3D/Extras/defaults/qml/"); diff --git a/src/quick3d/quick3dextras/items/items.pri b/src/quick3d/quick3dextras/items/items.pri new file mode 100644 index 000000000..cdb1e1245 --- /dev/null +++ b/src/quick3d/quick3dextras/items/items.pri @@ -0,0 +1,15 @@ +HEADERS += \ + $$PWD/quick3danimationcontroller_p.h \ + $$PWD/quick3danimationgroup_p.h \ + $$PWD/quick3dkeyframeanimation_p.h \ + $$PWD/quick3dmorphinganimation_p.h \ + $$PWD/quick3dmorphtarget_p.h + +SOURCES += \ + $$PWD/quick3danimationcontroller.cpp \ + $$PWD/quick3danimationgroup.cpp \ + $$PWD/quick3dkeyframeanimation.cpp \ + $$PWD/quick3dmorphinganimation.cpp \ + $$PWD/quick3dmorphtarget.cpp + +INCLUDEPATH += $$PWD diff --git a/src/quick3d/quick3dextras/items/quick3danimationcontroller.cpp b/src/quick3d/quick3dextras/items/quick3danimationcontroller.cpp new file mode 100644 index 000000000..4aceb0d55 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3danimationcontroller.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3danimationcontroller_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +QQuick3DAnimationController::QQuick3DAnimationController(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<QAnimationGroup> QQuick3DAnimationController::animationGroups() +{ + return QQmlListProperty<QAnimationGroup>(this, 0, + &QQuick3DAnimationController::appendAnimationGroup, + &QQuick3DAnimationController::animationGroupCount, + &QQuick3DAnimationController::animationGroupAt, + &QQuick3DAnimationController::clearAnimationGroups); +} + + +void QQuick3DAnimationController::appendAnimationGroup(QQmlListProperty<QAnimationGroup> *list, QAnimationGroup *bar) +{ + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + controller->parentAnimationController()->addAnimationGroup(bar); +} + +int QQuick3DAnimationController::animationGroupCount(QQmlListProperty<QAnimationGroup> *list) +{ + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + return controller->parentAnimationController()->animationGroupList().count(); + return 0; +} + +QAnimationGroup *QQuick3DAnimationController::animationGroupAt(QQmlListProperty<QAnimationGroup> *list, int index) +{ + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) + return qobject_cast<QAnimationGroup *>(controller->parentAnimationController()->getGroup(index)); + return nullptr; +} + +void QQuick3DAnimationController::clearAnimationGroups(QQmlListProperty<QAnimationGroup> *list) +{ + QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object); + if (controller) { + QVector<QAnimationGroup *> emptyList; + controller->parentAnimationController()->setAnimationGroups(emptyList); + } +} + + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3dextras/items/quick3danimationcontroller_p.h b/src/quick3d/quick3dextras/items/quick3danimationcontroller_p.h new file mode 100644 index 000000000..82ad29e2c --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3danimationcontroller_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QUICK_QUICK3DANIMATIONCONTROLLER_P_H +#define QT3DEXTRAS_QUICK_QUICK3DANIMATIONCONTROLLER_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 <QQmlListProperty> +#include <Qt3DExtras/QAnimationController> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +class QT3DQUICKEXTRASSHARED_EXPORT QQuick3DAnimationController : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DExtras::QAnimationGroup> animationGroups READ animationGroups) + +public: + + explicit QQuick3DAnimationController(QObject *parent = nullptr); + + inline Qt3DExtras::QAnimationController *parentAnimationController() const + { + return qobject_cast<Qt3DExtras::QAnimationController *>(parent()); + } + + QQmlListProperty<Qt3DExtras::QAnimationGroup> animationGroups(); + +private: + + static void appendAnimationGroup(QQmlListProperty<Qt3DExtras::QAnimationGroup> *list, Qt3DExtras::QAnimationGroup *bar); + static QAnimationGroup *animationGroupAt(QQmlListProperty<Qt3DExtras::QAnimationGroup> *list, int index); + static int animationGroupCount(QQmlListProperty<Qt3DExtras::QAnimationGroup> *list); + static void clearAnimationGroups(QQmlListProperty<Qt3DExtras::QAnimationGroup> *list); +}; + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_QUICK_QUICK3DEFFECT_P_H diff --git a/src/quick3d/quick3dextras/items/quick3danimationgroup.cpp b/src/quick3d/quick3dextras/items/quick3danimationgroup.cpp new file mode 100644 index 000000000..3e3813227 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3danimationgroup.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3danimationgroup_p.h" + +#include <Qt3DExtras/qabstractanimation.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +QQuick3DAnimationGroup::QQuick3DAnimationGroup(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<Qt3DExtras::QAbstractAnimation> QQuick3DAnimationGroup::animations() +{ + return QQmlListProperty<Qt3DExtras::QAbstractAnimation>(this, 0, + &QQuick3DAnimationGroup::appendAnimation, + &QQuick3DAnimationGroup::animationCount, + &QQuick3DAnimationGroup::animationAt, + &QQuick3DAnimationGroup::clearAnimation); +} + + +void QQuick3DAnimationGroup::appendAnimation(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list, + Qt3DExtras::QAbstractAnimation *animation) +{ + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) + animationGroup->parentAnimationGroup()->addAnimation(animation); +} + +int QQuick3DAnimationGroup::animationCount(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list) +{ + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) + return animationGroup->parentAnimationGroup()->animationList().count(); + return 0; +} + +Qt3DExtras::QAbstractAnimation *QQuick3DAnimationGroup::animationAt(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list, int index) +{ + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) { + return qobject_cast<Qt3DExtras::QAbstractAnimation *>( + animationGroup->parentAnimationGroup()->animationList().at(index)); + } + return nullptr; +} + +void QQuick3DAnimationGroup::clearAnimation(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list) +{ + QQuick3DAnimationGroup *animationGroup = qobject_cast<QQuick3DAnimationGroup *>(list->object); + if (animationGroup) { + QVector<Qt3DExtras::QAbstractAnimation *> emptyList; + animationGroup->parentAnimationGroup()->setAnimations(emptyList); + } +} + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3dextras/items/quick3danimationgroup_p.h b/src/quick3d/quick3dextras/items/quick3danimationgroup_p.h new file mode 100644 index 000000000..c7140c946 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3danimationgroup_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QUICK_QUICK3DANIMATIONGROUP_P_H +#define QT3DEXTRAS_QUICK_QUICK3DANIMATIONGROUP_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 <QtQml/qqmllist.h> +#include <Qt3DExtras/qabstractanimation.h> +#include <Qt3DExtras/qanimationgroup.h> + +#include <Qt3DQuickExtras/qt3dquickextras_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +class QT3DQUICKEXTRASSHARED_EXPORT QQuick3DAnimationGroup : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DExtras::QAbstractAnimation> animations READ animations) + +public: + + explicit QQuick3DAnimationGroup(QObject *parent = nullptr); + + inline Qt3DExtras::QAnimationGroup *parentAnimationGroup() const + { + return qobject_cast<Qt3DExtras::QAnimationGroup *>(parent()); + } + + QQmlListProperty<Qt3DExtras::QAbstractAnimation> animations(); + +private: + + static void appendAnimation(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list, Qt3DExtras::QAbstractAnimation *animation); + static Qt3DExtras::QAbstractAnimation *animationAt(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list, int index); + static int animationCount(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list); + static void clearAnimation(QQmlListProperty<Qt3DExtras::QAbstractAnimation> *list); +}; + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_QUICK_QUICK3DEFFECT_P_H diff --git a/src/quick3d/quick3dextras/items/quick3dkeyframeanimation.cpp b/src/quick3d/quick3dextras/items/quick3dkeyframeanimation.cpp new file mode 100644 index 000000000..cfd9ca7d2 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dkeyframeanimation.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3dkeyframeanimation_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +QQuick3DKeyframeAnimation::QQuick3DKeyframeAnimation(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<Qt3DCore::QTransform> QQuick3DKeyframeAnimation::keyframes() +{ + return QQmlListProperty<Qt3DCore::QTransform>(this, 0, + &QQuick3DKeyframeAnimation::appendKeyframe, + &QQuick3DKeyframeAnimation::keyframeCount, + &QQuick3DKeyframeAnimation::keyframeAt, + &QQuick3DKeyframeAnimation::clearKeyframes); +} + +void QQuick3DKeyframeAnimation::appendKeyframe(QQmlListProperty<Qt3DCore::QTransform> *list, + Qt3DCore::QTransform *transform) +{ + QQuick3DKeyframeAnimation *keyframeAnimation + = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); + if (keyframeAnimation) + keyframeAnimation->parentKeyframeAnimation()->addKeyframe(transform); +} + +int QQuick3DKeyframeAnimation::keyframeCount(QQmlListProperty<Qt3DCore::QTransform> *list) +{ + QQuick3DKeyframeAnimation *keyframeAnimation + = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); + if (keyframeAnimation) + return keyframeAnimation->parentKeyframeAnimation()->keyframeList().count(); + return 0; +} + +Qt3DCore::QTransform *QQuick3DKeyframeAnimation::keyframeAt(QQmlListProperty<Qt3DCore::QTransform> *list, + int index) +{ + QQuick3DKeyframeAnimation *keyframeAnimation + = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); + if (keyframeAnimation) { + return qobject_cast<Qt3DCore::QTransform *>( + keyframeAnimation->parentKeyframeAnimation()->keyframeList().at(index)); + } + return nullptr; +} + +void QQuick3DKeyframeAnimation::clearKeyframes(QQmlListProperty<Qt3DCore::QTransform> *list) +{ + QQuick3DKeyframeAnimation *keyframeAnimation + = qobject_cast<QQuick3DKeyframeAnimation *>(list->object); + if (keyframeAnimation) { + QVector<Qt3DCore::QTransform *> emptyList; + keyframeAnimation->parentKeyframeAnimation()->setKeyframes(emptyList); + } +} + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3dextras/items/quick3dkeyframeanimation_p.h b/src/quick3d/quick3dextras/items/quick3dkeyframeanimation_p.h new file mode 100644 index 000000000..e8309de9e --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dkeyframeanimation_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QUICK_QUICK3DKEYFRAMEANIMATION_P_H +#define QT3DEXTRAS_QUICK_QUICK3DKEYFRAMEANIMATION_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 <QtQml/qqmllist.h> + +#include <Qt3DExtras/qkeyframeanimation.h> + +#include <Qt3DQuickExtras/qt3dquickextras_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +class QT3DQUICKEXTRASSHARED_EXPORT QQuick3DKeyframeAnimation : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DCore::QTransform> keyframes READ keyframes) + +public: + QQuick3DKeyframeAnimation(QObject *parent = nullptr); + + inline QKeyframeAnimation *parentKeyframeAnimation() const + { + return qobject_cast<QKeyframeAnimation *>(parent()); + } + + QQmlListProperty<Qt3DCore::QTransform> keyframes(); + +private: + + static void appendKeyframe(QQmlListProperty<Qt3DCore::QTransform> *list, + Qt3DCore::QTransform *transform); + static Qt3DCore::QTransform *keyframeAt(QQmlListProperty<Qt3DCore::QTransform> *list, + int index); + static int keyframeCount(QQmlListProperty<Qt3DCore::QTransform> *list); + static void clearKeyframes(QQmlListProperty<Qt3DCore::QTransform> *list); +}; + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QUICK_QUICK3DKEYFRAMEANIMATION_P_H diff --git a/src/quick3d/quick3dextras/items/quick3dmorphinganimation.cpp b/src/quick3d/quick3dextras/items/quick3dmorphinganimation.cpp new file mode 100644 index 000000000..61636f06d --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dmorphinganimation.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3dmorphinganimation_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +QQuick3DMorphingAnimation::QQuick3DMorphingAnimation(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<Qt3DExtras::QMorphTarget> QQuick3DMorphingAnimation::morphTargets() +{ + return QQmlListProperty<Qt3DExtras::QMorphTarget>(this, 0, + &QQuick3DMorphingAnimation::appendMorphTarget, + &QQuick3DMorphingAnimation::morphTargetCount, + &QQuick3DMorphingAnimation::morphTargetAt, + &QQuick3DMorphingAnimation::clearMorphTargets); +} + +void QQuick3DMorphingAnimation::appendMorphTarget(QQmlListProperty<Qt3DExtras::QMorphTarget> *list, + Qt3DExtras::QMorphTarget *morphTarget) +{ + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) + animation->parentMorphingAnimation()->addMorphTarget(morphTarget); +} + +int QQuick3DMorphingAnimation::morphTargetCount(QQmlListProperty<Qt3DExtras::QMorphTarget> *list) +{ + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) + return animation->parentMorphingAnimation()->morphTargetList().count(); + return 0; +} + +Qt3DExtras::QMorphTarget *QQuick3DMorphingAnimation::morphTargetAt(QQmlListProperty<Qt3DExtras::QMorphTarget> *list, + int index) +{ + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) { + return qobject_cast<Qt3DExtras::QMorphTarget *>( + animation->parentMorphingAnimation()->morphTargetList().at(index)); + } + return nullptr; +} + +void QQuick3DMorphingAnimation::clearMorphTargets(QQmlListProperty<Qt3DExtras::QMorphTarget> *list) +{ + QQuick3DMorphingAnimation *animation = qobject_cast<QQuick3DMorphingAnimation *>(list->object); + if (animation) { + QVector<Qt3DExtras::QMorphTarget *> emptyList; + animation->parentMorphingAnimation()->setMorphTargets(emptyList); + } +} + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3dextras/items/quick3dmorphinganimation_p.h b/src/quick3d/quick3dextras/items/quick3dmorphinganimation_p.h new file mode 100644 index 000000000..5f052fd04 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dmorphinganimation_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QUICK_QUICK3DMORPHINGANIMATION_P_H +#define QT3DEXTRAS_QUICK_QUICK3DMORPHINGANIMATION_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 <QtQml/qqmllist.h> + +#include <Qt3DExtras/qmorphinganimation.h> + +#include <Qt3DQuickExtras/qt3dquickextras_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +class QT3DQUICKEXTRASSHARED_EXPORT QQuick3DMorphingAnimation : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DExtras::QMorphTarget> morphTargets READ morphTargets) + +public: + QQuick3DMorphingAnimation(QObject *parent = nullptr); + + inline QMorphingAnimation *parentMorphingAnimation() const + { + return qobject_cast<QMorphingAnimation *>(parent()); + } + + QQmlListProperty<Qt3DExtras::QMorphTarget> morphTargets(); + +private: + + static void appendMorphTarget(QQmlListProperty<Qt3DExtras::QMorphTarget> *list, + Qt3DExtras::QMorphTarget *morphTarget); + static Qt3DExtras::QMorphTarget *morphTargetAt(QQmlListProperty<Qt3DExtras::QMorphTarget> *list, + int index); + static int morphTargetCount(QQmlListProperty<Qt3DExtras::QMorphTarget> *list); + static void clearMorphTargets(QQmlListProperty<Qt3DExtras::QMorphTarget> *list); +}; + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QUICK_QUICK3DMORPHINGANIMATION_P_H diff --git a/src/quick3d/quick3dextras/items/quick3dmorphtarget.cpp b/src/quick3d/quick3dextras/items/quick3dmorphtarget.cpp new file mode 100644 index 000000000..8c1b9f0c1 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dmorphtarget.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3dmorphtarget_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +QQuick3DMorphTarget::QQuick3DMorphTarget(QObject *parent) + : QObject(parent) +{ +} + +QQmlListProperty<Qt3DRender::QAttribute> QQuick3DMorphTarget::attributes() +{ + return QQmlListProperty<Qt3DRender::QAttribute>(this, 0, + &QQuick3DMorphTarget::appendAttribute, + &QQuick3DMorphTarget::attributeCount, + &QQuick3DMorphTarget::attributeAt, + &QQuick3DMorphTarget::clearAttributes); +} + +void QQuick3DMorphTarget::appendAttribute(QQmlListProperty<Qt3DRender::QAttribute> *list, Qt3DRender::QAttribute *bar) +{ + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) + target->parentMorphTarget()->addAttribute(bar); +} + +int QQuick3DMorphTarget::attributeCount(QQmlListProperty<Qt3DRender::QAttribute> *list) +{ + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) + return target->parentMorphTarget()->attributeList().count(); + return 0; +} + +Qt3DRender::QAttribute *QQuick3DMorphTarget::attributeAt(QQmlListProperty<Qt3DRender::QAttribute> *list, int index) +{ + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) + return qobject_cast<Qt3DRender::QAttribute *>(target->parentMorphTarget()->attributeList().at(index)); + return nullptr; +} + +void QQuick3DMorphTarget::clearAttributes(QQmlListProperty<Qt3DRender::QAttribute> *list) +{ + QQuick3DMorphTarget *target = qobject_cast<QQuick3DMorphTarget *>(list->object); + if (target) { + QVector<Qt3DRender::QAttribute *> emptyList; + target->parentMorphTarget()->setAttributes(emptyList); + } +} + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3dextras/items/quick3dmorphtarget_p.h b/src/quick3d/quick3dextras/items/quick3dmorphtarget_p.h new file mode 100644 index 000000000..e5c664370 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dmorphtarget_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QUICK_QUICK3DMORPHTARGET_P_H +#define QT3DEXTRAS_QUICK_QUICK3DMORPHTARGET_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 <QQmlListProperty> +#include <Qt3DExtras/QMorphTarget> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Quick { + +class QT3DQUICKEXTRASSHARED_EXPORT QQuick3DMorphTarget : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DRender::QAttribute> attributes READ attributes) + +public: + QQuick3DMorphTarget(QObject *parent = nullptr); + + inline QMorphTarget *parentMorphTarget() const { return qobject_cast<QMorphTarget *>(parent()); } + + QQmlListProperty<Qt3DRender::QAttribute> attributes(); + +private: + + static void appendAttribute(QQmlListProperty<Qt3DRender::QAttribute> *list, Qt3DRender::QAttribute *bar); + static Qt3DRender::QAttribute *attributeAt(QQmlListProperty<Qt3DRender::QAttribute> *list, int index); + static int attributeCount(QQmlListProperty<Qt3DRender::QAttribute> *list); + static void clearAttributes(QQmlListProperty<Qt3DRender::QAttribute> *list); +}; + +} // namespace Quick +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QUICK_QUICK3DMORPHTARGET_P_H diff --git a/src/quick3d/quick3dextras/quick3dextras.pro b/src/quick3d/quick3dextras/quick3dextras.pro index 8965e9f5d..4f103765c 100644 --- a/src/quick3d/quick3dextras/quick3dextras.pro +++ b/src/quick3d/quick3dextras/quick3dextras.pro @@ -1,7 +1,7 @@ TARGET = Qt3DQuickExtras MODULE = 3dquickextras -QT += core core-private qml qml-private 3dcore 3dinput 3dquick 3drender 3drender-private 3dlogic +QT += core core-private qml qml-private 3dcore 3dinput 3dquick 3drender 3drender-private 3dlogic 3dextras CONFIG -= precompile_header # Qt3D is free of Q_FOREACH - make sure it stays that way: @@ -23,4 +23,6 @@ HEADERS += \ # otherwise mingw headers do not declare common functions like ::strcasecmp win32-g++*:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x +include(./items/items.pri) + load(qt_module) |