Moved io types definition (with conversions and preview) to a json file

This commit is contained in:
RodZill4 2020-01-28 22:40:03 +01:00
parent f1ff09dcc4
commit a811f3400f
28 changed files with 280 additions and 167 deletions

View File

@ -37,17 +37,6 @@ var parameters = {}
var seed_locked : bool = false
var seed_value : int = 0
const PORT_TYPE_NAMES : Array = [ "f", "rgb", "rgba", "sdf2d", "sdf3d" ]
const PORT_TYPES : Dictionary = {
f = { label="Greyscale", type="float", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 0.5) },
rgb = { label="Color", type="vec3", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.5, 0.5, 1.0) },
rgba = { label="RGBA", type="vec4", paramdefs="vec2 uv", params="uv", slot_type=0, color=Color(0.0, 0.5, 0.0, 0.5) },
sdf2d = { label="SDF2D", type="float", paramdefs="vec2 uv", params="uv", slot_type=1, color=Color(1.0, 0.5, 0.0) },
sdf3d = { label="SDF3D", type="float", paramdefs="vec3 p", params="p", slot_type=2, color=Color(1.0, 0.0, 0.0) },
any = { slot_type=42, color=Color(1.0, 1.0, 1.0) }
}
func _ready() -> void:
init_parameters()
@ -165,7 +154,7 @@ func get_input_shader(input_index : int) -> Dictionary:
func get_shader(output_index : int, context) -> Dictionary:
return get_shader_code("UV", output_index, context)
func generate_preview_shader(src_code) -> String:
func generate_preview_shader(src_code, type) -> String:
var code
code = "shader_type canvas_item;\n"
code += "render_mode blend_disabled;\n"
@ -181,55 +170,11 @@ func generate_preview_shader(src_code) -> String:
for g in src_code.globals:
code += g
var shader_code = src_code.defs
if src_code.has("rgba"):
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV;\n"
shader_code += src_code.code
shader_code += "COLOR = "+src_code.rgba+";\n"
shader_code += "}\n"
elif src_code.has("sdf2d"):
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV;\n"
shader_code += src_code.code
shader_code += "float d = "+src_code.sdf2d+";\n"
shader_code += "vec3 col = vec3(cos(d*min(256, preview_size)));\n"
shader_code += "col *= clamp(1.0-d*d, 0.0, 1.0);\n"
shader_code += "col *= vec3(1.0, vec2(step(-0.015, d)));\n"
shader_code += "col *= vec3(vec2(step(d, 0.015)), 1.0);\n"
shader_code += "COLOR = vec4(col, 1.0);\n"
shader_code += "}\n"
elif src_code.has("sdf3d"):
shader_code += "\nfloat calcdist(vec3 uv) {\n"
shader_code += src_code.code
shader_code += "return min("+src_code.sdf3d+", uv.z);\n"
shader_code += "}\n"
shader_code += "float raymarch(vec3 ro, vec3 rd) {\n"
shader_code += "float d=0.0;\n"
shader_code += "for (int i = 0; i < 50; i++) {\n"
shader_code += "vec3 p = ro + rd*d;\n"
shader_code += "float dstep = calcdist(p);\n"
shader_code += "d += dstep;\n"
shader_code += "if (dstep < 0.0001) break;\n"
shader_code += "}\n"
shader_code += "return d;\n"
shader_code += "}\n"
shader_code += "vec3 normal(vec3 p) {\n"
shader_code += " float d = calcdist(p);\n"
shader_code += " float e = .0001;\n"
shader_code += " vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e)));\n"
shader_code += " return normalize(n);\n"
shader_code += "}\n"
shader_code += "\nvoid fragment() {\n"
shader_code += "vec2 uv = UV-vec2(0.5);\n"
shader_code += "vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));\n"
shader_code += "vec3 n = normal(p);\n"
shader_code += "vec3 l = vec3(5.0, 5.0, 10.0);\n"
shader_code += "vec3 ld = normalize(l-p);\n"
shader_code += "float o = step(p.z, 0.001);\n"
shader_code += "float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01);\n"
shader_code += "float light = 0.3+0.7*dot(n, ld)*shadow;\n"
shader_code += "COLOR = vec4(vec3(0.8+0.2*o, 0.8+0.2*o, 1.0)*light, 1.0);\n"
shader_code += "}\n"
if src_code.has(type):
var preview_code : String = mm_io_types.types[type].preview
preview_code = preview_code.replace("$(code)", src_code.code)
preview_code = preview_code.replace("$(value)", src_code[type])
shader_code += preview_code
#print("GENERATED SHADER:\n"+shader_code)
code += shader_code
return code
@ -243,11 +188,11 @@ func render(output_index : int, size : int, preview : bool = false) -> Object:
source = { defs="", code="", textures={}, rgba="vec4(0.0)" }
var shader : String
if preview:
var output_type = "rgba"
var outputs = get_output_defs()
if outputs.size() > output_index:
var output = outputs[output_index]
print(output)
shader = generate_preview_shader(source)
output_type = outputs[output_index].type
shader = generate_preview_shader(source, output_type)
else:
shader = mm_renderer.generate_shader(source)
var result = mm_renderer.render_shader(shader, source.textures, size)
@ -259,20 +204,15 @@ func get_shader_code(uv : String, output_index : int, context : MMGenContext) ->
var rv = _get_shader_code(uv, output_index, context)
while rv is GDScriptFunctionState:
rv = yield(rv, "completed")
if !rv.empty():
if !rv.has("f"):
if rv.has("rgb"):
rv.f = "(dot("+rv.rgb+", vec3(1.0))/3.0)"
elif rv.has("rgba"):
rv.f = "(dot("+rv.rgba+".rgb, vec3(1.0))/3.0)"
if !rv.has("rgb"):
if rv.has("rgba"):
rv.rgb = rv.rgba+".rgb"
elif rv.has("f"):
rv.rgb = "vec3("+rv.f+")"
if !rv.has("rgba"):
if rv.has("rgb"):
rv.rgba = "vec4("+rv.rgb+", 1.0)"
if rv.has("type"):
if mm_io_types.types[rv.type].has("convert"):
for c in mm_io_types.types[rv.type].convert:
if !rv.has(c.type):
var expr = c.expr.replace("$(value)", rv[rv.type])
rv[c.type] = expr
else:
print("Missing type for node ")
print(rv)
return rv
func _get_shader_code(__, __, __) -> Dictionary:

