Beispiel #1
0
    def format(self, pos):
        if self.version == 2048 or self.version == 2049:
            reader = DataReader(self.data)
            header = self.read_header_801(reader)
            header.format(pos)
        elif self.version == 1860 or self.version == 1861:
            reader = DataReader(self.data)
            header = self.read_header_745(reader)
            header.format(pos)
            has_topology_ids = header.find_field('flags2').flag_set(
                'FLAG2_HAS_TOPOLOGY_IDS')
            num_vertices = header.find_field('nVerts').value
            for vertex_index in xrange(num_vertices):
                self.read_vertex(reader, vertex_index).format(pos)

            num_faces = header.find_field('nFaces').value
            for face_index in xrange(num_faces):
                self.read_face(reader, not has_topology_ids,
                               face_index).format(pos)

            if has_topology_ids:
                for vertex_index in xrange(num_vertices):
                    self.read_topology_id(reader, vertex_index).format(pos)

            num_texverts = header.find_field('nTVerts').value
            if num_texverts:
                for uv_index in xrange(num_texverts):
                    self.read_uv(reader, uv_index).format(pos)

                if not has_topology_ids:
                    for tex_face_index in xrange(num_faces):
                        self.read_tex_face(reader, tex_face_index).format(pos)

            if header.find_field('flags1').flag_set('FLAG1_BONE_INFO'):
                print 'Bone links count: {0} (same as vertex count)'.format(
                    num_vertices)
                for vertex_index in xrange(num_vertices):
                    num_links_object = self.read_num_bone_links(
                        reader, vertex_index)
                    num_links_object.format(pos)
                    num_links = num_links_object.find_field(
                        'num_links[{0}]'.format(vertex_index)).value
                    for link_index in xrange(num_links):
                        self.read_bone_link(reader).format(pos)

            if header.find_field('flags2').flag_set('FLAG2_HAS_VERTEX_COLOR'):
                print 'Color count: {0} (same as vertex count)'.format(
                    num_vertices)
                for vertex_index in xrange(num_vertices):
                    self.read_vertex_color(reader, vertex_index).format(pos)

            if header.find_field('flags2').flag_set('FLAG2_HAS_VERTEX_ALPHA'):
                print 'Alpha count: {0} (same as vertex count)'.format(
                    num_vertices)
                for vertex_index in xrange(num_vertices):
                    self.read_alpha(reader, vertex_index).format(pos)

        else:
            raise VersionError
Beispiel #2
0
 def format(self, pos):
     if self.version == 2083 or self.version == 2084:
         reader = DataReader(self.data)
         header = self.read_header(reader)
         header.format(pos)
         prop_str_len = header.find_field('PropStrLen').value
         prop_str = reader.read(prop_str_len)
         print prop_str
     else:
         raise VersionError
