diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index ea5c1ad16..947eae23a 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -76,6 +76,11 @@ sources = [ "nodes/sdf3d/sdf3d_tf_rotate.cpp", "nodes/sdf3d/sdf3d_shape_torus.cpp", + "nodes/sdf3d/sdf3d_shape_sphere.cpp", + "nodes/sdf3d/sdf3d_shape_cylinder.cpp", + "nodes/sdf3d/sdf3d_shape_cone.cpp", + "nodes/sdf3d/sdf3d_shape_capsule.cpp", + "nodes/sdf3d/sdf3d_shape_box.cpp", ] diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 4d9b1910f..4f2132328 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -46,6 +46,11 @@ def get_doc_classes(): "MMSdf3dTfRotate", "MMSdf3dShapeTorus", + "MMSdf3dShapeSphere", + "MMSdf3dShapeCylinder", + "MMSdf3dShapeCone", + "MMSdf3dShapeCapsule", + "MMSdf3dShapeBox", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp index ba1cc14b4..59b291bdd 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.cpp @@ -1,131 +1,79 @@ #include "sdf3d_shape_box.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Sdf3dShapeBox::get_output() { - return output; +Ref MMSdf3dShapeBox::get_output() { + return output; } -void Sdf3dShapeBox::set_output(const Ref &val) { -output = val; +void MMSdf3dShapeBox::set_output(const Ref &val) { + output = val; } - -Vector3 Sdf3dShapeBox::get_size() { - return size; +Vector3 MMSdf3dShapeBox::get_size() { + return size; } -void Sdf3dShapeBox::set_size(const Vector3 &val) { -size = val; +void MMSdf3dShapeBox::set_size(const Vector3 &val) { + size = val; + emit_changed(); + output->do_emit_changed(); } - -float Sdf3dShapeBox::get_radius() const { - return radius; +float MMSdf3dShapeBox::get_radius() const { + return radius; } -void Sdf3dShapeBox::set_radius(const float val) { -radius = val; +void MMSdf3dShapeBox::set_radius(const float val) { + radius = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdf3dShapeBox::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT); + output->set_slot_name(">>> Output >>>"); + output->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref output; - //export(Vector3) ; - Vector3 size = Vector3(0.3, 0.25, 0.25); - //export(float) ; - float radius = 0.01; - - void Sdf3dShapeBox::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; + register_output_property(output); } - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Output >>>"; - output.get_value_from_owner = true; - register_output_property(output); +void MMSdf3dShapeBox::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + mm_graph_node->add_slot_vector3("get_size", "set_size", "Size", 0.01); + mm_graph_node->add_slot_float("get_radius", "set_radius", "Radius", 0.01); } - - void Sdf3dShapeBox::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_vector3("get_size", "set_size", "Size", 0.01); - mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +Vector2 MMSdf3dShapeBox::_get_property_value_sdf3d(const Vector3 &uv3) { + return MMAlgos::sdf3d_box(uv3, size.x, size.y, size.z, radius); } - - Vector2 Sdf3dShapeBox::_get_property_value_sdf3d(const Vector3 &uv3) { - return MMAlgos.sdf3d_box(uv3, size.x, size.y, size.z, radius); +MMSdf3dShapeBox::MMSdf3dShapeBox() { + size = Vector3(0.3, 0.25, 0.25); + radius = 0.01; } - //size; - - Vector3 Sdf3dShapeBox::get_size() { - return size; +MMSdf3dShapeBox::~MMSdf3dShapeBox() { } +void MMSdf3dShapeBox::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdf3dShapeBox::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdf3dShapeBox::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - void Sdf3dShapeBox::set_size(const Vector3 &val) { - size = val; - emit_changed(); - output.emit_changed(); + ClassDB::bind_method(D_METHOD("get_size"), &MMSdf3dShapeBox::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMSdf3dShapeBox::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); + + ClassDB::bind_method(D_METHOD("get_radius"), &MMSdf3dShapeBox::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMSdf3dShapeBox::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); } - - //radius; - - float Sdf3dShapeBox::get_radius() { - return radius; -} - - - void Sdf3dShapeBox::set_radius(const float val) { - radius = val; - emit_changed(); - output.emit_changed(); -} - -} - - Sdf3dShapeBox::Sdf3dShapeBox() { - output; - size = Vector3(0.3, 0.25, 0.25); - radius = 0.01; - } - - Sdf3dShapeBox::~Sdf3dShapeBox() { - } - - - static void Sdf3dShapeBox::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeBox::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeBox::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_size"), &Sdf3dShapeBox::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &Sdf3dShapeBox::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeBox::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeBox::set_radius); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeBox::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeBox::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeBox::_get_property_value_sdf3d); - ClassDB::bind_method(D_METHOD("get_size"), &Sdf3dShapeBox::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &Sdf3dShapeBox::set_size); - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeBox::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeBox::set_radius); - - } - - - diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h index a34f89b9f..cf2d020f9 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_box.h @@ -1,45 +1,35 @@ -#ifndef SDF3D_SHAPE_BOX_H -#define SDF3D_SHAPE_BOX_H +#ifndef MM_SDF3D_SHAPE_BOX_H +#define MM_SDF3D_SHAPE_BOX_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Sdf3dShapeBox : public MMNode { - GDCLASS(Sdf3dShapeBox, MMNode); +class MMSdf3dShapeBox : public MMNode { + GDCLASS(MMSdf3dShapeBox, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + Vector3 get_size(); + void set_size(const Vector3 &val); - Vector3 get_size(); - void set_size(const Vector3 &val); + float get_radius() const; + void set_radius(const float val); - float get_radius() const; - void set_radius(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - Vector3 get_size(); - void set_size(const Vector3 &val); - float get_radius(); - void set_radius(const float val); + MMSdf3dShapeBox(); + ~MMSdf3dShapeBox(); - Sdf3dShapeBox(); - ~Sdf3dShapeBox(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(Vector3) - Vector3 size = Vector3(0.3, 0.25, 0.25); - //export(float) - float radius = 0.01; - //size - //radius + Ref output; + Vector3 size; + float radius; }; - #endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp index b8edbe263..d06cc7eaa 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.cpp @@ -1,229 +1,158 @@ #include "sdf3d_shape_capsule.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Sdf3dShapeCapsule::get_output() { - return output; +Ref MMSdf3dShapeCapsule::get_output() { + return output; } -void Sdf3dShapeCapsule::set_output(const Ref &val) { -output = val; +void MMSdf3dShapeCapsule::set_output(const Ref &val) { + output = val; } - -int Sdf3dShapeCapsule::get_axis() const { - return axis; +int MMSdf3dShapeCapsule::get_axis() const { + return axis; } -void Sdf3dShapeCapsule::set_axis(const int val) { -axis = val; +void MMSdf3dShapeCapsule::set_axis(const int val) { + axis = val; + emit_changed(); + output->do_emit_changed(); } - -float Sdf3dShapeCapsule::get_length() const { - return length; +float MMSdf3dShapeCapsule::get_length() const { + return length; } -void Sdf3dShapeCapsule::set_length(const float val) { -length = val; +void MMSdf3dShapeCapsule::set_length(const float val) { + length = val; + emit_changed(); + output->do_emit_changed(); } - -float Sdf3dShapeCapsule::get_radius() const { - return radius; +float MMSdf3dShapeCapsule::get_radius() const { + return radius; } -void Sdf3dShapeCapsule::set_radius(const float val) { -radius = val; +void MMSdf3dShapeCapsule::set_radius(const float val) { + radius = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdf3dShapeCapsule::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT); + output->set_slot_name(">>> Output >>>"); + output->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref output; - //export(int, "X,Y,Z") ; - int axis = 1; - //export(float) ; - float length = 0.3; - //export(float) ; - float radius = 0.2; - - void Sdf3dShapeCapsule::_init() { - init_points_11(); + register_output_property(output); } +void MMSdf3dShapeCapsule::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); - void Sdf3dShapeCapsule::_init_properties() { + Array arr; + arr.push_back("X"); + arr.push_back("Y"); + arr.push_back("Z"); - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; + mm_graph_node->add_slot_enum("get_axis", "set_axis", "Axis", arr); + mm_graph_node->add_slot_float("get_length", "set_length", "Length", 0.01); + mm_graph_node->add_slot_float("get_radius", "set_radius", "Radius", 0.01); + mm_graph_node->add_slot_curve(); } - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Output >>>"; - output.get_value_from_owner = true; - register_output_property(output); +Vector2 MMSdf3dShapeCapsule::_get_property_value_sdf3d(const Vector3 &uv3) { + if (axis == 0) { + return sdf3d_capsule_x(uv3, radius, length); + } else if (axis == 1) { + return sdf3d_capsule_y(uv3, radius, length); + } else if (axis == 2) { + return sdf3d_capsule_z(uv3, radius, length); + } + + return Vector2(); } +//vec3 $(name_uv)_p = $uv; +//$(name_uv)_p.$axis -= clamp($(name_uv)_p.$axis, -$l, $l); +//return length($(name_uv)_p) - $r * $profile(clamp(0.5+0.5*($uv).$axis/$l, 0.0, 1.0)); - void Sdf3dShapeCapsule::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Z" ]); - mm_graph_node.add_slot_float("get_length", "set_length", "Length", 0.01); - mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); - mm_graph_node.add_slot_curve(); +Vector2 MMSdf3dShapeCapsule::sdf3d_capsule_y(const Vector3 &p, const float r, const float l) { + Vector3 v = p; + v.y -= CLAMP(v.y, -l, l); + float cx = CLAMP(0.5 + 0.5 * p.y / l, 0.0, 1.0); + float cp = MMAlgos::curve(cx, points); + float f = v.length() - r * cp; + return Vector2(f, 0.0); } - - Vector2 Sdf3dShapeCapsule::_get_property_value_sdf3d(const Vector3 &uv3) { - - if (axis == 0) { - return sdf3d_capsule_x(uv3, radius, length); +Vector2 MMSdf3dShapeCapsule::sdf3d_capsule_x(const Vector3 &p, const float r, const float l) { + Vector3 v = p; + v.x -= CLAMP(v.x, -l, l); + float cx = CLAMP(0.5 + 0.5 * p.x / l, 0.0, 1.0); + float cp = MMAlgos::curve(cx, points); + float f = v.length() - r * cp; + return Vector2(f, 0.0); } - - else if (axis == 1) { - return sdf3d_capsule_y(uv3, radius, length); +Vector2 MMSdf3dShapeCapsule::sdf3d_capsule_z(const Vector3 &p, const float r, const float l) { + Vector3 v = p; + v.z -= CLAMP(v.z, -l, l); + float cx = CLAMP(0.5 + 0.5 * p.z / l, 0.0, 1.0); + float cp = MMAlgos::curve(cx, points); + float f = v.length() - r * cp; + return Vector2(f, 0.0); } - - else if (axis == 2) { - return sdf3d_capsule_z(uv3, radius, length); +void MMSdf3dShapeCapsule::_curve_changed() { + emit_changed(); + output->do_emit_changed(); } - return Vector2(); +MMSdf3dShapeCapsule::MMSdf3dShapeCapsule() { + axis = 1; + length = 0.3; + radius = 0.2; } - //vec3 $(name_uv)_p = $uv; - //$(name_uv)_p.$axis -= clamp($(name_uv)_p.$axis, -$l, $l); - //return length($(name_uv)_p) - $r * $profile(clamp(0.5+0.5*($uv).$axis/$l, 0.0, 1.0)); - - Vector2 Sdf3dShapeCapsule::sdf3d_capsule_y(const Vector3 &p, const float r, const float l) { - Vector3 v = p; - v.y -= clamp(v.y, -l, l); - float cx = clamp(0.5 + 0.5 * p.y / l, 0.0, 1.0); - float cp = MMAlgos.curve(cx, points_array); - float f = v.length() - r * cp; - return Vector2(f, 0.0); +MMSdf3dShapeCapsule::~MMSdf3dShapeCapsule() { } - - Vector2 Sdf3dShapeCapsule::sdf3d_capsule_x(const Vector3 &p, const float r, const float l) { - Vector3 v = p; - v.x -= clamp(v.x, -l, l); - float cx = clamp(0.5 + 0.5 * p.x / l, 0.0, 1.0); - float cp = MMAlgos.curve(cx, points_array); - float f = v.length() - r * cp; - return Vector2(f, 0.0); +void MMSdf3dShapeCapsule::_notification(int p_what) { + if (p_what == NOTIFICATION_POSTINITIALIZE) { + init_points_11(); + } } +void MMSdf3dShapeCapsule::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdf3dShapeCapsule::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdf3dShapeCapsule::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - Vector2 Sdf3dShapeCapsule::sdf3d_capsule_z(const Vector3 &p, const float r, const float l) { - Vector3 v = p; - v.z -= clamp(v.z, -l, l); - float cx = clamp(0.5 + 0.5 * p.z / l, 0.0, 1.0); - float cp = MMAlgos.curve(cx, points_array); - float f = v.length() - r * cp; - return Vector2(f, 0.0); + ClassDB::bind_method(D_METHOD("get_axis"), &MMSdf3dShapeCapsule::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &MMSdf3dShapeCapsule::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + ClassDB::bind_method(D_METHOD("get_length"), &MMSdf3dShapeCapsule::get_length); + ClassDB::bind_method(D_METHOD("set_length", "value"), &MMSdf3dShapeCapsule::set_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); + + ClassDB::bind_method(D_METHOD("get_radius"), &MMSdf3dShapeCapsule::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMSdf3dShapeCapsule::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); + + ClassDB::bind_method(D_METHOD("sdf3d_capsule_y", "p", "r", "l"), &MMSdf3dShapeCapsule::sdf3d_capsule_y); + ClassDB::bind_method(D_METHOD("sdf3d_capsule_x", "p", "r", "l"), &MMSdf3dShapeCapsule::sdf3d_capsule_x); + ClassDB::bind_method(D_METHOD("sdf3d_capsule_z", "p", "r", "l"), &MMSdf3dShapeCapsule::sdf3d_capsule_z); + + ClassDB::bind_method(D_METHOD("_curve_changed"), &MMSdf3dShapeCapsule::_curve_changed); } - - //axis; - - int Sdf3dShapeCapsule::get_axis() { - return axis; -} - - - void Sdf3dShapeCapsule::set_axis(const int val) { - axis = val; - emit_changed(); - output.emit_changed(); -} - - //length; - - float Sdf3dShapeCapsule::get_length() { - return length; -} - - - void Sdf3dShapeCapsule::set_length(const float val) { - length = val; - emit_changed(); - output.emit_changed(); -} - - //radius; - - float Sdf3dShapeCapsule::get_radius() { - return radius; -} - - - void Sdf3dShapeCapsule::set_radius(const float val) { - radius = val; - emit_changed(); - output.emit_changed(); -} - - - void Sdf3dShapeCapsule::_curve_changed() { - emit_changed(); - output.emit_changed(); -} - -} - - Sdf3dShapeCapsule::Sdf3dShapeCapsule() { - output; - axis = 1; - length = 0.3; - radius = 0.2; - } - - Sdf3dShapeCapsule::~Sdf3dShapeCapsule() { - } - - - static void Sdf3dShapeCapsule::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeCapsule::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeCapsule::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCapsule::get_axis); - ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeCapsule::set_axis); - ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); - - - ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCapsule::get_length); - ClassDB::bind_method(D_METHOD("set_length", "value"), &Sdf3dShapeCapsule::set_length); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); - - - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCapsule::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeCapsule::set_radius); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); - - - ClassDB::bind_method(D_METHOD("_init"), &Sdf3dShapeCapsule::_init); - ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeCapsule::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeCapsule::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeCapsule::_get_property_value_sdf3d); - ClassDB::bind_method(D_METHOD("sdf3d_capsule_y", "p", "r", "l"), &Sdf3dShapeCapsule::sdf3d_capsule_y); - ClassDB::bind_method(D_METHOD("sdf3d_capsule_x", "p", "r", "l"), &Sdf3dShapeCapsule::sdf3d_capsule_x); - ClassDB::bind_method(D_METHOD("sdf3d_capsule_z", "p", "r", "l"), &Sdf3dShapeCapsule::sdf3d_capsule_z); - ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCapsule::get_axis); - ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeCapsule::set_axis); - ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCapsule::get_length); - ClassDB::bind_method(D_METHOD("set_length", "val"), &Sdf3dShapeCapsule::set_length); - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCapsule::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeCapsule::set_radius); - ClassDB::bind_method(D_METHOD("_curve_changed"), &Sdf3dShapeCapsule::_curve_changed); - - } - - - diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h index 4eec5e890..480dd2114 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_capsule.h @@ -1,61 +1,48 @@ -#ifndef SDF3D_SHAPE_CAPSULE_H -#define SDF3D_SHAPE_CAPSULE_H +#ifndef MM_SDF3D_SHAPE_CAPSULE_H +#define MM_SDF3D_SHAPE_CAPSULE_H +#include "../bases/curve_base.h" +#include "../mm_node_universal_property.h" -class Sdf3dShapeCapsule : public CurveBase { - GDCLASS(Sdf3dShapeCapsule, CurveBase); +class MMSdf3dShapeCapsule : public CurveBase { + GDCLASS(MMSdf3dShapeCapsule, CurveBase); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + int get_axis() const; + void set_axis(const int val); - int get_axis() const; - void set_axis(const int val); + float get_length() const; + void set_length(const float val); - float get_length() const; - void set_length(const float val); + float get_radius() const; + void set_radius(const float val); - float get_radius() const; - void set_radius(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - void _init(); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - Vector2 sdf3d_capsule_y(const Vector3 &p, const float r, const float l); - Vector2 sdf3d_capsule_x(const Vector3 &p, const float r, const float l); - Vector2 sdf3d_capsule_z(const Vector3 &p, const float r, const float l); - int get_axis(); - void set_axis(const int val); - float get_length(); - void set_length(const float val); - float get_radius(); - void set_radius(const float val); - void _curve_changed(); + Vector2 sdf3d_capsule_y(const Vector3 &p, const float r, const float l); + Vector2 sdf3d_capsule_x(const Vector3 &p, const float r, const float l); + Vector2 sdf3d_capsule_z(const Vector3 &p, const float r, const float l); - Sdf3dShapeCapsule(); - ~Sdf3dShapeCapsule(); + void _curve_changed(); - protected: - static void _bind_methods(); + MMSdf3dShapeCapsule(); + ~MMSdf3dShapeCapsule(); - //tool - //export(Resource) - Ref output; - //export(int, "X,Y,Z") - int axis = 1; - //export(float) - float length = 0.3; - //export(float) - float radius = 0.2; - //vec3 $(name_uv)_p = $uv; - //$(name_uv)_p.$axis -= clamp($(name_uv)_p.$axis, -$l, $l); - //return length($(name_uv)_p) - $r * $profile(clamp(0.5+0.5*($uv).$axis/$l, 0.0, 1.0)) - //axis - //length - //radius +protected: + void _notification(int p_what); + + static void _bind_methods(); + + Ref output; + //export(int, "X,Y,Z") + int axis; + float length; + float radius; }; - #endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp index 9978da4ad..47d7cd1fa 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.cpp @@ -1,161 +1,101 @@ #include "sdf3d_shape_cone.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Sdf3dShapeCone::get_output() { - return output; +Ref MMSdf3dShapeCone::get_output() { + return output; } -void Sdf3dShapeCone::set_output(const Ref &val) { -output = val; +void MMSdf3dShapeCone::set_output(const Ref &val) { + output = val; } - -int Sdf3dShapeCone::get_axis() const { - return axis; +int MMSdf3dShapeCone::get_axis() const { + return axis; } -void Sdf3dShapeCone::set_axis(const int val) { -axis = val; +void MMSdf3dShapeCone::set_axis(const int val) { + axis = val; + emit_changed(); + output->do_emit_changed(); } - -float Sdf3dShapeCone::get_angle() const { - return angle; +float MMSdf3dShapeCone::get_angle() const { + return angle; } -void Sdf3dShapeCone::set_angle(const float val) { -angle = val; +void MMSdf3dShapeCone::set_angle(const float val) { + angle = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdf3dShapeCone::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } - - //tool; - //export(Resource) ; - Ref output; - //export(int, "+X,-X,+Y,-Y,+Z,-Z") ; - int axis = 2; - //export(float) ; - float angle = 30; - - void Sdf3dShapeCone::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT); + output->set_slot_name(">>> Output >>>"); + output->set_get_value_from_owner(true); + register_output_property(output); } - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Output >>>"; - output.get_value_from_owner = true; - register_output_property(output); +void MMSdf3dShapeCone::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + + Array arr; + arr.push_back("+X"); + arr.push_back("-X"); + arr.push_back("+Y"); + arr.push_back("-Y"); + arr.push_back("+Z"); + arr.push_back("-Z"); + + mm_graph_node->add_slot_enum("get_axis", "set_axis", "Axis", arr); + mm_graph_node->add_slot_float("get_angle", "set_angle", "Angle", 1); } +Vector2 MMSdf3dShapeCone::_get_property_value_sdf3d(const Vector3 &uv3) { + if (axis == 0) { + return MMAlgos::sdf3d_cone_px(uv3, angle); + } else if (axis == 1) { + return MMAlgos::sdf3d_cone_nx(uv3, angle); + } else if (axis == 2) { + return MMAlgos::sdf3d_cone_py(uv3, angle); + } else if (axis == 3) { + return MMAlgos::sdf3d_cone_ny(uv3, angle); + } else if (axis == 4) { + return MMAlgos::sdf3d_cone_pz(uv3, angle); + } else if (axis == 5) { + return MMAlgos::sdf3d_cone_nz(uv3, angle); + } - void Sdf3dShapeCone::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "+X", "-X", "+Y", "-Y", "+Z", "-Z" ]); - mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 1); + return Vector2(); } - - Vector2 Sdf3dShapeCone::_get_property_value_sdf3d(const Vector3 &uv3) { - - if (axis == 0) { - return MMAlgos.sdf3d_cone_px(uv3, angle); +MMSdf3dShapeCone::MMSdf3dShapeCone() { + axis = 2; + angle = 30; } - - else if (axis == 1) { - return MMAlgos.sdf3d_cone_nx(uv3, angle); +MMSdf3dShapeCone::~MMSdf3dShapeCone() { } +void MMSdf3dShapeCone::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdf3dShapeCone::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdf3dShapeCone::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - else if (axis == 2) { - return MMAlgos.sdf3d_cone_py(uv3, angle); + ClassDB::bind_method(D_METHOD("get_axis"), &MMSdf3dShapeCone::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &MMSdf3dShapeCone::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + ClassDB::bind_method(D_METHOD("get_angle"), &MMSdf3dShapeCone::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &MMSdf3dShapeCone::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); } - - - else if (axis == 3) { - return MMAlgos.sdf3d_cone_ny(uv3, angle); -} - - - else if (axis == 4) { - return MMAlgos.sdf3d_cone_pz(uv3, angle); -} - - - else if (axis == 5) { - return MMAlgos.sdf3d_cone_nz(uv3, angle); -} - - return Vector2(); -} - - //axis; - - int Sdf3dShapeCone::get_axis() { - return axis; -} - - - void Sdf3dShapeCone::set_axis(const int val) { - axis = val; - emit_changed(); - output.emit_changed(); -} - - //angle; - - float Sdf3dShapeCone::get_angle() { - return angle; -} - - - void Sdf3dShapeCone::set_angle(const float val) { - angle = val; - emit_changed(); - output.emit_changed(); -} - -} - - Sdf3dShapeCone::Sdf3dShapeCone() { - output; - axis = 2; - angle = 30; - } - - Sdf3dShapeCone::~Sdf3dShapeCone() { - } - - - static void Sdf3dShapeCone::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeCone::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeCone::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCone::get_axis); - ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeCone::set_axis); - ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); - - - ClassDB::bind_method(D_METHOD("get_angle"), &Sdf3dShapeCone::get_angle); - ClassDB::bind_method(D_METHOD("set_angle", "value"), &Sdf3dShapeCone::set_angle); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeCone::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeCone::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeCone::_get_property_value_sdf3d); - ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCone::get_axis); - ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeCone::set_axis); - ClassDB::bind_method(D_METHOD("get_angle"), &Sdf3dShapeCone::get_angle); - ClassDB::bind_method(D_METHOD("set_angle", "val"), &Sdf3dShapeCone::set_angle); - - } - - - diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h index f71f7aaf8..33cce20bb 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cone.h @@ -1,45 +1,36 @@ -#ifndef SDF3D_SHAPE_CONE_H -#define SDF3D_SHAPE_CONE_H +#ifndef MM_SDF3D_SHAPE_CONE_H +#define MM_SDF3D_SHAPE_CONE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Sdf3dShapeCone : public MMNode { - GDCLASS(Sdf3dShapeCone, MMNode); +class MMSdf3dShapeCone : public MMNode { + GDCLASS(MMSdf3dShapeCone, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + int get_axis() const; + void set_axis(const int val); - int get_axis() const; - void set_axis(const int val); + float get_angle() const; + void set_angle(const float val); - float get_angle() const; - void set_angle(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - int get_axis(); - void set_axis(const int val); - float get_angle(); - void set_angle(const float val); + MMSdf3dShapeCone(); + ~MMSdf3dShapeCone(); - Sdf3dShapeCone(); - ~Sdf3dShapeCone(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(int, "+X,-X,+Y,-Y,+Z,-Z") - int axis = 2; - //export(float) - float angle = 30; - //axis - //angle + Ref output; + //export(int, "+X,-X,+Y,-Y,+Z,-Z") + int axis; + float angle; }; - #endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp index 6e6555e2f..695fe5af6 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.cpp @@ -1,179 +1,112 @@ #include "sdf3d_shape_cylinder.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Sdf3dShapeCylinder::get_output() { - return output; +Ref MMSdf3dShapeCylinder::get_output() { + return output; } -void Sdf3dShapeCylinder::set_output(const Ref &val) { -output = val; +void MMSdf3dShapeCylinder::set_output(const Ref &val) { + output = val; } - -int Sdf3dShapeCylinder::get_axis() const { - return axis; +int MMSdf3dShapeCylinder::get_axis() const { + return axis; } -void Sdf3dShapeCylinder::set_axis(const int val) { -axis = val; +void MMSdf3dShapeCylinder::set_axis(const int val) { + axis = val; + emit_changed(); + output->do_emit_changed(); } - -float Sdf3dShapeCylinder::get_length() const { - return length; +float MMSdf3dShapeCylinder::get_length() const { + return length; } -void Sdf3dShapeCylinder::set_length(const float val) { -length = val; +void MMSdf3dShapeCylinder::set_length(const float val) { + length = val; + emit_changed(); + output->do_emit_changed(); } - -float Sdf3dShapeCylinder::get_radius() const { - return radius; +float MMSdf3dShapeCylinder::get_radius() const { + return radius; } -void Sdf3dShapeCylinder::set_radius(const float val) { -radius = val; +void MMSdf3dShapeCylinder::set_radius(const float val) { + radius = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdf3dShapeCylinder::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } - - //tool; - //export(Resource) ; - Ref output; - //export(int, "X,Y,Z") ; - int axis = 1; - //export(float) ; - float length = 0.25; - //export(float) ; - float radius = 0.25; - - void Sdf3dShapeCylinder::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT); + output->set_slot_name(">>> Output >>>"); + output->set_get_value_from_owner(true); + register_output_property(output); } - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Output >>>"; - output.get_value_from_owner = true; - register_output_property(output); +void MMSdf3dShapeCylinder::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + + Array arr; + arr.push_back("X"); + arr.push_back("Y"); + arr.push_back("Z"); + + mm_graph_node->add_slot_enum("get_axis", "set_axis", "Axis", arr); + mm_graph_node->add_slot_float("get_length", "set_length", "Length", 0.01); + mm_graph_node->add_slot_float("get_radius", "set_radius", "Radius", 0.01); } +Vector2 MMSdf3dShapeCylinder::_get_property_value_sdf3d(const Vector3 &uv3) { + if (axis == 0) { + return MMAlgos::sdf3d_cylinder_x(uv3, radius, length); + } - void Sdf3dShapeCylinder::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_enum("get_axis", "set_axis", "Axis", [ "X", "Y", "Z" ]); - mm_graph_node.add_slot_float("get_length", "set_length", "Length", 0.01); - mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); + else if (axis == 1) { + return MMAlgos::sdf3d_cylinder_y(uv3, radius, length); + } + + else if (axis == 2) { + return MMAlgos::sdf3d_cylinder_z(uv3, radius, length); + } + + return Vector2(); } - - Vector2 Sdf3dShapeCylinder::_get_property_value_sdf3d(const Vector3 &uv3) { - - if (axis == 0) { - return MMAlgos.sdf3d_cylinder_x(uv3, radius, length); +MMSdf3dShapeCylinder::MMSdf3dShapeCylinder() { + axis = 1; + length = 0.25; + radius = 0.25; } - - else if (axis == 1) { - return MMAlgos.sdf3d_cylinder_y(uv3, radius, length); +MMSdf3dShapeCylinder::~MMSdf3dShapeCylinder() { } +void MMSdf3dShapeCylinder::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdf3dShapeCylinder::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdf3dShapeCylinder::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - else if (axis == 2) { - return MMAlgos.sdf3d_cylinder_z(uv3, radius, length); + ClassDB::bind_method(D_METHOD("get_axis"), &MMSdf3dShapeCylinder::get_axis); + ClassDB::bind_method(D_METHOD("set_axis", "value"), &MMSdf3dShapeCylinder::set_axis); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); + + ClassDB::bind_method(D_METHOD("get_length"), &MMSdf3dShapeCylinder::get_length); + ClassDB::bind_method(D_METHOD("set_length", "value"), &MMSdf3dShapeCylinder::set_length); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); + + ClassDB::bind_method(D_METHOD("get_radius"), &MMSdf3dShapeCylinder::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMSdf3dShapeCylinder::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); } - - return Vector2(); -} - - //axis; - - int Sdf3dShapeCylinder::get_axis() { - return axis; -} - - - void Sdf3dShapeCylinder::set_axis(const int val) { - axis = val; - emit_changed(); - output.emit_changed(); -} - - //length; - - float Sdf3dShapeCylinder::get_length() { - return length; -} - - - void Sdf3dShapeCylinder::set_length(const float val) { - length = val; - emit_changed(); - output.emit_changed(); -} - - //radius; - - float Sdf3dShapeCylinder::get_radius() { - return radius; -} - - - void Sdf3dShapeCylinder::set_radius(const float val) { - radius = val; - emit_changed(); - output.emit_changed(); -} - -} - - Sdf3dShapeCylinder::Sdf3dShapeCylinder() { - output; - axis = 1; - length = 0.25; - radius = 0.25; - } - - Sdf3dShapeCylinder::~Sdf3dShapeCylinder() { - } - - - static void Sdf3dShapeCylinder::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeCylinder::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeCylinder::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCylinder::get_axis); - ClassDB::bind_method(D_METHOD("set_axis", "value"), &Sdf3dShapeCylinder::set_axis); - ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); - - - ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCylinder::get_length); - ClassDB::bind_method(D_METHOD("set_length", "value"), &Sdf3dShapeCylinder::set_length); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "length"), "set_length", "get_length"); - - - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCylinder::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeCylinder::set_radius); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeCylinder::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeCylinder::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeCylinder::_get_property_value_sdf3d); - ClassDB::bind_method(D_METHOD("get_axis"), &Sdf3dShapeCylinder::get_axis); - ClassDB::bind_method(D_METHOD("set_axis", "val"), &Sdf3dShapeCylinder::set_axis); - ClassDB::bind_method(D_METHOD("get_length"), &Sdf3dShapeCylinder::get_length); - ClassDB::bind_method(D_METHOD("set_length", "val"), &Sdf3dShapeCylinder::set_length); - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeCylinder::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeCylinder::set_radius); - - } - - - diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h index ca15f38b9..21887a50f 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_cylinder.h @@ -1,53 +1,40 @@ -#ifndef SDF3D_SHAPE_CYLINDER_H -#define SDF3D_SHAPE_CYLINDER_H +#ifndef MM_SDF3D_SHAPE_CYLINDER_H +#define MM_SDF3D_SHAPE_CYLINDER_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Sdf3dShapeCylinder : public MMNode { - GDCLASS(Sdf3dShapeCylinder, MMNode); +class MMSdf3dShapeCylinder : public MMNode { + GDCLASS(MMSdf3dShapeCylinder, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + int get_axis() const; + void set_axis(const int val); - int get_axis() const; - void set_axis(const int val); + float get_length() const; + void set_length(const float val); - float get_length() const; - void set_length(const float val); + float get_radius() const; + void set_radius(const float val); - float get_radius() const; - void set_radius(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - int get_axis(); - void set_axis(const int val); - float get_length(); - void set_length(const float val); - float get_radius(); - void set_radius(const float val); + MMSdf3dShapeCylinder(); + ~MMSdf3dShapeCylinder(); - Sdf3dShapeCylinder(); - ~Sdf3dShapeCylinder(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(int, "X,Y,Z") - int axis = 1; - //export(float) - float length = 0.25; - //export(float) - float radius = 0.25; - //axis - //length - //radius + Ref output; + //export(int, "X,Y,Z") + int axis; + float length; + float radius; }; - #endif diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp index 4fd6f5905..2f86ac939 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.cpp @@ -1,98 +1,63 @@ #include "sdf3d_shape_sphere.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Sdf3dShapeSphere::get_output() { - return output; +Ref MMSdf3dShapeSphere::get_output() { + return output; } -void Sdf3dShapeSphere::set_output(const Ref &val) { -output = val; +void MMSdf3dShapeSphere::set_output(const Ref &val) { + output = val; } - -float Sdf3dShapeSphere::get_radius() const { - return radius; +float MMSdf3dShapeSphere::get_radius() const { + return radius; } -void Sdf3dShapeSphere::set_radius(const float val) { -radius = val; +void MMSdf3dShapeSphere::set_radius(const float val) { + radius = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdf3dShapeSphere::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_FLOAT); + output->set_slot_name(">>> Output >>>"); + output->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref output; - //export(float) ; - float radius = 0.5; - - void Sdf3dShapeSphere::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; + register_output_property(output); } - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Output >>>"; - output.get_value_from_owner = true; - register_output_property(output); +void MMSdf3dShapeSphere::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + mm_graph_node->add_slot_float("get_radius", "set_radius", "Radius", 0.01); } - - void Sdf3dShapeSphere::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_float("get_radius", "set_radius", "Radius", 0.01); +Vector2 MMSdf3dShapeSphere::_get_property_value_sdf3d(const Vector3 &uv3) { + return MMAlgos::sdf3d_sphere(uv3, radius); } - - Vector2 Sdf3dShapeSphere::_get_property_value_sdf3d(const Vector3 &uv3) { - return MMAlgos.sdf3d_sphere(uv3, radius); +MMSdf3dShapeSphere::MMSdf3dShapeSphere() { + radius = 0.5; } - //radius; - - float Sdf3dShapeSphere::get_radius() { - return radius; +MMSdf3dShapeSphere::~MMSdf3dShapeSphere() { } +void MMSdf3dShapeSphere::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdf3dShapeSphere::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdf3dShapeSphere::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - void Sdf3dShapeSphere::set_radius(const float val) { - radius = val; - emit_changed(); - output.emit_changed(); + ClassDB::bind_method(D_METHOD("get_radius"), &MMSdf3dShapeSphere::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "value"), &MMSdf3dShapeSphere::set_radius); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); } - -} - - Sdf3dShapeSphere::Sdf3dShapeSphere() { - output; - radius = 0.5; - } - - Sdf3dShapeSphere::~Sdf3dShapeSphere() { - } - - - static void Sdf3dShapeSphere::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dShapeSphere::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dShapeSphere::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeSphere::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "value"), &Sdf3dShapeSphere::set_radius); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius"), "set_radius", "get_radius"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dShapeSphere::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dShapeSphere::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dShapeSphere::_get_property_value_sdf3d); - ClassDB::bind_method(D_METHOD("get_radius"), &Sdf3dShapeSphere::get_radius); - ClassDB::bind_method(D_METHOD("set_radius", "val"), &Sdf3dShapeSphere::set_radius); - - } - - - diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h index 8991b0721..3c78914ea 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h +++ b/modules/material_maker/nodes/sdf3d/sdf3d_shape_sphere.h @@ -1,37 +1,31 @@ -#ifndef SDF3D_SHAPE_SPHERE_H -#define SDF3D_SHAPE_SPHERE_H +#ifndef MM_SDF3D_SHAPE_SPHERE_H +#define MM_SDF3D_SHAPE_SPHERE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Sdf3dShapeSphere : public MMNode { - GDCLASS(Sdf3dShapeSphere, MMNode); +class MMSdf3dShapeSphere : public MMNode { + GDCLASS(MMSdf3dShapeSphere, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + float get_radius() const; + void set_radius(const float val); - float get_radius() const; - void set_radius(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Vector2 _get_property_value_sdf3d(const Vector3 &uv3); - float get_radius(); - void set_radius(const float val); + MMSdf3dShapeSphere(); + ~MMSdf3dShapeSphere(); - Sdf3dShapeSphere(); - ~Sdf3dShapeSphere(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(float) - float radius = 0.5; - //radius + Ref output; + float radius; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index af410129b..32c430786 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -67,6 +67,11 @@ SOFTWARE. #include "nodes/sdf3d/sdf3d_tf_scale.h" #include "nodes/sdf3d/sdf3d_tf_translate.h" +#include "nodes/sdf3d/sdf3d_shape_box.h" +#include "nodes/sdf3d/sdf3d_shape_capsule.h" +#include "nodes/sdf3d/sdf3d_shape_cone.h" +#include "nodes/sdf3d/sdf3d_shape_cylinder.h" +#include "nodes/sdf3d/sdf3d_shape_sphere.h" #include "nodes/sdf3d/sdf3d_shape_torus.h" static _MMAlgos *_mm_algos_singleton = nullptr; @@ -132,6 +137,16 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("SDF3D - Shape", "MMSdf3dShapeTorus"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF3D - Shape", "MMSdf3dShapeSphere"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF3D - Shape", "MMSdf3dShapeCylinder"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF3D - Shape", "MMSdf3dShapeCone"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF3D - Shape", "MMSdf3dShapeCapsule"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF3D - Shape", "MMSdf3dShapeBox"); _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));