mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 21:34:38 -05:00
add null check
This commit is contained in:
@@ -46,8 +46,6 @@ namespace VRM
|
||||
|
||||
public BlendShapeClipSelector(BlendShapeAvatar avatar, Action<BlendShapeClip> onSelected)
|
||||
{
|
||||
avatar.RemoveNullClip();
|
||||
|
||||
m_avatar = avatar;
|
||||
m_onSelected = onSelected;
|
||||
|
||||
|
||||
@@ -57,6 +57,12 @@ namespace VRM
|
||||
// 参照が生きているか
|
||||
foreach (var c in p.BlendShapeAvatar.Clips)
|
||||
{
|
||||
if (c == null)
|
||||
{
|
||||
yield return Validation.Warning($"BlendShapeName({c.BlendShapeName})'s BlendShapeClip is not found");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < c.Values.Length; ++i)
|
||||
{
|
||||
var v = c.Values[i];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,6 +12,11 @@ namespace VRM
|
||||
{
|
||||
foreach (var c in clips)
|
||||
{
|
||||
if (c == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (onlyPreset)
|
||||
{
|
||||
if (c.Preset == BlendShapePreset.Unknown)
|
||||
@@ -44,7 +50,7 @@ namespace VRM
|
||||
{
|
||||
if (proxy.BlendShapeAvatar != null)
|
||||
{
|
||||
Clips.AddRange(proxy.BlendShapeAvatar.Clips);
|
||||
Clips.AddRange(proxy.BlendShapeAvatar.Clips.Where(x => x != null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,11 @@ namespace VRM
|
||||
avatar.Clips = new List<BlendShapeClip>();
|
||||
foreach (var clip in src.Clips)
|
||||
{
|
||||
if (clip == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (removeUnknown && clip.Preset == BlendShapePreset.Unknown)
|
||||
{
|
||||
continue;
|
||||
@@ -70,7 +75,8 @@ namespace VRM
|
||||
if (mesh.blendShapeCount == 0) return;
|
||||
|
||||
// Mesh から BlendShapeClip からの参照がある blendShape の index を集める
|
||||
var usedBlendshapeIndexArray = copyBlendShapeAvatar.Clips
|
||||
var copyBlendShapeAvatarClips = copyBlendShapeAvatar.Clips.Where(x => x != null).ToArray();
|
||||
var usedBlendshapeIndexArray = copyBlendShapeAvatarClips
|
||||
.SelectMany(clip => clip.Values)
|
||||
.Where(val => target.transform.Find(val.RelativePath) == smr.transform)
|
||||
.Select(val => val.Index)
|
||||
@@ -95,7 +101,7 @@ namespace VRM
|
||||
var indexMapper = usedBlendshapeIndexArray
|
||||
.Select((x, i) => new { x, i })
|
||||
.ToDictionary(pair => pair.x, pair => pair.i);
|
||||
foreach (var clip in copyBlendShapeAvatar.Clips)
|
||||
foreach (var clip in copyBlendShapeAvatarClips)
|
||||
{
|
||||
for (var i = 0; i < clip.Values.Length; ++i)
|
||||
{
|
||||
|
||||
@@ -358,26 +358,26 @@ namespace VRM
|
||||
return;
|
||||
}
|
||||
|
||||
m_merger = new BlendShapeMerger(avatar.Clips, proxy.transform);
|
||||
m_merger = new BlendShapeMerger(avatar.Clips.Where(x => x != null), proxy.transform);
|
||||
|
||||
|
||||
GUILayout.Space(20);
|
||||
|
||||
EditorGUILayout.HelpBox(BlendShapeTabMessages.SCENE_MESSAGE.Msg(), MessageType.Info);
|
||||
|
||||
var options = avatar.Clips.Select(x => x.ToString()).ToArray();
|
||||
var options = avatar.Clips.Where(x => x != null).Select(x => x.ToString()).ToArray();
|
||||
m_selected = EditorGUILayout.Popup("select blendshape", m_selected, options);
|
||||
|
||||
if (GUILayout.Button(BlendShapeTabMessages.APPLY_BLENDSHAPECLIP_BUTTON.Msg()))
|
||||
{
|
||||
m_merger.SetValues(avatar.Clips.Select((x, i) => new KeyValuePair<BlendShapeKey, float>(x.Key, i == m_selected ? 1 : 0)));
|
||||
m_merger.SetValues(avatar.Clips.Where(x => x != null).Select((x, i) => new KeyValuePair<BlendShapeKey, float>(x.Key, i == m_selected ? 1 : 0)));
|
||||
m_merger.Apply();
|
||||
m_settings.PoseFreeze = true;
|
||||
}
|
||||
|
||||
if (GUILayout.Button(BlendShapeTabMessages.CLEAR_BLENDSHAPE_BUTTON.Msg()))
|
||||
{
|
||||
m_merger.SetValues(avatar.Clips.Select(x => new KeyValuePair<BlendShapeKey, float>(x.Key, 0)));
|
||||
m_merger.SetValues(avatar.Clips.Where(x => x != null).Select(x => new KeyValuePair<BlendShapeKey, float>(x.Key, 0)));
|
||||
m_merger.Apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,24 +16,6 @@ namespace VRM
|
||||
[SerializeField]
|
||||
public List<BlendShapeClip> Clips = new List<BlendShapeClip>();
|
||||
|
||||
/// <summary>
|
||||
/// NullのClipを削除して詰める
|
||||
/// </summary>
|
||||
public void RemoveNullClip()
|
||||
{
|
||||
if (Clips == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = Clips.Count - 1; i >= 0; --i)
|
||||
{
|
||||
if (Clips[i] == null)
|
||||
{
|
||||
Clips.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[ContextMenu("Restore")]
|
||||
void Restore()
|
||||
|
||||
@@ -113,6 +113,10 @@ namespace VRM.Samples
|
||||
{
|
||||
var gltfBlendShapeClip = context.VRM.blendShapeMaster.blendShapeGroups[i];
|
||||
var unityBlendShapeClip = blendshapeProxy.BlendShapeAvatar.Clips[i];
|
||||
if (unityBlendShapeClip == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Assert.AreEqual(Enum.Parse(typeof(BlendShapePreset), gltfBlendShapeClip.presetName, true), unityBlendShapeClip.Preset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace VRM.Sample.BlendShapeMenu
|
||||
var sb = new StringBuilder();
|
||||
foreach (var name in NAMES)
|
||||
{
|
||||
if (avatar.Clips.Find(x => x.Preset == BlendShapePreset.Unknown && x.BlendShapeName == name))
|
||||
if (avatar.Clips.Find(x => x != null && x.Preset == BlendShapePreset.Unknown && x.BlendShapeName == name))
|
||||
{
|
||||
// already exists
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user