-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGetTransformVectors.py
More file actions
49 lines (36 loc) · 1.69 KB
/
GetTransformVectors.py
File metadata and controls
49 lines (36 loc) · 1.69 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
from pxr import Usd, UsdGeom, UsdPhysics, UsdShade, Sdf, Gf, Tf
import omni.usd
import omni.timeline
# Get stage.
stage = omni.usd.get_context().get_stage()
# Get selection.
selection = omni.usd.get_context().get_selection()
paths = selection.get_selected_prim_paths()
time_code = Usd.TimeCode.Default()
for path in paths:
prim = stage.GetPrimAtPath(path)
if prim.IsValid() == True:
# Print prim name.
print(f"[ {prim.GetName()} ]")
# Get transform.
# However, the type that can be obtained here is different from the actual Type.
xformAPI = UsdGeom.XformCommonAPI(prim)
translation, rotation, scale, pivot, rotOrder = xformAPI.GetXformVectors(time_code)
print("** GetXformVectors **")
print(f"translation : {type(translation)} {translation}")
print(f"rotation : {type(rotation)} {rotation}")
print(f"scale : {type(scale)} {scale}")
print(f"pivot : {type(pivot)} {pivot}")
print(f"rotOrder : {type(rotOrder)} {rotOrder}")
print("** prim.GetAttribute **")
trans = prim.GetAttribute("xformOp:translate").Get()
print(f"trans : {type(trans)} {trans}")
# Convert rotOrder to "xformOp:rotateXYZ" etc.
t = xformAPI.ConvertRotationOrderToOpType(rotOrder)
rotateAttrName = "xformOp:" + UsdGeom.XformOp.GetOpTypeToken(t)
rotate = prim.GetAttribute(rotateAttrName).Get()
print(f"rotate ({rotateAttrName}) : {type(rotate)} {rotate}")
scale = prim.GetAttribute("xformOp:scale").Get()
print(f"scale : {type(scale)} {scale}")
pivot = prim.GetAttribute("xformOp:translate:pivot").Get()
print(f"pivot : {type(pivot)} {pivot}")