Skip to content

Instantly share code, notes, and snippets.

@Venkat-Swaraj
Created June 25, 2024 18:05
Show Gist options
  • Save Venkat-Swaraj/ce403d331b70e253555848887089731b to your computer and use it in GitHub Desktop.
Save Venkat-Swaraj/ce403d331b70e253555848887089731b to your computer and use it in GitHub Desktop.
This script can be used to save point cloud data.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class PointCloudParser : MonoBehaviour
{
public ARPointCloudManager pointCloudManager;
private void OnEnable()
{
pointCloudManager.pointCloudsChanged += PointCloudManager_pointCloudsChanged;
}
private void PointCloudManager_pointCloudsChanged(ARPointCloudChangedEventArgs obj)
{
List<ARPoint> addedPoints = new List<ARPoint>();
foreach (var pointCloud in obj.added)
{
foreach (var pos in pointCloud.positions)
{
ARPoint newPoint = new ARPoint(pos);
addedPoints.Add(newPoint);
}
}
List<ARPoint> updatedPoints = new List<ARPoint>();
foreach (var pointCloud in obj.updated)
{
foreach (var pos in pointCloud.positions)
{
ARPoint newPoint = new ARPoint(pos);
updatedPoints.Add(newPoint);
}
}
}
}
public class ARPoint
{
public float x;
public float y;
public float z;
public ARPoint(Vector3 pos)
{
x = pos.x;
y = pos.y;
z = pos.z;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment