2021-10-01 00:54:13 +02:00
|
|
|
tool
|
|
|
|
extends TextureRect
|
|
|
|
|
2021-10-01 23:30:23 +02:00
|
|
|
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
|
|
|
|
2021-10-01 00:54:13 +02:00
|
|
|
var image : Image
|
|
|
|
var tex : ImageTexture
|
|
|
|
|
|
|
|
export(Vector2) var bmin : Vector2 = Vector2(0.1, 0.1)
|
|
|
|
export(Vector2) var bmax : Vector2 = Vector2(1, 1)
|
|
|
|
|
|
|
|
export(bool) var refresh setget reff,reffg
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
#sdshow
|
|
|
|
var p_o47009_bevel = 0.100000000;
|
|
|
|
|
|
|
|
#circle
|
|
|
|
var p_o11635_r = 0.400000000;
|
|
|
|
var p_o11635_cx = 0.000000000;
|
|
|
|
var p_o11635_cy = 0.000000000;
|
|
|
|
|
|
|
|
#box
|
|
|
|
var p_o48575_w = 0.300000000;
|
|
|
|
var p_o48575_h = 0.200000000;
|
|
|
|
var p_o48575_cx = 0.000000000;
|
|
|
|
var p_o48575_cy = 0.000000000;
|
|
|
|
|
|
|
|
#line
|
|
|
|
var p_o49570_ax = -0.300000000;
|
|
|
|
var p_o49570_ay = -0.300000000;
|
|
|
|
var p_o49570_bx = 0.300000000;
|
|
|
|
var p_o49570_by = 0.300000000;
|
|
|
|
var p_o49570_r = 0.200000000;
|
|
|
|
|
|
|
|
#rhombus
|
|
|
|
var p_o50848_w = 0.300000000;
|
|
|
|
var p_o50848_h = 0.200000000;
|
|
|
|
var p_o50848_cx = 0.000000000;
|
|
|
|
var p_o50848_cy = 0.000000000;
|
|
|
|
|
|
|
|
#arc
|
|
|
|
var p_o51990_a1 = 0.000000000;
|
|
|
|
var p_o51990_a2 = 0.000000000;
|
|
|
|
var p_o51990_r1 = 0.300000000;
|
|
|
|
var p_o51990_r2 = 0.100000000;
|
|
|
|
|
|
|
|
func gen() -> void:
|
|
|
|
if !image:
|
|
|
|
image = Image.new()
|
|
|
|
image.create(300, 300, false, Image.FORMAT_RGBA8)
|
|
|
|
|
|
|
|
if !tex:
|
|
|
|
tex = ImageTexture.new()
|
|
|
|
|
|
|
|
# var bmin : Vector2 = Vector2(0.1, 0.1)
|
|
|
|
# var bmax : Vector2 = Vector2(1, 1)
|
|
|
|
|
|
|
|
image.lock()
|
|
|
|
|
|
|
|
var w : float = image.get_width()
|
|
|
|
var h : float = image.get_width()
|
|
|
|
|
|
|
|
var pseed : float = randf() + randi()
|
|
|
|
|
|
|
|
for x in range(image.get_width()):
|
|
|
|
for y in range(image.get_height()):
|
|
|
|
var v : Vector2 = Vector2(x / w, y / h)
|
|
|
|
|
|
|
|
# var fc : float = sdf_circle(v)
|
|
|
|
# var fc : float = sdf_box(v)
|
|
|
|
# var fc : float = sdf_line(v)
|
|
|
|
# var fc : float = sdf_rhombus(v)
|
|
|
|
# var fc : float = sdf_arc(v)
|
|
|
|
|
|
|
|
# var fc : float = sdf_boolean_union(sdf_circle(v), sdf_box(v))
|
|
|
|
# var fc : float = sdf_boolean_substraction(sdf_circle(v), sdf_box(v))
|
|
|
|
# var fc : float = sdf_boolean_intersection(sdf_circle(v), sdf_box(v))
|
|
|
|
|
|
|
|
# var fc : float = sdf_smooth_boolean_union(sdf_circle(v), sdf_box(v), 0.15)
|
|
|
|
# var fc : float = sdf_smooth_boolean_substraction(sdf_circle(v), sdf_box(v), 0.15)
|
|
|
|
# var fc : float = sdf_smooth_boolean_intersection(sdf_circle(v), sdf_box(v), 0.15)
|
|
|
|
|
|
|
|
# var fc : float = sdf_rounded_shape(sdf_box(v), 0.15)
|
|
|
|
# var fc : float = sdf_annular_shape(sdf_box(v), 0.15)
|
|
|
|
|
2021-10-02 10:39:30 +02:00
|
|
|
var fc : float = Commons.sdf_morph(sdf_circle(v), sdf_box(v), 0.5)
|
2021-10-01 00:54:13 +02:00
|
|
|
|
|
|
|
var col : Color = sdf_show(fc)
|
|
|
|
|
|
|
|
image.set_pixel(x, y, col)
|
|
|
|
|
|
|
|
|
|
|
|
image.unlock()
|
|
|
|
|
|
|
|
tex.create_from_image(image)
|
|
|
|
texture = tex
|
|
|
|
|
|
|
|
func sdf_show(val : float) -> Color:
|
|
|
|
var o47009_0_1_f : float = clamp(-val / max(p_o47009_bevel, 0.00001), 0.0, 1.0);
|
|
|
|
|
|
|
|
return Color(o47009_0_1_f, o47009_0_1_f, o47009_0_1_f, 1)
|
|
|
|
|
|
|
|
|
|
|
|
func sdf_circle(uv : Vector2) -> float:
|
|
|
|
return (uv - Vector2(p_o11635_cx + 0.5, p_o11635_cy + 0.5)).length() - p_o11635_r;
|
|
|
|
|
|
|
|
|
|
|
|
func sdf_box(uv : Vector2) -> float:
|
2021-10-01 23:30:23 +02:00
|
|
|
var o48575_0_d : Vector2 = Commons.absv2(uv - Vector2(p_o48575_cx+0.5, p_o48575_cy+0.5)) - Vector2(p_o48575_w, p_o48575_h)
|
2021-10-01 00:54:13 +02:00
|
|
|
|
2021-10-01 23:30:23 +02:00
|
|
|
return Commons.maxv2(o48575_0_d, Vector2(0, 0)).length() + min(max(o48575_0_d.x, o48575_0_d.y), 0.0)
|
2021-10-01 00:54:13 +02:00
|
|
|
|
|
|
|
func sdf_line(uv : Vector2) -> float:
|
2021-10-02 10:39:30 +02:00
|
|
|
return Commons.sdLine(uv, Vector2(p_o49570_ax+0.5, p_o49570_ay+0.5), Vector2(p_o49570_bx+0.5, p_o49570_by+0.5)) - p_o49570_r;
|
2021-10-01 00:54:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
func sdf_rhombus(uv : Vector2) -> float:
|
2021-10-02 10:39:30 +02:00
|
|
|
return Commons.sdRhombus(uv - Vector2(p_o50848_cx + 0.5, p_o50848_cy+0.5), Vector2(p_o50848_w, p_o50848_h));
|
2021-10-01 00:54:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
func sdf_arc(uv : Vector2) -> float:
|
2021-10-02 10:39:30 +02:00
|
|
|
return Commons.sdArc(uv - Vector2(0.5, 0.5), Commons.modf(p_o51990_a1, 360.0) * 0.01745329251, Commons.modf(p_o51990_a2, 360.0)*0.01745329251, p_o51990_r1, p_o51990_r2);
|
2021-10-01 00:54:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
func reffg():
|
|
|
|
return false
|
|
|
|
|
|
|
|
func reff(bb):
|
|
|
|
if bb:
|
|
|
|
gen()
|
|
|
|
|