Search Unity

Feedback Unity AR App (Android and iOS) Image Tracking: Using four Images to scale a Plane

Discussion in 'AR' started by Schoni, Jul 18, 2022.

  1. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    I started building an Android and iOS AR application with image tracking. The goal is to build a plane with a material on it based on the space between 4 trackable images. So my system should detect and store four image trackers and create Emptys at their locations. With these GameObjects, a custom written Mesh Pipeline should triangulate a plane scaled to these four trackers. I am currently trying to create and store the Emptys but dont really know how to debug my code in Unity since I have to run it on my phone and I'm not shure if my code works well.

    Based on the AR Tracked Image Manager from Unity in the following class I used the basics which I found in the documentation (OnEnable, OnDisable and OnChanged). In the OnChanged Method I implemented the handling if a new Image is tracked that the GameObject is build and the Entry in the List is done. Update and Remove are also in here.

    I don't know if this is the correct workflow after the ARTrackedImageManager.

    Thanks for your help!
     
    Last edited: Aug 9, 2022
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    Here you spawn a gameobject. GameObject tmp = setEmpty(trackedImage.name, trackedImage.transform.position);
    Have a list of gameobjects where you add these.
    If the list has a size of 4 make a quad out of them
     
  3. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    and this is what my Inspector for the Session Origin looks like
    upload_2022-7-19_12-34-37.png
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    Seems like you have an issue spawning objects in AR when getting an image, not so much the quad generation.
    Use debug.log to see where the code does and does not go
     
  5. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    The Tracked Image variable in Add Anchor threw an error because it wasn't assigned. I'm gonna make some more tests if every thing works
     
    DevDunk likes this.
  6. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    I tested it further more and found the problem that every GameObject I instantiate are set to the same position.
     
  7. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    Also when I lay down all four markers (I use old gamecards) before I start the application they are not being detected. But if I zoom in, then they are detected.
     
  8. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    So the position I get every time for every detected Image is: 588.24, 890.39, 46.88. This is the possition of the session origin. How do I get the positions from the tracked Images?
     
    Last edited: Jul 24, 2022
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    Maybe spawn a gameobject so you can track the transforms?
     
  10. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    how do you mean this exactly? I am spawning GameObjects at the tracked positions from the images but they all have the same coordinates.
     
  11. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    If you visually see them in different positions your code of reading them is wrong (maybe you read your prefab position instead of the spawned GO?)
     
  12. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    I can't see anything because I use Emptys and I use no prefabs actually because the plane is instantiatet on run time based on a script. I think I am using a wrong variable for the positions from the tracked images but couldn't find the solution therefore
     
  13. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    i updated the code in the AddAnchor class in one of the upper messages
     
    ankur-unity likes this.
  14. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    Then spawn a primitive?
     
  15. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    For debugging it can help and I am gonna test it now but with my written code they all are gonna set at the point (0,0,0). I moved the session origin to that point but every detected Image gives me this coordinates, so every GameObject gets it too. Then all my Gameobjects are at the point (0,0,0) and so my plane between these 4 points can't be shown
     
  16. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    I tried it with a primitiv cube but as predicted, it was build to the session Origin (0,0,0)
     
  17. Schoni

    Schoni

    Joined:
    Dec 10, 2021
    Posts:
    32
    I now found out that when I add an empty GameObject to the TrackedImagePrefab variable in the ARTrackedImageManager some of my tracked Images positions are not equal to the ARSession Origin Position. Do you may know why this is so? I realy can't explain it.
     
  18. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    Sorry, if you can't explain it I cannot help much