mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Optimized float parameters (now passed as dictionaries)
This commit is contained in:
parent
9ab8820598
commit
aad3991734
@ -90,7 +90,7 @@ func init_parameters() -> void:
|
||||
func set_position(p) -> void:
|
||||
position = p
|
||||
if has_randomness() and !is_seed_locked() and is_inside_tree():
|
||||
get_tree().call_group("preview", "on_float_parameter_changed", "seed_o%s" % [ str(get_instance_id()) ], get_seed())
|
||||
get_tree().call_group("preview", "on_float_parameters_changed", { "seed_o"+str(get_instance_id()): get_seed() })
|
||||
|
||||
func get_type() -> String:
|
||||
return "generic"
|
||||
@ -127,7 +127,7 @@ func set_parameter(n : String, v) -> void:
|
||||
if parameter_def.has("type"):
|
||||
if parameter_def.type == "float":
|
||||
var parameter_name = "p_o%s_%s" % [ str(get_instance_id()), n ]
|
||||
get_tree().call_group("preview", "on_float_parameter_changed", parameter_name, v)
|
||||
get_tree().call_group("preview", "on_float_parameters_changed", { parameter_name:v })
|
||||
return
|
||||
elif parameter_def.type == "gradient":
|
||||
if v.interpolation == old_value.interpolation && v.points.size() == old_value.points.size():
|
||||
@ -138,13 +138,14 @@ func set_parameter(n : String, v) -> void:
|
||||
old_value.points[i] = { pos=old.v, r=old.c.r, g=old.c.g, b=old.c.b, a=old.c.a }
|
||||
old_value.points.sort_custom(CustomGradientSorter, "compare")
|
||||
v.points.sort_custom(CustomGradientSorter, "compare")
|
||||
var parameter_changes = {}
|
||||
for i in range(old_value.points.size()):
|
||||
for f in [ "pos", "r", "g", "b", "a" ]:
|
||||
if v.points[i][f] != old_value.points[i][f]:
|
||||
var parameter_name = "p_o%s_%s_%d_%s" % [ str(get_instance_id()), n, i, f ]
|
||||
get_tree().call_group("preview", "on_float_parameter_changed", parameter_name, v.points[i][f])
|
||||
parameter_changes[parameter_name] = v.points[i][f]
|
||||
get_tree().call_group("preview", "on_float_parameters_changed", parameter_changes)
|
||||
return
|
||||
print("regenerating shader")
|
||||
source_changed(0)
|
||||
|
||||
func notify_output_change(output_index : int) -> void:
|
||||
|
@ -55,12 +55,12 @@ func update_shader() -> void:
|
||||
material.set_shader_param(k, source.textures[k])
|
||||
update_buffer()
|
||||
|
||||
func on_float_parameter_changed(n : String, v : float) -> void:
|
||||
func on_float_parameters_changed(parameter_changes : Dictionary) -> void:
|
||||
for n in parameter_changes.keys():
|
||||
for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
|
||||
if p.name == n:
|
||||
material.set_shader_param(n, v)
|
||||
update_buffer()
|
||||
return
|
||||
material.set_shader_param(n, parameter_changes[n])
|
||||
break
|
||||
|
||||
func on_texture_changed(n : String) -> void:
|
||||
for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
|
||||
|
@ -123,17 +123,17 @@ func render_textures() -> void:
|
||||
texture.flags ^= ImageTexture.FLAG_FILTER
|
||||
need_update[t.texture] = false
|
||||
|
||||
func on_float_parameter_changed(n : String, v : float) -> void:
|
||||
func on_float_parameters_changed(parameter_changes : Dictionary) -> void:
|
||||
for t in TEXTURE_LIST:
|
||||
if generated_textures[t.texture] != null:
|
||||
for n in parameter_changes.keys():
|
||||
for p in VisualServer.shader_get_param_list(shader_materials[t.texture].shader.get_rid()):
|
||||
if p.name == n:
|
||||
shader_materials[t.texture].set_shader_param(n, v)
|
||||
shader_materials[t.texture].set_shader_param(n, parameter_changes[n])
|
||||
need_render[t.texture] = true
|
||||
update_textures()
|
||||
break
|
||||
|
||||
|
||||
func on_texture_changed(n : String) -> void:
|
||||
for t in TEXTURE_LIST:
|
||||
if generated_textures[t.texture] != null:
|
||||
|
@ -72,6 +72,7 @@ func set_shader_model(data: Dictionary) -> void:
|
||||
if shader_model.has("instance"):
|
||||
if shader_model.instance.find("$seed") != -1 or shader_model.instance.find("$(seed)") != -1:
|
||||
uses_seed = true
|
||||
source_changed(0)
|
||||
|
||||
func find_keyword_call(string, keyword):
|
||||
var search_string = "$%s(" % keyword
|
||||
|
@ -103,7 +103,7 @@ func update_tab_title() -> void:
|
||||
if get_parent().has_method("set_tab_title"):
|
||||
get_parent().set_tab_title(get_index(), title)
|
||||
|
||||
func set_need_save(ns) -> void:
|
||||
func set_need_save(ns = true) -> void:
|
||||
if ns != need_save:
|
||||
need_save = ns
|
||||
update_tab_title()
|
||||
|
@ -53,7 +53,7 @@ func on_parameter_changed(p, v) -> void:
|
||||
o.value = gradient
|
||||
else:
|
||||
print("unsupported widget "+str(o))
|
||||
update_shaders()
|
||||
get_parent().set_need_save()
|
||||
|
||||
func initialize_properties() -> void:
|
||||
var parameter_names = []
|
||||
@ -82,33 +82,29 @@ func initialize_properties() -> void:
|
||||
else:
|
||||
print("unsupported widget "+str(o))
|
||||
|
||||
func update_shaders() -> void:
|
||||
#get_parent().send_changed_signal()
|
||||
update_preview()
|
||||
|
||||
func _on_text_changed(new_text, variable) -> void:
|
||||
ignore_parameter_change = variable
|
||||
generator.set_parameter(variable, new_text)
|
||||
ignore_parameter_change = ""
|
||||
update_shaders()
|
||||
get_parent().set_need_save()
|
||||
|
||||
func _on_value_changed(new_value, variable) -> void:
|
||||
ignore_parameter_change = variable
|
||||
generator.set_parameter(variable, new_value)
|
||||
ignore_parameter_change = ""
|
||||
if ! (new_value is float):
|
||||
update_shaders()
|
||||
get_parent().set_need_save()
|
||||
|
||||
func _on_color_changed(new_color, variable) -> void:
|
||||
ignore_parameter_change = variable
|
||||
generator.set_parameter(variable, new_color)
|
||||
ignore_parameter_change = ""
|
||||
update_shaders()
|
||||
get_parent().set_need_save()
|
||||
|
||||
func _on_gradient_changed(new_gradient, variable) -> void:
|
||||
ignore_parameter_change = variable
|
||||
generator.set_parameter(variable, MMType.serialize_value(new_gradient))
|
||||
ignore_parameter_change = ""
|
||||
get_parent().set_need_save()
|
||||
|
||||
func create_parameter_control(p : Dictionary) -> Control:
|
||||
var control = null
|
||||
@ -297,7 +293,7 @@ func edit_generator() -> void:
|
||||
func update_generator(shader_model) -> void:
|
||||
generator.set_shader_model(shader_model)
|
||||
update_node()
|
||||
update_shaders()
|
||||
get_parent().set_need_save()
|
||||
|
||||
func load_generator() -> void:
|
||||
var dialog = FileDialog.new()
|
||||
|
@ -51,11 +51,12 @@ func on_parameter_changed(n : String, v) -> void:
|
||||
_:
|
||||
set_generator(generator, output)
|
||||
|
||||
func on_float_parameter_changed(n : String, v : float) -> void:
|
||||
func on_float_parameters_changed(parameter_changes : Dictionary) -> void:
|
||||
for n in parameter_changes.keys():
|
||||
for p in VisualServer.shader_get_param_list(material.shader.get_rid()):
|
||||
if p.name == n:
|
||||
material.set_shader_param(n, v)
|
||||
return
|
||||
material.set_shader_param(n, parameter_changes[n])
|
||||
break
|
||||
|
||||
func on_resized() -> void:
|
||||
material.set_shader_param("size", rect_size)
|
||||
|
Loading…
Reference in New Issue
Block a user