[SOLVED] How can I find the unreferenced texture file names?


I used this code:

std::string module_nameString = std::string("mdl") + std::string(module_name);
mi::base::Handle<mi::IString> exportedModule(transaction->create<mi::IString>());
result = mdl_compiler->export_module_to_string(transaction.get(), module_nameString.c_str(), exportedModule.get(), m_execution_context.get());

to export the MDL text string from a compiled material. The material was compiled using (in a modified version of mdl_helper.cpp of OptiX 6.0.0) :

optix::Program Mdl_helper::create_program()
// Compiles the given target code to an OptiX program and loads all <b>referenced</b> textures.

The created MDL text string still contains also the unreferenced textures. When my main application wants to save the scene then, that leads to a problem on loading the new saved scene, cause it was only possbile to keep the texture file names during execution of
optix::Buffer Mdl_helper::create_texture_samplers() from all the referenced textures. The unreferenced ones are missing.
And so the new created MDL file cannot be loaded, cause the main application only copies the found textures to the new relative material location.
And so the unreferenced textures are not present in the relative directory, where the MDL file specifies them.

How can I find the unreferenced texture file names?

my system: OptiX 6.0.0 SDK CUDA 10.0 GTX 1050 2GB Win10PRO 64bit (version 1809) device driver: 419.67 VS2019 (toolkit v140 of VS2015)

Hi m1,

you can ask a module for all resources via mi::neuraylib::IModule::get_resources_count()/get_resource_type()/get_resource_mdl_file_path()/get_resource_name().
So instead of copying the textures reported by the mi::neuraylib::ITarget_code object, you could copy all resources (including light profiles and BSDF measurements) reported by the module.
If you really only want textures, you can check the kind of the resource type returned by mi::neuraylib::IType_resource::get_kind() against mi::neuraylib::IType::TK_TEXTURE.

Hope that helps!

Hi Moritz,

Great! that is exactly what I was looking for! Solved!
Thank you very much!