3

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?

Rahul Rastogi
  • 4,486
  • 5
  • 32
  • 51
  • Please update post with what you have done. First, Declare the Node, and put the Node into a sceneview. – Jay Ryu Jun 20 '19 at 05:23

1 Answers1

6

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

Mick
  • 24,231
  • 1
  • 54
  • 120
  • when I move the device close to model it moves away. – Nouman Ch Sep 25 '19 at 14:12
  • @NoumanCh Interesting - I just tested using a test app which uses the above code (https://github.com/mickod/LineView and on PlayStore) and while the 'Andy' seems to have no depth when you get close or walk through it, it does not move away (using a first gen Google Pixel). I have noticed that ARCore is evolving with updates and new releases and renderables are definitely less 'shaky' than before, so maybe this is just a characteristic of the framework. – Mick Sep 25 '19 at 14:58
  • 1
    I'm basically trying to popup model when image gets detected. The issue is some time I have image in horizontal position or some time in vertical but I have to popup model in horizontaly. – Nouman Ch Sep 25 '19 at 18:42
  • that's why I was trying to put the model manualy in front of camera when image gets detected instead of using image.getCenterPose() – Nouman Ch Sep 25 '19 at 18:43