|
@@ -135,15 +135,6 @@ typedef ShaderNodeDef = {
|
|
?functions: Array<TFunction>,
|
|
?functions: Array<TFunction>,
|
|
};
|
|
};
|
|
|
|
|
|
-typedef Node = {
|
|
|
|
- x : Float,
|
|
|
|
- y : Float,
|
|
|
|
- id : Int,
|
|
|
|
- type : String,
|
|
|
|
- ?properties : Dynamic,
|
|
|
|
- ?instance : ShaderNode,
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
typedef Edge = {
|
|
typedef Edge = {
|
|
?outputNodeId : Int,
|
|
?outputNodeId : Int,
|
|
nameOutput : String, // Fallback if name has changed
|
|
nameOutput : String, // Fallback if name has changed
|
|
@@ -154,7 +145,7 @@ typedef Edge = {
|
|
};
|
|
};
|
|
|
|
|
|
typedef Connection = {
|
|
typedef Connection = {
|
|
- from : Node,
|
|
|
|
|
|
+ from : ShaderNode,
|
|
outputId : Int,
|
|
outputId : Int,
|
|
};
|
|
};
|
|
|
|
|
|
@@ -173,14 +164,6 @@ enum Domain {
|
|
Fragment;
|
|
Fragment;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-typedef GenNodeInfo = {
|
|
|
|
- outputToInputMap: Map<String, Array<{node: Node, inputName: String}>>,
|
|
|
|
- inputTypes: Array<Type>,
|
|
|
|
- ?outputs: Map<String, TVar>,
|
|
|
|
- ?def: ShaderGraph.ShaderNodeDef,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
@:structInit @:publicFields
|
|
@:structInit @:publicFields
|
|
class
|
|
class
|
|
ExternVarDef {
|
|
ExternVarDef {
|
|
@@ -203,7 +186,7 @@ class ShaderGraphGenContext {
|
|
var nodes : Array<{
|
|
var nodes : Array<{
|
|
var outputs: Array<Array<{to: Int, input: Int}>>;
|
|
var outputs: Array<Array<{to: Int, input: Int}>>;
|
|
var inputs : Array<TExpr>;
|
|
var inputs : Array<TExpr>;
|
|
- var node : Node;
|
|
|
|
|
|
+ var node : ShaderNode;
|
|
}>;
|
|
}>;
|
|
|
|
|
|
var inputNodes : Array<Int> = [];
|
|
var inputNodes : Array<Int> = [];
|
|
@@ -227,7 +210,7 @@ class ShaderGraphGenContext {
|
|
var node = nodes[nodeId];
|
|
var node = nodes[nodeId];
|
|
genContext.initForNode(node.node, node.inputs);
|
|
genContext.initForNode(node.node, node.inputs);
|
|
|
|
|
|
- node.node.instance.generate(genContext);
|
|
|
|
|
|
+ node.node.generate(genContext);
|
|
|
|
|
|
for (outputId => expr in genContext.outputs) {
|
|
for (outputId => expr in genContext.outputs) {
|
|
if (expr == null) throw "null expr for output " + outputId;
|
|
if (expr == null) throw "null expr for output " + outputId;
|
|
@@ -280,7 +263,7 @@ class ShaderGraphGenContext {
|
|
|
|
|
|
for (id => node in nodes) {
|
|
for (id => node in nodes) {
|
|
if (node == null) continue;
|
|
if (node == null) continue;
|
|
- var inst = node.node.instance;
|
|
|
|
|
|
+ var inst = node.node;
|
|
var empty = true;
|
|
var empty = true;
|
|
var inputs = inst.getInputs();
|
|
var inputs = inst.getInputs();
|
|
|
|
|
|
@@ -290,7 +273,7 @@ class ShaderGraphGenContext {
|
|
if (connection == null)
|
|
if (connection == null)
|
|
continue;
|
|
continue;
|
|
empty = false;
|
|
empty = false;
|
|
- var nodeOutputs = connection.from.instance.getOutputs();
|
|
|
|
|
|
+ var nodeOutputs = connection.from.getOutputs();
|
|
var outputs = nodes[connection.from.id].outputs;
|
|
var outputs = nodes[connection.from.id].outputs;
|
|
if (outputs == null) {
|
|
if (outputs == null) {
|
|
outputs = [];
|
|
outputs = [];
|
|
@@ -647,7 +630,7 @@ class Graph {
|
|
var cachedGen : ShaderNodeDef = null;
|
|
var cachedGen : ShaderNodeDef = null;
|
|
var allParamDefaultValue = [];
|
|
var allParamDefaultValue = [];
|
|
var current_node_id = 0;
|
|
var current_node_id = 0;
|
|
- var nodes : Map<Int, Node> = [];
|
|
|
|
|
|
+ var nodes : Map<Int, ShaderNode> = [];
|
|
|
|
|
|
public var parent : ShaderGraph = null;
|
|
public var parent : ShaderGraph = null;
|
|
|
|
|
|
@@ -664,23 +647,18 @@ class Graph {
|
|
generate(Reflect.getProperty(json, "nodes"), Reflect.getProperty(json, "edges"));
|
|
generate(Reflect.getProperty(json, "nodes"), Reflect.getProperty(json, "edges"));
|
|
}
|
|
}
|
|
|
|
|
|
- public function generate(nodes : Array<Node>, edges : Array<Edge>) {
|
|
|
|
|
|
+ public function generate(nodes : Array<Dynamic>, edges : Array<Edge>) {
|
|
|
|
+ current_node_id = 0;
|
|
for (n in nodes) {
|
|
for (n in nodes) {
|
|
- var cl = std.Type.resolveClass(n.type);
|
|
|
|
- if( cl == null ) throw "Missing shader node "+n.type;
|
|
|
|
- n.instance = std.Type.createInstance(cl, []);
|
|
|
|
- n.instance.setId(n.id);
|
|
|
|
- n.instance.loadProperties(n.properties);
|
|
|
|
- this.nodes.set(n.id, n);
|
|
|
|
-
|
|
|
|
- var shaderParam = Std.downcast(n.instance, ShaderParam);
|
|
|
|
|
|
+ var node = ShaderNode.createFromDynamic(n);
|
|
|
|
+ this.nodes.set(node.id, node);
|
|
|
|
+ var shaderParam = Std.downcast(node, ShaderParam);
|
|
if (shaderParam != null) {
|
|
if (shaderParam != null) {
|
|
var paramShader = getParameter(shaderParam.parameterId);
|
|
var paramShader = getParameter(shaderParam.parameterId);
|
|
shaderParam.variable = paramShader.variable;
|
|
shaderParam.variable = paramShader.variable;
|
|
}
|
|
}
|
|
|
|
+ current_node_id = hxd.Math.imax(current_node_id, node.id+1);
|
|
}
|
|
}
|
|
- if (nodes[nodes.length-1] != null)
|
|
|
|
- this.current_node_id = nodes[nodes.length-1].id+1;
|
|
|
|
|
|
|
|
// Migration patch
|
|
// Migration patch
|
|
for (e in edges) {
|
|
for (e in edges) {
|
|
@@ -699,9 +677,8 @@ class Graph {
|
|
var node = this.nodes.get(edge.inputNodeId);
|
|
var node = this.nodes.get(edge.inputNodeId);
|
|
var output = this.nodes.get(edge.outputNodeId);
|
|
var output = this.nodes.get(edge.outputNodeId);
|
|
|
|
|
|
- var inputs = node.instance.getInputs();
|
|
|
|
- var outputs = output.instance.getOutputs();
|
|
|
|
-
|
|
|
|
|
|
+ var inputs = node.getInputs();
|
|
|
|
+ var outputs = output.getOutputs();
|
|
|
|
|
|
var outputId = edge.outputId;
|
|
var outputId = edge.outputId;
|
|
var inputId = edge.inputId;
|
|
var inputId = edge.inputId;
|
|
@@ -732,7 +709,7 @@ class Graph {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- node.instance.connections[inputId] = {from: output, outputId: outputId};
|
|
|
|
|
|
+ node.connections[inputId] = {from: output, outputId: outputId};
|
|
|
|
|
|
#if editor
|
|
#if editor
|
|
if (hasCycle()){
|
|
if (hasCycle()){
|
|
@@ -755,6 +732,10 @@ class Graph {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function addNode(shNode : ShaderNode) {
|
|
|
|
+ this.nodes.set(shNode.id, shNode);
|
|
|
|
+ }
|
|
|
|
+
|
|
public function areTypesCompatible(input: SgType, output: SgType) : Bool {
|
|
public function areTypesCompatible(input: SgType, output: SgType) : Bool {
|
|
return switch (input) {
|
|
return switch (input) {
|
|
case SgFloat(_):
|
|
case SgFloat(_):
|
|
@@ -773,9 +754,9 @@ class Graph {
|
|
|
|
|
|
public function removeEdge(idNode, inputId, update = true) {
|
|
public function removeEdge(idNode, inputId, update = true) {
|
|
var node = this.nodes.get(idNode);
|
|
var node = this.nodes.get(idNode);
|
|
- if (node.instance.connections[inputId] == null) return;
|
|
|
|
|
|
+ if (node.connections[inputId] == null) return;
|
|
|
|
|
|
- node.instance.connections[inputId] = null;
|
|
|
|
|
|
+ node.connections[inputId] = null;
|
|
}
|
|
}
|
|
|
|
|
|
public function setPosition(idNode : Int, x : Float, y : Float) {
|
|
public function setPosition(idNode : Int, x : Float, y : Float) {
|
|
@@ -796,19 +777,6 @@ class Graph {
|
|
return parent.getParameter(id);
|
|
return parent.getParameter(id);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public function addNode(x : Float, y : Float, nameClass : Class<ShaderNode>, args: Array<Dynamic>) {
|
|
|
|
- var node : Node = { x : x, y : y, id : current_node_id, type: std.Type.getClassName(nameClass) };
|
|
|
|
-
|
|
|
|
- node.instance = std.Type.createInstance(nameClass, args);
|
|
|
|
- node.instance.setId(current_node_id);
|
|
|
|
-
|
|
|
|
- this.nodes.set(node.id, node);
|
|
|
|
- current_node_id++;
|
|
|
|
-
|
|
|
|
- return node.instance;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public function hasCycle() : Bool {
|
|
public function hasCycle() : Bool {
|
|
var ctx = new ShaderGraphGenContext(this, false);
|
|
var ctx = new ShaderGraphGenContext(this, false);
|
|
@:privateAccess ctx.initNodes();
|
|
@:privateAccess ctx.initNodes();
|
|
@@ -823,15 +791,15 @@ class Graph {
|
|
public function saveToDynamic() : Dynamic {
|
|
public function saveToDynamic() : Dynamic {
|
|
var edgesJson : Array<Edge> = [];
|
|
var edgesJson : Array<Edge> = [];
|
|
for (n in nodes) {
|
|
for (n in nodes) {
|
|
- for (inputId => connection in n.instance.connections) {
|
|
|
|
|
|
+ for (inputId => connection in n.connections) {
|
|
if (connection == null) continue;
|
|
if (connection == null) continue;
|
|
var outputId = connection.outputId;
|
|
var outputId = connection.outputId;
|
|
- edgesJson.push({ outputNodeId: connection.from.id, nameOutput: connection.from.instance.getOutputs()[outputId].name, inputNodeId: n.id, nameInput: n.instance.getInputs()[inputId].name, inputId: inputId, outputId: outputId });
|
|
|
|
|
|
+ edgesJson.push({ outputNodeId: connection.from.id, nameOutput: connection.from.getOutputs()[outputId].name, inputNodeId: n.id, nameInput: n.getInputs()[inputId].name, inputId: inputId, outputId: outputId });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var json = {
|
|
var json = {
|
|
nodes: [
|
|
nodes: [
|
|
- for (n in nodes) { x : Std.int(n.x), y : Std.int(n.y), id: n.id, type: n.type, properties : n.instance.saveProperties() }
|
|
|
|
|
|
+ for (n in nodes) n.serializeToDynamic(),
|
|
],
|
|
],
|
|
edges: edgesJson
|
|
edges: edgesJson
|
|
};
|
|
};
|