diff --git a/Assets/VRM_Samples/BlendShapeMenu/AddBlankForPerfectSync.cs b/Assets/VRM_Samples/BlendShapeMenu/BlendShapeMenu.cs
similarity index 60%
rename from Assets/VRM_Samples/BlendShapeMenu/AddBlankForPerfectSync.cs
rename to Assets/VRM_Samples/BlendShapeMenu/BlendShapeMenu.cs
index c5eff8cb5..7cbdc8ee4 100644
--- a/Assets/VRM_Samples/BlendShapeMenu/AddBlankForPerfectSync.cs
+++ b/Assets/VRM_Samples/BlendShapeMenu/BlendShapeMenu.cs
@@ -1,4 +1,5 @@
-using System.Text;
+using System.IO;
+using System.Text;
using UnityEditor;
using UnityEngine;
@@ -62,6 +63,21 @@ namespace VRM.Sample.BlendShapeMenu
"TongueOut",
};
+ ///
+ /// fullpath C:/path/to/project/Assets/some.preset to Assets/some.preset
+ ///
+ ///
+ static string ToUnityPath(string src)
+ {
+ if (!src.StartsWith(Application.dataPath))
+ {
+ // not in Assets
+ throw new System.Exception("not in Assets");
+ }
+
+ return "Assets" + src.Substring(Application.dataPath.Length);
+ }
+
[MenuItem("CONTEXT/BlendShapeAvatar/Add ARKit FaceTracking BlendShapes")]
public static void AddARKitFaceTrackingBlendShapes(MenuCommand command)
{
@@ -82,14 +98,7 @@ namespace VRM.Sample.BlendShapeMenu
return;
}
- if (!dir.StartsWith(Application.dataPath))
- {
- // not in Assets
- EditorUtility.DisplayDialog("error", "folder is not in Assets", "ok");
- return;
- }
-
- var assetDir = "Assets" + dir.Substring(Application.dataPath.Length);
+ var assetDir = ToUnityPath(dir);
var sb = new StringBuilder();
foreach (var name in NAMES)
{
@@ -114,7 +123,58 @@ namespace VRM.Sample.BlendShapeMenu
avatar.Clips.Add(clip);
}
- Debug.Log(sb.ToString());
+ Debug.Log("Create\n" + sb.ToString());
+ }
+
+ [MenuItem("CONTEXT/BlendShapeAvatar/Assign all BlendShapes in a folder")]
+ static void AssginAllBlendShapesInAFolder(MenuCommand command)
+ {
+ // Debug.Log(command.context);
+ var avatar = command.context as BlendShapeAvatar;
+ if (avatar == null)
+ {
+ Debug.LogError("no context");
+ return;
+ }
+ var assetPath = AssetDatabase.GetAssetPath(avatar);
+
+ var dir = EditorUtility.SaveFolderPanel("blendshape folder", assetPath, "");
+ if (string.IsNullOrEmpty(dir))
+ {
+ // cancel
+ return;
+ }
+
+ var assetDir = ToUnityPath(dir);
+ var sb = new StringBuilder();
+ foreach (var f in Directory.EnumerateFiles(dir))
+ {
+ var extension = Path.GetExtension(f).ToLower();
+ if (extension != ".asset")
+ {
+ // not asset
+ continue;
+ }
+
+ var clipPath = ToUnityPath(f);
+ if (clipPath == null)
+ {
+ // not BlendShapeClip
+ continue;
+ }
+
+ var clip = AssetDatabase.LoadAssetAtPath(clipPath);
+ if (avatar.Clips.Contains(clip))
+ {
+ // already exists
+ continue;
+ }
+
+ sb.AppendLine(clipPath);
+ avatar.Clips.Add(clip);
+ }
+
+ Debug.Log($"Assign\n" + sb.ToString());
}
}
}
diff --git a/Assets/VRM_Samples/BlendShapeMenu/AddBlankForPerfectSync.cs.meta b/Assets/VRM_Samples/BlendShapeMenu/BlendShapeMenu.cs.meta
similarity index 100%
rename from Assets/VRM_Samples/BlendShapeMenu/AddBlankForPerfectSync.cs.meta
rename to Assets/VRM_Samples/BlendShapeMenu/BlendShapeMenu.cs.meta