AS3 Triangulation

AS3 Triangulation

We’ve recently been working with beacon technology at work. If you’re not up to date with what they are I’d suggest checking out this wikipedia article, but in a nut shell they’re little devices that periodically emit a bluetooth signal and based on the strength of said signal one can work out how far away the beacon is from the receiver (in most cases a users phone). However accuracy seems to fluctuate fairly badly when there is no clear line of sight. To combat this we decided to place the beacons on the roof as well as using at least three beacons in any given area, this allows us to firstly average out any signal fluctuates as well as triangulating the exactly position of the user. Below is an example of how to use the as3 Intersect class. Simply pass in a Vector of at least three Vector3D objects to the Intersect.of() function (in this example I’m using 4). Each Vector3D object that is past in should contain the x, y, z location of the beacon and the signal “distance” as w/radius. ?View Code ACTIONSCRIPT3var intersection:Vector3D = Intersect.of( new <Vector3D>[ new Vector3D(x, y, z, radius), new Vector3D(x, y, z, radius), new Vector3D(x, y, z, radius), new Vector3D(x, y, z, radius) ]); The above will return the best intersection of four beacons as a Vector3D object. Note: The class currently does not take into account z (height). peteshand / triangulationNo description or homepage.00Download as...

AS3 Instant Replay

Instant Replay is a small as3 service that can be used to record and playback user interactions. Simply register the display object that you wish to record/playback. ?View Code ACTIONSCRIPT3InstantReplay.register(stage); Next, when you’re ready to record interactions set the record property to true. ?View Code ACTIONSCRIPT3InstantReplay.record = true; Finally, call the play function to playback the recorded interactions. ?View Code ACTIONSCRIPT3InstantReplay.play(); You’ll obviously also need to add an event listener to the display object that you’ve registered otherwise you won’t actually see anything happening. ?View Code ACTIONSCRIPT3private var bitmap:Bitmap;   public function Main():void { bitmap = new Bitmap(new BitmapData(50, 50, false, 0xFF0000)); addChild(bitmap);   stage.addEventListener(MouseEvent.MOUSE_MOVE, OnMouseMove); }   private function OnMouseMove(e:Event):void { bitmap.x = e.stageX; bitmap.y = e.stageY; } Example below: peteshand / instant-replayNo description or homepage.10Download as...
XML to Typed Object Paser

XML to Typed Object Paser

The following is an example of how to use the XML2VO.as util to quickly map data from xml into a typed object. ?View Code ACTIONSCRIPT3private var loader:URLLoader; private var exampleVO:ExampleVO;   private function init():void { exampleVO = new ExampleVO(); var url:String = "config.xml"; loader = new URLLoader(); var request:URLRequest = new URLRequest(url); loader.addEventListener(Event.COMPLETE, OnLoadComplete); loader.load(request); } First you’ll need to load or embed your xml object. ?View Code ACTIONSCRIPT3private function OnLoadComplete(e:Event):void { XML2VO.map(XML(loader.data), exampleVO); } Then on load complete simply call XML2VO.map and pass in the xml data along with the object you’d like the data mapped to. example source xml is as follows: ?View Code XML<?xml version="1.0" encoding="utf-8" ?> <data> <arrayExample>1, 3.2, test</arrayExample> <intExample>60</intExample> <numberExample>30.45</numberExample> <stringExample>http://google.com</stringExample> <uintExample>0xded6ce</uintExample> <vectorExample>0xded6ce, 0xd1d6e0, 0xcddce2</vectorExample> <xmlExample> <item id="123"> <img>test.jpg</img> </item> </xmlExample> </data> and ExampleVO is as follows: ?View Code ACTIONSCRIPT3package { public class ExampleVO { public var arrayExample:Array; public var intExample:int; public var numberExample:Number; public var stringExample:String; public var uintExample:uint; public var vectorExample:Vector.<uint>; public var xmlExample:XML; } } ?View Code ACTIONSCRIPT3private function OnLoadComplete(e:Event):void { XML2VO.map(XML(loader.data), exampleVO); MonsterDebugger.initialize(exampleVO); } By using MonsterDebugger to display the content of exampleVO you can see that the xml data has successfully been mapped into our as3 object. Source code can be downloaded from...
Animated Gif Away3D 4.x Material

