diff options
author | Liang Qi <liang.qi@qt.io> | 2018-01-22 13:21:04 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-01-22 14:08:36 +0100 |
commit | 598acd70a44f787a3e72c586576bfc028d5af02d (patch) | |
tree | 30691da4bbdb935dbf592d9689d034060b9d4d74 /src/animation | |
parent | 32a511a667bab93d4fca2e71b38d89f8d76aa07c (diff) | |
parent | 2b19bde378e084331b1b7ba9aa076270492999bb (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/render/backend/renderer_p.h
src/render/geometry/geometryrenderer.cpp
src/render/geometry/qmesh.cpp
src/render/geometry/qmesh_p.h
tests/auto/render/commons/testrenderer.h
tests/auto/render/meshfunctors/tst_meshfunctors.cpp
tests/auto/render/qmesh/tst_qmesh.cpp
Change-Id: Ia078029e2faf23fe253c5ce385e393c094266e3b
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/backend/animationutils.cpp | 7 | ||||
-rw-r--r-- | src/animation/backend/animationutils_p.h | 12 | ||||
-rw-r--r-- | src/animation/backend/buildblendtreesjob.cpp | 35 | ||||
-rw-r--r-- | src/animation/backend/clipblendvalue.cpp | 12 | ||||
-rw-r--r-- | src/animation/backend/clipblendvalue_p.h | 3 | ||||
-rw-r--r-- | src/animation/backend/evaluateblendclipanimatorjob.cpp | 1 |
6 files changed, 65 insertions, 5 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index 8652c7df1..44bf31854 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -848,6 +848,13 @@ QVector<float> defaultValueForChannel(Handler *handler, return result; } +void applyComponentDefaultValues(const QVector<ComponentValue> &componentDefaults, + ClipResults &formattedClipResults) +{ + for (const auto &componentDefault : componentDefaults) + formattedClipResults[componentDefault.componentIndex] = componentDefault.value; +} + } // Animation } // Qt3DAnimation diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h index 6a1b18936..a0ab218d4 100644 --- a/src/animation/backend/animationutils_p.h +++ b/src/animation/backend/animationutils_p.h @@ -191,6 +191,13 @@ inline QDebug operator<<(QDebug dbg, const ChannelNameAndType &nameAndType) } #endif +struct ComponentValue +{ + int componentIndex; + float value; +}; +QT3D_DECLARE_TYPEINFO_2(Qt3DAnimation, Animation, ComponentValue, Q_PRIMITIVE_TYPE) + struct ClipFormat { // TODO: Remove the mask and store both the sourceClipIndices and @@ -200,6 +207,7 @@ struct ClipFormat QVector<QBitArray> sourceClipMask; QVector<ComponentIndices> formattedComponentIndices; QVector<ChannelNameAndType> namesAndTypes; + QVector<ComponentValue> defaultComponentValues; }; #ifndef QT_NO_DEBUG_STREAM @@ -338,6 +346,10 @@ ClipResults evaluateBlendTree(Handler *handler, Q_AUTOTEST_EXPORT QVector<float> defaultValueForChannel(Handler *handler, const ChannelNameAndType &channelDescription); +Q_AUTOTEST_EXPORT +void applyComponentDefaultValues(const QVector<ComponentValue> &componentDefaults, + ClipResults &formattedClipResults); + } // Animation } // Qt3DAnimation diff --git a/src/animation/backend/buildblendtreesjob.cpp b/src/animation/backend/buildblendtreesjob.cpp index a08aa2a34..581b133b5 100644 --- a/src/animation/backend/buildblendtreesjob.cpp +++ b/src/animation/backend/buildblendtreesjob.cpp @@ -90,10 +90,17 @@ void BuildBlendTreesJob::run() QVector<QBitArray> blendTreeChannelMask; const QVector<Qt3DCore::QNodeId> valueNodeIds = gatherValueNodesToEvaluate(m_handler, blendClipAnimator->blendTreeRootId()); + + // Store the clip value nodes to avoid further lookups below. + // TODO: Refactor this next block into a function in animationutils.cpp that takes + // a QVector<QClipBlendValue*> as input. + QVector<ClipBlendValue *> valueNodes; + valueNodes.reserve(valueNodeIds.size()); for (const auto valueNodeId : valueNodeIds) { ClipBlendValue *valueNode = static_cast<ClipBlendValue *>(m_handler->clipBlendNodeManager()->lookupNode(valueNodeId)); Q_ASSERT(valueNode); + valueNodes.push_back(valueNode); const Qt3DCore::QNodeId clipId = valueNode->clipId(); AnimationClip *clip = m_handler->animationClipLoaderManager()->lookupResource(clipId); @@ -132,6 +139,34 @@ void BuildBlendTreesJob::run() } } + // Now that we know the overall blend tree mask, go back and compare this to + // the masks from each of the value nodes. If the overall mask requires a + // channel but the value node does not provide it, we need to store default + // values to use for that channel so that the blending evaluation works as + // expected. + for (const auto valueNode : valueNodes) { + ClipFormat &f = valueNode->clipFormat(blendClipAnimator->peerId()); + + const int channelCount = blendTreeChannelMask.size(); + for (int i = 0; i < channelCount; ++i) { + if (blendTreeChannelMask[i] == f.sourceClipMask[i]) + continue; // Masks match, nothing to do + + // If we get to here then we need to obtain a default value + // for this channel and store it for later application to any + // missing components of this channel. + const QVector<float> defaultValue = defaultValueForChannel(m_handler, + f.namesAndTypes[i]); + + // Find the indices where we later need to inject these default + // values and store them in the format. + const ComponentIndices &componentIndices = f.formattedComponentIndices[i]; + Q_ASSERT(componentIndices.size() == defaultValue.size()); + for (int j = 0; j < defaultValue.size(); ++j) + f.defaultComponentValues.push_back({componentIndices[j], defaultValue[j]}); + } + } + // Finally, build the mapping data vector for this blended clip animator. This // gets used during the final stage of evaluation when sending the property changes // out to the targets of the animation. We do the costly work once up front. diff --git a/src/animation/backend/clipblendvalue.cpp b/src/animation/backend/clipblendvalue.cpp index c1de1fea7..5685d5191 100644 --- a/src/animation/backend/clipblendvalue.cpp +++ b/src/animation/backend/clipblendvalue.cpp @@ -102,12 +102,16 @@ void ClipBlendValue::setClipFormat(Qt3DCore::QNodeId animatorId, const ClipForma } } -ClipFormat ClipBlendValue::clipFormat(Qt3DCore::QNodeId animatorId) +ClipFormat &ClipBlendValue::clipFormat(Qt3DCore::QNodeId animatorId) { const int animatorIndex = m_animatorIds.indexOf(animatorId); - if (animatorIndex != -1) - return m_clipFormats[animatorIndex]; - return ClipFormat(); + return m_clipFormats[animatorIndex]; +} + +const ClipFormat &ClipBlendValue::clipFormat(Qt3DCore::QNodeId animatorId) const +{ + const int animatorIndex = m_animatorIds.indexOf(animatorId); + return m_clipFormats[animatorIndex]; } } // namespace Animation diff --git a/src/animation/backend/clipblendvalue_p.h b/src/animation/backend/clipblendvalue_p.h index 63dfe6ddc..168989a89 100644 --- a/src/animation/backend/clipblendvalue_p.h +++ b/src/animation/backend/clipblendvalue_p.h @@ -79,7 +79,8 @@ public: double duration() const override; void setClipFormat(Qt3DCore::QNodeId animatorId, const ClipFormat &formatIndices); - ClipFormat clipFormat(Qt3DCore::QNodeId animatorId); + ClipFormat &clipFormat(Qt3DCore::QNodeId animatorId); + const ClipFormat &clipFormat(Qt3DCore::QNodeId animatorId) const; protected: ClipResults doBlend(const QVector<ClipResults> &blendData) const override; diff --git a/src/animation/backend/evaluateblendclipanimatorjob.cpp b/src/animation/backend/evaluateblendclipanimatorjob.cpp index 5382b9c92..d01cf3bdd 100644 --- a/src/animation/backend/evaluateblendclipanimatorjob.cpp +++ b/src/animation/backend/evaluateblendclipanimatorjob.cpp @@ -105,6 +105,7 @@ void EvaluateBlendClipAnimatorJob::run() // Reformat the clip results into the layout used by this animator/blend tree const ClipFormat format = valueNode->clipFormat(blendedClipAnimator->peerId()); ClipResults formattedClipResults = formatClipResults(rawClipResults, format.sourceClipIndices); + applyComponentDefaultValues(format.defaultComponentValues, formattedClipResults); valueNode->setClipResults(blendedClipAnimator->peerId(), formattedClipResults); } |