From c76a6c728233e3775de5ccf73ca95f10e1bcd5f7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 6 Jul 2020 20:46:00 +0200 Subject: [PATCH] Implement processing PropDatalights. --- props/prop_data_light.cpp | 34 +++++++++++++++++++++++++++++++++- props/prop_data_light.h | 4 ++++ register_types.cpp | 3 +++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/props/prop_data_light.cpp b/props/prop_data_light.cpp index 3e7e466..4b963a2 100644 --- a/props/prop_data_light.cpp +++ b/props/prop_data_light.cpp @@ -22,6 +22,9 @@ SOFTWARE. #include "prop_data_light.h" +#include "prop_data.h" +#include "scene/3d/light.h" + Color PropDataLight::get_light_color() const { return _light_color; } @@ -36,8 +39,37 @@ void PropDataLight::set_light_size(const int value) { _light_size = value; } +bool PropDataLight::_processor_handles(Node *node) { + OmniLight *i = Object::cast_to(node); + + return i; +} + +void PropDataLight::_processor_process(Ref prop_data, Node *node, const Transform &transform) { + OmniLight *i = Object::cast_to(node); + + ERR_FAIL_COND(!i); + + Ref l; + l.instance(); + l->set_light_color(i->get_color()); + l->set_light_size(i->get_param(Light::PARAM_RANGE)); + l->set_transform(transform * i->get_transform()); + prop_data->add_prop(l); +} + +Node *PropDataLight::_processor_get_node_for(const Transform &transform) { + OmniLight *i = memnew(OmniLight); + + i->set_color(get_light_color()); + i->set_param(Light::PARAM_RANGE, get_light_size()); + i->set_transform(get_transform()); + + return i; +} + PropDataLight::PropDataLight() { - _light_size = 5; + _light_size = 0; } PropDataLight::~PropDataLight() { } diff --git a/props/prop_data_light.h b/props/prop_data_light.h index db9349b..fa8cdd3 100644 --- a/props/prop_data_light.h +++ b/props/prop_data_light.h @@ -37,6 +37,10 @@ public: int get_light_size() const; void set_light_size(const int value); + bool _processor_handles(Node *node); + void _processor_process(Ref prop_data, Node *node, const Transform &transform); + Node *_processor_get_node_for(const Transform &transform); + PropDataLight(); ~PropDataLight(); diff --git a/register_types.cpp b/register_types.cpp index 2477235..7bbcd3c 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -65,6 +65,9 @@ void register_props_types() { ClassDB::register_class(); Engine::get_singleton()->add_singleton(Engine::Singleton("PropUtils", PropUtils::get_singleton())); + Ref light_processor = Ref(memnew(PropDataLight)); + PropUtils::add_processor(light_processor); + #ifdef TOOLS_ENABLED EditorPlugins::add_by_type(); #endif