def pre_draw(viewer): global recompute, anim_t, poses, C, BE, P, U, M, anim_t_dir if recompute: # Find pose interval begin = int(math.floor(anim_t)) % len(poses) end = int(math.floor(anim_t) + 1) % len(poses) t = anim_t - math.floor(anim_t) # Interpolate pose and identity anim_pose = igl.RotationList() for e in range(len(poses[begin])): anim_pose.append(poses[begin][e].slerp(t, poses[end][e])) # Propagate relative rotations via FK to retrieve absolute transformations vQ = igl.RotationList() vT = [] igl.forward_kinematics(C, BE, P, anim_pose, vQ, vT) dim = C.cols() T = igl.eigen.MatrixXd(BE.rows() * (dim + 1), dim) for e in range(BE.rows()): a = igl.eigen.Affine3d.Identity() a.translate(vT[e]) a.rotate(vQ[e]) T.setBlock(e * (dim + 1), 0, dim + 1, dim, a.matrix().transpose().block(0, 0, dim + 1, dim)) # Compute deformation via LBS as matrix multiplication if use_dqs: igl.dqs(V, W, vQ, vT, U) else: U = M * T # Also deform skeleton edges CT = igl.eigen.MatrixXd() BET = igl.eigen.MatrixXi() igl.deform_skeleton(C, BE, T, CT, BET) viewer.data.set_vertices(U) viewer.data.set_edges(CT, BET, sea_green) viewer.data.compute_normals() if viewer.core.is_animating: anim_t += anim_t_dir else: recompute = False return False
def pre_draw(viewer): global pose, anim_t, C, BE, P, U, M, anim_t_dir if viewer.core.is_animating: # Interpolate pose and identity anim_pose = igl.RotationList(len(pose)) for e in range(len(pose)): anim_pose[e] = pose[e].slerp(anim_t, igl.eigen.Quaterniond.Identity()) # Propagate relative rotations via FK to retrieve absolute transformations vQ = igl.RotationList() vT = [] igl.forward_kinematics(C, BE, P, anim_pose, vQ, vT) dim = C.cols() T = igl.eigen.MatrixXd(BE.rows() * (dim + 1), dim) for e in range(BE.rows()): a = igl.eigen.Affine3d.Identity() a.translate(vT[e]) a.rotate(vQ[e]) T.setBlock(e * (dim + 1), 0, dim + 1, dim, a.matrix().transpose().block(0, 0, dim + 1, dim)) # Compute deformation via LBS as matrix multiplication U = M * T # Also deform skeleton edges CT = igl.eigen.MatrixXd() BET = igl.eigen.MatrixXi() igl.deform_skeleton(C, BE, T, CT, BET) viewer.data().set_vertices(U) viewer.data().set_edges(CT, BET, sea_green) viewer.data().compute_normals() anim_t += anim_t_dir anim_t_dir *= -1.0 if (0.0 >= anim_t or anim_t >= 1.0) else 1.0 return False
V = igl.eigen.MatrixXd() W = igl.eigen.MatrixXd() U = igl.eigen.MatrixXd() C = igl.eigen.MatrixXd() M = igl.eigen.MatrixXd() Q = igl.eigen.MatrixXd() T = igl.eigen.MatrixXi() F = igl.eigen.MatrixXi() BE = igl.eigen.MatrixXi() P = igl.eigen.MatrixXi() sea_green = igl.eigen.MatrixXd([[70. / 255., 252. / 255., 167. / 255.]]) selected = 0 pose = igl.RotationList() anim_t = 1.0 anim_t_dir = -0.03 igl.readMESH(TUTORIAL_SHARED_PATH + "hand.mesh", V, T, F) U = igl.eigen.MatrixXd(V) igl.readTGF(TUTORIAL_SHARED_PATH + "hand.tgf", C, BE) # Retrieve parents for forward kinematics igl.directed_edge_parents(BE, P) # Read pose as matrix of quaternions per row igl.readDMAT(TUTORIAL_SHARED_PATH + "hand-pose.dmat", Q) igl.column_to_quats(Q, pose) assert (len(pose) == BE.rows())