<?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>Northern Binary &#187; Papervision3D</title>
	<atom:link href="http://blog.northernbinary.org/category/papervision3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.northernbinary.org</link>
	<description></description>
	<lastBuildDate>Thu, 11 Mar 2010 10:16:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Papervision3D, Quake Models &amp; Color Palettes</title>
		<link>http://blog.northernbinary.org/actionscript/papervision3d-quake-models-color-palettes/</link>
		<comments>http://blog.northernbinary.org/actionscript/papervision3d-quake-models-color-palettes/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 05:23:10 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.opject.org/?p=16</guid>
		<description><![CDATA[Last week I was working on a port of a Quake model viewer I did in OpenGL to ActionScript 3.0 and Papervision3D. The actual AS3 code is reading the Quake model information from the original binary Quake .mdl file and contains, besides the polygon data, the bitmap that represents the texture for the model. The [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I was working on a port of a Quake model viewer I did in OpenGL to ActionScript 3.0 and Papervision3D. The actual AS3 code is reading the Quake model information from the original binary Quake .mdl file and contains, besides the polygon data, the bitmap that represents the texture for the model. The problem is that Quake uses a global color palette because the game was programmed for 256 colors (remember, this game is from 1996!). None of the models or textures actually stores a palette because they are assumed to all use the same palette and why store it many times&#8230; The actual color palette is stored in a separate binary file of 768 bytes in size (256 * 3 = 768, the 3 is for the three r, g, b color channels and every component ranges from the standard 0 &#8211; 255).</p>
<p>
When building the AS3 version of the Quake model viewer I could have chosen to read the color palette from the binary file by loading it in at runtime. Instead I chose another approach. I created a class that represented the color palette and I embedded the raw palette information as a resource in the swf itself:</p>
<p>
<pre class="box code">
package
{
   import flash.utils.ByteArray;

   public class QuakePalette
   {
      [Embed(source="quake.pal", mimeType="application/octet-stream")]
      private static const Palette : Class;

      public var r : Array = null;
      public var g : Array = null;
      public var b : Array = null;

      public function QuakePalette()
      {
         var i : int;
         var a : ByteArray;

         a = new Palette() as ByteArray;

         r = new Array();
         g = new Array();
         b = new Array();

         for( i = 0; i < 256; i++)
         {
            r[i] = a.readUnsignedByte();
            g[i] = a.readUnsignedByte();
            b[i] = a.readUnsignedByte();
         }
      }
   }
}
</pre>
<p>
Above is the code for the actual QuakePalette class that is used by the AS3 Quake model viewer. As you can see, the color palette is embedded inside the class as a resource. By setting the mimeType property to "application/octet-stream" the data is actually embedded as raw binary data. In the constructor the Palette class (the alias by which the raw binary data is known inside the class) is then casted as a ByteArray to be able to access the data. In the end the QuakePalette class has three public properties, r, g &#038; b, that represent the three RGB color channels for easy access.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.northernbinary.org/actionscript/papervision3d-quake-models-color-palettes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Papervision3D rocks!</title>
		<link>http://blog.northernbinary.org/actionscript-30/papervision3d-rocks/</link>
		<comments>http://blog.northernbinary.org/actionscript-30/papervision3d-rocks/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 06:10:48 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.opject.org/?p=15</guid>
		<description><![CDATA[Some months ago I was working on a conversion of an OpenGL Quake 1 model viewer I did years ago, it must have been 2000 or 2001 or something, to Papervision3D. The overall conversion went pretty smooth because all of the difficult stuff I already did when I was building the OpenGL version and the [...]]]></description>
			<content:encoded><![CDATA[<p>Some months ago I was working on a conversion of an OpenGL Quake 1 model viewer I did years ago, it must have been 2000 or 2001 or something, to Papervision3D. The overall conversion went pretty smooth because all of the difficult stuff I already did when I was building the OpenGL version and the code was <a href="http://blog.opject.org/?p=8" onclick="javascript:pageTracker._trackPageview ('/outbound/blog.opject.org');">documented</a> pretty well.</p>
<p>
When doing the conversion there was one problem I had at the time and that was the texturing. I just couldn&#8217;t get the texturing to work correctly with Papervision3D. I read the <a href="http://www.papervision3d.org/docs/as3/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.papervision3d.org');">Papervision3D documentation</a> and searched the web from top to bottom and inside out to find an example of the correct way to apply a texture to a Face3D object. At one point I just gave up and the code started to collect dust on my hard drive.
</p>
<p><a href="http://www.opject.org/quake" onclick="javascript:pageTracker._trackPageview ('/outbound/www.opject.org');"><img align="center" src="http://www.opject.org/blog/images/quake.jpg" /></a></p>
<p>
Until today. For a commercial project I&#8217;m currently working on I&#8217;m going to use Papervision3D and since I could spend paid hours on figuring out what the problem was with this code it seemed the right opportunity to dust off the Quake 1 model viewer code and fix this issue once and for all. And behold, after a day of debugging and bending my brain over and backwards, I seemed to have fixed the problem.</p>
<p>Basically, and I will not bore you with the details, I figured out that the Papervision3D documentation wasn&#8217;t that clear since the Face3D class constructor didn&#8217;t expected an array of {x,y} objects for the UV coordinates but an array of NumberUV objects. Second, the UV coordinates had to be given in percentage, something I lucky remembered from my OpenGL programming days.</p>
<p>So, there you go. You can checkout the Quake 1 model viewer <a href="http://www.opject.org/quake" onclick="javascript:pageTracker._trackPageview ('/outbound/www.opject.org');">here</a>  (might take a couple of seconds to load) and please let me know what you think&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.northernbinary.org/actionscript-30/papervision3d-rocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
