YouTube から拡張現実アプリ tut をやっています。私はこの FLARTool キット全体と papervision スタッフの初心者です。ヘルパーへの永遠の感謝。私はこのスクリプトを持っています:
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){}
}
}
}
テストを実行すると、次のログが表示されます。
TypeError: エラー #2007: パラメータの子は非 null でなければなりません。flash.display::DisplayObjectContainer/addChild() で test/createPapervision()[C:\Users\Omer Hacohen\Adobe Flash Builder 4.7\test\src\test.as:103] で test()[C:\Users \Omer Hacohen\Adobe Flash Builder 4.7\test\src\test.as:58]
どういう意味ですか?アプリケーションがカメラを開くことを伝える必要はありませんが、マーカー上にあるはずの立方体は表示されません