Python bpy_extras.view3d_utils.location_3d_to_region_2d() Examples

The following are 30 code examples of bpy_extras.view3d_utils.location_3d_to_region_2d(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bpy_extras.view3d_utils , or try the search function .
Example #1
Source File: 3dmouse_plugin_alpha.py    From android3dblendermouse with Apache License 2.0 6 votes vote down vote up
def pan(ary):
        #get reference to all the areas
        area = bpy.context.window_manager.windows[0].screen.areas[1]
        viewport = area.regions[4]
        rv3d = area.spaces[0].region_3d
        
        #convert view location's 3D Cords to 2D Cords
        locCord = rv3d.view_location
        cord =  view3d_utils.location_3d_to_region_2d(viewport, rv3d, locCord)
        
        cord[0] += float(ary[1])
        cord[1] += float(ary[2])
        
        #convert 2d cords to 3d Cords and apply
        vec = view3d_utils.region_2d_to_vector_3d(viewport, rv3d, cord)
        loc = view3d_utils.region_2d_to_location_3d(viewport, rv3d, cord, vec)
        rv3d.view_location = loc 
Example #2
Source File: mi_curve_main.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_curve_points_box(curve, context, mouse_coords, anchor):
    region = context.region
    rv3d = context.region_data

    picked_points = []
    picked_point_length = None
    mouse_vec = Vector(mouse_coords)
    for cu_point in curve.curve_points:
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)
        minx = min(anchor[0],mouse_coords[0])
        miny = min(anchor[1],mouse_coords[1])
        maxx = max(anchor[0], mouse_coords[0])
        maxy = max(anchor[1], mouse_coords[1])

        if point_pos_2d[0] > minx and point_pos_2d[0] < maxx and point_pos_2d[1] < maxy and point_pos_2d[1] > miny:
           picked_points.append(cu_point)
           picked_point_length = 0
        elif cu_point in picked_points:
            picked_points.remove(cu_point)

    return picked_points 
Example #3
Source File: mi_curve_main.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_curve_point(curve, context, mouse_coords):
    region = context.region
    rv3d = context.region_data

    picked_point = None
    picked_point_length = None
    mouse_vec = Vector(mouse_coords)
    for cu_point in curve.curve_points:
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)
        the_length = (point_pos_2d - mouse_vec).length
        if the_length <= 9.0:
            if picked_point is None:
                picked_point = cu_point
                picked_point_length = the_length
            else:
                if the_length < picked_point_length:
                    picked_point = cu_point
                    picked_point_length = the_length                    

    return picked_point, the_length 
Example #4
Source File: mi_curve_surfaces.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_surf(all_surfs, context, mouse_coords):
    region = context.region
    rv3d = context.region_data

    picked_surf = None
    picked_point_length = None
    mouse_vec = Vector(mouse_coords)
    for surf in all_surfs:
        if surf.main_loop_center:
            point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, surf.main_loop_center)
            the_length = (point_pos_2d - mouse_vec).length
            if the_length <= 9.0:
                if picked_surf is None:
                    picked_surf = surf
                    picked_point_length = the_length
                else:
                    if the_length < picked_point_length:
                        picked_surf = surf
                        picked_point_length = the_length                    

    return picked_surf 
Example #5
Source File: mi_widget_linear_deform.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_lw_point(context, m_coords, lw):
    region = context.region
    rv3d = context.region_data

    return_point = None
    good_distance = None

    mouse_coords = Vector(m_coords)

    lw_points = [lw.start_point, lw.middle_point, lw.end_point]
    for lw_point in lw_points:
        vec_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw_point.position)
        dist = (vec_2d - mouse_coords).length
        if dist <= 9.0:
            if not return_point:
                return_point = lw_point
                good_distance = dist
            elif good_distance > dist:
                return_point = lw_point

    return return_point 
Example #6
Source File: mi_linear_widget.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_lw_point(context, m_coords, lw):
    region = context.region
    rv3d = context.region_data

    return_point = None
    good_distance = None

    mouse_coords = Vector(m_coords)

    lw_points = [lw.start_point, lw.middle_point, lw.end_point]
    for lw_point in lw_points:
        vec_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw_point.position)
        dist = (vec_2d - mouse_coords).length
        if dist <= 9.0:
            if not return_point:
                return_point = lw_point
                good_distance = dist
            elif good_distance > dist:
                return_point = lw_point

    return return_point 
