add package files
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
//========= Copyright 2019, HTC Corporation. All rights reserved. ===========
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.OpenXR;
|
||||
namespace VIVE
|
||||
{
|
||||
namespace FacialTracking.Sample
|
||||
{
|
||||
public class Lip
|
||||
{
|
||||
public const int WeightingCount = (int)XrLipShapeHTC.XR_LIP_SHAPE_MAX_ENUM_HTC;
|
||||
private static int LastUpdateFrame = -1;
|
||||
private static Error LastUpdateResult = Error.FAILED;
|
||||
private static Dictionary<XrLipShapeHTC, float> Weightings;
|
||||
private static float[] blendshapes = new float[60];
|
||||
private static XrFacialExpressionsHTC LipExpression;
|
||||
|
||||
static Lip()
|
||||
{
|
||||
Weightings = new Dictionary<XrLipShapeHTC, float>();
|
||||
for (int i = 0; i < WeightingCount; ++i) Weightings.Add((XrLipShapeHTC)i, 0.0f);
|
||||
}
|
||||
|
||||
private static bool UpdateData()
|
||||
{
|
||||
if (Time.frameCount == LastUpdateFrame) return LastUpdateResult == Error.WORK;
|
||||
else LastUpdateFrame = Time.frameCount;
|
||||
LipExpression.expressionCount = 60;
|
||||
LipExpression.type = XrStructureType.XR_TYPE_FACIAL_EXPRESSIONS_HTC;
|
||||
LipExpression.blendShapeWeightings = Marshal.AllocCoTaskMem(sizeof(float)* LipExpression.expressionCount);
|
||||
var feature = OpenXRSettings.Instance.GetFeature<VIVE_FacialTracking_OpenXR_API>();
|
||||
int res = feature.xrGetFacialExpressionsHTC(OpenXRSettings.Instance.GetFeature<VIVE_FacialTracking_OpenXR_API>().m_expressionHandle_Lip, ref LipExpression);
|
||||
|
||||
|
||||
if(res == (int)XrResult.XR_SUCCESS)
|
||||
{
|
||||
LastUpdateResult = Error.WORK;
|
||||
Marshal.Copy(LipExpression.blendShapeWeightings, blendshapes,0, LipExpression.expressionCount);
|
||||
for (int i = 0; i < WeightingCount; ++i)
|
||||
{
|
||||
Weightings[(XrLipShapeHTC)(i)] = blendshapes[i];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LastUpdateResult = Error.FAILED;
|
||||
}
|
||||
return LastUpdateResult == Error.WORK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets weighting values from Lip module.
|
||||
/// </summary>
|
||||
/// <param name="shapes">Weighting values obtained from Lip module.</param>
|
||||
/// <returns>Indicates whether the values received are new.</returns>
|
||||
[Obsolete("Create FacialManager object and call member function GetWeightings instead")]
|
||||
public static bool GetLipWeightings(out Dictionary<XrLipShapeHTC, float> shapes)
|
||||
{
|
||||
bool update = UpdateData();
|
||||
shapes = Weightings;
|
||||
return update;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8bc508f7f051e624181e0391cf04db7f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
//========= Copyright 2019, HTC Corporation. All rights reserved. ===========
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VIVE
|
||||
{
|
||||
namespace FacialTracking.Sample
|
||||
{
|
||||
public enum LipShape
|
||||
{
|
||||
None = -1,
|
||||
Jaw_Right = 0,
|
||||
Jaw_Left = 1,
|
||||
Jaw_Forward = 2,
|
||||
Jaw_Open = 3,
|
||||
Mouth_Ape_Shape = 4,
|
||||
Mouth_Upper_Right = 5,
|
||||
Mouth_Upper_Left = 6,
|
||||
Mouth_Lower_Right = 7,
|
||||
Mouth_Lower_Left = 8,
|
||||
Mouth_Upper_Overturn = 9,
|
||||
Mouth_Lower_Overturn = 10,
|
||||
Mouth_Pout = 11,
|
||||
Mouth_Smile_Right = 12,
|
||||
Mouth_Smile_Left = 13,
|
||||
Mouth_Sad_Right = 14,
|
||||
Mouth_Sad_Left = 15,
|
||||
Cheek_Puff_Right = 16,
|
||||
Cheek_Puff_Left = 17,
|
||||
Cheek_Suck = 18,
|
||||
Mouth_Upper_UpRight = 19,
|
||||
Mouth_Upper_UpLeft = 20,
|
||||
Mouth_Lower_DownRight = 21,
|
||||
Mouth_Lower_DownLeft = 22,
|
||||
Mouth_Upper_Inside = 23,
|
||||
Mouth_Lower_Inside = 24,
|
||||
Mouth_Lower_Overlay = 25,
|
||||
Tongue_LongStep1 = 26,
|
||||
Tongue_LongStep2 = 32,
|
||||
Tongue_Down = 30,
|
||||
Tongue_Up = 29,
|
||||
Tongue_Right = 28,
|
||||
Tongue_Left = 27,
|
||||
Tongue_Roll = 31,
|
||||
Tongue_UpLeft_Morph = 34,
|
||||
Tongue_UpRight_Morph = 33,
|
||||
Tongue_DownLeft_Morph = 36,
|
||||
Tongue_DownRight_Morph = 35,
|
||||
Max = 37,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PredictionData
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 60)]
|
||||
public float[] blend_shape_weight;
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct LipData
|
||||
{
|
||||
public int frame;
|
||||
public int time;
|
||||
public IntPtr image;
|
||||
public PredictionData prediction_data;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44593dc2ec4dd36449dfb356ce482a0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
//========= Copyright 2019, HTC Corporation. All rights reserved. ===========
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
namespace VIVE
|
||||
{
|
||||
namespace FacialTracking.Sample
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(LipShapeTable))]
|
||||
public class LipShapeTableDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
Rect newFieldPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
newFieldPosition.height = EditorGUIUtility.singleLineHeight;
|
||||
Rect newLabelPosition = position;
|
||||
newLabelPosition.width -= newFieldPosition.width;
|
||||
newLabelPosition.height = newFieldPosition.height;
|
||||
SerializedProperty propSkinedMesh = property.FindPropertyRelative("skinnedMeshRenderer");
|
||||
SerializedProperty propLipShapes = property.FindPropertyRelative("lipShapes");
|
||||
EditorGUI.PropertyField(newFieldPosition, propSkinedMesh, GUIContent.none);
|
||||
newFieldPosition.y += EditorGUIUtility.singleLineHeight;
|
||||
|
||||
SkinnedMeshRenderer skinnedMesh = propSkinedMesh.objectReferenceValue as SkinnedMeshRenderer;
|
||||
if (skinnedMesh != null && skinnedMesh.sharedMesh.blendShapeCount > 0)
|
||||
{
|
||||
if (propLipShapes.arraySize != skinnedMesh.sharedMesh.blendShapeCount)
|
||||
{
|
||||
propLipShapes.arraySize = skinnedMesh.sharedMesh.blendShapeCount;
|
||||
for (int i = 0; i < skinnedMesh.sharedMesh.blendShapeCount; ++i)
|
||||
{
|
||||
SerializedProperty propLipShape = propLipShapes.GetArrayElementAtIndex(i);
|
||||
string elementName = skinnedMesh.sharedMesh.GetBlendShapeName(i);
|
||||
|
||||
propLipShape.intValue = (int)XrLipShapeHTC.XR_LIP_SHAPE_NONE_HTC;
|
||||
foreach (XrLipShapeHTC lipShape in (XrLipShapeHTC[])Enum.GetValues(typeof(XrLipShapeHTC)))
|
||||
{
|
||||
if (elementName == lipShape.ToString())
|
||||
propLipShape.intValue = (int)lipShape;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < skinnedMesh.sharedMesh.blendShapeCount; ++i)
|
||||
{
|
||||
SerializedProperty propLipShape = propLipShapes.GetArrayElementAtIndex(i);
|
||||
newLabelPosition.y = newFieldPosition.y;
|
||||
string elementName = skinnedMesh.sharedMesh.GetBlendShapeName(i);
|
||||
EditorGUI.LabelField(newLabelPosition, " " + elementName);
|
||||
EditorGUI.PropertyField(newFieldPosition, propLipShape, GUIContent.none);
|
||||
newFieldPosition.y += EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
int LineCount = 1;
|
||||
SerializedProperty propSkinedMesh = property.FindPropertyRelative("skinnedMeshRenderer");
|
||||
SkinnedMeshRenderer skinnedMesh = propSkinedMesh.objectReferenceValue as SkinnedMeshRenderer;
|
||||
if (skinnedMesh != null) LineCount += skinnedMesh.sharedMesh.blendShapeCount;
|
||||
return EditorGUIUtility.singleLineHeight * LineCount;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91324d258827df746818399b9a51d4d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
//========= Copyright 2019, HTC Corporation. All rights reserved. ===========
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.OpenXR;
|
||||
|
||||
namespace VIVE
|
||||
{
|
||||
namespace FacialTracking.Sample
|
||||
{
|
||||
public class Lip_Framework : MonoBehaviour
|
||||
{
|
||||
public enum FrameworkStatus { STOP, START, WORKING, ERROR }
|
||||
/// <summary>
|
||||
/// The status of the Lip engine.
|
||||
/// </summary>
|
||||
public static FrameworkStatus Status { get; protected set; }
|
||||
/// <summary>
|
||||
/// Whether to enable Lip module.
|
||||
/// </summary>
|
||||
public bool EnableLip = true;
|
||||
|
||||
private static Lip_Framework Mgr = null;
|
||||
public static Lip_Framework Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Mgr == null)
|
||||
{
|
||||
Mgr = FindObjectOfType<Lip_Framework>();
|
||||
}
|
||||
if (Mgr == null)
|
||||
{
|
||||
Debug.LogError("Lip_Framework not found");
|
||||
}
|
||||
return Mgr;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
StartFramework();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
StopFramework();
|
||||
}
|
||||
[Obsolete("Create FacialManager object and call member function StartFramework instead")]
|
||||
|
||||
private void StartFramework()
|
||||
{
|
||||
if (!EnableLip) return;
|
||||
if (Status == FrameworkStatus.WORKING) return;
|
||||
|
||||
Status = FrameworkStatus.START;
|
||||
|
||||
Debug.Log("Starting to Initial Lip Engine");
|
||||
XrFacialTrackerCreateInfoHTC m_expressioncreateInfo = new XrFacialTrackerCreateInfoHTC(
|
||||
XrStructureType.XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC,
|
||||
IntPtr.Zero,
|
||||
XrFacialTrackingTypeHTC.XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
|
||||
var feature = OpenXRSettings.Instance.GetFeature<VIVE_FacialTracking_OpenXR_API>();
|
||||
int res = (int)feature.xrCreateFacialTrackerHTC(m_expressioncreateInfo, out OpenXRSettings.Instance.GetFeature<VIVE_FacialTracking_OpenXR_API>().m_expressionHandle_Lip);
|
||||
if (res == (int)XrResult.XR_SUCCESS || res == (int)XrResult.XR_SESSION_LOSS_PENDING)
|
||||
{
|
||||
Debug.Log("Initial Lip Engine :" + res);
|
||||
Status = FrameworkStatus.WORKING;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Initial Lip Engine :" + res);
|
||||
Status = FrameworkStatus.ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
[Obsolete("Create FacialManager object and call member function StopFramework instead")]
|
||||
|
||||
public void StopFramework()
|
||||
{
|
||||
if (Status != FrameworkStatus.STOP)
|
||||
{
|
||||
var feature = OpenXRSettings.Instance.GetFeature<VIVE_FacialTracking_OpenXR_API>();
|
||||
int res = feature.xrDestroyFacialTrackerHTC(OpenXRSettings.Instance.GetFeature<VIVE_FacialTracking_OpenXR_API>().m_expressionHandle_Lip);
|
||||
if (res == (int)XrResult.XR_SUCCESS)
|
||||
{
|
||||
Debug.Log("Release Lip Engine : " + res);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Release Lip Engine : " + res);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Stop Lip Framework : module not on");
|
||||
}
|
||||
Status = FrameworkStatus.STOP;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41f6d745d46210a49a0df9fe7d0d1102
|
||||
timeCreated: 1545375801
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 846f91cae57562348bd10c1617b45b13
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
//========= Copyright 2019, HTC Corporation. All rights reserved. ===========
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VIVE
|
||||
{
|
||||
namespace FacialTracking.Sample
|
||||
{
|
||||
[Serializable]
|
||||
public class LipShapeTable
|
||||
{
|
||||
public SkinnedMeshRenderer skinnedMeshRenderer;
|
||||
public XrLipShapeHTC[] lipShapes;
|
||||
}
|
||||
public class AvatarLipSample : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<LipShapeTable> LipShapeTables;
|
||||
|
||||
public bool NeededToGetData = true;
|
||||
private Dictionary<XrLipShapeHTC, float> LipWeightings;
|
||||
private FacialManager facialManager = new FacialManager();
|
||||
private void Start()
|
||||
{
|
||||
facialManager.StartFramework(XrFacialTrackingTypeHTC.XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
|
||||
SetLipShapeTables(LipShapeTables);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (NeededToGetData)
|
||||
{
|
||||
facialManager.GetWeightings(out LipWeightings);
|
||||
//Lip.GetLipWeightings(out LipWeightings);
|
||||
UpdateLipShapes(LipWeightings);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLipShapeTables(List<LipShapeTable> lipShapeTables)
|
||||
{
|
||||
bool valid = true;
|
||||
if (lipShapeTables == null)
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int table = 0; table < lipShapeTables.Count; ++table)
|
||||
{
|
||||
if (lipShapeTables[table].skinnedMeshRenderer == null)
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
for (int shape = 0; shape < lipShapeTables[table].lipShapes.Length; ++shape)
|
||||
{
|
||||
XrLipShapeHTC lipShape = lipShapeTables[table].lipShapes[shape];
|
||||
if (lipShape > XrLipShapeHTC.XR_LIP_SHAPE_MAX_ENUM_HTC || lipShape < 0)
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (valid)
|
||||
LipShapeTables = lipShapeTables;
|
||||
}
|
||||
|
||||
public void UpdateLipShapes(Dictionary<XrLipShapeHTC, float> lipWeightings)
|
||||
{
|
||||
foreach (var table in LipShapeTables)
|
||||
RenderModelLipShape(table, lipWeightings);
|
||||
}
|
||||
|
||||
private void RenderModelLipShape(LipShapeTable lipShapeTable, Dictionary<XrLipShapeHTC, float> weighting)
|
||||
{
|
||||
for (int i = 0; i < lipShapeTable.lipShapes.Length; i++)
|
||||
{
|
||||
int targetIndex = (int)lipShapeTable.lipShapes[i];
|
||||
if (targetIndex > (int)XrLipShapeHTC.XR_LIP_SHAPE_MAX_ENUM_HTC || targetIndex < 0) continue;
|
||||
lipShapeTable.skinnedMeshRenderer.SetBlendShapeWeight(i, weighting[(XrLipShapeHTC)targetIndex] * 100);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
facialManager.StopFramework(XrFacialTrackingTypeHTC.XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42350b51669fc604cb2cad73c39f116c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
//========= Copyright 2019, HTC Corporation. All rights reserved. ===========
|
||||
using UnityEngine;
|
||||
|
||||
namespace VIVE
|
||||
{
|
||||
namespace FacialTracking.Sample
|
||||
{
|
||||
/// <summary>
|
||||
/// A very basic mirror.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Camera))]
|
||||
public class MirrorCameraSample_Lip : MonoBehaviour
|
||||
{
|
||||
private const float Distance = 0.6f;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Lip_Framework.Status != Lip_Framework.FrameworkStatus.WORKING) return;
|
||||
SetMirroTransform();
|
||||
}
|
||||
|
||||
private void SetMirroTransform()
|
||||
{
|
||||
transform.position = Camera.main.transform.position + Camera.main.transform.forward * Distance;
|
||||
transform.position = new Vector3(transform.position.x, Camera.main.transform.position.y, transform.position.z);
|
||||
transform.LookAt(Camera.main.transform);
|
||||
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8dcb8610a1e4fe94a8cc7983d3b650cb
|
||||
timeCreated: 1545375969
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user