IMdl_entity_resolver usage

Is there an example for proper usage of an IMdl_entity_resolver? In my specific application, I’m looking to make a custom resource resolver, and running into issues setting it up. As a test, I’m trying to create a minimal example, but running into link issues since the class is still abstract (missing retain/release/get_interface/get_iid).

class MdlEntityResolverTest : public mi::neuraylib::IMdl_entity_resolver
{
public:
virtual mi::neuraylib::IMdl_resolved_module* resolve_module(
const char* module_name,
const char* owner_file_path,
const char* owner_name,
int pos_line,
int pos_column,
mi::neuraylib::IMdl_execution_context* context);

virtual mi::neuraylib::IMdl_resolved_resource* resolve_resource(
    const char* file_path,
    const char* owner_file_path,
    const char* owner_name,
    int pos_line,
    int pos_column,
    mi::neuraylib::IMdl_execution_context* context);

};

mi::neuraylib::IMdl_resolved_module* MdlEntityResolverTest::resolve_module(
const char* module_name,
const char* owner_file_path,
const char* owner_name,
int pos_line,
int pos_column,
mi::neuraylib::IMdl_execution_context* context)
{
return nullptr;
}

mi::neuraylib::IMdl_resolved_resource* MdlEntityResolverTest::resolve_resource(
const char* file_path,
const char* owner_file_path,
const char* owner_name,
int pos_line,
int pos_column,
mi::neuraylib::IMdl_execution_context* context)
{
return nullptr;
}

/////

MdlEntityResolverTest* resolver = new MdlEntityResolverTest(); // link error

Thanks!

Hi habs,

you should not derive from mi::neuraylib::IMdl_entity_resolver directly but instead derive from mi::base::Interface_implement<mi::neuraylib::IMdl_entity_resolver>. This implements the missing interface functions.

You can find documentation about implementing MDL SDK interfaces at Library Design

And you can find the implementation of the entity resolver inside MDL SDK at

Do you mind sharing something about your use-case for the custom resource resolver?

Best regards
Moritz

Thanks Moritz. Much appreciated! I’ve been kinda hacking the example code together so the library design doc is very useful.

To give you a little context, my use case is to take a USD scene (such as in USD Composer) and flatten it into a standalone player. The first build step involves walking the USD stage and gathering all the assets, whereas the later stages involve processing meshes, compressing textures, and compiling materials (using MDL and DXC).

The specific reason for an asset resolver is a cache. In the original USD scene, the lines reference files online, like this:

                uniform asset info:mdl:sourceAsset = @https://omniverse-content-production.s3.us-west-2.amazonaws.com/Materials/2023_2_1/Base/Masonry/Brick_Wall_Brown.mdl@

Which I then store in the cache as 13024321917955784816.mdl. Then that mdl file has local references like this:

    diffuse_texture: texture_2d("./Brick_Wall_Brown/Brick_Wall_Brown_BaseColor.png" /* tag 2739, version 3703676365 */, ::tex::gamma_srgb),

So that’s the reason for the entity resolver. There needs to a correspondence between the full path and the data stored in the local cache. Hope that helps, and feel free to ask if you have any more questions.