Search Unity

Create ARReferencePoint

Discussion in 'Handheld AR' started by DreamEnder, Aug 8, 2018.

  1. DreamEnder

    DreamEnder

    Joined:
    Apr 12, 2011
    Posts:
    190
    How would you go about creating a reference point/anchor from script?
     
  2. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    297
    I've wondered this as well!
     
  3. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
  4. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    54
    I am also interested how I can anchor a gameobject using AR Reference Point.
    Is there a scripting example somewhere? I guess the AR Foundation Sample scripts are not setting Reference Points.

    One way is surely to insert the desired prefab to AR Reference Point Manager and instantiate it with the methods that Tim listed above, but then I guess the gameobject changes its name and parent. I'm not sure if that's the right way.

    I was thinking about spawning an gameobject normally, setting an ARReferencePoint in the same place and utilizing ARReferencePointUpdatedEventArgs to get the updated pose to update the gameobject's transform.
    Is that a good way to go?
     
  5. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    I would suggest parenting your GameObject to the returned ARReferencePoint (if you don't specify a prefab, it creates a GameObject with only an ARReferencePoint component).

    This would also work, and may be desirable if you plane to scale the ARSessionOrigin.
     
    Saicopate likes this.
  6. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    48
    Curious what the difference is between ARReferencePointManager.TryAddReferencePoint
    andARReferencePointManager.TryAttachReferencePoint? I was using TryAttachReferencePoint thinking that, by referencing a plane, the reference point would automatically update it's position when the plane updates its bounds/position.

    TryAttachReferencePoint is returning null for me though which seems like a bug. I have verified that my plane and pose are not null.

    Code (CSharp):
    1. _stageReferencePoint = ReferencePointManager.TryAttachReferencePoint(_planeHit, _hitPose);
    After the above code is run _stageReferencePoint is still null;

    EDIT:
    Just tried;
    Code (CSharp):
    1. _stageReferencePoint = ReferencePointManager.TryAddReferencePoint(_hitPose);
    This does return a ReferencePoint for me instead of null, so this one appears to be working.
     
    Last edited: Aug 10, 2018
  7. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    Arkit or ARCore?
     
  8. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    48
    I am testing on iOS.
     
  9. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    It definitely works, but some features will break if you don't include this link.xml file in your project. Attach to plane is one such feature.
     
  10. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    48
    Thanks fixed it, thank you. ReferencePointUpdated started firing after the fix when it was not while using TryAddReferencePoint, not sure if this is intended or not.

    Can you answer my other question above?

    "Curious what the difference is between ARReferencePointManager.TryAddReferencePoint
    andARReferencePointManager.TryAttachReferencePoint?"

    In my app I am placing a single item and want it to appear as if it is in the room with you. I have accomplished this with both calls but I am unsure of the "correct" way to do it. Both of these look like they do the same thing, wonder what are the differences/pros/cons?
     
  11. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    Add vs Attach maps closely to these concepts in ARCore: https://developers.google.com/ar/develop/developer-guides/anchors#pick_an_anchor_context

    When you "attach" a reference point to a plane, it maintains that distance from the plane. For example, if the plane is horizontal, then the reference point only moves up and down as the plane's Y position changes. The X and Z coordinates should not change. This is useful for "sticking" objects on or near planes.

    If you "add" a reference point, then you're asking the system to track a specific location in space. It may update if the overall environmental understanding of the session changes.
     
  12. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    48
    Thanks for the help it is appreciated, that was a great explanation. It sounds like i should use TryAttachReferencePoint since I am trying to place something on a table or flat surface.

    Last question, if I attach to a horizontal plane using TryAttachReferencePoint does the returned ReferencePoint take care of it's y position itself? Is there ever any need to do any repositioning with ReferencePointUpdated?
     
  13. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    Yes it takes care of the y position. The purpose of reference points is for the device to track and update them. You should not update them manually.
     
  14. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    48
    Ok I lied, one more. After I place my ReferencePoint do I need to keep ARPlaneManager enabled for it to keep updating it's y position.

    Just wondering if shutting down ARPlaneManager after placing a ReferencePoint would improve performance (not that perf is an issue at this point, just trying to be efficient).
     
  15. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    Disabling the ARPlaneManager will tell the device to stop detecting planes, so I wouldn't expect any further updates to the ReferencePoint.
     
  16. theDawckta

    theDawckta

    Joined:
    Jun 16, 2014
    Posts:
    48
    Thanks for the help, greatly appreciated.
     
  17. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    @tdmowrer Hey, I am wondering if I should be making use of a reference point to improve tracking, or just better practice.

    I am currently placing my content using standard place on plane method, turning off plane manager and making use of makecontentappearat for scaling.

    All is working well, but sometimes I suffer floating,jittering or relocating, and reference points have been mentioned as a way to improve tracking.

    My understanding is I am placing my content at a specific world space coord, and the arsession and trackposedriver looks after the tracking relative to the cameras movement after that etc.

    What would a reference point add? Can it be used in this case? Would it be better?

    Would you mind providing a simple explanation/comparison of a simple point in world space vs a referencepoint(anchor) to help my understanding of things.

    Thanks a lot

    Bump
     
    Last edited: Mar 27, 2019
    marie-hmm and viemr like this.
  18. GreeneMachine

    GreeneMachine

    Joined:
    Jul 3, 2015
    Posts:
    126
    @tdmowrer If you get time, can you offer any insight to my question above.
    Thanks a lot
     
  19. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    63
    What I don't get:
    If the reference points are essential, why are they not included in the sample scenes? I had to google my way over here with a lot of detours until I found out.
    It's the same with remoting:
    You guys updated the thread with a video, but kinda forgot to mention that they are broken in 2019, took me 2h to find that out.
    Sorry, had to say this, I´'ll try the reference points now.
     
  20. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    480
    Sorry, what's broken in 2019? Can you link me to the video?

    I agree a sample would be helpful. I'll see what we can do about that.
     
  21. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    63
  22. ArmanUnity

    ArmanUnity

    Joined:
    Nov 29, 2015
    Posts:
    13
    hello.. @tdmowrer ..Help me understand the advantage of adding a reference point(anchor point) to a object
    for example,1. we can place a cube by simply after a hit test, like instantiating a cube after a raycast hit on the trackable type plane and setting the position and rotation of the cube to the returned hit pos and rotation ,device can start tracking that cube........ does it improve/ make any difference in tracking, if we add a reference point to that hit position ???
    2. we can place a cube(not hit test) just 1 unit in front of the camera at the start itself and it will start tracking that cube relative to the world origin(position and rotation of the device when session starts), does it improve tracking if we add a reference point to that position ??????( for the test case i have done i cant observe much difference)
    3.ar core doc says using anchors improves realism and performance, but when the environment understanding changes in each frame position and rotation of these anchor also may changes ,so in effect the position of the objects using this anchor/reference also prone to the changes .... a possibility of drift may occur like a an object without anchor ryt?????
     
  23. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    63
    I have used anchors only in ARCore, but I assume they are similar here.
    If the track of the scene has been less than optimal before you place your object, there is a chance that the point cloud and therefore the transforms of the trackables change. An Anchor will be notified of the changes and change its pose relative to the the new tracking points' location.
     
    ArmanUnity likes this.
  24. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    85
    Hey @ArmanUnity I'm testing anchors with ARF2.1 and frankly not yet seeing much difference on tracking. Where I can see the benefit of anchors is if two objects are to maintain a specific distance to each other - by anchoring both objects as child of the anchor it would help be "more realistic" because both objects can keep their position relative to one another constant cos they're both child of the parent anchor; that's the example in arcore https://developers.google.com/ar/develop/developer-guides/anchors

    That's my interpretation to date.
     
  25. ArmanUnity

    ArmanUnity

    Joined:
    Nov 29, 2015
    Posts:
    13
    yes @Tarrag i understand the advantage if we need to maintain distance between two objects ... but in ar core doc they saying that .... you should place an anchor on the hit position place ...ryt????
    "For example, imagine that your app lets users place virtual furniture pieces around a room. A user opens the app and ARCore begins tracking a tabletop and a floor in the room as Planes. The user positions a virtual lamp on the tabletop. Then, the user puts a virtual chair on the floor.
    At this point, your scene should have one anchor attached to the tabletop Plane and another attached to the floor Plane."
    so for the normal hit test on a plane ... we can change the objects position to hit position and and start tracking, And we can also add a reference point in there and make object as child of reference point game object.. does the second way improves tracking .....???? i cant see much difference