-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGetAllFacesCount.py
More file actions
80 lines (61 loc) · 2.27 KB
/
GetAllFacesCount.py
File metadata and controls
80 lines (61 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
# ---------------------------------------.
# Get the number of faces used by PointInstancer.
# ---------------------------------------.
def TraversePointInstancer(prim):
allCou = 0
if prim.IsA(UsdGeom.Mesh):
m = UsdGeom.Mesh(prim)
# If it is displayed.
if m.ComputeVisibility() == UsdGeom.Tokens.inherited:
# Get the number of faces of Mesh.
allCou += len(m.GetFaceVertexCountsAttr().Get())
# Recursively traverse the hierarchy.
pChildren = prim.GetChildren()
for cPrim in pChildren:
allCou += TraversePointInstancer(cPrim)
return allCou
# ---------------------------------------.
# traverse the hierarchy.
# ---------------------------------------.
def TraverseHierarchy_number(depth, prim):
if prim.IsValid() == None:
return 0
typeName = prim.GetTypeName()
allCou = 0
if prim.IsA(UsdGeom.PointInstancer):
m = UsdGeom.PointInstancer(prim)
# If it is displayed.
if m.ComputeVisibility() == UsdGeom.Tokens.inherited:
# Get the number of faces used by PointInstancer.
facesCou = TraversePointInstancer(prim)
piCou = 0
positionsA = m.GetPositionsAttr().Get()
if positionsA != None:
piCou = len(positionsA)
allCou += facesCou * piCou
return allCou
if prim.IsA(UsdGeom.Mesh):
m = UsdGeom.Mesh(prim)
# If it is displayed.
if m.ComputeVisibility() == UsdGeom.Tokens.inherited:
# Get the number of faces of Mesh.
allCou += len(m.GetFaceVertexCountsAttr().Get())
# Recursively traverse the hierarchy.
pChildren = prim.GetChildren()
for cPrim in pChildren:
allCou += TraverseHierarchy_number(depth + 1, cPrim)
return allCou
# ---------------------------------------.
# Get stage.
stage = omni.usd.get_context().get_stage()
# Get default prim.
defaultPrim = stage.GetDefaultPrim()
# Get root path.
rootPath = "/"
if defaultPrim.IsValid():
rootPath = defaultPrim.GetPath().pathString
# traverse the hierarchy.
tPrim = stage.GetPrimAtPath(rootPath)
allFacesCou = TraverseHierarchy_number(0, tPrim)
print(f"Number of all faces : {allFacesCou}")