Skip to content

Instantly share code, notes, and snippets.

@kaorun55

kaorun55/FaceMove.cs

Created May 29, 2015
Embed
What would you like to do?
using UnityEngine;
using System.Collections;
using RSUnityToolkit;
public class FaceMove : MonoBehaviour
{
public SkinnedMeshRenderer MTH_DEF;
public SkinnedMeshRenderer EYE_DEF;
public SkinnedMeshRenderer EL_DEF;
// Use this for initialization
void Start()
{
// SenseToolkitManagerを探して、なけば作る
var senseManager = GameObject.FindObjectOfType( typeof( SenseToolkitManager ) );
if ( senseManager == null ) {
Debug.LogWarning( "Sense Manager Object not found and was added automatically" );
senseManager = (GameObject)Instantiate( Resources.Load( "SenseManager" ) );
senseManager.name = "SenseManager";
}
// 顔の機能を有効にする
SenseToolkitManager.Instance.SetSenseOption( SenseOption.SenseOptionID.Face );
}
// Update is called once per frame
void Update()
{
if ( SenseToolkitManager.Instance.FaceModuleOutput==null ) {
return;
}
// 検出した顔の一覧を取得する
var faces = SenseToolkitManager.Instance.FaceModuleOutput.QueryFaces();
if ( faces.Length == 0 ) {
return;
}
// 最初の顔の表情を取得する
var face = faces[0];
var expression = face.QueryExpressions();
if ( expression==null ) {
return;
}
// 口を動かす
if ( MTH_DEF != null ) {
PXCMFaceData.ExpressionsData.FaceExpressionResult result;
expression.QueryExpression( PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_MOUTH_OPEN, out result );
MTH_DEF.SetBlendShapeWeight( 6, (int)(result.intensity * 1.5) );
}
// 目と眉を動かす
if ( (EYE_DEF != null) && (EL_DEF != null) ) {
PXCMFaceData.ExpressionsData.FaceExpressionResult left;
expression.QueryExpression( PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_CLOSED_LEFT, out left );
PXCMFaceData.ExpressionsData.FaceExpressionResult right;
expression.QueryExpression( PXCMFaceData.ExpressionsData.FaceExpression.EXPRESSION_EYES_CLOSED_RIGHT, out right );
var value = (int)((left.intensity + right.intensity) / 2);
EYE_DEF.SetBlendShapeWeight( 6, value );
EL_DEF.SetBlendShapeWeight( 6, value );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.