Updated base library and added truchet generator

This commit is contained in:
RodZill4 2019-10-13 10:14:43 +02:00
parent 4dbfd6be75
commit 28654f3eba
23 changed files with 263 additions and 107 deletions

View File

@ -170,7 +170,7 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)):
return [] return []
func create_gen_from_type(gen_name): func create_gen_from_type(gen_name):
create_nodes({ type=gen_name }, scroll_offset+0.5*rect_size) create_nodes({ type=gen_name, parameters={} }, scroll_offset+0.5*rect_size)
func load_file(filename): func load_file(filename):
clear_material() clear_material()

View File

@ -3,7 +3,7 @@ extends VBoxContainer
var libraries = [] var libraries = []
onready var tree = $Tree onready var tree : Tree = $Tree
func _ready(): func _ready():
tree.set_column_expand(0, true) tree.set_column_expand(0, true)
@ -15,6 +15,17 @@ func _ready():
add_library("user://library/user.json") add_library("user://library/user.json")
update_tree() update_tree()
func get_selected_item_name():
var tree_item : TreeItem = tree.get_selected()
var rv = ""
while tree_item != null and tree_item != tree.get_root():
if rv == "":
rv = tree_item.get_text(0)
else:
rv = tree_item.get_text(0)+"/"+rv
tree_item = tree_item.get_parent()
return rv
func add_library(file_name : String, filter : String = ""): func add_library(file_name : String, filter : String = ""):
var root = tree.get_root() var root = tree.get_root()
var file = File.new() var file = File.new()

View File

