Made the polygon editor work with my setup, and added sd_polygon_shape node.

This commit is contained in:
Relintai 2021-10-20 17:46:31 +02:00
parent c082ee9a60
commit a690c76612
26 changed files with 239 additions and 103 deletions

View File

@ -2,6 +2,7 @@ tool
extends GraphNode
var gradient_editor_scene : PackedScene = preload("res://addons/mat_maker_gd/widgets/gradient_editor/gradient_editor.tscn")
var polygon_edit_scene : PackedScene = preload("res://addons/mat_maker_gd/widgets/polygon_edit/polygon_edit.tscn")
var slot_colors : PoolColorArray
@ -72,6 +73,18 @@ func add_slot_gradient() -> int:
return slot_idx
func add_slot_polygon() -> int:
var ge : Control = polygon_edit_scene.instance()
var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "", "", ge)
ge.set_value(_node)
#ge.texture = _node.call(getter, _material, slot_idx)
#properties[slot_idx].append(ge.texture)
return slot_idx
func add_slot_color(getter : String, setter : String) -> int:
var cp : ColorPickerButton = ColorPickerButton.new()

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=61 format=2]
[gd_resource type="Resource" load_steps=64 format=2]
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/noise.gd" type="Script" id=2]
@ -15,6 +15,7 @@
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_show.gd" type="Script" id=13]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_circle.gd" type="Script" id=14]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_box.gd" type="Script" id=15]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_polygon.gd" type="Script" id=16]
[sub_resource type="Resource" id=3]
script = ExtResource( 5 )
@ -52,7 +53,7 @@ sides = 11
radius = SubResource( 4 )
edge = SubResource( 3 )
[sub_resource type="Resource" id=55]
[sub_resource type="Resource" id=64]
script = ExtResource( 5 )
default_type = 5
default_int = 0
@ -64,7 +65,7 @@ default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=6]
script = ExtResource( 6 )
graph_position = Vector2( 300, -400 )
image = SubResource( 55 )
image = SubResource( 64 )
postfix = "-test"
[sub_resource type="Resource" id=9]
@ -413,7 +414,21 @@ output = SubResource( 59 )
center = Vector2( 0, 0 )
size = Vector2( 0.3, 0.2 )
[sub_resource type="Resource" id=62]
script = ExtResource( 5 )
default_type = 1
default_int = 0
default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=63]
script = ExtResource( 16 )
graph_position = Vector2( 1320, -280 )
output = SubResource( 62 )
[resource]
script = ExtResource( 1 )
image_size = Vector2( 128, 128 )
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ) ]
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ) ]

View File

@ -1,7 +1,7 @@
tool
extends MMNode
var points : Array = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]
var points : PoolVector2Array = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]
func to_string() -> String:
var rv = PoolStringArray()
@ -10,7 +10,9 @@ func to_string() -> String:
return rv.join(",")
func clear() -> void:
points.clear()
points.resize(0)
set_dirty(true)
func add_point(x : float, y : float, closed : bool = true) -> void:
var p : Vector2 = Vector2(x, y)
@ -21,13 +23,16 @@ func add_point(x : float, y : float, closed : bool = true) -> void:
var min_length : float = (p-Geometry.get_closest_point_to_segment_2d(p, points[0], points[points_count-1])).length()
var insert_point = 0
for i in points_count-1:
var length = (p-Geometry.get_closest_point_to_segment_2d(p, points[i], points[i+1])).length()
var length = (p - Geometry.get_closest_point_to_segment_2d(p, points[i], points[i+1])).length()
if length < min_length:
min_length = length
insert_point = i+1
if !closed and insert_point == 0 and (points[0]-p).length() > (points[points_count-1]-p).length():
insert_point = points_count
points.insert(insert_point, p)
set_dirty(true)
func remove_point(index : int) -> bool:
var s = points.size()
@ -35,6 +40,7 @@ func remove_point(index : int) -> bool:
return false
else:
points.remove(index)
set_dirty(true)
return true
func get_point_count() -> int:
@ -45,6 +51,11 @@ func get_point(i : int) -> Vector2:
func set_point(i : int, v : Vector2) -> void:
points[i] = v
set_dirty(true)
func set_points(v : PoolVector2Array) -> void:
points = v
set_dirty(true)
func get_shader() -> String:
var elements : PoolStringArray = PoolStringArray()

View File

@ -536,41 +536,12 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
#sdpolygon.mmg
#A polygon as a signed distance function
# "instance": "float sdPolygon_$(name)(vec2 p) {vec2 v[] = $polygon;int l = v.length(); float d = dot(p-v[0],p-v[0]); float s = 1.0;int j = l-1; for(int i=0; i<l; i++) { vec2 e = v[j] - v[i]; vec2 w = p - v[i]; vec2 b = w - e*clamp( dot(w,e)/dot(e,e), 0.0, 1.0 ); d = min( d, dot(b,b) ); bvec3 c = bvec3(p.y>=v[i].y,p.y<v[j].y,e.x*w.y>e.y*w.x); if( all(c) || all(not(c)) ) s*=-1.0;j=i; } return s*sqrt(d);}",
# "outputs": [
# {
# "longdesc": "The polygon as a signed distance function",
# "sdf2d": "sdPolygon_$(name)($uv)",
# "shortdesc": "Output",
# "type": "sdf2d"
# }
# ],
# "parameters": [
# {
# "default": {
# "points": [
# {
# "x": 0.2,
# "y": 0.2
# },
# {
# "x": 0.4,
# "y": 0.7
# },
# {
# "x": 0.7,
# "y": 0.4
# }
# ],
# "type": "Polygon"
# },
# "label": "",
# "longdesc": "The polygon to be drawn",
# "name": "polygon",
# "shortdesc": "Polygon",
# "type": "polygon"
# }
# ],
#Output:
#Out, sdf2d (float) (property)
#sdPolygon_$(name)($uv)
#Input:
#polygon points, default: 0.2, 0.2, 0.4, 0.7, 0.7, 0.4
#----------------------
#sdrepeat.mmg
@ -2624,4 +2595,51 @@ static func sdSmoothIntersection(d1 : float, d2 : float, k : float) -> float:
# return d;\n
#}
#$polygon = { p1(vec2), p2(vec2), p3(vec2) ... }
#float sdPolygon_$(name)(vec2 p) {
# vec2 v[] = $polygon;
# int l = v.length();
# float d = dot(p-v[0],p-v[0]);
# float s = 1.0;
# int j = l-1;
#
# for(int i=0; i<l; i++) {
# vec2 e = v[j] - v[i];
# vec2 w = p - v[i];
# vec2 b = w - e*clamp( dot(w,e)/dot(e,e), 0.0, 1.0 );
# d = min( d, dot(b,b) );
# bvec3 c = bvec3(p.y>=v[i].y,p.y<v[j].y,e.x*w.y>e.y*w.x);
#
# if(all(c) || all(not(c))) {
# s *= -1.0;
# }
#
# j = i;
# }
#
# return s*sqrt(d);
#}
static func sdPolygon(p : Vector2, v : PoolVector2Array) -> float:
var l : int = v.size()
var pmv0 : Vector2 = p - v[0]
var d : float = pmv0.dot(pmv0)
var s : float = 1.0
var j : int = l - 1
for i in range(l): #for(int i=0; i<l; i++)
var e : Vector2 = v[j] - v[i]
var w : Vector2 = p - v[i]
var b : Vector2 = w - e * clamp(w.dot(e) / e.dot(e), 0.0, 1.0)
d = min(d, b.dot(b))
var b1 : bool = p.y >= v[i].y
var b2 : bool = p.y < v[j].y
var b3 : bool = e.x * w.y > e.y * w.x
if((b1 && b2 && b3) || (!b1 && !b2 && !b3)):
s *= -1.0
j = i
return s * sqrt(d)

View File

@ -0,0 +1,26 @@
tool
extends "res://addons/mat_maker_gd/nodes/bases/polygon_base.gd"
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
var SDF2D = preload("res://addons/mat_maker_gd/nodes/common/sdf2d.gd")
export(Resource) var output : Resource
func _init_properties():
if !output:
output = MMNodeUniversalProperty.new()
output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
output.slot_name = ">>> Output >>>"
output.get_value_from_owner = true
register_output_property(output)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_label_universal(output)
mm_graph_node.add_slot_polygon()
func get_property_value(uv : Vector2) -> float:
return SDF2D.sdPolygon(uv, points)

