<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cannontrodder's world &#187; XNA with Blender</title>
	<atom:link href="http://www.cannontrodder.net/category/xna/xna-with-blender/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cannontrodder.net</link>
	<description>cannontrodder - Getting nothing done since 1975.</description>
	<lastBuildDate>Sat, 06 Feb 2010 22:19:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing Blender and the Collada exporter</title>
		<link>http://www.cannontrodder.net/2008/03/19/installing-blender-and-the-collada-exporter/</link>
		<comments>http://www.cannontrodder.net/2008/03/19/installing-blender-and-the-collada-exporter/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 01:01:12 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA with Blender]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2008/03/19/installing-blender-and-the-collada-exporter/</guid>
		<description><![CDATA[This is a guide on how to set up Blender and the Collada exporter plug-in. You&#8217;ll need to follow this guide in order to be able to use my XNA Blender importer.

First you will need to install Blender itself. There are new versions released quite often but at the time of writing, the current stable [...]]]></description>
			<content:encoded><![CDATA[<p>This is a guide on how to set up Blender and the Collada exporter plug-in. You&#8217;ll need to follow this guide in order to be able to use my XNA Blender importer.</p>
<p><span id="more-84"></span></p>
<p>First you will need to install Blender itself. There are new versions released quite often but at the time of writing, the current stable version is 2.45 and I suggest downloading it <a title="link Blender download page" href="http://www.blender.org/download/get-blender/" target="_blank">directly from the Blender Foundation</a>.</p>
<p>Installation should be simple, just use the defaults but make sure you have the following selected when the installer asks you:</p>
<p align="center"><img height="272" alt="Image" src="http://www.cannontrodder.net/wp-content/image-3.jpg" width="424" /></p>
<p>I chose the installation folder of <strong>&#8220;C:\Program Files\Blender Foundation\Blender&#8221;</strong> but if you install somewhere else, that is fine &#8211; just remember where as you are going to need to install the Collada exporter plugin there shortly.</p>
<p>Next, you need to install Python. Blender requires you to have Python installed as it&#8217;s what most of the custom Blender import/export plugins are written in. Blender 2.45 was compiled against Python 2.5 and you need to <a title="link to Python 2.5 download" href="http://www.python.org/download/releases/2.5/" target="_blank">download</a> and install that too. The Python project releases bug fixes from time to time while maintaining compatibility and currently the latest version of Python 2.5 is actually numbered 2.5.2. If a new version is released, anything matching 2.5.x will do. Just install Python with all the default options.</p>
<p><img height="103" alt="Image" src="http://www.cannontrodder.net/wp-content/image-4.jpg" width="376" align="right" />When you open Blender after this, you will notice that it opens a separate window apart from the main Blender one. In this window you will see the debug output from any Python plugins. If you installed Blender and Python correctly, you should see it confirm that Python has been detected.</p>
<p>Finally, we need to get the Collada Export plugin for Blender. You might notice if you look at the Blender export plugins in the File-&gt;Export menu, that there is already an entry for the Collada 1.4 exporter. Don&#8217;t use it. It&#8217;s the version that comes with the Blender installer and it&#8217;s broken. It bombs out when you try to export meshes so you need to get the latest bleeding-edge version from Sourceforge, directly from the subversion repository.</p>
<p><strong>Subversion?</strong></p>
<p>In case you don&#8217;t know about it, Subversion is a source-code revision control system which allows developers to collaborate on the same project, checking in their changes when they are happy and updating their local copy to bring in changes from other developers working along with them. I happen to use a Subversion repository at home and at work for my professional and part-time coding projects and highly recommend it. The developers of the Collada Blender export plugin also use a Subversion repository hosted at <a title="link to Sourceforge" href="http://sourceforge.net/" target="_blank">Sourceforge</a>. To get the latest version of the code, you&#8217;ll need to install a Subversion client to connect to and export the code to your local machine.</p>
<p>TortoiseSVN is the de-facto client for Windows and I&#8217;m currently running an alpha version of their up-coming 1.5.0 release. If you&#8217;d prefer not to install alpha version software, install the most recent stable version from <a title="TortoiseSVN download page" href="http://tortoisesvn.net/downloads" target="_blank">here</a>. I&#8217;m using <a title="TortoiseSVN Alpha download page" href="http://tortoisesvn.net/node/310" target="_blank">this one</a> but the instructions are the same, you just need to be aware that my screenshot will differ from yours cosmetically.</p>
<p>Once you have installed TortoiseSVN and rebooted, browse to the Blender installation folder. Remember, the default is &#8220;C:\Program Files\Blender Foundation\Blender\&#8221;. Then navigate to the .blender folder in there to find where all the plugins live. Right-click on the &#8220;scripts&#8221; folder and choose the option &#8220;TortoiseSVN-&gt;Export&#8221; from the context menu that pops up.</p>
<p>In the &#8220;URL of repository&#8221; text box, put this:</p>
<pre>
<code>https://colladablender.svn.sourceforge.net/svnroot/colladablender/trunk</code>
</pre>
<p>Then select the &#8220;<em>Immediate children, including folders</em>&#8221; option from the dropdown. It should look like this:</p>
<p align="center"><img height="389" alt="Image" src="http://www.cannontrodder.net/wp-content/image-5.jpg" width="555" /></p>
<p>Hit ok and it will export the latest version of the plugin, directly from the source-code repository the developers use, into your machines Blender plugin folder. It may be slow, and do not be surprised at data transfer rates of 1k/s &#8211; luckily the plugin is very small. If it asks you if you are sure, confirm your paths are exactly as in the image above and hit yes.</p>
<p>You are now ready to launch Blender and start exporting Blender models into Collada files!<img height="348" alt="Image" src="http://www.cannontrodder.net/wp-content/image-6.jpg" width="237" align="right" /></p>
<p>To do this, go to the File-&gt;Export menu in Blender and choose &#8220;COLLADA 1.4&#8243; and be sure to select the options in the image to the right, to avoid any errors.</p>
<p>Choosing to export to triangles is important as Blender allows you to model using quads which, while great for modelling, is not much use to hardware rendering code which requires geometry to be passed as triangles.</p>
<p>Disabling physics is important as the ability to export this is still under development and will cause an error if you do not disable it.</p>
<p>It will export the files with a .dae extension. Visual C# Express will still display it as an XML file with collapsible nodes to make browsing it easier. It also helps identify the file when added as content in an XNA project as the BlenderXNA Content Importer is setup to be automatically applied to .dae files by default.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2008/03/19/installing-blender-and-the-collada-exporter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blender and XNA &#8211; Part 2</title>
		<link>http://www.cannontrodder.net/2008/03/10/blender-and-xna-part-2/</link>
		<comments>http://www.cannontrodder.net/2008/03/10/blender-and-xna-part-2/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 15:50:02 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA with Blender]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2008/03/10/blender-and-xna-part-2/</guid>
		<description><![CDATA[In part 1, I looked at the Content Pipeline and it&#8217;s components. In this article, I will be looking at the files I am going to be importing and the tool I will be using to create them.

Why Blender?
Blender is an open-source 3D modelling package which is under active development by the Blender Foundation, a [...]]]></description>
			<content:encoded><![CDATA[<p>In part 1, I looked at the Content Pipeline and it&#8217;s components. In this article, I will be looking at the files I am going to be importing and the tool I will be using to create them.</p>
<p><span id="more-68"></span></p>
<p><strong>Why Blender?</strong></p>
<p><a title="Blender home page" href="http://www.blender.org/">Blender</a> is an open-source 3D modelling package which is under active development by the <a title="About Blender Foundation" href="http://www.blender.org/blenderorg/blender-foundation/">Blender Foundation</a>, a non-profit public benefit corporation. It is released under the terms of the <a title="GNU License" href="http://www.gnu.org/copyleft/gpl.html">GNU Public License</a> and is free for anyone to download and run on a wide-range of platforms, including Windows. There is a <a title="Blender Newbies" href="http://blendernewbies.blogspot.com/">huge</a> <a title="Blender nation" href="http://www.blendernation.com/">active</a> <a title="Blender artists site" href="http://blenderartists.org/">community</a> <a title="Blender website list of other community sites." href="http://www.blender.org/community/user-community/">around</a> the world currently using Blender.</p>
<p>It offers functionality to rival that of commercial packages, it&#8217;s very quick and it has a user interface that is centred on making your workflow as fast as possible.</p>
<p>Because Blender is free, there&#8217;ll be no worry that you&#8217;ll have to ditch it&#8217;s use when you one day decide to release a game. That might not be the case with using a <a title="maya learning edition" href="http://usa.autodesk.com/adsk/servlet/item?siteID=123112&amp;id=7679058">learning edition</a> version of a commercial package.</p>
<p><strong>Exporting from Blender</strong></p>
<p><img height="564" alt="A screenshot of the Blender export menu." src="http://www.cannontrodder.net/wp-content/blender-exportlist.png" width="295" align="left" />Because of the open nature of Blender people can extend it to provide export tools for others to use. This is made possible by having Blender integrated with <a title="Python" href="http://www.python.org/">Python</a>, another open-source package. Python is a script-based language that is often used to enable macros or scripting support in other applications.</p>
<p>As you can see from the image, there are quite a few different export plugins that come with Blender upon install. You might notice that XNA already supports two of the formats in this list: FBX (Autodesk) and X (DirectX). I actually don&#8217;t want to those though. I want to use <a title="COLLAborative Design Activity" href="http://www.collada.org/mediawiki/index.php/Main_Page">Collada</a>.</p>
<p><strong>Why Collada?</strong></p>
<p>Collada files are XML files, firstly. This makes them really easy to parse and also really easy to explore in Visual C# Express.</p>
<p>It&#8217;s an open standard which has the remit to provide a standard format for exchange of 3D assets between applications. The potential in the future is that this plugin can support all those other applications.</p>
<p><strong>The Plan</strong></p>
<p>By using Collada, I hope to make my ContentImporter support as much of it&#8217;s flexibility as possible. Then it would be useful just as a general purpose Collada importer for interfacing with other packages and tools you may wish to create. A level editor, for example.</p>
<p>It should be possible to use the plugin to read Collada files into the standard XNA Model class (which I think many users would want) but I also want to explore using it to import into custom classes. My plan is not to just use this to import meshes, but to import other things such as bounding boxes, level floor plans or skeletal animations.</p>
<p><strong>The Code</strong></p>
<p>Right now it is not ready for release in any form. The current status is I have written the ContentImporter, ContentProcessor, ContentTypeWriter, and ContentTypeReader and I&#8217;ve dropped a few test blender meshes into my current version of my framework:</p>
<p><strong>A centred cube.</strong></p>
<p><strong>Two cube meshes in different positions and rotations.</strong></p>
<p><img height="187" alt="Image" src="http://www.cannontrodder.net/wp-content/image-1.jpg" width="207" align="right" /><strong>Two instances of the same cube mesh but in different positions and rotations.</strong></p>
<p><strong>A cube made from multiple materials.</strong></p>
<p><strong>The Blender Suzanne built-in test model (<em>pictured right</em>).</strong></p>
<p>The good news?</p>
<p>They all import without errors. By tracing through the whole process with the simple cube models, I can see that the data is being passed through to my rendering code. The issue I have is that I have written the full pipeline form scratch and could be introducing problems at any point. In fact the current screen display is this:</p>
<p align="center"><img height="202" alt="Errrmm....." src="http://www.cannontrodder.net/wp-content/image-2.jpg" width="222" /></p>
<p>I&#8217;m literally in the dark as to what is happening in the code. The data is passed to the graphics device and I just have to cross my fingers and hope it will work.</p>
<p>To investigate this, I need to use <a title="PIX" href="http://msdn2.microsoft.com/en-us/library/bb173085(VS.85).aspx">PIX</a> the DirectX debugging tool.</p>
<p>I&#8217;ll put up an unsupported demo once I can iron out the rendering bugs, just so people can take a look but then the next task is to package it into more user-friendly plugins they can just drop into their existing projects.</p>
<h1>Next time&#8230;</h1>
<p>I&#8217;ll be looking at the Collada file format in more detail with a glimpse of some code examples to show how it will be parsed. I&#8217;ll also document progress on my work with PIX, something I think will be an interesting task.</p>
<p><a title="Blender and XNA - Part 2" href="http://www.cannontrodder.net/2008/03/08/blender-and-xna-part-1/">Read part 1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2008/03/10/blender-and-xna-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Blender and XNA &#8211; Part 1</title>
		<link>http://www.cannontrodder.net/2008/03/08/blender-and-xna-part-1/</link>
		<comments>http://www.cannontrodder.net/2008/03/08/blender-and-xna-part-1/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 00:20:49 +0000</pubDate>
		<dc:creator>cannontrodder</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[XNA with Blender]]></category>

		<guid isPermaLink="false">http://www.cannontrodder.net/2008/03/08/blender-and-xna/</guid>
		<description><![CDATA[It&#8217;s been a long time since I&#8217;ve posted on XNA on this blog. In fact, a long time since I posted on anything! After a re-shuffle of projects I have been undertaking in my own personal time, I&#8217;ve managed to make far more time to play around with XNA, my real passion.
When I first started [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time since I&#8217;ve posted on XNA on this blog. In fact, a long time since I posted on anything! After a re-shuffle of projects I have been undertaking in my own personal time, I&#8217;ve managed to make far more time to play around with XNA, my real passion.</p>
<p>When I first started playing with XNA, I was intrigued as to how XNA allows developers to get their game assets into XNA. Out-of-the box, XNA allows you to easily include certain graphics formats such as .PNG or .JPEG images and 3D file formats such as .X (DirectX) or .FBX (3D Studio Max). Great if your 3D modelling package exports these formats but not so convenient if it does not. I want to import from <a href="http://www.blender.org/">Blender</a> but this is not supported directly by XNA&#8230;.</p>
<p>However, XNA does have one pretty clever trick up its sleeve:</p>
<p align="center"><strong>The Content Pipeline</strong></p>
<p><span id="more-67"></span></p>
<p>This is a customisable process in which XNA can read source file formats and convert them into binary files for distribution with your game in a format that your game can then read in at run-time. Drop an FBX 3D model file into the content folder in your project and Visual C# Express will use the appropriate Content Pipeline class to parse it and package it into a binary file (an XNB file) during the build process. For your game to use it, you simple have to call the Load method in the XNA run-time content manager to pull the data in and populate a nice, clean runtime Model class.</p>
<p>Things get even more interesting when you realise that you can write your own Content Pipeline components to customise things to your liking. And if I want to import Blender models into my games and use them, I need to understand them.</p>
<p>So in this article, and subsequent ones to follow I am going to look at using the Content Pipeline to import Blender 3D models and render them in an XNA game. As this article is published, I am about 2 or 3 blog-posts ahead of what I am describing &#8211; and I&#8217;m still working it out as I go along!</p>
<p>What I&#8217;d like to share is what I&#8217;ve needed to learn in order to accomplish this, plus how I overcame any problems along the way. If you too are looking to create your own Content Pipeline plugins, this may be of use to you. Even if you are not, learning more about the Pipeline could open up some avenues in your game development that hadn&#8217;t really occurred to you. Let&#8217;s take a look at the Content Pipeline and its fundamental components.</p>
<p>The pipeline consists of 4 distinct parts:</p>
<p><strong>ContentImporter</strong>, <strong>ContentProcessor</strong>, <strong>ContentTypeWriter</strong>, and <strong>ContentTypeReader</strong>.</p>
<p>In Visual C# Express, when you add content you can specify which Content Importer and Content Processor it should us to compile that data into your project. If you wanted to, you could create just a ContentImporter and bolt that onto an existing ContentProcessor in order to support a new file format that XNA does not support already. The flexibility is there though if you wish to go one stage further and customise the entire pipeline for a particular type of game asset.</p>
<p>I&#8217;ll briefly run through the components mentioned above to explain what they do.</p>
<p><strong>ContentImporter</strong></p>
<p>The <a title="msdn class reference" href="http://msdn2.microsoft.com/en-us/library/bb195424(MSDN.9).aspx">ContentImporter</a> parses the content file and fills a set of appropriate classes with the data it contains. XNA provides a set of content classes ready to store such data. For example, if your file contained 3D geometry, you would populate a MeshContent class. For 2D bitmap graphics, you would use a TextureContent class. These content classes can be arranged in a hierarchy so you could pull in multiple images or multiple 3D meshes and arrange them in a parent-child configuration. The important thing to remember about a Content Importer is that it <em>does not care</em> about what the final use of the data will be. Its job is simply to retrive information from the file the content is contained in and make it available to the rest of the Pipeline to do with as it pleases.</p>
<p><strong>ContentProcessor</strong></p>
<p>A <a title="msdn class reference" href="http://msdn2.microsoft.com/en-us/library/bb195449.aspx">ContentProcessor</a> converts those standard data types mentioned above into something that resembles the run-time data structure. If you simply wished to support a new fileformat that XNA does not natively support, a ContentImporter would be all you needed, you could then use the built-in XNA Processors to prepare that content into one of the built-in types, such as <a title="msdn class reference" href="http://msdn2.microsoft.com/en-us/library/microsoft.xna.framework.graphics.model.aspx">Model</a> . So if you wanted to support the <a title="Wiki article about the ILBM format" href="http://en.wikipedia.org/wiki/ILBM">ILBM</a> format for textures (showing my age there), then a ContentImporter would do just fine providing it populated a TextureContent class properly ready for processing by the built-in XNA texture processor.</p>
<p>Conversely, if you wanted to ditch the standard XNA runtime classes, such as Model and use your own, you would need to create a ContentProcessor to spit out your custom class. You could still take advantage of the built-in ContentImporters to save you having to write a class to parse FBX files, for example.</p>
<p>Using your own class instead of the built-in XNA-provided ones might seem risky but it&#8217;s positively encouraged. And if Shawn Hargreaves, one of lead developers of the XNA framework <a href="http://blogs.msdn.com/shawnhar/archive/2007/09/19/note-to-self-model-hammer.aspx">endorses that approach</a> , you shouldn&#8217;t feel too worried about going down that route also.</p>
<p>A moment ago I said that the ContentProcessor creates something that &#8220;<em>resembles the run-time data structure</em> &#8220;. I don&#8217;t want to confuse the reader too much right now, but I&#8217;ll give one example of why this is necessary or useful:</p>
<p>You might wish to specify a particular shader or texture for your model when you import the model itself. That same shader or texture might well be used again in other models in your project. Without going into too much detail too soon, the pipeline allows you to put a placeholder in your content to refer to this other asset. The pipeline will then pull this particular asset in at runtime and plug it into every class that needs it. This ensures that you do not pull the same dependencies in more than once.</p>
<p><strong>ContentTypeWriter</strong></p>
<p>You only need to implement a <a title="msdn class reference" href="http://msdn2.microsoft.com/en-us/library/microsoft.xna.framework.content.pipeline.serialization.compiler.contenttypewriter.aspx">ContentTypeWriter</a> when you are going to use your own custom runtime class to hold your content asset. This is a surprisingly simple class to write as it simply dumps the intermediary class output from your ContentProcessor to an XNB file. An XNB file is what every item of content in the XNA framework is stored in after the project is built. You don&#8217;t need to understand what the exact format of the file is because &#8230;.. <em>it doesn&#8217;t have one</em> !</p>
<p>If you want to store 10 3D meshes in your XNB file, you can. You would simple write out the number of meshes and then follow that by writing out the meshes themselves. XNA looks after the hard part of serialising these objects into a binary format and your code just looks something like this:</p>
<pre>
<code>output.Write(Meshes.Count);
output.WriteObject(listOfVertices1);
output.WriteObject(listOfTriangles1);
..
..
output.WriteObject(listOfVertices10);
output.WriteObject(listOfTriangles10);</code>
</pre>
<p>I&#8217;ve simplified the above but it illustrates that you can just dump out whatever you please, providing you write the part that <em>reads it in</em> to use the same order. That brings us nicely to the final part:</p>
<p><strong>ContentTypeReader</strong></p>
<p>Again, like ContentTypeWriter, you only need to implement a <a title="msdn class reference" href="http://msdn2.microsoft.com/en-us/library/microsoft.xna.framework.content.contenttypereader(MSDN.9).aspx?ref=ZindeShop.Com">ContentTypeReader</a> class if you are not going to be using the built-in run-time classes such as Model or Texture and instead plan to use your own custom class. Using the pseudo-code above as an example, the complementary ContentTypeReader would do something like:</p>
<pre>
<code>meshCount = input.ReadInt32();
for (i=0; i &amp;lt; meshCount; i++)
{
   listOfVertices[i] = input.ReadObject();
   listOfTrangles[i] = input.ReadObject();
}</code>
</pre>
<p>The ContentReader creates an instance of your run-time custom class that will hold your game asset, populates it and returns it. When you ask the ContentManager in your game to load in your asset, the ContentManagers load method calls this ContentTypeReader and returns your custom content class ready to use in your game at runtime.</p>
<h1>Next time&#8230;</h1>
<p>In my next article, I am going to explain why I decided to use Blender for my game content generation and discuss the various ways to get content out of Blender. I&#8217;ll explain why I chose the export method I did and we&#8217;ll look at the file format directly so you can better understand how we actually go about pulling the data it contains into the XNA environment.</p>
<p><a title="Blender and XNA - Part 2" href="http://www.cannontrodder.net/2008/03/10/blender-and-xna-part-2/">Read part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cannontrodder.net/2008/03/08/blender-and-xna-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
