// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) (2018-2023) Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% namespace UnityEngine.XR.MagicLeap { using System; using System.Runtime.InteropServices; using UnityEngine.XR.MagicLeap.Native; using static UnityEngine.XR.MagicLeap.Native.MagicLeapNativeBindings; public partial class MLSpace { /// /// Maximum size for the name of a Magic Leap Space. /// public const uint MaxSpaceNameLength = 64; /// /// A structure containing settings for the space manager. /// This structure must be initialized by calling #MLSpaceManagerSettingsInit before use. /// [StructLayout(LayoutKind.Sequential)] public struct Settings { /// /// Version of this settings. /// public uint Version; /// /// Initializes default values for MLSpaceManagerSettings. /// public static Settings Create(uint version = 1) { return new Settings { Version = version, }; } } /// /// A structure containing information about a Magic Leap Space. /// This structure must be initialized by calling #MLSpaceInit before use. /// [StructLayout(LayoutKind.Sequential)] public struct Space { /// /// Version of the structure. /// public uint Version; /// /// Name of the Space. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)MaxSpaceNameLength)] public string SpaceName; /// /// Unique ID of the Space. /// public MLUUID SpaceId; /// /// Type of the Space. /// public Type SpaceType; /// /// Initializes default values for MLSpace. /// public static Space Create(uint version = 1u) { return new Space { Version = version, }; } } /// /// A structure containing list of #MLSpace. /// This structure must be initialized by calling #MLSpaceListInit before use. /// [StructLayout(LayoutKind.Sequential)] public readonly struct SpaceList { /// /// Version of the structure. /// public readonly uint Version; /// /// Number of Magic Leap Spaces. /// public readonly uint SpaceCount; /// /// List of Magic Leap Spaces. /// public readonly IntPtr Spaces; /// /// Initializes default values for MLSpaceList. /// SpaceList(uint version = 1u) { Version = version; SpaceCount = 0; Spaces = default; } } /// /// A collection of filters for Magic Leap Spaces. /// This structure must be initialized by calling #MLSpaceQueryFilterInit before use. /// There is no support for filters at this time. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceFilter { /// /// Version of the structure. /// public uint Version; /// /// Initializes the default values for a query filter (currently not supported). /// public static SpaceFilter Create(uint version = 1u) { return new SpaceFilter { Version = version, }; } } /// /// A collection of parameters to be used for localization request. /// This structure must be initialized by calling #MLSpaceLocalizationInfoInit before use. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceLocalizationInfo { /// /// Version of the structure. /// public uint Version; /// /// #MLUUID of the Space into which the device attempts to localize into. /// public MLUUID SpaceId; /// /// Initializes the default values for localization info. /// public static SpaceLocalizationInfo Create(uint version = 1u) { return new SpaceLocalizationInfo { Version = version, }; } } /// /// A structure containing information about the device's localization state. /// This structure must be initialized by calling #MLSpaceLocalizationResultInit before usebefore use. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceLocalizationResult { /// /// Version of the structure. /// public uint Version; /// /// The localization status at the time this structure was returned. /// public readonly Status LocalizationStatus; /// /// Space information. /// If localized(#MLSpaceLocalizationStatus_Localized) this will contain valid Space information. /// If not localized this field should be ignored. /// public readonly Space Space; /// /// Target space's origin relative to world origin. /// If localized this will contain the identifier of the transform of the target space's origin relative to the world origin. /// If not localized this will be null. /// public readonly NativeBindings.MLCoordinateFrameUID TargetSpaceOrigin; /// /// The confidence level of this localization result. /// public readonly LocalizationConfidence ConfidenceOfLocalization; /// /// Represents a bitmask of LocalizationErrorFlag. /// public readonly uint Error; /// /// Initialize default values for #MLSpaceLocalizationResult. /// public static SpaceLocalizationResult Create(uint version = 3u) { return new SpaceLocalizationResult { Version = version, }; } } /// /// A structure containing information about the device's localization state. /// public struct LocalizationResult { /// /// The localization status at the time this structure was returned. /// public Status LocalizationStatus; /// /// Space information. /// If localized(#MLSpaceLocalizationStatus_Localized) this will contain valid Space information. /// If not localized this field should be ignored. /// public Space Space; /// /// Target space's origin relative to world origin. /// If localized this will contain the identifier of the transform of the target space's origin relative to the world origin. /// If not localized this will be null. /// public NativeBindings.MLCoordinateFrameUID TargetSpaceOrigin; /// /// The confidence level of this localization result. /// public LocalizationConfidence ConfidenceOfLocalization; /// /// Represents a bitmask of LocalizationErrorFlag. /// public LocalizationErrorFlag Error; internal static LocalizationResult CreateFromSpaceLocalizationResult(SpaceLocalizationResult spaceLocalizationResult) { var localizedResult = new LocalizationResult { ConfidenceOfLocalization = spaceLocalizationResult.ConfidenceOfLocalization, LocalizationStatus = spaceLocalizationResult.LocalizationStatus, Space = spaceLocalizationResult.Space, TargetSpaceOrigin = spaceLocalizationResult.TargetSpaceOrigin, Error = (LocalizationErrorFlag) spaceLocalizationResult.Error, }; return localizedResult; } } /// /// A structure containing callbacks for events related to the Space. /// This structure must be initialized by calling #MLSpaceCallbacksInit before use. /// Application can unregister(stop receiving callbacks) at any time by setting /// the corresponding callback to NULL. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceCallbacks { /// /// Version of the structure. /// public uint Version; /// /// This callback will be invoked whenever there is an update to the localization status. /// Localization events can occur when the application requests for localization /// via #MLSpaceRequestLocalization or due to other events outside the control of /// the app such as head tracking failure, localization loss. /// public MLSpaceDelegate OnLocalizationChangedCallbacks; /// /// Initialize default values for #SpaceCallbacks. /// public static SpaceCallbacks Create(uint version = 1u) { return new SpaceCallbacks { Version = version, OnLocalizationChangedCallbacks = LocalizationChanged, }; } } /// /// A structure containing information needed to import Magic Leap Space. /// This structure must be initialized by calling #MLSpaceImportInfoInit before use. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceImportInfo { /// /// Version of the structure. /// public uint Version; /// /// Binary data size in bytes. /// public ulong Size; /// /// Binary data obtained from #MLSpaceExportSpace. /// public IntPtr Data; /// /// Initialize default values for #SpaceImportInfo. /// public static SpaceImportInfo Create(uint version = 1u) { return new SpaceImportInfo { Version = version, Size = 0u, Data = IntPtr.Zero, }; } } /// /// A structure containing information about the imported Space. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceImportOutData { /// /// Unique ID of the imported Space. /// public MLUUID SpaceId; } /// /// A structure containing information about the Space export settings. /// This structure must be initialized by calling #MLSpaceExportInfoInit before use. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceExportInfo { /// /// Version of the structure. /// public uint Version; /// /// #MLUUID of the Space that needs to be exported. /// public MLUUID SpaceId; /// /// Initialize default values for #SpaceExportInfo. /// public static SpaceExportInfo Create(uint version = 1u) { return new SpaceExportInfo { Version = version, }; } } /// /// A structure containing information about the exported Space. /// [StructLayout(LayoutKind.Sequential)] public struct SpaceExportOutData { /// /// Binary data size in bytes. /// public readonly ulong Size; /// /// Space data. /// This is binary data and typically does not include a terminating null /// character. /// public IntPtr Data; public static SpaceExportOutData Create() { return new SpaceExportOutData() { Data = IntPtr.Zero, }; } public static byte[] GetData(SpaceExportOutData data) { if (data.Data == IntPtr.Zero) return null; byte[] bytes = MLConvert.MarshalUnmanagedArray(data.Data, (int)data.Size); return bytes; } } /// /// Space data used when importing a space. /// public struct SpaceData { /// /// Size of space data in bytes. /// public ulong Size; /// /// Binary space data. /// public byte[] Data; } /// /// Space data returned when we successfully import space. /// public struct SpaceInfo { public MLUUID SpaceId; } } }