Cleaned up MMScale and MMRotate.

This commit is contained in:
Relintai 2022-06-16 21:20:48 +02:00
parent 778e4948ba
commit 3e1002c71d
7 changed files with 198 additions and 330 deletions

View File

@ -57,6 +57,8 @@ sources = [
"nodes/transform/transform.cpp", "nodes/transform/transform.cpp",
"nodes/transform/tiler.cpp", "nodes/transform/tiler.cpp",
"nodes/transform/shear.cpp", "nodes/transform/shear.cpp",
"nodes/transform/scale.cpp",
"nodes/transform/rotate.cpp",
] ]
if env["tools"]: if env["tools"]:

View File

@ -27,6 +27,8 @@ def get_doc_classes():
"MMTransform", "MMTransform",
"MMTiler", "MMTiler",
"MMShear", "MMShear",
"MMScale",
"MMRotate",
] ]
def get_doc_path(): def get_doc_path():

View File

@ -1,165 +1,105 @@
#include "rotate.h" #include "rotate.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Rotate::get_image() { Ref<MMNodeUniversalProperty> MMRotate::get_image() {
return image; return image;
} }
void Rotate::set_image(const Ref<Resource> &val) { void MMRotate::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
Ref<MMNodeUniversalProperty> MMRotate::get_input() {
Ref<Resource> Rotate::get_input() { return input;
return input;
} }
void Rotate::set_input(const Ref<Resource> &val) { void MMRotate::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val; input = val;
} }
Vector2 MMRotate::get_center() {
Vector2 Rotate::get_center() { return center;
return center;
} }
void Rotate::set_center(const Vector2 &val) { void MMRotate::set_center(const Vector2 &val) {
center = val; center = val;
set_dirty(true);
} }
float MMRotate::get_rotate() const {
float Rotate::get_rotate() const { return rotate;
return rotate;
} }
void Rotate::set_rotate(const float val) { void MMRotate::set_rotate(const float val) {
rotate = val; rotate = val;
set_dirty(true);
} }
void MMRotate::_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; if (!image.is_valid()) {
//export(Resource) ; image.instance();
Ref<Resource> image; image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
//export(Resource) ; }
Ref<Resource> input;
//export(Vector2) ;
Vector2 center = Vector2();
//export(float) ;
float rotate = 0;
void Rotate::_init_properties() { //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT;
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
//image.force_override = true;
if (!input) { register_input_property(input);
input = MMNodeUniversalProperty.new(); register_output_property(image);
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
} }
input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; void MMRotate::_register_methods(MMGraphNode *mm_graph_node) {
input.slot_name = ">>> Input1 "; mm_graph_node->add_slot_label_universal(input);
mm_graph_node->add_slot_texture_universal(image);
if (!image) { mm_graph_node->add_slot_vector2("get_center", "set_center", "Center", 0.01);
image = MMNodeUniversalProperty.new(); mm_graph_node->add_slot_float("get_rotate", "set_rotate", "MMRotate", 0.1);
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
} }
//image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; void MMRotate::_render(const Ref<MMMaterial> &material) {
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; Ref<Image> img = render_image(material);
//image.force_override = true; image->set_value(img);
register_input_property(input);
register_output_property(image);
} }
Color MMRotate::_get_value_for(const Vector2 &uv, const int pseed) {
void Rotate::_register_methods(const Variant &mm_graph_node) { //$i(rotate($uv, vec2(0.5+$cx, 0.5+$cy), $rotate*0.01745329251));
mm_graph_node.add_slot_label_universal(input); return input->get_value(MMAlgos::rotate(uv, center + Vector2(0.5, 0.5), rotate * 0.01745329251));
mm_graph_node.add_slot_texture_universal(image);
mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01);
mm_graph_node.add_slot_float("get_rotate", "set_rotate", "Rotate", 0.1);
} }
MMRotate::MMRotate() {
void Rotate::_render(const Variant &material) { rotate = 0;
Ref<Image> img = render_image(material);
image.set_value(img);
} }
MMRotate::~MMRotate() {
Color Rotate::_get_value_for(const Vector2 &uv, const int pseed) {
//$i(rotate($uv, vec2(0.5+$cx, 0.5+$cy), $rotate*0.01745329251));
return input.get_value(MMAlgos.rotate(uv, center + Vector2(0.5, 0.5), rotate*0.01745329251));
} }
//center; void MMRotate::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMRotate::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMRotate::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_image", "get_image");
Vector2 Rotate::get_center() { ClassDB::bind_method(D_METHOD("get_input"), &MMRotate::get_input);
return center; ClassDB::bind_method(D_METHOD("set_input", "value"), &MMRotate::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_center"), &MMRotate::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &MMRotate::set_center);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("get_rotate"), &MMRotate::get_rotate);
ClassDB::bind_method(D_METHOD("set_rotate", "value"), &MMRotate::set_rotate);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate");
} }
void Rotate::set_center(const Vector2 &val) {
center = val;
set_dirty(true);
}
//rotate;
float Rotate::get_rotate() {
return rotate;
}
void Rotate::set_rotate(const float val) {
rotate = val;
set_dirty(true);
}
}
Rotate::Rotate() {
image;
input;
center = Vector2();
rotate = 0;
}
Rotate::~Rotate() {
}
static void Rotate::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &Rotate::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Rotate::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"), &Rotate::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &Rotate::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_center"), &Rotate::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &Rotate::set_center);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("get_rotate"), &Rotate::get_rotate);
ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Rotate::set_rotate);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate");
ClassDB::bind_method(D_METHOD("_init_properties"), &Rotate::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Rotate::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &Rotate::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Rotate::_get_value_for);
ClassDB::bind_method(D_METHOD("get_center"), &Rotate::get_center);
ClassDB::bind_method(D_METHOD("set_center", "val"), &Rotate::set_center);
ClassDB::bind_method(D_METHOD("get_rotate"), &Rotate::get_rotate);
ClassDB::bind_method(D_METHOD("set_rotate", "val"), &Rotate::set_rotate);
}

View File

@ -1,51 +1,40 @@
#ifndef ROTATE_H #ifndef MM_ROTATE_H
#define ROTATE_H #define MM_ROTATE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Rotate : public MMNode { class MMRotate : public MMNode {
GDCLASS(Rotate, MMNode); GDCLASS(MMRotate, 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(); Vector2 get_center();
void set_input(const Ref<Resource> &val); void set_center(const Vector2 &val);
Vector2 get_center(); float get_rotate() const;
void set_center(const Vector2 &val); void set_rotate(const float val);
float get_rotate() const; void _init_properties();
void set_rotate(const float val); 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(); MMRotate();
void _register_methods(const Variant &mm_graph_node); ~MMRotate();
void _render(const Variant &material);
Color _get_value_for(const Vector2 &uv, const int pseed);
Vector2 get_center();
void set_center(const Vector2 &val);
float get_rotate();
void set_rotate(const float val);
Rotate(); protected:
~Rotate(); static void _bind_methods();
protected: Ref<MMNodeUniversalProperty> image;
static void _bind_methods(); Ref<MMNodeUniversalProperty> input;
Vector2 center;
//tool float rotate;
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(Vector2)
Vector2 center = Vector2();
//export(float)
float rotate = 0;
//center
//rotate
}; };
#endif #endif

View File

