Skip to content

Instantly share code, notes, and snippets.

@mfmfuyu
Last active December 6, 2022 10:25
Show Gist options
  • Save mfmfuyu/5dee0fcbb5ee273cd7963464d3eb584e to your computer and use it in GitHub Desktop.
Save mfmfuyu/5dee0fcbb5ee273cd7963464d3eb584e to your computer and use it in GitHub Desktop.
using System.IO;
using UniGLTF;
using UnityEditor;
using UnityEngine;
using VRM;
/**
* Assets/Editor/CreatePSBlendshapes.cs
* Use at your own risk
*
* Tested on UniVRM v0.99.2 / Unity 2019.4.31f1
*/
public class CreatePSBlendshapes : EditorWindow
{
private readonly string[] _names =
{
"BrowDownLeft",
"BrowDownRight",
"BrowInnerUp",
"BrowOuterUpLeft",
"BrowOuterUpRight",
"CheekPuff",
"CheekSquintLeft",
"CheekSquintRight",
"EyeBlinkLeft",
"EyeBlinkRight",
"EyeLookDownLeft",
"EyeLookDownRight",
"EyeLookInLeft",
"EyeLookInRight",
"EyeLookOutLeft",
"EyeLookOutRight",
"EyeLookUpLeft",
"EyeLookUpRight",
"EyeSquintLeft",
"EyeSquintRight",
"EyeWideLeft",
"EyeWideRight",
"JawForward",
"JawLeft",
"JawOpen",
"JawRight",
"MouthClose",
"MouthDimpleLeft",
"MouthDimpleRight",
"MouthFrownLeft",
"MouthFrownRight",
"MouthFunnel",
"MouthLeft",
"MouthLowerDownLeft",
"MouthLowerDownRight",
"MouthPressLeft",
"MouthPressRight",
"MouthPucker",
"MouthRight",
"MouthRollLower",
"MouthRollUpper",
"MouthShrugLower",
"MouthShrugUpper",
"MouthSmileLeft",
"MouthSmileRight",
"MouthStretchLeft",
"MouthStretchRight",
"MouthUpperUpLeft",
"MouthUpperUpRight",
"NoseSneerLeft",
"NoseSneerRight",
"TongueOut"
};
private BlendShapeAvatar _avatar;
[MenuItem("Tools/VRM/Create Perfect Sync Blendshapes")]
public static void Init()
{
var window = GetWindow<CreatePSBlendshapes>();
window.Show();
}
private void OnGUI()
{
_avatar = EditorGUILayout.ObjectField(_avatar, typeof(BlendShapeAvatar), false) as BlendShapeAvatar;
if (GUILayout.Button("Create Perfect Sync Blendshapes!"))
{
if (!_avatar) return;
var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(_avatar));
var path = EditorUtility.SaveFolderPanel(
"Create Perfect Sync BlendShapeClip",
dir,
"");
if (string.IsNullOrEmpty(path)) return;
foreach (string name in _names) {
var clip = BlendShapeAvatar.CreateBlendShapeClip(path.ToUnityRelativePath() + "/" + name + ".asset");
_avatar.Clips.Add(clip);
}
EditorUtility.SetDirty(_avatar);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment