Skip to content

Randomizer

The randomizer tree: a directed acyclic graph of nodes, each changing one aspect of the scene. Nodes are executed in dependency order, each receiving the Context.

Import

python
from telekinesis.illusion.randomizer.randomizer import Randomizer, EdgeConfig
from telekinesis.illusion.randomizer.randomizer_node import NodeConfig

Constructor

python
randomizer = Randomizer()

randomizer.add_randomizer(
    randomizer_node,     # a RandomizerNode
    node_name,           # unique node name
    node_config=None,    # NodeConfig
    edge_config=None,    # EdgeConfig
)

add_randomizer() appends the node to the chain: the first node becomes the start of the graph, and every subsequent node is added as a successor of the previous one. Execution order is recomputed on every randomize() call using a topological sort, so nodes always run in dependency order.

Methods

MethodDescription
add_randomizer(randomizer_node, node_name, node_config=None, edge_config=None)Append a node to the chain.
add_node(randomizer_node, name, node_config=None)Register a node without connecting it.
add_edge(from_node_name, to_node_name, edge_config=None)Connect two registered nodes.
get_randomizer_node(node_name)The node registered under node_name, or None.
replace_randomizer(node_name, randomizer_node)Swap a node's implementation, leaving the graph topology and node config untouched.
get_node_stages()The stage each registered node belongs to, keyed by node name.
randomize(context, stages=None)Execute the tree over context.

replace_randomizer() is what interactive tools use to re-tune a node's parameters between runs without rebuilding the scene. The Blender extension relies on it for live preview.

NodeConfig

Per-node execution metadata, passed as node_config.

FieldTypeDefaultDescription
enabledboolTrueWhether the node runs at all. Disabled nodes are skipped.
stagestrSTAGE_DEFAULTThe stage this node belongs to (see below).
priorityint0Reserved for ordering within a stage.
seed_keystr | NoneNoneReserved for per-node seeding.
apply_probfloat1.0Reserved for probabilistic application.
max_triesint1Reserved for node-level retries.
on_failurestr"raise"Reserved failure behavior: "raise", "skip_node", or "skip_sample".
profileboolFalseReserved for per-node profiling.

EdgeConfig currently carries a single enabled flag for an edge.

Stages

Stages group nodes by which part of the scene they change, so a caller can re-run only part of the tree.

StageConstantCovers
"composition"STAGE_COMPOSITIONWhich and how many instances are visible.
"pose"STAGE_POSEWhere the visible objects are placed.
"appearance"STAGE_APPEARANCEMaterials and the background HDRI.
"camera"STAGE_CAMERACamera pose sampling.
"default"STAGE_DEFAULTAssigned when a node opts into no stage. Never filtered out.

A node left at STAGE_DEFAULT runs in every pass, so a node that does not opt into a stage is never skipped by accident.

python
from telekinesis.illusion.randomizer.randomizer_node import (
    NodeConfig,
    STAGE_POSE,
    STAGE_CAMERA,
)

randomizer.add_randomizer(
    randomizer_node=object_pose_randomizer,
    node_name="pose_randomizer",
    node_config=NodeConfig(stage=STAGE_POSE),
)

# Re-sample geometry only: poses and camera, keeping materials and selection
randomizer.randomize(context, stages={STAGE_POSE, STAGE_CAMERA})

# A full generation run passes no stages, so everything executes
randomizer.randomize(context)

Next Steps