Exemplo n.º 1
0
        private IEnumerator <object> DragTip(Bone bone, BoneArray.Entry entry)
        {
            using (Document.Current.History.BeginTransaction()) {
                var iniMousePos = sv.MousePosition;
                var transform   = Document.Current.Container.AsWidget.LocalToWorldTransform.CalcInversed();

                var accumulativeRotationsHelpersByBones = new Dictionary <Bone, AccumulativeRotationHelper>();

                while (sv.Input.IsMousePressed())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                    if (sv.Input.IsKeyPressed(Key.Control))
                    {
                        var parent = bone.Parent.AsWidget.BoneArray[bone.BaseIndex];
                        var dir    = (sv.MousePosition * transform -
                                      bone.Parent.AsWidget.BoneArray[bone.Index].Joint).Snap(Vector2.Zero);
                        var angle = dir.Atan2Deg;
                        if (bone.BaseIndex != 0)
                        {
                            var prentDir = parent.Tip - parent.Joint;
                            angle = Vector2.AngleDeg(prentDir, dir);
                        }
                        if (!sv.Input.IsKeyPressed(Key.Alt))
                        {
                            Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Rotation),
                                                                        GetRotationByBone(accumulativeRotationsHelpersByBones, bone, angle),
                                                                        CoreUserPreferences.Instance.AutoKeyframes
                                                                        );
                        }
                        Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Length), dir.Length, CoreUserPreferences.Instance.AutoKeyframes);
                    }
                    else
                    {
                        var dragDelta = sv.MousePosition * transform - iniMousePos * transform;
                        var boneChain = IKSolver.SolveFor(bone, entry.Tip + dragDelta);
                        foreach (Tuple <Bone, float> pair in boneChain)
                        {
                            Core.Operations.SetAnimableProperty.Perform(pair.Item1, nameof(Bone.Rotation),
                                                                        GetRotationByBone(accumulativeRotationsHelpersByBones, pair.Item1, pair.Item2),
                                                                        CoreUserPreferences.Instance.AutoKeyframes
                                                                        );
                        }
                    }
                    bone.Parent.Update(0);
                    yield return(null);
                }
                sv.Input.ConsumeKey(Key.Mouse0);
                Window.Current.Invalidate();
                Document.Current.History.CommitTransaction();
            }
        }
Exemplo n.º 2
0
        private IEnumerator <object> DragTip(Bone bone, BoneArray.Entry entry)
        {
            Document.Current.History.BeginTransaction();

            try {
                var iniMousePos = sv.MousePosition;
                var transform   = sv.Scene.CalcTransitionToSpaceOf(Document.Current.Container.AsWidget);
                while (sv.Input.IsMousePressed())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                    if (sv.Input.IsKeyPressed(Key.Control))
                    {
                        var parent = bone.Parent.AsWidget.BoneArray[bone.BaseIndex];
                        var dir    = (sv.MousePosition * transform -
                                      bone.Parent.AsWidget.BoneArray[bone.Index].Joint).Snap(Vector2.Zero);
                        var angle = dir.Atan2Deg;
                        if (bone.BaseIndex != 0)
                        {
                            var prentDir = parent.Tip - parent.Joint;
                            angle = Vector2.AngleDeg(prentDir, dir);
                        }
                        if (!sv.Input.IsKeyPressed(Key.Alt))
                        {
                            Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Rotation), angle);
                        }
                        Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Length), dir.Length);
                    }
                    else
                    {
                        var dragDelta = sv.MousePosition * transform - iniMousePos * transform;
                        var boneChain = IKSolver.SolveFor(bone, entry.Tip + dragDelta);
                        foreach (var pair in boneChain)
                        {
                            Core.Operations.SetAnimableProperty.Perform(pair.Item1, nameof(Bone.Rotation), pair.Item2);
                        }
                    }
                    bone.Parent.Update(0);
                    yield return(null);
                }
            } finally {
                sv.Input.ConsumeKey(Key.Mouse0);
                Document.Current.History.EndTransaction();
                Window.Current.Invalidate();
            }
        }