Jake Pearson
Jake Pearson

Reputation: 27717

XNA load in a texture or mesh from a file without using the content pipeline

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

Upvotes: 2

Views: 5030

Answers (5)

Aranda
Aranda

Reputation: 865

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

Upvotes: 0

Acedia
Acedia

Reputation: 31

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);

Upvotes: 2

Taylor
Taylor

Reputation:

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

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

Upvotes: 3

Joel Martinez
Joel Martinez

Reputation: 47751

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.

Upvotes: 4

Cory
Cory

Reputation: 1339

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

Upvotes: 1

Related Questions