From a323f095b53fcba5b1ff7ef14d32588c38d0254a Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Mon, 24 Feb 2020 23:29:33 +0100 Subject: [PATCH] Fixed export node --- addons/material_maker/engine/gen_export.gd | 12 ++---------- material_maker/graph_edit.gd | 12 ++++-------- material_maker/main_window.gd | 15 +++------------ material_maker/main_window.tscn | 18 +++++++++--------- 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/addons/material_maker/engine/gen_export.gd b/addons/material_maker/engine/gen_export.gd index a9fc6cb..04227ca 100644 --- a/addons/material_maker/engine/gen_export.gd +++ b/addons/material_maker/engine/gen_export.gd @@ -34,19 +34,11 @@ func get_parameter_defs() -> Array: func get_input_defs() -> Array: return [ { name="in", type="rgba" } ] -func render_textures() -> void: +func export_material(prefix, _profile) -> void: var source = get_source(0) if source != null: var result = source.generator.render(source.output_index, get_image_size()) while result is GDScriptFunctionState: result = yield(result, "completed") - texture = ImageTexture.new() - result.copy_to_texture(texture) + result.save_to_file("%s_%s.png" % [ prefix, parameters.suffix]) result.release() - else: - texture = null - -func export_textures(prefix, __ = null) -> void: - if texture != null: - var image = texture.get_data() - image.save_png("%s_%s.png" % [ prefix, parameters.suffix]) diff --git a/material_maker/graph_edit.gd b/material_maker/graph_edit.gd index 892ebc1..9892eea 100644 --- a/material_maker/graph_edit.gd +++ b/material_maker/graph_edit.gd @@ -237,14 +237,10 @@ func get_material_node() -> MMGenMaterial: return g return null -func export_textures() -> void: - if save_path != null: - var prefix = save_path.left(save_path.rfind(".")) - for g in top_generator.get_children(): - if g.has_method("render_textures"): - g.render_textures() - if g.has_method("export_textures"): - g.export_textures(prefix, editor_interface) +func export_material(export_prefix, profile) -> void: + for g in top_generator.get_children(): + if g.has_method("export_material"): + g.export_material(export_prefix, profile) # Cut / copy / paste / duplicate diff --git a/material_maker/main_window.gd b/material_maker/main_window.gd index 5b0f757..22bab21 100644 --- a/material_maker/main_window.gd +++ b/material_maker/main_window.gd @@ -224,10 +224,8 @@ func export_material(file_path : String, profile : String) -> void: var graph_edit : MMGraphEdit = get_current_graph_edit() if graph_edit == null: return - var material_node = graph_edit.get_material_node() - if material_node == null: - return - material_node.export_material(file_path.trim_suffix("."+file_path.get_extension()), profile) + var export_prefix = file_path.trim_suffix("."+file_path.get_extension()) + graph_edit.export_material(export_prefix, profile) func _on_ExportMaterial_id_pressed(id) -> void: var graph_edit : MMGraphEdit = get_current_graph_edit() @@ -238,14 +236,11 @@ func _on_ExportMaterial_id_pressed(id) -> void: return var profile = material_node.get_export_profiles()[id] var dialog : FileDialog = FileDialog.new() - add_child(dialog) dialog.rect_min_size = Vector2(500, 500) dialog.access = FileDialog.ACCESS_FILESYSTEM dialog.mode = FileDialog.MODE_SAVE_FILE dialog.add_filter("*."+material_node.get_export_extension(profile)+";"+profile+" Material") - var export_path = material_node.get_export_path(profile) - if export_path != "": - dialog.current_path = export_path + add_child(dialog) dialog.connect("file_selected", self, "export_material", [ profile ]) dialog.popup_centered() @@ -356,10 +351,6 @@ func save_material_as() -> void: func close_material() -> void: projects.close_tab() -func export_material_is_disabled() -> bool: - var graph_edit : MMGraphEdit = get_current_graph_edit() - return graph_edit == null or graph_edit.save_path == null - func quit() -> void: dim_window() get_tree().quit() diff --git a/material_maker/main_window.tscn b/material_maker/main_window.tscn index b9bdee7..8aadbd9 100644 --- a/material_maker/main_window.tscn +++ b/material_maker/main_window.tscn @@ -94,39 +94,39 @@ margin_right = 1268.0 margin_bottom = 22.0 [node name="File" type="MenuButton" parent="VBoxContainer/Menu"] -margin_right = 35.0 +margin_right = 31.0 margin_bottom = 22.0 text = "File" items = [ "New material", null, 0, false, false, 0, 0, null, "", false, "Load material", null, 0, false, false, 1, 268435535, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Save material", null, 0, false, false, 4, 268435539, null, "", false, "Save material as...", null, 0, false, false, 5, 301989971, null, "", false, "Save all materials...", null, 0, false, false, 6, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Export material", null, 0, false, false, 8, 268435525, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Close material", null, 0, false, false, 10, 0, null, "", false, "Quit", null, 0, false, false, 11, 268435537, null, "", false ] switch_on_hover = true [node name="Edit" type="MenuButton" parent="VBoxContainer/Menu"] -margin_left = 39.0 -margin_right = 75.0 +margin_left = 35.0 +margin_right = 67.0 margin_bottom = 22.0 text = "Edit" items = [ "Cut", null, 0, false, false, 12, 268435544, null, "", false, "Copy", null, 0, false, false, 13, 268435523, null, "", false, "Paste", null, 0, false, false, 14, 268435542, null, "", false, "Duplicate", null, 0, false, false, 15, 268435524, null, "", false ] switch_on_hover = true [node name="View" type="MenuButton" parent="VBoxContainer/Menu"] -margin_left = 79.0 -margin_right = 121.0 +margin_left = 71.0 +margin_right = 109.0 margin_bottom = 22.0 text = "View" items = [ "Center view", null, 0, false, false, 16, 67, null, "", false, "Reset zoom", null, 0, false, false, 17, 268435504, null, "", false ] switch_on_hover = true [node name="Tools" type="MenuButton" parent="VBoxContainer/Menu"] -margin_left = 125.0 -margin_right = 171.0 +margin_left = 113.0 +margin_right = 155.0 margin_bottom = 22.0 text = "Tools" items = [ "Create", null, 0, false, false, 0, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 19, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 20, 268435543, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Add selected node to user library", null, 0, false, false, 22, 0, null, "", false, "Export the nodes library", null, 0, false, false, 23, 0, null, "", false ] switch_on_hover = true [node name="Help" type="MenuButton" parent="VBoxContainer/Menu"] -margin_left = 175.0 -margin_right = 217.0 +margin_left = 159.0 +margin_right = 197.0 margin_bottom = 22.0 text = "Help" items = [ "User manual", null, 0, false, false, 24, 16777244, null, "", false, "Show selected library item documentation", null, 0, false, false, 25, 285212700, null, "", false, "Report a bug", null, 0, false, false, 26, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 28, 0, null, "", false ]