DoppleX:- Is a custom model processor mostly responsible for taking in NodeData and outputting its custom type? Or is it for writing its data in XNB form?
The model processor converts NodeData to some other type.
If this type is not already supported, you must then also provide a ContentTypeWriter and ContentTypeReader pair for reading/writing that custom type to XNB format. We already have ContentTypeWriters and readers for built in types such as Model, and also for lists and collections, so if your processor output for instance a List<MyType>, you would only need to implement a ContentTypeWriter for MyType, rather than for the entire List<MyType> class. Our built in writer would handle the List collection, and then call into your custom writer when it came to write out the object data for each instance in the list.
DoppleX:- What is XNB anyway? My impression is that it’s sort of a generic “compiled” way of storing content post-buildtime. Is this accurate?
Exactly. XNB format is basically just whatever binary data the ContentTypeWriter decided to save into it, prefixed with a standard header that indicates what kind of object the file contains, and which ContentTypeReader should be used to load it.
DoppleX:- If all I’m doing is adding a list of edges to the standard ModelMeshPart class, is there a way to easily handle reading and writing my extra data from the XNB file? (Each entry in the list is four vertices, each with an associated normal vector – although I may also want to precalculate the face normal of the two triangles on the edge and include that in the data.)
Depending on how typesafe you want to be, if you make a custom MyData class that contains your four vertices, four normals, etc, you would also have to make a writer and reader for that class. Alternatively it seems like you could just use an array of Vector3 here, and use the first four elements for your vertices, next four for normals, etc, in which case our built-in array and vector writers would know how to handle this data without you writing any custom serialization code at all.
If you make your processor by deriving from the built-in ModelProcessor and overriding the Process method, you can call the base.Process to get the output ModelContent, then attach your custom data to the Tag property of whichever objects you are interested in within the output data tree. We have a builtin writer for ModelContent data, which will automatically save out whatever objects you attach to the Tag. If those are of a type that we already know how to save (for instance an array or list of vectors) it can do that automatically, otherwise it will try to look up and call into a type writer for whatever custom object type it finds in the tag.
The "picking with triangle accuracy" sample is probably the best example of attaching custom data to a model tag in this way.
DoppleX:- Is there an easy way of traversing the triangles in a mesh during content processing? Or do I need to reconstruct them from lists of vertices and indices?
You'll have to reconstruct them: we don't have any direct representation for edge data in the mesh object model. This is an area I'd love to get feedback about (via the Connect site) if you have any particular ideas for helpers you'd find useful.
DoppleX:
The
actual vertex locations for a piece of geometry content aren't directly
accessible through GeometryContent - they're actually in the
MeshContent object and I need to use the VertexContent object to match
the indices given by geometry.Indices to the corresponding indices in
the parent MeshContent...
You got it. We actually built in a shortcut for doing this, since it is such a common pattern: you can use the values from geometry.Indices to look up into geometry.Vertices.Positions (which will internally follow the backlink and pull the right position vector out of the parent MeshContent for you).
DoppleX:
And the normal data is in a totally
seperate array in the VertexContent object.. I'm not sure if I index
into it with the indices from geometryContent or whether I have to go
through the indirect indices in the VertexContent again...
You can use the values from geometry.Indices to index into geometry.Vertices.Channels[VertexChannelNames.Normal()].
DoppleX:
I
think I'm finally getting close to being able to put things together,
at least - which brings up a different question: Since this runs at
build time rather than run time, how do I go about debugging it?
If you have the full version of Visual Studio 2005, see the posts from Stephen and jwatte in
this thread. If you are using C# Express,
see here.
--
XNA Framework Developer
blog -
homepage