diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index 83a4cdfc1..93dfd873b 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -52,6 +52,8 @@ sources = [ "nodes/uniform/uniform.cpp", "nodes/uniform/greyscale_uniform.cpp", + + "nodes/transform/translate.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index d1dbbb38b..4dec6fd44 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -22,6 +22,8 @@ def get_doc_classes(): "MMUniform", "MMGreyscaleUniform", + + "MMTranslate", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/transform/translate.cpp b/modules/material_maker/nodes/transform/translate.cpp index 6ffda9332..628bea47a 100644 --- a/modules/material_maker/nodes/transform/translate.cpp +++ b/modules/material_maker/nodes/transform/translate.cpp @@ -1,133 +1,87 @@ #include "translate.h" +#include "../../editor/mm_graph_node.h" -Ref Translate::get_image() { - return image; +Ref MMTranslate::get_image() { + return image; } -void Translate::set_image(const Ref &val) { -image = val; +void MMTranslate::set_image(const Ref &val) { + image = val; } - -Ref Translate::get_input() { - return input; +Ref MMTranslate::get_input() { + return input; } -void Translate::set_input(const Ref &val) { -input = val; +void MMTranslate::set_input(const Ref &val) { + input = val; } - -Vector2 Translate::get_translation() { - return translation; +Vector2 MMTranslate::get_translation() { + return translation; } -void Translate::set_translation(const Vector2 &val) { -translation = val; +void MMTranslate::set_translation(const Vector2 &val) { + translation = val; + set_dirty(true); } +void MMTranslate::_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 translation = Vector2(); + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } - void Translate::_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 = ">>> Input1 "; - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; +void MMTranslate::_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_translation", "set_translation", "Translation", 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 MMTranslate::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void Translate::_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_translation", "set_translation", "Translation", 0.01); +Color MMTranslate::_get_value_for(const Vector2 &uv, const int pseed) { + //$i($uv-vec2($translate_x, $translate_y)); + return input->get_value(uv - translation); } - - void Translate::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +MMTranslate::MMTranslate() { } - - Color Translate::_get_value_for(const Vector2 &uv, const int pseed) { - //$i($uv-vec2($translate_x, $translate_y)); - return input.get_value(uv - translation); +MMTranslate::~MMTranslate() { } - //translation; +void MMTranslate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMTranslate::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMTranslate::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - Vector2 Translate::get_translation() { - return translation; + ClassDB::bind_method(D_METHOD("get_input"), &MMTranslate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMTranslate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); + + ClassDB::bind_method(D_METHOD("get_translation"), &MMTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "value"), &MMTranslate::set_translation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "translation"), "set_translation", "get_translation"); } - - - void Translate::set_translation(const Vector2 &val) { - translation = val; - set_dirty(true); -} - -} - - Translate::Translate() { - image; - input; - translation = Vector2(); - } - - Translate::~Translate() { - } - - - static void Translate::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Translate::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Translate::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_input"), &Translate::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Translate::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_translation"), &Translate::get_translation); - ClassDB::bind_method(D_METHOD("set_translation", "value"), &Translate::set_translation); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "translation"), "set_translation", "get_translation"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Translate::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Translate::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &Translate::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Translate::_get_value_for); - ClassDB::bind_method(D_METHOD("get_translation"), &Translate::get_translation); - ClassDB::bind_method(D_METHOD("set_translation", "val"), &Translate::set_translation); - - } - - - diff --git a/modules/material_maker/nodes/transform/translate.h b/modules/material_maker/nodes/transform/translate.h index 911d81e79..b38b365ce 100644 --- a/modules/material_maker/nodes/transform/translate.h +++ b/modules/material_maker/nodes/transform/translate.h @@ -1,43 +1,36 @@ -#ifndef TRANSLATE_H -#define TRANSLATE_H +#ifndef MM_TRANSLATE_H +#define MM_TRANSLATE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Translate : public MMNode { - GDCLASS(Translate, MMNode); +class MMTranslate : public MMNode { + GDCLASS(MMTranslate, 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_translation(); + void set_translation(const Vector2 &val); - Vector2 get_translation(); - void set_translation(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_translation(); - void set_translation(const Vector2 &val); + MMTranslate(); + ~MMTranslate(); - Translate(); - ~Translate(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(Resource) - Ref input; - //export(Vector2) - Vector2 translation = Vector2(); - //translation + Ref image; + Ref input; + Vector2 translation; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index cadd0cc0b..ac5f40c7d 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/translate.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -62,10 +64,13 @@ void register_material_maker_types() { ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); MMAlgos::register_node_class("Uniform", "MMUniform"); + ClassDB::register_class(); MMAlgos::register_node_class("Uniform", "MMGreyscaleUniform"); + ClassDB::register_class(); + MMAlgos::register_node_class("Transform", "MMTranslate"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));