def GetFaceMesh()

in renderer/glViewer.py [0:0]


def GetFaceMesh(faceModel, faceParam_list, bComputeNormal = True, bApplyRot = False, bApplyTrans = False, bShowFaceId = False, bApplyRotFlip=False):

    MoshParam_list = []

    v_template = faceModel['v_template'] #11510 x 3
    v_template_flat = v_template.flatten()  #(34530,)
    v_template_flat = v_template_flat[:,np.newaxis] #(34530,1)  for broadcasting

    trifaces = faceModel['trifaces']  #22800 x 3

    U_id = faceModel['U_id'] #34530 x 150
    U_exp = faceModel['U_exp'] #34530 x 200


    for i, faceParam in enumerate(faceParam_list):

        print('processing: humanIdx{0}/{1}'.format(i, len(faceParam_list) ))
        #faceParam = faceParam_all[humanIdx]


        #Debug: only use the first 5
        faceParam['face_exp'][5:,:]=0

        """Computing face vertices for all frames simultaneously"""
        face_exp_component = np.matmul(U_exp, faceParam['face_exp']) #(34,530 x 200)  x  (200 x frames)

        v_face_allFrames = v_template_flat + face_exp_component  #(34530 x frames). Ignore face Identity information

        if bShowFaceId:
            face_id_component = np.matmul(U_id, faceParam['face_id']) #(34,530 x 150)  x  (150 x frames)
            v_face_allFrames += face_id_component #(34530 x frames)
            #v_face_allFrames = v_template_flat+ face_id_component +face_exp_component  #(34530 x frames)

        v_face_allFrames = v_face_allFrames.swapaxes(0,1) # (frames, 34530)
        v_face_allFrames = np.reshape(v_face_allFrames,[v_face_allFrames.shape[0], -1, 3]) # (frames, 11510, 3)


        faceMassCenter = np.zeros((3,faceParam['face_exp'].shape[1]))#*0.0 #(3, frames)
        if 'rot_pivot' in faceParam.keys():


            rot_pivot = np.swapaxes(faceParam['rot_pivot'],0,1) #(frames,3)
            rot_pivot = np.expand_dims(rot_pivot,1)  #(frames,1, 3)

            v_face_allFrames = v_face_allFrames - rot_pivot     # (frames, 11510, 3)

        if bApplyRot:
            assert False, "This code cannot be run."
            from modelViewer.batch_lbs import batch_rodrigues
            #Apply rotationsvf
            global_rot = None
            #computing global rotation
            global_rot =  batch_rodrigues(np.swapaxes(faceParam['rot'],0,1)) #input (Nx3), output: (N,3,3)



            #global_rot *( v_face_allFrames - rot_pivot)
            for f in range(v_face_allFrames.shape[0]):

                pts = np.swapaxes(v_face_allFrames[f,:,:],0,1) # (3,11510)

                if bApplyRotFlip:
                    #Flip
                    rot = np.array( [ 0, -1, 0,  1,  0,  0, 0, 0, 1])
                    rot = np.reshape(rot,(3,3))
                    pts =  np.matmul( rot, pts)  # (3,3)  x (11510,3) =>(3,11510)
                    pts =  np.matmul( rot, pts)  # (3,3)  x (11510,3) =>(3,11510)
                    pts *= 0.94


                # rot = np.array( [ 0, -1,  0, 1,  0,  0,0,  0,  1])
                # rot = np.reshape(rot,(3,3))
                rot = global_rot[f,:,:]
                pts =  np.matmul( rot, pts)  # (3,3)  x (11510,3) =>(3,11510)

                v_face_allFrames[f,:,:] = pts.transpose()
        else:   #Rotate 180 degrees to flip y axis
            #global_rot =  batch_rodrigues(np.swapaxes(faceParam['rot'],0,1)) #input (Nx3), output: (N,3,3)

            #global_rot *( v_face_allFrames - rot_pivot)
            for f in range(v_face_allFrames.shape[0]):

                pts = np.swapaxes(v_face_allFrames[f,:,:],0,1) # (3,11510)

                #rot = np.array( [ 1, 0, 0,  0, 1,  0,  0, 0, -1])
                #rot = np.array( [ 1, 0, 0,  0, 1,  0,  0, 0, -1])
                rot = np.array( [ 0, -1, 0,  1,  0,  0, 0, 0, 1])
                #rot = np.array( [ 0, 1, 0,  1,  0,  0, 0, 0, 1])
                rot = np.reshape(rot,(3,3))
                #rot = global_rot[f,:,:]
                pts =  np.matmul( rot, pts)  # (3,3)  x (11510,3) =>(3,11510)
                pts =  np.matmul( rot, pts)  # (3,3)  x (11510,3) =>(3,11510)

                #trans = np.array([[0.0,-1.5,0.2]])
                trans = np.array([[0.0,-1,0.2]])
                v_face_allFrames[f,:,:] = pts.transpose() +trans


        if bApplyTrans:
            trans = np.swapaxes(faceParam['trans'],0,1) #(frames,3)
            trans = np.expand_dims(trans,1)  #(frames,1, 3)
            v_face_allFrames = v_face_allFrames + trans     # (frames, 11510, 3)


            faceMassCenter += faceParam['trans'] #(3, frames)


        if bComputeNormal==False:
            #Debug. no normal
            faceMassCenter = v_face_allFrames[:,5885,:] #5885th vertex. around the head top.
            MoshParam = {'ver': v_face_allFrames, 'normal': [], 'f': trifaces, 'centers': faceMassCenter}  # support rendering two models together
            MoshParam_list.append(MoshParam)
            continue


        # # CPU version
        start = time.time()
        vertex_normals = ComputeNormal(v_face_allFrames, trifaces)
        print("CPU: normal computing time: {}".format( time.time() - start))

        # GPU version
        # start = time.time()
        # vertex_normals = ComputeNormal_gpu(v_face_allFrames, trifaces)
        # print("GPU: normal computing time: {}".format( time.time() - start))


        faceMassCenter = v_face_allFrames[:,5885,:] #5885th vertex. around the head top.
        #faceMassCenter = np.swapaxes(faceMassCenter,0,1) # (3,frames) - >(frames,3)

        MoshParam = {'ver': v_face_allFrames, 'normal': vertex_normals, 'f': trifaces, 'centers': faceMassCenter}  # support rendering two models together
        MoshParam_list.append(MoshParam)

    return MoshParam_list