Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 2.51 KB

File metadata and controls

62 lines (44 loc) · 2.51 KB

WindowsMixedRealityUtilities

Namespace: Microsoft.MixedReality.Toolkit.WindowsMixedReality
Type: WindowsMixedRealityUtilities

MRTK provides already-marshalled types across both legacy WSA and XR SDK through the WindowsMixedRealityUtilities class.

public static HolographicFrame CurrentHolographicFrame { get; }
public static SpatialCoordinateSystem SpatialCoordinateSystem { get; }
public static SpatialInteractionManager SpatialInteractionManager { get; }

WindowsMREnvironment

Namespace: UnityEngine.XR.WindowsMR
Type: WindowsMREnvironment

The static WindowsMREnvironment class provides access to several native pointers.

public static IntPtr CurrentHolographicRenderFrame { get; } // Windows::Graphics::Holographic::IHolographicFrame
public static IntPtr HolographicSpace { get; } // Windows::Graphics::Holographic::IHolographicSpace
public static IntPtr OriginSpatialCoordinateSystem { get; } // Windows::Perception::Spatial::ISpatialCoordinateSystem

XRDevice

Namespace: UnityEngine.XR
Type: XRDevice

The XRDevice type allows you to get access to underlying native objects using the GetNativePtr method. What GetNativePtr returns varies between different platforms. On the Universal Windows Platform when targeting Windows Mixed Reality, XRDevice.GetNativePtr returns a pointer (IntPtr) to the following structure:

using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
struct HolographicFrameNativeData
{
    public uint VersionNumber;
    public uint MaxNumberOfCameras;
    public IntPtr ISpatialCoordinateSystemPtr; // Windows::Perception::Spatial::ISpatialCoordinateSystem
    public IntPtr IHolographicFramePtr; // Windows::Graphics::Holographic::IHolographicFrame
    public IntPtr IHolographicCameraPtr; // Windows::Graphics::Holographic::IHolographicCamera
}

You can convert it to HolographicFrameNativeData using Marshal.PtrToStructure method:

IntPtr nativePtr = UnityEngine.XR.XRDevice.GetNativePtr();
HolographicFrameNativeData hfd = Marshal.PtrToStructure<HolographicFrameNativeData>(nativePtr);

IHolographicCameraPtr is an array of IntPtr marshaled as UnmanagedType.ByValArray with a length equal to MaxNumberOfCameras