From 778e4948ba91e02bafb42d49dfa7cd4410235c32 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 16 Jun 2022 21:09:20 +0200 Subject: [PATCH] Cleaned up MMShear. --- modules/material_maker/SCsub | 1 + modules/material_maker/config.py | 1 + .../material_maker/nodes/transform/shear.cpp | 252 +++++++----------- .../material_maker/nodes/transform/shear.h | 76 +++--- modules/material_maker/register_types.cpp | 3 + 5 files changed, 125 insertions(+), 208 deletions(-) diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index a6c00d3ac..03d4cc89b 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -56,6 +56,7 @@ sources = [ "nodes/transform/translate.cpp", "nodes/transform/transform.cpp", "nodes/transform/tiler.cpp", + "nodes/transform/shear.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 1a6bfb22e..b9fbd2ac2 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -26,6 +26,7 @@ def get_doc_classes(): "MMTranslate", "MMTransform", "MMTiler", + "MMShear", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/transform/shear.cpp b/modules/material_maker/nodes/transform/shear.cpp index b8e9f3566..ed51ac4ad 100644 --- a/modules/material_maker/nodes/transform/shear.cpp +++ b/modules/material_maker/nodes/transform/shear.cpp @@ -1,207 +1,133 @@ #include "shear.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Shear::get_image() { - return image; +Ref MMShear::get_image() { + return image; } -void Shear::set_image(const Ref &val) { -image = val; +void MMShear::set_image(const Ref &val) { + image = val; } - -Ref Shear::get_input() { - return input; +Ref MMShear::get_input() { + return input; } -void Shear::set_input(const Ref &val) { -input = val; +void MMShear::set_input(const Ref &val) { + input = val; } - -int Shear::get_direction() const { - return direction; +int MMShear::get_direction() const { + return direction; } -void Shear::set_direction(const int val) { -direction = val; +void MMShear::set_direction(const int val) { + direction = val; + set_dirty(true); } - -float Shear::get_amount() const { - return amount; +float MMShear::get_amount() const { + return amount; } -void Shear::set_amount(const float val) { -amount = val; +void MMShear::set_amount(const float val) { + amount = val; + set_dirty(true); } - -float Shear::get_center() const { - return center; +float MMShear::get_center() const { + return center; } -void Shear::set_center(const float val) { -center = val; +void MMShear::set_center(const float val) { + center = val; + set_dirty(true); } +void MMShear::_init_properties() { + if (!input.is_valid()) { + input.instance(); + input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR); + input->set_default_value(Color(0, 0, 0, 1)); + } + input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + input->set_slot_name(">>> Input "); - //tool; - //export(Resource) ; - Ref image; - //export(Resource) ; - Ref input; - //export(int, "Horizontal,Vertical") ; - int direction = 0; - //export(float) ; - float amount = 1; - //export(float) ; - float center = 0; + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Shear::_init_properties() { + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + //image.force_override = true; - if (!input) { - input = MMNodeUniversalProperty.new(); - input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; - input.set_default_value(Color(0, 0, 0, 1)); + register_input_property(input); + register_output_property(image); } - input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - input.slot_name = ">>> Input "; +void MMShear::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(input); + mm_graph_node->add_slot_texture_universal(image); - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + Array arr; + arr.push_back("Horizontal"); + arr.push_back("Vertical"); + + mm_graph_node->add_slot_enum("get_direction", "set_direction", "Direction", arr); + mm_graph_node->add_slot_float("get_amount", "set_amount", "Amount", 0.01); + mm_graph_node->add_slot_float("get_center", "set_center", "Center", 0.01); } - //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - //image.force_override = true; - register_input_property(input); - register_output_property(image); +void MMShear::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } +Color MMShear::_get_value_for(const Vector2 &uv, const int pseed) { + //$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction)); - void Shear::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(input); - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_enum("get_direction", "set_direction", "Direction", [ "Horizontal", "Vertical" ]); - mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.01); - mm_graph_node.add_slot_float("get_center", "set_center", "Center", 0.01); + if (direction == 0) { + return input->get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(1, 0)); + } else if (direction == 1) { + return input->get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(0, 1)); + } + + return Color(0, 0, 0, 1); } - - void Shear::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMShear::MMShear() { + direction = 0; + amount = 1; + center = 0; } - - Color Shear::_get_value_for(const Vector2 &uv, const int pseed) { - //$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction)); - - if (direction == 0) { - return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(1, 0)); +MMShear::~MMShear() { } +void MMShear::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMShear::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMShear::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - else if (direction == 1) { - return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(0, 1)); + ClassDB::bind_method(D_METHOD("get_input"), &MMShear::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMShear::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + ClassDB::bind_method(D_METHOD("get_direction"), &MMShear::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "value"), &MMShear::set_direction); + ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); + + ClassDB::bind_method(D_METHOD("get_amount"), &MMShear::get_amount); + ClassDB::bind_method(D_METHOD("set_amount", "value"), &MMShear::set_amount); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount"); + + ClassDB::bind_method(D_METHOD("get_center"), &MMShear::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &MMShear::set_center); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "center"), "set_center", "get_center"); } - - return Color(0, 0, 0, 1); -} - - //direction; - - int Shear::get_direction() { - return direction; -} - - - void Shear::set_direction(const int val) { - direction = val; - set_dirty(true); -} - - //amount; - - float Shear::get_amount() { - return amount; -} - - - void Shear::set_amount(const float val) { - amount = val; - set_dirty(true); -} - - //center; - - float Shear::get_center() { - return center; -} - - - void Shear::set_center(const float val) { - center = val; - set_dirty(true); -} - -} - - Shear::Shear() { - image; - input; - direction = 0; - amount = 1; - center = 0; - } - - Shear::~Shear() { - } - - - static void Shear::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Shear::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Shear::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_input"), &Shear::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Shear::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_direction"), &Shear::get_direction); - ClassDB::bind_method(D_METHOD("set_direction", "value"), &Shear::set_direction); - ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); - - - ClassDB::bind_method(D_METHOD("get_amount"), &Shear::get_amount); - ClassDB::bind_method(D_METHOD("set_amount", "value"), &Shear::set_amount); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount"); - - - ClassDB::bind_method(D_METHOD("get_center"), &Shear::get_center); - ClassDB::bind_method(D_METHOD("set_center", "value"), &Shear::set_center); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "center"), "set_center", "get_center"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Shear::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Shear::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Shear::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Shear::_get_value_for); - ClassDB::bind_method(D_METHOD("get_direction"), &Shear::get_direction); - ClassDB::bind_method(D_METHOD("set_direction", "val"), &Shear::set_direction); - ClassDB::bind_method(D_METHOD("get_amount"), &Shear::get_amount); - ClassDB::bind_method(D_METHOD("set_amount", "val"), &Shear::set_amount); - ClassDB::bind_method(D_METHOD("get_center"), &Shear::get_center); - ClassDB::bind_method(D_METHOD("set_center", "val"), &Shear::set_center); - - } - - - diff --git a/modules/material_maker/nodes/transform/shear.h b/modules/material_maker/nodes/transform/shear.h index 59f4e8fc7..16d5987ec 100644 --- a/modules/material_maker/nodes/transform/shear.h +++ b/modules/material_maker/nodes/transform/shear.h @@ -1,59 +1,45 @@ -#ifndef SHEAR_H -#define SHEAR_H +#ifndef MM_SHEAR_H +#define MM_SHEAR_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Shear : public MMNode { - GDCLASS(Shear, MMNode); +class MMShear : public MMNode { + GDCLASS(MMShear, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Ref get_input(); + void set_input(const Ref &val); - Ref get_input(); - void set_input(const Ref &val); + int get_direction() const; + void set_direction(const int val); - int get_direction() const; - void set_direction(const int val); + float get_amount() const; + void set_amount(const float val); - float get_amount() const; - void set_amount(const float val); + float get_center() const; + void set_center(const float val); - float get_center() const; - void set_center(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_direction(); - void set_direction(const int val); - float get_amount(); - void set_amount(const float val); - float get_center(); - void set_center(const float val); + MMShear(); + ~MMShear(); - Shear(); - ~Shear(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Resource) - Ref input; - //export(int, "Horizontal,Vertical") - int direction = 0; - //export(float) - float amount = 1; - //export(float) - float center = 0; - //direction - //amount - //center + Ref image; + Ref input; + //export(int, "Horizontal,Vertical") + int direction; + float amount; + float center; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index b20d38572..bae021f6c 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -45,6 +45,7 @@ SOFTWARE. #include "nodes/uniform/greyscale_uniform.h" #include "nodes/uniform/uniform.h" +#include "nodes/transform/shear.h" #include "nodes/transform/tiler.h" #include "nodes/transform/transform.h" #include "nodes/transform/translate.h" @@ -76,6 +77,8 @@ void register_material_maker_types() { MMAlgos::register_node_class("Transform", "MMTransform"); ClassDB::register_class(); MMAlgos::register_node_class("Transform", "MMTiler"); + ClassDB::register_class(); + MMAlgos::register_node_class("Transform", "MMShear"); _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));