Beispiel #3
0
    def format(self, pos):
        if self.version == 2048 or self.version == 2049:
            reader = DataReader(self.data)
            header = self.read_header(reader)
            header.format(pos)
            num_morph_targets = header.find_field("numMorphTargets").value
            for morph_target_index in xrange(num_morph_targets):
                morph_target_header = self.read_morph_target_header_v1(
                    reader, morph_target_index
                )
                morph_target_header.format(pos)
                name_length = morph_target_header.find_field("NameLength").value
                self.read_morph_target_name(reader, name_length).format(pos)
                int_vertex_count = morph_target_header.find_field(
                    "numIntVertices"
                ).value
                for target_vertex_index in xrange(int_vertex_count):
                    self.read_morph_target_int_vertex(
                        reader, target_vertex_index
                    ).format(pos)

                ext_vertex_count = morph_target_header.find_field(
                    "numExtVertices"
                ).value
                for target_vertex_index in xrange(ext_vertex_count):
                    self.read_morph_target_ext_vertex(
                        reader, target_vertex_index
                    ).format(pos)

        else:
            raise VersionError
    def format(self, pos):
        if self.version == 1:
            reader = DataReader(self.data)
            header = self.read_header(reader)
            header.format(pos)
            num_vtx = header.find_field("nRetVtx").value
            num_tets = header.find_field("nRetTets").value
            for i in xrange(num_vtx):
                read_fields(
                    None,
                    self.bigendian,
                    (FieldDef("vtx[{0}]".format(i), "3f"), ),
                    reader,
                ).format(pos)

            for i in xrange(num_tets):
                read_fields(
                    None,
                    self.bigendian,
                    (FieldDef("tets[{0}]".format(i), "4i"), ),
                    reader,
                ).format(pos)

        else:
            raise VersionError
    def format(self, pos):
        if self.version != 2048:
            raise VersionError
        reader = DataReader(self.data)
        if not self.withoutheader:
            field_defs = []
            add_chunk_header_fields(field_defs)
            header = read_fields('', self.bigendian, field_defs, reader)
            header.format(pos)
        header = read_fields('', self.bigendian, (FieldDef('numPhysicalProxies', 'I'),), reader)
        header.format(pos)
        num_proxies = header.find_field('numPhysicalProxies').value
        if self.bigendian and num_proxies > 65535:
            num_proxies = ((num_proxies >> 0 & 255) << 24) + ((num_proxies >> 8 & 255) << 16) + ((num_proxies >> 16 & 255) << 8) + ((num_proxies >> 24 & 255) << 0)
            print 'Converting old broken little-endian numPhysicalProxies to big-endian: numPhysicalProxies = {0}'.format(num_proxies)
        for proxy_index in xrange(num_proxies):
            proxy_header = self.read_proxy_header(reader, proxy_index)
            proxy_header.format(pos)
            num_points = proxy_header.find_field('numPoints').value
            for point_index in xrange(num_points):
                self.read_point(reader, point_index).format(pos)

            num_indices = proxy_header.find_field('numIndices').value
            for index_index in xrange(num_indices):
                self.read_index(reader, index_index).format(pos)

            num_materials = proxy_header.find_field('numMaterials').value
            for material_index in xrange(num_materials):
                self.read_material(reader, material_index).format(pos)
Beispiel #6
0
    def format(self, pos):
        if self.version == 2048:
            reader = DataReader(self.data)
            header = self.read_header_800(reader)
            header.format(pos)
            hasDecompMatrices = header.find_field("flags").flag_set(
                "SH_HAS_DECOMPR_MAT"
            )
            hasBoneIndices = header.find_field("flags").flag_set("BONEINDICES")
            hasSubsetTexelDensity = header.find_field("flags").flag_set(
                "HAS_SUBSET_TEXEL_DENSITY"
            )
            subsetCount = header.find_field("nCount").value
            for subsetIndex in xrange(subsetCount):
                self.read_subset(reader, subsetIndex).format(pos)

            if hasDecompMatrices:
                for subsetIndex in xrange(subsetCount):
                    self.read_decomp_matrix(reader, subsetIndex).format(pos)

            if hasBoneIndices:
                for subsetIndex in xrange(subsetCount):
                    self.read_bone_indices(reader, subsetIndex).format(pos)

            if hasSubsetTexelDensity:
                for subsetIndex in xrange(subsetCount):
                    self.read_subset_texel_density(reader, subsetIndex).format(pos)

        else:
            raise VersionError
Beispiel #7
0
 def get_vertex_count(self):
     reader = DataReader(self.data)
     if self.version == 2048 or self.version == 2049:
         header = self.read_header_801(reader)
     elif self.version == 1860 or self.version == 1861:
         header = self.read_header_745(reader)
     return header.find_field('nVerts').value
Beispiel #8
0
def formatController827(self, pos):
    reader = DataReader(self.data)
    header = readHeader827(self, reader)
    header.format(pos)
    elementCount = header.find_field('numKeys').value
    for i in xrange(elementCount):
        readCryKeyPQLog(self, reader, i).format(pos)
