WinForms Series 2: Content Loading Sample  

This sample shows you how to import arbitrary 3D models at run time by running the Content Pipeline importers and processors dynamically on the fly as opposed to building all the content ahead of time in the usual way.


Sample Overview

This sample builds on the classes described previously in the WinForms Graphics Device sample. It implements a 3D model viewer control that uses a file selector to let the user choose any .fbx or .x format model. Then it imports that file, loads it, and displays it on the screen.

Note that this sample runs only on Windows. WinForms, MSBuild, and the Content Pipeline are not available on Xbox 360. If you want your game to run on Xbox 360, you must build all your content ahead of time as part of the Visual Studio project. Note also that the XNA Framework redistributable installer does not include the Content Pipeline. This sample will run only on computers that have the XNA Game Studio installed.

Minimum Shader Profile

Vertex Shader Model 1.1
Pixel Shader Model 1.1

Other items in the WinForms Series

WinForms Series 1: Graphics Device Sample  

Comments

 

Ultrahead said:

The ContentBuilder class is really great. Thanks.

January 11, 2008 6:32 AM
 

DodongoXP said:

outstanding!! just what i was looking for..

thanks!!

cheers!!

January 11, 2008 2:40 PM
 

Kludgy said:

Excellent and simple!  Is there a safe way to run the build in the background and raise events in the main application thread?

January 12, 2008 9:43 PM
 

RegisteredUser said:

That's pretty sweet, but will content pipeline ever be included in redist? It would be pretty neat to be able to make a game in which users would be able to add their own content.

January 12, 2008 10:49 PM
 

Matthew Picioccio - MSFT said:

Registered user:

Users do need both Visual Studio (Express is enough) for MSBuild and XNA Game Studio 2.0 for the XNA Content Pipeline.  Both are freely available; see the Getting Started page for more information.

January 12, 2008 11:28 PM
 

RegisteredUser said:

GoDFaDDa: I know it's the case at the moment. And I'm asking if that will ever change. Imagine I create some RPG game in which players go trough dungeons and stuff, then I make campaign editor that uses content pipeline. Then I release the editor to public and suddenly my game has new feature - make your own modules. Yeah, as far as some users could be interested in that if I tell them "Install visual studio for that" they won't be interested anymore. Why? Because they most probably will not need VS for anything else and VS is tool for professionals that they will sometimes think they won't even be able to install easily.

January 13, 2008 8:15 AM
 

Greg453 said:

Hey, cool.

I didn't even know that XNA is able to do that!

Great!

That could be perfect to make your own editor, all you would need now would be a sample showing how to save your own content and your own editor files, and also how a normal game could read those editor files.

January 13, 2008 12:32 PM
 

Matthew Picioccio - MSFT said:

RegisteredUser:  MSBuild is a key component of the XNA Content Pipeline.  If you do not want MSBuild (available free), then do not use the XNA Content Pipeline - load, parse, process, etc. the files yourself.

January 14, 2008 12:13 PM
 

Moramatte said:

So what would be the most lightweight way to redistribute a program that utilizes the content pipeline? If one would build an editor that loads models in runtime, but user are not developers. They should not need to install the heavy IDE´s right?

January 23, 2008 5:33 AM
 

Shawn Hargreaves said:

At the moment the only way to install the Content Pipeline functionality is by installing the full version of XNA Game Studio.

January 30, 2008 1:58 PM
 

XNASorcerer said:

We know that we have to install a full version of XNA Game Studio. I just don't understand why not to just add a few more dlls into the redistributable package.

February 1, 2008 1:48 PM
 

Larjohn said:

They may not be few, but we all want these dll's. What does msbuild needs to run anyway?

February 16, 2008 4:33 PM
 

DrDeth said:

I think that it would be relatively simple to write a "Content Compiler" using the existing content pipeline. Then you could compile your content just before you distribute your game? I guess it depends on the situation, but I dont see much benefit in distributing your content uncompiled.

February 19, 2008 3:12 AM
 

dayson123 said:

thanks for this its really good

February 23, 2008 4:53 PM
 

chimpy said:

Thanks for the great example.  I think I pretty much follow what is going on, but what I don't understand is why the .xnb files end up in a Content folder under bin.  I can't see what makes that happen, and I am just interested because I want to be able to control this in my app.

Thanks again!

March 8, 2008 3:17 PM
 

Matthew Picioccio - MSFT said:

chimpy:

The content project builds to the Content subdirectory by default.  If you click on the Content root in your project, the Properties tool-window will have a "Contend Build Root" property that you can change.

Note that this is different from right-clicking on the Content root and selecting "Properties" from the context menu, which opens a different window with different options.

March 21, 2008 4:52 PM
 

DRealMetroid88 said:

is there a way to get this to work in a net game so we could load a model (or anything else) in the server and the client PC could load the model as well?

March 23, 2008 1:21 PM
 

chimpy said:

Thanks for the response.  I follow what you are saying about setting the property from within VS, but what I was looking for was how to set it within your application so that I could manually control where the compiled files ended up (since the project is in ContentBuilder, not VS).  Turns out what I think I was looking for was:

msBuildProject.SetProperty( "ContentRootDirectory", "LevelOneContent" );

That seemed to do what I was looking for.

Thanks again!

March 26, 2008 2:12 PM
 

Mikeske said:

In the Derived Control Class I've set up a "postprocessor", so I can have a postprocessor in every "view"-control...

If I create a contentmanager in every control (needed to loadcontent of the postprocessor... is there any trouble I need to take count for???

Great sample!!!

Greetz,

Mikeske

May 5, 2008 4:59 PM
Anonymous comments are disabled

About Matthew Picioccio - MSFT

Developer - Developer Education
XNA Community Games Platform
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback