Пример #1
0
def draw_custom_2d_elements():
    context = bpy.context
    scs_globals = _get_scs_globals()

    font_id = 0  # TODO: Need to find out how best to get this.
    blf.size(font_id, 12, 72)

    region = context.region

    # draw 3d view import/export reports
    _draw_3dview_report(region)

    (prefab_locators, collision_locators,
     model_locators) = _get_custom_visual_elements()

    if not prefab_locators and not collision_locators and not model_locators:
        return

    glColor3f(
        scs_globals.info_text_color[0],
        scs_globals.info_text_color[1],
        scs_globals.info_text_color[2],
    )

    region3d = context.space_data.region_3d

    region_mid_width = region.width / 2.0
    region_mid_height = region.height / 2.0

    # VARS FOR PROJECTION
    perspective_matrix = region3d.perspective_matrix.copy()

    region_data = (perspective_matrix, region_mid_width, region_mid_height)

    # LOCATOR NAMES
    if scs_globals.display_info == 'locnames':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])),
                                     region_data)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])),
                                     region_data)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])),
                                     region_data)

    # LOCATOR COMPREHENSIVE INFO
    elif scs_globals.display_info == 'locinfo':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                textlines = [
                    '"' + key + '"',
                    str(obj.scs_props.locator_type + " - " +
                        obj.scs_props.locator_prefab_type)
                ]

                if obj.scs_props.locator_prefab_type == 'Control Node':

                    textlines.append(
                        str("Node Index: " +
                            str(obj.scs_props.locator_prefab_con_node_index)))

                elif obj.scs_props.locator_prefab_type == 'Spawn Point':

                    spawn_type_i = int(obj.scs_props.locator_prefab_spawn_type)
                    textlines.append(
                        str("Type: " +
                            obj.scs_props.enum_spawn_type_items[spawn_type_i]
                            [1]))

                elif obj.scs_props.locator_prefab_type == 'Traffic Semaphore':

                    textlines.append(
                        str("ID: " +
                            str(obj.scs_props.locator_prefab_tsem_id)))
                    if obj.scs_props.locator_prefab_tsem_profile != '':
                        textlines.append(
                            str("Profile: " +
                                str(obj.scs_props.locator_prefab_tsem_profile))
                        )
                    tsem_type_i = int(obj.scs_props.locator_prefab_tsem_type)
                    if tsem_type_i != _PL_consts.TST.PROFILE:
                        textlines.append(
                            str("Type: " +
                                obj.scs_props.enum_tsem_type_items[tsem_type_i]
                                [1]))
                        textlines.append(
                            str("G: %.2f" %
                                obj.scs_props.locator_prefab_tsem_gs +
                                " - O: %.2f" %
                                obj.scs_props.locator_prefab_tsem_os1 +
                                " - R: %.2f" %
                                obj.scs_props.locator_prefab_tsem_rs +
                                " - O: %.2f" %
                                obj.scs_props.locator_prefab_tsem_os2))
                        if obj.scs_props.locator_prefab_tsem_cyc_delay != 0:
                            textlines.append(
                                str("Cycle Delay: " + "%.2f s" %
                                    obj.scs_props.locator_prefab_tsem_cyc_delay
                                    ))

                elif obj.scs_props.locator_prefab_type == 'Navigation Point':

                    np_boundary_i = int(
                        obj.scs_props.locator_prefab_np_boundary)
                    if np_boundary_i != 0:
                        textlines.append(
                            str("Boundary: " + obj.scs_props.
                                enum_np_boundary_items[np_boundary_i][1]))

                    textlines.append(
                        str("B. Node: " +
                            str(obj.scs_props.locator_prefab_np_boundary_node))
                    )
                    if obj.scs_props.locator_prefab_np_traffic_semaphore != '-1':
                        textlines.append(
                            str("T. Light ID: " +
                                str(obj.scs_props.
                                    locator_prefab_np_traffic_semaphore)))

                elif obj.scs_props.locator_prefab_type == 'Map Point':

                    if obj.scs_props.locator_prefab_mp_road_over:
                        textlines.append("Road Over: YES")
                    if obj.scs_props.locator_prefab_mp_no_outline:
                        textlines.append("No Outline: YES")
                    if obj.scs_props.locator_prefab_mp_no_arrow:
                        textlines.append("No Arrow: YES")
                    if obj.scs_props.locator_prefab_mp_prefab_exit:
                        textlines.append("Prefab Exit: YES")

                    road_size_i = int(
                        obj.scs_props.locator_prefab_mp_road_size)
                    textlines.append(
                        str("Road Size: " +
                            obj.scs_props.enum_mp_road_size_items[road_size_i]
                            [1]))

                    road_offset_i = int(
                        obj.scs_props.locator_prefab_mp_road_offset)
                    if road_offset_i != _PL_consts.MPVF.ROAD_OFFSET_0:
                        textlines.append(
                            str("Offset: " + obj.scs_props.
                                enum_mp_road_offset_items[road_offset_i][1]))

                    custom_color_i = int(
                        obj.scs_props.locator_prefab_mp_custom_color)
                    if custom_color_i != 0:
                        textlines.append(
                            str("Custom Color: " + obj.scs_props.
                                enum_mp_custom_color_items[custom_color_i][1]))

                    assigned_node_i = int(
                        obj.scs_props.locator_prefab_mp_assigned_node)
                    if assigned_node_i != 0:
                        textlines.append(
                            str("Node: " + obj.scs_props.
                                enum_mp_assigned_node_items[assigned_node_i][1]
                                ))

                    des_nodes = "Destination Nodes:"
                    for index in obj.scs_props.locator_prefab_mp_dest_nodes:
                        des_nodes += " " + index
                    if des_nodes != "Destination Nodes:":
                        textlines.append(des_nodes)

                elif obj.scs_props.locator_prefab_type == 'Trigger Point':

                    textlines.append(
                        str("Range: %.2f m" %
                            obj.scs_props.locator_prefab_tp_range))
                    if obj.scs_props.locator_prefab_tp_reset_delay != 0:
                        textlines.append(
                            str("Reset Delay: %.2f s" %
                                obj.scs_props.locator_prefab_tp_reset_delay))
                    if obj.scs_props.locator_prefab_tp_sphere_trigger:
                        textlines.append("Sphere Trigger: YES")
                    if obj.scs_props.locator_prefab_tp_partial_activ:
                        textlines.append("Partial Activation: YES")
                    if obj.scs_props.locator_prefab_tp_onetime_activ:
                        textlines.append("One-Time Activation: YES")
                    if obj.scs_props.locator_prefab_tp_manual_activ:
                        textlines.append("Manual Activation: YES")

                for textline_i, textline in enumerate(textlines):
                    y_pos = (
                        (len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(
                        textline, font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data,
                        0, y_pos)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                textlines = [
                    '"' + key + '"',
                    str(obj.scs_props.locator_type + " - " +
                        obj.scs_props.locator_collider_type),
                    str("Mass: " + str(obj.scs_props.locator_collider_mass))
                ]

                # if obj.scs_props.locator_collider_centered:
                # textlines.append("Locator Centered")
                if obj.scs_props.locator_collider_margin != 0:
                    textlines.append(
                        str("Margin: " +
                            str(obj.scs_props.locator_collider_margin)))

                for textline_i, textline in enumerate(textlines):
                    y_pos = (
                        (len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(
                        textline, font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data,
                        0, y_pos)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                textlines = [
                    '"' + key + '"',
                    str(obj.scs_props.locator_type),
                    str(obj.scs_props.locator_model_hookup)
                ]

                if obj.scs_props.locator_show_preview_model:
                    textlines.append(
                        str(obj.scs_props.locator_preview_model_path))

                for textline_i, textline in enumerate(textlines):
                    y_pos = (
                        (len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(
                        textline, font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data,
                        0, y_pos)

    # LOCATOR BOUNDARY NODES
    elif scs_globals.display_info == 'locnodes':
        for key, obj in prefab_locators.items():
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                mat = obj.matrix_world
                _primitive.draw_text(
                    str(obj.scs_props.locator_prefab_np_boundary_node),
                    font_id, Vector(
                        (mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR BOUNDARY LANES
    elif scs_globals.display_info == 'loclanes':
        for key, obj in prefab_locators.items():
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                if obj.scs_props.locator_prefab_np_boundary != 'no':
                    mat = obj.matrix_world
                    np_boundary_i = int(
                        obj.scs_props.locator_prefab_np_boundary)
                    if np_boundary_i == 0:
                        continue

                    _primitive.draw_text(
                        str(obj.scs_props.enum_np_boundary_items[np_boundary_i]
                            [1]), font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)
Пример #2
0
def draw_custom_2d_elements():
    context = bpy.context

    font_id = 0  # TODO: Need to find out how best to get this.
    blf.size(font_id, 12, 72)

    (prefab_locators, collision_locators, model_locators) = _get_custom_visual_elements()

    if not prefab_locators and \
            not collision_locators and \
            not model_locators:
        return

    glColor3f(
        context.scene.scs_props.info_text_color[0],
        context.scene.scs_props.info_text_color[1],
        context.scene.scs_props.info_text_color[2],
    )

    region = context.region
    region3d = context.space_data.region_3d

    region_mid_width = region.width / 2.0
    region_mid_height = region.height / 2.0

    # VARS FOR PROJECTION
    perspective_matrix = region3d.perspective_matrix.copy()

    region_data = (perspective_matrix, region_mid_width, region_mid_height)

    # LOCATOR NAMES
    if context.scene.scs_props.display_info == 'locnames':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR COMPREHENSIVE INFO
    elif context.scene.scs_props.display_info == 'locinfo':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                textlines = ['"' + key + '"',
                             str(obj.scs_props.locator_type + " - " + obj.scs_props.locator_prefab_type)]

                if obj.scs_props.locator_prefab_type == 'Control Node':
                    textlines.append(str("Node Index: " + str(obj.scs_props.locator_prefab_con_node_index)))
                    if 1:  # TODO
                        textlines.append(str("Assigned Points: " + str(0)))
                elif obj.scs_props.locator_prefab_type == 'Spawn Point':
                    textlines.append(str("Type: " + str(obj.scs_props.locator_prefab_spawn_type)))
                elif obj.scs_props.locator_prefab_type == 'Traffic Semaphore':
                    textlines.append(str("ID: " + str(obj.scs_props.locator_prefab_tsem_id)))
                    # if obj.scs_props.locator_prefab_tsem_model != '':
                    # textlines.append(str("Model: " + str(obj.scs_props.locator_prefab_tsem_model)))
                    if obj.scs_props.locator_prefab_tsem_profile != '':
                        textlines.append(str("Profile: " + str(obj.scs_props.locator_prefab_tsem_profile)))
                    if obj.scs_props.locator_prefab_tsem_type != '0':
                        textlines.append(str("Type: " + str(obj.scs_props.locator_prefab_tsem_type)))
                    textlines.append(str(
                        "G: " + str(obj.scs_props.locator_prefab_tsem_gm) + " - O: " + str(obj.scs_props.locator_prefab_tsem_om1) + " - R: " + str(
                            obj.scs_props.locator_prefab_tsem_rm)))
                    if obj.scs_props.locator_prefab_tsem_cyc_delay != 0:
                        textlines.append(str("Cycle Delay: " + str(obj.scs_props.locator_prefab_tsem_cyc_delay)))
                    textlines.append(str("Activation: " + str(obj.scs_props.locator_prefab_tsem_activation)))
                    if obj.scs_props.locator_prefab_tsem_ai_only:
                        textlines.append("AI Only")
                elif obj.scs_props.locator_prefab_type == 'Navigation Point':
                    # if obj.scs_props.locator_prefab_np_speed_limit != 0:
                    # textlines.append(str(str(obj.scs_props.locator_prefab_np_speed_limit) + " km/h"))
                    if obj.scs_props.locator_prefab_np_boundary != 'no':
                        textlines.append(str("Lane " + str(obj.scs_props.locator_prefab_np_boundary)))
                    textlines.append(str("B. Node: " + str(obj.scs_props.locator_prefab_np_boundary_node)))
                    if obj.scs_props.locator_prefab_np_traffic_light != '-1':
                        textlines.append(str("T. Light ID: " + str(obj.scs_props.locator_prefab_np_traffic_light)))
                elif obj.scs_props.locator_prefab_type == 'Map Point':
                    if obj.scs_props.locator_prefab_mp_road_over:
                        textlines.append("Road Over")
                    if obj.scs_props.locator_prefab_mp_no_outline:
                        textlines.append("No Outline")
                    if obj.scs_props.locator_prefab_mp_no_arrow:
                        textlines.append("No Arrow")
                    if obj.scs_props.locator_prefab_mp_prefab_exit:
                        textlines.append("Prefab Exit")
                    textlines.append(str("Road Size: " + str(obj.scs_props.locator_prefab_mp_road_size)))
                    if obj.scs_props.locator_prefab_mp_road_offset != '0m':
                        textlines.append(str("Offset: " + str(obj.scs_props.locator_prefab_mp_road_offset)))
                    if obj.scs_props.locator_prefab_mp_custom_color != 'none':
                        textlines.append(str("Color: " + str(obj.scs_props.locator_prefab_mp_custom_color)))
                    if obj.scs_props.locator_prefab_mp_assigned_node != 'none':
                        textlines.append(str("Node: " + str(obj.scs_props.locator_prefab_mp_assigned_node)))
                    des_nodes = "Destination Nodes:"
                    if obj.scs_props.locator_prefab_mp_des_nodes_0:
                        des_nodes += " 0"
                    if obj.scs_props.locator_prefab_mp_des_nodes_1:
                        des_nodes += " 1"
                    if obj.scs_props.locator_prefab_mp_des_nodes_2:
                        des_nodes += " 2"
                    if obj.scs_props.locator_prefab_mp_des_nodes_3:
                        des_nodes += " 3"
                    if des_nodes != "Destination Nodes:":
                        textlines.append(des_nodes)
                    if obj.scs_props.locator_prefab_mp_des_nodes_ct:
                        textlines.append("Custom Target")
                elif obj.scs_props.locator_prefab_type == 'Trigger Point':
                    if obj.scs_props.locator_prefab_tp_action != '':
                        textlines.append(str("Action: " + str(obj.scs_props.locator_prefab_tp_action)))
                    textlines.append(str("Range: " + str(obj.scs_props.locator_prefab_tp_range)))
                    if obj.scs_props.locator_prefab_tp_reset_delay != 0:
                        textlines.append(str("Reset Delay: " + str(obj.scs_props.locator_prefab_tp_reset_delay)))
                    if obj.scs_props.locator_prefab_tp_sphere_trigger:
                        textlines.append("Sphere Trigger")
                    if obj.scs_props.locator_prefab_tp_partial_activ:
                        textlines.append("Partial Activation")
                    if obj.scs_props.locator_prefab_tp_onetime_activ:
                        textlines.append("One-Time Activation")
                    if obj.scs_props.locator_prefab_tp_manual_activ:
                        textlines.append("Manual Activation")

                for textline_i, textline in enumerate(textlines):
                    y_pos = ((len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                textlines = ['"' + key + '"',
                             str(obj.scs_props.locator_type + " - " + obj.scs_props.locator_collider_type),
                             str("Mass: " + str(obj.scs_props.locator_collider_mass))]

                # if obj.scs_props.locator_collider_centered:
                # textlines.append("Locator Centered")
                if obj.scs_props.locator_collider_margin != 0:
                    textlines.append(str("Margin: " + str(obj.scs_props.locator_collider_margin)))

                for textline_i, textline in enumerate(textlines):
                    y_pos = ((len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                textlines = ['"' + key + '"',
                             str(obj.scs_props.locator_type),
                             str(obj.scs_props.locator_model_hookup)]

                if obj.scs_props.locator_show_preview_model:
                    textlines.append(str(obj.scs_props.locator_preview_model_path))

                for textline_i, textline in enumerate(textlines):
                    y_pos = ((len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos)

    # LOCATOR SPEED LIMITS
    elif context.scene.scs_props.display_info == 'locspeed':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                if obj.scs_props.locator_prefab_type == 'Navigation Point':
                    if obj.scs_props.locator_prefab_np_speed_limit != 0:
                        mat = obj.matrix_world
                        _primitive.draw_text(str(str(obj.scs_props.locator_prefab_np_speed_limit) + " km/h"), font_id,
                                             Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR BOUNDARY NODES
    elif context.scene.scs_props.display_info == 'locnodes':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                if obj.scs_props.locator_prefab_type == 'Navigation Point':
                    mat = obj.matrix_world
                    _primitive.draw_text(str(obj.scs_props.locator_prefab_np_boundary_node), font_id,
                                         Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR BOUNDARY LANES
    elif context.scene.scs_props.display_info == 'loclanes':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                if obj.scs_props.locator_prefab_type == 'Navigation Point':
                    if obj.scs_props.locator_prefab_np_boundary != 'no':
                        mat = obj.matrix_world
                        _primitive.draw_text(str(obj.scs_props.locator_prefab_np_boundary), font_id,
                                             Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)
Пример #3
0
def draw_custom_2d_elements():
    context = bpy.context
    scs_globals = _get_scs_globals()

    font_id = 0  # TODO: Need to find out how best to get this.
    blf.size(font_id, 12, 72)

    region = context.region

    # draw 3d view import/export reports
    _draw_3dview_report(region)

    (prefab_locators, collision_locators, model_locators) = _get_custom_visual_elements()

    if not prefab_locators and not collision_locators and not model_locators:
        return

    glColor3f(
        scs_globals.info_text_color[0],
        scs_globals.info_text_color[1],
        scs_globals.info_text_color[2],
    )

    region3d = context.space_data.region_3d

    region_mid_width = region.width / 2.0
    region_mid_height = region.height / 2.0

    # VARS FOR PROJECTION
    perspective_matrix = region3d.perspective_matrix.copy()

    region_data = (perspective_matrix, region_mid_width, region_mid_height)

    # LOCATOR NAMES
    if scs_globals.display_info == 'locnames':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR COMPREHENSIVE INFO
    elif scs_globals.display_info == 'locinfo':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                textlines = ['"' + key + '"',
                             str(obj.scs_props.locator_type + " - " + obj.scs_props.locator_prefab_type)]

                if obj.scs_props.locator_prefab_type == 'Control Node':

                    textlines.append(str("Node Index: " + str(obj.scs_props.locator_prefab_con_node_index)))

                elif obj.scs_props.locator_prefab_type == 'Spawn Point':

                    spawn_type_i = int(obj.scs_props.locator_prefab_spawn_type)
                    textlines.append(str("Type: " + obj.scs_props.enum_spawn_type_items[spawn_type_i][1]))

                elif obj.scs_props.locator_prefab_type == 'Traffic Semaphore':

                    textlines.append(str("ID: " + str(obj.scs_props.locator_prefab_tsem_id)))
                    if obj.scs_props.locator_prefab_tsem_profile != '':
                        textlines.append(str("Profile: " + str(obj.scs_props.locator_prefab_tsem_profile)))
                    tsem_type_i = int(obj.scs_props.locator_prefab_tsem_type)
                    if tsem_type_i != _PL_consts.TST.PROFILE:
                        textlines.append(str("Type: " + obj.scs_props.enum_tsem_type_items[tsem_type_i][1]))
                        textlines.append(str("G: %.2f" % obj.scs_props.locator_prefab_tsem_gs +
                                             " - O: %.2f" % obj.scs_props.locator_prefab_tsem_os1 +
                                             " - R: %.2f" % obj.scs_props.locator_prefab_tsem_rs +
                                             " - O: %.2f" % obj.scs_props.locator_prefab_tsem_os2))
                        if obj.scs_props.locator_prefab_tsem_cyc_delay != 0:
                            textlines.append(str("Cycle Delay: " + "%.2f s" % obj.scs_props.locator_prefab_tsem_cyc_delay))

                elif obj.scs_props.locator_prefab_type == 'Navigation Point':

                    np_boundary_i = int(obj.scs_props.locator_prefab_np_boundary)
                    if np_boundary_i != 0:
                        textlines.append(str("Boundary: " + obj.scs_props.enum_np_boundary_items[np_boundary_i][1]))

                    textlines.append(str("B. Node: " + str(obj.scs_props.locator_prefab_np_boundary_node)))
                    if obj.scs_props.locator_prefab_np_traffic_semaphore != '-1':
                        textlines.append(str("T. Light ID: " + str(obj.scs_props.locator_prefab_np_traffic_semaphore)))

                elif obj.scs_props.locator_prefab_type == 'Map Point':

                    if obj.scs_props.locator_prefab_mp_road_over:
                        textlines.append("Road Over: YES")
                    if obj.scs_props.locator_prefab_mp_no_outline:
                        textlines.append("No Outline: YES")
                    if obj.scs_props.locator_prefab_mp_no_arrow:
                        textlines.append("No Arrow: YES")
                    if obj.scs_props.locator_prefab_mp_prefab_exit:
                        textlines.append("Prefab Exit: YES")

                    road_size_i = int(obj.scs_props.locator_prefab_mp_road_size)
                    textlines.append(str("Road Size: " + obj.scs_props.enum_mp_road_size_items[road_size_i][1]))

                    road_offset_i = int(obj.scs_props.locator_prefab_mp_road_offset)
                    if road_offset_i != _PL_consts.MPVF.ROAD_OFFSET_0:
                        textlines.append(str("Offset: " + obj.scs_props.enum_mp_road_offset_items[road_offset_i][1]))

                    custom_color_i = int(obj.scs_props.locator_prefab_mp_custom_color)
                    if custom_color_i != 0:
                        textlines.append(str("Custom Color: " + obj.scs_props.enum_mp_custom_color_items[custom_color_i][1]))

                    assigned_node_i = int(obj.scs_props.locator_prefab_mp_assigned_node)
                    if assigned_node_i != 0:
                        textlines.append(str("Node: " + obj.scs_props.enum_mp_assigned_node_items[assigned_node_i][1]))

                    des_nodes = "Destination Nodes:"
                    for index in obj.scs_props.locator_prefab_mp_dest_nodes:
                        des_nodes += " " + index
                    if des_nodes != "Destination Nodes:":
                        textlines.append(des_nodes)

                elif obj.scs_props.locator_prefab_type == 'Trigger Point':

                    textlines.append(str("Range: %.2f m" % obj.scs_props.locator_prefab_tp_range))
                    if obj.scs_props.locator_prefab_tp_reset_delay != 0:
                        textlines.append(str("Reset Delay: %.2f s" % obj.scs_props.locator_prefab_tp_reset_delay))
                    if obj.scs_props.locator_prefab_tp_sphere_trigger:
                        textlines.append("Sphere Trigger: YES")
                    if obj.scs_props.locator_prefab_tp_partial_activ:
                        textlines.append("Partial Activation: YES")
                    if obj.scs_props.locator_prefab_tp_onetime_activ:
                        textlines.append("One-Time Activation: YES")
                    if obj.scs_props.locator_prefab_tp_manual_activ:
                        textlines.append("Manual Activation: YES")

                for textline_i, textline in enumerate(textlines):
                    y_pos = ((len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                textlines = ['"' + key + '"',
                             str(obj.scs_props.locator_type + " - " + obj.scs_props.locator_collider_type),
                             str("Mass: " + str(obj.scs_props.locator_collider_mass))]

                # if obj.scs_props.locator_collider_centered:
                # textlines.append("Locator Centered")
                if obj.scs_props.locator_collider_margin != 0:
                    textlines.append(str("Margin: " + str(obj.scs_props.locator_collider_margin)))

                for textline_i, textline in enumerate(textlines):
                    y_pos = ((len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                textlines = ['"' + key + '"',
                             str(obj.scs_props.locator_type),
                             str(obj.scs_props.locator_model_hookup)]

                if obj.scs_props.locator_show_preview_model:
                    textlines.append(str(obj.scs_props.locator_preview_model_path))

                for textline_i, textline in enumerate(textlines):
                    y_pos = ((len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos)

    # LOCATOR BOUNDARY NODES
    elif scs_globals.display_info == 'locnodes':
        for key, obj in prefab_locators.items():
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                mat = obj.matrix_world
                _primitive.draw_text(str(obj.scs_props.locator_prefab_np_boundary_node), font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR BOUNDARY LANES
    elif scs_globals.display_info == 'loclanes':
        for key, obj in prefab_locators.items():
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                if obj.scs_props.locator_prefab_np_boundary != 'no':
                    mat = obj.matrix_world
                    np_boundary_i = int(obj.scs_props.locator_prefab_np_boundary)
                    if np_boundary_i == 0:
                        continue

                    _primitive.draw_text(str(obj.scs_props.enum_np_boundary_items[np_boundary_i][1]), font_id,
                                         Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)
Пример #4
0
def draw_custom_2d_elements():
    context = bpy.context

    font_id = 0  # TODO: Need to find out how best to get this.
    blf.size(font_id, 12, 72)

    (prefab_locators, collision_locators,
     model_locators) = _get_custom_visual_elements()

    if not prefab_locators and \
            not collision_locators and \
            not model_locators:
        return

    glColor3f(
        context.scene.scs_props.info_text_color[0],
        context.scene.scs_props.info_text_color[1],
        context.scene.scs_props.info_text_color[2],
    )

    region = context.region
    region3d = context.space_data.region_3d

    region_mid_width = region.width / 2.0
    region_mid_height = region.height / 2.0

    # VARS FOR PROJECTION
    perspective_matrix = region3d.perspective_matrix.copy()

    region_data = (perspective_matrix, region_mid_width, region_mid_height)

    # LOCATOR NAMES
    if context.scene.scs_props.display_info == 'locnames':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])),
                                     region_data)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])),
                                     region_data)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                _primitive.draw_text(key, font_id,
                                     Vector((mat[0][3], mat[1][3], mat[2][3])),
                                     region_data)

    # LOCATOR COMPREHENSIVE INFO
    elif context.scene.scs_props.display_info == 'locinfo':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                mat = obj.matrix_world
                textlines = [
                    '"' + key + '"',
                    str(obj.scs_props.locator_type + " - " +
                        obj.scs_props.locator_prefab_type)
                ]

                if obj.scs_props.locator_prefab_type == 'Control Node':
                    textlines.append(
                        str("Node Index: " +
                            str(obj.scs_props.locator_prefab_con_node_index)))
                    if 1:  # TODO
                        textlines.append(str("Assigned Points: " + str(0)))
                elif obj.scs_props.locator_prefab_type == 'Spawn Point':
                    textlines.append(
                        str("Type: " +
                            str(obj.scs_props.locator_prefab_spawn_type)))
                elif obj.scs_props.locator_prefab_type == 'Traffic Semaphore':
                    textlines.append(
                        str("ID: " +
                            str(obj.scs_props.locator_prefab_tsem_id)))
                    # if obj.scs_props.locator_prefab_tsem_model != '':
                    # textlines.append(str("Model: " + str(obj.scs_props.locator_prefab_tsem_model)))
                    if obj.scs_props.locator_prefab_tsem_profile != '':
                        textlines.append(
                            str("Profile: " +
                                str(obj.scs_props.locator_prefab_tsem_profile))
                        )
                    if obj.scs_props.locator_prefab_tsem_type != '0':
                        textlines.append(
                            str("Type: " +
                                str(obj.scs_props.locator_prefab_tsem_type)))
                    textlines.append(
                        str("G: " + str(obj.scs_props.locator_prefab_tsem_gm) +
                            " - O: " +
                            str(obj.scs_props.locator_prefab_tsem_om1) +
                            " - R: " +
                            str(obj.scs_props.locator_prefab_tsem_rm)))
                    if obj.scs_props.locator_prefab_tsem_cyc_delay != 0:
                        textlines.append(
                            str("Cycle Delay: " + str(
                                obj.scs_props.locator_prefab_tsem_cyc_delay)))
                    textlines.append(
                        str("Activation: " +
                            str(obj.scs_props.locator_prefab_tsem_activation)))
                    if obj.scs_props.locator_prefab_tsem_ai_only:
                        textlines.append("AI Only")
                elif obj.scs_props.locator_prefab_type == 'Navigation Point':
                    # if obj.scs_props.locator_prefab_np_speed_limit != 0:
                    # textlines.append(str(str(obj.scs_props.locator_prefab_np_speed_limit) + " km/h"))
                    if obj.scs_props.locator_prefab_np_boundary != 'no':
                        textlines.append(
                            str("Lane " +
                                str(obj.scs_props.locator_prefab_np_boundary)))
                    textlines.append(
                        str("B. Node: " +
                            str(obj.scs_props.locator_prefab_np_boundary_node))
                    )
                    if obj.scs_props.locator_prefab_np_traffic_light != '-1':
                        textlines.append(
                            str("T. Light ID: " +
                                str(obj.scs_props.
                                    locator_prefab_np_traffic_light)))
                elif obj.scs_props.locator_prefab_type == 'Map Point':
                    if obj.scs_props.locator_prefab_mp_road_over:
                        textlines.append("Road Over")
                    if obj.scs_props.locator_prefab_mp_no_outline:
                        textlines.append("No Outline")
                    if obj.scs_props.locator_prefab_mp_no_arrow:
                        textlines.append("No Arrow")
                    if obj.scs_props.locator_prefab_mp_prefab_exit:
                        textlines.append("Prefab Exit")
                    textlines.append(
                        str("Road Size: " +
                            str(obj.scs_props.locator_prefab_mp_road_size)))
                    if obj.scs_props.locator_prefab_mp_road_offset != '0m':
                        textlines.append(
                            str("Offset: " + str(
                                obj.scs_props.locator_prefab_mp_road_offset)))
                    if obj.scs_props.locator_prefab_mp_custom_color != 'none':
                        textlines.append(
                            str("Color: " + str(
                                obj.scs_props.locator_prefab_mp_custom_color)))
                    if obj.scs_props.locator_prefab_mp_assigned_node != 'none':
                        textlines.append(
                            str("Node: " +
                                str(obj.scs_props.
                                    locator_prefab_mp_assigned_node)))
                    des_nodes = "Destination Nodes:"
                    if obj.scs_props.locator_prefab_mp_des_nodes_0:
                        des_nodes += " 0"
                    if obj.scs_props.locator_prefab_mp_des_nodes_1:
                        des_nodes += " 1"
                    if obj.scs_props.locator_prefab_mp_des_nodes_2:
                        des_nodes += " 2"
                    if obj.scs_props.locator_prefab_mp_des_nodes_3:
                        des_nodes += " 3"
                    if des_nodes != "Destination Nodes:":
                        textlines.append(des_nodes)
                    if obj.scs_props.locator_prefab_mp_des_nodes_ct:
                        textlines.append("Custom Target")
                elif obj.scs_props.locator_prefab_type == 'Trigger Point':
                    if obj.scs_props.locator_prefab_tp_action != '':
                        textlines.append(
                            str("Action: " +
                                str(obj.scs_props.locator_prefab_tp_action)))
                    textlines.append(
                        str("Range: " +
                            str(obj.scs_props.locator_prefab_tp_range)))
                    if obj.scs_props.locator_prefab_tp_reset_delay != 0:
                        textlines.append(
                            str("Reset Delay: " + str(
                                obj.scs_props.locator_prefab_tp_reset_delay)))
                    if obj.scs_props.locator_prefab_tp_sphere_trigger:
                        textlines.append("Sphere Trigger")
                    if obj.scs_props.locator_prefab_tp_partial_activ:
                        textlines.append("Partial Activation")
                    if obj.scs_props.locator_prefab_tp_onetime_activ:
                        textlines.append("One-Time Activation")
                    if obj.scs_props.locator_prefab_tp_manual_activ:
                        textlines.append("Manual Activation")

                for textline_i, textline in enumerate(textlines):
                    y_pos = (
                        (len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(
                        textline, font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data,
                        0, y_pos)

        if collision_locators:
            for key, obj in collision_locators.items():
                mat = obj.matrix_world
                textlines = [
                    '"' + key + '"',
                    str(obj.scs_props.locator_type + " - " +
                        obj.scs_props.locator_collider_type),
                    str("Mass: " + str(obj.scs_props.locator_collider_mass))
                ]

                # if obj.scs_props.locator_collider_centered:
                # textlines.append("Locator Centered")
                if obj.scs_props.locator_collider_margin != 0:
                    textlines.append(
                        str("Margin: " +
                            str(obj.scs_props.locator_collider_margin)))

                for textline_i, textline in enumerate(textlines):
                    y_pos = (
                        (len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(
                        textline, font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data,
                        0, y_pos)

        if model_locators:
            for key, obj in model_locators.items():
                mat = obj.matrix_world
                textlines = [
                    '"' + key + '"',
                    str(obj.scs_props.locator_type),
                    str(obj.scs_props.locator_model_hookup)
                ]

                if obj.scs_props.locator_show_preview_model:
                    textlines.append(
                        str(obj.scs_props.locator_preview_model_path))

                for textline_i, textline in enumerate(textlines):
                    y_pos = (
                        (len(textlines) * 15) / 2) + (textline_i * -15) - 7
                    _primitive.draw_text(
                        textline, font_id,
                        Vector((mat[0][3], mat[1][3], mat[2][3])), region_data,
                        0, y_pos)

    # LOCATOR SPEED LIMITS
    elif context.scene.scs_props.display_info == 'locspeed':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                if obj.scs_props.locator_prefab_type == 'Navigation Point':
                    if obj.scs_props.locator_prefab_np_speed_limit != 0:
                        mat = obj.matrix_world
                        _primitive.draw_text(
                            str(
                                str(obj.scs_props.locator_prefab_np_speed_limit
                                    ) + " km/h"), font_id,
                            Vector((mat[0][3], mat[1][3], mat[2][3])),
                            region_data)

    # LOCATOR BOUNDARY NODES
    elif context.scene.scs_props.display_info == 'locnodes':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                if obj.scs_props.locator_prefab_type == 'Navigation Point':
                    mat = obj.matrix_world
                    _primitive.draw_text(
                        str(obj.scs_props.locator_prefab_np_boundary_node),
                        font_id, Vector(
                            (mat[0][3], mat[1][3], mat[2][3])), region_data)

    # LOCATOR BOUNDARY LANES
    elif context.scene.scs_props.display_info == 'loclanes':
        if prefab_locators:
            for key, obj in prefab_locators.items():
                if obj.scs_props.locator_prefab_type == 'Navigation Point':
                    if obj.scs_props.locator_prefab_np_boundary != 'no':
                        mat = obj.matrix_world
                        _primitive.draw_text(
                            str(obj.scs_props.locator_prefab_np_boundary),
                            font_id, Vector((mat[0][3], mat[1][3], mat[2][3])),
                            region_data)
Пример #5
0
def draw_custom_2d_elements():
    """Draws custom 2D elements from cache.
    """
    context = bpy.context
    scs_globals = _get_scs_globals()

    region = context.region
    region_3d = context.region_data
    space = context.space_data
    area = context.area
    window = context.window

    # draw 3d view import/export reports
    _draw_3dview_report(window, area, region)

    # cache & get valid locators for current region boundaries
    locators = _cache_custom_2d_elements(region, region_3d, space)

    # no locators, we can safely finish here
    if not locators:
        return

    font_id = 0  # default font
    blf.size(font_id, 12, 72)
    blf.color(font_id, scs_globals.info_text_color[0],
              scs_globals.info_text_color[1], scs_globals.info_text_color[2],
              1.0)
    blf.word_wrap(font_id, 999)
    blf.enable(font_id, blf.WORD_WRAP)

    persp_matrix_str = str(region_3d.perspective_matrix)

    # LOCATOR NAMES
    if scs_globals.display_info == 'locnames':
        for obj in locators:
            loc_2d = _2d_elements_cache.get_locator_location_2d(
                obj, persp_matrix_str)
            _primitive.draw_text(obj.name, font_id, loc_2d.x, loc_2d.y)

    # LOCATOR COMPREHENSIVE INFO
    elif scs_globals.display_info == 'locinfo':
        for obj in locators:
            loc_2d = _2d_elements_cache.get_locator_location_2d(
                obj, persp_matrix_str)
            loc_info = _2d_elements_cache.get_locator_info(obj)
            _primitive.draw_text(loc_info, font_id, loc_2d.x, loc_2d.y)

    # LOCATOR BOUNDARY NODES
    elif scs_globals.display_info == 'locnodes':
        for obj in locators:
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                loc_2d = _2d_elements_cache.get_locator_location_2d(
                    obj, persp_matrix_str)
                _primitive.draw_text(
                    str(obj.scs_props.locator_prefab_np_boundary_node),
                    font_id, loc_2d.x, loc_2d.y)

    # LOCATOR BOUNDARY LANES
    elif scs_globals.display_info == 'loclanes':
        for obj in locators:
            if obj.scs_props.locator_prefab_type == 'Navigation Point':
                if obj.scs_props.locator_prefab_np_boundary != 'no':
                    np_boundary_i = int(
                        obj.scs_props.locator_prefab_np_boundary)
                    if np_boundary_i == 0:
                        continue

                    loc_2d = _2d_elements_cache.get_locator_location_2d(
                        obj, persp_matrix_str)
                    _primitive.draw_text(
                        str(obj.scs_props.enum_np_boundary_items[np_boundary_i]
                            [1]), font_id, loc_2d.x, loc_2d.y)

    blf.disable(font_id, blf.WORD_WRAP)