ReduceBlendshapeClip

This commit is contained in:
ousttrue 2020-06-02 21:47:59 +09:00
parent 0d35c6df0d
commit 3db0de16bb
2 changed files with 22 additions and 12 deletions

View File

@ -42,12 +42,16 @@ namespace VRM
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
static BlendShapeAvatar CopyBlendShapeAvatar(BlendShapeAvatar src)
static BlendShapeAvatar CopyBlendShapeAvatar(BlendShapeAvatar src, bool removeUnknown)
{
var avatar = GameObject.Instantiate(src);
avatar.Clips = new List<BlendShapeClip>();
foreach (var clip in src.Clips)
{
if (removeUnknown && clip.Preset == BlendShapePreset.Unknown)
{
continue;
}
avatar.Clips.Add(GameObject.Instantiate(clip));
}
return avatar;
@ -128,16 +132,14 @@ namespace VRM
}
}
// 元のBlendShapeClipに変更を加えないように複製
var proxy = target.GetComponent<VRMBlendShapeProxy>();
var copyBlendShapeAvatar = CopyBlendShapeAvatar(proxy.BlendShapeAvatar, settings.ReduceBlendshapeClip);
proxy.BlendShapeAvatar = copyBlendShapeAvatar;
// BlendShape削減
if (settings.ReduceBlendshapeSize)
if (settings.ReduceBlendshape)
{
// remove unused blendShape
var proxy = target.GetComponent<VRMBlendShapeProxy>();
// 元のBlendShapeClipに変更を加えないように複製
var copyBlendShapeAvatar = CopyBlendShapeAvatar(proxy.BlendShapeAvatar);
proxy.BlendShapeAvatar = copyBlendShapeAvatar;
foreach (SkinnedMeshRenderer smr in target.GetComponentsInChildren<SkinnedMeshRenderer>())
{
// 未使用のBlendShapeを間引く
@ -148,7 +150,7 @@ namespace VRM
// 出力
{
var sw = System.Diagnostics.Stopwatch.StartNew();
var vrm = VRMExporter.Export(target, settings.ReduceBlendshapeSize);
var vrm = VRMExporter.Export(target, settings.ReduceBlendshape);
vrm.extensions.VRM.meta.title = settings.Title;
vrm.extensions.VRM.meta.version = settings.Version;
vrm.extensions.VRM.meta.author = settings.Author;

View File

@ -56,12 +56,20 @@ namespace VRM
/// <summary>
/// エクスポート時に新しいJsonSerializerを使う
/// </summary>
[Tooltip("Use new JSON serializer")]
public bool UseExperimentalExporter = false;
/// <summary>
/// エクスポート時にBlendShapeClipから参照されないBlendShapeを削除する
/// </summary>
public bool ReduceBlendshapeSize = false;
[Tooltip("Remove blendshape that is not used from BlendShapeClip")]
public bool ReduceBlendshape = false;
/// <summary>
/// skip if BlendShapeClip.Preset == Unknown
/// </summary>
[Tooltip("Remove blendShapeClip that preset is Unknown")]
public bool ReduceBlendshapeClip = false;
#endregion
public struct Validation
@ -160,7 +168,7 @@ namespace VRM
yield return Validation.Error("Require Author. ");
}
if (ReduceBlendshapeSize && Source.GetComponent<VRMBlendShapeProxy>() == null)
if (ReduceBlendshape && Source.GetComponent<VRMBlendShapeProxy>() == null)
{
yield return Validation.Error("ReduceBlendshapeSize is need VRMBlendShapeProxy, you need to convert to VRM once.");
}