wsd*_*wsd 4 c# xna effect blender
我想在XNA中绘制一个Model.我已经领先并在Blender中生成它并将其导出为fbx文件格式,以便内容管道可以使用它.我应该在WindowsGame()的Draw()方法中添加什么代码?我已经尝试过以下但是我得到的只是一个灰色的屏幕(灰色不是蓝色,这是清晰的颜色,请注意)模型是使用content.Load导入的,这不会引起任何错误,我称之为"碗" .
任何人都可以告诉我为什么这里不起作用?
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
BasicEffect b = new BasicEffect (graphics.GraphicsDevice, new EffectPool ( ));
foreach (ModelMesh m in Bowl.Meshes)
{
b.View = Cam.mView;
b.Projection = Cam.mProj;
b.World = mWorld;
b.EnableDefaultLighting ( );
b.Begin ( );
m.Draw ( );
b.End ( );
}
base.Draw(gameTime);
}
Run Code Online (Sandbox Code Playgroud)
我刚刚注意到这相当于谋杀效率,但我已经尝试了很多东西,我只是需要它才能优化它.
首次尝试渲染时,一个非常常见的问题是相机没有看到你认为它正在看的东西.另一个可能的问题是该模型的规模不符合您的预期.因此,例如,如果相机在z上有5个单位,但模型宽度为10个单位,那么您的相机在模型中是有效的.
至于渲染问题,微软在这方面有很好的文档:http://msdn.microsoft.com/en-us/library/bb203933.aspx
您可以将此代码段用作帮助程序:
private void DrawModel(Model m)
{
Matrix[] transforms = new Matrix[m.Bones.Count];
float aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9736 次 |
| 最近记录: |