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/tiler.cpp",
"nodes/transform/shear.cpp",
"nodes/transform/scale.cpp",
"nodes/transform/rotate.cpp",
]
if env["tools"]:

View File

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

View File

@ -1,165 +1,105 @@
#include "rotate.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Rotate::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMRotate::get_image() {
return image;
}
void Rotate::set_image(const Ref<Resource> &val) {
image = val;
void MMRotate::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> Rotate::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMRotate::get_input() {
return input;
}
void Rotate::set_input(const Ref<Resource> &val) {
input = val;
void MMRotate::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
Vector2 Rotate::get_center() {
return center;
Vector2 MMRotate::get_center() {
return center;
}
void Rotate::set_center(const Vector2 &val) {
center = val;
void MMRotate::set_center(const Vector2 &val) {
center = val;
set_dirty(true);
}
float Rotate::get_rotate() const {
return rotate;
float MMRotate::get_rotate() const {
return rotate;
}
void Rotate::set_rotate(const float val) {
rotate = val;
void MMRotate::set_rotate(const float 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;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(Vector2) ;
Vector2 center = Vector2();
//export(float) ;
float rotate = 0;
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
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) {
input = MMNodeUniversalProperty.new();
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
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 MMRotate::_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_center", "set_center", "Center", 0.01);
mm_graph_node->add_slot_float("get_rotate", "set_rotate", "MMRotate", 0.1);
}
//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 MMRotate::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
void Rotate::_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_center", "set_center", "Center", 0.01);
mm_graph_node.add_slot_float("get_rotate", "set_rotate", "Rotate", 0.1);
Color MMRotate::_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));
}
void Rotate::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
MMRotate::MMRotate() {
rotate = 0;
}
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));
MMRotate::~MMRotate() {
}
//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() {
return center;
ClassDB::bind_method(D_METHOD("get_input"), &MMRotate::get_input);
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
#define ROTATE_H
#ifndef MM_ROTATE_H
#define MM_ROTATE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Rotate : public MMNode {
GDCLASS(Rotate, MMNode);
class MMRotate : public MMNode {
GDCLASS(MMRotate, 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_center();
void set_center(const Vector2 &val);
Vector2 get_center();
void set_center(const Vector2 &val);
float get_rotate() const;
void set_rotate(const float val);
float get_rotate() const;
void set_rotate(const float 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_center();
void set_center(const Vector2 &val);
float get_rotate();
void set_rotate(const float val);
MMRotate();
~MMRotate();
Rotate();
~Rotate();
protected:
static void _bind_methods();
protected:
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(Vector2)
Vector2 center = Vector2();
//export(float)
float rotate = 0;
//center
//rotate
Ref<MMNodeUniversalProperty> image;
Ref<MMNodeUniversalProperty> input;
Vector2 center;
float rotate;
};
#endif

View File

@ -1,165 +1,105 @@
#include "scale.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Scale::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMScale::get_image() {
return image;
}
void Scale::set_image(const Ref<Resource> &val) {
image = val;
void MMScale::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> Scale::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMScale::get_input() {
return input;
}
void Scale::set_input(const Ref<Resource> &val) {
input = val;
void MMScale::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
Vector2 Scale::get_center() {
return center;
Vector2 MMScale::get_center() {
return center;
}
void Scale::set_center(const Vector2 &val) {
center = val;
void MMScale::set_center(const Vector2 &val) {
center = val;
set_dirty(true);
}
Vector2 Scale::get_scale() {
return scale;
Vector2 MMScale::get_scale() {
return scale;
}
void Scale::set_scale(const Vector2 &val) {
scale = val;
void MMScale::set_scale(const Vector2 &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;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(Vector2) ;
Vector2 center = Vector2();
//export(Vector2) ;
Vector2 scale = Vector2(1, 1);
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
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) {
input = MMNodeUniversalProperty.new();
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
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 MMScale::_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_center", "set_center", "Center", 0.01);
mm_graph_node->add_slot_vector2("get_scale", "set_scale", "MMScale", 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 MMScale::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
void Scale::_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_center", "set_center", "Center", 0.01);
mm_graph_node.add_slot_vector2("get_scale", "set_scale", "Scale", 0.01);
Color MMScale::_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));
}
void Scale::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
MMScale::MMScale() {
scale = Vector2(1, 1);
}
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));
MMScale::~MMScale() {
}
//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() {
return center;
ClassDB::bind_method(D_METHOD("get_input"), &MMScale::get_input);
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
#define SCALE_H
#ifndef MM_SCALE_H
#define MM_SCALE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Scale : public MMNode {
GDCLASS(Scale, MMNode);
class MMScale : public MMNode {
GDCLASS(MMScale, 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_center();
void set_center(const Vector2 &val);
Vector2 get_center();
void set_center(const Vector2 &val);
Vector2 get_scale();
void set_scale(const Vector2 &val);
Vector2 get_scale();
void set_scale(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_center();
void set_center(const Vector2 &val);
Vector2 get_scale();
void set_scale(const Vector2 &val);
MMScale();
~MMScale();
Scale();
~Scale();
protected:
static void _bind_methods();
protected:
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(Vector2)
Vector2 center = Vector2();
//export(Vector2)
Vector2 scale = Vector2(1, 1);
//center
//scale
Ref<MMNodeUniversalProperty> image;
Ref<MMNodeUniversalProperty> input;
Vector2 center;
Vector2 scale;
};
#endif

View File

@ -45,6 +45,8 @@ SOFTWARE.
#include "nodes/uniform/greyscale_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/tiler.h"
#include "nodes/transform/transform.h"
@ -79,6 +81,10 @@ void register_material_maker_types() {
MMAlgos::register_node_class("Transform", "MMTiler");
ClassDB::register_class<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);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));