有没有更简单的方法在XNA中制作3D模型?

时间:2013-11-24 13:43:27

标签: c# animation 3d xna

目前,我正在努力理解并在XNA中进行3D动画。

我的模特最初看起来像:

我不希望它像这样伸出双臂。使用XNA,我试图将手臂放在一边,结果就像:

我正在使用的代码是Microsoft的XNA动画示例:

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执行此操作?是否有更简单的方法来制作身体部位的动画?我花了最后3个小时做左臂并使用反复试验来确定每个部件的变换量。它看起来不错,但它并不“很棒”。

1 个答案:

答案 0 :(得分:0)

复杂3D几何体的动画仅使用视觉动画工具完成。即使使用合适的工具,也需要花费数小时的时间才能做到正确。

有各种免费或商业3D建模和动画软件包。要开始使用,我建议您查看Blender