sd_repeat node.

This commit is contained in:
Relintai 2021-10-22 10:51:06 +02:00
parent d570d8aea3
commit 8a896d0e3d
3 changed files with 121 additions and 74 deletions

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=92 format=2]
[gd_resource type="Resource" load_steps=95 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]
@ -24,6 +24,7 @@
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_smooth_bool.gd" type="Script" id=22]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_rounded_shape.gd" type="Script" id=23]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_annular_shape.gd" type="Script" id=24]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_repeat.gd" type="Script" id=25]
[sub_resource type="Resource" id=3]
script = ExtResource( 5 )
@ -346,7 +347,7 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=62]
[sub_resource type="Resource" id=59]
script = ExtResource( 5 )
default_type = 1
default_int = 0
@ -355,7 +356,7 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=87]
[sub_resource type="Resource" id=89]
script = ExtResource( 5 )
default_type = 1
default_int = 0
@ -363,7 +364,7 @@ default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
input_property = SubResource( 62 )
input_property = SubResource( 59 )
[sub_resource type="Resource" id=48]
script = ExtResource( 5 )
@ -373,7 +374,7 @@ default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
input_property = SubResource( 87 )
input_property = SubResource( 89 )
[sub_resource type="Resource" id=49]
script = ExtResource( 13 )
@ -425,7 +426,14 @@ input = SubResource( 57 )
bevel = 0.0
base = 0.0
[sub_resource type="Resource" id=59]
[sub_resource type="Resource" id=60]
script = ExtResource( 15 )
graph_position = Vector2( 1060, -1320 )
output = SubResource( 59 )
center = Vector2( 0.03, 0 )
size = Vector2( 0.1, 0.1 )
[sub_resource type="Resource" id=62]
script = ExtResource( 5 )
default_type = 1
default_int = 0
@ -434,13 +442,6 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=60]
script = ExtResource( 15 )
graph_position = Vector2( 1140, -1320 )
output = SubResource( 59 )
center = Vector2( 0.03, 0 )
size = Vector2( 0.38, 0.2 )
[sub_resource type="Resource" id=63]
script = ExtResource( 16 )
graph_position = Vector2( 960, -440 )
@ -555,7 +556,6 @@ default_float = 0.0
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
input_property = SubResource( 59 )
[sub_resource type="Resource" id=81]
script = ExtResource( 5 )
@ -600,6 +600,16 @@ graph_position = Vector2( 1460, -500 )
output = SubResource( 84 )
radius = 0.19
[sub_resource type="Resource" id=87]
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 )
input_property = SubResource( 62 )
[sub_resource type="Resource" id=88]
script = ExtResource( 24 )
graph_position = Vector2( 740, -620 )
@ -607,7 +617,15 @@ output = SubResource( 87 )
width = 0.02
ripples = 3
[sub_resource type="Resource" id=90]
script = ExtResource( 25 )
graph_position = Vector2( 840, -1140 )
output = SubResource( 89 )
x = 5
y = 5
random_rotation = 0.5
[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 ), SubResource( 63 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ), SubResource( 78 ), SubResource( 82 ), SubResource( 85 ), SubResource( 88 ) ]
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 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ), SubResource( 78 ), SubResource( 82 ), SubResource( 85 ), SubResource( 88 ), SubResource( 90 ) ]

View File

