Cannot create material definition

I’m following some tutorials to load an MDL file and use it in Optix7, but sadly, no matter what I try, I cannot create the material definition.

Here’s an example of the code I’m trying to use:

auto database = neuray->get_api_componentmi::neuraylib::IDatabase();
auto scope = database->get_global_scope();
auto transaction = scope->create_transaction();

// factory??
auto mdl_impexp_api = neuray->get_api_componentmi::neuraylib::IMdl_impexp_api();
auto mdl_factory = neuray->get_api_componentmi::neuraylib::IMdl_factory();
auto context = mdl_factory->create_execution_context();

if (mdl_impexp_api->load_module(transaction, “gun_metal”, context) < 0) {
std::cerr << “ERROR: fail to load module\n”;
return 2;

mi::base::Handle mtlDef(
if (!mtlDef) {
std::cerr << “\nERROR: material definition\n”;
return 3;

I properly initialized the Neuray object, I added some MDL and resource paths to where I placed that specific file. I can even access the module with:

auto module = transaction->accessmi::neuraylib::IModule(“mdl::gun_metal”);

and print out a bunch of information about it. The only thing stopping my progress, so far, is the material definition to then potentially compile to PTX and load in Optix7.

What am I missing?


Hi widgg,

as you noted at the end, the database name “mdl::gun_metal” refers to the MDL module gun_metal (.mdl). To reference the material “gun_metal” within the module gun_metal, you need to use the database name “mdl::gun_metal::gun_metal”. The material database name has the form “mdl::<fully-qualified-module-name>::<material-name>”.

If in doubt, you can use the mi::neuraylib::IModule::get_material() function to enumerate all material database names.

Hope that helps!

That was exactly that! I just noticed that an MDL file can also have multiple export statements, that explains the extra ::gun_metal needed here.

Thanks for the fast answer!