Example #7
Source File: mi_curve_surfaces.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_surf(all_surfs, context, mouse_coords):
    region = context.region
    rv3d = context.region_data

    picked_surf = None
    picked_point_length = None
    mouse_vec = Vector(mouse_coords)
    for surf in all_surfs:
        if surf.main_loop_center:
            point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, surf.main_loop_center)
            the_length = (point_pos_2d - mouse_vec).length
            if the_length <= 9.0:
                if picked_surf is None:
                    picked_surf = surf
                    picked_point_length = the_length
                else:
                    if the_length < picked_point_length:
                        picked_surf = surf
                        picked_point_length = the_length                    

    return picked_surf 
Example #8
Source File: mi_curve_main.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_curve_point(curve, context, mouse_coords):
    region = context.region
    rv3d = context.region_data

    picked_point = None
    picked_point_length = None
    mouse_vec = Vector(mouse_coords)
    for cu_point in curve.curve_points:
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)
        the_length = (point_pos_2d - mouse_vec).length
        if the_length <= 9.0:
            if picked_point is None:
                picked_point = cu_point
                picked_point_length = the_length
            else:
                if the_length < picked_point_length:
                    picked_point = cu_point
                    picked_point_length = the_length                    

    return picked_point, the_length 
Example #9
Source File: mi_curve_main.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_curve_points_box(curve, context, mouse_coords, anchor):
    region = context.region
    rv3d = context.region_data

    picked_points = []
    picked_point_length = None
    mouse_vec = Vector(mouse_coords)
    for cu_point in curve.curve_points:
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)
        minx = min(anchor[0],mouse_coords[0])
        miny = min(anchor[1],mouse_coords[1])
        maxx = max(anchor[0], mouse_coords[0])
        maxy = max(anchor[1], mouse_coords[1])

        if point_pos_2d[0] > minx and point_pos_2d[0] < maxx and point_pos_2d[1] < maxy and point_pos_2d[1] > miny:
           picked_points.append(cu_point)
           picked_point_length = 0
        elif cu_point in picked_points:
            picked_points.remove(cu_point)

    return picked_points 
Example #10
Source File: mi_curve_main.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def snap_to_surface(context, selected_points, picked_meshes, region, rv3d, move_offset):
    best_obj, hit_normal, hit_position = None, None, None

    for point in selected_points:
        # get the ray from the viewport and mouse
        final_pos = point.position
        if move_offset:
            final_pos = point.position + move_offset

        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, final_pos)

        if point_pos_2d:
            best_obj, hit_normal, hit_position = ut_base.get_mouse_raycast(context, picked_meshes, point_pos_2d)
            #best_obj, hit_normal, hit_position = ut_base.get_3dpoint_raycast(context, self.picked_meshes, final_pos, camera_dir, 10000.0)
        if hit_position:
            point.position = hit_position 
Example #11
Source File: opengl.py    From BlenderPro with GNU General Public License v3.0 6 votes vote down vote up
def draw(self,obj_1,obj_2):
        p1 = (obj_1.matrix_world[0][3], obj_1.matrix_world[1][3],obj_1.matrix_world[2][3])
        p2 = (obj_2.matrix_world[0][3], obj_2.matrix_world[1][3],obj_2.matrix_world[2][3])
        
        dist = distance(p1,p2)
        
        if dist > 0:
            
            dim_text = unit.dim_as_string(dist)
            text_width = self.txt_width(dim_text)
            text_height = self.txt_height(dim_text)
            
            txtpoint3d = interpolate3d(p1, p2, math.fabs(dist / 2))
            txtpoint2d = view3d_utils.location_3d_to_region_2d(self.region, self.rv3d, txtpoint3d)
            
            self.draw_dim_box(txtpoint2d, (text_width,text_height))
            self.draw_dim_text(txtpoint2d, dim_text, (text_width,text_height)) 
