當前位置: 首頁>>代碼示例>>Python>>正文


Python view3d_utils.location_3d_to_region_2d方法代碼示例

本文整理匯總了Python中bpy_extras.view3d_utils.location_3d_to_region_2d方法的典型用法代碼示例。如果您正苦於以下問題:Python view3d_utils.location_3d_to_region_2d方法的具體用法?Python view3d_utils.location_3d_to_region_2d怎麽用?Python view3d_utils.location_3d_to_region_2d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bpy_extras.view3d_utils的用法示例。


在下文中一共展示了view3d_utils.location_3d_to_region_2d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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)) 
開發者ID:CreativeDesigner3D,項目名稱:BlenderPro,代碼行數:19,代碼來源:opengl.py

示例2: pan

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:sketchpunk,項目名稱:android3dblendermouse,代碼行數:19,代碼來源:3dmouse_plugin_alpha.py

示例3: pick_surf

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:23,代碼來源:mi_curve_surfaces.py

示例4: pick_curve_point

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:22,代碼來源:mi_curve_main.py

示例5: pick_curve_points_box

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:23,代碼來源:mi_curve_main.py

示例6: pick_lw_point

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:23,代碼來源:mi_widget_linear_deform.py

示例7: snap_to_surface

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:mifth,項目名稱:mifthtools,代碼行數:18,代碼來源:mi_curve_main.py

示例8: draw_3d_points

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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 
開發者ID:patmo141,項目名稱:object_alignment,代碼行數:23,代碼來源:utilities.py

示例9: draw_gedge_text

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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) 
開發者ID:CGCookie,項目名稱:retopology-polystrips,代碼行數:16,代碼來源:polystrips_draw.py

示例10: ready_tool

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
def ready_tool(self, eventd, tool_fn):
        rgn   = eventd['context'].region
        r3d   = eventd['context'].space_data.region_3d
        mx,my = eventd['mouse']
        if self.sel_gvert:
            loc   = self.sel_gvert.position
            cx,cy = location_3d_to_region_2d(rgn, r3d, loc)
        elif self.sel_gedge:
            loc   = (self.sel_gedge.gvert0.position + self.sel_gedge.gvert3.position) / 2.0
            cx,cy = location_3d_to_region_2d(rgn, r3d, loc)
        else:
            cx,cy = mx-100,my
        rad   = math.sqrt((mx-cx)**2 + (my-cy)**2)

        self.action_center = (cx,cy)
        self.mode_start    = (mx,my)
        self.action_radius = rad
        self.mode_radius   = rad
        
        self.prev_pos      = (mx,my)

        # spc = bpy.data.window_managers['WinMan'].windows[0].screen.areas[4].spaces[0]
        # r3d = spc.region_3d
        vrot = r3d.view_rotation
        self.tool_x = (vrot * Vector((1,0,0))).normalized()
        self.tool_y = (vrot * Vector((0,1,0))).normalized()

        self.tool_rot = 0.0

        self.tool_fn = tool_fn
        self.tool_fn('init', eventd) 
開發者ID:CGCookie,項目名稱:retopology-polystrips,代碼行數:33,代碼來源:__init__.py

示例11: grab_tool_gvert_list

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
def grab_tool_gvert_list(self, command, eventd, lgv):
        '''
        translates list of gverts
        note: translation is relative to first gvert
        '''

        def l3dr2d(p): return location_3d_to_region_2d(eventd['region'], eventd['r3d'], p)

        if command == 'init':
            self.footer = 'Translating GVert position(s)'
            s2d = l3dr2d(lgv[0].position)
            self.tool_data = [(gv, Vector(gv.position), l3dr2d(gv.position)-s2d) for gv in lgv]
        elif command == 'commit':
            pass
        elif command == 'undo':
            for gv,p,_ in self.tool_data: gv.position = p
            for gv,_,_ in self.tool_data:
                gv.update()
                gv.update_visibility(eventd['r3d'], update_gedges=True)
        else:
            factor_slow,factor_fast = 0.2,1.0
            dv = Vector(command) * (factor_slow if eventd['shift'] else factor_fast)
            s2d = l3dr2d(self.tool_data[0][0].position)
            lgv2d = [s2d+relp+dv for _,_,relp in self.tool_data]
            pts = common_utilities.ray_cast_path(eventd['context'], self.obj, lgv2d)
            if len(pts) != len(lgv2d): return ''
            for d,p2d in zip(self.tool_data, pts):
                d[0].position = p2d
            for gv,_,_ in self.tool_data:
                gv.update()
                gv.update_visibility(eventd['r3d'], update_gedges=True) 
開發者ID:CGCookie,項目名稱:retopology-polystrips,代碼行數:33,代碼來源:__init__.py

示例12: get_2d_point

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
def get_2d_point(region, rv3d, point3d):
    if rv3d is not None and region is not None:
        return view3d_utils.location_3d_to_region_2d(region, rv3d, point3d)
    else:
        return get_render_location(point3d) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:opengl_dim.py

示例13: getscreencoords

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
def getscreencoords(self, vec, reg, rv3d):
	
		# calculate screencoords of given Vector
		vec.rotate(self.selobj.matrix_world)
		vec.rotate(self.selobj.matrix_world)
		vec =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()
		return location_3d_to_region_2d(reg, rv3d, vec) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:object_fastorigin.py

示例14: modal

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
def modal(self, context, event):
        em = bpy.data.objects['Empty for BProjection']
        sd = context.space_data

        center = view3d_utils.location_3d_to_region_2d(context.region, sd.region_3d, em.location if
                                                       em.custom_rotc3d else context.scene.cursor_location)
        vec_init = self.first_mouse - center
        vec_act = Vector((event.mouse_region_x, event.mouse_region_y)) - center
        rot = -vec_init.angle_signed(vec_act) * 180 / pi

        if event.shift:
            rot = rot
        else:
            rot = int(rot)

        if event.ctrl:
            rot = int(rot / 5) * 5

        if event.type == 'MOUSEMOVE':

            em.custom_rotation = self.first_rotation + rot

        if event.type == 'LEFTMOUSE':
            return {'FINISHED'}

        if event.type == 'ESC' or event.type == 'RIGHTMOUSE':
            em.custom_rotation = self.first_rotation
            return {'FINISHED'}

        return {'RUNNING_MODAL'} 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:32,代碼來源:space_view3d_paint_bprojection.py

示例15: get_snap_point

# 需要導入模塊: from bpy_extras import view3d_utils [as 別名]
# 或者: from bpy_extras.view3d_utils import location_3d_to_region_2d [as 別名]
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) 
開發者ID:CreativeDesigner3D,項目名稱:BlenderPro,代碼行數:35,代碼來源:view3d_ops.py


注:本文中的bpy_extras.view3d_utils.location_3d_to_region_2d方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。