Greytone

Hi,

I am currently porting my managed DX9 engine to XNA, and need to duplicated a model for writing vertex data to. In the old engine I just load the model twice to get 2 identical meshes, each with their own separate vertex buffer. With the content manager in XNA this appears to be 'optimized' into not working, as it appears to return the same vertex buffers for each model. This of course means if I change one vertex buffer the changes are reflected in both models, which is not the desired behavior.

So my question is, is there a way to force the content manager to load to a new buffer and not just return to me already loaded pointers. If not, any information as to how to create a new Model and fill it with a loaded models data would be greatly appreciated. (Seems most of the Model properties, like Meshes are read only) - Note, I do have access to the vertex data via a custom content processor.



Re: XNA Game Studio Express Duplicating Content Manager Resources

dczraptor

You could try using two different content managers.




Re: XNA Game Studio Express Duplicating Content Manager Resources

Greytone

Thanks for your reply,

Two content managers will be an acceptable work around for now. However its not very extendable as I would need a new content manager for every copy. So I am still interested in a method to duplicate that doesnt need a new content manager for each duplication.





Re: XNA Game Studio Express Duplicating Content Manager Resources

Shawn Hargreaves - MSFT

The framework Model class is not designed to be editable at runtime, so if you need that kind of functionality your best bet is probably to make a custom model class that can better implement whatever it is you need to do. That's not actually very hard to do, because the content pipeline does all the hard work of importing data from the different source formats. Probably about 95% of the model code in the framework is either in the importers or the content pipeline helper functions that you can resuse, and only maybe 5% in the Model class itself, so adding a custom Model type is fairly easy.

At the moment the best way of loading two copies of the same data is either using two content managers, or (what I would personally choose) just to load it once but then implement a Clone method on your type. Cloning is cool because you can often just duplicate the pieces of data that you need to modify, and leave all the constant things shared between multiple instances, so when used well it can dramatically reduce sizes for this kind of data.