Example #1
0
 IEnumerator <object> CreatePointObjectTask(Type nodeType)
 {
     while (true)
     {
         if (sv.InputArea.IsMouseOver())
         {
             Utils.ChangeCursorIfDefault(MouseCursor.Hand);
         }
         CreateNodeRequestComponent.Consume <Node>(sv.Components);
         if (sv.Input.WasMousePressed())
         {
             try {
                 var currentPoint = (PointObject)Core.Operations.CreateNode.Perform(nodeType, aboveSelected: nodeType != typeof(SplinePoint));
                 var container    = (Widget)Document.Current.Container;
                 var t            = sv.Scene.CalcTransitionToSpaceOf(container);
                 var pos          = Vector2.Zero;
                 if (container.Width.Abs() > Mathf.ZeroTolerance && container.Height.Abs() > Mathf.ZeroTolerance)
                 {
                     pos = sv.MousePosition * t / container.Size;
                 }
                 Core.Operations.SetProperty.Perform(currentPoint, nameof(PointObject.Position), pos);
             } catch (InvalidOperationException e) {
                 AlertDialog.Show(e.Message);
                 break;
             }
         }
         if (sv.Input.WasMousePressed(1))
         {
             break;
         }
         yield return(null);
     }
 }
 public IEnumerator <object> Task()
 {
     while (true)
     {
         if (CreateNodeRequestComponent.Consume <SplinePoint>(SceneView.Instance.Components, out command))
         {
             yield return(CreateSplinePointTask());
         }
         yield return(null);
     }
 }
Example #3
0
 public IEnumerator <object> Task()
 {
     while (true)
     {
         if (CreateNodeRequestComponent.Consume <Bone>(SceneView.Instance.Components))
         {
             yield return(CreateBoneTask());
         }
         yield return(null);
     }
 }
Example #4
0
 public IEnumerator <object> Task()
 {
     while (true)
     {
         Type nodeType;
         if (CreateNodeRequestComponent.Consume <PointObject>(sv.Components, out nodeType))
         {
             yield return(CreatePointObjectTask(nodeType));
         }
         yield return(null);
     }
 }
        IEnumerator <object> CreateSplinePointTask()
        {
            command.Checked = true;
            while (true)
            {
                if (sv.InputArea.IsMouseOver())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                }
                CreateNodeRequestComponent.Consume <Node>(sv.Components);
                if (sv.Input.ConsumeKeyPress(Key.Mouse0))
                {
                    using (Document.Current.History.BeginTransaction()) {
                        PointObject currentPoint;
                        try {
                            currentPoint = (PointObject)Core.Operations.CreateNode.Perform(typeof(SplinePoint), aboveSelected: false);
                        } catch (InvalidOperationException e) {
                            AlertDialog.Show(e.Message);
                            yield break;
                        }
                        var container = (Widget)Document.Current.Container;
                        var t         = sv.Scene.CalcTransitionToSpaceOf(container);
                        var pos       = Vector2.Zero;
                        if (container.Width.Abs() > Mathf.ZeroTolerance && container.Height.Abs() > Mathf.ZeroTolerance)
                        {
                            pos = sv.MousePosition * t / container.Size;
                        }
                        Core.Operations.SetProperty.Perform(currentPoint, nameof(PointObject.Position), pos);
                        using (Document.Current.History.BeginTransaction()) {
                            while (sv.Input.IsMousePressed())
                            {
                                Document.Current.History.RollbackTransaction();

                                var dir = (sv.MousePosition * t - currentPoint.TransformedPosition) / SplinePointPresenter.TangentWeightRatio;
                                Core.Operations.SetProperty.Perform(currentPoint, nameof(SplinePoint.TangentAngle), dir.Atan2Deg);
                                Core.Operations.SetProperty.Perform(currentPoint, nameof(SplinePoint.TangentWeight), dir.Length);
                                yield return(null);
                            }
                            Document.Current.History.CommitTransaction();
                        }
                        Document.Current.History.CommitTransaction();
                    }
                }
                if (sv.Input.WasMousePressed(1) || sv.Input.WasKeyPressed(Key.Escape))
                {
                    break;
                }
                yield return(null);
            }
            command.Checked = false;
        }