View File

@ -174,6 +174,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
for t in src_code.textures.keys():
rv.textures[t] = src_code.textures[t]
rv[convolution_params.output_type] = "%s_%d" % [ genname, variant_index ]
rv.type = convolution_params.output_type
return rv

View File

@ -55,7 +55,6 @@ func set_port_name(i : int, n : String) -> void:
ports[i].name = n
func set_port_type(i : int, t : String) -> void:
print(t)
ports[i].type = t
emit_signal("parameter_changed", "__update_all__", null)

View File

@ -55,7 +55,7 @@ func set_shader_model(data: Dictionary) -> void:
for i in range(shader_model.outputs.size()):
var output = shader_model.outputs[i]
var output_code = ""
for f in PORT_TYPES.keys():
for f in mm_io_types.types.keys():
if output.has(f):
shader_model.outputs[i].type = f
output_code = output[f]
@ -260,7 +260,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
var input = shader_model.inputs[i]
if input.has("function") and input.function:
var source = get_source(i)
var string = "$%s(%s)" % [ input.name, PORT_TYPES[input.type].params ]
var string = "$%s(%s)" % [ input.name, mm_io_types.types[input.type].params ]
var local_context = MMGenContext.new(context)
var result = replace_input(string, local_context, input.name, input.type, source, input.default)
while result is GDScriptFunctionState:
@ -274,7 +274,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
# Add textures
for t in result.textures.keys():
rv.textures[t] = result.textures[t]
rv.defs += "%s %s_input_%s(%s) {\n" % [ PORT_TYPES[input.type].type, genname, input.name, PORT_TYPES[input.type].paramdefs ]
rv.defs += "%s %s_input_%s(%s) {\n" % [ mm_io_types.types[input.type].type, genname, input.name, mm_io_types.types[input.type].paramdefs ]
rv.defs += "%s\n" % result.code
rv.defs += "return %s;\n}\n" % result.string
if shader_model.has("instance"):
@ -307,7 +307,7 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
var variant_index = context.get_variant(self, variant_string)
if variant_index == -1:
variant_index = context.get_variant(self, variant_string)
for f in PORT_TYPES.keys():
for f in mm_io_types.types.keys():
if output.has(f):
var subst_output = subst(output[f], context, uv)
while subst_output is GDScriptFunctionState:
@ -320,12 +320,13 @@ func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -
rv.defs += subst_output.defs
# Add generated code
rv.code += subst_output.code
rv.code += "%s %s_%d_%d_%s = %s;\n" % [ PORT_TYPES[f].type, genname, output_index, variant_index, f, subst_output.string ]
rv.code += "%s %s_%d_%d_%s = %s;\n" % [ mm_io_types.types[f].type, genname, output_index, variant_index, f, subst_output.string ]
for t in subst_output.textures.keys():
rv.textures[t] = subst_output.textures[t]
for f in PORT_TYPES.keys():
for f in mm_io_types.types.keys():
if output.has(f):
rv[f] = "%s_%d_%d_%s" % [ genname, output_index, variant_index, f ]
rv.type = output.type
if shader_model.has("global") && rv.globals.find(shader_model.global) == -1:
rv.globals.push_back(shader_model.global)
return rv

