diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index bbb585fdd..d1973152e 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -59,6 +59,8 @@ sources = [ "nodes/transform/shear.cpp", "nodes/transform/scale.cpp", "nodes/transform/rotate.cpp", + "nodes/transform/repeat.cpp", + "nodes/transform/mirror.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 57eaee8a2..2d01624ad 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -29,6 +29,8 @@ def get_doc_classes(): "MMShear", "MMScale", "MMRotate", + "MMRepeat", + "MMMirror", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/transform/mirror.cpp b/modules/material_maker/nodes/transform/mirror.cpp index 92da19759..b69fd89ba 100644 --- a/modules/material_maker/nodes/transform/mirror.cpp +++ b/modules/material_maker/nodes/transform/mirror.cpp @@ -1,175 +1,119 @@ #include "mirror.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Mirror::get_image() { - return image; +Ref MMMirror::get_image() { + return image; } -void Mirror::set_image(const Ref &val) { -image = val; +void MMMirror::set_image(const Ref &val) { + image = val; } - -Ref Mirror::get_input() { - return input; +Ref MMMirror::get_input() { + return input; } -void Mirror::set_input(const Ref &val) { -input = val; +void MMMirror::set_input(const Ref &val) { + input = val; } - -int Mirror::get_direction() const { - return direction; +int MMMirror::get_direction() const { + return direction; } -void Mirror::set_direction(const int val) { -direction = val; +void MMMirror::set_direction(const int val) { + direction = val; + set_dirty(true); } - -float Mirror::get_offset() const { - return offset; +float MMMirror::get_offset() const { + return offset; } -void Mirror::set_offset(const float val) { -offset = val; +void MMMirror::set_offset(const float val) { + offset = val; + set_dirty(true); } +void MMMirror::_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 offset = 0; + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Mirror::_init_properties() { - - if (!input) { - input = MMNodeUniversalProperty.new(); - input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; - input.set_default_value(Color(0, 0, 0, 1)); + //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); + //image.force_override = true; + register_input_property(input); + register_output_property(image); } - input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - input.slot_name = ">>> Input "; +void MMMirror::_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_offset", "set_offset", "offset", 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 MMMirror::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } +Color MMMirror::_get_value_for(const Vector2 &uv, const int pseed) { + //$i(uvmirror_$direction($uv, $offset)); - void Mirror::_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_offset", "set_offset", "offset", 0.01); + if (direction == 0) { + return input->get_value(MMAlgos::uvmirror_h(uv, offset)); + } + + else if (direction == 1) { + return input->get_value(MMAlgos::uvmirror_v(uv, offset)); + } + + return Color(0, 0, 0, 1); } - - void Mirror::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMMirror::MMMirror() { + direction = 0; + offset = 0; } - - Color Mirror::_get_value_for(const Vector2 &uv, const int pseed) { - //$i(uvmirror_$direction($uv, $offset)); - - if (direction == 0) { - return input.get_value(MMAlgos.uvmirror_h(uv, offset)); +MMMirror::~MMMirror() { } +void MMMirror::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMMirror::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMMirror::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(MMAlgos.uvmirror_v(uv, offset)); + ClassDB::bind_method(D_METHOD("get_input"), &MMMirror::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMMirror::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + ClassDB::bind_method(D_METHOD("get_direction"), &MMMirror::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "value"), &MMMirror::set_direction); + ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); + + ClassDB::bind_method(D_METHOD("get_offset"), &MMMirror::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "value"), &MMMirror::set_offset); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); } - - return Color(0, 0, 0, 1); -} - - //direction; - - int Mirror::get_direction() { - return direction; -} - - - void Mirror::set_direction(const int val) { - direction = val; - set_dirty(true); -} - - //offset; - - float Mirror::get_offset() { - return offset; -} - - - void Mirror::set_offset(const float val) { - offset = val; - set_dirty(true); -} - -} - - Mirror::Mirror() { - image; - input; - direction = 0; - offset = 0; - } - - Mirror::~Mirror() { - } - - - static void Mirror::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Mirror::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Mirror::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_input"), &Mirror::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Mirror::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_direction"), &Mirror::get_direction); - ClassDB::bind_method(D_METHOD("set_direction", "value"), &Mirror::set_direction); - ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction"); - - - ClassDB::bind_method(D_METHOD("get_offset"), &Mirror::get_offset); - ClassDB::bind_method(D_METHOD("set_offset", "value"), &Mirror::set_offset); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "offset"), "set_offset", "get_offset"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Mirror::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Mirror::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Mirror::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Mirror::_get_value_for); - ClassDB::bind_method(D_METHOD("get_direction"), &Mirror::get_direction); - ClassDB::bind_method(D_METHOD("set_direction", "val"), &Mirror::set_direction); - ClassDB::bind_method(D_METHOD("get_offset"), &Mirror::get_offset); - ClassDB::bind_method(D_METHOD("set_offset", "val"), &Mirror::set_offset); - - } - - - diff --git a/modules/material_maker/nodes/transform/mirror.h b/modules/material_maker/nodes/transform/mirror.h index 324095496..573a57862 100644 --- a/modules/material_maker/nodes/transform/mirror.h +++ b/modules/material_maker/nodes/transform/mirror.h @@ -1,51 +1,41 @@ -#ifndef MIRROR_H -#define MIRROR_H +#ifndef MM_MIRROR_H +#define MM_MIRROR_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Mirror : public MMNode { - GDCLASS(Mirror, MMNode); +class MMMirror : public MMNode { + GDCLASS(MMMirror, 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_offset() const; + void set_offset(const float val); - float get_offset() const; - void set_offset(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_offset(); - void set_offset(const float val); + MMMirror(); + ~MMMirror(); - Mirror(); - ~Mirror(); +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 offset = 0; - //direction - //offset + Ref image; + Ref input; + //export(int, "Horizontal,Vertical") + int direction; + float offset; }; - #endif diff --git a/modules/material_maker/nodes/transform/repeat.cpp b/modules/material_maker/nodes/transform/repeat.cpp index f679c7fa7..b867def3e 100644 --- a/modules/material_maker/nodes/transform/repeat.cpp +++ b/modules/material_maker/nodes/transform/repeat.cpp @@ -1,69 +1,51 @@ #include "repeat.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Repeat::get_input() { - return input; +Ref MMRepeat::get_input() { + return input; } -void Repeat::set_input(const Ref &val) { -input = val; +void MMRepeat::set_input(const Ref &val) { + input = val; } +void MMRepeat::_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(">>> Apply >>>"); + //input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; + input->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + input->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref input; - - void Repeat::_init_properties() { - - 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(input); } - input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - input.slot_name = ">>> Apply >>>"; - //input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; - input.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - input.get_value_from_owner = true; - register_input_property(input); - register_output_property(input); +void MMRepeat::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(input); } - - void Repeat::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(input); +Variant MMRepeat::_get_property_value(const Vector2 &uv) { + return input->get_value(MMAlgos::fractv2(uv), true); } - - void Repeat::_get_property_value(const Vector2 &uv) { - return input.get_value(MMAlgos.fractv2(uv), true); +MMRepeat::MMRepeat() { } +MMRepeat::~MMRepeat() { } - Repeat::Repeat() { - input; - } - - Repeat::~Repeat() { - } - - - static void Repeat::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_input"), &Repeat::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Repeat::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Repeat::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Repeat::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &Repeat::_get_property_value); - - } - - - +void MMRepeat::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &MMRepeat::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMRepeat::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); +} diff --git a/modules/material_maker/nodes/transform/repeat.h b/modules/material_maker/nodes/transform/repeat.h index 4ca66c961..36b907156 100644 --- a/modules/material_maker/nodes/transform/repeat.h +++ b/modules/material_maker/nodes/transform/repeat.h @@ -1,29 +1,27 @@ -#ifndef REPEAT_H -#define REPEAT_H +#ifndef MM_REPEAT_H +#define MM_REPEAT_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Repeat : public MMNode { - GDCLASS(Repeat, MMNode); +class MMRepeat : public MMNode { + GDCLASS(MMRepeat, MMNode); - public: +public: + Ref get_input(); + void set_input(const Ref &val); - Ref get_input(); - void set_input(const Ref &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Variant _get_property_value(const Vector2 &uv); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _get_property_value(const Vector2 &uv); + MMRepeat(); + ~MMRepeat(); - Repeat(); - ~Repeat(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref input; + Ref input; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index 542458f7f..3e51b8858 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/mirror.h" +#include "nodes/transform/repeat.h" #include "nodes/transform/rotate.h" #include "nodes/transform/scale.h" #include "nodes/transform/shear.h" @@ -85,6 +87,10 @@ void register_material_maker_types() { MMAlgos::register_node_class("Transform", "MMScale"); ClassDB::register_class(); MMAlgos::register_node_class("Transform", "MMRotate"); + ClassDB::register_class(); + MMAlgos::register_node_class("Transform", "MMRepeat"); + ClassDB::register_class(); + MMAlgos::register_node_class("Transform", "MMMirror"); _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));