diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index 7c3e907ed..927d6c10f 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -49,6 +49,8 @@ sources = [ "editor/widgets/polygon_edit/polygon_edit.cpp", "editor/widgets/polygon_edit/polygon_editor.cpp", "editor/widgets/polygon_edit/polygon_view.cpp", + + "nodes/uniform/uniform.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index 8a3016455..4437f4ce7 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -19,6 +19,8 @@ def get_doc_classes(): "MMMaterial", "MMGraphNode", "MatMakerGDEditor", + + "MMUniform", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/uniform/uniform.cpp b/modules/material_maker/nodes/uniform/uniform.cpp index 673ea2938..134b551b5 100644 --- a/modules/material_maker/nodes/uniform/uniform.cpp +++ b/modules/material_maker/nodes/uniform/uniform.cpp @@ -1,64 +1,47 @@ #include "uniform.h" +#include "../../editor/mm_graph_node.h" -Ref Uniform::get_uniform() { - return uniform; +Ref MMUniform::get_uniform() { + return uniform; } -void Uniform::set_uniform(const Ref &val) { -uniform = val; +void MMUniform::set_uniform(const Ref &val) { + uniform = val; } +void MMUniform::_init_properties() { + if (!uniform.is_valid()) { + uniform.instance(); + uniform->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_COLOR); + uniform->set_default_value(Color(1, 1, 1, 1)); + } - - //tool; - //export(Resource) ; - Ref uniform; - - void Uniform::_init_properties() { - - if (!uniform) { - uniform = MMNodeUniversalProperty.new(); - uniform.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_COLOR; - uniform.set_default_value(Color(1, 1, 1, 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 MMUniform::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_color_universal(uniform); } - - void Uniform::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_color_universal(uniform); +Color MMUniform::_get_value_for(const Vector2 &uv, const int pseed) { + return uniform->get_value(uv); } - - Color Uniform::_get_value_for(const Vector2 &uv, const int pseed) { - return uniform.get_value(uv); +MMUniform::MMUniform() { } +MMUniform::~MMUniform() { } - Uniform::Uniform() { - uniform; - } - - Uniform::~Uniform() { - } - - - static void Uniform::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_uniform"), &Uniform::get_uniform); - ClassDB::bind_method(D_METHOD("set_uniform", "value"), &Uniform::set_uniform); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "uniform", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_uniform", "get_uniform"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Uniform::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Uniform::_register_methods); - ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &Uniform::_get_value_for); - - } - - +void MMUniform::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_uniform"), &MMUniform::get_uniform); + ClassDB::bind_method(D_METHOD("set_uniform", "value"), &MMUniform::set_uniform); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "uniform", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_uniform", "get_uniform"); + ClassDB::bind_method(D_METHOD("_init_properties"), &MMUniform::_init_properties); + //ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &MMUniform::_register_methods); + ClassDB::bind_method(D_METHOD("_get_value_for", "uv", "pseed"), &MMUniform::_get_value_for); +} diff --git a/modules/material_maker/nodes/uniform/uniform.h b/modules/material_maker/nodes/uniform/uniform.h index 551831074..a15bab3cf 100644 --- a/modules/material_maker/nodes/uniform/uniform.h +++ b/modules/material_maker/nodes/uniform/uniform.h @@ -1,29 +1,27 @@ -#ifndef UNIFORM_H -#define UNIFORM_H +#ifndef MM_UNIFORM_H +#define MM_UNIFORM_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Uniform : public MMNode { - GDCLASS(Uniform, MMNode); +class MMUniform : public MMNode { + GDCLASS(MMUniform, 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); + MMUniform(); + ~MMUniform(); - Uniform(); - ~Uniform(); +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 83428bbfe..23b2c7373 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -42,6 +42,8 @@ SOFTWARE. #include "editor_plugin.h" #endif +#include "nodes/uniform/uniform.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -58,6 +60,9 @@ void register_material_maker_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + MMAlgos::register_node_class("Uniform", "MMUniform"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));