Skip to content

Custom Nodes

Any other axis of variation can be added by subclassing RandomizerNode and implementing randomize(). The method receives the Context and mutates it in place, exactly as the built-in nodes do.

python
import numpy as np

from telekinesis.illusion.randomizer.randomizer_node import RandomizerNode
from telekinesis.illusion.core.context import Context

class ScaleRandomizer(RandomizerNode):
    def __init__(self, target_objects, scale_range):
        self.target_objects = target_objects
        self.scale_range = scale_range

    def randomize(self, context: Context) -> None:
        for name, obj in context.get_objects().items():
            if name.startswith(tuple(self.target_objects)) and not obj.is_hidden():
                obj.set_scale(np.random.uniform(*self.scale_range))

randomizer.add_randomizer(
    randomizer_node=ScaleRandomizer(["part_1"], (0.9, 1.1)),
    node_name="scale_randomizer",
)

A custom node left without a node_config runs in STAGE_DEFAULT, so it executes in every pass. Assign it a stage to have it participate in stage-scoped re-randomization.

Next Steps