Omniverse Create .mdl Material Application Using C++ Sometimes Fails

Hello!

I’m developing an Omniverse connector for 3d geometry and I am trying to have it apply materials using the C++ API as demonstrated in the connector sample.

There are three different materials that I’m pulling in here - originally they were all from the NVIDIA mount on my Nucleus server, but now I’ve copied the whole vMaterials library off of the mount in an effort to remedy my inconsistencies (I was thinking it may have been an internet issue).

To elaborate: I’ve encountered some frustrating inconsistency and an error that I need help interpreting.

The inconsistency is that sometimes when I open a file all three materials appear to load in properly, but sometimes one or more of the materials will fail to load. I think this has something to do with the first error of the two shown below.

The second error below is quite clear - the texture file isn’t loading in for one of the materials (but the other two materials have loaded in successfully). This material has also loaded in perfectly fine as recently as this morning - and I don’t believe I’ve edited anything in this file since then.

I had received direction here on how to do this:

Following that advice: here is the function I’m using to bind the material. I quite literally ripped the MDL shader part of the function out of the connector sample and replaced some hardcoded material references with input variables pointing to mdl names and directories:

Please let me know if I’m doing anything blatantly wrong - or if I have anything missing here.



I’m using a gold material, a zinc material, and a clay material in my demo

Here are some more images - pay no attention to my scene hierarchy being out of order :)



Showing the gold material applied correctly



Showing failed application of the clay material



Showing successful application of zinc material on front face but strange behavior of the zinc material on the top face - could this be due to a failed uv map?


I appreciate any help! Thank you!

I can’t say what the problem is, but when using the HelloWorld.cpp code in one of my experiments, I noticed that the std::string newShaderName = mdlShaderModule.GetAssetPath(); and SdfAssetPath(newShaderName) pair is redundant because the latter is already the SdfAssetPath mdlShaderModule you defined at the beginning of that code block.

Also in the line with mdlShader.GetPrim().CreateAttribute()...Set(TfToken(materialName)); there is no need to create that TfToken again, because that is already available via materialNameToken in the second line of your screenshot.

That shouldn’t make any difference, except for cleaner code.

I basically used the same code, just copied the MDL shaders to a folder in Nucleus before referencing them and have not seen that error.

(Please do not post screen shots of code, instead use code blocks with the text. That would be easier to reference.)

1 Like

I’m just catching up, but we do not support “back slashes” in any paths in USD or MDL, so it’s possible that the key is in the Failed to load texture O:\Users\test\Materials\vMaterials_2\Ceramic\textures\fired_clay_fired_clay_diff.jpg.

I’ll continue looking at your question to see if there’s anything else I see.

1 Like

I will get rid of that redundancy! Good call!

And I think the back slashes are just how the file names are portrayed in the Omniverse console.

I had hardcoded these material names and paths for debugging purposes, here is how they are defined in code:

	string matname1 = "Metal_Gold";
	string matname2 = "Grog_Fired_Clay";
	string matname3 = "Metal_Zinc";

	string matpath1 = "O:/Users/test/Materials/vMaterials_2/Metal/Gold/Metal_Gold.mdl";
	string matpath2 = "O:/Users/test/Materials/vMaterials_2/Ceramic/Grog_Fired_Clay.mdl";
	string matpath3 = "O:/Users/test/Materials/vMaterials_2/Metal/Zinc/Metal_Zinc.mdl";

I used all forward slashes for that reason. And there isn’t an issue pointing to the .mdl file, only to one of the texture map images it references (even though the names appear to match), this one to be specific:

A discrepancy between the material previews when selecting individual meshes is apparent too. When looking at the gold and zinc materials here, the ‘preview material’ image is shown with the material applied to a complex object. But when looking at the material preview for the mesh with the clay applied to it, it only shows the sphere. I don’t think this is relevant, just wanted to point it out. The little previews are in the bottom left of the images included in the original post.

Matthew, I’m not satisfied that you’re still having issues, so I took some time to mess around with the helloWorld.cpp sample. I can’t reproduce what you’re seeing, but I’ll paste my code here and maybe you can make some sense of it. I made these changes:

  • Added a domelight function that allows you to specify the texture
  • Added a new createMaterialV2() function that allows you to specify a path to the material (like you did)
  • Added a createBoxReference() function so that you can reference the first box that you create rather than generating new geometry. This is also slightly related to a referencing and instancing question on the forums.

Note that it’s required that your O:/ drive is mapped to a Nucleus server that has the /NVIDIA folder mounted.

I hope to feed some of these changes back into the Connect Sample after I clean it up a bit.

helloWorld.cpp (33.8 KB)

1 Like

Great! I’m going to rewrite/reorganize my connector soon (now that I have a better idea of how USD and Omniverse work) so this will be a useful resource. I’ll reply here if I isolate the problem in case anyone else hits this issue