Skip to content

Commit

Permalink
draw both asf and smpl
Browse files Browse the repository at this point in the history
  • Loading branch information
CalciferZh committed May 29, 2018
1 parent 03d37f9 commit da49b46
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
70 changes: 50 additions & 20 deletions 3Dviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
import numpy as np
import time
import transforms3d.euler as euler
from reader import *

import reader
from transfer import *
from vistool import *
from skeleton import *
from smpl_np import SMPLModel

from OpenGL.GL import *
from OpenGL.GLU import *


class Viwer:
def __init__(self, joints=None, motions=None):
self.joints = joints
class Viewer:
def __init__(self, asf_joints, smpl_joints, motions):
self.asf_joints = asf_joints
self.smpl_joints = smpl_joints
align_smpl_asf(asf_joints, smpl_joints)

self.motions = motions
self.frame = 0
self.playing = False
Expand All @@ -28,7 +36,7 @@ def __init__(self, joints=None, motions=None):
self.speed_trans = 0.25
self.speed_zoom = 0.5
self.done = False
self.default_translate = np.array([0, -20, -100], dtype=np.float32)
self.default_translate = np.array([0, 0, -200], dtype=np.float32)
self.translate = np.copy(self.default_translate)

pygame.init()
Expand Down Expand Up @@ -120,8 +128,8 @@ def process_event(self):
gry = euler.euler2mat(0, self.global_ry, 0)
self.rotation_R = grx.dot(gry)

def set_joints(self, joints):
self.joints = joints
def set_asf_joints(self, asf_joints):
self.asf_joints = asf_joints

def set_motion(self, motions):
self.motions = motions
Expand All @@ -130,12 +138,21 @@ def draw(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glBegin(GL_POINTS)
self.draw_joints(self.asf_joints)
self.draw_joints(self.smpl_joints)
glEnd()

glBegin(GL_LINES)
self.draw_bones(self.asf_joints)
self.draw_bones(self.smpl_joints)
glEnd()

def draw_joints(self, joints):
for j in joints.values():
coord = np.array(np.squeeze(j.coordinate).dot(self.rotation_R)+self.translate, dtype=np.float32)
glVertex3f(*coord)
glEnd()

glBegin(GL_LINES)
def draw_bones(self, joints):
for j in joints.values():
child = j
parent = j.parent
Expand All @@ -144,16 +161,25 @@ def draw(self):
coord_y = np.array(np.squeeze(parent.coordinate).dot(self.rotation_R)+self.translate, dtype=np.float32)
glVertex3f(*coord_x)
glVertex3f(*coord_y)
glEnd()

def update_motion(self):
self.asf_joints['root'].set_motion(self.motions[self.frame])

R, offset = map_R_asf_smpl(asf_joints)
self.smpl_joints[0].coordinate = offset
self.smpl_joints[0].set_motion_R(R)
self.smpl_joints[0].update_coord()
move_skeleton(self.smpl_joints, [-40, 0, 0])

if self.playing:
self.frame += 1
if self.frame >= len(self.motions):
self.frame = 0

def run(self):
while not self.done:
self.process_event()
self.joints['root'].set_motion(self.motions[self.frame])
if self.playing:
self.frame += 1
if self.frame >= len(self.motions):
self.frame = 0
self.update_motion()
self.draw()
pygame.display.set_caption('AMC Parser - frame %d / %d' % (self.frame, len(self.motions)))
pygame.display.flip()
Expand All @@ -162,9 +188,13 @@ def run(self):


if __name__ == '__main__':
asf_path = './data/01/01.asf'
amc_path = './data/01/01_01.amc'
joints = parse_asf(asf_path)
motions = parse_amc(amc_path)
v = Viwer(joints, motions)
asf_joints = reader.parse_asf('./data/01/01.asf')
asf_joints['root'].reset_pose()

smpl = SMPLModel('./model.pkl')
smpl_joints = setup_smpl_joints(smpl)

motions = reader.parse_amc('./data/01/01_01.amc')

v = Viewer(asf_joints, smpl_joints, motions)
v.run()
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from skeleton import *
from vistool import *
from transfer import *
from 3Dviewer.py import *


def draw_pose():
def draw_pose_static():
asf_joints = reader.parse_asf('./data/01/01.asf')
asf_joints['root'].reset_pose()

Expand All @@ -18,9 +19,8 @@ def draw_pose():
motion = reader.parse_amc('./data/01/01_01.amc')[frame_idx]
asf_joints['root'].set_motion(motion)

R = map_R_asf_smpl(asf_joints)
R, offset = map_R_asf_smpl(asf_joints)
smpl_joints[0].set_motion_R(R)

smpl_joints[0].update_coord()

move_skeleton(smpl_joints, [40, 0, 0])
Expand All @@ -39,4 +39,4 @@ def draw_pose():
# draw_joints_in_motion_wrapper()
# smpl_joints_test()
# test()
draw_pose()
draw_pose_static()
2 changes: 1 addition & 1 deletion transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def map_R_asf_smpl(asf_joints):
R = {}
for k, v in smpl_asf_map.items():
R[k] = asf_joints[v].relative_R
return R
return R, np.copy(np.squeeze(asf_joints['root'].coordinate))

0 comments on commit da49b46

Please sign in to comment.