From 8c4540a2a6b03d38c7efaf97e9a1f1091500e664 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 25 Feb 2022 10:38:48 +0100 Subject: [PATCH] Update Prop2DDataLight. --- prop_2d_instance.cpp | 2 +- prop_2d_instance_merger.cpp | 2 +- props/prop_2d_data_light.cpp | 114 +++++++++++++++++++++++++++-------- props/prop_2d_data_light.h | 22 ++++++- 4 files changed, 111 insertions(+), 29 deletions(-) diff --git a/prop_2d_instance.cpp b/prop_2d_instance.cpp index 183a169..644ac5c 100644 --- a/prop_2d_instance.cpp +++ b/prop_2d_instance.cpp @@ -200,7 +200,7 @@ void Prop2DInstance::_prop_preprocess(Transform transform, const Ref OmniLight *light = memnew(OmniLight); add_child(light); light->set_color(light_data->get_light_color()); - light->set_param(Light::PARAM_RANGE, light_data->get_light_size()); + //light->set_param(Light::PARAM_RANGE, light_data->get_light_size()); light->set_transform(t); continue; diff --git a/prop_2d_instance_merger.cpp b/prop_2d_instance_merger.cpp index 2864dea..fac1bba 100644 --- a/prop_2d_instance_merger.cpp +++ b/prop_2d_instance_merger.cpp @@ -674,7 +674,7 @@ void Prop2DInstanceMerger::_prop_preprocess(Transform transform, const Refset_position(v); light->set_color(light_data->get_light_color()); - light->set_size(light_data->get_light_size()); + //light->set_size(light_data->get_light_size()); _job->add_light(light); diff --git a/props/prop_2d_data_light.cpp b/props/prop_2d_data_light.cpp index 03a0b46..532624c 100644 --- a/props/prop_2d_data_light.cpp +++ b/props/prop_2d_data_light.cpp @@ -24,13 +24,7 @@ SOFTWARE. #include "prop_2d_data.h" -#if VERSION_MAJOR < 4 -#include "scene/3d/light.h" -#else -#include "scene/3d/light_3d.h" -#define OmniLight OmniLight3D -#define Light Light3D -#endif +#include "scene/2d/light_2d.h" Color Prop2DDataLight::get_light_color() const { return _light_color; @@ -39,44 +33,100 @@ void Prop2DDataLight::set_light_color(const Color value) { _light_color = value; } -int Prop2DDataLight::get_light_size() const { - return _light_size; +int Prop2DDataLight::get_light_size_x() const { + return _light_size_x; } -void Prop2DDataLight::set_light_size(const int value) { - _light_size = value; +void Prop2DDataLight::set_light_size_x(const int value) { + _light_size_x = value; +} + +int Prop2DDataLight::get_light_size_y() const { + return _light_size_y; +} +void Prop2DDataLight::set_light_size_y(const int value) { + _light_size_y = value; +} + +float Prop2DDataLight::get_texture_scale() const { + return _texture_scale; +} +void Prop2DDataLight::set_texture_scale(const float value) { + _texture_scale = value; +} + +float Prop2DDataLight::get_energy() const { + return _energy; +} +void Prop2DDataLight::set_energy(const float value) { + _energy = value; +} + +Ref Prop2DDataLight::get_texture() const { + return _texture; +} +void Prop2DDataLight::set_texture(const Ref value) { + _texture = value; } bool Prop2DDataLight::_processor_handles(Node *node) { - OmniLight *i = Object::cast_to(node); + Light2D *i = Object::cast_to(node); return i; } void Prop2DDataLight::_processor_process(Ref prop_data, Node *node, const Transform2D &transform, Ref entry) { - OmniLight *i = Object::cast_to(node); + Light2D *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); + + Ref tex = i->get_texture(); + + int w = 0; + int h = 0; + + if (tex.is_valid()) { + w = tex->get_width(); + h = tex->get_height(); + } + + l->set_light_size_x(w); + l->set_light_size_y(h); + + l->set_texture_scale(i->get_texture_scale()); + l->set_energy(i->get_energy()); + l->set_texture(tex); + + Prop2DDataEntry::_processor_process(prop_data, node, transform, l); } Node *Prop2DDataLight::_processor_get_node_for(const Transform2D &transform, Node *node) { - OmniLight *i = memnew(OmniLight); + Light2D *i = nullptr; + + if (!node) { + i = memnew(Light2D); + } else { + i = Object::cast_to(node); + } i->set_color(get_light_color()); - i->set_param(Light::PARAM_RANGE, get_light_size()); - //i->set_transform(get_transform()); - return i; + i->set_texture_scale(get_texture_scale()); + i->set_energy(get_energy()); + i->set_texture(get_texture()); + + return Prop2DDataEntry::_processor_get_node_for(transform, i); } Prop2DDataLight::Prop2DDataLight() { - _light_size = 0; + _light_size_x = 0; + _light_size_y = 0; + _texture_scale = 0; + _energy = 0; } Prop2DDataLight::~Prop2DDataLight() { } @@ -86,7 +136,23 @@ void Prop2DDataLight::_bind_methods() { ClassDB::bind_method(D_METHOD("set_light_color", "value"), &Prop2DDataLight::set_light_color); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_light_color", "get_light_color"); - ClassDB::bind_method(D_METHOD("get_light_size"), &Prop2DDataLight::get_light_size); - ClassDB::bind_method(D_METHOD("set_light_size", "value"), &Prop2DDataLight::set_light_size); - ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size"), "set_light_size", "get_light_size"); + ClassDB::bind_method(D_METHOD("get_light_size_x"), &Prop2DDataLight::get_light_size_x); + ClassDB::bind_method(D_METHOD("set_light_size_x", "value"), &Prop2DDataLight::set_light_size_x); + ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size_x"), "set_light_size_x", "get_light_size_x"); + + ClassDB::bind_method(D_METHOD("get_light_size_y"), &Prop2DDataLight::get_light_size_y); + ClassDB::bind_method(D_METHOD("set_light_size_y", "value"), &Prop2DDataLight::set_light_size_y); + ADD_PROPERTY(PropertyInfo(Variant::INT, "light_size_y"), "set_light_size_y", "get_light_size_y"); + + ClassDB::bind_method(D_METHOD("get_texture_scale"), &Prop2DDataLight::get_texture_scale); + ClassDB::bind_method(D_METHOD("set_texture_scale", "value"), &Prop2DDataLight::set_texture_scale); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_scale"), "set_texture_scale", "get_texture_scale"); + + ClassDB::bind_method(D_METHOD("get_energy"), &Prop2DDataLight::get_energy); + ClassDB::bind_method(D_METHOD("set_energy", "value"), &Prop2DDataLight::set_energy); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy"), "set_energy", "get_energy"); + + ClassDB::bind_method(D_METHOD("get_texture"), &Prop2DDataLight::get_texture); + ClassDB::bind_method(D_METHOD("set_texture", "value"), &Prop2DDataLight::set_texture); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); } diff --git a/props/prop_2d_data_light.h b/props/prop_2d_data_light.h index 177ac75..087f0aa 100644 --- a/props/prop_2d_data_light.h +++ b/props/prop_2d_data_light.h @@ -40,8 +40,20 @@ public: Color get_light_color() const; void set_light_color(const Color value); - int get_light_size() const; - void set_light_size(const int value); + int get_light_size_x() const; + void set_light_size_x(const int value); + + int get_light_size_y() const; + void set_light_size_y(const int value); + + float get_texture_scale() const; + void set_texture_scale(const float value); + + float get_energy() const; + void set_energy(const float value); + + Ref get_texture() const; + void set_texture(const Ref value); bool _processor_handles(Node *node); void _processor_process(Ref prop_data, Node *node, const Transform2D &transform, Ref entry = Ref()); @@ -55,7 +67,11 @@ protected: private: Color _light_color; - int _light_size; + int _light_size_x; + int _light_size_y; + float _texture_scale; + float _energy; + Ref _texture; }; #endif