Cleaned up MMShear.

This commit is contained in:
Relintai 2022-06-16 21:09:20 +02:00
parent 6da5703d5c
commit 778e4948ba
5 changed files with 125 additions and 208 deletions

View File

@ -56,6 +56,7 @@ sources = [
"nodes/transform/translate.cpp",
"nodes/transform/transform.cpp",
"nodes/transform/tiler.cpp",
"nodes/transform/shear.cpp",
]
if env["tools"]:

View File

@ -26,6 +26,7 @@ def get_doc_classes():
"MMTranslate",
"MMTransform",
"MMTiler",
"MMShear",
]
def get_doc_path():

View File

@ -1,207 +1,133 @@
#include "shear.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Shear::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMShear::get_image() {
return image;
}
void Shear::set_image(const Ref<Resource> &val) {
image = val;
void MMShear::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
Ref<Resource> Shear::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMShear::get_input() {
return input;
}
void Shear::set_input(const Ref<Resource> &val) {
input = val;
void MMShear::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
int Shear::get_direction() const {
return direction;
int MMShear::get_direction() const {
return direction;
}
void Shear::set_direction(const int val) {
direction = val;
void MMShear::set_direction(const int val) {
direction = val;
set_dirty(true);
}
float Shear::get_amount() const {
return amount;
float MMShear::get_amount() const {
return amount;
}
void Shear::set_amount(const float val) {
amount = val;
void MMShear::set_amount(const float val) {
amount = val;
set_dirty(true);
}
float Shear::get_center() const {
return center;
float MMShear::get_center() const {
return center;
}
void Shear::set_center(const float val) {
center = val;
void MMShear::set_center(const float val) {
center = val;
set_dirty(true);
}
void MMShear::_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(">>> Input ");
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(Resource) ;
Ref<Resource> input;
//export(int, "Horizontal,Vertical") ;
int direction = 0;
//export(float) ;
float amount = 1;
//export(float) ;
float center = 0;
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
void Shear::_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 = ">>> Input ";
void MMShear::_register_methods(MMGraphNode *mm_graph_node) {
mm_graph_node->add_slot_label_universal(input);
mm_graph_node->add_slot_texture_universal(image);
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
Array arr;
arr.push_back("Horizontal");
arr.push_back("Vertical");
mm_graph_node->add_slot_enum("get_direction", "set_direction", "Direction", arr);
mm_graph_node->add_slot_float("get_amount", "set_amount", "Amount", 0.01);
mm_graph_node->add_slot_float("get_center", "set_center", "Center", 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 MMShear::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
Color MMShear::_get_value_for(const Vector2 &uv, const int pseed) {
//$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction));
void Shear::_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_enum("get_direction", "set_direction", "Direction", [ "Horizontal", "Vertical" ]);
mm_graph_node.add_slot_float("get_amount", "set_amount", "Amount", 0.01);
mm_graph_node.add_slot_float("get_center", "set_center", "Center", 0.01);
if (direction == 0) {
return input->get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(1, 0));
} else if (direction == 1) {
return input->get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(0, 1));
}
return Color(0, 0, 0, 1);
}
void Shear::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
MMShear::MMShear() {
direction = 0;
amount = 1;
center = 0;
}
Color Shear::_get_value_for(const Vector2 &uv, const int pseed) {
//$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction));
if (direction == 0) {
return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(1, 0));
MMShear::~MMShear() {
}
void MMShear::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMShear::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMShear::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_image", "get_image");
else if (direction == 1) {
return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(0, 1));
ClassDB::bind_method(D_METHOD("get_input"), &MMShear::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &MMShear::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_direction"), &MMShear::get_direction);
ClassDB::bind_method(D_METHOD("set_direction", "value"), &MMShear::set_direction);
ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction");
ClassDB::bind_method(D_METHOD("get_amount"), &MMShear::get_amount);
ClassDB::bind_method(D_METHOD("set_amount", "value"), &MMShear::set_amount);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount");
ClassDB::bind_method(D_METHOD("get_center"), &MMShear::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &MMShear::set_center);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "center"), "set_center", "get_center");
}
return Color(0, 0, 0, 1);
}
//direction;
int Shear::get_direction() {
return direction;
}
void Shear::set_direction(const int val) {
direction = val;
set_dirty(true);
}
//amount;
float Shear::get_amount() {
return amount;
}
void Shear::set_amount(const float val) {
amount = val;
set_dirty(true);
}
//center;
float Shear::get_center() {
return center;
}
void Shear::set_center(const float val) {
center = val;
set_dirty(true);
}
}
Shear::Shear() {
image;
input;
direction = 0;
amount = 1;
center = 0;
}
Shear::~Shear() {
}
static void Shear::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &Shear::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Shear::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"), &Shear::get_input);
ClassDB::bind_method(D_METHOD("set_input", "value"), &Shear::set_input);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_input", "get_input");
ClassDB::bind_method(D_METHOD("get_direction"), &Shear::get_direction);
ClassDB::bind_method(D_METHOD("set_direction", "value"), &Shear::set_direction);
ADD_PROPERTY(PropertyInfo(Variant::INT, "direction"), "set_direction", "get_direction");
ClassDB::bind_method(D_METHOD("get_amount"), &Shear::get_amount);
ClassDB::bind_method(D_METHOD("set_amount", "value"), &Shear::set_amount);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_amount");
ClassDB::bind_method(D_METHOD("get_center"), &Shear::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &Shear::set_center);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("_init_properties"), &Shear::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Shear::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &Shear::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Shear::_get_value_for);
ClassDB::bind_method(D_METHOD("get_direction"), &Shear::get_direction);
ClassDB::bind_method(D_METHOD("set_direction", "val"), &Shear::set_direction);
ClassDB::bind_method(D_METHOD("get_amount"), &Shear::get_amount);
ClassDB::bind_method(D_METHOD("set_amount", "val"), &Shear::set_amount);
ClassDB::bind_method(D_METHOD("get_center"), &Shear::get_center);
ClassDB::bind_method(D_METHOD("set_center", "val"), &Shear::set_center);
}

View File

@ -1,59 +1,45 @@
#ifndef SHEAR_H
#define SHEAR_H
#ifndef MM_SHEAR_H
#define MM_SHEAR_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Shear : public MMNode {
GDCLASS(Shear, MMNode);
class MMShear : public MMNode {
GDCLASS(MMShear, 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);
int get_direction() const;
void set_direction(const int val);
int get_direction() const;
void set_direction(const int val);
float get_amount() const;
void set_amount(const float val);
float get_amount() const;
void set_amount(const float val);
float get_center() const;
void set_center(const float val);
float get_center() const;
void set_center(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);
int get_direction();
void set_direction(const int val);
float get_amount();
void set_amount(const float val);
float get_center();
void set_center(const float val);
MMShear();
~MMShear();
Shear();
~Shear();
protected:
static void _bind_methods();
protected:
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(int, "Horizontal,Vertical")
int direction = 0;
//export(float)
float amount = 1;
//export(float)
float center = 0;
//direction
//amount
//center
Ref<MMNodeUniversalProperty> image;
Ref<MMNodeUniversalProperty> input;
//export(int, "Horizontal,Vertical")
int direction;
float amount;
float center;
};
#endif

View File

@ -45,6 +45,7 @@ SOFTWARE.
#include "nodes/uniform/greyscale_uniform.h"
#include "nodes/uniform/uniform.h"
#include "nodes/transform/shear.h"
#include "nodes/transform/tiler.h"
#include "nodes/transform/transform.h"
#include "nodes/transform/translate.h"
@ -76,6 +77,8 @@ void register_material_maker_types() {
MMAlgos::register_node_class("Transform", "MMTransform");
ClassDB::register_class<MMTiler>();
MMAlgos::register_node_class("Transform", "MMTiler");
ClassDB::register_class<MMShear>();
MMAlgos::register_node_class("Transform", "MMShear");
_mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));