diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index a00b2919f..72295acbc 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -66,6 +66,7 @@ sources = [ "nodes/transform/circle_map.cpp", "nodes/simple/shape.cpp", + "nodes/simple/image.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 3f23a9d80..7eb8845cd 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -36,6 +36,7 @@ def get_doc_classes(): "MMCircleMap", "MMShape", + "MMImage", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/simple/image.cpp b/modules/material_maker/nodes/simple/image.cpp index 98cfa6944..e1aed483f 100644 --- a/modules/material_maker/nodes/simple/image.cpp +++ b/modules/material_maker/nodes/simple/image.cpp @@ -1,104 +1,73 @@ #include "image.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" +#include "core/io/image_loader.h" +#include "core/io/resource_loader.h" -Ref Image::get_image() { - return image; +Ref MMImage::get_image() { + return image; } -void Image::set_image(const Ref &val) { -image = val; +void MMImage::set_image(const Ref &val) { + image = val; } - -String Image::get_image_path() { - return image_path; +String MMImage::get_image_path() { + return image_path; } -void Image::set_image_path(const String &val) { -image_path = val; +void MMImage::set_image_path(const String &val) { + image_path = val; + Ref img; + img.instance(); + + if (image_path != "") { + ImageLoader::load_image(image_path, img); + } + + image->set_value(img); + set_dirty(true); } +void MMImage::_init_properties() { + if (!image.is_valid()) { + image.instance(); + image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE); + } + image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE); - //tool; - //export(Resource) ; - Ref image; - //export(String) ; - String image_path = ; - - void Image::_init_properties() { - - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + register_output_property(image); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - register_output_property(image); +void MMImage::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_image_path_universal(image, "get_image_path", "set_image_path"); } +//func _render(material) -> void:; +// var img : MMImage = render_image(material); +//; +// image.set_value(img); - void Image::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_image_path_universal(image, "get_image_path", "set_image_path"); +Color MMImage::_get_value_for(const Vector2 &uv, const int pseed) { + return image->get_value(uv); } - //func _render(material) -> void:; - // var img : Image = render_image(material); - //; - // image.set_value(img); - - Color Image::_get_value_for(const Vector2 &uv, const int pseed) { - return image.get_value(uv); +MMImage::MMImage() { } - - String Image::get_image_path() { - return image_path; +MMImage::~MMImage() { } +void MMImage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &MMImage::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &MMImage::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - void Image::set_image_path(const String &val) { - image_path = val; - Ref img = Image.new(); - - if (image_path && image_path != "") { - img.load(image_path); + ClassDB::bind_method(D_METHOD("get_image_path"), &MMImage::get_image_path); + ClassDB::bind_method(D_METHOD("set_image_path", "value"), &MMImage::set_image_path); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path"), "set_image_path", "get_image_path"); } - - image.set_value(img); - set_dirty(true); -} - -} - - Image::Image() { - image; - image_path = ; - } - - Image::~Image() { - } - - - static void Image::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &Image::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &Image::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_image_path"), &Image::get_image_path); - ClassDB::bind_method(D_METHOD("set_image_path", "value"), &Image::set_image_path); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path"), "set_image_path", "get_image_path"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Image::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Image::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Image::_get_value_for); - ClassDB::bind_method(D_METHOD("get_image_path"), &Image::get_image_path); - ClassDB::bind_method(D_METHOD("set_image_path", "val"), &Image::set_image_path); - - } - - - diff --git a/modules/material_maker/nodes/simple/image.h b/modules/material_maker/nodes/simple/image.h index 1af951871..b829c5616 100644 --- a/modules/material_maker/nodes/simple/image.h +++ b/modules/material_maker/nodes/simple/image.h @@ -1,40 +1,31 @@ -#ifndef IMAGE_H -#define IMAGE_H +#ifndef MM_IMAGE_H +#define MM_IMAGE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Image : public MMNode { - GDCLASS(Image, MMNode); +class MMImage : public MMNode { + GDCLASS(MMImage, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + String get_image_path(); + void set_image_path(const String &val); - String get_image_path(); - void set_image_path(const String &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); - String get_image_path(); - void set_image_path(const String &val); + MMImage(); + ~MMImage(); - Image(); - ~Image(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref image; - //export(String) - String image_path = ; - //func _render(material) -> void: - // var img : Image = render_image(material) - // - // image.set_value(img) + Ref image; + String image_path; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index e3aacad29..fc6c4e8be 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -57,6 +57,7 @@ SOFTWARE. #include "nodes/transform/transform.h" #include "nodes/transform/translate.h" +#include "nodes/simple/image.h" #include "nodes/simple/shape.h" static _MMAlgos *_mm_algos_singleton = nullptr; @@ -105,6 +106,8 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("Simple", "MMShape"); + ClassDB::register_class(); + MMAlgos::register_node_class("Simple", "MMImage"); _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));