1

FLARToolKit について別の (初心者) 質問があります。これは、マーカーの上に 3 つのボックスを作成する Lee Brimelow のコードです。

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.shadematerials.FlatShadeMaterial;
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 FLARdemo extends Sprite
{
    [Embed(source="pat1.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 FLARdemo()
    {
        setupFLAR();
        setupCamera();
        setupBitmap();
        setupPV3D();
        addEventListener(Event.ENTER_FRAME, 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 MaterialsList({all: new 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){}
    }
}

このコードの欠陥は、マーカーが検出された後、はい、3D オブジェクトがレンダリングされたことです。しかし、マーカーが検出されなかった後、オブジェクトはまだ画面に表示されていました (動かなかったにもかかわらず)、どうすればこれを修正できますか?

4

1 に答える 1

0

検出条件で FLARBaseNode の visible プロパティを変更する必要があります

 if(detector.detectMarkerLite(raster, 80) && detector.getConfidence() > 0.5){
                    detector.getTransformMatrix(trans);
                    container.setTransformMatrix(trans);
            container.visible = true;
                    bre.renderScene(scene, camera, vp);
                }else
                container.visible = false;
于 2011-09-21T20:58:42.347 に答える