Added an EnvironmentData class.

This commit is contained in:
Relintai 2019-10-07 22:22:47 +02:00
parent 0175490bc5
commit cf9e3e8f19
4 changed files with 140 additions and 0 deletions

1
SCsub
View File

@ -19,6 +19,7 @@ env.add_source_files(env.modules_sources,"world/voxel_buffer.cpp")
env.add_source_files(env.modules_sources,"world/voxel_world.cpp")
env.add_source_files(env.modules_sources,"world/voxel_chunk.cpp")
env.add_source_files(env.modules_sources,"world/voxel_structure.cpp")
env.add_source_files(env.modules_sources,"world/environment_data.cpp")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_mesher_cubic.cpp")

View File

@ -13,6 +13,7 @@
#include "world/voxel_world.h"
#include "world/voxel_chunk.h"
#include "world/voxel_structure.h"
#include "world/environment_data.h"
#include "meshers/cubic_mesher/voxel_mesher_cubic.h"
#include "meshers/cubic_mesher/voxel_cube_points.h"
@ -40,6 +41,7 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelWorld>();
ClassDB::register_class<VoxelChunk>();
ClassDB::register_class<VoxelStructure>();
ClassDB::register_class<EnvironmentData>();
ClassDB::register_class<VoxelMesherCubic>();
ClassDB::register_class<VoxelCubePoints>();

View File

@ -0,0 +1,91 @@
#include "environment_data.h"
Ref<Environment> EnvironmentData::get_environment() {
return _environment;
}
void EnvironmentData::set_environment(Ref<Environment> value) {
_environment = value;
}
Color EnvironmentData::get_color(int index) {
ERR_FAIL_INDEX_V(index, LIGHT_COUNT, Color());
return _colors[index];
}
void EnvironmentData::set_color(int index, Color value) {
ERR_FAIL_INDEX(index, LIGHT_COUNT);
_colors[index] = value;
}
float EnvironmentData::get_energy(int index) {
ERR_FAIL_INDEX_V(index, LIGHT_COUNT, 0);
return _energies[index];
}
void EnvironmentData::set_energy(int index, float value) {
ERR_FAIL_INDEX(index, LIGHT_COUNT);
_energies[index] = value;
}
float EnvironmentData::get_indirect_energy(int index) {
ERR_FAIL_INDEX_V(index, LIGHT_COUNT, 0);
return _indirect_energies[index];
}
void EnvironmentData::set_indirect_energy(int index, float value) {
ERR_FAIL_INDEX(index, LIGHT_COUNT);
_indirect_energies[index] = value;
}
void EnvironmentData::setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light) {
if (has_method("_setup"))
call("_setup", world_environment, primary_light, secondary_light);
}
void EnvironmentData::setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light) {
setup(Object::cast_to<WorldEnvironment>(world_environment), Object::cast_to<DirectionalLight>(primary_light), Object::cast_to<DirectionalLight>(secondary_light));
}
EnvironmentData::EnvironmentData() {
_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;
}
EnvironmentData::~EnvironmentData() {
_environment.unref();
}
void EnvironmentData::_bind_methods() {
BIND_VMETHOD(MethodInfo("_setup", PropertyInfo(Variant::OBJECT, "world_environment", PROPERTY_HINT_RESOURCE_TYPE, "WorldEnvironment"), PropertyInfo(Variant::OBJECT, "primary_light", PROPERTY_HINT_RESOURCE_TYPE, "DirectionalLight"), PropertyInfo(Variant::OBJECT, "secondary_light", PROPERTY_HINT_RESOURCE_TYPE, "DirectionalLight")));
ClassDB::bind_method(D_METHOD("get_environment"), &EnvironmentData::get_environment);
ClassDB::bind_method(D_METHOD("set_environment", "value"), &EnvironmentData::set_environment);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
ClassDB::bind_method(D_METHOD("get_color", "index"), &EnvironmentData::get_color);
ClassDB::bind_method(D_METHOD("set_color", "index", "value"), &EnvironmentData::set_color);
ClassDB::bind_method(D_METHOD("get_energy", "index"), &EnvironmentData::get_energy);
ClassDB::bind_method(D_METHOD("set_energy", "index", "value"), &EnvironmentData::set_energy);
ClassDB::bind_method(D_METHOD("get_indirect_energy", "index"), &EnvironmentData::get_indirect_energy);
ClassDB::bind_method(D_METHOD("set_indirect_energy", "index", "value"), &EnvironmentData::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"), &EnvironmentData::setup_bind);
BIND_CONSTANT(LIGHT_COUNT);
}

46
world/environment_data.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef ENVIRONMENT_DATA_H
#define ENVIRONMENT_DATA_H
#include "core/resource.h"
#include "core/color.h"
#include "scene/main/node.h"
#include "scene/3d/world_environment.h"
#include "scene/3d/light.h"
class EnvironmentData : public Resource {
GDCLASS(EnvironmentData, Resource);
public:
Ref<Environment> get_environment();
void set_environment(Ref<Environment> value);
Color get_color(int index);
void set_color(int index, Color value);
float get_energy(int index);
void set_energy(int index, float value);
float get_indirect_energy(int index);
void set_indirect_energy(int index, float value);
void setup(WorldEnvironment *world_environment, DirectionalLight *primary_light, DirectionalLight *secondary_light);
void setup_bind(Node *world_environment, Node *primary_light, Node *secondary_light);
EnvironmentData();
~EnvironmentData();
public:
enum {
LIGHT_COUNT = 2,
};
protected:
static void _bind_methods();
private:
Ref<Environment> _environment;
Color _colors[LIGHT_COUNT];
float _energies[LIGHT_COUNT];
float _indirect_energies[LIGHT_COUNT];
};
#endif