Finish up the new mat_maker_gd input/output notification api and made shape use it. Now shape's image updates whenever a property changes.

This commit is contained in:
Relintai 2021-10-09 14:04:09 +02:00
parent 7fd3ccd4ad
commit c816f0e0fe
6 changed files with 61 additions and 23 deletions

View File

@ -37,6 +37,8 @@ func recreate() -> void:
_graph_edit.add_child(gn)
#connect them
_material.render()
func set_mmmaterial(object : MMMateial):
_material = object

View File

@ -1,4 +1,4 @@
[gd_resource type="Resource" load_steps=11 format=2]
[gd_resource type="Resource" load_steps=12 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/perlin.gd" type="Script" id=2]
@ -24,7 +24,16 @@ refresh = false
script = ExtResource( 5 )
default_type = 1
default_int = 0
default_float = 0.3
default_float = 0.8
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=6]
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 )
@ -33,7 +42,7 @@ default_color = Color( 0, 0, 0, 1 )
script = ExtResource( 5 )
default_type = 1
default_int = 0
default_float = 0.4
default_float = 0.45
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
@ -41,8 +50,9 @@ default_color = Color( 0, 0, 0, 1 )
[sub_resource type="Resource" id=5]
script = ExtResource( 4 )
graph_position = Vector2( -240, -340 )
shape_type = 2
sides = 6
image = SubResource( 6 )
shape_type = 3
sides = 4
radius = SubResource( 4 )
edge = SubResource( 3 )

View File

@ -5,9 +5,14 @@ extends Resource
export(Vector2) var image_size : Vector2 = Vector2(128, 128)
export(Array) var nodes : Array
func _init():
for n in nodes:
n.connect("changed", self, "on_node_changed")
var initialized : bool = false
func initialize():
if !initialized:
initialized = true
for n in nodes:
n.connect("changed", self, "on_node_changed")
func add_node(node : MMNode) -> void:
nodes.append(node)
@ -24,6 +29,9 @@ func remove_node(node : MMNode) -> void:
emit_changed()
func render() -> void:
if !initialized:
initialize()
var did_render : bool = true
while did_render:

View File

@ -5,6 +5,7 @@ extends Resource
export(Vector2) var graph_position : Vector2 = Vector2()
var input_properties : Array
var output_properties : Array
var properties_initialized : bool = false
@ -21,17 +22,17 @@ func render(material) -> bool:
_render(material)
dirty = false
return true
#MMMateial
func _render(material) -> void:
pass
func render_image(material) -> ImageTexture:
func render_image(material) -> Image:
var image : Image = Image.new()
image.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
var tex : ImageTexture = ImageTexture.new()
image.lock()
@ -49,10 +50,8 @@ func render_image(material) -> ImageTexture:
image.set_pixel(x, y, col)
image.unlock()
tex.create_from_image(image)
return tex
return image
func get_value_for(uv : Vector2, pseed : int) -> Color:
return Color()
@ -84,7 +83,8 @@ func set_graph_position(pos : Vector2) -> void:
func register_input_property(prop : MMNodeUniversalProperty) -> void:
prop.owner = self
prop.connect("changed", self, "on_input_property_changed")
if !prop.is_connected("changed", self, "on_input_property_changed"):
prop.connect("changed", self, "on_input_property_changed")
input_properties.append(prop)
@ -92,10 +92,22 @@ func unregister_input_property(prop : MMNodeUniversalProperty) -> void:
if prop.owner == self:
prop.owner = null
prop.disconnect("changed", self, "on_input_property_changed")
if prop.is_connected("changed", self, "on_input_property_changed"):
prop.disconnect("changed", self, "on_input_property_changed")
input_properties.erase(prop)
func register_output_property(prop : MMNodeUniversalProperty) -> void:
prop.owner = self
output_properties.append(prop)
func unregister_output_property(prop : MMNodeUniversalProperty) -> void:
if prop.owner == self:
prop.owner = null
output_properties.erase(prop)
func set_dirty(val : bool) -> void:
var changed : bool = val != dirty

View File

@ -14,7 +14,7 @@ func get_value_for(uv : Vector2, pseed : int) -> Color:
return NoisePerlin.perlinc(uv, scale, iterations, persistence, pseed)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, "render_image", "")
#mm_graph_node.add_slot_texture(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, "render_image", "")
mm_graph_node.add_slot_int(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_iterations", "set_iterations", "iterations")#, Vector2(1, 10))
mm_graph_node.add_slot_float(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_persistence", "set_persistence", "persistence", 0.05)#, Vector2(0, 1))
mm_graph_node.add_slot_vector2(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_scale", "set_scale", "scale", 1)#, Vector2(1, 32))

View File

@ -41,17 +41,23 @@ func _init_properties():
edge.slot_name = "edge"
edge.value_step = 0.05
#this will end up generating the image
#maybe whis should be automaticly done whenn added into material
#emit_changed()
register_input_property(radius)
register_input_property(edge)
register_output_property(image)
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, "render_image", "")
mm_graph_node.add_slot_texture_universal(image)
mm_graph_node.add_slot_enum(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_shape_typoe", "set_shape_typoe", "shape_type", [ "Circle", "Polygon", "Star", "Curved Star", "Rays" ])
mm_graph_node.add_slot_int(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_sides", "set_sides", "sides")#, Vector2(1, 10))
mm_graph_node.add_slot_float_universal(radius)
mm_graph_node.add_slot_float_universal(edge)
func _render(material) -> void:
var img : Image = render_image(material)
image.set_value(img)
func get_value_for(uv : Vector2, pseed : int) -> Color:
var c : float = 0
@ -74,7 +80,7 @@ func get_shape_typoe() -> int:
func set_shape_typoe(val : int) -> void:
shape_type = val
emit_changed()
set_dirty(true)
func get_sides() -> int:
return sides
@ -82,4 +88,4 @@ func get_sides() -> int:
func set_sides(val : int) -> void:
sides = val
emit_changed()
set_dirty(true)