2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "terrain_environment_data.h"
|
|
|
|
|
2022-08-29 17:33:10 +02:00
|
|
|
#include "scene/resources/environment_3d.h"
|
2022-03-17 19:35:23 +01:00
|
|
|
|
2022-08-29 17:21:40 +02:00
|
|
|
Ref<Environment3D> TerrainEnvironmentData::get_environment() {
|
2022-03-15 13:29:32 +01:00
|
|
|
return _environment;
|
|
|
|
}
|
2022-08-29 17:21:40 +02:00
|
|
|
void TerrainEnvironmentData::set_environment(const Ref<Environment3D> &value) {
|
2022-03-15 13:29:32 +01:00
|
|
|
_environment = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color TerrainEnvironmentData::get_color(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, LIGHT_COUNT, Color());
|
|
|
|
|
|
|
|
return _colors[index];
|
|
|
|
}
|
|
|
|
void TerrainEnvironmentData::set_color(const int index, const Color &value) {
|
|
|
|
ERR_FAIL_INDEX(index, LIGHT_COUNT);
|
|
|
|
|
|
|
|
_colors[index] = value;
|
|
|
|
}
|
|
|
|
float TerrainEnvironmentData::get_energy(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, LIGHT_COUNT, 0);
|
|
|
|
|
|
|
|
return _energies[index];
|
|
|
|
}
|
|
|
|
void TerrainEnvironmentData::set_energy(const int index, const float value) {
|
|
|
|
ERR_FAIL_INDEX(index, LIGHT_COUNT);
|
|
|
|
|
|
|
|
_energies[index] = value;
|
|
|
|
}
|
|
|
|
float TerrainEnvironmentData::get_indirect_energy(const int index) {
|
|
|
|
ERR_FAIL_INDEX_V(index, LIGHT_COUNT, 0);
|
|
|
|
|
|
|
|
return _indirect_energies[index];
|
|
|
|
}
|
|
|
|
void TerrainEnvironmentData::set_indirect_energy(const int index, const float value) {
|
|
|
|
ERR_FAIL_INDEX(index, LIGHT_COUNT);
|
|
|
|
|
|
|
|
_indirect_energies[index] = value;
|
|
|
|
}
|
|
|
|
|
2022-08-29 17:21:40 +02:00
|
|
|
void TerrainEnvironmentData::setup(WorldEnvironment3D *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light) {
|
2022-03-15 13:29:32 +01:00
|
|
|
if (has_method("_setup")) {
|
2022-03-18 10:56:48 +01:00
|
|
|
call("_setup", world_environment, primary_light, secondary_light);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void TerrainEnvironmentData::setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light) {
|
2022-08-29 17:21:40 +02:00
|
|
|
setup(Object::cast_to<WorldEnvironment3D>(world_environment), Object::cast_to<DirectionalLight>(primary_light), Object::cast_to<DirectionalLight>(secondary_light));
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TerrainEnvironmentData::TerrainEnvironmentData() {
|
|
|
|
_colors[0] = Color(1, 1, 1, 1);
|
|
|
|
_colors[1] = Color(1, 1, 1, 1);
|
|
|
|
|
|
|
|
_energies[0] = 1;
|
|
|
|
_energies[1] = 1;
|
|
|
|
|
|
|
|
_indirect_energies[0] = 1;
|
|
|
|
_indirect_energies[1] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TerrainEnvironmentData::~TerrainEnvironmentData() {
|
|
|
|
_environment.unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainEnvironmentData::_bind_methods() {
|
2022-08-29 17:21:40 +02:00
|
|
|
BIND_VMETHOD(MethodInfo("_setup", PropertyInfo(Variant::OBJECT, "world_environment", PROPERTY_HINT_RESOURCE_TYPE, "WorldEnvironment3D"), PropertyInfo(Variant::OBJECT, "primary_light", PROPERTY_HINT_RESOURCE_TYPE, "DirectionalLight"), PropertyInfo(Variant::OBJECT, "secondary_light", PROPERTY_HINT_RESOURCE_TYPE, "DirectionalLight")));
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_environment"), &TerrainEnvironmentData::get_environment);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_environment", "value"), &TerrainEnvironmentData::set_environment);
|
2022-08-29 17:21:40 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment3D"), "set_environment", "get_environment");
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color", "index"), &TerrainEnvironmentData::get_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "index", "value"), &TerrainEnvironmentData::set_color);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_energy", "index"), &TerrainEnvironmentData::get_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_energy", "index", "value"), &TerrainEnvironmentData::set_energy);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_indirect_energy", "index"), &TerrainEnvironmentData::get_indirect_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_indirect_energy", "index", "value"), &TerrainEnvironmentData::set_indirect_energy);
|
|
|
|
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::COLOR, "primary_light_color"), "set_color", "get_color", 0);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "primary_light_energy"), "set_energy", "get_energy", 0);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "primary_light_indirect_energy"), "set_indirect_energy", "get_indirect_energy", 0);
|
|
|
|
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::COLOR, "secondary_light_color"), "set_color", "get_color", 1);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "secondary_light_energy"), "set_energy", "get_energy", 1);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "secondary_light_indirect_energy"), "set_indirect_energy", "get_indirect_energy", 1);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("setup", "world_environment", "primary_light", "secondary_light"), &TerrainEnvironmentData::setup_bind);
|
|
|
|
|
|
|
|
BIND_CONSTANT(LIGHT_COUNT);
|
|
|
|
}
|