Example #6
0
 public IEnumerator <object> Task()
 {
     while (true)
     {
         Type type;
         if (CreateNodeRequestComponent.Consume <Node>(SceneView.Instance.Components, out type))
         {
             try {
                 Core.Operations.CreateNode.Perform(type);
             } catch (InvalidOperationException e) {
                 AlertDialog.Show(e.Message);
             }
         }
         yield return(null);
     }
 }
 IEnumerator <object> CreatePointObjectTask(Type nodeType)
 {
     command.Checked = true;
     while (true)
     {
         if (sv.InputArea.IsMouseOver())
         {
             Utils.ChangeCursorIfDefault(MouseCursor.Hand);
         }
         CreateNodeRequestComponent.Consume <Node>(sv.Components);
         if (sv.Input.WasMousePressed())
         {
             try {
                 Document.Current.History.DoTransaction(() => {
                     var currentPoint = (PointObject)Core.Operations.CreateNode.Perform(nodeType, aboveSelected: nodeType != typeof(SplinePoint));
                     var container    = (Widget)Document.Current.Container;
                     var t            = container.LocalToWorldTransform.CalcInversed();
                     var pos          = Vector2.Zero;
                     if (container.Width.Abs() > Mathf.ZeroTolerance && container.Height.Abs() > Mathf.ZeroTolerance)
                     {
                         pos = sv.MousePosition * t / container.Size;
                     }
                     if (container is ParticleEmitter && currentPoint is EmitterShapePoint)
                     {
                         Core.Operations.SetProperty.Perform(
                             container,
                             nameof(ParticleEmitter.Shape),
                             EmitterShape.Custom);
                     }
                     Core.Operations.SetProperty.Perform(currentPoint, nameof(PointObject.Position), pos);
                 });
             } catch (InvalidOperationException e) {
                 AlertDialog.Show(e.Message);
                 break;
             }
         }
         if (sv.Input.WasMousePressed(1) || sv.Input.WasKeyPressed(Key.Escape))
         {
             break;
         }
         yield return(null);
     }
     this.command.Checked = false;
 }
Example #8
0
 IEnumerator <object> CreateWidgetTask(Type nodeType)
 {
     while (true)
     {
         if (sv.InputArea.IsMouseOver())
         {
             Utils.ChangeCursorIfDefault(MouseCursor.Hand);
         }
         var container = Document.Current.Container as Widget;
         CreateNodeRequestComponent.Consume <Node>(sv.Components);
         if (sv.Input.WasMousePressed() && container != null)
         {
             sv.Input.ConsumeKey(Key.Mouse0);
             var t         = sv.Scene.CalcTransitionToSpaceOf(container);
             var rect      = new Rectangle(sv.MousePosition * t, sv.MousePosition * t);
             var presenter = new DelegatePresenter <Widget>(w => {
                 w.PrepareRendererState();
                 var t2 = container.CalcTransitionToSpaceOf(sv.Frame);
                 DrawRectOutline(rect.A, (rect.A + rect.B) / 2, t2);
                 DrawRectOutline(rect.A, rect.B, t2);
             });
             sv.Frame.CompoundPostPresenter.Add(presenter);
             while (sv.Input.IsMousePressed())
             {
                 rect.B = sv.MousePosition * t;
                 CommonWindow.Current.Invalidate();
                 yield return(null);
             }
             sv.Frame.CompoundPostPresenter.Remove(presenter);
             try {
                 var widget = (Widget)Core.Operations.CreateNode.Perform(nodeType);
                 Core.Operations.SetProperty.Perform(widget, nameof(Widget.Size), rect.B - rect.A);
                 Core.Operations.SetProperty.Perform(widget, nameof(Widget.Position), rect.A + widget.Size / 2);
                 Core.Operations.SetProperty.Perform(widget, nameof(Widget.Pivot), Vector2.Half);
             } catch (InvalidOperationException e) {
                 AlertDialog.Show(e.Message);
             }
             break;
         }
         yield return(null);
     }
     Utils.ChangeCursorIfDefault(MouseCursor.Default);
 }
