Cleaned up the rest of the SDShapes.

This commit is contained in:
Relintai 2022-06-17 19:58:57 +02:00
parent d339fb1fdb
commit f2fb6b8b7d
14 changed files with 409 additions and 693 deletions

View File

@ -93,6 +93,11 @@ sources = [
"nodes/sdf3d/sdf3d_op_bool.cpp", "nodes/sdf3d/sdf3d_op_bool.cpp",
"nodes/sdf2d/sd_shape_rhombus.cpp", "nodes/sdf2d/sd_shape_rhombus.cpp",
"nodes/sdf2d/sd_shape_polygon.cpp",
"nodes/sdf2d/sd_shape_line.cpp",
"nodes/sdf2d/sd_shape_circle.cpp",
"nodes/sdf2d/sd_shape_box.cpp",
"nodes/sdf2d/sd_shape_arc.cpp",
"nodes/sdf2d/sd_tf_translate.cpp", "nodes/sdf2d/sd_tf_translate.cpp",
"nodes/sdf2d/sd_tf_scale.cpp", "nodes/sdf2d/sd_tf_scale.cpp",

View File

@ -69,6 +69,11 @@ def get_doc_classes():
"MMSdTfRotate", "MMSdTfRotate",
"MMSdShapeRhombus", "MMSdShapeRhombus",
"MMSdShapePolygon",
"MMSdShapeLine",
"MMSdShapeCircle",
"MMSdShapeBox",
"MMSdShapeArc",
] ]
def get_doc_path(): def get_doc_path():

View File

@ -1,164 +1,95 @@
#include "sd_shape_arc.h" #include "sd_shape_arc.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> SdShapeArc::get_output() { Ref<MMNodeUniversalProperty> MMSdShapeArc::get_output() {
return output; return output;
} }
void SdShapeArc::set_output(const Ref<Resource> &val) { void MMSdShapeArc::set_output(const Ref<MMNodeUniversalProperty> &val) {
output = val; output = val;
} }
Vector2 MMSdShapeArc::get_angle() {
Vector2 SdShapeArc::get_angle() { return angle;
return angle;
} }
void SdShapeArc::set_angle(const Vector2 &val) { void MMSdShapeArc::set_angle(const Vector2 &val) {
angle = val; angle = val;
emit_changed();
output->do_emit_changed();
} }
float MMSdShapeArc::get_radius() const {
float SdShapeArc::get_radius() const { return radius;
return radius;
} }
void SdShapeArc::set_radius(const float val) { void MMSdShapeArc::set_radius(const float val) {
radius = val; radius = val;
emit_changed();
output->do_emit_changed();
} }
float MMSdShapeArc::get_width() const {
float SdShapeArc::get_width() const { return width;
return width;
} }
void SdShapeArc::set_width(const float val) { void MMSdShapeArc::set_width(const float val) {
width = val; width = val;
emit_changed();
output->do_emit_changed();
} }
void MMSdShapeArc::_init_properties() {
if (!output.is_valid()) {
output.instance();
output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
}
output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT);
output->set_slot_name(">>> Output >>>");
output->set_get_value_from_owner(true);
//tool; register_output_property(output);
//export(Resource) ;
Ref<Resource> output;
//export(Vector2) ;
Vector2 angle = Vector2(30, 150);
//export(float) ;
float radius = 0.3;
//export(float) ;
float width = 0.1;
void SdShapeArc::_init_properties() {
if (!output) {
output = MMNodeUniversalProperty.new();
output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT;
} }
output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; void MMSdShapeArc::_register_methods(MMGraphNode *mm_graph_node) {
output.slot_name = ">>> Output >>>"; mm_graph_node->add_slot_label_universal(output);
output.get_value_from_owner = true; mm_graph_node->add_slot_vector2("get_angle", "set_angle", "Angle", 1);
register_output_property(output); mm_graph_node->add_slot_float("get_radius", "set_radius", "Radius", 0.01);
mm_graph_node->add_slot_float("get_width", "set_width", "Width", 0.01);
} }
Variant MMSdShapeArc::_get_property_value(const Vector2 &uv) {
void SdShapeArc::_register_methods(const Variant &mm_graph_node) { return MMAlgos::sdf_arc(uv, angle, Vector2(radius, width));
mm_graph_node.add_slot_label_universal(output);
mm_graph_node.add_slot_vector2("get_angle", "set_angle", "Angle", 1);
mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01);
mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01);
} }
MMSdShapeArc::MMSdShapeArc() {
float SdShapeArc::_get_property_value(const Vector2 &uv) { angle = Vector2(30, 150);
return MMAlgos.sdf_arc(uv, angle, Vector2(radius, width)); radius = 0.3;
width = 0.1;
} }
//angle; MMSdShapeArc::~MMSdShapeArc() {
Vector2 SdShapeArc::get_angle() {
return angle;
} }
void MMSdShapeArc::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &MMSdShapeArc::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdShapeArc::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output");
void SdShapeArc::set_angle(const Vector2 &val) { ClassDB::bind_method(D_METHOD("get_angle"), &MMSdShapeArc::get_angle);
angle = val; ClassDB::bind_method(D_METHOD("set_angle", "value"), &MMSdShapeArc::set_angle);
emit_changed(); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "angle"), "set_angle", "get_angle");
output.emit_changed();
ClassDB::bind_method(D_METHOD("get_radius"), &MMSdShapeArc::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMSdShapeArc::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
ClassDB::bind_method(D_METHOD("get_width"), &MMSdShapeArc::get_width);
ClassDB::bind_method(D_METHOD("set_width", "value"), &MMSdShapeArc::set_width);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
} }
//radius;
float SdShapeArc::get_radius() {
return radius;
}
void SdShapeArc::set_radius(const float val) {
radius = val;
emit_changed();
output.emit_changed();
}
//width;
float SdShapeArc::get_width() {
return width;
}
void SdShapeArc::set_width(const float val) {
width = val;
emit_changed();
output.emit_changed();
}
}
SdShapeArc::SdShapeArc() {
output;
angle = Vector2(30, 150);
radius = 0.3;
width = 0.1;
}
SdShapeArc::~SdShapeArc() {
}
static void SdShapeArc::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &SdShapeArc::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeArc::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_output", "get_output");
ClassDB::bind_method(D_METHOD("get_angle"), &SdShapeArc::get_angle);
ClassDB::bind_method(D_METHOD("set_angle", "value"), &SdShapeArc::set_angle);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "angle"), "set_angle", "get_angle");
ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeArc::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &SdShapeArc::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
ClassDB::bind_method(D_METHOD("get_width"), &SdShapeArc::get_width);
ClassDB::bind_method(D_METHOD("set_width", "value"), &SdShapeArc::set_width);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeArc::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeArc::_register_methods);
ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeArc::_get_property_value);
ClassDB::bind_method(D_METHOD("get_angle"), &SdShapeArc::get_angle);
ClassDB::bind_method(D_METHOD("set_angle", "val"), &SdShapeArc::set_angle);
ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeArc::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "val"), &SdShapeArc::set_radius);
ClassDB::bind_method(D_METHOD("get_width"), &SdShapeArc::get_width);
ClassDB::bind_method(D_METHOD("set_width", "val"), &SdShapeArc::set_width);
}

