summaryrefslogtreecommitdiffstats
path: root/scene/3d/visual_instance.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-06-11 10:41:03 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-06-11 10:41:03 -0300
commit9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae (patch)
treeb2ed0515196bb774504b54aab0bf242992ac3d9f /scene/3d/visual_instance.cpp
parent6f0b4678e26c04abfc88c0226c803e78a108de98 (diff)
downloadredot-engine-9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae.tar.gz
Light Baker!
-=-=-=-=-=-= -Support for lightmap baker, have fun figuring out how it works before tutorial is published.
Diffstat (limited to 'scene/3d/visual_instance.cpp')
-rw-r--r--scene/3d/visual_instance.cpp78
1 files changed, 75 insertions, 3 deletions
diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp
index 96f16ab8c8..625da9b093 100644
--- a/scene/3d/visual_instance.cpp
+++ b/scene/3d/visual_instance.cpp
@@ -31,7 +31,7 @@
#include "servers/visual_server.h"
#include "room_instance.h"
#include "scene/scene_string_names.h"
-
+#include "baked_light_instance.h"
#include "skeleton.h"
AABB VisualInstance::get_transformed_aabb() const {
@@ -186,6 +186,61 @@ float GeometryInstance::get_draw_range_end() const {
return draw_end;
}
+void GeometryInstance::_notification(int p_what) {
+
+ if (p_what==NOTIFICATION_ENTER_WORLD) {
+
+ if (flags[FLAG_USE_BAKED_LIGHT]) {
+
+ _find_baked_light();
+ }
+
+
+ } else if (p_what==NOTIFICATION_EXIT_WORLD) {
+
+ if (flags[FLAG_USE_BAKED_LIGHT]) {
+
+ if (baked_light_instance) {
+ baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ baked_light_instance=NULL;
+ }
+ _baked_light_changed();
+
+ }
+ }
+
+}
+
+void GeometryInstance::_baked_light_changed() {
+
+ if (!baked_light_instance)
+ VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID());
+ else
+ VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance());
+
+}
+
+void GeometryInstance::_find_baked_light() {
+
+ Node *n=get_parent();
+ while(n) {
+
+ BakedLightInstance *bl=n->cast_to<BakedLightInstance>();
+ if (bl) {
+
+ baked_light_instance=bl;
+ baked_light_instance->connect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ _baked_light_changed();
+
+ return;
+ }
+
+ n=n->get_parent();
+ }
+
+ _baked_light_changed();
+}
+
void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
ERR_FAIL_INDEX(p_flag,FLAG_MAX);
@@ -198,8 +253,20 @@ void GeometryInstance::set_flag(Flags p_flag,bool p_value) {
_change_notify("geometry/visible");
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
}
-
-
+ if (p_flag==FLAG_USE_BAKED_LIGHT) {
+
+ if (is_inside_world()) {
+ if (!p_value) {
+ if (baked_light_instance) {
+ baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed);
+ baked_light_instance=NULL;
+ }
+ _baked_light_changed();
+ } else {
+ _find_baked_light();
+ }
+ }
+ }
}
bool GeometryInstance::get_flag(Flags p_flag) const{
@@ -224,6 +291,8 @@ void GeometryInstance::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_draw_range_end","mode"), &GeometryInstance::set_draw_range_end);
ObjectTypeDB::bind_method(_MD("get_draw_range_end"), &GeometryInstance::get_draw_range_end);
+ ObjectTypeDB::bind_method(_MD("_baked_light_changed"), &GeometryInstance::_baked_light_changed);
+
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/visible"), _SCS("set_flag"), _SCS("get_flag"),FLAG_VISIBLE);
ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "geometry/material_override",PROPERTY_HINT_RESOURCE_TYPE,"Material"), _SCS("set_material_override"), _SCS("get_material_override"));
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/cast_shadow"), _SCS("set_flag"), _SCS("get_flag"),FLAG_CAST_SHADOW);
@@ -234,6 +303,7 @@ void GeometryInstance::_bind_methods() {
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/billboard_y"), _SCS("set_flag"), _SCS("get_flag"),FLAG_BILLBOARD_FIX_Y);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/depth_scale"), _SCS("set_flag"), _SCS("get_flag"),FLAG_DEPH_SCALE);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/visible_in_all_rooms"), _SCS("set_flag"), _SCS("get_flag"),FLAG_VISIBLE_IN_ALL_ROOMS);
+ ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "geometry/use_baked_light"), _SCS("set_flag"), _SCS("get_flag"),FLAG_USE_BAKED_LIGHT);
ADD_SIGNAL( MethodInfo("visibility_changed"));
@@ -258,5 +328,7 @@ GeometryInstance::GeometryInstance() {
flags[FLAG_BILLBOARD_FIX_Y]=false;
flags[FLAG_DEPH_SCALE]=false;
flags[FLAG_VISIBLE_IN_ALL_ROOMS]=false;
+ baked_light_instance=NULL;
+
}