public VRM10ControllerEditorExpression(VRM10Controller target)
        {
            m_target = target;

            m_expressionKeyWeights = m_target.Vrm.Expression.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f);
            m_sliders = m_target.Vrm.Expression.Clips
                        .Where(x => x != null)
                        .Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x)))
                        .ToList()
            ;
        }
Beispiel #2
0
        public float GetCustomValue(String key)
        {
            var expressionKey = ExpressionKey.CreateCustom(key);

            if (this.expressionKeyWeights.ContainsKey(expressionKey))
            {
                return(this.expressionKeyWeights[expressionKey]);
            }
            else
            {
                return(0.0f);
            }
        }
Beispiel #3
0
        public float GetPresetValue(VrmLib.ExpressionPreset key)
        {
            var expressionKey = new ExpressionKey(key);

            if (this.expressionKeyWeights.ContainsKey(expressionKey))
            {
                return(this.expressionKeyWeights[expressionKey]);
            }
            else
            {
                return(0.0f);
            }
        }
Beispiel #4
0
        private void AccumulateValue(ExpressionKey key, float value)
        {
            m_valueMap[key] = value;

            VRM10Expression clip;

            if (!m_clipMap.TryGetValue(key, out clip))
            {
                return;
            }

            m_morphTargetBindingMerger.AccumulateValue(clip, value);
            m_materialValueBindingMerger.AccumulateValue(clip, value);
        }
        /// <summary>
        /// 即時に反映しない。後にApplyによって反映する
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void AccumulateValue(ExpressionKey key, float value)
        {
            m_valueMap[key] = value;

            VRM10Expression clip;

            if (!m_clipMap.TryGetValue(key, out clip))
            {
                return;
            }

            if (clip.IsBinary)
            {
                value = Mathf.Round(value);
            }

            m_morphTargetBindingMerger.AccumulateValue(clip, value);
            m_materialValueBindingMerger.AccumulateValue(clip, value);
        }
Beispiel #6
0
        public void SetClip(ExpressionKey key, VRM10Expression clip)
        {
            int index = -1;

            try
            {
                index = Clips.FindIndex(x => key.Match(x));
            }
            catch (Exception)
            {
            }
            if (index == -1)
            {
                Clips.Add(clip);
            }
            else
            {
                Clips[index] = clip;
            }
        }
Beispiel #7
0
        public override string GetInfoString()
        {
            var expression = CurrentExpression();

            if (expression == null)
            {
                return("no expression");
            }

            var key = ExpressionKey.CreateFromClip(expression);

            if (key.Preset != VrmLib.ExpressionPreset.Custom)
            {
                return(string.Format("Preset: {0}", key.Preset));
            }
            else
            {
                return(string.Format("Custom: {0}", key.Name));
            }
        }
        void OnEnable()
        {
            m_target = (VRM10Controller)target;

            m_expressionKeyWeights = m_target.Expression.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f);
            m_sliders = m_target.Expression.Clips
                        .Where(x => x != null)
                        .Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x)))
                        .ToList()
            ;

            if (m_target?.Meta.Meta != null)
            {
                m_metaEditor = Editor.CreateEditor(m_target.Meta.Meta);
            }
            m_controller  = PropGui.FromObject(serializedObject, nameof(m_target.Controller));
            m_meta        = PropGui.FromObject(serializedObject, nameof(m_target.Meta));
            m_expression  = PropGui.FromObject(serializedObject, nameof(m_target.Expression));
            m_lookAt      = PropGui.FromObject(serializedObject, nameof(m_target.LookAt));
            m_firstPerson = PropGui.FromObject(serializedObject, nameof(m_target.FirstPerson));
        }
        void Restore()
        {
            var assetPath = UnityPath.FromAsset(this);
            if (assetPath.IsNull)
            {
                return;
            }


            foreach (var x in assetPath.Parent.ChildFiles)
            {
                var clip = UnityEditor.AssetDatabase.LoadAssetAtPath<VRM10Expression>(x.Value);
                if (clip == null) continue;

                if (!Clips.Contains(clip))
                {
                    Clips.Add(clip);
                }

                Debug.LogFormat("{0}", clip.name);
            }
            Clips = Clips.OrderBy(x => ExpressionKey.CreateFromClip(x)).ToList();
        }
Beispiel #10
0
        public static void SetPresetValue(this IExpressionAccumulator self, VrmLib.ExpressionPreset key, float value)
        {
            var expressionKey = new ExpressionKey(key);

            self.SetValue(expressionKey, value);
        }
 public ExpressionSlider(Dictionary <ExpressionKey, float> expressionKeys, ExpressionKey key)
 {
     m_expressionKeys = expressionKeys;
     m_key            = key;
 }
Beispiel #12
0
 IEnumerable <SubAssetKey> EnumerateExpressinKeys(UniGLTF.Extensions.VRMC_vrm.Expressions expressions)
 {
     if (expressions?.Preset?.Happy != null)
     {
         yield return(ExpressionKey.Happy.SubAssetKey);
     }
     if (expressions?.Preset?.Angry != null)
     {
         yield return(ExpressionKey.Angry.SubAssetKey);
     }
     if (expressions?.Preset?.Sad != null)
     {
         yield return(ExpressionKey.Sad.SubAssetKey);
     }
     if (expressions?.Preset?.Relaxed != null)
     {
         yield return(ExpressionKey.Relaxed.SubAssetKey);
     }
     if (expressions?.Preset?.Surprised != null)
     {
         yield return(ExpressionKey.Surprised.SubAssetKey);
     }
     if (expressions?.Preset?.Aa != null)
     {
         yield return(ExpressionKey.Aa.SubAssetKey);
     }
     if (expressions?.Preset?.Ih != null)
     {
         yield return(ExpressionKey.Ih.SubAssetKey);
     }
     if (expressions?.Preset?.Ou != null)
     {
         yield return(ExpressionKey.Ou.SubAssetKey);
     }
     if (expressions?.Preset?.Ee != null)
     {
         yield return(ExpressionKey.Ee.SubAssetKey);
     }
     if (expressions?.Preset?.Oh != null)
     {
         yield return(ExpressionKey.Oh.SubAssetKey);
     }
     if (expressions?.Preset?.Blink != null)
     {
         yield return(ExpressionKey.Blink.SubAssetKey);
     }
     if (expressions?.Preset?.BlinkLeft != null)
     {
         yield return(ExpressionKey.BlinkLeft.SubAssetKey);
     }
     if (expressions?.Preset?.BlinkRight != null)
     {
         yield return(ExpressionKey.BlinkRight.SubAssetKey);
     }
     if (expressions?.Preset?.LookUp != null)
     {
         yield return(ExpressionKey.LookUp.SubAssetKey);
     }
     if (expressions?.Preset?.LookDown != null)
     {
         yield return(ExpressionKey.LookDown.SubAssetKey);
     }
     if (expressions?.Preset?.LookLeft != null)
     {
         yield return(ExpressionKey.LookLeft.SubAssetKey);
     }
     if (expressions?.Preset?.LookRight != null)
     {
         yield return(ExpressionKey.LookRight.SubAssetKey);
     }
     foreach (var kv in expressions.Custom)
     {
         yield return(ExpressionKey.CreateCustom(kv.Key).SubAssetKey);
     }
 }
 /// <summary>
 /// initilaize
 /// </summary>
 /// <param name="avatar"></param>
 public void OnStart(VRM10ExpressionAvatar avatar)
 {
     m_clipMap            = avatar.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => x);
     expressionKeyWeights = m_clipMap.Keys.ToDictionary(x => x, x => 0.0f);
 }
 public VRM10Expression GetClip(ExpressionKey key)
 {
     if (Clips == null) return null;
     return Clips.FirstOrDefault(x => key.Match(x));
 }
Beispiel #15
0
        public static void SetCustomValue(this IExpressionAccumulator self, string key, float value)
        {
            var expressionKey = ExpressionKey.CreateCustom(key);

            self.SetValue(expressionKey, value);
        }
Beispiel #16
0
        public static float GetCustomValue(this IExpressionAccumulator self, string key)
        {
            var expressionKey = ExpressionKey.CreateCustom(key);

            return(self.GetValue(expressionKey));
        }
Beispiel #17
0
        public static float GetPresetValue(this IExpressionAccumulator self, VrmLib.ExpressionPreset key)
        {
            var expressionKey = new ExpressionKey(key);

            return(self.GetValue(expressionKey));
        }
        void OnEnable()
        {
            m_target = (VRM10Controller)target;
            if (m_target.Expression.ExpressionAvatar != null && m_target.Expression.ExpressionAvatar.Clips != null)
            {
                m_expressionKeyWeights = m_target.Expression.ExpressionAvatar.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f);
                m_sliders = m_target.Expression.ExpressionAvatar.Clips
                            .Where(x => x != null)
                            .Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x)))
                            .ToList()
                ;
            }

            if (m_target.Meta)
            {
                m_metaEditor = Editor.CreateEditor(m_target.Meta);
            }
            m_controller  = serializedObject.FindProperty(nameof(m_target.Controller));
            m_expression  = serializedObject.FindProperty(nameof(m_target.Expression));
            m_lookAt      = serializedObject.FindProperty(nameof(m_target.LookAt));
            m_firstPerson = serializedObject.FindProperty(nameof(m_target.FirstPerson));
            m_asset       = serializedObject.FindProperty(nameof(m_target.ModelAsset));
        }