diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index a85fd13..acc3eab 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -116,6 +116,9 @@ func get_parameter_def(param_name : String) -> Dictionary: return p return {} +func get_parameter(n : String): + return parameters[n] + func set_parameter(n : String, v) -> void: parameters[n] = v source_changed(0) diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 707c92e..bd28cd9 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -1,4 +1,3 @@ -tool extends GraphEdit class_name MMGraphEdit @@ -11,6 +10,8 @@ var need_save = false var top_generator = null var generator = null +var last_selected = null + onready var timer : Timer = $Timer onready var subgraph_ui : HBoxContainer = $GraphUI/SubGraphUI @@ -45,6 +46,7 @@ func offset_from_global_position(global_position) -> Vector2: func add_node(node) -> void: add_child(node) + move_child(node, 0) node.connect("close_request", self, "remove_node", [ node ]) func connect_node(from, from_slot, to, to_slot): @@ -166,10 +168,11 @@ func new_material() -> void: top_generator = loader.create_gen({nodes=[{name="Material", type="material","parameters":{"size":11}}], connections=[]}) if top_generator != null: add_child(top_generator) + move_child(top_generator, 0) update_view(top_generator) + center_view() set_save_path(null) set_need_save(false) - center_view() func get_free_name(type) -> String: var i = 0 @@ -200,10 +203,11 @@ func load_file(filename) -> void: top_generator = MMGenLoader.load_gen(filename) if top_generator != null: add_child(top_generator) + move_child(top_generator, 0) update_view(top_generator) + center_view() set_save_path(filename) set_need_save(false) - center_view() func save_file(filename) -> void: var data = top_generator.serialize() @@ -352,3 +356,16 @@ func edit_subgraph(g : MMGenGraph) -> void: func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void: if button_pressed != generator.transmits_seed: 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) \ No newline at end of file diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index c2bc1ed..9319a45 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -79,6 +79,8 @@ icon = SubResource( 4 ) [connection signal="connection_request" from="." to="." method="connect_node"] [connection signal="disconnection_request" from="." to="." method="disconnect_node"] [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="text_changed" from="GraphUI/SubGraphUI/Label" to="." method="_on_Label_text_changed"] [connection signal="toggled" from="GraphUI/SubGraphUI/ButtonTransmitsSeed" to="." method="_on_ButtonTransmitsSeed_toggled"] diff --git a/addons/material_maker/icons/icons.svg b/addons/material_maker/icons/icons.svg index c493618..49ef1a4 100644 --- a/addons/material_maker/icons/icons.svg +++ b/addons/material_maker/icons/icons.svg @@ -11,14 +11,21 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="128" - height="64" - viewBox="0 0 128 64" + height="128" + viewBox="0 0 128 128" version="1.1" id="svg8" inkscape:version="0.92.4 (5da689c313, 2019-01-14)" sodipodi:docname="icons.svg"> + @@ -48,9 +55,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="28.608854" - inkscape:cx="86.841515" - inkscape:cy="21.061007" + inkscape:zoom="20.229515" + inkscape:cx="12.288977" + inkscape:cy="55.740147" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -87,10 +94,10 @@ inkscape:label="Calque 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-280.06665)"> + transform="translate(0,-216.06665)"> @@ -110,7 +117,7 @@ inkscape:export-xdpi="16.531826" inkscape:export-filename="remove.png" id="g4564" - transform="matrix(0.43370177,0.42718925,-0.43370177,0.42718925,43.791013,273.09803)" + transform="matrix(0.43370177,0.42718925,-0.43370177,0.42718925,43.791013,209.09803)" style="fill:#ff0909;fill-opacity:1"> + transform="matrix(0.52573689,0,0,0.513409,30.847756,228.09585)"> @@ -187,7 +194,7 @@ inkscape:export-filename="save.png" inkscape:export-xdpi="14" inkscape:export-ydpi="14" - transform="matrix(0.52616852,0,0,0.52616852,14.395212,275.18126)"> + transform="matrix(0.52616852,0,0,0.52616852,14.395212,211.18126)"> + transform="matrix(0.51223521,0,0,0.51223521,5.2214853,211.80647)"> @@ -276,28 +283,28 @@ style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:fill markers stroke" id="path5162" cx="7.8297439" - cy="319.77344" + cy="255.77344" rx="1.0486264" ry="0.87385535" /> @@ -317,7 +324,7 @@ inkscape:export-filename="config.png" inkscape:export-xdpi="16.559999" inkscape:export-ydpi="16.559999" - transform="matrix(0.52573689,0,0,0.513409,-1.7560956,259.17843)"> + transform="matrix(0.52573689,0,0,0.513409,-1.7560956,195.17843)"> @@ -356,45 +362,46 @@ sodipodi:nodetypes="cccccccc" inkscape:connector-curvature="0" id="path4561" - d="m 33.500409,335.78733 4.34961,-0.0488 0.123047,-6.82227 h 4.27539 l 0.125,6.82227 4.34961,0.0488 -6.611328,6.8457 z" - style="fill:#ffffff;fill-opacity:0.84322037;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + d="m 33.500409,271.78733 4.34961,-0.0488 0.123047,-6.82227 h 4.27539 l 0.125,6.82227 4.34961,0.0488 -6.611328,6.8457 z" + style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + id="g892" + transform="translate(0,-64)"> + transform="translate(16.00903,-64.034954)"> + + + + + + + + + + + + + + diff --git a/addons/material_maker/library.gd b/addons/material_maker/library.gd index 0980dac..a422354 100644 --- a/addons/material_maker/library.gd +++ b/addons/material_maker/library.gd @@ -1,4 +1,3 @@ -tool extends VBoxContainer var libraries = [] diff --git a/addons/material_maker/library/base.json b/addons/material_maker/library/base.json index adf3eb7..ee289d6 100644 --- a/addons/material_maker/library/base.json +++ b/addons/material_maker/library/base.json @@ -739,7 +739,6 @@ "cx": 0, "cy": 0, "h": 0.2, - "r": 0.3, "w": 0.3 }, "tree_item": "Simple/SDF/Shapes/sdBox", @@ -750,15 +749,10 @@ "icon": "simple_sdf_shapes_sdline", "name": "sdline", "parameters": { - "ax": 0.2, - "ay": 0.2, - "bx": 0.8, - "by": 0.8, - "cx": 0, - "cy": 0, - "h": 0.2, - "r": 0.3, - "w": 0.3 + "ax": -0.3, + "ay": -0.3, + "bx": 0.3, + "by": 0.3 }, "tree_item": "Simple/SDF/Shapes/sdLine", "type": "sdline" @@ -771,7 +765,6 @@ "cx": 0, "cy": 0, "h": 0.2, - "r": 0.3, "w": 0.3 }, "tree_item": "Simple/SDF/Shapes/sdRhombus", diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 198b3d8..0139047 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -1,4 +1,3 @@ -tool extends Panel var recent_files = [] @@ -14,6 +13,9 @@ var need_update : bool = false onready var projects = $VBoxContainer/HBoxContainer/ProjectsPane/Projects onready var library = $VBoxContainer/HBoxContainer/VBoxContainer/Library +onready var preview_2d = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview2D +onready var preview_3d = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D + const RECENT_FILES_COUNT = 15 const MENU = [ @@ -465,7 +467,7 @@ func update_preview() -> void: status = update_preview_2d() while status is GDScriptFunctionState: status = yield(status, "completed") - status = update_preview_3d() + status = update_preview_3d([ $VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D, $VBoxContainer/HBoxContainer/ProjectsPane/Preview3D]) while status is GDScriptFunctionState: status = yield(status, "completed") updating = false @@ -473,7 +475,6 @@ func update_preview() -> void: func update_preview_2d(node = null) -> void: var graph_edit : MMGraphEdit = get_current_graph_edit() if graph_edit != null: - var preview = $VBoxContainer/HBoxContainer/VBoxContainer/Preview if node == null: for n in graph_edit.get_children(): if n is GraphNode and n.selected: @@ -486,16 +487,23 @@ func update_preview_2d(node = null) -> void: var tex = ImageTexture.new() result.copy_to_texture(tex) result.release() - preview.set_2d(tex) + preview_2d.set_preview_texture(tex) + else: + preview_2d.set_preview_texture(null) -func update_preview_3d() -> void: +func update_preview_3d(previews : Array) -> void: var graph_edit : MMGraphEdit = get_current_graph_edit() if graph_edit != null and graph_edit.top_generator != null and graph_edit.top_generator.has_node("Material"): var gen_material = graph_edit.top_generator.get_node("Material") var status = gen_material.render_textures() while status is GDScriptFunctionState: status = yield(status, "completed") - gen_material.update_materials($VBoxContainer/HBoxContainer/VBoxContainer/Preview.get_materials()) + for p in previews: + 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: var new_tab = projects.get_current_tab_control() @@ -505,16 +513,10 @@ func _on_Projects_tab_changed(tab) -> void: if c.method_name == "update_preview" or c.method_name == "update_preview_2d": c.source.disconnect(c.signal_name, self, c.method_name) 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 update_preview() -func _on_Preview_show_background_preview(v) -> void: - var pv = $VBoxContainer/HBoxContainer/VBoxContainer/Preview/MaterialPreview - var bgpv = $VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport - bgpv.world = pv.find_world() - $VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview.visible = v - func _exit_tree() -> void: # Save the window position and size to remember it when restarting the application if !Engine.editor_hint: @@ -523,3 +525,7 @@ func _exit_tree() -> void: config_cache.set_value("window", "position", OS.window_position) config_cache.set_value("window", "size", OS.window_size) config_cache.save("user://cache.ini") + +func show_background_preview(button_pressed): + $VBoxContainer/HBoxContainer/ProjectsPane/Preview3D.visible = button_pressed + $VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer.visible = button_pressed diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 19c18dc..d8c3ef8 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -1,24 +1,23 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://addons/material_maker/main_window.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/library.tscn" type="PackedScene" id=2] -[ext_resource path="res://addons/material_maker/preview/preview.tscn" type="PackedScene" id=3] -[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4] -[ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=5] -[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=6] +[ext_resource path="res://addons/material_maker/preview/preview_2d.tscn" type="PackedScene" id=3] +[ext_resource path="res://addons/material_maker/preview/preview_3d.tscn" type="PackedScene" id=4] +[ext_resource path="res://addons/material_maker/preview/preview_3d_ui.tscn" type="PackedScene" id=5] +[ext_resource path="res://addons/material_maker/widgets/tabs.gd" type="Script" id=6] +[ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=7] +[ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=8] -[sub_resource type="PanoramaSky" id=1] -resource_local_to_scene = true -panorama = ExtResource( 4 ) +[sub_resource type="AtlasTexture" id=1] +flags = 4 +atlas = ExtResource( 7 ) +region = Rect2( 96, 32, 32, 32 ) -[sub_resource type="Environment" id=2] -background_mode = 2 -background_sky = SubResource( 1 ) -background_energy = 1.5 -ambient_light_color = Color( 1, 1, 1, 1 ) -ambient_light_energy = 0.32 -tonemap_mode = 2 -tonemap_white = 16.0 +[sub_resource type="AtlasTexture" id=2] +flags = 4 +atlas = ExtResource( 7 ) +region = Rect2( 96, 64, 32, 32 ) [node name="MainWindow" type="Panel"] anchor_right = 1.0 @@ -89,18 +88,27 @@ size_flags_vertical = 3 [node name="Library" parent="VBoxContainer/HBoxContainer/VBoxContainer" instance=ExtResource( 2 )] margin_right = 311.0 -margin_bottom = 404.0 +margin_bottom = 386.0 size_flags_vertical = 3 size_flags_stretch_ratio = 1.5 -[node name="Preview" parent="VBoxContainer/HBoxContainer/VBoxContainer" instance=ExtResource( 3 )] -anchor_left = 0.0 -anchor_right = 0.0 -margin_left = 0.0 -margin_top = 416.0 +[node name="Preview" type="TabContainer" parent="VBoxContainer/HBoxContainer/VBoxContainer"] +margin_top = 398.0 margin_right = 311.0 margin_bottom = 684.0 -rect_min_size = Vector2( 300, 200 ) +tab_align = 0 + +[node name="Preview2D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 3 )] +margin_left = 4.0 +margin_top = 32.0 +margin_right = -4.0 +margin_bottom = -4.0 +rect_min_size = Vector2( 250, 250 ) + +[node name="Preview3D" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview" instance=ExtResource( 4 )] +rect_min_size = Vector2( 250, 250 ) + +[node name="Preview3DUI" parent="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" instance=ExtResource( 5 )] [node name="ProjectsPane" type="Control" parent="VBoxContainer/HBoxContainer"] margin_left = 323.0 @@ -110,22 +118,12 @@ size_flags_horizontal = 3 size_flags_vertical = 3 size_flags_stretch_ratio = 3.0 -[node name="BackgroundPreview" type="ViewportContainer" parent="VBoxContainer/HBoxContainer/ProjectsPane"] -visible = false -anchor_right = 1.0 -anchor_bottom = 1.0 -stretch = true - -[node name="Viewport" type="Viewport" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview"] -size = Vector2( 945, 684 ) -handle_input_locally = false -msaa = 2 -render_target_update_mode = 0 - -[node name="Camera" type="Camera" parent="VBoxContainer/HBoxContainer/ProjectsPane/BackgroundPreview/Viewport"] -transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 2.24976, 2.68115 ) -environment = SubResource( 2 ) -current = true +[node name="Preview3D" parent="VBoxContainer/HBoxContainer/ProjectsPane" instance=ExtResource( 4 )] +margin_left = 0.0 +margin_top = 0.0 +margin_right = 0.0 +margin_bottom = 0.0 +ui_path = "../HBoxContainer/HBoxContainer/Preview3DUI" [node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"] self_modulate = Color( 1, 1, 1, 0 ) @@ -135,7 +133,7 @@ margin_right = 5.0 margin_bottom = 5.0 size_flags_horizontal = 3 size_flags_vertical = 3 -script = ExtResource( 5 ) +script = ExtResource( 6 ) [node name="Tabs" type="Tabs" parent="VBoxContainer/HBoxContainer/ProjectsPane/Projects"] margin_right = 950.0 @@ -143,51 +141,59 @@ margin_bottom = 24.0 tab_align = 0 tab_close_display_policy = 1 +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/ProjectsPane"] +anchor_top = 1.0 +anchor_bottom = 1.0 +margin_left = 1.0 +margin_top = -45.0 +margin_right = 331.0 +margin_bottom = -13.0 +custom_constants/separation = 7 + +[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer"] +margin_right = 44.0 +margin_bottom = 38.0 +hint_tooltip = "Show 3D preview" +toggle_mode = true +icon = SubResource( 1 ) + +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer"] +visible = false +margin_left = 51.0 +margin_right = 354.0 +margin_bottom = 38.0 +custom_constants/separation = 8 + +[node name="ControlView" type="TextureRect" parent="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer"] +margin_top = 3.0 +margin_right = 32.0 +margin_bottom = 35.0 +size_flags_vertical = 4 +texture = SubResource( 2 ) + +[node name="Preview3DUI" parent="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer" instance=ExtResource( 5 )] +anchor_right = 0.0 +margin_left = 40.0 +margin_top = 8.0 +margin_right = 303.0 +margin_bottom = 30.0 +size_flags_vertical = 4 + [node name="NodeFactory" type="Node" parent="."] -script = ExtResource( 6 ) -[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="update_preview_3d"] -[connection signal="show_background_preview" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview" to="." method="_on_Preview_show_background_preview"] +script = ExtResource( 8 ) +[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" to="." method="update_preview_3d"] +[connection signal="environment_selected" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Environment_item_selected"] +[connection signal="model_selected" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Model_item_selected"] +[connection signal="rotate_toggled" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Rotate_toggled"] +[connection signal="need_update" from="VBoxContainer/HBoxContainer/ProjectsPane/Preview3D" to="." method="update_preview_3d"] [connection signal="no_more_tabs" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="new_material"] [connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="_on_Projects_resized"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects" to="." method="_on_Projects_tab_changed"] -[connection signal="connection_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" method="connect_node"] -[connection signal="disconnection_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" method="disconnect_node"] -[connection signal="duplicate_nodes_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit" method="duplicate_selected"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer2/metallic" method="_on_LineEdit_text_entered"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer3/roughness" method="_on_LineEdit_text_entered"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer4/emission_energy" method="_on_LineEdit_text_entered"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer5/normal_scale" method="_on_LineEdit_text_entered"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer6/ao_light_affect" method="_on_LineEdit_text_entered"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer7/depth_scale" method="_on_LineEdit_text_entered"] -[connection signal="focus_exited" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_focus_exited"] -[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_gui_input"] -[connection signal="resized" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="do_update"] -[connection signal="text_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_text_changed"] -[connection signal="text_entered" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects/GraphEdit/node_Material/HBoxContainer8/subsurf_scatter_strength" method="_on_LineEdit_text_entered"] [connection signal="reposition_active_tab_request" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/Tabs" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="move_active_tab_to"] [connection signal="tab_changed" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/Tabs" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="set_current_tab"] [connection signal="tab_close" from="VBoxContainer/HBoxContainer/ProjectsPane/Projects/Tabs" to="VBoxContainer/HBoxContainer/ProjectsPane/Projects" method="close_tab"] +[connection signal="toggled" from="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/Button" to="." method="show_background_preview"] +[connection signal="gui_input" from="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer/ControlView" to="VBoxContainer/HBoxContainer/ProjectsPane/Preview3D" method="on_gui_input"] +[connection signal="environment_selected" from="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer/Preview3DUI" to="VBoxContainer/HBoxContainer/ProjectsPane/Preview3D" method="_on_Environment_item_selected"] +[connection signal="model_selected" from="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer/Preview3DUI" to="VBoxContainer/HBoxContainer/ProjectsPane/Preview3D" method="_on_Model_item_selected"] +[connection signal="rotate_toggled" from="VBoxContainer/HBoxContainer/ProjectsPane/HBoxContainer/HBoxContainer/Preview3DUI" to="VBoxContainer/HBoxContainer/ProjectsPane/Preview3D" method="_on_Rotate_toggled"] diff --git a/addons/material_maker/nodes/base.gd b/addons/material_maker/nodes/base.gd index 60c177e..bd3086e 100644 --- a/addons/material_maker/nodes/base.gd +++ b/addons/material_maker/nodes/base.gd @@ -7,6 +7,9 @@ var generator : MMGenBase = null setget set_generator func _ready() -> void: connect("offset_changed", self, "_on_offset_changed") +func _exit_tree() -> void: + get_parent().call_deferred("check_last_selected") + func _draw() -> void: 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") diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 10fe434..1257c89 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -1,4 +1,3 @@ -tool extends MMGraphNodeBase class_name MMGraphNodeGeneric diff --git a/addons/material_maker/nodes/sdannularshape.mmg b/addons/material_maker/nodes/sdannularshape.mmg index 12124a2..4d20335 100644 --- a/addons/material_maker/nodes/sdannularshape.mmg +++ b/addons/material_maker/nodes/sdannularshape.mmg @@ -35,6 +35,7 @@ ], "parameters": [ { + "control": "Radius1.x", "default": 0, "label": "", "max": 1, diff --git a/addons/material_maker/nodes/sdarc.mmg b/addons/material_maker/nodes/sdarc.mmg index 6bb49ba..4042492 100644 --- a/addons/material_maker/nodes/sdarc.mmg +++ b/addons/material_maker/nodes/sdarc.mmg @@ -5,8 +5,8 @@ "y": 0 }, "parameters": { - "a1": 0, - "a2": 0, + "a1": 135, + "a2": 45, "cx": 0, "cy": 0, "r": 0.4, @@ -15,7 +15,7 @@ }, "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,12 +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": "Angle1.a", "default": 0, "label": "Angle 1", "max": 180, @@ -38,6 +39,7 @@ "type": "float" }, { + "control": "Angle2.a", "default": 0, "label": "Angle 2", "max": 180, @@ -47,6 +49,7 @@ "type": "float" }, { + "control": "Radius1.r", "default": 0.5, "label": "Radius 1", "max": 1, @@ -56,6 +59,7 @@ "type": "float" }, { + "control": "Radius11.r", "default": 0.1, "label": "Radius 2", "max": 1, diff --git a/addons/material_maker/nodes/sdbox.mmg b/addons/material_maker/nodes/sdbox.mmg index 9592fdc..e6f92ea 100644 --- a/addons/material_maker/nodes/sdbox.mmg +++ b/addons/material_maker/nodes/sdbox.mmg @@ -12,7 +12,7 @@ "w": 0.3 }, "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": "", "inputs": [ @@ -27,6 +27,7 @@ ], "parameters": [ { + "control": "Rect1.x", "default": 0.5, "label": "Width", "max": 1, @@ -36,6 +37,7 @@ "type": "float" }, { + "control": "Rect1.y", "default": 1, "label": "Height", "max": 1, @@ -45,6 +47,7 @@ "type": "float" }, { + "control": "P1.x", "default": 0, "label": "Center X", "max": 1, @@ -54,6 +57,7 @@ "type": "float" }, { + "control": "P1.y", "default": 0, "label": "Center Y", "max": 1, diff --git a/addons/material_maker/nodes/sdcircle.mmg b/addons/material_maker/nodes/sdcircle.mmg index e9881b5..923a960 100644 --- a/addons/material_maker/nodes/sdcircle.mmg +++ b/addons/material_maker/nodes/sdcircle.mmg @@ -7,7 +7,7 @@ "parameters": { "cx": 0, "cy": 0, - "r": 0.25 + "r": 0.4 }, "shader_model": { "code": "", @@ -19,12 +19,13 @@ "name": "sdCircle", "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" } ], "parameters": [ { + "control": "Radius1.x", "default": 0.5, "label": "Radius", "max": 1, @@ -34,6 +35,7 @@ "type": "float" }, { + "control": "P1.x", "default": 0, "label": "Center X", "max": 1, @@ -43,6 +45,7 @@ "type": "float" }, { + "control": "P1.y", "default": 0, "label": "Center Y", "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/sdline.mmg b/addons/material_maker/nodes/sdline.mmg index 763df54..aded4bf 100644 --- a/addons/material_maker/nodes/sdline.mmg +++ b/addons/material_maker/nodes/sdline.mmg @@ -5,10 +5,10 @@ "y": 0 }, "parameters": { - "ax": 0.2, - "ay": 0.2, - "bx": 0.8, - "by": 0.8, + "ax": 0.224, + "ay": 0.2672, + "bx": -0.272, + "by": -0.2344, "cx": 0, "cy": 0, "h": 0.2, @@ -25,43 +25,47 @@ "name": "sdLine", "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" } ], "parameters": [ { + "control": "P1.x", "default": 0, "label": "A X", "max": 1, - "min": 0, + "min": -1, "name": "ax", "step": 0.01, "type": "float" }, { + "control": "P1.y", "default": 0, "label": "A Y", "max": 1, - "min": 0, + "min": -1, "name": "ay", "step": 0.01, "type": "float" }, { + "control": "P2.x", "default": 1, "label": "B X", "max": 1, - "min": 0, + "min": -1, "name": "bx", "step": 0.01, "type": "float" }, { + "control": "P2.y", "default": 1, "label": "B Y", "max": 1, - "min": 0, + "min": -1, "name": "by", "step": 0.01, "type": "float" diff --git a/addons/material_maker/nodes/sdrhombus.mmg b/addons/material_maker/nodes/sdrhombus.mmg index 02925e1..13029a9 100644 --- a/addons/material_maker/nodes/sdrhombus.mmg +++ b/addons/material_maker/nodes/sdrhombus.mmg @@ -5,11 +5,11 @@ "y": 0 }, "parameters": { - "cx": 0, - "cy": 0, - "h": 0.2, + "cx": -0.19353, + "cy": -0.224011, + "h": 0.187815, "r": 0.3, - "w": 0.5 + "w": 0.393785 }, "shader_model": { "code": "", @@ -21,12 +21,13 @@ "name": "sdRhombus", "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" } ], "parameters": [ { + "control": "Rect1.x", "default": 0.5, "label": "Width", "max": 1, @@ -36,6 +37,7 @@ "type": "float" }, { + "control": "Rect1.y", "default": 1, "label": "Height", "max": 1, @@ -45,6 +47,7 @@ "type": "float" }, { + "control": "P1.x", "default": 0, "label": "Center X", "max": 1, @@ -54,6 +57,7 @@ "type": "float" }, { + "control": "P1.y", "default": 0, "label": "Center Y", "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/sdroundedshape.mmg b/addons/material_maker/nodes/sdroundedshape.mmg index 80305a4..898bd82 100644 --- a/addons/material_maker/nodes/sdroundedshape.mmg +++ b/addons/material_maker/nodes/sdroundedshape.mmg @@ -11,7 +11,7 @@ "h": 0.08, "k": 0.15, "op": 0, - "r": 0.1, + "r": 0.15, "w": 0.28 }, "shader_model": { @@ -35,6 +35,7 @@ ], "parameters": [ { + "control": "Radius1.x", "default": 0, "label": "", "max": 1, diff --git a/addons/material_maker/nodes/sdscale.mmg b/addons/material_maker/nodes/sdscale.mmg index 0b5c875..6ffe6a2 100644 --- a/addons/material_maker/nodes/sdscale.mmg +++ b/addons/material_maker/nodes/sdscale.mmg @@ -6,7 +6,7 @@ }, "parameters": { "a": 0, - "s": 2.21, + "s": 1, "x": 0.35, "y": 0, "z": 0 @@ -32,6 +32,7 @@ ], "parameters": [ { + "control": "Scale1.x", "default": 1, "label": "", "max": 5, diff --git a/addons/material_maker/nodes/sdtranslate.mmg b/addons/material_maker/nodes/sdtranslate.mmg index a4b72f7..2dd0563 100644 --- a/addons/material_maker/nodes/sdtranslate.mmg +++ b/addons/material_maker/nodes/sdtranslate.mmg @@ -5,8 +5,8 @@ "y": 0 }, "parameters": { - "x": 0, - "y": 0, + "x": 0.024, + "y": 0.024, "z": 0 }, "shader_model": { @@ -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, 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/plugin.gd b/addons/material_maker/plugin.gd index 21a6471..67eaec6 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -1,47 +1,17 @@ tool extends EditorPlugin -var mm_button = null -var material_maker = null var importer = null func _enter_tree() -> void: - add_tool_menu_item("Material Maker", self, "open_material_maker") importer = preload("res://addons/material_maker/import_plugin/ptex_import.gd").new(self) add_import_plugin(importer) func _exit_tree() -> void: - remove_tool_menu_item("Material Maker") - if material_maker != null: - material_maker.hide() - material_maker.queue_free() - material_maker = null if importer != null: remove_import_plugin(importer) importer = null -func _get_state() -> Dictionary: - return { mm_button=mm_button, material_maker=material_maker } - -func _set_state(s) -> void: - mm_button = s.mm_button - material_maker = s.material_maker - -func open_material_maker(__) -> void: - if material_maker == null: - material_maker = preload("res://addons/material_maker/window_dialog.tscn").instance() - var panel = material_maker.get_node("MainWindow") - panel.editor_interface = get_editor_interface() - panel.connect("quit", self, "close_material_maker") - add_child(material_maker) - material_maker.popup_centered() - -func close_material_maker() -> void: - if material_maker != null: - material_maker.hide() - material_maker.queue_free() - material_maker = null - func generate_material(ptex_filename: String) -> Material: var generator = MMGenLoader.load_gen(ptex_filename) add_child(generator) diff --git a/addons/material_maker/preview/control_point.gd b/addons/material_maker/preview/control_point.gd new file mode 100644 index 0000000..403a28f --- /dev/null +++ b/addons/material_maker/preview/control_point.gd @@ -0,0 +1,156 @@ +extends TextureRect + +export var parent_control : String = "" +export(int, "Simple", "Rect", "Radius", "Scale" ) var control_type : int = 0 + +var generator : MMGenBase = null +var parameter_x : String = "" +var parameter_y : String = "" +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 = [] + +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 + 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 + 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: + hide() + if is_instance_valid(generator): + generator.disconnect("parameter_changed", self, "on_parameter_changed") + generator = g + parameter_x = "" + parameter_y = "" + parameter_r = "" + parameter_a = "" + 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 + 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()) + else: + generator = null + update_position(Vector2(0, 0)) + +func get_value() -> Vector2: + var pos : Vector2 = Vector2(0, 0) + if is_instance_valid(generator): + 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 or p == parameter_r or p == parameter_a): + update_position(get_value()) + update() + +func update_parameters(value : Vector2) -> void: + if !is_instance_valid(generator): + return + match control_type: + 1: # Rect + value.x = abs(value.x) + value.y = abs(value.y) + 3: # Scale + value = 4.0*value + if parameter_x != "": + generator.set_parameter(parameter_x, value.x) + if parameter_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: + 3: # Scale + pos *= 0.25 + if parent_control_node != null: + pos += parent_control_node.get_value() + 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: + 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(value) + update() + dragging = false + for c in children_control_nodes: + c.update_position(c.get_value()) diff --git a/addons/material_maker/preview/control_point.tscn b/addons/material_maker/preview/control_point.tscn new file mode 100644 index 0000000..001ce32 --- /dev/null +++ b/addons/material_maker/preview/control_point.tscn @@ -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"] diff --git a/addons/material_maker/preview/preview.tscn b/addons/material_maker/preview/preview.tscn deleted file mode 100644 index 932920e..0000000 --- a/addons/material_maker/preview/preview.tscn +++ /dev/null @@ -1,108 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://addons/material_maker/preview/preview.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/preview/preview_3d.tscn" type="PackedScene" id=2] - - -[sub_resource type="World" id=1] - -[sub_resource type="Shader" id=2] -code = "shader_type canvas_item; - -uniform sampler2D tex; - -void fragment() { - COLOR = texture(tex, UV); -}" - -[sub_resource type="ShaderMaterial" id=3] -shader = SubResource( 2 ) - -[node name="Preview" type="ViewportContainer"] -anchor_left = 1.0 -anchor_right = 1.0 -margin_left = -398.0 -margin_top = 3.0 -margin_right = -3.0 -margin_bottom = 373.0 -rect_min_size = Vector2( 200, 200 ) -mouse_filter = 1 -size_flags_horizontal = 3 -size_flags_vertical = 3 -stretch = true -script = ExtResource( 1 ) - -[node name="MaterialPreview" type="Viewport" parent="."] -size = Vector2( 395, 370 ) -own_world = true -world = SubResource( 1 ) -handle_input_locally = false -msaa = 2 -render_target_clear_mode = 1 -render_target_update_mode = 3 -physics_object_picking = true - -[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )] - -[node name="Config" type="HBoxContainer" parent="."] -anchor_right = 1.0 -margin_bottom = 20.0 -size_flags_horizontal = 3 - -[node name="Model" type="OptionButton" parent="Config"] -margin_right = 100.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 100, 0 ) -text = "Cube" -items = [ "Cube", null, false, -1, null, "Cylinder", null, false, -1, null, "Sphere", null, false, -1, null, "Sphere2", null, false, -1, null, "Quad", null, false, -1, null, "Plane", null, false, -1, null ] -selected = 0 - -[node name="Environment" type="OptionButton" parent="Config"] -margin_left = 104.0 -margin_right = 231.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 100, 0 ) -text = "Epping Forest" -items = [ "Epping Forest", null, false, -1, null, "Moonless Golf", null, false, -1, null ] -selected = 0 - -[node name="Rotate" type="Button" parent="Config"] -margin_left = 235.0 -margin_right = 255.0 -margin_bottom = 20.0 -rect_pivot_offset = Vector2( -4, 7 ) -hint_tooltip = "Rotate object" -size_flags_horizontal = 2 -toggle_mode = true -pressed = true -text = "R" - -[node name="Background" type="Button" parent="Config"] -margin_left = 372.0 -margin_right = 395.0 -margin_bottom = 20.0 -grow_horizontal = 2 -grow_vertical = 2 -rect_pivot_offset = Vector2( -4, 7 ) -hint_tooltip = "Show in main view" -size_flags_horizontal = 8 -toggle_mode = true -text = "O" - -[node name="Preview2D" type="ColorRect" parent="."] -material = SubResource( 3 ) -anchor_top = 1.0 -anchor_bottom = 1.0 -margin_top = -64.0 -margin_right = 64.0 -rect_min_size = Vector2( 64, 64 ) -mouse_filter = 1 -size_flags_horizontal = 0 -size_flags_vertical = 8 -[connection signal="gui_input" from="." to="." method="on_gui_input"] -[connection signal="resized" from="." to="." method="_on_Preview_resized"] -[connection signal="item_selected" from="Config/Model" to="." method="_on_Model_item_selected"] -[connection signal="item_selected" from="Config/Environment" to="." method="_on_Environment_item_selected"] -[connection signal="toggled" from="Config/Rotate" to="." method="_on_Rotate_toggled"] -[connection signal="toggled" from="Config/Background" to="." method="_on_Background_toggled"] -[connection signal="gui_input" from="Preview2D" to="." method="_on_Preview2D_gui_input"] diff --git a/addons/material_maker/preview/preview_2d.gd b/addons/material_maker/preview/preview_2d.gd new file mode 100644 index 0000000..d1d14e6 --- /dev/null +++ b/addons/material_maker/preview/preview_2d.gd @@ -0,0 +1,31 @@ +tool +extends ColorRect + +var generator = null + +func set_preview_texture(tex: Texture) -> void: + material.set_shader_param("tex", tex) + +func on_resized() -> void: + 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*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) diff --git a/addons/material_maker/preview/preview_2d.tscn b/addons/material_maker/preview/preview_2d.tscn new file mode 100644 index 0000000..337910a --- /dev/null +++ b/addons/material_maker/preview/preview_2d.tscn @@ -0,0 +1,115 @@ +[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/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] +code = "shader_type canvas_item; + +uniform sampler2D tex; +uniform vec2 size; + +void fragment() { + float ms = max(size.x, size.y); + vec2 uv = fract(0.5+1.2*(UV-vec2(0.5))*ms/size.yx); + vec2 m2 = min(fract(uv), 1.0-fract(uv)); + COLOR = mix(texture(tex, uv), vec4(0.0, 1.0, 0.0, 1.0), step(min(m2.x, m2.y), 1.0/min(size.x, size.y))); +}" + +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) +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( 16, 64, 16, 16 ) + +[node name="Preview2D" type="ColorRect"] +material = SubResource( 2 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = -559.0 +margin_bottom = -174.0 +rect_min_size = Vector2( 64, 64 ) +rect_clip_content = true +mouse_filter = 1 +size_flags_horizontal = 0 +size_flags_vertical = 8 +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 + +[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/preview/preview.gd b/addons/material_maker/preview/preview_3d.gd similarity index 64% rename from addons/material_maker/preview/preview.gd rename to addons/material_maker/preview/preview_3d.gd index a62aed4..2fefb78 100644 --- a/addons/material_maker/preview/preview.gd +++ b/addons/material_maker/preview/preview_3d.gd @@ -1,8 +1,5 @@ -tool extends ViewportContainer -var preview_maximized = false - const ENVIRONMENTS = [ "experiment", "lobby", "night", "park", "schelde" ] @@ -10,6 +7,8 @@ const ENVIRONMENTS = [ const CAMERA_DISTANCE_MIN = 1.0 const CAMERA_DISTANCE_MAX = 10.0 +export var ui_path : String = "Preview3DUI" + onready var objects = $MaterialPreview/Preview3d/Objects onready var current_object = objects.get_child(0) @@ -19,65 +18,48 @@ onready var current_environment = environments.get_child(0) onready var camera_stand = $MaterialPreview/Preview3d/CameraPivot onready var camera = $MaterialPreview/Preview3d/CameraPivot/Camera -signal need_update -signal show_background_preview +onready var ui = get_node(ui_path) + +signal need_update(me) func _ready() -> void: - $Config/Model.clear() + var model_list : Array = [] for o in objects.get_children(): var m = o.get_surface_material(0) o.set_surface_material(0, m.duplicate()) - $Config/Model.add_item(o.name) - call_deferred("_on_Model_item_selected", 0) - $Config/Environment.clear() + model_list.push_back(o.name) + ui.set_models(model_list) + var environment_list : Array = [] for e in environments.get_children(): - $Config/Environment.add_item(e.name) - call_deferred("_on_Environment_item_selected", 0) + environment_list.push_back(e.name) + ui.set_environments(environment_list) $MaterialPreview/Preview3d/ObjectRotate.play("rotate") - $Preview2D.material = $Preview2D.material.duplicate(true) - _on_Preview_resized() - $MaterialPreview/Preview3d/CameraPivot/Camera/RemoteTransform.set_remote_node("../../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera") - -func _on_Environment_item_selected(id) -> void: - current_environment.visible = false - current_environment = environments.get_child(id) - $MaterialPreview/Preview3d/CameraPivot/Camera.set_environment(current_environment.environment) - get_node("../../ProjectsPane/BackgroundPreview/Viewport/Camera").set_environment(current_environment.environment) - current_environment.visible = true func _on_Model_item_selected(id) -> void: current_object.visible = false current_object = objects.get_child(id) current_object.visible = true - emit_signal("need_update") + emit_signal("need_update", [ self ]) + +func _on_Environment_item_selected(id) -> void: + current_environment.visible = false + current_environment = environments.get_child(id) + $MaterialPreview/Preview3d/CameraPivot/Camera.set_environment(current_environment.environment) + current_environment.visible = true + +func _on_Rotate_toggled(button_pressed) -> void: + if button_pressed: + $MaterialPreview/Preview3d/ObjectRotate.play("rotate") + else: + $MaterialPreview/Preview3d/ObjectRotate.stop(false) func get_materials() -> Array: return [ current_object.get_surface_material(0) ] -func set_2d(tex: Texture) -> void: - $Preview2D.material.set_shader_param("tex", tex) - -func _on_Preview_resized() -> void: - if preview_maximized: - var size = min(rect_size.x, rect_size.y) - $Preview2D.rect_position = 0.5*Vector2(rect_size.x-size, rect_size.y-size) - $Preview2D.rect_size = Vector2(size, size) - else: - $Preview2D.rect_position = Vector2(0, rect_size.y-64) - $Preview2D.rect_size = Vector2(64, 64) - -func _on_Preview2D_gui_input(ev : InputEvent) -> void: - if ev is InputEventMouseButton and ev.button_index == 1 and ev.pressed: - preview_maximized = !preview_maximized - _on_Preview_resized() - -func _on_Background_toggled(button_pressed) -> void: - emit_signal("show_background_preview", button_pressed) - func on_gui_input(event) -> void: if event is InputEventMouseButton: $MaterialPreview/Preview3d/ObjectRotate.stop(false) - $Config/Rotate.pressed = false + ui.rotation_cancelled() match event.button_index: BUTTON_WHEEL_UP: camera.translation.z = clamp( @@ -106,9 +88,3 @@ func on_gui_input(event) -> void: camera_stand.rotate(camera_basis.y.normalized(), -motion.x) elif event.button_mask & BUTTON_MASK_RIGHT: camera_stand.rotate(camera_basis.z.normalized(), -motion.x) - -func _on_Rotate_toggled(button_pressed) -> void: - if button_pressed: - $MaterialPreview/Preview3d/ObjectRotate.play("rotate") - else: - $MaterialPreview/Preview3d/ObjectRotate.stop(false) diff --git a/addons/material_maker/preview/preview_3d.tscn b/addons/material_maker/preview/preview_3d.tscn index ac443bb..af2de4b 100644 --- a/addons/material_maker/preview/preview_3d.tscn +++ b/addons/material_maker/preview/preview_3d.tscn @@ -1,121 +1,34 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=4 format=2] -[ext_resource path="res://addons/material_maker/preview/preview_objects.tscn" type="PackedScene" id=1] -[ext_resource path="res://addons/material_maker/preview/panoramas/moonless_golf.hdr" type="Texture" id=2] -[ext_resource path="res://addons/material_maker/environment.gd" type="Script" id=3] -[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4] -[ext_resource path="res://addons/material_maker/preview/panoramas/studio_sky.tres" type="Environment" id=5] +[ext_resource path="res://addons/material_maker/preview/preview_3d.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/preview/preview_3d_scene.tscn" type="PackedScene" id=2] -[sub_resource type="PanoramaSky" id=3] -resource_local_to_scene = true -panorama = ExtResource( 2 ) +[sub_resource type="World" id=1] -[sub_resource type="Environment" id=4] -resource_local_to_scene = true -background_mode = 2 -background_sky = SubResource( 3 ) - -[sub_resource type="Animation" id=5] -loop = true -tracks/0/type = "value" -tracks/0/path = NodePath("Objects:rotation_degrees") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/keys = { -"times": PoolRealArray( 0, 1 ), -"transitions": PoolRealArray( 1, 1 ), -"update": 0, -"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ] -} - -[sub_resource type="PanoramaSky" id=1] -resource_local_to_scene = true -panorama = ExtResource( 4 ) - -[sub_resource type="Environment" id=2] -background_mode = 2 -background_sky = SubResource( 1 ) -background_energy = 1.5 -ambient_light_color = Color( 1, 1, 1, 1 ) -ambient_light_energy = 0.32 -tonemap_mode = 2 -tonemap_white = 16.0 - -[sub_resource type="CylinderMesh" id=6] -top_radius = 5.0 -bottom_radius = 5.0 -height = 0.5 - -[sub_resource type="SpatialMaterial" id=7] - -[sub_resource type="PlaneMesh" id=8] -size = Vector2( 1000, 1000 ) -subdivide_width = 10 -subdivide_depth = 10 - -[node name="Preview3d" type="Spatial"] - -[node name="Objects" parent="." instance=ExtResource( 1 )] -transform = Transform( -0.799512, 0, 0.60065, 0, 1, 0, -0.60065, 0, -0.799512, 0, 0, 0 ) - -[node name="CameraPivot" type="Spatial" parent="."] -transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 0, 0 ) - -[node name="Camera" type="Camera" parent="CameraPivot"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 ) -environment = SubResource( 4 ) -current = true - -[node name="RemoteTransform" type="RemoteTransform" parent="CameraPivot/Camera"] -remote_path = NodePath("../../../../../../ProjectsPane/BackgroundPreview/Viewport/Camera") - -[node name="ObjectRotate" type="AnimationPlayer" parent="."] -autoplay = "rotate" -playback_speed = 0.1 -anims/rotate = SubResource( 5 ) - -[node name="Environments" type="Spatial" parent="."] - -[node name="Epping Forest" type="Spatial" parent="Environments"] -editor/display_folded = true +[node name="Preview3D" type="ViewportContainer"] visible = false -script = ExtResource( 3 ) -environment = SubResource( 2 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 4.0 +margin_top = 32.0 +margin_right = -4.0 +margin_bottom = -4.0 +rect_min_size = Vector2( 200, 200 ) +mouse_filter = 1 +size_flags_horizontal = 3 +size_flags_vertical = 3 +stretch = true +script = ExtResource( 1 ) -[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Epping Forest"] -transform = Transform( 0.976272, -0.0494319, -0.21083, 0.216548, 0.222856, 0.950496, -8.69534e-009, -0.973597, 0.228272, -5.08826, 21.6274, 5.3744 ) -light_energy = 0.5 -shadow_enabled = true +[node name="MaterialPreview" type="Viewport" parent="."] +size = Vector2( 1272, 684 ) +own_world = true +world = SubResource( 1 ) +handle_input_locally = false +msaa = 2 +render_target_clear_mode = 1 +render_target_update_mode = 0 +physics_object_picking = true -[node name="MeshInstance" type="MeshInstance" parent="Environments/Epping Forest"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.3343, 0 ) -visible = false -mesh = SubResource( 6 ) -material/0 = SubResource( 7 ) - -[node name="Moonless Golf" type="Spatial" parent="Environments"] -editor/display_folded = true -visible = false -script = ExtResource( 3 ) -environment = SubResource( 4 ) - -[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Moonless Golf"] -transform = Transform( 0.569388, 0.170928, 0.804103, 0.171359, -0.981336, 0.087263, 0.804011, 0.088104, -0.588051, 91.9658, 9.62053, -85.1176 ) -light_energy = 0.2 -shadow_enabled = true - -[node name="Studio" type="Spatial" parent="Environments"] -visible = false -script = ExtResource( 3 ) -environment = ExtResource( 5 ) - -[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Studio"] -transform = Transform( 0.707107, -0.40558, 0.579228, 0, 0.819152, 0.573577, -0.707107, -0.40558, 0.579228, 10, 10, 0 ) -shadow_enabled = true - -[node name="GroundPlane" type="MeshInstance" parent="Environments/Studio"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.05186, 0 ) -mesh = SubResource( 8 ) -material/0 = null +[node name="Preview3d" parent="MaterialPreview" instance=ExtResource( 2 )] +[connection signal="gui_input" from="." to="." method="on_gui_input"] diff --git a/addons/material_maker/preview/preview_3d_scene.tscn b/addons/material_maker/preview/preview_3d_scene.tscn new file mode 100644 index 0000000..348f57e --- /dev/null +++ b/addons/material_maker/preview/preview_3d_scene.tscn @@ -0,0 +1,118 @@ +[gd_scene load_steps=14 format=2] + +[ext_resource path="res://addons/material_maker/preview/preview_objects.tscn" type="PackedScene" id=1] +[ext_resource path="res://addons/material_maker/preview/panoramas/moonless_golf.hdr" type="Texture" id=2] +[ext_resource path="res://addons/material_maker/environment.gd" type="Script" id=3] +[ext_resource path="res://addons/material_maker/preview/panoramas/epping_forest_01.hdr" type="Texture" id=4] +[ext_resource path="res://addons/material_maker/preview/panoramas/studio_sky.tres" type="Environment" id=5] + +[sub_resource type="PanoramaSky" id=1] +resource_local_to_scene = true +panorama = ExtResource( 2 ) + +[sub_resource type="Environment" id=2] +resource_local_to_scene = true +background_mode = 2 +background_sky = SubResource( 1 ) + +[sub_resource type="Animation" id=3] +loop = true +tracks/0/type = "value" +tracks/0/path = NodePath("Objects:rotation_degrees") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 1 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 0, +"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ] +} + +[sub_resource type="PanoramaSky" id=4] +resource_local_to_scene = true +panorama = ExtResource( 4 ) + +[sub_resource type="Environment" id=5] +background_mode = 2 +background_sky = SubResource( 4 ) +background_energy = 1.5 +ambient_light_color = Color( 1, 1, 1, 1 ) +ambient_light_energy = 0.32 +tonemap_mode = 2 +tonemap_white = 16.0 + +[sub_resource type="CylinderMesh" id=6] +top_radius = 5.0 +bottom_radius = 5.0 +height = 0.5 + +[sub_resource type="SpatialMaterial" id=7] + +[sub_resource type="PlaneMesh" id=8] +size = Vector2( 1000, 1000 ) +subdivide_width = 10 +subdivide_depth = 10 + +[node name="Preview3dScene" type="Spatial"] + +[node name="Objects" parent="." instance=ExtResource( 1 )] +transform = Transform( -0.799512, 0, 0.60065, 0, 1, 0, -0.60065, 0, -0.799512, 0, 0, 0 ) + +[node name="CameraPivot" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 0, 0 ) + +[node name="Camera" type="Camera" parent="CameraPivot"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3.5 ) +environment = SubResource( 2 ) +current = true + +[node name="ObjectRotate" type="AnimationPlayer" parent="."] +autoplay = "rotate" +playback_speed = 0.1 +anims/rotate = SubResource( 3 ) + +[node name="Environments" type="Spatial" parent="."] + +[node name="Epping Forest" type="Spatial" parent="Environments"] +editor/display_folded = true +visible = false +script = ExtResource( 3 ) +environment = SubResource( 5 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Epping Forest"] +transform = Transform( 0.976272, -0.0494319, -0.21083, 0.216548, 0.222856, 0.950496, -8.69534e-009, -0.973597, 0.228272, -5.08826, 21.6274, 5.3744 ) +light_energy = 0.5 +shadow_enabled = true + +[node name="MeshInstance" type="MeshInstance" parent="Environments/Epping Forest"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.3343, 0 ) +visible = false +mesh = SubResource( 6 ) +material/0 = SubResource( 7 ) + +[node name="Moonless Golf" type="Spatial" parent="Environments"] +editor/display_folded = true +visible = false +script = ExtResource( 3 ) +environment = SubResource( 2 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Moonless Golf"] +transform = Transform( 0.569388, 0.170928, 0.804103, 0.171359, -0.981336, 0.087263, 0.804011, 0.088104, -0.588051, 91.9658, 9.62053, -85.1176 ) +light_energy = 0.2 +shadow_enabled = true + +[node name="Studio" type="Spatial" parent="Environments"] +visible = false +script = ExtResource( 3 ) +environment = ExtResource( 5 ) + +[node name="DirectionalLight" type="DirectionalLight" parent="Environments/Studio"] +transform = Transform( 0.707107, -0.40558, 0.579228, 0, 0.819152, 0.573577, -0.707107, -0.40558, 0.579228, 10, 10, 0 ) +shadow_enabled = true + +[node name="GroundPlane" type="MeshInstance" parent="Environments/Studio"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.05186, 0 ) +mesh = SubResource( 8 ) +material/0 = null diff --git a/addons/material_maker/preview/preview_3d_ui.gd b/addons/material_maker/preview/preview_3d_ui.gd new file mode 100644 index 0000000..2764864 --- /dev/null +++ b/addons/material_maker/preview/preview_3d_ui.gd @@ -0,0 +1,29 @@ +extends HBoxContainer + +signal model_selected(id) +signal environment_selected(id) +signal rotate_toggled(b) + +func set_models(model_list : Array) -> void: + $Model.clear() + for m in model_list: + $Model.add_item(m) + call_deferred("_on_Model_item_selected", 0) + +func set_environments(environment_list : Array) -> void: + $Environment.clear() + for e in environment_list: + $Environment.add_item(e) + call_deferred("_on_Environment_item_selected", 0) + +func rotation_cancelled() -> void: + $Rotate.pressed = false + +func _on_Model_item_selected(ID) -> void: + emit_signal("model_selected", ID) + +func _on_Environment_item_selected(ID) -> void: + emit_signal("environment_selected", ID) + +func _on_Rotate_toggled(button_pressed) -> void: + emit_signal("rotate_toggled", button_pressed) diff --git a/addons/material_maker/preview/preview_3d_ui.tscn b/addons/material_maker/preview/preview_3d_ui.tscn new file mode 100644 index 0000000..2c74404 --- /dev/null +++ b/addons/material_maker/preview/preview_3d_ui.tscn @@ -0,0 +1,46 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://addons/material_maker/preview/preview_3d_ui.gd" type="Script" id=1] +[ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=2] + +[sub_resource type="AtlasTexture" id=1] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 48, 48, 16, 16 ) + +[node name="Preview3DUI" type="HBoxContainer"] +anchor_right = 1.0 +margin_bottom = 20.0 +size_flags_horizontal = 3 +script = ExtResource( 1 ) + +[node name="Model" type="OptionButton" parent="."] +margin_right = 100.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 100, 0 ) +text = "Cube" +items = [ "Cube", null, false, 0, null, "Cylinder", null, false, 1, null, "Sphere", null, false, 2, null, "Sphere2", null, false, 3, null, "Prism", null, false, 4, null, "Quad", null, false, 5, null, "Plane", null, false, 6, null, "SphereTess", null, false, 7, null ] +selected = 0 + +[node name="Environment" type="OptionButton" parent="."] +margin_left = 104.0 +margin_right = 231.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 100, 0 ) +text = "Epping Forest" +items = [ "Epping Forest", null, false, 0, null, "Moonless Golf", null, false, 1, null, "Studio", null, false, 2, null ] +selected = 0 + +[node name="Rotate" type="Button" parent="."] +margin_left = 235.0 +margin_right = 263.0 +margin_bottom = 22.0 +rect_pivot_offset = Vector2( -4, 7 ) +hint_tooltip = "Rotate object" +size_flags_horizontal = 2 +toggle_mode = true +pressed = true +icon = SubResource( 1 ) +[connection signal="item_selected" from="Model" to="." method="_on_Model_item_selected"] +[connection signal="item_selected" from="Environment" to="." method="_on_Environment_item_selected"] +[connection signal="toggled" from="Rotate" to="." method="_on_Rotate_toggled"] diff --git a/addons/material_maker/widgets/node_editor/parameter_float.gd b/addons/material_maker/widgets/node_editor/parameter_float.gd index fed7579..83a0973 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.gd +++ b/addons/material_maker/widgets/node_editor/parameter_float.gd @@ -1,14 +1,21 @@ 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, max = $Max.value, step = $Step.value, default = $Default.value, + control = $Control.get_item_text($Control.selected) } - return data func set_model_data(data) -> void: @@ -23,6 +30,12 @@ func set_model_data(data) -> void: $Default.step = data.step if data.has("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: diff --git a/addons/material_maker/widgets/node_editor/parameter_float.tscn b/addons/material_maker/widgets/node_editor/parameter_float.tscn index be82c6c..fb8098f 100644 --- a/addons/material_maker/widgets/node_editor/parameter_float.tscn +++ b/addons/material_maker/widgets/node_editor/parameter_float.tscn @@ -81,6 +81,20 @@ margin_left = 342.0 margin_right = 400.0 margin_bottom = 24.0 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" +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"] [connection signal="value_changed" from="Step" to="." method="_on_Step_value_changed"] diff --git a/addons/material_maker/widgets/tabs.gd b/addons/material_maker/widgets/tabs.gd index 818d5ea..9e665b3 100644 --- a/addons/material_maker/widgets/tabs.gd +++ b/addons/material_maker/widgets/tabs.gd @@ -1,4 +1,3 @@ -tool extends Panel var current_tab = -1 setget set_current_tab