C#Xna 4.0 foreach循环三维模型未加载

C#Xna 4.0 foreach循环三维模型未加载,c#,visual-studio-2010,3d,game-development,C#,Visual Studio 2010,3d,Game Development,我尝试过使用foreach循环制作DrawModel方法: void DrawModel(Model model, Vector3 modelPosition) { foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.LightingEn

我尝试过使用foreach循环制作DrawModel方法:

void DrawModel(Model model, Vector3 modelPosition)
    {
        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.LightingEnabled = true;
                effect.EnableDefaultLighting();
                effect.PreferPerPixelLighting = true;

                effect.World = Matrix.CreateTranslation(modelPosition);
                effect.Projection = cameraProjectionMatrix;
                effect.View = cameraViewMatrix;
            }
            mesh.Draw();
        }

    }

关于我遗漏的东西有什么想法吗?

看起来很接近,是从样本中复制的吗?到底是什么不起作用?你试过调试它吗?我试过了,当我调试它时,它出现了一个关于“null exception”之类的错误,当我研究foreach循环时,几乎所有的东西都说foreach循环必须完全正确,否则它们将无法工作。除此之外,不,我没有真正调试那么多,因为我还有其他更重要的项目:(请务必阅读有关该异常的内容