Exemplo n.º 1
0
def parse_actions(actions_filename):
    "Output dict mapping actionname to Stuct(use_upperedge, movements)."
    f = TabFile(actions_filename)
    f.head()

    # Action_info_count included "action", "reverse_leftright", "slide_count", "use_upper_edge" #
    action_info_count = 4

    for line in f.parse():
        info = list(f.parse_line(line))

        # 0 > name #
        actionname = info[0]

        # 1-3 > important info #
        reverse_lr, slide_count, use_ue = map(int, info[1:action_info_count])

        if not reverse_lr: transformation = lambda x: (x[0]-10, x[1]+10)
        elif reverse_lr == 1: transformation = reversed
        else: transformation = False

        # 4: > bodyparts and angle ranges #
        bodypart_angle_dict = {}
        for bodypart, raw_angles in parallel(f.header[action_info_count:], info[action_info_count:]):
            if raw_angles:
                angle_range = map(int, parse_definition(raw_angles))
                bodypart_angle_dict[bodypart] = tuple(spread(angle_range, slide_count))
                if transformation and bodypart[-2:] == '_r':
                    left_bodypart = bodypart[:-2]+'_l'
                    bodypart_angle_dict[left_bodypart] = tuple(spread(transformation(angle_range), slide_count))
                else: continue
            else: break

        yield Struct(action=actionname, use_upperedge=use_ue, movements=bodypart_angle_dict)
Exemplo n.º 2
0
def setup_clothing(size_factor, root_output, root_input):
    build_gen = tuple(init_build(path.join(root_input, "data/body_parts/humanoid.fa")))
    build_act = tuple(parse_actions(path.join(root_input, "data/actions/humanoid.txt")))

    output_images = path.join(root_output, "clothing")
    if not path.exists(output_images):
        makedirs(output_images)
    output_data = path.join(root_output, "clothing/data")
    if not path.exists(output_data):
        makedirs(output_data)
    resource_image_path = path.join(root_input, "images/characters/humanoid.unnamed/")

    appendage_files = {app: AppendageFile(path.join(output_data, app.bodypart + ".txt")) for app in build_gen}

    complete_file = path.join(output_images, "COMPLETE")
    if not path.exists(complete_file):
        p = ProgressBar(len(build_act) * len(build_gen), "Making pictures...")
        for app in build_gen:

            # Order is preserved when called with no change in between #
            joints = app.joints.keys()
            coords = app.joints.values()

            if app.bodypart[-2:] == "_l":
                image_filename = "".join((resource_image_path, app.bodypart[:-2] + "_r", ".png"))
                boxed_pixels, box, boxed_points = boxit(image_filename, points=coords)  # box also fits now
                boxed_pixels = tint(boxed_pixels, 20)
            else:
                image_filename = "".join((resource_image_path, app.bodypart, ".png"))
                boxed_pixels, box, boxed_points = boxit(image_filename, points=coords)  # box also fits now

            small_pixels, small_size, small_points = smallerize(boxed_pixels, size_factor, box, points=boxed_points)

            for act_struct in build_act:
                p.update()
                angle_list = act_struct.movements[app.bodypart]
                for angle in angle_list:
                    output_name = path.join(output_images, "".join((app.bodypart, "_", str(angle), ".png")))
                    rotate_pixels, rotate_size, rotate_points = rotate(
                        small_pixels, app.origin, angle, small_size, points=small_points
                    )

                    # save(output_name, small_pixels, small_size)#rotate_pixels, rotate_size)
                    appendage_files[app].add(angle, dict(parallel(joints, rotate_points)))

        for appfile in appendage_files.itervalues():
            appfile.push()
        t = localtime()
        write(complete_file, "%d/%d/%d@%d:%d:%d" % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec))
        p.close()

    else:
        pass
Exemplo n.º 3
0
    def _print(self, index):
        "Prints the entry specified."
        print '\t'+self.display_entry_num % (index+1)
        for head, info in parallel(self.header, self.entries[index]):
            if len(head) > 4: headspace = ':\t'
            else: headspace = ':\t\t'

            start = print_space
            print ''.join(('\t', headspace.join((head.upper(), info[:start]))))
            
            
            space_req = len(info)-start
            
            while space_req > 0:
                end = start+print_space
                print ''.join(('\t\t\t', info[start:end]))
                start = end
                space_req -= print_space