0 Replies Latest reply on Jun 23, 2010 1:04 PM by streamedie

    Flex and Augmented Reality, Preview not working

    streamedie

      Hi

       

      I have been following the tutorial  Introduction to Augmented Reality on gotoandlearn(http://www.gotoandlearn.com/play.php?id=105).

      I have followed the coding exactly  and yet nothing happens when I go to preview it.  I have even copied the  code in the provided code (ar.zip) into my project and have had no result.  When I go  to run the application inside Flex, the Flash Player opens with the  default Flex coluring but nothing occurs inside, Eg the camera is not  called up etc.

       

      I am using FlexBuilder 3 with Flex 3.5.  With  Flash Player 9.

       

      Here is the code (basically pulled straight  from the downloadables)

       

      package {
         import flash.display.BitmapData;
         import  flash.display.Sprite;
         import flash.events.Event;
         import  flash.media.Camera;
         import flash.media.Video;
         import  flash.utils.ByteArray;
        
         import  org.libspark.flartoolkit.core.FLARCode;
         import  org.libspark.flartoolkit.core.param.FLARParam;
         import  org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
         import  org.libspark.flartoolkit.detector.FLARSingleMarkerDetector;
         import  org.libspark.flartoolkit.pv3d.FLARBaseNode;
         import  org.libspark.flartoolkit.pv3d.FLARCamera3D;
         import  org.papervision3d.lights.PointLight3D;
         import  org.papervision3d.materials.utils.MaterialsList;
         import  org.papervision3d.objects.primitives.Cube;
         import  org.papervision3d.render.BasicRenderEngine;
         import  org.papervision3d.scenes.Scene3D;
         import  org.papervision3d.view.Viewport3D;
        
         [SWF(width="640".  height="480". frameRate="30". backgroundColor="#FFFFFF")]

          public class ARTester extends Sprite
         {
             [Embed(source="map.pat". mimeType="application/octet-stream")]
             private var pattern:Class;
           
             [Embed(source="camera_para.dat". mimeType="application/octet-stream")]
             private var params:Class;
           
            private var  fparams:FLARParam;
            private var mpattern:FLARCode;
             private var vid:Video;
            private var cam:Camera;
             private var bmd:BitmapData;
            private var raster:  FLARRgbRaster_BitmapData;
            private var  detector:FLARSingleMarkerDetector;
            private var scene:Scene3D;
             private var camera:FLARCamera3D;
            private var  container:FLARBaseNode;
            private var vp:Viewport3D;
             private var bre:BasicRenderEngine;
            private var  trans:FLARTransMatResult;
           
           
            public function  ARTester()
            {
               setupFLAR();
                setupCamera();
               setupBitmap();
               setupPV3D();
                addEventListener(Event,ENTER_NAME, loop);
            }
              
                private function setupFLAR():void
               {
                   fparams = new FLARParam();
                  fparams.loadARParam(new  params() as ByteArray);
                  mpattern = new FLARCode(16, 16);
                   mpattern.loadARPatt(new pattern());
         }
         private  function setupCamera():void
         {
            vid = new Video(640, 480);
             cam = Camera.getCamera();
            cam.setMode(640, 480, 30);
             vid.attachCamera(cam);
            addChild(vid);
             }
            
              private function setupBitmap():void
             {
                bmd =  new BitmapData(640, 480);
                bmd.draw(vid);
                 raster = new FLARRgbRaster_BitmapData(bmd);
                detector = new  FLARSingleMarkerDetector(fparams, mpattern, 80);
             }
              private function setupPV3D():void
             {
                scene = new  Scene3D();
                camera = new FLARCamera3D(fparams);
                 container = new FLARBaseNode();
                scene.addChild(container);
                
                var pl:PointLight3D = new PointLight3D();
                 pl.x = 1000;
                pl.y = 1000;
                pl.z = -1000;
                
                var ml:MaterialsList = new MaterialList({all:  FlatShadeMaterial(pl)});
               
                var cube1:Cube = new  Cube(ml, 30, 30, 30);
                var cube2:Cube = new Cube(ml, 30,  30, 30);
                cube2.z = 50
                var cube3:Cube = new  Cube(ml, 30, 30, 30);
                cube3.z = 100;
               
                 container.addChild(cube1);
                container.addChild(cube2);
                 container.addChild(cube3);
               
                bre = new  BasicRenderEngine();
                trans = new FLARTransMatResult();
                
                vp = new Viewport3D();
                 addChild(vp);  
             }
            
             private function  loop(e:Event):void
             {   
               
                    bmd.draw(vid);
                   try
                   {
                       if(detector.detectMarkerLite(raster. 80) &&  detector.getConfidence() > 0.5)
                      {
                       detector.getTransformMatrix(trans);
                       container.setTransformMatrix(trans);
                       bre.renderScene(scene, camera, vp);
                   }
             }
              catch(e:Error){}
         }
         }
      }

       


      Any help would be much appreiciated.

       

      Thanks
      Daniel.

       

      Also; sorry I wasn't sure how to neatly display my code in the post