Ejemplo n.º 1
0
def _sector_portal(data, sector):
    packed_reader = xray_io.PackedReader(data)
    portal_count = len(data) // format_.SECTOR_PORTAL_SIZE
    sector.portal_count = portal_count

    for portal_index in range(portal_count):
        portal = packed_reader.getf('H')[0]
Ejemplo n.º 2
0
def s_ikdata(data, visual, bones):
    packed_reader = xray_io.PackedReader(data)

    for bone_name, parent_name in bones:

        bone = visual.Bone()

        version = packed_reader.getf('I')[0]
        game_material = packed_reader.gets()

        s_bone_shape(packed_reader, bone)
        s_joint_ik_data(packed_reader, bone)

        rotate_x, rotate_y, rotate_z = packed_reader.getf('3f')
        offset_x, offset_y, offset_z = packed_reader.getf('3f')
        mass = packed_reader.getf('f')[0]
        center_of_mass = packed_reader.getf('3f')

        bone.name = bone_name
        bone.parent = parent_name
        bone.offset = (offset_x, offset_z, offset_y)
        bone.rotate = (-rotate_x, -rotate_z, -rotate_y)
        bone.game_material = game_material
        bone.mass = mass
        bone.center_of_mass = center_of_mass
        visual.bones.append(bone)
Ejemplo n.º 3
0
def _shaders_v13(data, level):
    packed_reader = xray_io.PackedReader(data)
    shaders_count = packed_reader.getf('I')[0]
    empty_shader = packed_reader.gets()

    for shader_index in range(shaders_count - 1):
        shader = packed_reader.gets()
        engine_shader, textures = shader.split('/')
        light_maps_count = textures.count(',')

        if not light_maps_count:
            texture = textures
            level.lmaps.append(None)
            level.lmaps_0.append(None)
            level.lmaps_1.append(None)

        elif light_maps_count == 1:
            texture, lmap = textures.split(',')
            level.lmaps.append(lmap)
            level.lmaps_0.append(None)
            level.lmaps_1.append(None)

        elif light_maps_count == 2:
            texture, lmap_0, lmap_1 = textures.split(',')
            level.lmaps.append(None)
            level.lmaps_0.append(lmap_0)
            level.lmaps_1.append(lmap_1)

        else:
            raise Exception('Shader has to many lmaps!')

        level.materials.append(texture)
        level.shaders.append(engine_shader)
Ejemplo n.º 4
0
def header(data):
    packed_reader = xray_io.PackedReader(data)
    xrlc_version = packed_reader.getf('H')[0]
    xrlc_quality = packed_reader.getf('H')[0]
    if xrlc_version not in format_.XRLC_SUPPORT_VERSIONS:
        raise Exception('UNSUPPORTED FORMAT VERSION: {}'.format(xrlc_version))
    return xrlc_version
Ejemplo n.º 5
0
def vertices(data, visual):
    packed_reader = xray_io.PackedReader(data)
    vertex_format = packed_reader.getf('I')[0]
    vertices_count = packed_reader.getf('I')[0]
    if vertex_format == 0x12071980:
        for vertex_index in range(vertices_count):
            location_x, location_y, location_z = packed_reader.getf('3f')
            normal_x, normal_y, normal_z = packed_reader.getf('3f')
            texture_coord_u, texture_coord_v = packed_reader.getf('2f')
            influences = packed_reader.getf('I')[0]
            visual.vertices.append((location_x, location_z, location_y))
            visual.uvs.append((texture_coord_u, 1 - texture_coord_v))
            visual.normals.append((normal_x, normal_z, normal_y))
    elif vertex_format == 0x240e3300:
        for vertex_index in range(vertices_count):
            bone_0 = packed_reader.getf('H')[0]
            bone_1 = packed_reader.getf('H')[0]
            location_x, location_y, location_z = packed_reader.getf('3f')
            normal_x, normal_y, normal_z = packed_reader.getf('3f')
            tangent_x, tangent_y, tangent_z = packed_reader.getf('3f')
            binormal_x, binormal_y, binormal_z = packed_reader.getf('3f')
            influences = packed_reader.getf('f')[0]
            texture_coord_u, texture_coord_v = packed_reader.getf('2f')
            visual.vertices.append((location_x, location_z, location_y))
            visual.uvs.append((texture_coord_u, 1 - texture_coord_v))
            visual.normals.append((normal_x, normal_z, normal_y))
    else:
        load_d3d7(visual, packed_reader, vertices_count, vertex_format)
Ejemplo n.º 6
0
def main(data, level):
    packed_reader = xray_io.PackedReader(data)
    format_version = packed_reader.getf('I')[0]
    if format_version == 4:
        cform_4(packed_reader, level)
    else:
        print('Unsupported cform version: {}'.format(format_version))
Ejemplo n.º 7
0
def read_glows(data):
    packed_reader = xray_io.PackedReader(data)
    glows_count = len(data) // GLOW_SIZE
    for glow_index in range(glows_count):
        center = packed_reader.getf('<3f')
        radius = packed_reader.getf('<f')[0]
        texture_index = packed_reader.getf('<I')[0]
        shader_index = packed_reader.getf('<I')[0]
Ejemplo n.º 8
0
def texture(data, visual):
    packed_reader = xray_io.PackedReader(data)

    texture = packed_reader.gets()
    shader = packed_reader.gets()

    visual.texture = texture
    visual.shader = shader
Ejemplo n.º 9
0
def _glows(data):
    packed_reader = xray_io.PackedReader(data)
    glows_count = len(data) // format_.GLOW_SIZE

    for glow_index in range(glows_count):
        position = packed_reader.getf('3f')
        radius = packed_reader.getf('f')[0]
        shader_index = packed_reader.getf('H')[0]
Ejemplo n.º 10
0
def treedef2(data, visual):
    packed_reader = xray_io.PackedReader(data)

    tree_xform = packed_reader.getf('16f')
    ogf_color(packed_reader)  # c_scale
    ogf_color(packed_reader)  # c_bias

    visual.tree_xform = tree_xform
Ejemplo n.º 11
0
def loddef2(data):
    packed_reader = xray_io.PackedReader(data)
    for i in range(8):
        for j in range(4):
            coord_x, coord_y, coord_z = packed_reader.getf('3f')
            coord_u, coord_v = packed_reader.getf('2f')
            hemi = packed_reader.getf('I')[0]
            sun = packed_reader.getf('B')[0]
            pad = packed_reader.getf('3B')
Ejemplo n.º 12
0
def read_portals(data):
    packed_reader = xray_io.PackedReader(data)
    portals_count = len(data) // PORTAL_SIZE
    for portal_index in range(portals_count):
        sector_front = packed_reader.getf('<H')[0]
        sector_back = packed_reader.getf('<H')[0]
        used_vertices_count = packed_reader.getf('<I')[0]
        for vertex_index in range(PORTAL_VERTICES_COUNT):
            vertex_coord = packed_reader.getf('<3f')
Ejemplo n.º 13
0
def indices_buffers(data, level, fastpath=False):
    packed_reader = xray_io.PackedReader(data)
    indices_buffers_count = packed_reader.getf('I')[0]
    for indices_buffer_index in range(indices_buffers_count):
        indices_count = packed_reader.getf('I')[0]
        indices_buffer = packed_reader.getf('{0}H'.format(indices_count))
        if not fastpath:
            level.indices_buffers.append(indices_buffer)
        else:
            level.fastpath.indices_buffers.append(indices_buffer)
Ejemplo n.º 14
0
def _glows(data, level):
    packed_reader = xray_io.PackedReader(data)
    glows_count = len(data) // format_.GLOW_SIZE

    for glow_index in range(glows_count):
        glow = types.Glow()
        glow.position = packed_reader.getf('3f')
        glow.radius = packed_reader.getf('f')[0]
        glow.shader_index = packed_reader.getf('H')[0]
        level.glows.append(glow)
