mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Added nodes removal & new node creation
This commit is contained in:
parent
a8dffae7cf
commit
470e55b212
@ -54,12 +54,13 @@ func disconnect_node(from, from_slot, to, to_slot):
|
|||||||
send_changed_signal();
|
send_changed_signal();
|
||||||
|
|
||||||
func remove_node(node):
|
func remove_node(node):
|
||||||
|
generator.remove_node(node.generator)
|
||||||
var node_name = node.name
|
var node_name = node.name
|
||||||
for c in get_connection_list():
|
for c in get_connection_list():
|
||||||
if c.from == node_name or c.to == node_name:
|
if c.from == node_name or c.to == node_name:
|
||||||
disconnect_node(c.from, c.from_port, c.to, c.to_port)
|
disconnect_node(c.from, c.from_port, c.to, c.to_port)
|
||||||
send_changed_signal()
|
|
||||||
node.queue_free()
|
node.queue_free()
|
||||||
|
send_changed_signal()
|
||||||
|
|
||||||
# Global operations on graph
|
# Global operations on graph
|
||||||
|
|
||||||
@ -91,12 +92,32 @@ func clear_material():
|
|||||||
if c is GraphNode:
|
if c is GraphNode:
|
||||||
remove_child(c)
|
remove_child(c)
|
||||||
c.free()
|
c.free()
|
||||||
|
if generator != null:
|
||||||
|
remove_child(generator)
|
||||||
|
generator.free()
|
||||||
|
generator = null
|
||||||
send_changed_signal()
|
send_changed_signal()
|
||||||
|
|
||||||
func new_material():
|
func new_material():
|
||||||
|
print("New material")
|
||||||
clear_material()
|
clear_material()
|
||||||
create_nodes({name="Material", type="material"})
|
var loader = MMGenLoader.new()
|
||||||
set_save_path(null)
|
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()
|
center_view()
|
||||||
|
|
||||||
func get_free_name(type):
|
func get_free_name(type):
|
||||||
@ -142,7 +163,6 @@ func load_file(filename):
|
|||||||
if generator != null:
|
if generator != null:
|
||||||
add_child(generator)
|
add_child(generator)
|
||||||
for g in generator.get_children():
|
for g in generator.get_children():
|
||||||
print(g.get_type())
|
|
||||||
var node = node_factory.create_node(g.get_type())
|
var node = node_factory.create_node(g.get_type())
|
||||||
if node != null:
|
if node != null:
|
||||||
node.name = "node_"+g.name
|
node.name = "node_"+g.name
|
||||||
|
@ -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/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"]
|
[node name="GraphEdit" type="GraphEdit"]
|
||||||
self_modulate = Color( 1, 1, 1, 0 )
|
self_modulate = Color( 1, 1, 1, 0 )
|
||||||
@ -14,14 +11,6 @@ scroll_offset = Vector2( -325, -250 )
|
|||||||
use_snap = false
|
use_snap = false
|
||||||
script = ExtResource( 1 )
|
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="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
wait_time = 0.2
|
wait_time = 0.2
|
||||||
one_shot = true
|
one_shot = true
|
||||||
|
@ -133,6 +133,7 @@ func new_pane():
|
|||||||
|
|
||||||
func new_material():
|
func new_material():
|
||||||
var graph_edit = new_pane()
|
var graph_edit = new_pane()
|
||||||
|
graph_edit.new_material()
|
||||||
graph_edit.update_tab_title()
|
graph_edit.update_tab_title()
|
||||||
|
|
||||||
func load_material():
|
func load_material():
|
||||||
@ -153,11 +154,14 @@ func do_load_material(filename):
|
|||||||
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
|
var graph_edit = $VBoxContainer/HBoxContainer/Projects.get_current_tab_control()
|
||||||
var node_count = 2 # So test below succeeds if graph_edit is null...
|
var node_count = 2 # So test below succeeds if graph_edit is null...
|
||||||
if graph_edit != null:
|
if graph_edit != null:
|
||||||
|
node_count = 0
|
||||||
for c in graph_edit.get_children():
|
for c in graph_edit.get_children():
|
||||||
if c is GraphNode:
|
if c is GraphNode:
|
||||||
|
print(c.name)
|
||||||
node_count += 1
|
node_count += 1
|
||||||
if node_count > 1:
|
if node_count > 1:
|
||||||
break
|
break
|
||||||
|
print(node_count)
|
||||||
if node_count > 1:
|
if node_count > 1:
|
||||||
graph_edit = new_pane()
|
graph_edit = new_pane()
|
||||||
graph_edit.load_file(filename)
|
graph_edit.load_file(filename)
|
||||||
|
@ -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"}]}
|
{"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"}]}
|
Loading…
Reference in New Issue
Block a user