Monday, August 15, 2011

XNA Notes–Day 5


In short, the Importer reads from text into objects, and the Processor loads stuff (like the actual textures from the texture name) using other Processors (like the default processor for a texture) and applies effects.

Content Processor

To create a custom content processor you add a new Content Pipeline Extension Library and add a reference to it from your project.

Create a new class in this project and derive it from ContentProcessor, setting the template variable to whatever type of file we want to load and what type of file we're going to generate.

public MyContentProcessor : ContentProcessor<InputType, OutputType> {}

Then we override the Process function (that looks something like this)

public OutputType Process(InputType input, ContentProcessorContext context)

Finally, in the Content project, select the element to process and change the processor to the new one you made.

You can add properties to the content processor you create, and they appear on the visual studio properties when you select the asset in the content project.

Content Importer

To load new formats (game level).
You crterate a Content Pipeline Extension Project and create a class that derives from ContentImporter<ToImport.Extension> and override the Import function.

Content Writer

You inherit from the ContetTypeWriter<ClassToWrite> class,
and in that class you override the Write function and write out all the data you need to.

2 comments:

  1. Your short definitions are a little incorrect, so lemme explain them:

    -Content Importer: interprets the source file (be it a model, texture, sound...) and converts it to a collection of managed data so C#/XNA can handle it easily later. This works at compile time.

    -Content Processor: takes the data preprocessed by the Content Importer and applies an additional layer of processing (swap winding order of polygons, change texture format...). Works at compile time, too.

    -Content Writer: serializes your processed content into a XNB. This is the last step done on compilation.

    -Content Reader: called when loading a resource with ContentManager.Load. Deserializes the XNB into your runtime type.

    Keep up the good work!

    ReplyDelete
  2. r2d2rigo: Thank you for looking through my notes and commenting, it really helps!

    ReplyDelete