Example #1
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
Example #2
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
Example #3
0
def load(filepath):
    scs_globals = _get_scs_globals()

    print("\n************************************")
    print("**      SCS PIC Importer          **")
    print("**      (c)2014 SCS Software      **")
    print("************************************\n")

    ind = '    '
    pic_container = _pix_container.get_data_from_file(filepath, ind)

    # TEST PRINTOUTS
    # ind = '  '
    # for section in pic_container:
    # print('SEC.: "%s"' % section.type)
    # for prop in section.props:
    # print('%sProp: %s' % (ind, prop))
    # for data in section.data:
    # print('%sdata: %s' % (ind, data))
    # for sec in section.sections:
    # print_section(sec, ind)
    # print('\nTEST - Source: "%s"' % pic_container[0].props[1][1])
    # print('')

    # TEST EXPORT
    # path, file = os.path.splitext(filepath)
    # export_filepath = str(path + '_reex' + file)
    # result = pix_write.write_data(pic_container, export_filepath, ind)
    # if result == {'FINISHED'}:
    # Print(dump_level, '\nI Test export succesful! The new file:\n  "%s"', export_filepath)
    # else:
    # Print(dump_level, '\nE Test export failed! File:\n  "%s"', export_filepath)

    # LOAD HEADER
    '''
    NOTE: skipped for now as no data needs to be readed
    format_version, source, f_type, f_name, source_filename, author = _get_header(pic_container)
    '''

    # LOAD GLOBALS
    '''
    NOTE: skipped for now as no data needs to be readed
    vertex_count, triangle_count, material_count, piece_count, part_count, locator_count = _get_global(pic_container)
    '''

    # LOAD MATERIALS
    if 0:  # NOTE: NO MATERIALS USED FOR COLLIDERS AT A MOMENT!
        loaded_materials = []
        for section in pic_container:
            if section.type == 'Material':
                material_alias, material_effect = _get_material(section)
                lprint('I Adding a Material Alias: "%s"', material_alias)
                loaded_materials.append(material_alias)

                # PRINT "MATERIAL SETTINGS" TO CONSOLE...
                if 0:
                    import pprint

                    pp = pprint.PrettyPrinter(indent=1)
                    print("===  MATERIAL SETTINGS  ==========================")
                    pp.pprint(material_effect)
                    print("==================================================")

    # LOAD PARTS
    parts = []
    for section in pic_container:
        if section.type == "Part":
            (name, pieces, locators) = _get_part(section)
            parts.append({
                "name": name,
                "pieces": pieces,
                "locators": locators
            })

    # LOAD (CONVEX) PIECES
    pieces = []
    for section in pic_container:
        if section.type == 'Piece':
            pieces.append(_get_piece(section))

    # LOAD AND CREATE LOCATORS
    import_scale = scs_globals.import_scale
    locators = []
    for section in pic_container:
        if section.type == 'Locator':
            (locator_name, locator_index, locator_position, locator_rotation,
             locator_alias, locator_weight, locator_type, locator_parameters,
             locator_convex_piece) = _get_locator(section)
            lprint('I Adding a Locator: "%s"', locator_name)
            locator = _object_utils.create_locator_empty(
                locator_name, locator_position, locator_rotation, (1, 1, 1),
                1.0, 'Collision')
            locator.scs_props.scs_part = _get_locator_part(
                parts, locator_index)
            locator.scs_props.locator_collider_centered = True
            locator.scs_props.locator_collider_mass = locator_weight
            locator.scs_props.locator_collider_type = locator_type
            if locator_type == 'Box':
                locator.scs_props.locator_collider_box_x = locator_parameters[
                    0] * import_scale
                locator.scs_props.locator_collider_box_y = locator_parameters[
                    2] * import_scale
                locator.scs_props.locator_collider_box_z = locator_parameters[
                    1] * import_scale
            elif locator_type in ('Sphere', 'Capsule', 'Cylinder'):
                locator.scs_props.locator_collider_dia = locator_parameters[
                    0] * 2 * import_scale
                locator.scs_props.locator_collider_len = locator_parameters[
                    1] * import_scale
            elif locator_type == 'Convex':
                piece_index, piece_material, verts, faces = pieces[
                    locator_convex_piece]
                if verts and faces:

                    # BOUNDING BOX DATA CREATION AND SPACE CONVERSION
                    min_val = [None, None, None]
                    max_val = [None, None, None]
                    scs_verts = []
                    for vert in verts:
                        scs_vert = _convert_utils.change_to_scs_xyz_coordinates(
                            vert, import_scale)
                        scs_verts.append(scs_vert)
                        min_val, max_val = _math_utils.evaluate_minmax(
                            scs_vert, min_val, max_val)
                    bbox, bbcenter = _math_utils.get_bb(min_val, max_val)

                    # FACE FLIPPING
                    flipped_faces = _mesh_utils.flip_faceverts(faces)

                    # COLLIDER CREATION
                    geom_data = (scs_verts, flipped_faces, bbox, bbcenter)
                    _object_utils.add_collider_convex_locator(
                        geom_data, {}, locator)

            locators.append(locator)

            # DATA BUILDING

            # WARNING PRINTOUTS
    # if piece_count < 0: Print(dump_level, '\nW More Pieces found than were declared!')
    # if piece_count > 0: Print(dump_level, '\nW Some Pieces not found, but were declared!')
    # if dump_level > 1: print('')

    print("************************************")
    return {'FINISHED'}, locators
