MMSDF3dTfTranslate node.

This commit is contained in:
Relintai 2022-06-17 11:25:09 +02:00
parent edf682cace
commit 3bbaaa3af0
7 changed files with 104 additions and 135 deletions

View File

@ -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"]:

View File

@ -38,6 +38,8 @@ def get_doc_classes():
"MMShape",
"MMImage",
"MMCurve",
"MMSdf3dTfTranslate",
]
def get_doc_path():

View File

@ -514,6 +514,10 @@ Ref<Image> 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);

View File

@ -105,6 +105,8 @@ public:
void set_default_value(const Variant &val);
Ref<Image> get_active_image();
void do_emit_changed();
MMNodeUniversalProperty();
~MMNodeUniversalProperty();

View File

@ -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<Resource> Sdf3dTfTranslate::get_input() {
return input;
Ref<MMNodeUniversalProperty> MMSdf3dTfTranslate::get_input() {
return input;
}
void Sdf3dTfTranslate::set_input(const Ref<Resource> &val) {
input = val;
void MMSdf3dTfTranslate::set_input(const Ref<MMNodeUniversalProperty> &val) {
input = val;
}
Ref<Resource> Sdf3dTfTranslate::get_output() {
return output;
Ref<MMNodeUniversalProperty> MMSdf3dTfTranslate::get_output() {
return output;
}
void Sdf3dTfTranslate::set_output(const Ref<Resource> &val) {
output = val;
void MMSdf3dTfTranslate::set_output(const Ref<MMNodeUniversalProperty> &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<Resource> input;
//export(Resource) ;
Ref<Resource> 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<Resource>"), "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<Resource>"), "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);
}

View File

@ -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<MMNodeUniversalProperty> get_input();
void set_input(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_input();
void set_input(const Ref<Resource> &val);
Ref<MMNodeUniversalProperty> get_output();
void set_output(const Ref<MMNodeUniversalProperty> &val);
Ref<Resource> get_output();
void set_output(const Ref<Resource> &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<Resource> input;
//export(Resource)
Ref<Resource> output;
//export(Vector3)
Vector3 translation = Vector3();
//translation
Ref<MMNodeUniversalProperty> input;
Ref<MMNodeUniversalProperty> output;
Vector3 translation;
};
#endif

View File

@ -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<MMCurve>();
MMAlgos::register_node_class("Simple", "MMCurve");
ClassDB::register_class<MMSdf3dTfTranslate>();
MMAlgos::register_node_class("SDF3D", "MMSdf3dTfTranslate");
_mm_algos_singleton = memnew(_MMAlgos);
Engine::get_singleton()->add_singleton(Engine::Singleton("MMAlgos", _MMAlgos::get_singleton()));