Merge branch 'master' into remove-trailing-whitespace

This commit is contained in:
Rodz Labs 2019-11-10 17:19:53 +01:00 committed by GitHub
commit 587f5d85a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 63 deletions

View File

@ -150,7 +150,8 @@ func get_generated_texture(slot, file_prefix = null) -> ImageTexture:
if file_prefix != null:
var file_name = "%s_%s.png" % [ file_prefix, slot ]
if File.new().file_exists(file_name):
return load(file_name) as ImageTexture
var texture = load(file_name)
return texture
else:
return null
else:
@ -162,7 +163,7 @@ func update_spatial_material(m, file_prefix = null) -> void:
if m is SpatialMaterial:
# Make the material double-sided for better visiblity in the preview
m.params_cull_mode = SpatialMaterial.CULL_DISABLED
# Albedo
m.albedo_color = parameters.albedo_color
m.albedo_texture = get_generated_texture("albedo", file_prefix)
m.metallic = parameters.metallic
@ -239,11 +240,13 @@ func export_textures(prefix, editor_interface = null) -> SpatialMaterial:
if Engine.editor_hint and editor_interface != null:
var resource_filesystem = editor_interface.get_resource_filesystem()
resource_filesystem.scan()
yield(resource_filesystem, "filesystem_changed")
yield(resource_filesystem, "resources_reimported")
print("resources_reimported")
var new_material = SpatialMaterial.new()
update_spatial_material(new_material, prefix)
ResourceSaver.save("%s.tres" % [ prefix ], new_material)
resource_filesystem.scan()
var file_name : String = "%s.tres" % [ prefix ]
ResourceSaver.save(file_name, new_material)
resource_filesystem.update_file(file_name)
return new_material
return null

View File

@ -47,7 +47,7 @@ func add_node(node) -> void:
func connect_node(from, from_slot, to, to_slot):
if generator.connect_children(get_node(from).generator, from_slot, get_node(to).generator, to_slot):
var disconnect = get_source(to, to_slot)
if disconnect != null:
if !disconnect.empty():
.disconnect_node(disconnect.node, disconnect.slot, to, to_slot)
.connect_node(from, from_slot, to, to_slot)
send_changed_signal()
@ -214,12 +214,11 @@ func save_file(filename) -> void:
func export_textures() -> void:
if save_path != null:
var prefix = save_path.left(save_path.rfind("."))
for c in get_children():
if c is GraphNode:
if c.generator.has_method("render_textures"):
c.generator.render_textures()
if c.generator.has_method("export_textures"):
c.generator.export_textures(prefix, editor_interface)
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)
# Cut / copy / paste

View File

@ -3,10 +3,10 @@ extends EditorImportPlugin
var plugin = null
const PRESET_NAMES = [ "Skip", "Import with Material Maker" ]
const PRESET_NAMES = [ "Render in game", "Prerender" ]
const PRESET_OPTIONS = [
[{ name="skip", default_value=true }],
[{ name="skip", default_value=false }]
[{ name="render", default_value=false }],
[{ name="render", default_value=true }]
]
func _init(p) -> void:
@ -37,7 +37,7 @@ func get_recognized_extensions() -> Array:
return [ "ptex" ]
func get_resource_type() -> String:
return "Material"
return "SpatialMaterial"
func get_save_extension() -> String:
return "tres"
@ -46,11 +46,19 @@ func get_visible_name() -> String:
return "Material Maker Importer"
func import(source_file: String, save_path: String, options: Dictionary, platform_variants: Array, gen_files: Array) -> int:
if !options.skip:
var filename = save_path + "." + get_save_extension()
var filename = save_path + "." + get_save_extension()
if options.render:
var material = plugin.generate_material(source_file)
while material is GDScriptFunctionState:
material = yield(material, "completed")
if material != null:
ResourceSaver.save(filename, material)
else:
var material : SpatialMaterial = SpatialMaterial.new()
material.set_script(preload("res://addons/material_maker/import_plugin/ptex_spatial_material.gd"))
var file : File = File.new()
if file.open(source_file, File.READ) == OK:
material.set_ptex_no_render(to_json(parse_json(file.get_as_text())))
file.close()
ResourceSaver.save(filename, material)
return OK

View File

