Changing material properties through python

Isaac Sim Version

  • 5.0.0

Operating System

  • Windows 11

Hello,

I am trying to create a material in Isaac Sim and modify its properties using Python, similar to the approach described in this post: Creating a material and changing its color - Omniverse / Isaac Sim - NVIDIA Developer Forums.

I’ve tried several different methods, including:

  • Creating a material using Kit commands, then attempting to edit its parameters
  • Loading an existing material and then modifying its parameters
  • Creating the material entirely in Python, then updating its parameters

Unfortunately, I haven’t been able to access or modify the material parameters directly. I read that materials are created lazily, but there must be a way to initialize and adjust them via Python.

Any help or suggestions would be greatly appreciated.

Here is a sample of the code I have been working with:

def create_emissive_material(prim_path, color=(1.0, 1.0, 1.0), intensity=100000.0, mtl_asset_path=None):
    stage = get_context().get_stage()
    emissive_material_prim = stage.GetPrimAtPath(prim_path)
    if not emissive_material_prim:
        mtl_url = mtl_asset_path if mtl_asset_path else 'OmniPBR.mdl'
        omni.kit.commands.execute(
            'CreateMdlMaterialPrimCommand',
            mtl_url=mtl_url,
            mtl_name='OmniPBR',
            mtl_path=prim_path
        )
        emissive_material_prim = stage.GetPrimAtPath(prim_path)

    if not mtl_asset_path:
        mat_shade = UsdShade.Material(emissive_material_prim)
        # pp.pprint(mat_shade.GetInputs())
        # mat_shade.GetInput("enable_emission").Set(True)
        # mat_shade.GetAttribute("inputs:enable_emission").Set(True)
        # mat_shade.GetAttribute("inputs:emissive_color").Set(Gf.Vec3f(color[0], color[1], color[2]))
        # mat_shade.GetAttribute("inputs:emissive_intensity").Set(intensity)

    return emissive_material_prim
def create_mdl_material(mtl_url, mtl_name, mtl_path):
    omni.kit.commands.execute('CreateMdlMaterialPrimCommand',
	mtl_url=mtl_url,
	mtl_name=mtl_name,
	mtl_path=Sdf.Path(mtl_path),
	select_new_prim=False)

    return

def bind_material(prim_path, mtl_path):
    omni.kit.commands.execute('BindMaterialCommand',
        prim_path=prim_path,
        material_path=mtl_path,
        strength='weakerThanDescendants')
    
    return

def change_color_attr(mat_path, value):
    prop_path = f"{mat_path}/Shader.inputs:diffuse_color_constant"
    omni.kit.commands.execute('ChangeProperty',
        prop_path=prop_path,
        value=value,
        prev=Gf.Vec3f(0.2, 0.2, 0.2),
        usd_context_name=omni.usd.get_context().get_stage())
    return

def apply_layout_material_to_area(area_prim_path, color, opacity, mat_asset_path):
    stage = get_context().get_stage()
    material_asset_path = mat_asset_path
    material_name = "layout_area_mat"
    material_path = f"{area_prim_path}/area_marking_mat"
    create_mdl_material(material_asset_path, material_name, material_path)
    change_color_attr(material_path, color)

    #mat_shade.GetAttribute("inputs:diffuse_color_constant").Set(color)
    #mat_shade.GetAttribute("inputs:opacity_constant").Set(opacity)
    bind_material(area_prim_path, material_path)

    return

Thank you in advance for your assistance!