Example #12
Source File: mi_widget_linear_deform.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pick_lw_point(context, m_coords, lw):
    region = context.region
    rv3d = context.region_data

    return_point = None
    good_distance = None

    mouse_coords = Vector(m_coords)

    lw_points = [lw.start_point, lw.middle_point, lw.end_point]
    for lw_point in lw_points:
        vec_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw_point.position)
        dist = (vec_2d - mouse_coords).length
        if dist <= 9.0:
            if not return_point:
                return_point = lw_point
                good_distance = dist
            elif good_distance > dist:
                return_point = lw_point

    return return_point 
Example #13
Source File: utilities.py    From object_alignment with GNU General Public License v3.0 6 votes vote down vote up
def draw_3d_points(context, points, color, size):
    '''
    draw a bunch of dots
    args:
        points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        size: integer? maybe a float
    '''
    points_2d = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points]
    if None in points_2d:
        points_2d = filter(None, points_2d)
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points_2d:
        #TODO:  Debug this problem....perhaps loc_3d is returning points off of the screen.
        if coord:
            bgl.glVertex2f(*coord)

    bgl.glEnd()
    return 
Example #14
Source File: polystrips_draw.py    From retopology-polystrips with GNU General Public License v2.0 5 votes vote down vote up
def draw_gedge_text(gedge,context, text):
    l = len(gedge.cache_igverts)
    if l > 4:
        n_quads = math.floor(l/2) + 1
        mid_vert_ind = math.floor(l/2)
        mid_vert = gedge.cache_igverts[mid_vert_ind]
        position_3d = mid_vert.position + 1.5 * mid_vert.tangent_y * mid_vert.radius
    else:
        position_3d = (gedge.gvert0.position + gedge.gvert3.position)/2
    
    position_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d,position_3d)
    txt_width, txt_height = blf.dimensions(0, text)
    blf.position(0, position_2d[0]-(txt_width/2), position_2d[1]-(txt_height/2), 0)
    blf.draw(0, text) 
Example #15
Source File: bp_draw_objects.py    From ProSidebar with GNU General Public License v3.0 5 votes vote down vote up
def get_snap_point(self,context,selected_point,selected_obj):
        """
            Used to set the self.snapping_point_2d for opengl and
            Used to set the self.placement_point_3d for final placement position
        """
        if selected_obj is not None:
            obj_data = selected_obj.to_mesh(bpy.context.scene, True, 'PREVIEW')
            mesh = obj_data
            size = len(mesh.vertices)
            kd = mathutils.kdtree.KDTree(size)
            for i, v in enumerate(mesh.vertices):
                kd.insert(selected_obj.matrix_world * v.co, i)
            kd.balance()
            snapping_point, index, dist = kd.find(selected_point)
            
            dist = self.calc_distance(snapping_point, selected_point)
            
            if dist > .5:
                #TOO FAR AWAY FROM SNAP POINT
                self.snapping_point_2d = location_3d_to_region_2d(context.region, 
                                                                  context.space_data.region_3d, 
                                                                  selected_point)
                self.placement_point_3d = selected_point
                self.found_snap_point = False
            else:
                #FOUND POINT TO SNAP TO
                self.snapping_point_2d = location_3d_to_region_2d(context.region, 
                                                                  context.space_data.region_3d, 
                                                                  snapping_point)
                self.placement_point_3d = snapping_point
                self.found_snap_point = True
                
            bpy.data.meshes.remove(obj_data) 
Example #16
Source File: mi_curve_main.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def snap_to_surface(context, selected_points, picked_meshes, region, rv3d, move_offset):
    for point in selected_points:
        # get the ray from the viewport and mouse
        final_pos = point.position
        if move_offset:
            final_pos = point.position + move_offset
        
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, final_pos)

        if point_pos_2d:
            best_obj, hit_normal, hit_position = ut_base.get_mouse_raycast(context, picked_meshes, point_pos_2d)
            #best_obj, hit_normal, hit_position = ut_base.get_3dpoint_raycast(context, self.picked_meshes, final_pos, camera_dir, 10000.0)
        if hit_position:
            point.position = hit_position 
Example #17
Source File: assetbar.py    From BlendLuxCore with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback_2d_progress(self, context):
    # x = ui_props.reports_x
    # y = ui_props.reports_y
    index = 0
    for threaddata in utils.download_threads:
        tcom = threaddata[2]

        if tcom.passargs['thumbnail']:
            continue

        asset_data = threaddata[1]

        iname = asset_data['thumbnail']
        img = bpy.data.images.get(iname)
        if img is None:
            img = utils.get_thumbnail('thumbnail_notready.jpg')


        if tcom.passargs.get('downloaders'):
            for d in tcom.passargs['downloaders']:

                loc = view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d,
                                                            d['location'])
                if loc is not None:
                    ui_bgl.draw_downloader(loc[0], loc[1], tcom.progress, img)

        # else:
        #     ui_bgl.draw_progress(x, y - index * 30, text='downloading %s' % asset_data['name'],
        #                   percent=tcom.progress)
        #     index += 1
    # for process in bg_blender.bg_processes:
    #     tcom = process[1]
    #     draw_progress(x, y - index * 30, '%s' % tcom.lasttext,
    #                   tcom.progress)
    #     index += 1
    # global reports
    # for report in reports:
    #     report.draw(x, y - index * 30)
    #     index += 1
    #     report.fade() 
Example #18
Source File: cellblender_molecules.py    From cellblender with GNU General Public License v2.0 5 votes vote down vote up
def draw_labels_callback(self, context):
    disp_mol_labels = context.window_manager.display_mol_labels
    if disp_mol_labels.show_mol_labels:
      if context.window_manager.display_mol_labels.enabled:
        if context == None:
          print ( "draw_labels_callback: context is None" )
          return
        if context.region == None:
          print ( "draw_labels_callback: context.region is None" )
          return
        if context.space_data == None:
          print ( "draw_labels_callback: context.space_data is None" )
          return
        if context.space_data.region_3d == None:
          print ( "draw_labels_callback: context.space_data.region_3d is None" )
          return

        mv = context.scene.mcell.mol_viz
        if 'mol_labels_index' in mv:
          ml_obj_labels_index = mv['mol_labels_index']
          ml_obj_labels_x = mv['mol_labels_x']
          ml_obj_labels_y = mv['mol_labels_y']
          ml_obj_labels_z = mv['mol_labels_z']
          ml_obj_labels_bngl = mv['mol_labels_bngl']
          for i in range(len(ml_obj_labels_index)):
            t = ml_obj_labels_index[i]
            x = ml_obj_labels_x[i]
            y = ml_obj_labels_y[i]
            z = ml_obj_labels_z[i]
            if ml_obj_labels_bngl[t] != None:
              screen_coords = location_3d_to_region_2d (context.region, context.space_data.region_3d, [x,y,z])
              # Note that screen_coords can be None when an object is too close in perspective mode
              if screen_coords != None:
                loc_x, loc_y = screen_coords
                blf.position(0, loc_x, loc_y, 0)
                blf.draw(0, ml_obj_labels_bngl[t]) 
Example #19
Source File: mi_simple_extrude.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mi_extrude_draw_2d(self, context):
    if self.center:
        rv3d = context.region_data
        region = context.region
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, self.center)

        p_col = col_man.dre_point_base
        c_widget.draw_2d_point(point_pos_2d.x, point_pos_2d.y, 6, p_col) 
Example #20
Source File: display.py    From phobos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def to2d(coords):
    """

    Args:
      coords: 

    Returns:

    """
    return view3d_utils.location_3d_to_region_2d(*getRegionData(), coords) 
