Xna Gs4 Loading Models From File

Started by
1 comment, last by MartinLoga 13 years, 3 months ago
Hi,

I'm searching for an easy way to load an fbx model directly from file instead of using Content.Load. I found some interessting stuff like a ContentBuilder doing the deal but I was hoping there ist something like Model.fromFile.

Thanks

Maddin
Advertisement
There is nothing built into the XNA Framework to easily facilitate Model.FromFile. There are three ways you can proceed:

1) Use the content pipeline and use Content.Load. This is generally good for most people as it does all the file parsing and processing at build time so the loading process is just reading in bytes which can greatly reduce loading times.

2) If you're building an editor or other tool you don't plan on redistributing, you can leverage the content pipeline at runtime to build and load your assets. There are a few examples at http://create.msdn.com that use this features, such as the sample on our built in effects which uses the content pipeline types to compile and load an FX file at runtime. Note that this requires the full .NET 4.0 framework and the content pipeline assemblies are not redistributable so it's only a valid option if you plan to use the tool on a machine that has XNA Game Studio 4.0 (not the redist) installed.

3) The last option is the manual route. You can open up any file you want, figure out how to parse it, and build your own set of vertex and index buffers. You can't make an actual Model type since it doesn't have public constructors, but you can build your own model class to mirror it and fill with any data you want. I don't really recommend this as it will take longer to load the models over the first option, but if you need this feature this is one of the ways you can handle it.

Hope that helps. :)
Tank you verry much. In the meantime I learned a lot about the content pipeline.

Basically I'm writing a model viewer. So yes I kind of need to load data wich was not processed by the content pipeline during compile time.
But the data does not change often. It's more like using the same data for weeks. So I decided to write a little tool wich converts my content to xnb files and deploy it to the systems using the viewer.
During runtime it's verry easy to load the xnb files via contentManager.Load<Model>("ModelName"); as long as you give the ContentManager the right path via contentManager.RootDirectory (e.g. ="Content";) where the precompiled files are.

This topic is closed to new replies.

Advertisement