要围绕世界 Y 轴将节点旋转任意度数,请执行以下操作(https://en.wikipedia.org/wiki/Rotation_matrix):
import math
from pyfbsdk import *
angle = 45.0
radians = math.radians(angle)
root_matrix = FBMatrix()
root.GetMatrix(root_matrix, FBModelTransformationType.kModelRotation, True)
transformation_matrix = FBMatrix([
math.cos(radians), 0.0, math.sin(radians), 0.0,
0.0, 1.0, 0.0, 0.0,
-math.sin(radians), 0.0, math.cos(radians), 0.0,
0.0, 0.0, 0.0, 1.0
])
result_matrix = root_matrix * transformation_matrix
root.SetMatrix(result_matrix , FBModelTransformationType.kModelRotation, True)
如果根节点上有任何预旋转,则该过程会更加复杂,您可以尝试使用带有 LRMToDof 方法的 SetVector 设置旋转。
result_vector = FBVector3d()
root.LRMToDof(result_vector, result_matrix)
root.SetVector(result_vector, FBModelTransformationType.kModelRotation, True)