Ejemplo n.º 1
0
def parse_mesh(data, mesh_id):
    position = 0
    shader, position = xray_utils.parse_string_nul(data, position)
    texture, position = xray_utils.parse_string_nul(data, position)
    mesh_info, position = u('IffII', data, position)
    flags, min_scale, max_scale, vertices_count, indices_count = mesh_info
    vertices = []
    uvs = []

    for vertex_id in range(vertices_count):
        vertex_data, position = u('5f', data, position)
        position_x, position_y, position_z, uv_x, uv_y = vertex_data
        vertices.append((position_x, position_z, position_y))
        uvs.append((uv_x, 1 - uv_y))

    triangles = []
    
    for index_id in range(indices_count//3):
        triangle_data, position = u('3H', data, position)
        index_1, index_2, index_3  = triangle_data
        triangles.append((index_1, index_3, index_2))
    
    mesh_data = {}
    mesh_data['vertices'] = vertices
    mesh_data['triangles'] = triangles
    mesh_data['uvs'] = uvs
    mesh_data['images'] = 'details\\build_details'
    mesh_data['material_indices'] = None
    mesh_data['materials'] = None
    
    xray_import.crete_mesh(mesh_data)
def parse_mesh(s):
    p = 0
    shr, p = ps(s, p)
    txr, p = ps(s, p)
    (flg, min, max, vcnt, icnt), p = u('IffII', s, p)
    # print('  shader: {}, image: {}'.format(shr, txr))
    # print('  vertices: {}, indices: {}\n'.format(vcnt, icnt))
    verts = []
    uvs = []
    for v in range(vcnt):
        (X, Z, Y), p = u('fff', s, p)
        (U, V), p = u('ff', s, p)
        verts.append((X, Y, Z))
        uvs.append((U, 1 - V))
    indices = []
    for t in range(icnt // 3):
        tri, p = u('3H', s, p)
        indices.append((tri[0], tri[2], tri[1]))
    mesh_data = {}
    mesh_data['vertices'] = verts
    mesh_data['triangles'] = indices
    mesh_data['uvs'] = uvs
    mesh_data['images'] = txr
    mesh_data['material_indices'] = None
    mesh_data['materials'] = None
    xray_import.crete_mesh(mesh_data)
Ejemplo n.º 3
0
def details_data_parse(details_data):
    position = 0
    while position < len(details_data):
        position, block_id, block_size = xray_utils.read_block(position, details_data)
        
        if block_id == 0x0:
            slots_coords = parse_header(details_data[position : position + block_size], coord_y)
            position += block_size
            mesh_data = {}
            mesh_data['vertices'] = slots_coords
            mesh_data['triangles'] = ()
            mesh_data['uvs'] = None
            mesh_data['images'] = None
            mesh_data['material_indices'] = None
            mesh_data['materials'] = None
            xray_import.crete_mesh(mesh_data)
        elif block_id == 0x1:
            parse_meshes(details_data[position : position + block_size])
            position += block_size
        elif block_id == 0x2:
            coord_y = parse_slots(details_data[position : position + block_size])
            position += block_size
        else:
            print(' ! UNKNOW BLOCK ({0}) {1} BYTES'.format(hex(block_id), block_size))
            position += block_size
Ejemplo n.º 4
0
def ogf_data_parse(data):
    data_size = len(data)
    position = 0
    parse_children = False
    while position < data_size:
        position, block_id, block_size = xray_utils.read_block(position, data)
        if block_id == HEADER[0]:
            parse_header(data[position:position + block_size])
        elif block_id == TEXTURE[0]:
            texture_name = parse_texture(data[position:position + block_size])
        elif block_id == VERTICES[0]:
            vertices, uvs = parse_vertices(data[position:position +
                                                block_size])
        elif block_id == INDICES[0]:
            triangles = parse_indices(data[position:position + block_size])
        elif block_id == CHILDREN[0]:
            parse_childrens(data[position:position + block_size])
            parse_children = True
        else:
            pass
            # print('! UNKNOWN BLOCK: {0}'.format(hex(block_id)))
        position += block_size

    if not parse_children:
        mesh_data = {}
        mesh_data['vertices'] = vertices
        mesh_data['triangles'] = triangles
        mesh_data['uvs'] = uvs
        mesh_data['materials'] = None
        mesh_data['images'] = texture_name
        mesh_data['material_indices'] = None
        xray_import.crete_mesh(mesh_data)
Ejemplo n.º 5
0
def parse_visual(s, ):
    p = 0
    offset, vertices, triangles, uvs = 0, None, None, None
    while p < len(s):
        (id, cmpr, sz), p = u('HHI', s, p)
        if id == 0x1:
            pass
        elif id == 0x6:
            offset = parse_swis(s[p:p + sz])
        elif id == 0xa:
            pass
        elif id == 0x15:
            vertices, triangles, uvs = parse_gcontainer(s[p:p + sz])
            xray_utils.print_bytes(s[p:p + sz], out_path='c:\\LOG.TXT')
        elif id == 0x16:
            pass
        else:
            pass
        p += sz
    if offset:
        triangles = triangles[offset:]
    mesh_data = {}
    mesh_data['vertices'] = vertices
    mesh_data['triangles'] = triangles
    mesh_data['uvs'] = uvs
    mesh_data['materials'] = None
    mesh_data['images'] = None
    mesh_data['material_indices'] = None
    if vertices:
        xray_import.crete_mesh(mesh_data)
def parse_main(s):
    p = 0
    block_id, p = u(I, s, p)
    block_size, p = u(I, s, p)
    wallmarks_count, p = u(I, s, p)

    for i in range(wallmarks_count):
        set_count, p = u(I, s, p)
        shader, p = xray_utils.parse_string_nul(s, p)
        texture, p = xray_utils.parse_string_nul(s, p)
        for i in range(set_count):
            bounds, p = u(f * 4, s, p)
            vertex_count, p = u(I, s, p)
            vertices = []
            uvs = []
            for i in range(vertex_count):
                vertex, p = u(f * 3 + I + f * 2, s, p)
                vertices.append((vertex[0], vertex[2], vertex[1]))
                uvs.append((vertex[4], 1 - vertex[5]))
            # generate faces
            triangles = []
            index = 0
            for i in range(vertex_count // 3):
                triangles.append((index, index + 2, index + 1))
                index += 3

            mesh_data = {}
            mesh_data['vertices'] = vertices
            mesh_data['triangles'] = triangles
            mesh_data['uvs'] = uvs
            mesh_data['images'] = texture
            mesh_data['materials'] = None
            mesh_data['material_indices'] = None
            xray_import.crete_mesh(mesh_data)
Ejemplo n.º 7
0
def parse_childrens(data):
    position = 0

    while position < len(data):
        position, mesh_id, mesh_size = xray_utils.read_block(position, data)
        mesh_data = parse_children(data[position:position + mesh_size])
        position += mesh_size
        xray_import.crete_mesh(mesh_data)
Ejemplo n.º 8
0
def import_file(absolute_path):
    start_time = time.time()
    ext = absolute_path.split('.')[-1]
    name = absolute_path.split('\\')[-1][0 : -(len(ext)+1)]
    path = absolute_path[:-(len(name) + len(ext) + 1)]
    file_data = read_bin_file(name, ext, path)
    mesh_data = parse_file(file_data, ext)
    if mesh_data:
        xray_import.crete_mesh(mesh_data)
    finish_time = time.time()
    print('{:.6}s'.format(finish_time-start_time))
Ejemplo n.º 9
0
def parse_visual(s):
    p = 0
    offset, vertices, triangles, uvs = 0, None, None, None
    while p < len(s):
        (id, cmpr, sz), p = u('HHI', s, p)
        if id == 0x6:
            offset = parse_swis(s[p:p + sz])
        elif id == 0x15:
            vertices, triangles, uvs = parse_gcontainer(s[p:p + sz])
        p += sz
    if offset:
        triangles = triangles[offset:]
    mesh_data = {}
    mesh_data['vertices'] = vertices
    mesh_data['triangles'] = triangles
    mesh_data['uvs'] = uvs
    mesh_data['materials'] = None
    mesh_data['images'] = None
    mesh_data['material_indices'] = None
    if vertices:
        xray_import.crete_mesh(mesh_data)