Project load fix and translate in transform

Added missing OptionButtons update when loading a project
Added translation to transforms
Added an example using transform
This commit is contained in:
RodZill4 2018-08-02 06:32:08 +02:00
parent 5b20a189f9
commit 0c062563c1
6 changed files with 124 additions and 22 deletions

View File

@ -34,6 +34,8 @@ func update_property_widgets():
o.text = str(get(o.name))
elif o is SpinBox:
o.value = get(o.name)
elif o is OptionButton:
o.selected = get(o.name)
elif o is ColorPickerButton:
o.color = get(o.name)

View File

@ -1,12 +1,14 @@
tool
extends "res://addons/procedural_material/node_base.gd"
var translate_x = 0.0
var translate_y = 0.0
var rotate = 0.0
var scale = 0.0
func _ready():
set_slot(0, true, 0, Color(0.5, 0.5, 1), true, 0, Color(0.5, 0.5, 1))
initialize_properties([ $GridContainer/rotate, $GridContainer/scale ])
initialize_properties([ $GridContainer/translate_x, $GridContainer/translate_y, $GridContainer/rotate, $GridContainer/scale ])
func _get_shader_code(uv):
var rv = { defs="", code="" }
@ -16,7 +18,7 @@ func _get_shader_code(uv):
rv.uv = name+"_uv("+uv+")"
var src_code = src.get_shader_code(rv.uv)
if !generated:
rv.defs = src_code.defs+"vec2 "+name+"_uv(vec2 uv) { return transform(uv, %.9f, %.9f); }\n" % [ 3.1415928*rotate/180.0, scale ]
rv.defs = src_code.defs+"vec2 "+name+"_uv(vec2 uv) { return transform(uv, vec2(%.9f, %.9f), %.9f, %.9f); }\n" % [ translate_x, translate_y, 3.1415928*rotate/180.0, scale ]
generated = true
rv.code = src_code.code;
if src_code.has("f"):

View File

