<?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>Promethe's Blog &#187; Quake 2</title>
	<atom:link href="http://blog.promethe.net/tag/quake-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.promethe.net</link>
	<description>Web, RIAs and chocolate spaghettis...</description>
	<lastBuildDate>Tue, 29 Jun 2010 09:24:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Quake 2&#8242;s 3D models in Flash 10</title>
		<link>http://blog.promethe.net/2009/10/07/quake-2-3d-models-in-flash-10/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quake-2-3d-models-in-flash-10</link>
		<comments>http://blog.promethe.net/2009/10/07/quake-2-3d-models-in-flash-10/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 12:42:28 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Quake 2]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=428</guid>
		<description><![CDATA[Loading and rendering Quake 2's maps is a challenge because Flash 10 doesn't handle complex 3D geometry very well. But what about a smaller count of polygons ? Say a 3D model for example... already done! What about an animated 3D model then? Details, pictures and a demo application right after the jump... MD2 file [...]]]></description>
			<content:encoded><![CDATA[<p>Loading and rendering Quake 2's maps is a challenge because Flash 10 doesn't handle complex 3D geometry very well. But what about a smaller count of polygons ? Say a 3D model for example... already done! What about an animated 3D model then?</p>
<p><strong>Details, pictures and a demo application right after the jump...</strong></p>
<p><span id="more-428"></span></p>
<h4>MD2 file format</h4>
<p>Quake 2 uses the MD2 file format  to store animated 3D models. It is a quite simple file format: each MD2 file stores a single mesh and its animations. Each animation is just copy of the original mesh with different positions for each vertex. The number of vertices and the indices are the same for each frame. Therefore, the MD2 file format is easy to adapt to the Flash Platform because no complicated shaders/bones are required to animate the model: you just have to display the right vertices!</p>
<p>But it is not THAT simple. Each animation is actually subdivided into frames (vertices really). Because storing a fluid animation would take a lot of frames (and a lot of memory), only a few keyframes are stored. When rendering, one must compute the interpolation coefficient between the current and the next keyframe and use it to get the interpolated vertices. The following code does it all:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> frame1	<span style="color: #000000; font-weight: bold;">:</span> Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>Number<span style="color: #000000; font-weight: bold;">&gt;</span>	= _currentFrame.vertices;
<span style="color: #6699cc; font-weight: bold;">var</span> frame2	<span style="color: #000000; font-weight: bold;">:</span> Vector.<span style="color: #000000; font-weight: bold;">&lt;</span>Number<span style="color: #000000; font-weight: bold;">&gt;</span>	= _nextFrame.vertices;
<span style="color: #6699cc; font-weight: bold;">var</span> c2		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>		= _frame <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>_frame<span style="color: #000000;">&#41;</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> c1		<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>		= <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000; font-weight: bold;">-</span> c2;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">length</span>	<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>		= frame1.<span style="color: #004993;">length</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">length</span>; <span style="color: #000000; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
	_vertices<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = frame1<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">*</span> c1 <span style="color: #000000; font-weight: bold;">+</span> frame2<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">*</span> c2;</pre></div></div>

<p>... and here is the demo application :</p>
<div id="attachment_475" class="wp-caption aligncenter" style="width: 510px"><a rel="shadowbox[q2];width=500;height=375" href="http://blog.promethe.net/wp-content/uploads/2009/10/MinkoMD2Demo.swf"><img class="size-full wp-image-475" title="minko_q2_brianna" src="http://blog.promethe.net/wp-content/uploads/2009/10/minko_q2_brianna.jpg" alt="minko_q2_brianna" width="500" height="375" /></a><p class="wp-caption-text">Flash 10 MD2 loader</p></div>
<p style="text-align: center;">
<h4>What it does...</h4>
<ul>
<li>load Quake 2's MD2 files</li>
<li>basic z-sorting using faces barycenter</li>
<li>add a "frame" property to the mesh to handle animations</li>
<li>interpolate and update vertices only when necessary</li>
<li>wireframe material (press "w")</li>
<li>"free chase" camera (mouse click + drag'n'drop to turn around the model)</li>
</ul>
<h4>What it doesn't do...</h4>
<ul>
<li>use BSP trees to handle z-sorting (1 BSP tree / frame takes a lot of time and memory...)</li>
<li>loop through a specific animation</li>
<li>read Quake 2's animation files</li>
</ul>
<h4>Known issue(s)</h4>
<p>None. If you find one please let me know! Performance seems to be very good actually...</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/10/07/quake-2-3d-models-in-flash-10/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Load and display Quake 2&#8242;s Maps in Flash 10</title>
		<link>http://blog.promethe.net/2009/10/01/load-and-display-quake-2s-maps-in-flash-10/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=load-and-display-quake-2s-maps-in-flash-10</link>
		<comments>http://blog.promethe.net/2009/10/01/load-and-display-quake-2s-maps-in-flash-10/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 17:37:26 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[Quake 2]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=433</guid>
		<description><![CDATA[The Quake-series is really awesome. Not only in terms of gameplay but also technically. Quake 1, 2 and 3 are especially impressive. No wonder why Quake's graphics engine, maps or models file formats have been reused in many many games such as Half Life, Call of Duty or Medal of Honnor! So why not in [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>Quake-series is really awesome</strong>. Not only in terms of gameplay but also <strong>technically</strong>. Quake 1, 2 and 3 are especially impressive. No wonder why Quake's graphics engine, maps or models file formats have been reused in many many games such as <strong>Half Life</strong>, <strong>Call of Duty</strong> or <strong>Medal of Honnor</strong>! So why not in your own Flash 10 game?</p>
<p>There are so many reasons why loading Quake 2 files inside the Flash player would be considered as just "impossible". Performance would be the first and main one. One would just consider that Flash is not fast enough to display complex 3D graphics, not even those of a game as old as Quake 2 (published in 1996!). But using Flash 10 latests features such as the Vector and GraphicsTrianglePath classes, it is actually quite doable!</p>
<p><strong>Details, pictures and a demo application right after the jump!</strong></p>
<p><span id="more-433"></span></p>
<h4>Quake 2's maps file format</h4>
<p>But the really big advantage here is inside the Quake 2 maps file format itself. Each map is a *.BSP file and the BSP file format might be the best ratio in terms of ease of implementation against performance optimization. As you might have guessed, *.BSP files actually store a pre-compiled <a href="http://en.wikipedia.org/wiki/Binary_space_partitioning" target="_blank">Binary Space Partitionning</a> tree of the map itself. For those who don't already know about BSP trees, just imagine that it is actually the best known method to handle a polygon-perfect z-sorting in Flash when dealing with 3D. But computing a good BSP tree of a large and complex 3D model such as a map takes a lot of time... that is why having a pre-compiled and ready to load BSP tree is just great!</p>
<p>You can find a lot of good documents on the Quake 2 BSP file format. The one hosted on <a href="http://www.flipcode.com/archives/Quake_2_BSP_File_Format.shtml" target="_blank">flipcode</a> is quite complete and easy to understand. It is actually the one I used to create my BSP loader. Reading the file formats specifications shows that *.BSP files also include "visibility information". This data is also very important because it makes the user able to know which area of the map is visible from any other area. This way, only the areas visible from the area where the player stands have to be displayed which is an incredible performance boost!</p>
<p>The following application is a proof of concept of a Flash powered Quake 2 *.BSP loader :</p>
<div id="attachment_434" class="wp-caption aligncenter" style="width: 508px"><a rel="shadowbox[quake2_proof];width=500;height=375" href="http://blog.promethe.net/wp-content/uploads/2009/10/MinkoQuake2BSPTest.swf"><img class="size-full wp-image-434" title="quake2_bsp_proof" src="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_bsp_proof.jpg" alt="quake2_bsp_proof" width="498" height="373" /></a><p class="wp-caption-text">Click on the picture to launch the demo application.</p></div>The application weights 174Ko because the *.BSP file is embed in it. With the map file as an external resource, the application weights only 20Ko! The map is called ''q264_3.bsp" and can be found on Google. It is not an actual Quake 2 map but a fan made map.</p>
<p>Here are some screenshots of the same application loading much more complex maps (those screenshots have been made with the Flash debugger which explains the higher memory consumption) :</p>
<p><div id="attachment_456" class="wp-caption aligncenter" style="width: 510px"><a href="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_actcity2.jpg" rel="shadowbox[post-433];player=img;"><img class="size-full wp-image-456" title="quake2_actcity2" src="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_actcity2.jpg" alt="quake2_actcity2" width="500" height="375" /></a><p class="wp-caption-text">actcity2</p></div>
<div id="attachment_457" class="wp-caption aligncenter" style="width: 510px"><a href="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_aqnitro.jpg" rel="shadowbox[post-433];player=img;"><img class="size-full wp-image-457" title="quake2_aqnitro" src="http://blog.promethe.net/wp-content/uploads/2009/10/quake2_aqnitro.jpg" alt="aqnitro" width="500" height="375" /></a><p class="wp-caption-text">aqnitro</p></div>
<h4>What it does...</h4>
<ul>
<li>load Quake 2's *.BSP files</li>
<li>build the corresponding geometry (vertices, indices and UV data) using Flash 10 native types such as Vector and GraphicsTrianglePath</li>
<li>frustum culling and clipping using bounding boxes and bounding spheres</li>
<li>mouse controlled "free chase" camera (click + drag'n'drop to look around, mouse wheel to zoom in/out)</li>
</ul>
<h4>What's next...</h4>
<ul>
<li>use the embed BSP data to handle z-sorting</li>
<li>use visibility information to display only visible clusters</li>
<li>load WAL textures (Quake 1 and 2 textures file format, already done just have to post it <img src='http://blog.promethe.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )  and use them properly to display the map</li>
<li>load MD2 animated 3D models (again, already done and just have to post it!)</li>
</ul>
<h4>Known issue(s)</h4>
<p>If you zoom enough to place the camera "inside" the map geometry, you will notice a severe framerate drop down. It is very logical since frustum clipping will have to check and eventually clip each polygon of the geometry against the relevant view frustum planes. Because visibility information tells us what is actually visible or not, handling it properly should offer a huge performance boost: instead of having to clip the whole geometry, only the visible areas will be treated.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/10/01/load-and-display-quake-2s-maps-in-flash-10/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
