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() {
Ref<MMNodeUniversalProperty> MMRotate::get_image() {
return image;
}
void Rotate::set_image(const Ref<Resource> &val) {
void MMRotate::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> Rotate::get_input() {
Ref<MMNodeUniversalProperty> MMRotate::get_input() {
return input;
}
void Rotate::set_input(const Ref<Resource> &val) {
void MMRotate::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
Vector2 Rotate::get_center() {
Vector2 MMRotate::get_center() {
return center;
}
void Rotate::set_center(const Vector2 &val) {
void MMRotate::set_center(const Vector2 &val) {
center = val;
set_dirty(true);
}
float Rotate::get_rotate() const {
float MMRotate::get_rotate() const {
return rotate;
}
void Rotate::set_rotate(const float val) {
void MMRotate::set_rotate(const float val) {
rotate = val;
set_dirty(true);
}
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(Vector2) ;
Vector2 center = Vector2();
//export(float) ;
float rotate = 0;
void Rotate::_init_properties() {
if (!input) {
input = MMNodeUniversalProperty.new();
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
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.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL;
input.slot_name = ">>> Input1 ";
input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input->set_slot_name(">>> Input1 ");
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
//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;
register_input_property(input);
register_output_property(image);
}
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);
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);
}
void Rotate::_render(const Variant &material) {
void MMRotate::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
image->set_value(img);
}
Color Rotate::_get_value_for(const Vector2 &uv, const int pseed) {
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));
return input->get_value(MMAlgos::rotate(uv, center + Vector2(0.5, 0.5), rotate * 0.01745329251));
}
//center;
Vector2 Rotate::get_center() {
return center;
}
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();
MMRotate::MMRotate() {
rotate = 0;
}
Rotate::~Rotate() {
MMRotate::~MMRotate() {
}
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");
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"), &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_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);
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"), &Rotate::get_rotate);
ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Rotate::set_rotate);
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");
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,17 +1,18 @@
#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:
Ref<MMNodeUniversalProperty> get_image();
void set_image(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_image();
void set_image(const Ref<Resource> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_input();
void set_input(const Ref<MMNodeUniversalProperty> &val);
Vector2 get_center();
void set_center(const Vector2 &val);
@ -20,32 +21,20 @@ class Rotate : public MMNode {
void set_rotate(const float val);
void _init_properties();
void _register_methods(const Variant &mm_graph_node);
void _render(const Variant &material);
void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Ref<MMMaterial> &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();
~Rotate();
MMRotate();
~MMRotate();
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() {
Ref<MMNodeUniversalProperty> MMScale::get_image() {
return image;
}
void Scale::set_image(const Ref<Resource> &val) {
void MMScale::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> Scale::get_input() {
Ref<MMNodeUniversalProperty> MMScale::get_input() {
return input;
}
void Scale::set_input(const Ref<Resource> &val) {
void MMScale::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
Vector2 Scale::get_center() {
Vector2 MMScale::get_center() {
return center;
}
void Scale::set_center(const Vector2 &val) {
void MMScale::set_center(const Vector2 &val) {
center = val;
set_dirty(true);
}
Vector2 Scale::get_scale() {
Vector2 MMScale::get_scale() {
return scale;
}
void Scale::set_scale(const Vector2 &val) {
void MMScale::set_scale(const Vector2 &val) {
scale = val;
set_dirty(true);
}
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(Vector2) ;
Vector2 center = Vector2();
//export(Vector2) ;
Vector2 scale = Vector2(1, 1);
void Scale::_init_properties() {
if (!input) {
input = MMNodeUniversalProperty.new();
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
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.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL;
input.slot_name = ">>> Input1 ";
input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input->set_slot_name(">>> Input1 ");
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
//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;
register_input_property(input);
register_output_property(image);
}
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);
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);
}
void Scale::_render(const Variant &material) {
void MMScale::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
image->set_value(img);
}
Color Scale::_get_value_for(const Vector2 &uv, const int pseed) {
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));
return input->get_value(MMAlgos::scale(uv, center + Vector2(0.5, 0.5), scale));
}
//center;
Vector2 Scale::get_center() {
return center;
}
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();
MMScale::MMScale() {
scale = Vector2(1, 1);
}
Scale::~Scale() {
MMScale::~MMScale() {
}
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");
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"), &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_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);
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"), &Scale::get_scale);
ClassDB::bind_method(D_METHOD("set_scale", "value"), &Scale::set_scale);
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");
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,17 +1,18 @@
#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:
Ref<MMNodeUniversalProperty> get_image();
void set_image(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_image();
void set_image(const Ref<Resource> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_input();
void set_input(const Ref<MMNodeUniversalProperty> &val);
Vector2 get_center();
void set_center(const Vector2 &val);
@ -20,32 +21,20 @@ class Scale : public MMNode {
void set_scale(const Vector2 &val);
void _init_properties();
void _register_methods(const Variant &mm_graph_node);
void _render(const Variant &material);
void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Ref<MMMaterial> &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();
~Scale();
MMScale();
~MMScale();
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()));