Ejemplo n.º 15
0
def read_sector_occluders(data):
    data_size = len(data)
    if not data_size:
        return
    packed_reader = xray_io.PackedReader(data)
    occluders_count = data_size // OCCLUDER_SIZE
    for occluder_index in range(occluders_count):
        sector_index = packed_reader.getf('<H')[0]
        vertices_count = packed_reader.getf('<H')[0]
        for vertex_index in range(OCCLUDER_VERTICES_COUNT):
            vertex_coord = packed_reader.getf('<3I')
Ejemplo n.º 16
0
def s_motions(data, visual, bones):
    chunked_reader = xray_io.ChunkedReader(data)
    chunk_motion_count_data = chunked_reader.next(0)
    motion_count_packed_reader = xray_io.PackedReader(chunk_motion_count_data)
    motions_count = motion_count_packed_reader.getf('I')[0]
    motions = {}

    for chunk_id, chunk_data in chunked_reader:
        motion = read_motion(chunk_data, bones)
        motions[motion.name] = motion

    return motions
Ejemplo n.º 17
0
def _portals(data):
    packed_reader = xray_io.PackedReader(data)
    portals_count = len(data) // format_.PORTAL_SIZE

    for portal_index in range(portals_count):
        sector_front = packed_reader.getf('H')[0]
        sector_back = packed_reader.getf('H')[0]

        for vertex_index in range(format_.PORTAL_VERTEX_COUNT):
            coord_x, coord_y, coord_z = packed_reader.getf('fff')

        used_vertices_count = packed_reader.getf('I')[0]
Ejemplo n.º 18
0
def _shaders_v8(data, level):
    packed_reader = xray_io.PackedReader(data)
    shaders_count = packed_reader.getf('I')[0]

    for shader_index in range(shaders_count):
        raw_string = packed_reader.gets()
        shader = ShaderV8()
        if ',' in raw_string:
            shader.shader, shader.light_map = raw_string.split(',')
        else:
            shader.shader = raw_string
        level.shaders.append(shader)
Ejemplo n.º 19
0
def read_motion(data, bones):
    packed_reader = xray_io.PackedReader(data)
    motion = types.Motion()
    motion.name = packed_reader.gets()
    motion.length = packed_reader.getf('I')[0]

    for bone_name, _ in bones:
        bone_motion = types.BoneMotion()
        bone_motion.bone_name = bone_name
        read_bone_motion(packed_reader, motion, bone_motion)
        motion.bones_motion[bone_motion.bone_name] = bone_motion

    return motion
Ejemplo n.º 20
0
def indices_container(data, visual):
    packed_reader = xray_io.PackedReader(data)

    indices_buffer_index = packed_reader.getf('I')[0]
    indices_buffer_offset = packed_reader.getf('I')[0]
    indices_buffer_size = packed_reader.getf('I')[0]

    if not visual.gcontainer:
        visual.gcontainer = types.GeometryContainer()

    visual.gcontainer.ib_index = indices_buffer_index
    visual.gcontainer.ib_offset = indices_buffer_offset
    visual.gcontainer.ib_size = indices_buffer_size
Ejemplo n.º 21
0
def vcontainer(data, visual):
    if not visual.gcontainer:
        visual.gcontainer = types.GeometryContainer()

    packed_reader = xray_io.PackedReader(data)

    vb_index = packed_reader.getf('I')[0]
    vb_offset = packed_reader.getf('I')[0]
    vb_size = packed_reader.getf('I')[0]

    gcontainer = visual.gcontainer

    gcontainer.vb_index = vb_index
    gcontainer.vb_offset = vb_offset
    gcontainer.vb_size = vb_size
Ejemplo n.º 22
0
def read_lights(data):
    packed_reader = xray_io.PackedReader(data)
    lights_count = len(data) // LIGHT_SIZE
    for light_index in range(lights_count):
        read_light(packed_reader)
        dw_frame = packed_reader.getf('<I')[0]
        flags = packed_reader.getf('<H')[0]
        not_used = packed_reader.getf('<H')[0]
        for_light_maps = bool(flags & LightFlags.LMAPS)
        for_dynamic_models = bool(flags & LightFlags.MODELS)
        is_procedural = bool(flags & LightFlags.PROCEDURAL)
        current_time = packed_reader.getf('<f')[0]
        speed = packed_reader.getf('<f')[0]
        key_start = packed_reader.getf('<H')[0]
        key_count = packed_reader.getf('<H')[0]
