1

我有一个问题,XNA 4.0 没有正确显示 3D FBX 模型。

一位朋友创建了一个模型,当我在 FBX Viewer 中打开它时,它会正确显示它 https://docs.google.com/open?id=0B54ow8GRluDUYTBubTQ4bjBramM

但是当我将它加载到 XNA 并单击运行时,它显示为 https://docs.google.com/open?id=0B54ow8GRluDUSE14TWMxcnBJWWc

The code that i have for the drawing is
foreach (ModelMesh mesh in model.Meshes)
{
    foreach (BasicEffect effect in mesh.Effects)
    {
         effect.Projection = projection;
         effect.View = view;
         effect.World = Matrix.CreateScale(1.0f) * Matrix.CreateRotationX(90) * Matrix.CreateTranslation(position);
         effect.EnableDefaultLighting();
     }
     mesh.Draw();
 }

任何解决此问题的帮助将不胜感激。

谢谢。

4

1 回答 1

2

每个网格都有一个骨骼...您应该使用它将网格定位在正确的位置...此代码来自 Microsoft

private void DrawModel(Model m)
{
    Matrix[] transforms = new Matrix[m.Bones.Count];
    float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
    m.CopyAbsoluteBoneTransformsTo(transforms);
    Matrix projection =
        Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
        aspectRatio, 1.0f, 10000.0f);
    Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, Zoom),
        Vector3.Zero, Vector3.Up);

    foreach (ModelMesh mesh in m.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();

            effect.View = view;
            effect.Projection = projection;
            effect.World = gameWorldRotation *
                transforms[mesh.ParentBone.Index] *
                Matrix.CreateTranslation(Position);
        }
        mesh.Draw();
    }
}

您可以在http://msdn.microsoft.com/en-us/library/bb203933(v=xnagamestudio.40).aspx找到它

于 2012-11-08T23:40:13.980 回答