<?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; Flash</title>
	<atom:link href="http://blog.promethe.net/tag/flash/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>Apple makes its own compiler&#8230; illegal!</title>
		<link>http://blog.promethe.net/2010/04/09/apple-makes-its-own-compiler-illegal/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=apple-makes-its-own-compiler-illegal</link>
		<comments>http://blog.promethe.net/2010/04/09/apple-makes-its-own-compiler-illegal/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 11:21:51 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Aerys]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Flash-to-iPhone packager]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=715</guid>
		<description><![CDATA[﻿"3.3.1 … Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.promethe.net/wp-content/uploads/2010/04/demotivator_compiling.jpg" rel="shadowbox[post-715];player=img;"><br />
<img class="aligncenter size-medium wp-image-717" title="demotivator_compiling" src="http://blog.promethe.net/wp-content/uploads/2010/04/demotivator_compiling-300x235.jpg" alt="" width="300" height="235" /></a></p>
<p><em>﻿"3.3.1 … Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited)."</em></p>
<p>This is the very bad (sad) addition (restriction) to the iPhone developers program everyone is talking about right now. And I feel very concerned about this... and now everyone is wondering if software like the Flash-to-iPhone packager, Mono or Unity are definitely banned from the iPhone programming tool-chain.</p>
<p>I never talked about it before, but Aerys is working on a project targeting the iPhone and the iPad (among a lot of other platforms). And this very project is leveraged by some home-made code generation tool. Therefore, we are very scared of what this kind of restrictions might imply for our business.</p>
<p>But as scary as this statement might look at first, it is actually even funnier when you understand it makes any iPhone/iPad application illegal. And it gets even better because even Apple's standard tool-chain finds itself... prohibited!</p>
<p>The reason is very simple: Objective-C, C or C++ never "link" to any library providing the Documented iPhone APIs. Objective-C, C or C++ actually never link to anything. When compiling your code, the compiler creates an intermediary representation of your program in order to make it easier to (eventually cross-)compile it. In the case of GCC, the compiler used to build such applications, those intermediary languages are:</p>
<ul>
<li>﻿the historical <a title="Register Transfer Language" href="http://en.wikipedia.org/wiki/Register_Transfer_Language">Register Transfer Language</a> (RTL)</li>
<li>the tree language <a title="GENERIC" href="http://en.wikipedia.org/wiki/GENERIC">GENERIC</a></li>
<li>the <a title="Static single assignment form" href="http://en.wikipedia.org/wiki/Static_single_assignment_form">SSA</a>-based <a title="GIMPLE" href="http://en.wikipedia.org/wiki/GIMPLE">GIMPLE</a></li>
</ul>
<p>(Source: <a href="http://en.wikipedia.org/wiki/Intermediate_language" target="_blank">Wikipedia - Intermediate language</a>)</p>
<p><strong>This very intermediate representation is built</strong> before the symbols resolution and <strong>before any linking is done</strong>. Thus, linking against the "Documented APIs" has always been done "through an intermediary translation or compatibility layer". And it won't change anytime soon! But, still, <strong>I wish good luck to Apple's engineers in their future work to patch GCC and make it "compliant" (sic!)</strong>.</p>
<p>To me, it is the most obvious sign that Apple doesn't care about its developers (but I was still pretty thrilled to eventually become one of them about a few days ago...). Not because it bannishes any interesting cross-compiling software venture. And not even because any iPhone/iPad developper who knows about other platforms openness and ease of production will feel sick just by reading this kind of restrictions.</p>
<p>No. To me, Apple is losing it all simply because this kind of idiocy can only be written by someone who doesn't have a clue about how a computer/compiler works! Apple started building casual devices and ends up targeting casual developers. Could this be the first sign of how (so called) intuitiveness - when enforced by completely hermeticly closed devices - finally makes people... dumber? So now the real question is "<strong>What happens when your developers program EULA is written by a marketing control-freak moron?</strong>".</p>
<p><em>PS : The title of this article was desgined to attract the eye. It is my interpretation of the latest Apple's developers program EULA additions and I might be completely off or wrong. Anyway, the doubt and worry caused by this very fuzzy and unclear addition stands as a major issue for all the companies and developers targeting the iPhone and iPad platforms.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2010/04/09/apple-makes-its-own-compiler-illegal/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>AS3 Monitor released on Google Code</title>
		<link>http://blog.promethe.net/2010/04/01/as3-monitor-released-on-google-code/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=as3-monitor-released-on-google-code</link>
		<comments>http://blog.promethe.net/2010/04/01/as3-monitor-released-on-google-code/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 17:22:01 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Aerys]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=683</guid>
		<description><![CDATA[I just released a small but useful piece of software on Google Code: my ActionScript 3.0 Monitor class. This little class makes it possible to watch the properties of any object directly on the stage. It was inspired by Mr. Doob's Stats class. But my Monitor class is entirely dynamic and you can watch any [...]]]></description>
			<content:encoded><![CDATA[<p>I just released a small but useful piece of software on Google Code: my ActionScript 3.0 Monitor class. This little class makes it possible to watch the properties of any object directly on the stage.</p>
<p>It was inspired by <a href="http://code.google.com/p/mrdoob/wiki/stats" target="_blank">Mr. Doob's Stats class</a>. But my Monitor class is entirely dynamic and you can watch any property of any object.</p>
<p>The following simple (and useless?) code sample show how to track the (x, y) position of the mouse cursor on the stage:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">import</span> aerys.<span style="color: #006600;">monitor</span>.<span style="color: #006600;">Monitor</span>;
&nbsp;
  <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
&nbsp;
  <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MonitorDemo <span style="color: #0066CC;">extends</span> Sprite
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MonitorDemo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> monitor : Monitor	= <span style="color: #000000; font-weight: bold;">new</span> Monitor<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
      monitor.<span style="color: #0066CC;">watch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>, <span style="color: #ff0000;">&quot;mouseX&quot;</span>, 0xff0000, 1. <span style="color: #66cc66;">/</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span><span style="color: #66cc66;">&#41;</span>;
      monitor.<span style="color: #0066CC;">watch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>, <span style="color: #ff0000;">&quot;mouseY&quot;</span>, 0x008800, 1. <span style="color: #66cc66;">/</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span>;
      addChild<span style="color: #66cc66;">&#40;</span>monitor<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And here is the result:</p>
<p><a href="http://blog.promethe.net/wp-content/uploads/2010/04/MonitorDemo.swf" rel="shadowbox[monitor];width=500;height=375;options={flashParams: {wmode:'opaque'}}"><img src="http://blog.promethe.net/wp-content/uploads/2010/04/aerys_monitor_demo.jpg" alt="" title="aerys_monitor_demo" width="516" height="433" class="aligncenter size-full wp-image-688" /></a></p>
<p>Here is another simple use case: tracking the (x, y, z) rotation of a 3D camera (<b>the actual application is available on <a href="http://aerys.in" target="_blank">the official Aerys website</a></b>):</p>
<p><a href="http://blog.promethe.net/wp-content/uploads/2010/04/aerys_monitor.jpg" rel="shadowbox[post-683];player=img;"><img src="http://blog.promethe.net/wp-content/uploads/2010/04/aerys_monitor-300x224.jpg" alt="" title="aerys_monitor" width="300" height="224" class="aligncenter size-medium wp-image-705" /></a></p>
<p>The code is open source and <a href="http://code.google.com/p/aerys-monitor/" target="_blank">available on Google Code</a>. Comments and suggestions would be greatly appreciated!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2010/04/01/as3-monitor-released-on-google-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Speaking at the french Flash user group</title>
		<link>http://blog.promethe.net/2010/03/17/speaking-at-the-french-flash-user-group/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=speaking-at-the-french-flash-user-group</link>
		<comments>http://blog.promethe.net/2010/03/17/speaking-at-the-french-flash-user-group/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 22:50:47 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Tontons Flexeurs]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=665</guid>
		<description><![CDATA[... or at least that's the plan! The next meeting of the Tonton Flexers - the closest thing to a "french Flash user group" - is taking place the 23rd of this March and I'll be there to present my 3D library. I would be more than happy to talk about the software, the way [...]]]></description>
			<content:encoded><![CDATA[<p>... or at least that's the plan! The next meeting of the Tonton Flexers - the closest thing to a "french Flash user group" - is taking place the 23rd of this March and I'll be there to present my 3D library.</p>
<p>I would be more than happy to talk about the software, the way I built it and the technical choices that drove its development. I will  also try to emphasize what makes this library different through a few demonstrations.</p>
<p>Depending on the agenda of one of my co-worker, we might also present a very cool piece of software I never spoke about!</p>
<p>You can read more about the event <a href="http://lacantine.org/events/les-tontons-parlent-aux-tontons-flex-camp-organise-par-les-tontons-flexeurs-la-communaute-des-developpeurs-flex-en-france" target="_blank">here</a> (in french).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2010/03/17/speaking-at-the-french-flash-user-group/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AIR 2.0 HTTP Web Server</title>
		<link>http://blog.promethe.net/2009/12/17/air-2-0-http-web-server/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=air-2-0-http-web-server</link>
		<comments>http://blog.promethe.net/2009/12/17/air-2-0-http-web-server/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 10:42:50 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[AIR 2.0]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=607</guid>
		<description><![CDATA[AIR 2.0 brings a lot of new features. Among them is the new ServerSocket class. The Socket class exists since Flash 9 and enabled a lot of new client/server applications. But it has always been limited to client side sockets as long as AIR (and the Flash Platform as a whole for that matter) is [...]]]></description>
			<content:encoded><![CDATA[<p>AIR 2.0 brings a lot of new features. Among them is the new ServerSocket class. The Socket class exists since Flash 9 and enabled a lot of new client/server applications. But it has always been limited to client side sockets as long as AIR (and the Flash Platform as a whole for that matter) is concerned. Therefor, this new server socket feature makes it possible to build actual server software using AIR!</p>
<p>Rich of this new and incredible ability, Christophe Coenraets posted a small but yet very powerful <a href="http://coenraets.org/blog/2009/12/air-2-0-web-server-using-the-new-server-socket-api/">code snippet to build an HTTP web server using AIR 2.0</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/12/17/air-2-0-http-web-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Voice Recognition in Flash 10</title>
		<link>http://blog.promethe.net/2009/12/16/voice-recognition-in-flash-10/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=voice-recognition-in-flash-10</link>
		<comments>http://blog.promethe.net/2009/12/16/voice-recognition-in-flash-10/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 09:59:05 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Microphone]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=602</guid>
		<description><![CDATA[The following video demonstrates a new "voice gesture" library targeting the Flash Platform. As you might have guessed, those "voice gestures" are pretty much like "mouse gestures" but they are activated by voice only. I guess it uses some kind of voice learning/recognition algorithm. I can't stress enough how trhilled I am to see this [...]]]></description>
			<content:encoded><![CDATA[<p>The following video demonstrates a new "voice gesture" library targeting the Flash Platform. As you might have guessed, those "voice gestures" are pretty much like "mouse gestures" but they are activated by voice only. I guess it uses some kind of voice learning/recognition algorithm. I can't stress enough how trhilled I am to see this kind of new and powerful software coming to Flash. This enables a whole new kind of usages and applications...</p>
<p><center><br />
<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8203323&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=8203323&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/8203323">Voice Gesture</a> from <a href="http://vimeo.com/user2807938">didier.brun</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p></center></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/12/16/voice-recognition-in-flash-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frustum Culling in Flash 10</title>
		<link>http://blog.promethe.net/2009/12/13/frustum-culling-in-flash-10/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=frustum-culling-in-flash-10</link>
		<comments>http://blog.promethe.net/2009/12/13/frustum-culling-in-flash-10/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 15:43:05 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=558</guid>
		<description><![CDATA[Update: corrected a few glitches in the bounding sphere creation routine. Optimization is always important. But when it comes to 3D for the Flash Platform, it's an everyday battle. The first ideas that come to mind are to avoid: redrawing the same regions : each pixel value must be set once and only once rendering [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color:#ff0000">Update:</span></strong> corrected a few glitches in the bounding sphere creation routine.</p>
<p>Optimization is always important. But when it comes to 3D for the Flash Platform, it's an everyday battle. The first ideas that come to mind are to avoid:</p>
<ol>
<li>redrawing the same regions : each pixel value must be set once and only once</li>
<li>rendering invisible objects : objects that are out of sight still take a lot of CPU horsepower</li>
</ol>
<p>While Flash takes care of the first one in its very renderer, the second one is not handled. But that is something we can easily address!</p>
<h4 style="text-align: left;">The Technic</h4>
<p>The method is called "frustum culling". The big picture is that every mesh is approximated using a bounding volume (typically a sphere or a box). If the bounding volume is visible, the corresponding mesh is rendered. The two following pictures show the frustum culling caught in action:</p>
<div id="attachment_569" class="wp-caption aligncenter" style="width: 510px"><a href="http://blog.promethe.net/wp-content/uploads/2009/12/frustum_culling_scene.PNG" rel="shadowbox[post-558];player=img;"><img class="size-full wp-image-569" title="frustum_culling_scene" src="http://blog.promethe.net/wp-content/uploads/2009/12/frustum_culling_scene.PNG" alt="The mesh is visible" width="500" height="375" /></a><p class="wp-caption-text">The mesh is visible: TPS counter indicates 18900 triangles per seconds</p></div>
<div id="attachment_568" class="wp-caption aligncenter" style="width: 510px"><a href="http://blog.promethe.net/wp-content/uploads/2009/12/frustum_culling_acting.PNG" rel="shadowbox[post-558];player=img;"><img class="size-full wp-image-568" title="frustum_culling_acting" src="http://blog.promethe.net/wp-content/uploads/2009/12/frustum_culling_acting.PNG" alt="Frustum culling in action (TPS counter indicates 0!)" width="500" height="375" /></a><p class="wp-caption-text">The mesh is out of sight: frustum culling is acting and TPS counter indicates 0!</p></div>
<p><span id="more-558"></span></p>
<h5>1. The frustum</h5>
<p>First things first: before performing frustum culling, you need to build the frustum! The frustum is the 3D shape that contains everything the camera can see. It's made of 6 planes and looks like a truncated pyramid:</p>
<div id="attachment_563" class="wp-caption aligncenter" style="width: 517px"><a href="http://blog.promethe.net/wp-content/uploads/2009/12/view_frustum.png" rel="shadowbox[post-558];player=img;"><img class="size-full wp-image-563" title="view_frustum" src="http://blog.promethe.net/wp-content/uploads/2009/12/view_frustum.png" alt="The view frustum" width="507" height="302" /></a><p class="wp-caption-text">The view frustum</p></div>
<p>Each plane is defined by a plane equation: ax + by + cz + d, where (a, b, c) is the normal of the plane and d the distance on that normal. The 6 planes must be extracted from one of the Matrix3D object used to define the transform from one space to another (world to camera for example). Here are the 6 plane equations:</p>
<ul>
<li>left: (a = m14 + m11, b = m24 + m21, c = m34 + m31, d = m44 + m41)</li>
<li>right: (a = m14 − m11, b = m24 − m21, c = m34 − m31, d = m44 − m41)</li>
<li>bottom: (a = m14 + m12, b = m24 + m22, c = m34 + m32, d = m44 + m42)</li>
<li>top: (a = m14 − m12, b = m24 − m22, c = m34 − m32, d = m44 − m42)</li>
<li>near: (a = m13, b = m23, c = m33, d = m43)</li>
<li>far: (a = m13, b = m23, c = m33, d = m43)</li>
</ul>
<p>The source matrix you chose defines the coordinates systems of the extracted planes:</p>
<ul>
<li>the projection matrix provides planes in view (or camera) space</li>
<li>the view * projection matrix provides planes in world space</li>
<li>the world * view * projection matrix provides planes in object (or local) space</li>
</ul>
<h5>2. Bounding volumes</h5>
<p>Testing every polygon against the frustum is a very expensive task. In order to speed things up, we will rather test a primitive shape that bounds the mesh: a "bounding volume". Common bounding volumes are spheres or boxes. I'll focus on the first one in the rest of the article.</p>
<p>A bounding sphere is pretty simple to implement: you just need to store the center of the sphere and it's radius. That being said, a BoundingSphere class would just contain the center as a Vector3D and the radius as a Number. When you have all the vertices of a mesh, building the bounding sphere is easy :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> computeBoundingSphere<span style="color: #000000;">&#40;</span>myVertices <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><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> BoundingSphere
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">min</span> <span style="color: #000000; font-weight: bold;">:</span> Vector3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span><span style="color: #004993;">Number</span>.<span style="color: #004993;">MAX_VALUE</span>, <span style="color: #004993;">Number</span>.<span style="color: #004993;">MAX_VALUE</span>, <span style="color: #004993;">Number</span>.<span style="color: #004993;">MAX_VALUE</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">max</span> <span style="color: #000000; font-weight: bold;">:</span> Vector3D = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span><span style="color: #004993;">Number</span>.<span style="color: #004993;">MIN_VALUE</span>, <span style="color: #004993;">Number</span>.<span style="color: #004993;">MIN_VALUE</span>, <span style="color: #004993;">Number</span>.<span style="color: #004993;">MIN_VALUE</span><span style="color: #000000;">&#41;</span>;
	<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;">int</span> = myVertices.<span style="color: #004993;">length</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> center <span style="color: #000000; font-weight: bold;">:</span> Vector3D = <span style="color: #0033ff; font-weight: bold;">null</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> radius <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = <span style="color: #0033ff; font-weight: bold;">null</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>; i <span style="color: #000000; font-weight: bold;">+</span>= <span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">min</span>.<span style="color: #004993;">x</span> = myVertices <span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">min</span>.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">?</span> myVertices<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">min</span>.<span style="color: #004993;">x</span>;
		<span style="color: #004993;">min</span>.<span style="color: #004993;">y</span> = myVertices <span style="color: #000000;">&#91;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">min</span>.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">?</span> myVertices<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">min</span>.<span style="color: #004993;">y</span>;
		<span style="color: #004993;">min</span>.z = myVertices <span style="color: #000000;">&#91;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #004993;">min</span>.z <span style="color: #000000; font-weight: bold;">?</span> myVertices<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">min</span>.z;
&nbsp;
 		<span style="color: #004993;">max</span>.<span style="color: #004993;">x</span> = myVertices <span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #004993;">max</span>.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">?</span> myVertices <span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">max</span>.<span style="color: #004993;">x</span>;
		<span style="color: #004993;">max</span>.<span style="color: #004993;">y</span> = myVertices <span style="color: #000000;">&#91;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #004993;">max</span>.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">?</span> myVertices<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">max</span>.<span style="color: #004993;">y</span>;
		<span style="color: #004993;">max</span>.z = myVertices <span style="color: #000000;">&#91;</span><span style="color: #004993;">uint</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #004993;">max</span>.z <span style="color: #000000; font-weight: bold;">?</span> myVertices<span style="color: #000000;">&#91;</span><span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>i <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">max</span>.z;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	center = <span style="color: #0033ff; font-weight: bold;">new</span> Vector3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>myMax.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> myMin.<span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2.0</span>, <span style="color: #000000;">&#40;</span>myMax.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> myMin.<span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2.0</span>, <span style="color: #000000;">&#40;</span>myMax.z <span style="color: #000000; font-weight: bold;">+</span> myMin.z<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2.0</span><span style="color: #000000;">&#41;</span>;
        radius = <span style="color: #004993;">Math</span>.<span style="color: #004993;">max</span><span style="color: #000000;">&#40;</span>myMax.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> center.<span style="color: #004993;">x</span>, myMax.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> center.<span style="color: #004993;">y</span>, myMax.z <span style="color: #000000; font-weight: bold;">-</span> center.z,
		          center.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> myMin.<span style="color: #004993;">x</span>, center.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> myMin.<span style="color: #004993;">y</span>, center.z <span style="color: #000000; font-weight: bold;">-</span> myMin.z<span style="color: #000000;">&#41;</span>;	
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">new</span> BoundingSphere<span style="color: #000000;">&#40;</span>center, radius<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<h5>3. Point to plane distance</h5>
<p>The plane equation (ax + by + cz + d) can be stored as a Vector3D object. Indeed, the Vector3D implements x, y and z but also a w Number attribute. This last one is supposed to store the homogenous coordinate. Nonetheless, we can use those 4 Number attributes to store the (a, b, c, d) values that defines our plane equation.</p>
<p>In order to test whether a bounding volume is inside or outside the frustum, we must be able to compute the distance of this object to the plane. To do so, we use the dot product of the point with the plane normal (which must be normalized first) :</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> planeToPointDistance<span style="color: #000000;">&#40;</span>myPlane <span style="color: #000000; font-weight: bold;">:</span> Vector3D, myPoint <span style="color: #000000; font-weight: bold;">:</span> Vector3D<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> myPlane.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">*</span> myPoint.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> myPlane.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">*</span> myPoint.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> myPlane.z <span style="color: #000000; font-weight: bold;">*</span> myPoint.z <span style="color: #000000; font-weight: bold;">+</span> myPlane.w;
<span style="color: #000000;">&#125;</span></pre></div></div>

<h5>4. The test function</h5>
<p>Now that our frustum and our bounding volumes are ready, we can add this little test function that checks whether an object is visible or not:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> testBoundingSphere<span style="color: #000000;">&#40;</span>myPlanes      <span style="color: #000000; font-weight: bold;">:</span> Vector.,
                                   mySphere      <span style="color: #000000; font-weight: bold;">:</span> BoundingSphere<span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span>
<span style="color: #000000;">&#123;</span>
	<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;">int</span> = myPlanes.<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>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">d</span> 	<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">Number</span> = planeToPointDistance<span style="color: #000000;">&#40;</span>myPlanes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #009900;">// bouding sphere is out of the frustum</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span> <span style="color: #000000; font-weight: bold;">+</span> mySphere.radius <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span>;
		<span style="color: #009900;">// bounding sphere is spanning</span>
		<span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">d</span> <span style="color: #000000; font-weight: bold;">-</span> mySphere.radius <span style="color: #000000; font-weight: bold;">&lt;</span>= <span style="color: #000000; font-weight:bold;">0.0</span><span style="color: #000000;">&#41;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">// bounding sphere is inside the frustum</span>
	<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<h4>The Experiment</h4>
<p>The following experiment demonstrates frustum culling in action (click on the picture to open the application) :</p>
<div id="attachment_560" class="wp-caption aligncenter" style="width: 510px"><a rel="shadowbox[tekkaman];width=500;height=375]" href="http://blog.promethe.net/wp-content/uploads/2009/12/Tekkaman.swf"><img class="size-full wp-image-560" title="frustum_culling" src="http://blog.promethe.net/wp-content/uploads/2009/12/frustum_culling.png" alt="frustum_culling" width="500" height="375" /></a><p class="wp-caption-text">Frustum culling experiment (use the arrow keys to move)</p></div>
<p style="text-align: left;">Use the arrow keys to move the robot across the scene. You can notice the TPS counter drops down to zero whenever the character is out of sight (on the near left or near right side of the screen). When the TPS indicates 0, no triangles are rendered and CPU usage drops down to 0%. It actually means that the rest of the rendering process has a minimal overhead!</p>
<h4>And it's even more awesome...</h4>
<p style="text-align: left;">This experiment also introduce my brand new mini-debugger inspired of <a href="http://mrdoob.com/80/Stats">Mr. Doob's work</a>. I replaced the maximum memory footprint counter with a per-second rendered triangles counter (or TPS counter). CPU usage or framerate alone are not absolute measurements but the TPS counter reflects the true performance of the application the old fashioned way: the more polygons per second the better. I also updated the timer to display the processing time and the overall rendering time.</p>
<p style="text-align: left;">You can compare this experiment to the <a href="http://blog.promethe.net/2009/10/07/quake-2-3d-models-in-flash-10/">"old" one I made up a few weeks ago</a>: the displayed 3D model features 30% more polygons but the CPU usage is the same.</p>
<p style="text-align: left;">The rendering process is done in such a way that absolutely no computation occurs on invisible objects, not even the slightest animation or z-sorting operation.</p>
<p style="text-align: left;">I enabled dynamic bounding volumes for animated meshes: if you place the mesh on the edges of the viewing space, you might notice that the TPS counter sometimes goes down to zero to raise up again to a few hundreds/thousands of triangles per second. The explanation is simple: the visibility test is done dynamically and follows the mesh animations. If the animation drives the mesh out of the viewing frustum, culling operates and it is not renderered.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/12/13/frustum-culling-in-flash-10/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MadCompany: Coming Soon!</title>
		<link>http://blog.promethe.net/2009/12/10/madcompany-coming-soon/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=madcompany-coming-soon</link>
		<comments>http://blog.promethe.net/2009/12/10/madcompany-coming-soon/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 23:05:04 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Augmented Reality]]></category>
		<category><![CDATA[FLARToolkit]]></category>
		<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=554</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><center><br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/wrfLwa1aXrI&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/wrfLwa1aXrI&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/12/10/madcompany-coming-soon/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Augmented Reality in Flash 10</title>
		<link>http://blog.promethe.net/2009/10/20/augmented-reality-in-flash-10/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=augmented-reality-in-flash-10</link>
		<comments>http://blog.promethe.net/2009/10/20/augmented-reality-in-flash-10/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:55:46 +0000</pubDate>
		<dc:creator>Promethe</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[3DS]]></category>
		<category><![CDATA[Augmented Reality]]></category>
		<category><![CDATA[FLARToolkit]]></category>
		<category><![CDATA[Flash 10]]></category>

		<guid isPermaLink="false">http://blog.promethe.net/?p=496</guid>
		<description><![CDATA[For those who have never heard of "augmented reality" (AR), here is Wikipedia's definition: Augmented reality (AR) is a term for a live direct or indirect view of a physical real-world environment whose elements are merged with (or augmented by) virtual computer-generated imagery - creating a mixed reality. Sounds a bit blury? Well... I'll try [...]]]></description>
			<content:encoded><![CDATA[<p>For those who have never heard of "augmented reality" (AR), here is <a href="http://en.wikipedia.org/wiki/Augmented_reality" target="_target">Wikipedia</a>'s definition:</p>
<blockquote><p>Augmented reality (AR) is a term for a live direct or indirect view of a physical real-world environment whose elements are merged with (or augmented by) virtual computer-generated imagery - creating a mixed reality.</p></blockquote>
<p>Sounds a bit blury? Well... I'll try to make it clearer with a demo...</p>
<h4>Demo</h4>
<p>First, you will have to print a little black and white "marker". The AR software scans the webcam picture and look for this very marker. When it is found, its 3D position, rotation and scale are computed and used to embed a 3D object. You can found the marker <a href="http://blog.promethe.net/wp-content/uploads/2009/10/flarlogo-marker.pdf" target="_blank">here</a> and it looks like this:</p>
<div id="attachment_517" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.promethe.net/wp-content/uploads/2009/10/flarlogo_marker.jpg" rel="shadowbox[post-496];player=img;"><img class="size-full wp-image-517" title="flarlogo_marker" src="http://blog.promethe.net/wp-content/uploads/2009/10/flarlogo_marker.jpg" alt="FLARToolkit Marker" width="300" height="300" /></a><p class="wp-caption-text">FLARToolkit Marker</p></div>
<p><span id="more-496"></span></p>
<p>Then, launch the following application and place the printed marker in front of your camera:</p>
<div id="attachment_505" class="wp-caption aligncenter" style="width: 330px"><a rel="shadowbox[minkoflar];width=640;height=480" href="http://blog.promethe.net/wp-content/uploads/2009/10/MinkoFLARDemo.swf"><img class="size-full wp-image-505" title="FLARToolkit in Flash 10" src="http://blog.promethe.net/wp-content/uploads/2009/10/minkoflar_tekkaman.jpg" alt="FLARToolkit in Flash 10" width="320" height="240" /></a><p class="wp-caption-text">FLARToolkit demo application (webcam required)</p></div>
<h4>What it does...</h4>
<ul>
<li>Load a <a href="http://blog.promethe.net/2009/10/07/quake-2-3d-models-in-flash-10/">MD2 file</a> and a JPEG texture</li>
<li>Loop through the animation of the model</li>
<li>Define multiple materials (press "w" to switch)</li>
<li>Use the <a href="http://www.libspark.org/wiki/saqoosha/FLARToolKit/en" target="_blank">FLARToolkit</a> library for the AR</li>
<li>Translate FLARToolkit matrices to fit the 3D API</li>
</ul>
<h4>How it works</h4>
<ul>
<li>The viewport and a dummy camera are initialized using the camera parameters and the size of the capture</li>
<li>The webcam image is binarized using a threshold filter: aeras that are darker than a threshold value end up completely white on a black background. Areas that are too small or too big are rejected.</li>
<li>Each remaining area is detected and its bounding box and position are computed</li>
<li>For each area that "looks like" a square, the data of what should be the pattern is extracted</li>
<li>This data is then compared to the actual pattern</li>
<li>If the match confidence is above a certain value (80% is this case), a matrix that contains the position/rotation/scale of the center of the marker is computed</li>
<li>This matrix is converted into a native Matrix3D object that can be used as the world transform for the 3D objects we want to display</li>
</ul>
<h4>What it does not do...</h4>
<ul>
<li>Use FLARManager to handle the AR. Lee "<a href="http://theflashblog.com/" target="_blank">The Flash Blog</a>" Brimelow juste made this <a href="http://gotoandlearn.com/play?id=114" target="_blank">excellent tutorial</a> about FLARManager: thank you Lee!</li>
</ul>
<h4>Known Issues</h4>
<p>The FLARToolkit library is very CPU intensive! I looked into it and beside the fact that it is poorly engineered, it looks like the blob extraction algorithm is the bottleneck. Sadly, there is not much to do about it...</p>
<p>It was ported from a Java port of a C++ library called ARToolkit. I never read the original C++ code or its Java port, but the AS3 version seems to be just a straight forward rewriting without much thinking. AS3 native types are totally ignored, if not re-implemented, and the design clearly perspires C++ (and not only because the original code is embeded in comments all over the place...). FLARManager apparently leverages the lack of a proper API.</p>
<p>To put it in a nutshell, FLARToolkit is an impressive tool but it needs a big cleanup!</p>
<h4>Credits</h4>
<ul>
<li><a href="http://mrdoob.com/80/Hi-ReS!_Stats" target="_blank">Framerate counter</a> by <a href="http://mrdoob.com" target="_blank">Mr. Doob</a></li>
<li>Augmented reality using <a href="http://www.libspark.org/wiki/saqoosha/FLARToolKit/en" target="_blank">FLARToolkit</a> by <a href="http://saqoosha.net/en/" target="_blank">Saqoosha</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.promethe.net/2009/10/20/augmented-reality-in-flash-10/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<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>
