From 470e55b2126b198c440c0d3ea26a1ad0570a88f5 Mon Sep 17 00:00:00 2001 From: Rodolphe Suescun Date: Wed, 14 Aug 2019 15:55:39 +0200 Subject: [PATCH] Added nodes removal & new node creation --- addons/material_maker/graph_edit.gd | 30 ++++++++++++++++++++++----- addons/material_maker/graph_edit.tscn | 13 +----------- addons/material_maker/main_window.gd | 4 ++++ addons/material_maker/new.ptex | 2 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index ab5d07c..ab70da9 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -54,12 +54,13 @@ func disconnect_node(from, from_slot, to, to_slot): send_changed_signal(); func remove_node(node): + generator.remove_node(node.generator) var node_name = node.name for c in get_connection_list(): if c.from == node_name or c.to == node_name: disconnect_node(c.from, c.from_port, c.to, c.to_port) - send_changed_signal() node.queue_free() + send_changed_signal() # Global operations on graph @@ -91,13 +92,33 @@ func clear_material(): if c is GraphNode: remove_child(c) c.free() + if generator != null: + remove_child(generator) + generator.free() + generator = null send_changed_signal() func new_material(): + print("New material") clear_material() - create_nodes({name="Material", type="material"}) - set_save_path(null) - center_view() + var loader = MMGenLoader.new() + generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) + if generator != null: + print("Not null !") + add_child(generator) + for g in generator.get_children(): + var node = node_factory.create_node(g.get_type()) + if node != null: + node.name = "node_"+g.name + add_node(node) + node.generator = g + node.offset = g.position + if generator.get("connections") != null: + for c in generator.connections: + .connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port) + set_save_path(filename) + set_need_save(false) + center_view() func get_free_name(type): var i = 0 @@ -142,7 +163,6 @@ func load_file(filename): if generator != null: add_child(generator) for g in generator.get_children(): - print(g.get_type()) var node = node_factory.create_node(g.get_type()) if node != null: node.name = "node_"+g.name diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index f00404f..04a242f 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -1,9 +1,6 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://addons/material_maker/graph_edit.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/nodes/material.tscn" type="PackedScene" id=2] - -[sub_resource type="Theme" id=1] [node name="GraphEdit" type="GraphEdit"] self_modulate = Color( 1, 1, 1, 0 ) @@ -14,14 +11,6 @@ scroll_offset = Vector2( -325, -250 ) use_snap = false script = ExtResource( 1 ) -[node name="Material" parent="." instance=ExtResource( 2 )] -margin_left = 525.0 -margin_top = 250.0 -margin_right = 755.0 -margin_bottom = 470.0 -theme = SubResource( 1 ) -offset = Vector2( 200, 0 ) - [node name="Timer" type="Timer" parent="."] wait_time = 0.2 one_shot = true diff --git a/addons/material_maker/main_window.gd b/addons/material_maker/main_window.gd index 8e9516d..ffda4e7 100644 --- a/addons/material_maker/main_window.gd +++ b/addons/material_maker/main_window.gd @@ -133,6 +133,7 @@ func new_pane(): func new_material(): var graph_edit = new_pane() + graph_edit.new_material() graph_edit.update_tab_title() func load_material(): @@ -153,11 +154,14 @@ func do_load_material(filename): var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control() var node_count = 2 # So test below succeeds if graph_edit is null... if graph_edit != null: + node_count = 0 for c in graph_edit.get_children(): if c is GraphNode: + print(c.name) node_count += 1 if node_count > 1: break + print(node_count) if node_count > 1: graph_edit = new_pane() graph_edit.load_file(filename) diff --git a/addons/material_maker/new.ptex b/addons/material_maker/new.ptex index 4d41f06..df087f9 100644 --- a/addons/material_maker/new.ptex +++ b/addons/material_maker/new.ptex @@ -1 +1 @@ -{"connections":[],"nodes":[{"name":"Material","node_position":{"x":307,"y":-53},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"}]} \ No newline at end of file +{"connections":[],"nodes":[{"name":"Material","node_position":{"x":300,"y":0},"parameters":{"albedo_color":{"a":1,"b":1,"g":1,"r":1,"type":"Color"},"ao_light_affect":1,"depth_scale":1,"emission_energy":1,"metallic":1,"normal_scale":1,"resolution":1,"roughness":1},"type":"material"}]} \ No newline at end of file