View File

@ -13,7 +13,7 @@ func get_output_defs() -> Array:
func _get_shader_code_lod(uv : String, output_index : int, context : MMGenContext, lod : float = 0.0) -> Dictionary:
var genname = "o"+str(get_instance_id())
var rv = { globals=[], defs="", code="" }
var rv = { globals=[], defs="", code="", type="rgba" }
var texture_name = genname+"_tex"
var variant_index = context.get_variant(self, uv)
if variant_index == -1:

View File

@ -0,0 +1,22 @@
tool
extends Node
var type_names : Array = []
var types : Dictionary = {}
func _ready():
var file = File.new()
if file.open("res://addons/material_maker/nodes/io_types.mmt", File.READ) != OK:
print("Cannot read types")
return false
var type_list = parse_json(file.get_as_text())
file.close()
for t in type_list:
if t.has("label"):
type_names.push_back(t.name)
var c = t.color
t.color = Color(c.r, c.g, c.b, c.a)
if file.open("res://addons/material_maker/nodes/preview_"+t.name+".shader", File.READ) == OK:
t.preview = file.get_as_text()
file.close()
types[t.name] = t

View File

@ -3,9 +3,6 @@ extends Node
const STD_GENDEF_PATH = "res://addons/material_maker/nodes"
func _ready():
print("loader ready!")
func generator_name_from_path(path : String) -> String:
for p in [ STD_GENDEF_PATH, OS.get_executable_path().get_base_dir()+"/generators" ]:
print(p)

View File

