using System.Collections.Generic;
using Convai.Scripts.Runtime.Core;
using Convai.Scripts.Runtime.Features.LipSync;
using Convai.Scripts.Runtime.Features.LipSync.Models;
using Service;
using UnityEngine;
namespace Convai.Scripts.Runtime.Features
{
///
/// This Class will serve as a base for any method of Lipsync that Convai will develop or use
///
public abstract class ConvaiLipSyncApplicationBase : MonoBehaviour
{
///
/// Reference to the NPC on which lipsync will be applied
///
protected ConvaiNPC ConvaiNPC;
///
/// Cached Reference of Facial Expression Data
///
protected FacialExpressionData FacialExpressionData;
///
/// Cached Reference of WeightBlendingPower
///
protected float WeightBlendingPower;
///
/// Initializes and setup up of the things necessary for lipsync to work
///
///
///
public virtual void Initialize(ConvaiLipSync convaiLipSync, ConvaiNPC convaiNPC)
{
FacialExpressionData = convaiLipSync.FacialExpressionData;
WeightBlendingPower = convaiLipSync.WeightBlendingPower;
HasHeadSkinnedMeshRenderer = FacialExpressionData.Head.Renderer != null;
HasTeethSkinnedMeshRenderer = FacialExpressionData.Teeth.Renderer != null;
HasTongueSkinnedMeshRenderer = FacialExpressionData.Tongue.Renderer != null;
HasJawBone = FacialExpressionData.JawBone != null;
HasTongueBone = FacialExpressionData.TongueBone != null;
ConvaiNPC = convaiNPC;
}
///
/// Updates the tongue bone rotation to the new rotation
///
///
protected void UpdateTongueBoneRotation(Vector3 newRotation)
{
if (!HasTongueBone) return;
FacialExpressionData.TongueBone.transform.localEulerAngles = newRotation;
}
///
/// Updates the jaw bone rotation to the new rotation
///
///
protected void UpdateJawBoneRotation(Vector3 newRotation)
{
if (!HasJawBone) return;
FacialExpressionData.JawBone.transform.localEulerAngles = newRotation;
}
///
/// This removes the excess frames in the queue
///
public abstract void PurgeExcessBlendShapeFrames();
///
/// This resets the whole queue of the frames
///
protected bool CanPurge(Queue queue)
{
// ? Should I hardcode the limiter for this check
return queue.Count < 10;
}
public abstract void ClearQueue();
///
/// Adds blendshape frames in the queue
///
///
public virtual void EnqueueQueue(Queue blendshapeFrames)
{
}
///
/// Adds Visemes frames in the list
///
///
public virtual void EnqueueQueue(Queue visemesFrames)
{
}
///
/// Adds a blendshape frame in the last queue
///
///
public virtual void EnqueueFrame(ARKitBlendShapes blendshapeFrame)
{
}
///
/// Adds a viseme frame to the last element of the list
///
///
public virtual void EnqueueFrame(VisemesData viseme)
{
}
#region Null States of References
protected bool HasHeadSkinnedMeshRenderer { get; private set; }
protected bool HasTeethSkinnedMeshRenderer { get; private set; }
protected bool HasTongueSkinnedMeshRenderer { get; private set; }
private bool HasJawBone { get; set; }
private bool HasTongueBone { get; set; }
#endregion
}
}