Example #9
0
 public IEnumerator <object> Task()
 {
     while (true)
     {
         Type     type;
         ICommand command;
         if (CreateNodeRequestComponent.Consume <Node>(SceneView.Instance.Components, out type, out command))
         {
             try {
                 Document.Current.History.DoTransaction(() => {
                     Core.Operations.CreateNode.Perform(type);
                 });
             } catch (InvalidOperationException e) {
                 AlertDialog.Show(e.Message);
             }
         }
         yield return(null);
     }
 }
        IEnumerator <object> CreateSplinePointTask()
        {
            while (true)
            {
                if (sv.InputArea.IsMouseOver())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                }
                CreateNodeRequestComponent.Consume <Node>(sv.Components);
                if (sv.Input.ConsumeKeyPress(Key.Mouse0))
                {
                    try {
                        var currentPoint = (PointObject)Core.Operations.CreateNode.Perform(typeof(SplinePoint), aboveSelected: false);
                        var container    = (Widget)Document.Current.Container;
                        var t            = sv.Scene.CalcTransitionToSpaceOf(container);
                        var pos          = Vector2.Zero;
                        if (container.Width.Abs() > Mathf.ZeroTolerance && container.Height.Abs() > Mathf.ZeroTolerance)
                        {
                            pos = sv.MousePosition * t / container.Size;
                        }
                        Core.Operations.SetProperty.Perform(currentPoint, nameof(PointObject.Position), pos);
                        Document.Current.History.BeginTransaction();
                        while (sv.Input.IsMousePressed())
                        {
                            Document.Current.History.RevertActiveTransaction();

                            var dir = (sv.MousePosition * t - currentPoint.TransformedPosition) / SplinePointPresenter.TangentWeightRatio;
                            Core.Operations.SetProperty.Perform(currentPoint, nameof(SplinePoint.TangentAngle), dir.Atan2Deg);
                            Core.Operations.SetProperty.Perform(currentPoint, nameof(SplinePoint.TangentWeight), dir.Length);
                            yield return(null);
                        }
                    } finally {
                        Document.Current.History.EndTransaction();
                    }
                }
                if (sv.Input.WasMousePressed(1))
                {
                    break;
                }
                yield return(null);
            }
        }
        IEnumerator <object> CreateSplinePoint3DTask()
        {
            var input = SceneView.Instance.Input;

            while (true)
            {
                if (SceneView.Instance.InputArea.IsMouseOver())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                }
                CreateNodeRequestComponent.Consume <Node>(SceneView.Instance.Components);
                if (SceneView.Instance.Input.ConsumeKeyPress(Key.Mouse0))
                {
                    SplinePoint3D point;
                    try {
                        point = (SplinePoint3D)Core.Operations.CreateNode.Perform(typeof(SplinePoint3D), aboveSelected: false);
                    } catch (InvalidOperationException e) {
                        AlertDialog.Show(e.Message);
                        yield break;
                    }
                    var spline  = (Spline3D)Document.Current.Container;
                    var vp      = spline.Viewport;
                    var ray     = vp.ScreenPointToRay(SceneView.Instance.Input.MousePosition);
                    var xyPlane = new Plane(new Vector3(0, 0, 1), 0).Transform(spline.GlobalTransform);
                    var d       = ray.Intersects(xyPlane);
                    if (d.HasValue)
                    {
                        var pos = (ray.Position + ray.Direction * d.Value) * spline.GlobalTransform.CalcInverted();
                        Core.Operations.SetProperty.Perform(point, nameof(SplinePoint3D.Position), pos);
                        Document.Current.History.BeginTransaction();
                        try {
                            while (input.IsMousePressed())
                            {
                                Document.Current.History.RevertActiveTransaction();

                                ray = vp.ScreenPointToRay(SceneView.Instance.Input.MousePosition);
                                d   = ray.Intersects(xyPlane);
                                if (d.HasValue)
                                {
                                    var tangent = (ray.Position + ray.Direction * d.Value) * spline.GlobalTransform.CalcInverted() - point.Position;
                                    Core.Operations.SetProperty.Perform(point, nameof(SplinePoint3D.TangentA), tangent);
                                    Core.Operations.SetProperty.Perform(point, nameof(SplinePoint3D.TangentB), -tangent);
                                }
                                yield return(null);
                            }
                        } finally {
                            if (point.TangentA.Length < 0.01f)
                            {
                                Core.Operations.SetProperty.Perform(point, nameof(SplinePoint3D.TangentA), new Vector3(1, 0, 0));
                                Core.Operations.SetProperty.Perform(point, nameof(SplinePoint3D.TangentB), new Vector3(-1, 0, 0));
                            }
                            Document.Current.History.EndTransaction();
                        }
                    }
                }
                if (SceneView.Instance.Input.WasMousePressed(1))
                {
                    break;
                }
                yield return(null);
            }
            Utils.ChangeCursorIfDefault(MouseCursor.Default);
        }
