From 3e1002c71d950818cd95a34b4d5d3e836f1f4d85 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 16 Jun 2022 21:20:48 +0200 Subject: [PATCH] Cleaned up MMScale and MMRotate. --- modules/material_maker/SCsub | 2 + modules/material_maker/config.py | 2 + .../material_maker/nodes/transform/rotate.cpp | 194 ++++++------------ .../material_maker/nodes/transform/rotate.h | 65 +++--- .../material_maker/nodes/transform/scale.cpp | 194 ++++++------------ .../material_maker/nodes/transform/scale.h | 65 +++--- modules/material_maker/register_types.cpp | 6 + 7 files changed, 198 insertions(+), 330 deletions(-) diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index 03d4cc89b..bbb585fdd 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -57,6 +57,8 @@ sources = [ "nodes/transform/transform.cpp", "nodes/transform/tiler.cpp", "nodes/transform/shear.cpp", + "nodes/transform/scale.cpp", + "nodes/transform/rotate.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index b9fbd2ac2..57eaee8a2 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -27,6 +27,8 @@ def get_doc_classes(): "MMTransform", "MMTiler", "MMShear", + "MMScale", + "MMRotate", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/transform/rotate.cpp b/modules/material_maker/nodes/transform/rotate.cpp index d349205e9..ae8f5398f 100644 --- a/modules/material_maker/nodes/transform/rotate.cpp +++ b/modules/material_maker/nodes/transform/rotate.cpp @@ -1,165 +1,105 @@ #include "rotate.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Rotate::get_image() { - return image; +Ref MMRotate::get_image() { + return image; } -void Rotate::set_image(const Ref &val) { -image = val; +void MMRotate::set_image(const Ref &val) { + image = val; } - -Ref Rotate::get_input() { - return input; +Ref MMRotate::get_input() { + return input; } -void Rotate::set_input(const Ref &val) { -input = val; +void MMRotate::set_input(const Ref &val) { + input = val; } - -Vector2 Rotate::get_center() { - return center; +Vector2 MMRotate::get_center() { + return center; } -void Rotate::set_center(const Vector2 &val) { -center = val; +void MMRotate::set_center(const Vector2 &val) { + center = val; + set_dirty(true); } - -float Rotate::get_rotate() const { - return rotate; +float MMRotate::get_rotate() const { + return rotate; } -void Rotate::set_rotate(const float val) { -rotate = val; +void MMRotate::set_rotate(const float val) { + rotate = val; + set_dirty(true); } +void MMRotate::_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(">>> Input1 "); - //tool; - //export(Resource) ; - Ref image; - //export(Resource) ; - Ref input; - //export(Vector2) ; - Vector2 center = Vector2(); - //export(float) ; - float rotate = 0; + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Rotate::_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 = ">>> Input1 "; - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +void MMRotate::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(input); + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node->add_slot_float("get_rotate", "set_rotate", "MMRotate", 0.1); } - //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 MMRotate::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Rotate::_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_vector2("get_center", "set_center", "Center", 0.01); - mm_graph_node.add_slot_float("get_rotate", "set_rotate", "Rotate", 0.1); +Color MMRotate::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(rotate($uv, vec2(0.5+$cx, 0.5+$cy), $rotate*0.01745329251)); + return input->get_value(MMAlgos::rotate(uv, center + Vector2(0.5, 0.5), rotate * 0.01745329251)); } - - void Rotate::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMRotate::MMRotate() { + rotate = 0; } - - Color Rotate::_get_value_for(const Vector2 &uv, const int pseed) { - //$i(rotate($uv, vec2(0.5+$cx, 0.5+$cy), $rotate*0.01745329251)); - return input.get_value(MMAlgos.rotate(uv, center + Vector2(0.5, 0.5), rotate*0.01745329251)); +MMRotate::~MMRotate() { } - //center; +void MMRotate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMRotate::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMRotate::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - Vector2 Rotate::get_center() { - return center; + ClassDB::bind_method(D_METHOD("get_input"), &MMRotate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMRotate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + ClassDB::bind_method(D_METHOD("get_center"), &MMRotate::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &MMRotate::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + ClassDB::bind_method(D_METHOD("get_rotate"), &MMRotate::get_rotate); + ClassDB::bind_method(D_METHOD("set_rotate", "value"), &MMRotate::set_rotate); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate"); } - - - void Rotate::set_center(const Vector2 &val) { - center = val; - set_dirty(true); -} - - //rotate; - - float Rotate::get_rotate() { - return rotate; -} - - - void Rotate::set_rotate(const float val) { - rotate = val; - set_dirty(true); -} - -} - - Rotate::Rotate() { - image; - input; - center = Vector2(); - rotate = 0; - } - - Rotate::~Rotate() { - } - - - static void Rotate::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Rotate::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Rotate::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_input"), &Rotate::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Rotate::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_center"), &Rotate::get_center); - ClassDB::bind_method(D_METHOD("set_center", "value"), &Rotate::set_center); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); - - - ClassDB::bind_method(D_METHOD("get_rotate"), &Rotate::get_rotate); - ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Rotate::set_rotate); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Rotate::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Rotate::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Rotate::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Rotate::_get_value_for); - ClassDB::bind_method(D_METHOD("get_center"), &Rotate::get_center); - ClassDB::bind_method(D_METHOD("set_center", "val"), &Rotate::set_center); - ClassDB::bind_method(D_METHOD("get_rotate"), &Rotate::get_rotate); - ClassDB::bind_method(D_METHOD("set_rotate", "val"), &Rotate::set_rotate); - - } - - - diff --git a/modules/material_maker/nodes/transform/rotate.h b/modules/material_maker/nodes/transform/rotate.h index 3941c86db..d9b1dddc8 100644 --- a/modules/material_maker/nodes/transform/rotate.h +++ b/modules/material_maker/nodes/transform/rotate.h @@ -1,51 +1,40 @@ -#ifndef ROTATE_H -#define ROTATE_H +#ifndef MM_ROTATE_H +#define MM_ROTATE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Rotate : public MMNode { - GDCLASS(Rotate, MMNode); +class MMRotate : public MMNode { + GDCLASS(MMRotate, 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); + Vector2 get_center(); + void set_center(const Vector2 &val); - Vector2 get_center(); - void set_center(const Vector2 &val); + float get_rotate() const; + void set_rotate(const float val); - float get_rotate() const; - void set_rotate(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_center(); - void set_center(const Vector2 &val); - float get_rotate(); - void set_rotate(const float val); + MMRotate(); + ~MMRotate(); - Rotate(); - ~Rotate(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Resource) - Ref input; - //export(Vector2) - Vector2 center = Vector2(); - //export(float) - float rotate = 0; - //center - //rotate + Ref image; + Ref input; + Vector2 center; + float rotate; }; - #endif diff --git a/modules/material_maker/nodes/transform/scale.cpp b/modules/material_maker/nodes/transform/scale.cpp index 3a9b4ce96..d60b8a83b 100644 --- a/modules/material_maker/nodes/transform/scale.cpp +++ b/modules/material_maker/nodes/transform/scale.cpp @@ -1,165 +1,105 @@ #include "scale.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Scale::get_image() { - return image; +Ref MMScale::get_image() { + return image; } -void Scale::set_image(const Ref &val) { -image = val; +void MMScale::set_image(const Ref &val) { + image = val; } - -Ref Scale::get_input() { - return input; +Ref MMScale::get_input() { + return input; } -void Scale::set_input(const Ref &val) { -input = val; +void MMScale::set_input(const Ref &val) { + input = val; } - -Vector2 Scale::get_center() { - return center; +Vector2 MMScale::get_center() { + return center; } -void Scale::set_center(const Vector2 &val) { -center = val; +void MMScale::set_center(const Vector2 &val) { + center = val; + set_dirty(true); } - -Vector2 Scale::get_scale() { - return scale; +Vector2 MMScale::get_scale() { + return scale; } -void Scale::set_scale(const Vector2 &val) { -scale = val; +void MMScale::set_scale(const Vector2 &val) { + scale = val; + set_dirty(true); } +void MMScale::_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(">>> Input1 "); - //tool; - //export(Resource) ; - Ref image; - //export(Resource) ; - Ref input; - //export(Vector2) ; - Vector2 center = Vector2(); - //export(Vector2) ; - Vector2 scale = Vector2(1, 1); + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Scale::_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 = ">>> Input1 "; - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +void MMScale::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(input); + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_vector2("get_center", "set_center", "Center", 0.01); + mm_graph_node->add_slot_vector2("get_scale", "set_scale", "MMScale", 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 MMScale::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Scale::_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_vector2("get_center", "set_center", "Center", 0.01); - mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.01); +Color MMScale::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(scale($uv, vec2(0.5+$cx, 0.5+$cy), vec2($scale_x, $scale_y))); + return input->get_value(MMAlgos::scale(uv, center + Vector2(0.5, 0.5), scale)); } - - void Scale::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMScale::MMScale() { + scale = Vector2(1, 1); } - - Color Scale::_get_value_for(const Vector2 &uv, const int pseed) { - //$i(scale($uv, vec2(0.5+$cx, 0.5+$cy), vec2($scale_x, $scale_y))); - return input.get_value(MMAlgos.scale(uv, center + Vector2(0.5, 0.5), scale)); +MMScale::~MMScale() { } - //center; +void MMScale::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMScale::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMScale::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - Vector2 Scale::get_center() { - return center; + ClassDB::bind_method(D_METHOD("get_input"), &MMScale::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMScale::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + ClassDB::bind_method(D_METHOD("get_center"), &MMScale::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &MMScale::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + ClassDB::bind_method(D_METHOD("get_scale"), &MMScale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMScale::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); } - - - void Scale::set_center(const Vector2 &val) { - center = val; - set_dirty(true); -} - - //scale; - - Vector2 Scale::get_scale() { - return scale; -} - - - void Scale::set_scale(const Vector2 &val) { - scale = val; - set_dirty(true); -} - -} - - Scale::Scale() { - image; - input; - center = Vector2(); - scale = Vector2(1, 1); - } - - Scale::~Scale() { - } - - - static void Scale::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Scale::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Scale::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_input"), &Scale::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Scale::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_center"), &Scale::get_center); - ClassDB::bind_method(D_METHOD("set_center", "value"), &Scale::set_center); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); - - - ClassDB::bind_method(D_METHOD("get_scale"), &Scale::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &Scale::set_scale); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Scale::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Scale::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Scale::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Scale::_get_value_for); - ClassDB::bind_method(D_METHOD("get_center"), &Scale::get_center); - ClassDB::bind_method(D_METHOD("set_center", "val"), &Scale::set_center); - ClassDB::bind_method(D_METHOD("get_scale"), &Scale::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "val"), &Scale::set_scale); - - } - - - diff --git a/modules/material_maker/nodes/transform/scale.h b/modules/material_maker/nodes/transform/scale.h index facbef5b0..477482ca1 100644 --- a/modules/material_maker/nodes/transform/scale.h +++ b/modules/material_maker/nodes/transform/scale.h @@ -1,51 +1,40 @@ -#ifndef SCALE_H -#define SCALE_H +#ifndef MM_SCALE_H +#define MM_SCALE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Scale : public MMNode { - GDCLASS(Scale, MMNode); +class MMScale : public MMNode { + GDCLASS(MMScale, 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); + Vector2 get_center(); + void set_center(const Vector2 &val); - Vector2 get_center(); - void set_center(const Vector2 &val); + Vector2 get_scale(); + void set_scale(const Vector2 &val); - Vector2 get_scale(); - void set_scale(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_center(); - void set_center(const Vector2 &val); - Vector2 get_scale(); - void set_scale(const Vector2 &val); + MMScale(); + ~MMScale(); - Scale(); - ~Scale(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Resource) - Ref input; - //export(Vector2) - Vector2 center = Vector2(); - //export(Vector2) - Vector2 scale = Vector2(1, 1); - //center - //scale + Ref image; + Ref input; + Vector2 center; + Vector2 scale; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index bae021f6c..542458f7f 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -45,6 +45,8 @@ SOFTWARE. #include "nodes/uniform/greyscale_uniform.h" #include "nodes/uniform/uniform.h" +#include "nodes/transform/rotate.h" +#include "nodes/transform/scale.h" #include "nodes/transform/shear.h" #include "nodes/transform/tiler.h" #include "nodes/transform/transform.h" @@ -79,6 +81,10 @@ void register_material_maker_types() { MMAlgos::register_node_class("Transform", "MMTiler"); ClassDB::register_class(); MMAlgos::register_node_class("Transform", "MMShear"); + ClassDB::register_class(); + MMAlgos::register_node_class("Transform", "MMScale"); + ClassDB::register_class(); + MMAlgos::register_node_class("Transform", "MMRotate"); _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));