2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* baked_light_instance.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 12:46:12 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2014-06-11 13:41:03 +00:00
|
|
|
#include "baked_light_instance.h"
|
|
|
|
#include "scene/scene_string_names.h"
|
|
|
|
|
|
|
|
RID BakedLightInstance::get_baked_light_instance() const {
|
|
|
|
|
|
|
|
if (baked_light.is_null())
|
|
|
|
return RID();
|
|
|
|
else
|
|
|
|
return get_instance();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void BakedLightInstance::set_baked_light(const Ref<BakedLight> &p_baked_light) {
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
baked_light = p_baked_light;
|
2014-06-11 13:41:03 +00:00
|
|
|
|
|
|
|
RID base_rid;
|
|
|
|
|
|
|
|
if (baked_light.is_valid())
|
2017-03-18 23:36:26 +00:00
|
|
|
base_rid = baked_light->get_rid();
|
2014-06-11 13:41:03 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
base_rid = RID();
|
2014-06-11 13:41:03 +00:00
|
|
|
|
|
|
|
set_base(base_rid);
|
|
|
|
|
|
|
|
if (is_inside_world()) {
|
|
|
|
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->baked_light_changed);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// for (List<Node*>::Element *E=baked_geometry.front();E;E=E->next()) {
|
|
|
|
// VS::get_singleton()->instance_geometry_set_baked_light(E->get()->get_instance(),baked_light.is_valid()?get_instance():RID());
|
|
|
|
// }
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
2016-07-26 02:45:20 +00:00
|
|
|
|
|
|
|
update_configuration_warning();
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<BakedLight> BakedLightInstance::get_baked_light() const {
|
2014-06-11 13:41:03 +00:00
|
|
|
|
|
|
|
return baked_light;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB BakedLightInstance::get_aabb() const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return AABB(Vector3(0, 0, 0), Vector3(1, 1, 1));
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
|
|
|
DVector<Face3> BakedLightInstance::get_faces(uint32_t p_usage_flags) const {
|
|
|
|
|
|
|
|
return DVector<Face3>();
|
|
|
|
}
|
|
|
|
|
2016-07-26 02:45:20 +00:00
|
|
|
String BakedLightInstance::get_configuration_warning() const {
|
|
|
|
if (get_baked_light().is_null()) {
|
|
|
|
return TTR("BakedLightInstance does not contain a BakedLight resource.");
|
|
|
|
}
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2014-06-11 13:41:03 +00:00
|
|
|
void BakedLightInstance::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_baked_light", "baked_light"), &BakedLightInstance::set_baked_light);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_baked_light"), &BakedLightInstance::get_baked_light);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_baked_light_instance"), &BakedLightInstance::get_baked_light_instance);
|
2014-06-11 13:41:03 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "baked_light", PROPERTY_HINT_RESOURCE_TYPE, "BakedLight"), _SCS("set_baked_light"), _SCS("get_baked_light"));
|
|
|
|
ADD_SIGNAL(MethodInfo("baked_light_changed"));
|
2014-06-11 13:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightInstance::BakedLightInstance() {
|
|
|
|
}
|
2014-10-28 01:54:32 +00:00
|
|
|
/////////////////////////
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void BakedLightSampler::set_param(Param p_param, float p_value) {
|
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
params[p_param] = p_value;
|
|
|
|
VS::get_singleton()->baked_light_sampler_set_param(base, VS::BakedLightSamplerParam(p_param), p_value);
|
2014-10-28 01:54:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
float BakedLightSampler::get_param(Param p_param) const {
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
|
2014-10-28 01:54:32 +00:00
|
|
|
return params[p_param];
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void BakedLightSampler::set_resolution(int p_resolution) {
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(p_resolution < 4 || p_resolution > 32);
|
|
|
|
resolution = p_resolution;
|
|
|
|
VS::get_singleton()->baked_light_sampler_set_resolution(base, resolution);
|
2014-10-28 01:54:32 +00:00
|
|
|
}
|
|
|
|
int BakedLightSampler::get_resolution() const {
|
|
|
|
|
|
|
|
return resolution;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB BakedLightSampler::get_aabb() const {
|
|
|
|
|
|
|
|
float r = get_param(PARAM_RADIUS);
|
2017-03-18 23:36:26 +00:00
|
|
|
return AABB(Vector3(-r, -r, -r), Vector3(r * 2, r * 2, r * 2));
|
2014-10-28 01:54:32 +00:00
|
|
|
}
|
|
|
|
DVector<Face3> BakedLightSampler::get_faces(uint32_t p_usage_flags) const {
|
|
|
|
return DVector<Face3>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightSampler::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_param", "param", "value"), &BakedLightSampler::set_param);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_param", "param"), &BakedLightSampler::get_param);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("set_resolution", "resolution"), &BakedLightSampler::set_resolution);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_resolution"), &BakedLightSampler::get_resolution);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
BIND_CONSTANT(PARAM_RADIUS);
|
|
|
|
BIND_CONSTANT(PARAM_STRENGTH);
|
|
|
|
BIND_CONSTANT(PARAM_ATTENUATION);
|
|
|
|
BIND_CONSTANT(PARAM_DETAIL_RATIO);
|
|
|
|
BIND_CONSTANT(PARAM_MAX);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/radius", PROPERTY_HINT_RANGE, "0.01,1024,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_RADIUS);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/strength", PROPERTY_HINT_RANGE, "0.01,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_STRENGTH);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/attenuation", PROPERTY_HINT_EXP_EASING), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "params/detail_ratio", PROPERTY_HINT_RANGE, "0.01,1.0,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_DETAIL_RATIO);
|
|
|
|
// ADD_PROPERTYI( PropertyInfo(Variant::REAL,"params/detail_ratio",PROPERTY_HINT_RANGE,"0,20,1"),_SCS("set_param"),_SCS("get_param"),PARAM_DETAIL_RATIO);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "params/resolution", PROPERTY_HINT_RANGE, "4,32,1"), _SCS("set_resolution"), _SCS("get_resolution"));
|
2014-10-28 01:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightSampler::BakedLightSampler() {
|
|
|
|
|
|
|
|
base = VS::get_singleton()->baked_light_sampler_create();
|
|
|
|
set_base(base);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
params[PARAM_RADIUS] = 1.0;
|
|
|
|
params[PARAM_STRENGTH] = 1.0;
|
|
|
|
params[PARAM_ATTENUATION] = 1.0;
|
|
|
|
params[PARAM_DETAIL_RATIO] = 0.1;
|
|
|
|
resolution = 16;
|
2014-10-28 01:54:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
BakedLightSampler::~BakedLightSampler() {
|
2014-10-28 01:54:32 +00:00
|
|
|
|
|
|
|
VS::get_singleton()->free(base);
|
|
|
|
}
|