2018-07-22 17:20:27 +02:00
|
|
|
tool
|
|
|
|
extends GraphNode
|
|
|
|
|
|
|
|
var generated = false
|
2018-07-22 23:25:05 +02:00
|
|
|
var generated_variants = []
|
|
|
|
|
|
|
|
var property_widgets = []
|
2018-07-22 17:20:27 +02:00
|
|
|
|
|
|
|
func _ready():
|
2018-07-23 22:18:43 +02:00
|
|
|
pass
|
2018-07-22 17:20:27 +02:00
|
|
|
|
|
|
|
func initialize_properties(object_list):
|
2018-07-22 23:25:05 +02:00
|
|
|
property_widgets = object_list
|
2018-07-22 17:20:27 +02:00
|
|
|
for o in object_list:
|
|
|
|
if o is LineEdit:
|
|
|
|
set(o.name, float(o.text))
|
|
|
|
o.connect("text_changed", self, "_on_text_changed", [ o.name ])
|
2018-07-24 08:04:25 +02:00
|
|
|
elif o is SpinBox:
|
|
|
|
set(o.name, o.value)
|
|
|
|
o.connect("value_changed", self, "_on_value_changed", [ o.name ])
|
2018-07-22 23:25:05 +02:00
|
|
|
elif o is ColorPickerButton:
|
|
|
|
set(o.name, o.color)
|
|
|
|
o.connect("color_changed", self, "_on_color_changed", [ o.name ])
|
|
|
|
|
2018-07-28 09:37:51 +02:00
|
|
|
func get_seed():
|
|
|
|
return int(offset.x)*3+int(offset.y)*5
|
|
|
|
|
2018-07-22 23:25:05 +02:00
|
|
|
func update_property_widgets():
|
|
|
|
for o in property_widgets:
|
|
|
|
if o is LineEdit:
|
|
|
|
o.text = str(get(o.name))
|
2018-07-28 09:37:51 +02:00
|
|
|
elif o is SpinBox:
|
|
|
|
o.value = get(o.name)
|
2018-07-22 23:25:05 +02:00
|
|
|
elif o is ColorPickerButton:
|
|
|
|
o.color = get(o.name)
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-07-28 09:37:51 +02:00
|
|
|
func update_shaders():
|
|
|
|
get_parent().send_changed_signal()
|
|
|
|
|
2018-07-22 17:20:27 +02:00
|
|
|
func _on_text_changed(new_text, variable):
|
|
|
|
set(variable, float(new_text))
|
2018-07-28 09:37:51 +02:00
|
|
|
update_shaders()
|
2018-07-22 17:20:27 +02:00
|
|
|
|
2018-07-24 08:04:25 +02:00
|
|
|
func _on_value_changed(new_value, variable):
|
|
|
|
set(variable, new_value)
|
2018-07-28 09:37:51 +02:00
|
|
|
update_shaders()
|
2018-07-24 08:04:25 +02:00
|
|
|
|
2018-07-22 23:25:05 +02:00
|
|
|
func _on_color_changed(new_color, variable):
|
|
|
|
set(variable, new_color)
|
2018-07-28 09:37:51 +02:00
|
|
|
update_shaders()
|
2018-07-22 23:25:05 +02:00
|
|
|
|
2018-07-22 17:20:27 +02:00
|
|
|
func get_source(index = 0):
|
|
|
|
for c in get_parent().get_children():
|
|
|
|
if c != self && c is GraphNode:
|
|
|
|
if get_parent().is_node_connected(c.name, 0, name, index):
|
|
|
|
return c
|
|
|
|
return null
|
|
|
|
|
2018-07-23 22:18:43 +02:00
|
|
|
func get_source_f(source):
|
|
|
|
var rv
|
|
|
|
if source.has("rgb"):
|
2018-07-28 09:37:51 +02:00
|
|
|
rv = "dot("+source.rgb+", vec3(1.0))/3.0"
|
2018-07-23 22:18:43 +02:00
|
|
|
elif source.has("f"):
|
|
|
|
rv = source.f
|
|
|
|
else:
|
|
|
|
rv = "***error***"
|
|
|
|
return rv
|
|
|
|
|
2018-07-22 23:25:05 +02:00
|
|
|
func get_source_rgb(source):
|
|
|
|
var rv
|
|
|
|
if source.has("rgb"):
|
|
|
|
rv = source.rgb
|
|
|
|
elif source.has("f"):
|
|
|
|
rv = "vec3("+source.f+")"
|
|
|
|
else:
|
|
|
|
rv = "***error***"
|
|
|
|
return rv
|
|
|
|
|
2018-07-26 08:31:28 +02:00
|
|
|
func get_shader_code(uv):
|
2018-07-28 09:37:51 +02:00
|
|
|
var rv = _get_shader_code(uv)
|
|
|
|
if !rv.has("f") && rv.has("rgb"):
|
|
|
|
rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)"
|
|
|
|
if !rv.has("rgb") && rv.has("f"):
|
|
|
|
rv.rgb = "vec3("+rv.f+")"
|
|
|
|
return rv
|
2018-07-26 08:31:28 +02:00
|
|
|
|
|
|
|
func get_textures():
|
|
|
|
var list = {}
|
|
|
|
for i in range(5):
|
|
|
|
var source = get_source(i)
|
|
|
|
if source != null:
|
|
|
|
var source_list = source.get_textures()
|
|
|
|
for k in source_list.keys():
|
|
|
|
list[k] = source_list[k]
|
|
|
|
return list
|
|
|
|
|
2018-07-22 17:20:27 +02:00
|
|
|
func queue_free():
|
|
|
|
get_parent().remove_node(self.name)
|
|
|
|
.queue_free()
|
2018-07-22 23:25:05 +02:00
|
|
|
|
|
|
|
func serialize_element(e):
|
|
|
|
if typeof(e) == TYPE_COLOR:
|
|
|
|
return { type= "Color", r=e.r, g=e.g, b=e.b, a=e.a }
|
|
|
|
return e
|
|
|
|
|
|
|
|
func deserialize_element(e):
|
|
|
|
if typeof(e) == TYPE_DICTIONARY:
|
|
|
|
if e.type == "Color":
|
|
|
|
return Color(e.r, e.g, e.b, e.a)
|
|
|
|
return e
|
|
|
|
|
|
|
|
func serialize():
|
|
|
|
var type = get_script().resource_path
|
|
|
|
type = type.right(type.find_last("/")+1)
|
|
|
|
type = type.left(type.find_last("."))
|
2018-07-23 06:19:45 +02:00
|
|
|
var data = { name=name, type=type, node_position={x=offset.x, y=offset.y} }
|
2018-07-23 22:18:43 +02:00
|
|
|
for w in property_widgets:
|
|
|
|
var v = w.name
|
2018-07-22 23:25:05 +02:00
|
|
|
data[v] = serialize_element(get(v))
|
|
|
|
return data
|
|
|
|
|
|
|
|
func deserialize(data):
|
2018-07-23 06:19:45 +02:00
|
|
|
offset = Vector2(data.node_position.x, data.node_position.y)
|
2018-07-23 22:18:43 +02:00
|
|
|
for w in property_widgets:
|
2018-07-28 09:37:51 +02:00
|
|
|
var variable = w.name
|
|
|
|
var value = deserialize_element(data[variable])
|
|
|
|
set(variable, value)
|
2018-07-22 23:25:05 +02:00
|
|
|
update_property_widgets()
|