当前位置: 首页>>代码示例>>Python>>正文


Python view3d_utils.region_2d_to_vector_3d方法代码示例

本文整理汇总了Python中bpy_extras.view3d_utils.region_2d_to_vector_3d方法的典型用法代码示例。如果您正苦于以下问题:Python view3d_utils.region_2d_to_vector_3d方法的具体用法?Python view3d_utils.region_2d_to_vector_3d怎么用?Python view3d_utils.region_2d_to_vector_3d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bpy_extras.view3d_utils的用法示例。


在下文中一共展示了view3d_utils.region_2d_to_vector_3d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pan

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [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

示例2: get_mouse_raycast

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def get_mouse_raycast(context, objects_list, coords_2d, ray_max=10000.0):
    region = context.region
    rv3d = context.region_data

    best_obj, hit_normal, hit_position = None, None, None
    best_length_squared = 20000.0 * 20000.0

    # get the ray from the viewport and mouse
    view_vector = view3d_utils.region_2d_to_vector_3d(
        region, rv3d, coords_2d)
    ray_origin = view3d_utils.region_2d_to_origin_3d(
        region, rv3d, coords_2d)

    for obj, matrix in objects_list:
        # Do RayCast! t1,t2,t3,t4 - temp values
        t1, t2, t3 = obj_raycast(
            obj, matrix, view_vector, ray_origin, ray_max)
        if t1 is not None and t3 < best_length_squared:
            best_obj, hit_normal, hit_position = obj, t1, t2
            best_length_squared = t3

    return best_obj, hit_normal, hit_position


# mesh picking from 3d space 
开发者ID:mifth,项目名称:mifthtools,代码行数:27,代码来源:mi_utils_base.py

示例3: get_mouse_on_plane

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def get_mouse_on_plane(context, plane_pos, plane_dir, mouse_coords):
    region = context.region
    rv3d = context.region_data

    final_dir = plane_dir
    if plane_dir is None:
        final_dir = rv3d.view_rotation * Vector((0.0, 0.0, -1.0))

    mouse_pos = view3d_utils.region_2d_to_origin_3d(region, rv3d, mouse_coords)
    mouse_dir = view3d_utils.region_2d_to_vector_3d(region, rv3d, mouse_coords)
    new_pos = mathu.geometry.intersect_line_plane(
        mouse_pos, mouse_pos + (mouse_dir * 10000.0), plane_pos, final_dir, False)
    if new_pos:
        return new_pos

    return None


# get object local axys 
开发者ID:mifth,项目名称:mifthtools,代码行数:21,代码来源:mi_utils_base.py

示例4: get_mouse_on_plane

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def get_mouse_on_plane(context, plane_pos, plane_dir, mouse_coords):
    region = context.region
    rv3d = context.region_data

    final_dir = plane_dir
    if plane_dir is None:
        final_dir = rv3d.view_rotation @ Vector((0.0, 0.0, -1.0))

    mouse_pos = view3d_utils.region_2d_to_origin_3d(region, rv3d, mouse_coords)
    mouse_dir = view3d_utils.region_2d_to_vector_3d(region, rv3d, mouse_coords)
    new_pos = mathu.geometry.intersect_line_plane(
        mouse_pos, mouse_pos + (mouse_dir * 10000.0), plane_pos, final_dir, False)
    if new_pos:
        return new_pos

    return None


# get object local axys 
开发者ID:mifth,项目名称:mifthtools,代码行数:21,代码来源:mi_utils_base.py

示例5: get_pos3d

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def get_pos3d(self, context):
        """
            convert mouse pos to 3d point over plane defined by origin and normal
            pt is in world space
        """
        region = context.region
        rv3d = context.region_data
        rM = context.active_object.matrix_world.to_3x3()
        view_vector_mouse = view3d_utils.region_2d_to_vector_3d(region, rv3d, self.mouse_pos)
        ray_origin_mouse = view3d_utils.region_2d_to_origin_3d(region, rv3d, self.mouse_pos)
        pt = intersect_line_plane(ray_origin_mouse, ray_origin_mouse + view_vector_mouse,
            self.origin, rM * self.manipulator.normal, False)
        # fix issue with parallel plane
        if pt is None:
            pt = intersect_line_plane(ray_origin_mouse, ray_origin_mouse + view_vector_mouse,
                self.origin, view_vector_mouse, False)
        return pt 
开发者ID:s-leger,项目名称:archipack,代码行数:19,代码来源:archipack_manipulator.py

示例6: get_pos3d

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def get_pos3d(self, context, normal=Vector((0, 0, 1))):
        """
            convert mouse pos to 3d point over plane defined by origin and normal
            pt is in world space
        """
        region = context.region
        rv3d = context.region_data
        view_vector_mouse = view3d_utils.region_2d_to_vector_3d(region, rv3d, self.mouse_pos)
        ray_origin_mouse = view3d_utils.region_2d_to_origin_3d(region, rv3d, self.mouse_pos)
        pt = intersect_line_plane(ray_origin_mouse, ray_origin_mouse + view_vector_mouse,
            self.origin, normal, False)
        # fix issue with parallel plane
        if pt is None:
            pt = intersect_line_plane(ray_origin_mouse, ray_origin_mouse + view_vector_mouse,
                self.origin, view_vector_mouse, False)
        return pt 
开发者ID:s-leger,项目名称:archipack,代码行数:18,代码来源:archipack_custom.py

示例7: screen_to_world

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def screen_to_world(context, x, y):
    depth_vector = view3d_utils.region_2d_to_vector_3d(\
        context.region, context.region_data, [x,y])
    vector = view3d_utils.region_2d_to_location_3d(\
        context.region, context.region_data, [x,y], depth_vector)

    return(vector)


# turn 3d world coordinates vector into screen coordinate integers (x,y) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:animation_motion_trail.py

示例8: Pick

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def Pick(context, event, self, ray_max=10000.0):
    scene = context.scene
    region = context.region
    rv3d = context.region_data
    coord = event.mouse_region_x, event.mouse_region_y
    view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
    ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
    ray_target = ray_origin + (view_vector * ray_max)

    def obj_ray_cast(obj, matrix):
        matrix_inv = matrix.inverted()
        ray_origin_obj = matrix_inv * ray_origin
        ray_target_obj = matrix_inv * ray_target
        success, hit, normal, face_index = obj.ray_cast(ray_origin_obj, ray_target_obj)
        if success:
            return hit, normal, face_index
        else:
            return None, None, None

    best_length_squared = ray_max * ray_max
    best_obj = None
    for obj in self.CList:
        matrix = obj.matrix_world
        hit, normal, face_index = obj_ray_cast(obj, matrix)
        if hit is not None:
            hit_world = matrix * hit
            length_squared = (hit_world - ray_origin).length_squared
            if length_squared < best_length_squared:
                best_length_squared = length_squared
                best_obj = obj
                hits = hit_world
                ns = normal
                fs = face_index

    if best_obj is not None:
        return hits, ns, fs
    else:
        return None, None, None 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:40,代码来源:mesh_carver.py

示例9: Point2D_to_Ray

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def Point2D_to_Ray(self, p2d):
        o = Point(region_2d_to_origin_3d(self.rgn, self.r3d, p2d))
        d = Direction(region_2d_to_vector_3d(self.rgn, self.r3d, p2d))
        return Ray(o, d) 
开发者ID:CGCookie,项目名称:addon_common,代码行数:6,代码来源:drawing.py

示例10: region_2d_to_orig_and_vect

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def region_2d_to_orig_and_vect(self, context, event):

        region = context.region
        rv3d = context.region_data
        coord = (event.mouse_region_x, event.mouse_region_y)

        vec = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
        orig = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)

        return rv3d.is_perspective, orig, vec 
