Can't get model to display properly

Hi,

I have a created a airplane in 3DS Max (it's not finished), but i have rendered it you can see it here:

http://home.exetel.com.au/feldaspar/plane_rendered.gif

When I go to diplay it while running the game from XNA stuidio express all I get is this:

http://home.exetel.com.au/feldaspar/game.gif

I think it is probably more the way it is being output from 3DS Max, but i'm new to both XNA and 3DS so I dont know. I exported it using the FBX extension, filmbox.

This is my code:

protected override void LoadGraphicsContent(bool loadAllContent){

if (loadAllContent){

mymodel = content.Load<Model>(@"Content\Models\p11");

}

}

........

protected override void Draw(GameTime gameTime)

{

graphics.GraphicsDevice.Clear(Color.Black);

foreach (ModelMesh mesh in mymodel.Meshes)

{

//This is where the mesh orientation is set, as well as our camera and projection

foreach (BasicEffect effect in mesh.Effects)

{

effect.EnableDefaultLighting();

effect.World = Matrix.CreateRotationY(modelrotation) * mesh.ParentBone.Transform * Matrix.CreateRotationZ(modelzrotation) *

Matrix.CreateTranslation(modelposition) * Matrix.CreateRotationX(-50);

effect.View = Matrix.CreateLookAt(camposition, Vector3.Zero, Vector3.Up);

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),

aspectRatio, 1.0f, 10000.0f);

}

//Draw the mesh, will use the effects set above.

mesh.Draw();

}

base.Draw(gameTime);

}



Answer this question

Can't get model to display properly

  • Hans Preuer

    The problem is in the way you calculate the world transform. ModelMesh.ParentBone.Transform is relative to that bone's parent bone. See Shawn's post about drawing models and notice that he uses CopyAbsoluteBoneTransformsTo() to get absolute transforms. You might also want to read Shawn's other post that talks about flattening the bone hierarchy so that you can use one transform for the whole model.

    This mistake is also made in the XNA documentation so you're not the first to hit this problem.

    Cheers,
    Leaf.



  • Can't get model to display properly