@ -0,0 +1,79 @@
[
{
"name":"f",
"label":"Greyscale",
"type":"float",
"paramdefs":"vec2 uv",
"params":"uv",
"slot_type":0,
"convert":[
{ "type":"rgb", "expr":"vec3($(value))" },
{ "type":"rgba", "expr":"vec4(vec3($(value)), 1.0)" }
],
"color":{ "r":0.5, "g":0.5, "b":0.5, "a":1.0 }
},
{
"name":"rgb",
"label":"Color",
"type":"vec3",
"paramdefs":"vec2 uv",
"params":"uv",
"slot_type":0,
"convert":[
{ "type":"f", "expr":"(dot($(value), vec3(1.0))/3.0)" },
{ "type":"rgba", "expr":"vec4($(value), 1.0)" }
],
"color":{ "r":0.5, "g":0.5, "b":1.0, "a":1.0 }
},
{
"name":"rgba",
"label":"RGBA",
"type":"vec4",
"paramdefs":"vec2 uv",
"params":"uv",
"slot_type":0,
"convert":[
{ "type":"f", "expr":"(dot(($(value)).rgb, vec3(1.0))/3.0)" },
{ "type":"rgb ", "expr":"(($(value)).rgb)" }
],
"color":{ "r":0.0, "g":0.5, "b":0.0, "a":0.5 }
},
{
"name":"sdf2d",
"label":"SDF2D",
"type":"float",
"paramdefs":"vec2 uv",
"params":"uv",
"slot_type":1,
"color":{ "r":1.0, "g":0.5, "b":0.0, "a":1.0 }
},
{
"name":"sdf3d",
"label":"SDF3D",
"type":"float",
"paramdefs":"vec3 p",
"params":"p",
"slot_type":2,
"convert":[
{ "type":"sdf3dc", "expr":"vec2($(value)).rgb, 0.0)" }
],
"color":{ "r":0.5, "g":0.0, "b":0.0, "a":1.0 }
},
{
"name":"sdf3dc",
"label":"SDF3D-C",
"type":"vec2",
"paramdefs":"vec3 p",
"params":"p",
"slot_type":2,
"convert":[
{ "type":"sdf3d", "expr":"($(value)).x" }
],
"color":{ "r":1.0, "g":0.0, "b":0.0, "a":1.0 }
},
{
"name":"any",
"slot_type":42,
"color":{ "r":1.0, "g":1.0, "b":1.0, "a":1.0 }
}
]

View File

@ -0,0 +1,5 @@
void fragment() {
vec2 uv = UV;
$(code)
COLOR = vec4(vec3($(value)), 1.0);
}

View File

@ -0,0 +1,5 @@
void fragment() {
vec2 uv = UV;
$(code)
COLOR = vec4($(value), 1.0);
}

View File

@ -0,0 +1,5 @@
void fragment() {
vec2 uv = UV;
$(code)
COLOR = $(value);
}

View File

@ -0,0 +1,10 @@
void fragment() {
vec2 uv = UV;
$(code)
float d = $(value);
vec3 col = vec3(cos(d*min(256, preview_size)));
col *= clamp(1.0-d*d, 0.0, 1.0);
col *= vec3(1.0, vec2(step(-0.015, d)));
col *= vec3(vec2(step(d, 0.015)), 1.0);
COLOR = vec4(col, 1.0);
}

View File

@ -0,0 +1,33 @@
float calcdist(vec3 uv) {
$(code)
return min($(value), uv.z);
}
float raymarch(vec3 ro, vec3 rd) {
float d=0.0;
for (int i = 0; i < 50; i++) {
vec3 p = ro + rd*d;
float dstep = calcdist(p);
d += dstep;
if (dstep < 0.0001) break;
}
return d;
}
vec3 normal(vec3 p) {
float d = calcdist(p);
float e = .0001;
vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)), calcdist(p-vec3(0.0, e, 0.0)), calcdist(p-vec3(0.0, 0.0, e)));
return normalize(n);
}
void fragment() {
vec2 uv = UV-vec2(0.5);
vec3 p = vec3(uv, 2.0-raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0)));
vec3 n = normal(p);
vec3 l = vec3(5.0, 5.0, 10.0);
vec3 ld = normalize(l-p);
float o = step(p.z, 0.001);
float shadow = 1.0-0.75*step(raymarch(l, -ld), length(l-p)-0.01);
float light = 0.3+0.7*dot(n, ld)*shadow;
COLOR = vec4(vec3(0.8+0.2*o, 0.8+0.2*o, 1.0)*light, 1.0);
}

