This example loads an MDL module and inspects it contents.
#include <iostream>
#include <string>
#include "example_shared.h"
const char* material_definition_name
= "mdl::nvidia::sdk_examples::tutorials::example_material(color,float)";
const char* function_definition_name
= "mdl::nvidia::sdk_examples::tutorials::example_function(color,float)";
template <class T>
void dump_definition(
const T* definition,
std::ostream& s)
{
mi::Size count = definition->get_parameter_count();
for(
mi::Size index = 0; index < count; index++) {
std::string name = definition->get_parameter_name( index);
s << " parameter " << type_text->get_c_str() << " " << name;
defaults->get_expression( name.c_str()));
if( default_.is_valid_interface()) {
expression_factory->dump( default_.get(), 0, depth+1));
s << ", default = " << default_text->get_c_str() << std::endl;
} else {
s << " (no default)" << std::endl;
}
}
mi::Size temporary_count = definition->get_temporary_count();
for(
mi::Size i = 0; i < temporary_count; ++i) {
std::stringstream name;
name << i;
expression_factory->dump( temporary.get(), name.str().c_str(), 1));
s << " temporary " << result->get_c_str() << std::endl;
}
if( result)
s << " body " << result->get_c_str() << std::endl;
else
s << " body not available for this function" << std::endl;
s << std::endl;
}
{
{
check_success(mdl_impexp_api->load_module(
transaction.get(), "::nvidia::sdk_examples::tutorials", context.get()) >= 0);
print_messages( context.get());
check_success( module.is_valid_interface());
std::cout << "Loaded file " << module->get_filename() << std::endl;
std::cout << "Found module " << module->get_mdl_name() << std::endl;
std::cout << std::endl;
mi::Size module_count = module->get_import_count();
std::cout << "The module imports the following modules:" << std::endl;
for(
mi::Size i = 0; i < module_count; i++)
std::cout << " " << module->get_import( i) << std::endl;
std::cout << std::endl;
std::cout << "The module contains the following types: " << std::endl;
for(
mi::Size i = 0; i < types->get_size(); ++i) {
std::cout << " " << result->get_c_str() << std::endl;
}
std::cout << std::endl;
std::cout << "The module contains the following constants: " << std::endl;
for(
mi::Size i = 0; i < constants->get_size(); ++i) {
const char* name = constants->get_name( i);
std::cout << " " << name << " = " << result->get_c_str() << std::endl;
}
std::cout << std::endl;
mi::Size function_count = module->get_function_count();
std::cout << "The module contains the following function definitions:" << std::endl;
for(
mi::Size i = 0; i < function_count; i++)
std::cout << " " << module->get_function( i) << std::endl;
std::cout << std::endl;
mi::Size material_count = module->get_material_count();
std::cout << "The module contains the following material definitions:" << std::endl;
for(
mi::Size i = 0; i < material_count; i++)
std::cout << " " << module->get_material( i) << std::endl;
std::cout << std::endl;
std::cout << "Dumping function definition \"" << function_definition_name << "\":"
<< std::endl;
dump_definition(
transaction.get(), mdl_factory.get(), function_definition.get(), 1, std::cout);
std::cout << "Dumping material definition \"" << material_definition_name << "\":"
<< std::endl;
dump_definition(
transaction.get(), mdl_factory.get(), material_definition.get(), 1, std::cout);
std::cout << "Dumping resources of this module: \n";
for(
mi::Size r = 0, rn = module->get_resources_count(); r < rn; ++r)
{
module->get_resource( r));
const char* db_name = resource->get_value();
const char* mdl_file_path = resource->get_file_path();
if( db_name == nullptr)
{
std::cout << " db_name: none" << std::endl;
std::cout << " mdl_file_path: " << mdl_file_path << std::endl
<< std::endl;
continue;
}
std::cout << " db_name: " << db_name << std::endl;
std::cout << " mdl_file_path: " << mdl_file_path << std::endl;
resource->get_type());
switch( type->get_kind())
{
{
if( texture)
{
for(
mi::Size f = 0, fn = image->get_length(); f < fn; ++f)
for(
mi::Size t = 0, tn = image->get_frame_length( f); t < tn; ++t)
{
const char* resolved_file_path = image->get_filename( f, t);
std::cout << " resolved_file_path[" << f << "," << t << "]: "
<< resolved_file_path << std::endl;
}
}
break;
}
{
if( light_profile)
{
const char* resolved_file_path = light_profile->get_filename();
std::cout << " resolved_file_path: " << resolved_file_path << std::endl;
}
break;
}
{
if( mbsdf)
{
const char* resolved_file_path = mbsdf->get_filename();
std::cout << " resolved_file_path: " << resolved_file_path << std::endl;
}
break;
}
default:
break;
}
std::cout << std::endl;
}
}
}
int MAIN_UTF8( int , char* [])
{
if (!neuray.is_valid_interface())
exit_failure("Failed to load the SDK.");
if (!mi::examples::mdl::configure(neuray.get()))
exit_failure("Failed to initialize the SDK.");
if (ret != 0)
exit_failure("Failed to initialize the SDK. Result code: %d", ret);
load_module( neuray.get());
exit_failure("Failed to shutdown the SDK.");
neuray = nullptr;
if (!mi::examples::mdl::unload())
exit_failure("Failed to unload the SDK.");
exit_success();
}
COMMANDLINE_TO_UTF8
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
A scene element that stores measured BSDF data.
Definition: ibsdf_measurement.h:39
This interface is used to interact with the distributed database.
Definition: idatabase.h:289
This interface represents a function definition.
Definition: ifunction_definition.h:44
This interface represents a pixel image file.
Definition: iimage.h:66
This interface represents light profiles.
Definition: ilightprofile.h:73
Factory for various MDL interfaces and functions.
Definition: imdl_factory.h:53
virtual IMdl_execution_context * create_execution_context()=0
Creates an execution context.
virtual IType_factory * create_type_factory(ITransaction *transaction)=0
Returns an MDL type factory for the given transaction.
virtual IExpression_factory * create_expression_factory(ITransaction *transaction)=0
Returns an MDL expression factory for the given transaction.
virtual IValue_factory * create_value_factory(ITransaction *transaction)=0
Returns an MDL value factory for the given transaction.
API component for MDL related import and export operations.
Definition: imdl_impexp_api.h:43
This interface represents an MDL module.
Definition: imodule.h:634
This is an object representing the MDL SDK library.
Definition: ineuray.h:44
virtual Sint32 shutdown(bool blocking=true)=0
Shuts down the library.
virtual base::IInterface * get_api_component(const base::Uuid &uuid) const =0
Returns an API component from the MDL SDK API.
virtual Sint32 start(bool blocking=true)=0
Starts the operation of the MDL SDK library.
Textures add image processing options to images.
Definition: itexture.h:68
A transaction provides a consistent view on the database.
Definition: itransaction.h:82
virtual const base::IInterface * access(const char *name)=0
Retrieves an element from the database.
virtual Sint32 commit()=0
Commits the transaction.
@ TK_TEXTURE
A texture type. See mi::neuraylib::IType_texture.
Definition: itype.h:180
@ TK_BSDF_MEASUREMENT
The bsdf_measurement type. See mi::neuraylib::IType_bsdf_measurement.
Definition: itype.h:184
@ TK_LIGHT_PROFILE
The light_profile type. See mi::neuraylib::IType_light_profile.
Definition: itype.h:182
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46