diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index f5ac524bb..2ff53eb66 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -122,6 +122,8 @@ sources = [ "nodes/pattern/iching.cpp", "nodes/pattern/bricks.cpp", "nodes/pattern/beehive.cpp", + + "nodes/other/output_image.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index b1597b044..a9cd564c5 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -92,6 +92,8 @@ def get_doc_classes(): "MMIching", "MMBricks", "MMBeehive", + + "MMOutputImage", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/other/output_image.cpp b/modules/material_maker/nodes/other/output_image.cpp index 23b6acd13..ee9d4f1db 100644 --- a/modules/material_maker/nodes/other/output_image.cpp +++ b/modules/material_maker/nodes/other/output_image.cpp @@ -1,110 +1,74 @@ #include "output_image.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref OutputImage::get_image() { - return image; +Ref MMOutputImage::get_image() { + return image; } -void OutputImage::set_image(const Ref &val) { -image = val; +void MMOutputImage::set_image(const Ref &val) { + image = val; } - -String OutputImage::get_postfix() { - return postfix; +String MMOutputImage::get_postfix() { + return postfix; } -void OutputImage::set_postfix(const String &val) { -postfix = val; +void MMOutputImage::set_postfix(const String &val) { + postfix = val; + set_dirty(true); } - - - //tool; - //export(Resource) ; - Ref image; - //export(String) ; - String postfix = ""; - - void OutputImage::_init_properties() { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; - image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - image.slot_name = "image"; - register_input_property(image); +void MMOutputImage::_init_properties() { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + image->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + image->set_slot_name("image"); + register_input_property(image); } - - void OutputImage::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_line_edit("get_postfix", "set_postfix", "postfix"); +void MMOutputImage::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_line_edit("get_postfix", "set_postfix", "postfix"); } +void MMOutputImage::_render(const Ref &material) { + if (!image.is_valid()) { + return; + } - void OutputImage::_render(const Variant &material) { + Ref img = image->get_active_image(); - if (!image) { - return; + if (!img.is_valid()) { + return; + } + + String matpath = material->get_path(); + + if (matpath == "") { + return; + } + + String matbn = matpath.get_basename(); + String final_file_name = matbn + postfix + ".png"; + img->save_png(final_file_name); } - Ref img = image.get_active_image(); - - if (!img) { - return; +MMOutputImage::MMOutputImage() { } - String matpath = material.get_path(); - - if (matpath == "") { - return; +MMOutputImage::~MMOutputImage() { } - String matbn = matpath.get_basename(); - String final_file_name = matbn + postfix + ".png"; - img.save_png(final_file_name); +void MMOutputImage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMOutputImage::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMOutputImage::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); + + ClassDB::bind_method(D_METHOD("get_postfix"), &MMOutputImage::get_postfix); + ClassDB::bind_method(D_METHOD("set_postfix", "value"), &MMOutputImage::set_postfix); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "postfix"), "set_postfix", "get_postfix"); } - - - String OutputImage::get_postfix() { - return postfix; -} - - - void OutputImage::set_postfix(const String &pf) { - postfix = pf; - set_dirty(true); -} - -} - - OutputImage::OutputImage() { - image; - postfix = ""; - } - - OutputImage::~OutputImage() { - } - - - static void OutputImage::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &OutputImage::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &OutputImage::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_postfix"), &OutputImage::get_postfix); - ClassDB::bind_method(D_METHOD("set_postfix", "value"), &OutputImage::set_postfix); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "postfix"), "set_postfix", "get_postfix"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &OutputImage::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &OutputImage::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &OutputImage::_render); - ClassDB::bind_method(D_METHOD("get_postfix"), &OutputImage::get_postfix); - ClassDB::bind_method(D_METHOD("set_postfix", "pf"), &OutputImage::set_postfix); - - } - - - diff --git a/modules/material_maker/nodes/other/output_image.h b/modules/material_maker/nodes/other/output_image.h index 120108f60..142fe0bed 100644 --- a/modules/material_maker/nodes/other/output_image.h +++ b/modules/material_maker/nodes/other/output_image.h @@ -1,36 +1,31 @@ -#ifndef OUTPUT_IMAGE_H -#define OUTPUT_IMAGE_H +#ifndef MM_OUTPUT_IMAGE_H +#define MM_OUTPUT_IMAGE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class OutputImage : public MMNode { - GDCLASS(OutputImage, MMNode); +class MMOutputImage : public MMNode { + GDCLASS(MMOutputImage, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + String get_postfix(); + void set_postfix(const String &val); - String get_postfix(); - void set_postfix(const String &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); - String get_postfix(); - void set_postfix(const String &pf); + MMOutputImage(); + ~MMOutputImage(); - OutputImage(); - ~OutputImage(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(String) - String postfix = ""; + Ref image; + String postfix; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index fa11233f2..8ef92304c 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -117,6 +117,8 @@ SOFTWARE. #include "nodes/pattern/truchet.h" #include "nodes/pattern/weave.h" +#include "nodes/other/output_image.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -267,6 +269,9 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("Patterns", "MMBeehive"); + ClassDB::register_class(); + MMAlgos::register_node_class("Output", "MMOutputImage"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));