Skip to content

Commit 0af40ba

Browse files
committed
Merge branch 'master' into lazy-connect
2 parents d096f05 + 1b20267 commit 0af40ba

356 files changed

Lines changed: 1120 additions & 431 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dev-desktop-builds.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ on:
1919
default: "true"
2020

2121
env:
22-
GODOT_VERSION: 4.5.1
22+
GODOT_VERSION: 4.6.1
2323
GODOT_SUB: stable
24-
GODOT_DOWNLOAD_DIR: https://github.com/godotengine/godot-builds/releases/download/4.5.1-stable
24+
GODOT_DOWNLOAD_DIR: https://github.com/godotengine/godot-builds/releases/download/4.6.1-stable
2525
EXPORT_NAME: material_maker
2626
MM_RELEASE: 1_6
2727

addons/material_maker/engine/loader.gd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@tool
2+
class_name MMLoader
23
extends Node
34

45
var predefined_generators : Dictionary = {}
@@ -157,20 +158,50 @@ static func string_to_dict_tree(string_data : String) -> Dictionary:
157158
static func dict_tree_to_string(data : Dictionary) -> String:
158159
return JSON.stringify(replace_multiline_strings_with_arrays(data.duplicate(true)), "\t", true)
159160

161+
static func interpret_file_name(file_name : String, path : String = "", file_extension : String = "", node : MMGenBase = null, additional_identifiers : Dictionary[String, String] = {}, resolution : String = "") -> String:
162+
for i in additional_identifiers:
163+
file_name = file_name.replace(i, additional_identifiers[i])
164+
165+
if node and node.has_meta("file_path"):
166+
var save_path : String = node.get_meta("file_path")
167+
file_name = file_name.replace("$project", save_path.get_file().trim_suffix("."+save_path.get_extension()))
168+
else:
169+
file_name = file_name.replace("$project", "unnamed_project")
170+
171+
if file_extension != "" and not file_name.ends_with(file_extension):
172+
file_name += file_extension
173+
174+
if resolution:
175+
file_name = file_name.replace("$resolution", resolution)
176+
177+
if "$idx" in file_name:
178+
if path:
179+
var idx := 1
180+
while FileAccess.file_exists(path.path_join(file_name).replace("$idx", str(idx).pad_zeros(2))):
181+
idx += 1
182+
file_name = file_name.replace("$idx", str(idx).pad_zeros(2))
183+
else:
184+
file_name = file_name.replace("$idx", str(1).pad_zeros(2))
185+
186+
return file_name
187+
160188
func load_gen(filename: String) -> MMGenBase:
161189
var file : FileAccess = FileAccess.open(filename, FileAccess.READ)
162190
if file != null:
163191
var data = string_to_dict_tree(file.get_as_text())
164192
if data != null:
165193
current_project_path = filename.get_base_dir()
166194
var generator = await create_gen(data)
195+
if generator:
196+
generator.set_meta("file_path", filename)
167197
current_project_path = ""
168198
return generator
169199
return null
170200

171201
func save_gen(filename : String, generator : MMGenBase) -> void:
172202
var file : FileAccess = FileAccess.open(filename, FileAccess.WRITE)
173203
if file != null:
204+
generator.set_meta("file_path", filename)
174205
var data = generator.serialize()
175206
data.name = filename.get_file().get_basename()
176207
data.node_position = { x=0, y=0 }

addons/material_maker/engine/nodes/gen_export.gd

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,22 @@ func get_image_format() -> String:
6565
return "exr"
6666
_: return "png"
6767

68-
func interpret_file_name(file_name: String, path:="") -> String:
69-
var additional_ids := { "$node":"unnamed" }
68+
func interpret_file_name(file_name : String, path : String = "") -> String:
69+
var additional_ids : Dictionary[String, String] = { "$node": "unnamed" }
7070

