Skip to content

Commit

Permalink
Merge pull request hecomi#27 from mkc1370/feature/add_vrm_expression_…
Browse files Browse the repository at this point in the history
…sample

Add vrm expression sample
  • Loading branch information
hecomi authored Dec 27, 2022
2 parents 8a3423b + e110e33 commit 96f979c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using UnityEditor;
using UnityEditorInternal;
using System.Linq;
using UniVRM10;
using VRM;

namespace uLipSync
{

[CustomEditor(typeof(uLipSyncExpressionVRM))]
public class uLipSyncExpressionVRMEditor : uLipSyncBlendShapeEditor
{
uLipSyncExpressionVRM expression { get { return target as uLipSyncExpressionVRM; } }
Vrm10Instance vrm10Instance;

void OnEnable()
{
vrm10Instance = expression.GetComponent<Vrm10Instance>();
}

public override void OnInspectorGUI()
{
serializedObject.Update();

if (EditorUtil.Foldout("LipSync Update Method", true))
{
++EditorGUI.indentLevel;
EditorUtil.DrawProperty(serializedObject, nameof(expression.updateMethod));
--EditorGUI.indentLevel;
EditorGUILayout.Separator();
}

if (EditorUtil.Foldout("Parameters", true))
{
++EditorGUI.indentLevel;
DrawParameters();
--EditorGUI.indentLevel;
EditorGUILayout.Separator();
}

if (EditorUtil.Foldout("Blend Shapes", true))
{
++EditorGUI.indentLevel;
DrawBlendShapeReorderableList();
--EditorGUI.indentLevel;
EditorGUILayout.Separator();
}

serializedObject.ApplyModifiedProperties();
}

protected override string[] GetBlendShapeArray()
{
if (!vrm10Instance || !vrm10Instance.Vrm) return new string[] { "" };

return vrm10Instance.Vrm.Expression.Clips.Select(x => x.Clip.name).ToArray();
}
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Assets/uLipSync/Samples/04. VRM/Runtime/uLipSyncExpressionVRM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Linq;
using UnityEngine;
using UniVRM10;

namespace uLipSync
{

[ExecuteAlways]
[RequireComponent(typeof(Vrm10Instance))]
public class uLipSyncExpressionVRM : uLipSyncBlendShape
{
protected override void OnApplyBlendShapes()
{
var vrm10Instance = GetComponent<Vrm10Instance>();
if (!vrm10Instance || !vrm10Instance.Vrm) return;

var clips = vrm10Instance.Vrm.Expression.Clips.ToArray();
foreach (var bs in blendShapes)
{
var index = bs.index + 1;
if (index < 0 || index >= clips.Length) continue;
var clip = clips[index];
var weight = bs.weight * bs.maxWeight * volume;
vrm10Instance.Runtime.Expression.SetWeight(new ExpressionKey(clip.Preset, clip.Clip.name), weight);
}
}
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96f979c

Please sign in to comment.