Beispiel #1
0
    def read(self, stream, resources=None):
        s = StreamReader(stream)
        s.version = s.u32()
        tgi = TGIList(package=resources)
        tgi.begin_read(stream)
        self.components = [s.hash(self.component_hashes) for i in range(s.i8())]
        self.component_data = {}

        def read_component_data():
            key = s.p32()
            val = None
            t = s.i8()
            if t == 0x00:
                val = t, s.p32()
            elif t == 0x01:
                val = t, tgi.get_resource(s.i32())
            elif t == 0x02:
                val = t, tgi.get_resource(s.i32())
            elif t == 0x03:
                val = t, s.p32()
            elif t == 0x04:
                val = t, s.u32()
            self.component_data[key] = val

        for i in range(s.i8()):
            read_component_data()
        self.visible = s.u8()
        tgi.end_read(stream)
        pass
Beispiel #2
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)
        tgi = TGIList(package=resources)
        tgi.begin_write(stream)
        s.i8(len(self.components))
        for component in self.components:
            s.hash(component)

        def write_component_data(data):
            s.i8(data[0])
            val = data[1]
            if isinstance(val, str):
                s.p32(val)
            elif isinstance(val, Resource):
                s.i32(tgi.get_resource_index(val))
            elif isinstance(val, int):
                s.u32(val)
            else:
                raise Exception("Unable to handle data type %" % type(val))

        k = self.component_data.keys()
        s.i8(len(k))
        for key in k:
            s.p32(key)
            write_component_data(self.component_data[key])
        s.i8(self.visible)
        tgi.end_write(stream)
Beispiel #3
0
    def read(self, stream, resources=None):
        s = StreamReader(stream)
        self.version = s.u32()
        tgi = TGIList(package=resources)
        tgi.begin_read(stream)
        if self.version >= 0x00000007:
            self.presets = ProductBase.read_presets(stream,tgi)
        self.product_info = ProductInfo()
        self.product_info.read(stream,tgi)
        self.model = tgi.get_resource(s.i32())
        self.diagonal_model = tgi.get_resource(s.i32())
        self.post_model = tgi.get_resource(s.i32())
        self.post_tile_spacing = s.i32()
        self.can_walk_over = s.i8() == 1

        if self.version >= 0x00000008:
            if self.version >= 0x000000A:
                self.should_not_get_thick_snow = s.i8() == 1
                self.snow_post_shape_is_circle = s.i8()==1
                self.snow_thickness_post_scale_factor = s.f32()
                self.snow_thickness_rail_scale_factor = s.f32()
                self.snow_thickness_post_vertical_offset = s.f32()
                self.snow_thickness_rail_vertical_offset = s.f32()
                self.has_wall = s.i8() == 1
            if self.version < 0x000000A or self.has_wall:
                self.raise_fence_geometry_above_wall = s.i8()== 1
                self.wall = tgi.get_resource(s.i32())
        tgi.end_read(stream)
Beispiel #4
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)
        tgi = TGIList()
        tgi.begin_write(stream)
        if self.version >= 0x00000007:
            ProductBase.write_presets(stream,self.presets,tgi)
        self.product_info.write(stream,tgi)

        s.i32(tgi.get_resource_index(self.model))
        s.i32(tgi.get_resource_index(self.diagonal_model))
        s.i32(tgi.get_resource_index(self.post_model))
        s.i32(self.post_tile_spacing)
        s.i8(1 if self.can_walk_over else 0)

        if self.version >= 0x00000008:
            if self.version >= 0x0000000A:
                s.i8(1 if self.should_not_get_thick_snow else 0)
                s.i8(1 if self.snow_post_shape_is_circle else 0)
                s.f32(self.snow_thickness_post_scale_factor)
                s.f32(self.snow_thickness_rail_scale_factor)
                s.f32(self.snow_thickness_post_vertical_offset)
                s.f32(self.snow_thickness_rail_vertical_offset)
                s.i8(1 if self.has_wall else 0)
            if self.version < 0x0000000A or self.has_wall:
                s.i8(1 if self.raise_fence_geometry_above_wall else 0)
                s.i32(tgi.get_resource_index(self.wall))
        tgi.end_write(stream)
Beispiel #5
0
    def serialize(self,complate,stream,resources):
        def write_element(s,tgi_list):
            def write_complate_string(string,s):
                if not string:
                    s.i8(0)
                    return
                if string in self.complate_string_lookup:
                    idx = self.complate_string_lookup[string]
                    if idx > 0x40:
                        s.i8(0x40)
                    s.i8(idx &0x3F)
                else:
                    x = len(string)


                pass
            def write_typecode(value,s,tgi_list):
                if isinstance(value,str):
                    s.i8(0x01)
                    write_complate_string(value,s)
                elif isinstance(value,list):
                    if len(value) == 4:
                        s.i8(0x02)
                        for e in value: s.u8(e)
                    elif len(value) == 2:
                        s.i8(0x05)
                        for e in value: s.f32(e)
                    elif len(value) == 3:
                        s.i8(0x06)
                        for e in value: s.f32(e)
                elif isinstance(value,Resource):
                    s.i8(0x03)
                    s.i8(tgi_list.get_resource_index(value))
                elif isinstance(value,float):
                    s.i8(0x04)
                    s.f32(value)
                elif isinstance(value,bool):
                    s.i8(0x07)
                    s.i8(1 if value else 0)
                else:
                    raise Exception ("Unable to handle typecode data %" %value)


                pass

            pass
        assert isinstance(complate,ComplateElement)
        s= StreamWriter(stream)
        s.i16(complate.priority)
        preset_tgi = TGIList(use_length=True)
        preset_tgi.begin_write(stream)

        raise NotImplementedError()
