Load a Model Mesh

Ok now if you have got the "Hello World" program running perfectly we can move on,

Now lets see how to Draw an animated mesh onto the screen. I will show you the code first and then explian by using comments:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using Xploit;

namespace sample
    public class Game1 : Microsoft.Xna.Framework.Game
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        XMeshModel model;                    // object of a model 

        public Game1()
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

        protected override void Initialize()
        protected override void LoadContent()
            model = new XMeshModel("default");                                            //name of the fbx/x file that you have added to your content folder
            XBase.BackgroundColor = Color.CornflowerBlue;                            //background color

        protected override void UnloadContent()

        protected override void Update(GameTime gameTime)
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)

            XBase.UpdateCamera(new Vector3(-50, 50, -60), Vector3.Zero);                                     //updates camera
            XBase.UpdateLight(new Vector3(100, 75, -100), Vector3.Zero, 2.0f, 0.1f);                        //will explain later
            model.UpdateModel(Matrix.CreateTranslation(0, 0, 0) * Matrix.CreateScale(.5f));            //update your model

        protected override void Draw(GameTime gameTime)
            XBase.BeginDraw();                                                                                                 //List all models between the BeginDraw and EndDraw methods
            model.Draw();                                                                                                          //just drawing the model

Last edited Jan 3, 2010 at 4:14 PM by adityav89, version 2


No comments yet.