Skip to content

ObjectPoseRandomizer

Samples 6-DoF poses for the visible target objects, rejecting poses that collide.

python
from telekinesis.illusion.randomizer.randomizer_node import ObjectPoseRandomizer

ObjectPoseRandomizer(
    pose_sampling_function,       # callable applied to each object
    target_objects=[],            # model names to place
    max_tries=10,                 # collision-free attempts per object
    sample_on_surface=None,       # name of a surface object
    surface_name_resolver=None,   # callable resolving that name at runtime
)

Parameters

ParameterTypeDescription
pose_sampling_functionCallable[[Object], None]Sets the location and rotation of the object passed to it. Called once per attempt.
target_objectslist[str]Names of the models to place. Empty places every visible object in the scene.
max_triesintAttempts to place an object without collision before it is hidden for the current scene.
sample_on_surfacestr | NoneName of the object whose surface the poses are sampled on, for example a bin.
surface_name_resolverCallable[[Context], str] | NoneResolves the surface name from the context at randomization time. Used when the surface differs per scene, and only consulted when sample_on_surface is None.

The sampling function defines the distribution; the node handles collision checking. When an object cannot be placed collision-free within max_tries, it is hidden for that scene, its rigid body is disabled, and it is removed from the visible objects – so the annotations never reference an object that is not there.

When a surface is given, poses are sampled onto it with additional spacing and ray-cast checks, and objects are dropped onto the surface geometry. Combine this with simulate_physics=True for realistic settling.

Usage

python
import numpy as np
from telekinesis.illusion.types.object import Object

def sample_pose(obj: Object):
    obj.set_location(np.random.uniform((-0.1, -0.1, 0.1), (0.1, 0.1, 0.1)))
    obj.set_rotation(np.random.uniform((-180, -180, -180), (180, 180, 180)))

randomizer.add_randomizer(
    randomizer_node=ObjectPoseRandomizer(
        pose_sampling_function=sample_pose,
        target_objects=["part_1", "part_2"],
    ),
    node_name="pose_randomizer",
)

Next Steps