Croid
Croid

Reputation: 111

Android Arcore Plane Tracker Target

I can't find anything on the forums and I would like to manage to create a target on arcore integrated in the plane, like Measure. (Avoids lag with an image centered on the layout)

Do you have a starting point?

I think about that! but don't stay in the center

 com.google.ar.sceneform.Camera camera = arFragment.getArSceneView().getScene().getCamera();
    MaterialFactory.makeTransparentWithColor(MainActivity.this, new com.google.ar.sceneform.rendering.Color(Color.parseColor("#ff333d")))
            .thenAccept(material -> {
                nodeRenderable = ShapeFactory.makeSphere(0.008f, new Vector3(camera.getWorldPosition().x, camera.getWorldPosition().y,  camera.getWorldPosition().z), material);

enter image description here

Upvotes: 1

Views: 566

Answers (1)

Simon Marquis
Simon Marquis

Reputation: 7526

What you should do is to create a Node and add it as a child of the scene.

Then on each Node.onUpdate(FrameTime) do these steps

  • Perform a hitTest from the center of the ArSceneView
  • Find the first HitResult beeing a Plane and isPoseInPolygon() == true
  • Update the Node worldPosition and worldRotation to match the hit pose translation and rotation

You can take a look at this Reticle class which is doing exactly that: https://github.com/SimonMarquis/AR-Toolbox/blob/fb31a9cfdf061104a4401cecc9bc73ffa7ad33e6/app/src/main/java/fr/smarquis/ar_toolbox/Settings.kt#L124-L185

Upvotes: 1

Related Questions