forked from hecomi/uLipSync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hecomi#27 from mkc1370/feature/add_vrm_expression_…
…sample Add vrm expression sample
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
Assets/uLipSync/Samples/04. VRM/Editor/uLipSyncExpressionVRMEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Assets/uLipSync/Samples/04. VRM/Editor/uLipSyncExpressionVRMEditor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
Assets/uLipSync/Samples/04. VRM/Runtime/uLipSyncExpressionVRM.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Assets/uLipSync/Samples/04. VRM/Runtime/uLipSyncExpressionVRM.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.