XNA 4:导入 FBX 问题
我在从 FBX 文件导入 3D 模型时遇到问题。
源模型包含 575 个对象 + 1 个相机,如下所示: http://habreffect.ru/ files/23d/542fa7f67/source_model.png
在 XNA 中,用内容管道准备的模型包含 82 个网格和 576 个骨骼。 因此,当我绘制模型时,我只能看到源模型的一部分。结果图如下: http://habreffect.ru/files/28a/6e61c0215/Result_view.png
我的绘图代码:
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] transforms = new Matrix[_model.Bones.Count];
_model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (var mesh in _model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.LightingEnabled = true;
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] * _world;
effect.View = _view;
effect.Projection = _proj;
}
mesh.Draw();
}
base.Draw(gameTime);
如何获取 XNA 模型实例中的所有 575 个网格?
谢谢!
UPD:我尝试将 FBX 模型导入 3ds max,选择所有网格并使用“导出所选”。结果 FBX 文件增大了 11 倍。然后我将其作为内容添加到 XNA 项目中,加载的模型包含所有 575 个网格,并且正确渲染。
不幸的是,这种手动转换方法不适合我 - 我需要从可变的 fbx 模型渲染存储库。
那么,什么 FBX 文件对于 XNA 内容处理器“好”(我使用 XNA 4)?
I have a problem with importing 3D model from FBX file.
Source model contains 575 objects + 1 camera and looks like this: http://habreffect.ru/files/23d/542fa7f67/source_model.png
In XNA prepared with content pipeline model contains 82 meshes, and 576 bones.
So, when I draw my model, I see only part of source model. Result picture like following:
http://habreffect.ru/files/28a/6e61c0215/Result_view.png
My drawing code:
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] transforms = new Matrix[_model.Bones.Count];
_model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (var mesh in _model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.LightingEnabled = true;
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] * _world;
effect.View = _view;
effect.Projection = _proj;
}
mesh.Draw();
}
base.Draw(gameTime);
How can I get all 575 meshes in my Model instance in XNA?
Thanks!
UPD: I tried to import my FBX model to 3ds max, select all meshes and use "Export selected". Result FBX file is 11x bigger. Then I add it as content to XNA project, loaded model contains all 575 meshes, and it rendered correctly.
Unfortunately, this manual converting method don't suit me - I need to render varied fbx models from mutable repository.
So, what FBX file are "good" for XNA content processor (I use XNA 4)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,在 MSDN 上我发现FbxImporter 设计用于处理 2006.11 版本的 FBX 格式。
最近 Autodesk 发布了 FBX Converter 2012.1,其中包含其他工具,如 FBX Eplorer、FBX Viewer。
FBX资源管理器可以显示FBX文件的结构,我比较了从3D MAX文件导出的和源FBX文件。它们具有不同的内部格式。我尝试进行以下转换: FBX ->科拉达 -> FBX,结果FBX文件包含类似于从MAX导出的数据结构。
因此,我只需将结果 FBX 添加到我的 XNA 应用程序的内容中,并且它的渲染效果很好:)
另一种使其工作的方法是使用 Autodesk FBX SDK 手动读取模型,并在 XNA 中绘制它。
结论:
So, on MSDN I found that FbxImporter designed to work with 2006.11 version of FBX format.
Recently Autodesk released FBX Converter 2012.1, which contains other tools, like FBX Eplorer, FBX Viewer.
FBX explorer can show structure of FBX file, and I compare exported from 3D MAX file, and source FBX file. They have different internal format. I tried to make following conversion: FBX -> Collada -> FBX, and the result FBX file contains similar to exported from MAX data structure.
So, I simply add the result FBX to Content of my XNA app, and it's rendered well :)
Another way to make it work is to use Autodesk FBX SDK to manually read model, and draw it in XNA.
Conclusion:
在最新的 3dx max 2012 中打开 3d 模型,并将其导出为
.fbx
格式。此.fbx
已使用 xna 模型加载器正确加载。导出时您甚至可以嵌入资源,因此您不必通过 XNA 添加纹理。Open the 3d model in latest 3dx max 2012 and export it in
.fbx
format. This.fbx
is loaded properly with the xna model loader. While exporting you can even embed the resources, so you dont have to add textures to it through XNA.您正在 3DS MAX 中使用实例化。 XNA 不直接支持这一点。
您必须自己为每个实例骨骼绘制网格。
理想情况下,您应该使用 DirectX 实例化在单个 Draw() 调用中为每个骨骼绘制一次网格。
但是您必须通过将骨骼转换为实例顶点来编写自己的代码来做到这一点。
默认情况下,XNA 仅支持最基本的操作。
You are using instancing in 3DS MAX. This isn't supported directly by XNA.
You have to draw the mesh for each instance bone yourself.
Ideally you would instead use DirectX instancing to draw each mesh once per bone in a single Draw() call.
But you have to roll your own code to do that, by converting the bones into instance vertices.
By default XNA only supports the most basic operations.