0

從YouTube做增強現實應用程序tut。我是整個FLARTool套件和papervision員工的新手。對幫手的永恆感激。 我有這個腳本:AS3:參數子項必須爲非空

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.raster.rgb.FLARRgbRaster_BitmapData; 
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult; 
import org.libspark.flartoolkit.detector.FLARSingleMarkerDetector; 
import org.libspark.flartoolkit.support.pv3d.FLARBaseNode; 
import org.libspark.flartoolkit.support.pv3d.FLARCamera3D; 
import org.papervision3d.lights.PointLight3D; 
import org.papervision3d.materials.BitmapFileMaterial; 
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 test extends Sprite 
{ 
    [Embed(source="marker15.pat", mimeType="application/octet-stream")] 
    private var marker:Class; 

    [Embed(source="camera_para.dat", mimeType="application/octet-stream")] 
    private var cam_params:Class; 

    //createFLAR variables 
    private var ar_params:FLARParam; 
    private var ar_marker:FLARCode; 
    //createCam variables 
    private var ar_vid:Video 
    private var ar_cam:Camera 
    //createBMP vairiables 
    private var ar_bmp:BitmapData; 
    private var ar_raster:FLARRgbRaster_BitmapData; 
    private var ar_detection:FLARSingleMarkerDetector; 
    //createPapervision variables 
    private var ar_scene:Scene3D; 
    private var ar_3dcam:org.libspark.flartoolkit.support.pv3d.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 test() 
    { 
     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 org.libspark.flartoolkit.support.pv3d.FLARCamera3D(ar_params); 
     ar_basenode= new FLARBaseNode(); 
     ar_renderengine= new BasicRenderEngine(); 
     ar_transmat= new FLARTransMatResult(); 

     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 ("LBP2.jpg"); 
     ar_bitmap.doubleSided=true; 

     ar_cube=new Cube(new MaterialsList({all:ar_bitmap}), 80, 80, 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); 
     ar_cube.rotationX +=4; 
     ar_cube.rotationY +=6; 

     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.renderLayers(ar_scene, ar_3dcam, ar_viewport); 
      } 
     } 

     catch (e:Error){} 
    } 

} 

} 

當我跑步時的測試我得到這個日誌:

類型錯誤:錯誤#2007:參數孩子必須爲非空。 ()[C:\ Users \ Omer Hacohen \ Adob​​e Flash Builder 4.7 \ test \ src \ test.as:103] at test.display :: DisplayObjectContainer/addChild() at test/createPapervision :\ Users \ Omer Hacohen \ Adob​​e Flash Builder 4.7 \ test \ src \ test.as:58]

這是什麼意思?沒有必要告訴應用程序是否打開應該坐在標記不會出現

+0

將有助於指出的代碼行的錯誤點(這樣我們沒有弄明白) – BadFeelingAboutThis

回答

0

您recieving因爲createPapervision方法下面一行的錯誤的相機,但立方體:

addChild(ar_viewport); 

從你的發佈代碼,你永遠不會初始化該變量(ar_viewport),所以當你嘗試添加它時它是空的。

試試這個:

ar_viewport = new Viewport3D(stage.stageWidth,stage.stageHeight); 
addChild(ar_viewport); 
相關問題