View File

@ -0,0 +1,45 @@
vec2 calcdist(vec3 uv) {
$(code)
vec2 v = $(value);
return vec2(min(v.x, uv.z), v.y);
}
vec2 raymarch(vec3 ro, vec3 rd) {
float d=0.0;
float color;
for (int i = 0; i < 50; i++) {
vec3 p = ro + rd*d;
vec2 dstep = calcdist(p);
d += dstep.x;
if (dstep.x < 0.0001) {
color = dstep.y;
break;
}
}
return vec2(d, color);
}
vec3 normal(vec3 p) {
float d = calcdist(p).x;
float e = .0001;
vec3 n = d - vec3(calcdist(p-vec3(e, 0.0, 0.0)).x, calcdist(p-vec3(0.0, e, 0.0)).x, calcdist(p-vec3(0.0, 0.0, e)).x);
return normalize(n);
}
vec3 rm_color(float c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(vec3(c) + K.xyz) * 6.0 - K.www);
return 1.0 * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), 1.0);
}
void fragment() {
vec2 uv = UV-vec2(0.5);
vec2 rm = raymarch(vec3(uv, 2.0), vec3(0.0, 0.0, -1.0));
vec3 p = vec3(uv, 2.0-rm.x);
vec3 n = normal(p);
vec3 l = vec3(5.0, 5.0, 10.0);
vec3 ld = normalize(l-p);
float o = step(p.z, 0.001);
float shadow = 1.0-0.75*step(raymarch(l, -ld).x, length(l-p)-0.01);
float light = 0.3+0.7*dot(n, ld)*shadow;
COLOR = vec4(mix(rm_color(fract(rm.y)), vec3(0.9), o)*light, 1.0);
}

View File

@ -23,7 +23,7 @@ signal graph_changed
func _ready() -> void:
OS.low_processor_usage_mode = true
center_view()
for t in range(5):
for t in range(41):
add_valid_connection_type(t, 42)
add_valid_connection_type(42, t)

View File

@ -28,6 +28,9 @@ custom_styles/bg = SubResource( 1 )
right_disconnects = true
use_snap = false
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Timer" type="Timer" parent="."]
wait_time = 0.2

View File

@ -1,9 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[sub_resource type="StreamTexture" id=1]
flags = 4
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1]
[resource]
flags = 4
atlas = SubResource( 1 )
atlas = ExtResource( 1 )
region = Rect2( 80, 32, 16, 16 )

View File

@ -1,9 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[sub_resource type="StreamTexture" id=1]
flags = 4
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1]
[resource]
flags = 4
atlas = SubResource( 1 )
atlas = ExtResource( 1 )
region = Rect2( 64, 32, 16, 16 )

View File

@ -177,8 +177,8 @@ func update_node() -> void:
var type_left = 0
if typeof(input) == TYPE_DICTIONARY:
enable_left = true
color_left = MMGenBase.PORT_TYPES[input.type].color
type_left = MMGenBase.PORT_TYPES[input.type].slot_type
color_left = mm_io_types.types[input.type].color
type_left = mm_io_types.types[input.type].slot_type
set_slot(i, enable_left, type_left, color_left, false, 0, Color())
var hsizer : HBoxContainer = HBoxContainer.new()
hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
@ -251,8 +251,8 @@ func update_node() -> void:
assert(typeof(output) == TYPE_DICTIONARY)
assert(output.has("type"))
enable_right = true
color_right = MMGenBase.PORT_TYPES[output.type].color
type_right = MMGenBase.PORT_TYPES[output.type].slot_type
color_right = mm_io_types.types[output.type].color
type_right = mm_io_types.types[output.type].slot_type
set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, type_right, color_right)
var hsizer : HBoxContainer
while i >= get_child_count():

View File

