Import Model without content pipeline

For my game I store all resources into .res file, so I can get bytes of each a resource file in runtime (like a zip file). For load texture with bytes data source it’s not a problem : Texture2D.FromStream(... and my bytes image).

But after lot of search on the web, I can’t find a way to load a model from bytes data… just content.Load<Model>(string) work where string is the name of xnb file but content.Load(xnbBytesArray) doesn’t exist and Model.FromStream( ...). And it’s impossible for performance/security reasons, to extract each model of the .res file, to load each file model with the content manager and after delete all created files.

I know we can’t import .fbx files directly because they need to pass into the content processor but when I compile my project, I found my models into .xnb file.

So if in runtime I have bytes array data of a xnb model file, how can I do for create a Model instance with that ?

Thank you a lot.

Do you really need to store the assets in .res files? Seems unusual. Nevertheless, here are some ideas.

Idea #1:
Write the resource stream into a temporary file and load the file using the ContentManager.

Idea #2:
You could create a custom ContentManager and override ContentManager.OpenStream. In OpenStream return your resource stream instead of a file stream. Then you can load the model with content.Load<Model>("name_of_model").

That is what I suggest as well. Overloading ContentManager.OpenStream is easy to do and allows you all sorts of flexibility.

Thank you for your answers, but the .res file allows me to perform encryption, so I will try your to override ContentManager.OpenStream :slight_smile: