Cleaned up gradients.

This commit is contained in:
Relintai 2022-06-18 16:49:53 +02:00
parent cbb5142be6
commit e8cb984e21
9 changed files with 273 additions and 464 deletions

View File

@ -131,6 +131,10 @@ sources = [
"nodes/noise/color_value.cpp", "nodes/noise/color_value.cpp",
"nodes/noise/color_noise.cpp", "nodes/noise/color_noise.cpp",
"nodes/noise/anisotropic_noise.cpp", "nodes/noise/anisotropic_noise.cpp",
"nodes/gradient/radial_gradient.cpp",
"nodes/gradient/gradient.cpp",
"nodes/gradient/circular_gradient.cpp",
] ]
if env["tools"]: if env["tools"]:

View File

@ -101,6 +101,10 @@ def get_doc_classes():
"MMColorValue", "MMColorValue",
"MMColorNoise", "MMColorNoise",
"MMAnisotropicNoise", "MMAnisotropicNoise",
"MMRadialGradient",
"MMGradient",
"MMCircularGradient",
] ]
def get_doc_path(): def get_doc_path():

View File

@ -1,148 +1,89 @@
#include "circular_gradient.h" #include "circular_gradient.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> CircularGradient::get_image() { Ref<MMNodeUniversalProperty> MMCircularGradient::get_image() {
return image; return image;
} }
void CircularGradient::set_image(const Ref<Resource> &val) { void MMCircularGradient::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
float MMCircularGradient::get_repeat() const {
float CircularGradient::get_repeat() const {
return repeat; return repeat;
} }
void CircularGradient::set_repeat(const float val) { void MMCircularGradient::set_repeat(const float val) {
repeat = val;
}
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(float) ;
float repeat = 1;
void CircularGradient::_init_properties() {
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
}
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE;
register_output_property(image);
}
void CircularGradient::_register_methods(const Variant &mm_graph_node) {
mm_graph_node.add_slot_texture_universal(image);
mm_graph_node.add_slot_float("get_repeat", "set_repeat", "repeat");
mm_graph_node.add_slot_gradient();
}
void CircularGradient::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
}
Color CircularGradient::_get_value_for(const Vector2 &uv, const int pseed) {
if (interpolation_type == 0) {
return MMAlgos.circular_gradient_type_1(uv, repeat, points);
}
else if (interpolation_type == 1) {
return MMAlgos.circular_gradient_type_2(uv, repeat, points);
}
else if (interpolation_type == 2) {
return MMAlgos.circular_gradient_type_3(uv, repeat, points);
}
else if (interpolation_type == 3) {
return MMAlgos.circular_gradient_type_4(uv, repeat, points);
}
return Color(1, 1, 1, 1);
}
Color CircularGradient::_get_gradient_color(const float x) {
if (interpolation_type == 0) {
return MMAlgos.gradient_type_1(x, points);
}
else if (interpolation_type == 1) {
return MMAlgos.gradient_type_2(x, points);
}
else if (interpolation_type == 2) {
return MMAlgos.gradient_type_3(x, points);
}
else if (interpolation_type == 3) {
return MMAlgos.gradient_type_4(x, points);
}
return Color(1, 1, 1, 1);
}
float CircularGradient::get_repeat() {
return repeat;
}
void CircularGradient::set_repeat(const float val) {
repeat = val; repeat = val;
set_dirty(true); set_dirty(true);
} }
void MMCircularGradient::_init_properties() {
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
} }
CircularGradient::CircularGradient() { image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
image; register_output_property(image);
}
void MMCircularGradient::_register_methods(MMGraphNode *mm_graph_node) {
mm_graph_node->add_slot_texture_universal(image);
mm_graph_node->add_slot_float("get_repeat", "set_repeat", "repeat");
mm_graph_node->add_slot_gradient();
}
void MMCircularGradient::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
Color MMCircularGradient::_get_value_for(const Vector2 &uv, const int pseed) {
if (interpolation_type == 0) {
return MMAlgos::circular_gradient_type_1(uv, repeat, points);
} else if (interpolation_type == 1) {
return MMAlgos::circular_gradient_type_2(uv, repeat, points);
} else if (interpolation_type == 2) {
return MMAlgos::circular_gradient_type_3(uv, repeat, points);
} else if (interpolation_type == 3) {
return MMAlgos::circular_gradient_type_4(uv, repeat, points);
}
return Color(1, 1, 1, 1);
}
Color MMCircularGradient::_get_gradient_color(const float x) {
if (interpolation_type == 0) {
return MMAlgos::gradient_type_1(x, points);
} else if (interpolation_type == 1) {
return MMAlgos::gradient_type_2(x, points);
} else if (interpolation_type == 2) {
return MMAlgos::gradient_type_3(x, points);
} else if (interpolation_type == 3) {
return MMAlgos::gradient_type_4(x, points);
}
return Color(1, 1, 1, 1);
}
MMCircularGradient::MMCircularGradient() {
repeat = 1; repeat = 1;
} }
CircularGradient::~CircularGradient() { MMCircularGradient::~MMCircularGradient() {
} }
void MMCircularGradient::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMCircularGradient::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMCircularGradient::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<MMNodeUniversalProperty>"), "set_image", "get_image");
static void CircularGradient::_bind_methods() { ClassDB::bind_method(D_METHOD("get_repeat"), &MMCircularGradient::get_repeat);
ClassDB::bind_method(D_METHOD("get_image"), &CircularGradient::get_image); ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMCircularGradient::set_repeat);
ClassDB::bind_method(D_METHOD("set_image", "value"), &CircularGradient::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_image", "get_image");
ClassDB::bind_method(D_METHOD("get_repeat"), &CircularGradient::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &CircularGradient::set_repeat);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat");
ClassDB::bind_method(D_METHOD("_init_properties"), &CircularGradient::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &CircularGradient::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &CircularGradient::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &CircularGradient::_get_value_for);
ClassDB::bind_method(D_METHOD("_get_gradient_color", "x"), &CircularGradient::_get_gradient_color);
ClassDB::bind_method(D_METHOD("get_repeat"), &CircularGradient::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "val"), &CircularGradient::set_repeat);
} }

View File

@ -1,38 +1,33 @@
#ifndef CIRCULAR_GRADIENT_H #ifndef MM_CIRCULAR_GRADIENT_H
#define CIRCULAR_GRADIENT_H #define MM_CIRCULAR_GRADIENT_H
#include "../bases/gradient_base.h"
#include "../mm_node_universal_property.h"
class CircularGradient : public GradientBase { class MMCircularGradient : public GradientBase {
GDCLASS(CircularGradient, GradientBase); GDCLASS(MMCircularGradient, GradientBase);
public: public:
Ref<MMNodeUniversalProperty> get_image();
Ref<Resource> get_image(); void set_image(const Ref<MMNodeUniversalProperty> &val);
void set_image(const Ref<Resource> &val);
float get_repeat() const; float get_repeat() const;
void set_repeat(const float val); void set_repeat(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);
Color _get_gradient_color(const float x); Color _get_gradient_color(const float x);
float get_repeat();
void set_repeat(const float val);
CircularGradient(); MMCircularGradient();
~CircularGradient(); ~MMCircularGradient();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> image;
//export(Resource) float repeat;
Ref<Resource> image;
//export(float)
float repeat = 1;
}; };
#endif #endif

View File

@ -1,179 +1,105 @@
#include "gradient.h" #include "gradient.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Gradient::get_image() { Ref<MMNodeUniversalProperty> MMGradient::get_image() {
return image; return image;
} }
void Gradient::set_image(const Ref<Resource> &val) { void MMGradient::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
float MMGradient::get_repeat() const {
float Gradient::get_repeat() const {
return repeat; return repeat;
} }
void Gradient::set_repeat(const float val) { void MMGradient::set_repeat(const float val) {
repeat = val; repeat = val;
set_dirty(true);
} }
float MMGradient::get_rotate() const {
float Gradient::get_rotate() const {
return rotate; return rotate;
} }
void Gradient::set_rotate(const float val) { void MMGradient::set_rotate(const float val) {
rotate = val; rotate = val;
set_dirty(true);
} }
void MMGradient::_init_properties() {
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(float) ;
float repeat = 1;
//export(float) ;
float rotate = 0;
void Gradient::_init_properties() {
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
} }
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
register_output_property(image); register_output_property(image);
} }
void MMGradient::_register_methods(MMGraphNode *mm_graph_node) {
void Gradient::_register_methods(const Variant &mm_graph_node) { mm_graph_node->add_slot_texture_universal(image);
mm_graph_node.add_slot_texture_universal(image); mm_graph_node->add_slot_float("get_repeat", "set_repeat", "repeat");
mm_graph_node.add_slot_float("get_repeat", "set_repeat", "repeat"); mm_graph_node->add_slot_float("get_rotate", "set_rotate", "rotate");
mm_graph_node.add_slot_float("get_rotate", "set_rotate", "rotate"); mm_graph_node->add_slot_gradient();
mm_graph_node.add_slot_gradient();
} }
void MMGradient::_render(const Ref<MMMaterial> &material) {
void Gradient::_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 MMGradient::_get_value_for(const Vector2 &uv, const int pseed) {
Color Gradient::_get_value_for(const Vector2 &uv, const int pseed) {
if (interpolation_type == 0) { if (interpolation_type == 0) {
return MMAlgos.normal_gradient_type_1(uv, repeat, rotate, points); return MMAlgos::normal_gradient_type_1(uv, repeat, rotate, points);
} } else if (interpolation_type == 1) {
return MMAlgos::normal_gradient_type_2(uv, repeat, rotate, points);
} else if (interpolation_type == 2) {
else if (interpolation_type == 1) { return MMAlgos::normal_gradient_type_3(uv, repeat, rotate, points);
return MMAlgos.normal_gradient_type_2(uv, repeat, rotate, points); } else if (interpolation_type == 3) {
} return MMAlgos::normal_gradient_type_4(uv, repeat, rotate, points);
else if (interpolation_type == 2) {
return MMAlgos.normal_gradient_type_3(uv, repeat, rotate, points);
}
else if (interpolation_type == 3) {
return MMAlgos.normal_gradient_type_4(uv, repeat, rotate, points);
} }
return Color(1, 1, 1, 1); return Color(1, 1, 1, 1);
} }
Color MMGradient::_get_gradient_color(const float x) {
Color Gradient::_get_gradient_color(const float x) {
if (interpolation_type == 0) { if (interpolation_type == 0) {
return MMAlgos.gradient_type_1(x, points); return MMAlgos::gradient_type_1(x, points);
} } else if (interpolation_type == 1) {
return MMAlgos::gradient_type_2(x, points);
} else if (interpolation_type == 2) {
else if (interpolation_type == 1) { return MMAlgos::gradient_type_3(x, points);
return MMAlgos.gradient_type_2(x, points); } else if (interpolation_type == 3) {
} return MMAlgos::gradient_type_4(x, points);
else if (interpolation_type == 2) {
return MMAlgos.gradient_type_3(x, points);
}
else if (interpolation_type == 3) {
return MMAlgos.gradient_type_4(x, points);
} }
return Color(1, 1, 1, 1); return Color(1, 1, 1, 1);
} }
MMGradient::MMGradient() {
float Gradient::get_repeat() {
return repeat;
}
void Gradient::set_repeat(const float val) {
repeat = val;
set_dirty(true);
}
float Gradient::get_rotate() {
return rotate;
}
void Gradient::set_rotate(const float val) {
rotate = val;
set_dirty(true);
}
}
Gradient::Gradient() {
image;
repeat = 1; repeat = 1;
rotate = 0; rotate = 0;
} }
Gradient::~Gradient() { MMGradient::~MMGradient() {
} }
void MMGradient::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMGradient::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMGradient::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image");
static void Gradient::_bind_methods() { ClassDB::bind_method(D_METHOD("get_repeat"), &MMGradient::get_repeat);
ClassDB::bind_method(D_METHOD("get_image"), &Gradient::get_image); ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMGradient::set_repeat);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Gradient::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_image", "get_image");
ClassDB::bind_method(D_METHOD("get_repeat"), &Gradient::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &Gradient::set_repeat);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat");
ClassDB::bind_method(D_METHOD("get_rotate"), &MMGradient::get_rotate);
ClassDB::bind_method(D_METHOD("get_rotate"), &Gradient::get_rotate); ClassDB::bind_method(D_METHOD("set_rotate", "value"), &MMGradient::set_rotate);
ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Gradient::set_rotate);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate");
ClassDB::bind_method(D_METHOD("_init_properties"), &Gradient::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Gradient::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &Gradient::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Gradient::_get_value_for);
ClassDB::bind_method(D_METHOD("_get_gradient_color", "x"), &Gradient::_get_gradient_color);
ClassDB::bind_method(D_METHOD("get_repeat"), &Gradient::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "val"), &Gradient::set_repeat);
ClassDB::bind_method(D_METHOD("get_rotate"), &Gradient::get_rotate);
ClassDB::bind_method(D_METHOD("set_rotate", "val"), &Gradient::set_rotate);
} }

View File

@ -1,14 +1,15 @@
#ifndef GRADIENT_H #ifndef MM_GRADIENT_H
#define GRADIENT_H #define MM_GRADIENT_H
#include "../bases/gradient_base.h"
#include "../mm_node_universal_property.h"
class Gradient : public GradientBase { class MMGradient : public GradientBase {
GDCLASS(Gradient, GradientBase); GDCLASS(MMGradient, GradientBase);
public: public:
Ref<MMNodeUniversalProperty> get_image();
Ref<Resource> get_image(); void set_image(const Ref<MMNodeUniversalProperty> &val);
void set_image(const Ref<Resource> &val);
float get_repeat() const; float get_repeat() const;
void set_repeat(const float val); void set_repeat(const float val);
@ -17,29 +18,20 @@ class Gradient : public GradientBase {
void set_rotate(const float val); void set_rotate(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);
Color _get_gradient_color(const float x); Color _get_gradient_color(const float x);
float get_repeat();
void set_repeat(const float val);
float get_rotate();
void set_rotate(const float val);
Gradient(); MMGradient();
~Gradient(); ~MMGradient();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> image;
//export(Resource) float repeat;
Ref<Resource> image; float rotate;
//export(float)
float repeat = 1;
//export(float)
float rotate = 0;
}; };
#endif #endif

View File

@ -1,148 +1,89 @@
#include "radial_gradient.h" #include "radial_gradient.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> RadialGradient::get_image() { Ref<MMNodeUniversalProperty> MMRadialGradient::get_image() {
return image; return image;
} }
void RadialGradient::set_image(const Ref<Resource> &val) { void MMRadialGradient::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val; image = val;
} }
float MMRadialGradient::get_repeat() const {
float RadialGradient::get_repeat() const {
return repeat; return repeat;
} }
void RadialGradient::set_repeat(const float val) { void MMRadialGradient::set_repeat(const float val) {
repeat = val;
}
//tool;
//export(Resource) ;
Ref<Resource> image;
//export(float) ;
float repeat = 1;
void RadialGradient::_init_properties() {
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
}
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE;
register_output_property(image);
}
void RadialGradient::_register_methods(const Variant &mm_graph_node) {
mm_graph_node.add_slot_texture_universal(image);
mm_graph_node.add_slot_float("get_repeat", "set_repeat", "repeat");
mm_graph_node.add_slot_gradient();
}
void RadialGradient::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
}
Color RadialGradient::_get_value_for(const Vector2 &uv, const int pseed) {
if (interpolation_type == 0) {
return MMAlgos.radial_gradient_type_1(uv, repeat, points);
}
else if (interpolation_type == 1) {
return MMAlgos.radial_gradient_type_2(uv, repeat, points);
}
else if (interpolation_type == 2) {
return MMAlgos.radial_gradient_type_3(uv, repeat, points);
}
else if (interpolation_type == 3) {
return MMAlgos.radial_gradient_type_4(uv, repeat, points);
}
return Color(1, 1, 1, 1);
}
Color RadialGradient::_get_gradient_color(const float x) {
if (interpolation_type == 0) {
return MMAlgos.gradient_type_1(x, points);
}
else if (interpolation_type == 1) {
return MMAlgos.gradient_type_2(x, points);
}
else if (interpolation_type == 2) {
return MMAlgos.gradient_type_3(x, points);
}
else if (interpolation_type == 3) {
return MMAlgos.gradient_type_4(x, points);
}
return Color(1, 1, 1, 1);
}
float RadialGradient::get_repeat() {
return repeat;
}
void RadialGradient::set_repeat(const float val) {
repeat = val; repeat = val;
set_dirty(true); set_dirty(true);
} }
void MMRadialGradient::_init_properties() {
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
} }
RadialGradient::RadialGradient() { image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
image; register_output_property(image);
}
void MMRadialGradient::_register_methods(MMGraphNode *mm_graph_node) {
mm_graph_node->add_slot_texture_universal(image);
mm_graph_node->add_slot_float("get_repeat", "set_repeat", "repeat");
mm_graph_node->add_slot_gradient();
}
void MMRadialGradient::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
Color MMRadialGradient::_get_value_for(const Vector2 &uv, const int pseed) {
if (interpolation_type == 0) {
return MMAlgos::radial_gradient_type_1(uv, repeat, points);
} else if (interpolation_type == 1) {
return MMAlgos::radial_gradient_type_2(uv, repeat, points);
} else if (interpolation_type == 2) {
return MMAlgos::radial_gradient_type_3(uv, repeat, points);
} else if (interpolation_type == 3) {
return MMAlgos::radial_gradient_type_4(uv, repeat, points);
}
return Color(1, 1, 1, 1);
}
Color MMRadialGradient::_get_gradient_color(const float x) {
if (interpolation_type == 0) {
return MMAlgos::gradient_type_1(x, points);
} else if (interpolation_type == 1) {
return MMAlgos::gradient_type_2(x, points);
} else if (interpolation_type == 2) {
return MMAlgos::gradient_type_3(x, points);
} else if (interpolation_type == 3) {
return MMAlgos::gradient_type_4(x, points);
}
return Color(1, 1, 1, 1);
}
MMRadialGradient::MMRadialGradient() {
repeat = 1; repeat = 1;
} }
RadialGradient::~RadialGradient() { MMRadialGradient::~MMRadialGradient() {
} }
void MMRadialGradient::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMRadialGradient::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMRadialGradient::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image");
static void RadialGradient::_bind_methods() { ClassDB::bind_method(D_METHOD("get_repeat"), &MMRadialGradient::get_repeat);
ClassDB::bind_method(D_METHOD("get_image"), &RadialGradient::get_image); ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMRadialGradient::set_repeat);
ClassDB::bind_method(D_METHOD("set_image", "value"), &RadialGradient::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_image", "get_image");
ClassDB::bind_method(D_METHOD("get_repeat"), &RadialGradient::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &RadialGradient::set_repeat);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat");
ClassDB::bind_method(D_METHOD("_init_properties"), &RadialGradient::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &RadialGradient::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &RadialGradient::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &RadialGradient::_get_value_for);
ClassDB::bind_method(D_METHOD("_get_gradient_color", "x"), &RadialGradient::_get_gradient_color);
ClassDB::bind_method(D_METHOD("get_repeat"), &RadialGradient::get_repeat);
ClassDB::bind_method(D_METHOD("set_repeat", "val"), &RadialGradient::set_repeat);
} }

View File

@ -1,38 +1,33 @@
#ifndef RADIAL_GRADIENT_H #ifndef MM_RADIAL_GRADIENT_H
#define RADIAL_GRADIENT_H #define MM_RADIAL_GRADIENT_H
#include "../bases/gradient_base.h"
#include "../mm_node_universal_property.h"
class RadialGradient : public GradientBase { class MMRadialGradient : public GradientBase {
GDCLASS(RadialGradient, GradientBase); GDCLASS(MMRadialGradient, GradientBase);
public: public:
Ref<MMNodeUniversalProperty> get_image();
Ref<Resource> get_image(); void set_image(const Ref<MMNodeUniversalProperty> &val);
void set_image(const Ref<Resource> &val);
float get_repeat() const; float get_repeat() const;
void set_repeat(const float val); void set_repeat(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);
Color _get_gradient_color(const float x); Color _get_gradient_color(const float x);
float get_repeat();
void set_repeat(const float val);
RadialGradient(); MMRadialGradient();
~RadialGradient(); ~MMRadialGradient();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> image;
//export(Resource) float repeat;
Ref<Resource> image;
//export(float)
float repeat = 1;
}; };
#endif #endif

View File

@ -126,6 +126,10 @@ SOFTWARE.
#include "nodes/noise/noise.h" #include "nodes/noise/noise.h"
#include "nodes/noise/voronoi.h" #include "nodes/noise/voronoi.h"
#include "nodes/gradient/circular_gradient.h"
#include "nodes/gradient/gradient.h"
#include "nodes/gradient/radial_gradient.h"
static _MMAlgos *_mm_algos_singleton = nullptr; static _MMAlgos *_mm_algos_singleton = nullptr;
void register_material_maker_types() { void register_material_maker_types() {
@ -292,6 +296,13 @@ void register_material_maker_types() {
ClassDB::register_class<MMAnisotropicNoise>(); ClassDB::register_class<MMAnisotropicNoise>();
MMAlgos::register_node_class("Noise", "MMAnisotropicNoise"); MMAlgos::register_node_class("Noise", "MMAnisotropicNoise");
ClassDB::register_class<MMRadialGradient>();
MMAlgos::register_node_class("Gradient", "MMRadialGradient");
ClassDB::register_class<MMGradient>();
MMAlgos::register_node_class("Gradient", "MMGradient");
ClassDB::register_class<MMCircularGradient>();
MMAlgos::register_node_class("Gradient", "MMCircularGradient");
_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()));