Placing objects right in front of camera in ARCore Android

邮差的信 提交于 2021-02-07 08:34:36

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/56679208/placing-objects-right-in-front-of-camera-in-arcore-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!