我遇到的问题是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();
}
非常感谢任何帮助解决这个问题。
感谢。
答案 0 :(得分:2)
每个网格都有一个骨骼...你应该用它来将网格定位在正确的位置......这段代码来自微软
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
找到它