Beispiel #6
0
 def write(self,stream,resources=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList()
     tgi.begin_write(stream)
     if self.version >= 0x00000003:
         ProductBase.write_presets(stream,self.presets,tgi)
     self.product_info.write(stream,tgi)
     s.i32(tgi.get_resource_index(self.steps_4x_model))
     s.i32(tgi.get_resource_index(self.steps_1x_model))
     s.i32(tgi.get_resource_index(self.wall_cap_model))
     s.i32(tgi.get_resource_index(self.railing))
     s.i32(tgi.get_resource_index(self.wall))
     s.i32(tgi.get_resource_index(self.floor))
     s.i32(tgi.get_resource_index(self.fence))
     tgi.end_write(stream)
Beispiel #7
0
 def read(self, stream, resources=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList(package=resources)
     tgi.begin_read(stream)
     if self.version >= 0x00000003:
         self.presets = ProductBase.read_presets(stream,tgi)
     self.product_info.read(stream,resources)
     self.steps_4x_model = tgi.get_resource(s.i32())
     self.steps_1x_model = tgi.get_resource(s.i32())
     self.wall_cap_model = tgi.get_resource(s.i32())
     self.railing = tgi.get_resource(s.i32())
     self.wall = tgi.get_resource(s.i32())
     self.floor = tgi.get_resource(s.i32())
     self.fence = tgi.get_resource(s.i32())
     tgi.end_read(stream)
Beispiel #8
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)

        tgi = resources
        use_tgi = not isinstance(tgi, TGIList)
        if use_tgi:
            tgi = TGIList(order='IGT',
                          use_length=False,
                          package=resources,
                          count_size=8)
            tgi.begin_write(self, stream)
        if self.version >= 7:
            s.i8(len(self.fabrics))
            for fabric in self.fabrics:
                s.i8(tgi.get_resource_index(fabric))
                fabric_len = 0
                with BytesIO() as fabric_stream:
                    fabric.write(fabric_stream, tgi)
                    s.u32(fabric_stream.tell())
                    fabric_stream.seek(0, SEEK_SET)
                    stream.write(fabric_stream.read(-1))
            s.u32(self.target_size)
            s.u32(self.part_type)
            s.u8(0)
            s.i32(len(self.steps))
            if self.version >= 0x08:
                s.u8(0)
            for step in self.steps:
                self.write_step(stream, tgi, step)
        if use_tgi:
            tgi.end_read(stream)
        else:
            s.u32(0)
Beispiel #9
0
 def write_rcol(self, stream, rcol):
     s = StreamWriter(stream)
     self.write_tag(stream)
     s.u32(self.version)
     tgi = TGIList(32, 'TGI')
     tgi.begin_write(stream)
     s.hash(self.shader)
     if self.shader:
         self.material.write(stream, tgi)
     s.u32(self.merge_group)
     s.u32(self.sort_order)
     s.u32(len(self.vertices))
     self.vertex_format.from_vertex(self.vertices[0])
     self.vertex_format.write(stream)
     for vertex in self.vertices:
         uv_index = 0
         for declaration in self.vertex_format.declarations:
             if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION:
                 for i in range(3):
                     s.f32(vertex.position)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL:
                 for i in range(3):
                     s.f32(vertex.normal)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV:
                 for i in range(2):
                     s.f32(vertex.uv[uv_index])
                 uv_index += 1
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX:
                 for i in range(4):
                     s.i8(vertex.blend_indices)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT:
                 for i in range(4):
                     s.f32(vertex.blend_weights)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT:
                 for i in range(3):
                     s.f32(vertex.tangents)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR:
                 for i in range(4):
                     s.i8(vertex.colour)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID:
                 s.u32(vertex.id)
     s.u32(tgi.get_resource_index(self.skin_controller))
     s.u32(len(self.bones))
     for bone in self.bones:
         s.u32(bone)
Beispiel #10
0
 def write_rcol(self, stream, rcol):
     self.write_tag(stream)
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList()
     tgi.begin_write(stream)
     s.u8(len(self.entries))
     for entry in self.entries:
         s.u8(entry.TYPE)
         entry.write(stream, tgi)
     s.u8(2)
     self.bounds.write(stream)
     s.u32(self.flags)
     if self.routing_footprint.key != ResourceKey():
         s.u8(1)
         s.tgi(self.routing_footprint.key, 'TGI')
     else: s.u8(0)
     tgi.end_write(stream)
Beispiel #11
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)

        tgi = resources
        use_tgi = not isinstance(tgi, TGIList)
        if use_tgi:
            tgi = TGIList(order='IGT', use_length=False, package=resources, count_size=8)
            tgi.begin_write(self, stream)
        if self.version >= 7:
            s.i8(len(self.fabrics))
            for fabric in self.fabrics:
                s.i8(tgi.get_resource_index(fabric))
                fabric_len = 0
                with BytesIO() as fabric_stream:
                    fabric.write(fabric_stream, tgi)
                    s.u32(fabric_stream.tell())
                    fabric_stream.seek(0, SEEK_SET)
                    stream.write(fabric_stream.read(-1))
            s.u32(self.target_size)
            s.u32(self.part_type)
            s.u8(0)
            s.i32(len(self.steps))
            if self.version >= 0x08:
                s.u8(0)
            for step in self.steps:
                self.write_step(stream, tgi, step)
        if use_tgi:
            tgi.end_read(stream)
        else:
            s.u32(0)
