Python Extension for distilling and baking MDL [omni.mdl.distill_and_bake]#
This is an extension for distilling and baking MDL to UsdPreviewSurface material. The extension adds a context menu “Distill and Bake” to the stage window. The selected USD material (can select multiple material) is distilled, texture are baked and a UsdPreviewSurface shader is created. The UsdPreviewSurface shader output is connected to the surface input of the material.
Interfaces#
class MdlDistillAndBake#
Constructor#
usd_prim (Usd.Prim): Prim to distill and bake to UsdPreviewSurface (default None).
ouput_folder (str): Output folder for texture maps. If not set, a temporary folder is created and deleted when the extension is unloaded (default None).
ouput_samples (int): Number of samples for baking (default 1).
ouput_resolution (int): Baking resolution (default 128).
Distill and bake#
await distill_async()
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 materials and choose detination 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, ouput_folder=’D:/temp’) await distiller.distill_async()
Distill and bake all materials in a stage#
Please replace ‘……..’ with spaces:
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) ……..await distiller.distill_async()
Known Limitations#
Material need to be bound to a USD Prim in order to be distilled and baked.
Normal mapping is not supported yet.
Materials using translucent shader (e.g. Jade) produce incorrect results due to the lack of support of transmission in UsdPreviewSurface.