XNA 3.1中的多重模型



我有XNA 3.1,如何在XNA 3.1中加载多个模型,以便从数组或按钮单击或切换任何内容进行渲染?我只需要加载多个三维模型来渲染。

这是链接

链接

我在哪里得到代码,但这个代码在4.0 中

Model[ ] modelArray;
protected override void LoadContent() 
{
   modelArray = new Model[3];
   modelArray[0] = Content.Load<Model>("model1");
   modelArray[1] = Content.Load<Model>("model2");
   modelArray[2] = Content.Load<Model>("model3");
}
protected override void Draw(GameTime time)
{
    GraphicsDevice.Clear(Color.LightBlue);
    foreach (Model m in modelArray) 
    {
       foreach (BasicEffect be in m.Effects) 
       {
          be.World = YOURWORLDMATRIX;
          be.View = YOURVIEWMATRIX;
          be.Projection = YOURPROJECTIONMATRIX;
       }
       m.Draw();
    }
    base.Draw(time);
}

这一行出现错误,他们向我显示了这个错误:

ERROR1:'Microsoft.Xna.Framework.Graphics.Model' does not contain a definition for    
   'effects' and no extension method 'effects' accepting a first argument of type  
         'Microsoft.Xna.Framework.Graphics.Model' could be found (are you missing a 
       using directive or an assembly reference?) 

以及Draw:中的相同错误

  'Microsoft.Xna.Framework.Graphics.Model' does not contain a definition for 'draw' 
       and no 
    extension method 'draw' accepting a first argument of type 
    'Microsoft.Xna.Framework.Graphics.Model' could be found (are you missing a using 
      directive or an assembly reference?) 

在这些线路

m.Effects
m.Draw();

有什么解决方案吗?

绘图过程不同,请尝试以下操作:

foreach (Model m in modelArray) 
{
   foreach (ModelMesh mesh in m.Meshes)
   {
       foreach (BasicEffect effect in mesh.Effects)
       {
          be.World = YOURWORLDMATRIX;
          be.View = YOURVIEWMATRIX;
          be.Projection = YOURPROJECTIONMATRIX;
       }
       mesh.Draw();
   }
}

参考MSDN。

附言:按照惯例,不要对变量使用大写字母。

相关内容

  • 没有找到相关文章

最新更新