mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
More progress on remote and various fixes
This commit is contained in:
parent
8af2c04f91
commit
201f911f75
@ -13,7 +13,7 @@ const TEXTURE_LIST = [
|
||||
{ port=2, texture="roughness" },
|
||||
{ port=3, texture="emission" },
|
||||
{ port=4, texture="normal_texture" },
|
||||
{ port=5, texture="ambient_occlusion" },
|
||||
{ port=5, texture="ao_texture" },
|
||||
{ port=6, texture="depth_texture" }
|
||||
]
|
||||
|
||||
@ -34,9 +34,12 @@ func get_type_name():
|
||||
func get_parameter_defs():
|
||||
return [
|
||||
{ name="albedo_color", label="Albedo", type="color", default={ r=1.0, g=1.0, b=1.0, a=1.0} },
|
||||
{ name="metallic", label="Metallic", type="float", min=0.0, max=1.0, default=1.0 },
|
||||
{ name="roughness", label="Roughness", type="float", min=0.0, max=1.0, default=1.0 },
|
||||
{ name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, default=1.0 }
|
||||
{ name="metallic", label="Metallic", type="float", min=0.0, max=1.0, step=0.05, default=1.0 },
|
||||
{ name="roughness", label="Roughness", type="float", min=0.0, max=1.0, step=0.05, default=1.0 },
|
||||
{ name="emission_energy", label="Emission", type="float", min=0.0, max=8.0, step=0.05, default=1.0 },
|
||||
{ name="normal_scale", label="Normal", type="float", min=0.0, max=8.0, step=0.05, default=1.0 },
|
||||
{ name="ao_light_affect", label="Ambient occlusion", type="float", min=0.0, max=1.0, step=0.05, default=1.0 },
|
||||
{ name="depth_scale", label="Depth", type="float", min=0.0, max=1.0, step=0.05, default=1.0 }
|
||||
]
|
||||
|
||||
func get_input_defs():
|
||||
@ -46,6 +49,7 @@ func get_input_defs():
|
||||
{ name="roughness_texture", label="", type="f" },
|
||||
{ name="emission_texture", label="", type="rgb" },
|
||||
{ name="normal_texture", label="", type="rgb" },
|
||||
{ name="ao_texture", label="", type="f" },
|
||||
{ name="depth_texture", label="", type="f" }
|
||||
]
|
||||
|
||||
@ -124,23 +128,24 @@ func update_spatial_material(m, file_prefix = null):
|
||||
if Engine.editor_hint:
|
||||
if (generated_textures.mrao.mask & (1 << 2)) != 0:
|
||||
m.ao_enabled = true
|
||||
#m.ao_light_affect = parameters.ao_light_affect
|
||||
m.ao_light_affect = parameters.ao_light_affect
|
||||
m.ao_texture = m.metallic_texture
|
||||
m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE
|
||||
else:
|
||||
m.ao_enabled = false
|
||||
else:
|
||||
texture = get_generated_texture("ambient_occlusion", file_prefix)
|
||||
texture = get_generated_texture("ao_texture", file_prefix)
|
||||
if texture != null:
|
||||
m.ao_enabled = true
|
||||
#m.ao_light_affect = parameters.ao_light_affect
|
||||
m.ao_light_affect = parameters.ao_light_affect
|
||||
m.ao_texture = texture
|
||||
else:
|
||||
m.ao_enabled = false
|
||||
texture = get_generated_texture("depth_texture", file_prefix)
|
||||
if texture != null:
|
||||
m.depth_enabled = true
|
||||
#m.depth_scale = parameters.depth_scale
|
||||
m.depth_deep_parallax = true
|
||||
m.depth_scale = parameters.depth_scale
|
||||
m.depth_texture = texture
|
||||
else:
|
||||
m.depth_enabled = false
|
||||
|
@ -18,7 +18,7 @@ func set_widgets(w):
|
||||
i += 1
|
||||
|
||||
func get_type():
|
||||
return "remot"
|
||||
return "remote"
|
||||
|
||||
func get_type_name():
|
||||
return "Remote"
|
||||
@ -68,3 +68,30 @@ func _serialize(data):
|
||||
data.type = "remote"
|
||||
data.widgets = widgets
|
||||
return data
|
||||
|
||||
func create_linked_control(label):
|
||||
var index = widgets.size()
|
||||
widgets.push_back({ label=label, type="linked_control", linked_widgets=[] })
|
||||
return index
|
||||
|
||||
func create_config_control(label):
|
||||
var index = widgets.size()
|
||||
widgets.push_back({ label=label, type="config_control", linked_widgets=[], configurations=[] })
|
||||
return index
|
||||
|
||||
func can_link_parameter(index, generator, param):
|
||||
return true
|
||||
|
||||
func link_parameter(index, generator, param):
|
||||
if !can_link_parameter(index, generator, param):
|
||||
return
|
||||
widgets[index].linked_widgets.push_back({ node=generator.name, widget=param })
|
||||
if widgets[index].linked_widgets.size() == 1:
|
||||
parameters["param"+str(index)] = generator.parameters[param]
|
||||
emit_signal("parameter_changed", "", null)
|
||||
|
||||
func remove_parameter(index):
|
||||
for i in range(index, widgets.size()-2):
|
||||
parameters["param"+str(i)] = parameters["param"+str(i+1)]
|
||||
widgets.remove(index)
|
||||
emit_signal("parameter_changed", "", null)
|
@ -31,7 +31,7 @@ func get_output_defs():
|
||||
return rv
|
||||
|
||||
func source_changed(input_index : int):
|
||||
notify_output_change(input_index % parameters.outputs)
|
||||
notify_output_change(input_index % int(parameters.outputs))
|
||||
|
||||
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||
var source = get_source(output_index+parameters.source*parameters.outputs)
|
||||
|
@ -6,6 +6,7 @@ export(String) var debug_path = null
|
||||
var debug_file_index : int = 0
|
||||
|
||||
var rendering : bool = false
|
||||
signal done
|
||||
|
||||
func _ready():
|
||||
$ColorRect.material = $ColorRect.material.duplicate(true)
|
||||
@ -70,9 +71,8 @@ func setup_material(shader_material, textures, shader_code):
|
||||
shader_material.shader.code = shader_code
|
||||
|
||||
func render_shader(shader, textures, render_size):
|
||||
if rendering:
|
||||
print("Already rendering...")
|
||||
return false
|
||||
while rendering:
|
||||
yield(self, "done")
|
||||
rendering = true
|
||||
if debug_path != null and debug_path != "":
|
||||
var f = File.new()
|
||||
@ -91,6 +91,7 @@ func render_shader(shader, textures, render_size):
|
||||
render_target_update_mode = Viewport.UPDATE_ONCE
|
||||
update_worlds()
|
||||
yield(get_tree(), "idle_frame")
|
||||
yield(get_tree(), "idle_frame")
|
||||
#yield(get_tree(), "idle_frame")
|
||||
rendering = false
|
||||
return true
|
||||
return true
|
||||
emit_signal("done")
|
||||
|
@ -23,7 +23,6 @@ render_target_v_flip = true
|
||||
render_target_update_mode = 1
|
||||
gui_disable_input = true
|
||||
script = ExtResource( 1 )
|
||||
debug_path = null
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
material = SubResource( 2 )
|
||||
|
@ -96,6 +96,7 @@ tab_align = 0
|
||||
tab_close_display_policy = 1
|
||||
|
||||
[node name="Renderer" parent="." instance=ExtResource( 5 )]
|
||||
debug_path = ""
|
||||
|
||||
[node name="NodeFactory" type="Node" parent="."]
|
||||
script = ExtResource( 6 )
|
||||
|
@ -1,14 +1,16 @@
|
||||
tool
|
||||
extends GraphNode
|
||||
class_name MMGraphNodeGeneric
|
||||
|
||||
var generator = null setget set_generator
|
||||
|
||||
var controls = {}
|
||||
var ignore_parameter_change = false
|
||||
|
||||
func set_generator(g):
|
||||
generator = g
|
||||
generator.connect("parameter_changed", self, "on_parameter_changed")
|
||||
update_node()
|
||||
call_deferred("update_node")
|
||||
|
||||
func on_close_request():
|
||||
generator.get_parent().remove_generator(generator)
|
||||
@ -17,6 +19,8 @@ func on_offset_changed():
|
||||
generator.position = offset
|
||||
|
||||
func on_parameter_changed(p, v):
|
||||
if ignore_parameter_change:
|
||||
return
|
||||
var o = controls[p]
|
||||
if o is LineEdit:
|
||||
o.text = str(v)
|
||||
@ -36,6 +40,7 @@ func on_parameter_changed(p, v):
|
||||
o.value = gradient
|
||||
else:
|
||||
print("unsupported widget "+str(o))
|
||||
update_shaders()
|
||||
|
||||
func initialize_properties():
|
||||
var parameter_names = []
|
||||
@ -67,21 +72,64 @@ func update_shaders():
|
||||
get_parent().send_changed_signal()
|
||||
|
||||
func _on_text_changed(new_text, variable):
|
||||
ignore_parameter_change = true
|
||||
generator.set_parameter(variable, float(new_text))
|
||||
ignore_parameter_change = false
|
||||
update_shaders()
|
||||
|
||||
func _on_value_changed(new_value, variable):
|
||||
ignore_parameter_change = true
|
||||
generator.set_parameter(variable, new_value)
|
||||
ignore_parameter_change = false
|
||||
update_shaders()
|
||||
|
||||
func _on_color_changed(new_color, variable):
|
||||
ignore_parameter_change = true
|
||||
generator.set_parameter(variable, new_color)
|
||||
ignore_parameter_change = false
|
||||
update_shaders()
|
||||
|
||||
func _on_gradient_changed(new_gradient, variable):
|
||||
ignore_parameter_change = true
|
||||
generator.set_parameter(variable, new_gradient)
|
||||
ignore_parameter_change = false
|
||||
update_shaders()
|
||||
|
||||
func create_parameter_control(p : Dictionary):
|
||||
var control = null
|
||||
if p.type == "float":
|
||||
if p.has("widget") and p.widget == "spinbox":
|
||||
control = SpinBox.new()
|
||||
else:
|
||||
control = HSlider.new()
|
||||
control.min_value = p.min
|
||||
control.max_value = p.max
|
||||
control.step = 0.005 if !p.has("step") else p.step
|
||||
control.allow_greater = true
|
||||
control.allow_lesser = true
|
||||
if p.has("default"):
|
||||
control.value = p.default
|
||||
control.rect_min_size.x = 80
|
||||
elif p.type == "size":
|
||||
control = OptionButton.new()
|
||||
for i in range(p.first, p.last+1):
|
||||
var s = pow(2, i)
|
||||
control.add_item("%dx%d" % [ s, s ])
|
||||
control.selected = 0 if !p.has("default") else p.default-p.first
|
||||
elif p.type == "enum":
|
||||
control = OptionButton.new()
|
||||
for i in range(p.values.size()):
|
||||
var value = p.values[i]
|
||||
control.add_item(value.name)
|
||||
control.selected = 0 if !p.has("default") else p.default
|
||||
elif p.type == "boolean":
|
||||
control = CheckBox.new()
|
||||
elif p.type == "color":
|
||||
control = ColorPickerButton.new()
|
||||
elif p.type == "gradient":
|
||||
control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance()
|
||||
return control
|
||||
|
||||
func update_node():
|
||||
# Clean node
|
||||
var custom_node_buttons = null
|
||||
@ -133,38 +181,7 @@ func update_node():
|
||||
for p in generator.get_parameter_defs():
|
||||
if !p.has("name") or !p.has("type"):
|
||||
continue
|
||||
var control = null
|
||||
if p.type == "float":
|
||||
if p.has("widget") and p.widget == "spinbox":
|
||||
control = SpinBox.new()
|
||||
else:
|
||||
control = HSlider.new()
|
||||
control.min_value = p.min
|
||||
control.max_value = p.max
|
||||
control.step = 0.005 if !p.has("step") else p.step
|
||||
control.allow_greater = true
|
||||
control.allow_lesser = true
|
||||
if p.has("default"):
|
||||
control.value = p.default
|
||||
control.rect_min_size.x = 80
|
||||
elif p.type == "size":
|
||||
control = OptionButton.new()
|
||||
for i in range(p.first, p.last+1):
|
||||
var s = pow(2, i)
|
||||
control.add_item("%dx%d" % [ s, s ])
|
||||
control.selected = 0 if !p.has("default") else p.default-p.first
|
||||
elif p.type == "enum":
|
||||
control = OptionButton.new()
|
||||
for i in range(p.values.size()):
|
||||
var value = p.values[i]
|
||||
control.add_item(value.name)
|
||||
control.selected = 0 if !p.has("default") else p.default
|
||||
elif p.type == "boolean":
|
||||
control = CheckBox.new()
|
||||
elif p.type == "color":
|
||||
control = ColorPickerButton.new()
|
||||
elif p.type == "gradient":
|
||||
control = preload("res://addons/material_maker/widgets/gradient_editor.tscn").instance()
|
||||
var control = create_parameter_control(p)
|
||||
if control != null:
|
||||
var label = p.name
|
||||
control.name = label
|
||||
|
@ -1,43 +1,56 @@
|
||||
tool
|
||||
extends "res://addons/material_maker/node_base.gd"
|
||||
extends MMGraphNodeGeneric
|
||||
class_name MMGraphNodeRemote
|
||||
|
||||
const LinkedControl = preload("res://addons/material_maker/widgets/linked_widgets/linked_control.tscn")
|
||||
const ConfigControl = preload("res://addons/material_maker/widgets/linked_widgets/config_control.tscn")
|
||||
|
||||
var generator = null setget set_generator
|
||||
|
||||
func set_generator(g):
|
||||
generator = g
|
||||
call_deferred("update_node")
|
||||
|
||||
func add_control(text, control):
|
||||
var index = $Controls.get_child_count() / 4
|
||||
var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance()
|
||||
label.set_text(text)
|
||||
$Controls.add_child(label)
|
||||
$Controls.add_child(control)
|
||||
var button = Button.new()
|
||||
button.icon = preload("res://addons/material_maker/icons/link.png")
|
||||
$Controls.add_child(button)
|
||||
button.connect("pressed", self, "_on_Link_pressed", [ index ])
|
||||
button = Button.new()
|
||||
button.icon = preload("res://addons/material_maker/icons/remove.png")
|
||||
$Controls.add_child(button)
|
||||
button.connect("pressed", generator, "remove_parameter", [ index ])
|
||||
|
||||
func update_node():
|
||||
for w in generator.widgets:
|
||||
var widget
|
||||
if w.type == "linked_control":
|
||||
widget = LinkedControl.instance()
|
||||
elif w.type == "config_control":
|
||||
widget = ConfigControl.instance()
|
||||
else:
|
||||
continue
|
||||
add_control(widget)
|
||||
widget.deserialize(w)
|
||||
|
||||
func add_control(widget):
|
||||
var controls = widget.get_associated_controls()
|
||||
$Controls.add_child(controls.label)
|
||||
$Controls.add_child(widget)
|
||||
$Controls.add_child(controls.buttons)
|
||||
var i : int = 0
|
||||
for c in $Controls.get_children():
|
||||
c.queue_free()
|
||||
yield(get_tree(), "idle_frame")
|
||||
controls = {}
|
||||
for p in generator.get_parameter_defs():
|
||||
var control = create_parameter_control(p)
|
||||
if control != null:
|
||||
control.name = p.name
|
||||
controls[control.name] = control
|
||||
add_control(generator.widgets[i].label, control)
|
||||
i += 1
|
||||
rect_size = Vector2(0, 0)
|
||||
initialize_properties()
|
||||
|
||||
func _on_AddLink_pressed():
|
||||
var widget = LinkedControl.instance()
|
||||
add_control(widget)
|
||||
widget.pick_linked()
|
||||
var widget = Control.new()
|
||||
add_control("Unnamed", widget)
|
||||
var link = MMNodeLink.new(get_parent())
|
||||
link.pick(widget, generator, generator.create_linked_control("Unnamed"), true)
|
||||
|
||||
func _on_AddConfig_pressed():
|
||||
var widget = ConfigControl.instance()
|
||||
add_control(widget)
|
||||
widget.pick_linked()
|
||||
var widget = Control.new()
|
||||
add_control("Unnamed", widget)
|
||||
var link = MMNodeLink.new(get_parent())
|
||||
link.pick(widget, generator, generator.create_config_control("Unnamed"), true)
|
||||
|
||||
func _on_Link_pressed(index):
|
||||
var link = MMNodeLink.new(get_parent())
|
||||
link.pick($Controls.get_child(index*4+1), generator, index)
|
||||
|
||||
func _on_Remote_resize_request(new_minsize):
|
||||
print("_on_Remote_resize_request")
|
||||
@ -46,9 +59,8 @@ func _on_Remote_resize_request(new_minsize):
|
||||
func _on_HBoxContainer_minimum_size_changed():
|
||||
print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size))
|
||||
|
||||
func serialize():
|
||||
var widgets = []
|
||||
for i in range(1, $Controls.get_child_count(), 3):
|
||||
widgets.append($Controls.get_child(i).serialize())
|
||||
var data = { type="remote", node_position={x=offset.x,y=offset.y}, editable=true, widgets=widgets }
|
||||
return data
|
||||
func on_parameter_changed(p, v):
|
||||
if p == "":
|
||||
update_node()
|
||||
else:
|
||||
.on_parameter_changed(p, v)
|
@ -1,14 +1,14 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/nodes/remote.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2]
|
||||
[ext_resource path="res://addons/material_maker/icons/config.png" type="Texture" id=3]
|
||||
[ext_resource path="res://addons/material_maker/icons/add_link.png" type="Texture" id=2]
|
||||
[ext_resource path="res://addons/material_maker/icons/add_config.png" type="Texture" id=3]
|
||||
|
||||
[sub_resource type="Theme" id=1]
|
||||
|
||||
[node name="Remote" type="GraphNode"]
|
||||
margin_right = 95.0
|
||||
margin_bottom = 55.0
|
||||
margin_bottom = 52.0
|
||||
mouse_filter = 1
|
||||
theme = SubResource( 1 )
|
||||
title = "Remote"
|
||||
@ -32,7 +32,7 @@ margin_left = 16.0
|
||||
margin_top = 24.0
|
||||
margin_right = 79.0
|
||||
margin_bottom = 24.0
|
||||
columns = 3
|
||||
columns = 4
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
margin_left = 16.0
|
||||
|
@ -48,15 +48,8 @@ func duplicate_value(value):
|
||||
value = value.duplicate()
|
||||
return value
|
||||
|
||||
func apply_configuration(c):
|
||||
for w in configurations[c]:
|
||||
var value = duplicate_value(w.value)
|
||||
w.widget.set(WIDGETS[get_widget_type(w.widget)].value_attr, value)
|
||||
w.node.generator.set_parameter(w.widget.name, value)
|
||||
var graph_node = get_parent()
|
||||
while !(graph_node is GraphNode):
|
||||
graph_node = graph_node.get_parent()
|
||||
graph_node.update_shaders()
|
||||
func apply_configuration(i):
|
||||
get_parent().get_parent().generator.set_parameter("param"+str(get_index()%4-1), i)
|
||||
|
||||
func do_update_configuration(name):
|
||||
var configuration = []
|
||||
@ -78,7 +71,7 @@ func _on_item_selected(ID):
|
||||
if ID >= 0 && ID < count:
|
||||
current = button.get_item_text(ID)
|
||||
update_options()
|
||||
apply_configuration(current)
|
||||
apply_configuration(ID)
|
||||
elif ID == count+1:
|
||||
button.selected = 0
|
||||
update_configuration()
|
||||
@ -116,10 +109,9 @@ func deserialize(data):
|
||||
var configuration = []
|
||||
for e in c:
|
||||
var node = graph_edit.get_node("node_"+e.node)
|
||||
print(e.widget)
|
||||
var widget = null
|
||||
for w in node.controls:
|
||||
if w.name == e.widget:
|
||||
if w == e.widget:
|
||||
widget = w
|
||||
break
|
||||
configuration.append({ node=node, widget=widget, value=Types.deserialize_value(e.value) })
|
||||
|
@ -1,33 +1,84 @@
|
||||
tool
|
||||
extends Control
|
||||
class_name MMNodeLink
|
||||
|
||||
var clip_pos = Vector2(0, 0)
|
||||
var clip_size = Vector2(0, 0)
|
||||
var end
|
||||
var source = null
|
||||
var target = null
|
||||
|
||||
func _ready():
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
var generator = null
|
||||
var param_index = 0
|
||||
var creating = false
|
||||
|
||||
func clip(p, s):
|
||||
clip_pos = p
|
||||
rect_global_position = Vector2(0, 0)
|
||||
rect_size = s
|
||||
func _init(parent):
|
||||
size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
size_flags_vertical = SIZE_EXPAND_FILL
|
||||
rect_size = parent.rect_size
|
||||
rect_clip_content = true
|
||||
parent.add_child(self)
|
||||
|
||||
func pick(s, g, i, c = false):
|
||||
source = s
|
||||
end = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size))
|
||||
generator = g
|
||||
param_index = i
|
||||
creating = c
|
||||
set_process_input(true)
|
||||
|
||||
func show_link(s, t):
|
||||
set_process_input(false)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
source = s
|
||||
target = t
|
||||
update()
|
||||
|
||||
func closest(rect, point):
|
||||
return Vector2(max(rect.position.x, min(rect.end.x, point.x)), max(rect.position.y, min(rect.end.y, point.y)))
|
||||
|
||||
func find_control(gp):
|
||||
for c in get_parent().get_children():
|
||||
if c is GraphNode:
|
||||
if c.get("controls") != null:
|
||||
for w in c.controls:
|
||||
var widget = c.controls[w]
|
||||
if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp):
|
||||
return { node=c, widget=widget }
|
||||
return null
|
||||
|
||||
func _draw():
|
||||
var start = source.rect_global_position+0.5*source.rect_size*source.get_global_transform().get_scale()
|
||||
draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2))
|
||||
draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false)
|
||||
var start = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size))
|
||||
var color = Color(1, 0.5, 0.5, 0.5)
|
||||
var rect
|
||||
if target != null:
|
||||
color = Color(0.5, 1, 0.5, 0.5)
|
||||
rect = Rect2(target.rect_global_position, target.rect_size*target.get_global_transform().get_scale())
|
||||
draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false)
|
||||
rect = get_global_transform().xform_inv(target.get_global_transform().xform(Rect2(Vector2(0, 0), target.rect_size)))
|
||||
draw_rect(rect, color, false)
|
||||
end = closest(rect, start)
|
||||
rect = Rect2(source.rect_global_position, source.rect_size*source.get_global_transform().get_scale())
|
||||
draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false)
|
||||
rect = get_global_transform().xform_inv(source.get_global_transform().xform(Rect2(Vector2(0, 0), source.rect_size)))
|
||||
draw_rect(rect, color, false)
|
||||
start = closest(rect, end)
|
||||
draw_line(start-clip_pos, end-clip_pos, color, 1, true)
|
||||
draw_line(start, end, color, 1, true)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey:
|
||||
if event.scancode == KEY_ESCAPE:
|
||||
set_process_input(false)
|
||||
queue_free()
|
||||
elif event is InputEventMouseMotion:
|
||||
var control = find_control(event.global_position)
|
||||
end = get_global_transform().xform_inv(event.global_position)
|
||||
target = control.widget if control != null and generator.can_link_parameter(param_index, control.node.generator, control.widget.name) else null
|
||||
update()
|
||||
elif event is InputEventMouseButton:
|
||||
if event.pressed:
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
var control = find_control(event.global_position)
|
||||
if control != null:
|
||||
generator.link_parameter(param_index, control.node.generator, control.widget.name)
|
||||
elif creating:
|
||||
generator.remove_parameter(param_index)
|
||||
set_process_input(false)
|
||||
queue_free()
|
||||
get_tree().set_input_as_handled()
|
||||
|
@ -77,19 +77,28 @@ func _on_value_changed(v):
|
||||
func _on_color_changed(c):
|
||||
for l in linked_widgets:
|
||||
l.widget.color = c
|
||||
l.node.parameters[l.widget.name] = c
|
||||
var parent = l.widget.get_parent()
|
||||
while !(parent is GraphNode):
|
||||
parent = parent.get_parent()
|
||||
parent.generator.set_parameter(l.widget.name, c)
|
||||
update_shaders()
|
||||
|
||||
func _on_item_selected(i):
|
||||
for l in linked_widgets:
|
||||
l.widget.selected = i
|
||||
l.node.parameters[l.widget.name] = i
|
||||
var parent = l.widget.get_parent()
|
||||
while !(parent is GraphNode):
|
||||
parent = parent.get_parent()
|
||||
parent.generator.set_parameter(l.widget.name, i)
|
||||
update_shaders()
|
||||
|
||||
func _on_gradient_updated(g):
|
||||
for l in linked_widgets:
|
||||
l.widget.value = g
|
||||
l.node.parameters[l.widget.name] = g
|
||||
var parent = l.widget.get_parent()
|
||||
while !(parent is GraphNode):
|
||||
parent = parent.get_parent()
|
||||
parent.generator.set_parameter(l.widget.name, g)
|
||||
update_shaders()
|
||||
|
||||
func serialize():
|
||||
|
@ -61,11 +61,9 @@ func _on_mouse_entered():
|
||||
links = []
|
||||
var viewport = get_viewport()
|
||||
for w in linked_widgets:
|
||||
var link = Link.new()
|
||||
link.clip(graph_edit.rect_global_position, graph_edit.rect_size)
|
||||
var link = Link.new(graph_edit)
|
||||
link.source = self
|
||||
link.target = w.widget
|
||||
graph_edit.add_child(link)
|
||||
links.append(link)
|
||||
|
||||
func _on_mouse_exited():
|
||||
@ -90,8 +88,9 @@ func find_control(gp):
|
||||
if c is GraphNode:
|
||||
if c.get("controls") != null:
|
||||
for w in c.controls:
|
||||
if Rect2(w.rect_global_position, w.rect_size*w.get_global_transform().get_scale()).has_point(gp):
|
||||
return { node=c, widget=w }
|
||||
var widget = c.controls[w]
|
||||
if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp):
|
||||
return { node=c, widget=widget }
|
||||
return null
|
||||
|
||||
func _input(event):
|
||||
@ -123,11 +122,9 @@ func pick_linked():
|
||||
return
|
||||
# Create line that will be shown when looking for a target
|
||||
var viewport = get_viewport()
|
||||
link = Link.new()
|
||||
link.clip(graph_edit.rect_global_position, graph_edit.rect_size)
|
||||
link = Link.new(graph_edit)
|
||||
link.source = self
|
||||
link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale()
|
||||
graph_edit.add_child(link)
|
||||
set_process_input(true)
|
||||
pointed_control = null
|
||||
|
||||
|
@ -4,76 +4,22 @@
|
||||
[ext_resource path="res://addons/material_maker/icons/link.png" type="Texture" id=2]
|
||||
[ext_resource path="res://addons/material_maker/icons/remove.png" type="Texture" id=3]
|
||||
|
||||
[node name="Buttons" type="HBoxContainer" index="0"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
[node name="Buttons" type="HBoxContainer"]
|
||||
margin_right = 60.0
|
||||
margin_bottom = 22.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
mouse_filter = 1
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 1
|
||||
alignment = 0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Link" type="Button" parent="." index="0"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
[node name="Link" type="Button" parent="."]
|
||||
margin_right = 28.0
|
||||
margin_bottom = 22.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
hint_tooltip = "Link new parameter"
|
||||
focus_mode = 2
|
||||
mouse_filter = 0
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 1
|
||||
toggle_mode = false
|
||||
enabled_focus_mode = 2
|
||||
shortcut = null
|
||||
group = null
|
||||
icon = ExtResource( 2 )
|
||||
flat = false
|
||||
align = 1
|
||||
_sections_unfolded = [ "Hint" ]
|
||||
|
||||
[node name="Remove" type="Button" parent="." index="1"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
[node name="Remove" type="Button" parent="."]
|
||||
margin_left = 32.0
|
||||
margin_right = 60.0
|
||||
margin_bottom = 22.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
hint_tooltip = "Delete this control"
|
||||
focus_mode = 2
|
||||
mouse_filter = 0
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 1
|
||||
toggle_mode = false
|
||||
enabled_focus_mode = 2
|
||||
shortcut = null
|
||||
group = null
|
||||
icon = ExtResource( 3 )
|
||||
flat = false
|
||||
align = 1
|
||||
_sections_unfolded = [ "Hint" ]
|
||||
|
||||
[connection signal="pressed" from="Link" to="." method="_on_Link_pressed"]
|
||||
|
||||
[connection signal="pressed" from="Remove" to="." method="_on_Remove_pressed"]
|
||||
|
||||
|
||||
|
@ -84,6 +84,21 @@ _global_script_classes=[ {
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/material_maker/types/gradient.gd"
|
||||
}, {
|
||||
"base": "GraphNode",
|
||||
"class": "MMGraphNodeGeneric",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/material_maker/nodes/generic.gd"
|
||||
}, {
|
||||
"base": "MMGraphNodeGeneric",
|
||||
"class": "MMGraphNodeRemote",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/material_maker/nodes/remote.gd"
|
||||
}, {
|
||||
"base": "Control",
|
||||
"class": "MMNodeLink",
|
||||
"language": "GDScript",
|
||||
"path": "res://addons/material_maker/widgets/linked_widgets/link.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "MMType",
|
||||
"language": "GDScript",
|
||||
@ -105,6 +120,9 @@ _global_script_class_icons={
|
||||
"MMGenSwitch": "",
|
||||
"MMGenTexture": "",
|
||||
"MMGradient": "",
|
||||
"MMGraphNodeGeneric": "",
|
||||
"MMGraphNodeRemote": "",
|
||||
"MMNodeLink": "",
|
||||
"MMType": ""
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user