Creating a Texture node with API

Is there a way to create an existing high level node using the API. For example, the file_texture node. The closest I’ve gotten is using CreateMdlMaterialPrimCommand, but it has issues. I may not understand how the platform architecture works. I am creating a OmniSurfaceShader and attempting to create a file_texture node then hopefully learn to connect it and set params. Heres the command I tried:

  omni.kit.commands.execute(
    "CreateMdlMaterialPrimCommand",
    mtl_url="C:/packman-repo/..long url../nvidia/core_definitions.mdl",
    mtl_name="file_texture",
    mtl_path="/World/Looks/MyMtl/file_texture"
  )

This makes a material and inside that is a shader which is a working file_texture if you manually move it out of the material capsule. Although its missing solo RGB outputs and color output is called tint. Any help would be appreciated.

Actually this method isnt working anymore on the newest kit, I’ll have to come back to this. But it would be cool to just be able to x.createNode(normalmap_texture) for any existing shaders. For an extenstion to automate material setup. Its possible with pbr through the map textbox, but for higher detail, subsurface, transmission, it needs the omnisurface, which needs nodes to conect to it.

Ok I can try to find out some information on this. And this HAS to be done through code and not through the normal Composer material node gui?

HI @derwinprince61

CreateMdlMaterialPrimCommand is used to create UsdShade Material prims. If what you’re trying to add to your scene is the File Texture Compound node from the Graph editor, you cannot do this with that command. Instead you need to use ImportCompoundCommand from omni.kit.window.material_graph or construct the compound node yourself using the USD UsdShadeAPI.

If the former is used, then you have to give it a USD file with the compound node that is stored in the extension.
If you look for the path of omni.kit.window.material_graph in the Extension Manager, you’ll see where the extension is stored.

The compound nodes are stored in /data/shaders/texture_return.usda

You can see usage in Command Utils.

And there’s sample code in /tests/test_commands.py

If you use the UsdShade API, then you need to create the UsdShade Material, Shader Prims, Attributes, and Connections for the complete Nodegraph.

I was actually able to find a solution after learning it was all just MDL. Which was to make a copy of a shader and learn a bit of mdl, enough to replace the colors with a texture slot. You can just import from core_definitons and base.

For the solution provided I’ll debug more but its having an error. Ill share the docu arguements expected and command used. And at bottom more about the issue.


parent_path - path of prim to add new compound to
source_asset - path to usd file (nodegraph as default prim)
identifier - name of the new prim

omni.kit.commands.execute(
“ImportCompoundCommand”,
parent_path=path,
source_asset=“C:/Users/x/Desktop/file_texture.usd”,
identifier=“Name”
)

Errors:
[omni.usd.commands.usd_commands] /World/Looks/(indentifier string) does not exist
Cannot copy unknown spec at </(indentifier string)> from layer <C:/Users/x/Desktop/file_texture.usd>’


Again, Ill look more into these later but it is kind of confusing when the path does exist for example /World/Looks/OmniPBR it will update and say path /World/Looks/OmniPBR_01 doesn’t exist. Thats with Sdf.Path(“/World/Looks”) + identifier = OmniPBR

And when adding random identifier name like “Name”, itll say path /World/Looks/X/Name doesn’t exist. Such as Sdf.Path(“/World/Looks/OmniPBR”) + identifier = Name

Also thank you for the additional info about usda, which I’ve not seen that format before and happy learn more about it. As well as the test_commands.py - which will be helpful to check out.

No it doesn’t have to be, and thanks for looking into it. @fpliu solution can be marked as solution if no further response. Thanks

Nvm its in the test_commands.py, haha. Didn’t realize it needs the texture usda. Marking as solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.