顶点蒙皮Vertex Skinning

Vertex Skinning

顶点蒙皮

Introduction

介绍

Qt Quick 3D supports vertex skinning for skeletal animation of mesh geometries.

Qt Quick 3D支持为网格几何体的骨骼动画进行顶点蒙皮。

See the Simple Skinning Example for a practical demonstration of skeletal animation.

​有关骨骼动画的实际演示,请参见“简单蒙皮示例”。

In most cases, application developers will not be using the skinning API manually. The normal workflow is to use an external content creation tool to define the skeleton and the skin (this is sometimes also referred to as rigging), and then use the Balsam Asset Import Tool to convert the asset to Qt Quick 3D's native format.

​在大多数情况下,应用程序开发人员不会手动使用蒙皮API。正常的工作流程是使用外部内容创建工具来定义骨架和蒙皮(有时也称为索具),然后使用Balsam资产导入工具将资产转换为Qt Quick 3D的原生格式。

Defining a skeleton

定义骨架

The basis of skeletal animation is the Skeleton. This is an abstract representation of how the model can move, inspired by how a physical skeleton works for vertebrates. The "bones" of the skeleton is represented by a hierarchy of Joint nodes. These do not necessarily need to represent actual bones, of course.

​骨架动画的基础是骨架。这是一个模型如何移动的抽象表示,灵感来自脊椎动物的物理骨骼是如何工作的。骨架的“骨骼”由关节节点的层次表示。当然,这些并不一定需要表示实际的骨骼。

Skeleton {
    id: qmlskeleton
    Joint {
        id: joint0
        index: 0
        skeletonRoot: qmlskeleton
        Joint {
            id: joint1
            index: 1
            skeletonRoot: qmlskeleton
        }
        Joint {
            id: joint2
            index: 2
            skeletonRoot: qmlskeleton
        }

    }
}

Connecting a skeleton to a model

将骨架连接到模型

To apply a skeleton to a model, set the model's skeleton property:

​若要将骨架应用于模型,请设置模型的骨架特性:

Model {
    skeleton: qmlskeleton
    ...

In order for the skeleton to have an effect, the model's geometry needs to include skinning information. This is done by including vertex attributes with JointSemantic and WeightSemantic in the vertex buffer.

​为了使骨骼具有效果,模型的几何体需要包括蒙皮信息。这是通过在顶点缓冲区中包含具有JointSemantic和WeightSemantic的顶点属性来实现的。

The JointSemantic attribute determines which of the joints in the skeleton can influence a given vertex. This uses the index values specified by Joint.index. Since this attribute contains 4 indexes, a maximum of 4 joints can influence one vertex.

JointSemantic属性确定骨骼中哪些关节可以影响给定顶点。这将使用Joint.index指定的索引值。由于该属性包含4个索引,因此最多4个关节可以影响一个顶点。

The WeightSemantic attribute describes the strength of the influence of those joints. It contains four floating point values, each value determining the weight given to the joint with the index at the corresponding position in the JointSemantic attribute.

WeightSemantic属性描述了这些关节的影响强度。它包含四个浮点值,每个值都确定赋予关节的权重,索引位于JointSemantic属性中的相应位置。

For example, given the skeleton above, if a vertex has these attributes:

例如,给定上面的骨架,如果顶点具有以下属性:

JointSemantic attributeWeightSemantic attribute
QVector4D(2, 0, 0, 0)QVector4D(1.0, 0.0, 0.0, 0.0)

that vertex will be 100% influenced by joint2, and it will move exactly as much as that joint. The last three indexes in the JointSemantic attribute are ignored since the corresponding weights are 0.0.

该顶点将100%受joint2的影响,并且其移动量与该关节的移动量完全相同。JointSsemantic属性中的最后三个索引将被忽略,因为相应的权重为0.0。

As another example, with these attributes:

作为另一个示例,使用这些属性:

JointSemantic attributeWeightSemantic attribute
QVector4D(1, 2, 0, 0)QVector4D(0.5, 0.25, 0.0, 0.0)

the vertex will be moved by 50% of joint1's movement plus 25% of joint2's movement.

顶点将移动joint1移动的50%加上joint2移动的25%。

In addition, since the skeleton is an abstract representation, the model need to specify geometry information for the joints. For performance reasons, this is not done by specifying the information directly. Instead, Model.inverseBindPoses contains the inverse of the transformation matrix needed to move each joint to its initial position.

​此外,由于骨架是一种抽象表示,因此模型需要指定关节的几何体信息。出于性能原因,这不是通过直接指定信息来实现的。相反,Model.inverseBindPoses包含将每个关节移动到其初始位置所需的变换矩阵的倒数。

Animating the skeleton

设置骨骼动画

Transforming a joint in a skeleton will move all vertexes connected to that joint. Since Joint inheriths from Node, a skeleton can be animated simply by using standard QML animations.

​变换骨骼中的关节将移动连接到该关节的所有顶点。由于关节继承自节点,因此可以简单地通过使用标准QML动画来设置骨架的动画。

NumberAnimation {
    target: joint1
    property: "eulerRotation.z"
    duration: 5000
    from: -90
    to: 90
    running: true
}

While it is possible to create complex animations by nesting SequentialAnimationParallelAnimation and NumberAnimation, it is generally more convenient to use timeline animations for animating skinned models.

​虽然可以通过嵌套SequentialAnimation、ParallelAnimation和NumberAnimation来创建复杂的动画,但通常使用时间轴动画来设置蒙皮模型的动画更方便。

© 2024 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值