2018-09-03 21:35:44 +02:00
|
|
|
tool
|
|
|
|
extends EditorPlugin
|
|
|
|
|
|
|
|
var mm_button = null
|
|
|
|
var material_maker = null
|
2019-07-31 20:53:00 +02:00
|
|
|
var importer = null
|
2018-09-03 21:35:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _enter_tree() -> void:
|
2019-04-13 19:44:37 +02:00
|
|
|
add_tool_menu_item("Material Maker", self, "open_material_maker")
|
2019-10-16 23:15:11 +02:00
|
|
|
importer = preload("res://addons/material_maker/import_plugin/ptex_import.gd").new(self)
|
|
|
|
add_import_plugin(importer)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _exit_tree() -> void:
|
2019-04-13 19:44:37 +02:00
|
|
|
remove_tool_menu_item("Material Maker")
|
2018-09-03 21:35:44 +02:00
|
|
|
if material_maker != null:
|
|
|
|
material_maker.hide()
|
|
|
|
material_maker.queue_free()
|
|
|
|
material_maker = null
|
2019-07-31 20:53:00 +02:00
|
|
|
if importer != null:
|
|
|
|
remove_import_plugin(importer)
|
|
|
|
importer = null
|
2018-09-03 21:35:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _get_state() -> Dictionary:
|
|
|
|
return { mm_button=mm_button, material_maker=material_maker }
|
2018-09-03 21:35:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _set_state(s) -> void:
|
2018-09-03 21:35:44 +02:00
|
|
|
mm_button = s.mm_button
|
|
|
|
material_maker = s.material_maker
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func open_material_maker(__) -> void:
|
2018-09-03 21:35:44 +02:00
|
|
|
if material_maker == null:
|
2018-09-04 21:45:14 +02:00
|
|
|
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")
|
2018-09-03 21:35:44 +02:00
|
|
|
add_child(material_maker)
|
|
|
|
material_maker.popup_centered()
|
2018-09-04 21:45:14 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func close_material_maker() -> void:
|
2018-09-04 21:45:14 +02:00
|
|
|
if material_maker != null:
|
|
|
|
material_maker.hide()
|
|
|
|
material_maker.queue_free()
|
|
|
|
material_maker = null
|
2019-07-31 20:53:00 +02:00
|
|
|
|
|
|
|
func generate_material(ptex_filename: String) -> Material:
|
2019-09-09 22:00:18 +02:00
|
|
|
var generator = MMGenLoader.load_gen(ptex_filename)
|
2019-07-31 20:53:00 +02:00
|
|
|
add_child(generator)
|
2019-10-01 08:34:08 +02:00
|
|
|
if generator.has_node("Material"):
|
|
|
|
var gen_material = generator.get_node("Material")
|
2019-10-16 23:15:11 +02:00
|
|
|
if gen_material != null:
|
2019-11-10 15:02:00 +01:00
|
|
|
var return_value = gen_material.render_textures()
|
2019-10-16 23:15:11 +02:00
|
|
|
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())
|
2019-10-01 08:34:08 +02:00
|
|
|
return null
|