Qt3DAnimation::QBlendedClipAnimator Class

class Qt3DAnimation::QBlendedClipAnimator

QBlendedClipAnimator 是一个为混合节点树提供动画播放功能的组件。更多

Header: #include <QBlendedClipAnimator>
CMake.QBlendedClipAnimator find_package(Qt6 REQUIRED COMPONENTS 3danimation)
target_link_libraries(mytarget PRIVATE Qt6::3danimation)
qmake: QT += 3danimation
在 QML 中: BlendedClipAnimator
继承: Qt3DAnimation::QAbstractClipAnimator
状态:已废弃

属性

  • blendTree : Qt3DAnimation::QAbstractClipBlendNode*

公共功能

Qt3DAnimation::QAbstractClipBlendNode *blendTree() const

公共插槽

void setBlendTree(Qt3DAnimation::QAbstractClipBlendNode *blendTree)

信号

void blendTreeChanged(Qt3DAnimation::QAbstractClipBlendNode *blendTree)

详细说明

QBlendedClipAnimator 的实例可由 QEntity 聚合,以增加播放动画片段的功能,并将计算出的动画值应用到 QObject 的属性中。

QClipAnimator 可从单个动画片段中获取动画数据,而 QBlendedClipAnimator 可将多个片段混合在一起。动画数据是通过评估所谓的混合树获得的。混合树是一种分层树结构,其中叶节点是封装动画片段的值节点(QAbstractAnimationClip );内部节点代表对操作数属性指向的节点进行操作的混合操作。

要将混合树与 QBlendedClipAnimator 关联,请将动画器的blendTree 属性设置为指向混合树的根节点:

auto blendTreeRoot = new QAdditiveClipBlend();
...
auto animator = new QBlendedClipAnimator();
animator->setBlendTree(blendTreeRoot);

混合树可以由以下节点类型构建:

注意: 混合节点树只能在动画播放器未运行时编辑。

随着时间的推移,还将添加其他节点类型。

以下面的混合树为例:

Clip0----
        |
        Lerp Node----
        |           |
Clip1----           Additive Node
                    |
            Clip2----

创建和使用方法如下:

// Create leaf nodes of blend tree
auto clip0 = new QClipBlendValue(
    new QAnimationClipLoader(QUrl::fromLocalFile("walk.json")));
auto clip1 = new QClipBlendValue(
    new QAnimationClipLoader(QUrl::fromLocalFile("run.json")));
auto clip2 = new QClipBlendValue(
    new QAnimationClipLoader(QUrl::fromLocalFile("wave-arm.json")));

// Create blend tree inner nodes
auto lerpNode = new QLerpClipBlend();
lerpNode->setStartClip(clip0);
lerpNode->setEndClip(clip1);
lerpNode->setBlendFactor(0.5f); // Half-walk, half-run

auto additiveNode = new QAdditiveClipBlend();
additiveNode->setBaseClip(lerpNode); // Comes from lerp sub-tree
additiveNode->setAdditiveClip(clip2);
additiveNode->setAdditiveFactor(1.0f); // Wave arm fully

// Run the animator
auto animator = new QBlendedClipAnimator();
animator->setBlendTree(additiveNode);
animator->setChannelMapper(...);
animator->setRunning(true);

通过制作一组动画片段,并在运行时使用混合树在它们之间进行动态混合,我们可以制作出大量可能的动画效果。在上述混合树的一些简单示例中,阿尔法是加法因子,贝塔是勒普混合因子,我们可以得到一个二维的连续动画:

(alpha = 0, beta = 1) Running, No arm waving --- (alpha = 1, beta = 1) Running, Arm waving
        |                                               |
        |                                               |
        |                                               |
(alpha = 0, beta = 0) Walking, No arm waving --- (alpha = 0, beta = 1) Running, No arm waving

更复杂的混合树为组合动画片段提供了更大的灵活性。请注意,用于控制混合树的值(上述 alpha 和 beta)是混合节点上的简单属性。这意味着这些属性本身也可由动画框架控制。

属性文档

blendTree : Qt3DAnimation::QAbstractClipBlendNode*

此属性用于保存动画混合树的根节点,在动画播放器进行插值之前将对其进行评估。

访问功能:

Qt3DAnimation::QAbstractClipBlendNode *blendTree() const
void setBlendTree(Qt3DAnimation::QAbstractClipBlendNode *blendTree)

通知信号

void blendTreeChanged(Qt3DAnimation::QAbstractClipBlendNode *blendTree)

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.