diff options
Diffstat (limited to 'scene/3d/world_environment.cpp')
-rw-r--r-- | scene/3d/world_environment.cpp | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index c8d7382e81..5e73e460ed 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -29,83 +29,113 @@ /*************************************************************************/ #include "world_environment.h" -#include "scene/main/viewport.h" -void WorldEnvironment::_notification(int p_what) { - - if (p_what == Spatial::NOTIFICATION_ENTER_WORLD || p_what == Spatial::NOTIFICATION_ENTER_TREE) { +#include "scene/main/window.h" +void WorldEnvironment::_notification(int p_what) { + if (p_what == Node3D::NOTIFICATION_ENTER_WORLD || p_what == Node3D::NOTIFICATION_ENTER_TREE) { if (environment.is_valid()) { - if (get_viewport()->find_world()->get_environment().is_valid()) { + if (get_viewport()->find_world_3d()->get_environment().is_valid()) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } - get_viewport()->find_world()->set_environment(environment); - add_to_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + get_viewport()->find_world_3d()->set_environment(environment); + add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } - } else if (p_what == Spatial::NOTIFICATION_EXIT_WORLD || p_what == Spatial::NOTIFICATION_EXIT_TREE) { + if (camera_effects.is_valid()) { + if (get_viewport()->find_world_3d()->get_camera_effects().is_valid()) { + WARN_PRINT("World already has a camera effects (Another WorldEnvironment?), overriding."); + } + get_viewport()->find_world_3d()->set_camera_effects(camera_effects); + add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + } + + } else if (p_what == Node3D::NOTIFICATION_EXIT_WORLD || p_what == Node3D::NOTIFICATION_EXIT_TREE) { + if (environment.is_valid() && get_viewport()->find_world_3d()->get_environment() == environment) { + get_viewport()->find_world_3d()->set_environment(Ref<Environment>()); + remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + } - if (environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { - get_viewport()->find_world()->set_environment(Ref<Environment>()); - remove_from_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + if (camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() == camera_effects) { + get_viewport()->find_world_3d()->set_camera_effects(Ref<CameraEffects>()); + remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } } } void WorldEnvironment::set_environment(const Ref<Environment> &p_environment) { - - if (is_inside_tree() && environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { - get_viewport()->find_world()->set_environment(Ref<Environment>()); - remove_from_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + if (is_inside_tree() && environment.is_valid() && get_viewport()->find_world_3d()->get_environment() == environment) { + get_viewport()->find_world_3d()->set_environment(Ref<Environment>()); + remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); //clean up } environment = p_environment; if (is_inside_tree() && environment.is_valid()) { - if (get_viewport()->find_world()->get_environment().is_valid()) { + if (get_viewport()->find_world_3d()->get_environment().is_valid()) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } - get_viewport()->find_world()->set_environment(environment); - add_to_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id())); + get_viewport()->find_world_3d()->set_environment(environment); + add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); } update_configuration_warning(); } Ref<Environment> WorldEnvironment::get_environment() const { - return environment; } -String WorldEnvironment::get_configuration_warning() const { +void WorldEnvironment::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { + if (is_inside_tree() && camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() == camera_effects) { + get_viewport()->find_world_3d()->set_camera_effects(Ref<CameraEffects>()); + remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + //clean up + } + camera_effects = p_camera_effects; + if (is_inside_tree() && camera_effects.is_valid()) { + if (get_viewport()->find_world_3d()->get_camera_effects().is_valid()) { + WARN_PRINT("World already has an camera_effects (Another WorldEnvironment?), overriding."); + } + get_viewport()->find_world_3d()->set_camera_effects(camera_effects); + add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id())); + } + + update_configuration_warning(); +} + +Ref<CameraEffects> WorldEnvironment::get_camera_effects() const { + return camera_effects; +} + +String WorldEnvironment::get_configuration_warning() const { if (!environment.is_valid()) { return TTR("WorldEnvironment requires its \"Environment\" property to contain an Environment to have a visible effect."); } - if (/*!is_visible_in_tree() ||*/ !is_inside_tree()) + if (!is_inside_tree()) { return String(); + } List<Node *> nodes; - get_tree()->get_nodes_in_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id()), &nodes); + get_tree()->get_nodes_in_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()), &nodes); if (nodes.size() > 1) { return TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes)."); } - // Commenting this warning for now, I think it makes no sense. If anyone can figure out what its supposed to do, feedback welcome. Else it should be deprecated. - //if (environment.is_valid() && get_viewport() && !get_viewport()->get_camera() && environment->get_background() != Environment::BG_CANVAS) { - // return TTR("This WorldEnvironment is ignored. Either add a Camera (for 3D scenes) or set this environment's Background Mode to Canvas (for 2D scenes)."); - //} - return String(); } void WorldEnvironment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_environment", "env"), &WorldEnvironment::set_environment); ClassDB::bind_method(D_METHOD("get_environment"), &WorldEnvironment::get_environment); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment"); + + ClassDB::bind_method(D_METHOD("set_camera_effects", "env"), &WorldEnvironment::set_camera_effects); + ClassDB::bind_method(D_METHOD("get_camera_effects"), &WorldEnvironment::get_camera_effects); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_effects", PROPERTY_HINT_RESOURCE_TYPE, "CameraEffects"), "set_camera_effects", "get_camera_effects"); } WorldEnvironment::WorldEnvironment() { |