开发者ID:s-leger,项目名称:archipack,代码行数:12,代码来源:archipack_object.py

示例11: _position_3d_from_coord

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def _position_3d_from_coord(self, context, coord):
        """return point in local input coordsys
        """
        region = context.region
        rv3d = context.region_data
        view_vector_mouse = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
        ray_origin_mouse = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
        loc = intersect_line_plane(ray_origin_mouse, ray_origin_mouse + view_vector_mouse,
                                   Vector((0, 0, 0)), Vector((0, 0, 1)), False)
        x, y, z = self.coordsys.invert * loc
        return Vector((x, y, z)) 
开发者ID:s-leger,项目名称:archipack,代码行数:13,代码来源:archipack_polylines.py

示例12: mouse_coo_to_3d_loc

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def mouse_coo_to_3d_loc(event, context):
    from bpy_extras.view3d_utils import region_2d_to_vector_3d, region_2d_to_location_3d
    coord = event.mouse_region_x, event.mouse_region_y
    region = context.region
    rv3d = context.space_data.region_3d
    vec = region_2d_to_vector_3d(region, rv3d, coord)
    loc = region_2d_to_location_3d(region, rv3d, coord, vec)
    return loc 
开发者ID:pelednoam,项目名称:mmvt,代码行数:10,代码来源:mmvt_utils.py

