DOWNLOAD AND PRINT THIS FIRST!
Example requires a webcam.
When we first saw the GE Smart Grid website all we could think was WOW. Great 3D and messaging. Seeing the Augmented Reality section that mixed the FLARToolkit and Papervision really created something unique.
We found a few examples of people playing with it online but no real amounts of source code. Also did not know the HIRO file format was. It turns out you don't need a *.hiro file, you can swap it out with a *.pat file. There is even an online ARToolKit Maker Generator that is quick and easy to use.
Onto the source code:
This is a modified example taken from the provided example source code (The hello world of the FLARToolKit):
-
package net.saqoosha.flartoolkit.example {
-
-
import org.papervision3d.materials.BitmapFileMaterial;
-
import org.papervision3d.objects.DisplayObject3D;
-
import flash.events.Event;
-
import flash.events.MouseEvent;
-
import org.papervision3d.core.proto.DisplayObjectContainer3D;
-
import org.papervision3d.objects.primitives.Sphere;
-
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.materials.WireframeMaterial;
-
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.primitives.Cube;
-
import org.papervision3d.objects.primitives.Plane;
-
-
-
[SWF(width=700,height=400,frameRate=30,backgroundColor=0x0)]
-
-
public class SimpleCube extends PV3DARApp {
-
-
private static const PATTERN_FILE:String = "resources/marker16.pat";
-
private static const CAMERA_FILE:String = "resources/camera_para.dat";
-
-
protected var plane:Plane;
-
protected var objectsContainer:DisplayObject3D;
-
protected var cube:Cube;
-
protected var sphere:Sphere
-
protected var wovenCube:Cube;
-
protected var imageMat:BitmapFileMaterial;
-
protected var fmat:FlatShadeMaterial;
-
protected var wmat:WireframeMaterial;
-
-
public function SimpleCube()
-
{
-
addEventListener(Event.INIT, onInit);
-
init(CAMERA_FILE, PATTERN_FILE);
-
}
-
-
private function onInit(e:Event):void
-
{
-
removeEventListener(Event.INIT, onInit);
-
-
//Create light source for shade material
-
var light:PointLight3D = new PointLight3D();
-
light.x = 1000;
-
light.y = 1000;
-
light.z = -1000;
-
-
//Create Materials
-
imageMat = new BitmapFileMaterial("resources/woven-logo.jpg", false);
-
fmat = new FlatShadeMaterial(light, 0xFFFFFF, 0x0);
-
wmat = new WireframeMaterial(0xff0000);
-
wmat.doubleSided = true;
-
-
//Create objects
-
objectsContainer = new DisplayObject3D();
-
plane = new Plane(wmat, 100, 100,1,1);
-
wovenCube = new Cube(new MaterialsList( { all: imageMat } ), 150, 150, 150);
-
cube = new Cube(new MaterialsList( { all: fmat } ), 20, 200, 20);
-
sphere = new Sphere(fmat, 20);
-
-
-
//Position elements
-
sphere.y = 200;
-
wovenCube.z += 100;
-
objectsContainer.z += 100;
-
-
//Add objects to my container
-
objectsContainer.addChild(sphere)
-
objectsContainer.addChild(wovenCube)
-
objectsContainer.addChild(cube)
-
-
//Add to base
-
_baseNode.addChild(plane);
-
_baseNode.addChild(objectsContainer);
-
-
}
-
-
override protected function _onEnterFrame(e:Event = null):void
-
{
-
super._onEnterFrame(e);
-
sphere.rotationY += 10;
-
wovenCube.rotationZ += 10;
-
}
-
-
}
-
-
}
As you can see from this line:
-
private static const PATTERN_FILE:String = "resources/marker16.pat";
We replaced the *.hiro file with a *.pat file.
To get this example to work you will have to DOWNLOAD AND PRINT THIS FIRST!
Download the full source
and / or
View the interactive example.
Learn more about the FLARToolKit
If you or your clients need any help getting started feel free to contact our Interactive Agency.