Example #4
0
def load(filepath):
    scs_globals = _get_scs_globals()

    print("\n************************************")
    print("**      SCS PIC Importer          **")
    print("**      (c)2014 SCS Software      **")
    print("************************************\n")

    ind = '    '
    pic_container = _pix_container.get_data_from_file(filepath, ind)

    # TEST PRINTOUTS
    # ind = '  '
    # for section in pic_container:
    # print('SEC.: "%s"' % section.type)
    # for prop in section.props:
    # print('%sProp: %s' % (ind, prop))
    # for data in section.data:
    # print('%sdata: %s' % (ind, data))
    # for sec in section.sections:
    # print_section(sec, ind)
    # print('\nTEST - Source: "%s"' % pic_container[0].props[1][1])
    # print('')

    # TEST EXPORT
    # path, file = os.path.splitext(filepath)
    # export_filepath = str(path + '_reex' + file)
    # result = pix_write.write_data(pic_container, export_filepath, ind)
    # if result == {'FINISHED'}:
    # Print(dump_level, '\nI Test export succesful! The new file:\n  "%s"', export_filepath)
    # else:
    # Print(dump_level, '\nE Test export failed! File:\n  "%s"', export_filepath)

    # LOAD HEADER
    '''
    NOTE: skipped for now as no data needs to be readed
    format_version, source, f_type, f_name, source_filename, author = _get_header(pic_container)
    '''

    # LOAD GLOBALS
    '''
    NOTE: skipped for now as no data needs to be readed
    vertex_count, triangle_count, material_count, piece_count, part_count, locator_count = _get_global(pic_container)
    '''

    # LOAD MATERIALS
    if 0:  # NOTE: NO MATERIALS USED FOR COLLIDERS AT A MOMENT!
        loaded_materials = []
        for section in pic_container:
            if section.type == 'Material':
                material_alias, material_effect = _get_material(section)
                lprint('I Adding a Material Alias: "%s"', material_alias)
                loaded_materials.append(material_alias)

                # PRINT "MATERIAL SETTINGS" TO CONSOLE...
                if 0:
                    import pprint

                    pp = pprint.PrettyPrinter(indent=1)
                    print("===  MATERIAL SETTINGS  ==========================")
                    pp.pprint(material_effect)
                    print("==================================================")

    # LOAD PARTS
    parts = []
    for section in pic_container:
        if section.type == "Part":
            (name, pieces, locators) = _get_part(section)
            parts.append({"name": name, "pieces": pieces, "locators": locators})

    # LOAD (CONVEX) PIECES
    pieces = []
    for section in pic_container:
        if section.type == 'Piece':
            pieces.append(_get_piece(section))

    # LOAD AND CREATE LOCATORS
    import_scale = scs_globals.import_scale
    locators = []
    for section in pic_container:
        if section.type == 'Locator':
            (locator_name,
             locator_index,
             locator_position,
             locator_rotation,
             locator_alias,
             locator_weight,
             locator_type,
             locator_parameters,
             locator_convex_piece) = _get_locator(section)
            lprint('I Adding a Locator: "%s"', locator_name)
            locator = _object_utils.create_locator_empty(locator_name, locator_position, locator_rotation, (1, 1, 1), 1.0, 'Collision')
            locator.scs_props.scs_part = _get_locator_part(parts, locator_index)
            locator.scs_props.locator_collider_centered = True
            locator.scs_props.locator_collider_mass = locator_weight
            locator.scs_props.locator_collider_type = locator_type
            if locator_type == 'Box':
                locator.scs_props.locator_collider_box_x = locator_parameters[0] * import_scale
                locator.scs_props.locator_collider_box_y = locator_parameters[2] * import_scale
                locator.scs_props.locator_collider_box_z = locator_parameters[1] * import_scale
            elif locator_type in ('Sphere', 'Capsule', 'Cylinder'):
                locator.scs_props.locator_collider_dia = locator_parameters[0] * 2 * import_scale
                locator.scs_props.locator_collider_len = locator_parameters[1] * import_scale
            elif locator_type == 'Convex':
                piece_index, piece_material, verts, faces = pieces[locator_convex_piece]
                if verts and faces:

                    # BOUNDING BOX DATA CREATION AND SPACE CONVERSION
                    min_val = [None, None, None]
                    max_val = [None, None, None]
                    scs_verts = []
                    for vert in verts:
                        scs_vert = _convert_utils.change_to_scs_xyz_coordinates(vert, import_scale)
                        scs_verts.append(scs_vert)
                        min_val, max_val = _math_utils.evaluate_minmax(scs_vert, min_val, max_val)
                    bbox, bbcenter = _math_utils.get_bb(min_val, max_val)

                    # FACE FLIPPING
                    flipped_faces = _mesh_utils.flip_faceverts(faces)

                    # COLLIDER CREATION
                    geom_data = (scs_verts, flipped_faces, bbox, bbcenter)
                    _object_utils.add_collider_convex_locator(geom_data, {}, locator)

            locators.append(locator)

            # DATA BUILDING

            # WARNING PRINTOUTS
    # if piece_count < 0: Print(dump_level, '\nW More Pieces found than were declared!')
    # if piece_count > 0: Print(dump_level, '\nW Some Pieces not found, but were declared!')
    # if dump_level > 1: print('')

    print("************************************")
    return {'FINISHED'}, locators