Get stage visibility of meshes

Hi, I’m trying to create a simple extension which returns the count of all visible meshes on a stage. So far I have :

from pxr import Usd, UsdGeom, UsdLux
stage = omni.usd.get_context().get_stage()
Mesh_Count = [x for x in stage.Traverse() if x.IsA(UsdGeom.Mesh)]
print(len(Mesh_Count))

Which totals all meshes on the stage, what is the best way to add to this to only get the currently visible meshes? Would GetVisibilityAttr () be the correct way?

Thanks!

Visibility is a property inherited from the UsdGeomImageable class. Here’s a snippet that I wrote, but I just realized that in your case you don’t really need to check if the prim inherits from Imageable because you’re already filtering down to Meshes only which are definitely Imageable. You can simplify this a bit for your case:

def isVisible(prim:Usd.Prim):
    if prim.IsA(UsdGeom.Imageable):
        imageable = UsdGeom.Imageable(prim)
        if imageable.ComputeVisibility() == UsdGeom.Tokens.invisible:
            return False
        else:
            return True
    return

Awesome, thanks Mati. I’ll try and integrate this into the code I already have later.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.