forked from godotengine/godot
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dummy implementation of EnvironmentRoot
- Loading branch information
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="EnvironmentRoot" inherits="Node" version="3.3"> | ||
<brief_description> | ||
Default environment properties for the entire scene (post-processing effects, lighting and background settings). | ||
</brief_description> | ||
<description> | ||
The [EnvironmentRoot] node is used to configure the default [Environment] for the scene. | ||
The parameters defined in the [EnvironmentRoot] can be overridden by an [Environment] node set on the current [Camera]. Additionally, only one [EnvironmentRoot] may be instanced in a given scene at a time. | ||
The [EnvironmentRoot] allows the user to specify default lighting parameters (e.g. ambient lighting), various post-processing effects (e.g. SSAO, DOF, Tonemapping), and how to draw the background (e.g. solid color, skybox). Usually, these are added in order to improve the realism/color balance of the scene. | ||
</description> | ||
<tutorials> | ||
<link title="Environment and post-processing">https://docs.godotengine.org/en/3.3/tutorials/3d/environment_and_post_processing.html</link> | ||
<link title="3D Material Testers Demo">https://godotengine.org/asset-library/asset/123</link> | ||
<link title="2D HDR Demo">https://godotengine.org/asset-library/asset/110</link> | ||
<link title="Third Person Shooter Demo">https://godotengine.org/asset-library/asset/678</link> | ||
</tutorials> | ||
<methods> | ||
</methods> | ||
<members> | ||
<member name="environment" type="Environment" setter="set_environment" getter="get_environment"> | ||
The [Environment] resource used by this [EnvironmentRoot], defining the default properties. | ||
</member> | ||
</members> | ||
<constants> | ||
</constants> | ||
</class> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/****************************************************************************/ | ||
/* environment_root.cpp */ | ||
/****************************************************************************/ | ||
/* !!!! NOTICE !!!! */ | ||
/* This type is a copy of the WorldEnvironment type */ | ||
/* This type is not a valid implementation of the BSE EnvironmentRoot type */ | ||
/****************************************************************************/ | ||
|
||
#include "environment_root.h" | ||
#include "scene/main/viewport.h" | ||
|
||
void EnvironmentRoot::_notification(int p_what) { | ||
|
||
if (p_what == Spatial::NOTIFICATION_ENTER_WORLD || p_what == Spatial::NOTIFICATION_ENTER_TREE) { | ||
|
||
if (environment.is_valid()) { | ||
if (get_viewport()->find_world()->get_environment().is_valid()) { | ||
WARN_PRINT("World already has an environment (Another EnvironmentRoot?), overriding."); | ||
} | ||
get_viewport()->find_world()->set_environment(environment); | ||
add_to_group("_environment_root_" + itos(get_viewport()->find_world()->get_scenario().get_id())); | ||
} | ||
|
||
} else if (p_what == Spatial::NOTIFICATION_EXIT_WORLD || p_what == Spatial::NOTIFICATION_EXIT_TREE) { | ||
|
||
if (environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { | ||
get_viewport()->find_world()->set_environment(Ref<Environment>()); | ||
remove_from_group("_environment_root_" + itos(get_viewport()->find_world()->get_scenario().get_id())); | ||
} | ||
} | ||
} | ||
|
||
void EnvironmentRoot::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("_environment_root_" + itos(get_viewport()->find_world()->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()) { | ||
WARN_PRINT("World already has an environment (Another EnvironmentRoot?), overriding."); | ||
} | ||
get_viewport()->find_world()->set_environment(environment); | ||
add_to_group("_environment_root_" + itos(get_viewport()->find_world()->get_scenario().get_id())); | ||
} | ||
|
||
update_configuration_warning(); | ||
} | ||
|
||
Ref<Environment> EnvironmentRoot::get_environment() const { | ||
|
||
return environment; | ||
} | ||
|
||
String EnvironmentRoot::get_configuration_warning() const { | ||
|
||
String warning = Node::get_configuration_warning(); | ||
if (!environment.is_valid()) { | ||
if (warning != String()) { | ||
warning += "\n\n"; | ||
} | ||
warning += TTR("EnvironmentRoot requires its \"Environment\" property to contain an Environment to have a visible effect."); | ||
return warning; | ||
} | ||
|
||
if (/*!is_visible_in_tree() ||*/ !is_inside_tree()) | ||
return String(); | ||
|
||
List<Node *> nodes; | ||
get_tree()->get_nodes_in_group("_environment_root_" + itos(get_viewport()->find_world()->get_scenario().get_id()), &nodes); | ||
|
||
if (nodes.size() > 1) { | ||
if (warning != String()) { | ||
warning += "\n\n"; | ||
} | ||
warning += TTR("Only one EnvironmentRoot 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 EnvironmentRoot is ignored. Either add a Camera (for 3D scenes) or set this environment's Background Mode to Canvas (for 2D scenes)."); | ||
//} | ||
|
||
return warning; | ||
} | ||
|
||
void EnvironmentRoot::_bind_methods() { | ||
|
||
ClassDB::bind_method(D_METHOD("set_environment", "env"), &EnvironmentRoot::set_environment); | ||
ClassDB::bind_method(D_METHOD("get_environment"), &EnvironmentRoot::get_environment); | ||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment"); | ||
} | ||
|
||
EnvironmentRoot::EnvironmentRoot() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/****************************************************************************/ | ||
/* environment_root.h */ | ||
/****************************************************************************/ | ||
/* !!!! NOTICE !!!! */ | ||
/* This type is a copy of the WorldEnvironment type */ | ||
/* This type is not a valid implementation of the BSE EnvironmentRoot type */ | ||
/****************************************************************************/ | ||
|
||
#ifndef SCENARIO_FX_H2 | ||
#define SCENARIO_FX_H2 | ||
|
||
#include "scene/3d/spatial.h" | ||
|
||
class EnvironmentRoot : public Node { | ||
|
||
GDCLASS(EnvironmentRoot, Node); | ||
|
||
Ref<Environment> environment; | ||
|
||
protected: | ||
void _notification(int p_what); | ||
static void _bind_methods(); | ||
|
||
public: | ||
void set_environment(const Ref<Environment> &p_environment); | ||
Ref<Environment> get_environment() const; | ||
|
||
String get_configuration_warning() const; | ||
|
||
EnvironmentRoot(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters