没有平面的ARCore对象跟踪

我是这个ARCore的新手,我一直在关注SDK中提供的HelloAR Java Android Studio项目 .

Everthing工作正常并且非常酷,但是,即使没有检测到飞机,我也想在触摸屏幕时放置/放下物体 . 让我解释一下......

据我所知,它将检测水平平面,并且只在那些水平平面上,我可以放置3D物体进行运动跟踪 .

有没有办法(可能使用PointCloud信息)能够在场景中放置一个对象,即使没有检测到水平面?有点像这些例子吗? https://experiments.withgoogle.com/ar/flight-paths https://experiments.withgoogle.com/ar/arcore-drawing

我知道他们正在使用Unity和openFrameworks,但这可以用Java完成吗?

另外,我看了How to put an object in the air?how to check ray intersection with object in ARCore

但我不认为我理解Ancor的概念(我设法将对象放在场景中,但它要么立即消失,要么只是一个普通的OpenGL对象,不了解现实世界 .

我想要了解的是: - 如何以及是否可以创建自定义/用户定义的平面,即ARCore不会自动检测到的平面? - 我怎样才能创建一个Ancor(我想这个样本在PlaneAttachment类中完成),它没有链接到任何连接到某个PointCloud点的平面OR? - 如何绘制对象并将其放置在先前创建的Ancor中?

我认为这个问题太多了,但是查看API文档根本没有帮助我

谢谢!

Edit

这是我添加到HelloArActivity.java的代码(除了// *****之后和之前的行之外,Everything与原始文件相同...

@Override
public void onDrawFrame(GL10 gl) {
...
        MotionEvent tap = mQueuedSingleTaps.poll();

        // I added this to use screenPointToWorldRay function in the second link I posted... I am probably using this wrong
        float[] worldXY = new float[6];
...
        if (tap != null && frame.getTrackingState() == TrackingState.TRACKING) {

            // ***** I added this to use screenPointToWorldRay function
            worldXY = screenPointToWorldRay(tap.getX(), tap.getY(), frame);
...

        }
...

        // Visualize anchors created by touch.
        float scaleFactor = 1.0f;
        for (PlaneAttachment planeAttachment : mTouches) {
...
        }

        // ***** This places the object momentarily in the scene (it disappears immediately)  
        frame.getPose().compose(Pose.makeTranslation(worldXY[3], worldXY[4], worldXY[5])).toMatrix(mAnchorMatrix, 0);

        // ***** This places the object in the middle of the scene but since it is not attached to anything, there is no tracking, it is always in the middle of the screen (pretty much expected behaviour)
        // frame.getPose().compose(Pose.makeTranslation(0, 0, -1.0f)).toMatrix(mAnchorMatrix, 0);

        // *****I duplicated this code which gets executed ONLY when touching a detected plane/surface.
        mVirtualObject.updateModelMatrix(mAnchorMatrix, scaleFactor);
        mVirtualObjectShadow.updateModelMatrix(mAnchorMatrix, scaleFactor);
        mVirtualObject.draw(viewmtx, projmtx, lightIntensity);
        mVirtualObjectShadow.draw(viewmtx, projmtx, lightIntensity);
...
}

回答(0)