Scripting

You can invoke the extension via Python. The following are function descriptions and examples.

class MdlDistillAndBake

Constructor

  • usd_prim (Usd.Prim): The prim to distill and bake to UsdPreviewSurface (default: None).

  • output_folder (str): The output folder for texture maps. If not set, a temporary folder is created and deleted when the extension is unloaded (default: None).

  • output_samples (int): The number of samples for baking (default: 1).

  • output_resolution (int): The baking resolution (default: 128).

Distill and Bake

  • distill()

Get parameter ranges and defaults

  • get_baking_resolution_min()

  • get_baking_resolution_max()

  • get_baking_resolution_default()

  • get_baking_samples_min()

  • get_baking_samples_max()

  • get_baking_samples_default()

Examples

Distill and bake a given material and choose the destination folder for texture maps

Assuming an OmniGlass is attached to a USD Prim:

import omni.mdl.distill_and_bake
import omni.usd

stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath('/World/Looks/OmniGlass')
distiller = omni.mdl.distill_and_bake.MdlDistillAndBake(prim, output_folder='D:/temp')
distiller.distill()

Distill and bake all materials in a stage

from pxr import UsdShade
import omni.mdl.distill_and_bake

stage = omni.usd.get_context().get_stage()
for prim in stage.Traverse():
    if UsdShade.Material(prim):
        matname = prim.GetPath()
        print(matname)
        distiller = omni.mdl.distill_and_bake.MdlDistillAndBake(prim)
        distiller.distill()

Known Limitations

  • A material needs to be bound to a USD Prim in order to be distilled and baked.

  • UDIMs are not currently supported.

  • Some things such as Subsurface Scattering do not translate to the UsdPreviewSurface.

  • Textures that have procedural components do not always transfer as expected, including some vMaterials.