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

slides built from carter chapter 6 and msdn the content
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Slides built from Carter Chapter 6 and MSDN

slide-2
SLIDE 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).

slide-3
SLIDE 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.

slide-4
SLIDE 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.

slide-5
SLIDE 5

Content Pipeline

From MSDN

slide-6
SLIDE 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 2nd method.

slide-7
SLIDE 7

Using the XELibrary (again)

Using XELibrary; private FPS fps; private FirstPersonCamera camera; private InputHandler input; input = new InputHandler(this); Components.Add(input); camera = new FirstPersonCamera(this); Components.Add(camera) #if DEBUG //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)

Declarations Constructor()

slide-8
SLIDE 8

Organizing project

 Create some subdirs

 Right click in solution explorer

  • n content

 Add new item -> folder

 Create one for Models  Create one for Textures  Will reduce clutter

slide-9
SLIDE 9

XNA logic

1.

Main app calls game constructor

2.

Game constructor creates any game components and calls their constructors

3.

XNA Framework calls the games Initialize()

4.

XNA calls each game component’s Initialize()

5.

XNA calls each Drawable Compenent’s LoadContent

6.

XNA calls game’s LoadContent()

slide-10
SLIDE 10

XNA logic

7.

XNA calls game Update() method

8.

XNA calls each game component’s Update()

  • 9. XNA calls game’s Draw()
  • 10. XNA calls ech drawable component’s Draw()
  • 11. Repeat 7-10 until exits
slide-11
SLIDE 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.
slide-12
SLIDE 12

Loading a 3D Model

private Model model;

 LoadContent()

model = content.Load<Model>(@"Content\Models\asteroid1");

slide-13
SLIDE 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);

slide-14
SLIDE 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(); } }

slide-15
SLIDE 15

Let’s texture

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

  • riginalAsteroid =

content.Load<Texture2D>(@"Content\Textures\as teroid1")

slide-16
SLIDE 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);

slide-17
SLIDE 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(); } }

slide-18
SLIDE 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);

slide-19
SLIDE 19

Screenshots