Skip to content

ObjectInstanceRandomizer ​

ObjectInstanceRandomizer samples how many instances of each registered model are active in a scene.

python
from telekinesis.illusion.randomizer.randomizer_node import (
    ObjectInstanceRandomizer,
)

node = ObjectInstanceRandomizer(
    counts={"gear": (1, 3), "pipe": (0, 1)},
    min_num_total_objects=2,
    max_num_total_objects=4,
)

Parameters ​

ParameterTypeDescription
countsMapping[str, tuple[int, int]]Inclusive minimum and maximum for each registered model name. The maxima determine the required prepared pool capacity.
min_num_total_objectsint | NoneOptional lower bound across all selected models. Defaults to the sum of per-model minima.
max_num_total_objectsint | NoneOptional upper bound across all selected models. Defaults to the sum of per-model maxima.

Bounds are validated when the node is constructed. Every sampled model receives at least its minimum, and the total stays inside both the per-model and total bounds. Enabled instance nodes declare their required capacity before Scene.prepare() imports geometry.

Multiple instance nodes may target the same model. Their capacities are additive and they activate disjoint prepared instances.

Usage ​

python
randomizer.add_randomizer(
    ObjectInstanceRandomizer(
        counts={"part_1": (1, 3), "part_2": (1, 1)},
        min_num_total_objects=2,
        max_num_total_objects=4,
    ),
    "instance_randomizer_objects",
)

Run instance selection before pose, material, light, and camera nodes so later nodes see the active objects for the current sample.

Next Steps ​