Updated Godot integration

This commit is contained in:
RodZill4 2019-10-16 23:15:11 +02:00
parent 2b67c5a4f5
commit e573a78fd6
9 changed files with 35 additions and 29 deletions

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,4 @@
tool
extends Tree
func get_drag_data(position):

View File

@ -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"]

View File

@ -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

View File

@ -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)

View File

@ -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"]

View File

@ -2,7 +2,6 @@ tool
extends Control
class_name MMGradientEditor
class GradientCursor:
extends ColorRect