Augmentations¶
Randomize objects, materials and any other value in the scene, in place.
Compose applies a list of augmentations to every object it is called with. Each
augmentation takes p, the probability that it runs, drawn per object; a call can
override it, aug(obj, p=0.5). After a
call, applied says whether it ran and actual (or actual_x/y/z) holds the values
it set. Number, Vector, Boolean, Menu, MaterialSlot, UVMap, Visibility,
ShadowCatcher, FocalLength and DepthOfField also take otherwise, a value to set
when they don't run. Each call overwrites them, so after a Compose call they describe
only the last object; results holds the values for every object, by name. Augment inside
with state.restoring():, which sets everything back when the datapoint is done.
Node sets the inputs of a node (e.g. the group node of a smart material or of a
geometry nodes setup), each with its own Number, Vector, Boolean or Menu
written without a data path: the Node gives each the path of its input;
Modifier does the same for the inputs of a geometry nodes modifier, by name, or the
settings of any other modifier (Subdivision Surface, Bevel...).
Node.template writes a Node with every input of a node and its range, to paste and
edit; the Blender add-on copies it for the selected node. Modifier.template and
Chain.shape_keys_template do the same for a modifier and for the shape keys of an
object.
MaterialSlot gives an object one of the materials in its own slots, and UVMap one
of its UV maps.
Visibility shows or hides objects in the render, and the labels follow it.
ShadowCatcher makes an object (a floor) a shadow catcher, rendering only the shadows on
it (Cycles).
KeepAbove, placed after the transforms, lifts objects out of a floor or terrain;
PlaceOn also lowers them, so they rest on it. Seed gives every seed in a node
group (e.g. a geometry nodes scatter) its own random value. PlaceOnCurve moves a
camera (or any object) to a random point on a curve, optionally facing along it. OneOf applies one
augmentation from a list, picked at random by weight, and Chain applies a list to one
object as one augmentation, e.g. to pick between whole sequences in a OneOf.
Compose.describe() is the graph of what a Compose can do, with the probability of
each outcome per object; graph_preview draws it on an HTML page before generating, and
generating.Augmentations saves it and records what happened in every label.
Ranges are (low, high), and most also take (low, high, step) for one of low,
low + step, ... high. A single number means one of two things. Where an augmentation
changes a value from where it is (Translation, Rotation, Scale, the defocus of
DepthOfField), a number v is the range (-v, v): Rotation(z=180) is any heading.
Where it sets a value (LookAt, FocalLength, DepthOfField's f_stop,
SimpleMaterial, PlaceOnCurve), a number is that exact value: FocalLength(50).
Number, Vector, Boolean and Menu change any value by its data path. A path
starting with bpy. is absolute: right click a value in Blender > Copy Full Data
Path. Any other path is relative to the augmented object, e.g. data.energy.
The augmentations that change an object (Translation, Rotation, Scale,
Visibility, ShadowCatcher, KeepAbove, PlaceOn, LookAt, PlaceOnCurve,
FocalLength, DepthOfField, MaterialSlot, UVMap, SimpleMaterial) change the object they are called
with, or with data_path='bpy.data.objects["Camera"]' always that object, so they can
also be called alone, aug().
Geometry nodes inputs moved in Blender 5, so their path depends on the version:
modifiers["GeometryNodes"]["Socket_2"] in 4.x,
modifiers["GeometryNodes"].properties.inputs.Socket_2.value in 5.x. Modifier
finds them by name in every version.
Compose
¶
Compose(
augmentations: list[Callable[[Object], Any]],
*,
p: float = 1.0,
name: Optional[str] = None,
)
Applies a list of augmentations to every object it is called with, in place.
Each augmentation runs once per object, in list order: all of them on the first
object, then all of them on the next one. Every augmentation draws its own p for
each object, so with Visibility(p=0.5) each object is shown or hidden
independently. Call it inside with state.restoring():, so the scene is set back
afterwards.
Every call first clears the results of its augmentations, also of the ones
nested in a OneOf, so afterwards they hold the values for the objects of this
call only, also when the call is skipped by p or a OneOf didn't pick them
(then they are empty). actual and applied on an augmentation describe
only the last object, read results for all of them.
Parameters:
-
augmentations(list[Callable[[Object], Any]]) –augmentations to apply, each a callable taking one object.
-
p(float, default:1.0) –probability of applying the whole list, drawn once per call. A call can override it with its own
p. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
applied(bool | None) –whether the last call applied the augmentations.
Example
objects_aug = augmentations.Compose([
augmentations.Translation(x=0.5, y=0.5),
augmentations.Rotation(z=180),
])
objects_aug([car_1, car_2])
objects_aug([car_1, car_2], p=0.5) # this call: the whole list half of the time
The values each augmentation set, per object:
visibility = augmentations.Visibility(p=0.5)
boxes_aug = augmentations.Compose([visibility])
boxes_aug([box_1, box_2, box_3])
visibility.results # e.g. {"box_1": False, "box_2": True, "box_3": False}
visibility.actual # False, only box_3
describe
¶
describe() -> dict[str, Any]
The graph of what this Compose can do: every augmentation in it, nested
ones included, with the probability of each outcome per object.
The probabilities multiply down the tree: a Compose and a Chain reach their
augmentations when they run (p), a OneOf reaches each one with its weight
share, a Node or Modifier reaches its inputs. They assume the p given at
construction, not one given to a call, and leave out what the scene decides:
options read from Blender, an object not over the PlaceOn surface, datapoints
a generating.BBox skips. generating.Augmentations saves this graph next to the
dataset and records what each augmentation did in every label, and
export.augmentation_stats compares the two.
Each node has:
id:"0"for theCompose, then the index of each augmentation down the tree, e.g."0.2.1": the 2nd augmentation of the 3rd one;type,name(thenameargument, when given) andsettings, the augmentation's other arguments;reached: the probability it is called,applied: that it runs (itspdrawn),skipped: that it is called but doesn't run,otherwise: the value it sets then,{value, probability};values: for aMenu,MaterialSlotorUVMapwith its options listed, aBoolean, aVisibilityor aShadowCatcher, each value it can set,{value, probability},otherwiseincluded;ignores_object: it changes the same thing for every object (an absolute data path,Seed), so only its last call counts;children; an augmentation used twice is described once, the second time only assame_asits first id. The children of aOneOfhaveweight(1 each withoutweights) andshare, the fraction of its picks they get.
Returns:
-
dict[str, Any]–The
Composeas the root node, plain values JSON can store.
Example
lights_aug = augmentations.Compose([
augmentations.OneOf([
augmentations.Menu("data.type", options=["SPOT", "AREA"]),
augmentations.Number("data.energy", (100, 1000)),
], weights=[1, 3]),
], p=0.5)
graph = lights_aug.describe()
graph["children"][0]["children"][0]["applied"] # 0.125: 0.5 * 1/4
graph["children"][0]["children"][0]["values"]
# [{"value": "SPOT", "probability": 0.0625}, {"value": "AREA", "probability": 0.0625}]
Augmentation
¶
Augmentation(
p: float = 1.0,
*,
otherwise: Any = None,
name: Optional[str] = None,
)
Base class of the augmentations.
It runs with probability p, drawn on every call, so once per object in a
Compose. A skipped augmentation leaves the object unchanged, unless it has an
otherwise value: then it sets that. Number, Vector, Boolean, Menu,
MaterialSlot, UVMap, Visibility, ShadowCatcher, FocalLength and DepthOfField take
otherwise; it is None (keep the value) by default, except for Boolean (False),
Visibility (hidden) and ShadowCatcher (a normal object).
A Compose skipped by its own p runs none of its augmentations, so their
otherwise isn't set either.
Subclasses implement apply(obj) and store what they sampled in actual, and
set_otherwise(obj) when they take otherwise.
applied and actual (actual_x/y/z for Translation, Rotation and Scale)
describe only the last call. A Compose calls each augmentation once per object,
so after Compose([aug])([a, b, c]) they hold what happened to c; the values for
a and b were overwritten. results keeps them for every object: each call
stores its actual under the object's name, and Translation, Rotation and
Scale store
(x, y, z). A call without an object, and every call of an augmentation that
doesn't use the object (an absolute data path, Seed, or a OneOf or Chain of
only those), stores it under None: in a Compose over several objects it runs
once per object on the same value, so results holds only the last one, the one
kept. With data_path, an augmentation that changes an object stores it under that
object's name. A skipped call stores what it set: its otherwise value, or None
when it left the value unchanged. A Compose call clears
results first; direct calls add to it, so clear it yourself
(aug.results.clear()) when you call an augmentation in your own loop.
A direct call can override p for that call only, like a Compose call:
rust(p=0.2).
Parameters:
-
p(float, default:1.0) –probability of applying the augmentation, 0-1.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
applied(bool | None) –whether the last call applied it.
-
actual(Any) –the values set by the last call, None when it was skipped and left the value unchanged.
-
results(dict[str | None, Any]) –the values set for each object, by object name, since the last
Composecall (or since it was cleared).
Example
visibility = augmentations.Visibility(p=0.5)
augmentations.Compose([visibility])([box_1, box_2, box_3])
visibility.results # e.g. {"box_1": False, "box_2": True, "box_3": False}
visibility.actual # False: only the last object, box_3
rotation = augmentations.Rotation(z=180)
for car in [car_1, car_2]:
rotation(car)
print(car.name, rotation.actual_z) # read actual after each call
rotation(car_1, p=0.5) # this call only: half of the time
OneOf
¶
OneOf(
augmentations: list[Callable[[Object], Any]],
weights: Optional[Sequence[float]] = None,
*,
p: float = 1.0,
name: Optional[str] = None,
)
Applies one augmentation from a list, picked at random by weight.
On every call it picks one augmentation and calls it with the object. In a
Compose it picks again for every object. The picked augmentation then draws its
own p; the others don't run, so they don't set their otherwise either. A
OneOf can contain another OneOf, and a
Chain to pick a whole sequence.
Compose clears the results of the augmentations inside it too.
Parameters:
-
augmentations(list[Callable[[Object], Any]]) –augmentations to pick from, each a callable taking one object.
-
weights(Optional[Sequence[float]], default:None) –relative probability of each augmentation. None = equal.
-
p(float, default:1.0) –probability of applying one of them.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(int | None) –index of the augmentation picked by the last call, None when it was skipped.
-
results(dict[str | None, int | None]) –the index picked for each object.
Raises:
-
ValueError–augmentationsis empty, the number of weights and augmentations differ, a weight is negative or not a number, or the weights sum to 0.
Example
# each part is either moved or turned, turned twice as often
one_of = augmentations.OneOf(
[augmentations.Translation(x=0.5, y=0.5), augmentations.Rotation(z=180)],
weights=[1, 2],
)
augmentations.Compose([one_of])([car_1, car_2])
one_of.results # e.g. {"car_1": 1, "car_2": 0}
Chain
¶
Chain(
augmentations: list[Callable[[Optional[Object]], Any]],
*,
p: float = 1.0,
name: Optional[str] = None,
)
Applies a list of augmentations to one object, in order, as one augmentation.
Where Compose is called with a list of objects, a Chain is called with one
object like any other augmentation, so it can go where one augmentation goes: in a
OneOf, to pick between whole sequences, or in a Compose. Each augmentation in it
draws its own p; when the Chain itself doesn't run, none of them do, so they
don't set their otherwise either. Compose clears the results of the
augmentations inside it.
Parameters:
-
augmentations(list[Callable[[Optional[Object]], Any]]) –augmentations to apply, each a callable taking one object.
-
p(float, default:1.0) –probability of applying the whole list.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(list | None) –what each augmentation set in the last call, as in its
results((x, y, z)forTranslation,RotationandScale,Nonefor a callable withoutactual), None when it was skipped.
Raises:
-
ValueError–augmentationsis empty.
Example
# a dim, warm light, or just another brightness
lamp_aug = augmentations.Compose([
augmentations.OneOf([
augmentations.Number("data.energy", value_range=(600, 1400)),
augmentations.Chain([
augmentations.Number("data.energy", value_range=(300, 600)),
augmentations.Vector("data.color", value_range=((1, 0.7, 0.5), (1, 0.85, 0.7))),
]),
], weights=[2, 1]),
])
A material picked from the object's slots, augmented only when it is picked:
material_aug = augmentations.Compose([
augmentations.OneOf([
augmentations.Chain([
augmentations.MaterialSlot(["Ferrous metal"]),
augmentations.Node('active_material.node_tree.nodes["Ferrous metal"]', {
"Rust strength": augmentations.Number((0.3, 1)),
}),
]),
augmentations.Chain([
augmentations.MaterialSlot(["Plastic"]),
augmentations.Node('active_material.node_tree.nodes["Principled BSDF"]', {
"Roughness": augmentations.Number((0.1, 0.6)),
}),
]),
], weights=[3, 1]),
])
shape_keys_template
staticmethod
¶
shape_keys_template(
obj: Object,
*,
prefix: str = "augmentations.",
relative: bool = True,
) -> str
Writes the source of a Chain that sets the value of every shape key of an
object, to paste into a script and edit.
Each shape key gets a Number with the range of its slider (Range Min and Max,
0 to 1 by default) and its current value in a comment. By default the paths are
relative (data.shape_keys.key_blocks["Smile"].value): pass the object to the
Compose, and the Chain also works for every other object with shape keys of
those names. With relative=False they are absolute
(bpy.data.objects["Face"].data.shape_keys...) and always change this object,
whatever the Chain is called with. A comment on top says which, with the
object's name. The basis is left out,
and muted or driven shape keys are only comments, since their value has no
effect or a driver overwrites it. With the default p=1 the Chain does the same
as its Numbers listed one by one in a Compose; it keeps them together, e.g.
to give the whole Chain a p or to put it in a OneOf.
In the Blender app, the add-on does the same for the active object and copies it to the clipboard: 3D Viewport sidebar (N) > Blendmentation > Copy Shape Keys Template, Relative or Absolute. See Installation.
Parameters:
-
obj(Object) –object with shape keys (a mesh, curve or lattice).
-
prefix(str, default:'augmentations.') –written before
ChainandNumber, e.g."aug."afterfrom blendmentation import augmentations as aug. -
relative(bool, default:True) –paths relative to the object; False: absolute paths through it.
Returns:
-
str–The source of the
Chain, ending in a newline.
Raises:
-
ValueError–the object has no shape keys besides the basis, or they are not relative (Evaluation Time sets them).
Example
print(augmentations.Chain.shape_keys_template(bpy.data.objects["Face"]))
prints
# Relative paths: they start from the object it is called with, here "Face".
# Pass that object to the Compose, compose([bpy.data.objects["Face"]]), or one set up the same way.
augmentations.Chain([
augmentations.Number('data.shape_keys.key_blocks["Smile"].value', (0.0, 1.0)), # now 0.0
augmentations.Number('data.shape_keys.key_blocks["Blink"].value', (0.0, 1.0)), # now 0.25
# 'data.shape_keys.key_blocks["Old"].value': muted, now 0.0
])
Translation
¶
Translation(
x: Offset = 0,
y: Offset = 0,
z: Offset = 0,
*,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Moves the object by a random offset per axis, in Blender units.
Each axis is a number v, sampled from (-v, v), a pair (low, high), or a
triple (low, high, step) for one of low, low + step, ... up to high.
The offset is added to the location.
Parameters:
-
x(Offset, default:0) –offset on X in Blender units.
-
y(Offset, default:0) –offset on Y in Blender units.
-
z(Offset, default:0) –offset on Z in Blender units.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Example
augmentations.Translation(x=0.5, y=0.5, z=(0, 1))
augmentations.Translation(x=(-1, 1, 0.5)) # -1, -0.5, 0, 0.5 or 1
Rotation
¶
Rotation(
x: Offset = 0,
y: Offset = 0,
z: Offset = 0,
*,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Rotates the object by a random angle per axis, in degrees.
Each axis is a number v, sampled from (-v, v), a pair (low, high), or a
triple (low, high, step) for one of low, low + step, ... up to high, each
equally likely. The angle is added to the rotation, in euler, quaternion and
axis-angle modes.
For whole turns in steps, leave out the last step: (0, 270, 90), not
(0, 360, 90), where 360 is the same as 0 and would make it twice as likely.
Parameters:
-
x(Offset, default:0) –angle around X in degrees.
-
y(Offset, default:0) –angle around Y in degrees.
-
z(Offset, default:0) –angle around Z in degrees.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Example
augmentations.Rotation(z=180) # any heading
augmentations.Rotation(z=(0, 270, 90)) # 0, 90, 180 or 270 degrees
# tilted by -30, -15, 0, 15 or 30 degrees, and turned in 45 degree steps
augmentations.Rotation(x=(-30, 30, 15), z=(0, 315, 45))
Scale
¶
Scale(
x: Offset = 0,
y: Offset = 0,
z: Offset = 0,
*,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Scales the object by a random percentage per axis.
Each axis is a number v, sampled from (-v, v), a pair (low, high), or a
triple (low, high, step) for one of low, low + step, ... up to high, in
percent: the scale is multiplied by 1 + sample / 100.
Parameters:
-
x(Offset, default:0) –change of the X scale in percent.
-
y(Offset, default:0) –change of the Y scale in percent.
-
z(Offset, default:0) –change of the Z scale in percent.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Example
augmentations.Scale(x=10, y=10, z=10, p=0.5) # ±10 %, in half of the datapoints
Visibility
¶
Visibility(
p: float = 0.5,
*,
otherwise: Optional[bool] = False,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Shows the object in the render with probability p, otherwise hides it.
It sets the object's render visibility (hide_render) both ways: an object hidden
in the scene is shown when the draw says visible, and a visible one is hidden when
it says not. The viewport visibility is left unchanged. Children are not affected,
pass them to the Compose too.
The labels follow the render: a hidden object has no pixels in the masks, passes
and AOVs, is left out of its instance's bbox (an instance with every object
hidden has bbox None and is ignored by the BBox skip settings), doesn't hide
keypoints behind it, and keypoints on it are not visible.
Parameters:
-
p(float, default:0.5) –probability that the object is visible.
-
otherwise(Optional[bool], default:False) –what happens the rest of the time: False hides the object, None leaves its visibility unchanged.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(bool | None) –whether the last call made the object visible, None when it left it unchanged. In a
Composethat is the last object;resultshas every object.
Example
distractors_aug = augmentations.Compose([augmentations.Visibility(p=0.7)])
distractors_aug([box_1, box_2, box_3]) # each one in about 70 % of the images
visibility = distractors_aug.augmentations[0]
visible = [name for name, shown in visibility.results.items() if shown]
# shown in 70 % of the images, otherwise as it is in the scene
augmentations.Visibility(p=0.7, otherwise=None)
ShadowCatcher
¶
ShadowCatcher(
p: float = 0.5,
*,
otherwise: Optional[bool] = False,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Makes the object a shadow catcher with probability p, otherwise a normal object.
It sets the object's Shadow Catcher option (Object Properties > Visibility,
is_shadow_catcher) both ways. A shadow catcher shows only the shadows and
reflections other objects cast on it, so with a transparent film (Render Properties
Film > Transparent) a floor under the objects leaves their shadows over a
generating.Backgroundor a photo composited later, and withpbelow 1 it is sometimes a floor and sometimes only shadows. Only Cycles renders shadow catchers; other engines render the object as usual.
The labels don't change: the object is still in the render, so it still hides what is behind it in the masks, and it keeps its own bbox and masks when it is in the classes.
Parameters:
-
p(float, default:0.5) –probability that the object is a shadow catcher.
-
otherwise(Optional[bool], default:False) –what happens the rest of the time: False makes it a normal object, None leaves the option unchanged.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Floor"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."floor or shadows". None: its class name.
Attributes:
-
actual(bool | None) –whether the last call made the object a shadow catcher, None when it left it unchanged. In a
Composethat is the last object;resultshas every object.
Example
floor_aug = augmentations.Compose([augmentations.ShadowCatcher()])
floor_aug([floor]) # only shadows in half of the images, the floor in the others
# always only the shadows on it
augmentations.ShadowCatcher(p=1, data_path='bpy.data.objects["Floor"]')()
KeepAbove
¶
KeepAbove(
surface: Object,
*,
margin: float = 0.0,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Moves the object up, if needed, so it stays above a surface, e.g. a floor or terrain.
It checks whether the object's lowest point is at least margin above the top of
the surface where they overlap seen from above, and if not, moves the object up
along world Z until it is. An object that is already high enough, or not over the
surface, is left where it is; it is never moved down. Both are compared as
everything they show, in world space: the evaluated mesh (modifiers included) and
the instances it makes (geometry nodes instances, e.g. Instance on Points or Object
Info with As Instance, and collection instancing). Uneven surfaces work, and the
contact is found exactly, also where an edge of the object crosses an edge of the
surface away from any vertex (an object lying across a ridge). Shape keys and
modifiers count as they are when it runs; a shape that depends on where the object
is (geometry nodes reading its position, a shape key or modifier setting driven by
its location) is measured again after the move, until it rests. It sets matrix_world, so parented objects work
too. Only the object's own geometry counts, not its children's.
Put it after the transforms
It checks the object where it is when it runs, so put it in the Compose
after Translation, Rotation, Scale and any other augmentation that moves
or deforms the object (e.g. a Number changing a modifier or shape key).
Augmentations after it can push the object into the surface again.
Parameters:
-
surface(Object) –object to stay above. It must have faces (a mesh, curve, text...), its own or of the instances it makes.
-
margin(float, default:0.0) –minimum gap between the surface and the object's lowest point, in Blender units.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(float | None) –how far the last call moved the object up, 0 when it was already above. In a
Composethat is the last object;resultshas every object.
Raises:
-
ValueError–the object is the surface.
-
TypeError–the surface has no faces.
Example
objects_aug = augmentations.Compose([
augmentations.Translation(x=0.5, y=0.5, z=(-0.3, 0.3)),
augmentations.Rotation(x=30, y=30, z=180),
augmentations.KeepAbove(floor, margin=0.01), # after the transforms
])
objects_aug([car_1, car_2])
PlaceOn
¶
PlaceOn(
surface: Object,
*,
margin: float = 0.0,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Moves the object up or down so it rests on a surface, e.g. a floor or table.
Like KeepAbove, but it also moves the object down: its lowest point ends up
exactly margin above the top of the surface where they overlap seen from above,
so a floating object drops onto the surface and a sunken one is lifted out. Only
the height changes, along world Z. An object that is not over the surface is left
where it is. Both are compared as everything they show, instances included, and
the contact is found exactly, as in KeepAbove. It sets matrix_world, so
parented objects work too. Only the object's own geometry counts, not its
children's.
Use it when the object must touch the surface, e.g. after a rotation that tips it
over around an origin that is not at its bottom. Use KeepAbove when the object
may also float above it.
Put it after the transforms
It places the object where it is when it runs, so put it in the Compose after
Translation, Rotation, Scale and any other augmentation that moves or
deforms the object.
Parameters:
-
surface(Object) –object to rest on. It must have faces (a mesh, curve, text...), its own or of the instances it makes.
-
margin(float, default:0.0) –gap between the surface and the object's lowest point, in Blender units.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(float | None) –how far the last call moved the object, positive up and negative down, 0 when it was not over the surface. In a
Composethat is the last object;resultshas every object.
Raises:
-
ValueError–the object is the surface.
-
TypeError–the surface has no faces.
Example
lying_aug = augmentations.Compose([
augmentations.Rotation(x=(90, 90), y=(0, 270, 90), z=180),
augmentations.Translation(x=0.5, y=0.5),
augmentations.PlaceOn(floor), # after the transforms
])
lying_aug([milk_box])
Seed
¶
Seed(
node_group: NodeTree,
*,
p: float = 1.0,
otherwise: Optional[int] = None,
name: Optional[str] = None,
)
Gives every seed in a node group its own random value.
On every call, each unlinked integer Seed input of the group's nodes (Distribute
Points on Faces, Distribute Points in Volume, Random Value, Hash Value...) gets a
different random int, nodes inside nested node groups included. Seeds connected to
other nodes are left alone. Seeds exposed as modifier inputs are not group nodes;
set those with Number.
It works on the node group, not on the object passed by Compose, so it can be
called as seed(). In a Compose it runs once per object, and the last seeds are
kept; results holds only those, under None.
Parameters:
-
node_group(NodeTree) –the node group, e.g.
bpy.data.node_groups["Geometry Nodes"], or any other node tree (a material'snode_tree). -
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[int], default:None) –seed to set on all of them when it doesn't run, None keeps them.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict[str, int] | None) –the seed set on each node, by node name (
"Group node/Node"for nodes in nested groups).
Raises:
-
TypeError–node_groupis not a node tree. -
ValueError–the node group has no unlinked Seed inputs, or
otherwiseis not an int.
Example
scatter = bpy.data.node_groups["Geometry Nodes"]
seed = augmentations.Seed(scatter)
for _ in range(100):
with state.restoring(): # the seeds are set back too
seed() # a new scatter every time
generator()
LookAt
¶
LookAt(
target: Target,
*,
distance: Optional[RangeOrValue] = None,
elevation: Optional[RangeOrValue] = None,
azimuth: Optional[RangeOrValue] = None,
roll: Optional[RangeOrValue] = None,
focal_length: Optional[RangeOrValue] = None,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Moves a camera (or a light, or any object) on a sphere around a target and points it at the target, upright.
The target stays in the center of the camera view. It sets matrix_world, so
parented cameras work too. Each parameter is a (min, max) range, an exact number,
or None to keep the current value.
Parameters:
-
target(Target) –an object, a list of objects (the center of their bounding boxes), or a point
(x, y, z). -
distance(Optional[RangeOrValue], default:None) –distance from the target in Blender units.
-
elevation(Optional[RangeOrValue], default:None) –angle above the target's horizontal plane in degrees. Avoid exactly 90 / -90.
-
azimuth(Optional[RangeOrValue], default:None) –angle around the world Z axis in degrees, 0 = +X.
-
roll(Optional[RangeOrValue], default:None) –rotation around the camera's view axis in degrees. None = upright.
-
focal_length(Optional[RangeOrValue], default:None) –camera lens in mm, cameras only.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict | None) –the distance, elevation, azimuth, roll and focal length set by the last call.
Example
camera_aug = augmentations.Compose([
augmentations.LookAt([car_1, car_2], distance=(6, 12), elevation=(10, 45),
azimuth=(0, 360), roll=(-5, 5)),
])
camera_aug([bpy.context.scene.camera])
PlaceOnCurve
¶
PlaceOnCurve(
curve: Object,
*,
align: bool = False,
position: RangeOrValue = (0.0, 1.0),
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Moves a camera (or any object) to a random point on a curve, e.g. a camera path.
The point is picked uniformly along the curve's length (a curve with several splines
counts them one after another, in their order), so straight and curved parts get
the same density. The curve is read as Blender evaluates it (modifiers included),
as the line it draws at its resolution, without bevel or extrusion. It sets
matrix_world, so parented objects work too.
By default only the location changes: the object keeps its rotation and scale.
With align, it also turns to face along the curve direction at that point, the
way the curve was drawn (from its first point to its last): a camera's view axis
(-Z) follows the tangent, upright (its Y axis up towards world Z). The curve's tilt
is ignored. Avoid vertical parts of the curve with align, where "up" is undefined.
Vary it after
Put Translation after it in the Compose to move the object off the curve
(in world axes, Blender units), and Rotation to turn it from there, e.g.
Rotation(z=(90, 90)) after align=True makes the camera look to the left
of the path, and Rotation(x=5, y=5, z=10) adds a little shake. To aim at
something instead, put LookAt(target) after it without distance,
elevation and azimuth: it keeps the point on the curve.
Parameters:
-
curve(Object) –the curve object to place the object on.
-
align(bool, default:False) –also rotate the object to face along the curve direction.
-
position(RangeOrValue, default:(0.0, 1.0)) –where on the curve, as a fraction of its length from its start, a
(min, max)range (the default is all of it) or an exact number, 0-1. -
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict | None) –the
position(fraction of the length) and the worldlocationset by the last call.
Raises:
-
TypeError–curveis not a curve object. -
ValueError–positionis not between 0 and 1, the object is the curve, the curve has no length, or it evaluates to faces.
Example
camera_path = bpy.data.objects["CameraPath"]
camera_aug = augmentations.Compose([
augmentations.PlaceOnCurve(camera_path, align=True),
augmentations.Translation(z=(-0.2, 0.2)), # a little up or down
augmentations.Rotation(x=5, z=(-20, 20)), # look around a bit
])
camera_aug([bpy.context.scene.camera])
FocalLength
¶
FocalLength(
focal_length: RangeOrValue,
*,
target: Optional[Target] = None,
keep_size: bool = False,
size: Optional[RangeOrValue] = None,
p: float = 1.0,
otherwise: Optional[float] = None,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Sets a random camera lens, optionally as a dolly zoom.
With keep_size, the camera also moves along the line to the target by the same
ratio as the lens, so the target keeps its size in the image while the perspective
changes. With size as well, the target gets a random size instead, in percent of
its size in the image before the call: size=(80, 120) makes it up to 20 % smaller
or bigger (the camera moves farther or closer). That is exact for parts at the
target's depth when the target is in the center of the view (e.g. after LookAt);
an off-center target also moves in the image. Perspective cameras only.
Parameters:
-
focal_length(RangeOrValue) –lens in mm, a
(min, max)range or an exact number. -
target(Optional[Target], default:None) –an object, a list of objects (the center of their bounding boxes), or a point
(x, y, z). Needed forkeep_size. -
keep_size(bool, default:False) –move the camera so the target keeps its size in the image.
-
size(Optional[RangeOrValue], default:None) –with
keep_size, the target's new size in the image in percent of its size before the call, a(min, max)range or an exact number. None (the default) keeps it exactly. -
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[float], default:None) –lens in mm to set when it doesn't run, None keeps the lens. Not with
keep_size. -
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict | None) –focal_lengthset by the last call, and withkeep_sizethe newdistanceto the target and thesizein percent (100 withoutsize), None when it was skipped withoutotherwise.
Raises:
-
ValueError–keep_sizewithout atarget,otherwisewithkeep_size,sizewithoutkeep_size, or asizethat is not a number or(min, max)above 0.
Example
augmentations.FocalLength((24, 85), target=[car_1, car_2], keep_size=True)
# the same, with the cars 80 to 120 % of the size they had before
augmentations.FocalLength((24, 85), target=[car_1, car_2], keep_size=True, size=(80, 120))
# a random lens in 30 % of the images, otherwise 50 mm
augmentations.FocalLength((24, 85), p=0.3, otherwise=50)
DepthOfField
¶
DepthOfField(
target: Optional[Target] = None,
*,
f_stop: Optional[RangeOrValue] = None,
defocus: Optional[Offset] = None,
p: float = 1.0,
otherwise: Optional[bool] = None,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Turns on depth of field, focused on a target, with a random f-stop, and optionally a little out of focus.
Focus is measured along the view axis from where the camera is when this runs, so
put it after LookAt / FocalLength in a Compose.
Only the image is blurred: the labels (masks, boxes, keypoints) keep the sharp
outlines of the objects (see generating.Segmentation).
defocus moves the focus off that distance by a random percent, added like a
Translation offset: defocus=10 focuses anywhere from 10 % nearer to 10 % farther,
(0, 20) only farther (behind the target). It works from the target's distance, or
without a target from the scene's focus (its Focus Distance, or the distance to its
Focus on Object, which is then replaced by the distance).
Parameters:
-
target(Optional[Target], default:None) –an object, a list of objects (the center of their bounding boxes), or a point
(x, y, z)to focus on. None keeps the current focus. -
f_stop(Optional[RangeOrValue], default:None) –aperture f-stop, a
(min, max)range or an exact number, lower gives more blur. None keeps the current one. -
defocus(Optional[Offset], default:None) –percent added to the focus distance: a number
vsamples from(-v, v),(low, high)from that range,(low, high, step)one of low, low + step, ... high. None (the default) focuses exactly. The distance doesn't go below 0. -
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[bool], default:None) –what happens the rest of the time: False turns depth of field off, None leaves the depth of field settings unchanged.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict | bool | None) –{"f_stop", "focus_distance"}set by the last call, with"defocus"(the percent added) whendefocusis given, False when it turned depth of field off, None when it left it unchanged.
Raises:
-
ValueError–defocusis not a number,(low, high)or(low, high, step).
Example
# blurred in half of the images, sharp in the others
augmentations.DepthOfField(car_1, f_stop=(1.4, 5.6), p=0.5, otherwise=False)
# focused up to 15 % in front of or behind the cars, so they are a little soft
augmentations.DepthOfField([car_1, car_2], f_stop=(1.4, 2.8), defocus=15)
# the focus set in the scene, moved up to 20 % farther
augmentations.DepthOfField(defocus=(0, 20))
MaterialSlot
¶
MaterialSlot(
slots: Optional[Sequence[Union[int, str]]] = None,
weights: Optional[Sequence[float]] = None,
*,
p: float = 1.0,
otherwise: Optional[Union[int, str]] = None,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Gives the object one of the materials in its own material slots, picked at random.
Add the materials to pick from to the object's slots in Blender (Material
Properties, +). On every call it assigns every face of the mesh to the picked
slot, and makes it the active slot, so later augmentations in the same Compose
reach the picked material through a relative path,
active_material.node_tree.nodes[...]. state.restoring() sets the faces' slots
and the active slot back.
It doesn't copy materials: an object shows a material that other objects may use too, and augmenting that material changes it for all of them. Which objects share a material, and a mesh (with its slots, by default), is up to how the scene is set up: give objects their own copies to augment them separately.
Parameters:
-
slots(Optional[Sequence[Union[int, str]]], default:None) –slots to pick from, by index or material name. None = all of them.
-
weights(Optional[Sequence[float]], default:None) –relative probability of each slot. None = equal.
-
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[Union[int, str]], default:None) –slot to use when it doesn't run, by index or material name. None keeps the faces' slots.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(str | None) –name of the picked slot's material (None for an empty slot, or when skipped without
otherwise).
Raises:
-
ValueError–the number of weights and slots differ, a weight is negative or not a number, the weights sum to 0, or
otherwiseis not an index or a name. At a call: the object has no material slots, or (withslotsNone) the number of weights and slots differ. -
TypeError–at a call, the object is not a mesh.
-
KeyError–at a call, a slot in
slotsdoesn't exist.
Note
A geometry nodes modifier that sets the material (Set Material) wins over the faces' slots.
Example
# the cube's slots: "Ferrous metal", "Plastic", "Rubber"
cube_aug = augmentations.Compose([
augmentations.MaterialSlot(weights=[3, 1, 1]),
# the picked material, whichever it is
augmentations.Number(
'active_material.node_tree.nodes["Principled BSDF"].inputs["Roughness"].default_value',
value_range=(0.1, 0.6),
),
])
cube_aug([cube])
Each material augmented its own way: a Node with an absolute path per
material. The ones that weren't picked are changed too, but don't show; to
augment only the picked one, see the example of
Chain.
cube_aug = augmentations.Compose([
augmentations.MaterialSlot(["Ferrous metal", "Plastic"]),
augmentations.Node(
'bpy.data.materials["Ferrous metal"].node_tree.nodes["Ferrous metal"]',
{"Rust strength": augmentations.Number((0.3, 1))},
),
augmentations.Node(
'bpy.data.materials["Plastic"].node_tree.nodes["Principled BSDF"]',
{"Base Color": augmentations.Vector((0, 1))},
),
])
UVMap
¶
UVMap(
uv_maps: Optional[Sequence[Union[int, str]]] = None,
weights: Optional[Sequence[float]] = None,
*,
p: float = 1.0,
otherwise: Optional[Union[int, str]] = None,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Makes one of the object's UV maps, picked at random, the one it renders with.
Add the UV maps to the mesh in Blender (Object Data Properties > UV Maps, +), e.g.
the same texture laid out at different scales or rotations; Blender allows at most 8
UV maps per mesh. On every call it makes
the picked UV map the render one (the camera icon in the list) and the active one.
Textures without a UV Map node, and the UV output of a Texture Coordinate node, use
it. state.restoring() sets both back.
The UV maps belong to the mesh, so objects sharing the mesh share the pick.
Parameters:
-
uv_maps(Optional[Sequence[Union[int, str]]], default:None) –UV maps to pick from, by index or name. None = all of them.
-
weights(Optional[Sequence[float]], default:None) –relative probability of each UV map. None = equal.
-
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[Union[int, str]], default:None) –UV map to use when it doesn't run, by index or name. None keeps the current one.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Crate"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(str | None) –name of the picked UV map (None when skipped without
otherwise).
Raises:
-
ValueError–the number of weights and UV maps differ, a weight is negative or not a number, the weights sum to 0, or
otherwiseis not an index or a name. At a call: the object has no UV maps, or (withuv_mapsNone) the number of weights and UV maps differ. -
TypeError–at a call, the object is not a mesh.
-
KeyError–at a call, a UV map in
uv_mapsdoesn't exist.
Note
A UV Map or Attribute node that names its UV map, and a geometry nodes modifier that replaces the UV maps, don't follow the pick.
Example
# the crate's UV maps: "UVMap", "Rotated", "Scaled"
crate_aug = augmentations.Compose([
augmentations.UVMap(weights=[2, 1, 1]),
])
crate_aug([crate])
SimpleMaterial
¶
SimpleMaterial(
material: str,
*,
hue: Optional[RangeOrValue] = None,
saturation: Optional[RangeOrValue] = None,
value: Optional[RangeOrValue] = None,
roughness: Optional[RangeOrValue] = None,
metallic: Optional[RangeOrValue] = None,
p: float = 1.0,
data_path: Optional[str] = None,
name: Optional[str] = None,
)
Sets random Principled BSDF base color, roughness and metallic values.
Each parameter is an absolute (min, max) range, 0-1, or an exact value, and None
leaves the value unchanged. The base color is set through hue, saturation and value. The sockets
must not be connected to other nodes.
It changes the material, so every object using it is affected.
Parameters:
-
material(str) –name of the material.
-
hue(Optional[RangeOrValue], default:None) –range of the base color hue.
-
saturation(Optional[RangeOrValue], default:None) –range of the base color saturation.
-
value(Optional[RangeOrValue], default:None) –range of the base color value (brightness).
-
roughness(Optional[RangeOrValue], default:None) –range of the roughness.
-
metallic(Optional[RangeOrValue], default:None) –range of the metallic.
-
p(float, default:1.0) –probability of applying the augmentation.
-
data_path(Optional[str], default:None) –absolute data path of an object to change instead of the one it is called with, e.g.
'bpy.data.objects["Camera"]'; then it can also be called alone,aug(). None (the default): the object it is called with. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Tip
Use SimpleMaterial for negative data, secondary objects, or to make a model
generalize over shape while ignoring the material. For finer control over the
materials of hero objects, use Node
to set the inputs of a node group, or Number
to set individual shader node inputs.
Example
augmentations.SimpleMaterial("CarPaint", hue=(0, 1), saturation=(0.5, 1), roughness=(0.1, 0.6))
augmentations.SimpleMaterial("CarPaint", hue=(0, 1), metallic=1) # always fully metallic
Number
¶
Number(
data_path: Union[str, Range, None] = None,
value_range: Optional[Range] = None,
*,
p: float = 1.0,
otherwise: Optional[float] = None,
name: Optional[str] = None,
)
Sets any int or float value, given by its data path, to a random value.
For shader node inputs, geometry nodes inputs, shape keys, light settings and so on. Ints are rounded. With a step, the value is one of min, min + step, ... max.
As an input of a Node or
Modifier, leave the data
path out: Number((0, 1)). The Node or Modifier gives it the path of the input.
Parameters:
-
data_path(Union[str, Range, None], default:None) –path to the value, absolute (starting with
bpy.) or relative to the object (or the World, material… passed in its place). Use[index]for one vector component, e.g.'location[2]'. Left out inside aNodeorModifier. -
value_range(Optional[Range], default:None) –(min, max)range of the new value, or(min, max, step). -
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[float], default:None) –value to set when it doesn't run, None keeps the value.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Raises:
-
ValueError–value_rangeis not(min, max)or(min, max, step), min is above max, or step is not above 0. At a call, there is no data path (outside aNodeorModifier).
With an absolute path
A path starting with bpy. doesn't use the object, so it can be called alone,
aug(). In a Compose it runs once per object the Compose is called with,
and the last value set is kept; results holds only that one, under None.
Example
augmentations.Number("data.energy", value_range=(600, 1400))
augmentations.Number("data.energy", value_range=(600, 1400, 200)) # 600, 800, ... 1400
augmentations.Number('data.shape_keys.key_blocks["Smile"].value', value_range=(0, 1))
# rust in 20 % of the images, none in the others
augmentations.Number('node_tree.nodes["Rust"].outputs[0].default_value',
value_range=(0.5, 1), p=0.2, otherwise=0)
# an input of a Node: the path comes from the Node
augmentations.Node('node_tree.nodes["Rust"]', {"Scale": augmentations.Number((1, 5))})
Vector
¶
Vector(
data_path: Union[str, tuple[Bound, Bound], None] = None,
value_range: Optional[tuple[Bound, Bound]] = None,
*,
p: float = 1.0,
otherwise: Optional[Bound] = None,
name: Optional[str] = None,
)
Sets any vector value, given by its data path, to random values per component.
For locations, colors, vector node inputs and so on. Each bound of value_range is
a number for all components, or a sequence with one value per component, where
None keeps that component. Int components are rounded.
As an input of a Node or
Modifier, leave the data
path out: Vector((-1, 1)). The Node or Modifier gives it the path of the
input. It sets vector, rotation (X, Y, Z angles in radians) and color inputs; on a
color input a bound (or otherwise) of one number or 3 values sets red, green and
blue and keeps alpha, so Vector((0, 1)) is any color.
Parameters:
-
data_path(Union[str, tuple[Bound, Bound], None], default:None) –path to the value, absolute (starting with
bpy.) or relative to the object (or the World, material… passed in its place). Left out inside aNodeorModifier. -
value_range(Optional[tuple[Bound, Bound]], default:None) –(min, max)bounds of the new values. -
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Optional[Bound], default:None) –vector to set when it doesn't run, a number for all components or one value per component (None keeps that component). None keeps the vector.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
With an absolute path
A path starting with bpy. doesn't use the object, so it can be called alone,
aug(). In a Compose it runs once per object the Compose is called with,
and the last value set is kept; results holds only that one, under None.
Example
augmentations.Vector("data.color", value_range=(0.8, 1.0))
# a random RGB color that keeps alpha
augmentations.Vector(
'bpy.data.materials["Mat"].node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value',
value_range=((0, 0, 0, None), (1, 1, 1, None)),
)
# a random offset in half of the images, no offset in the others
augmentations.Vector('node_tree.nodes["Offset"].vector', value_range=(-1, 1), p=0.5, otherwise=0)
# inputs of a Node: the path comes from the Node
augmentations.Node('active_material.node_tree.nodes["Principled BSDF"]', {
"Base Color": augmentations.Vector((0, 1)), # any color, alpha kept
})
Boolean
¶
Boolean(
data_path: Union[str, float, None] = None,
p: Optional[float] = None,
*,
otherwise: Optional[bool] = False,
name: Optional[str] = None,
)
Sets any boolean value, given by its data path, to True with probability p,
otherwise to otherwise (False by default).
For geometry nodes switches, object visibility, modifier toggles and so on.
As an input of a Node or
Modifier, leave the data
path out: Boolean(p=0.3). The Node or Modifier gives it the path of the input.
Parameters:
-
data_path(Union[str, float, None], default:None) –path to the value, absolute (starting with
bpy.) or relative to the object (or the World, material… passed in its place). Left out inside aNodeorModifier. -
p(Optional[float], default:None) –probability of True.
-
otherwise(Optional[bool], default:False) –value to set the rest of the time, None keeps the value.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
With an absolute path
A path starting with bpy. doesn't use the object, so it can be called alone,
aug(). In a Compose it runs once per object the Compose is called with,
and the last value set is kept; results holds only that one, under None.
Example
augmentations.Boolean("data.use_shadow", p=0.8)
# turned on in 30 % of the images, otherwise as it is in the scene
augmentations.Boolean("data.use_shadow", p=0.3, otherwise=None)
# an input of a Node: the path comes from the Node
augmentations.Node('node_tree.nodes["Scatter"]', {"Mossy": augmentations.Boolean(p=0.3)})
Menu
¶
Menu(
data_path: Union[str, Sequence[Any], None] = None,
options: Optional[Sequence[Any]] = None,
weights: Optional[Sequence[float]] = None,
*,
p: float = 1.0,
otherwise: Any = None,
name: Optional[str] = None,
)
Sets any menu (enum) value, given by its data path, to a random option.
For geometry nodes menu inputs, node settings like the Principled BSDF distribution, the light type and so on.
As an input of a Node or
Modifier, leave the data
path out: Menu(["Sand", "Gravel"]). The Node or Modifier gives it the path of
the input.
Parameters:
-
data_path(Union[str, Sequence[Any], None], default:None) –path to the value, absolute (starting with
bpy.) or relative to the object (or the World, material… passed in its place). Left out inside aNodeorModifier. -
options(Optional[Sequence[Any]], default:None) –options to choose from. None = all options of the menu: a Menu Switch's, or a group node's input that leads to one; required when Blender doesn't list them, e.g. for a built-in node's menu like Transform Geometry's Mode.
-
weights(Optional[Sequence[float]], default:None) –relative probability of each option, in the order of
options, or without them in Blender's order (a light's type: POINT, SUN, SPOT, AREA; a Menu Switch: its items top to bottom). None = equal. -
p(float, default:1.0) –probability of applying the augmentation.
-
otherwise(Any, default:None) –option to set when it doesn't run, None keeps the value. It doesn't have to be one of
options. -
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Raises:
-
ValueError–the number of weights and options differ (with
optionsNone, at a call), a weight is negative or not a number, or the weights sum to 0. -
TypeError–the data path is not a string, e.g.
Menu(["A", "B"], [3, 1])inside aNode, where the weights must be given by name:Menu(["A", "B"], weights=[3, 1]).
With an absolute path
A path starting with bpy. doesn't use the object, so it can be called alone,
aug(). In a Compose it runs once per object the Compose is called with,
and the last value set is kept; results holds only that one, under None.
Example
augmentations.Menu("data.type", options=["POINT", "SPOT", "AREA"], weights=[2, 1, 1])
# a spot or area light in 30 % of the images, a point light in the others
augmentations.Menu("data.type", options=["SPOT", "AREA"], p=0.3, otherwise="POINT")
# an input of a Node: the path comes from the Node
augmentations.Node('node_tree.nodes["Ground"]', {"Type": augmentations.Menu(["Sand", "Gravel"])})
Node
¶
Node(
node: str,
inputs: dict[Union[str, int], Any],
*,
p: float = 1.0,
name: Optional[str] = None,
)
Sets the inputs of a node to random values, each with its own range, probability
and otherwise.
For the group node of a smart material, of a geometry nodes setup, or any other
node in a shader, world or geometry nodes tree. The inputs of a geometry nodes
modifier are not a node: set them with
Modifier.
inputs maps each input to augment, by name (or index, for inputs that share a
name), to the augmentation that sets it, written without a data path: the
Node gives each one the path of its input. Inputs that are left out keep their
values.
| Socket | Set it with |
|---|---|
| Float, Int | Number((min, max)) or ((min, max, step)) |
| Vector | Vector((min, max)) |
| Rotation | Vector((min, max)) of the X, Y, Z angles in radians |
| Color | Vector((min, max)): 1 or 3 values set RGB and keep alpha ((0, 1): any color), 4 set alpha too |
| Boolean | Boolean(p=...), the probability of True |
| Menu | Menu([options]), or Menu() for every option |
They take all their usual arguments but the path (p, otherwise, weights…).
The path inherited from the Node is that of the input's value, so
augmentations.Node('active_material.node_tree.nodes["Ferrous metal"]', {"Rust
strength": augmentations.Number((0, 1))}) sets
active_material.node_tree.nodes["Ferrous metal"].inputs["Rust strength"].default_value:
relative to the object when the node's path is, absolute when it is. The Node
gives the path before each call and takes it back after, so the same Number does
nothing on its own (it raises a ValueError without a path). An augmentation that
doesn't match the socket, e.g. a Number on a color input, raises a TypeError
at the call. For short, an input can also be just the range or options, e.g.
"Rust strength": (0, 1), and Node picks the augmentation by the socket type.
Each input draws its own p, and Node's own p applies the whole node: when it
doesn't run, no input changes, also not to its otherwise.
The node is given by its data path, with the node's name: Sidebar (N) > Node >
Name, not the title on the node (a group node shows its group's name), or right
click an input > Copy Full Data Path. The path is absolute (starting with bpy.) or
relative to the object, e.g. active_material.node_tree.nodes["Ferrous metal"] to augment the
material of each object in a Compose. The inputs must not be connected to other
nodes. It changes the node tree (the material, the node group…), so everything
using it is affected.
Parameters:
-
node(str) –data path of the node.
-
inputs(dict[Union[str, int], Any]) –what to set each input to, by input name or index.
-
p(float, default:1.0) –probability of applying the augmentation.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict | None) –the value set to each input by the last call, by its key in
inputs(None for an input skipped by itspwithoutotherwise), None when it was skipped. -
augmentations(list) –one entry per input, with the
data_pathof its value;Composeclears theirresults.
Raises:
-
ValueError–inputsis empty, an input's key is not a name or index, or its augmentation has a data path of its own. At the first call: a short value doesn't fit its socket type, e.g. a Float without a range. -
TypeError–an input is set with an augmentation other than
Number,Vector,BooleanorMenu. At a call: the augmentation doesn't match the socket, or the input is not a number, vector, rotation, color, boolean or menu socket.
With an absolute path
A path starting with bpy. doesn't use the object, so it can be called alone,
node(). In a Compose it runs once per object the Compose is called with,
and the last values set are kept; results holds only those, under None.
Tip
Node is the same as a Chain of Number, Vector, Boolean and Menu
with the full path of each input's value,
'node_tree.nodes["Ferrous metal"].inputs["Rust strength"].default_value',
written once for the node. Its actual is keyed by input.
Example
ferrous_metal = augmentations.Node(
'bpy.data.materials["Master material"].node_tree.nodes["Ferrous metal"]',
{
"Texture ofset": augmentations.Vector((-100, 100)), # every axis
"Base metal type": augmentations.Menu(), # any option
"Surface effect": augmentations.Menu(["Weathered", "Grinded"], weights=[3, 1]),
"Base metal color": augmentations.Vector(((0.3, 0.3, 0.3), (0.6, 0.6, 0.6))), # alpha kept
"Rust strength": augmentations.Number((0, 1, 0.25)), # 0, 0.25, ... 1
# rust in 20 % of the images, none in the others
"Rust spread": augmentations.Number((0.5, 1), p=0.2, otherwise=0),
"Paint Color": augmentations.Vector((0, 1)), # any color
"Paint": augmentations.Boolean(p=0.3), # painted in 30 %
},
)
with state.restoring():
ferrous_metal() # absolute path: no object needed
ferrous_metal.actual # e.g. {"Texture ofset": (12.0, -40.3, 77.1), "Base metal type": "Cast metal", ...}
generator()
A group node in a geometry nodes tree:
rocks = augmentations.Node(
'bpy.data.node_groups["Scatter"].nodes["Rock generator"]',
{"Count": augmentations.Number((10, 50)),
"Size": augmentations.Number((0.5, 2), p=0.5, otherwise=1)},
)
template
staticmethod
¶
template(
node: Union[str, Node],
obj: Optional[Object] = None,
*,
prefix: str = "augmentations.",
relative: bool = False,
) -> str
Writes the source of a Node that sets every input of a node, to paste into a
script and edit.
Each input gets the augmentation that sets it, without a data path (the Node
gives it), with the widest range the node allows, so you narrow the ranges you
want and delete the inputs to leave alone:
| Socket | Written as |
|---|---|
| Float, Int | Number((min, max)) |
| Vector | Vector((min, max)) |
| Rotation | Vector((v, v)) with the current X, Y, Z angles in radians |
| Color | Vector((0.0, 1.0)): any color, alpha kept |
| Boolean | Boolean(p=0.5) |
| Menu | Menu([...]) with every option: a Menu Switch's, or a group input's that leads to one |
A built-in node's menu (e.g. Transform Geometry's Mode) is a Warning! comment,
since Python can't list its options: add Menu([...]) yourself.
The min and max of a Float, Int or Vector are those of the socket: for a group
node, Min and Max of the input in the group's interface; for other nodes, the
socket type's (0 to 1 for a factor). Without them, it is (v, v) with the
current value. A comment after each input gives its type and current value.
Connected inputs and sockets Node can't set (shader, geometry, string,
object...) are only comments, and hidden ones (unavailable in the node's current
mode) are left out.
Inputs that share a name are keyed by index, with the name in the comment. The
node's name and the input names are written exactly, trailing spaces included.
The path is absolute by default (bpy.data.materials["Paint"].node_tree...): the
Node always changes that node, so it works with any objects passed to the
Compose, or called alone. With relative=True it starts from obj, through
its active material, another material slot, its data (a light) or the
geometry nodes modifier using the node's group (active_material.node_tree...):
pass the object to the Compose, and the Node also works for other objects
set up the same way. A world's node is relative to the world. A comment on top
says which, with the object's name.
In the Blender app, the add-on does the same for the active node in the node editor and copies it to the clipboard: Sidebar (N) > Blendmentation > Copy Node Template, Relative (from the active object) or Absolute; or Node menu, right click a node or F3 > Copy Blendmentation Template. See Installation.
Parameters:
-
node(Union[str, Node]) –the node, or its data path. A path is kept in the text as it is, so a path relative to
objmakes a relative template. -
obj(Optional[Object], default:None) –object a relative path starts from.
-
prefix(str, default:'augmentations.') –written before
Node,Number,Vector,BooleanandMenu, e.g."aug."afterfrom blendmentation import augmentations as aug. -
relative(bool, default:False) –for a node, write its path relative to
obj.
Returns:
-
str–The source of the
Node, ending in a newline.
Raises:
-
TypeError–nodeis not a node. -
ValueError–the node has no inputs, or
relativeand the node can't be reached fromobj.
Example
print(augmentations.Node.template(
'bpy.data.materials["Master material"].node_tree.nodes["Ferrous metal"]'
))
prints
# Absolute paths: they always change the material "Master material", so it works with any
# objects passed to the Compose, or called alone without one.
augmentations.Node('bpy.data.materials["Master material"].node_tree.nodes["Ferrous metal"]', {
# "Texture Coordinate": connected
"Base metal color": augmentations.Vector((0.0, 1.0)), # color, now (0.1385, 0.1385, 0.1385, 1.0)
"Base metal type": augmentations.Menu(["Shiny metal", "Cast metal"]), # menu, now "Shiny metal"
"Texture scale": augmentations.Number((-10000.0, 10000.0)), # float, now 1.0
"Rust strength": augmentations.Number((0.0, 1.0)), # float, now 0.0
...
})
Modifier
¶
Modifier(
modifier: str,
inputs: dict[Union[str, int], Any],
*,
p: float = 1.0,
name: Optional[str] = None,
)
Sets the settings of a modifier to random values, each with its own range,
probability and otherwise: the inputs shown on a geometry nodes modifier, or the
settings of any other modifier (Subdivision Surface, Bevel, Array, Displace...).
It works like Node: inputs
maps each one to a Number, Vector, Boolean or Menu without a data path,
as in Node (see its table), or for short just the range or options. The
Modifier gives each one the path of its value before each call. The keys are:
- for a geometry nodes modifier, the input's name in the node group (or its index
among the group's inputs, Geometry included). The path depends on the Blender
version, and
Modifierbuilds it. A rotation is X, Y, Z angles in radians. An input set to be read from an attribute keeps reading it. - for any modifier, a setting by its Python name, e.g.
"levels"for Subdivision Surface's Levels Viewport,"width"for Bevel's Amount: hover over the setting with Python tooltips on (Preferences > Interface), or useModifier.template. A menu's options are Blender's identifiers, e.g."CATMULL_CLARK". On a geometry nodes modifier this also works, e.g."show_render"to turn it on and off, when no input has that name.
The modifier is given by its data path, relative to the object (e.g.
modifiers["Scatter"], to augment that modifier on every object in a Compose),
or absolute (bpy.data.objects["Floor"].modifiers["Scatter"]). It changes the
modifier only, not a geometry nodes modifier's node group, so objects with the same
group keep their own values.
Parameters:
-
modifier(str) –data path of the modifier.
-
inputs(dict[Union[str, int], Any]) –what to set each input or setting to, by input name or index (geometry nodes), or setting name.
-
p(float, default:1.0) –probability of applying the augmentation.
-
name(Optional[str], default:None) –a name for it in the graph and the report (
Compose.describe,export.augmentation_report), e.g."slide sideways". None: its class name.
Attributes:
-
actual(dict | None) –the value set to each input by the last call, by its key in
inputs(None for an input skipped by itspwithoutotherwise), None when it was skipped.
Raises:
-
ValueError–inputsis empty, an input's key is not a name or index, or its augmentation has a data path of its own. At the first call: a short value doesn't fit its socket type, e.g. a Float without a range. -
KeyError–at a call, the modifier has no such input or setting.
-
TypeError–an input is set with an augmentation other than
Number,Vector,BooleanorMenu. At a call: the path is not a modifier, the augmentation doesn't match the input, or the input is not a number, vector, rotation, color, boolean or menu.
Tip
Each input can also be set on its own, with Number, Vector, Boolean or
Menu and the data path of its value. That path uses the socket's identifier,
not its name, and changed in Blender 5:
modifiers["Scatter"]["Socket_2"] in 4.x,
modifiers["Scatter"].properties.inputs.Socket_2.value in 5.x. Modifier
finds the inputs by name and builds the path for the running version.
Example
floor = bpy.data.objects["Floor"]
scatter = augmentations.Modifier('modifiers["Scatter"]', {
"Density": augmentations.Number((5, 20)),
"Rock size": augmentations.Number((0.5, 2), p=0.5, otherwise=1),
"Mossy": augmentations.Boolean(p=0.3), # True 30 %
"Ground": augmentations.Menu(["Sand", "Gravel"]),
})
with state.restoring():
augmentations.Compose([scatter])([floor])
scatter.actual # e.g. {"Density": 12.7, "Rock size": 1, "Mossy": False, "Ground": "Sand"}
generator()
Any other modifier, by its settings' Python names:
smoothing = augmentations.Modifier('modifiers["Subdivision"]', {
"render_levels": augmentations.Number((1, 3)),
"subdivision_type": augmentations.Menu(["CATMULL_CLARK", "SIMPLE"]),
})
bevel = augmentations.Modifier('modifiers["Bevel"]', {
"width": augmentations.Number((0.01, 0.05)),
"segments": augmentations.Number((1, 4)),
"show_render": augmentations.Boolean(p=0.7), # beveled edges in 70 %
})
template
staticmethod
¶
template(
modifier: Union[str, Modifier],
obj: Optional[Object] = None,
*,
prefix: str = "augmentations.",
relative: bool = True,
) -> str
Writes the source of a Modifier that sets every input of a geometry nodes
modifier, or every setting of another modifier, to paste into a script and edit.
Each input gets the augmentation that sets it, without a data path (the
Modifier gives it), as in Node.template:
Number((min, max)) and Vector((min, max)), Vector((0.0, 1.0)) for a color,
Vector((v, v)) for a rotation, Boolean(p=0.5) and Menu([...]) with every
option. A comment after each gives its type and current value.
- A geometry nodes modifier: its inputs by name, the min and max from the input
in the node group's interface (
(v, v)with the current value without them). The Geometry input is left out; inputs set to read an attribute, and socketsModifiercan't set (object, material, string...) are only comments. Inputs that share a name are keyed by index. - Any other modifier: its settings by their Python name, with the name shown in
the UI in the comment, the min and max of the setting's slider. Settings
about the modifier's UI (Show in Edit Mode...) and settings
Modifiercan't set (objects, vertex groups, textures...) are left out.
A last comment says how to turn the modifier on and off in the render
("show_render"); it is not set by default.
The path is relative by default (modifiers["Scatter"]): pass the object to
the Compose, and the Modifier also works for other objects with a modifier
of that name. With relative=False it is absolute
(bpy.data.objects["Floor"].modifiers["Scatter"]) and always changes that
modifier. A comment on top says which, with the object's name.
In the Blender app, the add-on does the same for the active modifier of the active object (the one highlighted in the Modifier Properties) and copies it to the clipboard: 3D Viewport sidebar (N) > Blendmentation > Copy Modifier Template, Relative or Absolute. See Installation.
Parameters:
-
modifier(Union[str, Modifier]) –the modifier, or its data path. A path is kept in the text as it is, so a path relative to
objmakes a relative template. -
obj(Optional[Object], default:None) –object a relative path starts from.
-
prefix(str, default:'augmentations.') –written before
Modifier,Number,Vector,BooleanandMenu, e.g."aug."afterfrom blendmentation import augmentations as aug. -
relative(bool, default:True) –for a modifier, write its path relative to its object; False: absolute.
Returns:
-
str–The source of the
Modifier, ending in a newline.
Raises:
-
TypeError–modifieris not a modifier. -
ValueError–a geometry nodes modifier has no node group, or the modifier has no inputs or settings to set.
Example
print(augmentations.Modifier.template(bpy.data.objects["Floor"].modifiers["Scatter"]))
prints
# Relative paths: they start from the object it is called with, here "Floor".
# Pass that object to the Compose, compose([bpy.data.objects["Floor"]]), or one set up the same way.
augmentations.Modifier('modifiers["Scatter"]', {
"Density": augmentations.Number((0.0, 50.0)), # float, now 10.0
"Mossy": augmentations.Boolean(p=0.5), # boolean, now False
"Ground": augmentations.Menu(["Sand", "Gravel"]), # menu, now "Sand"
})
graph_preview
¶
graph_preview(
composes: Any, path: str, *, show: bool = False
) -> str
Draws what augmentation Composes can do on an HTML page, before generating.
The same page as export.augmentation_report, without a dataset: a flowchart where
the steps of a Compose or Chain run left to right in a frame and a OneOf forks
to its branches (with their weight and share), which join again. Each augmentation is
a card with a bar of how often it runs per object and, for a Menu,
MaterialSlot or UVMap with its options listed, a Boolean, a Visibility or a
ShadowCatcher, one per value (Compose.describe). Check the probabilities of a
pipeline before a long run; after it, export.augmentation_report adds what the dataset did.
Parameters:
-
composes(Any) –augmentation
Composes: one, a list (ids"0","1"...) or a dict{name: Compose}(ids the names), as forgenerating.Augmentations. -
path(str) –the HTML file to write (ending in
.html), or a folder to writeaugmentations_preview.htmlto, made when it doesn't exist yet (e.g. the generating path before the first datapoint).//paths are relative to the .blend file. -
show(bool, default:False) –open the page in the web browser.
Returns:
-
str–The path of the HTML file.
Raises:
-
TypeError–an item is not an
augmentations.Compose.
Example
augmentations.graph_preview({"objects": objects_aug, "camera": camera_aug}, "//preview.html", show=True)