What is the best way to generate an in memory usda representation of an existing UsdShadeMaterial, all of it’s connectables/attributes/metadata and it’s UsdShadeShader children without creating a new stage and exporting as a usda file to disk?
I read your question as “other than the right way to do this, what is the right way to do this” ![]()
I would strongly recommend creating a stage, using the USD APIs to create and set up your prims, and then using UsdStage::ExportToString to generate a string containing the USDA serialization of that stage.
I don’t even know what the second choice would be… Generating the USDA string directly? Maybe that would make sense if you have a template USDA and you just need to search and replace specific tokens, but in the general case of authoring generic shader prims you’d end up just alternative versions of the USD APIs that output USDA text directly.
More so looking for a way to achieve this using the current stage we are operating on and somehow utilize the PrimSpec to do this. I have it working with geometry like UsdGeomXform and Mesh, but materials are not filling out all the connections and attributes.
Create a new stage with the root layer of the original stage and set its population mask to be all the prims you want to include, and call ExportToString. …or just call SetPopulationMask on the original stage and set it back after exporting.
Jerry
That looks promising! I will give it a try. Thanks!