mirror of
https://github.com/Relintai/material-maker.git
synced 2025-01-09 05:39:38 +01:00
Added support for command line export (#80)
This commit is contained in:
parent
a323f095b5
commit
d1c162d7fb
@ -34,10 +34,12 @@ func get_parameter_defs() -> Array:
|
||||
func get_input_defs() -> Array:
|
||||
return [ { name="in", type="rgba" } ]
|
||||
|
||||
func export_material(prefix, _profile) -> void:
|
||||
func export_material(prefix : String, _profile : String, size : int = 0) -> void:
|
||||
if size == 0:
|
||||
size = get_image_size()
|
||||
var source = get_source(0)
|
||||
if source != null:
|
||||
var result = source.generator.render(source.output_index, get_image_size())
|
||||
var result = source.generator.render(source.output_index, size)
|
||||
while result is GDScriptFunctionState:
|
||||
result = yield(result, "completed")
|
||||
result.save_to_file("%s_%s.png" % [ prefix, parameters.suffix])
|
||||
|
@ -269,7 +269,9 @@ func create_file_from_template(template : String, file_name : String, export_con
|
||||
out_file.store_line(subst_string(l, export_context))
|
||||
return true
|
||||
|
||||
func export_material(prefix, profile) -> void:
|
||||
func export_material(prefix : String, profile : String, size : int = 0) -> void:
|
||||
if size == 0:
|
||||
size = get_image_size()
|
||||
export_paths[profile] = prefix
|
||||
var export_context : Dictionary = {
|
||||
"$(path_prefix)":prefix,
|
||||
@ -316,7 +318,7 @@ func export_material(prefix, profile) -> void:
|
||||
match f.type:
|
||||
"texture":
|
||||
var file_name = subst_string(f.file_name, export_context)
|
||||
var result = render(f.output, get_image_size())
|
||||
var result = render(f.output, size)
|
||||
while result is GDScriptFunctionState:
|
||||
result = yield(result, "completed")
|
||||
result.save_to_file(file_name)
|
||||
|
@ -34,8 +34,8 @@ codesign/digest_algorithm=1
|
||||
codesign/description=""
|
||||
codesign/custom_options=PoolStringArray( )
|
||||
application/icon="res://icon.ico"
|
||||
application/file_version="0.8"
|
||||
application/product_version="0.8"
|
||||
application/file_version="0.9"
|
||||
application/product_version="0.9"
|
||||
application/company_name="Rodz Labs"
|
||||
application/product_name="Material Maker"
|
||||
application/file_description=""
|
||||
@ -93,8 +93,8 @@ application/info="Made with Godot Engine"
|
||||
application/icon=""
|
||||
application/identifier=""
|
||||
application/signature=""
|
||||
application/short_version="0.8"
|
||||
application/version="0.8"
|
||||
application/short_version="0.9"
|
||||
application/version="0.9"
|
||||
application/copyright=""
|
||||
display/high_res=false
|
||||
privacy/camera_usage_description=""
|
||||
@ -163,8 +163,8 @@ codesign/digest_algorithm=1
|
||||
codesign/description=""
|
||||
codesign/custom_options=PoolStringArray( )
|
||||
application/icon="res://icon.ico"
|
||||
application/file_version="0.8"
|
||||
application/product_version="0.8"
|
||||
application/file_version="0.9"
|
||||
application/product_version="0.9"
|
||||
application/company_name="Rodz Labs"
|
||||
application/product_name="Material Maker"
|
||||
application/file_description=""
|
||||
|
File diff suppressed because one or more lines are too long
@ -171,7 +171,7 @@ _global_script_class_icons={
|
||||
[application]
|
||||
|
||||
config/name="Material Maker"
|
||||
config/description="An open source, extensible procedural material generation tool"
|
||||
config/description="An open source, extensible procedural material authoring tool"
|
||||
run/main_scene="res://start.tscn"
|
||||
config/use_custom_user_dir=true
|
||||
config/custom_user_dir_name="material_maker"
|
||||
|
96
start.gd
96
start.gd
@ -1,22 +1,83 @@
|
||||
extends Control
|
||||
|
||||
var loader
|
||||
var loader = null
|
||||
|
||||
onready var progress_bar = $VBoxContainer/ProgressBar
|
||||
|
||||
func _ready():
|
||||
set_process(false)
|
||||
var path : String
|
||||
if Directory.new().file_exists("res://material_maker/main_window.tscn"):
|
||||
path = "res://material_maker/main_window.tscn"
|
||||
|
||||
if OS.get_cmdline_args().size() > 0 && OS.get_cmdline_args()[0] == "--export":
|
||||
var output = []
|
||||
var dir : Directory = Directory.new()
|
||||
match OS.get_name():
|
||||
"Windows":
|
||||
var bat_file_path : String = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)+"\\mm_cd.bat"
|
||||
var bat_file : File = File.new()
|
||||
bat_file.open(bat_file_path, File.WRITE)
|
||||
bat_file.store_line("cd")
|
||||
bat_file.close()
|
||||
OS.execute(bat_file_path, [], true, output)
|
||||
dir.remove(bat_file_path)
|
||||
dir.change_dir(output[0].split("\n")[2])
|
||||
var target : String = "Godot"
|
||||
var output_dir : String = dir.get_current_dir()
|
||||
var size : int = 0
|
||||
var files : Array = []
|
||||
var i = 1
|
||||
while i < OS.get_cmdline_args().size():
|
||||
match OS.get_cmdline_args()[i]:
|
||||
"-t", "--target":
|
||||
i += 1
|
||||
target = OS.get_cmdline_args()[i]
|
||||
"-o", "--output-dir":
|
||||
i += 1
|
||||
output_dir = OS.get_cmdline_args()[i]
|
||||
"--size":
|
||||
i += 1
|
||||
size = int(OS.get_cmdline_args()[i])
|
||||
if size < 0:
|
||||
show_error("ERROR: incorrect size "+OS.get_cmdline_args()[i])
|
||||
return
|
||||
_:
|
||||
files.push_back(OS.get_cmdline_args()[i])
|
||||
i += 1
|
||||
if !dir.dir_exists(output_dir):
|
||||
show_error("ERROR: Output directory '%s' does not exist" % output_dir)
|
||||
return
|
||||
var expanded_files = []
|
||||
for f in files:
|
||||
var basedir : String = f.get_base_dir()
|
||||
if basedir == "":
|
||||
basedir = "."
|
||||
var basename : String = f.get_file()
|
||||
if basename.find("*") != -1:
|
||||
basename = basename.replace("*", ".*")
|
||||
if dir.open(basedir) == OK:
|
||||
var regex : RegEx = RegEx.new()
|
||||
regex.compile("^"+basename+"$")
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
if regex.search(file_name) && file_name.get_extension() == "ptex":
|
||||
expanded_files.push_back(basedir+"/"+file_name)
|
||||
file_name = dir.get_next()
|
||||
else:
|
||||
expanded_files.push_back(f)
|
||||
export_files(expanded_files, output_dir, target, size)
|
||||
return
|
||||
else:
|
||||
path = "res://material_maker/main_window.tscn"
|
||||
else:
|
||||
path = "res://demo/demo.tscn"
|
||||
loader = ResourceLoader.load_interactive(path)
|
||||
if loader == null: # check for errors
|
||||
print("error")
|
||||
queue_free()
|
||||
set_process(true)
|
||||
|
||||
func _process(_delta):
|
||||
func _process(_delta) -> void:
|
||||
var err = loader.poll()
|
||||
if err == ERR_FILE_EOF:
|
||||
var resource = loader.get_resource()
|
||||
@ -29,3 +90,30 @@ func _process(_delta):
|
||||
else: # error during loading
|
||||
print("error")
|
||||
queue_free()
|
||||
|
||||
func export_files(files, output_dir, target, size) -> void:
|
||||
$VBoxContainer/ProgressBar.min_value = 0
|
||||
$VBoxContainer/ProgressBar.max_value = files.size()
|
||||
$VBoxContainer/ProgressBar.value = 0
|
||||
for f in files:
|
||||
var gen = mm_loader.load_gen(f)
|
||||
if gen != null:
|
||||
add_child(gen)
|
||||
for c in gen.get_children():
|
||||
if c.has_method("get_export_profiles"):
|
||||
if c.get_export_profiles().find(target) == -1:
|
||||
show_error("ERROR: Unsupported target %s"+target)
|
||||
return
|
||||
$VBoxContainer/Label.text = "Exporting "+f.get_file()
|
||||
var prefix : String = output_dir+"/"+f.get_file().get_basename()
|
||||
var result = c.export_material(prefix, target, size)
|
||||
while result is GDScriptFunctionState:
|
||||
result = yield(result, "completed")
|
||||
break
|
||||
gen.queue_free()
|
||||
$VBoxContainer/ProgressBar.value += 1
|
||||
get_tree().quit()
|
||||
|
||||
func show_error(message : String):
|
||||
$ErrorPanel.show()
|
||||
$ErrorPanel/Label.text = message
|
||||
|
33
start.tscn
33
start.tscn
@ -1,8 +1,16 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://start.gd" type="Script" id=1]
|
||||
[ext_resource path="res://rodz_labs_logo.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=1]
|
||||
bg_color = Color( 0.0235294, 0.0313726, 0.12549, 0.929412 )
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color( 1, 0, 0, 1 )
|
||||
|
||||
[node name="Start" type="Panel"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
@ -40,3 +48,26 @@ align = 1
|
||||
margin_top = 492.0
|
||||
margin_right = 256.0
|
||||
margin_bottom = 506.0
|
||||
|
||||
[node name="ErrorPanel" type="Panel" parent="."]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
margin_left = -268.5
|
||||
margin_top = -76.0
|
||||
margin_right = 268.5
|
||||
margin_bottom = 76.0
|
||||
rect_pivot_offset = Vector2( 267.976, 75.7381 )
|
||||
custom_styles/panel = SubResource( 1 )
|
||||
|
||||
[node name="Label" type="Label" parent="ErrorPanel"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_left = 10.0
|
||||
margin_top = 10.0
|
||||
margin_right = -10.0
|
||||
margin_bottom = -10.0
|
||||
align = 1
|
||||
valign = 1
|
||||
|
Loading…
Reference in New Issue
Block a user