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?
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