0

I have XNA 3.1, how do I load multiple models in xna 3.1 for rendering either from array or button click or switches anything? I just need to load multiple 3d models to render.

This is the link

LINK

Where I get code, but this code is in 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);
}

Errors occur in this line, they show me this error:

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?) 

and also same error in 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?) 

in these lines

m.Effects
m.Draw();

Any solution?

pinckerman
  • 4,115
  • 6
  • 33
  • 42
user2931015
  • 219
  • 2
  • 8
  • 21

1 Answers1

0

The drawing procedure is different, try this:

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();
   }
}

Reference MSDN.

PS: As convention, do not use uppercase for your varables.

pinckerman
  • 4,115
  • 6
  • 33
  • 42