-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTraverseHierarchy.py
More file actions
66 lines (52 loc) · 1.66 KB
/
TraverseHierarchy.py
File metadata and controls
66 lines (52 loc) · 1.66 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
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
import omni.usd
# ---------------------------------------.
# traverse the hierarchy.
# ---------------------------------------.
def TraverseHierarchy(depth, prim):
if prim.IsValid() == None:
return
indentStr = ''
for i in range(depth):
indentStr += ' '
# Print Prim information.
name = prim.GetName()
typeName = prim.GetTypeName()
s = indentStr + '[ ' + name + ' ]'
s += ' type : ' + typeName
# If hidden.
if UsdGeom.Imageable(prim).ComputeVisibility() == 'invisible':
s += ' ** Hide **'
print(s)
if typeName == 'Mesh':
# Get the number of faces of Mesh.
m = UsdGeom.Mesh(prim)
faceCount = len(m.GetFaceVertexCountsAttr().Get())
print(indentStr + ' Face count : ' + str(faceCount))
# Recursively traverse the hierarchy.
pChildren = prim.GetChildren()
for cPrim in pChildren:
TraverseHierarchy(depth + 1, cPrim)
# ---------------------------------------.
# Get stage.
stage = omni.usd.get_context().get_stage()
# Get default prim.
print("--- Default prim ---")
defaultPrim = stage.GetDefaultPrim()
if defaultPrim.IsValid():
print("DefaultPrim(Name) : " + defaultPrim.GetName())
print("DefaultPrim(Path) : " + defaultPrim.GetPath().pathString)
else:
print("Default Prim does not exist.")
print("")
# Get root path.
rootPath = '/'
if defaultPrim.IsValid():
rootPath = defaultPrim.GetPath().pathString
print("Root path : " + rootPath)
print("")
# traverse the hierarchy.
tPrim = stage.GetPrimAtPath(rootPath)
print("--- Hierarchy ---")
TraverseHierarchy(0, tPrim)
print("")