blender_functions
Remote functions for blender.
- xrfeitoria.utils.functions.blender_functions.apply_motion_data_to_actor(motion_data: List[Dict[str, Dict[str, float | List[float]]]], actor_name: str, is_first_frame_as_origin: bool = True) None[source]
Applies motion data to a given actor in Blender.
- Parameters:
motion_data (List[MotionFrame]) – A list of dictionaries containing motion data for the actor.
actor_name (str) – The name of the actor to apply the motion data to.
is_first_frame_as_origin (bool, optional) – Whether to set the first frame as the origin. Defaults to True.
- xrfeitoria.utils.functions.blender_functions.apply_shape_keys_to_mesh(shape_keys: List[Dict[str, float]], mesh_name: str) None[source]
Apply shape keys to the given mesh.
- Parameters:
shape_keys (List[Dict[str, float]]) – A list of dictionaries representing the shape keys and their values.
mesh_name (str) – Name of the mesh.
- xrfeitoria.utils.functions.blender_functions.check_sequence(seq_name: str) bool[source]
Check whether the sequence exists.
- Parameters:
seq_name (str) – Name of the sequence.
- Returns:
bool – True if the sequence exists.
- xrfeitoria.utils.functions.blender_functions.cleanup_unused()[source]
Cleanup all the unused data in the current blend file.
- xrfeitoria.utils.functions.blender_functions.enable_gpu(gpu_num: int = 1)[source]
Enable GPU in blender.
- Parameters:
gpu_num (int, optional) – Number of GPUs to use. Defaults to 1.
- xrfeitoria.utils.functions.blender_functions.export_vertices(export_path: str | Path, use_animation: bool = True) None[source]
Export vertices in the world space of all objects in the active scene to npz file, with animation (export N frame) if use_animation is True. export_path will be an npz file with a single key ‘verts’ which is a numpy array in shape of (N, V, 3), where N is the number of frames, V is the number of vertices.
- Parameters:
export_path (PathLike) – Path to export vertices. (Require a folder)
use_animation (bool, optional) – Export with animation. Defaults to True.
- xrfeitoria.utils.functions.blender_functions.get_all_object_in_current_level(obj_type: Literal['MESH', 'ARMATURE', 'CAMERA']) List[str][source]
Get all the objects in the current level.
- Parameters:
obj_type (Literal["MESH";, "ARMATURE";, "CAMERA";]) – Object type.
- Returns:
List[str] – List of object names.
- xrfeitoria.utils.functions.blender_functions.get_all_object_in_seq(seq_name: str, obj_type: Literal['MESH', 'ARMATURE', 'CAMERA']) List[str][source]
Get all the objects in the given sequence.
- Parameters:
seq_name (str) – Name of the sequence.
obj_type (Literal["MESH", "ARMATURE", "CAMERA"]) – Object type.
- Returns:
List[str] – List of object names.
- xrfeitoria.utils.functions.blender_functions.get_frame_range() Tuple[int, int][source]
Get the frame range of the active scene.
- Returns:
Tuple[int, int] – Start frame and End frame.
- xrfeitoria.utils.functions.blender_functions.get_keys_range() Tuple[int, int][source]
Get the max keyframe range of all the objects in the active scene.
- Returns:
Tuple[int, int] – Start frame and End frame.
- xrfeitoria.utils.functions.blender_functions.get_rotation_to_look_at(location: Tuple[float, float, float], target: Tuple[float, float, float]) Tuple[float, float, float][source]
Get the rotation of an object to look at another object.
- Parameters:
location (Vector) – Location of the object.
target (Vector) – Location of the target object.
- Returns:
Vector – Rotation of the object.
- xrfeitoria.utils.functions.blender_functions.import_file(file_path: str | Path) None[source]
Import file to blender. This function will not return an instance of the imported actor. The file type is determined by the file extension. Supported file types: fbx, obj, abc, ply, stl.
Note
For fbx file, only support binary format. ASCII format is not supported. Ref: https://docs.blender.org/manual/en/3.6/addons/import_export/scene_fbx.html#id4
- xrfeitoria.utils.functions.blender_functions.init_scene_and_collection(name: str, cleanup: bool = False) None[source]
Init the default scene and default collection.
- Parameters:
name (str) – Name of the default scene and default collection.
cleanup (bool, optional) – Clean up the all the scenes, collections and objects. Defaults to False.
- xrfeitoria.utils.functions.blender_functions.install_plugin(plugin_path: str | Path, plugin_name_blender: str | None = None)[source]
Install plugin in blender.
- Parameters:
path (PathLike) – Path to the plugin.
- xrfeitoria.utils.functions.blender_functions.is_background_mode(warning: bool = False) bool[source]
Check whether Blender is running in background mode.
- Returns:
bool – True if Blender is running in background mode.
- xrfeitoria.utils.functions.blender_functions.new_level(name: str) None[source]
Create a new level.
- Parameters:
name (str) – Name of the level.
- xrfeitoria.utils.functions.blender_functions.render_viewport(animation: bool = False) None[source]
Render the current viewport. Disable multiview when rendering, and restore it after rendering.
- Parameters:
animation (bool, optional) – Render animation. Defaults to False.
- xrfeitoria.utils.functions.blender_functions.save_blend(save_path: str | Path = None, pack: bool = False)[source]
Save the current blend file to the given path. If no path is given, save to the current blend file path.
- Parameters:
save_path (PathLike, optional) – Path to save the blend file. Defaults to None.
pack (bool, optional) – Automatically pack all external data into .blend file. Defaults to False.
- Raises:
Exception – Failed to set autopack.
- xrfeitoria.utils.functions.blender_functions.set_active_level(level_name: str)[source]
Sets the active level in XRFeitoria Blender Factory.
- Parameters:
level_name (str) – The name of the level to set as active. (e.g. ‘Scene’)
Example
>>> import xrfeitoria as xf >>> xf_runner = xf.init_blender() >>> xf_runner.utils.set_active_level('Scene') # Return to default level defined by blender
- xrfeitoria.utils.functions.blender_functions.set_env_color(color: Tuple[float, float, float, float], intensity: float = 1.0)[source]
Set the color of the environment light.
- Parameters:
color (Tuple[float, float, float, float]) – RGBA color of the environment light.
intensity (float, optional) – Intensity of the environment light. Defaults to 1.0.
- xrfeitoria.utils.functions.blender_functions.set_frame_current(frame: int) None[source]
Set current frame of the active scene.
- Parameters:
frame (int) – Frame number.