Example #12
0
        IEnumerator <object> CreateSplinePoint3DTask()
        {
            command.Checked = true;
            while (true)
            {
                if (sv.InputArea.IsMouseOver())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                }
                CreateNodeRequestComponent.Consume <Node>(sv.Components);
                if (input.ConsumeKeyPress(Key.Mouse0))
                {
                    using (history.BeginTransaction()) {
                        SplinePoint3D point;
                        try {
                            point = (SplinePoint3D)CreateNode.Perform(typeof(SplinePoint3D), aboveSelected: false);
                        }
                        catch (InvalidOperationException e) {
                            AlertDialog.Show(e.Message);
                            yield break;
                        }
                        var spline  = (Spline3D)Document.Current.Container;
                        var vp      = spline.Viewport;
                        var ray     = vp.ScreenPointToRay(input.MousePosition);
                        var xyPlane = new Plane(new Vector3(0, 0, 1), 0).Transform(spline.GlobalTransform);
                        var d       = ray.Intersects(xyPlane);
                        if (d.HasValue)
                        {
                            var pos = (ray.Position + ray.Direction * d.Value) * spline.GlobalTransform.CalcInverted();
                            SetProperty.Perform(point, nameof(SplinePoint3D.Position), pos);
                            using (history.BeginTransaction()) {
                                while (input.IsMousePressed())
                                {
                                    history.RollbackTransaction();
                                    ray = vp.ScreenPointToRay(input.MousePosition);
                                    d   = ray.Intersects(xyPlane);
                                    if (d.HasValue)
                                    {
                                        var tangent = (ray.Position + ray.Direction * d.Value) *
                                                      spline.GlobalTransform.CalcInverted() - point.Position;
                                        SetProperty.Perform(point, nameof(SplinePoint3D.TangentA), tangent);
                                        SetProperty.Perform(point, nameof(SplinePoint3D.TangentB), -tangent);
                                    }
                                    history.CommitTransaction();
                                    yield return(null);
                                }

                                if (point.TangentA.Length < 0.01f)
                                {
                                    SetProperty.Perform(point, nameof(SplinePoint3D.TangentA), new Vector3(1, 0, 0));
                                    SetProperty.Perform(point, nameof(SplinePoint3D.TangentB), new Vector3(-1, 0, 0));
                                }
                            }
                        }
                        history.CommitTransaction();
                    }
                    history.CommitTransaction();
                }
                if (input.WasMousePressed(1) || input.WasKeyPressed(Key.Escape))
                {
                    break;
                }
                yield return(null);
            }

            command.Checked = false;
            Utils.ChangeCursorIfDefault(MouseCursor.Default);
        }
Example #13
0
        IEnumerator <object> CreateBoneTask()
        {
            command.Checked = true;
            while (true)
            {
                Bone bone = null;

                var transform = Document.Current.Container.AsWidget.CalcTransitionToSpaceOf(sv.Scene);
                if (sv.InputArea.IsMouseOver())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                }
                var items = Document.Current.Container.AsWidget.BoneArray.items;
                var index = 0;
                if (items != null)
                {
                    for (var i = 1; i < items.Length; i++)
                    {
                        if (sv.HitTestControlPoint(transform * items[i].Tip))
                        {
                            index = i;
                            break;
                        }
                    }
                    SceneView.Instance.Components.GetOrAdd <CreateBoneHelper>().HitTip =
                        index != 0 ? items[index].Tip : default(Vector2);
                }

                Window.Current.Invalidate();
                CreateNodeRequestComponent.Consume <Node>(sv.Components);
                if (sv.Input.ConsumeKeyPress(Key.Mouse0))
                {
                    Widget container = (Widget)Document.Current.Container;
                    int    boneIndex;
                    if (!container.BoneArray.Equals(default(BoneArray)))
                    {
                        boneIndex = container.BoneArray.items.Length + 1;
                    }
                    else
                    {
                        boneIndex = 1;
                    }
                    Matrix32 t            = sv.Scene.CalcTransitionToSpaceOf(container);
                    Vector2  initPosition = sv.MousePosition * t;

                    Vector2 pos = Vector2.Zero;
                    if (index == 0 && container.Width.Abs() > Mathf.ZeroTolerance && container.Height.Abs() > Mathf.ZeroTolerance)
                    {
                        pos = initPosition;
                    }
                    using (Document.Current.History.BeginTransaction()) {
                        try {
                            bone = (Bone)Core.Operations.CreateNode.Perform(typeof(Bone));
                        } catch (InvalidOperationException e) {
                            AlertDialog.Show(e.Message);
                            break;
                        }
                        bone.Index = boneIndex;
                        Core.Operations.SetProperty.Perform(bone, nameof(Bone.Position), pos);
                        Core.Operations.SetProperty.Perform(bone, nameof(Bone.BaseIndex), index);
                        Core.Operations.SelectNode.Perform(bone);
                        if (bone.BaseIndex != 0)
                        {
                            Core.Operations.SortBonesInChain.Perform(bone);
                        }
                        using (Document.Current.History.BeginTransaction()) {
                            while (sv.Input.IsMousePressed())
                            {
                                Document.Current.History.RollbackTransaction();

                                var dir   = (sv.MousePosition * t - initPosition).Snap(Vector2.Zero);
                                var angle = dir.Atan2Deg;
                                if (index != 0)
                                {
                                    var prentDir = items[index].Tip - items[index].Joint;
                                    angle = Vector2.AngleDeg(prentDir, dir);
                                }
                                Core.Operations.SetProperty.Perform(bone, nameof(Bone.Rotation), angle);
                                Core.Operations.SetProperty.Perform(bone, nameof(Bone.Length), dir.Length);
                                yield return(null);
                            }
                            Document.Current.History.CommitTransaction();
                        }
                        // do not create zero bone
                        if (bone != null && bone.Length == 0)
                        {
                            Document.Current.History.RollbackTransaction();
                            // must set length to zero to exectue "break;" later
                            bone.Length = 0;
                        }
                        Document.Current.History.CommitTransaction();
                    }
                    SceneView.Instance.Components.Remove <CreateBoneHelper>();
                }
                // turn off creation if was only click without drag (zero length bone)
                if (bone != null && bone.Length == 0)
                {
                    break;
                }
                if (sv.Input.WasMousePressed(1) || sv.Input.WasKeyPressed(Key.Escape))
                {
                    break;
                }

                yield return(null);
            }
            SceneView.Instance.Components.Remove <CreateBoneHelper>();
            command.Checked = false;
        }
