/**************************************************************************** ** ** 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:COMM$ ** ** 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. ** ** $QT_END_LICENSE$ ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ****************************************************************************/ #include "abstractevaluateclipanimatorjob_p.h" #include #include #include #include QT_BEGIN_NAMESPACE namespace Qt3DAnimation { namespace Animation { class AbstractEvaluateClipAnimatorJobPrivate : public Qt3DCore::QAspectJobPrivate { public: AbstractEvaluateClipAnimatorJobPrivate() { } ~AbstractEvaluateClipAnimatorJobPrivate() override { } void postFrame(Qt3DCore::QAspectManager *manager) override; AnimationRecord m_record; QVector m_callbacks; }; AbstractEvaluateClipAnimatorJob::AbstractEvaluateClipAnimatorJob() : Qt3DCore::QAspectJob(*new AbstractEvaluateClipAnimatorJobPrivate) { } void AbstractEvaluateClipAnimatorJob::setPostFrameData(const AnimationRecord &record, const QVector &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(manager->lookupNode(skeletonData.first)); if (node) { auto d = Qt3DCore::QAbstractSkeletonPrivate::get(node); d->m_localPoses = skeletonData.second; d->update(); } } QAbstractClipAnimator *animator = qobject_cast(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