diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index 927d6c10f..83a4cdfc1 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -51,6 +51,7 @@ sources = [ "editor/widgets/polygon_edit/polygon_view.cpp", "nodes/uniform/uniform.cpp", + "nodes/uniform/greyscale_uniform.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 4437f4ce7..557a90b24 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -21,6 +21,7 @@ def get_doc_classes(): "MatMakerGDEditor", "MMUniform", + "GreyscaleUniform ", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/uniform/greyscale_uniform.cpp b/modules/material_maker/nodes/uniform/greyscale_uniform.cpp index 3f3e8c9d9..f2cde33f0 100644 --- a/modules/material_maker/nodes/uniform/greyscale_uniform.cpp +++ b/modules/material_maker/nodes/uniform/greyscale_uniform.cpp @@ -1,68 +1,50 @@ #include "greyscale_uniform.h" +#include "../../editor/mm_graph_node.h" -Ref GreyscaleUniform::get_uniform() { - return uniform; +Ref GreyscaleUniform::get_uniform() { + return uniform; } -void GreyscaleUniform::set_uniform(const Ref &val) { -uniform = val; +void GreyscaleUniform::set_uniform(const Ref &val) { + uniform = val; } +void GreyscaleUniform::_init_properties() { + if (!uniform.is_valid()) { + uniform.instance(); + uniform->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_FLOAT); + uniform->set_default_value(0.5); + uniform->set_slot_name("Value (Color)"); + uniform->set_value_step(0.01); + uniform->set_value_range(Vector2(0, 1)); + } - - //tool; - //export(Resource) ; - Ref uniform; - - void GreyscaleUniform::_init_properties() { - - if (!uniform) { - uniform = MMNodeUniversalProperty.new(); - uniform.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_FLOAT; - uniform.set_default_value(0.5); - uniform.slot_name = "Value (Color)"; - uniform.value_step = 0.01; - uniform.value_range = Vector2(0, 1); + uniform->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_COLOR); + register_output_property(uniform); } - uniform.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; - register_output_property(uniform); +void GreyscaleUniform::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_float_universal(uniform); } - - void GreyscaleUniform::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_float_universal(uniform); +Color GreyscaleUniform::_get_value_for(const Vector2 &uv, const int pseed) { + float f = uniform->get_value(uv); + return Color(f, f, f, 1); } - - Color GreyscaleUniform::_get_value_for(const Vector2 &uv, const int pseed) { - float f = uniform.get_value(uv); - return Color(f, f, f, 1); +GreyscaleUniform::GreyscaleUniform() { } +GreyscaleUniform::~GreyscaleUniform() { } - GreyscaleUniform::GreyscaleUniform() { - uniform; - } - - GreyscaleUniform::~GreyscaleUniform() { - } - - - static void GreyscaleUniform::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_uniform"), &GreyscaleUniform::get_uniform); - ClassDB::bind_method(D_METHOD("set_uniform", "value"), &GreyscaleUniform::set_uniform); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "uniform", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_uniform", "get_uniform"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &GreyscaleUniform::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &GreyscaleUniform::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &GreyscaleUniform::_get_value_for); - - } - - +void GreyscaleUniform::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_uniform"), &GreyscaleUniform::get_uniform); + ClassDB::bind_method(D_METHOD("set_uniform", "value"), &GreyscaleUniform::set_uniform); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "uniform", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_uniform", "get_uniform"); + ClassDB::bind_method(D_METHOD("_init_properties"), &GreyscaleUniform::_init_properties); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &GreyscaleUniform::_get_value_for); +} diff --git a/modules/material_maker/nodes/uniform/greyscale_uniform.h b/modules/material_maker/nodes/uniform/greyscale_uniform.h index fc0fe8586..87e53dcbd 100644 --- a/modules/material_maker/nodes/uniform/greyscale_uniform.h +++ b/modules/material_maker/nodes/uniform/greyscale_uniform.h @@ -1,29 +1,27 @@ #ifndef GREYSCALE_UNIFORM_H #define GREYSCALE_UNIFORM_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" class GreyscaleUniform : public MMNode { - GDCLASS(GreyscaleUniform, MMNode); + GDCLASS(GreyscaleUniform, MMNode); - public: +public: + Ref get_uniform(); + void set_uniform(const Ref &val); - Ref get_uniform(); - void set_uniform(const Ref &val); + void _init_properties(); + void _register_methods(MMGraphNode *mm_graph_node); + Color _get_value_for(const Vector2 &uv, const int pseed); - void _init_properties(); - void _register_methods(const Variant &mm_graph_node); - Color _get_value_for(const Vector2 &uv, const int pseed); + GreyscaleUniform(); + ~GreyscaleUniform(); - GreyscaleUniform(); - ~GreyscaleUniform(); +protected: + static void _bind_methods(); - protected: - static void _bind_methods(); - - //tool - //export(Resource) - Ref uniform; + Ref uniform; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index 23b2c7373..11e8f0960 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -42,6 +42,7 @@ SOFTWARE. #include "editor_plugin.h" #endif +#include "nodes/uniform/greyscale_uniform.h" #include "nodes/uniform/uniform.h" static _MMAlgos *_mm_algos_singleton = nullptr; @@ -61,7 +62,9 @@ void register_material_maker_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); MMAlgos::register_node_class("Uniform", "MMUniform"); + MMAlgos::register_node_class("Uniform", "GreyscaleUniform"); _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));