MaterialRandomizer
SUMMARY
Gives the target models a new material in every scene: either a registered PBR texture set (selected by group or name) or a procedural material whose color and roughness are sampled from ranges. Material variety is one of the cheapest ways to make a detector ignore surface appearance and learn shape.
Usage
from telekinesis.illusion import config
from telekinesis.illusion.randomizer.randomizer_node import MaterialRandomizer
environment.add(config.MaterialConfig.discover(assets / "materials")) # register the pool first
randomizer.add(
MaterialRandomizer(config.MaterialRandomizerConfig(target_models=["gear"], groups=["metal"])),
"gear_material",
)Every instance of gear gets one of the registered metal texture sets, drawn independently per instance and per scene. Textures are loaded the first time a set is picked and cached after that.
MaterialRandomizerConfig
Which models: the union of both fields; with neither, every registered model:
| Field | Default | Description |
|---|---|---|
target_models | None | Registered model names, matched exactly. |
target_groups | None | Model groups, from ModelConfig(groups=...). |
Which materials: pick one source:
| Field | Default | Description |
|---|---|---|
groups | None | Groups of registered PBR materials, e.g. ["metal", "plastic"]. A group is drawn first, then a material within it. |
names | None | Names of registered PBR materials. Combined with groups as a union. |
materials | None | Explicit choices: PBR group names and/or PrincipledMaterialConfig recipes. Cannot be combined with groups or names. |
With none of the three, any registered material group can be drawn.
How they are applied:
| Field | Default | Description |
|---|---|---|
mode | derived | "active" replaces the active material slot, "model" uses one material for every slot of a model, "slots" samples each slot independently. Without mode: "slots" if material_slots is set, "model" if materials is set, else "active". |
material_slots | None | "all" to sample every slot independently, or a mapping from slot name or zero-based index to its own choices. |
seed | None | Seed for a private random generator, for reproducible material choices. |
The second positional argument, environment, is optional. Pass it to validate the targets and load the selected textures right away instead of before the first scene.
Procedural Materials
brushed_steel = config.PrincipledMaterialConfig("metal", parameters={"roughness": (0.2, 0.5)}, surface_imperfections=True)
painted = config.PrincipledMaterialConfig("plastic", parameters={"base_color": ((0.6, 0.0, 0.0), (1.0, 0.2, 0.1))})
MaterialRandomizer(config.MaterialRandomizerConfig(target_models=["gear"], materials=[brushed_steel, painted, "metal"]))A PrincipledMaterialConfig is a recipe for a Blender Principled BSDF. Each parameter is a fixed value or a (min, max) range sampled per scene, so one recipe produces endless variants. Mixing recipes with a PBR group name ("metal" above) draws from both.
| Field | Default | Description |
|---|---|---|
preset | None | Starting point: "metal", "plastic" or "rubber", or None for plain Principled defaults. |
parameters | {} | Overrides: base_color, metallic, roughness, ior, specular_ior_level, transmission, alpha, coat_weight, coat_roughness, subsurface_weight, subsurface_radius, emission_color, emission_strength. Colors are linear RGB(A). |
surface_imperfections | False | True adds scratch and smudge maps from <assets>/surface_imperfections to roughness and bump, or pass a mapping to tune roughness_strength, bump_strength, bump_distance, scale and directory. |
| Preset | Base color | Metallic | Roughness |
|---|---|---|---|
metal | gray 0.3–0.8 | 1.0 | 0.15–0.45 |
plastic | 0.05–0.8 | 0.0 | 0.25–0.65 |
rubber | near black, 0.01–0.08 | 0.0 | 0.65–0.95 |
Per-Slot Materials
Models with several material slots, such as a housing with a seal, can get different materials per slot. Keep the slots on import with material_preprocessing="preserve":
environment.add(config.ModelConfig.from_path("housing.glb", model_name="housing", material_preprocessing="preserve"))
MaterialRandomizer(config.MaterialRandomizerConfig(
target_models=["housing"],
material_slots={"Body": ["metal"], "Seal": [config.PrincipledMaterialConfig("rubber")]},
seed=17,
))Named slots must exist on every target; use one node per slot layout.