コード例 #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();
        }
コード例 #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));
        }
コード例 #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();
        }
コード例 #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);
        }
コード例 #5
0
ファイル: FunctionGraph.cs プロジェクト: hglei/Materia
        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);
            }
        }
コード例 #6
0
ファイル: FunctionGraph.cs プロジェクト: hglei/Materia
        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.");
            }
        }
コード例 #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();
        }
コード例 #8
0
ファイル: FunctionGraph.cs プロジェクト: hglei/Materia
        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());
        }
コード例 #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);
        }