Change texture via python API

Hello!

I want to change the barcode-labels e.g. on the small_KLT example assets so that not all boxes in the warehouse have the same label.
I found the texture file (albedo map), changed it manually and assigned the updated png to one of the materials, which nicely updated the texture in the scene.

I now try to do the same via a python script because I have hundreds of boxes. This is my current approach:

import omni
from pxr import Sdf, UsdPhysics, PhysxSchema
stage = omni.usd.get_context().get_stage()
material_path = '/Warehouse/KLT_Bins/SmallKLT_Visual_75/Visuals/Looks/FOF_Mesh_LabelsSG/Shader'

prim = stage.GetPrimAtPath(material_path)
print(prim.GetPropertyNames())

This shows me Properties like ‘inputs:albedo_brightness’, but not the albedo map (why is it called this, btw)?

So how could I iterate over all KLT (which share a common prefix) and assign a random texture from a given repository as the new texture?

As always: fixed it after asking online… I thought about changing the usda-file and reloading the scene, and found that the texture is stored as ‘inputs:diffuse_texture’ (still no idea why the GUI calls it ‘albedo map’).

texture = prim.GetAttribute('inputs:diffuse_texture')
texture.Set('./FOF_Mesh_Labels_D_12345.png')

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.