def from_table(cls, f, info): blk = cls(int(info[0][1]), int(info[0][3])) keyframes = [] print("filename " + f) frame_offset = 1 if f == "" or info[1][1] == "Duration": frame_offset = 2 blk.tan_type = 1 else: blk.tan_type = int(info[0][5]) for i in range(frame_offset, len(info[1])): if info[1][i] != "": text = info[1][i][6:] text = int(text) keyframes.append(text) print("keyframes") print(keyframes) for i in range(2, len(info)): #for each cluster current_anim = cluster_anim() for k in range(frame_offset, len(info[i])): #for each keyframe if info[i][k] != "": comp = j3d.AnimComponent(keyframes[k - frame_offset], float(info[i][k])) current_anim.seq.append(comp) current_anim.seq = j3d.make_tangents(current_anim.seq) blk.animations.append(current_anim) if f == "": print("no saving") return blk else: with open(f, "wb") as f: blk.write_blk(f) f.close()
def from_table(cls, f, info): brk = cls(int(info[0][0]), int(info[0][1]), int(info[0][2])) keyframes = [] for i in range(3, len( info[1] ) ): if info[1][i] != "": text = info[1][i][6:] text = int(text) keyframes.append(text) print(keyframes) for i in range(0, int( len(info) / 4) ): curr_line = 4 * i + 2 color_anim = ColorAnimation(i, info[curr_line][0], int( info[curr_line][1] ) ) for j in range(0, 4): rgba = "RGBA" rgba = rgba[j: j+1] for k in range(3, len( info[curr_line + j] ) ): if info[curr_line + j][k] != "": anim_comp = j3d.AnimComponent(keyframes[k - 3], int(info[curr_line + j][k]) ) color_anim.add_component(rgba, anim_comp) color_anim.component[rgba] = j3d.make_tangents(color_anim.component[rgba]) if info[curr_line + 1][0].startswith("Reg"): brk.register_animations.append(color_anim) else: brk.constant_animations.append(color_anim) if f == "": print("no saving") return brk else: with open(f, "wb") as f: brk.write_brk(f) f.close()
def from_table(cls, f, info): bck = cls(int(info[0][1]), int(info[0][3]), int(info[0][5])) if len(info[0]) >= 7 and info[0][7] != "": bck.tan_type = int( info[0][7] ) keyframes = [] for i in range(2, len( info[1] ) ): if info[1][i] != "": text = info[1][i][6:] text = int(text) keyframes.append(text) print("keyframes") print (keyframes) for i in range( int( len(info) / 9 ) ): #for each bone line = 9 * i + 2 current_anim = bone_anim() current_anim.name = info[line][0] if info[line + 1][0].startswith("S"): current_anim.tan_inter = 1 for j in range(9): #for each of thing in scale/rot/trans x/y/z/ xyz = "XYZ" xyz = xyz[j%3: j%3 + 1] for k in range(2, len(info[line + j])): #for each keyframe if info[line + j][k] != "": try: comp = j3d.AnimComponent( keyframes[k-2], float(info[line + j][k])) except: comp = j3d.AnimComponent( bck.duration, float(info[line + j][k]) ) if j < 3: current_anim.add_scale(xyz, comp) #print("scale " + xyz + " " + str(keyframes[k-2]) + ", " + str( float(info[line + j][k]))) elif j < 6: """if comp.value < -180 * bck.anglescale: comp.value = comp.value + 360 * bck.anglescale elif comp.value > 180 * bck.anglescale: comp.value = comp.value - 360 * bck.anglescale""" current_anim.add_rotation(xyz, comp) #print("rot " + xyz + " " + str(keyframes[k-2]) + ", " + str( float(info[line + j][k]))) else: current_anim.add_translation(xyz, comp) #print("trans " + xyz + " " + str(keyframes[k-2]) + ", " + str( float(info[line + j][k]))) #calculate tangents for j in range(9): xyz = "XYZ" xyz = xyz[j%3: j%3 + 1] if j < 3: current_anim.scale[xyz] = j3d.make_tangents(current_anim.scale[xyz], current_anim.tan_inter) if j < 6: current_anim.rotation[xyz] = j3d.make_tangents(current_anim.rotation[xyz], current_anim.tan_inter) else: current_anim.translation[xyz] = j3d.make_tangents(current_anim.translation[xyz], current_anim.tan_inter) bck.animations.append(current_anim) if f == "": print("no saving") return bck else: with open(f, "wb") as f: bck.write_bck(f) f.close()
def from_table(cls, f, info): btk = cls(int(info[0][0]), 0, int(info[0][1]), 0, int(info[0][2])) keyframes = [] for i in range(3, len(info[1])): if info[1][i] != "": text = info[1][i][6:] text = int(text) keyframes.append(text) print("keyframes") print(keyframes) num_of_mats = int((len(info) - 2) / 9) #read all the values for i in range(num_of_mats): #for each material line = 9 * i + 2 centrum = info[line + 4][0] if not isinstance(centrum, tuple): print("convert centrum to float tuple") centrum = centrum.strip("()") centrum = eval(centrum) #centrum = tuple(filter(float, centrum.split(",") ) ) assert isinstance(centrum, tuple) current_anim = MatrixAnimation(i, int(info[line + 2][0]), info[line][0], centrum) for j in range(9): #for each of thing in scale/rot/trans u/v/w/ uvw = "UVW" uvw = uvw[j % 3:j % 3 + 1] for k in range(3, len(info[line + j])): #for each keyframe if info[line + j][k] != "": comp = j3d.AnimComponent(keyframes[k - 3], float(info[line + j][k])) if info[line + j][1].startswith("S"): current_anim.tan_inter[j] = 1 else: current_anim.tan_inter[j] = 0 if j < 3: current_anim.add_scale(uvw, comp) #print("scale " + uvw + " " + str(keyframes[k-4]) + ", " + str( float(info[line + j][k]))) elif j < 6: current_anim.add_rotation(uvw, comp) # print("rot " + uvw + " " + str(keyframes[k-4]) + ", " + str( float(info[line + j][k]))) else: current_anim.add_translation(uvw, comp) # print("trans " + uvw + " " + str(keyframes[k-4]) + ", " + str( float(info[line + j][k]))) #calculate tangents for j in range(9): uvw = "UVW" uvw = uvw[j % 3:j % 3 + 1] if j < 3: current_anim.scale[uvw] = j3d.make_tangents( current_anim.scale[uvw], current_anim.tan_inter[j]) if j < 6: current_anim.rotation[uvw] = j3d.make_tangents( current_anim.rotation[uvw], current_anim.tan_inter[j]) else: current_anim.translation[uvw] = j3d.make_tangents( current_anim.translation[uvw], current_anim.tan_inter[j]) btk.animations.append(current_anim) if f == "": print("no saving") return btk else: with open(f, "wb") as f: btk.write_btk(f) f.close()
def from_table(cls, f, info, sound_data=None): #print("loop mode " + str( info[0][1] ) ) #loop mode, anglescale, duration, tantype bck = cls(int(info[0][0]), 0, int(info[0][1]), int(info[0][2])) max_angle = 0 #print(sound_data) bck.sound = sound_data if len(info[0]) >= 7 and info[0][7] != "": bck.tan_type = int(info[0][7]) keyframes = [] for i in range(3, len(info[1])): if info[1][i] != "": text = info[1][i][6:] text = int(text) keyframes.append(text) #print("keyframes") #print (keyframes) for i in range(int(len(info) / 9)): #for each bone line = 9 * i + 2 current_anim = bone_anim() current_anim.name = info[line][0] """ if info[line + 1][0].startswith("S"): current_anim.tan_inter = 1 """ for j in range(9): #for each of thing in scale/rot/trans x/y/z/ xyz = "XYZ" xyz = xyz[j % 3:j % 3 + 1] for k in range(3, len(info[line + j])): #for each keyframe if info[line + j][k] != "": try: comp = j3d.AnimComponent(keyframes[k - 3], float(info[line + j][k])) except: comp = j3d.AnimComponent(bck.duration, float(info[line + j][k])) if info[line + j][1].startswith("S"): current_anim.tan_inter[j] = 1 else: current_anim.tan_inter[j] = 0 if j < 3: current_anim.add_scale(xyz, comp) #print("scale " + xyz + " " + str(keyframes[k-2]) + ", " + str( float(info[line + j][k]))) elif j < 6: """if comp.value < -180 * bck.anglescale: comp.value = comp.value + 360 * bck.anglescale elif comp.value > 180 * bck.anglescale: comp.value = comp.value - 360 * bck.anglescale""" max_angle = max(max_angle, comp.value) current_anim.add_rotation(xyz, comp) #print("rot " + xyz + " " + str(keyframes[k-2]) + ", " + str( float(info[line + j][k]))) else: current_anim.add_translation(xyz, comp) #print("trans " + xyz + " " + str(keyframes[k-2]) + ", " + str( float(info[line + j][k]))) #calculate tangents bck.anglescale = math.ceil(abs(max_angle) / 180) #print("anglescale: ", bck.anglescale) for j in range(9): xyz = "XYZ" xyz = xyz[j % 3:j % 3 + 1] if j < 3: current_anim.scale[xyz] = j3d.make_tangents( current_anim.scale[xyz], current_anim.tan_inter[j]) if j < 6: current_anim.rotation[xyz] = j3d.make_tangents( current_anim.rotation[xyz], current_anim.tan_inter[j]) else: current_anim.translation[xyz] = j3d.make_tangents( current_anim.translation[xyz], current_anim.tan_inter[j]) bck.animations.append(current_anim) if f == "": #print("no saving") return bck else: with open(f, "wb") as f: bck.write_bck(f) f.close()
def from_table(cls, f, info): brk = cls(int(info[0][1]), int(info[0][3]), int(info[0][5])) constant_line = 0 for i in range(len(info)): if info[i][0].startswith("C"): constant_line = i if constant_line != 0: break print("constant line " + str(constant_line)) if constant_line > 2: #there are register animations print("there are register animations") keyframes = [] for i in range(3, len(info[2])): if info[2][i] != "": text = info[2][i][6:] text = int(text) keyframes.append(text) print(keyframes) for i in range(0, int(constant_line / 4)): curr_line = 4 * i + 3 color_anim = ColorAnimation(i, info[curr_line][0], int(info[curr_line][1])) for j in range(0, 4): rgba = "RGBA" rgba = rgba[j:j + 1] for k in range(3, len(info[curr_line + j])): if info[curr_line + j][k] != "": anim_comp = j3d.AnimComponent( keyframes[k - 3], int(info[curr_line + j][k])) color_anim.add_component(rgba, anim_comp) color_anim.component[rgba] = j3d.make_tangents( color_anim.component[rgba]) brk.register_animations.append(color_anim) #print(brk.register_animations) if constant_line + 1 < len(info): print("there are constant animations") keyframes = [] for i in range(3, len(info[constant_line + 1])): if info[constant_line + 1][i] != "": text = info[constant_line + 1][i][6:] text = int(text) keyframes.append(text) for i in range(0, int((len(info) - constant_line) / 4)): curr_line = constant_line + 4 * i + 2 color_anim = ColorAnimation(i, info[curr_line][0], int(info[curr_line][1])) for j in range(0, 4): rgba = "RGBA" rgba = rgba[j:j + 1] for k in range(3, len(info[curr_line + j])): if info[curr_line + j][k] != "": anim_comp = j3d.AnimComponent( keyframes[k - 3], int(info[curr_line + j][k])) color_anim.add_component(rgba, anim_comp) color_anim.component[rgba] = j3d.make_tangents( color_anim.component[rgba]) brk.constant_animations.append(color_anim) if f == "": print("no saving") return brk else: with open(f, "wb") as f: brk.write_brk(f) f.close()