@ -1,31 +1,73 @@
{"lib":[ {"lib":[
{ {
"tree_item":"Generators", "tree_item":"Simple",
"collapsed":false "collapsed":false
}, },
{ {
"tree_item":"Filters", "tree_item":"Simple/Uniform",
"collapsed":false
},
{
"tree_item":"Miscellaneous",
"collapsed":false
},
{
"tree_item":"Generators/Uniform",
"type":"uniform" "type":"uniform"
}, },
{ {
"tree_item":"Generators/Shape", "icon": "polygon",
"name": "shape",
"parameters": {
"edge": 0.051546,
"radius": 0.845361,
"shape": 1,
"sides": 6
},
"tree_item":"Simple/Shape",
"type":"shape" "type":"shape"
}, },
{ {
"tree_item":"Generators/Image", "icon": "star",
"type":"image", "name": "shape",
"file_path":"res://addons/material_maker/nodes/image/godot_logo.png" "parameters": {
"edge": 0.2,
"radius": 0.34375,
"shape": 2,
"sides": 5
},
"tree_item": "Simple/Shape/Star",
"type": "shape"
}, },
{ {
"tree_item":"Generators/Pattern", "icon": "curved_star",
"name": "shape",
"parameters": {
"edge": 0.628866,
"radius": 0.546392,
"shape": 3,
"sides": 6
},
"tree_item": "Simple/Shape/Curved Star",
"type": "shape"
},
{
"icon": "rays",
"name": "shape",
"parameters": {
"edge": 0.628866,
"radius": 0.546392,
"shape": 4,
"sides": 9
},
"tree_item": "Simple/Shape/Rays",
"type": "shape"
},
{
"tree_item":"Simple/Image",
"type":"image",
"parameters": {
"file_path":"res://addons/material_maker/nodes/image/godot_logo.png"
}
},
{
"tree_item":"Pattern",
"collapsed":false
},
{
"tree_item":"Pattern/Generic",
"icon":"pattern", "icon":"pattern",
"type":"pattern", "type":"pattern",
"parameters":{ "parameters":{
@ -37,7 +79,7 @@
} }
}, },
{ {
"tree_item": "Generators/Pattern/Checkerboard", "tree_item": "Pattern/Generic/Checkerboard",
"type": "pattern", "type": "pattern",
"icon": "checkerboard", "icon": "checkerboard",
"parameters":{ "parameters":{
@ -49,7 +91,7 @@
} }
}, },
{ {
"tree_item":"Generators/Bricks", "tree_item":"Pattern/Bricks",
"type":"bricks", "type":"bricks",
"icon":"bricks", "icon":"bricks",
"parameters":{ "parameters":{
@ -61,7 +103,7 @@
} }
}, },
{ {
"tree_item": "Generators/Bricks/Tiles", "tree_item": "Pattern/Bricks/Tiles",
"type": "bricks", "type": "bricks",
"icon": "tiles", "icon": "tiles",
"parameters":{ "parameters":{
@ -73,7 +115,7 @@
} }
}, },
{ {
"tree_item": "Generators/Bricks/BasketWeave", "tree_item": "Pattern/Bricks/BasketWeave",
"type": "bricks", "type": "bricks",
"icon": "basketweave", "icon": "basketweave",
"parameters":{ "parameters":{
@ -87,7 +129,7 @@
} }
}, },
{ {
"tree_item": "Generators/Bricks/HerringBone", "tree_item": "Pattern/Bricks/HerringBone",
"type": "bricks", "type": "bricks",
"icon": "herringbone", "icon": "herringbone",
"parameters":{ "parameters":{
@ -101,7 +143,7 @@
} }
}, },
{ {
"tree_item": "Generators/Bricks/SpanishBond", "tree_item": "Pattern/Bricks/SpanishBond",
"type": "bricks", "type": "bricks",
"icon": "spanishbond", "icon": "spanishbond",
"parameters":{ "parameters":{
@ -115,16 +157,61 @@
} }
}, },
{ {
"tree_item":"Generators/Noise", "icon": "weave",
"name": "weave",
"parameters": {
"columns": 4,
"rows": 4
},
"tree_item": "Pattern/Weave",
"type": "weave"
},
{
"icon": "truchet",
"name": "truchet",
"parameters": {
"Size": 4,
"shape": 0,
"size": 4,
"type": 1
},
"tree_item": "Pattern/Truchet",
"type": "truchet"
},
{
"icon": "runes",
"name": "runes",
"parameters": {
"columns": 4,
"rows": 4
},
"tree_item": "Pattern/Runes",
"type": "runes"
},
{
"tree_item":"Noise",
"type":"noise", "type":"noise",
"icon":"noise", "icon":"noise",
"collapsed":false,
"parameters":{ "parameters":{
"size":4, "size":4,
"density":0.5 "density":0.5
} }
}, },
{ {
"tree_item":"Generators/Perlin Noise", "tree_item":"Filter",
"collapsed":false
},
{
"tree_item":"Transform",
"collapsed":false
},
{
"tree_item":"Miscellaneous",
"collapsed":false
},
{
"tree_item":"Noise/Perlin",
"type":"perlin", "type":"perlin",
"icon":"perlin", "icon":"perlin",
"parameters":{ "parameters":{
@ -135,7 +222,7 @@
} }
}, },
{ {
"tree_item":"Generators/Voronoi Noise", "tree_item":"Noise/Voronoi",
"type":"voronoi", "type":"voronoi",
"icon":"voronoi", "icon":"voronoi",
"parameters":{ "parameters":{
@ -145,11 +232,7 @@
} }
}, },
{ {
"tree_item":"Filters/Buffer", "tree_item":"Filter/AdjustHSV",
"type":"buffer"
},
{
"tree_item":"Filters/AdjustHSV",
"type":"adjust_hsv", "type":"adjust_hsv",
"parameters":{ "parameters":{
"hue":0, "hue":0,
@ -158,69 +241,15 @@
} }
}, },
{ {
"tree_item":"Filters/Colorize", "icon": "colorize",
"tree_item":"Filter/Colorize",
"type":"colorize", "type":"colorize",
"parameters":{ "parameters":{
"gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}] "gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}]
} }
}, },
{
"tree_item":"Filters/Blend",
"type":"blend",
"parameters":{
"amount":0.5,
"blend_type":0
}
},
{
"tree_item":"Filters/Blur",
"type":"blur",
"parameters":{
"sigma":1.0
}
},
{
"tree_item":"Filters/Combine",
"type":"combine"
},
{
"tree_item":"Filters/Decompose",
"type":"decompose"
},
{
"tree_item":"Filters/Emboss",
"type":"emboss",
"parameters":{
"direction":0
}
},
{
"tree_item":"Filters/Normal map",
"type":"normal_map",
"parameters":{
"amount":0.5
}
},
{
"tree_item":"Filters/Transform",
"type":"transform",
"parameters":{
"rotate":0,
"scale_x":1,
"scale_y":1,
"translate_x":0,
"translate_y":0
}
},
{
"tree_item":"Filters/Warp",
"type":"warp",
"parameters":{
"amount":0.5
}
},
{ {
"tree_item": "Filters/Colorize/Invert", "tree_item": "Filter/Colorize/Invert",
"type": "colorize", "type": "colorize",
"icon": "invert", "icon": "invert",
"parameters":{ "parameters":{
@ -241,25 +270,139 @@
} }
}, },
{ {
"tree_item":"Miscellaneous/Comment", "icon": "rainbow",
"type":"comment" "name": "colorize",
"parameters": {
"gradient": {
"points": [
{
"a": 1,
"b": 0,
"g": 0,
"pos": 0,
"r": 1
},
{
"a": 1,
"b": 0,
"g": 0.96875,
"pos": 0.254545,
"r": 1
},
{
"a": 1,
"b": 0.125,
"g": 1,
"pos": 0.527273,
"r": 0
},
{
"a": 1,
"b": 1,
"g": 0.0625,
"pos": 0.772727,
"r": 0
},
{
"a": 1,
"b": 1,
"g": 0,
"pos": 1,
"r": 0.84375
}
],
"type": "Gradient"
}
},
"tree_item": "Filter/Colorize/Rainbow",
"type": "colorize"
}, },
{ {
"tree_item":"Miscellaneous/Export", "icon": "blend",
"type":"export" "tree_item":"Filter/Blend",
"type":"blend",
"parameters":{
"amount":0.5,
"blend_type":0
}
},
{
"tree_item":"Filter/Combine",
"type":"combine"
},
{
"tree_item":"Filter/Decompose",
"type":"decompose"
},
{
"icon": "normal_map",
"tree_item":"Filter/Normal map",
"type":"normal_map",
"parameters":{
"amount":0.5
}
},
{
"icon": "transform",
"tree_item":"Transform",
"type":"transform",
"parameters":{
"rotate":0,
"scale_x":1,
"scale_y":1,
"translate_x":0,
"translate_y":0
}
},
{
"icon": "mirror",
"name": "mirror",
"parameters": {
"direction": 0,
"offset": 0
},
"tree_item": "Transform/Mirror",
"type": "mirror"
},
{
"icon": "kaleidoscope",
"name": "kaleidoscope",
"parameters": {
"count": 5,
"direction": 0,
"offset": 0
},
"tree_item": "Transform/Kaleidoscope",
"type": "kaleidoscope"
},
{
"icon": "warp",
"tree_item":"Transform/Warp",
"type":"warp",
"parameters":{
"amount":0.5
}
},
{
"tree_item":"Miscellaneous/Buffer",
"type":"buffer"
},
{
"tree_item":"Miscellaneous/Custom Shader",
"type":"custom",
"shader_model":{}
}, },
{ {
"tree_item":"Miscellaneous/Switch", "tree_item":"Miscellaneous/Switch",
"type":"switch" "type":"switch"
}, },
{
"tree_item":"Miscellaneous/Custom",
"type":"custom",
"shader_model":{}
},
{ {
"tree_item":"Miscellaneous/Remote", "tree_item":"Miscellaneous/Remote",
"type":"remote", "type":"remote",
"widgets":[] "widgets":[]
},
{
"tree_item":"Miscellaneous/Comment",
"type":"comment"
} }
]} ]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

