diff --git a/addons/material_maker/icons/icons.svg b/addons/material_maker/icons/icons.svg index 31fb4ee..49ef1a4 100644 --- a/addons/material_maker/icons/icons.svg +++ b/addons/material_maker/icons/icons.svg @@ -535,5 +535,10 @@ d="m 6.5259032,281.28721 v 5.18946 H 1.3344969 v 2.96679 h 5.1914063 v 5.19141 h 2.9648437 v -5.19141 h 5.1914061 v -2.96679 H 9.4907469 v -5.18946 z" id="rect1173" inkscape:connector-curvature="0" /> + diff --git a/addons/material_maker/nodes/sdarc.mmg b/addons/material_maker/nodes/sdarc.mmg index 79b96d6..4042492 100644 --- a/addons/material_maker/nodes/sdarc.mmg +++ b/addons/material_maker/nodes/sdarc.mmg @@ -5,17 +5,17 @@ "y": 0 }, "parameters": { - "a1": 0, - "a2": -50, + "a1": 135, + "a2": 45, "cx": 0, "cy": 0, "r": 0.4, - "r1": 0.29021, - "r2": 0.075098 + "r1": 0.3, + "r2": 0.1 }, "shader_model": { "code": "", - "global": "float sdArc(vec2 p, vec2 sca, vec2 scb, float ra, float rb) {\n p *= mat2(vec2(sca.x,sca.y),vec2(-sca.y,sca.x));\n p.x = abs(p.x);\n float k = (scb.y*p.x>scb.x*p.y) ? dot(p.xy,scb) : length(p.xy);\n return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;\n}", + "global": "float sdArc(vec2 p, float a1, float a2, float ra, float rb) {\n\tfloat amid = 0.5*(a1+a2)+1.6+3.14*step(a1, a2);\n\tfloat alength = 0.5*(a1-a2)-1.6+3.14*step(a1, a2);\n\tvec2 sca = vec2(cos(amid), sin(amid));\n\tvec2 scb = vec2(cos(alength), sin(alength));\n p *= mat2(vec2(sca.x,sca.y),vec2(-sca.y,sca.x));\n p.x = abs(p.x);\n float k = (scb.y*p.x>scb.x*p.y) ? dot(p.xy,scb) : length(p.xy);\n return sqrt( dot(p,p) + ra*ra - 2.0*ra*k ) - rb;\n}\n", "inputs": [ ], @@ -23,13 +23,13 @@ "name": "sdArc", "outputs": [ { - "sdf2d": "sdArc($uv-vec2(0.5), vec2(cos($a1*0.01745329251), sin($a1*0.01745329251)), vec2(cos($a2*0.01745329251), sin($a2*0.01745329251)), $r1, $r2)", + "sdf2d": "sdArc($uv-vec2(0.5), mod($a1, 360.0)*0.01745329251, mod($a2, 360.0)*0.01745329251, $r1, $r2)", "type": "sdf2d" } ], "parameters": [ { - "control": "None", + "control": "Angle1.a", "default": 0, "label": "Angle 1", "max": 180, @@ -39,7 +39,7 @@ "type": "float" }, { - "control": "None", + "control": "Angle2.a", "default": 0, "label": "Angle 2", "max": 180, @@ -49,7 +49,7 @@ "type": "float" }, { - "control": "Radius1.x", + "control": "Radius1.r", "default": 0.5, "label": "Radius 1", "max": 1, @@ -59,7 +59,7 @@ "type": "float" }, { - "control": "Radius11.x", + "control": "Radius11.r", "default": 0.1, "label": "Radius 2", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_box.mmg b/addons/material_maker/nodes/sdf3d_box.mmg index cd4405e..dd3bf88 100644 --- a/addons/material_maker/nodes/sdf3d_box.mmg +++ b/addons/material_maker/nodes/sdf3d_box.mmg @@ -5,10 +5,10 @@ "y": 0 }, "parameters": { - "r": 0.01, - "sx": 0.25, + "r": 0.05, + "sx": 0.3, "sy": 0.25, - "sz": 0.5 + "sz": 0.25 }, "shader_model": { "code": "vec3 $(name_uv)_q = abs($uv) - vec3($sx, $sy, $sz);\n", @@ -26,6 +26,7 @@ ], "parameters": [ { + "control": "Rect1.x", "default": 0.5, "label": "Size X", "max": 1, @@ -35,6 +36,7 @@ "type": "float" }, { + "control": "Rect1.y", "default": 0.5, "label": "Size Y", "max": 1, @@ -44,6 +46,7 @@ "type": "float" }, { + "control": "None", "default": 0.5, "label": "Size Z", "max": 1, @@ -53,6 +56,7 @@ "type": "float" }, { + "control": "None", "default": 0.5, "label": "Radius", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_capsule.mmg b/addons/material_maker/nodes/sdf3d_capsule.mmg index e67b994..814585b 100644 --- a/addons/material_maker/nodes/sdf3d_capsule.mmg +++ b/addons/material_maker/nodes/sdf3d_capsule.mmg @@ -5,14 +5,14 @@ "y": 0 }, "parameters": { - "l": 0.25, - "r": 0.1, + "l": 0.3, + "r": 0.15, "sx": 0.25, "sy": 0.25, "sz": 0.5 }, "shader_model": { - "code": "vec3 $(name_uv)_p = $uv;\n$(name_uv)_p.y -= clamp($(name_uv)_p.y, -0.5*$l, 0.5*$l);\n", + "code": "vec3 $(name_uv)_p = $uv;\n$(name_uv)_p.y -= clamp($(name_uv)_p.y, -$l, $l);\n", "global": "", "inputs": [ @@ -27,7 +27,8 @@ ], "parameters": [ { - "default": 0.5, + "control": "Rect1.y", + "default": 0.25, "label": "Length", "max": 1, "min": 0, @@ -36,6 +37,7 @@ "type": "float" }, { + "control": "Rect1.x", "default": 0.2, "label": "Radius", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_cylinder.mmg b/addons/material_maker/nodes/sdf3d_cylinder.mmg index d26e8f1..34a7877 100644 --- a/addons/material_maker/nodes/sdf3d_cylinder.mmg +++ b/addons/material_maker/nodes/sdf3d_cylinder.mmg @@ -5,8 +5,8 @@ "y": 0 }, "parameters": { - "l": 0.25, - "r": 0.1, + "l": 0.4, + "r": 0.2, "sx": 0.25, "sy": 0.25, "sz": 0.5 @@ -27,6 +27,7 @@ ], "parameters": [ { + "control": "Rect1.y", "default": 0.5, "label": "Length", "max": 1, @@ -36,6 +37,7 @@ "type": "float" }, { + "control": "Rect1.x", "default": 0.2, "label": "Radius", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_scale.mmg b/addons/material_maker/nodes/sdf3d_scale.mmg index 0ee47bf..9cec47e 100644 --- a/addons/material_maker/nodes/sdf3d_scale.mmg +++ b/addons/material_maker/nodes/sdf3d_scale.mmg @@ -32,6 +32,7 @@ ], "parameters": [ { + "control": "Scale1.x", "default": 1, "label": "", "max": 5, diff --git a/addons/material_maker/nodes/sdf3d_sphere.mmg b/addons/material_maker/nodes/sdf3d_sphere.mmg index 06891a1..c62785e 100644 --- a/addons/material_maker/nodes/sdf3d_sphere.mmg +++ b/addons/material_maker/nodes/sdf3d_sphere.mmg @@ -5,7 +5,7 @@ "y": 0 }, "parameters": { - "r": 0.5 + "r": 0.4 }, "shader_model": { "code": "", @@ -23,6 +23,7 @@ ], "parameters": [ { + "control": "Radius1.r", "default": 0.5, "label": "", "max": 1, diff --git a/addons/material_maker/nodes/sdf3d_torus.mmg b/addons/material_maker/nodes/sdf3d_torus.mmg index 60022c1..4397002 100644 --- a/addons/material_maker/nodes/sdf3d_torus.mmg +++ b/addons/material_maker/nodes/sdf3d_torus.mmg @@ -5,7 +5,7 @@ "y": 0 }, "parameters": { - "R": 0.25, + "R": 0.3, "r": 0.1, "sx": 0.1, "sy": 0.1, @@ -27,6 +27,7 @@ ], "parameters": [ { + "control": "Radius1.r", "default": 0.5, "label": "R", "max": 1, @@ -36,6 +37,7 @@ "type": "float" }, { + "control": "Radius11.r", "default": 0.1, "label": "r", "max": 0.5, diff --git a/addons/material_maker/nodes/sdf3d_translate.mmg b/addons/material_maker/nodes/sdf3d_translate.mmg index 7a7f167..141810f 100644 --- a/addons/material_maker/nodes/sdf3d_translate.mmg +++ b/addons/material_maker/nodes/sdf3d_translate.mmg @@ -30,6 +30,7 @@ ], "parameters": [ { + "control": "P1.x", "default": 0, "label": "X", "max": 1, @@ -39,6 +40,7 @@ "type": "float" }, { + "control": "P1.y", "default": 0, "label": "Y", "max": 1, @@ -48,6 +50,7 @@ "type": "float" }, { + "control": "None", "default": 0, "label": "Z", "max": 1, diff --git a/addons/material_maker/nodes/sdrotate.mmg b/addons/material_maker/nodes/sdrotate.mmg index fefaaab..0f68851 100644 --- a/addons/material_maker/nodes/sdrotate.mmg +++ b/addons/material_maker/nodes/sdrotate.mmg @@ -31,6 +31,7 @@ ], "parameters": [ { + "control": "Radius1.a", "default": 0, "label": "", "max": 180, diff --git a/addons/material_maker/nodes/transform.mmg b/addons/material_maker/nodes/transform.mmg index 6112fc1..9b52fcc 100644 --- a/addons/material_maker/nodes/transform.mmg +++ b/addons/material_maker/nodes/transform.mmg @@ -63,54 +63,54 @@ ], "parameters": [ { + "control": "P1.x", "default": 0, "label": "2:Translate X:", "max": 1, "min": -1, "name": "translate_x", "step": 0.005, - "type": "float", - "widget": "spinbox" + "type": "float" }, { + "control": "P1.y", "default": 0, "label": "Translate Y:", "max": 1, "min": -1, "name": "translate_y", "step": 0.005, - "type": "float", - "widget": "spinbox" + "type": "float" }, { + "control": "Radius1.a", "default": 0, "label": "Rotate:", "max": 720, "min": -720, "name": "rotate", "step": 0.005, - "type": "float", - "widget": "spinbox" + "type": "float" }, { + "control": "Scale1.x", "default": 1, "label": "Scale X:", "max": 50, "min": 0, "name": "scale_x", "step": 0.005, - "type": "float", - "widget": "spinbox" + "type": "float" }, { + "control": "Scale1.y", "default": 1, "label": "Scale Y:", "max": 50, "min": 0, "name": "scale_y", "step": 0.005, - "type": "float", - "widget": "spinbox" + "type": "float" }, { "default": false, diff --git a/addons/material_maker/preview/control_point.gd b/addons/material_maker/preview/control_point.gd index 8845b1e..403a28f 100644 --- a/addons/material_maker/preview/control_point.gd +++ b/addons/material_maker/preview/control_point.gd @@ -1,12 +1,16 @@ extends TextureRect export var parent_control : String = "" -export(int, "Simple", "Rect", "Radius", "Scale", "ScaleXY" ) var control_type : int = 0 +export(int, "Simple", "Rect", "Radius", "Scale" ) var control_type : int = 0 var generator : MMGenBase = null var parameter_x : String = "" var parameter_y : String = "" -var dragging = false +var parameter_r : String = "" +var parameter_a : String = "" +var is_xy : bool = false + +var dragging : bool = false var parent_control_node = null var children_control_nodes = [] @@ -23,11 +27,18 @@ func _draw() -> void: var ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size draw_rect(Rect2(0.5*rect_size, 2.0*(ppos-(rect_position+0.5*rect_size))), modulate, false) 2: # Radius - draw_line(0.5*rect_size, 0.5*rect_size-get_parent().value_to_offset(get_value()), modulate) + var ppos + if parent_control_node == null: + ppos = get_parent().value_to_pos(Vector2(0, 0)) + else: + ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size + draw_line(0.5*rect_size, ppos-rect_position, modulate) 3: # Scale - draw_line(0.5*rect_size, 0.5*rect_size-get_parent().value_to_offset(0.25*get_value()), modulate) - 4: # ScaleXY - var ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size + var ppos + if parent_control_node == null: + ppos = get_parent().value_to_pos(Vector2(0, 0)) + else: + ppos = parent_control_node.rect_position+0.5*parent_control_node.rect_size draw_rect(Rect2(0.5*rect_size, ppos-(rect_position+0.5*rect_size)), modulate, false) func setup_control(g : MMGenBase, param_defs : Array) -> void: @@ -37,6 +48,8 @@ func setup_control(g : MMGenBase, param_defs : Array) -> void: generator = g parameter_x = "" parameter_y = "" + parameter_r = "" + parameter_a = "" for p in param_defs: if p.has("control"): if p.control == name+".x": @@ -45,6 +58,13 @@ func setup_control(g : MMGenBase, param_defs : Array) -> void: elif p.control == name+".y": show() parameter_y = p.name + elif p.control == name+".r": + show() + parameter_r = p.name + elif p.control == name+".a": + show() + parameter_a = p.name + is_xy = parameter_x != "" or parameter_y != "" if visible: generator.connect("parameter_changed", self, "on_parameter_changed") update_position(get_value()) @@ -55,32 +75,52 @@ func setup_control(g : MMGenBase, param_defs : Array) -> void: func get_value() -> Vector2: var pos : Vector2 = Vector2(0, 0) if is_instance_valid(generator): - if parameter_x != "": - pos.x = generator.get_parameter(parameter_x) - if parameter_y != "": - pos.y = generator.get_parameter(parameter_y) + if is_xy: + if parameter_x != "": + pos.x = generator.get_parameter(parameter_x) + if parameter_y != "": + pos.y = generator.get_parameter(parameter_y) + else: + var r = 0.25 + var a = 0 + if parameter_r != "": + r = generator.get_parameter(parameter_r) + if parameter_a != "": + a = generator.get_parameter(parameter_a)*0.01745329251 + pos.x = r*cos(a) + pos.y = r*sin(a) return pos +func get_parent_value() -> Vector2: + var parent_value = Vector2(0, 0) + var p = parent_control_node + while p != null: + parent_value += p.get_value() + p = p.parent_control_node + return parent_value + func on_parameter_changed(p, v) -> void: - if !dragging and (p == parameter_x or p == parameter_y): + if !dragging and (p == parameter_x or p == parameter_y or p == parameter_r or p == parameter_a): update_position(get_value()) update() -func update_parameters(pos : Vector2) -> void: +func update_parameters(value : Vector2) -> void: if !is_instance_valid(generator): return - if parent_control_node != null: - pos -= parent_control_node.get_value() match control_type: 1: # Rect - pos.x = abs(pos.x) - pos.y = abs(pos.y) + value.x = abs(value.x) + value.y = abs(value.y) 3: # Scale - pos.x = 4.0*pos.x + value = 4.0*value if parameter_x != "": - generator.set_parameter(parameter_x, pos.x) + generator.set_parameter(parameter_x, value.x) if parameter_y != "": - generator.set_parameter(parameter_y, pos.y) + generator.set_parameter(parameter_y, value.y) + if parameter_r != "": + generator.set_parameter(parameter_r, value.length()) + if parameter_a != "": + generator.set_parameter(parameter_a, atan2(value.y, value.x)*57.2957795131) func update_position(pos : Vector2) -> void: match control_type: @@ -88,24 +128,28 @@ func update_position(pos : Vector2) -> void: pos *= 0.25 if parent_control_node != null: pos += parent_control_node.get_value() - rect_position = get_parent().value_to_pos(pos+Vector2(0.5, 0.5))-0.5*rect_size + rect_position = get_parent().value_to_pos(pos)-0.5*rect_size for c in children_control_nodes: c.update_position(c.get_value()) update() func _on_Point_gui_input(event : InputEvent): if event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT: - rect_position += event.relative - match control_type: - 2: # Radius - rect_position.x = max(rect_position.x, parent_control_node.rect_position.x+0.5*(parent_control_node.rect_size.x-rect_size.x)) - rect_position.y = parent_control_node.rect_position.y+0.5*(parent_control_node.rect_size.y-rect_size.y) - 3: # Scale - rect_position.x = max(rect_position.x, parent_control_node.rect_position.x+0.5*(parent_control_node.rect_size.x-rect_size.x)) - rect_position.y = parent_control_node.rect_position.y+0.5*(parent_control_node.rect_size.y-rect_size.y) - var pos = get_parent().pos_to_value(rect_position+0.5*rect_size)-Vector2(0.5, 0.5) + var parent_value = get_parent_value() + var value = get_parent().pos_to_value(rect_position+0.5*rect_size+event.relative)-parent_value + if is_xy: + if parameter_x == "": + value.x = 0 + if parameter_y == "": + value.y = 0 + else: + if parameter_r == "": + value = 0.25*value/value.length() + if parameter_a == "": + value = Vector2(value.length(), 0.0) + rect_position = get_parent().value_to_pos(value+parent_value)-0.5*rect_size dragging = true - update_parameters(pos) + update_parameters(value) update() dragging = false for c in children_control_nodes: diff --git a/addons/material_maker/preview/preview_2d.gd b/addons/material_maker/preview/preview_2d.gd index a70f161..d1d14e6 100644 --- a/addons/material_maker/preview/preview_2d.gd +++ b/addons/material_maker/preview/preview_2d.gd @@ -22,10 +22,10 @@ func setup_controls(g : MMGenBase) -> void: c.setup_control(generator, []) func value_to_pos(value : Vector2) -> Vector2: - return rect_size*0.5+(value-Vector2(0.5, 0.5))*min(rect_size.x, rect_size.y)/1.2 + return rect_size*0.5+value*min(rect_size.x, rect_size.y)/1.2 func value_to_offset(value : Vector2) -> Vector2: return value*min(rect_size.x, rect_size.y)/1.2 func pos_to_value(pos : Vector2) -> Vector2: - return (pos - rect_size*0.5)*1.2/min(rect_size.x, rect_size.y)+Vector2(0.5, 0.5) + return (pos - rect_size*0.5)*1.2/min(rect_size.x, rect_size.y) diff --git a/addons/material_maker/preview/preview_2d.tscn b/addons/material_maker/preview/preview_2d.tscn index bcb8872..337910a 100644 --- a/addons/material_maker/preview/preview_2d.tscn +++ b/addons/material_maker/preview/preview_2d.tscn @@ -29,7 +29,7 @@ region = Rect2( 64, 48, 32, 32 ) [sub_resource type="AtlasTexture" id=4] flags = 4 atlas = ExtResource( 3 ) -region = Rect2( 0, 64, 16, 16 ) +region = Rect2( 16, 64, 16, 16 ) [node name="Preview2D" type="ColorRect"] material = SubResource( 2 ) @@ -92,4 +92,24 @@ mouse_default_cursor_shape = 10 texture = SubResource( 4 ) parent_control = "P1" control_type = 3 + +[node name="Angle1" parent="." instance=ExtResource( 2 )] +visible = false +self_modulate = Color( 1, 0.631373, 0, 1 ) +margin_right = 16.0 +margin_bottom = 16.0 +mouse_default_cursor_shape = 10 +texture = SubResource( 4 ) +parent_control = "P1" +control_type = 2 + +[node name="Angle2" parent="." instance=ExtResource( 2 )] +visible = false +self_modulate = Color( 1, 0.631373, 0, 1 ) +margin_right = 16.0 +margin_bottom = 16.0 +mouse_default_cursor_shape = 10 +texture = SubResource( 4 ) +parent_control = "P1" +control_type = 2 [connection signal="resized" from="." to="." method="on_resized"] diff --git a/addons/material_maker/widgets/node_editor/parameter_float.gd b/addons/material_maker/widgets/node_editor/parameter_float.gd index 0171951..83a0973 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.gd +++ b/addons/material_maker/widgets/node_editor/parameter_float.gd @@ -1,6 +1,13 @@ tool extends HBoxContainer +const CONTROLS = [ "None", "P1.x", "P1.y", "P1.a", "P1.r", "P2.x", "P2.y", "P2.a", "P2.r", "Rect1.x", "Rect1.y", "Radius1.r", "Radius1.a", "Radius11.r", "Radius11.a", "Scale1.x", "Scale1.y", "Angle1.a", "Angle2.a" ] + +func _ready() -> void: + $Control.clear() + for c in CONTROLS: + $Control.add_item(c) + func get_model_data() -> Dictionary: var data = { min = $Min.value, diff --git a/addons/material_maker/widgets/node_editor/parameter_float.tscn b/addons/material_maker/widgets/node_editor/parameter_float.tscn index 79ed7b8..fb8098f 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.tscn +++ b/addons/material_maker/widgets/node_editor/parameter_float.tscn @@ -94,7 +94,6 @@ margin_left = 458.0 margin_right = 533.0 margin_bottom = 24.0 text = "None" -items = [ "None", null, false, 0, null, "P1.x", null, false, 1, null, "P1.y", null, false, 2, null, "P2.x", null, false, 3, null, "P2.y", null, false, 4, null, "Rect1.x", null, false, 5, null, "Rect1.y", null, false, 6, null, "Radius1.x", null, false, 7, null, "Radius11.x", null, false, 8, null, "Scale1.x", null, false, 9, null ] selected = 0 [connection signal="value_changed" from="Min" to="." method="_on_Min_value_changed"] [connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"]