Cleaned up Uniform, and added it to the build.

This commit is contained in:
Relintai 2022-06-16 17:13:14 +02:00
parent d939ab54c7
commit c2a373a9cf
5 changed files with 53 additions and 63 deletions

View File

@ -49,6 +49,8 @@ sources = [
"editor/widgets/polygon_edit/polygon_edit.cpp", "editor/widgets/polygon_edit/polygon_edit.cpp",
"editor/widgets/polygon_edit/polygon_editor.cpp", "editor/widgets/polygon_edit/polygon_editor.cpp",
"editor/widgets/polygon_edit/polygon_view.cpp", "editor/widgets/polygon_edit/polygon_view.cpp",
"nodes/uniform/uniform.cpp",
] ]
if env["tools"]: if env["tools"]:

View File

@ -19,6 +19,8 @@ def get_doc_classes():
"MMMaterial", "MMMaterial",
"MMGraphNode", "MMGraphNode",
"MatMakerGDEditor", "MatMakerGDEditor",
"MMUniform",
] ]
def get_doc_path(): def get_doc_path():

View File

@ -1,64 +1,47 @@
#include "uniform.h" #include "uniform.h"
#include "../../editor/mm_graph_node.h"
Ref<Resource> Uniform::get_uniform() { Ref<MMNodeUniversalProperty> MMUniform::get_uniform() {
return uniform; return uniform;
} }
void Uniform::set_uniform(const Ref<Resource> &val) { void MMUniform::set_uniform(const Ref<MMNodeUniversalProperty> &val) {
uniform = 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));
}
uniform->set_output_slot_type(MMNodeUniversalProperty::SLOT_TYPE_COLOR);
//tool; register_output_property(uniform);
//export(Resource) ;
Ref<Resource> 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.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_COLOR; void MMUniform::_register_methods(MMGraphNode *mm_graph_node) {
register_output_property(uniform); mm_graph_node->add_slot_color_universal(uniform);
} }
Color MMUniform::_get_value_for(const Vector2 &uv, const int pseed) {
void Uniform::_register_methods(const Variant &mm_graph_node) { return uniform->get_value(uv);
mm_graph_node.add_slot_color_universal(uniform);
} }
MMUniform::MMUniform() {
Color Uniform::_get_value_for(const Vector2 &uv, const int pseed) {
return uniform.get_value(uv);
} }
MMUniform::~MMUniform() {
} }
Uniform::Uniform() { void MMUniform::_bind_methods() {
uniform; 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");
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<Resource>"), "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);
}
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);
}

View File

@ -1,29 +1,27 @@
#ifndef UNIFORM_H #ifndef MM_UNIFORM_H
#define UNIFORM_H #define MM_UNIFORM_H
#include "../mm_node.h"
#include "../mm_node_universal_property.h"
class Uniform : public MMNode { class MMUniform : public MMNode {
GDCLASS(Uniform, MMNode); GDCLASS(MMUniform, MMNode);
public: public:
Ref<MMNodeUniversalProperty> get_uniform();
void set_uniform(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_uniform(); void _init_properties();
void set_uniform(const Ref<Resource> &val); void _register_methods(MMGraphNode *mm_graph_node);
Color _get_value_for(const Vector2 &uv, const int pseed);
void _init_properties(); MMUniform();
void _register_methods(const Variant &mm_graph_node); ~MMUniform();
Color _get_value_for(const Vector2 &uv, const int pseed);
Uniform(); protected:
~Uniform(); static void _bind_methods();
protected: Ref<MMNodeUniversalProperty> uniform;
static void _bind_methods();
//tool
//export(Resource)
Ref<Resource> uniform;
}; };
#endif #endif

View File

@ -42,6 +42,8 @@ SOFTWARE.
#include "editor_plugin.h" #include "editor_plugin.h"
#endif #endif
#include "nodes/uniform/uniform.h"
static _MMAlgos *_mm_algos_singleton = nullptr; static _MMAlgos *_mm_algos_singleton = nullptr;
void register_material_maker_types() { void register_material_maker_types() {
@ -58,6 +60,9 @@ void register_material_maker_types() {
ClassDB::register_class<MMGraphNode>(); ClassDB::register_class<MMGraphNode>();
ClassDB::register_class<MatMakerGDEditor>(); ClassDB::register_class<MatMakerGDEditor>();
ClassDB::register_class<MMUniform>();
MMAlgos::register_node_class("Uniform", "MMUniform");
_mm_algos_singleton = memnew(_MMAlgos); _mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));