<?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>Hemanth Sharma - Tech Blog &#187; Papervision 3D</title>
	<atom:link href="http://www.hsharma.com/tech/category/papervision-3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hsharma.com/tech</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 13:44:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>3D Realistic Earth using Papervision 3D &#8211; Part 1</title>
		<link>http://www.hsharma.com/tech/flash/3d-realistic-earth-using-papervision-3d-part-1/</link>
		<comments>http://www.hsharma.com/tech/flash/3d-realistic-earth-using-papervision-3d-part-1/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 08:03:07 +0000</pubDate>
		<dc:creator>Hemanth Sharma</dc:creator>
				<category><![CDATA[Action Script 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Papervision 3D]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[earth]]></category>
		<category><![CDATA[papervision]]></category>

		<guid isPermaLink="false">http://www.hsharma.com/tech/?p=980</guid>
		<description><![CDATA[
Introduction
I was researching more on Papervision 3D when I realized I can share some information on creating a 3D realistic Earth model. I will also explain how to add rotation to earth and one way to show the rotation of moon and revolution of it around earth. I will also briefly describe how to handle [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-988" title="earth_render" src="http://www.hsharma.com/tech/wp-content/uploads/2009/11/earth_render.jpg" alt="earth_render" hspace="10" vspace="10" width="244" height="182" /></p>
<h3>Introduction</h3>
<p>I was researching more on Papervision 3D when I realized I can share some information on creating a 3D realistic Earth model. I will also explain how to add rotation to earth and one way to show the rotation of moon and revolution of it around earth. I will also briefly describe how to handle something called &#8220;Pivot&#8221; points in Papervision 3D.</p>
<h3>Setting Up</h3>
<p>To start with, if you are fresh and new to Papervision 3D, I will describe the basic steps to configure your Flash CS4 authoring tool to work with Papervision 3D.</p>
<p><span id="more-980"></span></p>
<ol>
<li>Navigate to <a href="http://code.google.com/p/papervision3d/downloads/list" target="_blank" rel='nofollow'>http://code.google.com/p/papervision3d/downloads/list</a> in your browser</li>
<li>Download the latest build&#8217;s ZIP file (You may also use the SWC or use SVN to download latest Papervision 3D class files if you know. This is just my way of setting up).</li>
<li>Extract it to a folder of your choice, e.g., C:\PV3D or Documents\PV3D</li>
<li>Open your Flash CS4 authoring tool and go to Edit&gt;Preferences(Win) or Flash&gt;Preferences (Mac)</li>
<li>Navigate to Action Script and choose Action Script 3.0.</li>
<li>In the &#8220;Source Path&#8221; section, click on the folder icon to browse to add a folder of libraries. Choose the folder where you extracted Papervision 3D class files.</li>
<li>Click OK and you are done with the setup. Now you can proceed creating Papervision 3D content.</li>
</ol>
<h3>Creating Basic Earth</h3>
<p>We shall create a simple sphere (basic shape) and rotate it in place along Y axis.</p>
<ol>
<li>Now that Papervision is set up, we create a new Action Script class file connected to an FLA file (e.g., Earth.as -&gt; Earth.fla). Go ahead and create a new Action Script file and save it as Earth.as. Also create an FLA file and name it Earth.fla and in the Document Properties of the FLA file, enter Earth (the class name attached to the document).</li>
<li>Before you compile, you need to pour in data in to .as file. We need to create basic class/package structure to start with as shown -
<pre class="brush: as3">package {
	import org.papervision3d.view.BasicView;
	import flash.events.Event;

	public class Earth extends BasicView {
		public function Earth():void {
			super(640, 480, false);
			stage.frameRate=30;
			startRendering();
		}
		override protected function onRenderTick(evt:Event=null):void {
			super.onRenderTick();
		}
	}
}</pre>
</li>
<li>If you compile the FLA file now, you shouldn&#8217;t be getting any error. In the above basic code, we have imported the <code>BasicView</code> class from Papervision 3D&#8217;s packages for making the rendering job easier as it contains necessary implementation of rendering, initiating scene, viewport, etc. Let&#8217;s not worry about it now. We have extended <code>Earth</code> class from <code>BasicView</code> and written a constructor with initialization code for rendering and stage properties. Also an override function <code>onRenderTick()</code> to handle each frame of animation for rendering.</li>
<li>Now we shall create a sphere and rotate it. Observe the highlighted code below -
<pre class="brush: as3;highlight: [3, 7, 13, 14]">package {
	import org.papervision3d.view.BasicView;
	import org.papervision3d.objects.primitives.Sphere;
	import flash.events.Event;

	public class Earth extends BasicView {
		private var earth:Sphere;

		public function Earth():void {
			super(640, 480, false);
			stage.frameRate=30;

			earth=new Sphere(null,300,20,20);
			scene.addChild(earth);

			startRendering();
		}
		override protected function onRenderTick(evt:Event=null):void {
			super.onRenderTick();
		}
	}
}</pre>
</li>
<li>We have created a new Sphere of radius 300 and 20 vertical and horizontal segments. This sphere is added as a child to the scene in order to display the created Sphere. Now test the file you created by saving and compiling the SWF. The output should seem similar to the below screenshot -</li>
<p style="text-align: center;"><a href="http://www.hsharma.com/tech/wp-content/uploads/2009/12/basic_sphere.jpg" target="_blank" rel='nofollow'><img class="alignnone size-thumbnail wp-image-998" title="basic_sphere" src="http://www.hsharma.com/tech/wp-content/uploads/2009/12/basic_sphere-150x150.jpg" alt="basic_sphere" hspace="5" vspace="5" width="150" height="150" / rel='nofollow'></a></p>
<li>Without delay, we shall rotate this sphere with only one line of code added to the above code (in function <code>onRenderTick</code>) -
<pre class="brush: as3; first-line: 18; highlight: [19]">	override protected function onRenderTick(evt:Event=null):void {
		earth.localRotationY+=1;
		super.onRenderTick();
	}</pre>
</li>
<li><code>localRotationY</code> is a property of every DisplayObject3D used to rotate the object along the Y axis with respect to it&#8217;s local origin. The below image should help you understand it in case you need.<br />
<a href="http://www.hsharma.com/tech/wp-content/uploads/2009/12/y_rotation.jpg" rel='nofollow'></a></li>
<p style="text-align: center;"><img class="alignnone size-full wp-image-1003" title="y_rotation" src="http://www.hsharma.com/tech/wp-content/uploads/2009/12/y_rotation.jpg" alt="y_rotation" width="303" height="227" /></p>
<li>Now you may test your movie by pressing Ctrl+Enter (Win) / Command+Enter (Mac). You will see that the sphere rotates according to the Y axis.</li>
</ol>
<p>Hold on with this output for now. I shall update with the next part soon where we will apply texture to the rotating sphere with proper lighting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hsharma.com/tech/flash/3d-realistic-earth-using-papervision-3d-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
