sd_op_smooth_bool node.

This commit is contained in:
Relintai 2021-10-21 21:41:18 +02:00
parent c849944f2b
commit d4da602f65
2 changed files with 132 additions and 7 deletions

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=81 format=2]
[gd_resource type="Resource" load_steps=86 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]
@ -21,6 +21,7 @@
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_tf_rotate.gd" type="Script" id=19]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_tf_scale.gd" type="Script" id=20]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_bool.gd" type="Script" id=21]
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_smooth_bool.gd" type="Script" id=22]
[sub_resource type="Resource" id=3]
script = ExtResource( 5 )
@ -343,7 +344,7 @@ default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=75]
[sub_resource type="Resource" id=79]
script = ExtResource( 5 )
default_type = 1
default_int = 0
@ -360,7 +361,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( 75 )
input_property = SubResource( 79 )
[sub_resource type="Resource" id=49]
script = ExtResource( 13 )
@ -506,7 +507,7 @@ input_property = SubResource( 53 )
script = ExtResource( 20 )
graph_position = Vector2( 1340, -740 )
output = SubResource( 72 )
scale = 1.83
scale = 1.8
[sub_resource type="Resource" id=76]
script = ExtResource( 5 )
@ -516,7 +517,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=77]
script = ExtResource( 5 )
@ -526,7 +526,15 @@ 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( 72 )
[sub_resource type="Resource" id=75]
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 )
[sub_resource type="Resource" id=78]
script = ExtResource( 21 )
@ -536,7 +544,36 @@ input2 = SubResource( 77 )
output = SubResource( 75 )
operation = 2
[sub_resource type="Resource" id=80]
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( 59 )
[sub_resource type="Resource" id=81]
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( 72 )
[sub_resource type="Resource" id=82]
script = ExtResource( 22 )
graph_position = Vector2( 1400, -1280 )
input1 = SubResource( 80 )
input2 = SubResource( 81 )
output = SubResource( 79 )
operation = 1
smoothness = 0.04
[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 ) ]
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 ) ]

View File

@ -0,0 +1,88 @@
tool
extends MMNode
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
var SDF2D = preload("res://addons/mat_maker_gd/nodes/common/sdf2d.gd")
export(Resource) var input1 : Resource
export(Resource) var input2 : Resource
export(Resource) var output : Resource
export(int, "Union,Substraction,Intersection") var operation : int = 0
export(float) var smoothness : float = 0.15
func _init_properties():
if !input1:
input1 = MMNodeUniversalProperty.new()
input1.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
input1.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
# input1.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
input1.slot_name = ">>> Input 1 "
if !input1.is_connected("changed", self, "on_input_changed"):
input1.connect("changed", self, "on_input_changed")
if !input2:
input2 = MMNodeUniversalProperty.new()
input2.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
input2.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
# input2.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
input2.slot_name = ">>> Input 2 "
if !input2.is_connected("changed", self, "on_input_changed"):
input2.connect("changed", self, "on_input_changed")
if !output:
output = MMNodeUniversalProperty.new()
output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
# output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
output.slot_name = " Output >>>"
output.get_value_from_owner = true
register_input_property(input1)
register_input_property(input2)
register_output_property(output)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_label_universal(input1)
mm_graph_node.add_slot_label_universal(input2)
mm_graph_node.add_slot_label_universal(output)
mm_graph_node.add_slot_enum("get_operation", "set_operation", "Operation", [ "Union", "Substraction", "Intersection" ])
mm_graph_node.add_slot_float("get_smoothness", "set_smoothness", "Smoothness", 0.01)
func get_property_value(uv : Vector2) -> float:
if operation == 0:
return SDF2D.sdf_smooth_boolean_union(input1.get_value(uv), input2.get_value(uv), smoothness)
elif operation == 1:
return SDF2D.sdf_smooth_boolean_substraction(input1.get_value(uv), input2.get_value(uv), smoothness)
elif operation == 2:
return SDF2D.sdf_smooth_boolean_intersection(input1.get_value(uv), input2.get_value(uv), smoothness)
return 0.0
#operation
func get_operation() -> int:
return operation
func set_operation(val : int) -> void:
operation = val
emit_changed()
output.emit_changed()
#smoothness
func get_smoothness() -> float:
return smoothness
func set_smoothness(val : float) -> void:
smoothness = val
emit_changed()
output.emit_changed()
func on_input_changed() -> void:
emit_changed()
output.emit_changed()