Pages

Saturday, November 27, 2010

how load model in your xbox game

now for developing your xbox game(or even in xna windows games) you need load model in your game.For this purpose you should first design your model in blender or 3ds max or maya or tools like that and export it to .x file .This format commonly used on developing DirectX and xna games.Next in your xbox games add model to to your content .Every model and other thing in content have name you can changed it on properties sidebar.

addmodelxbox

for coding you should doing this steps

1.create model

 Model newModel = Content.Load<Model> (assetName);    foreach (ModelMesh mesh in newModel.Meshes)
        foreach (ModelMeshPart meshPart in mesh.MeshParts)
            meshPart.Effect = effect.Clone(device)

2.next draw model in draw function with code

  Matrix worldMatrix = Matrix.CreateScale(0.0005f, 0.0005f, 0.0005f) * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(19, 12, -5));
     Matrix[] newModelTransforms = new Matrix[newModel .Bones.Count];
     newModel.CopyAbsoluteBoneTransformsTo(newModelTransforms);
     foreach (ModelMesh mesh in newModel .Meshes)
     {
         foreach (Effect currentEffect in mesh.Effects)
         {
             currentEffect.CurrentTechnique = currentEffect.Techniques["Colored"];
             currentEffect.Parameters["xWorld"].SetValue(newModelTransforms[mesh.ParentBone.Index] * worldMatrix);
             currentEffect.Parameters["xView"].SetValue(viewMatrix);
             currentEffect.Parameters["xProjection"].SetValue(projectionMatrix);
         }
         mesh.Draw();
     }

you should add this code before base.Draw(gameTime);

you can use this code in one functions for using more in games or even in more games or add codes during games .

But it is better use this code on functions for better reading or using.

No comments:

Post a Comment

linkwithin

Related Posts Plugin for WordPress, Blogger...