Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

[Solved] Unable to get feature points with ARPointCloud.Positions?

Discussion in 'AR' started by BuoDev, Jul 20, 2019.

  1. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    In update I'm trying to get all of the feature points currently detected.

    In AR foundation v1.0

    Code (CSharp):
    1. List<Vector3> featurePoints = new List<Vector3>();
    2. arPointCloud.GetPoints(featurePoints, Space.Self);
    with v2.2 I've tried

    Code (CSharp):
    1. List<Vector3> featurePoints = new List<Vector3>(arPointCloud.positions);
    2.  
    I must be doing something wrong here. Any advice?

    edit: My logcat is bombarded with this error
    E/native: hit_test.cc:376 generic::internal: No point hit.
     
    Last edited: Jul 20, 2019
  2. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    Still can't get it to work. Any help is highly appreciated.

    Code (CSharp):
    1. //get the arPointCloud
    2. ARPointCloud arPointCloud = arSessionOrigin.trackablesParent.GetComponent<ARPointCloud>();
    3. //check for existence of points
    4. if (arPointCloud.positions.IsCreated)
    5. {
    6. //add points to list
    7. List<Vector3> featurePoints = new List<Vector3>(arPointCloud.positions);
    8. }
     
  3. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    [Solved]

    ARPointCloud
    is generated as a child of the
    trackablesParent
    transform so you need to use
    trackablesParent.GetComponentInChildren<ARPointCloud>()
     
  4. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Thanks ! what arfoundation version did you use?

    I'm on "com.unity.xr.arfoundation": "2.1.0-preview.2", "com.unity.xr.arkit": "2.1.0-preview.3" , this solution does nto work for me, ARPointCloudManager does not seem to instantiate at m_SessionOrigin.trackablesParent in ARPointCloudManager script. Running this code I get obj ref not set to instance of an object.

    I see "com.unity.xr.arfoundation": "1.1.0-preview.6", "com.unity.xr.arkit": "1.0.0-preview.23" may work that work because ARPointCloudManager instantiates at m_SessionOrigin.trackablesParent

    I raised query at https://github.com/Unity-Technologies/arfoundation-samples/issues/223
     
    Last edited: Jul 24, 2019
  5. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    I'm using all the newest preview packages v2.2
     
  6. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Thanks, am I doing this in line with your method?

    on 2.1 I get NullReferenceException: Object reference not set to an instance of an object for

    ARPointCloud myARPointCloud=GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent<ARSessionOrigin>().trackablesParent.GetComponentInChildren<ARPointCloud>();
     
  7. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    I'm assuming your "ARSessionOrigin" GameObject has the ARSessionOrigin and ARPointCloudManager components attached?
    Then use this and add it to the same GameObject.

    Code (CSharp):
    1.  
    2. //get the ARSessionOrigin component
    3. arSessionOrigin = GetComponent<ARSessionOrigin>();
    4. //get the ARPointCloud component
    5. ARPointCloud arPointCloud = arSessionOrigin.trackablesParent.GetComponentInChildren<ARPointCloud>();
    6. //check for existence of points
    7. if (arPointCloud.positions.IsCreated)
    8. {
    9. //add points to list
    10. List<Vector3> featurePoints = new List<Vector3>(arPointCloud.positions);
    11. }
     
    Tarrag likes this.
  8. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Cool @BuoDev , thanks a bunch ! That worked :)

    I was getting the component at OnEnable and Session wasn't ready but couldn't see it so was getting null ref exception :eek:

    indeed found there is no confidence data with arkit (not even zeros, just doesn't return nothing)
     
  9. sasob8

    sasob8

    Joined:
    Jul 11, 2017
    Posts:
    19
    Ok, i really don't know what am i doing wrong. I tried everything and it doesnt work. Please help :)

    This is my simple code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR.ARFoundation;
    5. using UnityEngine.UI;
    6.  
    7. public class PointCloudList : MonoBehaviour
    8. {
    9.     [SerializeField]
    10.     ARSessionOrigin arSessionOrigin;
    11.     [SerializeField]
    12.     ARPointCloud arPointCloud;
    13.     [SerializeField]
    14.     ARPointCloudManager arPointCloudManager;
    15.  
    16.     public Text featurePointText;
    17.  
    18.     void Start()
    19.     {
    20.         arSessionOrigin = GetComponent<ARSessionOrigin>();
    21.         // arPointCloud = GetComponent<ARPointCloud>();
    22.         arPointCloudManager = GetComponent<ARPointCloudManager>();
    23.  
    24.      
    25.         arPointCloud = arSessionOrigin.trackablesParent.GetComponentInChildren<ARPointCloud>();
    26.  
    27.         Debug.Log(arPointCloud);
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.         // List<Vector3> featurePoints = new List<Vector3>(arPointCloud.positions);
    33.         if (arPointCloud != null)
    34.         {
    35.             featurePointText.text = "arPointCloud.positions.IsCreated = True";
    36.         }
    37.     }
    38. }
    If i use "arPointCloud.positions.IsCreated", unity throws error. Probably, because arPointCloud is still null.
    On my AR session origin Gameobject i have: ARSessionOrigin, ARPointCloud, ARPointCloudManager and my script PointCloudList.
    Do i need ARPointCloud? Do i need ARPointCloudManager?
    I tried all combinations, and also tried everything in code.
    Oh, and this version doesnt throw error, but arPointCloud is always null.

    I am using: Unity 2019.1.11f, AR Foundation 2.1.0 - preview.3, AR Core 2.1.0 - preview.5
    I am trying to build on android (Galaxy S8+).
     
  10. BuoDev

    BuoDev

    Joined:
    Nov 28, 2018
    Posts:
    45
    @sasob8 Try getting the PointCloud component in Update - it probably doesn't exist yet in Start. Also check for the actual positions after you know that the PointCloud component exists. This should work.

    Code (CSharp):
    1.  
    2.     void Update()
    3.     {
    4.         // List<Vector3> featurePoints = new List<Vector3>(arPointCloud.positions);
    5.      
    6.         if (arPointCloud == null)
    7.         {
    8.             arPointCloud = arSessionOrigin.trackablesParent.GetComponentInChildren<ARPointCloud>();
    9.         }
    10.         else
    11.         {
    12.             if(arPointCloud.positions.IsCreated)
    13.             {
    14.             featurePointText.text = "arPointCloud.positions.IsCreated = True";
    15.             }
    16.         }
    17.     }
    18.  
     
    Tarrag likes this.
  11. sasob8

    sasob8

    Joined:
    Jul 11, 2017
    Posts:
    19
    thank you it works... now i understand how it works. :)
     
unityunity