NVIDIA-Omniverse / OpenUSD-Code-Samples

Common code snippets for OpenUSD
Apache License 2.0
65 stars 17 forks source link

Prim visibility does not show visibility info #72

Open cadop opened 3 months ago

cadop commented 3 months ago

This example:

https://github.com/NVIDIA-Omniverse/OpenUSD-Code-Samples/blob/958494b8845768ed47be58bfc06e91987ea6e2d3/source/visibility/show-hide-prim/py_usd.py#L62-L67

Shows the prims attribute of visible or inherited. Inherited does not mean visible, but invisible means invisible. This is unclear. There should at least be some method showing how to check its actual visibility (based on what it inherits).

mati-nvidia commented 3 months ago

I'm jumping back on this repo soon.

I think we probably want an additional sample around the idea of "Get the visibility state of a prim" that shows the use of ComputeVisibility

cadop commented 3 months ago

Interesting,

This function should be considered a reference implementation for correctness. 
If called on each prim in the context of a traversal we will perform massive overcomputation, 
because sibling prims share sub-problems in the query that can be efficiently cached, 
but are not (cannot be) by this simple implementation.
 If you have control of your traversal, it will be far more efficient to manage visibility 
on a stack as you traverse.

So should an example be using this method, or doing the traversal

mati-nvidia commented 3 months ago

I think for most cases, I would start with this function and optimize when needed. It doesn't make sense to deal with the logic of traversal and caching if you're maybe just checking a few targeted prims.

cadop commented 3 months ago

For future PR reference:

Annoying syntax, instead of just having it as an attribute, create an Imageable, then compute it. It's not true/false, so then check against the token.

#Check if prim is visible in the scene or not
if UsdGeom.Imageable(x).ComputeVisibility() == UsdGeom.Tokens.invisible:
    print('Invisible')