Qt3DAnimation::QBlendedClipAnimator Class
class Qt3DAnimation::QBlendedClipAnimatorQBlendedClipAnimator 是一个组件,用于提供对混合节点树的动画播放功能。更多内容...
| 标题: | #include <qblendedclipanimator.h> |
| CMake: | 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 则可以混合多个片段。动画数据是通过评估所谓的混合树(blend tree)获得的。 混合树是一种分层树结构,其中叶节点是封装动画片段(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 是加法因子,beta 是线性插值因子),我们可以得到一组连续的 2D 动画效果:
(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) |
© 2026 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.