From dc56ca252b771741f9594ebee7447039229fef80 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 20 Oct 2021 20:22:44 +0200 Subject: [PATCH] sd_tf_scale, sd_tf_rotate, sd_tf_translate nodes. --- game/addons/mat_maker_gd/new_resource.tres | 112 +++++++++++++----- .../nodes/mm_node_universal_property.gd | 4 +- .../mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd | 41 +++++++ .../mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd | 41 +++++++ .../nodes/sdf2d/sd_tf_translate.gd | 38 ++++++ 5 files changed, 203 insertions(+), 33 deletions(-) create mode 100644 game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd create mode 100644 game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd create mode 100644 game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_translate.gd diff --git a/game/addons/mat_maker_gd/new_resource.tres b/game/addons/mat_maker_gd/new_resource.tres index e709d150..f44df87d 100644 --- a/game/addons/mat_maker_gd/new_resource.tres +++ b/game/addons/mat_maker_gd/new_resource.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=67 format=2] +[gd_resource type="Resource" load_steps=76 format=2] [ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1] [ext_resource path="res://addons/mat_maker_gd/nodes/noise/noise.gd" type="Script" id=2] @@ -17,6 +17,9 @@ [ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_box.gd" type="Script" id=15] [ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_polygon.gd" type="Script" id=16] [ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_line.gd" type="Script" id=17] +[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_tf_translate.gd" type="Script" id=18] +[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd" type="Script" id=19] +[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd" type="Script" id=20] [sub_resource type="Resource" id=3] script = ExtResource( 5 ) @@ -339,33 +342,6 @@ default_vector2 = Vector2( 0, 0 ) default_vector3 = Vector3( 0, 0, 0 ) default_color = Color( 0, 0, 0, 1 ) -[sub_resource type="Resource" id=65] -script = ExtResource( 5 ) -default_type = 1 -default_int = 0 -default_float = 0.0 -default_vector2 = Vector2( 0, 0 ) -default_vector3 = Vector3( 0, 0, 0 ) -default_color = Color( 0, 0, 0, 1 ) - -[sub_resource type="Resource" id=48] -script = ExtResource( 5 ) -default_type = 1 -default_int = 0 -default_float = 0.0 -default_vector2 = Vector2( 0, 0 ) -default_vector3 = Vector3( 0, 0, 0 ) -default_color = Color( 0, 0, 0, 1 ) -input_property = SubResource( 65 ) - -[sub_resource type="Resource" id=49] -script = ExtResource( 13 ) -graph_position = Vector2( 1480, -680 ) -image = SubResource( 47 ) -input = SubResource( 48 ) -bevel = 0.0 -base = 0.17 - [sub_resource type="Resource" id=53] script = ExtResource( 5 ) default_type = 1 @@ -375,12 +351,40 @@ default_vector2 = Vector2( 0, 0 ) default_vector3 = Vector3( 0, 0, 0 ) default_color = Color( 0, 0, 0, 1 ) +[sub_resource type="Resource" id=72] +script = ExtResource( 5 ) +default_type = 1 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) +input_property = SubResource( 53 ) + +[sub_resource type="Resource" id=48] +script = ExtResource( 5 ) +default_type = 1 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) +input_property = SubResource( 72 ) + +[sub_resource type="Resource" id=49] +script = ExtResource( 13 ) +graph_position = Vector2( 1580, -720 ) +image = SubResource( 47 ) +input = SubResource( 48 ) +bevel = 0.0 +base = 0.17 + [sub_resource type="Resource" id=54] script = ExtResource( 14 ) graph_position = Vector2( 1020, -680 ) output = SubResource( 53 ) -center = Vector2( 0.04, 0 ) -radius = 0.4 +center = Vector2( 0, 0 ) +radius = 0.1 [sub_resource type="Resource" id=56] script = ExtResource( 5 ) @@ -439,6 +443,15 @@ graph_position = Vector2( 960, -440 ) points = PoolVector2Array( 0.2, 0.2, 0.7, 0.4, 0.858401, 0.631436, 0.672764, 0.875339, 0.396341, 0.873984, 0.25542, 0.856369, 0.143902, 0.556369 ) output = SubResource( 62 ) +[sub_resource type="Resource" id=65] +script = ExtResource( 5 ) +default_type = 1 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) + [sub_resource type="Resource" id=66] script = ExtResource( 17 ) graph_position = Vector2( 1260, -580 ) @@ -448,7 +461,44 @@ A = Vector2( -0.3, -0.36 ) B = Vector2( 0.25, 0.35 ) width = 0.07 +[sub_resource type="Resource" id=68] +script = ExtResource( 5 ) +default_type = 1 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) + +[sub_resource type="Resource" id=69] +script = ExtResource( 18 ) +graph_position = Vector2( 1180, -880 ) +output = SubResource( 68 ) +translation = Vector2( 0.15, 0.03 ) + +[sub_resource type="Resource" id=70] +script = ExtResource( 5 ) +default_type = 1 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) +input_property = SubResource( 65 ) + +[sub_resource type="Resource" id=71] +script = ExtResource( 19 ) +graph_position = Vector2( 1480, -240 ) +output = SubResource( 70 ) +angle = 52.0 + +[sub_resource type="Resource" id=73] +script = ExtResource( 20 ) +graph_position = Vector2( 1340, -740 ) +output = SubResource( 72 ) +scale = 3.0 + [resource] script = ExtResource( 1 ) image_size = Vector2( 128, 128 ) -nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ), SubResource( 66 ) ] +nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ) ] 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 17de7e0e..ce31c061 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 @@ -52,8 +52,8 @@ func _init(): if input_property: input_property.connect("changed", self, "on_input_property_changed") -func get_value(uv : Vector2): - if get_value_from_owner: +func get_value(uv : Vector2, skip_owner_val : bool = false): + if get_value_from_owner && !skip_owner_val: return get_owner_value(uv) if !input_property: diff --git a/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd b/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd new file mode 100644 index 00000000..9ec52f7e --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd @@ -0,0 +1,41 @@ +tool +extends MMNode + +var SDF2D = preload("res://addons/mat_maker_gd/nodes/common/sdf2d.gd") + +export(Resource) var output : Resource +export(float) var angle : float = 0 + +func _init_properties(): + if !output: + output = MMNodeUniversalProperty.new() + output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT + + output.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL + output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL + #output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT + output.slot_name = ">>> Apply >>>" + output.get_value_from_owner = true + + register_input_property(output) + register_output_property(output) + +func _register_methods(mm_graph_node) -> void: + mm_graph_node.add_slot_label_universal(output) + + mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 1) + +func get_property_value(uv : Vector2): + #$in(sdf2d_rotate($uv, $a*0.01745329251))", + return output.get_value(SDF2D.sdf2d_rotate(uv, angle * 0.01745329251), true) + +#angle +func get_angle() -> float: + return angle + +func set_angle(val : float) -> void: + angle = val + + emit_changed() + output.emit_changed() + diff --git a/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd b/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd new file mode 100644 index 00000000..f6302fa2 --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd @@ -0,0 +1,41 @@ +tool +extends MMNode + +var SDF2D = preload("res://addons/mat_maker_gd/nodes/common/sdf2d.gd") + +export(Resource) var output : Resource +export(float) var scale : float = 1 + +func _init_properties(): + if !output: + output = MMNodeUniversalProperty.new() + output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT + + output.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL + output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL + #output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT + output.slot_name = ">>> Apply >>>" + output.get_value_from_owner = true + + register_input_property(output) + register_output_property(output) + +func _register_methods(mm_graph_node) -> void: + mm_graph_node.add_slot_label_universal(output) + + mm_graph_node.add_slot_float("get_scale", "set_scale", "Scale", 0.01) + +func get_property_value(uv : Vector2): + #$in(($uv-vec2(0.5))/$s+vec2(0.5))*$s + return output.get_value(((uv - Vector2(0.5, 0.5)) / scale + Vector2(0.5, 0.5)), true) + +#scale +func get_scale() -> float: + return scale + +func set_scale(val : float) -> void: + scale = val + + emit_changed() + output.emit_changed() + diff --git a/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_translate.gd b/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_translate.gd new file mode 100644 index 00000000..c3099e0b --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/sdf2d/sd_tf_translate.gd @@ -0,0 +1,38 @@ +tool +extends MMNode + +export(Resource) var output : Resource +export(Vector2) var translation : Vector2 = Vector2(0, 0) + +func _init_properties(): + if !output: + output = MMNodeUniversalProperty.new() + output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT + + output.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL + output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL + #output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT + output.slot_name = ">>> Apply >>>" + output.get_value_from_owner = true + + register_input_property(output) + register_output_property(output) + +func _register_methods(mm_graph_node) -> void: + mm_graph_node.add_slot_label_universal(output) + + mm_graph_node.add_slot_vector2("get_translation", "set_translation", "Translation", 0.01) + +func get_property_value(uv : Vector2): + return output.get_value(uv - translation, true) + +#a +func get_translation() -> Vector2: + return translation + +func set_translation(val : Vector2) -> void: + translation = val + + emit_changed() + output.emit_changed() +