7 Replies Latest reply on Sep 1, 2009 6:35 PM by babo_ya

    Won't display image

    ICEAR

      Hi, I've been trying to get this code to show an image for quite some time and just don't understand why it isn't. I run the program and it just shows a black square on my marker. Is there something wrong with it?

       

      package {
         
          import flash.display.BitmapData;
          import flash.display.Sprite;
          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.raster.rgb.FLARRgbRaster_BitmapData;
          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.objects.primitives.Cube;
          import org.papervision3d.render.BasicRenderEngine;
          import org.papervision3d.scenes.Scene3D;
          import org.papervision3d.view.Viewport3D;
          import org.papervision3d.materials.utils.MaterialsList;
          import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
          import org.papervision3d.materials.BitmapMaterial;
          import flash.events.Event;
          import org.papervision3d.materials.BitmapFileMaterial;
          import org.papervision3d.objects.parsers.DAE;
             
          [SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
         
          public class AugReality extends Sprite
          {       
              [Embed(source="ice.pat", mimeType="application/octet-stream")]
              private var marker:Class;
                 
              [Embed(source="camera_para.dat", mimeType="application/octet-stream")]
              private var cam_params:Class;
                     
              private var ar_params:FLARParam;
              private var ar_marker:FLARCode;       
              private var ar_vid:Video;
              private var ar_cam:Camera;       
              private var ar_bmp:BitmapData;
              private var ar_raster:FLARRgbRaster_BitmapData;
              private var ar_detection:FLARSingleMarkerDetector;       
              private var ar_scene:Scene3D;
              private var ar_3dcam:FLARCamera3D;
              private var ar_basenode:FLARBaseNode;
              private var ar_viewport:Viewport3D;
              private var ar_renderengine:BasicRenderEngine;
              private var ar_transmat:FLARTransMatResult;
              private var ar_cube:Cube       
                     
              public function AugReality()
              {
                  createFLAR();
                  createCam();
                  createBMP();
                  createPapervision();
                  addEventListener(Event.ENTER_FRAME, loop);
              }
             
              public function createFLAR()
              {
                  ar_params = new FLARParam();
                  ar_marker = new FLARCode(16, 16);
                  ar_params.loadARParam(new cam_params() as ByteArray);
                  ar_marker.loadARPatt(new marker());
              }
             
              public function createCam()
              {
                  ar_vid = new Video(640, 480);
                  ar_cam = Camera.getCamera();
                  ar_cam.setMode(640, 480, 30);
                  ar_vid.attachCamera(ar_cam);
                  addChild(ar_vid);
              }
             
              public function createBMP()
              {
                  ar_bmp = new BitmapData(640, 480);
                  ar_bmp.draw(ar_vid);
                  ar_raster = new FLARRgbRaster_BitmapData(ar_bmp);
                  ar_detection = new FLARSingleMarkerDetector(ar_params, ar_marker, 80);
              }
             
              public function createPapervision()
              {
                  ar_scene = new Scene3D();
                  ar_3dcam = new FLARCamera3D(ar_params);
                  ar_basenode = new FLARBaseNode();
                  ar_renderengine = new BasicRenderEngine();
                  ar_transmat = new FLARTransMatResult();
                  ar_viewport = new Viewport3D();
                 
                 
                  var ar_light:PointLight3D = new PointLight3D();
                  ar_light.x = 1000;
                  ar_light.y = 1000;
                  ar_light.z = -1000;
                 
                  var ar_bitmap:BitmapFileMaterial;
                  ar_bitmap = new BitmapFileMaterial("hilite.jpg");
                  ar_bitmap.doubleSided = true;
                 
                  ar_cube = new Cube(new MaterialsList({all:ar_bitmap}), 80, 0, 80);
                 
                             
                  ar_scene.addChild(ar_basenode);
                  ar_basenode.addChild(ar_cube);

       

                  addChild(ar_viewport);
              }
             
              private function loop(e:Event):void
              {
                  ar_bmp.draw(ar_vid);
                 
                  try
                  {
                     
                      if(ar_detection.detectMarkerLite(ar_raster, 80) && ar_detection.getConfidence() > 0.5)
                      {
                          ar_detection.getTransformMatrix(ar_transmat);
                          ar_basenode.setTransformMatrix(ar_transmat);
                          ar_renderengine.renderScene(ar_scene, ar_3dcam, ar_viewport);
                      }
                  }
                  catch(e:Error){}
              }
          }
      }

       

      Thanks!

        • 1. Re: Won't display image
          babo_ya Level 3

          public function AugReality()
                  {
                        addEventListener(Event.ADDED_TO_STAGE, onAddToStageHandler);
                  }

           

          private function onAddtoStageHandler(event:Event):void

          {

          createFLAR();
                      createCam();
                      createBMP();
                      createPapervision();
                      addEventListener(Event.ENTER_FRAME, loop);

           

           

          }

           

          try this..

           

          BaBo,

          • 2. Re: Won't display image
            ICEAR Level 1

            Thanks for the quick responce bobo! I added it but get the following error -

            Severity and Description    Path    Resource    Location    Creation Time    Id
            1120: Access of undefined property onAddToStageHandler.    AugReality/src    AugReality.as    line 56    1251840727890    480
            - one that I'm not familiar with at all

             

            Code --------

             

            package {
               
                import flash.display.BitmapData;
                import flash.display.Sprite;
                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.raster.rgb.FLARRgbRaster_BitmapData;
                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.objects.primitives.Cube;
                import org.papervision3d.render.BasicRenderEngine;
                import org.papervision3d.scenes.Scene3D;
                import org.papervision3d.view.Viewport3D;
                import org.papervision3d.materials.utils.MaterialsList;
                import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
                import org.papervision3d.materials.BitmapMaterial;
                import flash.events.Event;
                import org.papervision3d.materials.BitmapFileMaterial;
                import org.papervision3d.objects.parsers.DAE;
                   
                [SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
               
                public class AugReality extends Sprite
                {       
                    [Embed(source="ice.pat", mimeType="application/octet-stream")]
                    private var marker:Class;
                       
                    [Embed(source="camera_para.dat", mimeType="application/octet-stream")]
                    private var cam_params:Class;
                           
                    private var ar_params:FLARParam;
                    private var ar_marker:FLARCode;       
                    private var ar_vid:Video;
                    private var ar_cam:Camera;       
                    private var ar_bmp:BitmapData;
                    private var ar_raster:FLARRgbRaster_BitmapData;
                    private var ar_detection:FLARSingleMarkerDetector;       
                    private var ar_scene:Scene3D;
                    private var ar_3dcam:FLARCamera3D;
                    private var ar_basenode:FLARBaseNode;
                    private var ar_viewport:Viewport3D;
                    private var ar_renderengine:BasicRenderEngine;
                    private var ar_transmat:FLARTransMatResult;
                    private var ar_cube:Cube

                           
                    public function AugReality()
                    {
                        addEventListener(Event.ADDED_TO_STAGE, onAddToStageHandler);
                    }
                    private function onAddtoStageHandler(event:Event):void

             

                    {
                        createFLAR();
                        createCam();
                        createBMP();
                        createPapervision();
                        addEventListener(Event.ENTER_FRAME, loop);
                    }

             

            ...

             

            --------
                   

            • 3. Re: Won't display image
              babo_ya Level 3

              onAddtoStageHandler ... should be onAddToStageHandler

               

              babo,

              1 person found this helpful
              • 4. Re: Won't display image
                ICEAR Level 1

                Thanks again for the response bobo. This did get rid of the error but I'm still just getting a black square and not the image.

                 

                Code again if it helps ----

                 

                package {
                   
                    import flash.display.BitmapData;
                    import flash.display.Sprite;
                    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.raster.rgb.FLARRgbRaster_BitmapData;
                    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.objects.primitives.Cube;
                    import org.papervision3d.render.BasicRenderEngine;
                    import org.papervision3d.scenes.Scene3D;
                    import org.papervision3d.view.Viewport3D;
                    import org.papervision3d.materials.utils.MaterialsList;
                    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
                    import org.papervision3d.materials.BitmapMaterial;
                    import flash.events.Event;
                    import org.papervision3d.materials.BitmapFileMaterial;
                    import org.papervision3d.objects.parsers.DAE;
                       
                    [SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
                   
                    public class AugReality extends Sprite
                    {       
                        [Embed(source="ice.pat", mimeType="application/octet-stream")]
                        private var marker:Class;
                           
                        [Embed(source="camera_para.dat", mimeType="application/octet-stream")]
                        private var cam_params:Class;
                               
                        private var ar_params:FLARParam;
                        private var ar_marker:FLARCode;       
                        private var ar_vid:Video;
                        private var ar_cam:Camera;       
                        private var ar_bmp:BitmapData;
                        private var ar_raster:FLARRgbRaster_BitmapData;
                        private var ar_detection:FLARSingleMarkerDetector;       
                        private var ar_scene:Scene3D;
                        private var ar_3dcam:FLARCamera3D;
                        private var ar_basenode:FLARBaseNode;
                        private var ar_viewport:Viewport3D;
                        private var ar_renderengine:BasicRenderEngine;
                        private var ar_transmat:FLARTransMatResult;
                        private var ar_cube:Cube       
                //        private var ar_dae:DAE;//Uncomment for dae
                               
                        public function AugReality()
                        {
                            addEventListener(Event.ADDED_TO_STAGE, onAddToStageHandler);
                        }
                        private function onAddtoStageHandler(event:Event):void

                 

                        {
                            createFLAR();
                            createCam();
                            createBMP();
                            createPapervision();
                            addEventListener(Event.ENTER_FRAME, loop);
                        }
                       
                        public function createFLAR()
                        {
                            ar_params = new FLARParam();
                            ar_marker = new FLARCode(16, 16);
                            ar_params.loadARParam(new cam_params() as ByteArray);
                            ar_marker.loadARPatt(new marker());
                        }
                       
                        public function createCam()
                        {
                            ar_vid = new Video(640, 480);
                            ar_cam = Camera.getCamera();
                            ar_cam.setMode(640, 480, 30);
                            ar_vid.attachCamera(ar_cam);
                            addChild(ar_vid);
                        }
                       
                        public function createBMP()
                        {
                            ar_bmp = new BitmapData(640, 480);
                            ar_bmp.draw(ar_vid);
                            ar_raster = new FLARRgbRaster_BitmapData(ar_bmp);
                            ar_detection = new FLARSingleMarkerDetector(ar_params, ar_marker, 80);
                        }
                       
                        public function createPapervision()
                        {
                            ar_scene = new Scene3D();
                            ar_3dcam = new FLARCamera3D(ar_params);
                            ar_basenode = new FLARBaseNode();
                            ar_renderengine = new BasicRenderEngine();
                            ar_transmat = new FLARTransMatResult();
                            ar_viewport = new Viewport3D();
                           
                           
                            var ar_light:PointLight3D = new PointLight3D();
                            ar_light.x = 1000;
                            ar_light.y = 1000;
                            ar_light.z = -1000;
                           
                           
                            //Remove for dae
                            var ar_bitmap:BitmapFileMaterial;
                            ar_bitmap = new BitmapFileMaterial("hilite.jpg");
                            ar_bitmap.doubleSided = true;
                           
                            //Remove for dae
                            ar_cube = new Cube(new MaterialsList({all:ar_bitmap}), 250, 0, 250);
                           
                            //Uncomment for dae
                //            var ar_materials:MaterialsList = new MaterialsList({all: new FlatShadeMaterial(ar_light)});
                //            ar_dae = new DAE();
                //            ar_dae.load("lrg_acorn.dae", ar_materials);
                //            ar_dae.scaleX = 5;
                //            ar_dae.scaleY = 5;
                                       
                            ar_scene.addChild(ar_basenode);
                            ar_basenode.addChild(ar_cube);//Remove for dae
                //            ar_basenode.addChild(ar_dae);//Uncomment for dae
                            addChild(ar_viewport);
                        }
                       
                        private function loop(e:Event):void
                        {
                            ar_bmp.draw(ar_vid);
                //            ar_cube.rotationX +=4;
                //            ar_cube.rotationY +=6;
                //            ar_dae.rotationZ +=4; //Uncomment for dea rotation
                           
                            try
                            {
                               
                                if(ar_detection.detectMarkerLite(ar_raster, 80) && ar_detection.getConfidence() > 0.5)
                                {
                                    ar_detection.getTransformMatrix(ar_transmat);
                                    ar_basenode.setTransformMatrix(ar_transmat);
                                    ar_renderengine.renderScene(ar_scene, ar_3dcam, ar_viewport);
                                }
                            }
                            catch(e:Error){}
                        }
                    }
                }

                 

                ----

                 

                Thanks for helping me get through this bobo, I really appreciate it

                • 5. Re: Won't display image
                  babo_ya Level 3

                  I could create some that loads an image and display, is that what u r trying to do?

                  Because those papervision3d and all those doesn't make sense...

                  BaBo,

                  • 6. Re: Won't display image
                    ICEAR Level 1

                    Yeah I'm just trying to make it so that when the program recognizes the marker it displays the image that I tell it too : /

                    • 7. Re: Won't display image
                      babo_ya Level 3

                      package {

                      import flash.display.Loader;

                      import flash.display.Sprite;

                      import flash.events.*;

                      import flash.net.URLRequest;

                      import flash.system.ApplicationDomain;

                       

                      public class ZZACImageLoader extends Sprite

                      {

                      private var loader:Loader;

                      private var app:ApplicationDomain;

                       

                      public function ZZACImageLoader()

                      {

                       

                      addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

                       

                      }

                      private function onAddedToStage(event:Event):void

                      {

                      loader = new Loader();

                      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);

                      loader.load(new URLRequest("dell.png"));

                      }

                      private function onLoaderComplete(event:Event):void

                      {

                      addChild(loader);

                      }

                      }

                      }

                      Try this ..
                      Hope this helps,
                      BaBo,