From c9edde9ef9d6175fe82f9d6fa16941064af7c585 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 18 Oct 2021 11:00:13 +0200 Subject: [PATCH] Added uniform and greyscale_uniform nodes for mat_maker_gd. --- .../mat_maker_gd/editor/MatMakerGDEditor.tscn | 4 +- .../mat_maker_gd/editor/mm_graph_node.gd | 48 ++++++++++++++----- .../nodes/mm_node_universal_property.gd | 3 +- .../nodes/uniform/greyscale_uniform.gd | 25 ++++++++++ .../mat_maker_gd/nodes/uniform/uniform.gd | 20 ++++++++ 5 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 game/addons/mat_maker_gd/nodes/uniform/greyscale_uniform.gd create mode 100644 game/addons/mat_maker_gd/nodes/uniform/uniform.gd diff --git a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn index 172e53f0..f63a9ff8 100644 --- a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn +++ b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn @@ -13,7 +13,7 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -slot_colors = PoolColorArray( 0.905882, 0.0627451, 0.0627451, 1, 0.431373, 0.0352941, 0.0352941, 1, 0.827451, 0.376471, 0.376471, 1, 0.0431373, 0.478431, 0.427451, 1, 0.352941, 0.0352941, 0.341176, 1, 0.372549, 0.372549, 0.372549, 1 ) +slot_colors = PoolColorArray( 0.905882, 0.0627451, 0.0627451, 1, 0.431373, 0.0352941, 0.0352941, 1, 0.827451, 0.376471, 0.376471, 1, 0.0431373, 0.478431, 0.427451, 1, 0.352941, 0.0352941, 0.341176, 1, 0.0352941, 0.0509804, 1, 1, 0.372549, 0.372549, 0.372549, 1 ) [node name="VBoxContainer" type="VBoxContainer" parent="."] margin_right = 1024.0 @@ -49,7 +49,7 @@ margin_bottom = 600.0 mouse_filter = 2 [node name="AddPopup" parent="Popups" instance=ExtResource( 2 )] -type_folders = PoolStringArray( "res://addons/mat_maker_gd/nodes/noise", "res://addons/mat_maker_gd/nodes/filter", "res://addons/mat_maker_gd/nodes/gradient", "res://addons/mat_maker_gd/nodes/pattern", "res://addons/mat_maker_gd/nodes/sdf2d", "res://addons/mat_maker_gd/nodes/sdf3d", "res://addons/mat_maker_gd/nodes/simple", "res://addons/mat_maker_gd/nodes/other" ) +type_folders = PoolStringArray( "res://addons/mat_maker_gd/nodes/uniform", "res://addons/mat_maker_gd/nodes/noise", "res://addons/mat_maker_gd/nodes/filter", "res://addons/mat_maker_gd/nodes/gradient", "res://addons/mat_maker_gd/nodes/pattern", "res://addons/mat_maker_gd/nodes/sdf2d", "res://addons/mat_maker_gd/nodes/sdf3d", "res://addons/mat_maker_gd/nodes/simple", "res://addons/mat_maker_gd/nodes/other" ) [connection signal="pressed" from="VBoxContainer/PanelContainer/HBoxContainer/AddButton" to="." method="_on_AddButton_pressed"] [connection signal="ok_pressed" from="Popups/AddPopup" to="." method="_on_AddPopup_ok_pressed"] diff --git a/game/addons/mat_maker_gd/editor/mm_graph_node.gd b/game/addons/mat_maker_gd/editor/mm_graph_node.gd index f9df51e6..f6dbb49e 100644 --- a/game/addons/mat_maker_gd/editor/mm_graph_node.gd +++ b/game/addons/mat_maker_gd/editor/mm_graph_node.gd @@ -23,18 +23,6 @@ func add_slot_texture(getter : String, setter : String) -> int: return slot_idx -func add_slot_gradient() -> int: - var ge : Control = gradient_editor_scene.instance() - - var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "", "", ge) - - ge.set_value(_node) - #ge.texture = _node.call(getter, _material, slot_idx) - #properties[slot_idx].append(ge.texture) - - return slot_idx - - func add_slot_texture_universal(property : MMNodeUniversalProperty) -> int: var t : TextureRect = TextureRect.new() @@ -55,6 +43,39 @@ func add_slot_texture_universal(property : MMNodeUniversalProperty) -> int: return slot_idx +func add_slot_gradient() -> int: + var ge : Control = gradient_editor_scene.instance() + + var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "", "", ge) + + ge.set_value(_node) + #ge.texture = _node.call(getter, _material, slot_idx) + #properties[slot_idx].append(ge.texture) + + return slot_idx + +func add_slot_color(getter : String, setter : String) -> int: + var cp : ColorPickerButton = ColorPickerButton.new() + + var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, getter, setter, cp) + + cp.color = _node.call(getter) + + return slot_idx + +func add_slot_color_universal(property : MMNodeUniversalProperty) -> int: + var cp : ColorPickerButton = ColorPickerButton.new() + + var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", cp) + + cp.color = property.get_default_value() + + properties[slot_idx].append(property) + + cp.connect("color_changed", self, "on_universal_color_changed", [ slot_idx ]) + + return slot_idx + func add_slot_label(getter : String, setter : String, slot_name : String) -> int: var l : Label = Label.new() @@ -436,5 +457,8 @@ func on_universal_texture_changed(slot_idx : int) -> void: func on_slot_line_edit_text_entered(text : String, slot_idx : int) -> void: _node.call(properties[slot_idx][4], text) +func on_universal_color_changed(c : Color, slot_idx : int) -> void: + properties[slot_idx][6].set_default_value(c) + func get_material_node() -> MMNode: return _node diff --git a/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd b/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd index 2576ce4e..b1490a12 100644 --- a/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd +++ b/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd @@ -9,7 +9,8 @@ enum SlotTypes { SLOT_TYPE_FLOAT = 2, SLOT_TYPE_VECTOR2 = 3, SLOT_TYPE_VECTOR3 = 4, - SLOT_TYPE_UNIVERSAL = 5, + SLOT_TYPE_COLOR = 5, + SLOT_TYPE_UNIVERSAL = 6, } enum MMNodeUniversalPropertyDefaultType { diff --git a/game/addons/mat_maker_gd/nodes/uniform/greyscale_uniform.gd b/game/addons/mat_maker_gd/nodes/uniform/greyscale_uniform.gd new file mode 100644 index 00000000..c3bf2d61 --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/uniform/greyscale_uniform.gd @@ -0,0 +1,25 @@ +tool +extends MMNode + +export(Resource) var uniform : Resource + +func _init_properties(): + if !uniform: + uniform = MMNodeUniversalProperty.new() + uniform.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT + uniform.set_default_value(0.5) + uniform.slot_name = "Value (Color)" + uniform.value_step = 0.01 + uniform.value_range = Vector2(0, 1) + + uniform.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_COLOR + + register_output_property(uniform) + +func _register_methods(mm_graph_node) -> void: + mm_graph_node.add_slot_float_universal(uniform) + +func get_value_for(uv : Vector2, pseed : int) -> Color: + var f : float = uniform.get_value(uv) + + return Color(f, f, f, 1) diff --git a/game/addons/mat_maker_gd/nodes/uniform/uniform.gd b/game/addons/mat_maker_gd/nodes/uniform/uniform.gd new file mode 100644 index 00000000..dbd409a4 --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/uniform/uniform.gd @@ -0,0 +1,20 @@ +tool +extends MMNode + +export(Resource) var uniform : Resource + +func _init_properties(): + if !uniform: + uniform = MMNodeUniversalProperty.new() + uniform.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR + uniform.set_default_value(Color(1, 1, 1, 1)) + + uniform.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_COLOR + + register_output_property(uniform) + +func _register_methods(mm_graph_node) -> void: + mm_graph_node.add_slot_color_universal(uniform) + +func get_value_for(uv : Vector2, pseed : int) -> Color: + return uniform.get_value(uv)