Cleaned up MMImage.

This commit is contained in:
Relintai 2022-06-17 10:17:17 +02:00
parent 4b63250bc7
commit 87b0cd5733
5 changed files with 71 additions and 106 deletions

View File

@ -66,6 +66,7 @@ sources = [
"nodes/transform/circle_map.cpp", "nodes/transform/circle_map.cpp",
"nodes/simple/shape.cpp", "nodes/simple/shape.cpp",
"nodes/simple/image.cpp",
] ]
if env["tools"]: if env["tools"]:

View File

@ -36,6 +36,7 @@ def get_doc_classes():
"MMCircleMap", "MMCircleMap",
"MMShape", "MMShape",
"MMImage",
] ]
def get_doc_path(): def get_doc_path():

View File

@ -1,104 +1,73 @@
#include "image.h" #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<Resource> Image::get_image() { Ref<MMNodeUniversalProperty> MMImage::get_image() {
return image; return image;
} }
void Image::set_image(const Ref<Resource> &val) { void MMImage::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
String MMImage::get_image_path() {
String Image::get_image_path() {
return image_path; return image_path;
} }
void Image::set_image_path(const String &val) { void MMImage::set_image_path(const String &val) {
image_path = val; image_path = val;
Ref<MMImage> img;
img.instance();
if (image_path != "") {
ImageLoader::load_image(image_path, img);
} }
image->set_value(img);
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(String) ;
String image_path = ;
void Image::_init_properties() {
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
}
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE;
register_output_property(image);
}
void Image::_register_methods(const Variant &mm_graph_node) {
mm_graph_node.add_slot_image_path_universal(image, "get_image_path", "set_image_path");
}
//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);
}
String Image::get_image_path() {
return image_path;
}
void Image::set_image_path(const String &val) {
image_path = val;
Ref<Image> img = Image.new();
if (image_path && image_path != "") {
img.load(image_path);
}
image.set_value(img);
set_dirty(true); set_dirty(true);
} }
void MMImage::_init_properties() {
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
} }
Image::Image() { image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
image;
image_path = ; register_output_property(image);
} }
Image::~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);
static void Image::_bind_methods() { Color MMImage::_get_value_for(const Vector2 &uv, const int pseed) {
ClassDB::bind_method(D_METHOD("get_image"), &Image::get_image); return image->get_value(uv);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Image::set_image); }
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_image", "get_image");
MMImage::MMImage() {
}
ClassDB::bind_method(D_METHOD("get_image_path"), &Image::get_image_path); MMImage::~MMImage() {
ClassDB::bind_method(D_METHOD("set_image_path", "value"), &Image::set_image_path); }
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");
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"); 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);
} }

View File

@ -1,40 +1,31 @@
#ifndef IMAGE_H #ifndef MM_IMAGE_H
#define IMAGE_H #define MM_IMAGE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Image : public MMNode { class MMImage : public MMNode {
GDCLASS(Image, MMNode); GDCLASS(MMImage, MMNode);
public: public:
Ref<MMNodeUniversalProperty> get_image();
Ref<Resource> get_image(); void set_image(const Ref<MMNodeUniversalProperty> &val);
void set_image(const Ref<Resource> &val);
String get_image_path(); String get_image_path();
void set_image_path(const String &val); void set_image_path(const String &val);
void _init_properties(); void _init_properties();
void _register_methods(const Variant &mm_graph_node); void _register_methods(MMGraphNode *mm_graph_node);
Color _get_value_for(const Vector2 &uv, const int pseed); Color _get_value_for(const Vector2 &uv, const int pseed);
String get_image_path();
void set_image_path(const String &val);
Image(); MMImage();
~Image(); ~MMImage();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> image;
//export(Resource) String image_path;
Ref<Resource> image;
//export(String)
String image_path = ;
//func _render(material) -> void:
// var img : Image = render_image(material)
//
// image.set_value(img)
}; };
#endif #endif

View File

@ -57,6 +57,7 @@ SOFTWARE.
#include "nodes/transform/transform.h" #include "nodes/transform/transform.h"
#include "nodes/transform/translate.h" #include "nodes/transform/translate.h"
#include "nodes/simple/image.h"
#include "nodes/simple/shape.h" #include "nodes/simple/shape.h"
static _MMAlgos *_mm_algos_singleton = nullptr; static _MMAlgos *_mm_algos_singleton = nullptr;
@ -105,6 +106,8 @@ void register_material_maker_types() {
ClassDB::register_class<MMShape>(); ClassDB::register_class<MMShape>();
MMAlgos::register_node_class("Simple", "MMShape"); MMAlgos::register_node_class("Simple", "MMShape");
ClassDB::register_class<MMImage>();
MMAlgos::register_node_class("Simple", "MMImage");
_mm_algos_singleton = memnew(_MMAlgos); _mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));