LumaPictures / usd-qt

Reusable Qt Components for Pixar's USD
Other
153 stars 41 forks source link

HierarchyModel: Add support for automatically populating parents when looking up path #17

Open nrusch opened 5 years ago

nrusch commented 5 years ago

Currently, the HierarchyModel does not provide a way to search for a prim path in the active stage. While there is a GetIndexForPath method, this only looks at the current state of the hierarchy cache, without populating it any further.

We have an internal need to be able to look up a path's index (if present) without knowing whether the path's parent already exists in the hierarchy cache, and I think it makes sense to add this to the model as a first-class feature. This can currently be done semi-manually by recursing through the path's prefixes and calling HierarchyModel.index() for each child row, but I would like to implement this on the HierarchyModel in a more efficient way (possibly doing the leg work in the C++ _HierarchyCache class).

bfloch commented 5 years ago

Hi @nrusch,

Please correct me if I am wrong: Iterating SdfPath prefixes is not enough, since it does not know about the order among other child prims. Therefore the row necessary for the index can not be extracted.

I wonder what the most efficient way to do this correctly would be. SdfChildrenView? Stage traversal is depth-first so one would pretty much need to go through the whole stage. At this point the cache is not that lazy anymore.

Is there a current workaround that you can share? Our use case is pretty much a prim seleciton in a stageView that we want to communicate to the Outliner.

Thanks.

nrusch commented 5 years ago

Hey @bfloch,

Iterating SdfPath prefixes is not enough, since it does not know about the order among other child prims.

I was only mentioning that in relation to the current brute-force workaround we are using internally with the HierarchyModel itself, which looks something like this:

lastIndex = model.GetIndexForPath('/')
for prefix in pathToPopulate.GetPrefixes():
    index = model.GetIndexForPath(prefix)
    if not index:
        for row in xrange(model.rowCount(lastIndex)):
            model.index(row, 0, lastIndex
    lastIndex = index

As for the long-term solution, we'll definitely have to do a little experimentation.