Example #21
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_curve_2d(curves, context):
    region = context.region
    rv3d = context.region_data
    curve_settings = context.scene.mi_settings
    # coord = event.mouse_region_x, event.mouse_region_y
    for curve in curves:
        for cu_point in curve.curve_points:
            point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)

            if point_pos_2d:
                p_col = col_man.cur_point_base
                if curve.closed is True:
                    if curve.curve_points.index(cu_point) == 0:
                        p_col = col_man.cur_point_closed_start
                    elif curve.curve_points.index(cu_point) == len(curve.curve_points) - 1:
                        p_col = col_man.cur_point_closed_end

                if cu_point.select:
                    p_col = col_man.cur_point_selected
                if cu_point.point_id == curve.active_point:
                    p_col = col_man.cur_point_active
                mi_draw_2d_point(point_pos_2d.x, point_pos_2d.y, 6, p_col)

                # Handlers
                if curve_settings.draw_handlers:
                #if curve.curve_points.index(cu_point) < len(curve.curve_points)-1:
                    if cu_point.handle1:
                        handle_1_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.handle1)
                        if handle_1_pos_2d:
                            mi_draw_2d_point(handle_1_pos_2d.x, handle_1_pos_2d.y, 3, col_man.cur_handle_1_base)
                #if curve.curve_points.index(cu_point) > 0:
                    if cu_point.handle2:
                        handle_2_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.handle2)
                        if handle_2_pos_2d:
                            mi_draw_2d_point(handle_2_pos_2d.x, handle_2_pos_2d.y, 3, col_man.cur_handle_2_base)

# --------------------------------------- OLD STUFF 
Example #22
Source File: mi_curve_stretch.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_curve_2d(curves, active_cur, context):
    region = context.region
    rv3d = context.region_data
    curve_settings = context.scene.mi_settings
    # coord = event.mouse_region_x, event.mouse_region_y
    for curve in curves:
        for cu_point in curve.curve_points:
            point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)

            if point_pos_2d:
                p_col = col_man.cur_point_base
                if curve.closed is True:
                    if curve.curve_points.index(cu_point) == 0:
                        p_col = col_man.cur_point_closed_start
                    elif curve.curve_points.index(cu_point) == len(curve.curve_points) - 1:
                        p_col = col_man.cur_point_closed_end

                if cu_point.select:
                    p_col = col_man.cur_point_selected
                if cu_point.point_id == curve.active_point and curve is active_cur:
                    p_col = col_man.cur_point_active
                c_widget.draw_2d_point(point_pos_2d.x, point_pos_2d.y, 6, p_col)

                # Handlers
                if curve_settings.draw_handlers:
                #if curve.curve_points.index(cu_point) < len(curve.curve_points)-1:
                    if cu_point.handle1:
                        handle_1_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.handle1)
                        if handle_1_pos_2d:
                            c_widget.draw_2d_point(handle_1_pos_2d.x, handle_1_pos_2d.y, 3, col_man.cur_handle_1_base)
                #if curve.curve_points.index(cu_point) > 0:
                    if cu_point.handle2:
                        handle_2_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.handle2)
                        if handle_2_pos_2d:
                            c_widget.draw_2d_point(handle_2_pos_2d.x, handle_2_pos_2d.y, 3, col_man.cur_handle_2_base) 
Example #23
Source File: mi_curve_guide.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cur_guide_draw_3d(self, context):
    # active_obj = context.active_object
    region = context.region
    rv3d = context.region_data
    curve_settings = context.scene.mi_settings
    curguide_settings = context.scene.mi_curguide_settings

    if self.curve_tool:
        if curguide_settings.deform_type != 'Deform':
            # draw start line
            start_pos = self.lw_tool.start_point.position + (self.tool_side_vec * self.tool_side_vec_len)
            #start_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, start_pos)
            end_pos = self.lw_tool.end_point.position + (self.tool_side_vec * self.tool_side_vec_len)
            #end_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, end_pos)
            #draw_polyline_2d([start_pos_2d, end_pos_2d], 1, (0.3, 0.6, 0.99, 1.0))
            c_widget.draw_3d_polyline([start_pos, end_pos], 1, col_man.cur_line_base, True)

            # draw points
            for point in self.curve_tool.curve_points:
                start_pos = point.position
                #start_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, start_pos)
                p_dist = mathu.geometry.distance_point_to_plane(start_pos, self.lw_tool.start_point.position, self.tool_side_vec)
                end_pos = start_pos - (self.tool_side_vec * p_dist)
                #end_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, end_pos)
                #draw_polyline_2d([start_pos_2d, end_pos_2d], 1, (0.7, 0.5, 0.95, 1.0))
                c_widget.draw_3d_polyline([start_pos, end_pos], 1, col_man.cur_line_base, True)

        for cur_point in self.curve_tool.curve_points:
            if cur_point.point_id in self.curve_tool.display_bezier:
                c_widget.draw_3d_polyline(self.curve_tool.display_bezier[cur_point.point_id], 2, col_man.cur_line_base, True)
        #draw_curve_lines_2d(self.curve_tool, context) 
