blenderproc.python.utility.Utility module¶
-
class
blenderproc.python.utility.Utility.
BlockStopWatch
(block_name)[source]¶ Bases:
object
Calls a print statement to mark the start and end of this block and also measures execution time.
Usage: with BlockStopWatch(‘text’):
-
class
blenderproc.python.utility.Utility.
KeyFrame
(frame)[source]¶ Bases:
object
-
static
is_any_active
()[source]¶ Returns whether the current execution point is surrounded by a KeyFrame context manager.
Return type: bool
Returns: True, if there is at least one surrounding KeyFrame context manager
-
state
= <blenderproc.python.utility.Utility.KeyFrameState object>¶
-
static
-
class
blenderproc.python.utility.Utility.
NumpyEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
A json encoder that is also capable of serializing numpy arrays
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
blenderproc.python.utility.Utility.
UndoAfterExecution
(check_point_name=None, perform_undo_op=True)[source]¶ Bases:
object
Reverts all changes done to the blender project inside this block.
Usage: with UndoAfterExecution():
-
class
blenderproc.python.utility.Utility.
Utility
[source]¶ Bases:
object
-
static
add_output_entry
(output)[source]¶ Registers the given output in the scene’s custom properties
Parameters: output ( Dict
[str
,str
]) – A dict containing key and path of the new output type.
-
blenderproc_root
= '/home/wink_do/PycharmProjects/BlenderProcPublic/blenderproc/python/utility/../../..'¶
-
static
build_provider
(name, parameters)[source]¶ Builds up providers like sampler or getter.
It first builds the config and then constructs the required provider.
Parameters: Return type: Returns: The constructed provider.
-
static
build_provider_based_on_config
(config)[source]¶ Builds up the provider using the parameters described in the given config.
The given config should follow the following scheme:
{ "provider": "<name of provider class>" "parameters": { <provider parameters> } }
Parameters: config ( Config
) – A Configuration object or a dict containing the configuration data.Return type: Provider Returns: The constructed provider.
-
static
find_registered_output_by_key
(key)[source]¶ Returns the output which was registered with the given key.
Parameters: key ( str
) – The output key to look for.Return type: Optional
[Any
]Returns: The dict containing all information registered for that output. If no output with the given key exists, None is returned.
-
static
generate_equidistant_values
(num, space_size_per_dimension)[source]¶ This function generates N equidistant values in a 3-dim space and returns num of them.
Every dimension of the space is limited by [0, K], where K is the given space_size_per_dimension. Basically it splits a cube of shape K x K x K in to N smaller blocks. Where, N = cube_length^3 and cube_length is the smallest integer for which N >= num.
If K is not a multiple of N, then the sum of all blocks might not fill up the whole K ** 3 cube.
Parameters: Return type:
-
static
get_current_version
()[source]¶ Gets the git commit hash.
Return type: Optional
[str
]Returns: a string, the BlenderProc version, or None if unavailable
-
static
get_node_connected_to_the_output_and_unlink_it
(material)[source]¶ Searches for the OutputMaterial in the given material and finds the connected node to it, removes the connection between this node and the output and returns this node and the material_output
Parameters: material ( Material
) – Material on which this operation should be performedReturn type: Tuple
[Optional
[Node
],Node
]
-
static
get_nodes_created_in_func
(nodes, created_in_func)[source]¶ Returns all nodes which are created in the given function
Parameters: Return type: List
[Node
]Returns: The list of nodes with the given type.
-
static
get_nodes_with_type
(nodes, node_type, created_in_func='')[source]¶ Returns all nodes which are of the given node_type
Parameters: Return type: List
[Node
]Returns: list of nodes, which belong to the type
-
static
get_registered_outputs
()[source]¶ Returns a list of outputs which were registered.
Return type: List
[Dict
[str
,Any
]]Returns: A list of dicts containing all information registered for the outputs.
-
static
get_temporary_directory
()[source]¶ Return type: str
Returns: default temporary directory, shared memory if it exists
-
static
get_the_one_node_with_type
(nodes, node_type, created_in_func='')[source]¶ Returns the one nodes which is of the given node_type
This function will only work if there is only one of the nodes of this type.
Parameters: Return type: Node
Returns: node of the node type
-
static
hex_to_rgba
(hex_value)[source]¶ Converts the given hex string to rgba color values.
Parameters: hex_value ( str
) – The hex string, describing rgb.Return type: List
[float
]Returns: The rgba color, in form of a list. Values between 0 and 1.
-
static
initialize_modules
(module_configs)[source]¶ Initializes the modules described in the given configuration.
Example for module_configs:
[{ "module": "base.ModuleA", "config": {...} }, ...]
If you want to execute a certain module several times, add the amount_of_repetions on the same level as the module name:
[{ "module": "base.ModuleA", "config": {...}, "amount_of_repetitions": 3 }, ...]
Here the name contains the path to the module class, starting from inside the src directory.
Be aware that all attributes stored in the GlobalStorage are also accessible here, even though they are not copied into the new config.
Parameters: module_configs ( List
[Union
[Dict
[str
,Any
],str
]]) – A list of dicts, each one describing one module.Return type: List
[Forwardref
]Returns: a list of initialized modules
-
static
insert_keyframe
(obj, data_path, frame=None)[source]¶ Inserts a keyframe for the given object and data path at the specified frame number:
Parameters:
-
static
insert_node_instead_existing_link
(links, source_socket, new_node_dest_socket, new_node_src_socket, dest_socket)[source]¶ Replaces the node between source_socket and dest_socket with a new node.
Before: source_socket -> dest_socket After: source_socket -> new_node_dest_socket and new_node_src_socket -> dest_socket
Parameters: - links (
NodeLinks
) – The collection of all links. - source_socket (
NodeSocket
) – The source socket. - new_node_dest_socket (
NodeSocket
) – The new destination for the link starting from source_socket. - new_node_src_socket (
NodeSocket
) – The new source for the link towards dest_socket. - dest_socket (
NodeSocket
) – The destination socket
- links (
-
static
map_back_from_equally_spaced_equidistant_values
(values, num_splits_per_dimension, space_size_per_dimension)[source]¶ Maps the given values back to their original indices.
This function calculates for each given value the corresponding index in the list of values created by the generate_equidistant_values() method.
Parameters: - values (
ndarray
) – An array of shape [M, N, 3]; - num_splits_per_dimension (
int
) – The number of splits per dimension that were made when building up the equidistant values.
Return type: ndarray
Returns: A 2-dim array of indices corresponding to the given values.
- values (
-
static
merge_dicts
(source, destination)[source]¶ Recursively copies all key value pairs from src to dest (Overwrites existing)
Parameters: Return type: Returns: The modified destination dict.
-
static
output_already_registered
(output, output_list)[source]¶ Checks if the given output entry already exists in the list of outputs, by checking on the key and path. Also throws an error if it detects an entry having the same key but not the same path and vice versa since this is ambiguous.
Parameters: Return type: Returns: bool indicating whether it already exists.
-
static
read_suncg_lights_windows_materials
()[source]¶ Returns the lights dictionary and windows list which contains their respective materials
Return type: Tuple
[Dict
[str
,Tuple
[List
[str
],List
[str
]]],List
[str
]]Returns: dictionary of lights’ and list of windows’ materials
-
static
register_output
(output_dir, prefix, key, suffix, version, unique_for_camposes=True)[source]¶ Registers new output type using configured key and file prefix.
Parameters: - output_dir (
str
) – The output directory containing the generated files. - prefix (
str
) – The default prefix of the generated files. - key (
str
) – The default key which should be used for storing the output in merged file. - suffix (
str
) – The suffix of the generated files. - version (
str
) – The version number which will be stored at key_version in the final merged file. - unique_for_camposes (
bool
) – True if the output to be registered is unique for all the camera poses
- output_dir (
-
static
replace_output_entry
(output)[source]¶ Replaces the output in the scene’s custom properties with the given one
Parameters: output ( Dict
[str
,str
]) – A dict containing key and path of the new output type.
-
static
rgb_to_hex
(rgb)[source]¶ Converts the given rgb to hex values.
Parameters: rgb ( Tuple
[int
,int
,int
]) – tuple of three with rgb integers.Return type: str
Returns: Hex string.
-
temp_dir
= '/home/wink_do/PycharmProjects/BlenderProcPublic/docs/examples/debugging/temp'¶
-
used_temp_id
= None¶
-
static
-
blenderproc.python.utility.Utility.
num_frames
()[source]¶ Returns the currently total number of registered frames.
Return type: int
Returns: The number of frames.
-
blenderproc.python.utility.Utility.
reset_keyframes
()[source]¶ Removes registered keyframes from all objects and resets frame_start and frame_end
Return type: None
-
blenderproc.python.utility.Utility.
resolve_path
(path)[source]¶ Returns an absolute path. If given path is relative, current working directory is put in front.
Parameters: path ( str
) – The path to resolve.Return type: str
Returns: The absolute path.
-
blenderproc.python.utility.Utility.
resolve_resource
(relative_resource_path)[source]¶ Returns an absolute path to the given BlenderProc resource.
Parameters: relative_resource_path ( str
) – The relative path inside the BlenderProc resource folder.Return type: str
Returns: The absolute path.