Cleaned up MMShape.

This commit is contained in:
Relintai 2022-06-17 01:38:18 +02:00
parent 18b19d0293
commit a4d5219e26
5 changed files with 174 additions and 237 deletions

View File

@ -64,6 +64,8 @@ sources = [
"nodes/transform/kaleidoscope.cpp",
"nodes/transform/color_tiler.cpp",
"nodes/transform/circle_map.cpp",
"nodes/simple/shape.cpp",
]
if env["tools"]:

View File

@ -34,6 +34,8 @@ def get_doc_classes():
"MMKaleidoscope",
"MMColorTiler",
"MMCircleMap",
"MMShape",
]
def get_doc_path():

View File

@ -1,230 +1,169 @@
#include "shape.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> Shape::get_image() {
return image;
Ref<MMNodeUniversalProperty> MMShape::get_image() {
return image;
}
void Shape::set_image(const Ref<Resource> &val) {
image = val;
void MMShape::set_image(const Ref<MMNodeUniversalProperty> &val) {
image = val;
}
int Shape::get_shape_type() const {
return shape_type;
int MMShape::get_shape_type() const {
return shape_type;
}
void Shape::set_shape_type(const int val) {
shape_type = val;
void MMShape::set_shape_type(const int val) {
shape_type = val;
set_dirty(true);
}
int Shape::get_sides() const {
return sides;
int MMShape::get_sides() const {
return sides;
}
void Shape::set_sides(const int val) {
sides = val;
void MMShape::set_sides(const int val) {
sides = val;
set_dirty(true);
}
Ref<Resource> Shape::get_radius() {
return radius;
Ref<MMNodeUniversalProperty> MMShape::get_radius() {
return radius;
}
void Shape::set_radius(const Ref<Resource> &val) {
radius = val;
void MMShape::set_radius(const Ref<MMNodeUniversalProperty> &val) {
radius = val;
}
Ref<Resource> Shape::get_edge() {
return edge;
Ref<MMNodeUniversalProperty> MMShape::get_edge() {
return edge;
}
void Shape::set_edge(const Ref<Resource> &val) {
edge = val;
void MMShape::set_edge(const Ref<MMNodeUniversalProperty> &val) {
edge = val;
}
void MMShape::_init_properties() {
if (!image.is_valid()) {
image.instance();
image->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_IMAGE);
}
image->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_IMAGE);
//tool;
};
//export(Resource) ;
Ref<Resource> image;
//export(int, "Circle,Polygon,Star,Curved Star,Rays") ;
int shape_type = 0;
//export(int) ;
int sides = 6;
//export(Resource) ;
Ref<Resource> radius;
//export(Resource) ;
Ref<Resource> edge;
if (!radius.is_valid()) {
radius.instance();
radius->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
radius->set_default_value(0.34375);
}
void Shape::_init_properties() {
radius->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
radius->set_slot_name("radius");
radius->set_value_step(0.05);
if (!image) {
image = MMNodeUniversalProperty.new();
image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE;
if (!edge.is_valid()) {
edge.instance();
edge->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
edge->set_default_value(0.2);
}
edge->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL);
edge->set_slot_name("edge");
edge->set_value_step(0.05);
register_input_property(radius);
register_input_property(edge);
register_output_property(image);
}
image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE;
void MMShape::_register_methods(MMGraphNode *mm_graph_node) {
mm_graph_node->add_slot_texture_universal(image);
if (!radius) {
radius = MMNodeUniversalProperty.new();
radius.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT;
radius.set_default_value(0.34375);
Array arr;
arr.push_back("Circle");
arr.push_back("Polygon");
arr.push_back("Star");
arr.push_back("Curved Star");
arr.push_back("Rays");
mm_graph_node->add_slot_enum("get_shape_type", "set_shape_type", "shape_type", arr);
//, Vector2(1, 10));
mm_graph_node->add_slot_int("get_sides", "set_sides", "sides");
mm_graph_node->add_slot_float_universal(radius);
mm_graph_node->add_slot_float_universal(edge);
}
radius.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL;
radius.slot_name = "radius";
radius.value_step = 0.05;
if (!edge) {
edge = MMNodeUniversalProperty.new();
edge.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT;
edge.set_default_value(0.2);
void MMShape::_render(const Ref<MMMaterial> &material) {
Ref<Image> img = render_image(material);
image->set_value(img);
}
edge.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL;
edge.slot_name = "edge";
edge.value_step = 0.05;
register_input_property(radius);
register_input_property(edge);
register_output_property(image);
Color MMShape::_get_value_for(const Vector2 &uv, const int pseed) {
float c = 0;
float rad = radius->get_value(uv);
float edg = edge->get_value(uv);
if (rad == 0) {
rad = 0.0000001;
}
if (edg == 0) {
edg = 0.0000001;
}
if (shape_type == SHAPE_TYPE_CIRCLE) {
c = MMAlgos::shape_circle(uv, sides, rad, edg);
}
else if (shape_type == SHAPE_TYPE_POLYGON) {
c = MMAlgos::shape_polygon(uv, sides, rad, edg);
}
else if (shape_type == SHAPE_TYPE_STAR) {
c = MMAlgos::shape_star(uv, sides, rad, edg);
}
else if (shape_type == SHAPE_TYPE_CURVED_STAR) {
c = MMAlgos::shape_curved_star(uv, sides, rad, edg);
}
else if (shape_type == SHAPE_TYPE_RAYS) {
c = MMAlgos::shape_rays(uv, sides, rad, edg);
}
return Color(c, c, c, 1);
}
void Shape::_register_methods(const Variant &mm_graph_node) {
mm_graph_node.add_slot_texture_universal(image);
mm_graph_node.add_slot_enum("get_shape_typoe", "set_shape_typoe", "shape_type", [ "Circle", "Polygon", "Star", "Curved Star", "Rays" ]);
//, Vector2(1, 10));
mm_graph_node.add_slot_int("get_sides", "set_sides", "sides");
mm_graph_node.add_slot_float_universal(radius);
mm_graph_node.add_slot_float_universal(edge);
MMShape::MMShape() {
shape_type = 0;
sides = 6;
}
void Shape::_render(const Variant &material) {
Ref<Image> img = render_image(material);
image.set_value(img);
MMShape::~MMShape() {
}
void MMShape::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &MMShape::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &MMShape::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image");
Color Shape::_get_value_for(const Vector2 &uv, const int pseed) {
float c = 0;
float rad = radius.get_value(uv);
float edg = edge.get_value(uv);
ClassDB::bind_method(D_METHOD("get_shape_type"), &MMShape::get_shape_type);
ClassDB::bind_method(D_METHOD("set_shape_type", "value"), &MMShape::set_shape_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "shape_type"), "set_shape_type", "get_shape_type");
if (rad == 0) {
rad = 0.0000001;
ClassDB::bind_method(D_METHOD("get_sides"), &MMShape::get_sides);
ClassDB::bind_method(D_METHOD("set_sides", "value"), &MMShape::set_sides);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sides"), "set_sides", "get_sides");
ClassDB::bind_method(D_METHOD("get_radius"), &MMShape::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMShape::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "radius", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_radius", "get_radius");
ClassDB::bind_method(D_METHOD("get_edge"), &MMShape::get_edge);
ClassDB::bind_method(D_METHOD("set_edge", "value"), &MMShape::set_edge);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edge", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_edge", "get_edge");
}
if (edg == 0) {
edg = 0.0000001;
}
if (shape_type == ShapeType.SHAPE_TYPE_CIRCLE) {
c = MMAlgos.shape_circle(uv, sides, rad, edg);
}
else if (shape_type == ShapeType.SHAPE_TYPE_POLYGON) {
c = MMAlgos.shape_polygon(uv, sides, rad, edg);
}
else if (shape_type == ShapeType.SHAPE_TYPE_STAR) {
c = MMAlgos.shape_star(uv, sides, rad, edg);
}
else if (shape_type == ShapeType.SHAPE_TYPE_CURVED_STAR) {
c = MMAlgos.shape_curved_star(uv, sides, rad, edg);
}
else if (shape_type == ShapeType.SHAPE_TYPE_RAYS) {
c = MMAlgos.shape_rays(uv, sides, rad, edg);
}
return Color(c, c, c, 1);
}
int Shape::get_shape_typoe() {
return shape_type;
}
void Shape::set_shape_typoe(const int val) {
shape_type = val;
set_dirty(true);
}
int Shape::get_sides() {
return sides;
}
void Shape::set_sides(const int val) {
sides = val;
set_dirty(true);
}
}
Shape::Shape() {
image;
shape_type = 0;
sides = 6;
radius;
edge;
}
Shape::~Shape() {
}
static void Shape::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_image"), &Shape::get_image);
ClassDB::bind_method(D_METHOD("set_image", "value"), &Shape::set_image);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_image", "get_image");
ClassDB::bind_method(D_METHOD("get_shape_type"), &Shape::get_shape_type);
ClassDB::bind_method(D_METHOD("set_shape_type", "value"), &Shape::set_shape_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "shape_type"), "set_shape_type", "get_shape_type");
ClassDB::bind_method(D_METHOD("get_sides"), &Shape::get_sides);
ClassDB::bind_method(D_METHOD("set_sides", "value"), &Shape::set_sides);
ADD_PROPERTY(PropertyInfo(Variant::INT, "sides"), "set_sides", "get_sides");
ClassDB::bind_method(D_METHOD("get_radius"), &Shape::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &Shape::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "radius", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_radius", "get_radius");
ClassDB::bind_method(D_METHOD("get_edge"), &Shape::get_edge);
ClassDB::bind_method(D_METHOD("set_edge", "value"), &Shape::set_edge);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edge", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_edge", "get_edge");
ClassDB::bind_method(D_METHOD("_init_properties"), &Shape::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Shape::_register_methods);
ClassDB::bind_method(D_METHOD("_render", "material"), &Shape::_render);
ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Shape::_get_value_for);
ClassDB::bind_method(D_METHOD("get_shape_typoe"), &Shape::get_shape_typoe);
ClassDB::bind_method(D_METHOD("set_shape_typoe", "val"), &Shape::set_shape_typoe);
ClassDB::bind_method(D_METHOD("get_sides"), &Shape::get_sides);
ClassDB::bind_method(D_METHOD("set_sides", "val"), &Shape::set_sides);
}

View File

@ -1,64 +1,53 @@
#ifndef SHAPE_H
#define SHAPE_H
#ifndef MM_SHAPE_H
#define MM_SHAPE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Shape : public MMNode {
GDCLASS(Shape, MMNode);
class MMShape : public MMNode {
GDCLASS(MMShape, 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);
int get_shape_type() const;
void set_shape_type(const int val);
int get_shape_type() const;
void set_shape_type(const int val);
int get_sides() const;
void set_sides(const int val);
int get_sides() const;
void set_sides(const int val);
Ref<MMNodeUniversalProperty> get_radius();
void set_radius(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_radius();
void set_radius(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_edge();
void set_edge(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_edge();
void set_edge(const Ref<Resource> &val);
enum MMShapeType {
SHAPE_TYPE_CIRCLE = 0,
SHAPE_TYPE_POLYGON = 1,
SHAPE_TYPE_STAR = 2,
SHAPE_TYPE_CURVED_STAR = 3,
SHAPE_TYPE_RAYS = 4,
};
enum ShapeType {
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);
SHAPE_TYPE_CIRCLE = 0,
SHAPE_TYPE_POLYGON = 1,
SHAPE_TYPE_STAR = 2,
SHAPE_TYPE_CURVED_STAR = 3,
SHAPE_TYPE_RAYS = 4,
MMShape();
~MMShape();
protected:
static void _bind_methods();
Ref<MMNodeUniversalProperty> image;
//export(int, "Circle,Polygon,Star,Curved Star,Rays")
int shape_type;
int sides;
Ref<MMNodeUniversalProperty> radius;
Ref<MMNodeUniversalProperty> edge;
};
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_shape_typoe();
void set_shape_typoe(const int val);
int get_sides();
void set_sides(const int val);
Shape();
~Shape();
protected:
static void _bind_methods();
//tool
};
//export(Resource)
Ref<Resource> image;
//export(int, "Circle,Polygon,Star,Curved Star,Rays")
int shape_type = 0;
//export(int)
int sides = 6;
//export(Resource)
Ref<Resource> radius;
//export(Resource)
Ref<Resource> edge;
};
#endif

View File

@ -57,6 +57,8 @@ SOFTWARE.
#include "nodes/transform/transform.h"
#include "nodes/transform/translate.h"
#include "nodes/simple/shape.h"
static _MMAlgos *_mm_algos_singleton = nullptr;
void register_material_maker_types() {
@ -101,6 +103,9 @@ void register_material_maker_types() {
ClassDB::register_class<MMCircleMap>();
MMAlgos::register_node_class("Transform", "MMCircleMap");
ClassDB::register_class<MMShape>();
MMAlgos::register_node_class("Simple", "MMShape");
_mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));