From 3bbaaa3af0194d61a83effca2409abed76736280 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 17 Jun 2022 11:25:09 +0200 Subject: [PATCH] MMSDF3dTfTranslate node. --- modules/material_maker/SCsub | 2 + modules/material_maker/config.py | 2 + .../nodes/mm_node_universal_property.cpp | 6 + .../nodes/mm_node_universal_property.h | 2 + .../nodes/sdf3d/sdf3d_tf_translate.cpp | 168 +++++++----------- .../nodes/sdf3d/sdf3d_tf_translate.h | 54 +++--- modules/material_maker/register_types.cpp | 5 + 7 files changed, 104 insertions(+), 135 deletions(-) diff --git a/modules/material_maker/SCsub b/modules/material_maker/SCsub index b1d2ff837..fccad9b44 100644 --- a/modules/material_maker/SCsub +++ b/modules/material_maker/SCsub @@ -68,6 +68,8 @@ sources = [ "nodes/simple/shape.cpp", "nodes/simple/image.cpp", "nodes/simple/curve.cpp", + + "nodes/sdf3d/sdf3d_tf_translate.cpp", ] if env["tools"]: diff --git a/modules/material_maker/config.py b/modules/material_maker/config.py index f003560ec..3532f61e4 100644 --- a/modules/material_maker/config.py +++ b/modules/material_maker/config.py @@ -38,6 +38,8 @@ def get_doc_classes(): "MMShape", "MMImage", "MMCurve", + + "MMSdf3dTfTranslate", ] def get_doc_path(): diff --git a/modules/material_maker/nodes/mm_node_universal_property.cpp b/modules/material_maker/nodes/mm_node_universal_property.cpp index ec8b4a9c9..1093291e4 100644 --- a/modules/material_maker/nodes/mm_node_universal_property.cpp +++ b/modules/material_maker/nodes/mm_node_universal_property.cpp @@ -514,6 +514,10 @@ Ref MMNodeUniversalProperty::get_active_image() { return default_image; } +void MMNodeUniversalProperty::do_emit_changed() { + emit_changed(); +} + MMNodeUniversalProperty::MMNodeUniversalProperty() { default_type = DEFAULT_TYPE_INT; default_int = 0; @@ -624,6 +628,8 @@ void MMNodeUniversalProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("set_default_value", "val"), &MMNodeUniversalProperty::set_default_value); ClassDB::bind_method(D_METHOD("get_active_image"), &MMNodeUniversalProperty::get_active_image); + ClassDB::bind_method(D_METHOD("do_emit_changed"), &MMNodeUniversalProperty::do_emit_changed); + BIND_ENUM_CONSTANT(SLOT_TYPE_NONE); BIND_ENUM_CONSTANT(SLOT_TYPE_IMAGE); BIND_ENUM_CONSTANT(SLOT_TYPE_INT); diff --git a/modules/material_maker/nodes/mm_node_universal_property.h b/modules/material_maker/nodes/mm_node_universal_property.h index 97963c883..e13c16323 100644 --- a/modules/material_maker/nodes/mm_node_universal_property.h +++ b/modules/material_maker/nodes/mm_node_universal_property.h @@ -105,6 +105,8 @@ public: void set_default_value(const Variant &val); Ref get_active_image(); + void do_emit_changed(); + MMNodeUniversalProperty(); ~MMNodeUniversalProperty(); diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp index 353a4847f..2dab6f836 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.cpp @@ -1,139 +1,97 @@ #include "sdf3d_tf_translate.h" +#include "../../algos/mm_algos.h" +#include "../../editor/mm_graph_node.h" +#include "../mm_material.h" -Ref Sdf3dTfTranslate::get_input() { - return input; +Ref MMSdf3dTfTranslate::get_input() { + return input; } -void Sdf3dTfTranslate::set_input(const Ref &val) { -input = val; +void MMSdf3dTfTranslate::set_input(const Ref &val) { + input = val; } - -Ref Sdf3dTfTranslate::get_output() { - return output; +Ref MMSdf3dTfTranslate::get_output() { + return output; } -void Sdf3dTfTranslate::set_output(const Ref &val) { -output = val; +void MMSdf3dTfTranslate::set_output(const Ref &val) { + output = val; } - -Vector3 Sdf3dTfTranslate::get_translation() { - return translation; +Vector3 MMSdf3dTfTranslate::get_translation() { + return translation; } -void Sdf3dTfTranslate::set_translation(const Vector3 &val) { -translation = val; +void MMSdf3dTfTranslate::set_translation(const Vector3 &val) { + translation = val; + emit_changed(); + output->do_emit_changed(); } +void MMSdf3dTfTranslate::_init_properties() { + if (!input.is_valid()) { + input.instance(); + input->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } + input->set_input_slot_type(MMNodeUniversalProperty::SLOT_TYPE_UNIVERSAL); + // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; + input->set_slot_name(">>> Input "); - //tool; - //export(Resource) ; - Ref input; - //export(Resource) ; - Ref output; - //export(Vector3) ; - Vector3 translation = Vector3(); + if (!input->is_connected("changed", this, "on_input_changed")) { + input->connect("changed", this, "on_input_changed"); + } - void Sdf3dTfTranslate::_init_properties() { + if (!output.is_valid()) { + output.instance(); + output->set_default_type(MMNodeUniversalProperty::DEFAULT_TYPE_VECTOR2); + } - if (!input) { - input = MMNodeUniversalProperty.new(); - input.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_input_property(input); + register_output_property(output); } - input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_UNIVERSAL; - // input.input_slot_type = MMNodeUniversalProperty.SLOT_TYPE_VECTOR2; - input.slot_name = ">>> Input "; - - if (!input.is_connected("changed", self, "on_input_changed")) { - input.connect("changed", self, "on_input_changed"); +void MMSdf3dTfTranslate::_register_methods(MMGraphNode *mm_graph_node) { + mm_graph_node->add_slot_label_universal(input); + mm_graph_node->add_slot_label_universal(output); + mm_graph_node->add_slot_vector3("get_translation", "set_translation", "Translation", 0.01); } - - if (!output) { - output = MMNodeUniversalProperty.new(); - output.default_type = MMNodeUniversalProperty.DEFAULT_TYPE_VECTOR2; +Vector2 MMSdf3dTfTranslate::_get_property_value_sdf3d(const Vector3 &uv3) { + //$in($uv-vec3($x, $y, $z)); + return input->get_value_sdf3d(uv3 - translation); } - output.output_slot_type = MMNodeUniversalProperty.SLOT_TYPE_FLOAT; - output.slot_name = ">>> Output >>>"; - output.get_value_from_owner = true; - register_input_property(input); - register_output_property(output); +void MMSdf3dTfTranslate::on_input_changed() { + emit_changed(); + output->do_emit_changed(); } - - void Sdf3dTfTranslate::_register_methods(const Variant &mm_graph_node) { - mm_graph_node.add_slot_label_universal(input); - mm_graph_node.add_slot_label_universal(output); - mm_graph_node.add_slot_vector3("get_translation", "set_translation", "Translation", 0.01); +MMSdf3dTfTranslate::MMSdf3dTfTranslate() { } - - Vector2 Sdf3dTfTranslate::_get_property_value_sdf3d(const Vector3 &uv3) { - //$in($uv-vec3($x, $y, $z)); - return input.get_value_sdf3d(uv3 - translation); +MMSdf3dTfTranslate::~MMSdf3dTfTranslate() { } - //translation; +void MMSdf3dTfTranslate::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_input"), &MMSdf3dTfTranslate::get_input); + ClassDB::bind_method(D_METHOD("set_input", "value"), &MMSdf3dTfTranslate::set_input); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_input", "get_input"); - Vector3 Sdf3dTfTranslate::get_translation() { - return translation; + ClassDB::bind_method(D_METHOD("get_output"), &MMSdf3dTfTranslate::get_output); + ClassDB::bind_method(D_METHOD("set_output", "value"), &MMSdf3dTfTranslate::set_output); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "MMNodeUniversalProperty"), "set_output", "get_output"); + + ClassDB::bind_method(D_METHOD("get_translation"), &MMSdf3dTfTranslate::get_translation); + ClassDB::bind_method(D_METHOD("set_translation", "value"), &MMSdf3dTfTranslate::set_translation); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation"), "set_translation", "get_translation"); + + ClassDB::bind_method(D_METHOD("on_input_changed"), &MMSdf3dTfTranslate::on_input_changed); } - - - void Sdf3dTfTranslate::set_translation(const Vector3 &val) { - translation = val; - emit_changed(); - output.emit_changed(); -} - - - void Sdf3dTfTranslate::on_input_changed() { - emit_changed(); - output.emit_changed(); -} - -} - - Sdf3dTfTranslate::Sdf3dTfTranslate() { - input; - output; - translation = Vector3(); - } - - Sdf3dTfTranslate::~Sdf3dTfTranslate() { - } - - - static void Sdf3dTfTranslate::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_input"), &Sdf3dTfTranslate::get_input); - ClassDB::bind_method(D_METHOD("set_input", "value"), &Sdf3dTfTranslate::set_input); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "input", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_input", "get_input"); - - - ClassDB::bind_method(D_METHOD("get_output"), &Sdf3dTfTranslate::get_output); - ClassDB::bind_method(D_METHOD("set_output", "value"), &Sdf3dTfTranslate::set_output); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output", PROPERTY_HINT_RESOURCE_TYPE, "Ref"), "set_output", "get_output"); - - - ClassDB::bind_method(D_METHOD("get_translation"), &Sdf3dTfTranslate::get_translation); - ClassDB::bind_method(D_METHOD("set_translation", "value"), &Sdf3dTfTranslate::set_translation); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation"), "set_translation", "get_translation"); - - - ClassDB::bind_method(D_METHOD("_init_properties"), &Sdf3dTfTranslate::_init_properties); - ClassDB::bind_method(D_METHOD("_register_methods", "mm_graph_node"), &Sdf3dTfTranslate::_register_methods); - ClassDB::bind_method(D_METHOD("_get_property_value_sdf3d", "uv3"), &Sdf3dTfTranslate::_get_property_value_sdf3d); - ClassDB::bind_method(D_METHOD("get_translation"), &Sdf3dTfTranslate::get_translation); - ClassDB::bind_method(D_METHOD("set_translation", "val"), &Sdf3dTfTranslate::set_translation); - ClassDB::bind_method(D_METHOD("on_input_changed"), &Sdf3dTfTranslate::on_input_changed); - - } - - - diff --git a/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h index aee82c598..2aa4a7225 100644 --- a/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h +++ b/modules/material_maker/nodes/sdf3d/sdf3d_tf_translate.h @@ -1,43 +1,37 @@ -#ifndef SDF3D_TF_TRANSLATE_H -#define SDF3D_TF_TRANSLATE_H +#ifndef MM_SDF3D_TF_TRANSLATE_H +#define MM_SDF3D_TF_TRANSLATE_H +#include "../mm_node.h" +#include "../mm_node_universal_property.h" -class Sdf3dTfTranslate : public MMNode { - GDCLASS(Sdf3dTfTranslate, MMNode); +class MMSdf3dTfTranslate : public MMNode { + GDCLASS(MMSdf3dTfTranslate, MMNode); - public: +public: + Ref get_input(); + void set_input(const Ref &val); - Ref get_input(); - void set_input(const Ref &val); + Ref get_output(); + void set_output(const Ref &val); - Ref get_output(); - void set_output(const Ref &val); + Vector3 get_translation(); + void set_translation(const Vector3 &val); - Vector3 get_translation(); - void set_translation(const Vector3 &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_translation(); - void set_translation(const Vector3 &val); - void on_input_changed(); + void on_input_changed(); - Sdf3dTfTranslate(); - ~Sdf3dTfTranslate(); + MMSdf3dTfTranslate(); + ~MMSdf3dTfTranslate(); - protected: - static void _bind_methods(); +protected: + static void _bind_methods(); - //tool - //export(Resource) - Ref input; - //export(Resource) - Ref output; - //export(Vector3) - Vector3 translation = Vector3(); - //translation + Ref input; + Ref output; + Vector3 translation; }; - #endif diff --git a/modules/material_maker/register_types.cpp b/modules/material_maker/register_types.cpp index 5692acde5..35da1d017 100644 --- a/modules/material_maker/register_types.cpp +++ b/modules/material_maker/register_types.cpp @@ -61,6 +61,8 @@ SOFTWARE. #include "nodes/simple/image.h" #include "nodes/simple/shape.h" +#include "nodes/sdf3d/sdf3d_tf_translate.h" + static _MMAlgos *_mm_algos_singleton = nullptr; void register_material_maker_types() { @@ -112,6 +114,9 @@ void register_material_maker_types() { ClassDB::register_class(); MMAlgos::register_node_class("Simple", "MMCurve"); + ClassDB::register_class(); + MMAlgos::register_node_class("SDF3D", "MMSdf3dTfTranslate"); + _mm_algos_singleton = memnew(_MMAlgos); Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));