n order to create a new material I have followed the documentation here: Create an MDL Material — Omniverse Developer Guide latest documentation
I used one of the materials that can be found in vMaterials. When I use one of the mdl via the isaac-sim UI it automatically adds a new Look that can be later applied to a mesh.
When trying via python API it does not seem to work, the final mesh has a red colour on the surface and not the mdl one.
Test if one green mdl can be applied to the mesh:
def test_material_visibility(stage, mesh_path):
"""
Prueba de visibilidad con un material simple para verificar que el mesh
puede recibir materiales correctamente
"""
# Crear un material de prueba
material_path = Sdf.Path("/World/Looks/TestMaterial")
material = UsdShade.Material.Define(stage, material_path)
# Crear un shader de prueba (USD Preview Surface)
shader = UsdShade.Shader.Define(stage, material_path.AppendChild("Shader"))
shader.CreateIdAttr("UsdPreviewSurface")
# Establecer un color base visible (verde brillante para test)
shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).Set(Gf.Vec3f(0, 1, 0))
shader.CreateInput("metallic", Sdf.ValueTypeNames.Float).Set(0.0)
shader.CreateInput("roughness", Sdf.ValueTypeNames.Float).Set(0.4)
# Conectar shader al material
material.CreateSurfaceOutput().ConnectToSource(
shader.CreateOutput("surface", Sdf.ValueTypeNames.Token))
# Aplicar al mesh
mesh_prim = stage.GetPrimAtPath(mesh_path)
if mesh_prim:
UsdShade.MaterialBindingAPI(mesh_prim).Bind(material)
print(f"Material de prueba aplicado a {mesh_path}")
return True
else:
print(f"Error: No se encontró el mesh en {mesh_path}")
return False
test_material_visibility(stage, "/World/marco_grande/marco_grande")
It does work! The mesh now looks green.
But if I want to apply the mdl on the mesh it does not work properly:
mtl_path = Sdf.Path(“/World/Looks/OSB_Wood”)
mtl = UsdShade.Material.Define(stage, mtl_path)
shader = UsdShade.Shader.Define(stage, mtl_path.AppendPath(“Shader”))
shader.CreateImplementationSourceAttr(UsdShade.Tokens.sourceAsset)
# MDL shaders should use “mdl” sourceType
shader.SetSourceAsset(material_url, “mdl”)
shader.SetSourceAssetSubIdentifier(“OSB Wood - Rough”, “mdl”)
# MDL materials should use “mdl” renderContext
mtl.CreateSurfaceOutput(“mdl”).ConnectToSource(shader.ConnectableAPI(), “out”)
mtl.CreateDisplacementOutput(“mdl”).ConnectToSource(shader.ConnectableAPI(), “out”)
mtl.CreateVolumeOutput(“mdl”).ConnectToSource(shader.ConnectableAPI(), “out”)
material = UsdShade.Material(stage.GetPrimAtPath(material_path))
mesh_prim = stage.GetPrimAtPath(door_mesh_path)
binding_api = UsdShade.MaterialBindingAPI(mesh_prim)
binding_api.Bind(material)
I have also tried with this attributes:
mesh = UsdGeom.Mesh.Define(stage, Sdf.Path(door_mesh_path))
# Paso 2: Definir el material MDL y cargarlo en la escena
material_path = “/World/Looks/OSB_Wood”
mdl_material = UsdShade.Material.Define(stage, Sdf.Path(material_path))
# Usa UsdShade para crear un shader MDL en Omniverse
mdl_shader = UsdShade.Shader.Define(stage, Sdf.Path(f"{material_path}/Shader"))
mdl_shader.CreateIdAttr(“mdlMaterial”) # Especifica que este shader usa MDL
# Define la ruta al archivo MDL y el nombre del material en el archivo
mdl_shader.CreateInput(“mdl:sourceAsset”, Sdf.ValueTypeNames.Asset).Set(mdl_file_path)
mdl_shader.CreateInput(“mdl:sourceAsset:subIdentifier”, Sdf.ValueTypeNames.String).Set(“OSB Wood - Rough”) # Cambia al nombre del material
# Conecta el shader MDL al material
surface_output = mdl_material.CreateSurfaceOutput(“mdl”)
surface_output.ConnectToSource(mdl_shader.ConnectableAPI(), “out”)
# Paso 3: Asignar el material a la malla
UsdShade.MaterialBindingAPI(mesh).Bind(mdl_material)
But nothing seams to work. When i load the generated stage I can see some problems in the loggers.
2024-11-06 12:18:21 [24,902ms] [Error] [omni.usd] USD_MDL: in LoadModule at line 247 of ../../source/plugins/usdMdl/neuray.cpp -- 'rtx::neuraylib::MdlModuleId' for '/isaac-sim/src/mdl/vMaterials_2/Wood/OSB_Wood.mdl' is Invalid
2024-11-06 12:18:21 [24,902ms] [Error] [omni.usd] USD_MDL: in GetSdrFromDiscoveryResult at line 178 of ../../source/plugins/usdMdl/moduleRegistry.cpp -- Module: '/isaac-sim/src/mdl/vMaterials_2/Wood/OSB_Wood.mdl' with version '1' not found in 'MdlModuleRegistry::ModuleDataMap'.
2024-11-06 12:18:21 [24,902ms] [Error] [omni.hydra] Failed to create MDL shade node for prim '/World/Looks/OSB_Wood/Shader'. Empty identifier: '' and/or subIdentifier: ''
How can mdl be invalid if its downloaded from vMaterials? Identifier and subidentifier are setted, what am I missing?
Thank you in advance.