// %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%
using UnityEngine.XR.MagicLeap.Native;
namespace UnityEngine.XR.MagicLeap
{
using System;
using System.Runtime.InteropServices;
public partial class MLFacialExpression
{
///
/// See ml_facial_expression.h for additional comments.
///
private class NativeBindings : Native.MagicLeapNativeBindings
{
///
/// Number of eye expression types.
///
const int MLFacialExpressionEyeExpressionTypeCount = 12;
///
/// A structure containing settings for the facial expressions.
/// This structure must be initialized by calling #MLFacialExpressionSettingsInit before use.
/// (And calling ZeroStruct on our side.)
///
[StructLayout(LayoutKind.Sequential)]
public struct MLFacialExpressionSettings
{
///
/// Version of this settings
///
public uint Version;
///
/// Enable MLFacialExpressionEyeData.
/// If true, facial expressions will detect #MLFacialExpressionEyeData and the same can queried using
/// MLFacialExpressionGetEyeData. This should be disabled when app does not need facial expression data.
///
public bool EnableEyeExpression;
public static MLFacialExpressionSettings Init(uint version = 1)
{
return new MLFacialExpressionSettings
{
Version = version,
EnableEyeExpression = true
};
}
}
///
/// A structure containing information about eye expressions.
/// This structure must be initialized by calling MLFacialExpressionEyeDataInit before use.
///
[StructLayout(LayoutKind.Sequential)]
public struct MLFacialExpressionEyeData
{
///
/// Version of the structure.
///
public uint Version;
///
/// The MLTime timestamp when expression data was updated.
///
public long Timestamp;
///
/// An array of floats of size eye_expression_count. The values are between 0
/// and 1 and ordered such that the array can be indexed using
/// MLFacialExpressionEyeExpressionType.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MLFacialExpressionEyeExpressionTypeCount)]
public float[] EyeExpressionWeights;
public static MLFacialExpressionEyeData Init(uint version = 1)
{
return new MLFacialExpressionEyeData
{
Version = version,
};
}
}
///
/// Creates a Facial Expression Client handle. Although multiple client handles
/// can be created they all represent the same facial expressions backend system.
///
/// API Level 29
/// permissions com.magicleap.permission.FACIAL_EXPRESSION (protection level: dangerous)
///
/// Settings that configures the facial expressions system.
///
///
/// The handle to be created.
///
///
/// MLResult.Code.InvalidParam: One or more input parameters are not valid.
/// MLResult.Code.Ok: Facial expressions client was successfully created.
/// MLResult.Code.PerceptionSystemNotStarted: Perception System has not been started.
/// MLResult.Code.PermissionDenied: Necessary permission is missing.
/// MLResult.Code.UnspecifiedFailure: Operation failed for unknown reason.
///
[DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLFacialExpressionCreateClient(ref MLFacialExpressionSettings settings, out ulong handle);
///
/// Update the Facial Expression system with new settings
///
/// API Level 29
/// permissions None
///
/// Handle Facial expressions client handle created by MLFacialExpressionCreateClient.
///
///
/// Settings New Facial Expression settings..
///
///
/// MLResult.Code.InvalidParam: One or more input parameters are not valid.
/// MLResult.Code.Ok: Facial expression settings was updated successfully.
/// MLResult.Code.PerceptionSystemNotStarted: Perception System has not been started.
/// MLResult.Code.UnspecifiedFailure: Operation failed for unknown reason.
///
[DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLFacialExpressionUpdateSettings(ulong handle, in MLFacialExpressionSettings settings);
///
/// Get facial expressions data.
/// handle Facial expression client handle created by MLFacialExpressionCreateClient.
/// API Level 29
/// permissions None
///
///
/// Facial expressions client handle created by MLFacialExpressionCreateClient.
///
///
/// Eye expressions data.
///
///
/// MLResult.Code.InvalidParam: One or more input parameters are not valid.
/// MLResult.Code.Ok: Facial expressions data was retrieved successfully.
/// MLResult.Code.PerceptionSystemNotStarted: Perception System has not been started.
/// MLResult.Code.UnspecifiedFailure: Operation failed for unknown reason.
/// MLResult.Code.HeadsetFitIssue: Operation failed because unable to detect the eyes, check MLHeadsetFitStatus.
///
[DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLFacialExpressionGetEyeData(ulong handle, out MLFacialExpressionEyeData eye_data);
///
/// Destroy client handle and free client resources.
/// API Level 29
/// permissions None
///
///
/// Facial expression client handle created by MLFacialExpressionCreateClient.
///
///
/// MLResult.Code.InvalidParam: One or more input parameters are not valid.
/// MLResult.Code.Ok: Client handle was successfully destroyed.
/// MLResult.Code.PerceptionSystemNotStarted: Perception System has not been started.
/// MLResult.Code.UnspecifiedFailure: Operation failed for unknown reason.
///
[DllImport(MLPerceptionClientDll, CallingConvention = CallingConvention.Cdecl)]
public static extern MLResult.Code MLFacialExpressionDestroyClient(ulong handle);
}
}
}