Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions src/ARKit/ARAnchor_C.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// ARAnchor.cs: Bindings for the ARKit C API anchor types
//
// Copyright 2025 Microsoft Corp
//

#if __MACOS__
#nullable enable

using System;
using System.Runtime.InteropServices;
using CoreFoundation;
using ObjCRuntime;

using Matrix4 = global::CoreGraphics.NMatrix4;

namespace ARKit {

/// <summary>Represents an ARKit anchor in the C API.</summary>
[SupportedOSPlatform ("macos26.0")]
public class ARAnchor : ARObject {

[DllImport (Constants.ARKitLibrary)]
static extern /* simd_float4x4 */ SimdFloat4x4 ar_anchor_get_origin_from_anchor_transform (IntPtr anchor);

[DllImport (Constants.ARKitLibrary)]
unsafe static extern void ar_anchor_get_identifier (IntPtr anchor, byte* out_identifier);

[DllImport (Constants.ARKitLibrary)]
static extern double ar_anchor_get_timestamp (IntPtr anchor);

[Preserve (Conditional = true)]
internal ARAnchor (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

/// <summary>Gets the transform from this anchor to the origin coordinate system.</summary>
public Matrix4 OriginFromAnchorTransform {
get {
var simd = ar_anchor_get_origin_from_anchor_transform (GetCheckedHandle ());
return simd.ToNMatrix4 ();
}
}

/// <summary>Gets the unique identifier of this anchor.</summary>
public Guid Identifier {
get {
unsafe {
byte* uuid = stackalloc byte [16];
ar_anchor_get_identifier (GetCheckedHandle (), uuid);
return new Guid (new ReadOnlySpan<byte> (uuid, 16));
}
}
}

/// <summary>Gets the timestamp associated with this anchor.</summary>
public double Timestamp {
get {
return ar_anchor_get_timestamp (GetCheckedHandle ());
}
}
}

/// <summary>Represents a trackable ARKit anchor that can report whether it is currently tracked.</summary>
[SupportedOSPlatform ("macos26.0")]
public class ARTrackableAnchor : ARAnchor {

[DllImport (Constants.ARKitLibrary)]
static extern byte ar_trackable_anchor_is_tracked (IntPtr anchor);

[Preserve (Conditional = true)]
internal ARTrackableAnchor (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

/// <summary>Gets a value indicating whether this anchor is currently tracked.</summary>
public bool IsTracked {
get {
return ar_trackable_anchor_is_tracked (GetCheckedHandle ()) != 0;
}
}
}
}

#endif // __MACOS__
102 changes: 102 additions & 0 deletions src/ARKit/ARAuthorizationResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// ARAuthorizationResult.cs: Bindings for the ARKit C API authorization types
//
// Copyright 2025 Microsoft Corp
//

#if __MACOS__
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CoreFoundation;
using ObjCRuntime;

namespace ARKit {

/// <summary>Represents a single authorization result from the ARKit C API.</summary>
[SupportedOSPlatform ("macos26.0")]
public class ARAuthorizationResult : ARObject {

[DllImport (Constants.ARKitLibrary)]
static extern /* ar_authorization_type_t */ nuint ar_authorization_result_get_authorization_type (IntPtr authorization_result);

[DllImport (Constants.ARKitLibrary)]
static extern /* ar_authorization_status_t */ nint ar_authorization_result_get_status (IntPtr authorization_result);

[Preserve (Conditional = true)]
internal ARAuthorizationResult (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

/// <summary>Gets the authorization type associated with this result.</summary>
public ARAuthorizationType AuthorizationType {
get {
return (ARAuthorizationType) (ulong) ar_authorization_result_get_authorization_type (GetCheckedHandle ());
}
}

/// <summary>Gets the authorization status associated with this result.</summary>
public ARAuthorizationStatus Status {
get {
return (ARAuthorizationStatus) (long) ar_authorization_result_get_status (GetCheckedHandle ());
}
}
}

/// <summary>Represents a collection of authorization results from the ARKit C API.</summary>
[SupportedOSPlatform ("macos26.0")]
public class ARAuthorizationResults : ARObject {

[DllImport (Constants.ARKitLibrary)]
static extern /* size_t */ nuint ar_authorization_results_get_count (IntPtr authorization_results);

[DllImport (Constants.ARKitLibrary)]
unsafe static extern void ar_authorization_results_enumerate_results_f (
IntPtr authorization_results,
void* context,
delegate* unmanaged<void*, IntPtr, byte> enumerator);

[Preserve (Conditional = true)]
internal ARAuthorizationResults (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

/// <summary>Gets the number of authorization results in this collection.</summary>
public nuint Count {
get {
return ar_authorization_results_get_count (GetCheckedHandle ());
}
}

/// <summary>Returns all authorization results in this collection as an array.</summary>
public ARAuthorizationResult [] GetResults ()
{
var results = new List<ARAuthorizationResult> ();
unsafe {
delegate* unmanaged<void*, IntPtr, byte> callback = &EnumerateCallback;
var handle = GCHandle.Alloc (results);
try {
ar_authorization_results_enumerate_results_f (GetCheckedHandle (), (void*) GCHandle.ToIntPtr (handle), callback);
} finally {
handle.Free ();
}
}
return results.ToArray ();
}

[UnmanagedCallersOnly]
unsafe static byte EnumerateCallback (void* context, IntPtr authorization_result)
{
var handle = GCHandle.FromIntPtr ((IntPtr) context);
var results = (List<ARAuthorizationResult>) handle.Target!;
results.Add (new ARAuthorizationResult (authorization_result, owns: false));
return 1; // continue
}
}
}

#endif // __MACOS__
159 changes: 159 additions & 0 deletions src/ARKit/ARDataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//
// ARDataProvider.cs: Bindings for the ARKit C API data provider types
//
// Copyright 2025 Microsoft Corp
//

#if __MACOS__
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CoreFoundation;
using ObjCRuntime;

namespace ARKit {

/// <summary>Represents an ARKit data provider.</summary>
[SupportedOSPlatform ("macos26.0")]
public class ARDataProvider : ARObject {

[DllImport (Constants.ARKitLibrary)]
static extern /* ar_data_provider_state_t */ nint ar_data_provider_get_state (IntPtr data_provider);

[DllImport (Constants.ARKitLibrary)]
static extern /* ar_authorization_type_t */ nuint ar_data_provider_get_required_authorization_type (IntPtr data_provider);

[Preserve (Conditional = true)]
internal ARDataProvider (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

/// <summary>Gets the current state of this data provider.</summary>
public ARDataProviderState State {
get {
return (ARDataProviderState) (long) ar_data_provider_get_state (GetCheckedHandle ());
}
}

/// <summary>Gets the authorization type required by this data provider.</summary>
public ARAuthorizationType RequiredAuthorizationType {
get {
return (ARAuthorizationType) (ulong) ar_data_provider_get_required_authorization_type (GetCheckedHandle ());
}
}
}

/// <summary>Represents a mutable collection of ARKit data providers.</summary>
[SupportedOSPlatform ("macos26.0")]
public class ARDataProviders : ARObject {

[DllImport (Constants.ARKitLibrary)]
static extern /* ar_data_providers_t */ IntPtr ar_data_providers_create ();

[DllImport (Constants.ARKitLibrary)]
static extern void ar_data_providers_add_data_provider (IntPtr data_providers, IntPtr data_provider_to_add);

[DllImport (Constants.ARKitLibrary)]
static extern void ar_data_providers_add_data_providers (IntPtr data_providers, IntPtr data_providers_to_add);

[DllImport (Constants.ARKitLibrary)]
static extern void ar_data_providers_remove_data_provider (IntPtr data_providers, IntPtr data_provider_to_remove);

[DllImport (Constants.ARKitLibrary)]
static extern void ar_data_providers_remove_data_providers (IntPtr data_providers, IntPtr data_providers_to_remove);

[DllImport (Constants.ARKitLibrary)]
static extern /* size_t */ nuint ar_data_providers_get_count (IntPtr data_providers);

[DllImport (Constants.ARKitLibrary)]
unsafe static extern void ar_data_providers_enumerate_data_providers_f (
IntPtr data_providers,
void* context,
delegate* unmanaged<void*, IntPtr, byte> enumerator);

[Preserve (Conditional = true)]
internal ARDataProviders (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

/// <summary>Creates a new empty collection of data providers.</summary>
public ARDataProviders ()
: base (ar_data_providers_create (), owns: true)
{
}

/// <summary>Gets the number of data providers in this collection.</summary>
public nuint Count {
get {
return ar_data_providers_get_count (GetCheckedHandle ());
}
}

/// <summary>Adds a data provider to this collection.</summary>
public void Add (ARDataProvider dataProvider)
{
if (dataProvider is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dataProvider));
ar_data_providers_add_data_provider (GetCheckedHandle (), dataProvider.GetCheckedHandle ());
GC.KeepAlive (dataProvider);
}

/// <summary>Adds all data providers from another collection to this collection.</summary>
public void Add (ARDataProviders dataProviders)
{
if (dataProviders is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dataProviders));
ar_data_providers_add_data_providers (GetCheckedHandle (), dataProviders.GetCheckedHandle ());
GC.KeepAlive (dataProviders);
}

/// <summary>Removes a data provider from this collection.</summary>
public void Remove (ARDataProvider dataProvider)
{
if (dataProvider is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dataProvider));
ar_data_providers_remove_data_provider (GetCheckedHandle (), dataProvider.GetCheckedHandle ());
GC.KeepAlive (dataProvider);
}

/// <summary>Removes all data providers from another collection from this collection.</summary>
public void Remove (ARDataProviders dataProviders)
{
if (dataProviders is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (dataProviders));
ar_data_providers_remove_data_providers (GetCheckedHandle (), dataProviders.GetCheckedHandle ());
GC.KeepAlive (dataProviders);
}

/// <summary>Returns all data providers in this collection as an array.</summary>
public ARDataProvider [] GetDataProviders ()
{
var results = new List<ARDataProvider> ();
unsafe {
delegate* unmanaged<void*, IntPtr, byte> callback = &EnumerateCallback;
var handle = GCHandle.Alloc (results);
try {
ar_data_providers_enumerate_data_providers_f (GetCheckedHandle (), (void*) GCHandle.ToIntPtr (handle), callback);
} finally {
handle.Free ();
}
}
return results.ToArray ();
}

[UnmanagedCallersOnly]
unsafe static byte EnumerateCallback (void* context, IntPtr data_provider)
{
var handle = GCHandle.FromIntPtr ((IntPtr) context);
var results = (List<ARDataProvider>) handle.Target!;
results.Add (new ARDataProvider (data_provider, owns: false));
return 1; // continue
}
}
}

#endif // __MACOS__
Loading
Loading