@ -22,7 +22,7 @@ func update_node() -> void:
title = generator.get_type_name()
var color = Color(0.0, 0.5, 0.0, 0.5)
for p in generator.get_io_defs():
color = MMGenBase.PORT_TYPES[p.type].color
color = mm_io_types.types[p.type].color
set_slot(get_child_count(), generator.name != "gen_inputs", 0, color, generator.name != "gen_outputs", 0, color)
var port : Control
if generator.is_editable():

View File

@ -4,7 +4,7 @@ func set_label(l : String) -> void:
$Name.set_text(l)
func set_type(t : String) -> void:
$Type.selected = MMGenBase.PORT_TYPE_NAMES.find(t)
$Type.selected = mm_io_types.type_names.find(t)
func update_up_down_button() -> void:
var parent = get_parent()
@ -17,7 +17,7 @@ func _on_Name_label_changed(new_label) -> void:
get_parent().generator.set_port_name(get_index(), new_label)
func _on_Type_item_selected(ID) -> void:
get_parent().generator.set_port_type(get_index(), MMGenBase.PORT_TYPE_NAMES[ID])
get_parent().generator.set_port_type(get_index(), mm_io_types.type_names[ID])
func _on_Delete_pressed() -> void:
get_parent().generator.delete_port(get_index())

View File

@ -1,6 +1,12 @@
tool
extends HBoxContainer
func _ready():
$Type.clear()
for tn in mm_io_types.type_names:
var t = mm_io_types.types[tn]
$Type.add_item(t.label)
func update_up_down_button() -> void:
var parent = get_parent()
if parent == null:
@ -11,31 +17,13 @@ func update_up_down_button() -> void:
func set_model_data(data) -> void:
$Name.text = data.name
$Label.text = data.label
if data.type == "rgb":
$Type.selected = 1
elif data.type == "rgba":
$Type.selected = 2
elif data.type == "sdf2d":
$Type.selected = 3
elif data.type == "sdf3d":
$Type.selected = 4
else:
$Type.selected = 0
$Type.selected = mm_io_types.type_names.find(data.type)
$Default.text = data.default
$Function.pressed = data.has("function") and data.function
func get_model_data() -> Dictionary:
var data = { name=$Name.text, label=$Label.text, default=$Default.text }
if $Type.selected == 1:
data.type = "rgb"
elif $Type.selected == 2:
data.type = "rgba"
elif $Type.selected == 3:
data.type = "sdf2d"
elif $Type.selected == 4:
data.type = "sdf3d"
else:
data.type = "f"
data.type = mm_io_types.type_names[$Type.selected]
if $Function.pressed:
data.function = true
return data

View File