View File

@ -1,53 +1,39 @@
#ifndef SD_SHAPE_ARC_H #ifndef MM_SD_SHAPE_ARC_H
#define SD_SHAPE_ARC_H #define MM_SD_SHAPE_ARC_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class SdShapeArc : public MMNode { class MMSdShapeArc : public MMNode {
GDCLASS(SdShapeArc, MMNode); GDCLASS(MMSdShapeArc, MMNode);
public: public:
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output(); Vector2 get_angle();
void set_output(const Ref<Resource> &val); void set_angle(const Vector2 &val);
Vector2 get_angle(); float get_radius() const;
void set_angle(const Vector2 &val); void set_radius(const float val);
float get_radius() const; float get_width() const;
void set_radius(const float val); void set_width(const float val);
float get_width() const; void _init_properties();
void set_width(const float val); void _register_methods(MMGraphNode *mm_graph_node);
Variant _get_property_value(const Vector2 &uv);
void _init_properties(); MMSdShapeArc();
void _register_methods(const Variant &mm_graph_node); ~MMSdShapeArc();
float _get_property_value(const Vector2 &uv);
Vector2 get_angle();
void set_angle(const Vector2 &val);
float get_radius();
void set_radius(const float val);
float get_width();
void set_width(const float val);
SdShapeArc(); protected:
~SdShapeArc(); static void _bind_methods();
protected: Ref<MMNodeUniversalProperty> output;
static void _bind_methods(); Vector2 angle;
float radius;
//tool float width;
//export(Resource)
Ref<Resource> output;
//export(Vector2)
Vector2 angle = Vector2(30, 150);
//export(float)
float radius = 0.3;
//export(float)
float width = 0.1;
//angle
//radius
//width
}; };
#endif #endif

View File

@ -1,131 +1,79 @@
#include "sd_shape_box.h" #include "sd_shape_box.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> SdShapeBox::get_output() { Ref<MMNodeUniversalProperty> MMSdShapeBox::get_output() {
return output; return output;
} }
void SdShapeBox::set_output(const Ref<Resource> &val) { void MMSdShapeBox::set_output(const Ref<MMNodeUniversalProperty> &val) {
output = val; output = val;
} }
Vector2 MMSdShapeBox::get_center() {
Vector2 SdShapeBox::get_center() { return center;
return center;
} }
void SdShapeBox::set_center(const Vector2 &val) { void MMSdShapeBox::set_center(const Vector2 &val) {
center = val; center = val;
emit_changed();
output->do_emit_changed();
} }
Vector2 MMSdShapeBox::get_size() {
Vector2 SdShapeBox::get_size() { return size;
return size;
} }
void SdShapeBox::set_size(const Vector2 &val) { void MMSdShapeBox::set_size(const Vector2 &val) {
size = val; size = val;
emit_changed();
output->do_emit_changed();
} }
void MMSdShapeBox::_init_properties() {
if (!output.is_valid()) {
output.instance();
output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
}
output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT);
output->set_slot_name(">>> Output >>>");
output->set_get_value_from_owner(true);
//tool; register_output_property(output);
//export(Resource) ;
Ref<Resource> output;
//export(Vector2) ;
Vector2 center = Vector2(0, 0);
//export(Vector2) ;
Vector2 size = Vector2(0.3, 0.2);
void SdShapeBox::_init_properties() {
if (!output) {
output = MMNodeUniversalProperty.new();
output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT;
} }
output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; void MMSdShapeBox::_register_methods(MMGraphNode *mm_graph_node) {
output.slot_name = ">>> Output >>>"; mm_graph_node->add_slot_label_universal(output);
output.get_value_from_owner = true; mm_graph_node->add_slot_vector2("get_center", "set_center", "Center", 0.01);
register_output_property(output); mm_graph_node->add_slot_vector2("get_size", "set_size", "Size", 0.01);
} }
Variant MMSdShapeBox::_get_property_value(const Vector2 &uv) {
void SdShapeBox::_register_methods(const Variant &mm_graph_node) { return MMAlgos::sdf_box(uv, center, size);
mm_graph_node.add_slot_label_universal(output);
mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01);
mm_graph_node.add_slot_vector2("get_size", "set_size", "Size", 0.01);
} }
MMSdShapeBox::MMSdShapeBox() {
float SdShapeBox::_get_property_value(const Vector2 &uv) { center = Vector2(0, 0);
return MMAlgos.sdf_box(uv, center, size); size = Vector2(0.3, 0.2);
} }
//center; MMSdShapeBox::~MMSdShapeBox() {
Vector2 SdShapeBox::get_center() {
return center;
} }
void MMSdShapeBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &MMSdShapeBox::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdShapeBox::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output");
void SdShapeBox::set_center(const Vector2 &val) { ClassDB::bind_method(D_METHOD("get_center"), &MMSdShapeBox::get_center);
center = val; ClassDB::bind_method(D_METHOD("set_center", "value"), &MMSdShapeBox::set_center);
emit_changed(); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
output.emit_changed();
ClassDB::bind_method(D_METHOD("get_size"), &MMSdShapeBox::get_size);
ClassDB::bind_method(D_METHOD("set_size", "value"), &MMSdShapeBox::set_size);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
} }
//size;
Vector2 SdShapeBox::get_size() {
return size;
}
void SdShapeBox::set_size(const Vector2 &val) {
size = val;
emit_changed();
output.emit_changed();
}
}
SdShapeBox::SdShapeBox() {
output;
center = Vector2(0, 0);
size = Vector2(0.3, 0.2);
}
SdShapeBox::~SdShapeBox() {
}
static void SdShapeBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &SdShapeBox::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeBox::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_output", "get_output");
ClassDB::bind_method(D_METHOD("get_center"), &SdShapeBox::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &SdShapeBox::set_center);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("get_size"), &SdShapeBox::get_size);
ClassDB::bind_method(D_METHOD("set_size", "value"), &SdShapeBox::set_size);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeBox::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeBox::_register_methods);
ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeBox::_get_property_value);
ClassDB::bind_method(D_METHOD("get_center"), &SdShapeBox::get_center);
ClassDB::bind_method(D_METHOD("set_center", "val"), &SdShapeBox::set_center);
ClassDB::bind_method(D_METHOD("get_size"), &SdShapeBox::get_size);
ClassDB::bind_method(D_METHOD("set_size", "val"), &SdShapeBox::set_size);
}

View File

