mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Pattern node.
This commit is contained in:
parent
c634c3b882
commit
4f6829beb3
@ -123,9 +123,10 @@ func add_slot_line_edit(getter : String, setter : String, slot_name : String, pl
|
||||
func add_slot_enum(getter : String, setter : String, slot_name : String, values : Array) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
if slot_name:
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var mb : OptionButton = OptionButton.new()
|
||||
|
||||
|
@ -372,6 +372,9 @@ enum CombinerType {
|
||||
POW
|
||||
}
|
||||
|
||||
#"Sine,Triangle,Square,Sawtooth,Constant,Bounce"
|
||||
#"Multiply,Add,Max,Min,Xor,Pow"
|
||||
|
||||
#float $(name)_fct(vec2 uv) {
|
||||
# return mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));
|
||||
#}
|
||||
|
82
game/addons/mat_maker_gd/nodes/pattern/pattern.gd
Normal file
82
game/addons/mat_maker_gd/nodes/pattern/pattern.gd
Normal file
@ -0,0 +1,82 @@
|
||||
tool
|
||||
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
|
||||
export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") var combiner_axis_type_y : int = 0
|
||||
export(Vector2) var repeat : Vector2 = Vector2(4, 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_combiner_type", "set_combiner_type", "Combiner Type", [ "Multiply", "Add" , "Max", "Min", "Xor", "Pow" ])
|
||||
mm_graph_node.add_slot_enum("get_combiner_axis_type_x", "set_combiner_axis_type_x", "Combiner Axis type", [ "Sine", "Triangle", "Square", "Sawtooth", "Constant", "Bounce" ])
|
||||
mm_graph_node.add_slot_enum("get_combiner_axis_type_y", "set_combiner_axis_type_y", "", [ "Sine", "Triangle", "Square", "Sawtooth", "Constant", "Bounce" ])
|
||||
mm_graph_node.add_slot_vector2("get_repeat", "set_repeat", "Repeat", 1)#, Vector2(0, 32))
|
||||
|
||||
func _render(material) -> void:
|
||||
var img : Image = render_image(material)
|
||||
|
||||
image.set_value(img)
|
||||
|
||||
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
var f : float = Patterns.pattern(uv, repeat.x, repeat.y, combiner_type, combiner_axis_type_x, combiner_axis_type_y)
|
||||
|
||||
return Color(f, f, f, 1)
|
||||
|
||||
#combiner_type
|
||||
func get_combiner_type() -> int:
|
||||
return combiner_type
|
||||
|
||||
func set_combiner_type(val : int) -> void:
|
||||
combiner_type = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#combiner_axis_type_x
|
||||
func get_combiner_axis_type_x() -> int:
|
||||
return combiner_axis_type_x
|
||||
|
||||
func set_combiner_axis_type_x(val : int) -> void:
|
||||
combiner_axis_type_x = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#combiner_axis_type_y
|
||||
func get_combiner_axis_type_y() -> int:
|
||||
return combiner_axis_type_y
|
||||
|
||||
func set_combiner_axis_type_y(val : int) -> void:
|
||||
combiner_axis_type_y = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#repeat
|
||||
func get_repeat() -> Vector2:
|
||||
return repeat
|
||||
|
||||
func set_repeat(val : Vector2) -> void:
|
||||
repeat = val
|
||||
|
||||
set_dirty(true)
|
@ -1,61 +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 = Patterns.pattern(v, 4, 4, Patterns.CombinerType.MULTIPLY, Patterns.CombinerAxisType.SINE, Patterns.CombinerAxisType.SINE)
|
||||
|
||||
var col : Color = Color(f, f, f, 1)
|
||||
|
||||
image.set_pixel(x, y, col)
|
||||
|
||||
|
||||
image.unlock()
|
||||
|
||||
tex.create_from_image(image)
|
||||
# texture = tex
|
||||
|
||||
#var p_o7009_x_scale = 4.000000000;
|
||||
#var p_o7009_y_scale = 4.000000000;
|
||||
|
||||
func reffg():
|
||||
return false
|
||||
|
||||
func reff(bb):
|
||||
if bb:
|
||||
gen()
|
||||
|
Loading…
Reference in New Issue
Block a user