Beispiel #9
0
 def format(self, pos):
     if self.version != 2416:
         raise VersionError
     reader = DataReader(self.data)
     header = self.read_header(reader)
     header.format(pos)
     print 'parsing of remaining data is not implemented yet'
Beispiel #10
0
 def format(self, pos):
     if self.version == 2328:
         reader = DataReader(self.data)
         header = self.read_header(reader)
         header.format(pos)
     else:
         raise VersionError
Beispiel #11
0
 def format(self, pos):
     if self.version != 1:
         raise VersionError
     reader = DataReader(self.data)
     header = self.read_header(reader)
     header.format(pos)
     num_bones = header.find_field("numBones").value
     for bone_index in xrange(num_bones):
         self.read_bone(reader, bone_index).format(pos)
Beispiel #12
0
    def format(self, pos):
        if self.version == 1860:
            reader = DataReader(self.data)
            header = self.read_header(reader)
            header.format(pos)
            num_bones = header.find_field("nEntities").value
            for bone_index in xrange(num_bones):
                self.read_bone(reader, bone_index).format(pos)

        elif self.version == 1861:
            reader = DataReader(self.data)
            header = self.read_header_745(reader)
            header.format(pos)
            num_bones = header.find_field("numEntities").value
            for bone_index in xrange(num_bones):
                self.read_packed_bone(reader, bone_index).format(pos)

        else:
            raise VersionError
Beispiel #13
0
 def read_keys(self):
     if self.version == 2087:
         reader = DataReader(self.data)
         header = readHeader827(self, reader)
         elementCount = header.find_field('numKeys').value
         return [
             readCryKeyPQLog(self, reader, i) for i in xrange(elementCount)
         ]
     else:
         return []
 def format(self, pos):
     if self.version != 2048 and self.version != 2049:
         raise VersionError
     reader = DataReader(self.data)
     header = self.read_header(reader)
     header.format(pos)
     num_indices = header.find_field("indexCount").value
     for i in xrange(num_indices):
         r = read_fields(None, self.bigendian,
                         [FieldDef("index[{0}]".format(i), "h")], reader)
         r.format(pos)
Beispiel #15
0
    def format(self, pos):
        if self.version != 1860:
            raise VersionError
        reader = DataReader(self.data)
        header = self.read_header(reader)
        header.format(pos)
        num_vertices = header.find_field("nVerts").value
        for vertex_index in xrange(num_vertices):
            self.read_vertex(reader, vertex_index).format(pos)

        num_faces = header.find_field("nFaces").value
        for face_index in xrange(num_faces):
            self.read_face(reader, face_index).format(pos)
 def format(self, pos):
     if self.version != 2048:
         raise VersionError
     reader = DataReader(self.data)
     header_field_defs = []
     if not self.withoutheader:
         add_chunk_header_fields(header_field_defs)
     header_field_defs.extend((FieldDef('reserved', '32s', hex_dump),))
     header = read_fields('', self.bigendian, header_field_defs, reader)
     header.format(pos)
     num_vertices = (len(self.data) - get_fields_size(header_field_defs)) / get_fields_size(vertex_field_defs)
     print 'VertexCount: {0}'.format(num_vertices)
     for vertex_index in xrange(num_vertices):
         self.read_vertex(reader, vertex_index).format(pos)
Beispiel #17
0
 def format(self, pos):
     if self.version != 2048:
         raise VersionError
     reader = DataReader(self.data)
     header_field_defs = []
     if not self.withoutheader:
         add_chunk_header_fields(header_field_defs)
     header_field_defs.extend((FieldDef("reserved", "32s", hex_dump), ))
     header = read_fields("", self.bigendian, header_field_defs, reader)
     header.format(pos)
     num_bones = (len(self.data) - get_fields_size(header_field_defs)
                  ) / get_fields_size(bone_entity_field_defs)
     for bone_index in xrange(num_bones):
         self.read_bone_entity(reader, bone_index).format(pos)