@ -1,45 +1,35 @@
#ifndef SD_SHAPE_BOX_H #ifndef MM_SD_SHAPE_BOX_H
#define SD_SHAPE_BOX_H #define MM_SD_SHAPE_BOX_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class SdShapeBox : public MMNode { class MMSdShapeBox : public MMNode {
GDCLASS(SdShapeBox, MMNode); GDCLASS(MMSdShapeBox, MMNode);
public: public:
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output(); Vector2 get_center();
void set_output(const Ref<Resource> &val); void set_center(const Vector2 &val);
Vector2 get_center(); Vector2 get_size();
void set_center(const Vector2 &val); void set_size(const Vector2 &val);
Vector2 get_size(); void _init_properties();
void set_size(const Vector2 &val); void _register_methods(MMGraphNode *mm_graph_node);
Variant _get_property_value(const Vector2 &uv);
void _init_properties(); MMSdShapeBox();
void _register_methods(const Variant &mm_graph_node); ~MMSdShapeBox();
float _get_property_value(const Vector2 &uv);
Vector2 get_center();
void set_center(const Vector2 &val);
Vector2 get_size();
void set_size(const Vector2 &val);
SdShapeBox(); protected:
~SdShapeBox(); static void _bind_methods();
protected: Ref<MMNodeUniversalProperty> output;
static void _bind_methods(); Vector2 center;
Vector2 size;
//tool
//export(Resource)
Ref<Resource> output;
//export(Vector2)
Vector2 center = Vector2(0, 0);
//export(Vector2)
Vector2 size = Vector2(0.3, 0.2);
//center
//size
}; };
#endif #endif

View File

@ -1,131 +1,79 @@
#include "sd_shape_circle.h" #include "sd_shape_circle.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> SdShapeCircle::get_output() { Ref<MMNodeUniversalProperty> MMSdShapeCircle::get_output() {
return output; return output;
} }
void SdShapeCircle::set_output(const Ref<Resource> &val) { void MMSdShapeCircle::set_output(const Ref<MMNodeUniversalProperty> &val) {
output = val; output = val;
} }
Vector2 MMSdShapeCircle::get_center() {
Vector2 SdShapeCircle::get_center() { return center;
return center;
} }
void SdShapeCircle::set_center(const Vector2 &val) { void MMSdShapeCircle::set_center(const Vector2 &val) {
center = val; center = val;
emit_changed();
output->do_emit_changed();
} }
float MMSdShapeCircle::get_radius() const {
float SdShapeCircle::get_radius() const { return radius;
return radius;
} }
void SdShapeCircle::set_radius(const float val) { void MMSdShapeCircle::set_radius(const float val) {
radius = val; radius = val;
emit_changed();
output->do_emit_changed();
} }
void MMSdShapeCircle::_init_properties() {
if (!output.is_valid()) {
output.instance();
output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
}
output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT);
output->set_slot_name(">>> Output >>>");
output->set_get_value_from_owner(true);
//tool; register_output_property(output);
//export(Resource) ;
Ref<Resource> output;
//export(Vector2) ;
Vector2 center = Vector2(0, 0);
//export(float) ;
float radius = 0.4;
void SdShapeCircle::_init_properties() {
if (!output) {
output = MMNodeUniversalProperty.new();
output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT;
} }
output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; void MMSdShapeCircle::_register_methods(MMGraphNode *mm_graph_node) {
output.slot_name = ">>> Output >>>"; mm_graph_node->add_slot_label_universal(output);
output.get_value_from_owner = true; mm_graph_node->add_slot_vector2("get_center", "set_center", "Center", 0.01);
register_output_property(output); mm_graph_node->add_slot_float("get_radius", "set_radius", "Radius", 0.01);
} }
Variant MMSdShapeCircle::_get_property_value(const Vector2 &uv) {
void SdShapeCircle::_register_methods(const Variant &mm_graph_node) { return MMAlgos::sdf_circle(uv, center, radius);
mm_graph_node.add_slot_label_universal(output);
mm_graph_node.add_slot_vector2("get_center", "set_center", "Center", 0.01);
mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01);
} }
MMSdShapeCircle::MMSdShapeCircle() {
float SdShapeCircle::_get_property_value(const Vector2 &uv) { center = Vector2(0, 0);
return MMAlgos.sdf_circle(uv, center, radius); radius = 0.4;
} }
//center; MMSdShapeCircle::~MMSdShapeCircle() {
Vector2 SdShapeCircle::get_center() {
return center;
} }
void MMSdShapeCircle::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &MMSdShapeCircle::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdShapeCircle::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output");
void SdShapeCircle::set_center(const Vector2 &val) { ClassDB::bind_method(D_METHOD("get_center"), &MMSdShapeCircle::get_center);
center = val; ClassDB::bind_method(D_METHOD("set_center", "value"), &MMSdShapeCircle::set_center);
emit_changed(); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
output.emit_changed();
ClassDB::bind_method(D_METHOD("get_radius"), &MMSdShapeCircle::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMSdShapeCircle::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
} }
//radius;
float SdShapeCircle::get_radius() {
return radius;
}
void SdShapeCircle::set_radius(const float val) {
radius = val;
emit_changed();
output.emit_changed();
}
}
SdShapeCircle::SdShapeCircle() {
output;
center = Vector2(0, 0);
radius = 0.4;
}
SdShapeCircle::~SdShapeCircle() {
}
static void SdShapeCircle::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &SdShapeCircle::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeCircle::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_output", "get_output");
ClassDB::bind_method(D_METHOD("get_center"), &SdShapeCircle::get_center);
ClassDB::bind_method(D_METHOD("set_center", "value"), &SdShapeCircle::set_center);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center");
ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeCircle::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "value"), &SdShapeCircle::set_radius);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius");
ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeCircle::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeCircle::_register_methods);
ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeCircle::_get_property_value);
ClassDB::bind_method(D_METHOD("get_center"), &SdShapeCircle::get_center);
ClassDB::bind_method(D_METHOD("set_center", "val"), &SdShapeCircle::set_center);
ClassDB::bind_method(D_METHOD("get_radius"), &SdShapeCircle::get_radius);
ClassDB::bind_method(D_METHOD("set_radius", "val"), &SdShapeCircle::set_radius);
}

View File

@ -1,45 +1,35 @@
#ifndef SD_SHAPE_CIRCLE_H #ifndef MM_SD_SHAPE_CIRCLE_H
#define SD_SHAPE_CIRCLE_H #define MM_SD_SHAPE_CIRCLE_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class SdShapeCircle : public MMNode { class MMSdShapeCircle : public MMNode {
GDCLASS(SdShapeCircle, MMNode); GDCLASS(MMSdShapeCircle, MMNode);
public: public:
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output(); Vector2 get_center();
void set_output(const Ref<Resource> &val); void set_center(const Vector2 &val);
Vector2 get_center(); float get_radius() const;
void set_center(const Vector2 &val); void set_radius(const float val);
float get_radius() const; void _init_properties();
void set_radius(const float val); void _register_methods(MMGraphNode *mm_graph_node);
Variant _get_property_value(const Vector2 &uv);
void _init_properties(); MMSdShapeCircle();
void _register_methods(const Variant &mm_graph_node); ~MMSdShapeCircle();
float _get_property_value(const Vector2 &uv);
Vector2 get_center();
void set_center(const Vector2 &val);
float get_radius();
void set_radius(const float val);
SdShapeCircle(); protected:
~SdShapeCircle(); static void _bind_methods();
protected: Ref<MMNodeUniversalProperty> output;
static void _bind_methods(); Vector2 center;
float radius;
//tool
//export(Resource)
Ref<Resource> output;
//export(Vector2)
Vector2 center = Vector2(0, 0);
//export(float)
float radius = 0.4;
//center
//radius
}; };
#endif #endif

View File

@ -1,180 +1,111 @@
#include "sd_shape_line.h" #include "sd_shape_line.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> SdShapeLine::get_output() { Ref<MMNodeUniversalProperty> MMSdShapeLine::get_output() {
return output; return output;
} }
void SdShapeLine::set_output(const Ref<Resource> &val) { void MMSdShapeLine::set_output(const Ref<MMNodeUniversalProperty> &val) {
output = val; output = val;
} }
Vector2 MMSdShapeLine::get_a() {
Vector2 SdShapeLine::get_A() { return A;
return A;
} }
void SdShapeLine::set_A(const Vector2 &val) { void MMSdShapeLine::set_a(const Vector2 &val) {
A = val; A = val;
emit_changed();
output->do_emit_changed();
} }
Vector2 MMSdShapeLine::get_b() {
Vector2 SdShapeLine::get_B() { return B;
return B;
} }
void SdShapeLine::set_B(const Vector2 &val) { void MMSdShapeLine::set_b(const Vector2 &val) {
B = val; B = val;
emit_changed();
output->do_emit_changed();
} }
float MMSdShapeLine::get_width() const {
float SdShapeLine::get_width() const { return width;
return width;
} }
void SdShapeLine::set_width(const float val) { void MMSdShapeLine::set_width(const float val) {
width = val; width = val;
emit_changed();
output->do_emit_changed();
} }
void MMSdShapeLine::_init_properties() {
if (!output.is_valid()) {
output.instance();
output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
}
output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT);
output->set_slot_name(">>> Output >>>");
output->set_get_value_from_owner(true);
//tool; register_output_property(output);
//export(Resource) ;
Ref<Resource> output;
//export(Vector2) ;
Vector2 A = Vector2(-0.3, -0.3);
//export(Vector2) ;
Vector2 B = Vector2(0.3, 0.3);
//export(float) ;
float width = 0.1;
void SdShapeLine::_init() {
init_points_11();
} }
void MMSdShapeLine::_register_methods(MMGraphNode *mm_graph_node) {
void SdShapeLine::_init_properties() { mm_graph_node->add_slot_label_universal(output);
mm_graph_node->add_slot_vector2("get_a", "set_a", "A", 0.01);
if (!output) { mm_graph_node->add_slot_vector2("get_b", "set_b", "B", 0.01);
output = MMNodeUniversalProperty.new(); mm_graph_node->add_slot_float("get_width", "set_width", "Width", 0.01);
output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; mm_graph_node->add_slot_curve();
} }
output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; Variant MMSdShapeLine::_get_property_value(const Vector2 &uv) {
output.slot_name = ">>> Output >>>"; Vector2 line = MMAlgos::sdf_line(uv, A, B, width);
output.get_value_from_owner = true; //$(name_uv)_sdl.x - $r * $profile($(name_uv)_sdl.y);
register_output_property(output); return line.x - width * MMAlgos::curve(line.y, points);
} }
void MMSdShapeLine::_curve_changed() {
void SdShapeLine::_register_methods(const Variant &mm_graph_node) { emit_changed();
mm_graph_node.add_slot_label_universal(output); output->do_emit_changed();
mm_graph_node.add_slot_vector2("get_a", "set_a", "A", 0.01);
mm_graph_node.add_slot_vector2("get_b", "set_b", "B", 0.01);
mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01);
mm_graph_node.add_slot_curve();
} }
MMSdShapeLine::MMSdShapeLine() {
float SdShapeLine::_get_property_value(const Vector2 &uv) { A = Vector2(-0.3, -0.3);
Vector2 line = MMAlgos.sdf_line(uv, A, B, width); B = Vector2(0.3, 0.3);
//$(name_uv)_sdl.x - $r * $profile($(name_uv)_sdl.y); width = 0.1;
return line.x - width * MMAlgos.curve(line.y, points_array);
} }
//a; MMSdShapeLine::~MMSdShapeLine() {
Vector2 SdShapeLine::get_a() {
return A;
} }
void MMSdShapeLine::_notification(int p_what) {
void SdShapeLine::set_a(const Vector2 &val) { if (p_what == NOTIFICATION_POSTINITIALIZE) {
A = val; if (points.size() == 0) {
emit_changed(); init_points_11();
output.emit_changed(); }
}
} }
//b; void MMSdShapeLine::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &MMSdShapeLine::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdShapeLine::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output");
Vector2 SdShapeLine::get_b() { ClassDB::bind_method(D_METHOD("get_a"), &MMSdShapeLine::get_a);
return B; ClassDB::bind_method(D_METHOD("set_a", "value"), &MMSdShapeLine::set_a);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "A"), "set_a", "get_a");
ClassDB::bind_method(D_METHOD("get_b"), &MMSdShapeLine::get_b);
ClassDB::bind_method(D_METHOD("set_b", "value"), &MMSdShapeLine::set_b);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "B"), "set_b", "get_b");
ClassDB::bind_method(D_METHOD("get_width"), &MMSdShapeLine::get_width);
ClassDB::bind_method(D_METHOD("set_width", "value"), &MMSdShapeLine::set_width);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
} }
void SdShapeLine::set_b(const Vector2 &val) {
B = val;
emit_changed();
output.emit_changed();
}
//width;
float SdShapeLine::get_width() {
return width;
}
void SdShapeLine::set_width(const float val) {
width = val;
emit_changed();
output.emit_changed();
}
void SdShapeLine::_curve_changed() {
emit_changed();
output.emit_changed();
}
}
SdShapeLine::SdShapeLine() {
output;
A = Vector2(-0.3, -0.3);
B = Vector2(0.3, 0.3);
width = 0.1;
}
SdShapeLine::~SdShapeLine() {
}
static void SdShapeLine::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &SdShapeLine::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeLine::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_output", "get_output");
ClassDB::bind_method(D_METHOD("get_A"), &SdShapeLine::get_A);
ClassDB::bind_method(D_METHOD("set_A", "value"), &SdShapeLine::set_A);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "A"), "set_A", "get_A");
ClassDB::bind_method(D_METHOD("get_B"), &SdShapeLine::get_B);
ClassDB::bind_method(D_METHOD("set_B", "value"), &SdShapeLine::set_B);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "B"), "set_B", "get_B");
ClassDB::bind_method(D_METHOD("get_width"), &SdShapeLine::get_width);
ClassDB::bind_method(D_METHOD("set_width", "value"), &SdShapeLine::set_width);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
ClassDB::bind_method(D_METHOD("_init"), &SdShapeLine::_init);
ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeLine::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeLine::_register_methods);
ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeLine::_get_property_value);
ClassDB::bind_method(D_METHOD("get_a"), &SdShapeLine::get_a);
ClassDB::bind_method(D_METHOD("set_a", "val"), &SdShapeLine::set_a);
ClassDB::bind_method(D_METHOD("get_b"), &SdShapeLine::get_b);
ClassDB::bind_method(D_METHOD("set_b", "val"), &SdShapeLine::set_b);
ClassDB::bind_method(D_METHOD("get_width"), &SdShapeLine::get_width);
ClassDB::bind_method(D_METHOD("set_width", "val"), &SdShapeLine::set_width);
ClassDB::bind_method(D_METHOD("_curve_changed"), &SdShapeLine::_curve_changed);
}

