Beispiel #1
0
def _fill_channel_sections(data_list, channel_type="BoneChannel"):
    """Fills up Channel sections."""
    sections = []
    for item_i, item in enumerate(data_list):
        section = _SectionData(channel_type)
        section.props.append(("Name", item[0]))
        section.props.append(("StreamCount", len(item[1])))
        section.props.append(("KeyframeCount", len(item[1][0][1])))
        for stream in item[1]:
            # print(' stream[0]: %s\n stream[1]: %s' % (str(stream[0]), str(stream[1])))
            section.sections.append(_pix_container.make_stream_section(stream[1], stream[0], ()))
        sections.append(section)
    return sections
Beispiel #2
0
def _fill_channel_sections(data_list, channel_type="BoneChannel"):
    """Fills up Channel sections."""
    sections = []
    for item_i, item in enumerate(data_list):
        section = _SectionData(channel_type)
        section.props.append(("Name", item[0]))
        section.props.append(("StreamCount", len(item[1])))
        section.props.append(("KeyframeCount", len(item[1][0][1])))
        for stream in item[1]:
            # print(' stream[0]: %s\n stream[1]: %s' % (str(stream[0]), str(stream[1])))
            section.sections.append(_pix_container.make_stream_section(stream[1], stream[0], ()))
        sections.append(section)
    return sections
Beispiel #3
0
def _fill_piece_sections(convex_coll_locators, export_scale):
    """Fills up "Piece" sections for convex colliders."""

    len_vertices = 0
    len_faces = 0
    piece_sections = []
    index = 0
    for item in convex_coll_locators:
        stream_cnt = 0
        verts = item.scs_props.get("coll_convex_verts", 0)
        faces = item.scs_props.get("coll_convex_faces", 0)
        if verts:
            stream_cnt += 1

        len_vertices += len(verts)
        len_faces += len(faces)

        section = _SectionData("Piece")
        section.props.append(("Index", index))
        section.props.append(("Material", 0))
        section.props.append(("VertexCount", len(verts)))
        section.props.append(("TriangleCount", len(faces)))
        section.props.append(("StreamCount", stream_cnt))
        section.props.append(("", ""))

        # VERTICES
        if verts:
            vector_verts = []
            for vert in verts:
                # scs_position = Matrix.Scale(scs_globals.export_scale, 4) * io_utils.scs_to_blend_matrix().inverted() * mat_world * position ##
                # POSITION
                scs_position = Matrix.Scale(
                    export_scale, 4) * _convert_utils.scs_to_blend_matrix(
                    ).inverted() * Vector(vert)  # POSITION
                vector_verts.append(Vector(scs_position))
            section.sections.append(
                _pix_container.make_stream_section(vector_verts, "_POSITION",
                                                   ()))

        # FACES (TRIANGLES)
        if faces:
            # FACE FLIPPING
            flipped_faces = _mesh_utils.flip_faceverts(faces)
            section.sections.append(
                _pix_container.make_triangle_stream(flipped_faces))

        index += 1
        piece_sections.append(section)
    return len_vertices, len_faces, piece_sections
Beispiel #4
0
def _fill_piece_sections(convex_coll_locators, export_scale):
    """Fills up "Piece" sections for convex colliders."""

    len_vertices = 0
    len_faces = 0
    piece_sections = []
    index = 0
    for item in convex_coll_locators:
        stream_cnt = 0
        verts = item.scs_props.get("coll_convex_verts", 0)
        faces = item.scs_props.get("coll_convex_faces", 0)
        if verts:
            stream_cnt += 1

        len_vertices += len(verts)
        len_faces += len(faces)

        section = _SectionData("Piece")
        section.props.append(("Index", index))
        section.props.append(("Material", 0))
        section.props.append(("VertexCount", len(verts)))
        section.props.append(("TriangleCount", len(faces)))
        section.props.append(("StreamCount", stream_cnt))
        section.props.append(("", ""))

        # VERTICES
        if verts:
            vector_verts = []
            for vert in verts:
                # scs_position = Matrix.Scale(scs_globals.export_scale, 4) * io_utils.scs_to_blend_matrix().inverted() * mat_world * position ##
                # POSITION
                scs_position = Matrix.Scale(export_scale, 4) * _convert_utils.scs_to_blend_matrix().inverted() * Vector(vert)  # POSITION
                vector_verts.append(Vector(scs_position))
            section.sections.append(_pix_container.make_stream_section(vector_verts, "_POSITION", ()))

        # FACES (TRIANGLES)
        if faces:
            # FACE FLIPPING
            flipped_faces = _mesh_utils.flip_faceverts(faces)
            section.sections.append(_pix_container.make_triangle_stream(flipped_faces))

        index += 1
        piece_sections.append(section)
    return len_vertices, len_faces, piece_sections