@ -3,8 +3,6 @@
[ext_resource path="res://material_maker/widgets/node_editor/input.gd" type="Script" id=1]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=2]
[sub_resource type="AtlasTexture" id=1]
flags = 4
atlas = ExtResource( 2 )
@ -63,17 +61,17 @@ text = "Label"
[node name="Type" type="OptionButton" parent="."]
margin_left = 236.0
margin_right = 340.0
margin_right = 338.0
margin_bottom = 24.0
rect_min_size = Vector2( 102, 0 )
hint_tooltip = "Input flag"
text = "GreyScale"
items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null ]
text = "Greyscale"
items = [ "Greyscale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null, "SDF3D-C", null, false, 5, null ]
selected = 0
[node name="Default" type="LineEdit" parent="."]
margin_left = 344.0
margin_right = 414.0
margin_left = 342.0
margin_right = 412.0
margin_bottom = 24.0
rect_min_size = Vector2( 70, 0 )
hint_tooltip = "Default value"
@ -81,8 +79,8 @@ size_flags_horizontal = 3
text = "0.0"
[node name="Function" type="CheckBox" parent="."]
margin_left = 418.0
margin_right = 501.0
margin_left = 416.0
margin_right = 499.0
margin_bottom = 24.0
text = "Function"
[connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"]

View File

@ -1,6 +1,12 @@
tool
extends HBoxContainer
func _ready():
$Type.clear()
for tn in mm_io_types.type_names:
var t = mm_io_types.types[tn]
$Type.add_item(t.label)
func update_up_down_button() -> void:
var parent = get_parent()
if parent == null:
@ -9,33 +15,13 @@ func update_up_down_button() -> void:
$Down.disabled = (get_index() == get_parent().get_child_count()-2)
func set_model_data(data) -> void:
if data.has("rgb"):
$Type.selected = 1
$Value.text = data.rgb
elif data.has("rgba"):
$Type.selected = 2
$Value.text = data.rgba
elif data.has("sdf2d"):
$Type.selected = 3
$Value.text = data.sdf2d
elif data.has("sdf3d"):
$Type.selected = 4
$Value.text = data.sdf3d
elif data.has("f"):
$Type.selected = 0
$Value.text = data.f
for i in range(mm_io_types.type_names.size()):
if data.has(mm_io_types.type_names[i]):
$Type.selected = i
$Value.text = data[mm_io_types.type_names[i]]
func get_model_data() -> Dictionary:
if $Type.selected == 1:
return { rgb=$Value.text }
elif $Type.selected == 2:
return { rgba=$Value.text }
elif $Type.selected == 3:
return { sdf2d=$Value.text }
elif $Type.selected == 4:
return { sdf3d=$Value.text }
else:
return { f=$Value.text }
return { mm_io_types.type_names[$Type.selected]:$Value.text }
func _on_Delete_pressed() -> void:
var p = get_parent()

View File

@ -3,8 +3,6 @@
[ext_resource path="res://material_maker/widgets/node_editor/output.gd" type="Script" id=1]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=2]
[sub_resource type="AtlasTexture" id=1]
flags = 4
atlas = ExtResource( 2 )
@ -55,17 +53,17 @@ flat = true
[node name="Type" type="OptionButton" parent="."]
margin_left = 88.0
margin_right = 192.0
margin_right = 190.0
margin_bottom = 25.0
rect_min_size = Vector2( 102, 0 )
hint_tooltip = "Input flag"
text = "GreyScale"
items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null ]
text = "Greyscale"
items = [ "Greyscale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, 2, null, "SDF2D", null, false, 3, null, "SDF3D", null, false, 4, null, "SDF3D-C", null, false, 5, null ]
selected = 0
[node name="Value" type="LineEdit" parent="."]
margin_left = 196.0
margin_right = 290.0
margin_left = 194.0
margin_right = 288.0
margin_bottom = 25.0
hint_tooltip = "Default value"
size_flags_horizontal = 3

View File

@ -51,14 +51,14 @@ func _on_EnumValues_item_selected(id) -> void:
if id >= 0 and id < enum_values.size():
enum_current = id
elif id == ENUM_EDIT:
var dialog = load("res://addons/material_maker/widgets/node_editor/enum_editor.tscn").instance()
var dialog = load("res://material_maker/widgets/node_editor/enum_editor.tscn").instance()
var v = enum_values[enum_current]
add_child(dialog)
dialog.set_value(v.name, v.value)
dialog.connect("ok", self, "update_enum_value", [ enum_current ])
dialog.popup_centered()
elif id == ENUM_ADD:
var dialog = load("res://addons/material_maker/widgets/node_editor/enum_editor.tscn").instance()
var dialog = load("res://material_maker/widgets/node_editor/enum_editor.tscn").instance()
add_child(dialog)
dialog.connect("ok", self, "update_enum_value", [ -1 ])
dialog.popup_centered()

View File

@ -183,6 +183,7 @@ config/release="0.8"
[autoload]
mm_io_types="*res://addons/material_maker/engine/io_types.gd"
mm_loader="*res://addons/material_maker/engine/loader.gd"
mm_renderer="*res://addons/material_maker/engine/renderer.tscn"

View File

@ -1,7 +1,6 @@
extends Control
func _ready():
print("Loading...")
call_deferred("change_scene")
func change_scene():