Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

on iOS ARPointCloud script positions and confidenceValues - How access the data? #223

Closed sergiosolorzano closed 5 years ago

sergiosolorzano commented 5 years ago

Hi ! Please help, without Remote the debug is sooo painful :(

I'm trying to get information about feature points (ARPointCloud https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0/api/UnityEngine.XR.ARFoundation.ARPointCloud.html )

I've tried the code below but any debugging message stops when it his these lines. I also tested if either is or not NULL but the code just does not show anything or move forward after hitting these lines:

int numConfValues = 
GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent<ARPointCloud>().confidenceValues.Length;

also tried 
GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent<ARSessionOrigin>().trackablesParent.GetComponentInChildren<ARPointCloud>().confidenceValues.Length;

and

int numPositionValues = 
GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent<ARPointCloud>().positions.Length;

also tried 
GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent<ARSessionOrigin>().trackablesParent.GetComponentInChildren<ARPointCloud>().positions.Length

I've read confidenceValues are not reported by Arkit but positions? Are these methods currently working, how can I get cloud point information, e.g. number of feature points, its positions, even confidence if there is an alternative?

I can get the cloud position with for each update with GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent().pointCloudsChanged and foreach (var point in change.added) but i'm after the actual feature points within the cloud.

Code below.

Thanks a bunch for your help ! On Unity 2019.1.3, arfoundation 2.1.0-preview.2, arkit 2.1.0-preview.3

OnEnable: GetComponent<ARPointCloudManager>().pointCloudsChanged += UpdatedCloudPoints;

public void UpdatedCloudPoints(ARPointCloudChangedEventArgs change)
{

//Execute when there have been 1000 updates:

confValuesArray = new Unity.Collections.NativeArray<float>();
int numConfValues = C_ARCommonCached.c_ARPointCloudScript.confidenceValues.Length;
Debug.Log("numConfValues length:" + numConfValues);

            foreach (var confValue in confValuesArray)
            {
                Debug.Log("thisValue:" + confValue);
                sumConfValues += confValue;
            }

positionList = new Unity.Collections.NativeArray<Vector3>();
positionList = C_ARCommonCached.c_ARPointCloudScript.positions;

int numPositionValues = C_ARCommonCached.c_ARPointCloudScript.positions.Length;
int counter = 0;
            foreach (var positionValue in positionList)
            {
                Debug.Log("position " + counter + ":" + positionValue);
                counter++;
            }

}

sergiosolorzano commented 5 years ago

I was getting GameObject.FindGameObjectWithTag("ARSessionOrigin").GetComponent().trackablesParent.GetComponentInChildren() null ref exception cos was grabbing the component at OnEnable. Now works great, here's thread in case it helps someone https://forum.unity.com/threads/solved-unable-to-get-feature-points-with-arpointcloud-positions.713291/#post-4779689

sergiosolorzano commented 4 years ago

hey @aerchit sorry I have not been making use of it since the time I posted here, couldn't say sorry

pinnakkkk commented 3 years ago

hey @aerchit sorry I have not been making use of it since the time I posted here, couldn't say sorry

Could You help me out? I'm trying to display those values so can u tell me what datatype did u use for confValuesArray is it ArrayList and C_ARCommonCached again what datatype ? bcs when im creating new ArrayList it is throwing an error cant convert float to array