Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Aug 18, 2024
2 parents bd217af + 9dacdb6 commit 2d6acbe
Show file tree
Hide file tree
Showing 41 changed files with 1,705 additions and 877 deletions.
1 change: 1 addition & 0 deletions addons/flexible_layout/flexible_tab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func update():
add_theme_stylebox_override("panel", get_theme_stylebox("tab_selected" if is_current else "tab_unselected", "MM_FlexibleTab"))
$Container/Undock.visible = is_current and get_flex_layout().main_control.allow_undock
$Container/Close.visible = is_current
$Container/Label.add_theme_color_override("font_color", get_theme_color("font_selected_color" if is_current else "font_unselected_color", "MM_FlexibleTab") )
updating = false

func _on_undock_pressed():
Expand Down
5 changes: 4 additions & 1 deletion addons/material_maker/engine/io_types.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ func _ready():
if t.has("label"):
type_names.push_back(t.name)
var c = t.color
t.color = Color(c.r, c.g, c.b, c.a)
if c is String:
t.color = Color(c)
else:
t.color = Color(c.r, c.g, c.b, c.a)
file = FileAccess.open(p+"/preview_"+t.name+".gdshader", FileAccess.READ)
if file != null:
t.preview = file.get_as_text()
Expand Down
2 changes: 1 addition & 1 deletion addons/material_maker/engine/loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func create_gen(data : Dictionary, fix : bool = true) -> MMGenBase:
if generator == null:
print("LOADER: data not supported:"+str(data))
if generator != null:
var status = generator.deserialize(data)
var status = await generator.deserialize(data)
return generator

func get_generator_list() -> Array:
Expand Down
2 changes: 1 addition & 1 deletion addons/material_maker/engine/nodes/gen_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func _deserialize(_data : Dictionary) -> void:
pass

func deserialize(data : Dictionary) -> void:
_deserialize(data)
await _deserialize(data)
if data.has("name"):
name = data.name
if data.has("node_position"):
Expand Down
2 changes: 2 additions & 0 deletions addons/material_maker/engine/nodes/gen_buffer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func update_shader() -> void:
func do_update_shader() -> void:
if ! is_instance_valid(self) or exiting:
return
if not is_node_ready():
await ready
updating_shader = false
var context : MMGenContext = MMGenContext.new()
var source : ShaderCode
Expand Down
22 changes: 11 additions & 11 deletions addons/material_maker/nodes/io_types.mmt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{ "type":"rgb", "expr":"vec3($(value))" },
{ "type":"rgba", "expr":"vec4(vec3($(value)), 1.0)" }
],
"color":{ "r":0.5, "g":0.5, "b":0.5, "a":1.0 }
"color":"#8D8D8D",
},
{
"name":"rgb",
Expand All @@ -23,7 +23,7 @@
{ "type":"f", "expr":"(dot($(value), vec3(1.0))/3.0)" },
{ "type":"rgba", "expr":"vec4($(value), 1.0)" }
],
"color":{ "r":0.5, "g":0.5, "b":1.0, "a":1.0 }
"color":"#33A3C7",
},
{
"name":"rgba",
Expand All @@ -36,7 +36,7 @@
{ "type":"f", "expr":"(dot(($(value)).rgb, vec3(1.0))/3.0)" },
{ "type":"rgb", "expr":"(($(value)).rgb)" }
],
"color":{ "r":0.0, "g":0.5, "b":0.0, "a":0.5 }
"color":"#335DC7",
},
{
"name":"sdf2d",
Expand All @@ -45,7 +45,7 @@
"paramdefs":"vec2 uv",
"params":"uv",
"slot_type":1,
"color":{ "r":1.0, "g":0.5, "b":0.0, "a":1.0 }
"color":"#E8A31D",
},
{
"name":"sdf3d",
Expand All @@ -57,7 +57,7 @@
"convert":[
{ "type":"sdf3dc", "expr":"vec2($(value), 0.0)" }
],
"color":{ "r":0.5, "g":0.0, "b":0.0, "a":1.0 }
"color":"#EB6135",
},
{
"name":"sdf3dc",
Expand All @@ -69,7 +69,7 @@
"convert":[
{ "type":"sdf3d", "expr":"($(value)).x" }
],
"color":{ "r":1.0, "g":0.0, "b":0.0, "a":1.0 }
"color":"#DF2626",
},
{
"name":"tex3d_gs",
Expand All @@ -81,7 +81,7 @@
"convert":[
{ "type":"tex3d", "expr":"vec3($(value))" }
],
"color":{ "r":0.8, "g":0.0, "b":1.0, "a":1.0 }
"color":"#A734DD",
},
{
"name":"tex3d",
Expand All @@ -93,7 +93,7 @@
"convert":[
{ "type":"tex3d_gs", "expr":"(dot($(value), vec3(1.0))/3.0)" }
],
"color":{ "r":1.0, "g":0.0, "b":1.0, "a":1.0 }
"color":"#E739D5",
},
{
"name":"v4v4",
Expand All @@ -102,7 +102,7 @@
"paramdefs":"vec4 p",
"params":"p",
"slot_type":4,
"color":{ "r":0.6, "g":0.4, "b":0.1, "a":1.0 }
"color":"#B79074",
},
{
"name":"fill",
Expand All @@ -111,11 +111,11 @@
"paramdefs":"vec2 uv",
"params":"uv",
"slot_type":5,
"color":{ "r":0.86, "g":0.73, "b":0.53, "a":1.0 }
"color":"#2DB76C",
},
{
"name":"any",
"slot_type":42,
"color":{ "r":1.0, "g":1.0, "b":1.0, "a":1.0 }
"color":"#DEDEDE",
}
]
27 changes: 23 additions & 4 deletions addons/material_maker/types/gradient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ func get_shader_params(parameter_name : String, attribute : String = "uniform")
rv += p.to_str(attribute)
return rv


func get_parameters(parameter_name : String) -> Array[MMGenBase.ShaderUniform]:
var rv : Array[MMGenBase.ShaderUniform] = []
var parameter_values : Dictionary = get_parameter_values(parameter_name)
rv.append(MMGenBase.ShaderUniform.new("p_%s_pos" % parameter_name, "float", parameter_values["p_%s_pos" % parameter_name], points.size()))
rv.append(MMGenBase.ShaderUniform.new("p_%s_col" % parameter_name, "vec4", parameter_values["p_%s_col" % parameter_name], points.size()))
return rv


func get_parameter_values(parameter_name : String) -> Dictionary:
sort()
var rv : Dictionary = {}
Expand Down Expand Up @@ -115,11 +117,11 @@ func get_shader(parameter_name : String) -> String:
match interpolation:
0:
if points.size() > 0:
shader += " if (x < 0.5*(%s+%s)) {\n" % [ pv(parameter_name, 0), pv(parameter_name, 1) ]
shader += " if (x < %s) {\n" % pv(parameter_name, 1)
shader += " return "+pc(parameter_name, 0)+";\n"
var s = points.size()-1
for i in range(1, s):
shader += " } else if (x < 0.5*(%s+%s)) {\n" % [ pv(parameter_name, i), pv(parameter_name, i+1) ]
shader += " } else if (x < %s) {\n" % pv(parameter_name, i+1)
shader += " return "+pc(parameter_name, i)+";\n"
shader += " }\n"
shader += " return "+pc(parameter_name, s)+";\n"
Expand Down Expand Up @@ -172,8 +174,17 @@ func get_shader(parameter_name : String) -> String:
func serialize() -> Dictionary:
sort()
var rv = []
for p in points:
rv.append({ pos=p.v, r=p.c.r, g=p.c.g, b=p.c.b, a=p.c.a })
if interpolation == 0:
var p : Point = points[0]
rv.append({ pos=0, r=p.c.r, g=p.c.g, b=p.c.b, a=p.c.a })
for i in range(1, points.size()):
var next_p : Point = points[i]
rv.append({ pos=next_p.v-0.00001, r=p.c.r, g=p.c.g, b=p.c.b, a=p.c.a })
p = next_p
rv.append({ pos=next_p.v+0.00001, r=p.c.r, g=p.c.g, b=p.c.b, a=p.c.a })
else:
for p in points:
rv.append({ pos=p.v, r=p.c.r, g=p.c.g, b=p.c.b, a=p.c.a })
rv = { type="Gradient", points=rv, interpolation=interpolation }
return rv

Expand All @@ -183,12 +194,20 @@ func deserialize(v) -> void:
for i in v:
if !i.has("a"): i.a = 1.0
add_point(i.pos, Color(i.r, i.g, i.b, i.a))
interpolation = 1
elif typeof(v) == TYPE_DICTIONARY and v.has("type") && v.type == "Gradient":
for i in v.points:
if !i.has("a"): i.a = 1.0
add_point(i.pos, Color(i.r, i.g, i.b, i.a))
if v.has("interpolation"):
interpolation = int(v.interpolation)
if interpolation == 0:
for i in range(points.size()-1, 0, -1):
if points[i].c == points[i-1].c:
points.remove_at(i)
else:
points[i].v = 0.5*(points[i-1].v+points[i].v)
points[0].v = 0
else:
interpolation = 1
elif typeof(v) == TYPE_OBJECT and v.get_script() == get_script():
Expand Down
6 changes: 3 additions & 3 deletions export_presets.cfg

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions material_maker/doc/nodes_common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ connected to several node inputs. Each node output (and input) can be:

* a **color image** (shown in blue)

* an **RGBA image** (shown in semi-transparent green)
* an **RGBA image** (shown in blue)

* a **2D signed distance function** (shown in orange)

* a **3D signed distance function** (shown in red), with or without a color index
* a **3D signed distance function** (shown in orange-red), with or without a color index

* a color or greyscale **3D texture** (shown in fuchsia), that can be associated to
* a color or greyscale **3D texture** (shown in violet), that can be associated to
a color index, which makes it possible to associate several 3D textures in a single
3D scene

* **Fill information** (shown in light orange), that contain the bounding box of the
* **Fill information** (shown in green), that contain the bounding box of the
area. This information is generated by the Fill node and a few pattern nodes, and is
used as input by the Fill companion nodes

Expand Down
48 changes: 24 additions & 24 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,35 @@ func _ready() -> void:
get_window().transparent = false
get_window().move_to_foreground()
get_window().gui_embed_subwindows = false

get_window().close_requested.connect(self.on_close_requested)

get_tree().set_auto_accept_quit(false)

if mm_globals.get_config("locale") == "":
mm_globals.set_config("locale", TranslationServer.get_locale())

on_config_changed()

# Restore the window position/size if values are present in the configuration cache
if mm_globals.config.has_section_key("window", "screen"):
get_window().current_screen = mm_globals.config.get_value("window", "screen")

if mm_globals.config.has_section_key("window", "maximized"):
get_window().mode = Window.MODE_MAXIMIZED if (mm_globals.config.get_value("window", "maximized")) else Window.MODE_WINDOWED

if get_window().mode != Window.MODE_MAXIMIZED:
if mm_globals.config.has_section_key("window", "position"):
get_window().position = mm_globals.config.get_value("window", "position")
if mm_globals.config.has_section_key("window", "size"):
get_window().size = mm_globals.config.get_value("window", "size")

# Restore the theme
var theme_name : String = "default"
if mm_globals.config.has_section_key("window", "theme"):
theme_name = mm_globals.config.get_value("window", "theme")
change_theme(theme_name)

# In HTML5 export, copy all examples to the filesystem
if OS.get_name() == "HTML5":
print("Copying samples")
Expand All @@ -161,13 +161,13 @@ func _ready() -> void:
if f.ends_with(".ptex"):
print(f)
dir.copy("res://material_maker/examples/"+f, "/examples/"+f)

# Set a minimum window size to prevent UI elements from collapsing on each other.
get_window().min_size = Vector2(1024, 600)

# Set window title
get_window().set_title(ProjectSettings.get_setting("application/config/name")+" v"+ProjectSettings.get_setting("application/config/actual_release"))

layout.load_panels()
library = get_panel("Library")
preview_2d = [ get_panel("Preview2D"), get_panel("Preview2D (2)") ]
Expand All @@ -177,12 +177,12 @@ func _ready() -> void:
hierarchy = get_panel("Hierarchy")
hierarchy.connect("group_selected", self.on_group_selected)
brushes = get_panel("Brushes")

# Load recent projects
load_recents()

get_window().connect("files_dropped", self.on_files_dropped)

var args : PackedStringArray = OS.get_cmdline_args()
for a in args:
if a.get_extension() == "ptex":
Expand All @@ -198,7 +198,7 @@ func _ready() -> void:
continue
var project_filename : String = mesh_filename.get_basename()+".mmpp"
create_paint_project(mesh, mesh_filename, 1024, project_filename)

# Rescue unsaved projects
if true:
var dir : DirAccess = DirAccess.open("user://unsaved_projects")
Expand All @@ -223,16 +223,16 @@ func _ready() -> void:
"delete":
for f in files:
DirAccess.remove_absolute(f)

if get_current_graph_edit() == null:
await get_tree().process_frame
new_material()

size = get_window().size
position = Vector2.ZERO
set_anchors_preset(Control.PRESET_FULL_RECT)
update_menus()

mm_logger.message("Material Maker "+ProjectSettings.get_setting("application/config/actual_release"))

var menu_update_requested : bool = false
Expand Down Expand Up @@ -288,7 +288,7 @@ func on_config_changed() -> void:
ui_scale = 2 if DisplayServer.screen_get_dpi() >= 192 and DisplayServer.screen_get_size().x >= 2048 else 1
get_viewport().content_scale_factor = ui_scale
#ProjectSettings.set_setting("display/window/stretch/scale", scale)

# Clamp to reasonable values to avoid crashes on startup.
preview_rendering_scale_factor = clamp(mm_globals.get_config("ui_3d_preview_resolution"), 1.0, 2.0)
# warning-ignore:narrowing_conversion
Expand Down Expand Up @@ -566,7 +566,7 @@ func get_file_absolute_path(filename : String) -> String:
if file == null:
return ""
return file.get_path_absolute()

func do_load_projects(filenames) -> void:
var file_name : String = ""
for f in filenames:
Expand Down Expand Up @@ -1194,16 +1194,16 @@ func set_tip_text(tip : String, timeout : float = 0.0):
tip = tip.replace("#LMB", "[img]res://material_maker/icons/lmb.tres[/img]")
tip = tip.replace("#RMB", "[img]res://material_maker/icons/rmb.tres[/img]")
tip = tip.replace("#MMB", "[img]res://material_maker/icons/mmb.tres[/img]")
$VBoxContainer/StatusBar/Tip.text = tip
var tip_timer : Timer = $VBoxContainer/StatusBar/Tip/Timer
$VBoxContainer/StatusBar/HBox/Tip.text = tip
var tip_timer : Timer = $VBoxContainer/StatusBar/HBox/Tip/Timer
tip_timer.stop()
if timeout > 0.0:
tip_timer.one_shot = true
tip_timer.wait_time = timeout
tip_timer.start()

func _on_Tip_Timer_timeout():
$VBoxContainer/StatusBar/Tip.text = ""
$VBoxContainer/StatusBar/HBox/Tip.text = ""

# Add dialog

Expand Down
Loading

0 comments on commit 2d6acbe

Please sign in to comment.