<?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>dispatchEvent()™ &#187; Caleb Johnston</title>
	<atom:link href="http://dispatchevent.org/author/calebjohnston/feed/" rel="self" type="application/rss+xml" />
	<link>http://dispatchevent.org</link>
	<description>Collective thoughts on the Flash Platform, iOS, Unity, and any other technology we use.</description>
	<lastBuildDate>Mon, 23 Apr 2012 19:07:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Fast Intro to Flash</title>
		<link>http://dispatchevent.org/calebjohnston/fast-intro-to-flash/</link>
		<comments>http://dispatchevent.org/calebjohnston/fast-intro-to-flash/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 04:07:42 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Meta]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=620</guid>
		<description><![CDATA[There is plenty of documentation, tutorials and explanation of Flash on the internet, blogs and books. However, it&#8217;s hard for me to find a good, concise article that covers Flash well. I&#8217;ve been exposing Flash 9 to a friend of mine recently and I&#8217;ve decided that a concise explanation is something I should write. This [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Arial;">There is plenty of documentation, tutorials and explanation of Flash on the internet, blogs and books. However, it&#8217;s hard for me to find a good, concise article that covers Flash well. I&#8217;ve been exposing Flash 9 to a friend of mine recently and I&#8217;ve decided that a concise explanation is something I should write. This post will be brief, high level and will cover Flash as a platform and not the Flash IDE. This article is also intended for those with previous exposure to technical concepts such as virtual machines and compilers.<br style="font-family: Arial;" /> </span><span id="more-620"></span><br style="font-family: Arial;" /><strong><span style="font-family: Arial;">Overview</span></strong><br />
<span style="font-family: Arial;">Flash is a platform for building and deploying interactive multimedia on the internet. The term Flash is ambiguous because it can be used to describe the runtime environment (Flash Player) or one of two IDEs targeting the player (Adobe Flash and Adobe Flex Builder). Flash currently uses an ECMA-based scripting language known as Actionscript for authoring. This same language is used across all of Adobe&#8217;s platform -which includes Adobe AIR, Adobe Flex, and Adobe Flash. Actionscript uses a <em>strong, static, safe</em> type system which makes it&#8217;s syntax more similar to Java than Javascript.</span></p>
<p><strong><span style="font-family: Arial;">Runtime Environment</span></strong></p>
<p><span style="font-family: Arial;"><strong>SWF Files</strong></span><br style="font-family: Arial;" /><span style="font-family: Arial;">Swf files are compressed, multipurpose </span><span style="font-family: Arial;">packages designed to contain the following data: raster and vector graphics, video, audio, text, fonts, animation, and actionscript code. Swfs can be loaded at runtime whenever necessary and can use both static and dynamic linking based upon the compiler settings. The runtime environment uses security sandboxes for loaded swf files. The security settings primarily limit the extent of filesystem access and cross-domain access that swf files can use. Adobe has <a id="jj8r" title="provided the swf file format spec" href="http://www.adobe.com/devnet/swf/">provided the swf file format spec</a> and has recently provided the <a id="k0w6" title="FLV video format spec" href="http://www.adobe.com/devnet/flv/">FLV video format spec</a> and <a id="drt9" title="has declared that they will provide the RTMP specs" href="http://www.adobe.com/aboutadobe/pressroom/pressreleases/200901/012009RTMP.html">has declared that they will provide the RTMP spec</a> as well.</span><br />
<span style="font-family: Arial;"><strong><br />
Flash Player &amp; AVM2</strong><br />
The Flash Player runtime is a very light-weight, virtual machine and handles system calls. The Flash Player includes both AVM1 (AS1, AS2, for Flash versions 1-8) and AVM2  (AS3 for Flash 9,10+) which processes compiled <a id="obh5" title="Adobe Byte Code" href="http://www.anotherbigidea.com/javaswf/avm2/AVM2Instructions.html">Adobe Bytecode</a> (ABC). The term AVM stands for &#8220;ActionScript Virtual Machine&#8221;<strong>*</strong>. </span><span style="font-family: Arial;">The Flash Player uses a Deferred Reference Counting (DRC) mechanism combined with a conservative mark/sweep garbage collector.</span><span style="font-family: Arial;"> The Adobe VM uses both JIT compiling and code interpretation and may benefit from compile-time bytecode optimizations based upon compiler input parameters. AS3 computational performance is generally closer to Java than Javascript [<a id="zbpr" title="AS3 performance vs Java vs Javascript" href="http://www.oddhammer.com/actionscriptperformance/set4/">source</a>]. The player also maintains a variable framerate that reflects the time consumed for each frame update [<a id="w455" title="source" href="http://www.onflex.org/ted/2005/07/flash-player-mental-model-elastic.php">source</a>]. Each frame update consists of multiple stages that include internal player processing, rendering, and author script processing. The program framerate is the principle metric reflecting application performance.<br />
<span style="font-family: Arial;"><br style="font-family: Arial;" /></span><span style="font-size: small;"><strong><span style="font-family: Arial;">Development Environment</span></strong></span></span></p>
<p><strong><span style="font-family: Arial;">Actionscript API</span></strong><br style="font-family: Arial;" /> <span style="font-family: Arial;">The Actionscript API is divided up amongst the Adobe AIR environment, the Flex environment, and the Flash environment and the Flash Player</span><span style="font-family: Arial;">.</span><span style="font-family: Arial;"> The source for all the packages are divided up amongst <a id="lc9l" title="swc files" href="http://livedocs.adobe.com/flex/3/html/building_overview_5.html">swc files</a>. Swc files are pre-compiled catalogs of classes and assets. They are similar to swf files but they are used for compile-time dependency resolution. Furthermore, the native swc&#8217;s predominantly contain code and not visual assets. An overview of the Actionscript packages is kept up to date in the <a id="y1w4" title="Adobe Actionscript 3 package summary" href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/package-summary.html">Adobe Live Docs</a>.</span></p>
<p><span style="font-family: Arial;"><strong>The Flash IDE</strong><br />
The Flash IDE was designed for designers, artists and animators. So, it is equiped with a layer system which reflects the stage display list and a hierarchical timeline which reflects the temporal nature of the runtime. The objects placed on the stage are represented by the timeline and can be &#8220;tweened&#8221; (using runtime interpolated 2D geometric transformations or custom shape morphs). The same timeline is also used for object creation and destruction. All stage instances are confined to a small set of native data types including: MovieClips, Sprites, Shapes, <span style="font-family: Arial;">TextFields, </span><span style="font-family: Arial;">Videos, and Bitmaps. The IDE also has a library that contains source objects for all stage instances and even instances that aren&#8217;t used on the stage. Flash projects often have several build targets (compiled swf files) that use parts of the project codebase. After Macromedia was purchased by Adobe, the Flash authoring environment has been updated to provide much better interoperability with the Adobe Creative Suite.</span></span></p>
<p><span style="font-family: Arial;"><strong>Adobe Flex Builder</strong><br />
Flex Builder is an Eclipse-based Actionscript IDE for writing and compiling swf files. Flex Builder is primarily designed to build &#8220;Flex&#8221; projects which can be written in an interface tagging language known as MXML. MXML is a declarative XML langauge used to define interface elements in a project. MXML files provide the &#8220;view&#8221; in the MVC software design pattern. Flex Builder also provides plenty of useful features like code completion, syntax formatting, active debugging, memory profiling, and project building that expose errors and warnings during development time. Because the Flex framework is not bundled with the Flash Player, Flex projects must statically link to all swc assets specific to Flex which amounts to greater than 500kb. This is very unnatractive for most users, thus Adobe has provided <a id="ilsr" title="means by which the download can be significantly decreased" href="http://onflash.org/ted/2008/01/flex-3-framework-caching.php">means by which the download can be significantly decreased</a>. Flex Builder is also used to deploy applications for the <a id="kwwz" title="Adobe AIR platform" href="http://en.wikipedia.org/wiki/Adobe_Integrated_Runtime">Adobe AIR platform</a>. Adobe AIR is a desktop runtime that combines <a id="ffsj" title="webkit" href="http://webkit.org/">webkit</a> with the AVM2 portion of the Flash Player. AIR can be likened to a closed sourceÂ <a id="k10e" title="Java SE" href="http://en.wikipedia.org/wiki/Java_SE">Java SE</a> runtime but provides a smaller learning curve and greater accessibility than what comes with the Java ecosystem. </span></p>
<p><span style="font-family: Arial;"><strong>Compiler</strong><br />
Since Adobe has launched the Flex platform they have provided free access to their Flex and Actionscript compiler and SDK. They have also provided open source projects under the <a id="mz0t" title="Mozilla public license" href="http://en.wikipedia.org/wiki/Mozilla_Public_License">Mozilla public license</a>. The compiler (<a id="n5hv" title="Adobe Flex 3 Help - Compilers" href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_13.html">mxmlc</a>) provides an impressive amount of flexibility and customization for swf compiling. It can be configured with command line options or a <a id="xwm0" title="configuration XML file" href="http://livedocs.adobe.com/flex/3/html/compilers_11.html#134938">configuration XML file</a>.</span></p>
<p><span style="font-family: Arial;"><em><strong>* </strong>correction 09-12-2009, I had previously stated that the term AVM meant &#8220;Adobe Virtual Machine&#8221;, this is a mixup. It actually means &#8220;ActionScript Virtual Machine&#8221;. Thanks dbam.</em></span></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/fast-intro-to-flash/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Flash Player 10 &#8211; 3D Example</title>
		<link>http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/</link>
		<comments>http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 16:06:27 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Flash 10]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=431</guid>
		<description><![CDATA[I&#8217;ve tinkered a bit with Flash Player 10. One thing that seems almost funny about the 3D effects of Flash thus far is that very few examples show off actually 3D objects. Most examples I&#8217;ve examined show 2D planes transformed in 3D space. So, I&#8217;ve created a sample 3D cube primitive in AS3 as a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve tinkered a bit with Flash Player 10. One thing that seems almost funny about the 3D effects of Flash thus far is that very few examples show off actually 3D objects. Most examples I&#8217;ve examined show 2D planes transformed in 3D space. So, I&#8217;ve created a sample 3D cube primitive in AS3 as a convenient example for people who want to get started with their own parsers or drawing tools (etc).</p>
<p><span id="more-431"></span></p>
<p>My current configuration is Mac OS X 5.2 + TextMate 1.5.7 + Flex SDK 4.0.0.3504. I have two shell scripts in place:<a title="txt version of textmate bundle command" href="http://www.calebjohnston.com/storage/scripts/textmate_compile.txt"><br />
</a></p>
<ol>
<li><a title="txt version of mxmlc script" href="http://www.calebjohnston.com/storage/scripts/mxmlc.txt">/usr/bin/mxmlc</a></li>
<li><a title="txt version of textmate bundle command" href="http://www.calebjohnston.com/storage/scripts/textmate_compile.txt">A TextMate run bundle</a> set to a hotkey, &#8220;command + R&#8221;</li>
<li>I&#8217;ve also have my <a title="Flex 4 SDK download" href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4">Flex SDK</a> set to the absolute path of: <em>/Developer/SDKs/Flex/4.0.0.3504</em></li>
</ol>
<p>This configuration requires a flex-config.xml in the same directory as the AS3 class file that you&#8217;re compiling. When you run the TextMate script (or something similar in your Terminal shell) it will compile the filename you pass in and default to using a config.xml which acts as a local flex-config.xml file. All of these can be customized as needed.</p>
<p>Example Flash 10 3D cube rotation:<br />
[kml_flashembed movie="http://www.calebjohnston.com/storage/fl10_examples/01_cube_rotation/CubeRotationExample.swf" height="260" width="410" bgcolor="#FFFFFF" /]</p>
<p>Obviously, the above swf won&#8217;t work without Flash player 10 installed.</p>
<p><a title="Flash 10 3D cube rotation example source" href="http://www.calebjohnston.com/storage/fl10_examples/01_cube_rotation.zip">Download the source here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/flash-player-10-3d-example/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Double Dissapointment</title>
		<link>http://dispatchevent.org/calebjohnston/double-dissapointment/</link>
		<comments>http://dispatchevent.org/calebjohnston/double-dissapointment/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 00:22:59 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Discussion]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Videogames]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=319</guid>
		<description><![CDATA[ECMA script 4 (or 3.1) and OpenGL 3. I may be in the (rare?) position of being highly interested in two disparate technologies. The first being an online scripting language standard governed by ECMA (used in Javascript &#38; Actionscript). The second, an open standard for real-time rendering governed by the Khronos Group (OpenGL). In recent [...]]]></description>
			<content:encoded><![CDATA[<p><a title="ES 3.1 harmony" href="http://ejohn.org/blog/ecmascript-harmony/">ECMA script 4 (or 3.1)</a> and <a title="OpenGL 3 spec" href="http://www.tojiart.com/OpenGL/">OpenGL 3</a>.</p>
<p>I may be in the (rare?) position of being highly interested in two disparate technologies. The first being an online scripting language standard governed by <a title="ECMA international standards organization" href="http://www.ecma-international.org/">ECMA</a> (used in Javascript &amp; Actionscript). The second, an open standard for real-time rendering governed by the <a title="Khronos group" href="http://www.khronos.org/">Khronos Group</a> (<a title="OpenGL" href="http://en.wikipedia.org/wiki/OpenGL">OpenGL</a>). In recent days these two languages have faced most unfortunate developments. First the ECMA script 4&#8230;</p>
<p><span id="more-319"></span></p>
<p>On Nov 7, 2006 Adobe announced the <a title="Emmy Huang on Tamarin" href="http://www.adobe.com/devnet/logged_in/ehuang_tamarin.html">contribution of their ECMA scripting engine to the open source community</a> under the name &#8220;Tamarin&#8221;. <a title="Tamarin project home" href="http://www.mozilla.org/projects/tamarin/">Tamarin</a> is also being used as the JS scripting engine for Mozilla Firefox under the name &#8220;<a title="SpiderMonkey project home" href="http://www.mozilla.org/js/spidermonkey/">SpiderMonkey</a>&#8220;. It seemed like a good idea at the time of release. But now look at the situation: we have AVM2, directly connected to Firefox AND the ECMA committee &#8211;slowing the progress of Actionscript and the Flash Player (and the internet for that matter). Needless to say, this is a disappointment. But it doesn&#8217;t end there&#8230;</p>
<p>Though having plenty of contributors, the realm of real-time rendering is primarily controlled by Microsoft, Nvida, ATI/AMD, Apple, and (more recently) Intel. Microsoft hasn&#8217;t really contributed to the Khronos Group because long ago they decided to pursue their own 3D graphics rendering API known as Direct3D. The evolution of OpenGL has become painfully slow while <a title="DirectX API" href="http://en.wikipedia.org/wiki/DirectX">DirectX</a> and <a title="D3D API" href="http://en.wikipedia.org/wiki/Direct3D">Direct3D</a> are becoming the (de-facto) standard. Finally, the Khronos group promised to improve the long lost API by introducing an object-oriented structure in stark contrast to its current state machine model. That was in October 2007. Last week the specification was finally unveiled and it remains largely the same. Not only is this a big let down, but it will definitely damage all future 3D software and game development releases for non-Windows platforms (including future consoles). Very unfortunate.</p>
<h5>DISCLAIMER: Both of these developments are FAR more complex than what this post outlines -and there&#8217;s justification behind both developments. But on the whole, they both seem bad for everybody (or just me?).</h5>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/double-dissapointment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Papervision3D Part 3: Features continued</title>
		<link>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p3/</link>
		<comments>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p3/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 21:56:37 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=290</guid>
		<description><![CDATA[This posting is part 3 of a series. If you find that you&#8217;d rather start from the beginning, check out Part 1 and Part 2 first. In this post, I&#8217;ll cover Papervision animation, the ASCollada project, render statistics, performance optimization. Animation Animation in Papervision3D can be performed the exact same way animation would be performed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2008/07/pv3dlogo.png"><img class="alignleft size-medium wp-image-289" src="http://dispatchevent.org/wp-content/uploads/2008/07/pv3dlogo.png" alt="" width="226" height="111" /></a>This posting is part 3 of a series. If you find that you&#8217;d rather start from the beginning, check out <a href="http://dispatchevent.org/calebjohnston/papervision3d-introduction-p1/">Part 1</a> and <a href="http://dispatchevent.org/calebjohnston/papervision3d-introduction-p2/">Part 2</a> first. In this post, I&#8217;ll cover Papervision animation, the ASCollada project, render statistics, performance optimization.</p>
<p><em><strong>Animation</strong></em><br />
Animation in Papervision3D can be performed the exact same way animation would be performed in 2D. Simply apply any tween or algorithm to an object property (like x, y, rotationX, scaleY, etc) and re-render the scene. But, for imported animations its not quite that simple. Lately Moses&#8217;s GoASAP package is being adopted in testing for the Papervision engine. It could soon become adopted by the system.</p>
<p><em><strong>The Collada DAE Parser</strong></em><br />
Imported animations come in plenty of flavors but must conform to the same system. That&#8217;s the reason the animations package exists. Papervision has long supported externally created 3D assets. You&#8217;ll find those file parsers in <a title="pv3d.objects.parsers" href="http://code.google.com/p/papervision3d/source/browse/#svn/trunk/branches/GreatWhite/src/org/papervision3d/objects/parsers">pv3d.objects.parsers</a>. Although, these importers are nice to have, a big part of Great White was the introduction of the open source project ASCollada. ASCollada is an amazing parser for the standard 3D asset interchange format known as <a href="http://en.wikipedia.org/wiki/COLLADA">Collada</a>. Collada files are basically very dense XML files that use a .dae file extension. Collada files can be exported from Maya, 3D Studio Max, Blender, Google Sketchup, and XSI. However, level of support for those programs probably follows this order: 3D Studio Max, Maya, Blender, Google Sketchup, XSI. Also, if you&#8217;re importing MD2 models, the MD2 file parser will import most animations as well.</p>
<p><span id="more-290"></span></p>
<p>You can try it out using the DAE class like so:</p>
<p><span style="#0000ff;"><code>import org.papervision3d.events.FileLoadEvent;<br />
import org.papervision3d.objects.parsers.DAE;<br />
daeScene = new DAE();<br />
daeScene.addEventListener(FileLoadEvent.LOAD_COMPLETE, onSceneGeometryLoaded);<br />
daeScene.addEventListener(FileLoadEvent.ANIMATIONS_COMPLETE, onSceneAnimationsLoaded);<br />
daeScene.load("your_scene.dae");<br />
var animChannel:AbstractChannel3D = daeScene.getAnimationChannels()[0];<br />
var frame:uint = 20;<br />
var animObject:DisplayObject3D = animChannel.defaultTarget;<br />
animChannel.updateToFrame(frame, animObject);</code></span></p>
<p><em><strong>Render Statistics</strong></em><br />
Papervision records all the primary rendering tasks. If you want to monitor rendering statistics, you can have them captured when you execute the BasicRenderEngine instance method &#8220;renderScene().&#8221; When traced, a typical render report will appear like this:</p>
<p><span style="#0000ff;">ProjectionTime:0 RenderTime:1 Particles:0 CulledParticles:0 Triangles:38 ShadedTriangles:0 CulledTriangles:82 FilteredObjects:0 CulledObjects:0</span></p>
<p>You can use this information to determine how well your scene is rendering. And it could give you ideas on how you can improve rendering by adjusting camera settings, culling plans, and clipping.</p>
<p><em><strong>Optimization</strong></em><br />
Great White has gained many huge performance advantages over previous versions of Papervision. One important advantage is that nearly all materials will render a surface to BitmapData. This is great because, as of Flash Player Update 3 (9.0.115, mid-2007) <a title="flash.display.BitmapData multi-core support" href="http://www.kaourantin.net/2007/06/multi-core-support.html">Multicore CPU support has been added to much of the BitmapData operations</a>.</p>
<p>Clipping is a flag added to the Viewport3D constructor in Great White that will force the engine to perform clipping of all objects outside the the viewing rectangle (the viewport). This feature may seem obvious, but a lot of public engines neglect this.</p>
<p><em><strong>Culling Algorithms</strong></em><br />
Drawing is the most expensive process that Papervision performs. As such, there are a few <a title="Hidden surface removal" href="http://en.wikipedia.org/wiki/Hidden_surface_determination">different standard methods</a> for removing items from the render queue in any 3D drawing API. This helps speed up render times by removing renderable triangles that would otherwise be drawn. Papervision3D performs backface culling, view frustum culling, and contribution culling but NOT occlusion culling. Occlusion culling is a huge process that is more built into accelerated APIs like OpenGL. Though it can be very difficult to perform well, it can also add extrordinary benefits to rendering performance.</p>
<p><em><strong>MovieClip Materials</strong></em><br />
Papervision3D supports interactive, animated, and smoothed <a title="org.papervision3d.materials.MovieMaterial" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/MovieMaterial.as">MovieClip</a> materials. However, those features come at a cost. You may already be aware that BitmapData smoothing (anti-aliasing) is slower than normal BitmapData rendering. Anti-aliasing algorithms are simply expensive operations and thats the bottom line. The other two features are performance hogs because they require that the Flash player to update the surface BitmapData object on each frame update &#8211;instead of reusing the original object that was derived from the MovieClip.</p>
<p><em><strong>Relative Performance</strong></em><br />
I&#8217;m currently coding lots of Flash player performance tests as they relate to Papervision. Right now I&#8217;m only using the following methods for testing: Math.sqrt(), Math.sin(), Matrix3D.multiply3x3(), and BitmapData.draw(). The test is simply a for loop that iterates 9999 times. It looks interesting and helps me make another point about PV3D performance. I&#8217;ll have to publish this application elsewhere, but for now here&#8217;s a sample of what I&#8217;m finding:</p>
<table style="134px;" border="0" cellspacing="0" cellpadding="3" width="301">
<tbody>
<tr>
<td>method</td>
<td>milliseconds</td>
</tr>
<tr>
<td>Math.sqrt(x)</td>
<td>1</td>
</tr>
<tr>
<td>Math.sin(x)</td>
<td>2</td>
</tr>
<tr>
<td>Matrix3D.multiply3x3(a,b)</td>
<td>13</td>
</tr>
<tr>
<td>BitmapDataObject1.draw(c)</td>
<td>661</td>
</tr>
<tr>
<td>BitmapDataObject2.draw(d)</td>
<td>2037</td>
</tr>
</tbody>
</table>
<p>Figure A: Performance timetable for 4 operations in a for loop lasting 9999 iterations. BitmapDataObject1 is 40&#215;40, transparent and BitmapDataObject2 is 600&#215;600, transparent. They both draw a single purple circle.</p>
<p>As you can see bitmap drawing is the most expensive operation here. In almost every instance that I can think of, drawing will be the most performance intensive activity in any 3D rendering API. I could explain that here, but it would probably double the size of this post. ;)Â  In a nutshell, it always helps to render only when you actually need to feature interaction and/or animation. Additionally, actively perform any reasonable operation to limit the number of objects in the scene. Again, the library does a lot for you there, but gains can always be made. Also, a little experience will show you that keeping the renderable area small will help also.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Papervision3D Part 2: Features</title>
		<link>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p2/</link>
		<comments>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p2/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 04:50:12 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=287</guid>
		<description><![CDATA[This is part 2 of a 4 part series outlining 3D in Flash by dissecting the open source Papervision3D library. Before getting deep into features let me first make a few points about using Papervision3D. The Papervision3d source SVN location includes the standard AS3 version of Papervision3D (version 1.7 as of this writing). If you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2008/07/pv3dlogo.png"><img class="alignleft size-medium wp-image-289" src="http://dispatchevent.org/wp-content/uploads/2008/07/pv3dlogo.png" alt="" width="226" height="111" /></a>This is part 2 of a 4 part series outlining 3D in Flash by dissecting the open source Papervision3D library. Before getting deep into features let me first make a few points about using Papervision3D.</p>
<p>The <a title="Google Code PV3D SVN source" href="http://code.google.com/p/papervision3d/">Papervision3d source SVN location</a> includes the standard AS3 version of Papervision3D (<a title="pv3d.Papervision3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/as3/trunk/src/org/papervision3d/Papervision3D.as">version 1.7</a> as of this writing). If you look at the branches folder inside trunk you will find <a title="pv3d.Papervision3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/Papervision3D.as">version 2.0</a> which is code-named &#8220;Great White&#8221;. This series is focused on that branch, and NOT version 1.7. Also, its important to know that Great White is probably the fastest and most frequently changing part of the Papervision source and thus details in this article will likely change over time.</p>
<p>Also, as a convention in these posts, I&#8217;ll be putting direct references to actual Google Code hosted repository files inside this page. If you don&#8217;t wish to open that repository each time you want to know the path of a class, then simply mouse over the link and look at the link address or the tool tip that shows up for the link. All references to Papervision3D classes assume that all uses of the term &#8220;pv3d&#8221; refer to the root Papervision3D package.</p>
<p><span id="more-287"></span></p>
<p>All Flash demonstrations are interactive. After focusing on the Flash applet, you can use the following key controls to control the camera.</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td>key</td>
<td>control</td>
</tr>
<tr>
<td>w</td>
<td>move forward</td>
</tr>
<tr>
<td>s</td>
<td>move backward</td>
</tr>
<tr>
<td>a</td>
<td>move left</td>
</tr>
<tr>
<td>d</td>
<td>move right</td>
</tr>
<tr>
<td>q</td>
<td>decrease rotation Z</td>
</tr>
<tr>
<td>e</td>
<td>increase rotation Z</td>
</tr>
<tr>
<td>r</td>
<td>increase field of view</td>
</tr>
<tr>
<td>f</td>
<td>decrease field of view</td>
</tr>
<tr>
<td>t</td>
<td>increase distance of the near clipping plane</td>
</tr>
<tr>
<td>g</td>
<td>decrease distance of the near clipping plane</td>
</tr>
<tr>
<td>y</td>
<td>increase distance of the far clipping plane</td>
</tr>
<tr>
<td>h</td>
<td>decrease distance of the far clipping plane</td>
</tr>
<tr>
<td>mouse Y</td>
<td>pitch</td>
</tr>
<tr>
<td>mouse X</td>
<td>yaw</td>
</tr>
</tbody>
</table>
<p>Please note that nothing will promote your understanding of the code better than just reading it yourself. Although that may seem daunting, you&#8217;ll end up doing it anyway if you really get into the project. A good place to start might be reading the comments for classes in the folder pv3d.core.proto. If you&#8217;ve happened upon this page but are unfamiliar with computer graphics from a technical standpoint, please <a title="introduction" href="http://dispatchevent.org/calebjohnston/papervision3d-introduction-p1/">read Part 1</a></p>
<p><em><strong>Geometry</strong></em><br />
In Papervision, all geometry is basically stored in the form of vertex data (<a title="pv3d.core.geom.renderables.Vertex3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/core/geom/renderables/Vertex3D.as">Vertex3D</a>). Collections of Vertices are stored in <a title="pv3d.core.proto.GeometryObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/core/proto/GeometryObject3D.as?r=595">GeometryObject3D</a> instances. Every <a title="pv3d.objects.DisplayObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/objects/DisplayObject3D.as">DisplayObject3D</a> class contains object information (such as location, transformation, orientation axis, etc) AND a reference to a <a title="pv3d.core.proto.GeometryObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/core/proto/GeometryObject3D.as?r=595">GeometryObject3D</a> instance. The <a title="pv3d.objects.DisplayObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/objects/DisplayObject3D.as">DisplayObject3D</a> class is the building block of all 3D data in Papervision &#8211;much like the flash.display.DisplayObject class is the building block of a 2D stage. However, one important difference is that a <a title="pv3d.objects.DisplayObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/objects/DisplayObject3D.as">DisplayObject3D</a> will not contain any rasterized visual data (as the DisplayObject does in its graphics object). It contains only data that is used by the rendering engine (<a title="pv3d.render.BasicRenderEngine" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/render/BasicRenderEngine.as">BasicRenderEngine</a>) and the object&#8217;s material (* <a title="pv3d.core.proto.MaterialObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/core/proto/MaterialObject3D.as">MaterialObject3D</a>) which is used to draw the object onto a <a title="pv3d.view.Viewport3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/view/Viewport3D.as">Viewport3D</a> object.</p>
<p>*Note: the actual method performing all drawing operations is NOT <a title="pv3d.core.proto.MaterialObject3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/core/proto/MaterialObject3D.as">MaterialObject3D</a>.drawTriangle but instead any of its subclassses that are overriding that method (for example <a title="pv3d.materials.ColorMaterial" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/ColorMaterial.as">ColorMaterial</a>.drawTriangle).</p>
<p><em><strong>Texture Mapping</strong></em><br />
Up until now, all discussion about 3D rendering has excluded the use of images used on geometric surfaces. This feature, called texture mapping, is very widely used. Unfortunately, it can also be quite an expensive process in terms of CPU cylces. Texture mapping has also evolved to allow for plenty of visual effects like <a title="bump mapping" href="http://en.wikipedia.org/wiki/Bump_mapping">bump mapping</a>, <a title="normal mapping" href="http://en.wikipedia.org/wiki/Normal_mapping">normal mapping</a>, <a title="displacement mapping" href="http://en.wikipedia.org/wiki/Displacement_map">displacement mapping</a>, light mapping and more.</p>
<p>As you may recall from <a title="Papervision3D Introduction part 1" href="http://dispatchevent.org/calebjohnston/papervision3d-introduction-p1/">Part 1</a>, all surface geometry in Papervision is divided into triangles. However, since images used in texture mapping are rectangular, something must be done to determine how the image can be mapped onto triangles in order to render the rectangular map as a single image. This is where the <a title="uv mapping" href="http://en.wikipedia.org/wiki/UV_mapping">UV coordinates</a> come in. A UV is simply a 2D coordinate that represents a location on the texture map that is associated with the 3D point on a triangle. Figure A1 shows this relationship.</p>
<p>Figure A1: Three example UVs for texture mapping a rectangular plane.</p>
<p><img src="http://www.calebjohnston.com/storage/posts/uvs.jpg" alt="UV mapping example" width="450" height="168" /></p>
<p>In Papervision, all the actual drawing commands exist in the material class being used for an object (as I mentioned above). Please note that two options for texture mapping exist. There&#8217;s &#8216;normal&#8217; texture mapping which is also known as &#8216;<a title="Affine transformation of a plane" href="http://en.wikipedia.org/wiki/Affine_transformation#Affine_transformation_of_the_plane">affine</a>&#8216; texture mapping. And then there&#8217;s &#8216;precise&#8217; texture mapping which would be perspective correct. Normal texture mapping is a bit less accurate but far faster in rendering then precise textures. Exhibit A2 shows an example.</p>
<p>Exhibit A2: Normal (left) vs precise (right) texture mapping in Papervision3D 2.0</p>
<p>[kml_flashembed movie="http://www.calebjohnston.com/storage/posts/textureExample.swf" height="250" width="450" /]</p>
<p><strong><em>Materials</em></strong><br />
A Material is a term borrowed from 3D development tools (like 3D Studio Max) that describes a collection of properties that will determine how a 3D surface will be rendered. Materials can become very complicated in production 3D rendering tools, but in Papervision a material has only a few properties. Those properties will determine whether lines, fills and/or a bitmap is drawn and how they&#8217;re drawn. The real key component of all materials is the drawTriangle method which is called by the engine during the render cycle.</p>
<p><strong><em>Lighting and Shading</em></strong><br />
Light simulation is probably one of the most intricate and complicated aspects of 3D rasterisation. Other forms of computer rendering (like <a title="ray tracing" href="http://en.wikipedia.org/wiki/Ray_tracing">ray tracing</a>) don&#8217;t treat lighting the way the rasterisation technique does. The reason is simple, performance. So in order to mimic light phenomena using rasterisation, shaders can be used. With the Great White branch of Papervision, lighting and shading have been added. Outside of Papervision, the term &#8220;<a title="shader explanation" href="http://en.wikipedia.org/wiki/Shader">shader</a>&#8221; sort of has multiple definitions. Shaders are used in 3D development tools to determine how light will appear on a surface. But in real-time rendering APIs (like <a title="OpenGL API" href="http://en.wikipedia.org/wiki/OpenGL">OpenGL</a> and <a title="Microsoft Direct3D" href="http://en.wikipedia.org/wiki/Direct3D">Direct3D</a>) a shader is used to modify the <a title="graphics pipeline" href="http://en.wikipedia.org/wiki/Graphics_pipeline">graphics pipeline</a>. There are actually several languages that govern shader authoring. Even Adobe has their own brand of shader language called <a title="Adobe Image Foundation toolkit" href="http://labs.adobe.com/wiki/index.php/AIF_Toolkit">Adobe Image Foundation</a>. Although shading and lighting are rather complicated features in GPU accelerated APIs, in Great White they&#8217;re actually much simpler.</p>
<p>With Papervision, shaders are probably most useful for applying native flash effects (filters and blend modes) to any desired surface. Although, filters are not fully supported yet. Aside from that, applying a shader to a material is basically the same as applying a gradient-like light map to the BitmapData surface. So if you understand gradients and BitmapData objects in Flash, you basically understand Papervision shading as well. There are really 4 types of light maps you can use and those are <a title="pv3d.materials.shaders.PhongShader" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/shaders/PhongShader.as">Phong</a>, <a title="pv3d.materials.shaders.FlatShader" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/shaders/FlatShader.as">Flat</a>, <a title="pv3d.materials.shaders.GouraudShader" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/shaders/GouraudShader.as">Gouraud</a>, and <a title="pv3d.materials.shaders.CellShader" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/shaders/CellShader.as">Cell</a>. For each of those light maps there is a shader. There is also one other shader that can create an environment map. Its the <a title="pv3d.materials.shaders.EnvMapShader" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/shaders/EnvMapShader.as">EnvMapShader</a>. It allows one to pass in bitmap objects that are used in combination with the surface texture map. Also you can use bump maps in Papervision3D shaders. See the <a title="pv3d.materials.utils.BumpmapGenerator" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/materials/utils/BumpmapGenerator.as">BumpmapGenerator</a> class. Exhibit B illustrates a simple example of various shaders. While this is not really the same &#8216;shading&#8217; that happens in video games, with Flash 10, shading could definitely change radically in Papervision.</p>
<p>Exhibit B: Shading examples in Papervision3D 2.0</p>
<p>[kml_flashembed movie="http://www.calebjohnston.com/storage/posts/shadersExample.swf" height="250" width="450" /]</p>
<p>Its also important to note that shading requires a light source. Unlike other popular 3D APIs, there is no default ambient light. And any light sources that are used are not a part of the scene. Instead you must add a light source to the shader and its position is used in determining what the light map looks like. At the time of this writing there is only one light source supported per shader in Papervision3D. Also there is only one type of light to choose from -a <a title="pv3d.lights.PointLight3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/lights/PointLight3D.as">point light</a>.</p>
<p><em><strong>Cameras</strong></em><br />
Cameras aren&#8217;t that complicated in Papervision3D. There are three types of Cameras: free, target, and debug. A free camera is totally unattached to anything that exists in the environment and can be moved &#8216;freely&#8217;. But a target camera will have a focus object within the scene. That object can be moved freely, but the camera will always come along. It works just like a focus camera object would work in a 3D development tool like 3D Studio Max or Maya. And thus a key aspect of that behavior is that if you want to translate a <a title="pv3d.cameras.Camera3D" href="http://code.google.com/p/papervision3d/source/browse/trunk/branches/GreatWhite/src/org/papervision3d/cameras/Camera3D.as">Camera3D</a> object, it will actually rotate about its focus object. The last type of camera (debug) allows for key control, so that you can move the camera around as desired. This is highly useful when you&#8217;re building a complex scene or importing geometry from an external editor.</p>
<p>The only three camera-specific properties you can manipulate to control the view are zoom, focus and field of view (fov). The fov is in degrees. Normally 60 is representative of a normal 35mm camera lens. But the debug camera defaults to 90 degrees. Zoom and focus can be determined based on the fov and the camera&#8217;s distance to the near clipping plane. Exhibit C demonstrates the interaction of the fov and focus value. Also, here are some rather crude numbers for comparison:</p>
<table border="0" cellspacing="3" cellpadding="0" width="460">
<tbody>
<tr>
<td>lens focal length</td>
<td>lens type</td>
<td>PV3D camera focus</td>
<td>PV3D field of view</td>
</tr>
<tr>
<td>21 mm</td>
<td>very wide angle</td>
<td>6-</td>
<td>120+</td>
</tr>
<tr>
<td>21-35 mm</td>
<td>wide angle</td>
<td>6-12</td>
<td>80-120</td>
</tr>
<tr>
<td>37-70 mm</td>
<td>normal</td>
<td>12-17</td>
<td>60-80</td>
</tr>
<tr>
<td>70-135 mm</td>
<td>medium telephoto</td>
<td>17-27</td>
<td>40-60</td>
</tr>
<tr>
<td>135-300 mm</td>
<td>telephoto</td>
<td>27+</td>
<td>40-</td>
</tr>
</tbody>
</table>
<p>Note: all camera focus values are used with a default debug zoom value of 24. Field of view values are in degrees.</p>
<p>Exhibit C: Demonstration of camera field of view and focus. Use keys r and f to increase and decrease the fov respectively.</p>
<p>[kml_flashembed movie="http://www.calebjohnston.com/storage/posts/cameraExample.swf" height="250" width="450" /]</p>
<p>Stay tuned for more feature dissection in Part 3. In the meantime, <a title="Papervision3d introduction part2 examples" href="http://www.calebjohnston.com/storage/posts/Papervision3D-introduction-part2.zip">download examples source files here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Papervision3D Part 1: Introduction</title>
		<link>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p1/</link>
		<comments>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p1/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 15:51:40 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=286</guid>
		<description><![CDATA[I have many friends asking me for more information on Papervision 3D. Usually, they&#8217;re just genuinely interested in learning about it and also how they can use it. These friends are bright people, but generally unfamiliar with the topic of computer graphics. I&#8217;ve consistently directed them to Wikipedia articles that I think will make everything [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dispatchevent.org/wp-content/uploads/2008/07/pv3dlogo.png"><img class="alignleft size-medium wp-image-289" src="http://dispatchevent.org/wp-content/uploads/2008/07/pv3dlogo.png" alt="" width="226" height="111" /></a></p>
<p>I have many friends asking me for more information on Papervision 3D. Usually, they&#8217;re just genuinely interested in learning about it and also how they can use it. These friends are bright people, but generally unfamiliar with the topic of computer graphics. I&#8217;ve consistently directed them to Wikipedia articles that I think will make everything clear to them (in this order):</p>
<ol>
<li><a href="http://en.wikipedia.org/wiki/Rendering_(computer_graphics)#Scanline_rendering_and_rasterisation">Computer Rendering</a></li>
<li><a href="http://en.wikipedia.org/wiki/Rasterization">Rasterisation</a></li>
<li><a href="http://en.wikipedia.org/wiki/Perspective_projection#Perspective_projection">3D Projection</a></li>
<li><a href="http://en.wikipedia.org/wiki/Matrix_multiplication">Matrix Multiplication</a></li>
</ol>
<p>Unfortunately, I think people are reluctant to read those articles because they&#8217;re half written in math formulas. Those formulas are critical for getting a real understanding of what&#8217;s going on &#8220;under the hood&#8221; but I admit they&#8217;re annoying to read if you don&#8217;t really want to learn the math. And also, those articles won&#8217;t mention a single Papervision class file anywhere (naturally). I&#8217;m sure this is a little less exciting for someone who&#8217;s into 3D in Flash. Therefore, I&#8217;m reviewing and dissecting Papervision3D 2.0 (Great White) in a multi-part series for those who are curious about 3D in Flash.</p>
<p>Part 1 will review those Wikipedia articles and relate them to Papervision along the way. If you&#8217;re already familiar with computer graphics as a topic of CS, you may wish to skip this post. Parts 2 &amp; 3 will review the details of many features of Papervision3D. Part 4 will be a set of useful notes and tips for anyone who&#8217;s not already experienced with Papervision3D.</p>
<p><span id="more-286"></span></p>
<p><em><strong>An Ultra-Brief Background of Computer Graphics</strong></em><br />
Drawing an image from a 3D scene using a computer can be done many different ways. However, if its going to be done very quickly in order to allow for animation and/or interactivity then typically a process called rasterisation is best. This term is used to describe the transformation of (vector) data into raster (or pixel) data, such as an image.</p>
<p>A few things should also be understood about the vector data used in rasterisation. It really can be almost anything that defines a 3D entity. However Papervision follows the popular convention of using 3D points oriented into triangles. So if a surface looks like a rectangle, its actually (at least) two triangles &#8211;each triangle having at least one face. It should also be noted that in 3D space two more important values are often used: <a title="Normal vector" href="http://en.wikipedia.org/wiki/Surface_normal">normals</a> and <a title="UV Mapping" href="http://en.wikipedia.org/wiki/UV_mapping">UV</a>s. A normal is short for &#8220;surface normal vector&#8221; which is a vector value that is perpendicular to the triangle&#8217;s face. And a UV is a value that is used to determine how an image can be mapped to the triangle&#8217;s face. In Papervision, there can be one UV for every 3D point. And there can be one normal for every triangle.</p>
<p>Rasterisation is a term that is used for both 2D and 3D graphics. Without getting into the real nitty gritty behind what&#8217;s going on inside a computer to produce an image on a monitor, we can say that Flash has pretty much always performed 2D rasterisation. But with a 3D engine used, a lot of logic is plugged in to produce an illusion of 3D on a 2D screen.</p>
<p>So what is all that logic? In short, 3D projection, matrix math and display list management. Plus, a lot of performance enhancement, shading, parsers, presets, and the structure of a nice OOP API. Here are the basics.</p>
<p><em><strong>3D Projection</strong></em><br />
Ultimately, the task of projection is mapping points which are represented in 3D space in a 2D coordinate system. There are different ways of doing this. Figure A1 shows 2 common examples: orthographic and perspective projections.</p>
<p>Figure A1: two common 3D projections of a cube</p>
<p><img class="alignnone" src="http://www.calebjohnston.com/storage/posts/3d_projection.jpg" alt="3D Projections" /></p>
<p>When using either projection technique and mapping everything within view to a 2D rectangular plane, a renderable volume is determined. This volume will be the space bound by a cube if projection is orthographic. Or it will be a frustum if the projection is perspective. This space is highly useful for making some key optimizations. Figure A2 helps explain the view volume.</p>
<p>Figure A2: Perspective projection view frustum with view frustum culling.</p>
<p><img class="alignnone" src="http://www.calebjohnston.com/storage/posts/view_frustum.jpg" alt="3D perspective projection view frustum" /></p>
<p>The process of projection is achieved through transforming matrices. In Papervision (as in most 3D APIs) a 4&#215;4 matrix will represent translation, rotation, and scaling for all axes. If you want to understand the raw math behind the matrix convention in 3D graphics, you should actually be reading the links I posted above from Wikipedia. Otherwise the following section will very briefly review the topic.</p>
<p><em><strong>3D Matrices</strong></em><br />
A Papervision 3D matrix is represented in 16 Number values. Figure B helps to illustrate how those numbers are used in a right-handed coordinate system.Â  With Papervision, a left-hand coordinate system is used. This means that the z axis points into the screen and away from the viewer. This will have some important implications if you decide to import models into Papervision from files generated using common 3D software.</p>
<p>Figure B: Three example matrix transformations</p>
<p><img class="alignnone" src="http://www.calebjohnston.com/storage/posts/matrix_transformation.jpg" alt="3 example matrix transformation" /></p>
<p>There are also 3 matrices that are used to represent a 3D scene in Papervision: the world matrix, the view matrix (or camera matrix), and the object transform matrix. So when an object is projected, it will go through all 3 matrix multiplications AND any animation matrix operations that are performed. More explicitly, each 3D vertex that exists in each 3D object will have to be transformed by all these matrices to end up as a 2D point in Flash.</p>
<p><em><strong>Display List Management</strong></em><br />
When an object is added to a scene it is also added to a render list. That render list is sorted so that each object being rendered appears on the screen at the correct depth. Each renderable object is then drawn to the viewport using the viewport graphics object. NOTE: This means that the final render in Papervision is drawn in a single DisplayObject.</p>
<p>Display list management is also where a lot of performance gains can be made. Many times its not necessary to show all the triangle faces that are in a scene because they don&#8217;t exist inside the viewing volume (typically a frustum). Removing objects from the render list because they exist outside the viewing volume is called view frustum culling. There are plenty of other (more advanced) methods used in order to optimize the render cycle. Many of those will be explained in part 3.</p>
<p><em><strong>Valuable Presets</strong></em><br />
Simple objects like cubes and spheres that come prefabricated in Papervision are called Primitives. They may not seem so sophisticated but consider how you would describe a sphere in terms of triangles using only 3D coordinates. Not to mention how you would determine all the triangle&#8217;s UV coordinates and normals! And if you don&#8217;t desire creating your 3D scene from primitives, you can generate your own objects algorithmically or even import them from an external source such as a collada file. That&#8217;s very valuable indeed!</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/papervision3d-introduction-p1/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Actionscript 3 performance tuning review</title>
		<link>http://dispatchevent.org/calebjohnston/as3-performance-tuning/</link>
		<comments>http://dispatchevent.org/calebjohnston/as3-performance-tuning/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 16:34:47 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dispatchevent.org/?p=285</guid>
		<description><![CDATA[After late-night conversations amongst coworkers and friends over beers, I&#8217;ve discovered that many flash developers remain unfamiliar with AVM2&#8242;s inter workings. A while ago, I found a couple documents which have benefited me greatly in understanding AVM2 and AS3: Actionscript 3.0 and Performance Tuning AVM2 Overview There are definitely some big take-aways in these two [...]]]></description>
			<content:encoded><![CDATA[<p>After late-night conversations amongst coworkers and friends over beers, I&#8217;ve discovered that many flash developers remain unfamiliar with AVM2&#8242;s inter workings. A while ago, I found a couple documents which have benefited me greatly in understanding AVM2 and AS3:</p>
<p><a href="http://www.onflex.org/ACDS/AS3TuningInsideAVM2JIT.pdf">Actionscript 3.0 and Performance Tuning</a></p>
<p><a href="http://www.adobe.com/devnet/actionscript/articles/avm2overview.pdf">AVM2 Overview</a></p>
<p>There are definitely some big take-aways in these two documents. I would list them here, but then you might not read them for yourself! ;)</p>
<p>The first document is 74 powerpoint slides (prepared by Gary Grossman of Adobe) which is very useful for getting a quick understanding of AVM2 topics such as garbage collection, the benefits of strong typing, the Actionscript byte code (abc) format, the code interpreter and JIT compilation. For an AS3 developer this is a must-read.</p>
<p>The second document is a bit more dense. It contains 108 pages of more formally described underpinnings of the virtual machine. It focuses a lot on how your AS3 code will ultimately be run as processor instructions. Its a great follow-up to the first document. If you&#8217;re a geek, I would highly recommend reading this overview.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/as3-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Flash Site Experience Profile</title>
		<link>http://dispatchevent.org/calebjohnston/flash-site-experience-profile/</link>
		<comments>http://dispatchevent.org/calebjohnston/flash-site-experience-profile/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 05:21:45 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.extends.eventdispatcher.org/?p=277</guid>
		<description><![CDATA[This is essentially the second part to my last post. This time however, I&#8217;m concentrating on the user experience of the same campaign site (www.starbuckscoffeeathome.com) based on tracking data. I&#8217;ve used a custom-built statistics class which helped me to derive plenty of useful numbers from a normal user experience flow. My method was to record [...]]]></description>
			<content:encoded><![CDATA[<p>This is essentially the second part to <a href="http://blog.extends.eventdispatcher.org/calebjohnston/code-documentation/">my last post</a>. This time however, I&#8217;m concentrating on the user experience of the same campaign site (www.starbuckscoffeeathome.com) based on tracking data. I&#8217;ve used a custom-built statistics class which helped me to derive plenty of useful numbers from a normal user experience flow. My method was to record all important events and normal status data like the amount of external data loaded, the frame rate, and the memory usage. After recording the information I designed an infographic about what I discovered. <a href="http://www.calebjohnston.com/storage/coffee_experience_profile_fA.jpg">You can see the graph here</a>.</p>
<p>As you can see, there&#8217;s some disappointing trends. I noticed there seems to be a memory issue -something that must have become unresolved before final launch. The framerate reflects the usage on my trusty Intel 2 Ghz Mac Book Pro. Very unimpressive considering this is a decent machine really. I&#8217;m sure there&#8217;s a little bit of overhead which came from the statistics activity. Although the experience didn&#8217;t seem out of pace with the same one when the statistics class inactive. After considering when the average user leaves the site, I decided to make a second graphic <a href="http://www.calebjohnston.com/storage/coffee_experience_profile_fB.jpg">which can be seen here</a>.</p>
<p>And this is a little bit unfortunate. I will confess however that the connection speed on the machine I recorded the statistics with was a very slow DSL. A DSL connection would&#8217;ve produced more favorable results (assuming the user wasn&#8217;t doing other download work in the simultaneously). Although, as you can see a very large amount of time is consumed by watching a loader which brings me to the point of this post. If you build Flash sites which rely upon a pleasant user experience, then make sure all the content you load is well worth its weight.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/flash-site-experience-profile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Documentation</title>
		<link>http://dispatchevent.org/calebjohnston/code-documentation/</link>
		<comments>http://dispatchevent.org/calebjohnston/code-documentation/#comments</comments>
		<pubDate>Sat, 24 May 2008 16:29:46 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.extends.eventdispatcher.org/?p=276</guid>
		<description><![CDATA[I recently finished a campaign site for Starbucks in order to promote the Starbucks brand of coffee available in grocery stores. The address is www.starbuckscoffeeathome.com. It was a very pleasant project to work on, but it was also quite fast paced. The project also remained in a state of high flux until launch. These two [...]]]></description>
			<content:encoded><![CDATA[<p>I recently finished a campaign site for Starbucks in order to promote the Starbucks brand of coffee available in grocery stores. The address is <a href="http://www.starbuckscoffeeathome.com">www.starbuckscoffeeathome.com</a>. It was a very pleasant project to work on, but it was also quite fast paced. The project also remained in a state of high flux until launch. These two aspects combined made it nearly impossible to keep accurate comments on my code. So, after this project was complete I decided to re-write my UML for it based on the way it ended up (rather than the way I originally designed it). After doing so I&#8217;ve come to believe this serves as better and more digestible documentation for a developer than most inline commenting. Thats not to say it would completely replace code commenting, but I feel as though its more useful for another developer to see in order to get a grasp on how a body of code works. For this diagram I didn&#8217;t have the right tools available to me immediately so I used what I had (which was Adobe Illustrator). This required a greater investment of time, but the time consumed was likely on par with the amount of time required to produce sufficient written documention. For most practical situations, a simple sketch would suffice. Have a look at the diagram (and submit your critiques if you like).</p>
<p><a href="http://www.calebjohnston.com/storage/Starbucks_basic_class_UML.pdf">Download the Starbucks basic class UML (PDF).</a></p>
<p>I&#8217;ve also conducted a certain amount of performance profiling that I will write up in the near future.</p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/code-documentation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Pixel Shading and Adobe AIF</title>
		<link>http://dispatchevent.org/calebjohnston/pixel-shading-and-adobe-aif/</link>
		<comments>http://dispatchevent.org/calebjohnston/pixel-shading-and-adobe-aif/#comments</comments>
		<pubDate>Thu, 01 May 2008 19:07:15 +0000</pubDate>
		<dc:creator>Caleb Johnston</dc:creator>
				<category><![CDATA[Hydra]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://mimswright.com/blog/?p=269</guid>
		<description><![CDATA[Pixel shading is a feature supported on graphics hardware starting with the Radeon R200 based cards (8500-9250) and the GeForce FX series. Though pixel shading was first specified in OpenGL 1.1 and DirectX 8, it wasn&#8217;t implemented by consumer grade hardware until OpenGL 1.4 and DirectX 8.1. These consumer grade cards are enumerated on the [...]]]></description>
			<content:encoded><![CDATA[<p>Pixel shading is a feature supported on graphics hardware starting with the Radeon R200 based cards (8500-9250) and the GeForce FX series. Though pixel shading was first specified in OpenGL 1.1 and DirectX 8, it wasn&#8217;t implemented by consumer grade hardware until OpenGL 1.4 and DirectX 8.1. These consumer grade cards are enumerated on the <a href="http://labs.adobe.com/wiki/index.php/AIF_Toolkit">Adobe Labs AIF toolkit page</a> . Before shaders existed the graphics pipeline for real-time rasterisation (via a GPU) was fully procedural and the only means by which a programmer could interact with that processing pipeline was to use the standard APIs. However with shaders, any 3D author has the power to fully control the rasterisation algorithm at the frame buffer level. The only downside to this level of control is that the shader must be pre-compiled before put into use. Nvidia has recently opened the doors up more by introducing <a href="http://en.wikipedia.org/wiki/CUDA">CUDA.</a> It would be really interesting to see Adobe produce something similar (but cross-platform) with some future version of Flash. Whether that would be a good or bad thing can be debated and discussed for a long time.</p>
<p>Last night I decided to break out the AIF toolkit again and work some mathy expressions into a filter. Up to this point most of the filters that I&#8217;ve seen are along the lines of what you will find in Photoshop&#8217;s menus. Those filters certainly aren&#8217;t bad, but I&#8217;ve always been more interested in how an image can be sampled and reconstructed in a manner not unlike what&#8217;s found in the 90&#8242;s DJ scene. So with that introduction I&#8217;d like to demonstrate my latest filter.</p>
<p><img style="top;" src="http://www.calebjohnston.com/images/Hydra_Filter_Ripped3_01.jpg" alt="Ripped Filter (v3) image 01" width="500" height="375" /></p>
<p><img style="top;" src="http://www.calebjohnston.com/images/Hydra_Filter_Ripped3_02.jpg" alt="Ripped Filter (v3) image 02" width="500" height="375" /></p>
<p>Just like in Flash, you can think of the canvas as a 2D coordinate plane. For this filter I used a few trigonometric and polynomial expressions in combination. Most of the polynomial coefficients are also parameters that you can manipulate which is where all the fun is. More to come, stay tuned.</p>
<p><a href="http://www.calebjohnston.com/storage/calebjohnston_ripped3.hydra">Download the filter.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dispatchevent.org/calebjohnston/pixel-shading-and-adobe-aif/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

