in renderer/glViewer.py [0:0]
def DrawMeshes():
global g_firsttime
global g_meshes, g_frameIdx#, g_normals
global g_vao
global g_vertex_buffer
global g_normal_buffer
global g_tangent_buffer
global g_index_buffer
# MESH_SCALING = 100.0 #from meter (model def) to CM (panoptic def)
# MESH_SCALING = 1.0 #from meter (model def) to CM (panoptic def)
if g_meshes is None:
return
#g_meshes[humanIdx]['ver']: frames x 6890 x 3
for humanIdx in range(len(g_meshes)):
if False:#humanIdx ==1: #Second one red
glColor3f(0.7, 0.5, 0.5) #targer: spin color
# glColor3f(0.53, 0.53, 0.8) #SPIN: red
# glColor3f(0.4, 0.4, 0.7) #prediction: blue
elif 'color' in g_meshes[humanIdx].keys():
glColor3f(g_meshes[humanIdx]['color'][0]/255.0, g_meshes[humanIdx]['color'][1]/255.0, g_meshes[humanIdx]['color'][2]/255.0)
else:
# glColor3f(0.4, 0.4, 0.7) #prediction: blue
glColor3f(g_meshColor[0],g_meshColor[1],g_meshColor[2])
# glColor3f(0.53, 0.53, 0.8)
# glColor3f(g_meshColor[0],g_meshColor[1],g_meshColor[2])
if(g_frameIdx >= g_meshes[humanIdx]['ver'].shape[0]):
continue
# if(humanIdx==0 or humanIdx==1): #Debug
# continue
SMPL_vts = g_meshes[humanIdx]['ver'][g_frameIdx,:,: ] #6890x3
SMPL_inds = g_meshes[humanIdx]['f']
SMPL_vts = SMPL_vts.flatten() #* MESH_SCALING
SMPL_vts = SMPL_vts.astype(np.float32)
SMPL_inds = SMPL_inds.flatten()
vts_num = int(len(SMPL_vts) / 3)
face_num = int(len(SMPL_inds) / 3)
if 'normal' in g_meshes[humanIdx].keys() and g_meshes[humanIdx]['normal'] is None:
here=0
if 'normal' in g_meshes[humanIdx].keys() and len(g_meshes[humanIdx]['normal'])>0:
SMPL_normals = g_meshes[humanIdx]['normal'][g_frameIdx,:,: ]
SMPL_normals = SMPL_normals.flatten().astype(np.float32)
tangent = np.zeros(SMPL_normals.shape)
tangent.astype(np.float32)
normal_num = len(SMPL_normals) / 3
else :
SMPL_normals = None
glBindVertexArray(g_vao)
glEnableVertexAttribArray(0)
glBindBuffer(GL_ARRAY_BUFFER, g_vertex_buffer[humanIdx])
glBufferData(GL_ARRAY_BUFFER, len(SMPL_vts) * sizeof(ctypes.c_float), (ctypes.c_float * len(SMPL_vts))(*SMPL_vts), GL_STATIC_DRAW)
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, None)
if SMPL_normals is not None:
#this is not needed.. .but normal should be the third attribute...
if g_firsttime:
glEnableVertexAttribArray(1)
glBindBuffer(GL_ARRAY_BUFFER, g_tangent_buffer[humanIdx])
glBufferData(GL_ARRAY_BUFFER, len(tangent) * sizeof(ctypes.c_float), (ctypes.c_float * len(tangent))(*tangent), GL_STATIC_DRAW)
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, None)
glEnableVertexAttribArray(2)
glBindBuffer(GL_ARRAY_BUFFER, g_normal_buffer[humanIdx])
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, None)
#glBufferData(GL_ARRAY_BUFFER, len(SMPL_normals) * sizeof(ctypes.c_float), (ctypes.c_float * len(SMPL_normals))(*SMPL_normals), GL_STATIC_DRAW)
#glBufferData(GL_ARRAY_BUFFER, len(SMPL_normals) * sizeof(ctypes.c_float), (ctypes.c_float * len(SMPL_normals))(*SMPL_normals), GL_STATIC_DRAW)
glBufferData(GL_ARRAY_BUFFER,
len(SMPL_normals) * sizeof(ctypes.c_float),
SMPL_normals,
GL_STATIC_DRAW)
if True:#g_firsttime:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_index_buffer[humanIdx])
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ctypes.c_uint) * len(SMPL_inds), (ctypes.c_uint * len(SMPL_inds))(*SMPL_inds), GL_STATIC_DRAW)
g_firsttime = False
# set the dimensions of the position attribute, so it consumes 2 floats at a time (default is 4)
#Draw by vertex array
glPushMatrix()
# if humanIdx ==0:
# #glColor3f(0.5, 0.2, 0.2) #targer: red
# glColor3f(0.4, 0.4, 0.7) #prediction: blue
# elif humanIdx ==1:
# glColor3f(0.5, 0.2, 0.2) #targer: red
# #glColor3f(0.0, 0.8, 0.3) #buyer
# elif humanIdx ==2:
# glColor3f(0.0, 0.8, 0.3) #buyer
# #glColor3f(0.5, 0.5, 0) #another: yellow
# else:
# #elif humanIdx ==2:
# glColor3f(0.5, 0.5, 0) #another: yellow
# glColor3f(0.6, 0.6, 0.4) #another: yellow
#glColor3f(0.8, 0.8, 0.8)
glLineWidth(.5)
if SMPL_normals is not None and g_bShowWiredMesh==False:
glPolygonMode(GL_FRONT, GL_FILL)
glPolygonMode(GL_BACK, GL_FILL)
else:
glPolygonMode(GL_FRONT, GL_LINE)
glPolygonMode(GL_BACK, GL_LINE)
# for vao_object in g_vao_object_list:
# glBindVertexArray(vao_object)
# glDrawElements(GL_TRIANGLES, face_num * 3, GL_UNSIGNED_INT, None)
if g_bApplyRootOffset:
#glTranslatef(40*humanIdx,0,0)
glTranslatef(ROOT_OFFSET_DIST*humanIdx,0,0)
glDrawElements(GL_TRIANGLES, face_num * 3, GL_UNSIGNED_INT, None)
# glPolygonMode(GL_FRONT, GL_FILL)
# glPolygonMode(GL_BACK, GL_FILL)
glPopMatrix()
glDisableVertexAttribArray(0)
if SMPL_normals is not None:
glDisableVertexAttribArray(1)
glDisableVertexAttribArray(2)
glBindBuffer(GL_ARRAY_BUFFER, 0)
glBindVertexArray(0) #Unbind