-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parent_transform.py
More file actions
59 lines (47 loc) · 2.19 KB
/
test_parent_transform.py
File metadata and controls
59 lines (47 loc) · 2.19 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
#!/usr/bin/env python
"""
Test to check if parent prim has transforms that affect the Geom child.
"""
from pxr import Usd, UsdGeom
import sys
def main():
print("=" * 80)
print("PARENT TRANSFORM CHECK")
print("=" * 80)
# Open USD file
usd_file = "/Users/nickgrobler/Projects/USD/Kitchen_set/Kitchen_set.usd"
stage = Usd.Stage.Open(usd_file)
parent_path = "/Flat/Kitchen_set/Props_grp/DiningTable_grp/ChairB_2"
geom_path = "/Flat/Kitchen_set/Props_grp/DiningTable_grp/ChairB_2/Geom"
parent_prim = stage.GetPrimAtPath(parent_path)
geom_prim = stage.GetPrimAtPath(geom_path)
print(f"\n1. Parent prim: {parent_path}")
if parent_prim.IsA(UsdGeom.Xformable):
parent_xformable = UsdGeom.Xformable(parent_prim)
parent_ops = parent_xformable.GetOrderedXformOps()
print(f" Number of xform ops: {len(parent_ops)}")
for i, op in enumerate(parent_ops):
print(f" Op {i}: {op.GetOpName()} = {op.Get()}")
parent_local_to_world = parent_xformable.ComputeLocalToWorldTransform(Usd.TimeCode.Default())
parent_world_pos = parent_local_to_world.ExtractTranslation()
print(f" Parent world position: {parent_world_pos}")
else:
print(f" Parent is NOT xformable")
print(f"\n2. Geom child: {geom_path}")
if geom_prim.IsA(UsdGeom.Xformable):
geom_xformable = UsdGeom.Xformable(geom_prim)
geom_ops = geom_xformable.GetOrderedXformOps()
print(f" Number of xform ops: {len(geom_ops)}")
for i, op in enumerate(geom_ops):
print(f" Op {i}: {op.GetOpName()} = {op.Get()}")
geom_local_to_world = geom_xformable.ComputeLocalToWorldTransform(Usd.TimeCode.Default())
geom_world_pos = geom_local_to_world.ExtractTranslation()
print(f" Geom world position: {geom_world_pos}")
print(f"\n3. Analysis:")
print(f" If parent has transforms, the Geom child's LOCAL xform ops")
print(f" will be transformed by the parent's matrix.")
print(f" So setting Geom's translate to (300, 400, 0) will NOT result")
print(f" in world position (300, 400, 0) if parent has transforms!")
return 0
if __name__ == "__main__":
sys.exit(main())