<?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>David E Jones a web developer with a passion for problem solving</title>
	<atom:link href="http://davidejones.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidejones.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Mon, 07 May 2012 16:40:19 +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>Python half precision floating point</title>
		<link>http://davidejones.com/blog/1413-python-precision-floating-point/</link>
		<comments>http://davidejones.com/blog/1413-python-precision-floating-point/#comments</comments>
		<pubDate>Mon, 07 May 2012 16:40:19 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[blender]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1413</guid>
		<description><![CDATA[I&#8217;ve been working with python for a while to create some addons for Blender which allowing me to import and export various formats that aren&#8217;t supported by default. One of these file formats I&#8217;ve been working with compresses the vertices/uv/tangent/normal &#8230; <a href="http://davidejones.com/blog/1413-python-precision-floating-point/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with python for a while to create some addons for Blender which allowing me to import and export various formats that aren&#8217;t supported by default. One of these file formats I&#8217;ve been working with compresses the vertices/uv/tangent/normal data to reduce the space used. This data is usually stored as 32bit floating point values but in this case it is reduced to 16bit floating point or Half Precision floating point. Halfing the final size of this data.</p>
<p>I had a hard time recreating this with python, I&#8217;d never used python before starting using Blender so my understanding was still fairly new and most examples online I failed to understand or struggled to implement.</p>
<p>Finally I cobbled together something that works from different examples online and got the results I wanted. Like most things on my site I felt the need to share this with anyone else who may be trying a similar thing.</p>
<p>Here is my class in python</p>
<pre class="prettyprint" rel="Python"><code>class Float16Compressor:
	def __init__(self):
		self.temp = 0

	def compress(self,float32):
		F16_EXPONENT_BITS = 0x1F
		F16_EXPONENT_SHIFT = 10
		F16_EXPONENT_BIAS = 15
		F16_MANTISSA_BITS = 0x3ff
		F16_MANTISSA_SHIFT =  (23 - F16_EXPONENT_SHIFT)
		F16_MAX_EXPONENT =  (F16_EXPONENT_BITS << F16_EXPONENT_SHIFT)

		a = struct.pack('>f',float32)
		b = binascii.hexlify(a)

		f32 = int(b,16)
		f16 = 0
		sign = (f32 >> 16) &#038; 0x8000
		exponent = ((f32 >> 23) &#038; 0xff) - 127
		mantissa = f32 &#038; 0x007fffff

		if exponent == 128:
			f16 = sign | F16_MAX_EXPONENT
			if mantissa:
				f16 |= (mantissa &#038; F16_MANTISSA_BITS)
		elif exponent > 15:
			f16 = sign | F16_MAX_EXPONENT
		elif exponent > -15:
			exponent += F16_EXPONENT_BIAS
			mantissa >>= F16_MANTISSA_SHIFT
			f16 = sign | exponent << F16_EXPONENT_SHIFT | mantissa
		else:
			f16 = sign
		return f16

	def decompress(self,float16):
		s = int((float16 >> 15) &#038; 0x00000001)    # sign
		e = int((float16 >> 10) &#038; 0x0000001f)    # exponent
		f = int(float16 &#038; 0x000003ff)            # fraction

		if e == 0:
			if f == 0:
				return int(s << 31)
			else:
				while not (f &#038; 0x00000400):
					f = f << 1
					e -= 1
				e += 1
				f &#038;= ~0x00000400
				#print(s,e,f)
		elif e == 31:
			if f == 0:
				return int((s << 31) | 0x7f800000)
			else:
				return int((s << 31) | 0x7f800000 | (f << 13))

		e = e + (127 -15)
		f = f << 13
		return int((s << 31) | (e << 23) | f)</code></pre>
<p>and here is how to use it</p>
<pre class="prettyprint" rel="Python"><code>#read half float from file and print float
h = struct.unpack(">H",file.read(struct.calcsize(">H")))[0]
fcomp = Float16Compressor()
temp = fcomp.decompress(h)
str = struct.pack('I',temp)
f = struct.unpack('f',str)[0]
print(f)

#write half float to file from float
fcomp = Float16Compressor()
f16 = fcomp.compress(float32)
file.write(struct.pack(">H",f16))
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1413-python-precision-floating-point/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>blender 2.63.0 python accessing data with bmesh changes</title>
		<link>http://davidejones.com/blog/1402-blender-2630-accessing-data-bmesh/</link>
		<comments>http://davidejones.com/blog/1402-blender-2630-accessing-data-bmesh/#comments</comments>
		<pubDate>Tue, 01 May 2012 16:39:59 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[blender]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1402</guid>
		<description><![CDATA[I&#8217;ve just updated my blender to 2.63 and discovered that this uses the new bmesh! Bmesh gives you better control to manipulate your 3d models. For more information take a look at this. Anyway with this big change that means &#8230; <a href="http://davidejones.com/blog/1402-blender-2630-accessing-data-bmesh/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just updated my blender to 2.63 and discovered that this uses the new bmesh! Bmesh gives you better control to manipulate your 3d models. For more information take a <a href="http://gamefromscratch.com/post/2012/04/20/Blender-BMesh-in-action%E2%80%A6-what%E2%80%99s-so-special-about-ngons-anyways.aspx" target="_blank">look at this</a>.</p>
<p>Anyway with this big change that means there are more changes to the python api. Which means i have to update my addons again sigh. I&#8217;m learning what the new changes are and thought i&#8217;d post a little code snippet on how to access some of the usual data through this now.</p>
<p>The below code i used just on a simple triangulated cube, it may help point you in the right direction if you are having similar problems as I was.</p>
<pre class="prettyprint" rel="Python"><code>import bpy

obj = bpy.data.objects['Cube']
mesh = obj.data

normals = []
indices = []
for face in mesh.polygons:
    indices.append(face.vertices[0])
    indices.append(face.vertices[1])
    indices.append(face.vertices[2])
    for i in range(len(face.vertices)):
        v = mesh.vertices[face.vertices[i]]
        normals.append([v.normal[0],v.normal[1],v.normal[2]])

verts = []
for vert in mesh.vertices:
    verts.append(vert.co.xyz)

uvs = []
for uv_layer in mesh.uv_layers:
    for x in range(len(uv_layer.data)):
        uvs.append(uv_layer.data[x].uv)

print(indices)
print(verts)
print(uvs)
print(normals)</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1402-blender-2630-accessing-data-bmesh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MovieMaterial with alternativa3d 8</title>
		<link>http://davidejones.com/blog/1392-moviematerial-alternativa3d-8/</link>
		<comments>http://davidejones.com/blog/1392-moviematerial-alternativa3d-8/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 23:49:31 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[website development]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[alternativa3d]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1392</guid>
		<description><![CDATA[You can find a few examples of a MovieMaterial for version 5 and 7 of alternativa3d on their forums and wiki but I have yet to see one for version 8 so I thought I&#8217;d give it a go&#8230; You &#8230; <a href="http://davidejones.com/blog/1392-moviematerial-alternativa3d-8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You can find a few examples of a MovieMaterial for version 5 and 7 of alternativa3d on their <a href="http://forum.alternativaplatform.com" target="_blank">forums</a> and <a href="http://wiki.alternativaplatform.com" target="_blank">wiki</a> but I have yet to see one for version 8 so I thought I&#8217;d give it a go&#8230;</p>
<p>You may recognise the swf from the alternativa3d bunker demo that was created in version 5</p>
<p><a href="http://davidejones.com/labs/moviematerial-alternativa8/" target="_blank"><img src="http://davidejones.com/wp-content/uploads/2012/04/moviematerial-alternativa3d8.jpg" alt="" title="moviematerial-alternativa3d8" class="alignnone size-full wp-image-1395" /></a></p>
<p>The usage is the same as most materials just pass in the movieclip and apply the material and the rest is done. Here is a snippet of the usage&#8230;</p>
<pre class="prettyprint" rel="Actionscript"><code>[Embed(source="screen.swf")] static private const TestSWF:Class;

mybox = new Box();
var mat:MovieMaterial = new MovieMaterial(new TestSWF());
mybox.setMaterialToAllSurfaces(mat);
scene.addChild(mybox);
uploadResources(mybox.getResources(true));</code></pre>
<p>and here is the actual class.. it&#8217;s pretty similar to others except for the need to upload the new image resource as well. </p>
<pre class="prettyprint" rel="Actionscript"><code>package
{
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.engine3d.resources.TextureResource;
	import alternativa.engine3d.resources.BitmapTextureResource;
	import alternativa.engine3d.core.Camera3D;
	import alternativa.engine3d.objects.Surface;
	import alternativa.engine3d.resources.Geometry;
	import alternativa.engine3d.core.Light3D;
	import flash.display.MovieClip;
	import flash.display.BitmapData;
	import flash.events.Event;

	import alternativa.engine3d.alternativa3d;
	use namespace alternativa3d;

	public class MovieMaterial extends TextureMaterial
	{
		protected var mc:MovieClip;
		protected var bd:BitmapData;

		public function MovieMaterial(clip:MovieClip):void
		{
			mc = clip;
			this.diffuseMap = getDiffuse();
			this.alpha = 1;
			super(diffuseMap,null,alpha);
			mc.addEventListener(Event.ENTER_FRAME, updateTexture);
		}

		private function getDiffuse():TextureResource {
			bd = new BitmapData (mc.width, mc.height, true);
			return new BitmapTextureResource(bd);
		}

		protected function updateTexture(e:Event = null):void {
			if(mc) { bd.draw(mc); }
		}

		override alternativa3d function collectDraws(camera:Camera3D, surface:Surface, geometry:Geometry, lights:Vector.<Light3D>, lightsLength:int, objectRenderPriority:int = -1):void
		{
			if(diffuseMap) { diffuseMap.upload(camera.context3D); }
			super.collectDraws(camera, surface, geometry, lights, lightsLength, objectRenderPriority);
		}
	}
}</code></pre>
<p>Its not perfect I can see that it lights up white just before the swf starts playing. I&#8217;m guessing this is just the stage background colour of the embedded swf but i&#8217;m not 100% sure as I haven&#8217;t tested any other swfs. Its also worth noting that the bitmap data or swf still needs to be a power of 2 to be uploaded successfully. The example swf I used was 256&#215;256.</p>
<p>You can download the <a href='http://davidejones.com/wp-content/uploads/2012/04/moviematerialv8.zip'>source files here</a> or see the <a href="http://davidejones.com/labs/moviematerial-alternativa8/" target="_blank">demo here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1392-moviematerial-alternativa3d-8/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>turning off texture smoothing alternativa3d 8</title>
		<link>http://davidejones.com/blog/1376-turning-texture-smoothing-alternativa3d-8/</link>
		<comments>http://davidejones.com/blog/1376-turning-texture-smoothing-alternativa3d-8/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 23:04:40 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[website development]]></category>
		<category><![CDATA[AGAL]]></category>
		<category><![CDATA[alternativa3d]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[minecraft]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1376</guid>
		<description><![CDATA[Now that alternativa3d has been released as opensource and is available online at github, this opens up the opportunities for developers to try some great things with the technology and hopefully contribute to its development. The first thing that bugged &#8230; <a href="http://davidejones.com/blog/1376-turning-texture-smoothing-alternativa3d-8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Now that alternativa3d has been released as opensource and is available online at github, this opens up the opportunities for developers to try some great things with the technology and hopefully contribute to its development.</p>
<p>The first thing that bugged me with version 8 is that I couldn&#8217;t turn off the smoothing of images. In version 7 you could easily do this by setting material.smooth to false and get that pixelated look. So I thought now the source is released I&#8217;d put together a little example of how to get this same effect.</p>
<p><a href="http://davidejones.com/labs/texture-smooth-alternativa8/" target="_blank"><img src="http://davidejones.com/wp-content/uploads/2012/04/head.jpg" alt="" title="head" class="alignnone size-full wp-image-1384" /></a></p>
<p>To create this I duplicated the TextureMaterial class from the alternativa source code and made my own PixelTextureMaterial. </p>
<p>In this class there are 2 constants that contain AGAL code that is for the diffuse and diffuse with alpha rendering. If you aren&#8217;t familar with AGAL, I guess it can be described as sort of gpu assembly code. Anyway there is a line in the AGAL code that begins with &#8220;tex&#8221; and then has some various registers and flag options. </p>
<p>Here is an example of code</p>
<pre class="prettyprint" rel="Actionscript"><code>tex t0, v0, s0 &lt;2d, linear,linear,miplinear&gt;</code></pre>
<p>The flag options between the arrows are what we are interested in, these options represent this data</p>
<pre class="prettyprint" rel="Actionscript"><code>&lt;dimension,mipmapping,filtering,repeat&gt;</code></pre>
<p>The texture dimension can be : 2d, cube<br />
The texture mipmapping can be : nomip, mipnone, mipnearest, miplinear<br />
The texture filtering can be : nearest, linear<br />
The texture repeat can be : repeat, wrap, clamp</p>
<p>The texture filtering is responsible for the way our image is sampled and the current TextureMaterial is set to use linear filtering, if we change this to say nearest we can get that pixelated look we want.</p>
<p>Here is what my changed code looks like, you can of course alter the other flag options to remove mipmapping or change the repeat etc if you desire. The <a href='http://davidejones.com/wp-content/uploads/2012/04/smoothingv8.zip'>full source code is available here</a> or see the <a href="http://davidejones.com/labs/texture-smooth-alternativa8/" target="_blank">demo here</a>.</p>
<pre class="prettyprint" rel="Actionscript"><code>static alternativa3d const getDiffuseProcedure:Procedure = new Procedure([
	"#v0=vUV",
	"#s0=sDiffuse",
	"#c0=cThresholdAlpha",
	"tex t0, v0, s0 <2d, linear,nearest, miplinear>",
	"mul t0.w, t0.w, c0.w",
	"mov o0, t0"
], "getDiffuseProcedure");

static alternativa3d const getDiffuseOpacityProcedure:Procedure = new Procedure([
	"#v0=vUV",
	"#s0=sDiffuse",
	"#s1=sOpacity",
	"#c0=cThresholdAlpha",
	"tex t0, v0, s0 <2d, linear,nearest, miplinear>",
	"tex t1, v0, s1 <2d, linear,nearest, miplinear>",
	"mul t0.w, t1.x, c0.w",
	"mov o0, t0"
], "getDiffuseOpacityProcedure");</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1376-turning-texture-smoothing-alternativa3d-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fluid Water Simulation Alternativa3d 8</title>
		<link>http://davidejones.com/blog/1367-fluid-water-simulation-alternativa3d-8/</link>
		<comments>http://davidejones.com/blog/1367-fluid-water-simulation-alternativa3d-8/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 17:15:43 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[website development]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[alternativa3d]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1367</guid>
		<description><![CDATA[When a major release of the alternativa3d library comes out I slowly start to try recreating my previous tests and examples over to the new version to see how they work and learn a thing or 2 about the new &#8230; <a href="http://davidejones.com/blog/1367-fluid-water-simulation-alternativa3d-8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When a major release of the alternativa3d library comes out I slowly start to try recreating my previous tests and examples over to the new version to see how they work and learn a thing or 2 about the new system.</p>
<p>I&#8217;ve recently taken <a href="http://davidejones.com/blog/433-fluid-water-simulation-alternativa3d-7/">the fluid water simulation for version 7</a> and set it up for version 8 which works a lot better with the standard material and lighting effects. </p>
<p>To get it to work I had to create a Vertex class to assign the x y z values and then use version 8&#8242;s new geometry and streams to set the data back.</p>
<p><a href="http://davidejones.com/labs/fluidplane-version8/" target="_blank"><img src="http://davidejones.com/wp-content/uploads/2012/04/fluid-water-alternativa3d-8.jpg" alt="" title="fluid-water-alternativa3d-8" class="alignnone size-full wp-image-1368" /></a></p>
<p>Here is my document class</p>
<pre class="prettyprint" rel="Actionscript"><code>package
{
	import alternativa.engine3d.controllers.SimpleObjectController;
	import alternativa.engine3d.core.Camera3D;
	import alternativa.engine3d.core.Object3D;
	import alternativa.engine3d.core.Resource;
	import alternativa.engine3d.core.View;
	import alternativa.engine3d.materials.StandardMaterial;
	import alternativa.engine3d.resources.BitmapTextureResource;
	import alternativa.engine3d.lights.*;

	import flash.display.Sprite;
	import flash.display.Stage3D;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Vector3D;

	import FluidPlane;

	[SWF(backgroundColor="#000000", frameRate="100", width="800", height="600")]

	public class test extends Sprite
	{
		[Embed(source="465-diffuse.jpg")] static private const FluidDiffuse:Class;
		[Embed(source="465-normal.jpg")] static private const FluidNormal:Class;
		[Embed(source="465-bump.jpg")] static private const FluidSpec:Class;

		private var rootContainer:Object3D = new Object3D();
		private var camera:Camera3D;
		private var controller:SimpleObjectController;
		private var fplane:FluidPlane;
		private var stage3D:Stage3D;
		private var dl2:DirectionalLight;

		public function test():void
		{
			//setup stage
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			camera = new Camera3D(0.1, 10000);
			camera.view = new View(stage.stageWidth, stage.stageHeight);
			addChild(camera.view);
			addChild(camera.diagram);
			camera.y = 100;
			camera.z = 100;
			camera.x = -50;
			controller = new SimpleObjectController(stage, camera, 200);
			controller.lookAt(new Vector3D(0,0,0));
			rootContainer.addChild(camera);

			//setup material
			var mat:StandardMaterial = new StandardMaterial(new BitmapTextureResource(new FluidDiffuse().bitmapData),new BitmapTextureResource(new FluidNormal().bitmapData),null,new BitmapTextureResource(new FluidSpec().bitmapData));

			dl2 = new DirectionalLight(0xFFFFFF);
            dl2.intensity = 0.5;
            dl2.lookAt(0,0,0);
			dl2.rotationX = -2.26893;
            dl2.rotationY = 0;
            dl2.rotationZ = 0.698132;
            rootContainer.addChild(dl2);

			var al:AmbientLight = new AmbientLight(0xFFFFFF);
			al.intensity = 0.5;
			al.z = 100;
            rootContainer.addChild(al);

			//create fluidplane and apply material
			fplane = new FluidPlane(camera);
			fplane.setMaterialToAllSurfaces(mat);
			rootContainer.addChild(fplane);

			stage3D = stage.stage3Ds[0];
			stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
			stage3D.requestContext3D();
		}

		private function onContextCreate(e:Event):void {
			for each (var resource:Resource in rootContainer.getResources(true)) {
				resource.upload(stage3D.context3D);
			}

			//start a splash
			fplane.makeSplash(2);

			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(e:Event):void
		{
			controller.update();
			camera.render(stage3D);
			fplane.draw(stage3D);
		}

		private function onResize(e:Event = null):void {
			camera.view.width = stage.stageWidth;
			camera.view.height = stage.stageHeight;
		}

	}

}
</code></pre>
<p>and here is the revised fluid plane class.</p>
<pre class="prettyprint" rel="Actionscript"><code>// A conversion of the papervision and away3d example
// http://exey.ru/blog/home/fluid-simulation-pv3d-and-away3d

package
{
	import alternativa.engine3d.primitives.Plane;
	import alternativa.engine3d.materials.Material;
	import flash.geom.Vector3D;
	import alternativa.engine3d.core.Camera3D;
	import alternativa.engine3d.core.VertexAttributes;
	import flash.display.Stage3D;

	public class FluidPlane extends Plane
	{
		private var theta:Number = 0;
		private var buffer:Array = new Array(2);
		private var renderBuffer:int = 0;
		private var k1:Number;
		private var k2:Number;
		private var k3:Number;

		private var range:int = 20;
		private var waterSegsX:int = range;
		private var waterSegsY:int = range;
		private var waterSegsXreal:int = waterSegsX+1;
		private var waterSegsYreal:int = waterSegsY+1;
		private var waterXcenter:int = range/2;
		private var waterYcenter:int= range/2;
		private var isPause:Boolean = false;

		private var camera:Camera3D;
		private var vertices:Vector.<Vertex> = new Vector.<Vertex>();
		private var verts:Vector.<Number> = new Vector.<Number>();

		public function FluidPlane(camera:Camera3D,width:Number = 100, length:Number = 100, widthSegments:uint = 1, lengthSegments:uint = 1, twoSided:Boolean = true, reverse:Boolean = false, bottom:Material = null, top:Material = null)
		{
			this.camera = camera;
			widthSegments = waterSegsX;
			lengthSegments = waterSegsY;
			super(width, length, widthSegments, lengthSegments, twoSided, reverse, bottom, top);

			setupVertices();
			prepareMath();
		}

		private function setupVertices():void
		{
			verts =  this.geometry.getAttributeValues(VertexAttributes.POSITION);
			var x:int = 0;
			for(var i:int = 0; i < verts.length/3; i++)
			{
				var v:Vertex = new Vertex();
				v.x = verts[i + x]; x++;
				v.y = verts[i + x]; x++;
				v.z = verts[i + x];
				this.vertices.push(v);
			}
		}

		private function resaveVertices():void
		{
			this.verts = new Vector.<Number>();
			for(var i:int = 0; i < this.vertices.length; i++)
			{
				this.verts.push(this.vertices[i].x);
				this.verts.push(this.vertices[i].y);
				this.verts.push(this.vertices[i].z);
			}
		}

		public function draw(stage3D:Stage3D):void
		{
			theta += 0.05;
			var verCounter:uint = 0;
			for(var x:int = 0 ; x < waterSegsXreal ; x++){
				for(var z:int = 0 ; z < waterSegsYreal ; z++){
					this.vertices[verCounter].z = buffer[renderBuffer][x][z].y * 3;
					verCounter++;
				}
			}
			evaluate();

			resaveVertices();

            this.geometry.setAttributeValues(VertexAttributes.POSITION, verts);
			this.geometry.calculateNormals();
			this.geometry.calculateTangents(0);
			this.calculateBoundBox();
            this.geometry.upload(stage3D.context3D);
		}

		public function makeSplash(splashHeight:int):void
		{
			populateBuffer();
			buffer[renderBuffer][waterXcenter][waterYcenter].y = splashHeight;
		}

		public function prepareMath():void
		{
			populateBuffer();
			//trace(buffer[0].length, buffer[1].length)
			var d:Number = 1;
			var t:Number = 0.1;
			var c:Number = 2.1;
			var mu:Number = 0.001;
			var f1:Number = c*c*t*t/(d*d);
			var f2:Number = 1/(mu*t+2);
			k1 = (4 - 8*f1)*f2;
			k2 = (mu*t-2)*f2;
			k3 = 2 * f1 * f2;
		}

		public function populateBuffer():void
		{
			var x:int,y:int,z:int;
			// 3-d displacement will be stored in the array(2*w*h)
			for(var i:int = 0 ; i < 2; i++)
			{
				var a:Array = new Array();
				for(var j:int = 0 ; j < waterSegsYreal; j++)
				{
					var aa:Array = new Array();
					for(var k:int = 0 ; k < waterSegsXreal; k++)
						aa.push(new Vector3D(j,0,k));
					a.push(aa);
				}
				buffer[i] = a;
			}
		}

		private function evaluate():void
		{
			for(var j:int = 1 ; j < waterSegsYreal-1; j++)
			{
				var crnt:Array = buffer[renderBuffer][j];
				var prev:Array = buffer[1-renderBuffer][j];
				for (var i:int = 1 ; i < waterSegsXreal-1; i++)
				{
					//  trace(j, i);
					var currentN:Vector3D = (Vector3D)(buffer[renderBuffer][j + 1][i]);
					var currentP:Vector3D = (Vector3D)(buffer[renderBuffer][j - 1][i]);
					((Vector3D)(prev[i])).y = k1*((Vector3D)(crnt[i])).y + k2*((Vector3D)(prev[i])).y + k3*(((Vector3D)(crnt[i+1])).y + ((Vector3D)(crnt[i-1])).y + currentN.y + currentP.y);
				}
			}
			renderBuffer = 1-renderBuffer;
		}

	}
}

import flash.geom.Vector3D;
class Vertex extends Object
{

	public var x:Number;
	public var y:Number;
	public var z:Number;

	function Vertex()
	{
		return;
	}
}</code></pre>
<p><a href='http://davidejones.com/wp-content/uploads/2012/04/fluid-water-simulation-alternativa3d8.zip'>You can download the source files here</a> or see the <a href="http://davidejones.com/labs/fluidplane-version8/" target="_blank">demo here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1367-fluid-water-simulation-alternativa3d-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternativa3d Exporter update and move to github</title>
		<link>http://davidejones.com/blog/1358-alternativa3d-exporter-update-move-github/</link>
		<comments>http://davidejones.com/blog/1358-alternativa3d-exporter-update-move-github/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 05:58:03 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[website development]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[alternativa3d]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[blender]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1358</guid>
		<description><![CDATA[Hey folks, for those of you who follow my 3d work with and the flash alternativa3d library you will be glad to hear that I&#8217;ve updated my blender alternativa3d importer/exporter to work with version 8.27.0, Along with this update I &#8230; <a href="http://davidejones.com/blog/1358-alternativa3d-exporter-update-move-github/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hey folks, for those of you who follow my 3d work with and the flash alternativa3d library you will be glad to hear that I&#8217;ve updated my blender alternativa3d importer/exporter to work with version 8.27.0,</p>
<p>Along with this update I have moved the project over to <a href="https://github.com/davidejones/alternativa3d_tools" target="_blank">github</a>. Why <a href="https://github.com/davidejones/alternativa3d_tools" target="_blank">github?</a> it&#8217;s a preference thing it feels more comfortable, its easy for others to fork the code and do their own thing with it and I generally find it more intuitive browsing the source code.</p>
<p>The new version allows you to export 3d models that have textures or diffuse colours to actionscript <a href="http://alternativaplatform.com/en/" target="_blank">alternativa3d</a> compatible classes. I&#8217;ve created a quick demo just to show what it can do.</p>
<p>In the demo i&#8217;ve created 3 objects a cube, suzanne the monkey and lastly the torus. The cube is just a simple pink diffuse material applied to all faces. Suzanne the monkey is an example of uv wrapping and a single image texture. The last example is of applying multiple diffuse materials to faces, multiple uv image textures also work like this.</p>
<p><a href="http://davidejones.com/labs/alternativa-exporter-demo/"><img src="http://davidejones.com/wp-content/uploads/2012/03/2.jpg" alt="" title="2" width="500" height="404" class="alignnone size-full wp-image-1359" /></a></p>
<p>The code uses the geometry class as seen in previous version but uses the different streams for position coordinates, normals, uvs, indices and tangents. I&#8217;m still not sure how to export the tangents from blender so this doesn&#8217;t actually work right now but if you are using version 8.27.0 you can call the calculateTangents() function.</p>
<p><a href="http://davidejones.com/labs/alternativa-exporter-demo/">Click here to view the demo</a><br />
<a href='http://davidejones.com/wp-content/uploads/2012/03/alternativa3d-demo-blenderexport.zip'>Download the demo files including blender sourcefile</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1358-alternativa3d-exporter-update-move-github/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Alternativa 8.27.0 Undocumented ResourceLoader</title>
		<link>http://davidejones.com/blog/1334-alternativa-8-27-0-resourceloader/</link>
		<comments>http://davidejones.com/blog/1334-alternativa-8-27-0-resourceloader/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 20:21:07 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[website development]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[alternativa3d]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[stage3d]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1334</guid>
		<description><![CDATA[It was pointed out to me recently by the alternativa3d guys that there is actually another loader in their engine other than the TextureLoader called ResourceLoader. Its not documented but it provides a progress event which isn&#8217;t available in the &#8230; <a href="http://davidejones.com/blog/1334-alternativa-8-27-0-resourceloader/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It was pointed out to me recently by the alternativa3d guys that there is actually another loader in their engine other than the TextureLoader called ResourceLoader. Its not documented but it provides a progress event which isn&#8217;t available in the TextureLoader and I desperately needed this for a project of mine. </p>
<p>Seen as its currently undocumented I thought I&#8217;d spend a brief moment explaining how to use it.</p>
<p>I&#8217;m taking the parsersexample that comes with the alternativa files to illustrate how to use this new class. You should be able to find it at Alternativa3d_8.27.0\Alternativa3DExamples\src\parsersexample. </p>
<p>Once we have access to the file we need to add 2 new includes to it, so add these somewhere at the top.</p>
<pre class="prettyprint" rel="Actionscript"><code>import alternativa.engine3d.loaders.ResourceLoader;
import flash.events.ProgressEvent;</code></pre>
<p>Then add these variables that we are going to use to get the percentage loaded.</p>
<pre class="prettyprint" rel="Actionscript"><code>private var itemsTotal:Number = 0;
private var itemsLoaded:Number = 0;</code></pre>
<p>Once thats done we need to switch out the TextureLoader and use our new ResourceLoader. So find the following lines and comment them out or remove them.</p>
<pre class="prettyprint" rel="Actionscript"><code>//var texturesLoader:TexturesLoader = new TexturesLoader(stage3D.context3D);
//texturesLoader.loadResources(textures);</code></pre>
<p>Then just below this add the following</p>
<pre class="prettyprint" rel="Actionscript"><code>itemsTotal = textures.length;
var resldr:ResourceLoader = new ResourceLoader();
resldr.addEventListener(ProgressEvent.PROGRESS, onProgress);
resldr.addEventListener(Event.COMPLETE, onComplete);
resldr.addResources(textures);
resldr.load(stage3D.context3D);</code></pre>
<p>This will setup a new instance of the resourceloader and listen for a couple of events. We then pass in the vector of our textures this is the same one that was used in texturesloader, then we just run load to get things moving.</p>
<p>Before we run this code we need the 2 functions for the events too so add these somewhere in the parsersexample.</p>
<pre class="prettyprint" rel="Actionscript"><code>private function onProgress(e:ProgressEvent):void
{
	itemsLoaded++;
	var percentLoaded:Number = itemsLoaded / itemsTotal;
	percentLoaded = Math.round(percentLoaded * 100);
	trace(percentLoaded + "%");
}

private function onComplete():void
{
	trace("done");
}</code></pre>
<p>Normally I would do something like this code below to get the percentage but the bytesloaded and bytestotal always returned 0 so I scrapped that used the above solution.</p>
<pre class="prettyprint" rel="Actionscript"><code>var percentLoaded:Number = e.bytesLoaded / e.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace(percentLoaded + "%");</code></pre>
<p>I&#8217;ve put this code into a seperate &#8220;Examples&#8221; folder that you can use with the other alternativa3d examples to try this out. <a href='http://davidejones.com/wp-content/uploads/2012/03/alternativa3d-resourceloader.zip'>Download the files here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1334-alternativa-8-27-0-resourceloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jquery mouseover or hover</title>
		<link>http://davidejones.com/blog/1324-jquery-mouseover-hover/</link>
		<comments>http://davidejones.com/blog/1324-jquery-mouseover-hover/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 17:54:49 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[website development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1324</guid>
		<description><![CDATA[When I&#8217;m working with jQuery Its usually for something simple and I just throw together a few simple click and mouse events to get what I want. In a number of my projects I seem to switch between the functions &#8230; <a href="http://davidejones.com/blog/1324-jquery-mouseover-hover/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When I&#8217;m working with jQuery Its usually for something simple and I just throw together a few simple click and mouse events to get what I want.  In a number of my projects I seem to switch between the functions I use, sometimes its mouseover() , mouseout() and sometimes its hover(). </p>
<pre class="prettyprint" rel="javascript"><code>$("li").mousover(function(){
	//do something over
}).mouseout(function() {
	//do something out
});</code></pre>
<pre class="prettyprint" rel="javascript"><code>$("li").hover(
  function () {
    //do something enter
  },
  function () {
    //do something exit
  }
);</code></pre>
<p>Its only until I recently encountered a problem that I really spent the time to check what the difference was. It turns out that mouseover and mouseout fire events for the children of that element. Where as hover actually works with mouseenter and mouseleave without firing for children.</p>
<p>In the project I was working on I setup a container div to use mouseover and mouseout which added some html tabs to the container. This seemed perfectly fine but I discovered that using mouseover/mouseout meant the added html kept disappearing when I tried to interact with it along with the other jquery I had in place that was conflicting with it.</p>
<p>In the end my particular solution required me to use mouseenter and mouseleave with the live function rather than using hover because I was working with generated html.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1324-jquery-mouseover-hover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>css3 onClick using :target</title>
		<link>http://davidejones.com/blog/1289-css3-onclick-psuedo-target-effects/</link>
		<comments>http://davidejones.com/blog/1289-css3-onclick-psuedo-target-effects/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 06:18:41 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[website development]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1289</guid>
		<description><![CDATA[If you haven&#8217;t come across the :target psuedo class yet you may have missed a trick, its a great piece of css that can give you a more active page without the need of javascript. The easiest way to imagine &#8230; <a href="http://davidejones.com/blog/1289-css3-onclick-psuedo-target-effects/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t come across the <a href="http://www.w3.org/TR/selectors/#target-pseudo" title=":target">:target psuedo class</a> yet you may have missed a trick, its a great piece of css that can give you a more active page without the need of javascript.</p>
<p>The easiest way to imagine this working is to actually think of click events in javascript. Lets say you have a href link with an onClick event attached to it. Clicking this triggers some javascript to show a div somewhere in the page. To do this in javascript you might have some code like this</p>
<pre class="prettyprint" rel="Html"><code>&lt;a href="#" onClick="document.getElementById('box1').style.display='block'"&gt;Click Me&lt;/a&gt;
&lt;div id="box1" style="display:none;"&gt;test test&lt;/div&gt;</code></pre>
<p>Well this very same functionality is available using just the :target css and to great effect. Take this code below as an example, here we can do exactly the same as the javascript but now just with css.</p>
<pre class="prettyprint" rel="Html"><code>&lt;style type="text/css"&gt;
	#box1 {
		display:none;
	}
	#box1:target {
		display:block;
	}
&lt;/style&gt;

&lt;a href="#box1"&gt;Click Me&lt;/a&gt;
&lt;div id="box1"&gt;test test&lt;/div&gt;</code></pre>
<p>Of course there are the usual browser limitations but consider combining this with javascript as a fallback and you can have a more future proof native version of your code. Combine this with some of the css animation effects and you can have something that would easily fool others into thinking its made with javascript when in fact its css.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1289-css3-onclick-psuedo-target-effects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternativa3d 8 physics bowling pin</title>
		<link>http://davidejones.com/blog/1274-alternativa3d-8-physics-bowling-pin/</link>
		<comments>http://davidejones.com/blog/1274-alternativa3d-8-physics-bowling-pin/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 22:49:03 +0000</pubDate>
		<dc:creator>davidejones</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[website development]]></category>
		<category><![CDATA[alternativa3d]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://davidejones.com/?p=1274</guid>
		<description><![CDATA[Alternativa3d have just released their own physics library to go hand in hand with their already excellent flash 3d framework. I thought I would give it a quick try to see what its like. The physics engine has its own &#8230; <a href="http://davidejones.com/blog/1274-alternativa3d-8-physics-bowling-pin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Alternativa3d have just released their own physics library to go hand in hand with their already excellent flash 3d framework. I thought I would give it a quick try to see what its like.</p>
<p><a href="http://davidejones.com/labs/bowling-pin-alternativa3d8-physics/" target="_blank"><img src="http://davidejones.com/wp-content/uploads/2011/12/bowling-pin-alternativa3d-8-physics.jpg" alt="" title="bowling-pin-alternativa3d-8-physics" class="alignnone size-full wp-image-1275" /></a></p>
<p>The physics engine has its own set of classes that seem to integrate or extend alternativa3D 8. This means that all the scene and camera creation is already done and you can just override the setScene() and then  concentrate on handling of the physics and the rest of the code. Its setup is familiar to me and reminds me of the jiglib flash libraries so its quite easy to get up and running with.</p>
<p>The examples that come with the physics engine don&#8217;t actually show the loading of a 3d model and then applying physics to it but it is very simple task. Just load the .3ds file or .a3d file as you would as per the examples from the alternativa3d 8 library. Once its all loaded you setup a transform, a physical object and a collision area then add it to the scene.</p>
<pre class="prettyprint" rel="Actionscript"><code>override protected function setScene():void
{
	//add fps
	addChild(camera.diagram);

	//create and add light source
	var light:Light3D;
	light = new OmniLight(0xFFFFFF, 1, 7000);
	light.x = 0;
	light.y = 200;
	light.z = 1000;
	light.intensity = 0.8;
	addObject3D(light);
	light = new AmbientLight(0xFFFFFF);
	light.intensity = 0.2;
	addObject3D(light);

	//create a loader to load the pin
	var loader3DS:URLLoader = new URLLoader();
	loader3DS.dataFormat = URLLoaderDataFormat.BINARY;
	loader3DS.load(new URLRequest("pin.3ds"));
	loader3DS.addEventListener(Event.COMPLETE, on3DSLoad);
}

private function on3DSLoad(e:Event):void
{
	var parser:Parser3DS = new Parser3DS();
	parser.parse((e.target as URLLoader).data);
	var mesh:Mesh;
	for each (var object:Object3D in parser.objects) {
		if (object.name == "Mesh.007") {
			mesh = object as Mesh;
			break;
		}
	}
	uploadResources(mesh.getResources(false, Geometry));

	// Setup materials
	var textures:Vector.<ExternalTextureResource> = new Vector.<ExternalTextureResource>();
	for (var i:int = 0; i < mesh.numSurfaces; i++) {
		var surface:Surface = mesh.getSurface(i);
		var material:ParserMaterial = surface.material as ParserMaterial;
		if (material != null) {
			var diffuse:ExternalTextureResource = material.textures["diffuse"];
			if (diffuse != null) {
				diffuse.url = "" + diffuse.url;
				textures.push(diffuse);
				surface.material = new TextureMaterial(diffuse);
			}
		}
	}

	// Loading of textures
	var texturesLoader:TexturesLoader = new TexturesLoader(stage3d.context3D);
	texturesLoader.loadResources(textures);

	// setup loaded model in this case bowling pin
	var transform:Matrix4 = new Matrix4();
	transform.setPositionXYZ(0, 0, 1);
	var pin1:PhysicalSimObject = new DynamicObject(transform, new Vector3(0, 0, 2));
	pin1.addPhysicsPrimitive(
		new PhysicsPrimitive(new CollisionTriangleMesh(MeshUtils.createGeometryMeshFromMesh3d(mesh), CollisionType.DYNAMIC), 1)
	);
	pin1.addAppearanceComponent(mesh);
	addSimObject(pin1);
}

private function uploadResources(resources:Vector.<Resource>):void {
	for each (var resource:Resource in resources) {
		resource.upload(stage3d.context3D);
	}
}</code></pre>
<p>The boundaries for the collision are taken from the actual mesh this time instead of using a rectangle or other primitive shape. To do this we use the CollisionTriangleMesh and the meshutility to convert the mesh class to the accepted parameter class geometrymesh.</p>
<pre class="prettyprint" rel="Actionscript"><code>pin1.addPhysicsPrimitive(
	new PhysicsPrimitive(new CollisionTriangleMesh(MeshUtils.createGeometryMeshFromMesh3d(mesh), CollisionType.DYNAMIC), 1)
);</code></pre>
<p>While this did work I had some issues with the bowling pins sinking through the floor I created. Its like the origin point for the mesh had changed once it was run through the meshutility. So to get the effect i wanted I switched it around and used a cone shape for collision.</p>
<pre class="prettyprint" rel="Actionscript"><code>pin1.addPhysicsPrimitive(
	new PhysicsPrimitive(new CollisionCone(0.1, 0.3, 3, CollisionType.DYNAMIC), 0.5)
);</code></pre>
<p>You can <a href='http://davidejones.com/wp-content/uploads/2011/12/alternativa3d8-physics-bowling.zip'>download the files here</a> or view it on the <a href="http://davidejones.com/labs/bowling-pin-alternativa3d8-physics/" target="_blank">demo page here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidejones.com/blog/1274-alternativa3d-8-physics-bowling-pin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