Ejemplo n.º 23
0
def s_bone_names(data):
    packed_reader = xray_io.PackedReader(data)

    bones = []
    bones_count = packed_reader.getf('I')[0]

    for bone_index in range(bones_count):
        bone_name = packed_reader.gets()
        bone_parent = packed_reader.gets()

        obb(packed_reader)

        bones.append((bone_name, bone_parent))

    return bones
Ejemplo n.º 24
0
def desc(data, visual):
    packed_reader = xray_io.PackedReader(data)

    source = packed_reader.gets()

    export_tool = packed_reader.gets()
    export_time = packed_reader.getf('I')[0]

    owner_name = packed_reader.gets()
    creation_time = packed_reader.getf('I')[0]

    modif_name = packed_reader.gets()
    modified_time = packed_reader.getf('I')[0]

    visual.owner_name = owner_name
    visual.creation_time = creation_time
    visual.modif_name = modif_name
    visual.modified_time = modified_time
Ejemplo n.º 25
0
def _light_dynamic(data):
    packed_reader = xray_io.PackedReader(data)
    light_count = len(data) // format_.LIGHT_DYNAMIC_SIZE

    for light_index in range(light_count):
        controller_id = packed_reader.getf('I')[0]  # ???
        type = packed_reader.getf('I')[0]  # ???
        diffuse = packed_reader.getf('4f')
        specular = packed_reader.getf('4f')
        ambient = packed_reader.getf('4f')
        position = packed_reader.getf('3f')
        direction = packed_reader.getf('3f')
        range_ = packed_reader.getf('f')[0]
        falloff = packed_reader.getf('f')[0]
        attenuation_0 = packed_reader.getf('f')[0]
        attenuation_1 = packed_reader.getf('f')[0]
        attenuation_2 = packed_reader.getf('f')[0]
        theta = packed_reader.getf('f')[0]
        phi = packed_reader.getf('f')[0]
Ejemplo n.º 26
0
def read_cform(data):
    start_time = time.time()
    packed_reader = xray_io.PackedReader(data)
    version = packed_reader.getf('<I')[0]
    if version != CFORM_CURRENT_VERSION:
        raise Exception('Unsupported cform version: {}'.format(version))
    vertices_count = packed_reader.getf('<I')[0]
    triangles_count = packed_reader.getf('<I')[0]
    bounding_box = packed_reader.getf('<6f')
    for vertex_index in range(vertices_count):
        vertex_coord = packed_reader.getf('<3f')
    for triangle_index in range(triangles_count):
        vertex_indices = packed_reader.getf('<3I')
        adjacent_triangles = packed_reader.getf('<3I')
        material = packed_reader.getf('<H')[0]
        sector = packed_reader.getf('<H')[0]
        dummy = packed_reader.getf('<I')[0]
    end_time = time.time()
    print('cform time:', round(end_time - start_time, 4), 'sec')
Ejemplo n.º 27
0
def swidata(data, visual, fast_path=False):
    packed_reader = xray_io.PackedReader(data)
    swis = []
    reserved = packed_reader.getf('4I')
    swi_count = packed_reader.getf('I')[0]
    for swi_index in range(swi_count):
        offset = packed_reader.getf('I')[0]
        triangles_count = packed_reader.getf('H')[0]
        vertices_count = packed_reader.getf('H')[0]

        swidata = types.SlideWindowData()
        swidata.offset = offset
        swidata.triangles_count = triangles_count
        swidata.vertices_count = vertices_count
        swis.append(swidata)

    if not fast_path:
        visual.swidata = swis
    else:
        visual.fastpath.swidata = swis
