如何使用 BasicEffect 在 XNA 中绘制模型
我想在 XNA 中画一个模型。 我已经在 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);
}
我刚刚注意到这在效率方面相当于谋杀,但我已经尝试了很多东西,我只需要它在优化之前工作即可。
I want to draw a Model in XNA. I've gona ahead and produced it in Blender and Exported it to fbx File Format so the Content Pipeline can work with it. What code should I add to the Draw() method of my WindowsGame() ? I've tried the Following but All I get is a gray screen (Gray not Blue, which is the clear color, mind you) The Model is Imported with content.Load, and this throws no error, and I called it "Bowl".
Can Anyone tell my why this here won't work?
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);
}
I've just noticed that this is equivalent to murder in terms of efficiency but I've tried so many things, I just need it to work before I optimize it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一次尝试渲染某些内容时,一个非常常见的问题是相机没有看到您认为它看到的东西。 另一个可能的问题是模型的规模不符合您的预期。 例如,如果相机在 z 轴上向后 5 个单位,但模型宽 10 个单位,则相机实际上位于模型内部。
就渲染问题而言,微软对此有很好的文档: http: //msdn.microsoft.com/en-us/library/bb203933.aspx
您可以使用此代码段作为帮助器:
A really common issue when first trying to render something is that the camera isn't looking at what you think it's looking at. Another possible issue is that the model is not at a scale that you'd expect. So for example, if the camera is 5 units back on the z, but the model is 10 units wide, your camera is effectively inside the model.
As far as the rendering question goes, Microsoft has pretty good docs on this: http://msdn.microsoft.com/en-us/library/bb203933.aspx
You can use this snippet as a helper: