Added UI in 2D preview to edit parameters.

This commit is contained in:
Rodolphe Suescun 2019-12-27 22:30:49 +01:00
parent a806ea19a3
commit 5207b8093e
23 changed files with 329 additions and 47 deletions

View File

@ -116,6 +116,9 @@ func get_parameter_def(param_name : String) -> Dictionary:
return p return p
return {} return {}
func get_parameter(n : String):
return parameters[n]
func set_parameter(n : String, v) -> void: func set_parameter(n : String, v) -> void:
parameters[n] = v parameters[n] = v
source_changed(0) source_changed(0)

View File

@ -10,6 +10,8 @@ var need_save = false
var top_generator = null var top_generator = null
var generator = null var generator = null
var last_selected = null
onready var timer : Timer = $Timer onready var timer : Timer = $Timer
onready var subgraph_ui : HBoxContainer = $GraphUI/SubGraphUI onready var subgraph_ui : HBoxContainer = $GraphUI/SubGraphUI
@ -354,3 +356,16 @@ func edit_subgraph(g : MMGenGraph) -> void:
func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void: func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void:
if button_pressed != generator.transmits_seed: if button_pressed != generator.transmits_seed:
generator.transmits_seed = button_pressed generator.transmits_seed = button_pressed
func _on_GraphEdit_node_selected(node) -> void:
last_selected = node
func _on_GraphEdit_gui_input(event) -> void:
if event is InputEventMouseButton:
call_deferred("check_last_selected")
func check_last_selected() -> void:
if last_selected != null and !(is_instance_valid(last_selected) && last_selected.selected):
print("Unselected")
last_selected = null
emit_signal("node_selected", null)

View File

@ -79,6 +79,8 @@ icon = SubResource( 4 )
[connection signal="connection_request" from="." to="." method="connect_node"] [connection signal="connection_request" from="." to="." method="connect_node"]
[connection signal="disconnection_request" from="." to="." method="disconnect_node"] [connection signal="disconnection_request" from="." to="." method="disconnect_node"]
[connection signal="duplicate_nodes_request" from="." to="." method="duplicate_selected"] [connection signal="duplicate_nodes_request" from="." to="." method="duplicate_selected"]
[connection signal="gui_input" from="." to="." method="_on_GraphEdit_gui_input"]
[connection signal="node_selected" from="." to="." method="_on_GraphEdit_node_selected"]
[connection signal="timeout" from="Timer" to="." method="do_send_changed_signal"] [connection signal="timeout" from="Timer" to="." method="do_send_changed_signal"]
[connection signal="text_changed" from="GraphUI/SubGraphUI/Label" to="." method="_on_Label_text_changed"] [connection signal="text_changed" from="GraphUI/SubGraphUI/Label" to="." method="_on_Label_text_changed"]
[connection signal="toggled" from="GraphUI/SubGraphUI/ButtonTransmitsSeed" to="." method="_on_ButtonTransmitsSeed_toggled"] [connection signal="toggled" from="GraphUI/SubGraphUI/ButtonTransmitsSeed" to="." method="_on_ButtonTransmitsSeed_toggled"]

View File

@ -15,7 +15,7 @@
viewBox="0 0 128 128" viewBox="0 0 128 128"
version="1.1" version="1.1"
id="svg8" id="svg8"
inkscape:version="0.92.3 (2405546, 2018-03-11)" inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="icons.svg"> sodipodi:docname="icons.svg">
<defs <defs
id="defs2"> id="defs2">
@ -55,9 +55,9 @@
borderopacity="1.0" borderopacity="1.0"
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="28.608854" inkscape:zoom="20.229515"
inkscape:cx="54.703743" inkscape:cx="12.288977"
inkscape:cy="64.734209" inkscape:cy="55.740147"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
showgrid="true" showgrid="true"
@ -86,7 +86,7 @@
<dc:format>image/svg+xml</dc:format> <dc:format>image/svg+xml</dc:format>
<dc:type <dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title> <dc:title />
</cc:Work> </cc:Work>
</rdf:RDF> </rdf:RDF>
</metadata> </metadata>
@ -525,5 +525,15 @@
id="path4610" id="path4610"
inkscape:connector-curvature="0" inkscape:connector-curvature="0"
sodipodi:nodetypes="ccczccccczccc" /> sodipodi:nodetypes="ccczccccczccc" />
<path
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.8088189;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="M 80.011719 49.464844 C 72.001268 49.464844 65.474609 56.033506 65.474609 64.072266 C 65.474609 72.111026 72.001268 78.681641 80.011719 78.681641 C 88.022167 78.681641 94.544922 72.111026 94.544922 64.072266 C 94.544922 56.033506 88.022167 49.464844 80.011719 49.464844 z M 77.914062 53.720703 L 77.914062 57.927734 L 82.109375 57.927734 L 82.109375 53.720703 C 86.235662 54.556313 89.469292 57.812373 90.292969 61.976562 L 86.152344 61.976562 L 86.152344 66.169922 L 90.289062 66.169922 C 89.463951 70.331962 86.234181 73.590471 82.109375 74.425781 L 82.109375 70.21875 L 77.914062 70.21875 L 77.914062 74.425781 C 73.789254 73.590471 70.559484 70.331962 69.734375 66.169922 L 73.867188 66.169922 L 73.867188 61.976562 L 69.730469 61.976562 C 70.554144 57.812372 73.787776 54.556313 77.914062 53.720703 z M 77.876953 61.941406 L 77.876953 66.205078 L 82.142578 66.205078 L 82.142578 61.941406 L 77.876953 61.941406 z "
transform="translate(0,216.06665)"
id="path973" />
<path
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0.80881888;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
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" />
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -739,7 +739,6 @@
"cx": 0, "cx": 0,
"cy": 0, "cy": 0,
"h": 0.2, "h": 0.2,
"r": 0.3,
"w": 0.3 "w": 0.3
}, },
"tree_item": "Simple/SDF/Shapes/sdBox", "tree_item": "Simple/SDF/Shapes/sdBox",
@ -750,15 +749,10 @@
"icon": "simple_sdf_shapes_sdline", "icon": "simple_sdf_shapes_sdline",
"name": "sdline", "name": "sdline",
"parameters": { "parameters": {
"ax": 0.2, "ax": -0.3,
"ay": 0.2, "ay": -0.3,
"bx": 0.8, "bx": 0.3,
"by": 0.8, "by": 0.3
"cx": 0,
"cy": 0,
"h": 0.2,
"r": 0.3,
"w": 0.3
}, },
"tree_item": "Simple/SDF/Shapes/sdLine", "tree_item": "Simple/SDF/Shapes/sdLine",
"type": "sdline" "type": "sdline"
@ -771,7 +765,6 @@
"cx": 0, "cx": 0,
"cy": 0, "cy": 0,
"h": 0.2, "h": 0.2,
"r": 0.3,
"w": 0.3 "w": 0.3
}, },
"tree_item": "Simple/SDF/Shapes/sdRhombus", "tree_item": "Simple/SDF/Shapes/sdRhombus",

View File

@ -488,6 +488,8 @@ func update_preview_2d(node = null) -> void:
result.copy_to_texture(tex) result.copy_to_texture(tex)
result.release() result.release()
preview_2d.set_preview_texture(tex) preview_2d.set_preview_texture(tex)
else:
preview_2d.set_preview_texture(null)
func update_preview_3d(previews : Array) -> void: func update_preview_3d(previews : Array) -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit() var graph_edit : MMGraphEdit = get_current_graph_edit()
@ -499,6 +501,10 @@ func update_preview_3d(previews : Array) -> void:
for p in previews: for p in previews:
gen_material.update_materials(p.get_materials()) gen_material.update_materials(p.get_materials())
func on_selected_node_change(node) -> void:
preview_2d.setup_controls(node.generator if node != null else null)
update_preview_2d(node)
func _on_Projects_tab_changed(tab) -> void: func _on_Projects_tab_changed(tab) -> void:
var new_tab = projects.get_current_tab_control() var new_tab = projects.get_current_tab_control()
if new_tab != current_tab: if new_tab != current_tab:
@ -507,7 +513,7 @@ func _on_Projects_tab_changed(tab) -> void:
if c.method_name == "update_preview" or c.method_name == "update_preview_2d": if c.method_name == "update_preview" or c.method_name == "update_preview_2d":
c.source.disconnect(c.signal_name, self, c.method_name) c.source.disconnect(c.signal_name, self, c.method_name)
new_tab.connect("graph_changed", self, "update_preview") new_tab.connect("graph_changed", self, "update_preview")
new_tab.connect("node_selected", self, "update_preview_2d") new_tab.connect("node_selected", self, "on_selected_node_change")
current_tab = new_tab current_tab = new_tab
update_preview() update_preview()

View File

@ -7,6 +7,9 @@ var generator : MMGenBase = null setget set_generator
func _ready() -> void: func _ready() -> void:
connect("offset_changed", self, "_on_offset_changed") connect("offset_changed", self, "_on_offset_changed")
func _exit_tree() -> void:
get_parent().call_deferred("check_last_selected")
func _draw() -> void: func _draw() -> void:
if generator != null and generator.has_randomness(): if generator != null and generator.has_randomness():
var icon = preload("res://addons/material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://addons/material_maker/icons/randomness_unlocked.tres") var icon = preload("res://addons/material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://addons/material_maker/icons/randomness_unlocked.tres")

View File

@ -35,6 +35,7 @@
], ],
"parameters": [ "parameters": [
{ {
"control": "Radius1.x",
"default": 0, "default": 0,
"label": "", "label": "",
"max": 1, "max": 1,

View File

@ -6,12 +6,12 @@
}, },
"parameters": { "parameters": {
"a1": 0, "a1": 0,
"a2": 0, "a2": -50,
"cx": 0, "cx": 0,
"cy": 0, "cy": 0,
"r": 0.4, "r": 0.4,
"r1": 0.3, "r1": 0.29021,
"r2": 0.1 "r2": 0.075098
}, },
"shader_model": { "shader_model": {
"code": "", "code": "",
@ -29,6 +29,7 @@
], ],
"parameters": [ "parameters": [
{ {
"control": "None",
"default": 0, "default": 0,
"label": "Angle 1", "label": "Angle 1",
"max": 180, "max": 180,
@ -38,6 +39,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "None",
"default": 0, "default": 0,
"label": "Angle 2", "label": "Angle 2",
"max": 180, "max": 180,
@ -47,6 +49,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "Radius1.x",
"default": 0.5, "default": 0.5,
"label": "Radius 1", "label": "Radius 1",
"max": 1, "max": 1,
@ -56,6 +59,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "Radius11.x",
"default": 0.1, "default": 0.1,
"label": "Radius 2", "label": "Radius 2",
"max": 1, "max": 1,

View File

@ -12,7 +12,7 @@
"w": 0.3 "w": 0.3
}, },
"shader_model": { "shader_model": {
"code": "vec2 $(name_uv)_d = abs($uv-0.5*vec2($cx+1.0, $cy+1.0))-vec2($w, $h);\n", "code": "vec2 $(name_uv)_d = abs($uv-vec2($cx+0.5, $cy+0.5))-vec2($w, $h);\n",
"global": "", "global": "",
"inputs": [ "inputs": [
@ -27,6 +27,7 @@
], ],
"parameters": [ "parameters": [
{ {
"control": "Rect1.x",
"default": 0.5, "default": 0.5,
"label": "Width", "label": "Width",
"max": 1, "max": 1,
@ -36,6 +37,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "Rect1.y",
"default": 1, "default": 1,
"label": "Height", "label": "Height",
"max": 1, "max": 1,
@ -45,6 +47,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.x",
"default": 0, "default": 0,
"label": "Center X", "label": "Center X",
"max": 1, "max": 1,
@ -54,6 +57,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.y",
"default": 0, "default": 0,
"label": "Center Y", "label": "Center Y",
"max": 1, "max": 1,

View File

@ -7,7 +7,7 @@
"parameters": { "parameters": {
"cx": 0, "cx": 0,
"cy": 0, "cy": 0,
"r": 0.25 "r": 0.4
}, },
"shader_model": { "shader_model": {
"code": "", "code": "",
@ -19,12 +19,13 @@
"name": "sdCircle", "name": "sdCircle",
"outputs": [ "outputs": [
{ {
"sdf2d": "length($uv-0.5*vec2($cx+1.0, $cy+1.0))-$r", "sdf2d": "length($uv-vec2($cx+0.5, $cy+0.5))-$r",
"type": "sdf2d" "type": "sdf2d"
} }
], ],
"parameters": [ "parameters": [
{ {
"control": "Radius1.x",
"default": 0.5, "default": 0.5,
"label": "Radius", "label": "Radius",
"max": 1, "max": 1,
@ -34,6 +35,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.x",
"default": 0, "default": 0,
"label": "Center X", "label": "Center X",
"max": 1, "max": 1,
@ -43,6 +45,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.y",
"default": 0, "default": 0,
"label": "Center Y", "label": "Center Y",
"max": 1, "max": 1,

View File

@ -5,10 +5,10 @@
"y": 0 "y": 0
}, },
"parameters": { "parameters": {
"ax": 0.2, "ax": 0.224,
"ay": 0.2, "ay": 0.2672,
"bx": 0.8, "bx": -0.272,
"by": 0.8, "by": -0.2344,
"cx": 0, "cx": 0,
"cy": 0, "cy": 0,
"h": 0.2, "h": 0.2,
@ -25,43 +25,47 @@
"name": "sdLine", "name": "sdLine",
"outputs": [ "outputs": [
{ {
"sdf2d": "sdLine($uv, vec2($ax, $ay), vec2($bx, $by))", "sdf2d": "sdLine($uv, vec2($ax+0.5, $ay+0.5), vec2($bx+0.5, $by+0.5))",
"type": "sdf2d" "type": "sdf2d"
} }
], ],
"parameters": [ "parameters": [
{ {
"control": "P1.x",
"default": 0, "default": 0,
"label": "A X", "label": "A X",
"max": 1, "max": 1,
"min": 0, "min": -1,
"name": "ax", "name": "ax",
"step": 0.01, "step": 0.01,
"type": "float" "type": "float"
}, },
{ {
"control": "P1.y",
"default": 0, "default": 0,
"label": "A Y", "label": "A Y",
"max": 1, "max": 1,
"min": 0, "min": -1,
"name": "ay", "name": "ay",
"step": 0.01, "step": 0.01,
"type": "float" "type": "float"
}, },
{ {
"control": "P2.x",
"default": 1, "default": 1,
"label": "B X", "label": "B X",
"max": 1, "max": 1,
"min": 0, "min": -1,
"name": "bx", "name": "bx",
"step": 0.01, "step": 0.01,
"type": "float" "type": "float"
}, },
{ {
"control": "P2.y",
"default": 1, "default": 1,
"label": "B Y", "label": "B Y",
"max": 1, "max": 1,
"min": 0, "min": -1,
"name": "by", "name": "by",
"step": 0.01, "step": 0.01,
"type": "float" "type": "float"

View File

@ -5,11 +5,11 @@
"y": 0 "y": 0
}, },
"parameters": { "parameters": {
"cx": 0, "cx": -0.19353,
"cy": 0, "cy": -0.224011,
"h": 0.2, "h": 0.187815,
"r": 0.3, "r": 0.3,
"w": 0.5 "w": 0.393785
}, },
"shader_model": { "shader_model": {
"code": "", "code": "",
@ -21,12 +21,13 @@
"name": "sdRhombus", "name": "sdRhombus",
"outputs": [ "outputs": [
{ {
"sdf2d": "sdRhombus($uv-0.5*vec2($cx+1.0, $cy+1.0), vec2($w, $h))", "sdf2d": "sdRhombus($uv-vec2($cx+0.5, $cy+0.5), vec2($w, $h))",
"type": "sdf2d" "type": "sdf2d"
} }
], ],
"parameters": [ "parameters": [
{ {
"control": "Rect1.x",
"default": 0.5, "default": 0.5,
"label": "Width", "label": "Width",
"max": 1, "max": 1,
@ -36,6 +37,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "Rect1.y",
"default": 1, "default": 1,
"label": "Height", "label": "Height",
"max": 1, "max": 1,
@ -45,6 +47,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.x",
"default": 0, "default": 0,
"label": "Center X", "label": "Center X",
"max": 1, "max": 1,
@ -54,6 +57,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.y",
"default": 0, "default": 0,
"label": "Center Y", "label": "Center Y",
"max": 1, "max": 1,

View File

@ -11,7 +11,7 @@
"h": 0.08, "h": 0.08,
"k": 0.15, "k": 0.15,
"op": 0, "op": 0,
"r": 0.1, "r": 0.15,
"w": 0.28 "w": 0.28
}, },
"shader_model": { "shader_model": {
@ -35,6 +35,7 @@
], ],
"parameters": [ "parameters": [
{ {
"control": "Radius1.x",
"default": 0, "default": 0,
"label": "", "label": "",
"max": 1, "max": 1,

View File

@ -6,7 +6,7 @@
}, },
"parameters": { "parameters": {
"a": 0, "a": 0,
"s": 2.21, "s": 1,
"x": 0.35, "x": 0.35,
"y": 0, "y": 0,
"z": 0 "z": 0
@ -32,6 +32,7 @@
], ],
"parameters": [ "parameters": [
{ {
"control": "Scale1.x",
"default": 1, "default": 1,
"label": "", "label": "",
"max": 5, "max": 5,

View File

@ -5,8 +5,8 @@
"y": 0 "y": 0
}, },
"parameters": { "parameters": {
"x": 0, "x": 0.024,
"y": 0, "y": 0.024,
"z": 0 "z": 0
}, },
"shader_model": { "shader_model": {
@ -30,6 +30,7 @@
], ],
"parameters": [ "parameters": [
{ {
"control": "P1.x",
"default": 0, "default": 0,
"label": "X", "label": "X",
"max": 1, "max": 1,
@ -39,6 +40,7 @@
"type": "float" "type": "float"
}, },
{ {
"control": "P1.y",
"default": 0, "default": 0,
"label": "Y", "label": "Y",
"max": 1, "max": 1,

View File

@ -0,0 +1,112 @@
extends TextureRect
export var parent_control : String = ""
export(int, "Simple", "Rect", "Radius", "Scale", "ScaleXY" ) var control_type : int = 0
var generator : MMGenBase = null
var parameter_x : String = ""
var parameter_y : String = ""
var dragging = false
var parent_control_node = null
var children_control_nodes = []
func _ready() -> void:
if parent_control != "":
parent_control_node = get_parent().get_node(parent_control)
if parent_control_node != null:
parent_control_node.children_control_nodes.push_back(self)
func _draw() -> void:
match control_type:
1: # Rect
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)
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
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:
hide()
if is_instance_valid(generator):
generator.disconnect("parameter_changed", self, "on_parameter_changed")
generator = g
parameter_x = ""
parameter_y = ""
for p in param_defs:
if p.has("control"):
if p.control == name+".x":
show()
parameter_x = p.name
elif p.control == name+".y":
show()
parameter_y = p.name
if visible:
generator.connect("parameter_changed", self, "on_parameter_changed")
update_position(get_value())
else:
generator = null
update_position(Vector2(0, 0))
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)
return pos
func on_parameter_changed(p, v) -> void:
if !dragging and (p == parameter_x or p == parameter_y):
update_position(get_value())
update()
func update_parameters(pos : 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)
3: # Scale
pos.x = 4.0*pos.x
if parameter_x != "":
generator.set_parameter(parameter_x, pos.x)
if parameter_y != "":
generator.set_parameter(parameter_y, pos.y)
func update_position(pos : Vector2) -> void:
match control_type:
3: # Scale
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
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)
dragging = true
update_parameters(pos)
update()
dragging = false
for c in children_control_nodes:
c.update_position(c.get_value())

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/material_maker/preview/control_point.gd" type="Script" id=1]
[node name="Point" type="TextureRect"]
mouse_filter = 0
mouse_default_cursor_shape = 13
script = ExtResource( 1 )
[connection signal="gui_input" from="." to="." method="_on_Point_gui_input"]

View File

@ -1,8 +1,31 @@
tool tool
extends ColorRect extends ColorRect
var generator = null
func set_preview_texture(tex: Texture) -> void: func set_preview_texture(tex: Texture) -> void:
material.set_shader_param("tex", tex) material.set_shader_param("tex", tex)
func on_resized() -> void: func on_resized() -> void:
material.set_shader_param("size", rect_size) material.set_shader_param("size", rect_size)
setup_controls(generator)
func setup_controls(g : MMGenBase) -> void:
if is_instance_valid(g):
generator = g
var param_defs : Array = generator.get_parameter_defs()
for c in get_children():
c.setup_control(generator, param_defs)
else:
g = null
for c in get_children():
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
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)

View File

@ -1,6 +1,8 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=8 format=2]
[ext_resource path="res://addons/material_maker/preview/preview_2d.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/preview/preview_2d.gd" type="Script" id=1]
[ext_resource path="res://addons/material_maker/preview/control_point.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=3]
[sub_resource type="Shader" id=1] [sub_resource type="Shader" id=1]
code = "shader_type canvas_item; code = "shader_type canvas_item;
@ -17,17 +19,77 @@ void fragment() {
[sub_resource type="ShaderMaterial" id=2] [sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 ) shader = SubResource( 1 )
shader_param/size = Vector2( 64, 64 ) shader_param/size = Vector2( 721, 546 )
[sub_resource type="AtlasTexture" id=3]
flags = 4
atlas = ExtResource( 3 )
region = Rect2( 64, 48, 32, 32 )
[sub_resource type="AtlasTexture" id=4]
flags = 4
atlas = ExtResource( 3 )
region = Rect2( 0, 64, 16, 16 )
[node name="Preview2D" type="ColorRect"] [node name="Preview2D" type="ColorRect"]
material = SubResource( 2 ) material = SubResource( 2 )
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_right = -1216.0 margin_right = -559.0
margin_bottom = -656.0 margin_bottom = -174.0
rect_min_size = Vector2( 64, 64 ) rect_min_size = Vector2( 64, 64 )
rect_clip_content = true
mouse_filter = 1 mouse_filter = 1
size_flags_horizontal = 0 size_flags_horizontal = 0
size_flags_vertical = 8 size_flags_vertical = 8
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="P1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.466667, 0, 1 )
texture = SubResource( 3 )
[node name="P2" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 0, 0.505882, 1, 1 )
texture = SubResource( 3 )
[node name="Rect1" parent="." instance=ExtResource( 2 )]
visible = false
self_modulate = Color( 1, 0.631373, 0, 1 )
margin_right = 16.0
margin_bottom = 16.0
texture = SubResource( 4 )
parent_control = "P1"
control_type = 1
[node name="Radius1" 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="Radius11" 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 = "Radius1"
control_type = 2
[node name="Scale1" 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 = 3
[connection signal="resized" from="." to="." method="on_resized"] [connection signal="resized" from="." to="." method="on_resized"]

View File

@ -32,4 +32,3 @@ physics_object_picking = true
[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )] [node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )]
[connection signal="gui_input" from="." to="." method="on_gui_input"] [connection signal="gui_input" from="." to="." method="on_gui_input"]
[connection signal="resized" from="." to="." method="_on_Preview_resized"]

View File

@ -7,8 +7,8 @@ func get_model_data() -> Dictionary:
max = $Max.value, max = $Max.value,
step = $Step.value, step = $Step.value,
default = $Default.value, default = $Default.value,
control = $Control.get_item_text($Control.selected)
} }
return data return data
func set_model_data(data) -> void: func set_model_data(data) -> void:
@ -23,6 +23,12 @@ func set_model_data(data) -> void:
$Default.step = data.step $Default.step = data.step
if data.has("default"): if data.has("default"):
$Default.value = data.default $Default.value = data.default
if data.has("control"):
$Control.selected = 0
for i in range($Control.get_item_count()):
if data.control == $Control.get_item_text(i):
$Control.selected = i
break
func _on_Min_value_changed(v : float) -> void: func _on_Min_value_changed(v : float) -> void:

View File

@ -81,6 +81,21 @@ margin_left = 342.0
margin_right = 400.0 margin_right = 400.0
margin_bottom = 24.0 margin_bottom = 24.0
step = 0.1 step = 0.1
[node name="LabelControl" type="Label" parent="."]
margin_left = 404.0
margin_top = 5.0
margin_right = 454.0
margin_bottom = 19.0
text = "Control:"
[node name="Control" type="OptionButton" parent="."]
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="Min" to="." method="_on_Min_value_changed"]
[connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"] [connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"]
[connection signal="value_changed" from="Step" to="." method="_on_Step_value_changed"] [connection signal="value_changed" from="Step" to="." method="_on_Step_value_changed"]