mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Added sd show and sd shape circle nodes.
This commit is contained in:
parent
47cb1b8086
commit
bcd0fdbbb1
@ -24,12 +24,14 @@ func ensure_objs() -> void:
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_COLOR, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL)
|
||||
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_INT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_COLOR)
|
||||
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL)
|
||||
|
||||
@ -38,10 +40,10 @@ func ensure_objs() -> void:
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3)
|
||||
_graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_COLOR, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_COLOR)
|
||||
|
||||
_graph_edit.connect("connection_request", self, "on_graph_edit_connection_request")
|
||||
_graph_edit.connect("disconnection_request", self, "on_graph_edit_disconnection_request")
|
||||
|
||||
|
||||
func recreate() -> void:
|
||||
ensure_objs()
|
||||
|
@ -164,6 +164,16 @@ func add_slot_int(getter : String, setter : String, slot_name : String, prange :
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_label_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var l : Label = Label.new()
|
||||
l.text = property.slot_name
|
||||
|
||||
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", l)
|
||||
|
||||
properties[slot_idx].append(property)
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_int_universal(property : MMNodeUniversalProperty) -> int:
|
||||
var bc : VBoxContainer = VBoxContainer.new()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_resource type="Resource" load_steps=48 format=2]
|
||||
[gd_resource type="Resource" load_steps=55 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]
|
||||
@ -12,6 +12,8 @@
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/simple/image.gd" type="Script" id=10]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/filter/colorize.gd" type="Script" id=11]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/pattern/bricks.gd" type="Script" id=12]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_show.gd" type="Script" id=13]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_shape_circle.gd" type="Script" id=14]
|
||||
|
||||
[sub_resource type="Resource" id=3]
|
||||
script = ExtResource( 5 )
|
||||
@ -49,7 +51,7 @@ sides = 11
|
||||
radius = SubResource( 4 )
|
||||
edge = SubResource( 3 )
|
||||
|
||||
[sub_resource type="Resource" id=46]
|
||||
[sub_resource type="Resource" id=55]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 5
|
||||
default_int = 0
|
||||
@ -61,7 +63,7 @@ default_color = Color( 0, 0, 0, 1 )
|
||||
[sub_resource type="Resource" id=6]
|
||||
script = ExtResource( 6 )
|
||||
graph_position = Vector2( 300, -400 )
|
||||
image = SubResource( 46 )
|
||||
image = SubResource( 55 )
|
||||
postfix = "-test"
|
||||
|
||||
[sub_resource type="Resource" id=9]
|
||||
@ -325,7 +327,50 @@ folds = 0
|
||||
iterations = 3
|
||||
persistence = 0.5
|
||||
|
||||
[sub_resource type="Resource" id=47]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 5
|
||||
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=53]
|
||||
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=48]
|
||||
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( 53 )
|
||||
|
||||
[sub_resource type="Resource" id=49]
|
||||
script = ExtResource( 13 )
|
||||
graph_position = Vector2( 1280, -680 )
|
||||
image = SubResource( 47 )
|
||||
input = SubResource( 48 )
|
||||
bevel = 0.2
|
||||
base = 0.2
|
||||
|
||||
[sub_resource type="Resource" id=54]
|
||||
script = ExtResource( 14 )
|
||||
graph_position = Vector2( 1020, -680 )
|
||||
output = SubResource( 53 )
|
||||
center = Vector2( 0, 0 )
|
||||
radius = 0.4
|
||||
|
||||
[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 ) ]
|
||||
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 ) ]
|
||||
|
@ -811,50 +811,15 @@ const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
#sdshow.mmg
|
||||
#Creates a greyscale image from a shape described as a 2D Signed Distance Function
|
||||
|
||||
# "inputs": [
|
||||
# {
|
||||
# "default": "0.0",
|
||||
# "label": "",
|
||||
# "longdesc": "The input shape",
|
||||
# "name": "in",
|
||||
# "shortdesc": "Input",
|
||||
# "type": "sdf2d"
|
||||
# }
|
||||
# ],
|
||||
# "outputs": [
|
||||
# {
|
||||
# "f": "clamp($base-$in($uv)/max($bevel, 0.00001), 0.0, 1.0)",
|
||||
# "longdesc": "Shows the shape as a greyscale image",
|
||||
# "shortdesc": "Output",
|
||||
# "type": "f"
|
||||
# }
|
||||
# ],
|
||||
# "parameters": [
|
||||
# {
|
||||
# "control": "None",
|
||||
# "default": 0,
|
||||
# "label": "Bevel",
|
||||
# "longdesc": "The width of the gradient at the edges of the shape",
|
||||
# "max": 1,
|
||||
# "min": 0,
|
||||
# "name": "bevel",
|
||||
# "shortdesc": "Bevel",
|
||||
# "step": 0.01,
|
||||
# "type": "float"
|
||||
# },
|
||||
# {
|
||||
# "control": "None",
|
||||
# "default": 0,
|
||||
# "label": "Base",
|
||||
# "longdesc": "The base value of the output",
|
||||
# "max": 1,
|
||||
# "min": 0,
|
||||
# "name": "base",
|
||||
# "shortdesc": "Base",
|
||||
# "step": 0.01,
|
||||
# "type": "float"
|
||||
# }
|
||||
# ],
|
||||
#Output
|
||||
|
||||
#Output float (color) - Shows the shape as a greyscale image
|
||||
#clamp($base-$in($uv)/max($bevel, 0.00001), 0.0, 1.0)
|
||||
|
||||
#Input:
|
||||
#Input (sdf - shape), default: 0 - sdf2d - universal input
|
||||
#bevel, float, min 0, max 1, step 0.01, default 0
|
||||
#base, float, min 0, max 1, step 0.01, default 0
|
||||
|
||||
#----------------------
|
||||
#sdsmoothboolean.mmg
|
||||
|
@ -31,6 +31,7 @@ export(Vector3) var default_vector3 : Vector3
|
||||
export(Color) var default_color : Color
|
||||
export(Image) var default_image : Image
|
||||
|
||||
var get_value_from_owner : bool = false
|
||||
var force_override : bool = false
|
||||
#This is not exported on purpose!
|
||||
var override_image : Image
|
||||
@ -52,6 +53,9 @@ func _init():
|
||||
input_property.connect("changed", self, "on_input_property_changed")
|
||||
|
||||
func get_value(uv : Vector2):
|
||||
if get_value_from_owner:
|
||||
return get_owner_value(uv)
|
||||
|
||||
if !input_property:
|
||||
return get_default_value(uv)
|
||||
|
||||
@ -73,7 +77,25 @@ func get_value(uv : Vector2):
|
||||
|
||||
return input_property.get_value(uv)
|
||||
|
||||
func get_owner_value(uv : Vector2):
|
||||
if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT:
|
||||
return to_int(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT:
|
||||
return to_float(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2:
|
||||
return to_vector2(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3:
|
||||
return to_vector3(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR:
|
||||
return to_color(owner.get_property_value(uv))
|
||||
elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE:
|
||||
return to_color(owner.get_property_value(uv))
|
||||
|
||||
|
||||
func to_int(val) -> int:
|
||||
if val is int:
|
||||
return val
|
||||
|
||||
if val is float:
|
||||
return int(val)
|
||||
|
||||
@ -89,6 +111,9 @@ func to_int(val) -> int:
|
||||
return 0
|
||||
|
||||
func to_float(val) -> float:
|
||||
if val is float:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return float(val)
|
||||
|
||||
@ -104,6 +129,9 @@ func to_float(val) -> float:
|
||||
return 0.0
|
||||
|
||||
func to_vector2(val) -> Vector2:
|
||||
if val is Vector2:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return Vector2(val, val)
|
||||
|
||||
@ -119,6 +147,9 @@ func to_vector2(val) -> Vector2:
|
||||
return Vector2()
|
||||
|
||||
func to_vector3(val) -> Vector3:
|
||||
if val is Vector3:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return Vector3(val, val, val)
|
||||
|
||||
@ -134,6 +165,9 @@ func to_vector3(val) -> Vector3:
|
||||
return Vector3()
|
||||
|
||||
func to_color(val) -> Color:
|
||||
if val is Color:
|
||||
return val
|
||||
|
||||
if val is int:
|
||||
return Color(val, val, val, 1)
|
||||
|
||||
|
47
game/addons/mat_maker_gd/nodes/sdf2d/sd_shape_circle.gd
Normal file
47
game/addons/mat_maker_gd/nodes/sdf2d/sd_shape_circle.gd
Normal file
@ -0,0 +1,47 @@
|
||||
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 output : Resource
|
||||
export(Vector2) var center : Vector2 = Vector2(0, 0)
|
||||
export(float) var radius : float = 0.4
|
||||
|
||||
func _init_properties():
|
||||
if !output:
|
||||
output = MMNodeUniversalProperty.new()
|
||||
output.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
|
||||
|
||||
output.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||
output.slot_name = "Output"
|
||||
output.get_value_from_owner = true
|
||||
|
||||
register_output_property(output)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_label_universal(output)
|
||||
|
||||
mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01)
|
||||
mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01)
|
||||
|
||||
func get_property_value(uv : Vector2) -> float:
|
||||
return SDF2D.sdf_circle(uv, center, radius)
|
||||
|
||||
#center
|
||||
func get_center() -> Vector2:
|
||||
return center
|
||||
|
||||
func set_center(val : Vector2) -> void:
|
||||
center = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#radius
|
||||
func get_radius() -> float:
|
||||
return radius
|
||||
|
||||
func set_radius(val : float) -> void:
|
||||
radius = val
|
||||
|
||||
set_dirty(true)
|
67
game/addons/mat_maker_gd/nodes/sdf2d/sd_show.gd
Normal file
67
game/addons/mat_maker_gd/nodes/sdf2d/sd_show.gd
Normal file
@ -0,0 +1,67 @@
|
||||
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 image : Resource
|
||||
export(Resource) var input : Resource
|
||||
export(float) var bevel : float = 0
|
||||
export(float) var base : float = 0
|
||||
|
||||
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
|
||||
|
||||
if !input:
|
||||
input = MMNodeUniversalProperty.new()
|
||||
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
|
||||
|
||||
#for some reason this doesn't work, todo check
|
||||
# input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT
|
||||
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||
input.slot_name = "Input"
|
||||
|
||||
register_output_property(image)
|
||||
register_input_property(input)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_texture_universal(image)
|
||||
mm_graph_node.add_slot_label_universal(input)
|
||||
|
||||
mm_graph_node.add_slot_float("get_bevel", "set_bevel", "Bevel", 0.01)
|
||||
mm_graph_node.add_slot_float("get_base", "set_base", "Base", 0.01)
|
||||
|
||||
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 = input.get_value(uv)
|
||||
|
||||
#clamp($base-$in($uv)/max($bevel, 0.00001), 0.0, 1.0)
|
||||
var cf : float = clamp(base - f / max(bevel, 0.00001), 0.0, 1.0)
|
||||
|
||||
return Color(cf, cf, cf, 1)
|
||||
|
||||
#bevel
|
||||
func get_bevel() -> float:
|
||||
return bevel
|
||||
|
||||
func set_bevel(val : float) -> void:
|
||||
bevel = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#base
|
||||
func get_base() -> float:
|
||||
return base
|
||||
|
||||
func set_base(val : float) -> void:
|
||||
base = val
|
||||
|
||||
set_dirty(true)
|
Loading…
Reference in New Issue
Block a user