gpt4 book ai didi

c# - 有没有更简单的方法在 XNA 中制作 3D 模型的动画?

转载 作者:太空宇宙 更新时间:2023-11-03 16:04:01 26 4
gpt4 key购买 nike

目前,我正在努力理解和使用 XNA 制作 3D 动画。

我的模型原来是这样的:

我不希望它的双臂像这样伸到一边。使用 XNA,我尝试将 ARM 放在一边,结果如下:

我使用的代码是微软的 XNA Animation Sample:

public class SkinningSampleGame : Microsoft.Xna.Framework.Game
{
/* Other stuff here */

private Matrix rotate(float X, float Y, float Z)
{
return Matrix.CreateRotationX(MathHelper.ToRadians(X)) * Matrix.CreateRotationY(MathHelper.ToRadians(Y)) * Matrix.CreateRotationZ(MathHelper.ToRadians(Z));
}

protected override void Update(GameTime gameTime)
{
float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

//transform the model's left arm.

int boneId = currentModel.Bones["swat:LeftShoulder"].Index - 3;
animationPlayer.boneTransforms[boneId] = rotate(-2.593f, 1.84f, -14.782f) * Matrix.CreateTranslation(new Vector3(2, -3, 5)) * _originalBonesMatrix[boneId];

boneId = currentModel.Bones["swat:LeftShoulder"].Index - 2;
animationPlayer.boneTransforms[boneId] = rotate(0, -30, -56f) * Matrix.CreateTranslation(new Vector3(-25, 2, -1)) * _originalBonesMatrix[boneId];

boneId = currentModel.Bones["swat:LeftShoulder"].Index - 1;
animationPlayer.boneTransforms[boneId] = rotate(0, -2, -5f) * Matrix.CreateTranslation(new Vector3(0, 0, 0)) * _originalBonesMatrix[boneId];


//Transform model's right arm (the messed up arm)..

boneId = currentModel.Bones["swat:RightShoulder"].Index - 8;
animationPlayer.boneTransforms[boneId] = rotate(-2.593f, 1.84f, 14.782f) * Matrix.CreateTranslation(new Vector3(5, 3, 5)) * _originalBonesMatrix[boneId];

boneId = currentModel.Bones["swat:RightShoulder"].Index - 7;
animationPlayer.boneTransforms[boneId] = rotate(0, 7, 56f) * Matrix.CreateTranslation(new Vector3(-15, -2, 1)) * _originalBonesMatrix[boneId];

boneId = currentModel.Bones["swat:RightShoulder"].Index - 1;
animationPlayer.boneTransforms[boneId] = rotate(0, 2, 5f) * Matrix.CreateTranslation(new Vector3(0, 0, 0)) * _originalBonesMatrix[boneId];

animationPlayer.UpdateWorldTransforms(Matrix.Identity);
animationPlayer.UpdateSkinTransforms();
base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
GraphicsDevice device = graphics.GraphicsDevice;

device.Clear(Color.CornflowerBlue);

Matrix[] bones = animationPlayer.GetSkinTransforms();

// Compute camera matrices.
Matrix view = Matrix.CreateScale(0.005f) * Matrix.CreateTranslation(0, 0, 0) * Matrix.CreateRotationY(MathHelper.ToRadians(0)) *
Matrix.CreateLookAt(new Vector3(0, 1, 1), Vector3.Forward, Vector3.Up);

Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.1f, 1000f);

// Render the skinned mesh.
foreach (ModelMesh mesh in currentModel.Meshes)
{
foreach (SkinnedEffect effect in mesh.Effects)
{
effect.SetBoneTransforms(bones);

effect.View = view;
effect.Projection = projection;

effect.EnableDefaultLighting();

effect.SpecularColor = new Vector3(0.35f);
effect.SpecularPower = 16;
}

mesh.Draw();
}

base.Draw(gameTime);
}
}

模型中的骨骼是: enter image description here

我希望它像这样平滑:

enter image description here

我如何使用 XNA 执行此操作?有没有更简单的方法来制作 body 部位的动画?我花了最后 3 个小时只做左臂,并使用试错来计算每个部分的变形量。它看起来不错,但不是“很好”。

最佳答案

复杂 3D 几何体的动画完全使用视觉动画工具完成。即使使用正确的工具,也需要许多小时的练习才能正确使用。

有各种免费或商业的 3D 建模和动画软件包。首先,我建议您查看 Blender .

关于c# - 有没有更简单的方法在 XNA 中制作 3D 模型的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20175194/

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