Ejemplo n.º 1
0
        public string GetJson()
        {
            GraphParameterValueData d = new GraphParameterValueData();

            d.name        = Name;
            d.isFunction  = IsFunction();
            d.description = Description;
            d.type        = (int)Type;
            d.min         = Min;
            d.max         = Max;
            d.inputType   = (int)inputType;
            d.id          = Id;
            d.section     = Section;

            if (d.isFunction)
            {
                FunctionGraph g = Value as FunctionGraph;

                d.value = g.GetJson();
            }
            else
            {
                if (v is Matrix4)
                {
                    d.value = ((Matrix4)v).ToArray();
                }
                else
                {
                    d.value = v;
                }
            }

            return(JsonConvert.SerializeObject(d));
        }
Ejemplo n.º 2
0
        public static GraphParameterValue FromJson(string data, Node n)
        {
            GraphParameterValueData d = JsonConvert.DeserializeObject <GraphParameterValueData>(data);
            //create a dummy graph parameter
            var g = new GraphParameterValue(d.name, 0);

            //load real data
            g.SetJson(d, n);
            return(g);
        }
Ejemplo n.º 3
0
        public static GraphParameterValue FromJson(string data)
        {
            GraphParameterValueData d = JsonConvert.DeserializeObject <GraphParameterValueData>(data);

            if (d.isFunction)
            {
                FunctionGraph t = new FunctionGraph("temp");
                t.FromJson((string)d.value);
                return(new GraphParameterValue(d.name, t));
            }


            return(new GraphParameterValue(d.name, d.value));
        }
Ejemplo n.º 4
0
        public static GraphParameterValue FromJson(string data, Node n)
        {
            GraphParameterValueData d = JsonConvert.DeserializeObject <GraphParameterValueData>(data);

            if (d.isFunction)
            {
                //we have a chicken and egg problem here...
                //which comes first the node population
                //or the parameter population?
                FunctionGraph t = new FunctionGraph("temp");
                t.FromJson((string)d.value);
                t.ParentNode = n;
                t.SetConnections();
                return(new GraphParameterValue(d.name, t, d.description, (NodeType)d.type, d.min, d.max));
            }


            return(new GraphParameterValue(d.name, d.value, d.description, (NodeType)d.type, d.min, d.max));
        }
Ejemplo n.º 5
0
        public string GetJson()
        {
            GraphParameterValueData d = new GraphParameterValueData();

            d.name       = Name;
            d.isFunction = IsFunction();

            if (d.isFunction)
            {
                FunctionGraph g = Value as FunctionGraph;

                d.value = g.GetJson();
            }
            else
            {
                d.value = Value;
            }

            return(JsonConvert.SerializeObject(d));
        }
Ejemplo n.º 6
0
        public string GetJson()
        {
            GraphParameterValueData d = new GraphParameterValueData();

            d.name        = Name;
            d.isFunction  = IsFunction();
            d.description = Description;
            d.type        = (int)Type;
            d.min         = Min;
            d.max         = Max;

            if (d.isFunction)
            {
                FunctionGraph g = Value as FunctionGraph;

                d.value = g.GetJson();
            }
            else
            {
                d.value = Value;
            }

            return(JsonConvert.SerializeObject(d));
        }
Ejemplo n.º 7
0
        public virtual void SetJson(GraphParameterValueData d, Node n)
        {
            Name = d.name;

            type      = (NodeType)d.type;
            inputType = (ParameterInputType)d.inputType;
            Id        = d.id;
            min       = d.min;
            max       = d.max;

            if (d.isFunction)
            {
                FunctionGraph t = new FunctionGraph("temp");
                t.AssignParentNode(n);
                t.FromJson((string)d.value);
                t.ExpectedOutput = (NodeType)d.type;
                t.SetConnections();
                v = t;
            }
            else
            {
                v = d.value;
            }

            //then it is a matrix
            if (v is Newtonsoft.Json.Linq.JArray && type == NodeType.Matrix)
            {
                float[] m = DeserializeValueArray <float[]>(v);
                //if this fails then the ValidateValue
                //will simply fill it in with the corresponding
                //matrix identity
                if (m != null)
                {
                    //4x4 matrix
                    if (m.Length == 16)
                    {
                        Matrix4 m4 = new Matrix4();
                        m4.FromArray(m);
                        v = m4;
                    }
                }
            }
            //handle this in case parser actually returns it as
            //a float[] instead of a JArray
            //not sure which it will return at the moment
            //when it encodes it from the value field
            //which is classified as a generic object
            else if (v is float[] && type == NodeType.Matrix)
            {
                float[] m = (float[])v;

                if (m != null && m.Length == 16)
                {
                    Matrix4 m4 = new Matrix4();
                    m4.FromArray(m);
                    v = m4;
                }
            }

            Description = d.description;
            Section     = d.section;

            //whoops forgot to check for this!
            //otherwise d.section from a file
            //without d.section is null!
            if (string.IsNullOrEmpty(Section))
            {
                Section = "Default";
            }

            ValidateValue();
        }