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/greyscale_uniform.cpp",
"nodes/transform/translate.cpp",
]
if env["tools"]:

View File

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

View File

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

View File

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