View File

@ -278,6 +278,7 @@ func add_to_user_library():
var selected_nodes = get_selected_nodes() var selected_nodes = get_selected_nodes()
if !selected_nodes.empty(): if !selected_nodes.empty():
var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance() var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance()
dialog.set_value(library.get_selected_item_name())
dialog.set_texts("New library element", "Select a name for the new library element") dialog.set_texts("New library element", "Select a name for the new library element")
add_child(dialog) add_child(dialog)
dialog.connect("ok", self, "do_add_to_user_library", [ selected_nodes ]) dialog.connect("ok", self, "do_add_to_user_library", [ selected_nodes ])
@ -296,12 +297,12 @@ func do_add_to_user_library(name, nodes):
dir.make_dir("user://library/user") dir.make_dir("user://library/user")
data.library = "user://library/user.json" data.library = "user://library/user.json"
data.icon = name.right(name.rfind("/")+1).to_lower() data.icon = name.right(name.rfind("/")+1).to_lower()
library.add_item(data, name)
var result = nodes[0].generator.render(0, renderer, 64) var result = nodes[0].generator.render(0, renderer, 64)
while result is GDScriptFunctionState: while result is GDScriptFunctionState:
result = yield(result, "completed") result = yield(result, "completed")
result.save_to_file("user://library/user/"+data.icon+".png") result.save_to_file("user://library/user/"+data.icon+".png")
result.release() result.release()
library.add_item(data, name, library.get_preview_texture(data))
func save_user_library(): func save_user_library():
print("Saving user library") print("Saving user library")