Beispiel #12
0
    def read(self, stream, resources=None):
        s = StreamReader(stream)
        self.version = s.u32()

        use_tgi = not isinstance(resources, TGIList)
        tgi = resources
        if use_tgi:
            tgi = TGIList(order='IGT', use_length=False, package=resources, count_size=8)
            tgi.begin_read(stream)

        if self.version >= 7:
            cFabrics = s.i8()
            for fabric_index in range(cFabrics):
                key = tgi.get_resource(s.u8())
                fabric = TextureCompositor(key)
                fabric_len = s.u32()
                with BytesIO() as fabric_stream:
                    fabric_stream.write(stream.read(fabric_len))
                    fabric_stream.seek(0, SEEK_SET)
                    fabric.read(fabric_stream, tgi)
                self.fabrics.append(fabric)
        self.target_size = s.u32()
        self.part_type = s.u32()
        assert s.u8() == 0
        cSteps = s.i32()
        if self.version >= 0x08:
            assert s.u8() == 0
        self.steps = []
        for step_index in range(cSteps):
            self.steps.append(self.read_step(stream, tgi))
        if use_tgi:
            tgi.end_read(stream)
        else:
            assert s.u32() == 0
Beispiel #13
0
    def deserialize(self,stream,parent_tgi):
        def read_element(s,tgi_list):
            def read_complate_string(s):
                a = s.i8()
                if not a: return None
                if a & 0x80: return s.chars(s.i8() if a & 0x40 else a &0x3F)
                if a & 0x40: a = (a & 0x3F) + s.i8()
                return self.complate_string_lookup[a]
            def read_typecode(s,tgi_list):
                tc = s.u8()
                if   tc == 1: return read_complate_string(s)
                elif tc == 0x02: return [s.u8() for i in range(4)]
                elif tc == 0x03: return tgi_list.get_resource(s.i8())
                elif tc == 0x04: return s.f32()
                elif tc == 0x05: return [s.f32() for i in range(2)]
                elif tc == 0x06: return [s.f32() for i in range(3)]
                elif tc == 0x07: return bool(s.i8())
                else: raise Exception("Unknown typecode %02X"%tc)
            element = Preset.Element()
            element.resource = tgi_list.get_resource(s.u8())
            element.name = read_complate_string(s)
            element.variable = read_complate_string(s)

            for i in range(s.i32()):
                name = read_complate_string(s)
                value = read_typecode(s,tgi_list)
                element.values[name] =value
            element.patterns = [read_element(s,tgi_list) for i in range(s.i32())]
            return element
        s = StreamReader(stream)
        unk = s.i16()
        preset_tgi = TGIList(use_length=True)
        preset_tgi.begin_read(stream)
        element = read_element(s,preset_tgi)
        preset_tgi.end_read(stream)
        complate = ComplateElement()
        complate.preset = element
        complate.priority = unk
        return complate
