threedb.rendering.base_renderer

An abstract class of a Renderer which must be subclassed when adding new renderers. See here for details.

class threedb.rendering.base_renderer.RenderEnv

Bases: abc.ABC

class threedb.rendering.base_renderer.RenderObject

Bases: abc.ABC

class threedb.rendering.base_renderer.BaseRenderer(root_dir: str, render_settings: Dict[str, Any], env_extensions: List[str] = [])

Bases: abc.ABC

NAME: str = 'BaseRenderer'
KEYS: List[str] = ['rgb']
__init__(root_dir: str, render_settings: Dict[str, Any], env_extensions: List[str] = [])None

Initialize self. See help(type(self)) for accurate signature.

abstract static enumerate_models(search_dir: str)List[str]

Given a root folder, returns all valid .blend files (according to a per-renderer convention).

abstract static enumerate_environments(search_dir: str)List[str]

Given a root folder, returns all files in root/blender_environments/ which have extensions in ENV_EXTENSIONS above.

abstract declare_outputs()Dict[str, Tuple[List[int], str]]

This function declares what the output of render() will be, based on the renderer settings. Returns a dictionary mapping keys to (dtype, size) tuples—the output of render() is string-to-tensor dictionary whose tensors will be checked against the return value of this function for both size and type.

A basic implementation which suffices for most applications is provided in the abstract class threedb.rendering.base_renderer.BaseRenderer.

abstract load_model(model: str)threedb.rendering.base_renderer.RenderObject

Given a root directory and a model id, loads the model into the renderer and returns the corresponding object.

abstract get_model_uid(model: threedb.rendering.base_renderer.RenderObject)str

Given an 3D model, return its UID as assigned by the renderer.

abstract load_env(env: str)Optional[threedb.rendering.base_renderer.RenderEnv]

Given a root folder and environment ID, load the environment into the renderer. If needed, returns an environment object, to be passed back to the render() function.

abstract setup_render(model: Optional[threedb.rendering.base_renderer.RenderObject], env: Optional[threedb.rendering.base_renderer.RenderEnv])None

Perform setup operations for rendering. Called only when the model or environment being rendered changes—otherwise, only render() will be called. No return value.

abstract get_context_dict(model_uid: str, object_class: int)Dict[str, Any]

Returns, for a given model id, a “context” dictionary; this context will be passed to the controls (see :class:threedb.controls.base_control.PreProcessControl for more info).

Parameters
  • model_uid (str) – The ID of the model being rendered.

  • object_class (int) – The class label for the model.

Returns

A context dictionary

Return type

Dict[str, Any]

abstract render(model_uid: str, loaded_model: threedb.rendering.base_renderer.RenderObject, loaded_env: threedb.rendering.base_renderer.RenderEnv)Dict[str, torch.Tensor]

[summary]

Parameters
  • model_uid (str) – Render a model and environment. You can assume that setup_render() has been called with the relevant model and object in context. This function should also handle applying the pre and post-processing controls.

  • loaded_model (RenderObject) – The model that was most recently loaded and passed to setup_render.

  • loaded_env (RenderEnv) – the environment that was most recently loaded and passed to setup_render.

Returns

A dictionary mapping result keys (e.g., ‘rgb’, ‘segmentation’, etc.) to PyTorch tensor outputs.

Return type

Dict[str, ch.Tensor]