0

我在 3DS Max 中使用库存引擎模型创建了一个场景,并添加了我自己、飞机和按钮的一些东西。

http://i.stack.imgur.com/R2iva.png

无论我如何导出场景,无论是使用 panda 导出器的 .X 还是使用 2012.2 fbx 导出器的 .fbx,当加载到 XNA 并渲染时,它们都出现在彼此之上。

http://i.stack.imgur.com/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 并没有导出我在场景中创建的对象相对于场景原点的位置。

4

1 回答 1

1

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.

于 2012-01-18T23:50:10.323 回答