Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions addons/material_maker/engine/nodes/gen_export.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class_name MMGenExport

# Can be used to export an additional texture


var texture = null

# The default texture size as a power-of-two exponent
Expand Down Expand Up @@ -39,12 +38,16 @@ func _serialize(data: Dictionary) -> Dictionary:
return data

func get_parameter_defs() -> Array:
var tooltip := """
Filename for the exported texture.
$node, $project, $idx and $resolution can be used.
"""
return [
{ name="size", label="Size", type="size", first=4, last=13, default=10 },
{ name="format", label="Format", default=0, type="enum", values=[
{ name="PNG" }, { name="JPG" }, { name="WEBP" }, { name="EXR" },
]},
{ name="suffix", label="Suffix", type="string", default="suffix" }
{ name="suffix", label="Filename", type="string", default="$project", longdesc=tooltip }
]

func get_input_defs() -> Array:
Expand All @@ -62,13 +65,29 @@ func get_image_format() -> String:
return "exr"
_: return "png"

func interpret_file_name(file_name: String, path:="") -> String:
var additional_ids := { "$node":"unnamed" }

if "$node" in file_name:
var graph : MMGraphEdit = mm_globals.main_window.get_current_graph_edit()
if graph != null:
for c in graph.connections:
if c.to_node == "node_" + name:
var node_title : String = graph.get_node(NodePath(c.from_node)).title
additional_ids["$node"] = node_title.to_snake_case()
break

var resolution := str(get_image_size())
return mm_globals.interpret_file_name(file_name, path, "."+get_image_format(), additional_ids, resolution)

func export_material(prefix : String, _profile : String, size : int = 0, command_line : bool = false) -> void:
if size == 0:
size = get_image_size()
var source = get_source(0)
if source != null:
var texture : MMTexture = await source.generator.render_output_to_texture(source.output_index, Vector2i(size, size))
if parameters.suffix != "":
await texture.save_to_file("%s_%s.%s" % [ prefix, parameters.suffix, get_image_format() ])
var filename := interpret_file_name(parameters.suffix, prefix.get_base_dir())
await texture.save_to_file(prefix.get_base_dir().path_join(filename))
else:
await texture.result.save_to_file("%s.%s" % [ prefix, get_image_format() ])
await texture.save_to_file("%s.%s" % [ prefix, get_image_format() ])
11 changes: 6 additions & 5 deletions material_maker/doc/node_miscellaneous_export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ Export node

The **Export** node defines a texture that will be saved together with the
material textures when exporting the project. This node can also be triggered
manually via **Quick Export** under material exports.
manually via **Quick Export** under material exports without exporting a full
materaial.

.. image:: images/node_miscellaneous_export.png
:align: center

Inputs
++++++

The **Export** node has an input that will be saved when exporting the project.
The **Export** node has an input that will be saved when exporting the project or triggered via **Quick Export**.

Outputs
+++++++
Expand All @@ -23,8 +24,8 @@ Parameters

The **Export** node has three parameters:

* the resolution size of the exported file
* *Resolution* size of the exported file

* the format of the exported file (i.e. PNG, JPG, WebP or EXR)
* *Format* of the exported file (i.e. PNG, JPG, WebP or EXR)

* the suffix of the file that will be created
* *Filename* of the created file. $node, $project, $idx and $resolution can be used.
3 changes: 2 additions & 1 deletion material_maker/nodes/reroute/reroute.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://dj08rlr43tqxj"]

[ext_resource type="Script" path="res://material_maker/nodes/reroute/reroute.gd" id="1"]
[ext_resource type="Script" uid="uid://bfkmqgx6bd2i4" path="res://material_maker/nodes/reroute/reroute.gd" id="1"]

[sub_resource type="StyleBoxFlat" id="1"]
corner_radius_top_left = 12
Expand Down Expand Up @@ -45,6 +45,7 @@ custom_minimum_size = Vector2(24, 24)
offset_right = 24.0
offset_bottom = 24.0
theme = SubResource("3")
title = "Reroute"
slot/0/left_enabled = true
slot/0/left_type = 42
slot/0/left_color = Color(1, 1, 1, 1)
Expand Down