我有一个问题,即XNA 4.0无法正确显示3D FBX模型。
一个朋友创建了一个模型,当我在FBX查看器中打开此模型时,它会正确显示它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();
}
任何帮助解决此问题的帮助将不胜感激。
谢谢。
每个网格都有一个骨头...您应该使用它将网格放在正确的位置...此代码来自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