增强现实 flarttoolkit 旋转

发布于 2024-10-26 16:38:38 字数 3071 浏览 1 评论 0原文

我正在尝试使用 flartoolkit 做一些增强现实项目。我现在可以在标记上放置简单的 3D 对象,并且效果很好,但我想为我的项目提供一些用户可以与之交互的事件。我正在尝试追踪标记的旋转。有一个容器: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(); 
}

I'm trying to do some augmented reality projects with flartoolkit . I can now put simple 3d objects on my marker and it works fine , but I wanna give my project some events that the user can interact with . I'm trying to trace the rotation of the marker. there's a container:DisplayObject3D which my application uses to add the 3d objects , I traced this :"trace(container.rotationZ)" but it's just returning 0 . I studied another AR application's source code and it was using the rotation of it's container object without problem .and I think I should mention that I'm using the exercise file of seb lee delisle papervision3d course from lynda.com . anyone has any experience with flartoolkit? the main functions of my my code is as below:

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(); 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈独秀 2024-11-02 16:38:38

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

这帮助我运行了一个简单的 PV3D 示例:
PV3D 基本交互教程

I might not be able to help with the main problem but If you want users to interact with the models you need to set their materials to be interactive, otherwise they don't receive mouse events. Regarding the rotation...I might be missing something but it's the instances inside the container thar you're applying the rotation to, not the the container itself?

This helped me with getting a simple PV3D example running:
PV3D Tutorial for basic interactivity

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文