View File

@ -1,3 +1,4 @@
tool
extends Control
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")
@ -18,11 +19,14 @@ func _ready():
pass # Replace with function body.
func _draw():
var current_theme : Theme = get_node("/root/MainWindow").theme
var color : Color = current_theme.get_color("font_color", "Label")
# var current_theme : Theme = get_node("/root/MainWindow").theme
# var color : Color = current_theme.get_color("font_color", "Label")
var color : Color = Color(1, 1, 1, 1)
for c in get_children():
if c.visible:
draw_line(OFFSET, c.rect_position+OFFSET, color)
draw_rect(Rect2(0, 0, 7, 7), color)
#p : MMCurve.Point

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/curve_edit/slope_point.gd" type="Script" id=1]
[ext_resource path="res://material_maker/widgets/curve_edit/control_point.gd" type="Script" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/slope_point.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/control_point.gd" type="Script" id=2]
[node name="ControlPoint" type="Control"]
margin_left = 56.9864

View File

@ -1,3 +1,4 @@
tool
extends WindowDialog
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_editor.tscn" type="PackedScene" id=1]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_dialog.gd" type="Script" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_editor.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_dialog.gd" type="Script" id=2]
[node name="CurveDialog" type="WindowDialog"]
anchor_right = 1.0

View File

@ -1,3 +1,4 @@
tool
extends Control
var MMCurve = preload("res://addons/mat_maker_gd/nodes/bases/curve_base.gd")

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_edit.gd" type="Script" id=1]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_edit.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=2]
[node name="CurveEdit" type="Button"]
anchor_left = 1.0

View File

@ -1,3 +1,4 @@
tool
extends "res://addons/mat_maker_gd/widgets/curve_edit/curve_view.gd"
signal value_changed(value)

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=1]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_editor.gd" type="Script" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_editor.gd" type="Script" id=2]
[node name="CurveEditor" instance=ExtResource( 1 )]
margin_left = 10.0

View File

@ -19,16 +19,23 @@ func reverse_transform_point(p : Vector2) -> Vector2:
return Vector2(0.0, 1.0)+Vector2(1.0, -1.0)*p/rect_size
func _draw():
var current_theme : Theme = get_node("/root/MainWindow").theme
var bg = current_theme.get_stylebox("panel", "Panel").bg_color
var fg = current_theme.get_color("font_color", "Label")
var axes_color : Color = bg.linear_interpolate(fg, 0.25)
var curve_color : Color = bg.linear_interpolate(fg, 0.75)
# var current_theme : Theme = get_node("/root/MainWindow").theme
#
# var bg = current_theme.get_stylebox("panel", "Panel").bg_color
# var fg = current_theme.get_color("font_color", "Label")
#
# var axes_color : Color = bg.linear_interpolate(fg, 0.25)
# var curve_color : Color = bg.linear_interpolate(fg, 0.75)
var axes_color : Color = Color(0.9, 0.9, 0.9, 1)
var curve_color : Color = Color(1, 1, 1, 1)
if show_axes:
for i in range(5):
var p = transform_point(0.25*Vector2(i, i))
draw_line(Vector2(p.x, 0), Vector2(p.x, rect_size.y-1), axes_color)
draw_line(Vector2(0, p.y), Vector2(rect_size.x-1, p.y), axes_color)
for i in range(curve.points.size()-1):
var p1 = curve.points[i].p
var p2 = curve.points[i+1].p

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_view.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.gd" type="Script" id=1]
[node name="CurveView" type="Control"]
anchor_right = 1.0

View File

@ -1,3 +1,4 @@
tool
extends Control
export var distance : float
@ -10,8 +11,11 @@ func _ready():
pass # Replace with function body.
func _draw():
var current_theme : Theme = get_node("/root/MainWindow").theme
var color : Color = current_theme.get_color("font_color", "Label")
# var current_theme : Theme = get_node("/root/MainWindow").theme
# var color : Color = current_theme.get_color("font_color", "Label")
var color : Color = Color(1, 1, 1, 1)
draw_circle(Vector2(3.0, 3.0), 3.0, color)
func _on_ControlPoint_gui_input(event):

