チェンジセット 2933

差分発生行の前後
無視リスト:
コミット日時:
2009/07/29 17:26:44 (3 年前)
コミッタ:
saqoosha
ログメッセージ:

Alchemy version of FLARToolKit with some examples.

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/FLARToolKit/branches/alchemy/starter-kit/ARAppBase.as

    r2780 r2933  
    1 package { 
     1package { 
    22         
    33        import flash.display.Bitmap; 
     
    1515         
    1616        import org.libspark.flartoolkit.core.FLARCode; 
    17         import org.libspark.flartoolkit.core.param.FLARParam; 
    18         import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData
     17        import org.libspark.flartoolkit.core.FLARParam; 
     18        import org.libspark.flartoolkit.core.FLARRgbRaster
    1919        import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector; 
    2020         
     
    2626        public class ARAppBase extends Sprite { 
    2727                 
    28                 private var _loader:URLLoader; 
    29                 private var _cameraFile:String; 
    30                 private var _codeFile:String; 
    3128                private var _width:int; 
    3229                private var _height:int; 
     
    3532                protected var _param:FLARParam; 
    3633                protected var _code:FLARCode; 
    37                 protected var _raster:FLARRgbRaster_BitmapData
     34                protected var _raster:FLARRgbRaster
    3835                protected var _detector:FLARSingleMarkerDetector; 
    3936                 
     
    4542                } 
    4643                 
    47                 protected function init(cameraFile:String, codeFile:String, canvasWidth:int = 320, canvasHeight:int = 240, codeWidth:int = 80):void { 
    48                         this._cameraFile = cameraFile; 
    49                         this._width = canvasWidth; 
    50                         this._height = canvasHeight; 
    51                         this._codeFile = codeFile; 
    52                         this._codeWidth = codeWidth; 
    53                          
    54                         this._loader = new URLLoader(); 
    55                         this._loader.dataFormat = URLLoaderDataFormat.BINARY; 
    56                         this._loader.addEventListener(Event.COMPLETE, this._onLoadParam); 
    57                         this._loader.addEventListener(IOErrorEvent.IO_ERROR, this.dispatchEvent); 
    58                         this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.dispatchEvent); 
    59                         this._loader.load(new URLRequest(this._cameraFile)); 
    60                 } 
    61                  
    62                 private function _onLoadParam(e:Event):void { 
    63                         this._loader.removeEventListener(Event.COMPLETE, this._onLoadParam); 
    64                         this._param = new FLARParam(); 
    65                         this._param.loadARParam(this._loader.data); 
    66                         this._param.changeScreenSize(this._width, this._height); 
    67                          
    68                         this._loader.dataFormat = URLLoaderDataFormat.TEXT; 
    69                         this._loader.addEventListener(Event.COMPLETE, this._onLoadCode); 
    70                         this._loader.load(new URLRequest(this._codeFile)); 
     44                protected function init(codeFile:String, canvasWidth:int = 320, canvasHeight:int = 240, codeWidth:int = 80):void { 
     45                        _width = canvasWidth; 
     46                        _height = canvasHeight; 
     47                        _codeWidth = codeWidth; 
     48 
     49                        _param = FLARParam.getDefaultParam(_width, _height); 
     50 
     51                        var loader:URLLoader = new URLLoader(); 
     52                        loader.addEventListener(IOErrorEvent.IO_ERROR, dispatchEvent); 
     53                        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, dispatchEvent); 
     54                        loader.dataFormat = URLLoaderDataFormat.TEXT; 
     55                        loader.addEventListener(Event.COMPLETE, _onLoadCode); 
     56                        loader.load(new URLRequest(codeFile)); 
    7157                } 
    7258                 
    7359                private function _onLoadCode(e:Event):void { 
    74                         this._code = new FLARCode(16, 16); 
    75                         this._code.loadARPatt(this._loader.data); 
    76                          
    77                         this._loader.removeEventListener(Event.COMPLETE, this._onLoadCode); 
    78                         this._loader.removeEventListener(IOErrorEvent.IO_ERROR, this.dispatchEvent); 
    79                         this._loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.dispatchEvent); 
    80                         this._loader = null; 
     60                        _code = new FLARCode(16, 16); 
     61                        _code.loadARPattFromFile(URLLoader(e.target).data); 
    8162 
    8263                        // setup webcam 
    83                         this._webcam = Camera.getCamera(); 
    84                         if (!this._webcam) { 
     64                        _webcam = Camera.getCamera(); 
     65                        if (!_webcam) { 
    8566                                throw new Error('No webcam!!!!'); 
    8667                        } 
    87                         this._webcam.setMode(this._width, this._height, 30); 
    88                         this._video = new Video(this._width, this._height); 
    89                         this._video.attachCamera(this._webcam); 
    90                         this._capture = new Bitmap(new BitmapData(this._width, this._height, false, 0), PixelSnapping.AUTO, true); 
     68                        _webcam.setMode(_width, _height, 30); 
     69                        _video = new Video(_width, _height); 
     70                        _video.attachCamera(_webcam); 
     71                        _capture = new Bitmap(new BitmapData(_width, _height, false, 0), PixelSnapping.AUTO, true); 
    9172                         
    9273                        // setup ARToolkit 
    93                         this._raster = new FLARRgbRaster_BitmapData(this._capture.bitmapData); 
    94                         this._detector = new FLARSingleMarkerDetector(this._param, this._code, this._codeWidth); 
    95                         this._detector.setContinueMode(true); 
    96                          
    97                         this.onInit(); 
    98                 } 
    99                  
    100                 protected function onInit():void { 
     74                        _raster = new FLARRgbRaster(_width, _height); 
     75                        _detector = new FLARSingleMarkerDetector(_param, _code, _codeWidth); 
     76                        //_detector.setContinueMode(true); 
     77 
     78                        dispatchEvent(new Event(Event.INIT)); 
    10179                } 
    10280        } 
  • as3/FLARToolKit/branches/alchemy/starter-kit/Earth.as

    r2786 r2933  
    33        import flash.events.Event; 
    44        import org.papervision3d.objects.parsers.DAE; 
     5 
     6        [SWF(width=640, height=480, backgroundColor=0x808080, frameRate=30)] 
    57         
    68        public class Earth extends PV3DARApp { 
     
    911                 
    1012                public function Earth() { 
    11                         this.init('Data/camera_para.dat', 'Data/flarlogo.pat'); 
     13                        addEventListener(Event.INIT, _onInit); 
     14                        init('Data/flarlogo.pat'); 
    1215                } 
    1316                 
    14                 protected override function onInit():void { 
    15                         super.onInit(); 
     17                private function _onInit(e:Event):void { 
     18                        _earth = new DAE(); 
     19                        _earth.load('model/earth.dae'); 
     20                        _earth.scale = 10; 
     21                        _earth.rotationX = -90; 
     22                        _markerNode.addChild(_earth); 
    1623                         
    17                         this._earth = new DAE(); 
    18                         this._earth.load('model/earth.dae'); 
    19                         this._earth.scale = 10; 
    20                         this._earth.rotationX = -90; 
    21                         this._baseNode.addChild(this._earth); 
    22                          
    23                         this.addEventListener(Event.ENTER_FRAME, this._update); 
     24                        addEventListener(Event.ENTER_FRAME, _update); 
    2425                } 
    2526                 
    2627                private function _update(e:Event):void { 
    27                         this._earth.rotationZ += 0.5 
     28                        _earth.rotationZ += 0.5 
    2829                } 
    2930        } 
  • as3/FLARToolKit/branches/alchemy/starter-kit/PV3DARApp.as

    r2780 r2933  
    44        import flash.events.Event; 
    55         
    6         import org.libspark.flartoolkit.core.transmat.FLARTransMatResult; 
    7         import org.libspark.flartoolkit.pv3d.FLARBaseNode
    8         import org.libspark.flartoolkit.pv3d.FLARCamera3D
     6        import org.libspark.flartoolkit.core.FLARTransMatResult; 
     7        import org.libspark.flartoolkit.support.pv3d.FLARCamera3D
     8        import org.libspark.flartoolkit.support.pv3d.FLARMarkerNode
    99        import org.papervision3d.render.LazyRenderEngine; 
    1010        import org.papervision3d.scenes.Scene3D; 
    1111        import org.papervision3d.view.Viewport3D; 
    12         import org.papervision3d.view.stats.StatsView; 
    1312         
    1413        public class PV3DARApp extends ARAppBase { 
     
    1918                protected var _scene:Scene3D; 
    2019                protected var _renderer:LazyRenderEngine; 
    21                 protected var _baseNode:FLARBaseNode; 
     20                protected var _markerNode:FLARMarkerNode; 
    2221                 
    2322                protected var _resultMat:FLARTransMatResult = new FLARTransMatResult(); 
     
    2625                } 
    2726                 
    28                 protected override function onInit():void { 
    29                         super.onInit(); 
     27                protected override function init(codeFile:String, canvasWidth:int = 320, canvasHeight:int = 240, codeWidth:int = 80):void { 
     28                        addEventListener(Event.INIT, _onInit, false, int.MAX_VALUE); 
     29                        super.init(codeFile, canvasWidth, canvasHeight, codeWidth); 
     30                } 
     31                 
     32                private function _onInit(e:Event):void { 
     33                        _base = addChild(new Sprite()) as Sprite; 
    3034                         
    31                         this._base = this.addChild(new Sprite()) as Sprite; 
     35                        _capture.width = 640; 
     36                        _capture.height = 480; 
     37                        _base.addChild(_capture); 
    3238                         
    33                         this._capture.width = 640; 
    34                         this._capture.height = 480; 
    35                         this._base.addChild(this._capture); 
     39                        _viewport = _base.addChild(new Viewport3D(320, 240)) as Viewport3D; 
     40                        _viewport.scaleX = 640 / 320; 
     41                        _viewport.scaleY = 480 / 240; 
     42                        _viewport.x = -4; // 4pix ??? 
    3643                         
    37                         this._viewport = this._base.addChild(new Viewport3D(320, 240)) as Viewport3D; 
    38                         this._viewport.scaleX = 640 / 320; 
    39                         this._viewport.scaleY = 480 / 240; 
    40                         this._viewport.x = -4; // 4pix ??? 
     44                        _camera3d = new FLARCamera3D(_param); 
    4145                         
    42                         this._camera3d = new FLARCamera3D(this._param); 
     46                        _scene = new Scene3D(); 
     47                        _markerNode = _scene.addChild(new FLARMarkerNode()) as FLARMarkerNode; 
    4348                         
    44                         this._scene = new Scene3D(); 
    45                         this._baseNode = this._scene.addChild(new FLARBaseNode(FLARBaseNode.AXIS_MODE_PV3D)) as FLARBaseNode; 
    46                          
    47                         this._renderer = new LazyRenderEngine(this._scene, this._camera3d, this._viewport); 
    48                          
    49                         this.addEventListener(Event.ENTER_FRAME, this._onEnterFrame); 
     49                        _renderer = new LazyRenderEngine(_scene, _camera3d, _viewport); 
     50 
     51                        addEventListener(Event.ENTER_FRAME, _onEnterFrame); 
    5052                } 
    5153                 
    5254                private function _onEnterFrame(e:Event = null):void { 
    53                         this._capture.bitmapData.draw(this._video); 
    54                          
    55                         var detected:Boolean = false; 
    56                         try { 
    57                                 detected = this._detector.detectMarkerLite(this._raster, 80) && this._detector.getConfidence() > 0.5; 
    58                         } catch (e:Error) {} 
    59                          
    60                         if (detected) { 
    61                                 this._detector.getTransformMatrix(this._resultMat); 
    62                                 this._baseNode.setTransformMatrix(this._resultMat); 
    63                                 this._baseNode.visible = true; 
     55                        _capture.bitmapData.draw(_video); 
     56                        _raster.setBitmapData(_capture.bitmapData); 
     57                        if (_detector.detectMarkerLite(_raster, 80) && _detector.getConfidence() > 0.3) { 
     58                                _detector.getTransformMatrix(_resultMat); 
     59                                _markerNode.setTransformMatrix(_resultMat); 
     60                                _markerNode.visible = true; 
    6461                        } else { 
    65                                 this._baseNode.visible = false; 
     62                                _markerNode.visible = false; 
    6663                        } 
    67                          
    68                         this._renderer.render(); 
     64                        _renderer.render(); 
    6965                } 
    7066                 
    7167                public function set mirror(value:Boolean):void { 
    7268                        if (value) { 
    73                                 this._base.scaleX = -1; 
    74                                 this._base.x = 640; 
     69                                _base.scaleX = -1; 
     70                                _base.x = 640; 
    7571                        } else { 
    76                                 this._base.scaleX = 1; 
    77                                 this._base.x = 0; 
     72                                _base.scaleX = 1; 
     73                                _base.x = 0; 
    7874                        } 
    7975                } 
    8076                 
    8177                public function get mirror():Boolean { 
    82                         return this._base.scaleX < 0; 
     78                        return _base.scaleX < 0; 
    8379                } 
    8480        } 
  • as3/FLARToolKit/branches/alchemy/starter-kit/SimpleCube.as

    r2788 r2933  
    11package { 
     2         
     3        import flash.events.Event; 
     4        import flash.events.MouseEvent; 
    25         
    36        import org.papervision3d.lights.PointLight3D; 
     
    1821                        // Initalize application with the path of camera calibration file and patter definition file. 
    1922                        // カメラ補正ファイルとパターン定義ファイルのファイル名を渡して初期化。 
    20                         this.init('Data/camera_para.dat', 'Data/flarlogo.pat'); 
     23                        addEventListener(Event.INIT, _onInit); 
     24                        init('Data/flarlogo.pat'); 
    2125                } 
    2226                 
    23                 protected override function onInit():void { 
    24                         super.onInit(); // You must call this. / 必ず呼ぶアル。 
    25                          
     27                private function _onInit(e:Event):void { 
    2628                        // Create Plane with same size of the marker. 
    2729                        // マーカーと同じサイズを Plane を作ってみる。 
    2830                        var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2); // with wireframe. / ワイヤーフレームで。 
    29                         this._plane = new Plane(wmat, 80, 80); // 80mm x 80mm。 
    30                         this._baseNode.addChild(this._plane); // attach to _baseNode to follow the marker. / _baseNode に addChild するとマーカーに追従する。 
     31                        _plane = new Plane(wmat, 80, 80); // 80mm x 80mm。 
     32                        _markerNode.addChild(_plane); // attach to _markerNode to follow the marker. / _markerNode に addChild するとマーカーに追従する。 
    3133 
    3234                        // Place the light at upper front. 
     
    4042                        // Cube を作る。 
    4143                        var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x75104e); // Color is ping. / ピンク色。 
    42                         this._cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 40); // 40mm x 40mm x 40mm 
    43                         this._cube.z = -20; // Move the cube to upper (minus Z) direction Half height of the Cube. / 立方体の高さの半分、上方向(-Z方向)に移動させるとちょうどマーカーにのっかる形になる。 
    44                         this._baseNode.addChild(this._cube); 
     44                        _cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 40); // 40mm x 40mm x 40mm 
     45                        _cube.z = -20; // Move the cube to upper (minus Z) direction Half height of the Cube. / 立方体の高さの半分、上方向(-Z方向)に移動させるとちょうどマーカーにのっかる形になる。 
     46                        _markerNode.addChild(_cube); 
     47                         
     48                        stage.addEventListener(MouseEvent.CLICK, _onClick); 
     49                } 
     50                 
     51                private function _onClick(e:MouseEvent):void { 
     52                        mirror = !mirror; 
    4553                } 
    4654        }