Animated Gif Away3D 4.x Material

If I’m perfectly honest I really can’t stand animated gifs (as a format), simply because the compression is really poor and the resulting filesize is usually huge. Never the less it’s pretty university accepted on the old interwebs, so I thought it might be handy to have a fast and easy way of applying them to Away3d materials. Dependencies: My fork of “Flash-Animated-GIF-Library” https://github.com/peteshand/Flash-Animated-GIF-Library My fork of “away3d-core-fp11” https://github.com/peteshand/away3d-core-fp11 First step is to load or embed your gif. In my case I’m simply going to embed it. ?View Code ACTIONSCRIPT[Embed(source="image.gif", mimeType = "application/octet-stream")] public static const data:Class; Next create a new GIFPlayer instance and add a GIFPlayerEvent.COMPLETE event listener ?View Code ACTIONSCRIPTgifPlayer = new GIFPlayer(true); gifPlayer.addEventListener(GIFPlayerEvent.COMPLETE, OnDecodeComplete); gifPlayer.loadBytes(new data()); Then all you need to do is create a GifTexture and a GifMaterial and your home free. ?View Code ACTIONSCRIPTvar texture:GifTexture = new GifTexture(gifPlayer); var gifMaterial:GifMaterial = new GifMaterial(texture); Animated Gif applied to a plane ?View Code ACTIONSCRIPTvar geo:PlaneGeometry = new PlaneGeometry(gifPlayer.width, gifPlayer.height, 1, 1, false); var mesh:Mesh = new Mesh(geo, gifMaterial); addChild(mesh); Animated Gif applied to a cube ?View Code ACTIONSCRIPTvar geo:CubeGeometry = new PlaneGeometry(200,200,200,1,1,1,false); var mesh:Mesh = new Mesh(geo, gifMaterial); addChild(mesh); Transparent...
Away3d AGAL Vertex animation (Part 2)

Away3d AGAL Vertex animation (Part 2)

In part 1 of this post (Which can be viewed here) I discussed various approaches to creating a AGAL vertex shader within the away3d framework. I successfully created a custom material and pass that achieved basic vertex animation, however the issue was that I wanted to apply this effect to standard materials. So I investigated using an away3d effect method instead. As outlined in my previous post the issue I was facing with using an effect method is that the custom AGAL was being inserted at the wrong location in respect to the complete material vertex AGAL. So my hack to get around this was to add the following variable to ShadingMethodBase public var preTransfer:Boolean = false; As you can see the default value is false, however if it is set to true the ShaderCompiler will insert the AGAL before the matrix transfer AGAL. Once I had my AGAL being placed in the right location it was just a matter of writing the AGAL to match the material and material params that I was using. The result can be viewed below. (environment map / normals AGAL still needs work) While I’m happy with the result, this is by no means a real solution. As i’m sure my preTransfer hack is far from the best way to insert the AGAL in the correct location, and my custom effect method only works with a material that has an environment and normal map applied to it, as soon as you use a material without these you’ll get a runtime error. Source code can be download...
Showreel 2012

Showreel 2012

This video features projects produced by Peter J Shand during 2012 and were created in collaboration with RESN, Circul8 and Imagination. The projects all use Flash 11 stage3d technology, enabling full 1080p 60fps rendering. A big thank you goes to the many contributors of the Away3d and Starling frameworks. EDF Light Games (RESN – Wellington) The EDF Light Games serves up a series of 7 Olympic sports events brought to life on desktop, touchscreen and as an iPad app. The Games were created with Flash 11’s stage3d technology and utilized the away3d library. Wrapped In Merino (Circul8 – Sydney) Wrapped in Merino connected people with wool globally, asking them to collaboratively design a giant virtual scarf. Again the site was built with Flash 11’s stage3d technology and utilized the away3d library. Users were prompted to upload a photo, take a snap with their webcam or select a photo from facebook. They could then customize their portion of the scarf. The site was integrated with facebook, twitter and pinterest, allowing the users to share their creation & encourage friends to join in. GE Innovation (Imagination – Sydney) 12 touch screen applications, along with 4 additional supporting applications were developed for the GE Saudi Arabia Innovation Center. Adobe air was used to package the applications and the Away3D and Starling frameworks were used extensively throughout the applications to produce full 1080p 60 frames per second...