Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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