diff options
Diffstat (limited to 'src/animation/backend')
22 files changed, 344 insertions, 190 deletions
diff --git a/src/animation/backend/abstractevaluateclipanimatorjob.cpp b/src/animation/backend/abstractevaluateclipanimatorjob.cpp new file mode 100644 index 000000000..236a96efe --- /dev/null +++ b/src/animation/backend/abstractevaluateclipanimatorjob.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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 "abstractevaluateclipanimatorjob_p.h" +#include <Qt3DCore/private/qaspectjob_p.h> +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DCore/private/qskeleton_p.h> +#include <Qt3DAnimation/qabstractclipanimator.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +class AbstractEvaluateClipAnimatorJobPrivate : public Qt3DCore::QAspectJobPrivate +{ +public: + AbstractEvaluateClipAnimatorJobPrivate() { } + ~AbstractEvaluateClipAnimatorJobPrivate() override { } + + void postFrame(Qt3DCore::QAspectManager *manager) override; + + Q_DECLARE_PUBLIC(AbstractEvaluateClipAnimatorJob) + + AnimationRecord m_record; + QVector<AnimationCallbackAndValue> m_callbacks; + +private: + AbstractEvaluateClipAnimatorJob *q_ptr; +}; + +AbstractEvaluateClipAnimatorJob::AbstractEvaluateClipAnimatorJob() + : Qt3DCore::QAspectJob(*new AbstractEvaluateClipAnimatorJobPrivate) +{ +} + +void AbstractEvaluateClipAnimatorJob::setPostFrameData(const AnimationRecord &record, const QVector<AnimationCallbackAndValue> &callbacks) +{ + auto mainThreadCB = callbacks; + mainThreadCB.erase(std::remove_if(mainThreadCB.begin(), mainThreadCB.end(), [](const AnimationCallbackAndValue &callback) { + if (callback.flags.testFlag(QAnimationCallback::OnThreadPool)) { + // call these now and remove them from the list + callback.callback->valueChanged(callback.value); + return true; + } + return false; + }), mainThreadCB.end()); + // Should now only have callbacks to be called on main thread + + Q_D(AbstractEvaluateClipAnimatorJob); + d->m_record = record; + d->m_callbacks = mainThreadCB; +} + +void AbstractEvaluateClipAnimatorJobPrivate::postFrame(Qt3DCore::QAspectManager *manager) +{ + if (m_record.animatorId.isNull()) + return; + + for (auto targetData : qAsConst(m_record.targetChanges)) { + Qt3DCore::QNode *node = manager->lookupNode(targetData.targetId); + if (node) + node->setProperty(targetData.propertyName, targetData.value); + } + + for (auto skeletonData : qAsConst(m_record.skeletonChanges)) { + Qt3DCore::QAbstractSkeleton *node = qobject_cast<Qt3DCore::QAbstractSkeleton *>(manager->lookupNode(skeletonData.first)); + if (node) { + auto d = Qt3DCore::QAbstractSkeletonPrivate::get(node); + d->m_localPoses = skeletonData.second; + d->update(); + } + } + + QAbstractClipAnimator *animator = qobject_cast<QAbstractClipAnimator *>(manager->lookupNode(m_record.animatorId)); + if (animator) { + if (isValidNormalizedTime(m_record.normalizedTime)) + animator->setNormalizedTime(m_record.normalizedTime); + if (m_record.finalFrame) + animator->setRunning(false); + } + + for (const AnimationCallbackAndValue &callback: qAsConst(m_callbacks)) { + if (callback.callback) + callback.callback->valueChanged(callback.value); + } + + m_record = {}; +} + +} // Animation +} // Qt3DAnimation + +QT_END_NAMESPACE diff --git a/src/animation/backend/abstractevaluateclipanimatorjob_p.h b/src/animation/backend/abstractevaluateclipanimatorjob_p.h new file mode 100644 index 000000000..2a8914faa --- /dev/null +++ b/src/animation/backend/abstractevaluateclipanimatorjob_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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 QT3DANIMATION_ANIMATION_ABSTRACTEVALUATECLIPANIMATORJOB_P_H +#define QT3DANIMATION_ANIMATION_ABSTRACTEVALUATECLIPANIMATORJOB_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/qaspectjob.h> +#include <Qt3DAnimation/private/animationutils_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DAnimation { +namespace Animation { + +class AbstractEvaluateClipAnimatorJobPrivate; + +class AbstractEvaluateClipAnimatorJob : public Qt3DCore::QAspectJob +{ +protected: + AbstractEvaluateClipAnimatorJob(); + + void setPostFrameData(const AnimationRecord &record, const QVector<AnimationCallbackAndValue> &callbacks); + +private: + Q_DECLARE_PRIVATE(AbstractEvaluateClipAnimatorJob) +}; + +} // Animation +} // Qt3DAnimation + +QT_END_NAMESPACE + +#endif // QT3DANIMATION_ANIMATION_ABSTRACTEVALUATECLIPANIMATORJOB_P_H diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp index 690972075..2dea81b52 100644 --- a/src/animation/backend/animationclip.cpp +++ b/src/animation/backend/animationclip.cpp @@ -43,7 +43,6 @@ #include <Qt3DAnimation/private/managers_p.h> #include <Qt3DAnimation/private/gltfimporter_p.h> #include <Qt3DRender/private/qurlhelper_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> #include <QtCore/qbytearray.h> #include <QtCore/qfile.h> @@ -90,11 +89,6 @@ void AnimationClip::setStatus(QAnimationClipLoader::Status status) { if (status != m_status) { m_status = status; - Qt3DCore::QPropertyUpdatedChangePtr e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("status"); - e->setValue(QVariant::fromValue(m_status)); - notifyObservers(e); } } @@ -124,7 +118,7 @@ void AnimationClip::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool first Q_ASSERT(m_dataType == File); if (m_source != loaderNode->source()) { m_source = loaderNode->source(); - if (m_clipData.isValid()) + if (!m_source.isEmpty()) setDirty(Handler::AnimationClipDirty); } } @@ -317,13 +311,6 @@ void AnimationClip::setDuration(float duration) return; m_duration = duration; - - // Send a change to the frontend - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("duration"); - e->setValue(m_duration); - notifyObservers(e); } int AnimationClip::channelIndex(const QString &channelName, int jointIndex) const diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index 24c484dc2..80c296a89 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -40,8 +40,6 @@ #include <Qt3DAnimation/private/clipblendnode_p.h> #include <Qt3DAnimation/private/clipblendnodevisitor_p.h> #include <Qt3DAnimation/private/clipblendvalue_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> -#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h> #include <QtGui/qvector2d.h> #include <QtGui/qvector3d.h> #include <QtGui/qvector4d.h> @@ -407,13 +405,17 @@ QVariant buildPropertyValue(const MappingData &mappingData, const QVector<float> return QVariant(); } -QVector<Qt3DCore::QSceneChangePtr> preparePropertyChanges(Qt3DCore::QNodeId animatorId, - const QVector<MappingData> &mappingDataVec, - const QVector<float> &channelResults, - bool finalFrame, - float normalizedLocalTime) +AnimationRecord prepareAnimationRecord(Qt3DCore::QNodeId animatorId, + const QVector<MappingData> &mappingDataVec, + const QVector<float> &channelResults, + bool finalFrame, + float normalizedLocalTime) { - QVector<Qt3DCore::QSceneChangePtr> changes; + AnimationRecord record; + record.finalFrame = finalFrame; + record.animatorId = animatorId; + record.normalizedTime = normalizedLocalTime; + QVarLengthArray<Skeleton *, 4> dirtySkeletons; // Iterate over the mappings @@ -453,43 +455,14 @@ QVector<Qt3DCore::QSceneChangePtr> preparePropertyChanges(Qt3DCore::QNodeId anim break; } } else { - // TODOSYNC remove once we've found a way to propagate animation changes - // Construct a property update change, set target, property and delivery options - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(mappingData.targetId); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName(mappingData.propertyName); - // Handle intermediate updates vs final flag properly - Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isIntermediate = !finalFrame; - // Assign new value and send - e->setValue(v); - changes.push_back(e); + record.targetChanges.push_back({mappingData.targetId, mappingData.propertyName, v}); } } for (const auto skeleton : dirtySkeletons) - skeleton->sendLocalPoses(); - - if (isValidNormalizedTime(normalizedLocalTime)) { - // TODOSYNC remove once we've found a way to propagate animation changes - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(animatorId); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("normalizedTime"); - e->setValue(normalizedLocalTime); - Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(e.data())->m_isIntermediate = !finalFrame; - changes.push_back(e); - } - - // If it's the final frame, notify the frontend that we've stopped - if (finalFrame) { - // TODOSYNC remove once we've found a way to propagate animation changes - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(animatorId); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("running"); - e->setValue(false); - changes.push_back(e); - } + record.skeletonChanges.push_back({skeleton->peerId(), skeleton->joints()}); - return changes; + return record; } QVector<AnimationCallbackAndValue> prepareCallbacks(const QVector<MappingData> &mappingDataVec, diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h index 90b3efa46..8c71e704a 100644 --- a/src/animation/backend/animationutils_p.h +++ b/src/animation/backend/animationutils_p.h @@ -53,6 +53,7 @@ #include <Qt3DAnimation/qanimationcallback.h> #include <Qt3DCore/qnodeid.h> #include <Qt3DCore/qscenechange.h> +#include <Qt3DCore/private/sqt_p.h> #include <QtCore/qbitarray.h> #include <QtCore/qdebug.h> @@ -183,7 +184,7 @@ struct ChannelNameAndType case Rotation: componentCount = 4; break; - }; + } } bool operator==(const ChannelNameAndType &rhs) const @@ -264,6 +265,32 @@ struct AnimationCallbackAndValue QVariant value; }; +struct AnimationRecord { + struct TargetChange { + TargetChange(Qt3DCore::QNodeId id, const char *name, QVariant v) + : targetId(id), propertyName(name), value(v) { + + } + + Qt3DCore::QNodeId targetId; + const char *propertyName = nullptr; + QVariant value; + }; + + Qt3DCore::QNodeId animatorId; + QVector<TargetChange> targetChanges; + QVector<QPair<Qt3DCore::QNodeId, QVector<Qt3DCore::Sqt>>> skeletonChanges; + float normalizedTime = -1.f; + bool finalFrame = false; +}; + +Q_AUTOTEST_EXPORT +AnimationRecord prepareAnimationRecord(Qt3DCore::QNodeId animatorId, + const QVector<MappingData> &mappingDataVec, + const QVector<float> &channelResults, + bool finalFrame, + float normalizedLocalTime); + inline constexpr double toSecs(qint64 nsecs) { return nsecs / 1.0e9; } inline qint64 toNsecs(double seconds) { return qRound64(seconds * 1.0e9); } @@ -328,12 +355,6 @@ ClipResults evaluateClipAtPhase(AnimationClip *clip, float phase); Q_AUTOTEST_EXPORT -QVector<Qt3DCore::QSceneChangePtr> preparePropertyChanges(Qt3DCore::QNodeId animatorId, - const QVector<MappingData> &mappingDataVec, - const QVector<float> &channelResults, - bool finalFrame, float normalizedLocalTime); - -Q_AUTOTEST_EXPORT QVector<AnimationCallbackAndValue> prepareCallbacks(const QVector<MappingData> &mappingDataVec, const QVector<float> &channelResults); @@ -390,5 +411,7 @@ void applyComponentDefaultValues(const QVector<ComponentValue> &componentDefault QT_END_NAMESPACE +Q_DECLARE_METATYPE(Qt3DAnimation::Animation::AnimationRecord) // LCOV_EXCL_LINE + #endif // QT3DANIMATION_ANIMATION_ANIMATIONUTILS_P_H diff --git a/src/animation/backend/backend.pri b/src/animation/backend/backend.pri index cc1104102..ef7da55f0 100644 --- a/src/animation/backend/backend.pri +++ b/src/animation/backend/backend.pri @@ -17,6 +17,7 @@ HEADERS += \ $$PWD/channelmapping_p.h \ $$PWD/channelmapper_p.h \ $$PWD/findrunningclipanimatorsjob_p.h \ + $$PWD/abstractevaluateclipanimatorjob_p.h \ $$PWD/evaluateclipanimatorjob_p.h \ $$PWD/clipblendnode_p.h \ $$PWD/clipblendnodevisitor_p.h \ @@ -43,6 +44,7 @@ SOURCES += \ $$PWD/channelmapping.cpp \ $$PWD/channelmapper.cpp \ $$PWD/findrunningclipanimatorsjob.cpp \ + $$PWD/abstractevaluateclipanimatorjob.cpp \ $$PWD/evaluateclipanimatorjob.cpp \ $$PWD/clipblendnode.cpp \ $$PWD/managers.cpp \ diff --git a/src/animation/backend/blendedclipanimator.cpp b/src/animation/backend/blendedclipanimator.cpp index 254883478..7d771745b 100644 --- a/src/animation/backend/blendedclipanimator.cpp +++ b/src/animation/backend/blendedclipanimator.cpp @@ -40,8 +40,6 @@ #include <Qt3DAnimation/qclock.h> #include <Qt3DAnimation/qabstractclipblendnode.h> #include <Qt3DAnimation/private/qblendedclipanimator_p.h> -#include <Qt3DAnimation/private/qanimationcallbacktrigger_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> QT_BEGIN_NAMESPACE @@ -123,27 +121,6 @@ void BlendedClipAnimator::setRunning(bool running) setDirty(Handler::BlendedClipAnimatorDirty); } -void BlendedClipAnimator::sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes) -{ - for (const Qt3DCore::QSceneChangePtr &change : changes) - notifyObservers(change); -} - -void BlendedClipAnimator::sendCallbacks(const QVector<AnimationCallbackAndValue> &callbacks) -{ - for (const AnimationCallbackAndValue &callback : callbacks) { - if (callback.flags.testFlag(QAnimationCallback::OnThreadPool)) { - callback.callback->valueChanged(callback.value); - } else { - auto e = QAnimationCallbackTriggerPtr::create(peerId()); - e->setCallback(callback.callback); - e->setValue(callback.value); - e->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes); - notifyObservers(e); - } - } -} - Qt3DCore::QNodeId BlendedClipAnimator::blendTreeRootId() const { diff --git a/src/animation/backend/blendedclipanimator_p.h b/src/animation/backend/blendedclipanimator_p.h index f47b55796..04f609438 100644 --- a/src/animation/backend/blendedclipanimator_p.h +++ b/src/animation/backend/blendedclipanimator_p.h @@ -92,9 +92,6 @@ public: void setMappingData(const QVector<MappingData> &mappingData) { m_mappingData = mappingData; } QVector<MappingData> mappingData() const { return m_mappingData; } - void sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes); - void sendCallbacks(const QVector<AnimationCallbackAndValue> &callbacks); - void animationClipMarkedDirty() { setDirty(Handler::BlendedClipAnimatorDirty); } qint64 nsSincePreviousFrame(qint64 currentGlobalTimeNS); diff --git a/src/animation/backend/channelmapper.cpp b/src/animation/backend/channelmapper.cpp index 7ea07557b..e5d4eb009 100644 --- a/src/animation/backend/channelmapper.cpp +++ b/src/animation/backend/channelmapper.cpp @@ -40,9 +40,6 @@ #include <Qt3DAnimation/private/qchannelmapper_p.h> #include <Qt3DAnimation/private/animationlogging_p.h> #include <Qt3DAnimation/private/managers_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> -#include <Qt3DCore/qpropertynodeaddedchange.h> -#include <Qt3DCore/qpropertynoderemovedchange.h> #include <algorithm> diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp index b6bcc9239..32b02d2bb 100644 --- a/src/animation/backend/clipanimator.cpp +++ b/src/animation/backend/clipanimator.cpp @@ -42,9 +42,6 @@ #include <Qt3DAnimation/private/animationclip_p.h> #include <Qt3DAnimation/private/managers_p.h> #include <Qt3DAnimation/private/animationlogging_p.h> -#include <Qt3DAnimation/private/qanimationcallbacktrigger_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> -#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h> QT_BEGIN_NAMESPACE @@ -146,27 +143,6 @@ void ClipAnimator::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstT setDirty(Handler::ClipAnimatorDirty); } -void ClipAnimator::sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes) -{ - for (const Qt3DCore::QSceneChangePtr &change : changes) - notifyObservers(change); -} - -void ClipAnimator::sendCallbacks(const QVector<AnimationCallbackAndValue> &callbacks) -{ - for (const AnimationCallbackAndValue &callback : callbacks) { - if (callback.flags.testFlag(QAnimationCallback::OnThreadPool)) { - callback.callback->valueChanged(callback.value); - } else { - auto e = QAnimationCallbackTriggerPtr::create(peerId()); - e->setCallback(callback.callback); - e->setValue(callback.value); - e->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes); - notifyObservers(e); - } - } -} - qint64 ClipAnimator::nsSincePreviousFrame(qint64 currentGlobalTimeNS) { return currentGlobalTimeNS - m_lastGlobalTimeNS; diff --git a/src/animation/backend/clipanimator_p.h b/src/animation/backend/clipanimator_p.h index 54d1527a4..d154bdab9 100644 --- a/src/animation/backend/clipanimator_p.h +++ b/src/animation/backend/clipanimator_p.h @@ -93,9 +93,6 @@ public: int currentLoop() const { return m_currentLoop; } void setCurrentLoop(int currentLoop) { m_currentLoop = currentLoop; } - void sendPropertyChanges(const QVector<Qt3DCore::QSceneChangePtr> &changes); - void sendCallbacks(const QVector<AnimationCallbackAndValue> &callbacks); - void animationClipMarkedDirty() { setDirty(Handler::ClipAnimatorDirty); } void setClipFormat(const ClipFormat &clipFormat) { m_clipFormat = clipFormat; } diff --git a/src/animation/backend/clipblendnode.cpp b/src/animation/backend/clipblendnode.cpp index 81fc61910..57fbdb920 100644 --- a/src/animation/backend/clipblendnode.cpp +++ b/src/animation/backend/clipblendnode.cpp @@ -37,8 +37,6 @@ #include "clipblendnode_p.h" #include <Qt3DAnimation/qclipblendnodecreatedchange.h> #include <Qt3DAnimation/qabstractanimationclip.h> -#include <Qt3DCore/qpropertynoderemovedchange.h> -#include <Qt3DCore/qpropertynodeaddedchange.h> QT_BEGIN_NAMESPACE diff --git a/src/animation/backend/clipblendvalue.cpp b/src/animation/backend/clipblendvalue.cpp index e1586953b..0db9544f6 100644 --- a/src/animation/backend/clipblendvalue.cpp +++ b/src/animation/backend/clipblendvalue.cpp @@ -38,7 +38,6 @@ #include <Qt3DAnimation/qclipblendnodecreatedchange.h> #include <Qt3DAnimation/qclipblendvalue.h> #include <Qt3DAnimation/private/qclipblendvalue_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> QT_BEGIN_NAMESPACE diff --git a/src/animation/backend/clock.cpp b/src/animation/backend/clock.cpp index ab30f735c..a9446c2d6 100644 --- a/src/animation/backend/clock.cpp +++ b/src/animation/backend/clock.cpp @@ -38,8 +38,6 @@ #include <Qt3DAnimation/qclock.h> #include <Qt3DAnimation/private/qclock_p.h> #include <Qt3DAnimation/private/animationutils_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> -#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h> QT_BEGIN_NAMESPACE diff --git a/src/animation/backend/evaluateblendclipanimatorjob.cpp b/src/animation/backend/evaluateblendclipanimatorjob.cpp index e0bb8b155..9b6802d3b 100644 --- a/src/animation/backend/evaluateblendclipanimatorjob.cpp +++ b/src/animation/backend/evaluateblendclipanimatorjob.cpp @@ -35,6 +35,9 @@ ****************************************************************************/ #include "evaluateblendclipanimatorjob_p.h" +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DCore/private/qskeleton_p.h> +#include <Qt3DAnimation/qblendedclipanimator.h> #include <Qt3DAnimation/private/handler_p.h> #include <Qt3DAnimation/private/managers_p.h> #include <Qt3DAnimation/private/animationlogging_p.h> @@ -50,9 +53,9 @@ namespace Qt3DAnimation { namespace Animation { EvaluateBlendClipAnimatorJob::EvaluateBlendClipAnimatorJob() - : Qt3DCore::QAspectJob() + : AbstractEvaluateClipAnimatorJob() { - SET_JOB_RUN_STAT_TYPE(this, JobTypes::EvaluateBlendClipAnimator, 0); + SET_JOB_RUN_STAT_TYPE(this, JobTypes::EvaluateBlendClipAnimator, 0) } void EvaluateBlendClipAnimatorJob::run() @@ -105,7 +108,7 @@ void EvaluateBlendClipAnimatorJob::run() AnimationClip *clip = clipLoaderManager->lookupResource(valueNode->clipId()); Q_ASSERT(clip); - ClipResults rawClipResults = evaluateClipAtPhase(clip, phase); + ClipResults rawClipResults = evaluateClipAtPhase(clip, float(phase)); // Reformat the clip results into the layout used by this animator/blend tree const ClipFormat format = valueNode->clipFormat(blendedClipAnimator->peerId()); @@ -120,24 +123,23 @@ void EvaluateBlendClipAnimatorJob::run() const double localTime = phase * duration; blendedClipAnimator->setLastGlobalTimeNS(globalTimeNS); blendedClipAnimator->setLastLocalTime(localTime); - blendedClipAnimator->setLastNormalizedLocalTime(phase); + blendedClipAnimator->setLastNormalizedLocalTime(float(phase)); blendedClipAnimator->setNormalizedLocalTime(-1.0f); // Re-set to something invalid. blendedClipAnimator->setCurrentLoop(animatorData.currentLoop); - const bool finalFrame = isFinalFrame(localTime, duration, animatorData.currentLoop, animatorData.loopCount); - // Prepare the property change events + // Prepare the change record + const bool finalFrame = isFinalFrame(localTime, duration, animatorData.currentLoop, animatorData.loopCount); const QVector<MappingData> mappingData = blendedClipAnimator->mappingData(); - const QVector<Qt3DCore::QSceneChangePtr> changes = preparePropertyChanges(blendedClipAnimator->peerId(), - mappingData, - blendedResults, - finalFrame, - phase); - // Send the property changes - blendedClipAnimator->sendPropertyChanges(changes); + auto record = prepareAnimationRecord(blendedClipAnimator->peerId(), + mappingData, + blendedResults, + finalFrame, + float(phase)); // Trigger callbacks either on this thread or by notifying the gui thread. - const QVector<AnimationCallbackAndValue> callbacks = prepareCallbacks(mappingData, blendedResults); - blendedClipAnimator->sendCallbacks(callbacks); + auto callbacks = prepareCallbacks(mappingData, blendedResults); + + setPostFrameData(record, callbacks); } } // Animation diff --git a/src/animation/backend/evaluateblendclipanimatorjob_p.h b/src/animation/backend/evaluateblendclipanimatorjob_p.h index 7548168e9..b2a5a6d17 100644 --- a/src/animation/backend/evaluateblendclipanimatorjob_p.h +++ b/src/animation/backend/evaluateblendclipanimatorjob_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include <Qt3DCore/qaspectjob.h> +#include <Qt3DAnimation/private/abstractevaluateclipanimatorjob_p.h> #include <Qt3DAnimation/private/handle_types_p.h> #include <Qt3DAnimation/private/animationutils_p.h> #include <Qt3DAnimation/private/blendedclipanimator_p.h> @@ -60,8 +60,9 @@ namespace Animation { class Handler; class ClipBlendNode; +class EvaluateBlendClipAnimatorJobPrivate; -class EvaluateBlendClipAnimatorJob : public Qt3DCore::QAspectJob +class EvaluateBlendClipAnimatorJob : public AbstractEvaluateClipAnimatorJob { public: EvaluateBlendClipAnimatorJob(); diff --git a/src/animation/backend/evaluateclipanimatorjob.cpp b/src/animation/backend/evaluateclipanimatorjob.cpp index 74f9012d7..7a568e829 100644 --- a/src/animation/backend/evaluateclipanimatorjob.cpp +++ b/src/animation/backend/evaluateclipanimatorjob.cpp @@ -35,6 +35,9 @@ ****************************************************************************/ #include "evaluateclipanimatorjob_p.h" +#include <Qt3DCore/private/qaspectjob_p.h> +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DAnimation/qclipanimator.h> #include <Qt3DAnimation/private/handler_p.h> #include <Qt3DAnimation/private/managers_p.h> #include <Qt3DAnimation/private/animationlogging_p.h> @@ -46,10 +49,11 @@ QT_BEGIN_NAMESPACE namespace Qt3DAnimation { namespace Animation { + EvaluateClipAnimatorJob::EvaluateClipAnimatorJob() - : Qt3DCore::QAspectJob() + : AbstractEvaluateClipAnimatorJob() { - SET_JOB_RUN_STAT_TYPE(this, JobTypes::EvaluateClipAnimator, 0); + SET_JOB_RUN_STAT_TYPE(this, JobTypes::EvaluateClipAnimator, 0) } void EvaluateClipAnimatorJob::run() @@ -98,19 +102,16 @@ void EvaluateClipAnimatorJob::run() clipAnimator->setNormalizedLocalTime(-1.0f); // Re-set to something invalid. // Prepare property changes (if finalFrame it also prepares the change for the running property for the frontend) - const QVector<Qt3DCore::QSceneChangePtr> changes = preparePropertyChanges(clipAnimator->peerId(), - clipAnimator->mappingData(), - formattedClipResults, - preEvaluationDataForClip.isFinalFrame, - preEvaluationDataForClip.normalizedLocalTime); - - // Send the property changes - clipAnimator->sendPropertyChanges(changes); + auto record = prepareAnimationRecord(clipAnimator->peerId(), + clipAnimator->mappingData(), + formattedClipResults, + preEvaluationDataForClip.isFinalFrame, + preEvaluationDataForClip.normalizedLocalTime); // Trigger callbacks either on this thread or by notifying the gui thread. - const QVector<AnimationCallbackAndValue> callbacks = prepareCallbacks(clipAnimator->mappingData(), - formattedClipResults); - clipAnimator->sendCallbacks(callbacks); + auto callbacks = prepareCallbacks(clipAnimator->mappingData(), formattedClipResults); + + setPostFrameData(record, callbacks); } } // namespace Animation diff --git a/src/animation/backend/evaluateclipanimatorjob_p.h b/src/animation/backend/evaluateclipanimatorjob_p.h index c9b1a8f96..2e88c9579 100644 --- a/src/animation/backend/evaluateclipanimatorjob_p.h +++ b/src/animation/backend/evaluateclipanimatorjob_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include <Qt3DCore/qaspectjob.h> +#include <Qt3DAnimation/private/abstractevaluateclipanimatorjob_p.h> #include <Qt3DAnimation/private/handle_types_p.h> QT_BEGIN_NAMESPACE @@ -58,7 +58,7 @@ namespace Animation { class Handler; -class EvaluateClipAnimatorJob : public Qt3DCore::QAspectJob +class EvaluateClipAnimatorJob : public AbstractEvaluateClipAnimatorJob { public: EvaluateClipAnimatorJob(); diff --git a/src/animation/backend/loadanimationclipjob.cpp b/src/animation/backend/loadanimationclipjob.cpp index d3319f8e1..977564c7f 100644 --- a/src/animation/backend/loadanimationclipjob.cpp +++ b/src/animation/backend/loadanimationclipjob.cpp @@ -36,7 +36,11 @@ #include "loadanimationclipjob_p.h" +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DAnimation/qanimationcliploader.h> +#include <Qt3DAnimation/private/qanimationcliploader_p.h> #include <Qt3DAnimation/private/animationclip_p.h> +#include <Qt3DAnimation/private/qabstractanimationclip_p.h> #include <Qt3DAnimation/private/handler_p.h> #include <Qt3DAnimation/private/managers_p.h> #include <Qt3DAnimation/private/job_common_p.h> @@ -46,16 +50,27 @@ QT_BEGIN_NAMESPACE namespace Qt3DAnimation { namespace Animation { +class LoadAnimationClipJobPrivate : public Qt3DCore::QAspectJobPrivate +{ +public: + LoadAnimationClipJobPrivate() { } + ~LoadAnimationClipJobPrivate() override { } + + void postFrame(Qt3DCore::QAspectManager *manager) override; + + QVector<AnimationClip *> m_updatedNodes; +}; + LoadAnimationClipJob::LoadAnimationClipJob() - : Qt3DCore::QAspectJob() + : Qt3DCore::QAspectJob(*new LoadAnimationClipJobPrivate) , m_animationClipHandles() { - SET_JOB_RUN_STAT_TYPE(this, JobTypes::LoadAnimationClip, 0); + SET_JOB_RUN_STAT_TYPE(this, JobTypes::LoadAnimationClip, 0) } void LoadAnimationClipJob::addDirtyAnimationClips(const QVector<HAnimationClip> &animationClipHandles) { - for (const auto handle : animationClipHandles) { + for (const auto &handle : animationClipHandles) { if (!m_animationClipHandles.contains(handle)) m_animationClipHandles.push_back(handle); } @@ -69,16 +84,40 @@ void LoadAnimationClipJob::clearDirtyAnimationClips() void LoadAnimationClipJob::run() { Q_ASSERT(m_handler); + Q_D(LoadAnimationClipJob); + + d->m_updatedNodes.reserve(m_animationClipHandles.size()); AnimationClipLoaderManager *animationClipManager = m_handler->animationClipLoaderManager(); for (const auto &animationClipHandle : qAsConst(m_animationClipHandles)) { AnimationClip *animationClip = animationClipManager->data(animationClipHandle); Q_ASSERT(animationClip); animationClip->loadAnimation(); + d->m_updatedNodes.push_back(animationClip); } clearDirtyAnimationClips(); } +void LoadAnimationClipJobPrivate::postFrame(Qt3DCore::QAspectManager *manager) +{ + for (AnimationClip *clip: qAsConst(m_updatedNodes)) { + QAbstractAnimationClip *node = qobject_cast<QAbstractAnimationClip *>(manager->lookupNode(clip->peerId())); + if (!node) + continue; + + QAbstractAnimationClipPrivate *dnode = static_cast<QAbstractAnimationClipPrivate *>(Qt3DCore::QNodePrivate::get(node)); + dnode->setDuration(clip->duration()); + + QAnimationClipLoader *loader = qobject_cast<QAnimationClipLoader *>(node); + if (loader) { + QAnimationClipLoaderPrivate *dloader = static_cast<QAnimationClipLoaderPrivate *>(dnode); + dloader->setStatus(clip->status()); + } + } + + m_updatedNodes.clear(); +} + } // namespace Animation } // namespace Qt3DAnimation diff --git a/src/animation/backend/loadanimationclipjob_p.h b/src/animation/backend/loadanimationclipjob_p.h index 25de2c6b6..07d78d416 100644 --- a/src/animation/backend/loadanimationclipjob_p.h +++ b/src/animation/backend/loadanimationclipjob_p.h @@ -59,6 +59,7 @@ namespace Animation { class Handler; class FindGraphJob; +class LoadAnimationClipJobPrivate; class LoadAnimationClipJob : public Qt3DCore::QAspectJob { @@ -75,6 +76,8 @@ protected: void run() override; private: + Q_DECLARE_PRIVATE(LoadAnimationClipJob) + QVector<HAnimationClip> m_animationClipHandles; Handler *m_handler; }; diff --git a/src/animation/backend/skeleton.cpp b/src/animation/backend/skeleton.cpp index 720b43e33..60e436a71 100644 --- a/src/animation/backend/skeleton.cpp +++ b/src/animation/backend/skeleton.cpp @@ -36,6 +36,7 @@ #include "skeleton_p.h" #include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DCore/private/qabstractskeleton_p.h> QT_BEGIN_NAMESPACE @@ -62,40 +63,20 @@ void Skeleton::cleanup() m_jointLocalPoses.clear(); } -// TODOSYNC remove once backend > backend communication no longer requires messages -void Skeleton::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +void Skeleton::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - // Get the joint names and initial local poses from a change sent - // by the render aspect when the skeleton has been loaded. - switch (e->type()) { - case PropertyUpdated: { - const auto change = qSharedPointerCast<QPropertyUpdatedChange>(e); - if (change->propertyName() == QByteArrayLiteral("jointNamesAndLocalPoses")) { - const auto payload = change->value().value<JointNamesAndLocalPoses>(); - m_jointNames = payload.names; - m_jointLocalPoses = payload.localPoses; + BackendNode::syncFromFrontEnd(frontEnd, firstTime); - // TODO: Mark joint info as dirty so we can rebuild any indexes used - // by the animators and channel mappings. - } + const Qt3DCore::QAbstractSkeleton *node = qobject_cast<const Qt3DCore::QAbstractSkeleton *>(frontEnd); + if (!node) + return; - break; - } + auto dnode = Qt3DCore::QAbstractSkeletonPrivate::get(node); - default: - break; - } - - BackendNode::sceneChangeEvent(e); -} - -void Skeleton::sendLocalPoses() -{ - auto e = QPropertyUpdatedChangePtr::create(peerId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::BackendNodes); - e->setPropertyName("localPoses"); - e->setValue(QVariant::fromValue(m_jointLocalPoses)); - notifyObservers(e); + // TODO: Mark joint info as dirty so we can rebuild any indexes used + // by the animators and channel mappings. + m_jointNames = dnode->m_jointNames; + m_jointLocalPoses = dnode->m_localPoses; } } // namespace Animation diff --git a/src/animation/backend/skeleton_p.h b/src/animation/backend/skeleton_p.h index 668ff8712..d44f8fc1c 100644 --- a/src/animation/backend/skeleton_p.h +++ b/src/animation/backend/skeleton_p.h @@ -62,8 +62,9 @@ public: Skeleton(); void cleanup(); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; + QVector<Qt3DCore::Sqt> joints() const { return m_jointLocalPoses; } int jointCount() const { return m_jointLocalPoses.size(); } QString jointName(int jointIndex) const { return m_jointNames.at(jointIndex); } @@ -97,8 +98,6 @@ public: return m_jointLocalPoses[jointIndex].translation; } - void sendLocalPoses(); - #if defined(QT_BUILD_INTERNAL) void setJointCount(int jointCount) { |