Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a scene that contains mutiple objects. How can I import it in XNA and maintain each object position? Right now I export the scene in .fbx and load it in a model like this:

 cube.model = contentManager.Load<Model>("cub");

But the objects don't retain their position and are all gathered in one point.

I need a method to import all the objects as individual objects but to retain the objects position in the scene. (i.e. I need to import the scene so that I may manipulate the objects and retain their position in the scene so that I shouldn't reposition all the objects by myself)

The objects are not connected, thus there are no bones. They are individual objects, just placed in some positions.

This is my drawing function, the cube is the gameobject.

void DrawGameObject(GameObject gameobject)
{
    foreach (ModelMesh mesh in gameobject.model.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.PreferPerPixelLighting = true;
            Matrix b = Matrix.Identity;
            effect.World = b * gameobject.orientation;
            effect.Projection = camera.projectionMatrix;
            effect.View = camera.viewMatrix;
        }

        mesh.Draw();
    }
}
share|improve this question

1 Answer 1

Done. I was drawing the model wrong. It actually had bones:

void DrawGameObject(GameObject gameobject)
{
    Matrix[] transforms = new Matrix[gameobject.model.Bones.Count];
    gameobject.model.CopyAbsoluteBoneTransformsTo(transforms);

    foreach (ModelMesh mesh ingameobject.model.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();
            effect.Projection = camera.projectionMatrix;
            effect.View = camera.viewMatrix;
            effect.World = transforms[mesh.ParentBone.Index] * gameobject.orientation;
        }

        mesh.Draw();
    }
}
share|improve this answer
    
You can also accept your own answer, as it solves the problem in question. Just in case you didn't know. –  famousgarkin Jan 12 '12 at 21:11
    
yes i know, but to accept your own answer you must wait for 2 days (22 hrs left) –  Badescu Alexandru Jan 13 '12 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.