material-maker/addons/material_maker/engine/gen_export.gd
2020-02-24 23:29:33 +01:00

45 lines
1.0 KiB
GDScript

tool
extends MMGenBase
class_name MMGenExport
"""
Can be used to export an additional texture
"""
var texture = null
# The default texture size as a power-of-two exponent
const TEXTURE_SIZE_DEFAULT = 10 # 1024x1024
func get_image_size() -> int:
var rv : int
if parameters.has("size"):
rv = int(pow(2, parameters.size))
else:
rv = int(pow(2, TEXTURE_SIZE_DEFAULT))
return rv
func get_type() -> String:
return "export"
func get_type_name() -> String:
return "Export"
func get_parameter_defs() -> Array:
return [
{ name="size", type="size", first=4, last=12, default=10 },
{ name="suffix", type="string", default="suffix" }
]
func get_input_defs() -> Array:
return [ { name="in", type="rgba" } ]
func export_material(prefix, _profile) -> void:
var source = get_source(0)
if source != null:
var result = source.generator.render(source.output_index, get_image_size())
while result is GDScriptFunctionState:
result = yield(result, "completed")
result.save_to_file("%s_%s.png" % [ prefix, parameters.suffix])
result.release()