Core Plugin API

The core functionality of the Unity plugin can be found in the class Immersal.Core. There are no AR Foundation dependencies.

Image Localization

The code below returns the position and orientation of the image (typically from a camera feed) within the map. The LocalizeImage function returns 0 if localization failed and 1 if it succeeded.

See Immersal.AR.ARLocalizer in the Samples/Scripts/AR folder as an example of how to get the pixel buffer data and intrinsics for the image in an AR Foundation application. Samples/Scenes/SampleScene utilizes this class and can be used for quickly testing of your mappings.

To localize, use this code

int width; // width of the image
int height; // height of the image
Vector4 intrinsics; // camera intrinsics
byte[] pixels; // image data
Vector3 pos; // resulting device position
Quaternion rot; // resulting device orientation
int result = Immersal.Core.LocalizeImage(out pos, out rot, width, height, ref intrinsics, pixels);

Image Capturing

The code below captures and saves an image to the current mapping session. Typically, capturing several images is required to calculate a continuous point cloud map. The CaptureImage function returns the number of bytes captured.

See the Immersal.Samples.Mapping.Mapper class and Samples/Scenes/MappingApp as an example.

To capture an image, use this code

byte[] pixels; // image data (typically from the camera)
int width; // image width
int height; // image height
int channels; // 1 or 3, monochromatic or RGB capture
byte[] capture = new byte[4 * 1024 * 1024]; // should need less than 2 megs when reso is 1440p
int size = Immersal.Core.CaptureImage(capture, capture.Length, pixels, width, height, channels);

Getting the Point Cloud

The currently loaded point cloud can be retrieved for e.g. visualization.

The code below retrieves the currently active point cloud and visualizes it. The GetPointCloud function returns the number of points in the cloud.

To get the point cloud, use this code

Vector3[] points = new Vector3[65536]; // allocate space
int num = Immersal.Core.GetPointCloud(points); // get the point cloud
m_PointRenderer.CreateCloud(points, num); // do something with the point cloud data, e.g. visualize

Loading the Map

The code below initializes the plugin with a previously captured and saved map data. See Immersal.AR.ARCloud in the Samples/Scripts/AR folder as an example.

To load the captured point cloud map, use this code

TextAsset m_cloudFile;