@ -1,165 +1,105 @@
#include "scale.h" #include "scale.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Scale::get_image() { Ref<MMNodeUniversalProperty> MMScale::get_image() {
return image; return image;
} }
void Scale::set_image(const Ref<Resource> &val) { void MMScale::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
Ref<MMNodeUniversalProperty> MMScale::get_input() {
Ref<Resource> Scale::get_input() { return input;
return input;
} }
void Scale::set_input(const Ref<Resource> &val) { void MMScale::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val; input = val;
} }
Vector2 MMScale::get_center() {
Vector2 Scale::get_center() { return center;
return center;
} }
void Scale::set_center(const Vector2 &val) { void MMScale::set_center(const Vector2 &val) {
center = val; center = val;
set_dirty(true);
} }
Vector2 MMScale::get_scale() {
Vector2 Scale::get_scale() { return scale;
return scale;
} }
void Scale::set_scale(const Vector2 &val) { void MMScale::set_scale(const Vector2 &val) {
scale = val; scale = val;
set_dirty(true);
} }
void MMScale::_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; if (!image.is_valid()) {
//export(Resource) ; image.instance();
Ref<Resource> image; image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
//export(Resource) ; }
Ref<Resource> input;
//export(Vector2) ;
Vector2 center = Vector2();
//export(Vector2) ;
Vector2 scale = Vector2(1, 1);
void Scale::_init_properties() { //image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT;
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
//image.force_override = true;
if (!input) { register_input_property(input);
input = MMNodeUniversalProperty.new(); register_output_property(image);
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
} }
input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; void MMScale::_register_methods(MMGraphNode *mm_graph_node) {
input.slot_name = ">>> Input1 "; mm_graph_node->add_slot_label_universal(input);
mm_graph_node->add_slot_texture_universal(image);
if (!image) { mm_graph_node->add_slot_vector2("get_center", "set_center", "Center", 0.01);
image = MMNodeUniversalProperty.new(); mm_graph_node->add_slot_vector2("get_scale", "set_scale", "MMScale", 0.01);
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
} }
//image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; void MMScale::_render(const Ref<MMMaterial> &material) {
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; Ref<Image> img = render_image(material);
//image.force_override = true; image->set_value(img);
register_input_property(input);
register_output_property(image);
} }
Color MMScale::_get_value_for(const Vector2 &uv, const int pseed) {
void Scale::_register_methods(const Variant &mm_graph_node) { //$i(scale($uv, vec2(0.5+$cx, 0.5+$cy), vec2($scale_x, $scale_y)));
mm_graph_node.add_slot_label_universal(input); return input->get_value(MMAlgos::scale(uv, center + Vector2(0.5, 0.5), scale));
mm_graph_node.add_slot_texture_universal(image);
mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01);
mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.01);
} }
MMScale::MMScale() {
void Scale::_render(const Variant &material) { scale = Vector2(1, 1);
Ref<Image> img = render_image(material);
image.set_value(img);
} }
MMScale::~MMScale() {
Color Scale::_get_value_for(const Vector2 &uv, const int pseed) {
//$i(scale($uv, vec2(0.5+$cx, 0.5+$cy), vec2($scale_x, $scale_y)));
return input.get_value(MMAlgos.scale(uv, center + Vector2(0.5, 0.5), scale));
} }
//center; void MMScale::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMScale::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMScale::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_image", "get_image");
Vector2 Scale::get_center() { ClassDB::bind_method(D_METHOD("get_input"), &MMScale::get_input);
return center; ClassDB::bind_method(D_METHOD("set_input", "value"), &MMScale::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_center"), &MMScale::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &MMScale::set_center);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("get_scale"), &MMScale::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMScale::set_scale);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
} }
void Scale::set_center(const Vector2 &val) {
center = val;
set_dirty(true);
}
//scale;
Vector2 Scale::get_scale() {
return scale;
}
void Scale::set_scale(const Vector2 &val) {
scale = val;
set_dirty(true);
}
}
Scale::Scale() {
image;
input;
center = Vector2();
scale = Vector2(1, 1);
}
Scale::~Scale() {
}
static void Scale::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &Scale::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Scale::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"), &Scale::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &Scale::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_center"), &Scale::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &Scale::set_center);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("get_scale"), &Scale::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "value"), &Scale::set_scale);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
ClassDB::bind_method(D_METHOD("_init_properties"), &Scale::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Scale::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &Scale::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Scale::_get_value_for);
ClassDB::bind_method(D_METHOD("get_center"), &Scale::get_center);
ClassDB::bind_method(D_METHOD("set_center", "val"), &Scale::set_center);
ClassDB::bind_method(D_METHOD("get_scale"), &Scale::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "val"), &Scale::set_scale);
}

View File

@ -1,51 +1,40 @@
#ifndef SCALE_H #ifndef MM_SCALE_H
#define SCALE_H #define MM_SCALE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Scale : public MMNode { class MMScale : public MMNode {
GDCLASS(Scale, MMNode); GDCLASS(MMScale, 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(); Vector2 get_center();
void set_input(const Ref<Resource> &val); void set_center(const Vector2 &val);
Vector2 get_center(); Vector2 get_scale();
void set_center(const Vector2 &val); void set_scale(const Vector2 &val);
Vector2 get_scale(); void _init_properties();
void set_scale(const Vector2 &val); 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(); MMScale();
void _register_methods(const Variant &mm_graph_node); ~MMScale();
void _render(const Variant &material);
Color _get_value_for(const Vector2 &uv, const int pseed);
Vector2 get_center();
void set_center(const Vector2 &val);
Vector2 get_scale();
void set_scale(const Vector2 &val);
Scale(); protected:
~Scale(); static void _bind_methods();
protected: Ref<MMNodeUniversalProperty> image;
static void _bind_methods(); Ref<MMNodeUniversalProperty> input;
Vector2 center;
//tool Vector2 scale;
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(Vector2)
Vector2 center = Vector2();
//export(Vector2)
Vector2 scale = Vector2(1, 1);
//center
//scale
}; };
#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/rotate.h"
#include "nodes/transform/scale.h"
#include "nodes/transform/shear.h" #include "nodes/transform/shear.h"
#include "nodes/transform/tiler.h" #include "nodes/transform/tiler.h"
#include "nodes/transform/transform.h" #include "nodes/transform/transform.h"
@ -79,6 +81,10 @@ void register_material_maker_types() {
MMAlgos::register_node_class("Transform", "MMTiler"); MMAlgos::register_node_class("Transform", "MMTiler");
ClassDB::register_class<MMShear>(); ClassDB::register_class<MMShear>();
MMAlgos::register_node_class("Transform", "MMShear"); MMAlgos::register_node_class("Transform", "MMShear");
ClassDB::register_class<MMScale>();
MMAlgos::register_node_class("Transform", "MMScale");
ClassDB::register_class<MMRotate>();
MMAlgos::register_node_class("Transform", "MMRotate");
_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()));