Issues with internal classes and members when doing Custom Content Pipeline

I’m currently trying to write a Scene Processor / Reader / Writer to make the art pipeline from Blender into our game a little easier. The intention is to be able to take an FBX exported from Blender and get not only the standard model data from it, but additional information such as lighting, animation, etc.

I’ve seen a lot of code around for doing one of two things:

  1. Extending the ModelProcessor and adding some additional information (such as animation) to its Tag property.
  2. Doing a full custom data type with the writer / reader / processor, but it’s always something completely unique to models (Weapon data from an XML for example)

The issue I’m having is that basically I need to do a combination of the two. I need a custom reader, writer, and processor to get the data from the FBX to eventually loading my Scene object in-game.

The processor is pretty simple and easy to work with, I was able to understand and get a rough version of that working without any issues. However, the Reader / Writer parts are giving me issues. The biggest issues I’m running into is the fact that Model-related classes and the ContentTypeReader class has such a large number of internal fields. This prevents me from working with them since all my game-specific code is obviously in my game’s namespace instead of Microsoft.Xna.Framework.Content

So I’m curious if anyone has successfully done a custom content reader / writer that blends custom data and built-in classes such as Model? If so, how have you managed to get around the internal issues?

I got my Writer (mostly) working by simply copying a bulk of the ModelWriter code. The only real issue here was it couldn’t write the BoundingSphere info because that is internal to the Content namespace.

The main issue when trying to do the same thing on the Reader side of things is that the base ContentTypeReader class has internal on its GraphicsDevice field, so anything outside of the Content namespace can’t access this. And since this is one of the required parameters for creating a ModelMesh, I’m unsure of how exactly I could provide this aside from making some otherwise unnecessary dependencies to my Game class from all my custom content classes.

Pretty much all the code I’ve mentioned can be seen in the ModelWriter, ModelReader, and ModelProcessor classes. I’m happy to post my code if anyone thinks it will be helpful, but right now it’s literally just copy / pasted from the Model-related classes and adds one additional test string so I can confirm it working.

TLDR - Does anyone have a working example of a custom reader / writer that uses the Model class?

Managed to get around the issues by making my own classes for anything that was causing issues. They’re all exact duplicates of the classes inside the XNA Framework namespace, but they’re in my game’s namespace. It’s a pretty hack way of handling this but it works fine.

If anyone knows the intended way to handle this, or the reasoning behind some of the internal fields / sealed classes, I’d still be very interested in hearing it. They seem extremely arbitrary - is it just leftover from some odd choices in XNA? For example, why is ModelBoneCollection perfectly fine to use but ModelMeshCollection isn’t due to its internal constructor? Or why so many classes have just one random function marked internal, especially when often it’s a simple helper function.

Maybe from the start there were more methods marked as internal and then these modifiers have changed over time just out of necessity or something? Just a thought since I don’t know either and also wondered why it seems a bit arbitrary in some places some times… :thought_balloon: