mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 04:16:50 +01:00
Cleaned up gradients.
This commit is contained in:
parent
cbb5142be6
commit
e8cb984e21
@ -131,6 +131,10 @@ sources = [
|
||||
"nodes/noise/color_value.cpp",
|
||||
"nodes/noise/color_noise.cpp",
|
||||
"nodes/noise/anisotropic_noise.cpp",
|
||||
|
||||
"nodes/gradient/radial_gradient.cpp",
|
||||
"nodes/gradient/gradient.cpp",
|
||||
"nodes/gradient/circular_gradient.cpp",
|
||||
]
|
||||
|
||||
if env["tools"]:
|
||||
|
@ -101,6 +101,10 @@ def get_doc_classes():
|
||||
"MMColorValue",
|
||||
"MMColorNoise",
|
||||
"MMAnisotropicNoise",
|
||||
|
||||
"MMRadialGradient",
|
||||
"MMGradient",
|
||||
"MMCircularGradient",
|
||||
]
|
||||
|
||||
def get_doc_path():
|
||||
|
@ -1,148 +1,89 @@
|
||||
|
||||
#include "circular_gradient.h"
|
||||
|
||||
#include "../../algos/mm_algos.h"
|
||||
#include "../../editor/mm_graph_node.h"
|
||||
#include "../mm_material.h"
|
||||
|
||||
Ref<Resource> CircularGradient::get_image() {
|
||||
return image;
|
||||
Ref<MMNodeUniversalProperty> MMCircularGradient::get_image() {
|
||||
return image;
|
||||
}
|
||||
|
||||
void CircularGradient::set_image(const Ref<Resource> &val) {
|
||||
image = val;
|
||||
void MMCircularGradient::set_image(const Ref<MMNodeUniversalProperty> &val) {
|
||||
image = val;
|
||||
}
|
||||
|
||||
|
||||
float CircularGradient::get_repeat() const {
|
||||
return repeat;
|
||||
float MMCircularGradient::get_repeat() const {
|
||||
return repeat;
|
||||
}
|
||||
|
||||
void CircularGradient::set_repeat(const float val) {
|
||||
repeat = val;
|
||||
void MMCircularGradient::set_repeat(const float val) {
|
||||
repeat = val;
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
void MMCircularGradient::_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;
|
||||
|
||||
void CircularGradient::_init_properties() {
|
||||
|
||||
if (!image) {
|
||||
image = MMNodeUniversalProperty.new();
|
||||
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
|
||||
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
|
||||
register_output_property(image);
|
||||
}
|
||||
|
||||
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_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 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 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);
|
||||
}
|
||||
|
||||
void CircularGradient::_render(const Variant &material) {
|
||||
Ref<Image> img = render_image(material);
|
||||
image.set_value(img);
|
||||
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);
|
||||
}
|
||||
|
||||
Color CircularGradient::_get_value_for(const Vector2 &uv, const int pseed) {
|
||||
|
||||
if (interpolation_type == 0) {
|
||||
return MMAlgos.circular_gradient_type_1(uv, repeat, points);
|
||||
return Color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
else if (interpolation_type == 1) {
|
||||
return MMAlgos.circular_gradient_type_2(uv, repeat, points);
|
||||
MMCircularGradient::MMCircularGradient() {
|
||||
repeat = 1;
|
||||
}
|
||||
|
||||
|
||||
else if (interpolation_type == 2) {
|
||||
return MMAlgos.circular_gradient_type_3(uv, repeat, points);
|
||||
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");
|
||||
|
||||
else if (interpolation_type == 3) {
|
||||
return MMAlgos.circular_gradient_type_4(uv, repeat, points);
|
||||
ClassDB::bind_method(D_METHOD("get_repeat"), &MMCircularGradient::get_repeat);
|
||||
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMCircularGradient::set_repeat);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat");
|
||||
}
|
||||
|
||||
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;
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CircularGradient::CircularGradient() {
|
||||
image;
|
||||
repeat = 1;
|
||||
}
|
||||
|
||||
CircularGradient::~CircularGradient() {
|
||||
}
|
||||
|
||||
|
||||
static void CircularGradient::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_image"), &CircularGradient::get_image);
|
||||
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");
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,38 +1,33 @@
|
||||
#ifndef CIRCULAR_GRADIENT_H
|
||||
#define CIRCULAR_GRADIENT_H
|
||||
#ifndef MM_CIRCULAR_GRADIENT_H
|
||||
#define MM_CIRCULAR_GRADIENT_H
|
||||
|
||||
#include "../bases/gradient_base.h"
|
||||
#include "../mm_node_universal_property.h"
|
||||
|
||||
class CircularGradient : public GradientBase {
|
||||
GDCLASS(CircularGradient, GradientBase);
|
||||
class MMCircularGradient : public GradientBase {
|
||||
GDCLASS(MMCircularGradient, GradientBase);
|
||||
|
||||
public:
|
||||
public:
|
||||
Ref<MMNodeUniversalProperty> get_image();
|
||||
void set_image(const Ref<MMNodeUniversalProperty> &val);
|
||||
|
||||
Ref<Resource> get_image();
|
||||
void set_image(const Ref<Resource> &val);
|
||||
float get_repeat() const;
|
||||
void set_repeat(const float val);
|
||||
|
||||
float get_repeat() const;
|
||||
void set_repeat(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);
|
||||
Color _get_gradient_color(const float x);
|
||||
|
||||
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);
|
||||
Color _get_gradient_color(const float x);
|
||||
float get_repeat();
|
||||
void set_repeat(const float val);
|
||||
MMCircularGradient();
|
||||
~MMCircularGradient();
|
||||
|
||||
CircularGradient();
|
||||
~CircularGradient();
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
//export(Resource)
|
||||
Ref<Resource> image;
|
||||
//export(float)
|
||||
float repeat = 1;
|
||||
Ref<MMNodeUniversalProperty> image;
|
||||
float repeat;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,179 +1,105 @@
|
||||
|
||||
#include "gradient.h"
|
||||
|
||||
#include "../../algos/mm_algos.h"
|
||||
#include "../../editor/mm_graph_node.h"
|
||||
#include "../mm_material.h"
|
||||
|
||||
Ref<Resource> Gradient::get_image() {
|
||||
return image;
|
||||
Ref<MMNodeUniversalProperty> MMGradient::get_image() {
|
||||
return image;
|
||||
}
|
||||
|
||||
void Gradient::set_image(const Ref<Resource> &val) {
|
||||
image = val;
|
||||
void MMGradient::set_image(const Ref<MMNodeUniversalProperty> &val) {
|
||||
image = val;
|
||||
}
|
||||
|
||||
|
||||
float Gradient::get_repeat() const {
|
||||
return repeat;
|
||||
float MMGradient::get_repeat() const {
|
||||
return repeat;
|
||||
}
|
||||
|
||||
void Gradient::set_repeat(const float val) {
|
||||
repeat = val;
|
||||
void MMGradient::set_repeat(const float val) {
|
||||
repeat = val;
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
|
||||
float Gradient::get_rotate() const {
|
||||
return rotate;
|
||||
float MMGradient::get_rotate() const {
|
||||
return rotate;
|
||||
}
|
||||
|
||||
void Gradient::set_rotate(const float val) {
|
||||
rotate = val;
|
||||
void MMGradient::set_rotate(const float 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->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
|
||||
register_output_property(image);
|
||||
}
|
||||
|
||||
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE;
|
||||
register_output_property(image);
|
||||
void MMGradient::_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_float("get_rotate", "set_rotate", "rotate");
|
||||
mm_graph_node->add_slot_gradient();
|
||||
}
|
||||
|
||||
|
||||
void Gradient::_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_float("get_rotate", "set_rotate", "rotate");
|
||||
mm_graph_node.add_slot_gradient();
|
||||
void MMGradient::_render(const Ref<MMMaterial> &material) {
|
||||
Ref<Image> img = render_image(material);
|
||||
image->set_value(img);
|
||||
}
|
||||
|
||||
Color MMGradient::_get_value_for(const Vector2 &uv, const int pseed) {
|
||||
if (interpolation_type == 0) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
void Gradient::_render(const Variant &material) {
|
||||
Ref<Image> img = render_image(material);
|
||||
image.set_value(img);
|
||||
return Color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
Color MMGradient::_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);
|
||||
}
|
||||
|
||||
Color Gradient::_get_value_for(const Vector2 &uv, const int pseed) {
|
||||
|
||||
if (interpolation_type == 0) {
|
||||
return MMAlgos.normal_gradient_type_1(uv, repeat, rotate, points);
|
||||
return Color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
else if (interpolation_type == 1) {
|
||||
return MMAlgos.normal_gradient_type_2(uv, repeat, rotate, points);
|
||||
MMGradient::MMGradient() {
|
||||
repeat = 1;
|
||||
rotate = 0;
|
||||
}
|
||||
|
||||
|
||||
else if (interpolation_type == 2) {
|
||||
return MMAlgos.normal_gradient_type_3(uv, repeat, rotate, points);
|
||||
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");
|
||||
|
||||
else if (interpolation_type == 3) {
|
||||
return MMAlgos.normal_gradient_type_4(uv, repeat, rotate, points);
|
||||
ClassDB::bind_method(D_METHOD("get_repeat"), &MMGradient::get_repeat);
|
||||
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMGradient::set_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("set_rotate", "value"), &MMGradient::set_rotate);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotate"), "set_rotate", "get_rotate");
|
||||
}
|
||||
|
||||
return Color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
Color Gradient::_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 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;
|
||||
rotate = 0;
|
||||
}
|
||||
|
||||
Gradient::~Gradient() {
|
||||
}
|
||||
|
||||
|
||||
static void Gradient::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_image"), &Gradient::get_image);
|
||||
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");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_rotate"), &Gradient::get_rotate);
|
||||
ClassDB::bind_method(D_METHOD("set_rotate", "value"), &Gradient::set_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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,45 +1,37 @@
|
||||
#ifndef GRADIENT_H
|
||||
#define GRADIENT_H
|
||||
#ifndef MM_GRADIENT_H
|
||||
#define MM_GRADIENT_H
|
||||
|
||||
#include "../bases/gradient_base.h"
|
||||
#include "../mm_node_universal_property.h"
|
||||
|
||||
class Gradient : public GradientBase {
|
||||
GDCLASS(Gradient, GradientBase);
|
||||
class MMGradient : public GradientBase {
|
||||
GDCLASS(MMGradient, GradientBase);
|
||||
|
||||
public:
|
||||
public:
|
||||
Ref<MMNodeUniversalProperty> get_image();
|
||||
void set_image(const Ref<MMNodeUniversalProperty> &val);
|
||||
|
||||
Ref<Resource> get_image();
|
||||
void set_image(const Ref<Resource> &val);
|
||||
float get_repeat() const;
|
||||
void set_repeat(const float val);
|
||||
|
||||
float get_repeat() const;
|
||||
void set_repeat(const float 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);
|
||||
Color _get_gradient_color(const float x);
|
||||
|
||||
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);
|
||||
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);
|
||||
MMGradient();
|
||||
~MMGradient();
|
||||
|
||||
Gradient();
|
||||
~Gradient();
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
//export(Resource)
|
||||
Ref<Resource> image;
|
||||
//export(float)
|
||||
float repeat = 1;
|
||||
//export(float)
|
||||
float rotate = 0;
|
||||
Ref<MMNodeUniversalProperty> image;
|
||||
float repeat;
|
||||
float rotate;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,148 +1,89 @@
|
||||
|
||||
#include "radial_gradient.h"
|
||||
|
||||
#include "../../algos/mm_algos.h"
|
||||
#include "../../editor/mm_graph_node.h"
|
||||
#include "../mm_material.h"
|
||||
|
||||
Ref<Resource> RadialGradient::get_image() {
|
||||
return image;
|
||||
Ref<MMNodeUniversalProperty> MMRadialGradient::get_image() {
|
||||
return image;
|
||||
}
|
||||
|
||||
void RadialGradient::set_image(const Ref<Resource> &val) {
|
||||
image = val;
|
||||
void MMRadialGradient::set_image(const Ref<MMNodeUniversalProperty> &val) {
|
||||
image = val;
|
||||
}
|
||||
|
||||
|
||||
float RadialGradient::get_repeat() const {
|
||||
return repeat;
|
||||
float MMRadialGradient::get_repeat() const {
|
||||
return repeat;
|
||||
}
|
||||
|
||||
void RadialGradient::set_repeat(const float val) {
|
||||
repeat = val;
|
||||
void MMRadialGradient::set_repeat(const float val) {
|
||||
repeat = val;
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
void MMRadialGradient::_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;
|
||||
|
||||
void RadialGradient::_init_properties() {
|
||||
|
||||
if (!image) {
|
||||
image = MMNodeUniversalProperty.new();
|
||||
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
|
||||
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
|
||||
register_output_property(image);
|
||||
}
|
||||
|
||||
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_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 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 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);
|
||||
}
|
||||
|
||||
void RadialGradient::_render(const Variant &material) {
|
||||
Ref<Image> img = render_image(material);
|
||||
image.set_value(img);
|
||||
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);
|
||||
}
|
||||
|
||||
Color RadialGradient::_get_value_for(const Vector2 &uv, const int pseed) {
|
||||
|
||||
if (interpolation_type == 0) {
|
||||
return MMAlgos.radial_gradient_type_1(uv, repeat, points);
|
||||
return Color(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
else if (interpolation_type == 1) {
|
||||
return MMAlgos.radial_gradient_type_2(uv, repeat, points);
|
||||
MMRadialGradient::MMRadialGradient() {
|
||||
repeat = 1;
|
||||
}
|
||||
|
||||
|
||||
else if (interpolation_type == 2) {
|
||||
return MMAlgos.radial_gradient_type_3(uv, repeat, points);
|
||||
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");
|
||||
|
||||
else if (interpolation_type == 3) {
|
||||
return MMAlgos.radial_gradient_type_4(uv, repeat, points);
|
||||
ClassDB::bind_method(D_METHOD("get_repeat"), &MMRadialGradient::get_repeat);
|
||||
ClassDB::bind_method(D_METHOD("set_repeat", "value"), &MMRadialGradient::set_repeat);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "repeat"), "set_repeat", "get_repeat");
|
||||
}
|
||||
|
||||
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;
|
||||
set_dirty(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RadialGradient::RadialGradient() {
|
||||
image;
|
||||
repeat = 1;
|
||||
}
|
||||
|
||||
RadialGradient::~RadialGradient() {
|
||||
}
|
||||
|
||||
|
||||
static void RadialGradient::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_image"), &RadialGradient::get_image);
|
||||
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");
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,38 +1,33 @@
|
||||
#ifndef RADIAL_GRADIENT_H
|
||||
#define RADIAL_GRADIENT_H
|
||||
#ifndef MM_RADIAL_GRADIENT_H
|
||||
#define MM_RADIAL_GRADIENT_H
|
||||
|
||||
#include "../bases/gradient_base.h"
|
||||
#include "../mm_node_universal_property.h"
|
||||
|
||||
class RadialGradient : public GradientBase {
|
||||
GDCLASS(RadialGradient, GradientBase);
|
||||
class MMRadialGradient : public GradientBase {
|
||||
GDCLASS(MMRadialGradient, GradientBase);
|
||||
|
||||
public:
|
||||
public:
|
||||
Ref<MMNodeUniversalProperty> get_image();
|
||||
void set_image(const Ref<MMNodeUniversalProperty> &val);
|
||||
|
||||
Ref<Resource> get_image();
|
||||
void set_image(const Ref<Resource> &val);
|
||||
float get_repeat() const;
|
||||
void set_repeat(const float val);
|
||||
|
||||
float get_repeat() const;
|
||||
void set_repeat(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);
|
||||
Color _get_gradient_color(const float x);
|
||||
|
||||
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);
|
||||
Color _get_gradient_color(const float x);
|
||||
float get_repeat();
|
||||
void set_repeat(const float val);
|
||||
MMRadialGradient();
|
||||
~MMRadialGradient();
|
||||
|
||||
RadialGradient();
|
||||
~RadialGradient();
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//tool
|
||||
//export(Resource)
|
||||
Ref<Resource> image;
|
||||
//export(float)
|
||||
float repeat = 1;
|
||||
Ref<MMNodeUniversalProperty> image;
|
||||
float repeat;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -126,6 +126,10 @@ SOFTWARE.
|
||||
#include "nodes/noise/noise.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;
|
||||
|
||||
void register_material_maker_types() {
|
||||
@ -292,6 +296,13 @@ void register_material_maker_types() {
|
||||
ClassDB::register_class<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);
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user