From 17f87a44e8b19244be3ad403be90540635b7cb0d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 28 Dec 2018 12:19:33 +0900 Subject: [PATCH 1/3] Remove JsonSchemaValidationContext.Push --- UniGLTF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UniGLTF b/UniGLTF index a59f6438e..232818e03 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit a59f6438ec560c356a9bbb1517d95877e85927f4 +Subproject commit 232818e03cb9ee703dc5ced5aae82e95ceeef2ce From 5c7e7b06274bb8869fbbb036a9863c8d7f4f7195 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 28 Dec 2018 14:47:19 +0900 Subject: [PATCH 2/3] Fixed build error #93 --- Scripts/Format/VRMImporterContext.cs | 30 ++++++++++++++-------------- UniGLTF | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Scripts/Format/VRMImporterContext.cs b/Scripts/Format/VRMImporterContext.cs index f84e28480..04b336208 100644 --- a/Scripts/Format/VRMImporterContext.cs +++ b/Scripts/Format/VRMImporterContext.cs @@ -17,20 +17,6 @@ namespace VRM { } - public override bool IsOverwrite(UnityEngine.Object o) - { - if(o is BlendShapeAvatar) - { - return false; - } - if(o is BlendShapeClip) - { - return false; - } - - return base.IsOverwrite(o); - } - public override void Parse(string path, byte[] bytes) { var ext = Path.GetExtension(path).ToLower(); @@ -332,7 +318,6 @@ namespace VRM return meta; } -#if UNITY_EDITOR protected override IEnumerable ObjectsForSubAsset() { foreach (var x in base.ObjectsForSubAsset()) @@ -355,6 +340,21 @@ namespace VRM yield return Meta; } +#if UNITY_EDITOR + public override bool IsOverwrite(UnityEngine.Object o) + { + if (o is BlendShapeAvatar) + { + return false; + } + if (o is BlendShapeClip) + { + return false; + } + + return base.IsOverwrite(o); + } + protected override UnityPath GetAssetPath(UnityPath prefabPath, UnityEngine.Object o) { if (o is BlendShapeAvatar diff --git a/UniGLTF b/UniGLTF index 232818e03..690847a1a 160000 --- a/UniGLTF +++ b/UniGLTF @@ -1 +1 @@ -Subproject commit 232818e03cb9ee703dc5ced5aae82e95ceeef2ce +Subproject commit 690847a1a5a0bd3df55187e1f1cb6f338c09225b From 6d5e3f871d3c8a351d428099b306ec738a3f4dd0 Mon Sep 17 00:00:00 2001 From: TORISOUP Date: Fri, 28 Dec 2018 20:25:26 +0900 Subject: [PATCH 3/3] optimize comparing struct in dictionary key --- Scripts/BlendShape/BlendShapeBindingMerger.cs | 9 ++-- Scripts/BlendShape/BlendShapeClip.cs | 51 +++++++++++++++++-- .../BlendShape/MaterialValueBindingMerger.cs | 20 +++++++- 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/Scripts/BlendShape/BlendShapeBindingMerger.cs b/Scripts/BlendShape/BlendShapeBindingMerger.cs index 9de217d35..fdd41b71f 100644 --- a/Scripts/BlendShape/BlendShapeBindingMerger.cs +++ b/Scripts/BlendShape/BlendShapeBindingMerger.cs @@ -9,7 +9,7 @@ namespace VRM /// class BlendShapeBindingMerger { - class BlendShapeBindingComparer : IEqualityComparer + class DictionaryKeyBlendShapeBindingComparer : IEqualityComparer { public bool Equals(BlendShapeBinding x, BlendShapeBinding y) { @@ -22,19 +22,22 @@ namespace VRM return obj.RelativePath.GetHashCode() + obj.Index; } } + + private static DictionaryKeyBlendShapeBindingComparer comparer = new DictionaryKeyBlendShapeBindingComparer(); + /// /// BlendShapeの適用値を蓄積する /// /// /// /// - Dictionary m_blendShapeValueMap = new Dictionary(new BlendShapeBindingComparer()); + Dictionary m_blendShapeValueMap = new Dictionary(comparer); /// /// /// /// - Dictionary> m_blendShapeSetterMap = new Dictionary>(); + Dictionary> m_blendShapeSetterMap = new Dictionary>(comparer); public BlendShapeBindingMerger(Dictionary clipMap, Transform root) { diff --git a/Scripts/BlendShape/BlendShapeClip.cs b/Scripts/BlendShape/BlendShapeClip.cs index 6f3a5f3a2..4902902d7 100644 --- a/Scripts/BlendShape/BlendShapeClip.cs +++ b/Scripts/BlendShape/BlendShapeClip.cs @@ -4,8 +4,8 @@ using UnityEngine; namespace VRM { - [Serializable] - public struct BlendShapeBinding + [Serializable] + public struct BlendShapeBinding : IEquatable { public String RelativePath; public int Index; @@ -15,15 +15,60 @@ namespace VRM { return string.Format("{0}[{1}]=>{2}", RelativePath, Index, Weight); } + + public bool Equals(BlendShapeBinding other) + { + return string.Equals(RelativePath, other.RelativePath) && Index == other.Index && Weight.Equals(other.Weight); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is BlendShapeBinding && Equals((BlendShapeBinding)obj); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = (RelativePath != null ? RelativePath.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ Index; + hashCode = (hashCode * 397) ^ Weight.GetHashCode(); + return hashCode; + } + } } [Serializable] - public struct MaterialValueBinding + public struct MaterialValueBinding : IEquatable { public String MaterialName; public String ValueName; public Vector4 TargetValue; public Vector4 BaseValue; + + public bool Equals(MaterialValueBinding other) + { + return string.Equals(MaterialName, other.MaterialName) && string.Equals(ValueName, other.ValueName) && TargetValue.Equals(other.TargetValue) && BaseValue.Equals(other.BaseValue); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + return obj is MaterialValueBinding && Equals((MaterialValueBinding)obj); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = (MaterialName != null ? MaterialName.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ (ValueName != null ? ValueName.GetHashCode() : 0); + hashCode = (hashCode * 397) ^ TargetValue.GetHashCode(); + hashCode = (hashCode * 397) ^ BaseValue.GetHashCode(); + return hashCode; + } + } } [CreateAssetMenu(menuName = "VRM/BlendShapeClip")] diff --git a/Scripts/BlendShape/MaterialValueBindingMerger.cs b/Scripts/BlendShape/MaterialValueBindingMerger.cs index f626e483d..0ec9e5b36 100644 --- a/Scripts/BlendShape/MaterialValueBindingMerger.cs +++ b/Scripts/BlendShape/MaterialValueBindingMerger.cs @@ -11,6 +11,22 @@ namespace VRM /// class MaterialValueBindingMerger { + + struct DictionaryKeyMaterialValueBindingComparer : IEqualityComparer + { + public bool Equals(MaterialValueBinding x, MaterialValueBinding y) + { + return x.TargetValue == y.TargetValue && x.BaseValue == y.BaseValue && x.MaterialName == y.MaterialName && x.ValueName == y.ValueName; + } + + public int GetHashCode(MaterialValueBinding obj) + { + return obj.GetHashCode(); + } + } + + static DictionaryKeyMaterialValueBindingComparer comparer = new DictionaryKeyMaterialValueBindingComparer(); + /// /// 名前とmaterialのマッピング /// @@ -24,9 +40,9 @@ namespace VRM /// /// /// - Dictionary m_materialValueMap = new Dictionary(); + Dictionary m_materialValueMap = new Dictionary(comparer); - Dictionary m_materialSetterMap = new Dictionary(); + Dictionary m_materialSetterMap = new Dictionary(comparer); //BlendShapeClip[] m_clips;