gpt4 book ai didi

c# - 具有骨骼及其矩阵的 3D 动画

转载 作者:行者123 更新时间:2023-11-30 16:58:45 25 4
gpt4 key购买 nike

我真的是万不得已才问这个问题。我已经两天没能解决这个问题了。因此,如果有人对 3D、矩阵和动画有所了解,我将非常感谢您的意见。

我已经下载了这个项目并将其实现到我自己的项目中:http://xbox.create.msdn.com/en-US/education/catalog/sample/skinned_model .我游戏中的角色在施法时会移动他的手。我已经成功制作了这个动画并将其导入到项目中。但我需要在他的手掌内产生粒子,这些粒子会根据动画移动。 我只需要应用动画后手掌的 3D 位置。

动画中的手图: http://s18.postimg.org/qkaipufa1/hands.png

如果您查看蒙皮模型示例项目:类:AnimationPlayer.cs,您会注意到它处理了 3 次矩阵:

    public void Update(TimeSpan time, bool relativeToCurrentTime,
Matrix rootTransform)
{
UpdateBoneTransforms(time, relativeToCurrentTime);
UpdateWorldTransforms(rootTransform);
UpdateSkinTransforms();
}

并允许我们在每个步骤后访问它们:

        /// Gets the current bone transform matrices, relative to their parent bones.
/// </summary>
public Matrix[] GetBoneTransforms()
{
return boneTransforms;
}


/// <summary>
/// Gets the current bone transform matrices, in absolute format.
/// </summary>
public Matrix[] GetWorldTransforms()
{
return worldTransforms;
}


/// <summary>
/// Gets the current bone transform matrices,
/// relative to the skinning bind pose.
/// </summary>
public Matrix[] GetSkinTransforms()
{
return skinTransforms;
}

我还应该提一下,我知道手掌中骨头的索引及其所有 parent 的索引:

10 - 11 的父级,Root 骨骼

11 - 12 的 parent

12 - 13 岁的 parent

13 - 14 岁的 parent

14 - 15 岁的 parent

15 - 16 岁的 parent

16 - 掌骨

据我所知,这个项目是我上面列出的所有 GetXXXXXXXX 命令返回一个根据骨骼索引排序的 Matrix[] 数组。所以要获得骨骼 10 的变换。我相信代码将如下所示:

Matrix[] M = animtionplayer.GetSkinTransforms();
Matrix transform = M[10];

好的,现在说说我不明白的部分。我不知道我需要使用 3 个 GetXXXXXXXXX 函数中的哪一个来获取手掌位置。

我认为着色器计算骨骼位置的方式是将它们乘以它们的每个父骨骼。所以:

Matrix[] M = animtionplayer.GetBoneTransforms();
Matrix transform = M[10];
transform = transform * M[11];
transform = transform * M[12];
transform = transform * M[13];
transform = transform * M[14];
transform = transform * M[15];
transform = transform * M[16];
//maybe apply the world position of the model?
transform = transform * MyWorld;

然后可能获得 vector3 位置。

Vector3 HandPosition = transform.Up;

好吧,当我尝试上面的解决方案时,我得到了不同的结果。对于某些骨骼,它会在动画的中间部分正确移动。但老实说没什么好东西。有人可以解释这里发生了什么吗?如何获得骨骼在手掌中的位置?我真的在黑暗中。两个月前才知道什么是矩阵,这周才知道什么是骨骼动画。

最佳答案

好吧,这个错误非常令人沮丧,所以我休息了大约一周的编码时间。 2 天前我又开始研究它。尝试很多随机的事情......查看矩阵的值寻找模式,我终于明白了。这是一张图片,其中的手是动画的,所有的骨头都用白色的大球体完美地突出显示。它也完美地跟随动画! http://s27.postimg.org/f48i7ae4x/2014_07_30_18_H14_M20_S.jpg

代码:

Matrix[] BoneTransforms = animtionPlayer.GetWorldTransforms();
for (int i = 0; i < BoneTransforms.Length; i++)
{
Vector3 v3 = new Vector3(BoneTransforms[i].M41, BoneTransforms[i].M42, BoneTransforms[i].M43);
v3 = Vector3.Transform(v3, GetWorld(Position, Rotation, Scale));//GetWorld is the models world matrix: position, rotation and scale.
Game1.DrawMarker(v3); //v3 is the position of the current Bone.
}

我只是通过观察特定矩阵的所有值来编写该代码。我了解到 M41、M42、M43 是来自特定骨骼的 X、Y、Z 索。

关于c# - 具有骨骼及其矩阵的 3D 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24845536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com