@ -5,7 +5,7 @@
[sub_resource type="Theme" id=1]
[node name="Transform" type="GraphNode"]
[node name="Transform" type="GraphNode" index="0"]
anchor_left = 0.0
anchor_top = 0.0
@ -46,8 +46,8 @@ anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 16.0
margin_top = 24.0
margin_right = 139.0
margin_bottom = 76.0
margin_right = 168.0
margin_bottom = 132.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
@ -63,7 +63,7 @@ anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 5.0
margin_right = 45.0
margin_right = 74.0
margin_bottom = 19.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
@ -71,20 +71,116 @@ mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Translate X:"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="translate_x" type="SpinBox" parent="GridContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 78.0
margin_right = 152.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = -1.0
max_value = 1.0
step = 0.05
page = 0.0
value = 0.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Caret", "Placeholder" ]
[node name="Label2" type="Label" parent="GridContainer" index="2"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 33.0
margin_right = 74.0
margin_bottom = 47.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Translate Y:"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="translate_y" type="SpinBox" parent="GridContainer" index="3"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 78.0
margin_top = 28.0
margin_right = 152.0
margin_bottom = 52.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
min_value = -1.0
max_value = 1.0
step = 0.05
page = 0.0
value = 0.0
exp_edit = false
rounded = false
editable = true
prefix = ""
suffix = ""
_sections_unfolded = [ "Caret", "Placeholder" ]
[node name="Label3" type="Label" parent="GridContainer" index="4"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 61.0
margin_right = 74.0
margin_bottom = 75.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "Rotate:"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="rotate" type="SpinBox" parent="GridContainer" index="1"]
[node name="rotate" type="SpinBox" parent="GridContainer" index="5"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 49.0
margin_right = 123.0
margin_bottom = 24.0
margin_left = 78.0
margin_top = 56.0
margin_right = 152.0
margin_bottom = 80.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
@ -103,15 +199,15 @@ prefix = ""
suffix = ""
_sections_unfolded = [ "Caret", "Placeholder" ]
[node name="Label2" type="Label" parent="GridContainer" index="2"]
[node name="Label4" type="Label" parent="GridContainer" index="6"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 33.0
margin_right = 45.0
margin_bottom = 47.0
margin_top = 89.0
margin_right = 74.0
margin_bottom = 103.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
@ -123,16 +219,16 @@ percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[node name="scale" type="SpinBox" parent="GridContainer" index="3"]
[node name="scale" type="SpinBox" parent="GridContainer" index="7"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 49.0
margin_top = 28.0
margin_right = 123.0
margin_bottom = 52.0
margin_left = 78.0
margin_top = 84.0
margin_right = 152.0
margin_bottom = 108.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0

View File

@ -492,7 +492,7 @@ tracks/2/keys = {
"values": [ 3 ]
}
[node name="ProceduralMaterialEditor" type="MarginContainer"]
[node name="ProceduralMaterialEditor" type="MarginContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
@ -677,7 +677,7 @@ _sections_unfolded = [ "GUI", "Render Target" ]
[node name="Objects" type="Spatial" parent="Preview/Preview/MaterialPreview" index="0"]
transform = Transform( -0.139228, 0, 0.990259, 0, 1, 0, -0.990259, 0, -0.139228, 0, 0, 0 )
transform = Transform( -0.822992, 0, -0.568049, 0, 1, 0, 0.568049, 0, -0.822992, 0, 0, 0 )
_sections_unfolded = [ "Transform" ]
[node name="Cube" type="MeshInstance" parent="Preview/Preview/MaterialPreview/Objects" index="0"]

View File

@ -118,13 +118,14 @@ vec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*min(c1, c2) + (1.0-opacity)*c2;
}
vec2 transform(vec2 uv, float rotate, float scale) {
vec2 transform(vec2 uv, vec2 translate, float rotate, float scale) {
vec2 rv;
uv -= vec2(0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += vec2(0.5);
rv -= translate;
return rv;
}

View File

@ -0,0 +1 @@
{"connections":[{"from":"pattern_0","from_port":0,"to":"colorize_0","to_port":0},{"from":"colorize_0","from_port":0,"to":"blend_0","to_port":0},{"from":"transform_0","from_port":0,"to":"blend_0","to_port":1},{"from":"colorize_0","from_port":0,"to":"transform_0","to_port":0},{"from":"blend_0","from_port":0,"to":"transform_1","to_port":0},{"from":"transform_1","from_port":0,"to":"blend_1","to_port":1},{"from":"blend_0","from_port":0,"to":"blend_1","to_port":0},{"from":"blend_1","from_port":0,"to":"colorize_1","to_port":0},{"from":"colorize_1","from_port":0,"to":"normal_map_0","to_port":0},{"from":"normal_map_0","from_port":0,"to":"Material","to_port":4}],"nodes":[{"mix":5,"name":"pattern_0","node_position":{"x":26,"y":50},"type":"pattern","x_scale":8,"x_wave":0,"y_scale":8,"y_wave":0},{"gradient":[{"b":0,"g":0,"pos":0.018182,"r":0},{"b":1,"g":1,"pos":0.045455,"r":1}],"name":"colorize_0","node_position":{"x":70,"y":174},"type":"colorize"},{"name":"transform_0","node_position":{"x":54,"y":241},"rotate":0,"scale":1,"translate_x":0.06,"translate_y":0.06,"type":"transform"},{"amount":1,"blend_type":2,"name":"blend_0","node_position":{"x":255,"y":208},"type":"blend"},{"name":"transform_1","node_position":{"x":247,"y":319},"rotate":90,"scale":1,"translate_x":0.06,"translate_y":0,"type":"transform"},{"amount":1,"blend_type":2,"name":"blend_1","node_position":{"x":449,"y":288},"type":"blend"},{"name":"Material","node_position":{"x":717,"y":291},"type":"material"},{"gradient":[{"b":0,"g":0,"pos":0,"r":0},{"b":1,"g":1,"pos":1,"r":1}],"name":"colorize_1","node_position":{"x":444,"y":404},"type":"colorize"},{"amount":0.35,"name":"normal_map_0","node_position":{"x":500,"y":485},"type":"normal_map"}]}