blenderproc.python.modules.main.GlobalStorage module¶
-
class
blenderproc.python.modules.main.GlobalStorage.
GlobalStorage
[source]¶ Bases:
object
- The GlobalStorage has two functions:
- It can store data over the boundaries of modules with the add(), set() and get() functions
- It keeps a global config, which can be used as a fallback strategy in the case a config value is used in many modules, for example the “output_dir”.
- To 1. you can save your own keys in the GlobalStorage to access them in a later module.
- For example you have a personal renderer or loader, which has attributes, which are independent of the scene and the objects so custom properties for those are not the way to go. In these instances you can use these functions.
Here is a list of all used global_storage_keys to avoid that your key is clashing with existing keys:
Parameter Description Type renderer_distance_end This key is saved by the Renderer during distance rendering and is used in the StereoGlobalMatchingWriter. string Please add all new keys you create to this list.
To 2. the global config is inited during the main.Initializer module, this means before that it is not possible to access keys from the global config, but it is possible to add keys, which can then be later accessed for that check: add_to_config_before_init(). It is usually not necessary that you will access the global config yourself as each Config checks automatically if the key is stored in the global config, if it was not defined in the current module. The checking order: Local module then the global config if both fail the default value is used, if there is none an Exception is thrown.
-
_add_to_global_config_at_init
= {}¶
-
_global_config
= None¶
-
_storage_dict
= {}¶
-
static
add
(key, value)[source]¶ Adds a key to the GlobalStorage this is independent of the global config, this can be used to store values over Module boundaries. Adding only works if there is not already a key like this in the GlobalStorage.
For example the distance renderer sets the value “distance_end” during the rendering process, a module which is executed afterwards can then with get() access this value.
These values can be added before the global config was inited as they do not depend on each other.
Parameters:
-
static
add_to_config_before_init
(key, value)[source]¶ Adds values to the global config before the GlobalStorage was inited, these value can only be accessed after the GlobalStorage was inited.
Parameters:
-
static
get
(key)[source]¶ Returns a value from the GlobalStorage, please check add() and set() for more information
Parameters: key ( str
) – for which a value is searchedReturn type: Any
Returns: value for the key
-
static
get_global_config
()[source]¶ Returns the global config, this function should be used with care!
There are only a few cases where this function should be called, please read the description at the top and make sure you have to call this function.
Return type: Config Returns: the global config as a utility.Config object
-
static
has_param
(key)[source]¶ Checks if this key is in the global config not in the GlobalStorage!
Parameters: key ( str
) – which should be checkedReturn type: bool
Returns: True if the key is in the global config
-
static
init_global
(global_config)[source]¶ Inits the global config with the given config, global_config should be of type blenderproc.python.Config
Adds a key value pairs from add_to_global_config_at_init
Parameters: global_config (Config) – the config to use
-
static
is_in_storage
(key)[source]¶ Checks if a key is in the GlobalStorage
Parameters: key ( str
) – for which a value is searchedReturn type: bool
Returns: True if the key is in the storage
-
static
set
(key, value)[source]¶ Sets a key in the GlobalStorage this is independent of the global config, this can be used to store values over Module boundaries. Setting always works and overwrites existing keys
For example the distance renderer sets the value “renderer_distance_end” during the rendering process, a module which is executed afterwards can then with get() access this value.
These values can be added before the global config was inited as they do not depend on each other.
Parameters: