Example #1
0
        public Vrm10InstanceRuntime(Vrm10Instance target)
        {
            m_target = target;
            var animator = target.GetComponent <Animator>();

            if (animator == null)
            {
                throw new Exception();
            }

            m_head = animator.GetBoneTransform(HumanBodyBones.Head);
            target.Vrm.LookAt.Setup(animator, m_head, target.LookAtTargetType, target.Gaze);
            target.Vrm.Expression.Setup(target, target.Vrm.LookAt, target.Vrm.LookAt.EyeDirectionApplicable);

            if (m_constraints == null)
            {
                m_constraints = target.GetComponentsInChildren <VRM10Constraint>();
            }

            if (!Application.isPlaying)
            {
                // for UnitTest
                return;
            }

            m_fastSpringBoneService = FastSpringBoneService.Instance;
            m_fastSpringBoneBuffer  = CreateFastSpringBoneBuffer(m_target.SpringBone);
            m_fastSpringBoneService.BufferCombiner.Register(m_fastSpringBoneBuffer);
        }
Example #2
0
        void Setup(Vrm10Instance instance)
        {
            if (instance.Vrm != null)
            {
                // OK
                return;
            }

            if (!CheckHumanoid(instance.gameObject))
            {
                // can not
                return;
            }

            EditorGUILayout.HelpBox("Humanoid OK.", MessageType.Info);
            if (GUILayout.Button("Create new VRM10Object"))
            {
                var saveName = (instance.name ?? "VRMObject") + ".asset";
                var path     = SaveFileDialog.GetPath(SaveTitle, saveName, SaveExtensions);
                var asset    = CreateAsset(path);
                if (asset != null)
                {
                    // update editor
                    serializedObject.Update();
                    var prop = serializedObject.FindProperty(nameof(Vrm10Instance.Vrm));
                    prop.objectReferenceValue = asset;
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }
Example #3
0
 static SpringBoneTreeView GetTree(Vrm10Instance target, SerializedObject so)
 {
     if (s_treeView == null || s_treeView.Target != target)
     {
         var state = new TreeViewState();
         s_treeView = new SpringBoneTreeView(state, target, so);
         s_treeView.Reload();
     }
     return(s_treeView);
 }
        public Vrm10InstanceEditorExpression(Vrm10Instance target)
        {
            m_target = target;

            m_expressionKeyWeights = m_target.Vrm.Expression.Clips.ToDictionary(x => target.Vrm.Expression.CreateKey(x.Clip), x => 0.0f);
            m_sliders = m_target.Vrm.Expression.Clips
                        .Where(x => x.Clip != null)
                        .Select(x => new ExpressionSlider(m_expressionKeyWeights, target.Vrm.Expression.CreateKey(x.Clip)))
                        .ToList()
            ;
        }
Example #5
0
        /// <summary>
        /// 2D の GUI 描画
        /// </summary>
        public static void Draw2D(Vrm10Instance target, SerializedObject so)
        {
            var tree = GetTree(target, so);

            if (GUILayout.Button("Reload"))
            {
                Disable();
                return;
            }

            tree.Draw2D();
        }
Example #6
0
        void Setup(Vrm10Instance instance)
        {
            if (instance.Vrm != null)
            {
                // OK
                return;
            }

            if (!CheckHumanoid(instance.gameObject))
            {
                // can not
                return;
            }

            EditorGUILayout.HelpBox("Humanoid OK.", MessageType.Info);
            if (GUILayout.Button("Create new VRM10Object"))
            {
                var saveName = (instance.name ?? "vrm-1.0");
                var dir      = SaveFileDialog.GetDir(SaveTitle, saveName);
                if (!string.IsNullOrEmpty(dir))
                {
                    var expressions = new Dictionary <ExpressionPreset, VRM10Expression>();
                    foreach (ExpressionPreset expression in System.Enum.GetValues(typeof(ExpressionPreset)))
                    {
                        if (expression == ExpressionPreset.custom)
                        {
                            continue;
                        }
                        expressions[expression] = CreateAndSaveExpression(expression, dir);
                    }

                    var path  = System.IO.Path.Combine(dir, (instance.name ?? "VRMObject") + ".asset");
                    var asset = CreateAsset(path, expressions);
                    if (asset != null)
                    {
                        // update editor
                        serializedObject.Update();
                        var prop = serializedObject.FindProperty(nameof(Vrm10Instance.Vrm));
                        prop.objectReferenceValue = asset;
                        serializedObject.ApplyModifiedProperties();
                    }
                }
            }
        }
Example #7
0
        internal Vrm10RuntimeExpression(Vrm10Instance target, ILookAtEyeDirectionProvider eyeDirectionProvider, ILookAtEyeDirectionApplicable eyeDirectionApplicable)
        {
            Restore();

            _merger = new ExpressionMerger(target.Vrm.Expression, target.transform);
            _keys   = target.Vrm.Expression.Clips.Select(x => target.Vrm.Expression.CreateKey(x.Clip)).ToList();
            var oldInputWeights = _inputWeights;

            _inputWeights = _keys.ToDictionary(x => x, x => 0f);
            foreach (var key in _keys)
            {
                // remain user input weights.
                if (oldInputWeights.ContainsKey(key))
                {
                    _inputWeights[key] = oldInputWeights[key];
                }
            }
            _actualWeights          = _keys.ToDictionary(x => x, x => 0f);
            _validator              = ExpressionValidatorFactory.Create(target.Vrm.Expression);
            _eyeDirectionProvider   = eyeDirectionProvider;
            _eyeDirectionApplicable = eyeDirectionApplicable;
        }
Example #8
0
        public SpringBoneTreeView(TreeViewState state, Vrm10Instance target, SerializedObject so) : base(state)
        {
            Target = target;
            _so    = so;

            _root = new TreeViewItem(_nextNodeID++, -1, "Root");
            var springBone = new TreeViewItem(_nextNodeID++, 0, "SpringBone");

            _root.AddChild(springBone);

            _colliderGroups = new TreeViewItem(_nextNodeID++, 1, "ColliderGroups");
            springBone.AddChild(_colliderGroups);

            _springs = new TreeViewItem(_nextNodeID++, 1, "Springs");
            springBone.AddChild(_springs);

            // load
            _map = new Dictionary <int, object>();
            for (var i = 0; i < target.SpringBone.ColliderGroups.Count; ++i)
            {
                var colliderGroup = target.SpringBone.ColliderGroups[i];
                var name          = colliderGroup.GUIName(i);
                var id            = _nextNodeID++;
                var item          = new TreeViewItem(id, 2, name);
                _map.Add(id, colliderGroup);
                _colliderGroups.AddChild(item);
            }

            for (var i = 0; i < target.SpringBone.Springs.Count; ++i)
            {
                var spring = target.SpringBone.Springs[i];
                var name   = spring.GUIName(i);
                var id     = _nextNodeID++;
                var item   = new TreeViewItem(id, 2, name);
                _map.Add(id, spring);
                _springs.AddChild(item);
            }
        }
Example #9
0
        public SelectedSpringGUI(Vrm10Instance target, SerializedObject so, int i) : base(so, i)
        {
            Property = so.FindProperty($"SpringBone.Springs.Array.data[{i}]");

            {
                var prop = Property.FindPropertyRelative("ColliderGroups");
                _springColliderGroupList = new ReorderableList(so, prop);
                _springColliderGroupList.drawElementCallback = (rect, index, isActive, isFocused) =>
                {
                    rect.height -= 4;
                    rect.y      += 2;

                    SerializedProperty element = prop.GetArrayElementAtIndex(index);
                    var elements       = target.SpringBone.ColliderGroups;
                    var element_index  = elements.IndexOf(element.objectReferenceValue as VRM10SpringBoneColliderGroup);
                    var colliderGroups = target.SpringBone.ColliderGroups.Select((x, y) => x.GUIName(y)).ToArray();
                    var new_index      = EditorGUI.Popup(rect, element_index, colliderGroups);
                    if (new_index != element_index)
                    {
                        element.objectReferenceValue = elements[new_index];
                    }
                };
            }

            {
                var prop = Property.FindPropertyRelative("Joints");
                _springJointList = new ReorderableList(so, prop);
                _springJointList.drawElementCallback = (rect, index, isActive, isFocused) =>
                {
                    SerializedProperty element = prop.GetArrayElementAtIndex(index);
                    rect.height -= 4;
                    rect.y      += 2;
                    EditorGUI.PropertyField(rect, element);
                };
            }
        }
Example #10
0
        /// <summary>
        /// 3D の Handle 描画
        /// </summary>
        public static void Draw3D(Vrm10Instance target, SerializedObject so)
        {
            var tree = GetTree(target, so);

            tree.Draw3D();
        }