2013-11-26 83 views
0

我有XNA 3.1,如何在xna 3.1中加载多个模型以便从数组或按钮单击或切换任何东西?我只需要加载多个3D模型来渲染。在XNA 3.1中的多个模型

这是链接

LINK

从哪里获得的代码,但是这个代码是在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(); 

任何溶液

回答

0

绘图程序是不同的,试试这个:

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。 PS:按照约定,不要使用大写字母作为可变物。