View File

@ -1,3 +1,4 @@
tool
extends Control
var moving : bool = false
@ -8,12 +9,14 @@ signal moved(index)
signal removed(index)
func _draw():
var current_theme : Theme = get_node("/root/MainWindow").theme
var color : Color = current_theme.get_color("font_color", "Label")
# var current_theme : Theme = get_node("/root/MainWindow").theme
# var color : Color = current_theme.get_color("font_color", "Label")
var color : Color = Color(1, 1, 1, 1)
draw_rect(Rect2(0, 0, 7, 7), color)
func initialize(p : Vector2) -> void:
rect_position = get_parent().transform_point(p)-OFFSET
rect_position = get_parent().transform_point(p) - OFFSET
func _on_ControlPoint_gui_input(event):
if event is InputEventMouseButton:

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://material_maker/widgets/polygon_edit/control_point.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/control_point.gd" type="Script" id=1]
[node name="ControlPoint" type="Control"]
margin_left = 56.9864

View File

@ -1,10 +1,11 @@
tool
extends WindowDialog
export var closed : bool = true setget set_closed
var previous_value
var previous_points : PoolVector2Array
var polygon
signal polygon_changed(polygon)
signal return_polygon(polygon)
func set_closed(c : bool = true):
closed = c
@ -12,21 +13,33 @@ func set_closed(c : bool = true):
$VBoxContainer/EditorContainer/PolygonEditor.set_closed(closed)
func _on_CurveDialog_popup_hide():
emit_signal("return_polygon", null)
# emit_signal("return_polygon", null)
queue_free()
pass
func _on_OK_pressed():
emit_signal("return_polygon", $VBoxContainer/EditorContainer/PolygonEditor.polygon)
emit_signal("polygon_changed", polygon)
queue_free()
func _on_Cancel_pressed():
emit_signal("return_polygon", previous_value)
polygon.set_points(previous_points)
emit_signal("polygon_changed", polygon)
queue_free()
func edit_polygon(polygon) -> Array:
previous_value = polygon.duplicate()
func edit_polygon(poly):
polygon = poly
previous_points = polygon.points
$VBoxContainer/EditorContainer/PolygonEditor.set_polygon(polygon)
popup_centered()
var result = yield(self, "return_polygon")
queue_free()
return result
#var result = yield(self, "return_polygon")
#queue_free()
#return result
func _on_PolygonEditor_value_changed(value):
emit_signal("polygon_changed", value)

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/polygon_edit/polygon_editor.tscn" type="PackedScene" id=1]
[ext_resource path="res://material_maker/widgets/polygon_edit/polygon_dialog.gd" type="Script" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_dialog.gd" type="Script" id=2]
[node name="PolygonDialog" type="WindowDialog"]
anchor_right = 1.0

View File

@ -1,3 +1,4 @@
tool
extends Control
var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd")
@ -5,34 +6,29 @@ var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd")
export var closed : bool = true setget set_closed
var value = null setget set_value
signal updated(polygon)
func set_closed(c : bool = true):
closed = c
$PolygonView.set_closed(c)
func _ready():
set_value(MMPolygon.new())
func set_value(v) -> void:
value = v.duplicate()
$PolygonView.polygon = value
value = v
$PolygonView.set_polygon(value)
$PolygonView.update()
func _on_PolygonEdit_pressed():
var dialog = preload("res://addons/mat_maker_gd/widgets/polygon_edit/polygon_dialog.tscn").instance()
dialog.set_closed(closed)
add_child(dialog)
dialog.connect("polygon_changed", self, "on_value_changed")
var new_polygon = dialog.edit_polygon(value)
while new_polygon is GDScriptFunctionState:
new_polygon = yield(new_polygon, "completed")
if new_polygon != null:
set_value(new_polygon)
emit_signal("updated", new_polygon.duplicate())
dialog.edit_polygon(value)
func on_value_changed(v) -> void:
set_value(v)
emit_signal("updated", v.duplicate())
#set_value(v)
emit_signal("updated", v)
$PolygonView.update()

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/polygon_edit/polygon_edit.gd" type="Script" id=1]
[ext_resource path="res://material_maker/widgets/polygon_edit/polygon_view.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_edit.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.tscn" type="PackedScene" id=2]
[node name="PolygonEdit" type="Button"]
anchor_left = 1.0

View File

@ -1,3 +1,4 @@
tool
extends "res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd"
signal value_changed(value)
@ -13,6 +14,10 @@ func set_polygon(p) -> void:
func update_controls() -> void:
for c in get_children():
c.queue_free()
if !polygon:
return
for i in polygon.points.size():
var p = polygon.points[i]
var control_point = preload("res://addons/mat_maker_gd/widgets/polygon_edit/control_point.tscn").instance()
@ -21,12 +26,14 @@ func update_controls() -> void:
control_point.rect_position = transform_point(p)-control_point.OFFSET
control_point.connect("moved", self, "_on_ControlPoint_moved")
control_point.connect("removed", self, "_on_ControlPoint_removed")
emit_signal("value_changed", polygon)
func _on_ControlPoint_moved(index):
var control_point = get_child(index)
polygon.points[index] = reverse_transform_point(control_point.rect_position+control_point.OFFSET)
update()
emit_signal("value_changed", polygon)
func _on_ControlPoint_removed(index):
@ -35,6 +42,9 @@ func _on_ControlPoint_removed(index):
update_controls()
func _on_PolygonEditor_gui_input(event):
if !polygon:
return
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.doubleclick:
var new_point_position = reverse_transform_point(get_local_mouse_position())

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://material_maker/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=1]
[ext_resource path="res://material_maker/widgets/polygon_edit/polygon_editor.gd" type="Script" id=2]
[ext_resource path="res://addons/mat_maker_gd/widgets/curve_edit/curve_view.tscn" type="PackedScene" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_editor.gd" type="Script" id=2]
[node name="PolygonEditor" instance=ExtResource( 1 )]
margin_left = 10.0

View File

@ -3,7 +3,8 @@ extends Control
var MMPolygon = preload("res://addons/mat_maker_gd/nodes/bases/polygon_base.gd")
var polygon #: MMPolygon
#: MMPolygon
var polygon
var draw_size : Vector2 = Vector2(1, 1)
var draw_offset : Vector2 = Vector2(0, 0)
@ -14,7 +15,7 @@ func set_closed(c : bool = true):
update()
func _ready() -> void:
polygon = MMPolygon.new()
# polygon = MMPolygon.new()
connect("resized", self, "_on_resize")
_on_resize()
@ -24,12 +25,24 @@ func transform_point(p : Vector2) -> Vector2:
func reverse_transform_point(p : Vector2) -> Vector2:
return (p-draw_offset)/draw_size
func set_polygon(val):
polygon = val
update()
func _draw():
var current_theme : Theme = get_node("/root/MainWindow").theme
var bg = current_theme.get_stylebox("panel", "Panel").bg_color
var fg = current_theme.get_color("font_color", "Label")
var axes_color : Color = bg.linear_interpolate(fg, 0.25)
var curve_color : Color = bg.linear_interpolate(fg, 0.75)
if !polygon:
return
# var current_theme : Theme = get_node("/root/MainWindow").theme
# var bg = current_theme.get_stylebox("panel", "Panel").bg_color
# var fg = current_theme.get_color("font_color", "Label")
# var axes_color : Color = bg.linear_interpolate(fg, 0.25)
# var curve_color : Color = bg.linear_interpolate(fg, 0.75)
var axes_color : Color = Color(0.9, 0.9, 0.9, 1)
var curve_color : Color = Color(1, 1, 1, 1)
draw_rect(Rect2(draw_offset, draw_size), axes_color, false)
var tp : Vector2 = transform_point(polygon.points[polygon.points.size()-1 if closed else 0])
for p in polygon.points:

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://material_maker/widgets/polygon_edit/polygon_view.gd" type="Script" id=1]
[ext_resource path="res://addons/mat_maker_gd/widgets/polygon_edit/polygon_view.gd" type="Script" id=1]
[node name="PolygonView" type="Control"]
margin_right = 64.0