mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Truchet node.
This commit is contained in:
parent
4f6829beb3
commit
095fcab86c
@ -425,8 +425,10 @@ static func pattern(uv : Vector2, x_scale : float, y_scale : float, ct : int, ca
|
||||
return 0.0
|
||||
|
||||
|
||||
static func truchet1c(uv : Vector2, pseed : Vector2) -> Color:
|
||||
var f : float = truchet1(uv, pseed)
|
||||
#"Line,Circle"
|
||||
|
||||
static func truchet1c(uv : Vector2, size : float, pseed : float) -> Color:
|
||||
var f : float = truchet1(uv * size, Vector2(pseed, pseed))
|
||||
return Color(f, f, f, 1);
|
||||
|
||||
#float truchet1(vec2 uv, vec2 seed) {
|
||||
@ -440,10 +442,10 @@ static func truchet1(uv : Vector2, pseed : Vector2) -> float:
|
||||
var i : Vector2 = Commons.floorv2(uv);
|
||||
var f : Vector2 = Commons.fractv2(uv) - Vector2(0.5, 0.5);
|
||||
|
||||
return 1.0 - abs(abs((2.0*Commons.step(Commons.rand(i+pseed), 0.5)-1.0)*f.x+f.y)-0.5);
|
||||
return 1.0 - abs(abs((2.0 * Commons.step(Commons.rand(i + pseed), 0.5) - 1.0) * f.x + f.y) - 0.5);
|
||||
|
||||
static func truchet2c(uv : Vector2, pseed : Vector2) -> Color:
|
||||
var f : float = truchet2(uv, pseed)
|
||||
static func truchet2c(uv : Vector2, size : float, pseed : float) -> Color:
|
||||
var f : float = truchet2(uv * size, Vector2(pseed, pseed))
|
||||
return Color(f, f, f, 1);
|
||||
|
||||
#float truchet2(vec2 uv, vec2 seed) {
|
||||
@ -460,9 +462,9 @@ static func truchet2c(uv : Vector2, pseed : Vector2) -> Color:
|
||||
static func truchet2(uv : Vector2, pseed : Vector2) -> float:
|
||||
var i : Vector2 = Commons.floorv2(uv);
|
||||
var f : Vector2 = Commons.fractv2(uv);
|
||||
var random : float = Commons.step(Commons.rand(i+pseed), 0.5);
|
||||
var random : float = Commons.step(Commons.rand(i + pseed), 0.5);
|
||||
|
||||
f.x *= 2.0 * random-1.0;
|
||||
f.x *= 2.0 * random - 1.0;
|
||||
f.x += 1.0 - random;
|
||||
|
||||
return 1.0 - min(abs(f.length() - 0.5), abs((Vector2(1, 1) - f).length() - 0.5));
|
||||
|
@ -3,16 +3,6 @@ extends MMNode
|
||||
|
||||
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
|
||||
|
||||
#----------------------
|
||||
#pattern.mmg
|
||||
#Outputs: $(name)_fct($(uv))
|
||||
|
||||
#Combiner, enum, default: 0, values (CombinerType): Multiply, Add, Max, Min, Xor, Pow
|
||||
#Pattern_x_type, enum, default: 5, values (CombinerAxisType): Sine, Triangle, Square, Sawtooth, Constant, Bounce
|
||||
#Pattern_y_type, enum, default: 5, values (CombinerAxisType): Sine, Triangle, Square, Sawtooth, Constant, Bounce
|
||||
#Pattern_Repeat, vector2, min: 0, max: 32, default:4, step: 1
|
||||
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(int, "Multiply,Add,Max,Min,Xor,Pow") var combiner_type : int = 0
|
||||
export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") var combiner_axis_type_x : int = 0
|
||||
|
@ -1,68 +0,0 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
|
||||
|
||||
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():
|
||||
if !Engine.editor_hint:
|
||||
gen()
|
||||
|
||||
|
||||
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 f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
|
||||
|
||||
var col : Color = trunchet(v)
|
||||
|
||||
image.set_pixel(x, y, col)
|
||||
|
||||
|
||||
image.unlock()
|
||||
|
||||
tex.create_from_image(image)
|
||||
# texture = tex
|
||||
|
||||
|
||||
|
||||
var seed_o9164 = 6039;
|
||||
var p_o9164_size = 4.000000000;
|
||||
|
||||
func trunchet(uv : Vector2) -> Color:
|
||||
return Patterns.truchet1c(uv * p_o9164_size, Vector2(float(seed_o9164), float(seed_o9164)));
|
||||
# return Patterns.truchet2c(uv * p_o9164_size, Vector2(float(seed_o9164), float(seed_o9164)));
|
||||
|
||||
func reffg():
|
||||
return false
|
||||
|
||||
func reff(bb):
|
||||
if bb:
|
||||
gen()
|
||||
|
53
game/addons/mat_maker_gd/nodes/pattern/truchet.gd
Normal file
53
game/addons/mat_maker_gd/nodes/pattern/truchet.gd
Normal file
@ -0,0 +1,53 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Patterns = preload("res://addons/mat_maker_gd/nodes/common/patterns.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
export(int, "Line,Circle") var shape : int = 0
|
||||
export(float) var size : float = 4
|
||||
|
||||
func _init_properties():
|
||||
if !image:
|
||||
image = MMNodeUniversalProperty.new()
|
||||
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
|
||||
|
||||
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
|
||||
|
||||
register_output_property(image)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_texture_universal(image)
|
||||
mm_graph_node.add_slot_enum("get_shape", "set_shape", "Shape", [ "Line", "Circle" ])
|
||||
mm_graph_node.add_slot_float("get_size", "set_size", "Size", 1)
|
||||
|
||||
func _render(material) -> void:
|
||||
var img : Image = render_image(material)
|
||||
|
||||
image.set_value(img)
|
||||
|
||||
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
if shape == 0:
|
||||
return Patterns.truchet1c(uv, size, pseed)
|
||||
elif shape == 1:
|
||||
return Patterns.truchet2c(uv, size, pseed)
|
||||
|
||||
return Color()
|
||||
|
||||
#shape
|
||||
func get_shape() -> int:
|
||||
return shape
|
||||
|
||||
func set_shape(val : int) -> void:
|
||||
shape = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#size
|
||||
func get_size() -> float:
|
||||
return size
|
||||
|
||||
func set_size(val : float) -> void:
|
||||
size = val
|
||||
|
||||
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user