Fixed connecting/disconnecting generators

This commit is contained in:
Rodolphe Suescun 2019-08-14 09:02:38 +02:00
parent 049250e073
commit a8dffae7cf
4 changed files with 31 additions and 21 deletions

View File

@ -10,5 +10,29 @@ func get_port_source(gen_name: String, input_index: int) -> OutputPort:
return OutputPort.new(get_node(c.from), c.from_port) return OutputPort.new(get_node(c.from), c.from_port)
return null return null
func connect_children(src, src_index : int, dst, dst_index : int): func connect_children(from, from_port : int, to, to_port : int):
pass # disconnect target
while true:
var remove = -1
for i in connections.size():
if connections[i].to == to.name and connections[i].to_port == to_port:
remove = i
break
if remove == -1:
break
connections.remove(remove)
# create new connection
connections.append({from=from.name, from_port=from_port, to=to.name, to_port=to_port})
return true
func disconnect_children(from, from_port : int, to, to_port : int):
while true:
var remove = -1
for i in connections.size():
if connections[i].from == from.name and connections[i].from_port == from_port and connections[i].to == to.name and connections[i].to_port == to_port:
remove = i
break
if remove == -1:
break
connections.remove(remove)
return true

View File

@ -47,22 +47,11 @@ func connect_node(from, from_slot, to, to_slot):
.disconnect_node(disconnect.node, disconnect.slot, to, to_slot) .disconnect_node(disconnect.node, disconnect.slot, to, to_slot)
.connect_node(from, from_slot, to, to_slot) .connect_node(from, from_slot, to, to_slot)
send_changed_signal() send_changed_signal()
var source_list = [ from ]
# Check if the new connection creates a cycle in the graph
while !source_list.empty():
var source = source_list.pop_front()
if source == to:
#print("cannot connect %s to %s (%s)" % [from, to, source])
return false
for c in get_connection_list():
if c.to == source and source_list.find(c.from) == -1:
source_list.append(c.from)
send_changed_signal()
return true
func disconnect_node(from, from_slot, to, to_slot): func disconnect_node(from, from_slot, to, to_slot):
.disconnect_node(from, from_slot, to, to_slot) if generator.disconnect_children(get_node(from).generator, from_slot, get_node(to).generator, to_slot):
send_changed_signal(); .disconnect_node(from, from_slot, to, to_slot)
send_changed_signal();
func remove_node(node): func remove_node(node):
var node_name = node.name var node_name = node.name

View File

@ -307,7 +307,6 @@ func update_preview_2d(node = null):
node = n node = n
break break
if node != null: if node != null:
print(node.name)
var source = node.generator.get_shader(0) var source = node.generator.get_shader(0)
if source != null: if source != null:
var shader : String = renderer.generate_shader(source) var shader : String = renderer.generate_shader(source)

View File

@ -1,8 +1,7 @@
[gd_scene load_steps=14 format=2] [gd_scene load_steps=13 format=2]
[ext_resource path="res://addons/material_maker/preview.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/preview.gd" type="Script" id=1]
[ext_resource path="res://addons/material_maker/panoramas/park.hdr" type="Texture" id=2] [ext_resource path="res://addons/material_maker/panoramas/park.hdr" type="Texture" id=2]
[ext_resource path="res://icon.png" type="Texture" id=3]
[sub_resource type="Animation" id=1] [sub_resource type="Animation" id=1]
loop = true loop = true
@ -100,7 +99,6 @@ void fragment() {
[sub_resource type="ShaderMaterial" id=10] [sub_resource type="ShaderMaterial" id=10]
shader = SubResource( 9 ) shader = SubResource( 9 )
shader_param/tex = ExtResource( 3 )
[node name="Preview" type="ViewportContainer"] [node name="Preview" type="ViewportContainer"]
anchor_left = 1.0 anchor_left = 1.0
@ -129,7 +127,7 @@ render_target_clear_mode = 1
render_target_update_mode = 3 render_target_update_mode = 3
[node name="Objects" type="Spatial" parent="MaterialPreview"] [node name="Objects" type="Spatial" parent="MaterialPreview"]
transform = Transform( -0.956327, 0, -0.292284, 0, 1, 0, 0.292284, 0, -0.956327, 0, 0, 0 ) transform = Transform( 0.979431, 0, -0.201756, 0, 1, 0, 0.201756, 0, 0.979431, 0, 0, 0 )
[node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects"] [node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects"]
mesh = SubResource( 2 ) mesh = SubResource( 2 )