@ -0,0 +1,29 @@
tool
extends SpatialMaterial
export var ptex : String = "" setget set_ptex
func set_ptex_no_render(s : String) -> void :
ptex = s
func set_ptex(s : String) -> void :
if ptex == s:
return
ptex = s
call_deferred("update_texture")
func update_texture() -> void:
var loader = MMGenLoader.new()
var mm_graph = loader.create_gen(parse_json(ptex))
if mm_graph == null:
return
var mm_material : MMGenMaterial = mm_graph.get_node("Material")
if ! (mm_material is MMGenMaterial):
return
mm_renderer.add_child(mm_graph)
var status = mm_material.render_textures()
while status is GDScriptFunctionState:
status = yield(status, "completed")
mm_material.update_spatial_material(self)
mm_graph.queue_free()

View File

@ -22,15 +22,16 @@ func _unhandled_input(event : InputEvent) -> void:
filter_line_edit.select_all()
func get_selected_item_name() -> String:
var tree_item : TreeItem = tree.get_selected()
var rv = ""
while tree_item != null and tree_item != tree.get_root():
if rv == "":
rv = tree_item.get_text(0)
else:
rv = tree_item.get_text(0)+"/"+rv
tree_item = tree_item.get_parent()
return rv
return get_item_path(tree.get_selected())
func get_selected_item_doc_name() -> String:
var item : TreeItem = tree.get_selected()
if item == null:
return ""
var m : Dictionary = item.get_metadata(0)
if m == null or !m.has("icon"):
return ""
return m.icon
func add_library(file_name : String, filter : String = "") -> bool:
var root = tree.get_root()
@ -110,6 +111,8 @@ func add_item(item, item_name, item_icon = null, item_parent = null, force_expan
return add_item(item, suffix, item_icon, new_parent, force_expand)
func get_item_path(item : TreeItem) -> String:
if item == null:
return ""
var item_path = item.get_text(0)
var item_parent = item.get_parent()
while item_parent != tree.get_root():

View File

@ -39,8 +39,9 @@ const MENU = [
{ menu="Tools" },
{ menu="Tools", command="add_to_user_library", description="Add selected node to user library" },
{ menu="Tools", command="export_library", description="Export the nodes library" },
{ menu="Help", command="show_doc", description="User manual" },
{ menu="Help", command="show_doc", shortcut="F1", description="User manual" },
{ menu="Help", command="show_library_item_doc", shortcut="Control+F1", description="Show selected library item documentation" },
{ menu="Help", command="bug_report", description="Report a bug" },
{ menu="Help" },
{ menu="Help", command="about", description="About" }
@ -100,6 +101,8 @@ func create_menu(menu, menu_name) -> PopupMenu:
for i in MENU.size():
if MENU[i].has("standalone_only") and MENU[i].standalone_only and Engine.editor_hint:
continue
if MENU[i].has("editor_only") and MENU[i].editor_only and !Engine.editor_hint:
continue
if MENU[i].menu != menu_name:
continue
if MENU[i].has("submenu"):
@ -344,11 +347,11 @@ func do_add_to_user_library(name, nodes) -> void:
dir.make_dir("user://library")
dir.make_dir("user://library/user")
data.library = "user://library/user.json"
data.icon = name.right(name.rfind("/")+1).to_lower()
data.icon = library.get_icon_name(name)
var result = nodes[0].generator.render(0, 64)
while result is GDScriptFunctionState:
result = yield(result, "completed")
result.save_to_file("user://library/user/"+library.get_icon_name(name)+".png")
result.save_to_file("user://library/user/"+data.icon+".png")
result.release()
library.add_item(data, name, library.get_preview_texture(data))
library.save_library("user://library/user.json")
@ -366,27 +369,38 @@ func export_library() -> void:
func do_export_library(path : String) -> void:
library.export_libraries(path)
func show_doc() -> void:
func get_doc_dir() -> String:
var base_dir = OS.get_executable_path().replace("\\", "/").get_base_dir()
# In release builds, documentation is expected to be located in
# a subdirectory of the program directory
var release_doc_path = base_dir.plus_file("doc/index.html")
var release_doc_path = base_dir.plus_file("doc")
# In development, documentation is part of the project files.
# We can use a globalized `res://` path here as the project isn't exported.
var devel_doc_path = ProjectSettings.globalize_path("res://addons/material_maker/doc/_build/html/index.html")
var devel_doc_path = ProjectSettings.globalize_path("res://addons/material_maker/doc/_build/html")
for p in [ release_doc_path, devel_doc_path ]:
var file = File.new()
if file.file_exists(p+"/index.html"):
return p
return ""
var file = File.new()
if file.file_exists(release_doc_path):
# Open local prebuilt documentation (used in release builds)
OS.shell_open(release_doc_path)
elif file.file_exists(devel_doc_path):
# Open local documentation built from source (used during development)
OS.shell_open(devel_doc_path)
else:
# Open online documentation
OS.shell_open("https://rodzill4.github.io/godot-procedural-textures/doc/")
func show_doc() -> void:
var doc_dir = get_doc_dir()
if doc_dir != "":
OS.shell_open(doc_dir+"/index.html")
func show_doc_is_disabled() -> bool:
return get_doc_dir() == ""
func show_library_item_doc() -> void:
var doc_dir : String = get_doc_dir()
if doc_dir != "":
var doc_name = library.get_selected_item_doc_name()
if doc_name != "":
var doc_path : String = doc_dir+"/node_"+doc_name+".html"
OS.shell_open(doc_path)
func show_library_item_doc_is_disabled() -> bool:
return get_doc_dir() == "" or library.get_selected_item_doc_name() == ""
func bug_report() -> void:
OS.shell_open("https://github.com/RodZill4/godot-procedural-textures/issues")

View File

@ -45,35 +45,35 @@ margin_bottom = 20.0
margin_right = 35.0
margin_bottom = 20.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 ]
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, "Export embedded PTEX", null, 0, false, false, 9, 301989957, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Close material", null, 0, false, false, 11, 0, null, "", false, "Quit", null, 0, false, false, 12, 268435537, null, "", false ]
[node name="Edit" type="MenuButton" parent="VBoxContainer/Menu"]
margin_left = 39.0
margin_right = 75.0
margin_bottom = 20.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 ]
items = [ "Cut", null, 0, false, false, 13, 268435544, null, "", false, "Copy", null, 0, false, false, 14, 268435523, null, "", false, "Paste", null, 0, false, false, 15, 268435542, null, "", false ]
[node name="View" type="MenuButton" parent="VBoxContainer/Menu"]
margin_left = 79.0
margin_right = 121.0
margin_bottom = 20.0
text = "View"
items = [ "Center view", null, 0, false, false, 15, 67, null, "", false, "Reset zoom", null, 0, false, false, 16, 268435504, null, "", false ]
items = [ "Center view", null, 0, false, false, 16, 67, null, "", false, "Reset zoom", null, 0, false, false, 17, 268435504, null, "", false ]
[node name="Tools" type="MenuButton" parent="VBoxContainer/Menu"]
margin_left = 125.0
margin_right = 171.0
margin_bottom = 20.0
text = "Tools"
items = [ "Create", null, 0, false, false, -1, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 18, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 19, 268435525, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Add selected node to user library", null, 0, false, false, 21, 0, null, "", false, "Export the nodes library", null, 0, false, false, 22, 0, null, "", false ]
items = [ "Create", null, 0, false, false, -1, 0, null, "PopupMenu", false, "Create group", null, 0, false, false, 19, 268435527, null, "", false, "Make selected nodes editable", null, 0, false, false, 20, 268435525, 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 ]
[node name="Help" type="MenuButton" parent="VBoxContainer/Menu"]
margin_left = 175.0
margin_right = 217.0
margin_bottom = 20.0
text = "Help"
items = [ "User manual", null, 0, false, false, 23, 0, null, "", false, "Report a bug", null, 0, false, false, 24, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "About", null, 0, false, false, 26, 0, null, "", false ]
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 ]
[node name="HBoxContainer" type="HSplitContainer" parent="VBoxContainer"]
margin_top = 24.0

View File

@ -7,19 +7,8 @@ var importer = null
func _enter_tree() -> void:
add_tool_menu_item("Material Maker", self, "open_material_maker")
add_tool_menu_item("Register Material Maker Import", self, "register_material_maker_import")
func register_material_maker_import(__) -> void:
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")
add_tool_menu_item("Unregister Material Maker Import", self, "unregister_material_maker_import")
func unregister_material_maker_import(__) -> void:
remove_import_plugin(importer)
importer = null
remove_tool_menu_item("Unregister Material Maker Import")
add_tool_menu_item("Register Material Maker Import", self, "register_material_maker_import")
func _exit_tree() -> void:
remove_tool_menu_item("Material Maker")
@ -59,7 +48,7 @@ func generate_material(ptex_filename: String) -> Material:
if generator.has_node("Material"):
var gen_material = generator.get_node("Material")
if gen_material != null:
var return_value = gen_material.render_textures(mm_renderer)
var return_value = gen_material.render_textures()
while return_value is GDScriptFunctionState:
return_value = yield(return_value, "completed")
var prefix = ptex_filename.left(ptex_filename.rfind("."))