Example #14
0
        public IEnumerator <object> Task()
        {
            ICommand command        = new Command();
            Type     nodeTypeActive = null;

            while (true)
            {
                if (sv.Input.WasKeyPressed(Key.Escape) || sv.Input.WasMousePressed(1))
                {
                    nodeTypeActive = null;
                }
                Type     nodeTypeIncome;
                ICommand newCommand;
                if (CreateNodeRequestComponent.Consume <Widget>(sv.Components, out nodeTypeIncome, out newCommand))
                {
                    nodeTypeActive  = nodeTypeIncome;
                    command.Checked = false;
                    command         = newCommand;
                    command.Checked = true;
                }

                if (nodeTypeActive == null)
                {
                    command.Checked = false;
                    yield return(null);

                    continue;
                }

                if (sv.InputArea.IsMouseOver())
                {
                    Utils.ChangeCursorIfDefault(MouseCursor.Hand);
                }
                var container = Document.Current.Container as Widget;
                CreateNodeRequestComponent.Consume <Node>(sv.Components);
                if (sv.Input.WasMousePressed() && container != null)
                {
                    sv.Input.ConsumeKey(Key.Mouse0);
                    var t         = sv.Scene.CalcTransitionToSpaceOf(container);
                    var rect      = new Rectangle(sv.MousePosition * t, sv.MousePosition * t);
                    var presenter = new SyncDelegatePresenter <Widget>(w => {
                        w.PrepareRendererState();
                        var t2 = container.CalcTransitionToSpaceOf(sv.Frame);
                        DrawRectOutline(rect.A, (rect.A + rect.B) / 2, t2);
                        DrawRectOutline(rect.A, rect.B, t2);
                    });
                    sv.Frame.CompoundPostPresenter.Add(presenter);
                    using (Document.Current.History.BeginTransaction()) {
                        while (sv.Input.IsMousePressed())
                        {
                            rect.B = sv.MousePosition * t;
                            CommonWindow.Current.Invalidate();
                            yield return(null);
                        }
                        sv.Frame.CompoundPostPresenter.Remove(presenter);
                        try {
                            var widget = (Widget)Core.Operations.CreateNode.Perform(nodeTypeActive);
                            Core.Operations.SetProperty.Perform(widget, nameof(Widget.Size), rect.B - rect.A);
                            Core.Operations.SetProperty.Perform(widget, nameof(Widget.Position), rect.A + widget.Size / 2);
                            Core.Operations.SetProperty.Perform(widget, nameof(Widget.Pivot), Vector2.Half);
                        } catch (InvalidOperationException e) {
                            AlertDialog.Show(e.Message);
                        }
                        Document.Current.History.CommitTransaction();
                    }

                    nodeTypeActive = null;
                    Utils.ChangeCursorIfDefault(MouseCursor.Default);
                }

                yield return(null);
            }
        }