0

我正在尝试使用 lartoolkit 做一些增强现实项目。我现在可以将简单的 3d 对象放在我的标记上,它工作正常,但我想给我的项目一些用户可以与之交互的事件。我正在尝试追踪标记的旋转。有一个 container:DisplayObject3D 我的应用程序使用它来添加 3d 对象,我跟踪了这​​个 :"trace(container.rotationZ)" 但它只是返回 0 。我研究了另一个 AR 应用程序的源代码,它毫无问题地使用了它的容器对象的旋转。我想我应该提到我正在使用 lynda.com 的 seb lee delisle papervision3d 课程的练习文件。任何人都有使用 flartoolkit 的经验吗?我的代码的主要功能如下:

public function AR_AlchemyBase()
{
    super(640,480, false); 
    cameraParams = FLARParam.getDefaultParam(WIDTH * 0.5, HEIGHT * 0.5);

    marker = new FLARCode(16, 16);
    marker.loadARPattFromFile(new MarkerPattern());

    init();
}

public function init():void
{           
    video = new Video(WIDTH, HEIGHT);
    webCam = Camera.getCamera();
    webCam.setMode(WIDTH, HEIGHT, 30);
    video.attachCamera(webCam);
    video.smoothing = true; 

    camBitmapData = new BitmapData(WIDTH *0.5, HEIGHT * 0.5,false, 0x000000);

    camBitmap = new Bitmap(camBitmapData); 
    camBitmap.scaleX = camBitmap.scaleY = 2; 
    addChildAt(camBitmap,0); 

    raster = new FLARRgbRaster(WIDTH *0.5, HEIGHT * 0.5);
    detector = new FLARSingleMarkerDetector(cameraParams, marker, 80);
    result = new FLARTransMatResult();

    viewport.x = -4;

    _camera = new FLARCamera3D(cameraParams);
    container = new FLARMarkerNode();
    scene.addChild(container);

    addSceneObjects(); 

    stage.addEventListener(Event.ENTER_FRAME, enterFrame);
}

//the function to put our objects in 
public function addSceneObjects() : void
{

    var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2);
    wmat.doubleSided = true;

    var plane : Plane = new Plane(wmat, 80, 80);
    container.addChild(plane);

    var light:PointLight3D = new PointLight3D();
    light.x = 1000;
    light.y = 1000;
    light.z = -1000;

    var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, 0xff22aa, 0x0);
    var cube : Cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 40);
    cube.z = -20;
    container.addChild(cube);           
}

public function enterFrame(e:Event):void
{
    var scaleMatrix:Matrix = new Matrix();
    scaleMatrix.scale(0.5, 0.5);
    camBitmapData.draw(video, scaleMatrix);

    raster.setBitmapData(camBitmapData);

    counter++; 

    if(counter == 3) counter = 0; 

    var imageFound : Boolean = false

    currentThreshold = threshold+ (((counter%3)-1)*thresholdVariance);
    currentThreshold = (currentThreshold>255) ? 255 : (currentThreshold<0) ? 0 : currentThreshold; 

    imageFound = (detector.detectMarkerLite(raster, currentThreshold) && detector.getConfidence() > 0.5) ;

    if(imageFound)
    { 
        detector.getTransformMatrix(result);
        container.setTransformMatrix(result);
        container.visible = true;

        threshold = currentThreshold;
        thresholdVariance = 0; 

        if(onImageFound!=null) onImageFound();
    } 
    else 
    {
        if(counter==2) thresholdVariance +=2; 

        if(thresholdVariance>128 ) thresholdVariance = 1; 

        if(onImageLost!=null) onImageLost(); 

    }   

    singleRender(); 
}
4

1 回答 1

1

我可能无法解决主要问题,但如果您希望用户与模型进行交互,您需要将他们的材料设置为交互式,否则他们不会收到鼠标事件。关于旋转......我可能会遗漏一些东西,但它是容器内的实例,你正在应用旋转,而不是容器本身?

这帮助我运行了一个简单的 PV3D 示例: PV3D Tutorial for basic interactivity

于 2011-03-25T13:23:47.987 回答