mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Color parameters and RGBA generic outputs
Also added default value to float, boolean and enum parameters
This commit is contained in:
parent
5d80d9db63
commit
78bb4551a8
@ -80,6 +80,8 @@ func update_node(data):
|
||||
control.selected = 0 if !p.has("default") else p.default
|
||||
elif p.type == "boolean":
|
||||
control = CheckBox.new()
|
||||
elif p.type == "color":
|
||||
control = ColorPickerButton.new()
|
||||
if control != null:
|
||||
var label = p.name
|
||||
control.name = label
|
||||
@ -108,6 +110,9 @@ func update_node(data):
|
||||
if output.has("rgb"):
|
||||
enable_right = true
|
||||
color_right = Color(0.5, 0.5, 1.0)
|
||||
elif output.has("rgba"):
|
||||
enable_right = true
|
||||
color_right = Color(0.0, 0.5, 0.0, 0.5)
|
||||
elif output.has("f"):
|
||||
enable_right = true
|
||||
set_slot(i, false, 0, color_right, enable_right, 0, color_right)
|
||||
@ -132,6 +137,8 @@ func subst(string, uv = ""):
|
||||
value_string = "%.9f" % pow(2, value+p.first)
|
||||
elif p.type == "enum":
|
||||
value_string = p.values[value].value
|
||||
elif p.type == "color":
|
||||
value_string = "vec4(%.9f, %.9f, %.9f, %.9f)" % [ value.r, value.g, value.b, value.a ]
|
||||
if value_string != null:
|
||||
string = string.replace("$(%s)" % p.name, value_string)
|
||||
return string
|
||||
@ -147,10 +154,14 @@ func _get_shader_code(uv, slot = 0):
|
||||
if variant_index == -1:
|
||||
variant_index = generated_variants.size()
|
||||
generated_variants.append(variant_string)
|
||||
if output.has("rgba"):
|
||||
rv.code += "vec4 %s_%d_%d_rgba = %s;\n" % [ name, slot, variant_index, subst(output.rgba, uv) ]
|
||||
if output.has("rgb"):
|
||||
rv.code += "vec3 %s_%d_%d_rgb = %s;\n" % [ name, slot, variant_index, subst(output.rgb, uv) ]
|
||||
if output.has("f"):
|
||||
rv.code += "float %s_%d_%d_f = %s;\n" % [ name, slot, variant_index, subst(output.f, uv) ]
|
||||
if output.has("rgba"):
|
||||
rv.rgba = "%s_%d_%d_rgba" % [ name, slot, variant_index ]
|
||||
if output.has("rgb"):
|
||||
rv.rgb = "%s_%d_%d_rgb" % [ name, slot, variant_index ]
|
||||
if output.has("f"):
|
||||
|
@ -7,16 +7,21 @@ func _ready():
|
||||
func set_model_data(data):
|
||||
if data.has("rgb"):
|
||||
$Type.selected = 1
|
||||
$Default.text = data.rgb
|
||||
$Value.text = data.rgb
|
||||
elif data.has("rgba"):
|
||||
$Type.selected = 2
|
||||
$Value.text = data.rgba
|
||||
elif data.has("f"):
|
||||
$Type.selected = 0
|
||||
$Default.text = data.f
|
||||
$Value.text = data.f
|
||||
|
||||
func get_model_data():
|
||||
if $Type.selected == 1:
|
||||
return { rgb=$Default.text }
|
||||
return { rgb=$Value.text }
|
||||
elif $Type.selected == 2:
|
||||
return { rgba=$Value.text }
|
||||
else:
|
||||
return { f=$Default.text }
|
||||
return { f=$Value.text }
|
||||
|
||||
func _on_Delete_pressed():
|
||||
queue_free()
|
||||
|
@ -3,7 +3,7 @@
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/output.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/material_maker/icons/minus.png" type="Texture" id=2]
|
||||
|
||||
[node name="Output" type="HBoxContainer"]
|
||||
[node name="Output" type="HBoxContainer" index="0"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
@ -70,11 +70,11 @@ group = null
|
||||
text = "GreyScale"
|
||||
flat = false
|
||||
align = 0
|
||||
items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null ]
|
||||
items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGBA", null, false, -1, null ]
|
||||
selected = 0
|
||||
_sections_unfolded = [ "Focus", "Hint", "Rect" ]
|
||||
|
||||
[node name="Default" type="LineEdit" parent="." index="2"]
|
||||
[node name="Value" type="LineEdit" parent="." index="2"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/material_maker/icons/minus.png" type="Texture" id=2]
|
||||
@ -6,6 +6,7 @@
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_size.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_enum.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_boolean.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_color.tscn" type="PackedScene" id=7]
|
||||
|
||||
[node name="Parameter" type="HBoxContainer" index="0"]
|
||||
|
||||
@ -106,7 +107,7 @@ anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 180.0
|
||||
margin_right = 250.0
|
||||
margin_right = 247.0
|
||||
margin_bottom = 24.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
@ -120,10 +121,10 @@ action_mode = 0
|
||||
enabled_focus_mode = 2
|
||||
shortcut = null
|
||||
group = null
|
||||
text = "Float"
|
||||
text = "float"
|
||||
flat = false
|
||||
align = 0
|
||||
items = [ ]
|
||||
items = [ "float", null, false, -1, null, "size", null, false, -1, null, "enum", null, false, -1, null, "boolean", null, false, -1, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="Types" type="HBoxContainer" parent="." index="4"]
|
||||
@ -132,8 +133,8 @@ anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 254.0
|
||||
margin_right = 254.0
|
||||
margin_left = 251.0
|
||||
margin_right = 251.0
|
||||
margin_bottom = 24.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
@ -164,6 +165,12 @@ margin_right = 839.0
|
||||
margin_left = 843.0
|
||||
margin_right = 917.0
|
||||
|
||||
[node name="color" parent="Types" index="4" instance=ExtResource( 7 )]
|
||||
|
||||
visible = false
|
||||
margin_left = 551.0
|
||||
margin_right = 563.0
|
||||
|
||||
[connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"]
|
||||
|
||||
[connection signal="item_selected" from="Type" to="." method="_on_Type_item_selected"]
|
||||
|
@ -6,7 +6,9 @@ func _ready():
|
||||
|
||||
func get_model_data():
|
||||
var data = {}
|
||||
data.default = $Default.pressed
|
||||
return data
|
||||
|
||||
func set_model_data(data):
|
||||
pass
|
||||
if data.has("default"):
|
||||
$Default.pressed = data.default
|
@ -4,7 +4,6 @@
|
||||
|
||||
[node name="boolean" type="HBoxContainer"]
|
||||
|
||||
editor/display_folded = true
|
||||
visible = false
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
|
15
addons/material_maker/widgets/node_editor/parameter_color.gd
Normal file
15
addons/material_maker/widgets/node_editor/parameter_color.gd
Normal file
@ -0,0 +1,15 @@
|
||||
tool
|
||||
extends HBoxContainer
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
func get_model_data():
|
||||
var data = {}
|
||||
var default = $Default.color
|
||||
data.default = { r=default.r, g=default.g, b=default.b, a=default.a}
|
||||
return data
|
||||
|
||||
func set_model_data(data):
|
||||
if data.has("default"):
|
||||
$Default.color = Color(data.default.r, data.default.g, data.default.b, data.default.a)
|
@ -0,0 +1,48 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_color.gd" type="Script" id=1]
|
||||
|
||||
[node name="color" type="HBoxContainer" index="0"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_right = 74.0
|
||||
margin_bottom = 24.0
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
mouse_filter = 1
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 1
|
||||
alignment = 0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Default" type="ColorPickerButton" parent="." index="0"]
|
||||
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 24.0
|
||||
rect_min_size = Vector2( 100, 0 )
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
focus_mode = 2
|
||||
mouse_filter = 0
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 1
|
||||
toggle_mode = false
|
||||
enabled_focus_mode = 2
|
||||
shortcut = null
|
||||
group = null
|
||||
flat = false
|
||||
align = 1
|
||||
color = Color( 1, 1, 1, 1 )
|
||||
edit_alpha = true
|
||||
_sections_unfolded = [ "Rect" ]
|
||||
|
||||
|
@ -16,10 +16,12 @@ func _ready():
|
||||
func get_model_data():
|
||||
var data = {}
|
||||
data.values = enum_values
|
||||
data.default = enum_current
|
||||
return data
|
||||
|
||||
func set_model_data(data):
|
||||
enum_values = data.values.duplicate()
|
||||
enum_current = data.default
|
||||
update_enum_list()
|
||||
|
||||
func update_enum_list():
|
||||
|
@ -9,6 +9,7 @@ func get_model_data():
|
||||
data.min = $Min.value
|
||||
data.max = $Max.value
|
||||
data.step = $Step.value
|
||||
data.default = $Default.value
|
||||
if $SpinBox.pressed:
|
||||
data.widget = "spinbox"
|
||||
return data
|
||||
@ -20,4 +21,6 @@ func set_model_data(data):
|
||||
$Max.value = data.max
|
||||
if data.has("step"):
|
||||
$Step.value = data.step
|
||||
if data.has("default"):
|
||||
$Default.value = data.default
|
||||
$SpinBox.pressed = ( data.has("widget") && data.widget == "spinbox" )
|
||||
|
Loading…
Reference in New Issue
Block a user