Skip to content

ObjectInstanceRandomizer

Samples how many instances of each model are visible in the scene, and reveals them.

python
from telekinesis.illusion.randomizer.randomizer_node import ObjectInstanceRandomizer

ObjectInstanceRandomizer(
    target_objects=[],            # model names to randomize
    min_num_total_objects=None,   # lower bound across all targets
    max_num_total_objects=None,   # upper bound across all targets
)

Parameters

ParameterTypeDescription
target_objectslist[str]Names of the models whose instance count is randomized.
min_num_total_objectsint | NoneMinimum number of visible objects across all targets. None uses the sum of each model's min_number_instances.
max_num_total_objectsint | NoneMaximum number of visible objects across all targets. None uses the sum of each model's max_number_instances, and the value is capped at that sum in any case.

A total is drawn uniformly between the two bounds. Each model first receives its own minimum, then the remaining slots are distributed across the models with the lowest fill ratio, so clutter stays balanced rather than concentrating on one part. Revealed instances also get their rigid body enabled, so they participate in the physics simulation.

Raises a ValueError when the minimum exceeds the maximum, and a RuntimeError when target_objects is empty.

Usage

python
randomizer.add_randomizer(
    randomizer_node=ObjectInstanceRandomizer(
        target_objects=["part_1", "part_2"],
        min_num_total_objects=2,
        max_num_total_objects=4,
    ),
    node_name="instance_randomizer_objects",
)

Instance randomization runs first in the tree, because every later node only acts on the objects that are actually visible.

Next Steps