|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.XR; |
|
|
|
using UnityEngine.Serialization; |
|
|
|
using UnityEngine.XR.ARFoundation; |
|
|
|
using UnityEngine.XR.ARKit; |
|
|
|
|
|
|
|
|
|
|
public class ARFaceArkitBlendShapeVisualizer : MonoBehaviour |
|
|
|
{ |
|
|
|
[SerializeField] |
|
|
|
float coefficientScale = 100.0f; |
|
|
|
float m_CoefficientScale = 100.0f; |
|
|
|
SkinnedMeshRenderer skinnedMeshRenderer = null; |
|
|
|
SkinnedMeshRenderer m_SkinnedMeshRenderer; |
|
|
|
ARKitFaceSubsystem arkitFaceSubsystem; |
|
|
|
ARKitFaceSubsystem m_ArkitFaceSubsystem; |
|
|
|
|
|
|
|
|
|
|
|
public SkinnedMeshRenderer skinnedMeshRenderer |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return m_SkinnedMeshRenderer; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
m_SkinnedMeshRenderer = value; |
|
|
|
CreateFeatureBlendMapping(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public float coefficientScale |
|
|
|
{ |
|
|
|
get { return m_CoefficientScale; } |
|
|
|
set { m_CoefficientScale = value; } |
|
|
|
} |
|
|
|
|
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
s_FaceArkitBlendShapeCoefficients = new List<XRFaceArkitBlendShapeCoefficient>(); |
|
|
|
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
{ |
|
|
|
arkitFaceSubsystem = (ARKitFaceSubsystem) ARSubsystemManager.faceSubsystem; |
|
|
|
if (arkitFaceSubsystem == null ) |
|
|
|
m_ArkitFaceSubsystem = (ARKitFaceSubsystem) ARSubsystemManager.faceSubsystem; |
|
|
|
if (m_ArkitFaceSubsystem == null ) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void UpdateFaceFeatures() |
|
|
|
{ |
|
|
|
if (skinnedMeshRenderer == null || !skinnedMeshRenderer.enabled) |
|
|
|
if (skinnedMeshRenderer == null || !skinnedMeshRenderer.enabled || skinnedMeshRenderer.sharedMesh == null) |
|
|
|
if (!arkitFaceSubsystem.TryGetFaceARKitBlendShapeCoefficients(m_Face.xrFace.trackableId,s_FaceArkitBlendShapeCoefficients)) |
|
|
|
if (!m_ArkitFaceSubsystem.TryGetFaceARKitBlendShapeCoefficients(m_Face.xrFace.trackableId,s_FaceArkitBlendShapeCoefficients)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|