From e573a78fd63308a8fc6571c96997978b3de0f740 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 16 Oct 2019 23:15:11 +0200 Subject: [PATCH] Updated Godot integration --- addons/material_maker/engine/gen_material.gd | 2 +- addons/material_maker/graph_edit.gd | 4 ++-- .../import_plugin/ptex_import.gd | 3 ++- addons/material_maker/library_tree.gd | 1 + addons/material_maker/main_window.tscn | 8 +++---- addons/material_maker/plugin.gd | 22 +++++++++++-------- addons/material_maker/preview.gd | 11 +++++----- addons/material_maker/preview.tscn | 12 +++++----- .../material_maker/widgets/gradient_editor.gd | 1 - 9 files changed, 35 insertions(+), 29 deletions(-) diff --git a/addons/material_maker/engine/gen_material.gd b/addons/material_maker/engine/gen_material.gd index 0690255..dd8476d 100644 --- a/addons/material_maker/engine/gen_material.gd +++ b/addons/material_maker/engine/gen_material.gd @@ -174,7 +174,7 @@ func export_textures(prefix, editor_interface = null): if texture != null: var image = texture.get_data() image.save_png("%s_%s.png" % [ prefix, t.texture ]) - if Engine.editor_hint: + if Engine.editor_hint and editor_interface != null: var resource_filesystem = editor_interface.get_resource_filesystem() resource_filesystem.scan() yield(resource_filesystem, "filesystem_changed") diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 16ef10c..30d757b 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -191,12 +191,12 @@ func save_file(filename): set_save_path(filename) set_need_save(false) -func export_textures(size = null): +func export_textures(): if save_path != null: var prefix = save_path.left(save_path.rfind(".")) for c in get_children(): if c is GraphNode and c.generator.has_method("export_textures"): - c.generator.export_textures(prefix, size) + c.generator.export_textures(prefix, editor_interface) # Cut / copy / paste diff --git a/addons/material_maker/import_plugin/ptex_import.gd b/addons/material_maker/import_plugin/ptex_import.gd index 1df636b..17d60e6 100644 --- a/addons/material_maker/import_plugin/ptex_import.gd +++ b/addons/material_maker/import_plugin/ptex_import.gd @@ -47,5 +47,6 @@ func import(source_file: String, save_path: String, options: Dictionary, platfor var material = plugin.generate_material(source_file) while material is GDScriptFunctionState: material = yield(material, "completed") - ResourceSaver.save(filename, material) + if material != null: + ResourceSaver.save(filename, material) return OK diff --git a/addons/material_maker/library_tree.gd b/addons/material_maker/library_tree.gd index 6319edf..4f9ea4e 100644 --- a/addons/material_maker/library_tree.gd +++ b/addons/material_maker/library_tree.gd @@ -1,3 +1,4 @@ +tool extends Tree func get_drag_data(position): diff --git a/addons/material_maker/main_window.tscn b/addons/material_maker/main_window.tscn index 7969dca..c601fc3 100644 --- a/addons/material_maker/main_window.tscn +++ b/addons/material_maker/main_window.tscn @@ -8,13 +8,13 @@ [ext_resource path="res://addons/material_maker/engine/renderer.tscn" type="PackedScene" id=6] [ext_resource path="res://addons/material_maker/node_factory.gd" type="Script" id=7] -[sub_resource type="PanoramaSky" id=6] +[sub_resource type="PanoramaSky" id=1] resource_local_to_scene = true panorama = ExtResource( 4 ) -[sub_resource type="Environment" id=7] +[sub_resource type="Environment" id=2] background_mode = 2 -background_sky = SubResource( 6 ) +background_sky = SubResource( 1 ) [node name="MainWindow" type="Panel"] anchor_right = 1.0 @@ -107,7 +107,7 @@ 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( 7 ) +environment = SubResource( 2 ) current = true [node name="Projects" type="Panel" parent="VBoxContainer/HBoxContainer/ProjectsPane"] diff --git a/addons/material_maker/plugin.gd b/addons/material_maker/plugin.gd index e4644c9..73b5c10 100644 --- a/addons/material_maker/plugin.gd +++ b/addons/material_maker/plugin.gd @@ -8,11 +8,15 @@ var renderer = null func _enter_tree(): 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) + add_tool_menu_item("Register Material Maker Import", self, "register_material_maker_import") renderer = preload("res://addons/material_maker/engine/renderer.tscn").instance() add_child(renderer) +func register_material_maker_import(__): + importer = preload("res://addons/material_maker/import_plugin/ptex_import.gd").new(self) + add_import_plugin(importer) + remove_tool_menu_item("Register Material Maker Import") + func _exit_tree(): remove_tool_menu_item("Material Maker") if material_maker != null: @@ -31,7 +35,7 @@ func _set_state(s): mm_button = s.mm_button material_maker = s.material_maker -func open_material_maker(foo = null): +func open_material_maker(__): if material_maker == null: material_maker = preload("res://addons/material_maker/window_dialog.tscn").instance() var panel = material_maker.get_node("MainWindow") @@ -51,10 +55,10 @@ func generate_material(ptex_filename: String) -> Material: add_child(generator) if generator.has_node("Material"): var gen_material = generator.get_node("Material") - print(renderer) - var return_value = gen_material.render_textures(renderer) - while return_value is GDScriptFunctionState: - return_value = yield(return_value, "completed") - var prefix = ptex_filename.left(ptex_filename.rfind(".")) - return gen_material.export_textures(prefix, get_editor_interface()) + if gen_material != null: + var return_value = gen_material.render_textures(renderer) + while return_value is GDScriptFunctionState: + return_value = yield(return_value, "completed") + var prefix = ptex_filename.left(ptex_filename.rfind(".")) + return gen_material.export_textures(prefix, get_editor_interface()) return null diff --git a/addons/material_maker/preview.gd b/addons/material_maker/preview.gd index 16b88ee..b4047e2 100644 --- a/addons/material_maker/preview.gd +++ b/addons/material_maker/preview.gd @@ -38,7 +38,6 @@ func _ready(): func _on_Environment_item_selected(id): current_environment.visible = false current_environment = environments.get_child(id) - print(current_environment.environment) $MaterialPreview/Preview3d/CameraPivot/Camera.set_environment(current_environment.environment) get_node("../../ProjectsPane/BackgroundPreview/Viewport/Camera").set_environment(current_environment.environment) current_environment.visible = true @@ -75,6 +74,7 @@ func _on_Background_toggled(button_pressed): func on_gui_input(event): if event is InputEventMouseButton: $MaterialPreview/Preview3d/ObjectRotate.stop(false) + $Config/Rotate.pressed = false match event.button_index: BUTTON_WHEEL_UP: camera.translation.z *= 1.01 if event.shift else 1.1 @@ -96,9 +96,8 @@ func on_gui_input(event): elif event.button_mask & BUTTON_MASK_RIGHT: camera_stand.rotate(camera_basis.z.normalized(), -motion.x) - -func _on_Rotate_pressed(): - if $MaterialPreview/Preview3d/ObjectRotate.is_playing(): - $MaterialPreview/Preview3d/ObjectRotate.stop(false) - else: +func _on_Rotate_toggled(button_pressed): + if button_pressed: $MaterialPreview/Preview3d/ObjectRotate.play("rotate") + else: + $MaterialPreview/Preview3d/ObjectRotate.stop(false) diff --git a/addons/material_maker/preview.tscn b/addons/material_maker/preview.tscn index 0925853..8257b45 100644 --- a/addons/material_maker/preview.tscn +++ b/addons/material_maker/preview.tscn @@ -65,12 +65,14 @@ items = [ "Epping Forest", null, false, -1, null, "Moonless Golf", null, false, selected = 0 [node name="Rotate" type="Button" parent="Config"] -margin_left = 348.0 -margin_right = 368.0 +margin_left = 235.0 +margin_right = 255.0 margin_bottom = 20.0 rect_pivot_offset = Vector2( -4, 7 ) -hint_tooltip = "Show in main view" -size_flags_horizontal = 10 +hint_tooltip = "Rotate object" +size_flags_horizontal = 2 +toggle_mode = true +pressed = true text = "R" [node name="Background" type="Button" parent="Config"] @@ -99,6 +101,6 @@ size_flags_vertical = 8 [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="pressed" from="Config/Rotate" to="." method="_on_Rotate_pressed"] +[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/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index 91e457f..7e49a77 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -2,7 +2,6 @@ tool extends Control class_name MMGradientEditor - class GradientCursor: extends ColorRect