Create Backdrop
# The following is an example on how to create backdrops.
import ufe
import lookdevx as lx
if not shadingContainer:
raise Exception('This example requires a shading container i.e., a MaterialX document or a USD '
'material. Check the other examples to see how to create one.')
# Create a few nodes and make sure their positions are authored.
runTimeId = shadingContainer.runTimeId()
items = []
for i in range(5):
items.append(ufe.NodeDef.definition(runTimeId, 'ND_add_float').createNode(shadingContainer, ufe.PathComponent('add')))
position = 2 * (i - 2)
ufe.UINodeGraphNode.uiNodeGraphNode(items[-1]).setPosition(ufe.Vector2f(position, position))
# Parameters for backdrop creation:
# parent - The new backdrop will be a child of this item.
# name - The desired name for the new backdrop. If the name is already taken, a number suffix
# will be added or incremented. If the name is empty, a default name will be used.
# position - The coordinates at which the new backdrop will be placed. If no position is provided,
# it remains unauthored. LookdevX will set a position when first displaying it.
# size - The size of the new backdrop. If no size is provided, it remains unauthored. LookdevX
# will set a default size when first displaying it.
# color - The color of the new backdrop. If no color is provided, it remains unauthored.
# items - The list of items to be encompassed by the backdrop. The backdrops position and size
# is determined by computing the bounding box of the items. All items must be a child of
# `parent` and have position information. This parameter is mutually exclusive with
# `position` and `size`.
# The return value is the scene item of the newly created backdrop.
# The parent item is the only mandatory parameter. All other parameters are optional.
backdrop0 = lx.createBackdrop(shadingContainer)
# The parameters can either be specified in the order above or in any order by using their names.
backdrop1 = lx.createBackdrop(shadingContainer,
ufe.PathComponent("myBackdrop1"),
ufe.Vector2f(-2, 2),
ufe.Vector2f(1, 1),
ufe.Color3f(1, 0, 0))
backdrop2 = lx.createBackdrop(shadingContainer,
color=ufe.Color3f(0, 1, 0),
position=ufe.Vector2f(-4, 4),
size=ufe.Vector2f(1, 1),
name=ufe.PathComponent("myBackdrop2"))
# To encompass a set of items in a backdrop, specify these items instead of a position and size. The
# items can be nodes, node graphs or other backdrops.
backdrop3 = lx.createBackdrop(shadingContainer,
name=ufe.PathComponent("myBackdrop3"),
color=ufe.Color3f(1, 1, 0),
items=[items[0], items[1]])
backdrop4 = lx.createBackdrop(shadingContainer,
name=ufe.PathComponent("myBackdrop4"),
color=ufe.Color3f(1, 0, 1),
items=[backdrop1, backdrop2])
backdrop5 = lx.createBackdrop(shadingContainer,
name=ufe.PathComponent("myBackdrop5"),
color=ufe.Color3f(0, 1, 1),
items=[backdrop2, items[4]])