Search Unity

Question Is it possible to "set" the Session Origin?

Discussion in 'AR' started by adammpolak, Dec 27, 2020.

  1. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    I understand that when an ARSession starts the device's current position is initialized as the ARSessions "origin" (like local model space). The Pose Driver then updates the parent GameObjects Transform.

    Is it possible to "set" the current Pose to a Transform in world space so that updated poses deltas are added to that coordinate?

    ARCameraGameObject (gameObject)
    -PoseDriver (script)

    Scenario:
    - ARSession has a current translation of (1,6,5)

    ARSession.SetCurrentLocation(3,1,8)

    This would make it so that the current "pose" calculated by the Pose Driver is (3,1,8).
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    Hey @adammpolak - give the method ARSessionOrigin.MakeContentAppearAt() a try.

    Please let us know if that doesn't work!
     
    adammpolak likes this.
  3. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    @TreyK-47 sorry so the method would be ARSessionOrigin.MakeContentAppearAt(3,1,8)?

    And thank you for the response!
     
  4. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    121
    Here is the link to this method, you need to give a GameObject and the Position. Maybe the PoseDrive GameObject and is current position will work.
     
  5. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    Thank yoU!
     
  6. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    @TreyK-47 it doesn't seem to work but I am not sure if its because I am implementing this incorrectly.

    - Pose Driver starts at (0,0,0) and the AR device moves around and let's say they are at (5,6,8)
    - I want to "spawn" the AR player at (1,3,-4) (so the equivalent of reseting the Pose Driver to (0,0,0) but at (1,3,-4))

    I would like the response after setting origin to new location to be the value of the new location.

    Note 1:
    Calling MakeContentAppearAt() seems to be additive?

    What I am doing:
    float3 newPostTranslation = (some value)
    quaternion newPostRotation = (some value)

    Transform dummyTransform = new GameObject().transform;
    m_ARSessionOrigin.MakeContentAppearAt(dummyTransform, newPoseTranslation, newPoseRotation);

    If I call this several times the AR position seems to "travel forward".

    Below you can see the Debug.Log() of the following steps:
    - Getting a spawn position
    - Calculating where the camera should be (relative to the spawn position it's (0,2,-10)
    - After calling MakeContentAppearAt I log the camera transform

    Code (CSharp):
    1. spawn position is: float3(-2.11f, 9.44f, 16.13f)
    2. ARPoseSampler:Update()
    3. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    4.  
    5. calculated camera position is: float3(-2.11f, 11.44f, 6.129999f)
    6. ARPoseSampler:Update()
    7. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    8.  
    9. transform after MakeContentAppearAt: (2.2, -11.4, -6.1)
    10. ARPoseSampler:Update()
    It appears to be -1 of where I want it to be.

    Weirder still is that as I call it more times the offset seems to change based on previous calls. Seems like maybe I need an equivalent "clear" call before I call it again?

    I am going to save each update, reverse it, then apply the new one *-1

    Note 2:
    I got it working by saving the last update, reversing it, then creating the new update

    Code (CSharp):
    1.            Transform dummyTransform = new GameObject().transform;
    2.             //First we will undo our last MakeContentAppearAt
    3.             m_ARSessionOrigin.MakeContentAppearAt(dummyTransform, -1f*m_LastPosition, Quaternion.Inverse(m_LastRotation));
    4.        
    5.             //Now we will do our current MakeContentAppearAt
    6.             m_LastPosition = -1f * newPoseTranslation;
    7.             m_LastRotation = Quaternion.Inverse(newPoseRotation);
    8.             m_ARSessionOrigin.MakeContentAppearAt(dummyTransform, m_LastPosition, m_LastRotation);
    Result from Debug.Log:
    Code (CSharp):
    1. spawn position is: float3(6.33f, 9.88f, 2.03f)
    2. ARPoseSampler:Update()
    3. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    4.  
    5. calculated camera position is: float3(6.33f, 11.88f, -7.97f)
    6. ARPoseSampler:Update()
    7. (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    8.  
    9. transform after MakeContentAppearAt: (6.3, 11.9, -8.0)
    10. ARPoseSampler:Update()
    This isn't great because rounding errors causes it to drift away from being correct. Is there anyway to "reset" so I can 0 out? Should I adjust the actual ARSessionOrigin's Translation and Rotation?
     
    Last edited: Jan 31, 2021
  7. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    @TreyK-47 hey sorry this isn't resolved.

    Is there any Unity way of updating the origin? This is needed for AR applications. If you want to correct for drip or make the player "exist" in another location.

    My method doesn't work for the reasons explained above.
     
  8. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,144