<?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>Benny's Blog &#187; skybox</title>
	<atom:link href="http://blog.projectnibble.org/tag/skybox/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.projectnibble.org</link>
	<description>House Of Code</description>
	<lastBuildDate>Fri, 13 Aug 2010 15:06:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Easy Papervision3D skybox tutorial and source</title>
		<link>http://blog.projectnibble.org/2009/05/22/easy-papervision3d-skybox-tutorial-and-source/</link>
		<comments>http://blog.projectnibble.org/2009/05/22/easy-papervision3d-skybox-tutorial-and-source/#comments</comments>
		<pubDate>Fri, 22 May 2009 08:06:23 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[game design]]></category>
		<category><![CDATA[skybox]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=112</guid>
		<description><![CDATA[Adding a skybox in Papervision3D is easy. I've made a small class that nicely encapsulates what you need.]]></description>
			<content:encoded><![CDATA[<div style="float:left; margin: 1em">

<object width="300" height="300">
<param name="movie" value="http://projectnibble.org/dump/blog/papervision3d_skybox/Skyboxtutorial.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#000000"></param>
<embed type="application/x-shockwave-flash" width="300" height="300" src="http://projectnibble.org/dump/blog/papervision3d_skybox/Skyboxtutorial.swf" quality="high" bgcolor="#000000" wmode="window" menu="false" ></embed>
</object>

</div>
<div style="padding-top:.5em">
<p>Adding a skybox in Papervision3D is extremely easy. I couldn&#8217;t find a whole lot of examples/tutorials about skyboxes in Papervision3D, but I managed to find a <a href="http://professionalpapervision.wordpress.com/2008/10/20/putting-stars-and-more-into-a-skybox-source/">skybox tutorial source</a> and learned how to do it. The tutorial I got the initial source from is actually about adding stars using particle fields, but I just used the skybox part of it (and used the textures).</p>
<p>I decided to clean it up and make a nice class out of it. I&#8217;ve used the trunk of the papervision code repository, revision 851, but since it&#8217;s very basic stuff I doubt it&#8217;ll break with future versions.</p>
<ul style="text-indent:1cm">
<li><a href="http://projectnibble.org/dump/blog/papervision3d_skybox/skyboxtutorial.rar">download skybox source</a></li>
</ul>
</div>
<div style="clear:both">&nbsp;</div>
<p><span id="more-112"></span></p>
<pre  name="code" class="java">
package org.codemonkey.papervision3d {
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;

	public class Skybox extends Cube {

		public static const QUALITY_LOW:Number = 4;
		public static const QUALITY_MEDIUM:Number = 6;
		public static const QUALITY_HIGH:Number = 8;

		public function Skybox(bf:Class, bl:Class, bb:Class, bu:Class, br:Class, bd:Class, skysize:Number, quality:Number):void {
			super(generateMaterials(bf, bl, bb, bu, br, bd), skysize, skysize, skysize, quality, quality, quality);
		}

		protected function generateMaterials(bf:Class, bl:Class, bb:Class, bu:Class, br:Class, bd:Class):MaterialsList {
			var materials:MaterialsList = new MaterialsList();
			materials.addMaterial(new BitmapMaterial(new bf().bitmapData), "front");
			materials.addMaterial(new BitmapMaterial(new bl().bitmapData), "left");
			materials.addMaterial(new BitmapMaterial(new bb().bitmapData), "back");
			materials.addMaterial(new BitmapMaterial(new bu().bitmapData), "top");
			materials.addMaterial(new BitmapMaterial(new br().bitmapData), "right");
			materials.addMaterial(new BitmapMaterial(new bd().bitmapData), "bottom");

			for each (var material:BitmapMaterial in materials.materialsByName) {
				material.doubleSided = true;
			}

			return materials;
		}
	}
}
</pre>
<ul>
<li><a href="http://projectnibble.org/dump/blog/papervision3d_skybox/Skybox.as">download Skybox.as</a></li>
</ul>
<p>See the line <i>material.doubleSided = true;</i>? That&#8217;s needed since we&#8217;re inside the cube that is the skybox. Since normally you can only see objects from the outside we&#8217;re setting the double-sidedness of the skybox. Perhaps a better solution is to flip the faces of the skybox and leave out the double-sidedness all together:</p>
<pre  name="code" class="java">
		public function Skybox(bf:Class, bl:Class, bb:Class, bu:Class, br:Class, bd:Class, skysize:Number, quality:Number):void {
			super(generateMaterials(bf, bl, bb, bu, br, bd), skysize, skysize, skysize, quality, quality, quality);
			geometry.flipFaces(); // now you can only see the box from the inside...
		}
</pre>
<p>To use the Skybox class, here&#8217;s an example:</p>
<pre  name="code" class="java">
public class SkyboxTest {

		// skybox images
		[Embed (source="assets/hot_nebula_0.jpg")]
		private var BitmapFront:Class;
		[Embed (source="assets/hot_nebula_270.jpg")]
		private var BitmapRight:Class;
		[Embed (source="assets/hot_nebula_180.jpg")]
		private var BitmapBack:Class;
		[Embed (source="assets/hot_nebula_90.jpg")]
		private var BitmapLeft:Class;
		[Embed (source="assets/hot_nebula_bottom.jpg")]
		private var BitmapDown:Class;
		[Embed (source="assets/hot_nebula_top.jpg")]
		private var BitmapUp:Class;

		public static const SKYSIZE:Number = Number.MAX_VALUE;

		public function loadSkyBox(scene:Scene3D) {
			var skybox:Skybox = new Skybox(BitmapFront, BitmapLeft, BitmapBack, BitmapUp, BitmapRight, BitmapDown, SKYSIZE, Skybox.QUALITY_HIGH);
			scene.addChild(skybox);
		}
}
</pre>
<p>Here are the steps you need:</p>
<ul>
<li>define a bunch of textures in the top of your classes by embedding them and pass these classes to the Skybox constructor.</li>
<li>pass in a size for your skybox: I&#8217;ve used <i>Number.MAX_VALUE</i> so the skybox won&#8217;t move or pixelate while I move through it with the camera.</li>
<li>pass in a quality value: this can be any number actually, I just found 4, 6 and 8 to work nicely. These numbers determine how many segments are used in each of the faces of the skybox to avoid texture distortion and awkward transitions from one texture into another.</li>
</ul>
<p>For my own convenience I&#8217;ve made a NebulaSkybox which simply encapsulates all the embedded images for the nebula sky:</p>
<pre  name="code" class="java">
	public class NebulaSkybox extends Skybox {

		// nebula skybox images
		[Embed (source="../../../assets/hot_nebula_0_lowquality.jpg")]
		private var BitmapFront:Class;
		[Embed (source="../../../assets/hot_nebula_270_lowquality.jpg")]
		private var BitmapRight:Class;
		[Embed (source="../../../assets/hot_nebula_180_lowquality.jpg")]
		private var BitmapBack:Class;
		[Embed (source="../../../assets/hot_nebula_90_lowquality.jpg")]
		private var BitmapLeft:Class;
		[Embed (source="../../../assets/hot_nebula_bottom_lowquality.jpg")]
		private var BitmapDown:Class;
		[Embed (source="../../../assets/hot_nebula_top_lowquality.jpg")]
		private var BitmapUp:Class;

		public function NebulaSkybox(skysize:Number, quality:Number) {
			super(BitmapFront, BitmapLeft, BitmapBack, BitmapUp, BitmapRight, BitmapDown, skysize, quality);
		}
	}

	public class SkyboxTest {

		public static const SKYSIZE:Number = Number.MAX_VALUE;

		public function loadSkyBox(scene:Scene3D) {
			var skybox:Skybox = new NebulaSkybox(SKYSIZE, Skybox.QUALITY_HIGH);
			scene.addChild(skybox);
		}
	}
</pre>
<p><a href="http://blog.projectnibble.org/2009/05/22/easy-papervision3d-skybox-tutorial-and-source/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/05/22/easy-papervision3d-skybox-tutorial-and-source/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
