Esempio n. 1
0
class AnimatedTexturePC(object):
    surface_format = get_surface_format(VERSION_40, FORMAT4_COLOR)

    def __init__(self, width, height, actual_width, actual_height, data, frames):
        self.width = width
        self.height = height
        self.actual_width = actual_width
        self.actual_height = actual_height
        self.data = data
        self.frames = frames

    def __str__(self):
        return "AnimatedTexturePC d:{}x{} a:{}x{} f:{}".format(self.width, self.height, self.actual_width,
                                                               self.actual_height, len(self.frames))

    def xml(self, parent=None):
        if parent is None:
            root = ET.Element('AnimatedTexturePC')
        else:
            root = ET.SubElement(parent, 'AnimatedTexturePC')
        root.set('width', str(self.width))
        root.set('height', str(self.height))
        root.set('actualWidth', str(self.actual_width))
        root.set('actualHeight', str(self.actual_height))
        if self.frames is not None:
            self.frames.xml(root, 'Frames')
        return root

    def export(self, filename):
        if self.data is not None:
            texture = Texture2D(self.surface_format, self.width, self.height, [self.data])
            texture.export(filename + '.ani')
Esempio n. 2
0
 def read(self):
     surface_format_raw = self.stream.read_int32()
     surface_format = get_surface_format(self.stream.file_version, surface_format_raw)
     width = self.stream.read_int32()
     height = self.stream.read_int32()
     mip_count = self.stream.read_int32()
     mip_levels = []
     for _ in range(mip_count):
         size = self.stream.read_int32()
         data = self.stream.read(size)
         mip_levels.append(data)
     return Texture2D(surface_format, width, height, mip_levels, self.stream.needs_swap)
Esempio n. 3
0
 def read(self):
     surface_format_raw = self.stream.read_int32()
     surface_format = get_surface_format(self.stream.file_version, surface_format_raw)
     texture_size = self.stream.read_int32()
     mip_count = self.stream.read_int32()
     sides = {}
     for side in CUBE_SIDES:
         mip_levels = []
         for _ in range(mip_count):
             size = self.stream.read_int32()
             data = self.stream.read(size)
             mip_levels.append(data)
         sides[side] = mip_levels
     return TextureCube(surface_format, texture_size, sides, self.stream.needs_swap)
Esempio n. 4
0
 def read(self):
     surface_format_raw = self.stream.read_int32()
     surface_format = get_surface_format(self.stream.file_version,
                                         surface_format_raw)
     width = self.stream.read_int32()
     height = self.stream.read_int32()
     mip_count = self.stream.read_int32()
     mip_levels = []
     for _ in range(mip_count):
         size = self.stream.read_int32()
         data = self.stream.read(size)
         mip_levels.append(data)
     return Texture2D(surface_format, width, height, mip_levels,
                      self.stream.needs_swap)
Esempio n. 5
0
 def read(self):
     surface_format_raw = self.stream.read_int32()
     surface_format = get_surface_format(self.stream.file_version,
                                         surface_format_raw)
     texture_size = self.stream.read_int32()
     mip_count = self.stream.read_int32()
     sides = {}
     for side in CUBE_SIDES:
         mip_levels = []
         for _ in range(mip_count):
             size = self.stream.read_int32()
             data = self.stream.read(size)
             mip_levels.append(data)
         sides[side] = mip_levels
     return TextureCube(surface_format, texture_size, sides,
                        self.stream.needs_swap)
Esempio n. 6
0
class AnimatedTexture(object):
    surface_format = get_surface_format(VERSION_31, FORMAT_COLOR)

    def __init__(self, width, height, actual_width, actual_height, frames):
        self.width = width
        self.height = height
        self.actual_width = actual_width
        self.actual_height = actual_height
        self.frames = frames

    def __str__(self):
        return "AnimatedTexture d:{}x{} a:{}x{} f:{}".format(self.width, self.height, self.actual_width,
                                                             self.actual_height, len(self.frames))

    def xml(self, parent=None):
        if parent is None:
            root = ET.Element('AnimatedTexture')
        else:
            root = ET.SubElement(parent, 'AnimatedTexture')
        root.set('width', str(self.width))
        root.set('height', str(self.height))
        root.set('actualWidth', str(self.actual_width))
        root.set('actualHeight', str(self.actual_height))
        if self.frames is not None:
            self.frames.xml(root, 'Frames')
        return root

    def export(self, filename):
        if self.frames is not None:
            self.export_single(filename)

    def export_each(self, filename):
        for i, cur_frame in enumerate(self.frames):
            texture = Texture2D(self.surface_format, self.width, self.height, [cur_frame.data])
            cur_filename = "{}_ani\\{}".format(filename, i)
            texture.export(cur_filename)

    def export_single(self, filename):
        texture_data = bytearray()
        for cur_frame in self.frames:
            texture_data.extend(cur_frame.data)
        texture = Texture2D(self.surface_format, self.width, self.height * len(self.frames), [texture_data])
        texture.export(filename + '.ani')