Adding a .x Model to the Pipeline by hand

Hey all,
I was just curious if there's any way to add a Model from a .x file to the project by code (ie- without using the GSE's asset creation functionality).
I've disected my .csproj file, and I got something like the following, but I don't really know how to translate this to code.


Answer this question

Adding a .x Model to the Pipeline by hand

  • Tryin2Bgood

    VisualStudio uses MSBuild to build .Net projects. MSBuild is an extensible build engine (similar to Ant and NAnt) that is included with the .Net framework. The content pipeline is exposed to msbuild so that VS can build assets but there is nothing to stop you from running msbuild yourself, outside of VS. You could do this using the msbuild.exe command line program or by using the MSBuild Api from IronPython.

    Shawn Hargreaves has posted on how to write a msbuild project file that just does content pipeline builds here. MSBuild is very flexible and its quite easy, once you understand the basic structure of build projects, to make it do what you want - for example it would be quite easy to make it use wild cards to build any file instead of specifying file names inside the build file.

    Cheers,
    Leaf.


  • JustinS

    Wow. I was in some IRC rooms last night, and the guys told me to check out MSBuild, but they weren't quite as descriptive - I thought they were encouraging me to look at the csproj, figure out what libraries the GSE was running to build it, and emulate that code. I didn't realize MSBuild was a whole seperate process with pipeline access.

    That's a great help, thanks so much for the very informative post.
    I look forward to figuring all this out, and hopefully writing up a guide detailing my experience coding a 3d game in IronPython using XNA. I don't think it's something that's been done to any great extent yet, and I'd love to provide extensive documentation.

  • paolob

    Wow, no kidding, that solved it! I've got a working 3D model now. I'll keep playing with it, tutorial coming soon. Thanks so much!

  • WilderLand

    Ok, here's one last question:
    MSBuild gives me a lovely "obj" folder (with subfolder Windows that holds ContentPipeline.xml and House~0.xml) and a "bin" folder (sub windows with house.xnb).

    I'd imagine that my next step is to tell my GraphicsProvider to use that ContentPipeline.xml file as my ContentPipeline, correct This is something that typically the GSE provides for us, but does anyone know exactly what goes on internally to compile a .cs file "with" the content pipeline
    (Because I now need to do the equivalent, by hand, with a .py file, essentially).

    I'll keep on googling around, I've found lots of fascinating stuff that's close to (but not exactly) what I want to be doing right now. I'm sure I'll figure it out, but if anyone knows the answer, and is willing to share it, that'd trump search engines :)

    -Lee Bailey

  • Kris Nye

    You're welcome. I look forward to seeing your results. I use IronPython in various things but mainly as a learning tool - its really useful being able to create a type and then explore it in the interactive console. I've been meaning to code something up for XNA in IronPython but the lure of IntelliSense is just too much.

    Cheers,
    Leaf.


  • Mansoor Shiraz

    IPy handles generics pretty well, it uses square brackets instead of angle brackets though:

    content.Load[Model]("house")

    One thing that might bite you is that the ContentManager defaults to using the executing assembly's directory as the root for locating content files. If you are using IPy this will be whereever ipy.exe is located. Fortunately the ContentManager has a second ctor that takes a string path to use as the root.

    Cheers,
    Leaf.


  • S_Parikh

    ContentPipeline.xml is just an internal cache file used for the incremental rebuild functionality. You can ignore this.

    The content pipeline is only needed to compile your meshes and textures. The *.cs or *.py source code is compiled separately (although in the case of Python I think maybe you just run the .py files directly without needing to compile them first Don't know exactly how that works).

    Once you've run the content build, you will end up with .xnb files for all your built assets in the bin directory. You then just need to point your runtime game code at this directory, using the path parameter when you construct the ContentManager that you will be using the load the content into your game.


  • Nick Karasev

    Beautiful. That was exactly what I was looking for.
    It's still not working correctly, content.Load<Model>("house") is returning False, but I think that might be an issue with Python's support (lack of ) for templating/generics.
    When I get home from work, I'm going to try building a C# library with an overloaded (and renamed) version of ContentManager.Load() that always returns a model, just to simplify things on the python end. That should probably help a bit.

    Thanks so much for all the help, guys
    - Lee Bailey

    (And yes, to answer you, you don't have to build IronPython, you just run the .py file with the ipy.exe interpreter. Sometimes, and I haven't figured out why exactly, you can get a .pyc file out of your .py, which windows recognizes as "Python Compiled Binary". As I understand it, this step is optional, and I haven't yet worried about the performance benefits this may have)

  • Adding a .x Model to the Pipeline by hand