View File

@ -1,55 +1,43 @@
#ifndef SD_SHAPE_LINE_H #ifndef MM_SD_SHAPE_LINE_H
#define SD_SHAPE_LINE_H #define MM_SD_SHAPE_LINE_H
#include "../bases/curve_base.h"
#include "../mm_node_universal_property.h"
class SdShapeLine : public CurveBase { class MMSdShapeLine : public CurveBase {
GDCLASS(SdShapeLine, CurveBase); GDCLASS(MMSdShapeLine, CurveBase);
public: public:
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output(); Vector2 get_a();
void set_output(const Ref<Resource> &val); void set_a(const Vector2 &val);
Vector2 get_A(); Vector2 get_b();
void set_A(const Vector2 &val); void set_b(const Vector2 &val);
Vector2 get_B(); float get_width() const;
void set_B(const Vector2 &val); void set_width(const float val);
float get_width() const; void _init_properties();
void set_width(const float val); void _register_methods(MMGraphNode *mm_graph_node);
Variant _get_property_value(const Vector2 &uv);
void _init(); void _curve_changed();
void _init_properties();
void _register_methods(const Variant &mm_graph_node);
float _get_property_value(const Vector2 &uv);
Vector2 get_a();
void set_a(const Vector2 &val);
Vector2 get_b();
void set_b(const Vector2 &val);
float get_width();
void set_width(const float val);
void _curve_changed();
SdShapeLine(); MMSdShapeLine();
~SdShapeLine(); ~MMSdShapeLine();
protected: protected:
static void _bind_methods(); void _notification(int p_what);
//tool static void _bind_methods();
//export(Resource)
Ref<Resource> output; Ref<MMNodeUniversalProperty> output;
//export(Vector2) Vector2 A;
Vector2 A = Vector2(-0.3, -0.3); Vector2 B;
//export(Vector2) float width;
Vector2 B = Vector2(0.3, 0.3);
//export(float)
float width = 0.1;
//a
//b
//width
}; };
#endif #endif

View File

@ -1,73 +1,53 @@
#include "sd_shape_polygon.h" #include "sd_shape_polygon.h"
#include "../../algos/mm_algos.h"
#include "../../editor/mm_graph_node.h"
#include "../mm_material.h"
Ref<Resource> SdShapePolygon::get_output() { Ref<MMNodeUniversalProperty> MMSdShapePolygon::get_output() {
return output; return output;
} }
void SdShapePolygon::set_output(const Ref<Resource> &val) { void MMSdShapePolygon::set_output(const Ref<MMNodeUniversalProperty> &val) {
output = val; output = val;
} }
void MMSdShapePolygon::_init_properties() {
if (!output.is_valid()) {
output.instance();
output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT);
}
output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT);
output->set_slot_name(">>> Output >>>");
output->set_get_value_from_owner(true);
//tool; register_output_property(output);
//export(Resource) ;
Ref<Resource> output;
void SdShapePolygon::_init_properties() {
if (!output) {
output = MMNodeUniversalProperty.new();
output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT;
} }
output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; void MMSdShapePolygon::_register_methods(MMGraphNode *mm_graph_node) {
output.slot_name = ">>> Output >>>"; mm_graph_node->add_slot_label_universal(output);
output.get_value_from_owner = true; mm_graph_node->add_slot_polygon();
register_output_property(output);
} }
Variant MMSdShapePolygon::_get_property_value(const Vector2 &uv) {
void SdShapePolygon::_register_methods(const Variant &mm_graph_node) { return MMAlgos::sdPolygon(uv, points);
mm_graph_node.add_slot_label_universal(output);
mm_graph_node.add_slot_polygon();
} }
void MMSdShapePolygon::_polygon_changed() {
float SdShapePolygon::_get_property_value(const Vector2 &uv) { emit_changed();
return MMAlgos.sdPolygon(uv, points); output->do_emit_changed();
} }
MMSdShapePolygon::MMSdShapePolygon() {
void SdShapePolygon::_polygon_changed() {
emit_changed();
output.emit_changed();
} }
MMSdShapePolygon::~MMSdShapePolygon() {
} }
SdShapePolygon::SdShapePolygon() { void MMSdShapePolygon::_bind_methods() {
output; ClassDB::bind_method(D_METHOD("get_output"), &MMSdShapePolygon::get_output);
} ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdShapePolygon::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output");
SdShapePolygon::~SdShapePolygon() { }
}
static void SdShapePolygon::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_output"), &SdShapePolygon::get_output);
ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapePolygon::set_output);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref<Resource>"), "set_output", "get_output");
ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapePolygon::_init_properties);
ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapePolygon::_register_methods);
ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapePolygon::_get_property_value);
ClassDB::bind_method(D_METHOD("_polygon_changed"), &SdShapePolygon::_polygon_changed);
}

