Esempio n. 1
0
        public void AccumulateValue(VRM10Expression clip, float value)
        {
            // material color
            foreach (var binding in clip.MaterialColorBindings)
            {
                float acc;
                if (m_materialColorMap.TryGetValue(binding, out acc))
                {
                    m_materialColorMap[binding] = acc + value;
                }
                else
                {
                    m_materialColorMap[binding] = value;
                }
            }

            // maetrial uv
            foreach (var binding in clip.MaterialUVBindings)
            {
                Vector4 acc;
                if (!m_materialUVMap.TryGetValue(binding.MaterialName, out acc))
                {
                    acc = DefaultUVScaleOffset;
                }

                var delta = binding.ScalingOffset - DefaultUVScaleOffset;
                m_materialUVMap[binding.MaterialName] = acc + delta * value;
            }
        }
Esempio n. 2
0
        public static ExpressionKey CreateFromClip(VRM10Expression clip)
        {
            if (clip == null)
            {
                return(default(ExpressionKey));
            }

            return(new ExpressionKey(clip.Preset, clip.ExpressionName));
        }
Esempio n. 3
0
        void RaiseSelected(VRM10Expression selected)
        {
            var handler = Selected;

            if (handler == null)
            {
                return;
            }
            handler(selected);
        }
Esempio n. 4
0
 public void AccumulateValue(VRM10Expression clip, float value)
 {
     foreach (var binding in clip.MorphTargetBindings)
     {
         float acc;
         if (m_morphTargetValueMap.TryGetValue(binding, out acc))
         {
             m_morphTargetValueMap[binding] = acc + binding.Weight * value;
         }
         else
         {
             m_morphTargetValueMap[binding] = binding.Weight * value;
         }
     }
 }
Esempio n. 5
0
        public void AddClip(VRM10Expression clip)
        {
            switch (clip.Preset)
            {
            case ExpressionPreset.happy: Happy = clip; break;

            case ExpressionPreset.angry: Angry = clip; break;

            case ExpressionPreset.sad: Sad = clip; break;

            case ExpressionPreset.relaxed: Relaxed = clip; break;

            case ExpressionPreset.surprised: Surprised = clip; break;

            case ExpressionPreset.aa: Aa = clip; break;

            case ExpressionPreset.ih: Ih = clip; break;

            case ExpressionPreset.ou: Ou = clip; break;

            case ExpressionPreset.ee: Ee = clip; break;

            case ExpressionPreset.oh: Oh = clip; break;

            case ExpressionPreset.blink: Blink = clip; break;

            case ExpressionPreset.blinkLeft: BlinkLeft = clip; break;

            case ExpressionPreset.blinkRight: BlinkRight = clip; break;

            case ExpressionPreset.lookUp: LookUp = clip; break;

            case ExpressionPreset.lookDown: LookDown = clip; break;

            case ExpressionPreset.lookLeft: LookLeft = clip; break;

            case ExpressionPreset.lookRight: LookRight = clip; break;

            case ExpressionPreset.neutral: Neutral = clip; break;

            default: CustomClips.Add(clip); break;
            }
        }
Esempio n. 6
0
        public SerializedExpressionEditor(SerializedObject serializedObject, VRM10Expression targetObject,
                                          PreviewSceneManager previewSceneManager)
        {
            this.m_serializedObject = serializedObject;
            this.m_targetObject     = targetObject;

            m_isBinaryProp     = serializedObject.FindProperty(nameof(targetObject.IsBinary));
            m_ignoreBlinkProp  = serializedObject.FindProperty(nameof(targetObject.OverrideBlink));
            m_ignoreLookAtProp = serializedObject.FindProperty(nameof(targetObject.OverrideLookAt));
            m_ignoreMouthProp  = serializedObject.FindProperty(nameof(targetObject.OverrideMouth));

            m_morphTargetBindings   = new ReorderableMorphTargetBindingList(serializedObject, previewSceneManager, 20);
            m_materialColorBindings = new ReorderableMaterialColorBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);
            m_materialUVBindings    = new ReorderableMaterialUVBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);

            m_items = previewSceneManager.EnumRenderItems
                      .Where(x => x.SkinnedMeshRenderer != null)
                      .ToArray();
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
0
        public SerializedExpressionEditor(SerializedObject serializedObject, VRM10Expression targetObject,
                                          PreviewSceneManager previewSceneManager, EditorStatus status)
        {
            m_status = status;
            this.m_serializedObject = serializedObject;
            this.m_targetObject     = targetObject;

            m_expressionNameProp = serializedObject.FindProperty("expressionName");
            m_presetProp         = serializedObject.FindProperty("Preset");
            m_isBinaryProp       = serializedObject.FindProperty("IsBinary");
            m_ignoreBlinkProp    = serializedObject.FindProperty("IgnoreBlink");
            m_ignoreLookAtProp   = serializedObject.FindProperty("IgnoreLookAt");
            m_ignoreMouthProp    = serializedObject.FindProperty("IgnoreMouth");

            m_morphTargetBindings   = new ReorderableMorphTargetBindingList(serializedObject, previewSceneManager, 20);
            m_materialColorBindings = new ReorderableMaterialColorBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);
            m_materialUVBindings    = new ReorderableMaterialUVBindingList(serializedObject, previewSceneManager?.MaterialNames, 20);

            m_items = previewSceneManager.EnumRenderItems
                      .Where(x => x.SkinnedMeshRenderer != null)
                      .ToArray();
        }