Example #24
Source File: mi_curve_guide.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_curve_points_2d(curve, context, curve_settings):
    region = context.region
    rv3d = context.region_data
    curve_settings = context.scene.mi_settings

    for cu_point in curve.curve_points:
        point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.position)

        if point_pos_2d:
            p_col = col_man.cur_point_base
            if curve.closed is True:
                if curve.curve_points.index(cu_point) == 0:
                    p_col = col_man.cur_point_closed_start
                elif curve.curve_points.index(cu_point) == len(curve.curve_points) - 1:
                    p_col = col_man.cur_point_closed_end

            if cu_point.select:
                p_col = col_man.cur_point_selected
            if cu_point.point_id == curve.active_point:
                p_col = col_man.cur_point_active
            c_widget.draw_2d_point(point_pos_2d[0], point_pos_2d[1], 6, p_col)

            # Handlers
            if curve_settings.draw_handlers:
            #if curve.curve_points.index(cu_point) < len(curve.curve_points)-1:
                if cu_point.handle1:
                    handle_1_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.handle1)
                    if handle_1_pos_2d:
                        c_widget.draw_2d_point(handle_1_pos_2d[0], handle_1_pos_2d[1], 3, col_man.cur_handle_1_base)
            #if curve.curve_points.index(cu_point) > 0:
                if cu_point.handle2:
                    handle_2_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, cu_point.handle2)
                    if handle_2_pos_2d:
                        c_widget.draw_2d_point(handle_2_pos_2d[0], handle_2_pos_2d[1], 3, col_man.cur_handle_2_base) 
Example #25
Source File: mi_draw_extrude.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mi_extrude_draw_2d(self, context):
    active_obj = context.active_object
    region = context.region
    rv3d = context.region_data
    point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, self.extrude_points[-1].position)

    p_col = col_man.dre_point_base
    c_widget.draw_2d_point(point_pos_2d.x, point_pos_2d.y, 6, p_col) 
Example #26
Source File: mi_draw_extrude.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mi_pick_extrude_point(point, context, mouse_coords):
    region = context.region
    rv3d = context.region_data

    # for cu_point in curve.curve_points:
    point_pos_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, point)
    length = (point_pos_2d - Vector(mouse_coords)).length
    if length <= 9.0:
        return True

    return False 
Example #27
Source File: oscurart_meshes.py    From BlenderAddons with GNU General Public License v2.0 5 votes vote down vote up
def dibuja_callback(self, context):
    font_id = 0
    bm = bmesh.from_edit_mesh(bpy.context.object.data)
    for v in bm.verts:
        cord = location_3d_to_region_2d(
            context.region,
            context.space_data.region_3d,
            self.matr * v.co)
        blf.position(font_id, cord[0], cord[1], 0)
        blf.size(font_id, self.tsize, 72)
        blf.draw(font_id, str(v.index)) 
Example #28
Source File: archipack_polylines.py    From archipack with GNU General Public License v3.0 5 votes vote down vote up
def _position_2d_from_coord(self, context, coord):
        """ coord given in local input coordsys
        """
        region = context.region
        rv3d = context.region_data
        loc = view3d_utils.location_3d_to_region_2d(region, rv3d, self.coordsys.world * coord)
        x, y = loc
        return Vector((x, y)) 
Example #29
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 5 votes vote down vote up
def position_2d_from_coord(self, context, coord, render=False):
        """ coord given in local input coordsys
        """
        if self.d == 2:
            return Vector(coord)
        if render:
            return self.get_render_location(context, coord)
        region = context.region
        rv3d = context.region_data
        loc = view3d_utils.location_3d_to_region_2d(region, rv3d, coord, self.pos_2d)
        return Vector(loc) 
Example #30
Source File: offscreen.py    From jewelcraft with GNU General Public License v3.0 5 votes vote down vote up
def loc_3d_to_2d(region, region_3d, loc, ratio_w, ratio_h):
    x, y = location_3d_to_region_2d(region, region_3d, loc)
    return x * ratio_w, y * ratio_h