This example illustrates the export of materials to the MDL encapsulated format as well as loading a material from an MDLE.
Core of the creation process is the mi::neuraylib::IMdle_api and the Mdle_data
structure. A new instance of this structure is created using an mi::neuraylib::ITransaction:
The fields of the structure describe the content of the MDLE to create. This includes the future main material or function which is specified by passing the database
name of an existing function definition of function call in the prototype_name
field.
Depending on the selected prototype, different default parameters are generated for the future main material/function. In case a definition is provided, the default values of the definitions are copied. In case of an material instance or a function call, the arguments that have been applied during the instantiation are used instead. To override these defaults, a new mi::neuraylib::IExpression_list is created and new expressions are added for the parameters to override. Finally, the created list is set to the defaults
field of
the Mdle_data
structure.
Note, that all parameters need to be set to create an MDLE. This allows a drag-and-drop workflow and out-of-the-box usage without further setup.
Optionally, a thumbnail can be added to the MDLE. Since there is a high chance of changed default parameters, existing thumbnail images are not added automatically. Instead, the path to the correct thumbnail needs to be added manually. This path can either be relative to a search path or a file system path.
Besides the thumbnail arbitrary user files can be added using an array of Mdle_user_file
structures. Each of those has a source_path
field to select the file to add. Again, this can either be relative to a search path or a file system path. The second field, target_path
, specifies the path in the created MDLE relative to the root.
To trigger the actual MDLE export, the Mdle_data
structure, along with a target file path, is passed to mi::neuraylib::IMdle_api::export_mdle provided by the MDLE API component:
Analogously, functions can be exported to MDLE, too. Note, that the database name of functions consists of the function name itself followed by its parameter list.
Each file in an MDLE is stored along with a MD5 hash and the MDLE itself has a 8 byte header that contains the letters MDLE
and a version number. Both, header and hashes can be checked using the mi::neuraylib::IMdle_api::validate_mdle function of the MDLE API component.
The return value as well as the context
can be checked in order to see whether the file is valid.
In order to simplify the integration of MDLE into existing systems, an MDLE file is loaded like any other MDL module. Therefore the absolute file path to the MDLE is passed instead of a qualified module name.
After successfully loading the module, the main function is available in the database. To identify MDLE elements, there is an mdle
prefix instead of the usual mdl
. The prefix is followed by the normalized MDLE file path (using forward slashes and a leading slash), followed by the material/function name. Note, that function names again have their parameter list appended. The sample contains helper functions to construct these database names:
From that point, the functions and materials can be used as any other MDL function or material.
Source Code Location: examples/mdl_sdk/mdle/example_mdle.cpp