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(); }
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)); }
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(); }
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); }
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); } }
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."); } }
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(); }
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()); }
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); }