IEnumerator <object> Rotate(Bone bone, BoneArray.Entry entry) { using (Document.Current.History.BeginTransaction()) { float rotation = 0; var mousePos = sv.MousePosition; var initRotation = bone.Rotation; while (sv.Input.IsMousePressed()) { Document.Current.History.RollbackTransaction(); var t = Document.Current.Container.AsWidget.LocalToWorldTransform.CalcInversed(); Utils.ChangeCursorIfDefault(Cursors.Rotate); var a = mousePos * t - entry.Joint; var b = sv.MousePosition * t - entry.Joint; mousePos = sv.MousePosition; if (a.Length > Mathf.ZeroTolerance && b.Length > Mathf.ZeroTolerance) { rotation += Mathf.Wrap180(b.Atan2Deg - a.Atan2Deg); } Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Rotation), initRotation + rotation, CoreUserPreferences.Instance.AutoKeyframes); bone.Parent.Update(0); yield return(null); } yield return(null); sv.Input.ConsumeKey(Key.Mouse0); Document.Current.History.CommitTransaction(); } yield return(null); }
IEnumerator <object> Rotate(Bone bone, BoneArray.Entry entry) { Document.Current.History.BeginTransaction(); try { float rotation = 0; var mousePos = sv.MousePosition; var initRotation = bone.Rotation; while (sv.Input.IsMousePressed()) { Document.Current.History.RevertActiveTransaction(); var t = sv.Scene.CalcTransitionToSpaceOf(Document.Current.Container.AsWidget); Utils.ChangeCursorIfDefault(Cursors.Rotate); var a = mousePos * t - entry.Joint; var b = sv.MousePosition * t - entry.Joint; mousePos = sv.MousePosition; if (a.Length > Mathf.ZeroTolerance && b.Length > Mathf.ZeroTolerance) { rotation += Mathf.Wrap180(b.Atan2Deg - a.Atan2Deg); } Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Rotation), initRotation + rotation); bone.Parent.Update(0); yield return(null); } yield return(null); } finally { sv.Input.ConsumeKey(Key.Mouse0); Document.Current.History.EndTransaction(); } yield return(null); }
private IEnumerator <object> Drag(Bone bone, BoneArray.Entry entry) { Document.Current.History.BeginTransaction(); try { var iniMousePos = sv.MousePosition; var transform = sv.Scene.CalcTransitionToSpaceOf(Document.Current.Container.AsWidget); var transformInversed = transform.CalcInversed(); int index = 0; var dragDelta = Vector2.Zero; while (sv.Input.IsMousePressed()) { Document.Current.History.RevertActiveTransaction(); var snapEnabled = sv.Input.IsKeyPressed(Key.Alt); Utils.ChangeCursorIfDefault(MouseCursor.Hand); var items = Document.Current.Container.AsWidget.BoneArray.items; index = 0; SceneView.Instance.Components.GetOrAdd <CreateBoneHelper>().HitTip = default(Vector2); if (items != null && snapEnabled) { for (var i = 0; i < items.Length; i++) { if (sv.HitTestControlPoint(transformInversed * items[i].Tip)) { index = i; break; } } if (bone.Index != index) { SceneView.Instance.Components.GetOrAdd <CreateBoneHelper>().HitTip = index != 0 ? items[index].Tip : default(Vector2); } } var b = bone.Parent.AsWidget.BoneArray[bone.BaseIndex]; dragDelta = sv.MousePosition * transform - iniMousePos * transform; var position = bone.WorldToLocalTransform * (entry.Joint - b.Tip + (index != 0 && index != bone.Index && snapEnabled ? items[index].Tip - entry.Joint : dragDelta)); Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Position), position); bone.Parent.Update(0); yield return(null); } if (index != bone.Index && sv.Input.IsKeyPressed(Key.Alt)) { Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Position), index == 0 ? entry.Joint + dragDelta : Vector2.Zero); Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.BaseIndex), index); Core.Operations.SortBonesInChain.Perform(bone); } } finally { SceneView.Instance.Components.Remove <CreateBoneHelper>(); sv.Input.ConsumeKey(Key.Mouse0); Document.Current.History.EndTransaction(); Window.Current.Invalidate(); } }
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(); } }
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(); } }
private IEnumerator <object> Drag(Bone bone, BoneArray.Entry entry) { using (Document.Current.History.BeginTransaction()) { var iniMousePos = sv.MousePosition; var transform = Document.Current.Container.AsWidget.LocalToWorldTransform.CalcInversed(); var transformInversed = transform.CalcInversed(); int index = 0; var dragDelta = Vector2.Zero; while (sv.Input.IsMousePressed()) { Document.Current.History.RollbackTransaction(); var snapEnabled = sv.Input.IsKeyPressed(Key.Alt); Utils.ChangeCursorIfDefault(MouseCursor.Hand); var items = Document.Current.Container.AsWidget.BoneArray.items; index = 0; SceneView.Instance.Components.GetOrAdd <CreateBoneHelper>().HitTip = default(Vector2); if (items != null && snapEnabled) { for (var i = 0; i < items.Length; i++) { if (sv.HitTestControlPoint(transformInversed * items[i].Tip)) { index = i; break; } } if (bone.Index != index) { SceneView.Instance.Components.GetOrAdd <CreateBoneHelper>().HitTip = index != 0 ? items[index].Tip : default(Vector2); } } var b = bone.Parent.AsWidget.BoneArray[bone.BaseIndex]; dragDelta = sv.MousePosition * transform - iniMousePos * transform; var parentToLocalTransform = bone.CalcLocalToParentWidgetTransform().CalcInversed(); parentToLocalTransform.T = Vector2.Zero; var position = parentToLocalTransform * (entry.Joint - b.Tip + (index != 0 && index != bone.Index && snapEnabled ? items[index].Tip - entry.Joint : dragDelta)); Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Position), position, CoreUserPreferences.Instance.AutoKeyframes); bone.Parent.Update(0); yield return(null); } if (index != bone.Index && sv.Input.IsKeyPressed(Key.Alt)) { Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Position), index == 0 ? entry.Joint + dragDelta : Vector2.Zero, CoreUserPreferences.Instance.AutoKeyframes); var parentEntry = bone.Parent.AsWidget.BoneArray[index]; float parentAngle = (parentEntry.Tip - parentEntry.Joint).Atan2Deg; var boneEntry = bone.Parent.AsWidget.BoneArray[bone.Index]; float boneAngle = (boneEntry.Tip - boneEntry.Joint).Atan2Deg; Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.Rotation), index == 0 ? boneAngle : boneAngle - parentAngle, CoreUserPreferences.Instance.AutoKeyframes); Core.Operations.SetAnimableProperty.Perform(bone, nameof(Bone.BaseIndex), index, CoreUserPreferences.Instance.AutoKeyframes); Core.Operations.SortBonesInChain.Perform(bone); } SceneView.Instance.Components.Remove <CreateBoneHelper>(); sv.Input.ConsumeKey(Key.Mouse0); Window.Current.Invalidate(); Document.Current.History.CommitTransaction(); } }