From 3fbf9713f74b0cac07332962b33d49d4a8d6cb11 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 18 Jun 2022 00:19:06 +0200 Subject: [PATCH] Cleaned up the patterns. --- modules/material_maker/SCsub | 10 + modules/material_maker/config.py | 10 + .../material_maker/nodes/pattern/beehive.cpp | 286 +++--- .../material_maker/nodes/pattern/beehive.h | 62 +- .../material_maker/nodes/pattern/bricks.cpp | 857 ++++++++---------- modules/material_maker/nodes/pattern/bricks.h | 152 ++-- .../material_maker/nodes/pattern/iching.cpp | 116 +-- modules/material_maker/nodes/pattern/iching.h | 48 +- .../material_maker/nodes/pattern/pattern.cpp | 251 ++--- .../material_maker/nodes/pattern/pattern.h | 81 +- .../material_maker/nodes/pattern/runes.cpp | 116 +-- modules/material_maker/nodes/pattern/runes.h | 48 +- .../nodes/pattern/scratches.cpp | 270 ++---- .../material_maker/nodes/pattern/scratches.h | 88 +- .../nodes/pattern/sine_wave.cpp | 192 ++-- .../material_maker/nodes/pattern/sine_wave.h | 68 +- .../material_maker/nodes/pattern/truchet.cpp | 173 ++-- .../material_maker/nodes/pattern/truchet.h | 59 +- .../material_maker/nodes/pattern/weave.cpp | 356 +++----- modules/material_maker/nodes/pattern/weave.h | 79 +- modules/material_maker/register_types.cpp | 29 + 21 files changed, 1329 insertions(+), 2022 deletions(-) diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index 606ef228d..f5ac524bb 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -112,6 +112,16 @@ sources = [ "nodes/sdf2d/sd_op_circle_repeat.cpp", "nodes/sdf2d/sd_op_bool.cpp", "nodes/sdf2d/sd_op_annular_shape.cpp", + + "nodes/pattern/weave.cpp", + "nodes/pattern/truchet.cpp", + "nodes/pattern/sine_wave.cpp", + "nodes/pattern/scratches.cpp", + "nodes/pattern/runes.cpp", + "nodes/pattern/pattern.cpp", + "nodes/pattern/iching.cpp", + "nodes/pattern/bricks.cpp", + "nodes/pattern/beehive.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 4ce50c6c0..b1597b044 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -82,6 +82,16 @@ def get_doc_classes(): "MMSdOpCircleRepeat", "MMSdOpBool", "MMSdOpAnnularShape", + + "MMWeave", + "MMTruchet", + "MMSineWave", + "MMScratches", + "MMRunes", + "MMPattern", + "MMIching", + "MMBricks", + "MMBeehive", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/pattern/beehive.cpp b/modules/material_maker/nodes/pattern/beehive.cpp index e94eacccb..03d714f84 100644 --- a/modules/material_maker/nodes/pattern/beehive.cpp +++ b/modules/material_maker/nodes/pattern/beehive.cpp @@ -1,201 +1,161 @@ #include "beehive.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Beehive::get_out_main() { - return out_main; +Ref MMBeehive::get_out_main() { + return out_main; } -void Beehive::set_out_main(const Ref &val) { -out_main = val; +void MMBeehive::set_out_main(const Ref &val) { + out_main = val; } - -Ref Beehive::get_out_random_color() { - return out_random_color; +Ref MMBeehive::get_out_random_color() { + return out_random_color; } -void Beehive::set_out_random_color(const Ref &val) { -out_random_color = val; +void MMBeehive::set_out_random_color(const Ref &val) { + out_random_color = val; } - -Ref Beehive::get_out_uv_map() { - return out_uv_map; +Ref MMBeehive::get_out_uv_map() { + return out_uv_map; } -void Beehive::set_out_uv_map(const Ref &val) { -out_uv_map = val; +void MMBeehive::set_out_uv_map(const Ref &val) { + out_uv_map = val; } - -Vector2 Beehive::get_size() { - return size; +Vector2 MMBeehive::get_size() { + return size; } -void Beehive::set_size(const Vector2 &val) { -size = val; +void MMBeehive::set_size(const Vector2 &val) { + size = val; + set_dirty(true); } +void MMBeehive::_init_properties() { + if (!out_main.is_valid()) { + out_main.instance(); + out_main->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + out_main->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - //tool; - //export(Resource) ; - Ref out_main; - //export(Resource) ; - Ref out_random_color; - //export(Resource) ; - Ref out_uv_map; - //export(Vector2) ; - Vector2 size = Vector2(4, 4); + if (!out_random_color.is_valid()) { + out_random_color.instance(); + out_random_color->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Beehive::_init_properties() { + out_random_color->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - if (!out_main) { - out_main = MMNodeUniversalProperty.new(); - out_main.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + if (!out_uv_map.is_valid()) { + out_uv_map.instance(); + out_uv_map->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_uv_map->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + register_output_property(out_main); + register_output_property(out_random_color); + register_output_property(out_uv_map); } - out_main.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_random_color) { - out_random_color = MMNodeUniversalProperty.new(); - out_random_color.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +void MMBeehive::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(out_main); + mm_graph_node->add_slot_texture_universal(out_random_color); + mm_graph_node->add_slot_texture_universal(out_uv_map); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_vector2("get_size", "set_size", "Size"); } - out_random_color.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; +void MMBeehive::_render(const Ref &material) { + Ref main_pattern; + Ref random_color; + Ref uv_map; - if (!out_uv_map) { - out_uv_map = MMNodeUniversalProperty.new(); - out_uv_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + main_pattern.instance(); + random_color.instance(); + uv_map.instance(); + + main_pattern->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + random_color->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + uv_map->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + + main_pattern->lock(); + random_color->lock(); + uv_map->lock(); + + float w = material->image_size.x; + float h = material->image_size.y; + float pseed = Math::randf() + Math::rand(); + + for (int x = 0; x < material->image_size.x; ++x) { //x in range(material.image_size.x) + for (int y = 0; y < material->image_size.y; ++y) { //y in range(material.image_size.y) + Vector2 uv = Vector2(x / w, y / h); + float ps = 1.0 / float(pseed); + //vec2 $(name_uv)_uv = $uv*vec2($sx, $sy*1.73205080757); + //vec4 $(name_uv)_center = beehive_center($(name_uv)_uv); + Vector2 beehive_uv = uv * size; + Color beehive_uv_center = MMAlgos::beehive_center(beehive_uv); + //Output (float) - Shows the greyscale pattern; + //1.0-2.0*beehive_dist($(name_uv)_center.xy); + float f = 1.0 - 2.0 * MMAlgos::beehive_dist(Vector2(beehive_uv_center.r, beehive_uv_center.g)); + Color main_pattern_col = Color(f, f, f, 1); + //Random color (rgb) - Shows a random color for each hexagonal tile; + //rand3(fract($(name_uv)_center.zw/vec2($sx, $sy))+vec2(float($seed))); + Vector3 rcv3 = MMAlgos::rand3(MMAlgos::fractv2(Vector2(beehive_uv_center.b, beehive_uv_center.a) / size) + Vector2(ps, ps)); + Color random_color_col = Color(rcv3.x, rcv3.y, rcv3.z, 1); + //UV map (rgb) - Shows an UV map to be connected to the UV map port of the Custom UV node; + //vec3(vec2(0.5)+$(name_uv)_center.xy, rand(fract($(name_uv)_center.zw/vec2($sx, $sy))+vec2(float($seed)))); + Vector2 uvm1 = Vector2(0.5, 0.5) + Vector2(beehive_uv_center.r, beehive_uv_center.g); + Vector2 uvm2 = MMAlgos::rand2(MMAlgos::fractv2(Vector2(beehive_uv_center.b, beehive_uv_center.a) / size) + Vector2(ps, ps)); + Color uv_map_col = Color(uvm1.x, uvm1.y, uvm2.x, 1); + + main_pattern->set_pixel(x, y, main_pattern_col); + random_color->set_pixel(x, y, random_color_col); + uv_map->set_pixel(x, y, uv_map_col); + } + } + + main_pattern->unlock(); + random_color->unlock(); + uv_map->unlock(); + + out_main->set_value(main_pattern); + out_random_color->set_value(random_color); + out_uv_map->set_value(uv_map); } - out_uv_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(out_main); - register_output_property(out_random_color); - register_output_property(out_uv_map); +Color MMBeehive::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); } - - void Beehive::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(out_main); - mm_graph_node.add_slot_texture_universal(out_random_color); - mm_graph_node.add_slot_texture_universal(out_uv_map); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_vector2("get_size", "set_size", "Size"); +MMBeehive::MMBeehive() { + size = Vector2(4, 4); } - - void Beehive::_render(const Variant &material) { - Ref main_pattern = Image.new(); - Ref random_color = Image.new(); - Ref uv_map = Image.new(); - main_pattern.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - random_color.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - uv_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - main_pattern.lock(); - random_color.lock(); - uv_map.lock(); - float w = material.image_size.x; - float h = material.image_size.y; - float pseed = randf() + randi(); - - for (int x = 0; x < material.image_size.x; ++x) { //x in range(material.image_size.x) - - for (int y = 0; y < material.image_size.y; ++y) { //y in range(material.image_size.y) - Vector2 uv = Vector2(x / w, y / h); - float ps = 1.0 / float(pseed); - //vec2 $(name_uv)_uv = $uv*vec2($sx, $sy*1.73205080757); - //vec4 $(name_uv)_center = beehive_center($(name_uv)_uv); - Vector2 beehive_uv = uv * size; - Color beehive_uv_center = MMAlgos.beehive_center(beehive_uv); - //Output (float) - Shows the greyscale pattern; - //1.0-2.0*beehive_dist($(name_uv)_center.xy); - float f = 1.0 - 2.0 * MMAlgos.beehive_dist(Vector2(beehive_uv_center.r, beehive_uv_center.g)); - Color main_pattern_col = Color(f, f, f, 1); - //Random color (rgb) - Shows a random color for each hexagonal tile; - //rand3(fract($(name_uv)_center.zw/vec2($sx, $sy))+vec2(float($seed))); - Vector3 rcv3 = MMAlgos.rand3(MMAlgos.fractv2(Vector2(beehive_uv_center.b, beehive_uv_center.a) / size) + Vector2(ps, ps)); - Color random_color_col = Color(rcv3.x, rcv3.y, rcv3.z, 1); - //UV map (rgb) - Shows an UV map to be connected to the UV map port of the Custom UV node; - //vec3(vec2(0.5)+$(name_uv)_center.xy, rand(fract($(name_uv)_center.zw/vec2($sx, $sy))+vec2(float($seed)))); - Vector2 uvm1 = Vector2(0.5, 0.5) + Vector2(beehive_uv_center.r, beehive_uv_center.g); - Vector2 uvm2 = MMAlgos.rand2(MMAlgos.fractv2(Vector2(beehive_uv_center.b, beehive_uv_center.a) / size) + Vector2(ps, ps)); - Color uv_map_col = Color(uvm1.x, uvm1.y, uvm2.x, 1); - main_pattern.set_pixel(x, y, main_pattern_col); - random_color.set_pixel(x, y, random_color_col); - uv_map.set_pixel(x, y, uv_map_col); +MMBeehive::~MMBeehive() { } +void MMBeehive::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_main"), &MMBeehive::get_out_main); + ClassDB::bind_method(D_METHOD("set_out_main", "value"), &MMBeehive::set_out_main); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_main", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_main", "get_out_main"); + + ClassDB::bind_method(D_METHOD("get_out_random_color"), &MMBeehive::get_out_random_color); + ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &MMBeehive::set_out_random_color); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_random_color", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_random_color", "get_out_random_color"); + + ClassDB::bind_method(D_METHOD("get_out_uv_map"), &MMBeehive::get_out_uv_map); + ClassDB::bind_method(D_METHOD("set_out_uv_map", "value"), &MMBeehive::set_out_uv_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_uv_map", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_uv_map", "get_out_uv_map"); + + ClassDB::bind_method(D_METHOD("get_size"), &MMBeehive::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMBeehive::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); } - - main_pattern.unlock(); - random_color.unlock(); - uv_map.unlock(); - out_main.set_value(main_pattern); - out_random_color.set_value(random_color); - out_uv_map.set_value(uv_map); -} - - - Color Beehive::_get_value_for(const Vector2 &uv, const int pseed) { - return Color(); -} - - //size; - - Vector2 Beehive::get_size() { - return size; -} - - - void Beehive::set_size(const Vector2 &val) { - size = val; - set_dirty(true); -} - -} - - Beehive::Beehive() { - out_main; - out_random_color; - out_uv_map; - size = Vector2(4, 4); - } - - Beehive::~Beehive() { - } - - - static void Beehive::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_out_main"), &Beehive::get_out_main); - ClassDB::bind_method(D_METHOD("set_out_main", "value"), &Beehive::set_out_main); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_main", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_main", "get_out_main"); - - - ClassDB::bind_method(D_METHOD("get_out_random_color"), &Beehive::get_out_random_color); - ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &Beehive::set_out_random_color); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_random_color", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_random_color", "get_out_random_color"); - - - ClassDB::bind_method(D_METHOD("get_out_uv_map"), &Beehive::get_out_uv_map); - ClassDB::bind_method(D_METHOD("set_out_uv_map", "value"), &Beehive::set_out_uv_map); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_uv_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_uv_map", "get_out_uv_map"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Beehive::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Beehive::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Beehive::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Beehive::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Beehive::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Beehive::_get_value_for); - ClassDB::bind_method(D_METHOD("get_size"), &Beehive::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Beehive::set_size); - - } - - - diff --git a/modules/material_maker/nodes/pattern/beehive.h b/modules/material_maker/nodes/pattern/beehive.h index c387ece2f..a45c024c4 100644 --- a/modules/material_maker/nodes/pattern/beehive.h +++ b/modules/material_maker/nodes/pattern/beehive.h @@ -1,48 +1,40 @@ -#ifndef BEEHIVE_H -#define BEEHIVE_H +#ifndef MM_BEEHIVE_H +#define MM_BEEHIVE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Beehive : public MMNode { - GDCLASS(Beehive, MMNode); +class MMBeehive : public MMNode { + GDCLASS(MMBeehive, MMNode); - public: +public: + Ref get_out_main(); + void set_out_main(const Ref &val); - Ref get_out_main(); - void set_out_main(const Ref &val); + Ref get_out_random_color(); + void set_out_random_color(const Ref &val); - Ref get_out_random_color(); - void set_out_random_color(const Ref &val); + Ref get_out_uv_map(); + void set_out_uv_map(const Ref &val); - Ref get_out_uv_map(); - void set_out_uv_map(const Ref &val); + Vector2 get_size(); + void set_size(const Vector2 &val); - Vector2 get_size(); - void set_size(const Vector2 &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - Vector2 get_size(); - void set_size(const Vector2 &val); + MMBeehive(); + ~MMBeehive(); - Beehive(); - ~Beehive(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref out_main; - //export(Resource) - Ref out_random_color; - //export(Resource) - Ref out_uv_map; - //export(Vector2) - Vector2 size = Vector2(4, 4); - //size + Ref out_main; + Ref out_random_color; + Ref out_uv_map; + Vector2 size; }; - #endif diff --git a/modules/material_maker/nodes/pattern/bricks.cpp b/modules/material_maker/nodes/pattern/bricks.cpp index 45ca02071..056cfc384 100644 --- a/modules/material_maker/nodes/pattern/bricks.cpp +++ b/modules/material_maker/nodes/pattern/bricks.cpp @@ -1,584 +1,441 @@ #include "bricks.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Bricks::get_out_bricks_pattern() { - return out_bricks_pattern; +Ref MMBricks::get_out_bricks_pattern() { + return out_bricks_pattern; } -void Bricks::set_out_bricks_pattern(const Ref &val) { -out_bricks_pattern = val; +void MMBricks::set_out_bricks_pattern(const Ref &val) { + out_bricks_pattern = val; } - -Ref Bricks::get_out_random_color() { - return out_random_color; +Ref MMBricks::get_out_random_color() { + return out_random_color; } -void Bricks::set_out_random_color(const Ref &val) { -out_random_color = val; +void MMBricks::set_out_random_color(const Ref &val) { + out_random_color = val; } - -Ref Bricks::get_out_position_x() { - return out_position_x; +Ref MMBricks::get_out_position_x() { + return out_position_x; } -void Bricks::set_out_position_x(const Ref &val) { -out_position_x = val; +void MMBricks::set_out_position_x(const Ref &val) { + out_position_x = val; } - -Ref Bricks::get_out_position_y() { - return out_position_y; +Ref MMBricks::get_out_position_y() { + return out_position_y; } -void Bricks::set_out_position_y(const Ref &val) { -out_position_y = val; +void MMBricks::set_out_position_y(const Ref &val) { + out_position_y = val; } - -Ref Bricks::get_out_brick_uv() { - return out_brick_uv; +Ref MMBricks::get_out_brick_uv() { + return out_brick_uv; } -void Bricks::set_out_brick_uv(const Ref &val) { -out_brick_uv = val; +void MMBricks::set_out_brick_uv(const Ref &val) { + out_brick_uv = val; } - -Ref Bricks::get_out_corner_uv() { - return out_corner_uv; +Ref MMBricks::get_out_corner_uv() { + return out_corner_uv; } -void Bricks::set_out_corner_uv(const Ref &val) { -out_corner_uv = val; +void MMBricks::set_out_corner_uv(const Ref &val) { + out_corner_uv = val; } - -Ref Bricks::get_out_direction() { - return out_direction; +Ref MMBricks::get_out_direction() { + return out_direction; } -void Bricks::set_out_direction(const Ref &val) { -out_direction = val; +void MMBricks::set_out_direction(const Ref &val) { + out_direction = val; } - -int Bricks::get_type() const { - return type; +int MMBricks::get_type() const { + return type; } -void Bricks::set_type(const int val) { -type = val; +void MMBricks::set_type(const int val) { + type = val; + set_dirty(true); } - -int Bricks::get_repeat() const { - return repeat; +int MMBricks::get_repeat() const { + return repeat; } -void Bricks::set_repeat(const int val) { -repeat = val; +void MMBricks::set_repeat(const int val) { + repeat = val; + set_dirty(true); } - -Vector2 Bricks::get_col_row() { - return col_row; +Vector2 MMBricks::get_col_row() { + return col_row; } -void Bricks::set_col_row(const Vector2 &val) { -col_row = val; +void MMBricks::set_col_row(const Vector2 &val) { + col_row = val; + set_dirty(true); } - -float Bricks::get_offset() const { - return offset; +float MMBricks::get_offset() const { + return offset; } -void Bricks::set_offset(const float val) { -offset = val; +void MMBricks::set_offset(const float val) { + offset = val; + set_dirty(true); } - -Ref Bricks::get_mortar() { - return mortar; +Ref MMBricks::get_mortar() { + return mortar; } -void Bricks::set_mortar(const Ref &val) { -mortar = val; +void MMBricks::set_mortar(const Ref &val) { + mortar = val; } - -Ref Bricks::get_bevel() { - return bevel; +Ref MMBricks::get_bevel() { + return bevel; } -void Bricks::set_bevel(const Ref &val) { -bevel = val; +void MMBricks::set_bevel(const Ref &val) { + bevel = val; } - -Ref Bricks::get_roundness() { - return roundness; +Ref MMBricks::get_roundness() { + return roundness; } -void Bricks::set_roundness(const Ref &val) { -roundness = val; +void MMBricks::set_roundness(const Ref &val) { + roundness = val; } - -float Bricks::get_corner() const { - return corner; +float MMBricks::get_corner() const { + return corner; } -void Bricks::set_corner(const float val) { -corner = val; +void MMBricks::set_corner(const float val) { + corner = val; + set_dirty(true); } +void MMBricks::_init_properties() { + if (!out_bricks_pattern.is_valid()) { + out_bricks_pattern.instance(); + out_bricks_pattern->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + out_bricks_pattern->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - //tool; - //export(Resource) ; - Ref out_bricks_pattern; - //export(Resource) ; - Ref out_random_color; - //export(Resource) ; - Ref out_position_x; - //export(Resource) ; - Ref out_position_y; - //export(Resource) ; - Ref out_brick_uv; - //export(Resource) ; - Ref out_corner_uv; - //export(Resource) ; - Ref out_direction; - //export(int, "Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond") ; - int type = 0; - //export(int) ; - int repeat = 1; - //export(Vector2) ; - Vector2 col_row = Vector2(4, 4); - //export(float) ; - float offset = 0.5; - //export(Resource) ; - Ref mortar; - //export(Resource) ; - Ref bevel; - //export(Resource) ; - Ref roundness; - //export(float) ; - float corner = 0.3; + if (!out_random_color.is_valid()) { + out_random_color.instance(); + out_random_color->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Bricks::_init_properties() { + out_random_color->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - if (!out_bricks_pattern) { - out_bricks_pattern = MMNodeUniversalProperty.new(); - out_bricks_pattern.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + if (!out_position_x.is_valid()) { + out_position_x.instance(); + out_position_x->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_position_x->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!out_position_y.is_valid()) { + out_position_y.instance(); + out_position_y->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_position_y->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!out_brick_uv.is_valid()) { + out_brick_uv.instance(); + out_brick_uv->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_brick_uv->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!out_corner_uv.is_valid()) { + out_corner_uv.instance(); + out_corner_uv->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_corner_uv->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!out_direction.is_valid()) { + out_direction.instance(); + out_direction->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_direction->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!mortar.is_valid()) { + mortar.instance(); + mortar->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + mortar->set_default_value(0.1); + } + + mortar->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + mortar->set_slot_name("Mortar"); + mortar->set_value_step(0.01); + mortar->set_value_range(Vector2(0, 0.5)); + + if (!bevel.is_valid()) { + bevel.instance(); + bevel->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + bevel->set_default_value(0.1); + } + + bevel->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + bevel->set_slot_name("Bevel"); + bevel->set_value_step(0.01); + bevel->set_value_range(Vector2(0, 0.5)); + + if (!roundness.is_valid()) { + roundness.instance(); + roundness->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + roundness->set_default_value(0.1); + } + + roundness->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + roundness->set_slot_name("Roundness"); + roundness->set_value_step(0.01); + roundness->set_value_range(Vector2(0, 0.5)); + + register_output_property(out_bricks_pattern); + register_output_property(out_random_color); + register_output_property(out_position_x); + register_output_property(out_position_y); + register_output_property(out_brick_uv); + register_output_property(out_corner_uv); + register_output_property(out_direction); + register_input_property(mortar); + register_input_property(bevel); + register_input_property(roundness); } - out_bricks_pattern.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; +void MMBricks::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(out_bricks_pattern); + mm_graph_node->add_slot_texture_universal(out_random_color); + mm_graph_node->add_slot_texture_universal(out_position_x); + mm_graph_node->add_slot_texture_universal(out_position_y); + mm_graph_node->add_slot_texture_universal(out_brick_uv); + mm_graph_node->add_slot_texture_universal(out_corner_uv); + mm_graph_node->add_slot_texture_universal(out_direction); - if (!out_random_color) { - out_random_color = MMNodeUniversalProperty.new(); - out_random_color.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + Array arr; + arr.push_back("Running Bond"); + arr.push_back("Running Bond (2)"); + arr.push_back("HerringBone"); + arr.push_back("Basket Weave"); + arr.push_back("Spanish Bond"); + + mm_graph_node->add_slot_enum("get_type", "set_type", "Type", arr); + mm_graph_node->add_slot_int("get_repeat", "set_repeat", "Repeat"); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_vector2("get_col_row", "set_col_row", "Col, Row"); + mm_graph_node->add_slot_float("get_offset", "set_offset", "Offset"); + mm_graph_node->add_slot_float_universal(mortar); + mm_graph_node->add_slot_float_universal(bevel); + mm_graph_node->add_slot_float_universal(roundness); + mm_graph_node->add_slot_float("get_corner", "set_corner", "Corner"); } - out_random_color.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; +void MMBricks::_render(const Ref &material) { + Ref bricks_pattern; + Ref random_color; + Ref position_x; + Ref position_y; + Ref brick_uv; + Ref corner_uv; + Ref direction; - if (!out_position_x) { - out_position_x = MMNodeUniversalProperty.new(); - out_position_x.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + bricks_pattern.instance(); + random_color.instance(); + position_x.instance(); + position_y.instance(); + brick_uv.instance(); + corner_uv.instance(); + direction.instance(); + + bricks_pattern->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + random_color->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + position_x->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + position_y->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + brick_uv->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + corner_uv->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + direction->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + + bricks_pattern->lock(); + random_color->lock(); + position_x->lock(); + position_y->lock(); + brick_uv->lock(); + corner_uv->lock(); + direction->lock(); + + float w = material->image_size.x; + float h = material->image_size.y; + float pseed = Math::randf() + Math::rand(); + + for (int x = 0; x < material->image_size.x; ++x) { //x in range(material.image_size.x) + for (int y = 0; y < material->image_size.y; ++y) { //y in range(material.image_size.y) + Vector2 uv = Vector2(x / w, y / h); + //vec4 $(name_uv)_rect = bricks_$pattern($uv, vec2($columns, $rows), $repeat, $row_offset); + Color brick_rect = Color(); + //"Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond"; + + if (type == 0) { + brick_rect = MMAlgos::bricks_rb(uv, col_row, repeat, offset); + } else if (type == 1) { + brick_rect = MMAlgos::bricks_rb2(uv, col_row, repeat, offset); + } else if (type == 2) { + brick_rect = MMAlgos::bricks_hb(uv, col_row, repeat, offset); + } else if (type == 3) { + brick_rect = MMAlgos::bricks_bw(uv, col_row, repeat, offset); + } else if (type == 4) { + brick_rect = MMAlgos::bricks_sb(uv, col_row, repeat, offset); + } + + //vec4 $(name_uv) = brick($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.001, $bevel*$bevel_map($uv))); + Color brick = MMAlgos::brick(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar->get_value(uv), roundness->get_value(uv), MAX(0.001, float(bevel->get_value(uv)))); + //MMBricks pattern (float) - A greyscale image that shows the bricks pattern; + //$(name_uv).x; + Color bricks_pattern_col = Color(brick.r, brick.r, brick.r, 1); + //Random color (rgb) - A random color for each brick; + //brick_random_color($(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed)); + Vector3 brc = MMAlgos::brick_random_color(Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), 1 / float(pseed)); + Color random_color_col = Color(brc.x, brc.y, brc.z, 1); + //Position.x (float) - The position of each brick along the X axis",; + //$(name_uv).y; + Color position_x_col = Color(brick.g, brick.g, brick.g, 1); + //Position.y (float) - The position of each brick along the Y axis; + //$(name_uv).z; + Color position_y_col = Color(brick.b, brick.b, brick.b, 1); + //Brick UV (rgb) - An UV map output for each brick, to be connected to the Map input of a CustomUV node; + //brick_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed)); + Vector3 buv = MMAlgos::brick_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), pseed); + Color brick_uv_col = Color(buv.x, buv.y, buv.z, 1); + //Corner UV (rgb) - An UV map output for each brick corner, to be connected to the Map input of a CustomUV node; + //brick_corner_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $corner, float($seed)); + Vector3 bcuv = MMAlgos::brick_corner_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar->get_value(uv), corner, pseed); + Color corner_uv_col = Color(bcuv.x, bcuv.y, bcuv.z, 1); + //Direction (float) - The direction of each brick (white: horizontal, black: vertical); + //0.5*(sign($(name_uv)_rect.z-$(name_uv)_rect.x-$(name_uv)_rect.w+$(name_uv)_rect.y)+1.0); + float d = 0.5 * (SGN(brick_rect.b - brick_rect.r - brick_rect.a + brick_rect.g) + 1.0); + Color direction_col = Color(d, d, d, 1); + + bricks_pattern->set_pixel(x, y, bricks_pattern_col); + random_color->set_pixel(x, y, random_color_col); + position_x->set_pixel(x, y, position_x_col); + position_y->set_pixel(x, y, position_y_col); + brick_uv->set_pixel(x, y, brick_uv_col); + corner_uv->set_pixel(x, y, corner_uv_col); + direction->set_pixel(x, y, direction_col); + } + } + + bricks_pattern->unlock(); + random_color->unlock(); + position_x->unlock(); + position_y->unlock(); + brick_uv->unlock(); + corner_uv->unlock(); + direction->unlock(); + + out_bricks_pattern->set_value(bricks_pattern); + out_random_color->set_value(random_color); + out_position_x->set_value(position_x); + out_position_y->set_value(position_y); + out_brick_uv->set_value(brick_uv); + out_corner_uv->set_value(corner_uv); + out_direction->set_value(direction); } - out_position_x.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_position_y) { - out_position_y = MMNodeUniversalProperty.new(); - out_position_y.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +Color MMBricks::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); } - out_position_y.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_brick_uv) { - out_brick_uv = MMNodeUniversalProperty.new(); - out_brick_uv.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +MMBricks::MMBricks() { + type = 0; + repeat = 1; + col_row = Vector2(4, 4); + offset = 0.5; + corner = 0.3; } - out_brick_uv.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_corner_uv) { - out_corner_uv = MMNodeUniversalProperty.new(); - out_corner_uv.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +MMBricks::~MMBricks() { } - out_corner_uv.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; +void MMBricks::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_bricks_pattern"), &MMBricks::get_out_bricks_pattern); + ClassDB::bind_method(D_METHOD("set_out_bricks_pattern", "value"), &MMBricks::set_out_bricks_pattern); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_bricks_pattern", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_bricks_pattern", "get_out_bricks_pattern"); - if (!out_direction) { - out_direction = MMNodeUniversalProperty.new(); - out_direction.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + ClassDB::bind_method(D_METHOD("get_out_random_color"), &MMBricks::get_out_random_color); + ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &MMBricks::set_out_random_color); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_random_color", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_random_color", "get_out_random_color"); + + ClassDB::bind_method(D_METHOD("get_out_position_x"), &MMBricks::get_out_position_x); + ClassDB::bind_method(D_METHOD("set_out_position_x", "value"), &MMBricks::set_out_position_x); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_position_x", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_position_x", "get_out_position_x"); + + ClassDB::bind_method(D_METHOD("get_out_position_y"), &MMBricks::get_out_position_y); + ClassDB::bind_method(D_METHOD("set_out_position_y", "value"), &MMBricks::set_out_position_y); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_position_y", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_position_y", "get_out_position_y"); + + ClassDB::bind_method(D_METHOD("get_out_brick_uv"), &MMBricks::get_out_brick_uv); + ClassDB::bind_method(D_METHOD("set_out_brick_uv", "value"), &MMBricks::set_out_brick_uv); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_brick_uv", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_brick_uv", "get_out_brick_uv"); + + ClassDB::bind_method(D_METHOD("get_out_corner_uv"), &MMBricks::get_out_corner_uv); + ClassDB::bind_method(D_METHOD("set_out_corner_uv", "value"), &MMBricks::set_out_corner_uv); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_corner_uv", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_corner_uv", "get_out_corner_uv"); + + ClassDB::bind_method(D_METHOD("get_out_direction"), &MMBricks::get_out_direction); + ClassDB::bind_method(D_METHOD("set_out_direction", "value"), &MMBricks::set_out_direction); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_direction", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_direction", "get_out_direction"); + + ClassDB::bind_method(D_METHOD("get_type"), &MMBricks::get_type); + ClassDB::bind_method(D_METHOD("set_type", "value"), &MMBricks::set_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); + + ClassDB::bind_method(D_METHOD("get_repeat"), &MMBricks::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMBricks::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::INT, "repeat"), "set_repeat", "get_repeat"); + + ClassDB::bind_method(D_METHOD("get_col_row"), &MMBricks::get_col_row); + ClassDB::bind_method(D_METHOD("set_col_row", "value"), &MMBricks::set_col_row); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "col_row"), "set_col_row", "get_col_row"); + + ClassDB::bind_method(D_METHOD("get_offset"), &MMBricks::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "value"), &MMBricks::set_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); + + ClassDB::bind_method(D_METHOD("get_mortar"), &MMBricks::get_mortar); + ClassDB::bind_method(D_METHOD("set_mortar", "value"), &MMBricks::set_mortar); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mortar", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_mortar", "get_mortar"); + + ClassDB::bind_method(D_METHOD("get_bevel"), &MMBricks::get_bevel); + ClassDB::bind_method(D_METHOD("set_bevel", "value"), &MMBricks::set_bevel); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bevel", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_bevel", "get_bevel"); + + ClassDB::bind_method(D_METHOD("get_roundness"), &MMBricks::get_roundness); + ClassDB::bind_method(D_METHOD("set_roundness", "value"), &MMBricks::set_roundness); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "roundness", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_roundness", "get_roundness"); + + ClassDB::bind_method(D_METHOD("get_corner"), &MMBricks::get_corner); + ClassDB::bind_method(D_METHOD("set_corner", "value"), &MMBricks::set_corner); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "corner"), "set_corner", "get_corner"); } - - out_direction.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!mortar) { - mortar = MMNodeUniversalProperty.new(); - mortar.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; - mortar.set_default_value(0.1); -} - - mortar.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - mortar.slot_name = "Mortar"; - mortar.value_step = 0.01; - mortar.value_range = Vector2(0, 0.5); - - if (!bevel) { - bevel = MMNodeUniversalProperty.new(); - bevel.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; - bevel.set_default_value(0.1); -} - - bevel.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - bevel.slot_name = "Bevel"; - bevel.value_step = 0.01; - bevel.value_range = Vector2(0, 0.5); - - if (!roundness) { - roundness = MMNodeUniversalProperty.new(); - roundness.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; - roundness.set_default_value(0.1); -} - - roundness.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - roundness.slot_name = "Roundness"; - roundness.value_step = 0.01; - roundness.value_range = Vector2(0, 0.5); - register_output_property(out_bricks_pattern); - register_output_property(out_random_color); - register_output_property(out_position_x); - register_output_property(out_position_y); - register_output_property(out_brick_uv); - register_output_property(out_corner_uv); - register_output_property(out_direction); - register_input_property(mortar); - register_input_property(bevel); - register_input_property(roundness); -} - - - void Bricks::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(out_bricks_pattern); - mm_graph_node.add_slot_texture_universal(out_random_color); - mm_graph_node.add_slot_texture_universal(out_position_x); - mm_graph_node.add_slot_texture_universal(out_position_y); - mm_graph_node.add_slot_texture_universal(out_brick_uv); - mm_graph_node.add_slot_texture_universal(out_corner_uv); - mm_graph_node.add_slot_texture_universal(out_direction); - mm_graph_node.add_slot_enum("get_type", "set_type", "Type", [ "Running Bond", "Running Bond (2)", "HerringBone", "Basket Weave", "Spanish Bond" ]); - mm_graph_node.add_slot_int("get_repeat", "set_repeat", "Repeat"); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_vector2("get_col_row", "set_col_row", "Col, Row"); - mm_graph_node.add_slot_float("get_offset", "set_offset", "Offset"); - mm_graph_node.add_slot_float_universal(mortar); - mm_graph_node.add_slot_float_universal(bevel); - mm_graph_node.add_slot_float_universal(roundness); - mm_graph_node.add_slot_float("get_corner", "set_corner", "Corner"); -} - - - void Bricks::_render(const Variant &material) { - Ref bricks_pattern = Image.new(); - Ref random_color = Image.new(); - Ref position_x = Image.new(); - Ref position_y = Image.new(); - Ref brick_uv = Image.new(); - Ref corner_uv = Image.new(); - Ref direction = Image.new(); - bricks_pattern.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - random_color.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - position_x.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - position_y.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - brick_uv.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - corner_uv.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - direction.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - bricks_pattern.lock(); - random_color.lock(); - position_x.lock(); - position_y.lock(); - brick_uv.lock(); - corner_uv.lock(); - direction.lock(); - float w = material.image_size.x; - float h = material.image_size.y; - float pseed = randf() + randi(); - - for (int x = 0; x < material.image_size.x; ++x) { //x in range(material.image_size.x) - - for (int y = 0; y < material.image_size.y; ++y) { //y in range(material.image_size.y) - Vector2 uv = Vector2(x / w, y / h); - //vec4 $(name_uv)_rect = bricks_$pattern($uv, vec2($columns, $rows), $repeat, $row_offset); - Color brick_rect = Color(); - //"Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond"; - - if (type == 0) { - brick_rect = MMAlgos.bricks_rb(uv, col_row, repeat, offset); -} - - - else if (type == 1) { - brick_rect = MMAlgos.bricks_rb2(uv, col_row, repeat, offset); -} - - - else if (type == 2) { - brick_rect = MMAlgos.bricks_hb(uv, col_row, repeat, offset); -} - - - else if (type == 3) { - brick_rect = MMAlgos.bricks_bw(uv, col_row, repeat, offset); -} - - - else if (type == 4) { - brick_rect = MMAlgos.bricks_sb(uv, col_row, repeat, offset); -} - - //vec4 $(name_uv) = brick($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.001, $bevel*$bevel_map($uv))); - Color brick = MMAlgos.brick(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar.get_value(uv), roundness.get_value(uv), max(0.001, bevel.get_value(uv))); - //Bricks pattern (float) - A greyscale image that shows the bricks pattern; - //$(name_uv).x; - Color bricks_pattern_col = Color(brick.r, brick.r, brick.r, 1); - //Random color (rgb) - A random color for each brick; - //brick_random_color($(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed)); - Vector3 brc = MMAlgos.brick_random_color(Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), 1 / float(pseed)); - Color random_color_col = Color(brc.x, brc.y, brc.z, 1); - //Position.x (float) - The position of each brick along the X axis",; - //$(name_uv).y; - Color position_x_col = Color(brick.g, brick.g, brick.g, 1); - //Position.y (float) - The position of each brick along the Y axis; - //$(name_uv).z; - Color position_y_col = Color(brick.b, brick.b, brick.b, 1); - //Brick UV (rgb) - An UV map output for each brick, to be connected to the Map input of a CustomUV node; - //brick_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, float($seed)); - Vector3 buv = MMAlgos.brick_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), pseed); - Color brick_uv_col = Color(buv.x, buv.y, buv.z, 1); - //Corner UV (rgb) - An UV map output for each brick corner, to be connected to the Map input of a CustomUV node; - //brick_corner_uv($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $corner, float($seed)); - Vector3 bcuv = MMAlgos.brick_corner_uv(uv, Vector2(brick_rect.r, brick_rect.g), Vector2(brick_rect.b, brick_rect.a), mortar.get_value(uv), corner, pseed); - Color corner_uv_col = Color(bcuv.x, bcuv.y, bcuv.z, 1); - //Direction (float) - The direction of each brick (white: horizontal, black: vertical); - //0.5*(sign($(name_uv)_rect.z-$(name_uv)_rect.x-$(name_uv)_rect.w+$(name_uv)_rect.y)+1.0); - float d = 0.5 * (sign(brick_rect.b - brick_rect.r - brick_rect.a + brick_rect.g) + 1.0); - Color direction_col = Color(d, d, d, 1); - bricks_pattern.set_pixel(x, y, bricks_pattern_col); - random_color.set_pixel(x, y, random_color_col); - position_x.set_pixel(x, y, position_x_col); - position_y.set_pixel(x, y, position_y_col); - brick_uv.set_pixel(x, y, brick_uv_col); - corner_uv.set_pixel(x, y, corner_uv_col); - direction.set_pixel(x, y, direction_col); -} - -} - - bricks_pattern.unlock(); - random_color.unlock(); - position_x.unlock(); - position_y.unlock(); - brick_uv.unlock(); - corner_uv.unlock(); - direction.unlock(); - out_bricks_pattern.set_value(bricks_pattern); - out_random_color.set_value(random_color); - out_position_x.set_value(position_x); - out_position_y.set_value(position_y); - out_brick_uv.set_value(brick_uv); - out_corner_uv.set_value(corner_uv); - out_direction.set_value(direction); -} - - - Color Bricks::_get_value_for(const Vector2 &uv, const int pseed) { - return Color(); -} - - //type; - - int Bricks::get_type() { - return type; -} - - - void Bricks::set_type(const int val) { - type = val; - set_dirty(true); -} - - //repeat; - - int Bricks::get_repeat() { - return repeat; -} - - - void Bricks::set_repeat(const int val) { - repeat = val; - set_dirty(true); -} - - //col_row; - - Vector2 Bricks::get_col_row() { - return col_row; -} - - - void Bricks::set_col_row(const Vector2 &val) { - col_row = val; - set_dirty(true); -} - - //offset; - - float Bricks::get_offset() { - return offset; -} - - - void Bricks::set_offset(const float val) { - offset = val; - set_dirty(true); -} - - //corner; - - float Bricks::get_corner() { - return corner; -} - - - void Bricks::set_corner(const float val) { - corner = val; - set_dirty(true); -} - -} - - Bricks::Bricks() { - out_bricks_pattern; - out_random_color; - out_position_x; - out_position_y; - out_brick_uv; - out_corner_uv; - out_direction; - type = 0; - repeat = 1; - col_row = Vector2(4, 4); - offset = 0.5; - mortar; - bevel; - roundness; - corner = 0.3; - } - - Bricks::~Bricks() { - } - - - static void Bricks::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_out_bricks_pattern"), &Bricks::get_out_bricks_pattern); - ClassDB::bind_method(D_METHOD("set_out_bricks_pattern", "value"), &Bricks::set_out_bricks_pattern); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_bricks_pattern", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_bricks_pattern", "get_out_bricks_pattern"); - - - ClassDB::bind_method(D_METHOD("get_out_random_color"), &Bricks::get_out_random_color); - ClassDB::bind_method(D_METHOD("set_out_random_color", "value"), &Bricks::set_out_random_color); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_random_color", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_random_color", "get_out_random_color"); - - - ClassDB::bind_method(D_METHOD("get_out_position_x"), &Bricks::get_out_position_x); - ClassDB::bind_method(D_METHOD("set_out_position_x", "value"), &Bricks::set_out_position_x); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_position_x", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_position_x", "get_out_position_x"); - - - ClassDB::bind_method(D_METHOD("get_out_position_y"), &Bricks::get_out_position_y); - ClassDB::bind_method(D_METHOD("set_out_position_y", "value"), &Bricks::set_out_position_y); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_position_y", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_position_y", "get_out_position_y"); - - - ClassDB::bind_method(D_METHOD("get_out_brick_uv"), &Bricks::get_out_brick_uv); - ClassDB::bind_method(D_METHOD("set_out_brick_uv", "value"), &Bricks::set_out_brick_uv); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_brick_uv", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_brick_uv", "get_out_brick_uv"); - - - ClassDB::bind_method(D_METHOD("get_out_corner_uv"), &Bricks::get_out_corner_uv); - ClassDB::bind_method(D_METHOD("set_out_corner_uv", "value"), &Bricks::set_out_corner_uv); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_corner_uv", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_corner_uv", "get_out_corner_uv"); - - - ClassDB::bind_method(D_METHOD("get_out_direction"), &Bricks::get_out_direction); - ClassDB::bind_method(D_METHOD("set_out_direction", "value"), &Bricks::set_out_direction); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_direction", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_direction", "get_out_direction"); - - - ClassDB::bind_method(D_METHOD("get_type"), &Bricks::get_type); - ClassDB::bind_method(D_METHOD("set_type", "value"), &Bricks::set_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "type"), "set_type", "get_type"); - - - ClassDB::bind_method(D_METHOD("get_repeat"), &Bricks::get_repeat); - ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Bricks::set_repeat); - ADD_PROPERTY(PropertyInfo(Variant::INT, "repeat"), "set_repeat", "get_repeat"); - - - ClassDB::bind_method(D_METHOD("get_col_row"), &Bricks::get_col_row); - ClassDB::bind_method(D_METHOD("set_col_row", "value"), &Bricks::set_col_row); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "col_row"), "set_col_row", "get_col_row"); - - - ClassDB::bind_method(D_METHOD("get_offset"), &Bricks::get_offset); - ClassDB::bind_method(D_METHOD("set_offset", "value"), &Bricks::set_offset); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); - - - ClassDB::bind_method(D_METHOD("get_mortar"), &Bricks::get_mortar); - ClassDB::bind_method(D_METHOD("set_mortar", "value"), &Bricks::set_mortar); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mortar", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_mortar", "get_mortar"); - - - ClassDB::bind_method(D_METHOD("get_bevel"), &Bricks::get_bevel); - ClassDB::bind_method(D_METHOD("set_bevel", "value"), &Bricks::set_bevel); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bevel", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_bevel", "get_bevel"); - - - ClassDB::bind_method(D_METHOD("get_roundness"), &Bricks::get_roundness); - ClassDB::bind_method(D_METHOD("set_roundness", "value"), &Bricks::set_roundness); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "roundness", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_roundness", "get_roundness"); - - - ClassDB::bind_method(D_METHOD("get_corner"), &Bricks::get_corner); - ClassDB::bind_method(D_METHOD("set_corner", "value"), &Bricks::set_corner); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "corner"), "set_corner", "get_corner"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Bricks::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Bricks::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Bricks::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Bricks::_get_value_for); - ClassDB::bind_method(D_METHOD("get_type"), &Bricks::get_type); - ClassDB::bind_method(D_METHOD("set_type", "val"), &Bricks::set_type); - ClassDB::bind_method(D_METHOD("get_repeat"), &Bricks::get_repeat); - ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Bricks::set_repeat); - ClassDB::bind_method(D_METHOD("get_col_row"), &Bricks::get_col_row); - ClassDB::bind_method(D_METHOD("set_col_row", "val"), &Bricks::set_col_row); - ClassDB::bind_method(D_METHOD("get_offset"), &Bricks::get_offset); - ClassDB::bind_method(D_METHOD("set_offset", "val"), &Bricks::set_offset); - ClassDB::bind_method(D_METHOD("get_corner"), &Bricks::get_corner); - ClassDB::bind_method(D_METHOD("set_corner", "val"), &Bricks::set_corner); - - } - - - diff --git a/modules/material_maker/nodes/pattern/bricks.h b/modules/material_maker/nodes/pattern/bricks.h index eb1fa0d54..794750e06 100644 --- a/modules/material_maker/nodes/pattern/bricks.h +++ b/modules/material_maker/nodes/pattern/bricks.h @@ -1,115 +1,85 @@ -#ifndef BRICKS_H -#define BRICKS_H +#ifndef MM_BRICKS_H +#define MM_BRICKS_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Bricks : public MMNode { - GDCLASS(Bricks, MMNode); +class MMBricks : public MMNode { + GDCLASS(MMBricks, MMNode); - public: +public: + Ref get_out_bricks_pattern(); + void set_out_bricks_pattern(const Ref &val); - Ref get_out_bricks_pattern(); - void set_out_bricks_pattern(const Ref &val); + Ref get_out_random_color(); + void set_out_random_color(const Ref &val); - Ref get_out_random_color(); - void set_out_random_color(const Ref &val); + Ref get_out_position_x(); + void set_out_position_x(const Ref &val); - Ref get_out_position_x(); - void set_out_position_x(const Ref &val); + Ref get_out_position_y(); + void set_out_position_y(const Ref &val); - Ref get_out_position_y(); - void set_out_position_y(const Ref &val); + Ref get_out_brick_uv(); + void set_out_brick_uv(const Ref &val); - Ref get_out_brick_uv(); - void set_out_brick_uv(const Ref &val); + Ref get_out_corner_uv(); + void set_out_corner_uv(const Ref &val); - Ref get_out_corner_uv(); - void set_out_corner_uv(const Ref &val); + Ref get_out_direction(); + void set_out_direction(const Ref &val); - Ref get_out_direction(); - void set_out_direction(const Ref &val); + int get_type() const; + void set_type(const int val); - int get_type() const; - void set_type(const int val); + int get_repeat() const; + void set_repeat(const int val); - int get_repeat() const; - void set_repeat(const int val); + Vector2 get_col_row(); + void set_col_row(const Vector2 &val); - Vector2 get_col_row(); - void set_col_row(const Vector2 &val); + float get_offset() const; + void set_offset(const float val); - float get_offset() const; - void set_offset(const float val); + Ref get_mortar(); + void set_mortar(const Ref &val); - Ref get_mortar(); - void set_mortar(const Ref &val); + Ref get_bevel(); + void set_bevel(const Ref &val); - Ref get_bevel(); - void set_bevel(const Ref &val); + Ref get_roundness(); + void set_roundness(const Ref &val); - Ref get_roundness(); - void set_roundness(const Ref &val); + float get_corner() const; + void set_corner(const float val); - float get_corner() const; - void set_corner(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - int get_type(); - void set_type(const int val); - int get_repeat(); - void set_repeat(const int val); - Vector2 get_col_row(); - void set_col_row(const Vector2 &val); - float get_offset(); - void set_offset(const float val); - float get_corner(); - void set_corner(const float val); + MMBricks(); + ~MMBricks(); - Bricks(); - ~Bricks(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref out_bricks_pattern; - //export(Resource) - Ref out_random_color; - //export(Resource) - Ref out_position_x; - //export(Resource) - Ref out_position_y; - //export(Resource) - Ref out_brick_uv; - //export(Resource) - Ref out_corner_uv; - //export(Resource) - Ref out_direction; - //export(int, "Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond") - int type = 0; - //export(int) - int repeat = 1; - //export(Vector2) - Vector2 col_row = Vector2(4, 4); - //export(float) - float offset = 0.5; - //export(Resource) - Ref mortar; - //export(Resource) - Ref bevel; - //export(Resource) - Ref roundness; - //export(float) - float corner = 0.3; - //type - //repeat - //col_row - //offset - //corner + Ref out_bricks_pattern; + Ref out_random_color; + Ref out_position_x; + Ref out_position_y; + Ref out_brick_uv; + Ref out_corner_uv; + Ref out_direction; + //export(int, "Running Bond,Running Bond (2),HerringBone,Basket Weave,Spanish Bond") + int type; + int repeat; + Vector2 col_row; + float offset; + Ref mortar; + Ref bevel; + Ref roundness; + float corner; }; - #endif diff --git a/modules/material_maker/nodes/pattern/iching.cpp b/modules/material_maker/nodes/pattern/iching.cpp index b20ccce59..a35c732bd 100644 --- a/modules/material_maker/nodes/pattern/iching.cpp +++ b/modules/material_maker/nodes/pattern/iching.cpp @@ -1,104 +1,66 @@ #include "iching.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Iching::get_image() { - return image; +Ref MMIching::get_image() { + return image; } -void Iching::set_image(const Ref &val) { -image = val; +void MMIching::set_image(const Ref &val) { + image = val; } - -Vector2 Iching::get_size() { - return size; +Vector2 MMIching::get_size() { + return size; } -void Iching::set_size(const Vector2 &val) { -size = val; +void MMIching::set_size(const Vector2 &val) { + size = val; + set_dirty(true); } +void MMIching::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(Vector2) ; - Vector2 size = Vector2(4, 4); - - void Iching::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMIching::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_vector2("get_size", "set_size", "Size", 1); } - - void Iching::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 1); +void MMIching::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Iching::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +Color MMIching::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //IChing(vec2($columns, $rows)*$uv, float($seed)); + return MMAlgos::IChingc(uv, size, ps); } - - Color Iching::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //IChing(vec2($columns, $rows)*$uv, float($seed)); - return MMAlgos.IChingc(uv, size, ps); +MMIching::MMIching() { + size = Vector2(4, 4); } - //size; - - Vector2 Iching::get_size() { - return size; +MMIching::~MMIching() { } +void MMIching::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMIching::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMIching::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void Iching::set_size(const Vector2 &val) { - size = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_size"), &MMIching::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMIching::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); } - -} - - Iching::Iching() { - image; - size = Vector2(4, 4); - } - - Iching::~Iching() { - } - - - static void Iching::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Iching::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Iching::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Iching::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Iching::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Iching::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Iching::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Iching::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Iching::_get_value_for); - ClassDB::bind_method(D_METHOD("get_size"), &Iching::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Iching::set_size); - - } - - - diff --git a/modules/material_maker/nodes/pattern/iching.h b/modules/material_maker/nodes/pattern/iching.h index 727ae3231..4f743c444 100644 --- a/modules/material_maker/nodes/pattern/iching.h +++ b/modules/material_maker/nodes/pattern/iching.h @@ -1,38 +1,32 @@ -#ifndef ICHING_H -#define ICHING_H +#ifndef MM_ICHING_H +#define MM_ICHING_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Iching : public MMNode { - GDCLASS(Iching, MMNode); +class MMIching : public MMNode { + GDCLASS(MMIching, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Vector2 get_size(); + void set_size(const Vector2 &val); - Vector2 get_size(); - void set_size(const Vector2 &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - Vector2 get_size(); - void set_size(const Vector2 &val); + MMIching(); + ~MMIching(); - Iching(); - ~Iching(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Vector2) - Vector2 size = Vector2(4, 4); - //size + Ref image; + Vector2 size; }; - #endif diff --git a/modules/material_maker/nodes/pattern/pattern.cpp b/modules/material_maker/nodes/pattern/pattern.cpp index 238de46a7..251e8cd50 100644 --- a/modules/material_maker/nodes/pattern/pattern.cpp +++ b/modules/material_maker/nodes/pattern/pattern.cpp @@ -1,200 +1,129 @@ #include "pattern.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Pattern::get_image() { - return image; +Ref MMPattern::get_image() { + return image; } -void Pattern::set_image(const Ref &val) { -image = val; +void MMPattern::set_image(const Ref &val) { + image = val; } - -int Pattern::get_combiner_type() const { - return combiner_type; +int MMPattern::get_combiner_type() const { + return combiner_type; } -void Pattern::set_combiner_type(const int val) { -combiner_type = val; +void MMPattern::set_combiner_type(const int val) { + combiner_type = val; + set_dirty(true); } - -int Pattern::get_combiner_axis_type_x() const { - return combiner_axis_type_x; +int MMPattern::get_combiner_axis_type_x() const { + return combiner_axis_type_x; } -void Pattern::set_combiner_axis_type_x(const int val) { -combiner_axis_type_x = val; +void MMPattern::set_combiner_axis_type_x(const int val) { + combiner_axis_type_x = val; + set_dirty(true); } - -int Pattern::get_combiner_axis_type_y() const { - return combiner_axis_type_y; +int MMPattern::get_combiner_axis_type_y() const { + return combiner_axis_type_y; } -void Pattern::set_combiner_axis_type_y(const int val) { -combiner_axis_type_y = val; +void MMPattern::set_combiner_axis_type_y(const int val) { + combiner_axis_type_y = val; + set_dirty(true); } - -Vector2 Pattern::get_repeat() { - return repeat; +Vector2 MMPattern::get_repeat() { + return repeat; } -void Pattern::set_repeat(const Vector2 &val) { -repeat = val; +void MMPattern::set_repeat(const Vector2 &val) { + repeat = val; + set_dirty(true); } +void MMPattern::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(int, "Multiply,Add,Max,Min,Xor,Pow") ; - int combiner_type = 0; - //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") ; - int combiner_axis_type_x = 0; - //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") ; - int combiner_axis_type_y = 0; - //export(Vector2) ; - Vector2 repeat = Vector2(4, 4); - - void Pattern::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMPattern::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + + Array arr1; + arr1.push_back("Multiply"); + arr1.push_back("Add"); + arr1.push_back("Max"); + arr1.push_back("Min"); + arr1.push_back("Xor"); + arr1.push_back("Pow"); + + mm_graph_node->add_slot_enum("get_combiner_type", "set_combiner_type", "Combiner Type", arr1); + + Array arr2; + arr2.push_back("Sine"); + arr2.push_back("Triangle"); + arr2.push_back("Square"); + arr2.push_back("Sawtooth"); + arr2.push_back("Constant"); + arr2.push_back("Bounce"); + + mm_graph_node->add_slot_enum("get_combiner_axis_type_x", "set_combiner_axis_type_x", "Combiner Axis type", arr2); + mm_graph_node->add_slot_enum("get_combiner_axis_type_y", "set_combiner_axis_type_y", "", arr2); + //, Vector2(0, 32)); + mm_graph_node->add_slot_vector2("get_repeat", "set_repeat", "Repeat", 1); } - - void Pattern::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_enum("get_combiner_type", "set_combiner_type", "Combiner Type", [ "Multiply", "Add" , "Max", "Min", "Xor", "Pow" ]); - mm_graph_node.add_slot_enum("get_combiner_axis_type_x", "set_combiner_axis_type_x", "Combiner Axis type", [ "Sine", "Triangle", "Square", "Sawtooth", "Constant", "Bounce" ]); - mm_graph_node.add_slot_enum("get_combiner_axis_type_y", "set_combiner_axis_type_y", "", [ "Sine", "Triangle", "Square", "Sawtooth", "Constant", "Bounce" ]); - //, Vector2(0, 32)); - mm_graph_node.add_slot_vector2("get_repeat", "set_repeat", "Repeat", 1); +void MMPattern::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Pattern::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +Color MMPattern::_get_value_for(const Vector2 &uv, const int pseed) { + float f = MMAlgos::pattern(uv, repeat.x, repeat.y, combiner_type, combiner_axis_type_x, combiner_axis_type_y); + return Color(f, f, f, 1); } - - Color Pattern::_get_value_for(const Vector2 &uv, const int pseed) { - float f = MMAlgos.pattern(uv, repeat.x, repeat.y, combiner_type, combiner_axis_type_x, combiner_axis_type_y); - return Color(f, f, f, 1); +MMPattern::MMPattern() { + combiner_type = 0; + combiner_axis_type_x = 0; + combiner_axis_type_y = 0; + repeat = Vector2(4, 4); } - //combiner_type; - - int Pattern::get_combiner_type() { - return combiner_type; +MMPattern::~MMPattern() { } +void MMPattern::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMPattern::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMPattern::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void Pattern::set_combiner_type(const int val) { - combiner_type = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_combiner_type"), &MMPattern::get_combiner_type); + ClassDB::bind_method(D_METHOD("set_combiner_type", "value"), &MMPattern::set_combiner_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_type"), "set_combiner_type", "get_combiner_type"); + + ClassDB::bind_method(D_METHOD("get_combiner_axis_type_x"), &MMPattern::get_combiner_axis_type_x); + ClassDB::bind_method(D_METHOD("set_combiner_axis_type_x", "value"), &MMPattern::set_combiner_axis_type_x); + ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_axis_type_x"), "set_combiner_axis_type_x", "get_combiner_axis_type_x"); + + ClassDB::bind_method(D_METHOD("get_combiner_axis_type_y"), &MMPattern::get_combiner_axis_type_y); + ClassDB::bind_method(D_METHOD("set_combiner_axis_type_y", "value"), &MMPattern::set_combiner_axis_type_y); + ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_axis_type_y"), "set_combiner_axis_type_y", "get_combiner_axis_type_y"); + + ClassDB::bind_method(D_METHOD("get_repeat"), &MMPattern::get_repeat); + ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMPattern::set_repeat); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "repeat"), "set_repeat", "get_repeat"); } - - //combiner_axis_type_x; - - int Pattern::get_combiner_axis_type_x() { - return combiner_axis_type_x; -} - - - void Pattern::set_combiner_axis_type_x(const int val) { - combiner_axis_type_x = val; - set_dirty(true); -} - - //combiner_axis_type_y; - - int Pattern::get_combiner_axis_type_y() { - return combiner_axis_type_y; -} - - - void Pattern::set_combiner_axis_type_y(const int val) { - combiner_axis_type_y = val; - set_dirty(true); -} - - //repeat; - - Vector2 Pattern::get_repeat() { - return repeat; -} - - - void Pattern::set_repeat(const Vector2 &val) { - repeat = val; - set_dirty(true); -} - -} - - Pattern::Pattern() { - image; - combiner_type = 0; - combiner_axis_type_x = 0; - combiner_axis_type_y = 0; - repeat = Vector2(4, 4); - } - - Pattern::~Pattern() { - } - - - static void Pattern::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Pattern::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Pattern::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_combiner_type"), &Pattern::get_combiner_type); - ClassDB::bind_method(D_METHOD("set_combiner_type", "value"), &Pattern::set_combiner_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_type"), "set_combiner_type", "get_combiner_type"); - - - ClassDB::bind_method(D_METHOD("get_combiner_axis_type_x"), &Pattern::get_combiner_axis_type_x); - ClassDB::bind_method(D_METHOD("set_combiner_axis_type_x", "value"), &Pattern::set_combiner_axis_type_x); - ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_axis_type_x"), "set_combiner_axis_type_x", "get_combiner_axis_type_x"); - - - ClassDB::bind_method(D_METHOD("get_combiner_axis_type_y"), &Pattern::get_combiner_axis_type_y); - ClassDB::bind_method(D_METHOD("set_combiner_axis_type_y", "value"), &Pattern::set_combiner_axis_type_y); - ADD_PROPERTY(PropertyInfo(Variant::INT, "combiner_axis_type_y"), "set_combiner_axis_type_y", "get_combiner_axis_type_y"); - - - ClassDB::bind_method(D_METHOD("get_repeat"), &Pattern::get_repeat); - ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Pattern::set_repeat); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "repeat"), "set_repeat", "get_repeat"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Pattern::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Pattern::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Pattern::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Pattern::_get_value_for); - ClassDB::bind_method(D_METHOD("get_combiner_type"), &Pattern::get_combiner_type); - ClassDB::bind_method(D_METHOD("set_combiner_type", "val"), &Pattern::set_combiner_type); - ClassDB::bind_method(D_METHOD("get_combiner_axis_type_x"), &Pattern::get_combiner_axis_type_x); - ClassDB::bind_method(D_METHOD("set_combiner_axis_type_x", "val"), &Pattern::set_combiner_axis_type_x); - ClassDB::bind_method(D_METHOD("get_combiner_axis_type_y"), &Pattern::get_combiner_axis_type_y); - ClassDB::bind_method(D_METHOD("set_combiner_axis_type_y", "val"), &Pattern::set_combiner_axis_type_y); - ClassDB::bind_method(D_METHOD("get_repeat"), &Pattern::get_repeat); - ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Pattern::set_repeat); - - } - - - diff --git a/modules/material_maker/nodes/pattern/pattern.h b/modules/material_maker/nodes/pattern/pattern.h index 0d1838dba..dbe5d4bb0 100644 --- a/modules/material_maker/nodes/pattern/pattern.h +++ b/modules/material_maker/nodes/pattern/pattern.h @@ -1,62 +1,49 @@ -#ifndef PATTERN_H -#define PATTERN_H +#ifndef MM_PATTERN_H +#define MM_PATTERN_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Pattern : public MMNode { - GDCLASS(Pattern, MMNode); +class MMPattern : public MMNode { + GDCLASS(MMPattern, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + int get_combiner_type() const; + void set_combiner_type(const int val); - int get_combiner_type() const; - void set_combiner_type(const int val); + int get_combiner_axis_type_x() const; + void set_combiner_axis_type_x(const int val); - int get_combiner_axis_type_x() const; - void set_combiner_axis_type_x(const int val); + int get_combiner_axis_type_y() const; + void set_combiner_axis_type_y(const int val); - int get_combiner_axis_type_y() const; - void set_combiner_axis_type_y(const int val); + Vector2 get_repeat(); + void set_repeat(const Vector2 &val); - Vector2 get_repeat(); - void set_repeat(const Vector2 &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - int get_combiner_type(); - void set_combiner_type(const int val); - int get_combiner_axis_type_x(); - void set_combiner_axis_type_x(const int val); - int get_combiner_axis_type_y(); - void set_combiner_axis_type_y(const int val); - Vector2 get_repeat(); - void set_repeat(const Vector2 &val); + Color _get_value_for(const Vector2 &uv, const int pseed); - Pattern(); - ~Pattern(); + MMPattern(); + ~MMPattern(); - protected: - static void _bind_methods(); +protected: + static void _bind_methods(); - //tool - //export(Resource) - Ref image; - //export(int, "Multiply,Add,Max,Min,Xor,Pow") - int combiner_type = 0; - //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") - int combiner_axis_type_x = 0; - //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") - int combiner_axis_type_y = 0; - //export(Vector2) - Vector2 repeat = Vector2(4, 4); - //combiner_type - //combiner_axis_type_x - //combiner_axis_type_y - //repeat + Ref image; + //export(int, "Multiply,Add,Max,Min,Xor,Pow") + int combiner_type = 0; + //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") + int combiner_axis_type_x = 0; + //export(int, "Sine,Triangle,Square,Sawtooth,Constant,Bounce") + int combiner_axis_type_y = 0; + //export(Vector2) + Vector2 repeat = Vector2(4, 4); }; - #endif diff --git a/modules/material_maker/nodes/pattern/runes.cpp b/modules/material_maker/nodes/pattern/runes.cpp index df4944049..8ceb1a504 100644 --- a/modules/material_maker/nodes/pattern/runes.cpp +++ b/modules/material_maker/nodes/pattern/runes.cpp @@ -1,104 +1,66 @@ #include "runes.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Runes::get_image() { - return image; +Ref MMRunes::get_image() { + return image; } -void Runes::set_image(const Ref &val) { -image = val; +void MMRunes::set_image(const Ref &val) { + image = val; } - -Vector2 Runes::get_size() { - return size; +Vector2 MMRunes::get_size() { + return size; } -void Runes::set_size(const Vector2 &val) { -size = val; +void MMRunes::set_size(const Vector2 &val) { + size = val; + set_dirty(true); } +void MMRunes::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(Vector2) ; - Vector2 size = Vector2(4, 4); - - void Runes::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMRunes::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_vector2("get_size", "set_size", "Size", 1); } - - void Runes::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 1); +void MMRunes::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Runes::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +Color MMRunes::_get_value_for(const Vector2 &uv, const int pseed) { + float ps = 1.0 / float(pseed); + //Rune(vec2($columns, $rows)*$uv, float($seed)); + return MMAlgos::runesc(uv, size, ps); } - - Color Runes::_get_value_for(const Vector2 &uv, const int pseed) { - float ps = 1.0 / float(pseed); - //Rune(vec2($columns, $rows)*$uv, float($seed)); - return MMAlgos.runesc(uv, size, ps); +MMRunes::MMRunes() { + size = Vector2(4, 4); } - //size; - - Vector2 Runes::get_size() { - return size; +MMRunes::~MMRunes() { } +void MMRunes::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMRunes::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMRunes::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void Runes::set_size(const Vector2 &val) { - size = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_size"), &MMRunes::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMRunes::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); } - -} - - Runes::Runes() { - image; - size = Vector2(4, 4); - } - - Runes::~Runes() { - } - - - static void Runes::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Runes::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Runes::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Runes::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Runes::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Runes::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Runes::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Runes::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Runes::_get_value_for); - ClassDB::bind_method(D_METHOD("get_size"), &Runes::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Runes::set_size); - - } - - - diff --git a/modules/material_maker/nodes/pattern/runes.h b/modules/material_maker/nodes/pattern/runes.h index 7e7f570d0..88713be9c 100644 --- a/modules/material_maker/nodes/pattern/runes.h +++ b/modules/material_maker/nodes/pattern/runes.h @@ -1,38 +1,32 @@ -#ifndef RUNES_H -#define RUNES_H +#ifndef MM_RUNES_H +#define MM_RUNES_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Runes : public MMNode { - GDCLASS(Runes, MMNode); +class MMRunes : public MMNode { + GDCLASS(MMRunes, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Vector2 get_size(); + void set_size(const Vector2 &val); - Vector2 get_size(); - void set_size(const Vector2 &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - Vector2 get_size(); - void set_size(const Vector2 &val); + MMRunes(); + ~MMRunes(); - Runes(); - ~Runes(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Vector2) - Vector2 size = Vector2(4, 4); - //size + Ref image; + Vector2 size; }; - #endif diff --git a/modules/material_maker/nodes/pattern/scratches.cpp b/modules/material_maker/nodes/pattern/scratches.cpp index 32b39dc9d..0d1413b97 100644 --- a/modules/material_maker/nodes/pattern/scratches.cpp +++ b/modules/material_maker/nodes/pattern/scratches.cpp @@ -1,231 +1,125 @@ #include "scratches.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Scratches::get_image() { - return image; +Ref MMScratches::get_image() { + return image; } -void Scratches::set_image(const Ref &val) { -image = val; +void MMScratches::set_image(const Ref &val) { + image = val; } - -Vector2 Scratches::get_size() { - return size; +Vector2 MMScratches::get_size() { + return size; } -void Scratches::set_size(const Vector2 &val) { -size = val; +void MMScratches::set_size(const Vector2 &val) { + size = val; + set_dirty(true); } - -int Scratches::get_layers() const { - return layers; +int MMScratches::get_layers() const { + return layers; } -void Scratches::set_layers(const int val) { -layers = val; +void MMScratches::set_layers(const int val) { + layers = val; + set_dirty(true); } - -float Scratches::get_waviness() const { - return waviness; +float MMScratches::get_waviness() const { + return waviness; } -void Scratches::set_waviness(const float val) { -waviness = val; +void MMScratches::set_waviness(const float val) { + waviness = val; + set_dirty(true); } - -int Scratches::get_angle() const { - return angle; +int MMScratches::get_angle() const { + return angle; } -void Scratches::set_angle(const int val) { -angle = val; +void MMScratches::set_angle(const int val) { + angle = val; + set_dirty(true); } - -float Scratches::get_randomness() const { - return randomness; +float MMScratches::get_randomness() const { + return randomness; } -void Scratches::set_randomness(const float val) { -randomness = val; +void MMScratches::set_randomness(const float val) { + randomness = val; + set_dirty(true); } +void MMScratches::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(Vector2) ; - Vector2 size = Vector2(0.25, 0.4); - //export(int) ; - int layers = 4; - //export(float) ; - float waviness = 0.51; - //export(int) ; - int angle = 0; - //export(float) ; - float randomness = 0.44; - - void Scratches::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMScratches::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_vector2("get_size", "set_size", "Size", 0.01); + mm_graph_node->add_slot_int("get_layers", "set_layers", "Layers"); + mm_graph_node->add_slot_float("get_waviness", "set_waviness", "Waviness", 0.01); + mm_graph_node->add_slot_int("get_angle", "set_angle", "Angle"); + mm_graph_node->add_slot_float("get_randomness", "set_randomness", "Randomness", 0.01); } - - void Scratches::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 0.01); - mm_graph_node.add_slot_int("get_layers", "set_layers", "Layers"); - mm_graph_node.add_slot_float("get_waviness", "set_waviness", "Waviness", 0.01); - mm_graph_node.add_slot_int("get_angle", "set_angle", "Angle"); - mm_graph_node.add_slot_float("get_randomness", "set_randomness", "Randomness", 0.01); +void MMScratches::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Scratches::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +Color MMScratches::_get_value_for(const Vector2 &uv, const int pseed) { + //scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0)); + return MMAlgos::scratchesc(uv, layers, size, waviness, angle, randomness, Vector2(pseed, 0.0)); } - - Color Scratches::_get_value_for(const Vector2 &uv, const int pseed) { - //scratches($uv, int($layers), vec2($length, $width), $waviness, $angle, $randomness, vec2(float($seed), 0.0)); - return MMAlgos.scratchesc(uv, layers, size, waviness, angle, randomness, Vector2(pseed, 0.0)); +MMScratches::MMScratches() { + size = Vector2(0.25, 0.4); + layers = 4; + waviness = 0.51; + angle = 0; + randomness = 0.44; } - //size; - - Vector2 Scratches::get_size() { - return size; +MMScratches::~MMScratches() { } +void MMScratches::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMScratches::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMScratches::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void Scratches::set_size(const Vector2 &val) { - size = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_size"), &MMScratches::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMScratches::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + ClassDB::bind_method(D_METHOD("get_layers"), &MMScratches::get_layers); + ClassDB::bind_method(D_METHOD("set_layers", "value"), &MMScratches::set_layers); + ADD_PROPERTY(PropertyInfo(Variant::INT, "layers"), "set_layers", "get_layers"); + + ClassDB::bind_method(D_METHOD("get_waviness"), &MMScratches::get_waviness); + ClassDB::bind_method(D_METHOD("set_waviness", "value"), &MMScratches::set_waviness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "waviness"), "set_waviness", "get_waviness"); + + ClassDB::bind_method(D_METHOD("get_angle"), &MMScratches::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &MMScratches::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::INT, "angle"), "set_angle", "get_angle"); + + ClassDB::bind_method(D_METHOD("get_randomness"), &MMScratches::get_randomness); + ClassDB::bind_method(D_METHOD("set_randomness", "value"), &MMScratches::set_randomness); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness"), "set_randomness", "get_randomness"); } - - //layers; - - int Scratches::get_layers() { - return layers; -} - - - void Scratches::set_layers(const int val) { - layers = val; - set_dirty(true); -} - - //waviness; - - float Scratches::get_waviness() { - return waviness; -} - - - void Scratches::set_waviness(const float val) { - waviness = val; - set_dirty(true); -} - - //angle; - - int Scratches::get_angle() { - return angle; -} - - - void Scratches::set_angle(const int val) { - angle = val; - set_dirty(true); -} - - //randomness; - - float Scratches::get_randomness() { - return randomness; -} - - - void Scratches::set_randomness(const float val) { - randomness = val; - set_dirty(true); -} - -} - - Scratches::Scratches() { - image; - size = Vector2(0.25, 0.4); - layers = 4; - waviness = 0.51; - angle = 0; - randomness = 0.44; - } - - Scratches::~Scratches() { - } - - - static void Scratches::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Scratches::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Scratches::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Scratches::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Scratches::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("get_layers"), &Scratches::get_layers); - ClassDB::bind_method(D_METHOD("set_layers", "value"), &Scratches::set_layers); - ADD_PROPERTY(PropertyInfo(Variant::INT, "layers"), "set_layers", "get_layers"); - - - ClassDB::bind_method(D_METHOD("get_waviness"), &Scratches::get_waviness); - ClassDB::bind_method(D_METHOD("set_waviness", "value"), &Scratches::set_waviness); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "waviness"), "set_waviness", "get_waviness"); - - - ClassDB::bind_method(D_METHOD("get_angle"), &Scratches::get_angle); - ClassDB::bind_method(D_METHOD("set_angle", "value"), &Scratches::set_angle); - ADD_PROPERTY(PropertyInfo(Variant::INT, "angle"), "set_angle", "get_angle"); - - - ClassDB::bind_method(D_METHOD("get_randomness"), &Scratches::get_randomness); - ClassDB::bind_method(D_METHOD("set_randomness", "value"), &Scratches::set_randomness); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness"), "set_randomness", "get_randomness"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Scratches::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Scratches::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Scratches::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Scratches::_get_value_for); - ClassDB::bind_method(D_METHOD("get_size"), &Scratches::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Scratches::set_size); - ClassDB::bind_method(D_METHOD("get_layers"), &Scratches::get_layers); - ClassDB::bind_method(D_METHOD("set_layers", "val"), &Scratches::set_layers); - ClassDB::bind_method(D_METHOD("get_waviness"), &Scratches::get_waviness); - ClassDB::bind_method(D_METHOD("set_waviness", "val"), &Scratches::set_waviness); - ClassDB::bind_method(D_METHOD("get_angle"), &Scratches::get_angle); - ClassDB::bind_method(D_METHOD("set_angle", "val"), &Scratches::set_angle); - ClassDB::bind_method(D_METHOD("get_randomness"), &Scratches::get_randomness); - ClassDB::bind_method(D_METHOD("set_randomness", "val"), &Scratches::set_randomness); - - } - - - diff --git a/modules/material_maker/nodes/pattern/scratches.h b/modules/material_maker/nodes/pattern/scratches.h index c66b182a9..728805ddc 100644 --- a/modules/material_maker/nodes/pattern/scratches.h +++ b/modules/material_maker/nodes/pattern/scratches.h @@ -1,70 +1,48 @@ -#ifndef SCRATCHES_H -#define SCRATCHES_H +#ifndef MM_SCRATCHES_H +#define MM_SCRATCHES_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Scratches : public MMNode { - GDCLASS(Scratches, MMNode); +class MMScratches : public MMNode { + GDCLASS(MMScratches, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Vector2 get_size(); + void set_size(const Vector2 &val); - Vector2 get_size(); - void set_size(const Vector2 &val); + int get_layers() const; + void set_layers(const int val); - int get_layers() const; - void set_layers(const int val); + float get_waviness() const; + void set_waviness(const float val); - float get_waviness() const; - void set_waviness(const float val); + int get_angle() const; + void set_angle(const int val); - int get_angle() const; - void set_angle(const int val); + float get_randomness() const; + void set_randomness(const float val); - float get_randomness() const; - void set_randomness(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - Vector2 get_size(); - void set_size(const Vector2 &val); - int get_layers(); - void set_layers(const int val); - float get_waviness(); - void set_waviness(const float val); - int get_angle(); - void set_angle(const int val); - float get_randomness(); - void set_randomness(const float val); + MMScratches(); + ~MMScratches(); - Scratches(); - ~Scratches(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Vector2) - Vector2 size = Vector2(0.25, 0.4); - //export(int) - int layers = 4; - //export(float) - float waviness = 0.51; - //export(int) - int angle = 0; - //export(float) - float randomness = 0.44; - //size - //layers - //waviness - //angle - //randomness + Ref image; + Vector2 size; + int layers; + float waviness; + int angle; + float randomness; }; - #endif diff --git a/modules/material_maker/nodes/pattern/sine_wave.cpp b/modules/material_maker/nodes/pattern/sine_wave.cpp index f85c6e7f2..df6bee9d1 100644 --- a/modules/material_maker/nodes/pattern/sine_wave.cpp +++ b/modules/material_maker/nodes/pattern/sine_wave.cpp @@ -1,167 +1,95 @@ #include "sine_wave.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref SineWave::get_image() { - return image; +Ref MMSineWave::get_image() { + return image; } -void SineWave::set_image(const Ref &val) { -image = val; +void MMSineWave::set_image(const Ref &val) { + image = val; } - -float SineWave::get_amplitude() const { - return amplitude; +float MMSineWave::get_amplitude() const { + return amplitude; } -void SineWave::set_amplitude(const float val) { -amplitude = val; +void MMSineWave::set_amplitude(const float val) { + amplitude = val; + set_dirty(true); } - -float SineWave::get_frequency() const { - return frequency; +float MMSineWave::get_frequency() const { + return frequency; } -void SineWave::set_frequency(const float val) { -frequency = val; +void MMSineWave::set_frequency(const float val) { + frequency = val; + set_dirty(true); } - -float SineWave::get_phase() const { - return phase; +float MMSineWave::get_phase() const { + return phase; } -void SineWave::set_phase(const float val) { -phase = val; +void MMSineWave::set_phase(const float val) { + phase = val; + set_dirty(true); } +void MMSineWave::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - - //tool; - //export(Resource) ; - Ref image; - //export(float) ; - float amplitude = 0.5; - //export(float) ; - float frequency = 2; - //export(float) ; - float phase = 0; - - void SineWave::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMSineWave::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_float("get_amplitude", "set_amplitude", "Amplitude", 0.01); + mm_graph_node->add_slot_float("get_frequency", "set_frequency", "Frequency", 0.1); + mm_graph_node->add_slot_float("get_phase", "set_phase", "Phase", 0.01); } - - void SineWave::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_float("get_amplitude", "set_amplitude", "Amplitude", 0.01); - mm_graph_node.add_slot_float("get_frequency", "set_frequency", "Frequency", 0.1); - mm_graph_node.add_slot_float("get_phase", "set_phase", "Phase", 0.01); +void MMSineWave::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void SineWave::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +Color MMSineWave::_get_value_for(const Vector2 &uv, const int pseed) { + float f = 1.0 - abs(2.0 * (uv.y - 0.5) - amplitude * sin((frequency * uv.x + phase) * 6.28318530718)); + return Color(f, f, f, 1); } - - Color SineWave::_get_value_for(const Vector2 &uv, const int pseed) { - float f = 1.0 - abs(2.0 * (uv.y - 0.5) - amplitude *sin((frequency * uv.x + phase)*6.28318530718)); - return Color(f, f, f, 1); +MMSineWave::MMSineWave() { + amplitude = 0.5; + frequency = 2; + phase = 0; } - //amplitude; - - float SineWave::get_amplitude() { - return amplitude; +MMSineWave::~MMSineWave() { } +void MMSineWave::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMSineWave::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMSineWave::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void SineWave::set_amplitude(const float val) { - amplitude = val; - set_dirty(true); + ClassDB::bind_method(D_METHOD("get_amplitude"), &MMSineWave::get_amplitude); + ClassDB::bind_method(D_METHOD("set_amplitude", "value"), &MMSineWave::set_amplitude); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amplitude"), "set_amplitude", "get_amplitude"); + + ClassDB::bind_method(D_METHOD("get_frequency"), &MMSineWave::get_frequency); + ClassDB::bind_method(D_METHOD("set_frequency", "value"), &MMSineWave::set_frequency); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "frequency"), "set_frequency", "get_frequency"); + + ClassDB::bind_method(D_METHOD("get_phase"), &MMSineWave::get_phase); + ClassDB::bind_method(D_METHOD("set_phase", "value"), &MMSineWave::set_phase); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "phase"), "set_phase", "get_phase"); } - - //frequency; - - float SineWave::get_frequency() { - return frequency; -} - - - void SineWave::set_frequency(const float val) { - frequency = val; - set_dirty(true); -} - - //phase; - - float SineWave::get_phase() { - return phase; -} - - - void SineWave::set_phase(const float val) { - phase = val; - set_dirty(true); -} - -} - - SineWave::SineWave() { - image; - amplitude = 0.5; - frequency = 2; - phase = 0; - } - - SineWave::~SineWave() { - } - - - static void SineWave::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &SineWave::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &SineWave::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_amplitude"), &SineWave::get_amplitude); - ClassDB::bind_method(D_METHOD("set_amplitude", "value"), &SineWave::set_amplitude); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "amplitude"), "set_amplitude", "get_amplitude"); - - - ClassDB::bind_method(D_METHOD("get_frequency"), &SineWave::get_frequency); - ClassDB::bind_method(D_METHOD("set_frequency", "value"), &SineWave::set_frequency); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "frequency"), "set_frequency", "get_frequency"); - - - ClassDB::bind_method(D_METHOD("get_phase"), &SineWave::get_phase); - ClassDB::bind_method(D_METHOD("set_phase", "value"), &SineWave::set_phase); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "phase"), "set_phase", "get_phase"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &SineWave::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SineWave::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &SineWave::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &SineWave::_get_value_for); - ClassDB::bind_method(D_METHOD("get_amplitude"), &SineWave::get_amplitude); - ClassDB::bind_method(D_METHOD("set_amplitude", "val"), &SineWave::set_amplitude); - ClassDB::bind_method(D_METHOD("get_frequency"), &SineWave::get_frequency); - ClassDB::bind_method(D_METHOD("set_frequency", "val"), &SineWave::set_frequency); - ClassDB::bind_method(D_METHOD("get_phase"), &SineWave::get_phase); - ClassDB::bind_method(D_METHOD("set_phase", "val"), &SineWave::set_phase); - - } - - - diff --git a/modules/material_maker/nodes/pattern/sine_wave.h b/modules/material_maker/nodes/pattern/sine_wave.h index 456197fd4..11b148d1f 100644 --- a/modules/material_maker/nodes/pattern/sine_wave.h +++ b/modules/material_maker/nodes/pattern/sine_wave.h @@ -1,54 +1,40 @@ -#ifndef SINE_WAVE_H -#define SINE_WAVE_H +#ifndef MM_SINE_WAVE_H +#define MM_SINE_WAVE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class SineWave : public MMNode { - GDCLASS(SineWave, MMNode); +class MMSineWave : public MMNode { + GDCLASS(MMSineWave, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + float get_amplitude() const; + void set_amplitude(const float val); - float get_amplitude() const; - void set_amplitude(const float val); + float get_frequency() const; + void set_frequency(const float val); - float get_frequency() const; - void set_frequency(const float val); + float get_phase() const; + void set_phase(const float val); - float get_phase() const; - void set_phase(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - float get_amplitude(); - void set_amplitude(const float val); - float get_frequency(); - void set_frequency(const float val); - float get_phase(); - void set_phase(const float val); + MMSineWave(); + ~MMSineWave(); - SineWave(); - ~SineWave(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(float) - float amplitude = 0.5; - //export(float) - float frequency = 2; - //export(float) - float phase = 0; - //amplitude - //frequency - //phase + Ref image; + float amplitude; + float frequency; + float phase; }; - #endif diff --git a/modules/material_maker/nodes/pattern/truchet.cpp b/modules/material_maker/nodes/pattern/truchet.cpp index fd2608f5b..34a9953d1 100644 --- a/modules/material_maker/nodes/pattern/truchet.cpp +++ b/modules/material_maker/nodes/pattern/truchet.cpp @@ -1,144 +1,93 @@ #include "truchet.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Truchet::get_image() { - return image; +Ref MMTruchet::get_image() { + return image; } -void Truchet::set_image(const Ref &val) { -image = val; +void MMTruchet::set_image(const Ref &val) { + image = val; } - -int Truchet::get_shape() const { - return shape; +int MMTruchet::get_shape() const { + return shape; } -void Truchet::set_shape(const int val) { -shape = val; +void MMTruchet::set_shape(const int val) { + shape = val; + set_dirty(true); } - -float Truchet::get_size() const { - return size; +float MMTruchet::get_size() const { + return size; } -void Truchet::set_size(const float val) { -size = val; +void MMTruchet::set_size(const float val) { + size = val; + set_dirty(true); } +void MMTruchet::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - //tool; - //export(Resource) ; - Ref image; - //export(int, "Line,Circle") ; - int shape = 0; - //export(float) ; - float size = 4; - - void Truchet::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMTruchet::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + + Array arr; + arr.push_back("Line"); + arr.push_back("Circle"); + + mm_graph_node->add_slot_enum("get_shape", "set_shape", "Shape", arr); + mm_graph_node->add_slot_float("get_size", "set_size", "Size", 1); } - - void Truchet::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_enum("get_shape", "set_shape", "Shape", [ "Line", "Circle" ]); - mm_graph_node.add_slot_float("get_size", "set_size", "Size", 1); +void MMTruchet::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } +Color MMTruchet::_get_value_for(const Vector2 &uv, const int pseed) { + if (shape == 0) { + return MMAlgos::truchet1c(uv, size, pseed); + } - void Truchet::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); + else if (shape == 1) { + return MMAlgos::truchet2c(uv, size, pseed); + } + + return Color(); } - - Color Truchet::_get_value_for(const Vector2 &uv, const int pseed) { - - if (shape == 0) { - return MMAlgos.truchet1c(uv, size, pseed); +MMTruchet::MMTruchet() { + shape = 0; + size = 4; } - - else if (shape == 1) { - return MMAlgos.truchet2c(uv, size, pseed); +MMTruchet::~MMTruchet() { } - return Color(); +void MMTruchet::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMTruchet::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMTruchet::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); + + ClassDB::bind_method(D_METHOD("get_shape"), &MMTruchet::get_shape); + ClassDB::bind_method(D_METHOD("set_shape", "value"), &MMTruchet::set_shape); + ADD_PROPERTY(PropertyInfo(Variant::INT, "shape"), "set_shape", "get_shape"); + + ClassDB::bind_method(D_METHOD("get_size"), &MMTruchet::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMTruchet::set_size); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "size"), "set_size", "get_size"); } - - //shape; - - int Truchet::get_shape() { - return shape; -} - - - void Truchet::set_shape(const int val) { - shape = val; - set_dirty(true); -} - - //size; - - float Truchet::get_size() { - return size; -} - - - void Truchet::set_size(const float val) { - size = val; - set_dirty(true); -} - -} - - Truchet::Truchet() { - image; - shape = 0; - size = 4; - } - - Truchet::~Truchet() { - } - - - static void Truchet::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Truchet::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Truchet::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_shape"), &Truchet::get_shape); - ClassDB::bind_method(D_METHOD("set_shape", "value"), &Truchet::set_shape); - ADD_PROPERTY(PropertyInfo(Variant::INT, "shape"), "set_shape", "get_shape"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Truchet::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Truchet::set_size); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Truchet::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Truchet::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Truchet::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Truchet::_get_value_for); - ClassDB::bind_method(D_METHOD("get_shape"), &Truchet::get_shape); - ClassDB::bind_method(D_METHOD("set_shape", "val"), &Truchet::set_shape); - ClassDB::bind_method(D_METHOD("get_size"), &Truchet::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Truchet::set_size); - - } - - - diff --git a/modules/material_maker/nodes/pattern/truchet.h b/modules/material_maker/nodes/pattern/truchet.h index 0d079f3ab..3bfa8f962 100644 --- a/modules/material_maker/nodes/pattern/truchet.h +++ b/modules/material_maker/nodes/pattern/truchet.h @@ -1,46 +1,37 @@ -#ifndef TRUCHET_H -#define TRUCHET_H +#ifndef MM_TRUCHET_H +#define MM_TRUCHET_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Truchet : public MMNode { - GDCLASS(Truchet, MMNode); +class MMTruchet : public MMNode { + GDCLASS(MMTruchet, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + int get_shape() const; + void set_shape(const int val); - int get_shape() const; - void set_shape(const int val); + float get_size() const; + void set_size(const float val); - float get_size() const; - void set_size(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - int get_shape(); - void set_shape(const int val); - float get_size(); - void set_size(const float val); + MMTruchet(); + ~MMTruchet(); - Truchet(); - ~Truchet(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(int, "Line,Circle") - int shape = 0; - //export(float) - float size = 4; - //shape - //size + Ref image; + //export(int, "Line,Circle") + int shape; + float size; }; - #endif diff --git a/modules/material_maker/nodes/pattern/weave.cpp b/modules/material_maker/nodes/pattern/weave.cpp index a3c22eea8..ce131f33a 100644 --- a/modules/material_maker/nodes/pattern/weave.cpp +++ b/modules/material_maker/nodes/pattern/weave.cpp @@ -1,258 +1,196 @@ #include "weave.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Weave::get_out_main() { - return out_main; +Ref MMWeave::get_out_main() { + return out_main; } -void Weave::set_out_main(const Ref &val) { -out_main = val; +void MMWeave::set_out_main(const Ref &val) { + out_main = val; } - -Ref Weave::get_out_horizontal_map() { - return out_horizontal_map; +Ref MMWeave::get_out_horizontal_map() { + return out_horizontal_map; } -void Weave::set_out_horizontal_map(const Ref &val) { -out_horizontal_map = val; +void MMWeave::set_out_horizontal_map(const Ref &val) { + out_horizontal_map = val; } - -Ref Weave::get_out_vertical_map() { - return out_vertical_map; +Ref MMWeave::get_out_vertical_map() { + return out_vertical_map; } -void Weave::set_out_vertical_map(const Ref &val) { -out_vertical_map = val; +void MMWeave::set_out_vertical_map(const Ref &val) { + out_vertical_map = val; } - -Vector2 Weave::get_size() { - return size; +Vector2 MMWeave::get_size() { + return size; } -void Weave::set_size(const Vector2 &val) { -size = val; +void MMWeave::set_size(const Vector2 &val) { + size = val; + set_dirty(true); } - -Ref Weave::get_width() { - return width; +Ref MMWeave::get_width() { + return width; } -void Weave::set_width(const Ref &val) { -width = val; +void MMWeave::set_width(const Ref &val) { + width = val; } - -int Weave::get_stitch() const { - return stitch; +int MMWeave::get_stitch() const { + return stitch; } -void Weave::set_stitch(const int val) { -stitch = val; +void MMWeave::set_stitch(const int val) { + stitch = val; + set_dirty(true); } +void MMWeave::_init_properties() { + if (!out_main.is_valid()) { + out_main.instance(); + out_main->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + out_main->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - //tool; - //export(Resource) ; - Ref out_main; - //export(Resource) ; - Ref out_horizontal_map; - //export(Resource) ; - Ref out_vertical_map; - //export(Vector2) ; - Vector2 size = Vector2(4, 4); - //export(Resource) ; - Ref width; - //export(int) ; - int stitch = 1; + if (!out_horizontal_map.is_valid()) { + out_horizontal_map.instance(); + out_horizontal_map->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Weave::_init_properties() { + out_horizontal_map->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - if (!out_main) { - out_main = MMNodeUniversalProperty.new(); - out_main.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + if (!out_vertical_map.is_valid()) { + out_vertical_map.instance(); + out_vertical_map->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + + out_vertical_map->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + + if (!width.is_valid()) { + width.instance(); + width->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + width->set_default_value(Vector2(0.9, 0.9)); + } + + width->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + width->set_slot_name("Width"); + width->set_value_step(0.01); + width->set_value_range(Vector2(0, 1)); + + register_output_property(out_main); + register_output_property(out_horizontal_map); + register_output_property(out_vertical_map); + register_input_property(width); } - out_main.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!out_horizontal_map) { - out_horizontal_map = MMNodeUniversalProperty.new(); - out_horizontal_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +void MMWeave::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(out_main); + mm_graph_node->add_slot_texture_universal(out_horizontal_map); + mm_graph_node->add_slot_texture_universal(out_vertical_map); + //, Vector2(1, 32))//, Vector2(0, 32)); + mm_graph_node->add_slot_vector2("get_size", "set_size", "Size"); + mm_graph_node->add_slot_vector2_universal(width); + mm_graph_node->add_slot_int("get_stitch", "set_stitch", "Stitch"); } - out_horizontal_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; +void MMWeave::_render(const Ref &material) { + Ref main_pattern; + Ref horizontal_map; + Ref vertical_map; - if (!out_vertical_map) { - out_vertical_map = MMNodeUniversalProperty.new(); - out_vertical_map.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + main_pattern.instance(); + horizontal_map.instance(); + vertical_map.instance(); + + main_pattern->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + horizontal_map->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + vertical_map->create(material->image_size.x, material->image_size.y, false, Image::FORMAT_RGBA8); + + main_pattern->lock(); + horizontal_map->lock(); + vertical_map->lock(); + + float w = material->image_size.x; + float h = material->image_size.y; + //float pseed = Math::randf() + Math::rand(); + + for (int x = 0; x < material->image_size.x; ++x) { //x in range(material.image_size.x) + for (int y = 0; y < material->image_size.y; ++y) { //y in range(material.image_size.y) + Vector2 uv = Vector2(x / w, y / h); + Vector2 width_val = width->get_value(uv); + //vec3 $(name_uv) = weave2($uv, vec2($columns, $rows), $stitch, $width_x*$width_map($uv), $width_y*$width_map($uv)); + Vector3 weave = MMAlgos::weave2(uv, size, stitch, width_val.x, width_val.y); + //Outputs:; + //Output (float) - Shows the generated greyscale weave pattern.; + //$(name_uv).x; + Color main_pattern_col = Color(weave.x, weave.x, weave.x, 1); + //Horizontal mask (float) - Horizontal mask; + //$(name_uv).y; + Color horizontal_map_col = Color(weave.y, weave.y, weave.y, 1); + //Vertical mask (float) - Mask for vertical stripes; + //$(name_uv).z; + Color vertical_map_col = Color(weave.z, weave.z, weave.z, 1); + + main_pattern->set_pixel(x, y, main_pattern_col); + horizontal_map->set_pixel(x, y, horizontal_map_col); + vertical_map->set_pixel(x, y, vertical_map_col); + } + } + + main_pattern->unlock(); + horizontal_map->unlock(); + vertical_map->unlock(); + + out_main->set_value(main_pattern); + out_horizontal_map->set_value(horizontal_map); + out_vertical_map->set_value(vertical_map); } - out_vertical_map.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!width) { - width = MMNodeUniversalProperty.new(); - width.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; - width.set_default_value(Vector2(0.9, 0.9)); +Color MMWeave::_get_value_for(const Vector2 &uv, const int pseed) { + return Color(); } - width.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - width.slot_name = "Width"; - width.value_step = 0.01; - width.value_range = Vector2(0, 1); - register_output_property(out_main); - register_output_property(out_horizontal_map); - register_output_property(out_vertical_map); - register_input_property(width); +MMWeave::MMWeave() { + size = Vector2(4, 4); + stitch = 1; } - - void Weave::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(out_main); - mm_graph_node.add_slot_texture_universal(out_horizontal_map); - mm_graph_node.add_slot_texture_universal(out_vertical_map); - //, Vector2(1, 32))//, Vector2(0, 32)); - mm_graph_node.add_slot_vector2("get_size", "set_size", "Size"); - mm_graph_node.add_slot_vector2_universal(width); - mm_graph_node.add_slot_int("get_stitch", "set_stitch", "Stitch"); +MMWeave::~MMWeave() { } +void MMWeave::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_out_main"), &MMWeave::get_out_main); + ClassDB::bind_method(D_METHOD("set_out_main", "value"), &MMWeave::set_out_main); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_main", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_main", "get_out_main"); - void Weave::_render(const Variant &material) { - Ref main_pattern = Image.new(); - Ref horizontal_map = Image.new(); - Ref vertical_map = Image.new(); - main_pattern.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - horizontal_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - vertical_map.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8); - main_pattern.lock(); - horizontal_map.lock(); - vertical_map.lock(); - float w = material.image_size.x; - float h = material.image_size.y; - float pseed = randf() + randi(); + ClassDB::bind_method(D_METHOD("get_out_horizontal_map"), &MMWeave::get_out_horizontal_map); + ClassDB::bind_method(D_METHOD("set_out_horizontal_map", "value"), &MMWeave::set_out_horizontal_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_horizontal_map", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_horizontal_map", "get_out_horizontal_map"); - for (int x = 0; x < material.image_size.x; ++x) { //x in range(material.image_size.x) + ClassDB::bind_method(D_METHOD("get_out_vertical_map"), &MMWeave::get_out_vertical_map); + ClassDB::bind_method(D_METHOD("set_out_vertical_map", "value"), &MMWeave::set_out_vertical_map); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_vertical_map", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_out_vertical_map", "get_out_vertical_map"); - for (int y = 0; y < material.image_size.y; ++y) { //y in range(material.image_size.y) - Vector2 uv = Vector2(x / w, y / h); - Vector2 width_val = width.get_value(uv); - //vec3 $(name_uv) = weave2($uv, vec2($columns, $rows), $stitch, $width_x*$width_map($uv), $width_y*$width_map($uv)); - Vector3 weave = MMAlgos.weave2(uv, size, stitch, width_val.x, width_val.y); - //Outputs:; - //Output (float) - Shows the generated greyscale weave pattern.; - //$(name_uv).x; - Color main_pattern_col = Color(weave.x, weave.x, weave.x, 1); - //Horizontal mask (float) - Horizontal mask; - //$(name_uv).y; - Color horizontal_map_col = Color(weave.y, weave.y, weave.y, 1); - //Vertical mask (float) - Mask for vertical stripes; - //$(name_uv).z; - Color vertical_map_col = Color(weave.z, weave.z, weave.z, 1); - main_pattern.set_pixel(x, y, main_pattern_col); - horizontal_map.set_pixel(x, y, horizontal_map_col); - vertical_map.set_pixel(x, y, vertical_map_col); + ClassDB::bind_method(D_METHOD("get_size"), &MMWeave::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMWeave::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + + ClassDB::bind_method(D_METHOD("get_width"), &MMWeave::get_width); + ClassDB::bind_method(D_METHOD("set_width", "value"), &MMWeave::set_width); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_width", "get_width"); + + ClassDB::bind_method(D_METHOD("get_stitch"), &MMWeave::get_stitch); + ClassDB::bind_method(D_METHOD("set_stitch", "value"), &MMWeave::set_stitch); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stitch"), "set_stitch", "get_stitch"); } - -} - - main_pattern.unlock(); - horizontal_map.unlock(); - vertical_map.unlock(); - out_main.set_value(main_pattern); - out_horizontal_map.set_value(horizontal_map); - out_vertical_map.set_value(vertical_map); -} - - - Color Weave::_get_value_for(const Vector2 &uv, const int pseed) { - return Color(); -} - - //size; - - Vector2 Weave::get_size() { - return size; -} - - - void Weave::set_size(const Vector2 &val) { - size = val; - set_dirty(true); -} - - //stitch; - - int Weave::get_stitch() { - return stitch; -} - - - void Weave::set_stitch(const int val) { - stitch = val; - set_dirty(true); -} - -} - - Weave::Weave() { - out_main; - out_horizontal_map; - out_vertical_map; - size = Vector2(4, 4); - width; - stitch = 1; - } - - Weave::~Weave() { - } - - - static void Weave::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_out_main"), &Weave::get_out_main); - ClassDB::bind_method(D_METHOD("set_out_main", "value"), &Weave::set_out_main); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_main", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_main", "get_out_main"); - - - ClassDB::bind_method(D_METHOD("get_out_horizontal_map"), &Weave::get_out_horizontal_map); - ClassDB::bind_method(D_METHOD("set_out_horizontal_map", "value"), &Weave::set_out_horizontal_map); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_horizontal_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_horizontal_map", "get_out_horizontal_map"); - - - ClassDB::bind_method(D_METHOD("get_out_vertical_map"), &Weave::get_out_vertical_map); - ClassDB::bind_method(D_METHOD("set_out_vertical_map", "value"), &Weave::set_out_vertical_map); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "out_vertical_map", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_out_vertical_map", "get_out_vertical_map"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Weave::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Weave::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("get_width"), &Weave::get_width); - ClassDB::bind_method(D_METHOD("set_width", "value"), &Weave::set_width); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_width", "get_width"); - - - ClassDB::bind_method(D_METHOD("get_stitch"), &Weave::get_stitch); - ClassDB::bind_method(D_METHOD("set_stitch", "value"), &Weave::set_stitch); - ADD_PROPERTY(PropertyInfo(Variant::INT, "stitch"), "set_stitch", "get_stitch"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Weave::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Weave::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Weave::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Weave::_get_value_for); - ClassDB::bind_method(D_METHOD("get_size"), &Weave::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Weave::set_size); - ClassDB::bind_method(D_METHOD("get_stitch"), &Weave::get_stitch); - ClassDB::bind_method(D_METHOD("set_stitch", "val"), &Weave::set_stitch); - - } - - - diff --git a/modules/material_maker/nodes/pattern/weave.h b/modules/material_maker/nodes/pattern/weave.h index eaf6fb0c0..cc01ef4fe 100644 --- a/modules/material_maker/nodes/pattern/weave.h +++ b/modules/material_maker/nodes/pattern/weave.h @@ -1,61 +1,48 @@ -#ifndef WEAVE_H -#define WEAVE_H +#ifndef MM_WEAVE_H +#define MM_WEAVE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Weave : public MMNode { - GDCLASS(Weave, MMNode); +class MMWeave : public MMNode { + GDCLASS(MMWeave, MMNode); - public: +public: + Ref get_out_main(); + void set_out_main(const Ref &val); - Ref get_out_main(); - void set_out_main(const Ref &val); + Ref get_out_horizontal_map(); + void set_out_horizontal_map(const Ref &val); - Ref get_out_horizontal_map(); - void set_out_horizontal_map(const Ref &val); + Ref get_out_vertical_map(); + void set_out_vertical_map(const Ref &val); - Ref get_out_vertical_map(); - void set_out_vertical_map(const Ref &val); + Vector2 get_size(); + void set_size(const Vector2 &val); - Vector2 get_size(); - void set_size(const Vector2 &val); + Ref get_width(); + void set_width(const Ref &val); - Ref get_width(); - void set_width(const Ref &val); + int get_stitch() const; + void set_stitch(const int val); - int get_stitch() const; - void set_stitch(const int val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _render(const Variant &material); - Color _get_value_for(const Vector2 &uv, const int pseed); - Vector2 get_size(); - void set_size(const Vector2 &val); - int get_stitch(); - void set_stitch(const int val); + MMWeave(); + ~MMWeave(); - Weave(); - ~Weave(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref out_main; - //export(Resource) - Ref out_horizontal_map; - //export(Resource) - Ref out_vertical_map; - //export(Vector2) - Vector2 size = Vector2(4, 4); - //export(Resource) - Ref width; - //export(int) - int stitch = 1; - //size - //stitch + Ref out_main; + Ref out_horizontal_map; + Ref out_vertical_map; + Vector2 size; + Ref width; + int stitch; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index 9db0bc017..fa11233f2 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -107,6 +107,16 @@ SOFTWARE. #include "nodes/sdf2d/sd_op_rounded_shape.h" #include "nodes/sdf2d/sd_op_smooth_bool.h" +#include "nodes/pattern/beehive.h" +#include "nodes/pattern/bricks.h" +#include "nodes/pattern/iching.h" +#include "nodes/pattern/pattern.h" +#include "nodes/pattern/runes.h" +#include "nodes/pattern/scratches.h" +#include "nodes/pattern/sine_wave.h" +#include "nodes/pattern/truchet.h" +#include "nodes/pattern/weave.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -238,6 +248,25 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("SDF2D - OP", "MMSdOpAnnularShape"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMWeave"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMTruchet"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMSineWave"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMScratches"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMRunes"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMPattern"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMIching"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMBricks"); + ClassDB::register_class(); + MMAlgos::register_node_class("Patterns", "MMBeehive"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));