Brandon Bloom

I implemented a scene graph. Items in the graph are of type Entity. StaticVisual, a subclass of Entity, takes a Model as a constructor parameter. Using the content pipeline and contentManager.Load<Model>("assetName") things seem to be working smoothly.

Now, I want to extend the content pipeline to have complete scenes be content. I'm not sure how to do this without writing a ton of redundant and error prone code...

My idea is to write a Model Processor and look at the node's names in order to decide which types of Entities to instantiate. I'd modify my StaticVisual class to take a ModelMesh (or a ModelMeshPart ) as a parameter and in theory I could construct a whole scene graph.

I'd like to write single generic pair of EntityReader and EntityWriter classes, but I don't have a run-time Model to pass to my StaticVisual class. It looks like I will I have to write a Content class and a ContentReader/Writer for every single type of Entity. Is this correct

I noticed the ContentSerializer attribute, but I can't find the documentation on it. Will that help me at all

Thanks!

Brandon Bloom



Re: XNA Game Studio Express The Content Pipeline and my Scene Graph

Shawn Hargreaves - MSFT

I'm not sure I'm fully understanding your question, but you can use generics for ContentTypeReader and ContentTypeWriter implementations. If you have a class:

class MyEntity<T>

you can write:

[ContentTypeWriter]
class MyEntityWriter : ContentTypeWriter<MyEntity<T>>
{
}

and this will be picked up and used to serialize any instances of MyEntity, regardless of the type of T.

Is that any help





Re: XNA Game Studio Express The Content Pipeline and my Scene Graph

Brandon Bloom

When I said "genric" I didn't mean like .net generics :-)

Let me attempt to rephrase my question more generally (without refering to my particular implementation).

This is a little contrived, but let's say I have the following:

class Thingamajig
{
public int SomeMagicValue;
public Model Model;
}

[ContentProcessor]
class ThingamajigProcessor : ContentProcessor<NodeContent, Thingamajig>
{
public override Thingamajig Process(NodeContent input, ContentProcessorContext context)
{
ModelContent modelContent = new ModelProcessor().Process(input, context);

Thingamajig thing = new Thingamajig();
thing.SomeMagicValue = 10;
thing.Model = // Can't assign here!! Need to make a ThingamajigContent class
}
}

In this case, it looks like I have to make a ThingamajigContent class where the Model property is of type ModelContent. I then need to write a reader and writer. This isn't a big deal for a single class, but I plan to have a whole bunch of different types of Thingamajigs (a class heiarchy various levels deep) which will all need their own corresponding *Content class and reader/writer. That seems like a ton of work, how can I avoid that

Am I making any more sense now





Re: XNA Game Studio Express The Content Pipeline and my Scene Graph

Shawn Hargreaves - MSFT

Gotcha. Yeah, this can be kind of a pain. I've used three different solutions in various places, all seem to work ok for different scenarios.

The pattern of having one runtime type and a separate *Content is in some ways the cleanest, and that's what we've done in the framework. As you say, this can be a pain for a large class hierarchy though.

Another option is to go for a more loosely typed object model and store your references as type object. That way you can assign either the runtime or design time model type to them, and cast as appropriate when you use the data.

A third option is to use .NET generics:

class Thingamajig<T>
{
    public int SomeMagicValue;
    public T Model;
}

Then in your design time code, you can write processors that operate on a Thingamajig<ModelContent>, while at runtime you can use
Thingamajig<Model>, while only having to write a single implementation of Thingamajig.




Re: XNA Game Studio Express The Content Pipeline and my Scene Graph

Brandon Bloom

Ah clever...

Thanks for the speedy and helpful responses.

I'm still unsure of how to tackle the reader/writer problems. Do I need to write a reader/writer per class I saw the ContentSerializer attribute and was hoping to be able to invoke some simple serialize method on any Thingamajig subclass.





Re: XNA Game Studio Express The Content Pipeline and my Scene Graph

Shawn Hargreaves - MSFT

At the moment you need a reader/writer pair per class, yes.

We have automatic reflection based serialization for the xml intermediate files, but not for the binary .xnb output files.

This is an area I'd like to improve in future versions, but at least for now I'm afraid you have to implement the ContentTypeWriter and ContentTypeReader by hand.





Re: XNA Game Studio Express The Content Pipeline and my Scene Graph

Brandon Bloom

Bummer...

Oh well, maybe I can see what I can whip up with reflection myself :-)

Thanks again for the kick *** support.