def read_vmdtext_camframe(rawlist_text: List[list]) -> List[vmdstruct.VmdCamFrame]: ########################################### # cam frames global readfrom_line cam_list = [] check2_match_first_item(rawlist_text, keystr_camframect) camframe_ct = rawlist_text[readfrom_line][1] core.MY_PRINT_FUNC("...# of camframes = %d" % camframe_ct) readfrom_line += 1 if camframe_ct > 0: # ensure the key-line is where i think it is check3_match_keystr(rawlist_text, keystr_camframekey) # if it is indeed here, then inc the readpointer readfrom_line += 1 for i in range(camframe_ct): # ensure it has the right # of items on the line check1_match_len(rawlist_text, len(keystr_camframekey)) r = rawlist_text[readfrom_line] newframe = vmdstruct.VmdCamFrame(f=r[0], dist=r[1], pos=r[2:5], rot=r[5:8], interp=r[8:32], fov=r[32], perspective=r[33]) cam_list.append(newframe) # increment the readfrom_line pointer readfrom_line += 1 # progress tracker just because core.print_progress_oneline(i / camframe_ct) return cam_list
def parse_vmd_camframe(raw: bytearray, moreinfo: bool) -> List[vmdstruct.VmdCamFrame]: camframe_list = [] # is there enough file left to read a single number? if (len(raw) - core.get_readfrom_byte()) < struct.calcsize(fmt_number): core.MY_PRINT_FUNC( "Warning: expected camframe_ct field but file ended unexpectedly! Assuming 0 camframes and continuing..." ) return camframe_list ############################ # get the number of cam frames camframe_ct = core.my_unpack(fmt_number, raw) if moreinfo: core.MY_PRINT_FUNC("...# of camframes = %d" % camframe_ct) for z in range(camframe_ct): try: # unpack into variables (f, d, xp, yp, zp, xr, yr, zr, x_ax, x_bx, x_ay, x_by, y_ax, y_bx, y_ay, y_by, z_ax, z_bx, z_ay, z_by, r_ax, r_bx, r_ay, r_by, dist_ax, dist_bx, dist_ay, dist_by, ang_ax, ang_bx, ang_ay, ang_by, fov, per) = core.my_unpack(fmt_camframe, raw) interp_list = [ x_ax, x_bx, x_ay, x_by, y_ax, y_bx, y_ay, y_by, z_ax, z_bx, z_ay, z_by, r_ax, r_bx, r_ay, r_by, dist_ax, dist_bx, dist_ay, dist_by, ang_ax, ang_bx, ang_ay, ang_by ] this_camframe = vmdstruct.VmdCamFrame( f=f, dist=d, pos=[xp, yp, zp], rot=[ math.degrees(j) for j in (xr, yr, zr) ], # angle comes in as radians, convert radians to degrees interp=interp_list, fov=fov, perspective=per) camframe_list.append(this_camframe) # display progress printouts core.print_progress_oneline(core.get_readfrom_byte() / len(raw)) except Exception as e: core.MY_PRINT_FUNC(e.__class__.__name__, e) core.MY_PRINT_FUNC("frame=", z) core.MY_PRINT_FUNC("totalframes=", camframe_ct) core.MY_PRINT_FUNC("section=camframe") core.MY_PRINT_FUNC( "Err: something went wrong while parsing, file is probably corrupt/malformed" ) raise RuntimeError() return camframe_list