XNA 模型导入 - 所有网格都显示在彼此之上
我在 3DS Max 中使用库存引擎模型创建了一个场景,并添加了一些我自己、飞机和按钮的东西。
https://i.sstatic.net/R2iva.png
无论我如何导出场景,无论是使用 panda 导出器的 .X 还是使用 2012.2 fbx 导出器的 .fbx,当加载到 XNA 并渲染时,都显示在彼此之上。
https://i.sstatic.net/6gdMb.png
由于引擎的各个部分都保留在它们应该在的位置(并且在 3ds max 中是独立的),我非常确定在 3ds max 中有些东西与我的其余对象的布局设置不正确。
更新 1:我用来在 xna 中加载模型的代码如下
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect be in mesh.Effects)
{
be.EnableDefaultLighting();
be.Projection = camera.projection;
be.View = camera.view;
be.World = GetWorld() * mesh.ParentBone.Transform;
// adding the additional * transforms[i]; didnt do anything
}
mesh.Draw();
}
此代码非常适合其他人的模型,但不适用于我制作的任何模型。就像 3ds max 不会导出我在场景中创建的对象相对于场景原点的位置。
I have created a scene in 3DS Max with a stock engine model and some things i added my self, the plane, and the button.
https://i.sstatic.net/R2iva.png
Regardless of how i export the scene, whether its as a .X using panda exporter or .fbx using 2012.2 fbx exporter both, when loaded into XNA and rendered, all appear on top of each other.
https://i.sstatic.net/6gdMb.png
Since the individual parts of the engine all remain where they should (and are seperate in 3ds max) im pretty sure there is something im not setting correctly in 3ds max with the layout of the rest of my objects.
Update 1 : The code i use to load the models in xna is as follows
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect be in mesh.Effects)
{
be.EnableDefaultLighting();
be.Projection = camera.projection;
be.View = camera.view;
be.World = GetWorld() * mesh.ParentBone.Transform;
// adding the additional * transforms[i]; didnt do anything
}
mesh.Draw();
}
This code works great for other peoples models but not any that i make. Its like 3ds max isnt exporting out the positions of the objects that i create in the scene relative to the scenes origin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将父骨骼和子骨骼的所有变换矩阵组合起来,如下所示:
可能有更好的方法,但此代码应该可以工作。
You need to combine all the transform matrices from parent bones and child bones like this:
There is probably a better way, but this code should work.