Question

In XNA, how do I load in a texture or mesh from a file without using the content pipeline?

Was it helpful?

Solution

I believe Texture2D.FromFile(); is what you are looking for.

It does not look like you can do this with a Model though.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture2d.fromfile.aspx

OTHER TIPS

The .FromFile method will not work on xbox or zune. You have two choices:

  1. Just use the content pipeline ... on xbox or zune (if you care about them), you can't have user-supplied content anyways, so it doesn't matter if you only use the content pipeline.
  2. Write code to load the texture (using .SetData), or of course to parse the model file and load the appropriate vertexbuffers, etc.

For anyone interested in loading a model from a file check out this tutorial:

http://creators.xna.com/en-us/sample/winforms_series2

This is a windows only Way to load a texture without loading it through the pipeline, As Cory stated above, all content must be compiled before loading it on the Xbox, and Zune.

Texture2D texture = Texture2D.FromFile(GraphicsDeviceManager.GraphicsDevice, @Location of your Texture Here.png);

If you really want to load an Xna Xna.Framework.Graphics.Model on PC without the content pipeline (eg for user generated content), there is a way. I used SlimDX to load an X file, and avoid the parsing code, the some reflection tricks to instantiate the Model (it is sealed and has a private constructor so wasn't meant to be extended or customised). See here: http://contenttracker.codeplex.com/SourceControl/changeset/view/20704#346981

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top