mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-18 01:06:47 +01:00
sdf3d_op_repeat and circle_repeat nodes.
This commit is contained in:
parent
6429b4e725
commit
1c8af1f3f7
@ -74,13 +74,6 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
|
||||
#Outputs:
|
||||
|
||||
#+X: $axis = length($uv.yz),-$uv.x
|
||||
#-X: $axis = length($uv.yz),$uv.x
|
||||
#+Y: $axis = length($uv.xz),$uv.y
|
||||
#-Y: $axis = length($uv.xz),-$uv.y
|
||||
#+Z: $axis = length($uv.xy),-$uv.z
|
||||
#-Z: $axis = length($uv.xy),$uv.z
|
||||
|
||||
#Output (sdf3d)
|
||||
#Output - (sdf3dc) - The shape generated by the repeat operation
|
||||
#$in(repeat($uv, vec3(1.0/$rx, 1.0/$ry, 0.0), float($seed), $r))
|
||||
@ -640,7 +633,8 @@ static func sdf3d_elongation(p : Vector3, v : Vector3) -> Vector3:
|
||||
return ((p) - Commons.clampv3((p), - Commons.absv3(v), Commons.absv3(v)))
|
||||
|
||||
static func sdf3d_repeat(p : Vector3, r : Vector2, randomness : float, pseed : int) -> Vector3:
|
||||
return (repeat(p, Vector3(1.0/r.x, 1.0/r.y, 0.00001), float(pseed), randomness))
|
||||
#$in(repeat($uv, vec3(1.0/$rx, 1.0/$ry, 0.0), float($seed), $r))
|
||||
return repeat(p, Vector3(1.0 / r.x, 1.0 / r.y, 0.00001), float(pseed), randomness)
|
||||
|
||||
#vec3 repeat(vec3 p, vec3 r, float seed, float randomness) {
|
||||
# vec3 a = (rand3(floor(mod((p.xy+0.5*r.xy)/r.xy, 1.0/r.xy)+vec2(seed)))-0.5)*6.28*randomness;
|
||||
@ -673,48 +667,33 @@ static func sdf3d_repeat(p : Vector3, r : Vector2, randomness : float, pseed : i
|
||||
# return rv;
|
||||
#}
|
||||
|
||||
#Needs work
|
||||
static func repeat(p : Vector3, r : Vector3, pseed : float, randomness : float) -> Vector3:
|
||||
#fix division by zero
|
||||
# p.x += 0.000001
|
||||
# p.y += 0.000001
|
||||
# p.z += 0.000001
|
||||
# r.x += 0.000001
|
||||
# r.y += 0.000001
|
||||
# r.z += 0.000001
|
||||
var a : Vector3 = (Commons.rand3(Commons.floorv2(Commons.modv2((Vector2(p.x, p.y) + Vector2(0.5, 0.5) * Vector2(r.x, r.y)) / Vector2(r.x, r.y), Vector2(1, 1) / Vector2(r.x, r.y)) + Vector2(pseed, pseed))) - Vector3(0.5, 0.5, 0.5)) * 6.28 * randomness
|
||||
p = Commons.modv3(p + Vector3(0.5, 0.5, 0.5) * r, r) - Vector3(0.5, 0.5, 0.5) * r;
|
||||
|
||||
var pxy : Vector2 = Vector2(p.x, p.y)
|
||||
var rxy : Vector2 = Vector2(r.x, r.y)
|
||||
|
||||
var r3 : Vector2 = Commons.floorv2(Commons.modv2((pxy + 0.5 * rxy) / rxy, Vector2(1.0 / rxy.x, 1.0 / rxy.y)) + Vector2(pseed, pseed))
|
||||
|
||||
var rr : Vector3 = Commons.rand3(r3)
|
||||
|
||||
rr.x -= 0.5
|
||||
rr.y -= 0.5
|
||||
rr.z -= 0.5
|
||||
|
||||
var a : Vector3 = (rr) * 6.28 * randomness;
|
||||
var rv : Vector3 = Vector3()
|
||||
var c : float = 0
|
||||
var s : float = 0
|
||||
|
||||
p = Commons.modv3(p + 0.5 * r, r) - 0.5*r;
|
||||
var rv : Vector3;
|
||||
var c : float;
|
||||
var s : float;
|
||||
|
||||
c = cos(a.x);
|
||||
s = sin(a.x);
|
||||
|
||||
rv.x = p.x;
|
||||
rv.y = p.y*c+p.z*s;
|
||||
rv.z = -p.y*s+p.z*c;
|
||||
rv.y = p.y* c + p.z * s;
|
||||
rv.z = -p.y * s + p.z * c;
|
||||
|
||||
c = cos(a.y);
|
||||
s = sin(a.y);
|
||||
|
||||
p.x = rv.x*c+rv.z*s;
|
||||
p.y = rv.y;
|
||||
p.z = -rv.x*s+rv.z*c;
|
||||
|
||||
c = cos(a.z);
|
||||
s = sin(a.z);
|
||||
rv.x = p.x*c+p.y*s;
|
||||
rv.y = -p.x*s+p.y*c;
|
||||
|
||||
rv.x = p.x * c + p.y * s;
|
||||
rv.y = -p.x * s + p.y * c;
|
||||
rv.z = p.z;
|
||||
|
||||
return rv;
|
||||
@ -764,7 +743,8 @@ static func rotate3d(p : Vector3, a : Vector3) -> Vector3:
|
||||
return rv
|
||||
|
||||
#vec3 circle_repeat_transform(vec3 p, float count) {
|
||||
# float r = 6.28/count;float pa = atan(p.x, p.y);
|
||||
# float r = 6.28/count;
|
||||
# float pa = atan(p.x, p.y);
|
||||
# float a = mod(pa+0.5*r, r)-0.5*r;
|
||||
# vec3 rv;
|
||||
# float c = cos(a-pa);
|
||||
@ -776,8 +756,16 @@ static func rotate3d(p : Vector3, a : Vector3) -> Vector3:
|
||||
#}
|
||||
|
||||
static func circle_repeat_transform(p : Vector3, count : float) -> Vector3:
|
||||
#todo
|
||||
return Vector3()
|
||||
var r : float = 6.28 / count
|
||||
var pa : float = atan2(p.x, p.y)
|
||||
var a : float = Commons.modf(pa + 0.5 * r, r) - 0.5 * r
|
||||
var rv : Vector3 = Vector3()
|
||||
var c : float = cos(a-pa)
|
||||
var s : float = sin(a-pa)
|
||||
rv.x = p.x * c + p.y * s
|
||||
rv.y = -p.x * s + p.y * c
|
||||
rv.z = p.z
|
||||
return rv
|
||||
|
||||
#todo this needs to be solved
|
||||
static func sdf3d_input(p : Vector3) -> Vector2:
|
||||
|
@ -0,0 +1,59 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
var SDF3D = preload("res://addons/mat_maker_gd/nodes/common/sdf3d.gd")
|
||||
|
||||
export(Resource) var input : Resource
|
||||
export(Resource) var output : Resource
|
||||
export(int) var count : int = 5
|
||||
|
||||
func _init_properties():
|
||||
if !input:
|
||||
input = MMNodeUniversalProperty.new()
|
||||
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2
|
||||
|
||||
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||
# input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2
|
||||
input.slot_name = ">>> Input "
|
||||
|
||||
if !input.is_connected("changed", self, "on_input_changed"):
|
||||
input.connect("changed", self, "on_input_changed")
|
||||
|
||||
if !output:
|
||||
output = MMNodeUniversalProperty.new()
|
||||
output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2
|
||||
|
||||
output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||
output.slot_name = ">>> Output >>>"
|
||||
output.get_value_from_owner = true
|
||||
|
||||
register_input_property(input)
|
||||
register_output_property(output)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_label_universal(input)
|
||||
mm_graph_node.add_slot_label_universal(output)
|
||||
|
||||
mm_graph_node.add_slot_int("get_count", "set_count", "Count")
|
||||
|
||||
func get_property_value_sdf3d(uv3 : Vector3) -> Vector2:
|
||||
#todo make seed a class variable probably into MMNode
|
||||
|
||||
var new_uv : Vector3 = SDF3D.circle_repeat_transform(uv3, count)
|
||||
|
||||
return input.get_value_sdf3d(new_uv)
|
||||
|
||||
#count
|
||||
func get_count() -> int:
|
||||
return count
|
||||
|
||||
func set_count(val : int) -> void:
|
||||
count = val
|
||||
|
||||
emit_changed()
|
||||
output.emit_changed()
|
||||
|
||||
func on_input_changed() -> void:
|
||||
emit_changed()
|
||||
output.emit_changed()
|
71
game/addons/mat_maker_gd/nodes/sdf3d/sdf3d_op_repeat.gd
Normal file
71
game/addons/mat_maker_gd/nodes/sdf3d/sdf3d_op_repeat.gd
Normal file
@ -0,0 +1,71 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
var SDF3D = preload("res://addons/mat_maker_gd/nodes/common/sdf3d.gd")
|
||||
|
||||
export(Resource) var input : Resource
|
||||
export(Resource) var output : Resource
|
||||
export(Vector2) var col_row : Vector2 = Vector2(3, 3)
|
||||
export(float) var rotation : float = 0.3
|
||||
|
||||
func _init_properties():
|
||||
if !input:
|
||||
input = MMNodeUniversalProperty.new()
|
||||
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2
|
||||
|
||||
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||
# input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2
|
||||
input.slot_name = ">>> Input "
|
||||
|
||||
if !input.is_connected("changed", self, "on_input_changed"):
|
||||
input.connect("changed", self, "on_input_changed")
|
||||
|
||||
if !output:
|
||||
output = MMNodeUniversalProperty.new()
|
||||
output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2
|
||||
|
||||
output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||
output.slot_name = ">>> Output >>>"
|
||||
output.get_value_from_owner = true
|
||||
|
||||
register_input_property(input)
|
||||
register_output_property(output)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_label_universal(input)
|
||||
mm_graph_node.add_slot_label_universal(output)
|
||||
|
||||
mm_graph_node.add_slot_vector2("get_col_row", "set_col_row", "Col,Row", 1)
|
||||
mm_graph_node.add_slot_float("get_rotation", "set_rotation", "Rotation", 0.01)
|
||||
|
||||
func get_property_value_sdf3d(uv3 : Vector3) -> Vector2:
|
||||
#todo make seed a class variable probably into MMNode
|
||||
|
||||
var new_uv : Vector3 = SDF3D.sdf3d_repeat(uv3, col_row, rotation, 1)
|
||||
|
||||
return input.get_value_sdf3d(new_uv)
|
||||
|
||||
#col_row
|
||||
func get_col_row() -> Vector2:
|
||||
return col_row
|
||||
|
||||
func set_col_row(val : Vector2) -> void:
|
||||
col_row = val
|
||||
|
||||
emit_changed()
|
||||
output.emit_changed()
|
||||
|
||||
#rotation
|
||||
func get_rotation() -> float:
|
||||
return rotation
|
||||
|
||||
func set_rotation(val : float) -> void:
|
||||
rotation = val
|
||||
|
||||
emit_changed()
|
||||
output.emit_changed()
|
||||
|
||||
func on_input_changed() -> void:
|
||||
emit_changed()
|
||||
output.emit_changed()
|
Loading…
Reference in New Issue
Block a user