Hi,
I’m trying to create a new material function by cloning an existing material function definition. I can generate the new function body by walking the argument trees of the source function (IFunction_definition::get_body()->get_arguments()). This appears to generate a valid set of arguments for the new function call but after calling IMdl_module_builder::add_function, any unresolved resource values (ie body textures) are getting squashed to invalid resource references. At a high level the code looks like this:
mi::base::Handle<const mi::neuraylib::IExpression> sourceBody(sourceDefinition->get_body());
mi::base::Handle<const mi::neuraylib::IExpression_direct_call> sourceBodyDC(sourceBody->get_interface<mi::neuraylib::IExpression_direct_call>());
mi::base::Handle<const mi::neuraylib::IExpression_list> sourceArgs(sourceBodyDC->get_arguments());
mi::base::Handle<mi::neuraylib::IExpression_list> newBodyArgs(CloneExpression(sourceArgs));
mi::base::Handle<mi::neuraylib::IExpression> newBodyDC(ef->create_direct_call(sourceBodyDC->get_definition(), newBodyArgs.get()));
moduleBuilder->add_function(newName, newBodyDC.get(), ...);
When accessing the newly created function I see all the body resources are now invalid references. I think it’s happening because the AST builder can’t handle unresolved resources (MDL-SDK/src/io/scene/mdl_elements/mdl_elements_ast_builder.cpp at 203d5140b1dee89de17b26e828c4333571878629 · NVIDIA/MDL-SDK · GitHub)? With that theory I tried to find a way to resolve an IValue_resource to a DB element but as far as I can see I can only get the file path. Can I get the DB name from the file path? Is there a better way to clone a material (eventually I’ll be injecting some code)?
Cheers,
Justin