7171
if "$node" in file_name:
72-
var graph : MMGraphEdit = mm_globals.main_window.get_current_graph_edit()
73-
if graph != null:
74-
for c in graph.connections:
75-
if c.to_node == "node_" + name:
76-
var node_title : String = graph.get_node(NodePath(c.from_node)).title
77-
additional_ids["$node"] = node_title.to_snake_case()
78-
break
79-
80-
var resolution := str(get_image_size())
81-
return mm_globals.interpret_file_name(file_name, path, "."+get_image_format(), additional_ids, resolution)
72+
var source_port : OutputPort = get_source(0)
73+
if source_port != null:
74+
var source_node : MMGenBase = source_port.generator
75+
if source_node:
76+
additional_ids["$node"] = source_node.get_type_name().to_snake_case()
77+
78+
var graph_node : MMGenBase = self
79+
while graph_node.get_parent() is MMGenBase:
80+
graph_node = graph_node.get_parent()
81+
82+
var resolution : String = str(get_image_size())
83+
return MMLoader.interpret_file_name(file_name, path, "."+get_image_format(), graph_node, additional_ids, resolution)
8284

8385
func export_material(prefix : String, _profile : String, size : int = 0, command_line : bool = false) -> void:
8486
if size == 0:
@@ -87,7 +89,7 @@ func export_material(prefix : String, _profile : String, size : int = 0, command
8789
if source != null:
8890
var texture : MMTexture = await source.generator.render_output_to_texture(source.output_index, Vector2i(size, size))
8991
if parameters.suffix != "":
90-
var filename := interpret_file_name(parameters.suffix, prefix.get_base_dir())
92+
var filename : String = interpret_file_name(parameters.suffix, prefix.get_base_dir())
9193
await texture.save_to_file(prefix.get_base_dir().path_join(filename))
9294
else:
9395
await texture.save_to_file("%s.%s" % [ prefix, get_image_format() ])

addons/material_maker/engine/paths.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const WEBSITE_ADDRESS : String = "https://www.materialmaker.org"
77
const STD_GENDEF_PATH = "res://addons/material_maker/nodes"
88

99
static func get_resource_dir() -> String:
10-
if OS.has_feature("editor"):
10+
if Engine.is_editor_hint():
1111
return ProjectSettings.globalize_path("res://material_maker")
1212
return OS.get_executable_path().get_base_dir()
1313

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "color_pick",
3+
"node_position": {
4+
"x": 0,
5+
"y": 0
6+
},
7+
"parameters": {
8+
9+
},
10+
"seed_int": 0,
11+
"shader_model": {
12+
"code": "",
13+
"global": "",
14+
"inputs": [
15+
{
16+
"default": "vec3(1.0)",
17+
"label": "",
18+
"longdesc": "The input ID map",
19+
"name": "in",
20+
"shortdesc": "Input",
21+
"type": "rgb"
22+
}
23+
],
24+
"instance": "",
25+
"longdesc": "Pick colors from an input ID map",
26+
"name": "Color Pick",
27+
"outputs": [
28+
{
29+
"f": "1.0 - clamp((dot(abs($in($uv) - $color#.rgb), vec3(1.0/3.0)) - $threshold) / max($falloff, 0.00001), 0.0, 1.0)",
30+
"longdesc": "Output mask corresponding to the picked color",
31+
"shortdesc": "Output #",
32+
"type": "f"
33+
}
34+
],
35+
"parameters": [
36+
{
37+
"default": {
38+
"a": 1,
39+
"b": 1,
40+
"g": 1,
41+
"r": 1
42+
},
43+
"label": "",
44+
"longdesc": "Color to pick from the ID map",
45+
"name": "color#",
46+
"shortdesc": "Color #",
47+
"type": "color"
48+
},
49+
{
50+
"control": "None",
51+
"default": 0.01,
52+
"label": "Threshold",
53+
"longdesc": "Controls the sensitivity of color matching. Higher values will match more colors.",
54+
"max": 1,
55+
"min": 0,
56+
"name": "threshold",
57+
"shortdesc": "Threshold",
58+
"step": 0.01,
59+
"type": "float"
60+
},
61+
{
62+
"control": "None",
63+
"default": 0,
64+
"label": "Falloff",
65+
"longdesc": "Controls the softness of the output mask. Set to 0 to output a binary black/white image.",
66+
"max": 1,
67+
"min": 0,
68+
"name": "falloff",
69+
"shortdesc": "Falloff",
70+
"step": 0.01,
71+
"type": "float"
72+
}
73+
],
74+
"shortdesc": "Pick colors"
75+
},
76+
"type": "shader"
77+
}

0 commit comments

Comments
 (0)