So Away3D has been around for some time now (they’re currently in v4.0.0 beta) and I have not tasted this new hardware-accelerated library for Flash. In my previous years I worked with Papervision3D in AS2 (yes, version 2) and quickly moved to Papervision3D 2 for AS3. Papervision3D was pretty easy to use (I have a small Maya background) and actually got a chance to teach it to my students a few times as an intro to high-level 3D in my Intermediate ActionScript class. The problem was performance: I couldn’t get everything I wanted out of p3d like advanced UV mapping and high poly scenes; I should give it credit though, it did pioneer 3D for flash (AFAIK) and eventually implemented shader support and did a great job at it (e.g. phongs). It eventually fell off of my radar due to random professional reasons (like working around the clock on projects that $$) and other techy stuff.
Overview
I was looking for something with direct hardware acceleration and a few other clever native techniques. A colleague of mine told me about this thing called Stage3D, a.k.a “Molehill,” which i totally forgot about. This part of Flash renders separately from the DisplayList but just on top of the StageVideo, and utilizes the GPU (holy shit!). I was leery at first since my experience with Flash in previous had been 2.5D (two-n-a-half-D) and I wasn’t impressed especially coming from a P3D background. Apparently in my absence it had come a long way (at the time of this writing the current version is 11.2 beta). So I gave it a whirl.
I have a Gentoo mindset (even though my weapon of choice is RHEL), so I naturally downloaded the v4 beta, which I came to find had severely limited documentation (found some generated docs here, although not perfect). Found the v4 documentation, I guess someone flipped a switch at a datacenter somewhere… Not good for entry-level development into this new lib! Not to mention, the examples were AMAZING… amazingly overdone – I just wanna see how the stupid thing works; that’s great that you can generate trees and import 3DS models, congratu-fuckin-lations, but what about us n00bs, i need some practical and minimalist examples.
TL;DR: Right to the Code
After an hour of toying with it, skimming through some haphazard docs, watching for code hints and perusing around the source code I wrote this little ditty…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
package { import away3d.cameras.*; import away3d.containers.*; import away3d.controllers.*; import away3d.entities.*; import away3d.materials.*; import away3d.primitives.*; import flash.display.*; import flash.events.*; /** * ... * @author Andrew Zammit */ public class Main extends Sprite { private var scene:Scene3D; private var camera:Camera3D; private var view:View3D; private var controller:HoverController; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; this.scene = new Scene3D(); this.camera = new Camera3D(); this.view = new View3D(this.scene, this.camera); this.controller = new HoverController(this.camera); this.camera.lens.far = 2100; this.view.width = stage.width; this.view.height = stage.height; var plane:Mesh = new Mesh(new PlaneGeometry(1000, 1000), new ColorMaterial(0x0000cc, 1)); this.scene.addChild(plane); this.addChild(this.view); this.addEventListener(Event.ENTER_FRAME, this.loop); } private function loop(event:Event):void { this.controller.panAngle = stage.mouseX; this.controller.tiltAngle = stage.mouseY*0.03; this.view.render(); } } } |
Hope that helps. Think of it as a kickstarter.
Development Setup
So, I completely forgot the installation steps for using Away3D. BTW, I use FlashDevelop (currently have the latest version 4.0.1RTM) and am building against Flex SDK v4.6.0, AIR 3.1 (which I think was auto-downloaded by FlashDevelop) for flash player 11.
- For portability (but not flexibility or debugging) download the away3d core 4.0b SWC.
- Create a new project in FlashDevelop
- Put the SWC in the ./lib folder (or wherever… just do the lib folder)
- In FlashDevelop right click on “away3d-core-fp11_4_0_0_beta.swc” and choose “Add to Library” – it should turn blue
- That’s it, you’re ready to go.
I can see myself getting deeper and deeper into this sexy beast of a lib. And the fact that my CPU utilization is a big fat ZERO and i’m getting uber sweet FPS, i’m hooked. About friggin’ time Flash, about time!
Working SWF

Download the ZIP containing the demo (no source code): away3d-simple-demo
Resources