Пример #1
0
    private void SaveState()
    {
        List<SerializableNode> serializableNodes = new List<SerializableNode> ();
        foreach (Node node in Nodes)
        {
            SerializableNode newNode = new SerializableNode();
            newNode.Name = node.Name;
            newNode.Position = new Double2 (node.Position.x, node.Position.y);
            newNode.HasOutput = node.HasOutput;
            newNode.Content = node._content;

            newNode.Inputs = new List<int>();
            newNode.InputNames = new List<string>();
            if (node.Inputs != null)
            {
                int i=0;
                foreach (Node input in node.Inputs)
                {
                    newNode.InputNames.Add (node.InputNames[i]);
                    if (input != null)
                    {
                        newNode.Inputs.Add(Nodes.IndexOf(input));
                    }
                    else
                    {
                        newNode.Inputs.Add(-1);
                    }
                    i++;
                }
            }

            newNode.FloatUserInputs = new List<double>();
            newNode.Vector2UserInputs = new List<Double2>();
            newNode.ColorUserInputs = new List<Double4>();
            foreach (object userInput in node.UserInputs)
            {
                if (userInput.GetType() == typeof(float))
                {
                    double value = (float)userInput;
                    newNode.FloatUserInputs.Add(value);
                }
                if (userInput.GetType() == typeof(Vector2))
                {
                    Double2 value = new Double2(((Vector2)userInput).x, ((Vector2)userInput).y);
                    newNode.Vector2UserInputs.Add(value);
                }
                if (userInput.GetType() == typeof(Color))
                {
                    Double4 value = new Double4(((Color)userInput).r, ((Color)userInput).g, ((Color)userInput).b, ((Color)userInput).a);
                    newNode.ColorUserInputs.Add(value);
                }
            }
            serializableNodes.Add(newNode);
        }
        string json = JsonMapper.ToJson (serializableNodes);
        string actualSavePath = string.Format(WINDOW_SAVESTATE_PATH, SelectedmaterialName) + ".txt";
        File.WriteAllText (actualSavePath, json);
    }
Пример #2
0
        private void MouseMove(System.Drawing.Point pt, Double2 xy, MouseKey buttons)
        {
            if (buttons == MouseKey.Left && enabled)
            {
                if (shifting && !lockPositions)
                {
                    double  zoomNormalizedScreenHeight = camera.ZoomFactor;
                    Double2 offset = (xy - lastPos);
                    offset.X *= zoomNormalizedScreenHeight * camera.AspectRatio;
                    offset.Y *= zoomNormalizedScreenHeight;

                    Double3 o = camera.Up * offset.Y + camera.Right * offset.X;

                    for (int i = 0; i < selectionHandler.Count; ++i)
                    {
                        SelectableSceneNode node = selectionHandler[i];

                        Double4x4 m = node.AbsoluteTransformation;
                        m.ClearTranslation();
                        Double4x4 mInv = m;
                        mInv.Invert();

                        Double4x4 translation = (mInv * Double4x4.CreateTranslation(o) * m);
                        if (!xDirectionEnabled)
                        {
                            translation.M14 = 0;
                        }
                        if (!yDirectionEnabled)
                        {
                            translation.M24 = 0;
                        }
                        if (!zDirectionEnabled)
                        {
                            translation.M34 = 0;
                        }

                        node.RelativeTransformation = translation * node.RelativeTransformation;
                        OnNodeChanged(node);
                    }

                    lastPos = xy;
                }
                else if (directionEditingEnabled)
                {
                    for (int i = 0; i < selectionHandler.Count; ++i)
                    {
                        IInteractiveDirectionSceneNode n = selectionHandler[i] as IInteractiveDirectionSceneNode;
                        //object test = selectionHandler[i];
                        if (n != null)
                        {
                            if (rotateAroundViewDirectionOnly)
                            {
                                Double3 dir = selectionHandler[i].AbsoluteTransformation.Inverted().TransformDirection(camera.LookAt).Normalized();
                                n.SetEndInPlane(xy, camera, dir);
                            }
                            else
                            {
                                n.SetEnd(xy, camera);
                            }

                            OnNodeChanged(selectionHandler[i]);
                        }
                    }
                }

                if (selectionHandler.Count > 0)
                {
                    OnPositionChanged();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 获取格子坐标
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public Short2 GetIndex(Double2 pos)
        {
            Double2 diff = (pos - Double2.zero) / _tileSize;

            return(new Short2((int)diff.x, (int)diff.x));
        }
 public static Curve CubicBezier(Double2 a, Double2 b, Double2 c, Double2 d)
 => new Curve(CurveType.CubicBezier, a, b, c, d);