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 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]))

        # Propogate 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
Example #3
0
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
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