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