<?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>flashsimulations.com &#187; blender</title>
	<atom:link href="http://flashsimulations.com/category/blender/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashsimulations.com</link>
	<description>Rich Internet Applications and Mobile Development &#124; Flash, Flex, AIR, iOS, Android</description>
	<lastBuildDate>Sun, 18 Dec 2011 22:42:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How it&#039;s made? Blender + Papervision3D = Flash car drive</title>
		<link>http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-its-made-blender-papervision3d-car-drive-in-flash</link>
		<comments>http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 21:54:05 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[blender]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[papervision3d]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[papervision]]></category>
		<category><![CDATA[polonez]]></category>

		<guid isPermaLink="false">http://91.205.74.118/flashsimulations.com/wordpress/?p=19</guid>
		<description><![CDATA[Welcome to flashsimulations.com! Hello. If you&#8217;ve been to this website before, you might be suprised, because it has changed significantly. I decided to run a blog under flashsimulations.com to archive my experiments involving various technologies. If you&#8217;re looking for the &#8230; <a href="http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><div id="attachment_93" class="wp-caption aligncenter" style="width: 549px"><a href="http://flashsimulations.com/polonez"><img src="http://flashsimulations.com/wp-content/uploads/2009/12/PV3DPolonezPostImage.jpg" alt="How it&#039;s made? Blender + Papervision3D = Car drive in flash" title="PV3DPolonezPostImage" width="539" height="238" class="size-full wp-image-93" /></a><p class="wp-caption-text">Polonez Borewicz - click to drive it!</p></div>
<h2>Welcome to flashsimulations.com!</h2>
<p>Hello.</p>
<p>If you&#8217;ve been to this website before, you might be suprised, because it has changed significantly. I decided to run a blog under flashsimulations.com to archive my experiments involving various technologies.<br />
If you&#8217;re looking for the car demo that used to be the landing page, read on. You&#8217;ll find it and even more.<br />
This site&#8217;s name is flashsimulations.com, but it&#8217;s not going to cover only topics that have something to do with Adobe Flash Platform.</p>
<h2>Let&#8217;s start blogging !</h2>
<p>Long time ago, in April of 2008 while experimenting with 3d in flash, I created a car driving experiment that used to be under this address &#8211; you can find it <a href="http://flashsimulations.com/polonez2008">here</a>. In October 2008 my demo has been  selected as one of the 9 cool experiments on Papervision3D official blog, since then I got a lot of feedback and questions from enthusiasts of flash and 3d.</p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 260px"><a href="http://blog.papervision3d.org/2008/10/08/pv3d-showcase-9-cool-experiments-in-3d/" target="_blank"><img class="size-full wp-image-25 " title="Polonez Borewicz on PV3D blog (click to visit Papervision3D blog)" src="http://flashsimulations.com/wp-content/uploads/2009/12/flashsimulations-pv3d-blog.jpg" alt="flashsimulations-pv3d-blog" width="250" height="250" /></a><p class="wp-caption-text">Fig. 1: Polonez Borewicz showcased on PV3D blog, October 2008</p></div>
<p style="text-align: center;">
<p>I decided to write this tutorial after I got many e-mails from people asking how that car demo was made. Unfortunately, I didn&#8217;t have time to write everyone back, due to the complexity of this topic.</p>
<h2>1981 FSO Polonez &#8220;Borewicz&#8221;, the car</h2>
<p>Recently, I updated the original flash demo to work with the latest version of Papervision3D 2 and I slightly upgraded the car model itself. In this tutorial I will describe how you can export your model from Blender 2.49 to Flash and create a 3D car driving simulation using ActionScript 3 and Papervision3D engine.<br />
I guess that most of you aren&#8217;t familliar with the car that I&#8217;ve modeled, it&#8217;s the  1981 FSO Polonez, nicknamed &#8220;Borewicz&#8221;.</p>
<p>Here&#8217;s the test drive of Polonez by Jeremy Clarkson.<br />
<p><a href="http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/"><em>Click here to view the embedded video.</em></a></p></p>
<h2>Preparing the model in Blender</h2>
<p>First of all, you need to export model from the 3d application of your choice &#8211; Papervision 2 accepts formats such as: .3ds, Collada, .MD2 and a few other.</p>
<p>I created Polonez model using Blender 2.49 and exported it to Collada 1.4 (.dae). I admit &#8211; the model isn&#8217;t pretty, but it was the first model I ever did. My priority was to keep the number of triangles as low as possible, to get better rendering speed in flash.<br />
After many Papervision performance tests I managed to get a reasonable frame rate (at least 15) when the model had less than 2,000 triangles. Of course the performance of the application varies depending on the user&#8217;s processor  &#8211; I wanted this demo (in April 2008) to run smoothly even on low budget computers, so I tested it on Intel Core2Duo T 5250@1.50Ghz with 2GB RAM laptop. The performance is no longer such an issuse as it was back then, as Papervision has been improved and the performance increased.</p>
<p>Since we want to be able to control the car wheels to simulate steering and movement, we need to provide proper name to each element of the car. On the following picture you can see the names I gave to wheels and the &#8216;Transforn Properties&#8217; window (&#8216;N&#8217; key shotcut), where you enter the name.</p>
<div id="attachment_38" class="wp-caption aligncenter" style="width: 310px"><a href="http://flashsimulations.com/wp-content/uploads/2009/12/blender-polonez-model-elements-names1.jpg" target="_blank"><img class="size-medium wp-image-38 " title="Naming car model elements in Blender" src="http://91.205.74.118/flashsimulations.com/wordpress/wp-content/uploads/2009/12/blender-polonez-model-elements-names-300x141.jpg" alt="Naming car model elements in Blender" width="300" height="141" /></a><p class="wp-caption-text">Fig. 2: Naming car model elements in Blender</p></div>
<p>When the model is finished, it&#8217;s time to export it to Collada 1.4. Select File -&gt; Export -&gt; Collada 1.4(.dae) , set the plugin options like on the picture below; click &#8216;Export &amp; Close&#8217; and that&#8217;s it.</p>
<div id="attachment_39" class="wp-caption aligncenter" style="width: 256px"><img class="size-full wp-image-39 " title="Blender - Collada 1.4 export plugin options" src="http://flashsimulations.com/wp-content/uploads/2009/12/collada_export.jpg" alt="Blender - Collada 1.4 export plugin options" width="246" height="442" /><p class="wp-caption-text">Fig. 3: Blender - Collada 1.4 export plugin options</p></div>
<h2>Importing the model to Papervision</h2>
<p>When the model is ready, it&#8217;s time to do some coding. You&#8217;ll need the latest version of PV3D, get it <a href="http://code.google.com/p/papervision3d/" target="_blank">here</a>. The code of the car simulation  is pretty straightforward (I also commented it heavily), so I&#8217;m going to comment it just briefly.<br />
Main class is based on PV3D&#8217;s BasicView and here&#8217;s the init function, where we setup everything.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; initCameras<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; initTextures<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; initModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//...</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//pv3d statistics and other UI stuff</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Initialize four cameras &#8211; their positions will be set in other function.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initCameras<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">zoom</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>cameras<span style="color: #000000;">&#91;</span>CAMERA_CAR_HOOD<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_CAR_BEHIND<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_CAR_WHEEL<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//set the camera to default</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_camera = cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Init material from embedded texture .jpg.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initTextures<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; carModelTexture = <span style="color: #0033ff; font-weight: bold;">new</span> BitmapMaterial<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> carTextureAsset <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//looks better, but the framerate drops</span><br />
&nbsp; &nbsp; carModelTexture<span style="color: #000066; font-weight: bold;">.</span>smooth = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The loaded model will be parented to an empty container because we won&#8217;t apply any tranlations nor rotations to the model itself.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; carModelParent = <span style="color: #0033ff; font-weight: bold;">new</span> DisplayObject3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>carModelParent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//car texture</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> mats<span style="color: #000066; font-weight: bold;">:</span>MaterialsList = <span style="color: #0033ff; font-weight: bold;">new</span> MaterialsList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; mats<span style="color: #000066; font-weight: bold;">.</span>addMaterial<span style="color: #000000;">&#40;</span>carModelTexture<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;all&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>carModel = <span style="color: #0033ff; font-weight: bold;">new</span> DAE<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//initial position</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">1050</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>rotationY = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">35</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FileLoadEvent<span style="color: #000066; font-weight: bold;">.</span>LOAD_COMPLETE<span style="color: #000066; font-weight: bold;">,</span> onLoad<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> carModelAsset<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> mats<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//we add the Collada model to the parent DO3D</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>carModel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>To control the wheels roll and steer angle we have to create a series of instances of DisplayObject3D class that will hold the reference to each part of the car &#8211; that&#8217;s the moment when the knowledge car elements&#8217; names comes in handy. The same rule applies to our defined cameras and their targets.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onLoad<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scale</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; viewport<span style="color: #000066; font-weight: bold;">.</span>getChildLayer<span style="color: #000000;">&#40;</span>carModel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>layerIndex = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//set references to car wheels;</span><br />
&nbsp; &nbsp; wheelFrontRight = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Front_Right&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelFrontLeft = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Front_Left&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearLeft = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Rear_Left&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearRight = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Rear_Right&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//set targets for all cameras</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_CAR_HOOD<span style="color: #000000;">&#93;</span> = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Camera_Hood_Target&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span> = carModelParent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_CAR_BEHIND<span style="color: #000000;">&#93;</span> = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Licence_Plate_Front&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_CAR_WHEEL<span style="color: #000000;">&#93;</span> = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Camera_Wheel_Target&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>enableListeners<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//KEY_UP, KEY_DOWN and ENTER_FRAME</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Here&#8217;s the  ENTER_FRAME handler</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> tick<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; updateCamerasPositions<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; camera<span style="color: #000066; font-weight: bold;">.</span>lookAt<span style="color: #000000;">&#40;</span>cameraTargets<span style="color: #000000;">&#91;</span>currentCamera<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; driveCar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; updateCarState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; singleRender<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The last thing I&#8217;m going to describe is the updateCarStateFunction. All the coefficients that you can see have been matched by trial &amp; error method. Change them to get different car behaviour.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> updateCarState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> movingForward<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = speed <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//adjust the angular velocity of the wheel</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> wheelRoll<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.7</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>wheelFrontRight<span style="color: #000066; font-weight: bold;">.</span>rotationY &nbsp;<span style="color: #000066; font-weight: bold;">-</span>= wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelFrontLeft<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">+</span>= wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearLeft<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= &nbsp;wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearRight<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= &nbsp;wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//90 and -90 are here to fix the rotation - normal vectors of front wheels must be opposite</span><br />
&nbsp; &nbsp; wheelFrontRight<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">-</span>wheelAngle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelFrontLeft<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">-</span>wheelAngle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>yaw<span style="color: #000000;">&#40;</span>speed <span style="color: #000066; font-weight: bold;">*</span> wheelAngle <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.002</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.0004</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>movingForward<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// we use different speed for car rotation around it's Z axis</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//(lower value when the car is reversing - simple technique, but adds a bit of realism</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>moveBackward<span style="color: #000000;">&#40;</span> speed <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.9</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.2</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>movingForward<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><a href="http://flashsimulations.com/wp-content/uploads/2009/12/PolonezBorewiczPV3D1.zip">Get this project sources (FlashDevelop AS3 project)</a>. Requires Flex 3.4 SDK.</p>
<div class="shr-publisher-19"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