View File

@ -0,0 +1 @@
{"name":"truchet","node_position":{"x":0,"y":0},"parameters":{"Size":4,"shape":1,"size":4,"type":1},"shader_model":{"code":"","global":"float truchet1(vec2 uv, vec2 seed) {\n vec2 i = floor(uv);\n vec2 f = fract(uv)-vec2(0.5);\n return 1.0-abs(abs((2.0*step(rand(i+seed), 0.5)-1.0)*f.x+f.y)-0.5);\n}\n\nfloat truchet2(vec2 uv, vec2 seed) {\n vec2 i = floor(uv);\n vec2 f = fract(uv);\n float random = step(rand(i+seed), 0.5);\n f.x *= 2.0*random-1.0;\n f.x += 1.0-random;\n return 1.0-min(abs(length(f)-0.5), abs(length(1.0-f)-0.5));\n}\n","inputs":[],"instance":"","name":"Truchet","outputs":[{"f":"truchet$shape($uv*$size, vec2($seed, $seed))","type":"f"}],"parameters":[{"default":0,"label":"Shape","name":"shape","type":"enum","values":[{"name":"Line","value":"1"},{"name":"Circle","value":"2"}]},{"default":4,"label":"Size","max":64,"min":2,"name":"size","step":1,"type":"float","widget":"spinbox"}]},"type":"shader"}

View File

@ -32,7 +32,7 @@ shader = SubResource( 3 )
[node name="Control" type="Control"] [node name="Control" type="Control"]
margin_right = 120.0 margin_right = 120.0
margin_bottom = 30.0 margin_bottom = 30.0
rect_min_size = Vector2( 120, 30 ) rect_min_size = Vector2( 120, 32 )
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="Background" type="ColorRect" parent="."] [node name="Background" type="ColorRect" parent="."]

View File

@ -3,8 +3,8 @@ extends WindowDialog
signal ok signal ok
func _ready(): func set_value(v):
pass $VBoxContainer/LineEdit.text = v
func set_texts(title, label): func set_texts(title, label):
window_title = title window_title = title

File diff suppressed because one or more lines are too long