Cleaned up MMTranslate.

This commit is contained in:
Relintai 2022-06-16 18:59:21 +02:00
parent 90f6ba8369
commit 20af76c795
5 changed files with 88 additions and 132 deletions

View File

@ -52,6 +52,8 @@ sources = [
"nodes/uniform/uniform.cpp", "nodes/uniform/uniform.cpp",
"nodes/uniform/greyscale_uniform.cpp", "nodes/uniform/greyscale_uniform.cpp",
"nodes/transform/translate.cpp",
] ]
if env["tools"]: if env["tools"]:

View File

@ -22,6 +22,8 @@ def get_doc_classes():
"MMUniform", "MMUniform",
"MMGreyscaleUniform", "MMGreyscaleUniform",
"MMTranslate",
] ]
def get_doc_path(): def get_doc_path():

View File

@ -1,133 +1,87 @@
#include "translate.h" #include "translate.h"
#include "../../editor/mm_graph_node.h"
Ref<Resource> Translate::get_image() { Ref<MMNodeUniversalProperty> MMTranslate::get_image() {
return image; return image;
} }
void Translate::set_image(const Ref<Resource> &val) { void MMTranslate::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
Ref<MMNodeUniversalProperty> MMTranslate::get_input() {
Ref<Resource> Translate::get_input() {
return input; return input;
} }
void Translate::set_input(const Ref<Resource> &val) { void MMTranslate::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val; input = val;
} }
Vector2 MMTranslate::get_translation() {
Vector2 Translate::get_translation() {
return translation; return translation;
} }
void Translate::set_translation(const Vector2 &val) { void MMTranslate::set_translation(const Vector2 &val) {
translation = val; translation = val;
set_dirty(true);
} }
void MMTranslate::_init_properties() {
if (!input.is_valid()) {
//tool; input.instance();
//export(Resource) ; input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR);
Ref<Resource> image; input->set_default_value(Color(0, 0, 0, 1));
//export(Resource) ;
Ref<Resource> input;
//export(Vector2) ;
Vector2 translation = Vector2();
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));
} }
input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input.slot_name = ">>> Input1 "; input->set_slot_name(">>> Input1 ");
if (!image) { if (!image.is_valid()) {
image = MMNodeUniversalProperty.new(); image.instance();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
} }
//image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT;
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
//image.force_override = true; //image.force_override = true;
register_input_property(input); register_input_property(input);
register_output_property(image); register_output_property(image);
} }
void MMTranslate::_register_methods(MMGraphNode *mm_graph_node) {
void Translate::_register_methods(const Variant &mm_graph_node) { mm_graph_node->add_slot_label_universal(input);
mm_graph_node.add_slot_label_universal(input); mm_graph_node->add_slot_texture_universal(image);
mm_graph_node.add_slot_texture_universal(image); mm_graph_node->add_slot_vector2("get_translation", "set_translation", "Translation", 0.01);
mm_graph_node.add_slot_vector2("get_translation", "set_translation", "Translation", 0.01);
} }
void MMTranslate::_render(const Ref<MMMaterial> &material) {
void Translate::_render(const Variant &material) {
Ref<Image> img = render_image(material); Ref<Image> img = render_image(material);
image.set_value(img); image->set_value(img);
} }
Color MMTranslate::_get_value_for(const Vector2 &uv, const int pseed) {
Color Translate::_get_value_for(const Vector2 &uv, const int pseed) {
//$i($uv-vec2($translate_x, $translate_y)); //$i($uv-vec2($translate_x, $translate_y));
return input.get_value(uv - translation); return input->get_value(uv - translation);
} }
//translation; MMTranslate::MMTranslate() {
Vector2 Translate::get_translation() {
return translation;
} }
MMTranslate::~MMTranslate() {
void Translate::set_translation(const Vector2 &val) {
translation = val;
set_dirty(true);
} }
} 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<MMNodeUniversalProperty>"), "set_image", "get_image");
Translate::Translate() { ClassDB::bind_method(D_METHOD("get_input"), &MMTranslate::get_input);
image; ClassDB::bind_method(D_METHOD("set_input", "value"), &MMTranslate::set_input);
input; ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_input", "get_input");
translation = Vector2();
}
Translate::~Translate() { ClassDB::bind_method(D_METHOD("get_translation"), &MMTranslate::get_translation);
} ClassDB::bind_method(D_METHOD("set_translation", "value"), &MMTranslate::set_translation);
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<Resource>"), "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<Resource>"), "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"); 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);
} }

View File

@ -1,43 +1,36 @@
#ifndef TRANSLATE_H #ifndef MM_TRANSLATE_H
#define TRANSLATE_H #define MM_TRANSLATE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Translate : public MMNode { class MMTranslate : public MMNode {
GDCLASS(Translate, MMNode); GDCLASS(MMTranslate, MMNode);
public: public:
Ref<MMNodeUniversalProperty> get_image();
void set_image(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_image(); Ref<MMNodeUniversalProperty> get_input();
void set_image(const Ref<Resource> &val); void set_input(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
Vector2 get_translation(); Vector2 get_translation();
void set_translation(const Vector2 &val); void set_translation(const Vector2 &val);
void _init_properties(); void _init_properties();
void _register_methods(const Variant &mm_graph_node); void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Variant &material); void _render(const Ref<MMMaterial> &material);
Color _get_value_for(const Vector2 &uv, const int pseed); Color _get_value_for(const Vector2 &uv, const int pseed);
Vector2 get_translation();
void set_translation(const Vector2 &val);
Translate(); MMTranslate();
~Translate(); ~MMTranslate();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> image;
//export(Resource) Ref<MMNodeUniversalProperty> input;
Ref<Resource> image; Vector2 translation;
//export(Resource)
Ref<Resource> input;
//export(Vector2)
Vector2 translation = Vector2();
//translation
}; };
#endif #endif

View File

@ -45,6 +45,8 @@ SOFTWARE.
#include "nodes/uniform/greyscale_uniform.h" #include "nodes/uniform/greyscale_uniform.h"
#include "nodes/uniform/uniform.h" #include "nodes/uniform/uniform.h"
#include "nodes/transform/translate.h"
static _MMAlgos *_mm_algos_singleton = nullptr; static _MMAlgos *_mm_algos_singleton = nullptr;
void register_material_maker_types() { void register_material_maker_types() {
@ -62,10 +64,13 @@ void register_material_maker_types() {
ClassDB::register_class<MatMakerGDEditor>(); ClassDB::register_class<MatMakerGDEditor>();
ClassDB::register_class<MMUniform>(); ClassDB::register_class<MMUniform>();
ClassDB::register_class<MMGreyscaleUniform>();
MMAlgos::register_node_class("Uniform", "MMUniform"); MMAlgos::register_node_class("Uniform", "MMUniform");
ClassDB::register_class<MMGreyscaleUniform>();
MMAlgos::register_node_class("Uniform", "MMGreyscaleUniform"); MMAlgos::register_node_class("Uniform", "MMGreyscaleUniform");
ClassDB::register_class<MMTranslate>();
MMAlgos::register_node_class("Transform", "MMTranslate");
_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()));