This example loads an MDL module and inspects it contents.
In order to allow the the MDL SDK to locate MDL modules and its resources in the file system it is necessary to configure the MDL module search path. This is done by calling mi::neuraylib::IMdl_configuration::add_mdl_path().
Our example module ::nvidia::sdk_examples::tutorials
makes use of textures. The support for image formats in the the MDL SDK is provided by image plugins, which have to be loaded explicitly via mi::neuraylib::IPlugin_configuration::load_plugin_library().
The Python bindings provide a helper function for loading plugins as well. The file extension can be omitted to platform dependent code.
MDL modules are loaded with the method mi::neuraylib::IMdl_impexp_api::load_module(). Note that this method expects the module name, not the name of the file containing the module. To find the corresponding file it is necessary to configure the module search path as described above.
To load a module the IMdl_impexp_api
component is acquired first. It is good practice to also create an optional context in order to get detailed log messages.
The mi::neuraylib::IModule interface offers various methods related to metadata, like the name of the module, or the name of the file it was loaded from. Furthermore, it offers methods to enumerate the material and function definitions contained in the module. It also allows to enumerate all modules that have been (directly) imported by that module. Imported modules will be automatically loaded (if not already loaded before).
MDL materials and functions (as found in a .mdl file) are represented in the MDL SDK API by the interface. Similar to the module interface this interface offers various methods related to metadata, like the name of the definition, or the name of the containing module. Important methods are those that provide details about the parameters, like their names, types, and the values of defaults (if present).
In this example we simply print the parameter information for a selected material and the exported elements of the parenting module.
To read information about a module that has been loaded before it has to accessed using a transaction.
Compared to the native API, there are two access functions. The access_as
used above returns an object of a given type, in this case IModule
. The access
functions returns a generic interface and the type has to be queried manually.
Source Code Location:
examples/mdl_python/modules/example_modules.py