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

View File

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

View File

@ -1,207 +1,133 @@
#include "shear.h" #include "shear.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Shear::get_image() { Ref<MMNodeUniversalProperty> MMShear::get_image() {
return image; return image;
} }
void Shear::set_image(const Ref<Resource> &val) { void MMShear::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
Ref<MMNodeUniversalProperty> MMShear::get_input() {
Ref<Resource> Shear::get_input() {
return input; return input;
} }
void Shear::set_input(const Ref<Resource> &val) { void MMShear::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val; input = val;
} }
int MMShear::get_direction() const {
int Shear::get_direction() const {
return direction; return direction;
} }
void Shear::set_direction(const int val) { void MMShear::set_direction(const int val) {
direction = val; direction = val;
set_dirty(true);
} }
float MMShear::get_amount() const {
float Shear::get_amount() const {
return amount; return amount;
} }
void Shear::set_amount(const float val) { void MMShear::set_amount(const float val) {
amount = val; amount = val;
set_dirty(true);
} }
float MMShear::get_center() const {
float Shear::get_center() const {
return center; return center;
} }
void Shear::set_center(const float val) { void MMShear::set_center(const float val) {
center = val; center = val;
set_dirty(true);
} }
void MMShear::_init_properties() {
if (!input.is_valid()) {
//tool; input.instance();
//export(Resource) ; input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR);
Ref<Resource> image; input->set_default_value(Color(0, 0, 0, 1));
//export(Resource) ;
Ref<Resource> input;
//export(int, "Horizontal,Vertical") ;
int direction = 0;
//export(float) ;
float amount = 1;
//export(float) ;
float center = 0;
void Shear::_init_properties() {
if (!input) {
input = MMNodeUniversalProperty.new();
input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR;
input.set_default_value(Color(0, 0, 0, 1));
} }
input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
input.slot_name = ">>> Input "; input->set_slot_name(">>> Input ");
if (!image) { if (!image.is_valid()) {
image = MMNodeUniversalProperty.new(); image.instance();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
} }
//image.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; //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; //image.force_override = true;
register_input_property(input); register_input_property(input);
register_output_property(image); register_output_property(image);
} }
void MMShear::_register_methods(MMGraphNode *mm_graph_node) {
mm_graph_node->add_slot_label_universal(input);
mm_graph_node->add_slot_texture_universal(image);
void Shear::_register_methods(const Variant &mm_graph_node) { Array arr;
mm_graph_node.add_slot_label_universal(input); arr.push_back("Horizontal");
mm_graph_node.add_slot_texture_universal(image); arr.push_back("Vertical");
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_enum("get_direction", "set_direction", "Direction", arr);
mm_graph_node.add_slot_float("get_center", "set_center", "Center", 0.01); 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);
} }
void MMShear::_render(const Ref<MMMaterial> &material) {
void Shear::_render(const Variant &material) {
Ref<Image> img = render_image(material); Ref<Image> img = render_image(material);
image.set_value(img); image->set_value(img);
} }
Color MMShear::_get_value_for(const Vector2 &uv, const int pseed) {
Color Shear::_get_value_for(const Vector2 &uv, const int pseed) {
//$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction)); //$in($uv+$amount*($uv.yx-vec2($center))*vec2($direction));
if (direction == 0) { if (direction == 0) {
return input.get_value(uv + amount * (Vector2(uv.y, uv.x) - Vector2(center, center)) * Vector2(1, 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));
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); return Color(0, 0, 0, 1);
} }
//direction; MMShear::MMShear() {
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; direction = 0;
amount = 1; amount = 1;
center = 0; center = 0;
} }
Shear::~Shear() { 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");
static void Shear::_bind_methods() { ClassDB::bind_method(D_METHOD("get_input"), &MMShear::get_input);
ClassDB::bind_method(D_METHOD("get_image"), &Shear::get_image); ClassDB::bind_method(D_METHOD("set_input", "value"), &MMShear::set_input);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Shear::set_image); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_input", "get_input");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_image", "get_image");
ClassDB::bind_method(D_METHOD("get_direction"), &MMShear::get_direction);
ClassDB::bind_method(D_METHOD("get_input"), &Shear::get_input); ClassDB::bind_method(D_METHOD("set_direction", "value"), &MMShear::set_direction);
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"); 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("get_amount"), &Shear::get_amount); ClassDB::bind_method(D_METHOD("set_amount", "value"), &MMShear::set_amount);
ClassDB::bind_method(D_METHOD("set_amount", "value"), &Shear::set_amount);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "amount"), "set_amount", "get_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("get_center"), &Shear::get_center); ClassDB::bind_method(D_METHOD("set_center", "value"), &MMShear::set_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &Shear::set_center);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "center"), "set_center", "get_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,17 +1,18 @@
#ifndef SHEAR_H #ifndef MM_SHEAR_H
#define SHEAR_H #define MM_SHEAR_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Shear : public MMNode { class MMShear : public MMNode {
GDCLASS(Shear, MMNode); GDCLASS(MMShear, 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();
void set_input(const Ref<Resource> &val);
int get_direction() const; int get_direction() const;
void set_direction(const int val); void set_direction(const int val);
@ -23,37 +24,22 @@ class Shear : public MMNode {
void set_center(const float val); void set_center(const float val);
void _init_properties(); void _init_properties();
void _register_methods(const Variant &mm_graph_node); void _register_methods(MMGraphNode *mm_graph_node);
void _render(const Variant &material); void _render(const Ref<MMMaterial> &material);
Color _get_value_for(const Vector2 &uv, const int pseed); 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);
Shear(); MMShear();
~Shear(); ~MMShear();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> image;
//export(Resource) Ref<MMNodeUniversalProperty> input;
Ref<Resource> image;
//export(Resource)
Ref<Resource> input;
//export(int, "Horizontal,Vertical") //export(int, "Horizontal,Vertical")
int direction = 0; int direction;
//export(float) float amount;
float amount = 1; float center;
//export(float)
float center = 0;
//direction
//amount
//center
}; };
#endif #endif

View File

@ -45,6 +45,7 @@ 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/shear.h"
#include "nodes/transform/tiler.h" #include "nodes/transform/tiler.h"
#include "nodes/transform/transform.h" #include "nodes/transform/transform.h"
#include "nodes/transform/translate.h" #include "nodes/transform/translate.h"
@ -76,6 +77,8 @@ void register_material_maker_types() {
MMAlgos::register_node_class("Transform", "MMTransform"); MMAlgos::register_node_class("Transform", "MMTransform");
ClassDB::register_class<MMTiler>(); ClassDB::register_class<MMTiler>();
MMAlgos::register_node_class("Transform", "MMTiler"); MMAlgos::register_node_class("Transform", "MMTiler");
ClassDB::register_class<MMShear>();
MMAlgos::register_node_class("Transform", "MMShear");
_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()));