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/simple/shape.cpp",
"nodes/simple/image.cpp",
]
if env["tools"]:

View File

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

View File

@ -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<Resource> Image::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMImage::get_image() {
return image;
}
void Image::set_image(const Ref<Resource> &val) {
image = val;
void MMImage::set_image(const Ref<MMNodeUniversalProperty> &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<MMImage> 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<Resource> 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<Image> 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<Resource>"), "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);
}

View File

@ -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<MMNodeUniversalProperty> get_image();
void set_image(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_image();
void set_image(const Ref<Resource> &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<Resource> image;
//export(String)
String image_path = ;
//func _render(material) -> void:
// var img : Image = render_image(material)
//
// image.set_value(img)
Ref<MMNodeUniversalProperty> image;
String image_path;
};
#endif

View File

@ -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<MMShape>();
MMAlgos::register_node_class("Simple", "MMShape");
ClassDB::register_class<MMImage>();
MMAlgos::register_node_class("Simple", "MMImage");
_mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));