pandemonium_engine/modules/vertex_lights_3d/vertex_light_3d_environment.cpp

97 lines
4.0 KiB
C++
Raw Normal View History

2024-03-20 20:27:56 +01:00
/*************************************************************************/
2024-04-21 15:27:36 +02:00
/* vertex_light_3d_environment.cpp */
2024-03-20 20:27:56 +01:00
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "vertex_light_3d_environment.h"
#include "core/config/engine.h"
2024-03-20 20:27:56 +01:00
#include "scene/resources/world_3d.h"
2024-03-20 20:27:56 +01:00
#include "vertex_lights_3d_server.h"
2024-03-20 20:27:56 +01:00
bool VertexLight3DEnvironment::get_is_enabled() {
return _enabled;
}
void VertexLight3DEnvironment::set_enabled(const bool p_enabled) {
_enabled = p_enabled;
2024-03-20 20:27:56 +01:00
_update_light_visibility();
}
2024-03-20 20:27:56 +01:00
Color VertexLight3DEnvironment::get_color() {
return _color;
}
void VertexLight3DEnvironment::set_color(const Color &p_color) {
_color = p_color;
2024-03-20 20:27:56 +01:00
_update_light_visibility();
}
2024-03-20 20:27:56 +01:00
VertexLight3DEnvironment::VertexLight3DEnvironment() {
_enabled = true;
}
2024-03-20 20:27:56 +01:00
VertexLight3DEnvironment::~VertexLight3DEnvironment() {
}
2024-03-20 20:27:56 +01:00
void VertexLight3DEnvironment::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_light_visibility();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
_update_light_visibility();
} break;
}
}
2024-03-20 20:27:56 +01:00
void VertexLight3DEnvironment::_update_light_visibility() {
if (!is_inside_tree() || !_enabled || !is_visible_in_tree()) {
return;
}
2024-03-20 20:27:56 +01:00
Ref<World3D> world = get_world_3d();
ERR_FAIL_COND(!world.is_valid());
RID map = world->get_vertex_lights_3d_map();
2024-03-20 20:27:56 +01:00
VertexLights3DServer::get_singleton()->map_set_base_color(map, _color);
}
2024-03-20 20:27:56 +01:00
void VertexLight3DEnvironment::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_is_enabled"), &VertexLight3DEnvironment::get_is_enabled);
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &VertexLight3DEnvironment::set_enabled);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "get_is_enabled");
2024-03-20 20:27:56 +01:00
ClassDB::bind_method(D_METHOD("get_color"), &VertexLight3DEnvironment::get_color);
ClassDB::bind_method(D_METHOD("set_color", "color"), &VertexLight3DEnvironment::set_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
}