Esempio n. 9
0
        void OnSelected(VRM10Expression clip)
        {
            if (PreviewSceneManager == null)
            {
                m_serializedEditor = null;
                return;
            }

            if (clip != null)
            {
                // select clip
                var status = SerializedExpressionEditor.EditorStatus.Default;
                if (m_serializedEditor != null)
                {
                    status = m_serializedEditor.Status;
                }
                m_serializedEditor = new SerializedExpressionEditor(clip, PreviewSceneManager, status);
            }
            else
            {
                // clear selection
                m_serializedEditor = null;
                PreviewSceneManager.Bake(default, 1.0f);
Esempio n. 10
0
        protected override void OnEnable()
        {
            m_target = (VRM10Expression)target;

            base.OnEnable();
        }
Esempio n. 11
0
        /// <summary>
        /// VRM-0.X の MaterialBindValue を VRM-1.0 仕様に変換する
        ///
        /// * Property名 => enum MaterialBindType
        /// * 特に _MainTex_ST の場合、MaterialBindType.UvScale + MaterialBindType.UvScale 2つになりうる
        ///
        /// </summary>
        VrmLib.Expression ToVrmLib(VRM10Expression clip, GameObject root)
        {
            var expression = new VrmLib.Expression(clip.Preset, clip.ExpressionName, clip.IsBinary);

            expression.OverrideBlink  = EnumUtil.Cast <VrmLib.ExpressionOverrideType>(clip.OverrideBlink);
            expression.OverrideLookAt = EnumUtil.Cast <VrmLib.ExpressionOverrideType>(clip.OverrideLookAt);
            expression.OverrideMouth  = EnumUtil.Cast <VrmLib.ExpressionOverrideType>(clip.OverrideMouth);

            foreach (var binding in clip.MorphTargetBindings)
            {
                var transform = GetTransformFromRelativePath(root.transform, binding.RelativePath);
                if (transform == null)
                {
                    continue;
                }
                var renderer = transform.gameObject.GetComponent <SkinnedMeshRenderer>();
                if (renderer == null)
                {
                    continue;
                }
                var mesh = renderer.sharedMesh;
                if (mesh == null)
                {
                    continue;
                }

                var names = new List <string>();
                for (int i = 0; i < mesh.blendShapeCount; ++i)
                {
                    names.Add(mesh.GetBlendShapeName(i));
                }

                var node            = Nodes[transform.gameObject];
                var blendShapeValue = new VrmLib.MorphTargetBind(
                    node,
                    names[binding.Index],
                    // Unity Range [0-100] to VRM-1.0 Range [0-1.0]
                    binding.Weight * 0.01f
                    );
                expression.MorphTargetBinds.Add(blendShapeValue);
            }

            foreach (var binding in clip.MaterialColorBindings)
            {
                var materialPair = Materials.FirstOrDefault(x => x.Key.name == binding.MaterialName);
                if (materialPair.Value != null)
                {
                    var bind = new VrmLib.MaterialColorBind(
                        materialPair.Value,
                        binding.BindType,
                        binding.TargetValue.ToNumericsVector4()
                        );
                    expression.MaterialColorBinds.Add(bind);
                }
            }

            foreach (var binding in clip.MaterialUVBindings)
            {
                var materialPair = Materials.FirstOrDefault(x => x.Key.name == binding.MaterialName);
                if (materialPair.Value != null)
                {
                    var bind = new VrmLib.TextureTransformBind(
                        materialPair.Value,
                        binding.Scaling.ToNumericsVector2(),
                        binding.Offset.ToNumericsVector2()
                        );
                    expression.TextureTransformBinds.Add(bind);
                }
            }

            return(expression);
        }
Esempio n. 12
0
        public void Bake(VRM10Expression bake, float weight)
        {
            if (bake == null)
            {
                return;
            }

            //
            // Bake Expression
            //
            m_bounds = default(Bounds);
            if (m_meshes != null)
            {
                if (bake != null)
                {
                    foreach (var x in m_meshes)
                    {
                        x.Bake(bake.MorphTargetBindings, weight);
                        m_bounds.Expand(x.Mesh.bounds.size);
                    }
                }
            }

            //
            // Update Material
            //
            if (m_materialMap != null)
            {
                // clear
                foreach (var kv in m_materialMap)
                {
                    kv.Value.Clear();
                }

                // color
                if (bake.MaterialColorBindings != null)
                {
                    foreach (var x in bake.MaterialColorBindings)
                    {
                        PreviewMaterialItem item;
                        if (m_materialMap.TryGetValue(x.MaterialName, out item))
                        {
                            //Debug.Log("set material");
                            PropItem prop;
                            if (item.PropMap.TryGetValue(x.BindType, out prop))
                            {
                                // var valueName = x.ValueName;
                                // if (valueName.EndsWith("_ST_S")
                                // || valueName.EndsWith("_ST_T"))
                                // {
                                //     valueName = valueName.Substring(0, valueName.Length - 2);
                                // }

                                var value = item.Material.GetVector(prop.Name);
                                //Debug.LogFormat("{0} => {1}", valueName, x.TargetValue);
                                value += ((x.TargetValue - prop.DefaultValues) * weight);
                                item.Material.SetColor(prop.Name, value);
                            }
                        }
                    }
                }

                // uv
                if (bake.MaterialUVBindings != null)
                {
                    foreach (var x in bake.MaterialUVBindings)
                    {
                        PreviewMaterialItem item;
                        if (m_materialMap.TryGetValue(x.MaterialName, out item))
                        {
                            item.AddScaleOffset(x.ScalingOffset, weight);
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        public bool Draw(out VRM10Expression bakeValue)
        {
            m_changed = false;

            m_serializedObject.Update();

            // Readonly の Expression 参照
            GUI.enabled = false;
            EditorGUILayout.ObjectField("Current clip",
                                        m_targetObject, typeof(VRM10Expression), false);
            GUI.enabled = true;

            EditorGUILayout.PropertyField(m_expressionNameProp, true);
            EditorGUILayout.PropertyField(m_presetProp, true);

            m_status.MorphTargetFoldout = CustomUI.Foldout(Status.MorphTargetFoldout, "MorphTarget");
            if (Status.MorphTargetFoldout)
            {
                EditorGUI.indentLevel++;
                var changed = MorphTargetBindsGUI();
                if (changed)
                {
                    string maxWeightName;
                    var    bindings = GetBindings(out maxWeightName);
                    m_morphTargetBindings.SetValues(bindings);

                    m_changed = true;
                }
                EditorGUI.indentLevel--;
            }

            m_status.AdvancedFoldout = CustomUI.Foldout(Status.AdvancedFoldout, "Advanced");
            if (Status.AdvancedFoldout)
            {
                EditorGUI.indentLevel++;

                // v0.45 Added. Binary flag
                EditorGUILayout.PropertyField(m_isBinaryProp, true);

                // v1.0 Ignore State
                EditorGUILayout.PropertyField(m_ignoreBlinkProp, true);
                EditorGUILayout.PropertyField(m_ignoreLookAtProp, true);
                EditorGUILayout.PropertyField(m_ignoreMouthProp, true);

                EditorGUILayout.Space();
                m_status.Mode = GUILayout.Toolbar(Status.Mode, MODES);
                switch (Status.Mode)
                {
                case 0:
                    // MorphTarget
                {
                    if (m_morphTargetBindings.Draw())
                    {
                        m_changed = true;
                    }
                }
                break;

                case 1:
                    // Material
                {
                    if (m_materialColorBindings.Draw())
                    {
                        m_changed = true;
                    }
                }
                break;

                case 2:
                    // MaterialUV
                {
                    if (m_materialUVBindings.Draw())
                    {
                        m_changed = true;
                    }
                }
                break;
                }

                EditorGUI.indentLevel--;
            }

            m_serializedObject.ApplyModifiedProperties();

            bakeValue = m_targetObject;
            return(m_changed);
        }
Esempio n. 14
0
 public SerializedExpressionEditor(VRM10Expression expression,
                                   PreviewSceneManager previewSceneManager, EditorStatus status) : this(
         new SerializedObject(expression), expression, previewSceneManager, status)
 {
 }
Esempio n. 15
0
        void Replace(VRM10Expression src, VRM10Expression dst)
        {
            if (Happy == src)
            {
                Happy = dst; return;
            }
            if (Angry == src)
            {
                Angry = dst; return;
            }
            if (Sad == src)
            {
                Sad = dst; return;
            }
            if (Relaxed == src)
            {
                Relaxed = dst; return;
            }
            if (Surprised == src)
            {
                Surprised = dst; return;
            }
            if (Aa == src)
            {
                Aa = dst; return;
            }
            if (Ih == src)
            {
                Ih = dst; return;
            }
            if (Ou == src)
            {
                Ou = dst; return;
            }
            if (Ee == src)
            {
                Ee = dst; return;
            }
            if (Oh == src)
            {
                Oh = dst; return;
            }
            if (Blink == src)
            {
                Blink = dst; return;
            }
            if (BlinkLeft == src)
            {
                BlinkLeft = dst; return;
            }
            if (BlinkRight == src)
            {
                BlinkRight = dst; return;
            }
            if (LookUp == src)
            {
                LookUp = dst; return;
            }
            if (LookDown == src)
            {
                LookDown = dst; return;
            }
            if (LookLeft == src)
            {
                LookLeft = dst; return;
            }
            if (LookRight == src)
            {
                LookRight = dst; return;
            }
            if (Neutral == src)
            {
                Neutral = dst; return;
            }

            for (int i = 0; i < CustomClips.Count; ++i)
            {
                if (CustomClips[i] == src)
                {
                    CustomClips[i] = dst;
                    return;
                }
            }
        }
Esempio n. 16
0
 public bool Match(VRM10Expression clip)
 {
     return(this.Equals(CreateFromClip(clip)));
 }
Esempio n. 17
0
        public void Bake(VRM10Expression bake, float weight)
        {
            if (bake == null)
            {
                return;
            }

            //
            // Bake Expression
            //
            m_bounds = default(Bounds);
            if (m_meshes != null)
            {
                if (bake != null)
                {
                    foreach (var x in m_meshes)
                    {
                        x.Bake(bake.MorphTargetBindings, weight);
                        m_bounds.Expand(x.Mesh.bounds.size);
                    }
                }
            }

            //
            // Update Material
            //
            if (m_materialMap != null)
            {
                // clear
                //Debug.LogFormat("clear material");
                foreach (var kv in m_materialMap)
                {
                    foreach (var _kv in kv.Value.PropMap)
                    {
                        // var prop = VrmLib.MaterialBindTypeExtensions.GetProperty(_kv.Key);
                        kv.Value.Material.SetColor(_kv.Value.Name, _kv.Value.DefaultValues);
                    }

                    // clear UV
                    kv.Value.Material.SetVector("_MainTex_ST", new Vector4(1, 1, 0, 0));
                }

                if (bake.MaterialColorBindings != null)
                {
                    foreach (var x in bake.MaterialColorBindings)
                    {
                        PreviewMaterialItem item;
                        if (m_materialMap.TryGetValue(x.MaterialName, out item))
                        {
                            //Debug.Log("set material");
                            PropItem prop;
                            if (item.PropMap.TryGetValue(x.BindType, out prop))
                            {
                                // var valueName = x.ValueName;
                                // if (valueName.EndsWith("_ST_S")
                                // || valueName.EndsWith("_ST_T"))
                                // {
                                //     valueName = valueName.Substring(0, valueName.Length - 2);
                                // }

                                var value = item.Material.GetVector(prop.Name);
                                //Debug.LogFormat("{0} => {1}", valueName, x.TargetValue);
                                value += ((x.TargetValue - prop.DefaultValues) * weight);
                                item.Material.SetColor(prop.Name, value);
                            }
                        }
                    }
                }

                if (bake.MaterialUVBindings != null)
                {
                    foreach (var x in bake.MaterialUVBindings)
                    {
                        PreviewMaterialItem item;
                        if (m_materialMap.TryGetValue(x.MaterialName, out item))
                        {
                            // var valueName = x.ValueName;
                            // if (valueName.EndsWith("_ST_S")
                            // || valueName.EndsWith("_ST_T"))
                            // {
                            //     valueName = valueName.Substring(0, valueName.Length - 2);
                            // }

                            var value = item.Material.GetVector("_MainTex_ST");
                            //Debug.LogFormat("{0} => {1}", valueName, x.TargetValue);
                            value += ((x.ScalingOffset - new Vector4(1, 1, 0, 0)) * weight);
                            item.Material.SetColor("_MainTex_ST", value);
                        }
                    }
                }
            }
        }