mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-15 23:20:10 -05:00
Merge pull request #330 from Kohei-Yanagida/feature_suppress_blendshape_gc
suppress blendshape gabage collection
This commit is contained in:
commit
03f96bdc55
|
|
@ -12,16 +12,31 @@ namespace VRM
|
|||
{
|
||||
var key = new BlendShapeKey("Blink", BlendShapePreset.Blink);
|
||||
|
||||
Assert.AreEqual(key, new BlendShapeKey("blink"));
|
||||
Assert.AreEqual(key, new BlendShapeKey("Blink", BlendShapePreset.Blink));
|
||||
Assert.AreEqual(key, new BlendShapeKey(BlendShapePreset.Blink));
|
||||
Assert.AreEqual(key, new BlendShapeKey("xxx", BlendShapePreset.Blink));
|
||||
|
||||
var dict = new Dictionary<BlendShapeKey, float>();
|
||||
dict[new BlendShapeKey("xxx", BlendShapePreset.Blink)] = 1.0f;
|
||||
dict[key] = 1.0f;
|
||||
|
||||
Assert.IsTrue(dict.ContainsKey(new BlendShapeKey("blink")));
|
||||
Assert.IsTrue(dict.ContainsKey(new BlendShapeKey("Blink",BlendShapePreset.Blink)));
|
||||
Assert.IsTrue(dict.ContainsKey(new BlendShapeKey(BlendShapePreset.Blink)));
|
||||
Assert.IsTrue(dict.ContainsKey(new BlendShapeKey("xxx", BlendShapePreset.Blink)));
|
||||
|
||||
dict.Clear();
|
||||
|
||||
var key2 = new BlendShapeKey("Blink"); // name: Blink, Preset: Unknown
|
||||
dict[key2] = 1.0f;
|
||||
|
||||
Assert.AreEqual( key2, new BlendShapeKey("Blink", BlendShapePreset.Unknown));
|
||||
Assert.AreNotEqual(key2, new BlendShapeKey("blink"));
|
||||
Assert.AreNotEqual(key2, new BlendShapeKey("Blink", BlendShapePreset.Blink));
|
||||
Assert.AreNotEqual(key2, new BlendShapeKey(BlendShapePreset.Blink));
|
||||
|
||||
Assert.IsFalse(dict.ContainsKey(new BlendShapeKey("blink")));
|
||||
Assert.IsFalse(dict.ContainsKey(new BlendShapeKey("Blink",BlendShapePreset.Blink)));
|
||||
Assert.IsFalse(dict.ContainsKey(new BlendShapeKey(BlendShapePreset.Blink)));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,34 @@
|
|||
using System;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
[Serializable]
|
||||
public struct BlendShapeKey : IEquatable<BlendShapeKey>, IComparable<BlendShapeKey>
|
||||
{
|
||||
public string Name;
|
||||
/// <summary>
|
||||
/// Enum.ToString() のGC回避用キャッシュ
|
||||
/// </summary>
|
||||
private static readonly Dictionary<BlendShapePreset, string> m_presetNameDictionary =
|
||||
new Dictionary<BlendShapePreset, string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// BlendShapePresetと同名の名前を持つ独自に追加したBlendShapeを区別するためのprefix
|
||||
/// </summary>
|
||||
private static readonly string UnknownPresetPrefix = "Unknown_";
|
||||
|
||||
private string m_name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name.ToUpper(); }
|
||||
}
|
||||
|
||||
public BlendShapePreset Preset;
|
||||
|
||||
string m_id;
|
||||
|
||||
string ID
|
||||
{
|
||||
get
|
||||
|
|
@ -18,42 +37,56 @@ namespace VRM
|
|||
{
|
||||
if (Preset != BlendShapePreset.Unknown)
|
||||
{
|
||||
m_id = Preset.ToString().ToUpper();
|
||||
if (m_presetNameDictionary.ContainsKey(Preset))
|
||||
{
|
||||
m_id = m_presetNameDictionary[Preset];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_presetNameDictionary.Add(Preset, Preset.ToString());
|
||||
m_id = m_presetNameDictionary[Preset];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_id = Name;
|
||||
m_id = UnknownPresetPrefix + m_name;
|
||||
}
|
||||
}
|
||||
|
||||
return m_id;
|
||||
}
|
||||
}
|
||||
|
||||
public BlendShapeKey(string name) : this(name, BlendShapePreset.Unknown)
|
||||
public BlendShapeKey(BlendShapePreset preset) : this(preset.ToString(), preset)
|
||||
{
|
||||
}
|
||||
|
||||
public BlendShapeKey(BlendShapePreset preset) : this(preset.ToString(), BlendShapePreset.Unknown)
|
||||
public BlendShapeKey(string name, BlendShapePreset preset = BlendShapePreset.Unknown)
|
||||
{
|
||||
}
|
||||
|
||||
public BlendShapeKey(string name, BlendShapePreset preset)
|
||||
{
|
||||
Name = name.ToUpper();
|
||||
m_name = name;
|
||||
Preset = preset;
|
||||
|
||||
if (Preset != BlendShapePreset.Unknown)
|
||||
{
|
||||
m_id = Preset.ToString().ToUpper();
|
||||
if (m_presetNameDictionary.ContainsKey((Preset)))
|
||||
{
|
||||
m_id = m_presetNameDictionary[Preset];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_presetNameDictionary.Add(Preset, Preset.ToString());
|
||||
m_id = m_presetNameDictionary[Preset];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_id = Name;
|
||||
m_id = UnknownPresetPrefix + m_name;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ID;
|
||||
return ID.Replace(UnknownPresetPrefix, "").ToUpper();
|
||||
}
|
||||
|
||||
public bool Equals(BlendShapeKey other)
|
||||
|
|
@ -65,7 +98,7 @@ namespace VRM
|
|||
{
|
||||
if (obj is BlendShapeKey)
|
||||
{
|
||||
return Equals((BlendShapeKey)obj);
|
||||
return Equals((BlendShapeKey) obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -84,6 +117,7 @@ namespace VRM
|
|||
{
|
||||
return default(BlendShapeKey);
|
||||
}
|
||||
|
||||
return new BlendShapeKey(clip.BlendShapeName, clip.Preset);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user