Beispiel #14
0
 def read(self, stream, resources=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList(package=resources)
     tgi.begin_read(stream)
     self.locale_key = s.u64()
     self.indexers = [tgi.get_resource(s.i32()) for i in range(s.i32())]
     self.is_bi_directional = bool(s.u32())
     self.cas_panel_group = s.u32()
     self.sort_index = s.i32()
     assert s.u32() == 0
     tgi.end_read(stream)
Beispiel #15
0
 def write_rcol(self, stream, rcol):
     s = StreamWriter(stream)
     self.write_tag(stream)
     s.u32(self.version)
     tgi = TGIList(32, 'TGI')
     tgi.begin_write(stream)
     s.hash(self.shader)
     if self.shader:
         self.material.write(stream, tgi)
     s.u32(self.merge_group)
     s.u32(self.sort_order)
     s.u32(len(self.vertices))
     self.vertex_format.from_vertex(self.vertices[0])
     self.vertex_format.write(stream)
     for vertex in self.vertices:
         uv_index = 0
         for declaration in self.vertex_format.declarations:
             if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION:
                 for i in range(3): s.f32(vertex.position)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL:
                 for i in range(3): s.f32(vertex.normal)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV:
                 for i in range(2): s.f32(vertex.uv[uv_index])
                 uv_index += 1
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX:
                 for i in range(4): s.i8(vertex.blend_indices)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT:
                 for i in range(4): s.f32(vertex.blend_weights)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT:
                 for i in range(3): s.f32(vertex.tangents)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR:
                 for i in range(4): s.i8(vertex.colour)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID:
                 s.u32(vertex.id)
     s.u32(tgi.get_resource_index(self.skin_controller))
     s.u32(len(self.bones))
     for bone in self.bones: s.u32(bone)
Beispiel #16
0
 def read(self, stream, resources=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList(package=resources)
     tgi.begin_read(stream)
     if self.version >= 0x00000003:
         self.presets = ProductBase.read_presets(stream,tgi)
     self.product_info = ProductInfo()
     self.product_info.read(stream,tgi)
     self.railing_4x_model = tgi.get_resource(s.i32())
     self.railing_1x_model = tgi.get_resource(s.i32())
     self.post_model = tgi.get_resource(s.i32())
     tgi.end_read(stream)
Beispiel #17
0
 def write(self, stream, resources=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList(package=resources)
     tgi.begin_write(stream)
     s.u64(self.locale_key)
     for indexer in self.indexers:
         s.u32(tgi.get_resource_index(indexer))
     s.u32(0 if not self.is_bi_directional else 1)
     s.u32(self.cas_panel_group)
     s.i32(self.sort_index)
     s.u32(0)
     tgi.end_read(stream)
Beispiel #18
0
 def read(self, stream, resources=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList()
     tgi.begin_read(stream)
     self.shader_keys = [self.ShaderKey(self, stream, tgi) for i in range(s.i32())]
     self.sub_skin_ramp = tgi.get_resource(s.u32())
     self.tone_ramp = tgi.get_resource(s.u32())
     self.texture_keys = [self.TextureKey(self, stream, tgi) for i in range(s.i32())]
     self.dominant = bool(s.u8())
Beispiel #19
0
 def write(self, stream, resources=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList()
     tgi.begin_write(stream)
     for shader_key in self.shader_keys: shader_key.write(stream, tgi)
     s.u32(tgi.get_resource_index(self.sub_skin_ramp))
     s.u32(tgi.get_resource_index(self.tone_ramp))
     for texture_key in self.texture_keys: texture_key.write(stream, tgi)
     s.u8(self.is_dominant)
Beispiel #20
0
 def read_rcol(self, stream, rcol):
     s = StreamReader(stream)
     self.read_tag(stream)
     self.version = s.u32()
     tgi = TGIList()
     tgi.begin_read(stream)
     self.shader = s.u32()
     if self.shader:
         end_material = s.u32() + stream.tell()
         self.material = MaterialBlock()
         self.material.read(stream, tgi)
         assert stream.tell() == end_material
     self.merge_group = s.u32()
     self.sort_order = s.u32()
     cVertices = s.u32()
     self.vertex_format.read(stream)
     for vertex_index in range(cVertices):
         vertex = Vertex()
         for declaration in self.vertex_format.declarations:
             if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION:
                 vertex.position = [s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL:
                 vertex.normal = [s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV:
                 uv = [s.f32(), s.f32()]
                 if vertex.uv == None:
                     vertex.uv = []
                 vertex.uv.append(uv)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX:
                 vertex.blend_indices = [s.i8(), s.i8(), s.i8(), s.i8()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT:
                 vertex.blend_weights = [s.f32(), s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT:
                 vertex.tangent = [s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR:
                 vertex.colour = [s.u8(), s.u8(), s.u8(), s.u8()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID:
                 vertex.id = s.u32()
         self.vertices.append(vertex)
     assert s.u32() == 1
     bytes_per_index = s.u8()
     assert bytes_per_index == 2
     self.indices = [[s.u16() for i in range(3)]
                     for i in range(int(s.u32() / 3))]
     self.skin_controller = tgi.get_resource(s.u32())
     self.bones = [s.u32() for i in range(s.u32())]
     tgi.end_read(stream)
Beispiel #21
0
 def read_rcol(self, stream, rcol):
     self.read_tag(stream)
     s = StreamReader(stream)
     tgi = TGIList()
     self.version = s.u32()
     tgi.begin_read(stream)
     cEntries = s.u8()
     for entry_index in range(cEntries):
         type = s.u8()
         entry = self.Entry.create_instance(type)
         entry.read(stream, tgi)
         self.entries.append(entry)
     assert s.u8() == 0x02
     self.bounds.read(stream)
     self.flags = s.u32()
     if s.u8():
         self.routing_footprint = tgi.get_resource(s.u32())
     tgi.end_read(stream)
Beispiel #22
0
    def read_xml(self, xml_string, resources):
        def parse_value(value_string, resources):
            items = []
            strings = value_string.split(',')
            for string in strings:
                if string[:4] == 'key:':
                    keyVals = string[4:].split(':')
                    key = ResourceKey(int(keyVals[0], 16), int(keyVals[1], 16),
                                      int(keyVals[2], 16))
                    items.append(key)
                elif string in ('true', 'false'):
                    items.append(string == 'true')
                else:
                    items.append(string)
            return items if len(items) > 1 else items[0]

        doc = parseString(xml_string)
        presetElement = doc.documentElement
        complateElement = presetElement.getElementsByTagName('complate')[0]
        if not resources:
            resources = TGIList()

        self.complate = self.Element()
        self.complate.name = complateElement.nodeName
        self.complate.resource = parse_value(
            complateElement.attributes['reskey'].nodeValue, resources)
        for keyElement in complateElement.getElementsByTagName('value'):
            key = keyElement.attributes['key'].nodeValue
            value = keyElement.attributes['value'].nodeValue
            self.complate.values[key] = parse_value(value, resources)
        for patternElement in complateElement.getElementsByTagName('pattern'):
            pattern = self.Element()
            pattern.name = patternElement.nodeName
            pattern.resource = parse_value(
                patternElement.attributes['reskey'].nodeValue, resources)
            pattern.variable = parse_value(
                patternElement.attributes['variable'].nodeValue, resources)
            for keyElement in patternElement.getElementsByTagName('value'):
                key = keyElement.attributes['key'].nodeValue
                value = keyElement.attributes['value'].nodeValue
                pattern.values[key] = parse_value(value, resources)
            self.complate.patterns.append(pattern)
Beispiel #23
0
 def write(self, stream, resource=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList(use_length=self.version >= 7, add_eight=True)
     tgi.begin_write(stream)
     s.s7(self.part_name, 16, '>')
     s.u32(self.blend_type)
     s.i32(len(self.entries))
     for entry in self.entries:
         s.u32(entry.region_flags)
         s.i32(len(entry.geom_entries))
         for geom_entry in entry.geom_entries: geom_entry.write_rcol(stream, tgi)
         s.i32(len(entry.bone_entries))
         for bone_entry in entry.bone_entries: bone_entry.write_rcol(stream, tgi)
     tgi.end_write(stream)
Beispiel #24
0
 def read_rcol(self, stream, rcol):
     s = StreamReader(stream)
     self.read_tag(stream)
     self.version = s.u32()
     tgi = TGIList()
     tgi.begin_read(stream)
     self.shader = s.u32()
     if self.shader:
         end_material = s.u32() + stream.tell()
         self.material = MaterialBlock()
         self.material.read(stream, tgi)
         assert stream.tell() == end_material
     self.merge_group = s.u32()
     self.sort_order = s.u32()
     cVertices = s.u32()
     self.vertex_format.read(stream)
     for vertex_index in range(cVertices):
         vertex = Vertex()
         for declaration in self.vertex_format.declarations:
             if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION:
                 vertex.position = [s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL:
                 vertex.normal = [s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV:
                 uv = [s.f32(), s.f32()]
                 if vertex.uv == None:
                     vertex.uv = []
                 vertex.uv.append(uv)
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX:
                 vertex.blend_indices = [s.i8(), s.i8(), s.i8(), s.i8()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT:
                 vertex.blend_weights = [s.f32(), s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT:
                 vertex.tangent = [s.f32(), s.f32(), s.f32()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR:
                 vertex.colour = [s.u8(), s.u8(), s.u8(), s.u8()]
             elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID:
                 vertex.id = s.u32()
         self.vertices.append(vertex)
     assert s.u32() == 1
     bytes_per_index = s.u8()
     assert bytes_per_index == 2
     self.indices = [[s.u16() for i in range(3)] for i in range(int(s.u32() / 3))]
     self.skin_controller = tgi.get_resource(s.u32())
     self.bones = [s.u32() for i in range(s.u32())]
     tgi.end_read(stream)
Beispiel #25
0
 def write_rcol(self, stream, rcol):
     self.write_tag(stream)
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList()
     tgi.begin_write(stream)
     s.u8(len(self.entries))
     for entry in self.entries:
         s.u8(entry.TYPE)
         entry.write(stream, tgi)
     s.u8(2)
     self.bounds.write(stream)
     s.u32(self.flags)
     if self.routing_footprint.key != ResourceKey():
         s.u8(1)
         s.tgi(self.routing_footprint.key, 'TGI')
     else: s.u8(0)
     tgi.end_write(stream)
Beispiel #26
0
 def read_rcol(self, stream, rcol):
     self.read_tag(stream)
     s = StreamReader(stream)
     tgi = TGIList()
     self.version = s.u32()
     tgi.begin_read(stream)
     cEntries = s.u8()
     for entry_index in range(cEntries):
         t = s.u8()
         entry = self.Entry.create_instance(t)
         entry.read(stream, tgi)
         self.entries.append(entry)
     assert s.u8() == 0x02
     self.bounds.read(stream)
     self.flags = s.u32()
     if s.u8():
         self.routing_footprint = tgi.get_resource(s.u32())
     tgi.end_read(stream)
Beispiel #27
0
 def read(self, stream, resource=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList(use_length=self.version >= 7, add_eight=True)
     tgi.begin_read(stream)
     self.part_name = s.s7(16, '>')
     self.blend_type = s.u32()
     if self.version >= 8:
         key = s.tgi()
         bgeo = ExternalResource(key=key)
         self.blend_geometry = bgeo
     cEntries = s.i32()
     for i in range(cEntries):
         entry = self.RegionEntry()
         entry.region_flags = s.u32()
         entry.geom_entries = [self.GeomEntry(stream, tgi) for i in range(s.i32())]
         entry.bone_entries = [self.BoneEntry(stream, tgi) for i in range(s.i32())]
         self.entries.append(entry)
     tgi.end_read(stream)
Beispiel #28
0
    def read(self, stream, resources=None):
        s = StreamReader(stream)
        self.version = s.u32()

        use_tgi = not isinstance(resources, TGIList)
        tgi = resources
        if use_tgi:
            tgi = TGIList(order='IGT',
                          use_length=False,
                          package=resources,
                          count_size=8)
            tgi.begin_read(stream)

        if self.version >= 7:
            cFabrics = s.i8()
            for fabric_index in range(cFabrics):
                key = tgi.get_resource(s.u8())
                fabric = TextureCompositor(key)
                fabric_len = s.u32()
                with BytesIO() as fabric_stream:
                    fabric_stream.write(stream.read(fabric_len))
                    fabric_stream.seek(0, SEEK_SET)
                    fabric.read(fabric_stream, tgi)
                self.fabrics.append(fabric)
        self.target_size = s.u32()
        self.part_type = s.u32()
        assert s.u8() == 0
        cSteps = s.i32()
        if self.version >= 0x08:
            assert s.u8() == 0
        self.steps = []
        for step_index in range(cSteps):
            self.steps.append(self.read_step(stream, tgi))
        if use_tgi:
            tgi.end_read(stream)
        else:
            assert s.u32() == 0
Beispiel #29
0
    def deserialize(self, stream, parent_tgi):
        def read_element(s, tgi_list):
            def read_complate_string(s):
                a = s.i8()
                if not a: return None
                if a & 0x80: return s.chars(s.i8() if a & 0x40 else a & 0x3F)
                if a & 0x40: a = (a & 0x3F) + s.i8()
                return self.complate_string_lookup[a]

            def read_typecode(s, tgi_list):
                tc = s.u8()
                if tc == 1: return read_complate_string(s)
                elif tc == 0x02: return [s.u8() for i in range(4)]
                elif tc == 0x03: return tgi_list.get_resource(s.i8())
                elif tc == 0x04: return s.f32()
                elif tc == 0x05: return [s.f32() for i in range(2)]
                elif tc == 0x06: return [s.f32() for i in range(3)]
                elif tc == 0x07: return bool(s.i8())
                else: raise Exception("Unknown typecode %02X" % tc)

            element = Preset.Element()
            element.resource = tgi_list.get_resource(s.u8())
            element.name = read_complate_string(s)
            element.variable = read_complate_string(s)

            for i in range(s.i32()):
                name = read_complate_string(s)
                value = read_typecode(s, tgi_list)
                element.values[name] = value
            element.patterns = [
                read_element(s, tgi_list) for i in range(s.i32())
            ]
            return element

        s = StreamReader(stream)
        unk = s.i16()
        preset_tgi = TGIList(use_length=True)
        preset_tgi.begin_read(stream)
        element = read_element(s, preset_tgi)
        preset_tgi.end_read(stream)
        return element
Beispiel #30
0
    def read(self, stream, resources=None):
        s = StreamReader(stream)
        self.version = s.u32()
        tgi = TGIList(package=resources)
        tgi.begin_read(stream)
        self.product_info = ProductInfo()
        self.product_info.read(stream,tgi)

        self.fireplace_width = s.i8()
        self.mantle =  tgi.get_resource(s.i32())
        self.chimney_mantle =  tgi.get_resource(s.i32())
        self.chimney_full_level =  tgi.get_resource(s.i32())
        self.chimney_ground_level =  tgi.get_resource(s.i32())
        self.chimney_body =  tgi.get_resource(s.i32())
        self.chimney_top =  tgi.get_resource(s.i32())
        self.chimney_cap =  tgi.get_resource(s.i32())
        tgi.end_read(stream)
Beispiel #31
0
 def read(self, stream, resources=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList()
     tgi.begin_read(stream)
     self.presets = ProductBase.read_presets(stream,tgi)
     if self.version >= 0x00000016:
         self.instance_name = s.s7(size=16,order='>')
     self.product_info = ProductInfo()
     self.product_info.read(stream,tgi)
     self.object_component = tgi.get_resource(s.i32())
     self.object_type_flags = s.u32()
     if self.version >= 0x00000001A:
         self.object_type_flags_2 = s.u32()
     self.wall_placement_flags = s.u32()
     self.movement_flags = s.u32()
     self.num_wall_cutout_tiles_per_level = s.i32()
     self.num_levels = s.i32()
     self.wall_masks = [self.WallMaskEntry(stream,tgi) for i in range(s.i8())]
     self.script_enabled = s.i8() == 1
     self.diagonal_object = tgi.get_resource(s.i32())
     self.ambiance_type = s.hash()
     self.room_flags = s.u32()
     self.function_category_flags = s.u32()
     self.sub_category_flags = s.u64()
     if self.version >= 0x0000001C:
         self.sub_category_flags_2 = s.u64()
     self.sub_room_flags = s.u64()
     self.build_category_flags = s.u32()
     self.wall_cutout_texture = tgi.get_resource(s.i32())
     if self.version >= 0x00000017:
         self.floor_cutout_texture = tgi.get_resource(s.i32())
         self.floor_cutout_level_offset = s.i32()
         self.floor_cutout_bounds_length = s.f32()
     if self.version >= 0x00000020:
         self.floor_cutout_bounds_width = s.f32()
     if self.version >= 0x0000021:
         self.floor_cutout_offset_x = s.f32()
         self.floor_cutout_offset_z = s.f32()
     if self.version >= 0x00000018:
         self.shell_states = [s.hash() for i in range(s.i32())]
     if self.version >= 0x00000019:
         self.shell_level_below =tgi.get_resource(s.i32())
     if self.version >= 0x0000001B:
         self.shell_proxy =tgi.get_resource(s.i32())
     if self.version >= 0x0000001D:
         self.blueprint_xml =tgi.get_resource(s.i32())
     if self.version >= 0x0000001E:
         self.blueprint_icon =tgi.get_resource(s.i32())
     if self.version >= 0x0000001F:
         self.blueprint_icon_offset_min_x = s.f32()
         self.blueprint_icon_offset_min_z = s.f32()
         self.blueprint_icon_offset_max_x = s.f32()
         self.blueprint_icon_offset_max_z = s.f32()
     self.slot_placement_flags = s.u32()
     self.surface_type = s.s7(size=16,order='>')
     self.source_material = s.s7(size=16,order='>')
     self.moodlet_given = s.u32()
     self.moodlet_score = s.u32()
     assert s.u32() == 5
     self.ratings = [self.ProductRating(stream) for i in range(5)]
     self.fallback = tgi.get_resource(s.i32())
     if self.version >= 0x00000022:
         self.modular_arch_end_east_model = tgi.get_resource(s.i32())
         self.modular_arch_end_west_model = tgi.get_resource(s.i32())
         self.modular_arch_connecting_model = tgi.get_resource(s.i32())
         self.modular_arch_single_model = tgi.get_resource(s.i32())
     tgi.end_read(stream)
Beispiel #32
0
 def write(self, stream, resources=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList()
     tgi.begin_write(stream)
     ProductBase.write_presets(stream,self.presets,tgi)
     if self.version >= 0x00000016:
         s.s7(self.instance_name,size=16,order='>')
     self.product_info.write(stream,tgi)
     s.i32(tgi.get_resource(self.object_component))
     s.u32(self.object_type_flags)
     if self.version >= 0x000001A:
         s.u32(self.object_type_flags_2)
     s.u32(self.wall_placement_flags)
     s.u32(self.movement_flags)
     s.i32(self.num_wall_cutout_tiles_per_level)
     s.i32(self.num_levels)
     s.i8(len(self.wall_masks))
     for wall_mask in self.wall_masks:
         wall_mask.write(stream,tgi)
     s.i8(1 if self.script_enabled else 0)
     s.i32(tgi.get_resource_index(self.diagonal_object))
     s.hash(self.ambiance_type)
     s.u32(self.room_flags)
     s.u32(self.function_category_flags)
     s.u64(self.sub_category_flags)
     if self.version >= 0x0000001C:
         s.u64(self.sub_category_flags_2)
     s.u64(self.sub_room_flags)
     s.u32(self.build_category_flags)
     s.i32(tgi.get_resource_index(self.wall_cutout_texture))
     if self.version >= 0x00000017:
         s.i32(tgi.get_resource_index(self.floor_cutout_texture))
         s.i32(self.floor_cutout_level_offset)
         s.f32(self.floor_cutout_bounds_length )
     if self.version >= 0x00000020:
         s.f32(self.floor_cutout_bounds_width )
     if self.version >= 0x0000021:
         s.f32(self.floor_cutout_offset_x )
         s.f32(self.floor_cutout_offset_z )
     if self.version >= 0x00000018:
         s.i32(len(self.shell_states))
         for shell_state in self.shell_states: s.hash(shell_state)
     if self.version >= 0x00000019:
         s.i32(tgi.get_resource_index(self.shell_level_below ))
     if self.version >= 0x0000001B:
         s.i32(tgi.get_resource_index(self.shell_proxy ))
     if self.version >= 0x0000001D:
         s.i32(tgi.get_resource_index(self.blueprint_xml ))
     if self.version >= 0x0000001E:
         s.i32(tgi.get_resource_index(self.blueprint_icon ))
     if self.version >= 0x0000001F:
         s.f32(self.blueprint_icon_offset_min_x)
         s.f32(self.blueprint_icon_offset_min_z)
         s.f32(self.blueprint_icon_offset_max_x)
         s.f32(self.blueprint_icon_offset_max_z)
     s.u32(self.slot_placement_flags)
     s.s7(self.surface_type,size=16,order='>')
     s.s7(self.source_material,size=16,order='>')
     s.u32(self.moodlet_given)
     s.u32(self.moodlet_score)
     s.u32(5)
     for rating in self.ratings: rating.write(stream)
     s.i32(tgi.get_resource_index(self.fallback))
     if self.version >= 0x00000022:
         s.i32(tgi.get_resource_index(self.modular_arch_end_east_model))
         s.i32(tgi.get_resource_index(self.modular_arch_end_east_model))
         s.i32(tgi.get_resource_index(self.modular_arch_connecting_model))
         s.i32(tgi.get_resource_index(self.modular_arch_single_model))
     tgi.end_write(stream)
Beispiel #33
0
 def read(self, stream, resource=None):
     s = StreamReader(stream)
     self.version = s.u32()
     tgi = TGIList(order='igt', count_size=8, package=resource, use_length=False)
     tgi.begin_read(stream)
     self.presets = [self.CasPreset(stream, tgi) for i in range(s.u32())]
     self.part_name = s.s7(16, '>')
     self.display_index = s.f32()
     self.has_unique_texture_space = s.u8()
     self.body_type = s.u32()
     self.part_flags = s.u32()
     self.age_gender_flags = s.u32()
     self.clothing_category = s.u32()
     self.naked_cas_part = tgi.get_resource(s.i8())
     self.base_cas_part = tgi.get_resource(s.i8())
     self.blend_fat = tgi.get_resource(s.i8())
     self.blend_fit = tgi.get_resource(s.i8())
     self.blend_thin = tgi.get_resource(s.i8())
     self.blend_special = tgi.get_resource(s.i8())
     self.draw_layer = s.u32()
     self.sources = [tgi.get_resource(s.i8()) for i in range(s.u8())]
     self.lod_infos = [CASLodInfo(stream) for i in range(s.u8())]
     self.diffuse_refs = [tgi.get_resource(s.i8()) for i in range(s.u8())]
     self.specular_refs = [tgi.get_resource(s.i8()) for i in range(s.u8())]
     self.secondary_diffuse_refs = [tgi.get_resource(s.i8()) for i in range(s.u8())]
     self.secondary_specular_refs = [tgi.get_resource(s.i8()) for i in range(s.u8())]
     self.slot_poses = [tgi.get_resource(s.i8()) for i in range(s.u8())]
     self.shoe_material = s.s7(16, '>')
     tgi.end_read(stream)
Beispiel #34
0
    def write(self, stream, resources=None):
        s = StreamWriter(stream)
        s.u32(self.version)
        tgi = TGIList()
        tgi.begin_write(stream)
        self.product_info.write(stream,tgi)

        s.i8(self.fireplace_width)
        s.i32(tgi.get_resource_index(self.mantle))
        s.i32(tgi.get_resource_index(self.chimney_mantle))
        s.i32(tgi.get_resource_index(self.chimney_full_level))
        s.i32(tgi.get_resource_index(self.chimney_ground_level))
        s.i32(tgi.get_resource_index(self.chimney_body))
        s.i32(tgi.get_resource_index(self.chimney_top))
        s.i32(tgi.get_resource_index(self.chimney_cap))

        tgi.end_write(stream)
Beispiel #35
0
 def write(self, stream, resource=None):
     s = StreamWriter(stream)
     s.u32(self.version)
     tgi = TGIList('igt', 8, False)
     tgi.begin_write(stream)
     for preset in self.presets: preset.write(stream)
     s.s7(self.part_name, 16, '>')
     s.f32(self.display_index)
     s.u8(self.has_unique_texture_space)
     s.u32(self.body_type)
     s.u32(self.part_flags)
     s.u32(self.age_gender_flags)
     s.u32(self.clothing_category)
     s.i8(tgi.get_resource_index(self.naked_cas_part))
     s.i8(tgi.get_resource_index(self.base_cas_part))
     s.i8(tgi.get_resource_index(self.blend_fat))
     s.i8(tgi.get_resource_index(self.blend_fit))
     s.i8(tgi.get_resource_index(self.blend_thin))
     s.i8(tgi.get_resource_index(self.blend_special))
     s.u32(self.draw_layer)
     s.i8(len(self.sources))
     for source in self.sources: s.i8(tgi.get_resource_index(source))
     s.i8(len(self.lod_infos))
     for lod_info in self.lod_infos: lod_info.write(stream)
     s.i8(len(self.diffuse_refs))
     for diffuse_ref in self.diffuse_refs: s.i8(tgi.get_resource_index(diffuse_ref))
     s.i8(len(self.specular_refs))
     for specular_ref in self.specular_refs: s.i8(tgi.get_resource_index(specular_ref))
     s.u8(len(self.secondary_diffuse_refs))
     for block in self.secondary_diffuse_refs: s.u8(tgi.get_resource_index(block))
     s.u8(len(self.secondary_specular_refs))
     for block in self.secondary_specular_refs: s.u8(tgi.get_resource_index(block))
     s.u8(len(self.slot_poses))
     for block in self.slot_poses: s.u8(tgi.get_resource_index(block))
     s.s7(self.shoe_material, 16, '>')
     tgi.end_write(stream)