Beispiel #18
0
    def format(self, pos):
        if self.version == 1:
            reader = DataReader(self.data)
            header = self.read_header_v1(reader)
            header.format(pos)
            num_target_vertices = header.find_field("numMorphVertices").value
            for target_vertex_index in xrange(num_target_vertices):
                self.read_mesh_morph_target_vertex(
                    reader, target_vertex_index).format(pos)

            string_length = self.size - reader.position
            self.read_name(reader, string_length).format(pos)
        else:
            raise VersionError
Beispiel #19
0
 def get_info(self):
     reader = DataReader(self.data)
     sourcefilename = read_string(reader)
     datetime = read_string(reader)
     user = ''
     host = ''
     if datetime.endswith('\n'):
         datetime = datetime[:-1]
         user, host = read_string(reader).split('@')
     else:
         datetime, user = datetime.split('\n')
         user, host = user.split('@')
     return (sourcefilename,
      datetime,
      user,
      host)
Beispiel #20
0
 def format(self, pos):
     reader = DataReader(self.data)
     sourcefilename = read_string(reader)
     datetime = read_string(reader)
     user = ''
     host = ''
     if datetime.endswith('\n'):
         datetime = datetime[:-1]
         user, host = read_string(reader).split('@')
     else:
         datetime, user = datetime.split('\n')
         user, host = user.split('@')
     print "sourcefilename = '%s'" % sourcefilename
     print "datetime = '%s'" % datetime
     print "user = '******'" % user
     print "host = '%s'" % host
Beispiel #21
0
 def format(self, pos):
     if self.version != 2048:
         raise VersionError
     reader = DataReader(self.data)
     header_field_defs = []
     if not self.withoutheader:
         add_chunk_header_fields(header_field_defs)
     if len(header_field_defs) > 0:
         header = read_fields('', self.bigendian, header_field_defs, reader)
         header.format(pos)
         num_faces = (len(self.data) - get_fields_size(header_field_defs)
                      ) / struct.calcsize('3H')
     else:
         num_faces = len(self.data) / struct.calcsize('3H')
     print 'FaceCount: {0}'.format(num_faces)
     for face_index in xrange(num_faces):
         self.read_face(reader, face_index).format(pos)
Beispiel #22
0
 def format(self, pos):
     if self.version != 1860:
         raise VersionError
     reader = DataReader(self.data)
     header = self.read_header(reader)
     header.format(pos)
     num = header.find_field("propCount").value
     for i in xrange(num):
         r = read_fields(
             None,
             self.bigendian,
             [
                 FieldDef("name[{0}]".format(i), "32s", strz_add_quotes),
                 FieldDef("value[{0}]".format(i), "64s", strz_add_quotes),
             ],
             reader,
         )
         r.format(pos)
Beispiel #23
0
 def format(self, pos):
     if self.version != 2048:
         raise VersionError
     reader = DataReader(self.data)
     header = self.read_header(reader)
     header.format(pos)
     data_length = header.find_field('nDataSize').value
     physics_data_header = self.read_physics_data(reader, data_length)
     physics_data_header.format(pos)
     geom_type = physics_data_header.find_field(
         'GeomType').get_enum_string()
     geom_readers = dict([(name, func) for name, index, func in geom_types])
     if geom_type in geom_readers:
         func = geom_readers[geom_type]
         if func:
             getattr(self, func)(reader, pos)
         else:
             print '<PARSER FOR THIS GEOM TYPE IS NOT IMPLEMENTED>'
     else:
         print '<INVALID GEOM TYPE>'
