Skip to content

Instantly share code, notes, and snippets.

@andijakl
Created August 9, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andijakl/21b70d417c3bddf0858be8917928706c to your computer and use it in GitHub Desktop.
Save andijakl/21b70d417c3bddf0858be8917928706c to your computer and use it in GitHub Desktop.
AR Foundation Point Cloud Logging
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class PointCloudInfo : MonoBehaviour
{
// The AR Foundation PointCloud script
private ARPointCloud _pointCloud;
// Reference to logging UI element in the canvas
public UnityEngine.UI.Text Log;
void OnEnable()
{
// Subscribe to event when point cloud changed
_pointCloud = GetComponent<ARPointCloud>();
_pointCloud.updated += OnPointCloudChanged;
}
void OnDisable()
{
// Unsubscribe event when this element is disabled
_pointCloud.updated -= OnPointCloudChanged;
}
private void OnPointCloudChanged(ARPointCloudUpdatedEventArgs eventArgs)
{
if (!_pointCloud.positions.HasValue ||
!_pointCloud.identifiers.HasValue ||
!_pointCloud.confidenceValues.HasValue)
return;
var positions = _pointCloud.positions.Value;
var identifiers = _pointCloud.identifiers.Value;
var confidence = _pointCloud.confidenceValues.Value;
if (positions.Length == 0) return;
var logText = "Number of points: " + positions.Length + "\nPoint info: x = "
+ positions[0].x + ", y = " + positions[0].y + ", z = " + positions[0].z
+ ",\n Identifier = " + identifiers[0] + ", Confidence = " + confidence[0];
if (Log)
{
Log.text = logText;
}
else
{
Debug.Log(logText);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment