Added switch node

Added node that can select between 2x2 inputs to generate 2 outputs
This commit is contained in:
RodZill4 2018-09-09 15:20:01 +02:00
parent 9dc6d4b18a
commit f116aa0e22
4 changed files with 294 additions and 5 deletions

View File

@ -198,6 +198,10 @@
"tree_item":"Miscellaneous/Export",
"type":"export"
},
{
"tree_item":"Miscellaneous/Switch",
"type":"switch"
},
{
"tree_item":"Miscellaneous/Remote",
"type":"remote"

View File

@ -0,0 +1,27 @@
tool
extends "res://addons/material_maker/node_base.gd"
var source = 0
func _ready():
initialize_properties([ $source ])
func reset():
generated = false
generated_variants = [ [], [] ]
func _get_shader_code(uv, index = 0):
var rv = { defs="", code="" }
var src = get_source(source+2*index)
var src_code = { defs="", code="", rgb="0.0" }
if src != null:
src_code = src.get_shader_code(uv)
if generated_variants[index].empty():
rv.defs = src_code.defs;
var variant_index = generated_variants[index].find(uv)
if variant_index == -1:
variant_index = generated_variants[index].size()
generated_variants[index].append(uv)
rv.code = src_code.code
rv.rgb = src_code.rgb
return rv

View File

@ -0,0 +1,249 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/material_maker/nodes/switch.gd" type="Script" id=1]
[sub_resource type="Theme" id=1]
[node name="Switch" type="GraphNode" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 1.0
margin_top = 1.0
margin_right = 87.0
margin_bottom = 89.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
theme = SubResource( 1 )
title = "Switch"
offset = Vector2( 0, 0 )
show_close = true
resizable = false
selected = false
comment = false
overlay = 0
slot/0/left_enabled = false
slot/0/left_type = 0
slot/0/left_color = Color( 0.498039, 0.498039, 1, 1 )
slot/0/right_enabled = false
slot/0/right_type = 0
slot/0/right_color = Color( 0.498039, 0.498039, 1, 1 )
slot/1/left_enabled = true
slot/1/left_type = 0
slot/1/left_color = Color( 0.498039, 0.498039, 1, 1 )
slot/1/right_enabled = true
slot/1/right_type = 0
slot/1/right_color = Color( 0.498039, 0.498039, 1, 1 )
slot/2/left_enabled = true
slot/2/left_type = 0
slot/2/left_color = Color( 0.498039, 0.498039, 1, 1 )
slot/2/right_enabled = false
slot/2/right_type = 0
slot/2/right_color = Color( 0.498039, 0.498039, 1, 1 )
slot/3/left_enabled = true
slot/3/left_type = 0
slot/3/left_color = Color( 0.498039, 0.498039, 1, 1 )
slot/3/right_enabled = true
slot/3/right_type = 0
slot/3/right_color = Color( 0.498039, 0.498039, 1, 1 )
slot/4/left_enabled = true
slot/4/left_type = 0
slot/4/left_color = Color( 0.498039, 0.498039, 1, 1 )
slot/4/right_enabled = false
slot/4/right_type = 0
slot/4/right_color = Color( 1, 0, 0, 1 )
script = ExtResource( 1 )
_sections_unfolded = [ "Theme", "slot", "slot/0", "slot/1", "slot/2", "slot/3", "slot/4" ]
[node name="source" type="OptionButton" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 24.0
margin_right = 103.0
margin_bottom = 44.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
action_mode = 0
enabled_focus_mode = 2
shortcut = null
group = null
text = "Objet 0"
flat = false
align = 0
items = [ "1", null, false, 0, null, "2", null, false, 1, null ]
selected = 0
[node name="HBoxContainer1" type="HBoxContainer" parent="." index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 44.0
margin_right = 103.0
margin_bottom = 58.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
[node name="Label1" type="Label" parent="HBoxContainer1" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 74.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "A1"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="Label2" type="Label" parent="HBoxContainer1" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 78.0
margin_right = 87.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 9
size_flags_vertical = 4
text = "A"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="Label2" type="Label" parent="." index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 59.0
margin_right = 103.0
margin_bottom = 73.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "A2"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="HBoxContainer2" type="HBoxContainer" parent="." index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 74.0
margin_right = 103.0
margin_bottom = 88.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
[node name="Label1" type="Label" parent="HBoxContainer2" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 74.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 4
text = "B1"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="Label2" type="Label" parent="HBoxContainer2" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 78.0
margin_right = 87.0
margin_bottom = 14.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 9
size_flags_vertical = 4
text = "B"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="Label4" type="Label" parent="." index="4"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 89.0
margin_right = 103.0
margin_bottom = 103.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "B2"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1

View File

@ -34,25 +34,34 @@ func mirror(to, from, type):
for a in WIDGETS[type].attrs:
to.set(a, from.get(a))
func update_shaders():
var graph_edit = get_parent()
while !(graph_edit is GraphEdit):
graph_edit = graph_edit.get_parent()
graph_edit.send_changed_signal()
func _on_value_changed(v):
for l in linked_widgets:
l.widget.value = v
l.node.set(l.widget.name, v)
update_shaders()
func _on_color_changed(c):
for l in linked_widgets:
l.widget.color = c
l.node.set(l.widget.name, c)
update_shaders()
func _on_item_selected(i):
for l in linked_widgets:
l.widget.selected = i
l.node.set(l.widget.name, i)
update_shaders()
func _on_gradient_updated(i):
func _on_gradient_updated(g):
for l in linked_widgets:
l.widget.value = i
l.node.set(l.widget.name, i)
l.widget.value = g
update_shaders()
func serialize():
var data = .serialize()