Exemple #1
0
        public void SetParameterValue(string id, string parameter, object v)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;
                    g.OnGraphUpdated -= Graph_OnGraphUpdated;
                    g.Dispose();
                }

                p.Value = v;
            }
            else
            {
                Parameters[cid] = new GraphParameterValue(parameter, v);
            }

            if (v is FunctionGraph)
            {
                (v as FunctionGraph).OnGraphUpdated += Graph_OnGraphUpdated;
            }

            Updated();
        }
Exemple #2
0
        public T GetParameterValue <T>(string id, string parameter)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;

                    g.TryAndProcess();

                    if (g.Result == null)
                    {
                        return(default(T));
                    }

                    return((T)g.Result);
                }
                else
                {
                    return((T)p.Value);
                }
            }

            return(default(T));
        }
Exemple #3
0
        public void SetParameterValue(string id, string parameter, object v)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;
                    g.OnGraphUpdated -= Graph_OnGraphUpdated;
                    g.Dispose();
                }

                if (v is float || v is int || v is double)
                {
                    p.Type = NodeType.Float;
                }
                else if (v is bool)
                {
                    p.Type = NodeType.Bool;
                }
                else if (v is MVector)
                {
                    p.Type = NodeType.Float4;
                }

                p.Value = v;
            }
            else
            {
                p = Parameters[cid] = new GraphParameterValue(parameter, v);

                if (v is float || v is int || v is double)
                {
                    p.Type = NodeType.Float;
                }
                else if (v is bool)
                {
                    p.Type = NodeType.Bool;
                }
                else if (v is MVector)
                {
                    p.Type = NodeType.Float4;
                }
            }

            if (v is FunctionGraph)
            {
                (v as FunctionGraph).OnGraphUpdated += Graph_OnGraphUpdated;
            }

            Updated();
        }
Exemple #4
0
        public bool IsParameterValueFunction(string id, string parameter)
        {
            string cid = id + "." + parameter;

            GraphParameterValue v = null;

            if (Parameters.TryGetValue(cid, out v))
            {
                return(v.IsFunction());
            }

            return(false);
        }
Exemple #5
0
        protected void BuildShaderParam(GraphParameterValue param, StringBuilder builder, bool useMinMaxValue = false)
        {
            string type = "";

            if (param.Type == NodeType.Bool)
            {
                type = "bool ";
            }
            else if (param.Type == NodeType.Float)
            {
                type = "float ";
            }
            else if (param.Type == NodeType.Color || param.Type == NodeType.Float4 || param.Type == NodeType.Gray)
            {
                type = "vec4 ";
            }
            else if (param.Type == NodeType.Float2)
            {
                type = "vec2 ";
            }
            else if (param.Type == NodeType.Float3)
            {
                type = "vec3 ";
            }
            else if (param.Type == NodeType.Matrix)
            {
                type = "mat4 ";
            }
            else
            {
                return;
            }

            string prefix = "p_";
            string s1     = prefix + param.Name.Replace(" ", "").Replace("-", "") + " = ";

            builder.Append(type);
            builder.Append(s1);

            if (param.IsFunction())
            {
                BuildShaderFunctionValue(param, builder);
            }
            else
            {
                BuildShaderParamValue(param, builder, useMinMaxValue);
            }
        }
Exemple #6
0
        protected void SetParentGraphVars(Graph g)
        {
            if (g == null)
            {
                return;
            }

            try
            {
                var p = g;

                if (p != null)
                {
                    foreach (var k in p.Parameters.Keys)
                    {
                        var param = p.Parameters[k];

                        if (!param.IsFunction())
                        {
                            SetVar("p_" + param.Name.Replace(" ", "").Replace("-", ""), param.Value, param.Type);
                        }
                    }

                    int count = p.CustomParameters.Count;
                    for (int i = 0; i < count; i++)
                    {
                        GraphParameterValue param = p.CustomParameters[i];

                        if (!param.IsFunction())
                        {
                            SetVar("p_" + param.Name.Replace(" ", "").Replace("-", ""), param.Value, param.Type);
                        }
                    }
                }
            }
            catch (StackOverflowException e)
            {
                //possible
                Log.Error(e);
                Log.Error("There is an infinite function reference loop in promoted graph parameters.");
            }
        }
Exemple #7
0
        public void RemoveParameterValue(string id, string parameter)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;
                    g.OnGraphUpdated -= Graph_OnGraphUpdated;
                    g.Dispose();
                }
            }

            Parameters.Remove(cid);

            Updated();
        }
Exemple #8
0
        protected string GetParentGraphShaderParams()
        {
            StringBuilder builder = new StringBuilder();

            try
            {
                var p = TopGraph();

                if (p != null)
                {
                    foreach (var param in p.Parameters.Values)
                    {
                        BuildShaderParam(param, builder);
                    }

                    int count = p.CustomParameters.Count;
                    for (int i = 0; i < count; i++)
                    {
                        GraphParameterValue param = p.CustomParameters[i];
                        if (param.IsFunction())
                        {
                            continue;
                        }
                        BuildShaderParam(param, builder, true);
                    }
                }
            }
            catch (StackOverflowException e)
            {
                Log.Error(e);
                Log.Error("There is an infinite function reference loop in promoted graph parameters.");
                return("");
            }

            return(builder.ToString());
        }
Exemple #9
0
        public object GetParameterValue(string id, string parameter)
        {
            string cid = id + "." + parameter;

            GraphParameterValue p = null;

            if (Parameters.TryGetValue(cid, out p))
            {
                if (p.IsFunction())
                {
                    FunctionGraph g = p.Value as FunctionGraph;

                    g.TryAndProcess();

                    return(g.Result);
                }
                else
                {
                    return(p.Value);
                }
            }

            return(null);
        }