将对象放在 ARCore Android 中的相机前面 [英] Placing objects right in front of camera in ARCore Android

查看:15
本文介绍了将对象放在 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 中的相机前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