MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Graph Editor: Add OpenUSD export option to the menu

Open beersandrew opened this issue 2 years ago • 5 comments

Add an option to the menu that allows the user to create a new OpenUSD stage that references the currently active MaterialX material.

beersandrew avatar Oct 06 '23 15:10 beersandrew

Some info from Slack and additional suggestions.

It seems it would be easiest to write this in Python but don't have it.

  • Grab a prebuilt version of Usd (e.g. from NVIDIA)
  • Suggested to create a stage file with a reference to the MaterialX document.
    • So that needs to be created and saved.
    • Can use some default geometry or reference the MaterialX shader ball or any other geometry (bit more work)
  • You can use Python to create the usda file and write the reference
  • Use usdcat to "flatten" the file to another usda file.
  • Load it into something like usdview for comparison.
  • If you want to be "nice" hook this all up to a the editor and bring up usdview.

e.g. Here is the default marble in usdview image

Notes: Make sure that your PYTHONPATH, PATH and PXR_MTLX_STDLIB_SEARCH_PATHS are set correctly. You need the latter so that MaterialX definitions are found.

kwokcb avatar Oct 06 '23 21:10 kwokcb

@kwokcb Could we potentially simplify this further, and run usdcat directly on the MaterialX file that is saved from the Graph Editor? This would reduce the process of USD file generation to a single step, and the Graph Editor would only need the ability to run an arbitrary "post-process hook" on a MaterialX file after it is saved, with the invocation of usdcat on the generated file being one option that the user can request.

jstone-lucasfilm avatar Oct 06 '23 23:10 jstone-lucasfilm

Hi @jstone-lucasfilm ,

I think the simplest possible option is to pass the filename to a script / cmd (which is your command hook). The script needs to consume the file name as an argument and can then do whatever it want's with it. So in this case it would need to fill-in / create the usda file with the materialx reference such as shown below:

#usda 1.0
(
    defaultPrim = "mxCapsule"
)

def Xform "mxCapsule" (
    kind = "component"
)
{
    def Capsule "geom" (
        prepend apiSchemas = ["MaterialBindingAPI"]
    )
    {
        rel material:binding = </MaterialX/Materials/Marble_3D>
    }
}

over "MaterialX"
(
    references = [@  ...file string inserted here... @</MaterialX>]
)
{
}

The script can run usdcat for flattening or any command it wants, including also running usdview.

If you want to make it arbitrary a command line option could be added. e.g.

--<export / post save option> "<run my script %f>" 

where %f is the name of the saved file, and "run my script %f" would be run after save.

kwokcb avatar Oct 10 '23 02:10 kwokcb

I think this example is the simplest goal / target to dynamically generate.

kwokcb avatar Oct 10 '23 12:10 kwokcb