mirror of
https://github.com/Relintai/material-maker.git
synced 2025-01-09 05:39:38 +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=2, texture="roughness" },
|
||||||
{ port=3, texture="emission" },
|
{ port=3, texture="emission" },
|
||||||
{ port=4, texture="normal_texture" },
|
{ port=4, texture="normal_texture" },
|
||||||
{ port=5, texture="ambient_occlusion" },
|
{ port=5, texture="ao_texture" },
|
||||||
{ port=6, texture="depth_texture" }
|
{ port=6, texture="depth_texture" }
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -34,9 +34,12 @@ func get_type_name():
|
|||||||
func get_parameter_defs():
|
func get_parameter_defs():
|
||||||
return [
|
return [
|
||||||
{ name="albedo_color", label="Albedo", type="color", default={ r=1.0, g=1.0, b=1.0, a=1.0} },
|
{ 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="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, 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, 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():
|
func get_input_defs():
|
||||||
@ -46,6 +49,7 @@ func get_input_defs():
|
|||||||
{ name="roughness_texture", label="", type="f" },
|
{ name="roughness_texture", label="", type="f" },
|
||||||
{ name="emission_texture", label="", type="rgb" },
|
{ name="emission_texture", label="", type="rgb" },
|
||||||
{ name="normal_texture", label="", type="rgb" },
|
{ name="normal_texture", label="", type="rgb" },
|
||||||
|
{ name="ao_texture", label="", type="f" },
|
||||||
{ name="depth_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 Engine.editor_hint:
|
||||||
if (generated_textures.mrao.mask & (1 << 2)) != 0:
|
if (generated_textures.mrao.mask & (1 << 2)) != 0:
|
||||||
m.ao_enabled = true
|
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 = m.metallic_texture
|
||||||
m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE
|
m.ao_texture_channel = SpatialMaterial.TEXTURE_CHANNEL_BLUE
|
||||||
else:
|
else:
|
||||||
m.ao_enabled = false
|
m.ao_enabled = false
|
||||||
else:
|
else:
|
||||||
texture = get_generated_texture("ambient_occlusion", file_prefix)
|
texture = get_generated_texture("ao_texture", file_prefix)
|
||||||
if texture != null:
|
if texture != null:
|
||||||
m.ao_enabled = true
|
m.ao_enabled = true
|
||||||
#m.ao_light_affect = parameters.ao_light_affect
|
m.ao_light_affect = parameters.ao_light_affect
|
||||||
m.ao_texture = texture
|
m.ao_texture = texture
|
||||||
else:
|
else:
|
||||||
m.ao_enabled = false
|
m.ao_enabled = false
|
||||||
texture = get_generated_texture("depth_texture", file_prefix)
|
texture = get_generated_texture("depth_texture", file_prefix)
|
||||||
if texture != null:
|
if texture != null:
|
||||||
m.depth_enabled = true
|
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
|
m.depth_texture = texture
|
||||||
else:
|
else:
|
||||||
m.depth_enabled = false
|
m.depth_enabled = false
|
||||||
|
@ -18,7 +18,7 @@ func set_widgets(w):
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
func get_type():
|
func get_type():
|
||||||
return "remot"
|
return "remote"
|
||||||
|
|
||||||
func get_type_name():
|
func get_type_name():
|
||||||
return "Remote"
|
return "Remote"
|
||||||
@ -68,3 +68,30 @@ func _serialize(data):
|
|||||||
data.type = "remote"
|
data.type = "remote"
|
||||||
data.widgets = widgets
|
data.widgets = widgets
|
||||||
return data
|
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
|
return rv
|
||||||
|
|
||||||
func source_changed(input_index : int):
|
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):
|
func _get_shader_code(uv : String, output_index : int, context : MMGenContext):
|
||||||
var source = get_source(output_index+parameters.source*parameters.outputs)
|
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 debug_file_index : int = 0
|
||||||
|
|
||||||
var rendering : bool = false
|
var rendering : bool = false
|
||||||
|
signal done
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
$ColorRect.material = $ColorRect.material.duplicate(true)
|
$ColorRect.material = $ColorRect.material.duplicate(true)
|
||||||
@ -70,9 +71,8 @@ func setup_material(shader_material, textures, shader_code):
|
|||||||
shader_material.shader.code = shader_code
|
shader_material.shader.code = shader_code
|
||||||
|
|
||||||
func render_shader(shader, textures, render_size):
|
func render_shader(shader, textures, render_size):
|
||||||
if rendering:
|
while rendering:
|
||||||
print("Already rendering...")
|
yield(self, "done")
|
||||||
return false
|
|
||||||
rendering = true
|
rendering = true
|
||||||
if debug_path != null and debug_path != "":
|
if debug_path != null and debug_path != "":
|
||||||
var f = File.new()
|
var f = File.new()
|
||||||
@ -91,6 +91,7 @@ func render_shader(shader, textures, render_size):
|
|||||||
render_target_update_mode = Viewport.UPDATE_ONCE
|
render_target_update_mode = Viewport.UPDATE_ONCE
|
||||||
update_worlds()
|
update_worlds()
|
||||||
yield(get_tree(), "idle_frame")
|
yield(get_tree(), "idle_frame")
|
||||||
yield(get_tree(), "idle_frame")
|
#yield(get_tree(), "idle_frame")
|
||||||
rendering = false
|
rendering = false
|
||||||
return true
|
return true
|
||||||
|
emit_signal("done")
|
||||||
|
@ -23,7 +23,6 @@ render_target_v_flip = true
|
|||||||
render_target_update_mode = 1
|
render_target_update_mode = 1
|
||||||
gui_disable_input = true
|
gui_disable_input = true
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
debug_path = null
|
|
||||||
|
|
||||||
[node name="ColorRect" type="ColorRect" parent="."]
|
[node name="ColorRect" type="ColorRect" parent="."]
|
||||||
material = SubResource( 2 )
|
material = SubResource( 2 )
|
||||||
|
@ -96,6 +96,7 @@ tab_align = 0
|
|||||||
tab_close_display_policy = 1
|
tab_close_display_policy = 1
|
||||||
|
|
||||||
[node name="Renderer" parent="." instance=ExtResource( 5 )]
|
[node name="Renderer" parent="." instance=ExtResource( 5 )]
|
||||||
|
debug_path = ""
|
||||||
|
|
||||||
[node name="NodeFactory" type="Node" parent="."]
|
[node name="NodeFactory" type="Node" parent="."]
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
tool
|
tool
|
||||||
extends GraphNode
|
extends GraphNode
|
||||||
|
class_name MMGraphNodeGeneric
|
||||||
|
|
||||||
var generator = null setget set_generator
|
var generator = null setget set_generator
|
||||||
|
|
||||||
var controls = {}
|
var controls = {}
|
||||||
|
var ignore_parameter_change = false
|
||||||
|
|
||||||
func set_generator(g):
|
func set_generator(g):
|
||||||
generator = g
|
generator = g
|
||||||
generator.connect("parameter_changed", self, "on_parameter_changed")
|
generator.connect("parameter_changed", self, "on_parameter_changed")
|
||||||
update_node()
|
call_deferred("update_node")
|
||||||
|
|
||||||
func on_close_request():
|
func on_close_request():
|
||||||
generator.get_parent().remove_generator(generator)
|
generator.get_parent().remove_generator(generator)
|
||||||
@ -17,6 +19,8 @@ func on_offset_changed():
|
|||||||
generator.position = offset
|
generator.position = offset
|
||||||
|
|
||||||
func on_parameter_changed(p, v):
|
func on_parameter_changed(p, v):
|
||||||
|
if ignore_parameter_change:
|
||||||
|
return
|
||||||
var o = controls[p]
|
var o = controls[p]
|
||||||
if o is LineEdit:
|
if o is LineEdit:
|
||||||
o.text = str(v)
|
o.text = str(v)
|
||||||
@ -36,6 +40,7 @@ func on_parameter_changed(p, v):
|
|||||||
o.value = gradient
|
o.value = gradient
|
||||||
else:
|
else:
|
||||||
print("unsupported widget "+str(o))
|
print("unsupported widget "+str(o))
|
||||||
|
update_shaders()
|
||||||
|
|
||||||
func initialize_properties():
|
func initialize_properties():
|
||||||
var parameter_names = []
|
var parameter_names = []
|
||||||
@ -67,21 +72,64 @@ func update_shaders():
|
|||||||
get_parent().send_changed_signal()
|
get_parent().send_changed_signal()
|
||||||
|
|
||||||
func _on_text_changed(new_text, variable):
|
func _on_text_changed(new_text, variable):
|
||||||
|
ignore_parameter_change = true
|
||||||
generator.set_parameter(variable, float(new_text))
|
generator.set_parameter(variable, float(new_text))
|
||||||
|
ignore_parameter_change = false
|
||||||
update_shaders()
|
update_shaders()
|
||||||
|
|
||||||
func _on_value_changed(new_value, variable):
|
func _on_value_changed(new_value, variable):
|
||||||
|
ignore_parameter_change = true
|
||||||
generator.set_parameter(variable, new_value)
|
generator.set_parameter(variable, new_value)
|
||||||
|
ignore_parameter_change = false
|
||||||
update_shaders()
|
update_shaders()
|
||||||
|
|
||||||
func _on_color_changed(new_color, variable):
|
func _on_color_changed(new_color, variable):
|
||||||
|
ignore_parameter_change = true
|
||||||
generator.set_parameter(variable, new_color)
|
generator.set_parameter(variable, new_color)
|
||||||
|
ignore_parameter_change = false
|
||||||
update_shaders()
|
update_shaders()
|
||||||
|
|
||||||
func _on_gradient_changed(new_gradient, variable):
|
func _on_gradient_changed(new_gradient, variable):
|
||||||
|
ignore_parameter_change = true
|
||||||
generator.set_parameter(variable, new_gradient)
|
generator.set_parameter(variable, new_gradient)
|
||||||
|
ignore_parameter_change = false
|
||||||
update_shaders()
|
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():
|
func update_node():
|
||||||
# Clean node
|
# Clean node
|
||||||
var custom_node_buttons = null
|
var custom_node_buttons = null
|
||||||
@ -133,38 +181,7 @@ func update_node():
|
|||||||
for p in generator.get_parameter_defs():
|
for p in generator.get_parameter_defs():
|
||||||
if !p.has("name") or !p.has("type"):
|
if !p.has("name") or !p.has("type"):
|
||||||
continue
|
continue
|
||||||
var control = null
|
var control = create_parameter_control(p)
|
||||||
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()
|
|
||||||
if control != null:
|
if control != null:
|
||||||
var label = p.name
|
var label = p.name
|
||||||
control.name = label
|
control.name = label
|
||||||
|
@ -1,43 +1,56 @@
|
|||||||
tool
|
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 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")
|
const ConfigControl = preload("res://addons/material_maker/widgets/linked_widgets/config_control.tscn")
|
||||||
|
|
||||||
var generator = null setget set_generator
|
func add_control(text, control):
|
||||||
|
var index = $Controls.get_child_count() / 4
|
||||||
func set_generator(g):
|
var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance()
|
||||||
generator = g
|
label.set_text(text)
|
||||||
call_deferred("update_node")
|
$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():
|
func update_node():
|
||||||
for w in generator.widgets:
|
var i : int = 0
|
||||||
var widget
|
for c in $Controls.get_children():
|
||||||
if w.type == "linked_control":
|
c.queue_free()
|
||||||
widget = LinkedControl.instance()
|
yield(get_tree(), "idle_frame")
|
||||||
elif w.type == "config_control":
|
controls = {}
|
||||||
widget = ConfigControl.instance()
|
for p in generator.get_parameter_defs():
|
||||||
else:
|
var control = create_parameter_control(p)
|
||||||
continue
|
if control != null:
|
||||||
add_control(widget)
|
control.name = p.name
|
||||||
widget.deserialize(w)
|
controls[control.name] = control
|
||||||
|
add_control(generator.widgets[i].label, control)
|
||||||
func add_control(widget):
|
i += 1
|
||||||
var controls = widget.get_associated_controls()
|
rect_size = Vector2(0, 0)
|
||||||
$Controls.add_child(controls.label)
|
initialize_properties()
|
||||||
$Controls.add_child(widget)
|
|
||||||
$Controls.add_child(controls.buttons)
|
|
||||||
|
|
||||||
func _on_AddLink_pressed():
|
func _on_AddLink_pressed():
|
||||||
var widget = LinkedControl.instance()
|
var widget = Control.new()
|
||||||
add_control(widget)
|
add_control("Unnamed", widget)
|
||||||
widget.pick_linked()
|
var link = MMNodeLink.new(get_parent())
|
||||||
|
link.pick(widget, generator, generator.create_linked_control("Unnamed"), true)
|
||||||
|
|
||||||
func _on_AddConfig_pressed():
|
func _on_AddConfig_pressed():
|
||||||
var widget = ConfigControl.instance()
|
var widget = Control.new()
|
||||||
add_control(widget)
|
add_control("Unnamed", widget)
|
||||||
widget.pick_linked()
|
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):
|
func _on_Remote_resize_request(new_minsize):
|
||||||
print("_on_Remote_resize_request")
|
print("_on_Remote_resize_request")
|
||||||
@ -46,9 +59,8 @@ func _on_Remote_resize_request(new_minsize):
|
|||||||
func _on_HBoxContainer_minimum_size_changed():
|
func _on_HBoxContainer_minimum_size_changed():
|
||||||
print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size))
|
print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size))
|
||||||
|
|
||||||
func serialize():
|
func on_parameter_changed(p, v):
|
||||||
var widgets = []
|
if p == "":
|
||||||
for i in range(1, $Controls.get_child_count(), 3):
|
update_node()
|
||||||
widgets.append($Controls.get_child(i).serialize())
|
else:
|
||||||
var data = { type="remote", node_position={x=offset.x,y=offset.y}, editable=true, widgets=widgets }
|
.on_parameter_changed(p, v)
|
||||||
return data
|
|
@ -1,14 +1,14 @@
|
|||||||
[gd_scene load_steps=5 format=2]
|
[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/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/add_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_config.png" type="Texture" id=3]
|
||||||
|
|
||||||
[sub_resource type="Theme" id=1]
|
[sub_resource type="Theme" id=1]
|
||||||
|
|
||||||
[node name="Remote" type="GraphNode"]
|
[node name="Remote" type="GraphNode"]
|
||||||
margin_right = 95.0
|
margin_right = 95.0
|
||||||
margin_bottom = 55.0
|
margin_bottom = 52.0
|
||||||
mouse_filter = 1
|
mouse_filter = 1
|
||||||
theme = SubResource( 1 )
|
theme = SubResource( 1 )
|
||||||
title = "Remote"
|
title = "Remote"
|
||||||
@ -32,7 +32,7 @@ margin_left = 16.0
|
|||||||
margin_top = 24.0
|
margin_top = 24.0
|
||||||
margin_right = 79.0
|
margin_right = 79.0
|
||||||
margin_bottom = 24.0
|
margin_bottom = 24.0
|
||||||
columns = 3
|
columns = 4
|
||||||
|
|
||||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||||
margin_left = 16.0
|
margin_left = 16.0
|
||||||
|
@ -48,15 +48,8 @@ func duplicate_value(value):
|
|||||||
value = value.duplicate()
|
value = value.duplicate()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
func apply_configuration(c):
|
func apply_configuration(i):
|
||||||
for w in configurations[c]:
|
get_parent().get_parent().generator.set_parameter("param"+str(get_index()%4-1), i)
|
||||||
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 do_update_configuration(name):
|
func do_update_configuration(name):
|
||||||
var configuration = []
|
var configuration = []
|
||||||
@ -78,7 +71,7 @@ func _on_item_selected(ID):
|
|||||||
if ID >= 0 && ID < count:
|
if ID >= 0 && ID < count:
|
||||||
current = button.get_item_text(ID)
|
current = button.get_item_text(ID)
|
||||||
update_options()
|
update_options()
|
||||||
apply_configuration(current)
|
apply_configuration(ID)
|
||||||
elif ID == count+1:
|
elif ID == count+1:
|
||||||
button.selected = 0
|
button.selected = 0
|
||||||
update_configuration()
|
update_configuration()
|
||||||
@ -116,10 +109,9 @@ func deserialize(data):
|
|||||||
var configuration = []
|
var configuration = []
|
||||||
for e in c:
|
for e in c:
|
||||||
var node = graph_edit.get_node("node_"+e.node)
|
var node = graph_edit.get_node("node_"+e.node)
|
||||||
print(e.widget)
|
|
||||||
var widget = null
|
var widget = null
|
||||||
for w in node.controls:
|
for w in node.controls:
|
||||||
if w.name == e.widget:
|
if w == e.widget:
|
||||||
widget = w
|
widget = w
|
||||||
break
|
break
|
||||||
configuration.append({ node=node, widget=widget, value=Types.deserialize_value(e.value) })
|
configuration.append({ node=node, widget=widget, value=Types.deserialize_value(e.value) })
|
||||||
|
@ -1,33 +1,84 @@
|
|||||||
|
tool
|
||||||
extends Control
|
extends Control
|
||||||
|
class_name MMNodeLink
|
||||||
|
|
||||||
var clip_pos = Vector2(0, 0)
|
|
||||||
var clip_size = Vector2(0, 0)
|
|
||||||
var end
|
var end
|
||||||
var source = null
|
var source = null
|
||||||
var target = null
|
var target = null
|
||||||
|
|
||||||
func _ready():
|
var generator = null
|
||||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
var param_index = 0
|
||||||
|
var creating = false
|
||||||
|
|
||||||
func clip(p, s):
|
func _init(parent):
|
||||||
clip_pos = p
|
size_flags_horizontal = SIZE_EXPAND_FILL
|
||||||
rect_global_position = Vector2(0, 0)
|
size_flags_vertical = SIZE_EXPAND_FILL
|
||||||
rect_size = s
|
rect_size = parent.rect_size
|
||||||
rect_clip_content = true
|
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):
|
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)))
|
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():
|
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 color = Color(1, 0.5, 0.5, 0.5)
|
||||||
var rect
|
var rect
|
||||||
if target != null:
|
if target != null:
|
||||||
color = Color(0.5, 1, 0.5, 0.5)
|
color = Color(0.5, 1, 0.5, 0.5)
|
||||||
rect = Rect2(target.rect_global_position, target.rect_size*target.get_global_transform().get_scale())
|
rect = get_global_transform().xform_inv(target.get_global_transform().xform(Rect2(Vector2(0, 0), target.rect_size)))
|
||||||
draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false)
|
draw_rect(rect, color, false)
|
||||||
end = closest(rect, start)
|
end = closest(rect, start)
|
||||||
rect = Rect2(source.rect_global_position, source.rect_size*source.get_global_transform().get_scale())
|
rect = get_global_transform().xform_inv(source.get_global_transform().xform(Rect2(Vector2(0, 0), source.rect_size)))
|
||||||
draw_rect(Rect2(rect.position-clip_pos, rect.size), color, false)
|
draw_rect(rect, color, false)
|
||||||
start = closest(rect, end)
|
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):
|
func _on_color_changed(c):
|
||||||
for l in linked_widgets:
|
for l in linked_widgets:
|
||||||
l.widget.color = c
|
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()
|
update_shaders()
|
||||||
|
|
||||||
func _on_item_selected(i):
|
func _on_item_selected(i):
|
||||||
for l in linked_widgets:
|
for l in linked_widgets:
|
||||||
l.widget.selected = i
|
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()
|
update_shaders()
|
||||||
|
|
||||||
func _on_gradient_updated(g):
|
func _on_gradient_updated(g):
|
||||||
for l in linked_widgets:
|
for l in linked_widgets:
|
||||||
l.widget.value = g
|
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()
|
update_shaders()
|
||||||
|
|
||||||
func serialize():
|
func serialize():
|
||||||
|
@ -61,11 +61,9 @@ func _on_mouse_entered():
|
|||||||
links = []
|
links = []
|
||||||
var viewport = get_viewport()
|
var viewport = get_viewport()
|
||||||
for w in linked_widgets:
|
for w in linked_widgets:
|
||||||
var link = Link.new()
|
var link = Link.new(graph_edit)
|
||||||
link.clip(graph_edit.rect_global_position, graph_edit.rect_size)
|
|
||||||
link.source = self
|
link.source = self
|
||||||
link.target = w.widget
|
link.target = w.widget
|
||||||
graph_edit.add_child(link)
|
|
||||||
links.append(link)
|
links.append(link)
|
||||||
|
|
||||||
func _on_mouse_exited():
|
func _on_mouse_exited():
|
||||||
@ -90,8 +88,9 @@ func find_control(gp):
|
|||||||
if c is GraphNode:
|
if c is GraphNode:
|
||||||
if c.get("controls") != null:
|
if c.get("controls") != null:
|
||||||
for w in c.controls:
|
for w in c.controls:
|
||||||
if Rect2(w.rect_global_position, w.rect_size*w.get_global_transform().get_scale()).has_point(gp):
|
var widget = c.controls[w]
|
||||||
return { node=c, widget=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
|
return null
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
@ -123,11 +122,9 @@ func pick_linked():
|
|||||||
return
|
return
|
||||||
# Create line that will be shown when looking for a target
|
# Create line that will be shown when looking for a target
|
||||||
var viewport = get_viewport()
|
var viewport = get_viewport()
|
||||||
link = Link.new()
|
link = Link.new(graph_edit)
|
||||||
link.clip(graph_edit.rect_global_position, graph_edit.rect_size)
|
|
||||||
link.source = self
|
link.source = self
|
||||||
link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale()
|
link.end = rect_global_position+0.5*rect_size*get_global_transform().get_scale()
|
||||||
graph_edit.add_child(link)
|
|
||||||
set_process_input(true)
|
set_process_input(true)
|
||||||
pointed_control = null
|
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/link.png" type="Texture" id=2]
|
||||||
[ext_resource path="res://addons/material_maker/icons/remove.png" type="Texture" id=3]
|
[ext_resource path="res://addons/material_maker/icons/remove.png" type="Texture" id=3]
|
||||||
|
|
||||||
[node name="Buttons" type="HBoxContainer" index="0"]
|
[node name="Buttons" type="HBoxContainer"]
|
||||||
|
|
||||||
anchor_left = 0.0
|
|
||||||
anchor_top = 0.0
|
|
||||||
anchor_right = 0.0
|
|
||||||
anchor_bottom = 0.0
|
|
||||||
margin_right = 60.0
|
margin_right = 60.0
|
||||||
margin_bottom = 22.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 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Link" type="Button" parent="." index="0"]
|
[node name="Link" type="Button" parent="."]
|
||||||
|
|
||||||
anchor_left = 0.0
|
|
||||||
anchor_top = 0.0
|
|
||||||
anchor_right = 0.0
|
|
||||||
anchor_bottom = 0.0
|
|
||||||
margin_right = 28.0
|
margin_right = 28.0
|
||||||
margin_bottom = 22.0
|
margin_bottom = 22.0
|
||||||
rect_pivot_offset = Vector2( 0, 0 )
|
|
||||||
rect_clip_content = false
|
|
||||||
hint_tooltip = "Link new parameter"
|
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 )
|
icon = ExtResource( 2 )
|
||||||
flat = false
|
|
||||||
align = 1
|
|
||||||
_sections_unfolded = [ "Hint" ]
|
|
||||||
|
|
||||||
[node name="Remove" type="Button" parent="." index="1"]
|
[node name="Remove" type="Button" parent="."]
|
||||||
|
|
||||||
anchor_left = 0.0
|
|
||||||
anchor_top = 0.0
|
|
||||||
anchor_right = 0.0
|
|
||||||
anchor_bottom = 0.0
|
|
||||||
margin_left = 32.0
|
margin_left = 32.0
|
||||||
margin_right = 60.0
|
margin_right = 60.0
|
||||||
margin_bottom = 22.0
|
margin_bottom = 22.0
|
||||||
rect_pivot_offset = Vector2( 0, 0 )
|
|
||||||
rect_clip_content = false
|
|
||||||
hint_tooltip = "Delete this control"
|
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 )
|
icon = ExtResource( 3 )
|
||||||
flat = false
|
|
||||||
align = 1
|
|
||||||
_sections_unfolded = [ "Hint" ]
|
|
||||||
|
|
||||||
[connection signal="pressed" from="Link" to="." method="_on_Link_pressed"]
|
[connection signal="pressed" from="Link" to="." method="_on_Link_pressed"]
|
||||||
|
|
||||||
[connection signal="pressed" from="Remove" to="." method="_on_Remove_pressed"]
|
[connection signal="pressed" from="Remove" to="." method="_on_Remove_pressed"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,6 +84,21 @@ _global_script_classes=[ {
|
|||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://addons/material_maker/types/gradient.gd"
|
"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",
|
"base": "Node",
|
||||||
"class": "MMType",
|
"class": "MMType",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
@ -105,6 +120,9 @@ _global_script_class_icons={
|
|||||||
"MMGenSwitch": "",
|
"MMGenSwitch": "",
|
||||||
"MMGenTexture": "",
|
"MMGenTexture": "",
|
||||||
"MMGradient": "",
|
"MMGradient": "",
|
||||||
|
"MMGraphNodeGeneric": "",
|
||||||
|
"MMGraphNodeRemote": "",
|
||||||
|
"MMNodeLink": "",
|
||||||
"MMType": ""
|
"MMType": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user