From d339fb1fdb985574aa26a83afe3b844b12942525 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 17 Jun 2022 18:59:08 +0200 Subject: [PATCH] Cleaned up SDF show, rhombus, and transforms. --- modules/material_maker/SCsub | 8 + modules/material_maker/config.py | 8 + .../nodes/sdf2d/sd_shape_rhombus.cpp | 150 +++++-------- .../nodes/sdf2d/sd_shape_rhombus.h | 56 ++--- .../material_maker/nodes/sdf2d/sd_show.cpp | 197 ++++++------------ modules/material_maker/nodes/sdf2d/sd_show.h | 64 +++--- .../nodes/sdf2d/sd_tf_rotate.cpp | 117 ++++------- .../material_maker/nodes/sdf2d/sd_tf_rotate.h | 42 ++-- .../nodes/sdf2d/sd_tf_scale.cpp | 117 ++++------- .../material_maker/nodes/sdf2d/sd_tf_scale.h | 46 ++-- .../nodes/sdf2d/sd_tf_translate.cpp | 115 ++++------ .../nodes/sdf2d/sd_tf_translate.h | 46 ++-- modules/material_maker/register_types.cpp | 21 ++ 13 files changed, 385 insertions(+), 602 deletions(-) diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index f4f2a065e..a351ca017 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -92,6 +92,14 @@ sources = [ "nodes/sdf3d/sdf3d_op_circle_repeat.cpp", "nodes/sdf3d/sdf3d_op_bool.cpp", + "nodes/sdf2d/sd_shape_rhombus.cpp", + + "nodes/sdf2d/sd_tf_translate.cpp", + "nodes/sdf2d/sd_tf_scale.cpp", + "nodes/sdf2d/sd_tf_rotate.cpp", + + "nodes/sdf2d/sd_show.cpp", + ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index ff1578862..dca52dd1e 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -61,6 +61,14 @@ def get_doc_classes(): "MMSdf3dOpElongation", "MMSdf3dOpCircleRepeat", "MMSdf3dOpBool", + + "SSSdShow", + + "MMSdTfTranslate", + "MMSdTfScale", + "MMSdTfRotate", + + "MMSdShapeRhombus", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp index c02951dec..8aa9e3a29 100644 --- a/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp +++ b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.cpp @@ -1,131 +1,79 @@ #include "sd_shape_rhombus.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref SdShapeRhombus::get_output() { - return output; +Ref MMSdShapeRhombus::get_output() { + return output; } -void SdShapeRhombus::set_output(const Ref &val) { -output = val; +void MMSdShapeRhombus::set_output(const Ref &val) { + output = val; } - -Vector2 SdShapeRhombus::get_center() { - return center; +Vector2 MMSdShapeRhombus::get_center() { + return center; } -void SdShapeRhombus::set_center(const Vector2 &val) { -center = val; +void MMSdShapeRhombus::set_center(const Vector2 &val) { + center = val; + emit_changed(); + output->do_emit_changed(); } - -Vector2 SdShapeRhombus::get_size() { - return size; +Vector2 MMSdShapeRhombus::get_size() { + return size; } -void SdShapeRhombus::set_size(const Vector2 &val) { -size = val; +void MMSdShapeRhombus::set_size(const Vector2 &val) { + size = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdShapeRhombus::_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; - //export(Resource) ; - Ref output; - //export(Vector2) ; - Vector2 center = Vector2(0, 0); - //export(Vector2) ; - Vector2 size = Vector2(0.3, 0.2); - - void SdShapeRhombus::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + 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 MMSdShapeRhombus::_register_methods(MMGraphNode *mm_graph_node) { + 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); } - - void SdShapeRhombus::_register_methods(const Variant &mm_graph_node) { - 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); +Variant MMSdShapeRhombus::_get_property_value(const Vector2 &uv) { + return MMAlgos::sdf_rhombus(uv, center, size); } - - float SdShapeRhombus::_get_property_value(const Vector2 &uv) { - return MMAlgos.sdf_rhombus(uv, center, size); +MMSdShapeRhombus::MMSdShapeRhombus() { + center = Vector2(0, 0); + size = Vector2(0.3, 0.2); } - //center; - - Vector2 SdShapeRhombus::get_center() { - return center; +MMSdShapeRhombus::~MMSdShapeRhombus() { } +void MMSdShapeRhombus::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdShapeRhombus::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdShapeRhombus::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - void SdShapeRhombus::set_center(const Vector2 &val) { - center = val; - emit_changed(); - output.emit_changed(); + ClassDB::bind_method(D_METHOD("get_center"), &MMSdShapeRhombus::get_center); + ClassDB::bind_method(D_METHOD("set_center", "value"), &MMSdShapeRhombus::set_center); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); + + ClassDB::bind_method(D_METHOD("get_size"), &MMSdShapeRhombus::get_size); + ClassDB::bind_method(D_METHOD("set_size", "value"), &MMSdShapeRhombus::set_size); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); } - - //size; - - Vector2 SdShapeRhombus::get_size() { - return size; -} - - - void SdShapeRhombus::set_size(const Vector2 &val) { - size = val; - emit_changed(); - output.emit_changed(); -} - -} - - SdShapeRhombus::SdShapeRhombus() { - output; - center = Vector2(0, 0); - size = Vector2(0.3, 0.2); - } - - SdShapeRhombus::~SdShapeRhombus() { - } - - - static void SdShapeRhombus::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &SdShapeRhombus::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &SdShapeRhombus::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_center"), &SdShapeRhombus::get_center); - ClassDB::bind_method(D_METHOD("set_center", "value"), &SdShapeRhombus::set_center); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "center"), "set_center", "get_center"); - - - ClassDB::bind_method(D_METHOD("get_size"), &SdShapeRhombus::get_size); - ClassDB::bind_method(D_METHOD("set_size", "value"), &SdShapeRhombus::set_size); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &SdShapeRhombus::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShapeRhombus::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdShapeRhombus::_get_property_value); - ClassDB::bind_method(D_METHOD("get_center"), &SdShapeRhombus::get_center); - ClassDB::bind_method(D_METHOD("set_center", "val"), &SdShapeRhombus::set_center); - ClassDB::bind_method(D_METHOD("get_size"), &SdShapeRhombus::get_size); - ClassDB::bind_method(D_METHOD("set_size", "val"), &SdShapeRhombus::set_size); - - } - - - diff --git a/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h index bbf709aff..a1b5cfe5f 100644 --- a/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h +++ b/modules/material_maker/nodes/sdf2d/sd_shape_rhombus.h @@ -1,45 +1,35 @@ -#ifndef SD_SHAPE_RHOMBUS_H -#define SD_SHAPE_RHOMBUS_H +#ifndef MM_SD_SHAPE_RHOMBUS_H +#define MM_SD_SHAPE_RHOMBUS_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class SdShapeRhombus : public MMNode { - GDCLASS(SdShapeRhombus, MMNode); +class MMSdShapeRhombus : public MMNode { + GDCLASS(MMSdShapeRhombus, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + Vector2 get_center(); + void set_center(const Vector2 &val); - Vector2 get_center(); - void set_center(const Vector2 &val); + Vector2 get_size(); + void set_size(const Vector2 &val); - Vector2 get_size(); - void set_size(const Vector2 &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Variant _get_property_value(const Vector2 &uv); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - 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); + MMSdShapeRhombus(); + ~MMSdShapeRhombus(); - SdShapeRhombus(); - ~SdShapeRhombus(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(Vector2) - Vector2 center = Vector2(0, 0); - //export(Vector2) - Vector2 size = Vector2(0.3, 0.2); - //center - //size + Ref output; + Vector2 center; + Vector2 size; }; - #endif diff --git a/modules/material_maker/nodes/sdf2d/sd_show.cpp b/modules/material_maker/nodes/sdf2d/sd_show.cpp index 24c87954c..52cb53752 100644 --- a/modules/material_maker/nodes/sdf2d/sd_show.cpp +++ b/modules/material_maker/nodes/sdf2d/sd_show.cpp @@ -1,166 +1,107 @@ #include "sd_show.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref SdShow::get_image() { - return image; +Ref SSSdShow::get_image() { + return image; } -void SdShow::set_image(const Ref &val) { -image = val; +void SSSdShow::set_image(const Ref &val) { + image = val; } - -Ref SdShow::get_input() { - return input; +Ref SSSdShow::get_input() { + return input; } -void SdShow::set_input(const Ref &val) { -input = val; +void SSSdShow::set_input(const Ref &val) { + input = val; } - -float SdShow::get_bevel() const { - return bevel; +float SSSdShow::get_bevel() const { + return bevel; } -void SdShow::set_bevel(const float val) { -bevel = val; +void SSSdShow::set_bevel(const float val) { + bevel = val; + set_dirty(true); } - -float SdShow::get_base() const { - return base; +float SSSdShow::get_base() const { + return base; } -void SdShow::set_base(const float val) { -base = val; +void SSSdShow::set_base(const float val) { + base = val; + set_dirty(true); } +void SSSdShow::_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 image; - //export(Resource) ; - Ref input; - //export(float) ; - float bevel = 0; - //export(float) ; - float base = 0; + if (!input.is_valid()) { + input.instance(); + input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + } - void SdShow::_init_properties() { + //for some reason this doesn't work, todo check; + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + input->set_slot_name("Input"); - if (!image) { - image = MMNodeUniversalProperty.new(); - image.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_IMAGE; + register_output_property(image); + register_input_property(input); } - image.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_IMAGE; - - if (!input) { - input = MMNodeUniversalProperty.new(); - input.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; +void SSSdShow::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_texture_universal(image); + mm_graph_node->add_slot_label_universal(input); + mm_graph_node->add_slot_float("get_bevel", "set_bevel", "Bevel", 0.01); + mm_graph_node->add_slot_float("get_base", "set_base", "Base", 0.01); } - //for some reason this doesn't work, todo check; - // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - input.slot_name = "Input"; - register_output_property(image); - register_input_property(input); +void SSSdShow::_render(const Ref &material) { + Ref img = render_image(material); + image->set_value(img); } - - void SdShow::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_texture_universal(image); - mm_graph_node.add_slot_label_universal(input); - mm_graph_node.add_slot_float("get_bevel", "set_bevel", "Bevel", 0.01); - mm_graph_node.add_slot_float("get_base", "set_base", "Base", 0.01); +Color SSSdShow::_get_value_for(const Vector2 &uv, const int pseed) { + float f = input->get_value(uv); + //clamp($base-$in($uv)/max($bevel, 0.00001), 0.0, 1.0); + float cf = CLAMP(base - f / MAX(bevel, 0.00001), 0.0, 1.0); + return Color(cf, cf, cf, 1); } - - void SdShow::_render(const Variant &material) { - Ref img = render_image(material); - image.set_value(img); +SSSdShow::SSSdShow() { + bevel = 0; + base = 0; } - - Color SdShow::_get_value_for(const Vector2 &uv, const int pseed) { - float f = input.get_value(uv); - //clamp($base-$in($uv)/max($bevel, 0.00001), 0.0, 1.0); - float cf = clamp(base - f / max(bevel, 0.00001), 0.0, 1.0); - return Color(cf, cf, cf, 1); +SSSdShow::~SSSdShow() { } - //bevel; +void SSSdShow::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_image"), &SSSdShow::get_image); + ClassDB::bind_method(D_METHOD("set_image", "value"), &SSSdShow::set_image); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_image", "get_image"); - float SdShow::get_bevel() { - return bevel; + ClassDB::bind_method(D_METHOD("get_input"), &SSSdShow::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &SSSdShow::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_input", "get_input"); + + ClassDB::bind_method(D_METHOD("get_bevel"), &SSSdShow::get_bevel); + ClassDB::bind_method(D_METHOD("set_bevel", "value"), &SSSdShow::set_bevel); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "bevel"), "set_bevel", "get_bevel"); + + ClassDB::bind_method(D_METHOD("get_base"), &SSSdShow::get_base); + ClassDB::bind_method(D_METHOD("set_base", "value"), &SSSdShow::set_base); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base"); } - - - void SdShow::set_bevel(const float val) { - bevel = val; - set_dirty(true); -} - - //base; - - float SdShow::get_base() { - return base; -} - - - void SdShow::set_base(const float val) { - base = val; - set_dirty(true); -} - -} - - SdShow::SdShow() { - image; - input; - bevel = 0; - base = 0; - } - - SdShow::~SdShow() { - } - - - static void SdShow::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_image"), &SdShow::get_image); - ClassDB::bind_method(D_METHOD("set_image", "value"), &SdShow::set_image); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_image", "get_image"); - - - ClassDB::bind_method(D_METHOD("get_input"), &SdShow::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &SdShow::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_bevel"), &SdShow::get_bevel); - ClassDB::bind_method(D_METHOD("set_bevel", "value"), &SdShow::set_bevel); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "bevel"), "set_bevel", "get_bevel"); - - - ClassDB::bind_method(D_METHOD("get_base"), &SdShow::get_base); - ClassDB::bind_method(D_METHOD("set_base", "value"), &SdShow::set_base); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &SdShow::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdShow::_register_methods); - ClassDB::bind_method(D_METHOD("_render", "material"), &SdShow::_render); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &SdShow::_get_value_for); - ClassDB::bind_method(D_METHOD("get_bevel"), &SdShow::get_bevel); - ClassDB::bind_method(D_METHOD("set_bevel", "val"), &SdShow::set_bevel); - ClassDB::bind_method(D_METHOD("get_base"), &SdShow::get_base); - ClassDB::bind_method(D_METHOD("set_base", "val"), &SdShow::set_base); - - } - - - diff --git a/modules/material_maker/nodes/sdf2d/sd_show.h b/modules/material_maker/nodes/sdf2d/sd_show.h index 7f9427b2d..412ee341a 100644 --- a/modules/material_maker/nodes/sdf2d/sd_show.h +++ b/modules/material_maker/nodes/sdf2d/sd_show.h @@ -1,51 +1,41 @@ -#ifndef SD_SHOW_H -#define SD_SHOW_H +#ifndef MM_SD_SHOW_H +#define MM_SD_SHOW_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class SdShow : public MMNode { - GDCLASS(SdShow, MMNode); +class SSSdShow : public MMNode { + GDCLASS(SSSdShow, MMNode); - public: +public: + Ref get_image(); + void set_image(const Ref &val); - Ref get_image(); - void set_image(const Ref &val); + Ref get_input(); + void set_input(const Ref &val); - Ref get_input(); - void set_input(const Ref &val); + float get_bevel() const; + void set_bevel(const float val); - float get_bevel() const; - void set_bevel(const float val); + float get_base() const; + void set_base(const float val); - float get_base() const; - void set_base(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + void _render(const Ref &material); - 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); - float get_bevel(); - void set_bevel(const float val); - float get_base(); - void set_base(const float val); + Color _get_value_for(const Vector2 &uv, const int pseed); - SdShow(); - ~SdShow(); + SSSdShow(); + ~SSSdShow(); - protected: - static void _bind_methods(); +protected: + static void _bind_methods(); - //tool - //export(Resource) - Ref image; - //export(Resource) - Ref input; - //export(float) - float bevel = 0; - //export(float) - float base = 0; - //bevel - //base + Ref image; + Ref input; + float bevel; + float base; }; - #endif diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp index ce6ae84d9..40e7fe25c 100644 --- a/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp +++ b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.cpp @@ -1,102 +1,67 @@ #include "sd_tf_rotate.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref SdTfRotate::get_output() { - return output; +Ref MMSdTfRotate::get_output() { + return output; } -void SdTfRotate::set_output(const Ref &val) { -output = val; +void MMSdTfRotate::set_output(const Ref &val) { + output = val; } - -float SdTfRotate::get_angle() const { - return angle; +float MMSdTfRotate::get_angle() const { + return angle; } -void SdTfRotate::set_angle(const float val) { -angle = val; +void MMSdTfRotate::set_angle(const float val) { + angle = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdTfRotate::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + } + output->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output->set_slot_name(">>> Apply >>>"); + output->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref output; - //export(float) ; - float angle = 0; - - void SdTfRotate::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + register_input_property(output); + register_output_property(output); } - output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Apply >>>"; - output.get_value_from_owner = true; - register_input_property(output); - register_output_property(output); +void MMSdTfRotate::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + mm_graph_node->add_slot_float("get_angle", "set_angle", "Angle", 1); } - - void SdTfRotate::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_float("get_angle", "set_angle", "Angle", 1); +Variant MMSdTfRotate::_get_property_value(const Vector2 &uv) { + //$in(sdf2d_rotate($uv, $a*0.01745329251))",; + return output->get_value(MMAlgos::sdf2d_rotate(uv, angle * 0.01745329251), true); } - - void SdTfRotate::_get_property_value(const Vector2 &uv) { - //$in(sdf2d_rotate($uv, $a*0.01745329251))",; - return output.get_value(MMAlgos.sdf2d_rotate(uv, angle * 0.01745329251), true); +MMSdTfRotate::MMSdTfRotate() { + angle = 0; } - //angle; - - float SdTfRotate::get_angle() { - return angle; +MMSdTfRotate::~MMSdTfRotate() { } +void MMSdTfRotate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdTfRotate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdTfRotate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - void SdTfRotate::set_angle(const float val) { - angle = val; - emit_changed(); - output.emit_changed(); + ClassDB::bind_method(D_METHOD("get_angle"), &MMSdTfRotate::get_angle); + ClassDB::bind_method(D_METHOD("set_angle", "value"), &MMSdTfRotate::set_angle); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); } - -} - - SdTfRotate::SdTfRotate() { - output; - angle = 0; - } - - SdTfRotate::~SdTfRotate() { - } - - - static void SdTfRotate::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &SdTfRotate::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &SdTfRotate::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_angle"), &SdTfRotate::get_angle); - ClassDB::bind_method(D_METHOD("set_angle", "value"), &SdTfRotate::set_angle); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle"), "set_angle", "get_angle"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &SdTfRotate::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdTfRotate::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdTfRotate::_get_property_value); - ClassDB::bind_method(D_METHOD("get_angle"), &SdTfRotate::get_angle); - ClassDB::bind_method(D_METHOD("set_angle", "val"), &SdTfRotate::set_angle); - - } - - - diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h index c05d21ae7..d18533c14 100644 --- a/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h +++ b/modules/material_maker/nodes/sdf2d/sd_tf_rotate.h @@ -1,37 +1,31 @@ #ifndef SD_TF_ROTATE_H #define SD_TF_ROTATE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class SdTfRotate : public MMNode { - GDCLASS(SdTfRotate, MMNode); +class MMSdTfRotate : public MMNode { + GDCLASS(MMSdTfRotate, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &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); + Variant _get_property_value(const Vector2 &uv); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _get_property_value(const Vector2 &uv); - float get_angle(); - void set_angle(const float val); + MMSdTfRotate(); + ~MMSdTfRotate(); - SdTfRotate(); - ~SdTfRotate(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(float) - float angle = 0; - //angle + Ref output; + float angle; }; - #endif diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp b/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp index dce9a0240..63e679f1a 100644 --- a/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp +++ b/modules/material_maker/nodes/sdf2d/sd_tf_scale.cpp @@ -1,102 +1,67 @@ #include "sd_tf_scale.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref SdTfScale::get_output() { - return output; +Ref MMSdTfScale::get_output() { + return output; } -void SdTfScale::set_output(const Ref &val) { -output = val; +void MMSdTfScale::set_output(const Ref &val) { + output = val; } - -float SdTfScale::get_scale() const { - return scale; +float MMSdTfScale::get_scale() const { + return scale; } -void SdTfScale::set_scale(const float val) { -scale = val; +void MMSdTfScale::set_scale(const float val) { + scale = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdTfScale::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + } + output->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output->set_slot_name(">>> Apply >>>"); + output->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref output; - //export(float) ; - float scale = 1; - - void SdTfScale::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + register_input_property(output); + register_output_property(output); } - output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Apply >>>"; - output.get_value_from_owner = true; - register_input_property(output); - register_output_property(output); +void MMSdTfScale::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + mm_graph_node->add_slot_float("get_scale", "set_scale", "Scale", 0.01); } - - void SdTfScale::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_float("get_scale", "set_scale", "Scale", 0.01); +Variant MMSdTfScale::_get_property_value(const Vector2 &uv) { + //$in(($uv-vec2(0.5))/$s+vec2(0.5))*$s; + return output->get_value(((uv - Vector2(0.5, 0.5)) / scale + Vector2(0.5, 0.5)), true); } - - void SdTfScale::_get_property_value(const Vector2 &uv) { - //$in(($uv-vec2(0.5))/$s+vec2(0.5))*$s; - return output.get_value(((uv - Vector2(0.5, 0.5)) / scale + Vector2(0.5, 0.5)), true); +MMSdTfScale::MMSdTfScale() { + scale = 1; } - //scale; - - float SdTfScale::get_scale() { - return scale; +MMSdTfScale::~MMSdTfScale() { } +void MMSdTfScale::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdTfScale::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdTfScale::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - void SdTfScale::set_scale(const float val) { - scale = val; - emit_changed(); - output.emit_changed(); + ClassDB::bind_method(D_METHOD("get_scale"), &MMSdTfScale::get_scale); + ClassDB::bind_method(D_METHOD("set_scale", "value"), &MMSdTfScale::set_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale"), "set_scale", "get_scale"); } - -} - - SdTfScale::SdTfScale() { - output; - scale = 1; - } - - SdTfScale::~SdTfScale() { - } - - - static void SdTfScale::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &SdTfScale::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &SdTfScale::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_scale"), &SdTfScale::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "value"), &SdTfScale::set_scale); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale"), "set_scale", "get_scale"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &SdTfScale::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdTfScale::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdTfScale::_get_property_value); - ClassDB::bind_method(D_METHOD("get_scale"), &SdTfScale::get_scale); - ClassDB::bind_method(D_METHOD("set_scale", "val"), &SdTfScale::set_scale); - - } - - - diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_scale.h b/modules/material_maker/nodes/sdf2d/sd_tf_scale.h index d49c45d75..66f724778 100644 --- a/modules/material_maker/nodes/sdf2d/sd_tf_scale.h +++ b/modules/material_maker/nodes/sdf2d/sd_tf_scale.h @@ -1,37 +1,31 @@ -#ifndef SD_TF_SCALE_H -#define SD_TF_SCALE_H +#ifndef MM_SD_TF_SCALE_H +#define MM_SD_TF_SCALE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class SdTfScale : public MMNode { - GDCLASS(SdTfScale, MMNode); +class MMSdTfScale : public MMNode { + GDCLASS(MMSdTfScale, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + float get_scale() const; + void set_scale(const float val); - float get_scale() const; - void set_scale(const float val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Variant _get_property_value(const Vector2 &uv); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _get_property_value(const Vector2 &uv); - float get_scale(); - void set_scale(const float val); + MMSdTfScale(); + ~MMSdTfScale(); - SdTfScale(); - ~SdTfScale(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(float) - float scale = 1; - //scale + Ref output; + float scale; }; - #endif diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp b/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp index f57feab14..5936caf7e 100644 --- a/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp +++ b/modules/material_maker/nodes/sdf2d/sd_tf_translate.cpp @@ -1,101 +1,66 @@ #include "sd_tf_translate.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref SdTfTranslate::get_output() { - return output; +Ref MMSdTfTranslate::get_output() { + return output; } -void SdTfTranslate::set_output(const Ref &val) { -output = val; +void MMSdTfTranslate::set_output(const Ref &val) { + output = val; } - -Vector2 SdTfTranslate::get_translation() { - return translation; +Vector2 MMSdTfTranslate::get_translation() { + return translation; } -void SdTfTranslate::set_translation(const Vector2 &val) { -translation = val; +void MMSdTfTranslate::set_translation(const Vector2 &val) { + translation = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdTfTranslate::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + } + output->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + output->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; + output->set_slot_name(">>> Apply >>>"); + output->set_get_value_from_owner(true); - //tool; - //export(Resource) ; - Ref output; - //export(Vector2) ; - Vector2 translation = Vector2(0, 0); - - void SdTfTranslate::_init_properties() { - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; + register_input_property(output); + register_output_property(output); } - output.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - //output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Apply >>>"; - output.get_value_from_owner = true; - register_input_property(output); - register_output_property(output); +void MMSdTfTranslate::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(output); + mm_graph_node->add_slot_vector2("get_translation", "set_translation", "Translation", 0.01); } - - void SdTfTranslate::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_vector2("get_translation", "set_translation", "Translation", 0.01); +Variant MMSdTfTranslate::_get_property_value(const Vector2 &uv) { + return output->get_value(uv - translation, true); } - - void SdTfTranslate::_get_property_value(const Vector2 &uv) { - return output.get_value(uv - translation, true); +MMSdTfTranslate::MMSdTfTranslate() { + translation = Vector2(0, 0); } - //a; - - Vector2 SdTfTranslate::get_translation() { - return translation; +MMSdTfTranslate::~MMSdTfTranslate() { } +void MMSdTfTranslate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_output"), &MMSdTfTranslate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdTfTranslate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); - void SdTfTranslate::set_translation(const Vector2 &val) { - translation = val; - emit_changed(); - output.emit_changed(); + ClassDB::bind_method(D_METHOD("get_translation"), &MMSdTfTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "value"), &MMSdTfTranslate::set_translation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "translation"), "set_translation", "get_translation"); } - -} - - SdTfTranslate::SdTfTranslate() { - output; - translation = Vector2(0, 0); - } - - SdTfTranslate::~SdTfTranslate() { - } - - - static void SdTfTranslate::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_output"), &SdTfTranslate::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &SdTfTranslate::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_translation"), &SdTfTranslate::get_translation); - ClassDB::bind_method(D_METHOD("set_translation", "value"), &SdTfTranslate::set_translation); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "translation"), "set_translation", "get_translation"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &SdTfTranslate::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &SdTfTranslate::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value", "uv"), &SdTfTranslate::_get_property_value); - ClassDB::bind_method(D_METHOD("get_translation"), &SdTfTranslate::get_translation); - ClassDB::bind_method(D_METHOD("set_translation", "val"), &SdTfTranslate::set_translation); - - } - - - diff --git a/modules/material_maker/nodes/sdf2d/sd_tf_translate.h b/modules/material_maker/nodes/sdf2d/sd_tf_translate.h index 8df50192e..88c51acef 100644 --- a/modules/material_maker/nodes/sdf2d/sd_tf_translate.h +++ b/modules/material_maker/nodes/sdf2d/sd_tf_translate.h @@ -1,37 +1,31 @@ -#ifndef SD_TF_TRANSLATE_H -#define SD_TF_TRANSLATE_H +#ifndef MM_SD_TF_TRANSLATE_H +#define MM_SD_TF_TRANSLATE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class SdTfTranslate : public MMNode { - GDCLASS(SdTfTranslate, MMNode); +class MMSdTfTranslate : public MMNode { + GDCLASS(MMSdTfTranslate, MMNode); - public: +public: + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + Vector2 get_translation(); + void set_translation(const Vector2 &val); - Vector2 get_translation(); - void set_translation(const Vector2 &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Variant _get_property_value(const Vector2 &uv); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - void _get_property_value(const Vector2 &uv); - Vector2 get_translation(); - void set_translation(const Vector2 &val); + MMSdTfTranslate(); + ~MMSdTfTranslate(); - SdTfTranslate(); - ~SdTfTranslate(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref output; - //export(Vector2) - Vector2 translation = Vector2(0, 0); - //a + Ref output; + Vector2 translation; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index b52d97d5f..0594f1968 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -84,6 +84,14 @@ SOFTWARE. #include "nodes/sdf3d/sdf3d_op_rounded.h" #include "nodes/sdf3d/sdf3d_op_smooth_bool.h" +#include "nodes/sdf2d/sd_shape_rhombus.h" + +#include "nodes/sdf2d/sd_tf_rotate.h" +#include "nodes/sdf2d/sd_tf_scale.h" +#include "nodes/sdf2d/sd_tf_translate.h" + +#include "nodes/sdf2d/sd_show.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -177,6 +185,19 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("SDF3D - OP", "MMSdf3dOpBool"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF2D", "SSSdShow"); + + ClassDB::register_class(); + MMAlgos::register_node_class("SDF2D - Shape", "MMSdShapeRhombus"); + + ClassDB::register_class(); + MMAlgos::register_node_class("SDF2D - TF", "MMSdTfTranslate"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF2D - TF", "MMSdTfScale"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF2D - TF", "MMSdTfRotate"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));