Beispiel #24
0
    def format(self, pos):
        if self.version != 2048:
            raise VersionError
        reader = DataReader(self.data)
        header = self.read_header(reader, self.streamTypeStrings)
        header.format(pos)
        typeString = header.find_field("nStreamType").get_enum_string()
        elementHeader, fieldDefs = self.typeDefs[typeString]
        fieldDefs = copy.deepcopy(fieldDefs)
        if elementHeader == "Position":
            if header.find_field("nElementSize").value == 8:
                fieldDefs = [FieldDef("pos", "4H", halffloat_to_str)]
            else:
                fieldDefs = [FieldDef("pos", "3f")]
        if elementHeader == "Index":
            if header.find_field("nElementSize").value == 2:
                fieldDefs = [FieldDef("index", "H")]
            else:
                fieldDefs = [FieldDef("index", "I")]
        if elementHeader == "Bone Mapping":
            if header.find_field("nElementSize").value == 8:
                fieldDefs = [
                    FieldDef("boneIDs", "4B"),
                    FieldDef("weights", "4B", normalizeduint8_to_str),
                ]
            else:
                fieldDefs = [
                    FieldDef("boneIDs", "4H"),
                    FieldDef("weights", "4B", normalizeduint8_to_str),
                ]
        fieldNames = [fd.name for fd in fieldDefs]
        elementCount = header.find_field("nCount").value
        for elementIndex in xrange(elementCount):
            for i in xrange(len(fieldDefs)):
                fieldDefs[i].name = fieldNames[i] + "[{0}]".format(
                    elementIndex)

            read_fields(None, self.bigendian, fieldDefs, reader).format(pos)
Beispiel #25
0
def formatController826(self, pos):
    typeDefEntries = [('CTRL_NONE', None), ('CTRL_CRYBONE', None),
                      ('CTRL_LINEER1', None), ('CTRL_LINEER3', None),
                      ('CTRL_LINEERQ ', None), ('CTRL_BEZIER1', None),
                      ('CTRL_BEZIER3', None), ('CTRL_BEZIERQ', None),
                      ('CTRL_TCB1', None),
                      ('CTRL_TCB3', ('TCB3', [
                          FieldDef('time', 'i'),
                          FieldDef('BaseKey3', '3f'),
                          FieldDef('t', 'f'),
                          FieldDef('c', 'f'),
                          FieldDef('b', 'f'),
                          FieldDef('ein', 'f'),
                          FieldDef('eout', 'f')
                      ])),
                      ('CTRL_TCBQ', ('TCBQ', [
                          FieldDef('time', 'i'),
                          FieldDef('BasekeyQ', '4f'),
                          FieldDef('t', 'f'),
                          FieldDef('c', 'f'),
                          FieldDef('b', 'f'),
                          FieldDef('ein', 'f'),
                          FieldDef('eout', 'f')
                      ])), ('CTRL_BSPLINE_2O', None),
                      ('CTRL_BSPLINE_1O', None), ('CTRL_BSPLINE_2C', None),
                      ('CTRL_BSPLINE_1C', None)]
    typeDefs = dict(typeDefEntries)
    reader = DataReader(self.data)
    header = readHeader826(self, reader, [x for x, y in typeDefEntries])
    header.format(pos)
    typeString = header.find_field('type').get_enum_string()
    if typeString in typeDefs and typeDefs[typeString]:
        keyHeader, fieldDefs = typeDefs[typeString]
        count = header.find_field('nKeys').value
        for key in xrange(count):
            read_fields('%s (%d)' % (keyHeader, key), self.bigendian,
                        fieldDefs, reader).format(pos)
Beispiel #26
0
 def get_streams_chunk_ids(self):
     reader = DataReader(self.data)
     header = self.read_header_801(reader)
     ids = header.find_field('nStreamChunkID').value
     return ids
Beispiel #27
0
 def format(self, pos):
     if self.version != 2417:
         raise VersionError
     reader = DataReader(self.data)
     header = self.read_header(reader)
     header.format(pos)
Beispiel #28
0
 def get_node_pos(self):
     reader = DataReader(self.data)
     header = self.read_header(reader)
     pos = header.find_field('pos').value
     return pos
Beispiel #29
0
 def get_node_name(self):
     reader = DataReader(self.data)
     header = self.read_header(reader)
     name = header.find_field('name').value
     return name
Beispiel #30
0
 def get_props(self):
     reader = DataReader(self.data)
     header = self.read_header(reader)
     prop_str_len = header.find_field('PropStrLen').value
     prop_str = reader.read(prop_str_len)
     return prop_str