Get Value from Root and Session Layer

Hi,

Happy new year !

I’m trying to get values of attribute, from both root and session layers in an efficient way.

For example, root layer and session layer

#sdf 1.4.32

def "test"
{
    def Xform "a"
    {
        double3 xformOp:translate = (0, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate"]
    }
}
#usda 1.0

over "test"
{
    over "a"
    {
        double3 xformOp:translate = (1, -2, 3)
    }
}

If UsdAttribute API is being used, only override value (1, -2, 3) will be retrieved, the only way I figured out to get (0, 0, 0) from root layer will be like

auto tmp_stage = pxr::UsdStage::Open(stage->GetRootLayer());
auto attr = tmp_stage ->GetAttributeAtPath(_attr.GetPath());
pxr::VtValue value;
attr.Get(&value);

It has to re-open the root layer again to get rid of session layer, is there any better way to get the actual value at root layer ?

Thank you very much

You could use the GetPropertyStack method to find all the specs that contribute to the attribute

https://openusd.org/dev/api/class_usd_property.html#a2159d3d651cd66e4fb1c724be90ed5e0

1 Like

Unfortunately, PropertyStacks are not a robust means of fetching attribute values, except possibly in the case where all data is authored in defaults. If an attribute possess timeSamples or Value Clips, the PropertyStack will not provide you with the time-mapping information you’d need to correctly resolve a value. And once sparse array overrides are implemented, it will no longer be safe even to use PropertyStacks for resolving defaults, if the attribute is array valued.

The desired solution here is something I think we’ve filed, but have not yet scheduled, is the ability to provide an optional UsdEditTarget to UsdAttribute::Get(), which would be the layer/site to begin value resolution with.

In the meantime, the only thing I can suggest that is more efficient than reopening the stage is to mute the stage’s session layer, perform your necessary queries (better if you can batch them up to avoid needing to do this too many times), and then unmute it.

1 Like

Still many thanks to you :slight_smile:

Understood, I used to assume that the UsdEditTarget should work, and tried it to specify the session layer only but the API still returned override value.

Wish this could be solved in a more better way.