@ -465,62 +465,15 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
#sdrepeat.mmg
#Repeats its input shape on a grid.This node does not support overlapping between instances.
# "inputs": [
# {
# "default": "0.0",
# "label": "",
# "longdesc": "The input shape, defined as a signed distance function",
# "name": "in",
# "shortdesc": "Input",
# "type": "sdf2d"
# }
# ],
# "outputs": [
# {
# "longdesc": "The shape generated by the repeat operation",
# "sdf2d": "$in(repeat_2d($uv, vec2(1.0/$rx, 1.0/$ry), float($seed), $r))",
# "shortdesc": "Output",
# "type": "sdf2d"
# }
# ],
# "parameters": [
# {
# "control": "None",
# "default": 4,
# "label": "X",
# "longdesc": "The number of columns in the grid",
# "max": 32,
# "min": 1,
# "name": "rx",
# "shortdesc": "Columns",
# "step": 1,
# "type": "float"
# },
# {
# "control": "None",
# "default": 4,
# "label": "Y",
# "longdesc": "The number of lines in the grid",
# "max": 32,
# "min": 1,
# "name": "ry",
# "shortdesc": "Lines",
# "step": 1,
# "type": "float"
# },
# {
# "control": "None",
# "default": 0.5,
# "label": "R",
# "longdesc": "The amount of random rotation on each instance of the input shape",
# "max": 1,
# "min": 0,
# "name": "r",
# "shortdesc": "Rotation",
# "step": 0.01,
# "type": "float"
# }
# ],
#Output:
#Out, sdf2d (float) (property)
#$in(repeat_2d($uv, vec2(1.0/$rx, 1.0/$ry), float($seed), $r))
#Input:
#in, float (sdf2d), default : 0
#x, int, min: 1, max: 32, default: 4
#y, int, min: 1, max: 32, default: 4
#random_rotation, min: 0, max: 1, step:0.01, default: 0.5
#----------------------
#sdrhombus.mmg
@ -2418,9 +2371,17 @@ static func sdNgon(pos : Vector2, r : float, n : float) -> Vector2:
# return rv+vec2(0.5);
#}
static func repeat_2d(pos : Vector2, r : Vector2, pseed : float, randomness : float) -> Vector2:
return Vector2()
static func repeat_2d(p : Vector2, r : Vector2, pseed : float, randomness : float) -> Vector2:
p -= Vector2(0.5, 0.5);
var v : Vector2 = Vector2(p.x, p.y) + Vector2(0.5, 0.5) + Vector2(r.x, r.y)
var a : float = ((Commons.rand2(Commons.floorv2(Commons.modv2(v / Vector2(r.x, r.y), Vector2(1.0, 1.0) / Vector2(r.x, r.y)) + Vector2(pseed, pseed))) - Vector2(0.5, 0.5)) * 6.28 * randomness).x
p = Commons.modv2(p + Vector2(0.5, 0.5) * r,r)- Vector2(0.5, 0.5) * r
var rv : Vector2 = Vector2()
var c : float = cos(a)
var s : float = sin(a)
rv.x = p.x * c + p.y * s
rv.y = -p.x * s + p.y * c
return rv + Vector2(0.5, 0.5);
#float sdSmoothUnion( float d1, float d2, float k ) {
# float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );

View File

@ -0,0 +1,68 @@
tool
extends MMNode
var SDF2D = preload("res://addons/mat_maker_gd/nodes/common/sdf2d.gd")
export(Resource) var output : Resource
export(int) var x : int = 3
export(int) var y : int = 3
export(float) var random_rotation : float = 0.5
func _init_properties():
if !output:
output = MMNodeUniversalProperty.new()
output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
output.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
#output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
output.slot_name = ">>> Apply >>>"
output.get_value_from_owner = true
register_input_property(output)
register_output_property(output)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_label_universal(output)
mm_graph_node.add_slot_int("get_x", "set_x", "X")
mm_graph_node.add_slot_int("get_y", "set_y", "Y")
mm_graph_node.add_slot_float("get_random_rotation", "set_random_rotation", "Random rotation", 0.01)
func get_property_value(uv : Vector2):
#todo add this as a parameter
var pseed : int = 123123
#$in(repeat_2d($uv, vec2(1.0/$rx, 1.0/$ry), float($seed), $r))
var new_uv : Vector2 = SDF2D.repeat_2d(uv, Vector2(1.0 / float(x), 1.0/ float(y)), 1.0/float(pseed), random_rotation)
return output.get_value(new_uv, true)
#x
func get_x() -> int:
return x
func set_x(val : int) -> void:
x = val
emit_changed()
output.emit_changed()
#y
func get_y() -> int:
return y
func set_y(val : int) -> void:
y = val
emit_changed()
output.emit_changed()
#random_rotation
func get_random_rotation() -> float:
return random_rotation
func set_random_rotation(val : float) -> void:
random_rotation = val
emit_changed()
output.emit_changed()