-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDecomposeTransform2.py
More file actions
37 lines (30 loc) · 1.15 KB
/
DecomposeTransform2.py
File metadata and controls
37 lines (30 loc) · 1.15 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
from pxr import Usd, UsdGeom, UsdSkel, UsdPhysics, UsdShade, Sdf, Gf, Tf
# --------------------------------------------------.
# Use Gf.Matrix4d.
# --------------------------------------------------.
# Dump matrix.
def DumpMatrix(m : Gf.Matrix4d):
print("---------------------")
for i in range(4):
print(f"{mm[i,0]} {mm[i,1]} {mm[i,2]} {mm[i,3]}")
print("")
# Create Matrix4.
translate = Gf.Vec3d(10.5, 2.8, 6.0)
rotation = Gf.Rotation(Gf.Vec3d(0, 1, 0), 20) * Gf.Rotation(Gf.Vec3d(0, 0, 1), 45)
scale = Gf.Vec3d(2.0, 0.5, 1.0)
mm = Gf.Matrix4d().SetScale(scale) * Gf.Matrix4d(rotation, Gf.Vec3d(0)) * Gf.Matrix4d().SetTranslate(translate)
DumpMatrix(mm)
# Decompose matrix.
mTransRotate = mm.RemoveScaleShear()
rTrans = mTransRotate.ExtractTranslation()
rRot = mTransRotate.ExtractRotation()
mScale = mm * mTransRotate.GetInverse()
rScale = Gf.Vec3d(mScale[0][0], mScale[1][1], mScale[2][2])
rAxisX = Gf.Vec3d(1, 0, 0)
rAxisY = Gf.Vec3d(0, 1, 0)
rAxisZ = Gf.Vec3d(0, 0, 1)
rRotE = rRot.Decompose(rAxisZ, rAxisY, rAxisX)
rRotE = Gf.Vec3d(rRotE[2], rRotE[1], rRotE[0])
print(f"Trans : {rTrans}")
print(f"Rot : {rRotE}")
print(f"Scale : {rScale}")