diff --git a/Libraries/shaderlib/Sources/arm/shader/NodesMaterial.hx b/Libraries/shaderlib/Sources/arm/shader/NodesMaterial.hx index f73b7c6f..4ac86792 100644 --- a/Libraries/shaderlib/Sources/arm/shader/NodesMaterial.hx +++ b/Libraries/shaderlib/Sources/arm/shader/NodesMaterial.hx @@ -2466,31 +2466,37 @@ class NodesMaterial { isInputs ? n.inputs = sockets : n.outputs = sockets; for (s in sockets) s.node_id = n.id; var numSockets = sockets.length < oldSockets.length ? sockets.length : oldSockets.length; - for (i in 0...numSockets) if (sockets[i].type == oldSockets[i].type) sockets[i].default_value = oldSockets[i].default_value; + for (i in 0...numSockets) { + if (sockets[i].type == oldSockets[i].type) { + sockets[i].default_value = oldSockets[i].default_value; + } + } } } } - static inline function get_socket_color(type: String): Int { + public static inline function get_socket_color(type: String): Int { return type == "RGBA" ? 0xffc7c729 : type == "VECTOR" ? 0xff6363c7 : 0xffa1a1a1; } - static inline function get_socket_default_value(type: String): Dynamic { + public static inline function get_socket_default_value(type: String): Dynamic { return type == "RGBA" ? f32([0.8, 0.8, 0.8, 1.0]) : type == "VECTOR" ? f32([0.0, 0.0, 0.0]) : 0.0; } - static inline function get_socket_name(type: String): String { + public static inline function get_socket_name(type: String): String { return type == "RGBA" ? _tr("Color") : type == "VECTOR" ? _tr("Vector") : _tr("Value"); } - public static function createSocket(nodes: Nodes, node: TNode, type: String, canvas: TNodeCanvas): TNodeSocket { + public static function createSocket(nodes: Nodes, node: TNode, type: String, canvas: TNodeCanvas, min = 0.0, max = 1.0, default_value: Dynamic = null): TNodeSocket { return { id: nodes.getSocketId(canvas.nodes), node_id: node.id, name: get_socket_name(type), type: type, color: get_socket_color(type), - default_value: get_socket_default_value(type) + default_value: default_value == null ? get_socket_default_value(type) : default_value, + min: min, + max: max } } diff --git a/Sources/arm/ui/UINodes.hx b/Sources/arm/ui/UINodes.hx index 8c67db81..b5c6f71c 100644 --- a/Sources/arm/ui/UINodes.hx +++ b/Sources/arm/ui/UINodes.hx @@ -115,20 +115,69 @@ class UINodes { arm.ui.UIMenu.draw(function(ui: Zui) { ui.text(tr("Socket"), Right, ui.t.HIGHLIGHT_COL); if (ui.button(tr("Edit"), Left)) { - var h = Id.handle(); - h.text = socket.name; - UIBox.showCustom(function(ui: Zui) { - if (ui.tab(Id.handle(), tr("Socket"))) { - ui.row([0.5, 0.5]); - var name = ui.textInput(h, tr("Name")); - if (ui.button(tr("OK")) || ui.isReturnDown) { - socket.name = name; - UIBox.show = false; - NodesMaterial.syncSockets(node); - hwnd.redraws = 2; + var htype = Id.handle(); + var hname = Id.handle(); + var hmin = Id.handle(); + var hmax = Id.handle(); + var hval0 = Id.handle(); + var hval1 = Id.handle(); + var hval2 = Id.handle(); + var hval3 = Id.handle(); + htype.position = socket.type == "RGBA" ? 0 : socket.type == "VECTOR" ? 1 : 2; + hname.text = socket.name; + hmin.value = socket.min; + hmax.value = socket.max; + if (socket.type == "RGBA" || socket.type == "VECTOR") { + hval0.value = socket.default_value[0]; + hval1.value = socket.default_value[1]; + hval2.value = socket.default_value[2]; + if (socket.type == "RGBA") { + hval3.value = socket.default_value[3]; } } - }); + else hval0.value = socket.default_value; + App.notifyOnNextFrame(function() { + App.uiBox.endInput(); + UIBox.showCustom(function(ui: Zui) { + if (ui.tab(Id.handle(), tr("Socket"))) { + var type = ui.combo(htype, [tr("Color"), tr("Vector"), tr("Value")], tr("Type"), true); + if (htype.changed) hname.text = type == 0 ? tr("Color") : type == 1 ? tr("Vector") : tr("Value"); + var name = ui.textInput(hname, tr("Name")); + var min = zui.Ext.floatInput(ui, hmin, tr("Min")); + var max = zui.Ext.floatInput(ui, hmax, tr("Max")); + var default_value: Dynamic = null; + if (type == 0) { + ui.row([1 / 4, 1 / 4, 1 / 4, 1 / 4]); + zui.Ext.floatInput(ui, hval0, tr("R")); + zui.Ext.floatInput(ui, hval1, tr("G")); + zui.Ext.floatInput(ui, hval2, tr("B")); + zui.Ext.floatInput(ui, hval3, tr("A")); + default_value = [hval0.value, hval1.value, hval2.value, hval3.value]; + } + else if (type == 1) { + ui.row([1 / 3, 1 / 3, 1 / 3]); + hval0.value = zui.Ext.floatInput(ui, hval0, tr("X")); + hval1.value = zui.Ext.floatInput(ui, hval1, tr("Y")); + hval2.value = zui.Ext.floatInput(ui, hval2, tr("Z")); + default_value = [hval0.value, hval1.value, hval2.value]; + } + else { + default_value = zui.Ext.floatInput(ui, hval0, tr("default_value")); + } + if (ui.button(tr("OK"))) { // || ui.isReturnDown + socket.name = name; + socket.type = type == 0 ? "RGBA" : type == 1 ? "VECTOR" : "VALUE"; + socket.color = NodesMaterial.get_socket_color(socket.type); + socket.min = min; + socket.max = max; + socket.default_value = default_value; + UIBox.show = false; + NodesMaterial.syncSockets(node); + hwnd.redraws = 2; + } + } + }, 400, 250); + }); } if (ui.button(tr("Delete"), Left)) { node.inputs.remove(socket); @@ -689,15 +738,23 @@ class UINodes { node.id = nodes.getNodeId(canvas.nodes); node.x = UINodes.inst.getNodeX(); node.y = UINodes.inst.getNodeY(); - var origin: TNode = null; - for (m in Project.materials) for (n in m.canvas.nodes) if (n.type == "GROUP" && n.name == node.name) { origin = n; break; } - if (origin == null) for (g in Project.materialGroups) for (n in g.canvas.nodes) if (n.type == "GROUP" && n.name == node.name) { origin = n; break; } - if (origin != null) { - for (soc in origin.inputs) { - node.inputs.push(NodesMaterial.createSocket(nodes, node, soc.type, canvas)); + var groupInput: TNode = null; + var groupOutput: TNode = null; + for (g in Project.materialGroups) { + if (g.canvas.name == node.name) { + for (n in g.canvas.nodes) { + if (n.type == "GROUP_INPUT") groupInput = n; + else if (n.type == "GROUP_OUTPUT") groupOutput = n; + } + break; } - for (soc in origin.outputs) { - node.outputs.push(NodesMaterial.createSocket(nodes, node, soc.type, canvas)); + } + if (groupInput != null && groupOutput != null) { + for (soc in groupInput.outputs) { + node.inputs.push(NodesMaterial.createSocket(nodes, node, soc.type, canvas, soc.min, soc.max, soc.default_value)); + } + for (soc in groupOutput.inputs) { + node.outputs.push(NodesMaterial.createSocket(nodes, node, soc.type, canvas, soc.min, soc.max, soc.default_value)); } } return node;