def open_file(): # read_file file_read load_file global root # Root window global myskeleton global skelscreenedges global gridedges global slidert global myviewport global mycamera global mymenu global mytransport global redraw_grid global redraw_axes global file_prefix # No, you aren't allowed to try to load a new BVH in the middle of playing # back the current BVH... nice try. mytransport.playing = 0 mycanvas = myviewport.canvas if file_prefix == 'NONE': filename = askopenfilename(title = 'Open BVH file', parent=root, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) else: filename = askopenfilename(title = 'Open BVH file', parent=root, \ initialdir = file_prefix, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) print "filename = ", filename # Remove this line later index = filename.rfind('/') # Unix index2 = filename.rfind('\\') # Windows if index != -1: file_prefix = filename[0:index + 1] print "File prefix is ", file_prefix elif index2 != -1: file_prefix = filename[0:index2 + 1] print "File prefix is ", file_prefix # askopenfilename also allows: initialdir = '' # "filename" will have length 0 if user cancels the open. if len(filename) > 0: try: if filename[-3:] == 'bvh': myskeleton2 = process_bvhfile(filename, DEBUG=0) else: myskeleton2 = process_bvhfile(filename, DEBUG=0) print 'wangqi' ## myskeleton2 = profile.run('process_bvhfile(FILE,DEBUG=0)') except IOError: string = "IO Error while attempting to read file." print string error_popup(string) return except SyntaxError: string = "Parse error in BVH file." print string error_popup(string) return except: string = "Unknown error while attempting to read file." print string error_popup(string) return # If we make it here then we've successfully read and parsed the BVH file, # and created myskeleton2 # Undraw all grid edges for edge in gridedges: edge.undraw(mycanvas) # Undraw all skeleton edges for edge in skelscreenedges: edge.undraw(mycanvas) # Don't need to undraw axes - leave as-is # Reset slider to 1 slidert.set(1) # Say farewell to previous skeleton myskeleton = myskeleton2 # Set camera position to something that will hopefully put the skeleton # in view. For Z we want something large so that we're set back from # the skeleton. mycamera.t[0] = int((myskeleton.minx + myskeleton.maxx) / 2) mycamera.t[1] = int((myskeleton.miny + myskeleton.maxy) / 2) if (mycamera.t[1] < 10): mycamera.t[1] = 10 mycamera.t[2] = myskeleton.maxz + 100 mycamera.yrot = 0 mycamera.Recompute() if mymenu.readout: myviewport.draw_readout(mycamera) # Create skelscreenedges[] with sufficient space to handle one # screenedge per skeleton edge. skelscreenedges = myskeleton.make_skelscreenedges(DEBUG=0, arrow='none', circle=1) # Give us some screen edges to display. myskeleton.populate_skelscreenedges(skelscreenedges, slidert.get(), \ DEBUG=0) # print "skelscreenedges after population is:" # print skelscreenedges myplaybar.resetscale(myskeleton.frames) gridedges = grid_setup(myskeleton.minx, myskeleton.minz, \ myskeleton.maxx, myskeleton.maxz, DEBUG=0) redraw_grid = 1 redraw_axes = 1 redraw()
def open_file(): # read_file file_read load_file global root # Root window global myskeleton global skelscreenedges global gridedges global slidert global myviewport global mycamera global mymenu global mytransport global redraw_grid global redraw_axes global file_prefix # No, you aren't allowed to try to load a new BVH in the middle of playing # back the current BVH... nice try. mytransport.playing = 0 mycanvas = myviewport.canvas if file_prefix == 'NONE': filename = askopenfilename(title = 'Open BVH file', parent=root, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) else: filename = askopenfilename(title = 'Open BVH file', parent=root, \ initialdir = file_prefix, \ filetypes =[ ('BVH files', '*.bvh'), ('All files', '*')] ) print "filename = ",filename # Remove this line later index = filename.rfind('/') # Unix index2 = filename.rfind('\\') # Windows if index != -1: file_prefix = filename[0:index+1] print "File prefix is ", file_prefix elif index2 != -1: file_prefix = filename[0:index2+1] print "File prefix is ", file_prefix # askopenfilename also allows: initialdir = '' # "filename" will have length 0 if user cancels the open. if len(filename) > 0: try: myskeleton2 = process_bvhfile(filename,DEBUG=0) ## myskeleton2 = profile.run('process_bvhfile(FILE,DEBUG=0)') except IOError: string = "IO Error while attempting to read file." print string error_popup(string) return except SyntaxError: string = "Parse error in BVH file." print string error_popup(string) return except: string = "Unknown error while attempting to read file." print string error_popup(string) return # If we make it here then we've successfully read and parsed the BVH file, # and created myskeleton2 # Undraw all grid edges for edge in gridedges: edge.undraw(mycanvas) # Undraw all skeleton edges for edge in skelscreenedges: edge.undraw(mycanvas) # Don't need to undraw axes - leave as-is # Reset slider to 1 slidert.set(1) # Say farewell to previous skeleton myskeleton = myskeleton2 # Set camera position to something that will hopefully put the skeleton # in view. For Z we want something large so that we're set back from # the skeleton. mycamera.t[0] = int((myskeleton.minx + myskeleton.maxx)/2) mycamera.t[1] = int((myskeleton.miny + myskeleton.maxy)/2) if (mycamera.t[1] < 10): mycamera.t[1] = 10 mycamera.t[2] = myskeleton.maxz + 100 mycamera.yrot = 0 mycamera.Recompute() if mymenu.readout: myviewport.draw_readout(mycamera) # Create skelscreenedges[] with sufficient space to handle one # screenedge per skeleton edge. skelscreenedges = myskeleton.make_skelscreenedges(DEBUG=0, arrow='none', circle=1) # Give us some screen edges to display. myskeleton.populate_skelscreenedges(skelscreenedges, slidert.get(), \ DEBUG=0) # print "skelscreenedges after population is:" # print skelscreenedges myplaybar.resetscale(myskeleton.frames) gridedges = grid_setup(myskeleton.minx, myskeleton.minz, \ myskeleton.maxx, myskeleton.maxz, DEBUG=0) redraw_grid = 1 redraw_axes = 1 redraw()
axisedges.append(se1) # Y axis sv1 = screenvert(0., 0., 0.) sv2 = screenvert(0., 10., 0.) se1 = screenedge(sv1, sv2, color='green', description='green y axis') axisedges.append(se1) # Z axis sv1 = screenvert(0., 0., 0.) sv2 = screenvert(0., 0., 10.) se1 = screenedge(sv1, sv2, color='blue', description='blue z axis') axisedges.append(se1) redraw_axes = 1 # Default grid prior to a skeleton load. gridedges = grid_setup(-50, -50, 50, 50, DEBUG=0) redraw_grid = 1 # Global flag - set to 1 when you move the camera please file_prefix = 'NONE' # redraw() only redraws edges, not the camera readout, because the # camera readout only changes when the camera moves, not when the # skeleton animates. If I were to have redraw() call draw_readout, # we'd erase and redraw the readout every timestep, which is a waste. if mymenu.readout: myviewport.draw_readout(mycamera) redraw() mainloop()
# Y axis sv1 = screenvert(0.,0.,0.) sv2 = screenvert(0.,10.,0.) se1 = screenedge(sv1, sv2, color='green', description='green y axis') axisedges.append(se1) # Z axis sv1 = screenvert(0.,0.,0.) sv2 = screenvert(0.,0.,10.) se1 = screenedge(sv1, sv2, color='blue', description='blue z axis') axisedges.append(se1) redraw_axes = 1 # Default grid prior to a skeleton load. gridedges = grid_setup(-50, -50, 50, 50, DEBUG=0) redraw_grid = 1 # Global flag - set to 1 when you move the camera please file_prefix = 'NONE' # redraw() only redraws edges, not the camera readout, because the # camera readout only changes when the camera moves, not when the # skeleton animates. If I were to have redraw() call draw_readout, # we'd erase and redraw the readout every timestep, which is a waste. if mymenu.readout: myviewport.draw_readout(mycamera) redraw() mainloop()