Michael Jackson Pearl Jam Stevie Ray Vaughan Ozzy Osbourne Finntroll MP3 list A Fine Frenzy Capone Phil Collins Shakira Pink Floyd Keane

Monthly Archive for February, 2009

Source: Using Augmented Reality FLARToolkit and Papervision to create a unique 3D experience

woven-interactive-flark-test

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):

Actionscript:
  1. package net.saqoosha.flartoolkit.example {
  2.    
  3.     import org.papervision3d.materials.BitmapFileMaterial;
  4.     import org.papervision3d.objects.DisplayObject3D;
  5.     import flash.events.Event;
  6.     import flash.events.MouseEvent;
  7.     import org.papervision3d.core.proto.DisplayObjectContainer3D;
  8.     import org.papervision3d.objects.primitives.Sphere;
  9.    
  10.     import org.papervision3d.lights.PointLight3D;
  11.     import org.papervision3d.materials.WireframeMaterial;
  12.     import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
  13.     import org.papervision3d.materials.utils.MaterialsList;
  14.     import org.papervision3d.objects.primitives.Cube;
  15.     import org.papervision3d.objects.primitives.Plane;
  16.    
  17.  
  18.     [SWF(width=700,height=400,frameRate=30,backgroundColor=0x0)]
  19.  
  20.     public class SimpleCube extends PV3DARApp {
  21.        
  22.         private static const PATTERN_FILE:String = "resources/marker16.pat";
  23.         private static const CAMERA_FILE:String = "resources/camera_para.dat";
  24.        
  25.         protected var plane:Plane;
  26.         protected var objectsContainer:DisplayObject3D;
  27.         protected var cube:Cube;
  28.         protected var sphere:Sphere
  29.         protected var wovenCube:Cube;
  30.         protected var imageMat:BitmapFileMaterial;
  31.         protected var fmat:FlatShadeMaterial;
  32.         protected var wmat:WireframeMaterial;
  33.        
  34.         public function SimpleCube()
  35.         {
  36.             addEventListener(Event.INIT, onInit);
  37.             init(CAMERA_FILE, PATTERN_FILE);
  38.         }
  39.        
  40.         private function onInit(e:Event):void
  41.         {
  42.             removeEventListener(Event.INIT, onInit);
  43.            
  44.             //Create light source for shade material
  45.             var light:PointLight3D = new PointLight3D();
  46.             light.x = 1000;
  47.             light.y = 1000;
  48.             light.z = -1000;
  49.            
  50.             //Create Materials
  51.             imageMat = new BitmapFileMaterial("resources/woven-logo.jpg", false);
  52.             fmat = new FlatShadeMaterial(light, 0xFFFFFF, 0x0);
  53.             wmat = new WireframeMaterial(0xff0000);
  54.             wmat.doubleSided = true;
  55.            
  56.             //Create objects
  57.             objectsContainer = new DisplayObject3D();
  58.             plane = new Plane(wmat, 100, 100,1,1);
  59.             wovenCube = new Cube(new MaterialsList( { all: imageMat } ), 150, 150, 150);
  60.             cube = new Cube(new MaterialsList( { all: fmat } ), 20, 200, 20);
  61.             sphere = new Sphere(fmat, 20);
  62.            
  63.            
  64.             //Position elements
  65.             sphere.y = 200;
  66.             wovenCube.z += 100;
  67.             objectsContainer.z += 100;
  68.            
  69.             //Add objects to my container
  70.             objectsContainer.addChild(sphere)
  71.             objectsContainer.addChild(wovenCube)
  72.             objectsContainer.addChild(cube)
  73.            
  74.             //Add to base
  75.             _baseNode.addChild(plane);
  76.             _baseNode.addChild(objectsContainer);
  77.  
  78.         }
  79.        
  80.         override protected function _onEnterFrame(e:Event = null):void
  81.         {
  82.             super._onEnterFrame(e);
  83.             sphere.rotationY += 10;
  84.             wovenCube.rotationZ += 10;
  85.         }
  86.        
  87.     }
  88.    
  89. }

As you can see from this line:

Actionscript:
  1. 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.

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post

Nascar Race Car in Papervision 3D

nascar-3d

Here is an example of using a 3ds model in Flash / Papervision with zoom / rotational controls. For the reflection a second viewport was created with the model inside of it and filters applied:

Actionscript:
  1. <br />
  2. viewPort2.filters = [new BlurFilter()];<br />

View Papervision Nascar

Source code will follow in the next few weeks when I am able to clean up the extra garbage.

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post


Follow WovenCharlie on Twitter

Flash and the City banner
2010 Flash And The City Speaker

RSS Feed