Beispiel #5
0
def _fill_piece_sections_5(root_object, object_list, bone_list, scene,
                           used_materials, offset_matrix, scs_globals):
    """Fills up "Piece" sections for file version 5.

    :param root_object: SCS Root Object
    :type root_object: bpy.types.Object
    :param object_list: Object for export
    :type object_list: list of Objects
    :param bone_list: Bones for export
    :type bone_list: list
    :param scene: Blender Scene to operate on
    :type scene: bpy.types.Scene
    :param used_materials: All Materials used in 'SCS Game Object'
    :type used_materials: list
    :param offset_matrix: Matrix for specifying of pivot point
    :type offset_matrix: Matrix
    :param scs_globals: SCS Tools Globals
    :type scs_globals: GlobalSCSProps
    :return: list of parameters
    :rtype: list
    """

    handle_unused_arg(__file__, _fill_piece_sections_5.__name__,
                      "used_materials", used_materials)

    apply_modifiers = scs_globals.apply_modifiers
    exclude_edgesplit = scs_globals.exclude_edgesplit
    include_edgesplit = scs_globals.include_edgesplit
    piece_sections = []
    piece_index_obj = {}
    piece_index = global_vertex_count = global_face_count = 0

    # ----- START: SOLVE THIS!
    skin_list = []
    skin_weights_cnt = skin_clones_cnt = 0
    # -----   END: SOLVE THIS!

    print_info = False

    if print_info:
        print('used_materials: %s\n' % str(used_materials))
        print('object_list: %s\n' % str(object_list))

    # For each object...
    for obj_i, obj in enumerate(object_list):
        piece_index_obj[obj_i] = obj
        # Get all Materials from Object as they're set in material slots...
        object_materials = _object_utils.get_object_materials(obj)
        if print_info:
            print('  object_materials: %s' % str(object_materials))

        # Make Material dictionary (needed for getting rid of Material duplicities)...
        material_dict = _make_material_dict(object_materials)
        if print_info:
            for item in material_dict:
                print('    "%s" = %s' % (str(item), str(material_dict[item])))
            print('')

        # Get Object's Mesh data and list of temporarily disabled "Edge Split" Modifiers...
        mesh = _object_utils.get_mesh(obj)

        # SORT GEOMETRY
        piece_dict, skin_list, skin_weights_cnt, skin_clones_cnt = _get_geometry_dict(
            root_object, obj, mesh, offset_matrix, material_dict,
            used_materials, bone_list, scs_globals)

        # DUMP
        if 0:
            for piece in piece_dict:
                print('Pm: %r' % piece)
                for data in piece_dict[piece]:
                    print('  Da: %r' % str(data))
                    if data == 'hash_dict':
                        if len(piece_dict[piece][data]) > 0:
                            for val in piece_dict[piece][data]:
                                print('    HD: %s:%s' %
                                      (str(val),
                                       str(piece_dict[piece][data][val])))
                        else:
                            print('    NO "hash_dict" Data!')
                    elif data == 'verts':
                        if len(piece_dict[piece][data]) > 0:
                            for val in piece_dict[piece][data]:
                                print('    Ve: %s' % str(val))
                        else:
                            print('    NO "verts" Data!')
                    elif data == 'faces':
                        if len(piece_dict[piece][data]) > 0:
                            for val in piece_dict[piece][data]:
                                print('    Fa: %s' % str(val))
                        else:
                            print('    NO "faces" Data!')
                print('')
            print('')

        # CREATE SECTIONS
        for piece in piece_dict:
            vertex_count = len(piece_dict[piece]['verts'])
            global_vertex_count += vertex_count
            face_count = len(piece_dict[piece]['faces'])
            global_face_count += face_count
            stream_sections = []

            # VERTEX STREAMS
            verts_data = {}
            for val in piece_dict[piece]['verts']:
                facevert_common_data, facevert_unique_data = val
                for data_key in facevert_common_data:
                    # print(' data_key: %s' % str(data_key))
                    if data_key == '_VG':
                        pass
                    else:
                        if data_key not in verts_data:
                            verts_data[data_key] = []
                        verts_data[data_key].append(
                            facevert_common_data[data_key])
                for data_key in facevert_unique_data:
                    # print(' data_key: %s' % str(data_key))
                    if data_key == '_UV':
                        for layer_i, layer in enumerate(
                                facevert_unique_data[data_key]):
                            layer_data_key = str(data_key + str(layer_i))
                            if layer_data_key not in verts_data:
                                verts_data[layer_data_key] = []
                            verts_data[layer_data_key].append(
                                facevert_unique_data[data_key][layer])
                    if data_key == '_RGBA':
                        for layer_i, layer in enumerate(
                                facevert_unique_data[data_key]):
                            if len(facevert_unique_data[data_key]) > 1:
                                layer_data_key = str(data_key + str(layer_i))
                            else:
                                layer_data_key = data_key
                            if layer_data_key not in verts_data:
                                verts_data[layer_data_key] = []
                            verts_data[layer_data_key].append(
                                facevert_unique_data[data_key][layer])
            lprint('S verts_data: %s', (str(verts_data), ))

            data_types = ('_POSITION', '_NORMAL', '_UV', '_UV0', '_UV1',
                          '_UV2', '_UV3', '_UV4', '_UV5', '_UV6', '_UV7',
                          '_UV8', '_UV9', '_RGBA', '_RGBA0', '_RGBA1',
                          '_RGBA2', '_RGBA3', '_RGBA4', '_RGBA5', '_RGBA6',
                          '_RGBA7', '_RGBA8', '_RGBA9', '_VG')
            add_uv = True
            add_rgba = False
            for data_type in data_types:
                if '_RGBA' not in verts_data:
                    add_rgba = True
                if data_type in verts_data:
                    if data_type.startswith('_UV'):
                        add_uv = False
                        stream_sections.append(
                            _pix_container.make_stream_section(
                                verts_data[data_type], data_type,
                                (data_type, )))
                    else:
                        stream_sections.append(
                            _pix_container.make_stream_section(
                                verts_data[data_type], data_type, ()))

            # ADD DEFAULT UV LAYER
            if add_uv:
                lprint('I Adding default UV layer.')
                uv_dummy_data = []
                for vert in range(len(piece_dict[piece]['verts'])):
                    uv_dummy_data.append(Vector((0.0, 0.0)))
                stream_sections.append(
                    _pix_container.make_stream_section(uv_dummy_data, '_UV0',
                                                       ('_UV0', )))

            # ADD DEFAULT RGBA LAYER
            if add_rgba:
                lprint('I Adding default RGBA (vertex color) layer.')
                rgba_dummy_data = []
                for vert in range(len(piece_dict[piece]['verts'])):
                    rgba_dummy_data.append(Vector((1.0, 1.0, 1.0, 1.0)))
                stream_sections.append(
                    _pix_container.make_stream_section(rgba_dummy_data,
                                                       '_RGBA', ()))

            # PIECE PROPERTIES
            piece_section = _SectionData("Piece")
            piece_section.props.append(("Index", piece_index))
            piece_section.props.append(
                ("Material", piece_dict[piece]['material_index']))
            piece_section.props.append(("VertexCount", vertex_count))
            piece_section.props.append(("TriangleCount", face_count))
            piece_section.props.append(("StreamCount", len(stream_sections)))
            piece_section.props.append(("", ""))
            piece_index += 1
            for stream_section in stream_sections:
                piece_section.sections.append(stream_section)

            # FACE STREAM
            stream_section = _SectionData("Triangles")
            stream_section.data = piece_dict[piece]['faces']
            piece_section.sections.append(stream_section)

            piece_sections.append(piece_section)

    return piece_sections, global_vertex_count, global_face_count, piece_index_obj, skin_list, skin_weights_cnt, skin_clones_cnt
