Exemplo n.º 1
0
    def convert(p):
        dct = {
                'sheet': p.sheet_idx,
                # Give the offset of the pixel corresponding to (0,0,0)
                'offset': geom.sub(p.offset, p.base),
                'vert_idx': p.vert_idx,
                'vert_count': p.vert_count,
                }

        flags = p.get_flags()
        if flags != 0:
            dct.update(
                flags=flags)

        if isinstance(p.img, image2.Anim):
            dct.update(
                anim_length=p.img.length,
                anim_rate=p.img.rate,
                anim_oneshot=p.img.oneshot,
                anim_size=p.img.px_size)

        return dct
Exemplo n.º 2
0
    def __init__(self, name, image, model, shape, layer):
        super(StructureDef, self).__init__(name, shape, layer)
        px_size = tuple(x * TILE_SIZE for x in shape.size)
        mesh = model.to_mesh()

        if isinstance(image, StaticAnimDef):
            base = image2.Image(img=image_cache.ConstImage(image.static_base))
            base_model2 = Model2(mesh, ((0, 0, 0), px_size))
            self.add_part(base_model2, base)

            frame_sheet = image2.Image(img=image_cache.ConstImage(image.anim_sheet),
                    unit=image.anim_size)
            frames = [frame_sheet.extract((x, 0)) for x in range(image.length)]
            anim = image2.Anim(frames, image.framerate, image.oneshot)
            box_min = geom.sub(image.anim_offset, (0, shape.size[2] * TILE_SIZE))
            box_max = geom.add(box_min, image.anim_size)
            anim_mesh = mesh.copy()
            geom.clip_xv(anim_mesh, *(box_min + box_max))
            anim_model2 = Model2(anim_mesh, anim_mesh.get_bounds())
            self.add_part(anim_model2, anim)
        else:
            image = image2.Image(img=image_cache.ConstImage(image))
            model2 = Model2(mesh, ((0, 0, 0), px_size))
            self.add_part(model2, image)