Ejemplo n.º 28
0
def header(data, visual):
    packed_reader = xray_io.PackedReader(data)

    ogf_version = packed_reader.getf('B')[0]
    if ogf_version not in (3, 4):
        raise BaseException('Unsupported format version: {0}'.format(ogf_version))

    model_type = packed_reader.getf('B')[0]
    shader_id = packed_reader.getf('H')[0]
    if ogf_version == 4:
        bbox(packed_reader)
        bsphere(packed_reader)

    if format_.model_types.get(model_type, None):
        visual.type = format_.model_types[model_type]
    else:
        visual.type = 'UNKNOWN'
    visual.shader_id = shader_id

    return ogf_version
Ejemplo n.º 29
0
def read_vertex_buffers(data):
    start_time = time.time()
    packed_reader = xray_io.PackedReader(data)
    vertex_buffers_count = packed_reader.getf('<I')[0]
    FVF = Direct3DFlexibleVertexFormat
    cycle_code = 'for vertex_index in range(vertices_count):\n    '
    pos_code = "pos_x, poz_y, pos_z = packed_reader.getf('<3f')"
    norm_code = "norm_x, norm_y, norm_z = packed_reader.getf('<3f')"
    diffuse_code = "color_r, color_g, color_b, color_a = packed_reader.getf('<4B')"
    tex_uv_code = "tex_u, tex_v = packed_reader.getf('<2f')"
    lmap_uv_code = "lmap_u, lmap_v = packed_reader.getf('<2f')"
    uv_code = "coord_u, coord_v = packed_reader.getf('<2f')"
    for vertex_buffer_index in range(vertex_buffers_count):
        vertex_format = packed_reader.getf('<I')[0]
        vertices_count = packed_reader.getf('<I')[0]
        position_flags = vertex_format & FVF.POSITION_MASK
        tex_coord_count = (vertex_format & FVF.TEXCOUNT_MASK) >> FVF.TEXCOUNT_SHIFT
        code_list = []
        if position_flags == FVF.XYZ:
            code_list.append(pos_code)
        if vertex_format & FVF.NORMAL:
            code_list.append(norm_code)
        if vertex_format & FVF.DIFFUSE:
            code_list.append(diffuse_code)
        if tex_coord_count:
            if tex_coord_count == (FVF.TEX1 >> FVF.TEXCOUNT_SHIFT):
                code_list.append(tex_uv_code)
            elif tex_coord_count == (FVF.TEX2 >> FVF.TEXCOUNT_SHIFT):
                code_list.append(tex_uv_code)
                code_list.append(lmap_uv_code)
            else:
                print('\n    UV Warrning!\n')
                code_list.append(tex_uv_code)
                code_list.append(lmap_uv_code)
                for coord_index in range(2, tex_coord_count):
                    code_list.append(uv_code)
        vertex_code = '\n    '.join(code_list)
        vertices_code = cycle_code + vertex_code
        exec(vertices_code)
    end_time = time.time()
    print('vb time:', round(end_time - start_time, 4), 'sec')
Ejemplo n.º 30
0
def s_smparams(data, visual):
    packed_reader = xray_io.PackedReader(data)

    params_version = packed_reader.getf('H')[0]
    partition_count = packed_reader.getf('H')[0]

    for partition_index in range(partition_count):
        partition_name = packed_reader.gets()
        bone_count = packed_reader.getf('H')[0]

        partition = visual.Partition(partition_name)

        for bone in range(bone_count):
            if params_version == 1:
                bone_id = packed_reader.getf('I')[0]
                partition.bones_indices.append(bone_id)
            elif params_version == 2:
                bone_name = packed_reader.gets()
                partition.bones_names.append(bone_name)
            elif params_version == 3 or params_version == 4:
                bone_name = packed_reader.gets()
                bone_id = packed_reader.getf('I')[0]
                partition.bones_names.append(bone_name)
                partition.bones_indices.append(bone_id)
            else:
                raise BaseException('Unknown params version')

        visual.partitions.append(partition)

    motion_count = packed_reader.getf('H')[0]

    for motion_index in range(motion_count):
        motion_name = packed_reader.gets()
        motion_flags = packed_reader.getf('I')[0]

        motion_def(packed_reader)

        if params_version == 4:
            num_marks = packed_reader.getf('I')[0]
            for mark_index in range(num_marks):
                motion_mark(packed_reader)