Beispiel #6
0
def _fill_piece_sections_5(root_object, object_list, bone_list, scene, used_materials, offset_matrix, scs_globals):
    """Fills up "Piece" sections for file version 5.

    :param root_object: SCS Root Object
    :type root_object: bpy.types.Object
    :param object_list: Object for export
    :type object_list: list of Objects
    :param bone_list: Bones for export
    :type bone_list: list
    :param scene: Blender Scene to operate on
    :type scene: bpy.types.Scene
    :param used_materials: All Materials used in 'SCS Game Object'
    :type used_materials: list
    :param offset_matrix: Matrix for specifying of pivot point
    :type offset_matrix: Matrix
    :param scs_globals: SCS Tools Globals
    :type scs_globals: GlobalSCSProps
    :return: list of parameters
    :rtype: list
    """

    handle_unused_arg(__file__, _fill_piece_sections_5.__name__, "used_materials", used_materials)

    apply_modifiers = scs_globals.apply_modifiers
    exclude_edgesplit = scs_globals.exclude_edgesplit
    include_edgesplit = scs_globals.include_edgesplit
    piece_sections = []
    piece_index_obj = {}
    piece_index = global_vertex_count = global_face_count = 0

    # ----- START: SOLVE THIS!
    skin_list = []
    skin_weights_cnt = skin_clones_cnt = 0
    # -----   END: SOLVE THIS!

    print_info = False

    if print_info:
        print('used_materials: %s\n' % str(used_materials))
        print('object_list: %s\n' % str(object_list))

    # For each object...
    for obj_i, obj in enumerate(object_list):
        piece_index_obj[obj_i] = obj
        # Get all Materials from Object as they're set in material slots...
        object_materials = _object_utils.get_object_materials(obj)
        if print_info:
            print('  object_materials: %s' % str(object_materials))

        # Make Material dictionary (needed for getting rid of Material duplicities)...
        material_dict = _make_material_dict(object_materials)
        if print_info:
            for item in material_dict:
                print('    "%s" = %s' % (str(item), str(material_dict[item])))
            print('')

        # Get Object's Mesh data and list of temporarily disabled "Edge Split" Modifiers...
        mesh = _object_utils.get_mesh(obj)

        # SORT GEOMETRY
        piece_dict, skin_list, skin_weights_cnt, skin_clones_cnt = _get_geometry_dict(root_object,
                                                                                      obj,
                                                                                      mesh,
                                                                                      offset_matrix,
                                                                                      material_dict,
                                                                                      used_materials,
                                                                                      bone_list,
                                                                                      scs_globals)

        # DUMP
        if 0:
            for piece in piece_dict:
                print('Pm: %r' % piece)
                for data in piece_dict[piece]:
                    print('  Da: %r' % str(data))
                    if data == 'hash_dict':
                        if len(piece_dict[piece][data]) > 0:
                            for val in piece_dict[piece][data]:
                                print('    HD: %s:%s' % (str(val), str(piece_dict[piece][data][val])))
                        else:
                            print('    NO "hash_dict" Data!')
                    elif data == 'verts':
                        if len(piece_dict[piece][data]) > 0:
                            for val in piece_dict[piece][data]:
                                print('    Ve: %s' % str(val))
                        else:
                            print('    NO "verts" Data!')
                    elif data == 'faces':
                        if len(piece_dict[piece][data]) > 0:
                            for val in piece_dict[piece][data]:
                                print('    Fa: %s' % str(val))
                        else:
                            print('    NO "faces" Data!')
                print('')
            print('')

        # CREATE SECTIONS
        for piece in piece_dict:
            vertex_count = len(piece_dict[piece]['verts'])
            global_vertex_count += vertex_count
            face_count = len(piece_dict[piece]['faces'])
            global_face_count += face_count
            stream_sections = []

            # VERTEX STREAMS
            verts_data = {}
            for val in piece_dict[piece]['verts']:
                facevert_common_data, facevert_unique_data = val
                for data_key in facevert_common_data:
                    # print(' data_key: %s' % str(data_key))
                    if data_key == '_VG':
                        pass
                    else:
                        if data_key not in verts_data:
                            verts_data[data_key] = []
                        verts_data[data_key].append(facevert_common_data[data_key])
                for data_key in facevert_unique_data:
                    # print(' data_key: %s' % str(data_key))
                    if data_key == '_UV':
                        for layer_i, layer in enumerate(facevert_unique_data[data_key]):
                            layer_data_key = str(data_key + str(layer_i))
                            if layer_data_key not in verts_data:
                                verts_data[layer_data_key] = []
                            verts_data[layer_data_key].append(facevert_unique_data[data_key][layer])
                    if data_key == '_RGBA':
                        for layer_i, layer in enumerate(facevert_unique_data[data_key]):
                            if len(facevert_unique_data[data_key]) > 1:
                                layer_data_key = str(data_key + str(layer_i))
                            else:
                                layer_data_key = data_key
                            if layer_data_key not in verts_data:
                                verts_data[layer_data_key] = []
                            verts_data[layer_data_key].append(facevert_unique_data[data_key][layer])
            lprint('S verts_data: %s', (str(verts_data),))

            data_types = (
                '_POSITION', '_NORMAL', '_UV', '_UV0', '_UV1', '_UV2', '_UV3', '_UV4', '_UV5', '_UV6', '_UV7', '_UV8', '_UV9', '_RGBA', '_RGBA0',
                '_RGBA1', '_RGBA2', '_RGBA3', '_RGBA4', '_RGBA5', '_RGBA6', '_RGBA7', '_RGBA8', '_RGBA9', '_VG')
            add_uv = True
            add_rgba = False
            for data_type in data_types:
                if '_RGBA' not in verts_data:
                    add_rgba = True
                if data_type in verts_data:
                    if data_type.startswith('_UV'):
                        add_uv = False
                        stream_sections.append(_pix_container.make_stream_section(verts_data[data_type], data_type, (data_type,)))
                    else:
                        stream_sections.append(_pix_container.make_stream_section(verts_data[data_type], data_type, ()))

            # ADD DEFAULT UV LAYER
            if add_uv:
                lprint('I Adding default UV layer.')
                uv_dummy_data = []
                for vert in range(len(piece_dict[piece]['verts'])):
                    uv_dummy_data.append(Vector((0.0, 0.0)))
                stream_sections.append(_pix_container.make_stream_section(uv_dummy_data, '_UV0', ('_UV0',)))

            # ADD DEFAULT RGBA LAYER
            if add_rgba:
                lprint('I Adding default RGBA (vertex color) layer.')
                rgba_dummy_data = []
                for vert in range(len(piece_dict[piece]['verts'])):
                    rgba_dummy_data.append(Vector((1.0, 1.0, 1.0, 1.0)))
                stream_sections.append(_pix_container.make_stream_section(rgba_dummy_data, '_RGBA', ()))

            # PIECE PROPERTIES
            piece_section = _SectionData("Piece")
            piece_section.props.append(("Index", piece_index))
            piece_section.props.append(("Material", piece_dict[piece]['material_index']))
            piece_section.props.append(("VertexCount", vertex_count))
            piece_section.props.append(("TriangleCount", face_count))
            piece_section.props.append(("StreamCount", len(stream_sections)))
            piece_section.props.append(("", ""))
            piece_index += 1
            for stream_section in stream_sections:
                piece_section.sections.append(stream_section)

            # FACE STREAM
            stream_section = _SectionData("Triangles")
            stream_section.data = piece_dict[piece]['faces']
            piece_section.sections.append(stream_section)

            piece_sections.append(piece_section)

    return piece_sections, global_vertex_count, global_face_count, piece_index_obj, skin_list, skin_weights_cnt, skin_clones_cnt