View File

@ -1,30 +1,29 @@
#ifndef SD_SHAPE_POLYGON_H #ifndef MM_SD_SHAPE_POLYGON_H
#define SD_SHAPE_POLYGON_H #define MM_SD_SHAPE_POLYGON_H
#include "../bases/polygon_base.h"
#include "../mm_node_universal_property.h"
class SdShapePolygon : public PolygonBase { class MMSdShapePolygon : public PolygonBase {
GDCLASS(SdShapePolygon, PolygonBase); GDCLASS(MMSdShapePolygon, PolygonBase);
public: public:
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output(); void _init_properties();
void set_output(const Ref<Resource> &val); void _register_methods(MMGraphNode *mm_graph_node);
Variant _get_property_value(const Vector2 &uv);
void _init_properties(); void _polygon_changed();
void _register_methods(const Variant &mm_graph_node);
float _get_property_value(const Vector2 &uv);
void _polygon_changed();
SdShapePolygon(); MMSdShapePolygon();
~SdShapePolygon(); ~MMSdShapePolygon();
protected: protected:
static void _bind_methods(); static void _bind_methods();
//tool Ref<MMNodeUniversalProperty> output;
//export(Resource)
Ref<Resource> output;
}; };
#endif #endif

View File

@ -1,5 +1,5 @@
#ifndef SD_TF_ROTATE_H #ifndef MM_SD_TF_ROTATE_H
#define SD_TF_ROTATE_H #define MM_SD_TF_ROTATE_H
#include "../mm_node.h" #include "../mm_node.h"
#include "../mm_node_universal_property.h" #include "../mm_node_universal_property.h"

View File

@ -84,6 +84,11 @@ SOFTWARE.
#include "nodes/sdf3d/sdf3d_op_rounded.h" #include "nodes/sdf3d/sdf3d_op_rounded.h"
#include "nodes/sdf3d/sdf3d_op_smooth_bool.h" #include "nodes/sdf3d/sdf3d_op_smooth_bool.h"
#include "nodes/sdf2d/sd_shape_arc.h"
#include "nodes/sdf2d/sd_shape_box.h"
#include "nodes/sdf2d/sd_shape_circle.h"
#include "nodes/sdf2d/sd_shape_line.h"
#include "nodes/sdf2d/sd_shape_polygon.h"
#include "nodes/sdf2d/sd_shape_rhombus.h" #include "nodes/sdf2d/sd_shape_rhombus.h"
#include "nodes/sdf2d/sd_tf_rotate.h" #include "nodes/sdf2d/sd_tf_rotate.h"
@ -190,6 +195,16 @@ void register_material_maker_types() {
ClassDB::register_class<MMSdShapeRhombus>(); ClassDB::register_class<MMSdShapeRhombus>();
MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeRhombus"); MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeRhombus");
ClassDB::register_class<MMSdShapePolygon>();
MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapePolygon");
ClassDB::register_class<MMSdShapeLine>();
MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeLine");
ClassDB::register_class<MMSdShapeCircle>();
MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeCircle");
ClassDB::register_class<MMSdShapeBox>();
MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeBox");
ClassDB::register_class<MMSdShapeArc>();
MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeArc");
ClassDB::register_class<MMSdTfTranslate>(); ClassDB::register_class<MMSdTfTranslate>();
MMAlgos::register_node_class("SDF2D - TF", "MMSdTfTranslate"); MMAlgos::register_node_class("SDF2D - TF", "MMSdTfTranslate");