Skip to content

Context

The scene state shared by every randomizer node: registered models, categories, materials, background, and camera. telekinesis-illusion separates what is in the scene from how the scene varies – the Context is the first half.

Import

python
from telekinesis.illusion.core.context import Context

Constructor

python
context = Context(
    auto_config=True,    # pick a default background HDRI
    camera_config=None,  # CameraConfig, or None for defaults
    asset_dir=None,      # directory holding models/, hdris/, materials/
)
ParameterTypeDescription
auto_configboolConfigure the scene for default generation.
camera_configCameraConfig | NoneCamera intrinsics and image resolution. None uses the defaults.
asset_dirstr | Path | NoneDirectory holding models/, hdris/, and materials/. None resolves the bundled default asset directory.

Creating a Context initializes BlenderProc, so a process holds exactly one scene at a time.

Registering Models

add_model() loads a 3D model, assigns it a COCO category, and pre-creates linked duplicates so instance counts can be randomized without reloading geometry.

python
context.add_model(
    model_path,                   # path to the model file
    object_name,                  # unique name within the scene
    category_name=None,           # COCO category name
    category_id=None,             # COCO category id
    min_number_instances=1,
    max_number_instances=1,
    active_in_simulation=False,   # participates in physics
    collision_shape="CONVEX_HULL",  # "CONVEX_HULL" | "MESH"
    scale=1.0,
    preprocess_model=True,
)
ParameterTypeDescription
model_pathstrPath to the 3D model file on disk.
object_namestrUnique name within the scene. Instances are keyed <object_name>_INSTANCE_<n>.
category_namestr | NoneCOCO category name. Defaults to object_name. Use "distractor" together with category_id=None to exclude the model from the annotations.
category_idint | NoneExplicit COCO category id. Assigned automatically when omitted. Several models may share one id to fold multiple meshes into a single class.
min_number_instancesintLower bound on visible instances per scene.
max_number_instancesintUpper bound on visible instances per scene. Determines how many linked duplicates are created.
active_in_simulationboolWhether the model participates in the physics simulation. Containers are typically False.
collision_shapestrCollider type: "CONVEX_HULL" for parts, "MESH" for concave geometry such as bins.
scalefloat | np.ndarrayUniform or per-axis scale applied on import.
preprocess_modelboolWhether to run import-time preprocessing.

Object names must be unique. Registering the same model twice raises a ValueError – increase max_number_instances instead. Category ids and names are kept in a strict one-to-one mapping; providing a combination that conflicts with an existing mapping also raises a ValueError.

Reading the Scene

MethodReturns
get_objects()All registered instances, keyed by instance name.
get_objects_by_name(name)The instance, or the list of instances, whose name contains name.
get_object_group(object_name)Every instance of the model registered under object_name.
get_visible_object_names()Names of the objects currently visible in the scene.
get_camera()The Camera used for rendering.
get_background()The scene Background.
get_categories()The category-id to category-name mapping.
get_asset_dir()The resolved asset directory.

Next Steps