XNA 模型导入 - 所有网格都显示在彼此之上

发布于 2024-12-27 20:50:30 字数 1137 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潇烟暮雨 2025-01-03 20:50:30

您需要将父骨骼和子骨骼的所有变换矩阵组合起来,如下所示:

Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);

foreach (ModelMesh mesh in model.Meshes) {
    foreach (BasicEffect ef in mesh.Effects) {
        ef.World = transforms[mesh.ParentBone.Index];
        //Also do other stuff here, set projection and view matrices
    }
}

可能有更好的方法,但此代码应该可以工作。

You need to combine all the transform matrices from parent bones and child bones like this:

Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);

foreach (ModelMesh mesh in model.Meshes) {
    foreach (BasicEffect ef in mesh.Effects) {
        ef.World = transforms[mesh.ParentBone.Index];
        //Also do other stuff here, set projection and view matrices
    }
}

There is probably a better way, but this code should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文