Let’s say I have a usd primitive, I want on stage saving (before) change a string attribute of the primitive. My primitive should be compatible with all the existing usd editor without to modify anything and neither I want to ask a change in OpenUSD ( because it would mean wait the next editor release to update the openusd version ). Is it possible?
Looking into the code I was thinking to a really dirty way using HdRprim::Finalize that should be called on stage close/save but I don’t know if I can modify a usd attribute directly from an HdRprim.
Probably I’m confused and I’m only trying to do something not supported.
All classes starting with “Hd” refer to Hydra, which is only used for passing data to a renderer. Sounds like you want to modify the .usd or .usda file that ends up on disk, which has nothing at all to do with hydra, so that class won’t help.
As far as I’m aware there is no mechanism built into USD which provides any kind of “callback” or other opportunity to edit data before it is written to disk. Most DCCs probably have some mechanism for this, and you can always wait until the save is done, then reopen the USD file that was just written, modify the data and re-save it. This is obviously more expensive than changing the data before saving, but not very expensive for binary USD files (which can save the change to the data without having to rewrite the entire file).
I would agree with @mtucker that that might fit better as part of DCC frameworks… so potentially a feature that could be added to usdview, as well. But having user-plugins invoked as part of UsdStage::Save() introduces several potential points of failure and confusion, so not something we’d be likely to pursue.
The idea was to make a plugin able to work in any openusd editor, modify the dcc code (when possible) is not a solution. I have to design something different.