Content processor parameters in XNA Game Studio 2.0

Originally posted to Shawn Hargreaves Blog on MSDN, Monday, November 26, 2007

One of the 2.0 features I am personally happiest about is the addition of custom parameters to control how your content gets built. This is something we always wanted to do, but didn't have time for in v1, so it feels great to be able to finally finish our original design!

The most obvious impact of this change is that the previous muddle of TextureProcessor, SpriteTextureProcessor, and ModelTextureProcessor class has been replaced with a single improved TextureProcessor. Here it is in the Visual Studio properties window:

See that little + box to the left of the "Content Processor" label? Guess what happens if you expand it:

Tada! If you don't like our default texture format or color keying behavior, you can now easily change this without having to write any custom processor code.

Even better, remember the hoops you had to jump through to customize how models built their textures? Not any more. The built in ModelProcessor now provides parameters controlling not only the 3D model processing, but also how to build any textures that are used on the model:

It is easy to add custom parameters to your own processors. Simply create a public property:

    [ContentProcessor]
    public class MyProcessor : ContentProcessor<MyType, MyOtherType>
    {
        public float numberOfCats;
        {
            get { return numberOfCats; }
            set { numberOfCats = value; }
        }

        float numberOfCats = 23;

        ...

This will automatically show up in Visual Studio when your processor is selected. For bonus points you can include attributes to customize how the property is displayed and initialized:

   [DefaultValue(23.0f)]
   [DisplayName("Number of cats")]
   [Description("Sets how many cats you wish to splice afore the mizzen")]
   public float numberOfCats;
   {

I'm excited about the possibilities this will open up for more powerful and reusable content processors. Imagine if the VegetationProcessor from the Billboard Sample let you choose what textures to use, or if the NormalMapProcessor from the Sprite Effects Sample let you choose how bumpy a normalmap to create...

Blog index   -   Back to my homepage