示例13: mouse_raycast

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def mouse_raycast(context, mx, my):
    r = context.region
    rv3d = context.region_data
    coord = mx, my

    # get the ray from the viewport and mouse
    view_vector = view3d_utils.region_2d_to_vector_3d(r, rv3d, coord)
    ray_origin = view3d_utils.region_2d_to_origin_3d(r, rv3d, coord)
    ray_target = ray_origin + (view_vector * 1000000000)

    vec = ray_target - ray_origin

    has_hit, snapped_location, snapped_normal, face_index, object, matrix = bpy.context.scene.ray_cast(
        bpy.context.view_layer, ray_origin, vec)

    randoffset = math.pi
    if has_hit:
        snapped_rotation = snapped_normal.to_track_quat('Z', 'Y').to_euler()
        up = Vector((0, 0, 1))
        props = bpy.context.scene.luxcoreOL.model
        if props.randomize_rotation and snapped_normal.angle(up) < math.radians(10.0):
            randoffset = props.offset_rotation_amount + math.pi + (
                    random.random() - 0.5) * props.randomize_rotation_amount
        else:
            randoffset = props.offset_rotation_amount  # we don't rotate this way on walls and ceilings. + math.pi
        # snapped_rotation.z += math.pi + (random.random() - 0.5) * .2
    else:
        snapped_rotation = mathutils.Quaternion((0, 0, 0, 0)).to_euler()

    snapped_rotation.rotate_axis('Z', randoffset)

    return has_hit, snapped_location, snapped_normal, snapped_rotation, face_index, object, matrix 
开发者ID:LuxCoreRender,项目名称:BlendLuxCore,代码行数:34,代码来源:viewport.py

示例14: floor_raycast

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def floor_raycast(context, mx, my):
    r = context.region
    rv3d = context.region_data
    coord = mx, my

    # get the ray from the viewport and mouse
    view_vector = view3d_utils.region_2d_to_vector_3d(r, rv3d, coord)
    ray_origin = view3d_utils.region_2d_to_origin_3d(r, rv3d, coord)
    ray_target = ray_origin + (view_vector * 1000)

    # various intersection plane normals are needed for corner cases that might actually happen quite often - in front and side view.
    # default plane normal is scene floor.
    plane_normal = (0, 0, 1)
    if math.isclose(view_vector.x, 0, abs_tol=1e-4) and math.isclose(view_vector.z, 0, abs_tol=1e-4):
        plane_normal = (0, 1, 0)
    elif math.isclose(view_vector.z, 0, abs_tol=1e-4):
        plane_normal = (1, 0, 0)

    snapped_location = mathutils.geometry.intersect_line_plane(ray_origin, ray_target, (0, 0, 0), plane_normal,
                                                               False)
    if snapped_location != None:
        has_hit = True
        snapped_normal = Vector((0, 0, 1))
        face_index = None
        object = None
        matrix = None
        snapped_rotation = snapped_normal.to_track_quat('Z', 'Y').to_euler()

        props = bpy.context.scene.luxcoreOL.model
        if props.randomize_rotation:
            randoffset = props.offset_rotation_amount + math.pi + (
                    random.random() - 0.5) * props.randomize_rotation_amount
        else:
            randoffset = props.offset_rotation_amount + math.pi

        snapped_rotation.rotate_axis('Z', randoffset)

    return has_hit, snapped_location, snapped_normal, snapped_rotation, face_index, object, matrix 
开发者ID:LuxCoreRender,项目名称:BlendLuxCore,代码行数:40,代码来源:viewport.py

示例15: mouseTo3d

# 需要导入模块: from bpy_extras import view3d_utils [as 别名]
# 或者: from bpy_extras.view3d_utils import region_2d_to_vector_3d [as 别名]
def mouseTo3d(context, x, y):
	'''Convert event.mouse_region to world coordinates'''
	if context.area.type != 'VIEW_3D':
		raise Exception('Wrong context')
	coords = (x, y)
	reg = context.region
	reg3d = context.region_data
	vec = region_2d_to_vector_3d(reg, reg3d, coords)
	loc = region_2d_to_location_3d(reg, reg3d, coords, vec) #WARNING, this function return indeterminate value when view3d clip distance is too large
	return loc 
开发者ID:domlysz,项目名称:BlenderGIS,代码行数:12,代码来源:bgis_utils.py


注:本文中的bpy_extras.view3d_utils.region_2d_to_vector_3d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。