本文介绍了在ARCore Android中将对象放置在相机的正前方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将大型3D对象(从.obj文件生成)放置在相机前面,但无法执行此操作.以命中结果为中心放置模型.有办法完成吗?

I'm trying to place a large 3D object (generated from .obj file) in front of camera and not able to do it. The model gets placed considering the hit result as the center point. Any way to get it done?

推荐答案

以下代码将在摄像机前面放置一个锚点1M-您可以根据需要调整深度:

The following code will place an anchor 1M in front of the camera - you can adjust the depth to whatever you need:

            // Place the anchor 1m in front of the camera.
            Log.d(TAG,"adding Andy in fornt of camera");
            Frame frame = arFragment.getArSceneView().getArFrame();
            Session session = arFragment.getArSceneView().getSession();
            Anchor newMarkAnchor = session.createAnchor(
                    frame.getCamera().getPose()
                            .compose(Pose.makeTranslation(0, 0, -1f))
                            .extractTranslation());
            AnchorNode addedAnchorNode = new AnchorNode(newMarkAnchor);
            addedAnchorNode.setRenderable(andyRenderable);
            addedAnchorNode.setParent(arFragment.getArSceneView().getScene());

您可以在此处看到一个完整的工作示例-它使用按钮添加节点而不是使用点击结果,这也可能对您有用: https://github.com/mickod/LineView

You can see a full working example here - this uses a button to add the node rather than using the hit result, which may be useful for you also: https://github.com/mickod/LineView

这篇关于在ARCore Android中将对象放置在相机的正前方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:35