slides built from carter chapter 6 and msdn the content
play

Slides built from Carter Chapter 6 and MSDN The Content Pipeline - PowerPoint PPT Presentation

Slides built from Carter Chapter 6 and MSDN The Content Pipeline Youre an artist, you have your favorite tool to create content, do you want to learn yet another one? So the content pipeline must be able to take assets in various


  1. Slides built from Carter Chapter 6 and MSDN

  2. The Content Pipeline  You’re an artist, you have your favorite tool to create content, do you want to learn yet another one?  So the content pipeline must be able to take assets in various formats and load them into an XNA game.  E.g. our 3d model must be converted to be used.  Do you want to build vertices and triangles for you models?  Designed to work for both programmers and artists.  The Content Pipeline will take our files (assets) as input, then convert them so that XNA can compile them into an easily loadable format (F5 does this).

  3. Content Importer  Reads data in  Standard imports  3D: Autodesk FBX and DirectX .x ( NodeContent )  Textures: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. ( TextureContent )  Spritefont ( FontDescription )  DirectX effects ( EffectContent )  XML ( NodeContent )  Can build your own for other file types  Can also find many on the web.

  4. Content Processor  Standard processors  Effect Processor – compiles EffectContent program  ModelProcessor – Takes a NodeContent and compiles it into a ModelContent (can texture and transform)  PassThroughProcessor – Does nothing  FontDescriptionProcessor – Compiles FontDescription into a SpriteFontContent  FontTextureProcessor – Compiles TextureContent into a SpriteFontContent (also takes Texture2Dcontent)  TextureProcessor – Processes TextureContent – allows you to manipulate textures  XACT for sound  Also can write a custom processor  Might also want to modify existing processor, i.e always scale.

  5. Content Pipeline From MSDN

  6. 3D models  We could build models by creating all of the vertices and triangles in our code like last time.  Joy!  Or, we could get someone to create a model for us, or find one on the web.  Maya, Blender, 3dStudioMax, etc.  Numerous formats, there are some converters, you tend to get what you pay for, i.e. free ones don’t always work so well  Let’s try the 2 nd method.

  7. Using the XELibrary (again) Using XELibrary; private FPS fps; Declarations private FirstPersonCamera camera; private InputHandler input; input = new InputHandler(this); Components.Add(input); camera = new FirstPersonCamera(this); Components.Add(camera) #if DEBUG Constructor() //draw 60fps and update as often as possible fps = new FPS(this, true, false); #else fps = new FPS(this, true, false); #endif Components.Add(fps)

  8. Organizing project  Create some subdirs  Right click in solution explorer on content  Add new item -> folder  Create one for Models  Create one for Textures  Will reduce clutter

  9. XNA logic Main app calls game constructor 1. Game constructor creates any game components and 2. calls their constructors XNA Framework calls the games Initialize() 3. XNA calls each game component’s Initialize() 4. XNA calls each Drawable Compenent’s LoadContent 5. XNA calls game’s LoadContent() 6.

  10. XNA logic XNA calls game Update() method 7. XNA calls each game component’s Update() 8. 9. XNA calls game’s Draw() 10. XNA calls ech drawable component’s Draw() 11. Repeat 7-10 until exits

  11. XNA Logic 12. If device is lost call UnloadContent() 13. If the device is reset start at step 6 (loadContent) 14. Gamer exits game 15. XNA calls game’s Dispose method. 16. Game’s dispose calls base object’s dispose …. 17. XNA calls each game component’s dispose. 18. XNA calls UnloadContent() 19. Game’s dispose get focus back and game exits.

  12. Loading a 3D Model private Model model;  LoadContent() model = content.Load<Model>(@"Content\Models\asteroid1");

  13. Drawing a 3D Model  Set up the world matrix (model to world transforms) world = Matrix.CreateRotationZ(.1f * (float)gameTime.TotalGameTime.TotalSeconds) * Matrix.CreateScale(.5f) * Matrix.CreateTranslation(new Vector3(1000, 0, - 4500));  Now draw model DrawModel(ref model, ref world);

  14. Drawing a 3D Model private void DrawModel(ref Model m, ref Matrix world, Texture2D texture) { Matrix[] transforms = new Matrix[m.Bones.Count]; m.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in m.Meshes) { foreach (BasicEffect be in mesh.Effects) { be.EnableDefaultLighting(); be.Projection = camera.Projection; be.View = camera.View; be.World = world * mesh.ParentBone.Transform; } mesh.Draw(); } }

  15. Let’s texture private Model model; model = content.Load<Model>(@"Content\Models\asteroid1"); greyAsteroid = content.Load<Texture2D>(@"Content\Textures\as teroid1-grey"); originalAsteroid = content.Load<Texture2D>(@"Content\Textures\as teroid1")

  16. Drawing a 3D Model  Set up the world matrix (model to world transforms) world = Matrix.CreateRotationZ(.1f * (float)gameTime.TotalGameTime.TotalSeconds) * Matrix.CreateScale(.5f) * Matrix.CreateTranslation(new Vector3(1000, 0, - 4500));  Now draw model DrawModel(ref model, ref world, greyAsteroid );

  17. Drawing a 3D Model private void DrawModel(ref Model m, ref Matrix world, Texture2D texture) { Matrix[] transforms = new Matrix[m.Bones.Count]; m.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in m.Meshes) { foreach (BasicEffect be in mesh.Effects) { be.EnableDefaultLighting(); if (texture != null) be.Texture = texture; be.Projection = camera.Projection; be.View = camera.View; be.World = world * mesh.ParentBone.Transform; } mesh.Draw(); } }

  18. Draw Many Objects world = Matrix.CreateTranslation(new Vector3(0, 0, 1)); DrawModel(ref penguinModel, ref world, originalAsteroid); world = Matrix.CreateTranslation(new Vector3(0, 0, 5 )); DrawModel(ref penguinModel, ref world, null); world = Matrix.CreateRotationZ(.1f * (float)gameTime.TotalGameTime.TotalSeconds) * Matrix.CreateScale(.5f) * Matrix.CreateTranslation(new Vector3(1000, 0, -4500)); DrawModel(ref model, ref world, greyAsteroid); world = Matrix.CreateRotationY(.2f * (float)gameTime.TotalGameTime.TotalSeconds) * Matrix.CreateTranslation(new Vector3(-1000, 0, -4500)); DrawModel(ref model, ref world, originalAsteroid); world = Matrix.CreateRotationX( MathHelper.ToRadians(270.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateTranslation(new Vector3(0, 0, -4500)); DrawModel(ref model, ref world, greyAsteroid); world = Matrix.CreateRotationY(1.57f * (float)gameTime.TotalGameTime.TotalSeconds) * Matrix.CreateRotationZ(.785f * (float)gameTime.TotalGameTime.TotalSeconds) * Matrix.CreateTranslation(new Vector3(0, 0, 4000 )); DrawModel(ref model, ref world, originalAsteroid);

  19. Screenshots

Recommend


More recommend