Blender V4.3
view3d_utils.cc File Reference
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include "DNA_camera_types.h"
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_world_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_array_utils.h"
#include "BLI_bitmap_draw_2d.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "BKE_camera.h"
#include "BKE_context.hh"
#include "BKE_object.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "GPU_matrix.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "ED_keyframing.hh"
#include "ED_screen.hh"
#include "ED_undo.hh"
#include "ED_view3d.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "UI_resources.hh"
#include "view3d_intern.hh"

Go to the source code of this file.

Classes

struct  PointsInPlanesMinMax_UserData
 
struct  View3D_AutoDistLast
 
struct  ReadData
 

Functions

View Data Access Utilities
void ED_view3d_background_color_get (const Scene *scene, const View3D *v3d, float r_color[3])
 
void ED_view3d_text_colors_get (const Scene *scene, const View3D *v3d, float r_text_color[4], float r_shadow_color[4])
 
bool ED_view3d_has_workbench_in_texture_color (const Scene *scene, const Object *ob, const View3D *v3d)
 
CameraED_view3d_camera_data_get (View3D *v3d, RegionView3D *rv3d)
 
void ED_view3d_dist_range_get (const View3D *v3d, float r_dist_range[2])
 
bool ED_view3d_clip_range_get (const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, const bool use_ortho_factor, float *r_clip_start, float *r_clip_end)
 
bool ED_view3d_viewplane_get (const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, int winx, int winy, rctf *r_viewplane, float *r_clip_start, float *r_clip_end, float *r_pixsize)
 
View State/Context Utilities
void view3d_operator_needs_opengl (const bContext *C)
 
void view3d_region_operator_needs_opengl (wmWindow *, ARegion *region)
 
void ED_view3d_polygon_offset (const RegionView3D *rv3d, const float dist)
 
bool ED_view3d_context_activate (bContext *C)
 
View Clipping Utilities
void ED_view3d_clipping_calc_from_boundbox (float clip[4][4], const BoundBox *bb, const bool is_flip)
 
void ED_view3d_clipping_calc (BoundBox *bb, float planes[4][4], const ARegion *region, const Object *ob, const rcti *rect)
 
View Clipping Clamp Min/Max
static void points_in_planes_minmax_fn (const float co[3], int, int, int, void *user_data_p)
 
bool ED_view3d_clipping_clamp_minmax (const RegionView3D *rv3d, float min[3], float max[3])
 
View Bound-Box Utilities
static bool view3d_boundbox_clip_m4 (const BoundBox *bb, const float persmatob[4][4])
 
bool ED_view3d_boundbox_clip_ex (const RegionView3D *rv3d, const BoundBox *bb, float obmat[4][4])
 
bool ED_view3d_boundbox_clip (RegionView3D *rv3d, const BoundBox *bb)
 
View Perspective & Mode Switching

Misc view utility functions.

bool ED_view3d_offset_lock_check (const View3D *v3d, const RegionView3D *rv3d)
 
void ED_view3d_lastview_store (RegionView3D *rv3d)
 
void ED_view3d_lock_clear (View3D *v3d)
 
void ED_view3d_persp_switch_from_camera (const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, const char persp)
 
bool ED_view3d_persp_ensure (const Depsgraph *depsgraph, View3D *v3d, ARegion *region)
 
Camera View Utilities

Utilities for manipulating the camera-view.

bool ED_view3d_camera_view_zoom_scale (RegionView3D *rv3d, const float scale)
 
bool ED_view3d_camera_view_pan (ARegion *region, const float event_ofs[2])
 
Camera Lock API

Lock the camera to the 3D Viewport, allowing view manipulation to transform the camera.

bool ED_view3d_camera_lock_check (const View3D *v3d, const RegionView3D *rv3d)
 
void ED_view3d_camera_lock_init_ex (const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, const bool calc_dist)
 
void ED_view3d_camera_lock_init (const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
 
bool ED_view3d_camera_lock_sync (const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
 
bool ED_view3d_camera_autokey (const Scene *scene, ID *id_key, bContext *C, const bool do_rotate, const bool do_translate)
 
bool ED_view3d_camera_lock_autokey (View3D *v3d, RegionView3D *rv3d, bContext *C, const bool do_rotate, const bool do_translate)
 
bool ED_view3d_camera_lock_undo_test (const View3D *v3d, const RegionView3D *rv3d, bContext *C)
 
static bool view3d_camera_lock_undo_ex (const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C, const bool undo_group)
 
bool ED_view3d_camera_lock_undo_push (const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
 
bool ED_view3d_camera_lock_undo_grouped_push (const char *str, const View3D *v3d, const RegionView3D *rv3d, bContext *C)
 
Box View Support

Use with quad-split so each view is clipped by the bounds of each view axis.

static void view3d_boxview_clip (ScrArea *area)
 
static void view3d_boxview_sync_axis (RegionView3D *rv3d_dst, RegionView3D *rv3d_src)
 
void view3d_boxview_sync (ScrArea *area, ARegion *region)
 
void view3d_boxview_copy (ScrArea *area, ARegion *region)
 
void ED_view3d_quadview_update (ScrArea *area, ARegion *region, bool do_clip)
 
View Auto-Depth Utilities
static float view_autodist_depth_margin (ARegion *region, const int mval[2], int margin)
 
bool ED_view3d_autodist (ARegion *region, View3D *v3d, const int mval[2], float mouse_worldloc[3], const float fallback_depth_pt[3])
 
bool ED_view3d_autodist_simple (ARegion *region, const int mval[2], float mouse_worldloc[3], int margin, const float *force_depth)
 
static bool depth_segment_cb (int x, int y, void *user_data)
 
bool ED_view3d_depth_read_cached_seg (const ViewDepths *vd, const int mval_sta[2], const int mval_end[2], int margin, float *r_depth)
 
View Radius/Distance Utilities

Use to calculate a distance to a point based on its radius.

float ED_view3d_radius_to_dist_persp (const float angle, const float radius)
 
float ED_view3d_radius_to_dist_ortho (const float lens, const float radius)
 
float ED_view3d_radius_to_dist (const View3D *v3d, const ARegion *region, const Depsgraph *depsgraph, const char persp, const bool use_aspect, const float radius)
 
View Distance Utilities
float ED_view3d_offset_distance (const float mat[4][4], const float ofs[3], const float fallback_dist)
 
void ED_view3d_distance_set (RegionView3D *rv3d, const float dist)
 
bool ED_view3d_distance_set_from_location (RegionView3D *rv3d, const float dist_co[3], const float dist_min)
 
View Transform Utilities
void ED_view3d_from_m4 (const float mat[4][4], float ofs[3], float quat[4], const float *dist)
 
void ED_view3d_to_m4 (float mat[4][4], const float ofs[3], const float quat[4], const float dist)
 
void ED_view3d_from_object (const Object *ob, float ofs[3], float quat[4], const float *dist, float *lens)
 
void ED_view3d_to_object (const Depsgraph *depsgraph, Object *ob, const float ofs[3], const float quat[4], const float dist)
 
static bool view3d_camera_to_view_selected_impl (Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob, float *r_clip_start, float *r_clip_end)
 
bool ED_view3d_camera_to_view_selected (Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob)
 
bool ED_view3d_camera_to_view_selected_with_set_clipping (Main *bmain, Depsgraph *depsgraph, const Scene *scene, Object *camera_ob)
 
Depth Buffer Utilities
static bool depth_read_test_fn (const void *value, void *userdata)
 
bool ED_view3d_depth_read_cached (const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
 
bool ED_view3d_depth_read_cached_normal (const ARegion *region, const ViewDepths *depths, const int mval[2], float r_normal[3])
 
bool ED_view3d_depth_unproject_v3 (const ARegion *region, const int mval[2], const double depth, float r_location_world[3])
 

View Auto-Depth Last State Access

Calling consecutive trackpad gestures reuses the previous offset to prevent each trackpad event using a different offset, see: #103263.

static const char * view3d_autodepth_last_id = "view3d_autodist_last"
 
bool ED_view3d_autodist_last_check (wmWindow *win, const wmEvent *event)
 
void ED_view3d_autodist_last_clear (wmWindow *win)
 
void ED_view3d_autodist_last_set (wmWindow *win, const wmEvent *event, const float ofs[3], const bool has_depth)
 
bool ED_view3d_autodist_last_get (wmWindow *win, float r_ofs[3])
 

View Axis Utilities

static float view3d_quat_axis [6][4][4]
 
bool ED_view3d_quat_from_axis_view (const char view, const char view_axis_roll, float r_quat[4])
 
bool ED_view3d_quat_to_axis_view (const float quat[4], const float epsilon, char *r_view, char *r_view_axis_roll)
 
bool ED_view3d_quat_to_axis_view_and_reset_quat (float quat[4], const float epsilon, char *r_view, char *r_view_axis_roll)
 
char ED_view3d_lock_view_from_index (int index)
 
char ED_view3d_axis_view_opposite (char view)
 
bool ED_view3d_lock (RegionView3D *rv3d)
 

Detailed Description

3D View checks and manipulation (no operators).

Definition in file view3d_utils.cc.

Function Documentation

◆ depth_read_test_fn()

static bool depth_read_test_fn ( const void * value,
void * userdata )
static

Definition at line 1730 of file view3d_utils.cc.

References ReadData::r_depth.

Referenced by ED_view3d_depth_read_cached().

◆ depth_segment_cb()

static bool depth_segment_cb ( int x,
int y,
void * user_data )
static

Definition at line 1199 of file view3d_utils.cc.

References ED_view3d_depth_read_cached(), x, and y.

Referenced by ED_view3d_depth_read_cached_seg().

◆ ED_view3d_autodist()

bool ED_view3d_autodist ( ARegion * region,
View3D * v3d,
const int mval[2],
float mouse_worldloc[3],
const float fallback_depth_pt[3] )

Get the world-space 3D location from a screen-space 2D point. It may be useful to call ED_view3d_depth_override before.

Parameters
mvalInput screen-space pixel location.
mouse_worldlocOutput world-space location.
fallback_depth_ptUse this points depth when no depth can be found.

Definition at line 1142 of file view3d_utils.cc.

References ARRAY_SIZE, ED_view3d_unproject_v3(), ED_view3d_win_to_3d_int(), float, FLT_MAX, and view_autodist_depth_margin().

Referenced by depthdropper_depth_sample_pt(), ED_view3d_cursor3d_position(), navigate_pivot_get(), paint_proj_stroke(), and viewcenter_pick_invoke().

◆ ED_view3d_autodist_last_check()

bool ED_view3d_autodist_last_check ( wmWindow * win,
const wmEvent * event )

Check if the last auto-dist can be used.

Definition at line 1062 of file view3d_utils.cc.

References wmEvent::flag, view3d_autodepth_last_id, WM_event_consecutive_data_get(), and WM_EVENT_IS_CONSECUTIVE.

Referenced by navigate_pivot_get().

◆ ED_view3d_autodist_last_clear()

void ED_view3d_autodist_last_clear ( wmWindow * win)

Clear and free auto-dist data.

Definition at line 1074 of file view3d_utils.cc.

References WM_event_consecutive_data_free().

Referenced by ED_view3d_autodist_last_set(), and navigate_pivot_get().

◆ ED_view3d_autodist_last_get()

bool ED_view3d_autodist_last_get ( wmWindow * win,
float r_ofs[3] )
Returns
true when r_ofs is set.
Warning
ED_view3d_autodist_last_check should be called first to ensure the data is available.

Definition at line 1097 of file view3d_utils.cc.

References BLI_assert, copy_v3_v3(), View3D_AutoDistLast::has_depth, View3D_AutoDistLast::ofs, view3d_autodepth_last_id, WM_event_consecutive_data_get(), and zero_v3().

Referenced by navigate_pivot_get().

◆ ED_view3d_autodist_last_set()

void ED_view3d_autodist_last_set ( wmWindow * win,
const wmEvent * event,
const float ofs[3],
const bool has_depth )

◆ ED_view3d_autodist_simple()

bool ED_view3d_autodist_simple ( ARegion * region,
const int mval[2],
float mouse_worldloc[3],
int margin,
const float * force_depth )

◆ ED_view3d_axis_view_opposite()

char ED_view3d_axis_view_opposite ( char view)

◆ ED_view3d_background_color_get()

◆ ED_view3d_boundbox_clip()

bool ED_view3d_boundbox_clip ( RegionView3D * rv3d,
const BoundBox * bb )

Definition at line 461 of file view3d_utils.cc.

References RegionView3D::persmatob, and view3d_boundbox_clip_m4().

◆ ED_view3d_boundbox_clip_ex()

bool ED_view3d_boundbox_clip_ex ( const RegionView3D * rv3d,
const BoundBox * bb,
float obmat[4][4] )

Definition at line 446 of file view3d_utils.cc.

References mul_m4_m4m4(), RegionView3D::persmat, and view3d_boundbox_clip_m4().

◆ ED_view3d_camera_autokey()

bool ED_view3d_camera_autokey ( const Scene * scene,
ID * id_key,
bContext * C,
const bool do_rotate,
const bool do_translate )

◆ ED_view3d_camera_data_get()

Camera * ED_view3d_camera_data_get ( View3D * v3d,
RegionView3D * rv3d )

◆ ED_view3d_camera_lock_autokey()

bool ED_view3d_camera_lock_autokey ( View3D * v3d,
RegionView3D * rv3d,
bContext * C,
bool do_rotate,
bool do_translate )

◆ ED_view3d_camera_lock_check()

◆ ED_view3d_camera_lock_init()

void ED_view3d_camera_lock_init ( const Depsgraph * depsgraph,
View3D * v3d,
RegionView3D * rv3d )

◆ ED_view3d_camera_lock_init_ex()

void ED_view3d_camera_lock_init_ex ( const Depsgraph * depsgraph,
View3D * v3d,
RegionView3D * rv3d,
bool calc_dist )

Copy the camera to the view before starting a view transformation.

Apply the camera object transformation to the 3D Viewport. (needed so we can use regular 3D Viewport manipulation operators, that sync back to the camera).

Definition at line 594 of file view3d_utils.cc.

References View3D::camera, DEG_get_evaluated_object(), depsgraph, RegionView3D::dist, ED_view3d_camera_lock_check(), ED_view3d_from_object(), ED_view3d_offset_distance(), RegionView3D::ofs, VIEW3D_DIST_FALLBACK, and RegionView3D::viewquat.

Referenced by ED_view3d_camera_lock_init(), and ViewOpsData::init_navigation().

◆ ED_view3d_camera_lock_sync()

◆ ED_view3d_camera_lock_undo_grouped_push()

bool ED_view3d_camera_lock_undo_grouped_push ( const char * str,
const View3D * v3d,
const RegionView3D * rv3d,
bContext * C )

A version of ED_view3d_camera_lock_undo_push that performs a grouped undo push.

Note
use for actions that are likely to be repeated such as mouse wheel to zoom, where adding a separate undo step each time isn't desirable.

Definition at line 772 of file view3d_utils.cc.

References str, and view3d_camera_lock_undo_ex().

Referenced by ED_view3d_smooth_view_undo_end(), and viewzoom_exec().

◆ ED_view3d_camera_lock_undo_push()

bool ED_view3d_camera_lock_undo_push ( const char * str,
const View3D * v3d,
const RegionView3D * rv3d,
bContext * C )

Create an undo step when the camera is locked to the view.

Parameters
strThe name of the undo step (typically wmOperatorType.name should be used).
Returns
true when the call to push an undo step was made.

Definition at line 764 of file view3d_utils.cc.

References str, and view3d_camera_lock_undo_ex().

Referenced by ED_view3d_smooth_view_undo_end(), fly_modal(), view3d_navigate_modal_fn(), viewdolly_modal(), and walk_modal().

◆ ED_view3d_camera_lock_undo_test()

bool ED_view3d_camera_lock_undo_test ( const View3D * v3d,
const RegionView3D * rv3d,
bContext * C )

Check if creating an undo step should be performed if the viewport moves.

Returns
true if ED_view3d_camera_lock_undo_push would do an undo push.

Definition at line 728 of file view3d_utils.cc.

References ED_undo_is_memfile_compatible(), and ED_view3d_camera_lock_check().

Referenced by ED_view3d_smooth_view_undo_begin(), ED_view3d_smooth_view_undo_end(), and view3d_camera_lock_undo_ex().

◆ ED_view3d_camera_to_view_selected()

bool ED_view3d_camera_to_view_selected ( Main * bmain,
Depsgraph * depsgraph,
const Scene * scene,
Object * camera_ob )

◆ ED_view3d_camera_to_view_selected_with_set_clipping()

bool ED_view3d_camera_to_view_selected_with_set_clipping ( Main * bmain,
Depsgraph * depsgraph,
const Scene * scene,
Object * camera_ob )

◆ ED_view3d_camera_view_pan()

bool ED_view3d_camera_view_pan ( ARegion * region,
const float event_ofs[2] )

Utility to pan when in camera view.

Parameters
event_ofsThe offset the pan in screen (pixel) coordinates.
Returns
true when a change was made.

Definition at line 568 of file view3d_utils.cc.

References BKE_screen_view3d_zoom_to_fac(), RegionView3D::camdx, RegionView3D::camdy, RegionView3D::camzoom, and CLAMP.

Referenced by viewmove_apply().

◆ ED_view3d_camera_view_zoom_scale()

bool ED_view3d_camera_view_zoom_scale ( RegionView3D * rv3d,
const float scale )

Utility to scale zoom level when in camera-view RegionView3D.camzoom and apply limits.

Returns
true a change was made.

Definition at line 555 of file view3d_utils.cc.

References BKE_screen_view3d_zoom_from_fac(), BKE_screen_view3d_zoom_to_fac(), RegionView3D::camzoom, CLAMP, RV3D_CAMZOOM_MAX, RV3D_CAMZOOM_MAX_FACTOR, RV3D_CAMZOOM_MIN, and RV3D_CAMZOOM_MIN_FACTOR.

◆ ED_view3d_clip_range_get()

bool ED_view3d_clip_range_get ( const Depsgraph * depsgraph,
const View3D * v3d,
const RegionView3D * rv3d,
bool use_ortho_factor,
float * r_clip_start,
float * r_clip_end )

◆ ED_view3d_clipping_calc()

◆ ED_view3d_clipping_calc_from_boundbox()

void ED_view3d_clipping_calc_from_boundbox ( float clip[4][4],
const BoundBox * bb,
const bool is_flip )

◆ ED_view3d_clipping_clamp_minmax()

bool ED_view3d_clipping_clamp_minmax ( const RegionView3D * rv3d,
float min[3],
float max[3] )

Clamp min/max by the viewport clipping.

Note
This is an approximation, with the limitation that the bounding box from the (mix, max) calculation might not have any geometry inside the clipped region. Performing a clipping test on each vertex would work well enough for most cases, although it's not perfect either as edges/faces may intersect the clipping without having any of their vertices inside it. A more accurate result would be quite involved.
Returns
True when the arguments were clamped.

Definition at line 358 of file view3d_utils.cc.

References RegionView3D::clip, copy_v3_v3(), INIT_MINMAX, isect_planes_v3_fn(), PointsInPlanesMinMax_UserData::max, min, PointsInPlanesMinMax_UserData::min, negate_v4_v4(), points_in_planes_minmax_fn(), RV3D_BOXCLIP, RV3D_LOCK_FLAGS, and zero_v3().

Referenced by view3d_all_exec(), and viewselected_exec().

◆ ED_view3d_context_activate()

◆ ED_view3d_depth_read_cached()

◆ ED_view3d_depth_read_cached_normal()

◆ ED_view3d_depth_read_cached_seg()

bool ED_view3d_depth_read_cached_seg ( const ViewDepths * vd,
const int mval_sta[2],
const int mval_end[2],
int margin,
float * r_depth )

◆ ED_view3d_depth_unproject_v3()

◆ ED_view3d_dist_range_get()

void ED_view3d_dist_range_get ( const View3D * v3d,
float r_dist_range[2] )

◆ ED_view3d_distance_set()

void ED_view3d_distance_set ( RegionView3D * rv3d,
float dist )

Set the dist without moving the view (compensate with RegionView3D.ofs)

Note
take care that #RegionView3d.viewinv is up to date, ED_view3d_update_viewmat first.

Definition at line 1363 of file view3d_utils.cc.

References BLI_assert, copy_v3_fl3(), RegionView3D::dist, invert_qt_qt_normalized(), mul_mat3_m4_v3(), mul_qt_v3(), RegionView3D::ofs, sub_v3_v3(), RegionView3D::viewinv, and RegionView3D::viewquat.

Referenced by ED_view3d_cameracontrol_acquire(), and ED_view3d_cameracontrol_release().

◆ ED_view3d_distance_set_from_location()

bool ED_view3d_distance_set_from_location ( RegionView3D * rv3d,
const float dist_co[3],
float dist_min )

Change the distance & offset to match the depth of dist_co along the view axis.

Parameters
dist_coA world-space location to use for the new depth.
dist_minResulting distances below this will be ignored.
Returns
Success if the distance was set.

Definition at line 1383 of file view3d_utils.cc.

References RegionView3D::dist, dot_v3v3(), invert_qt_qt_normalized(), madd_v3_v3fl(), mul_qt_v3(), negate_v3_v3(), RegionView3D::ofs, sub_v3_v3v3(), and RegionView3D::viewquat.

◆ ED_view3d_from_m4()

void ED_view3d_from_m4 ( const float mat[4][4],
float ofs[3],
float quat[4],
const float * dist )

Set the view transformation from a 4x4 matrix.

Parameters
matThe view 4x4 transformation matrix to assign.
ofsThe view offset, normally from RegionView3D.ofs.
quatThe view rotation, quaternion normally from RegionView3D.viewquat.
distThe view distance from ofs, normally from RegionView3D.dist.

Definition at line 1577 of file view3d_utils.cc.

References BLI_assert, copy_m3_m4(), invert_qt_normalized(), madd_v3_v3fl(), mat3_normalized_to_quat(), negate_v3_v3(), and normalize_m3().

Referenced by ED_view3d_from_object(), and object_apply_mat4_with_protect().

◆ ED_view3d_from_object()

void ED_view3d_from_object ( const Object * ob,
float ofs[3],
float quat[4],
const float * dist,
float * lens )

Set the RegionView3D members from an objects transformation and optionally lens.

Parameters
obThe object to set the view to.
ofsThe view offset to be set, normally from RegionView3D.ofs.
quatThe view rotation to be set, quaternion normally from RegionView3D.viewquat.
distThe view distance from ofsto be set, normally from RegionView3D.dist.
lensThe view lens angle set for cameras and lights, normally from View3D.lens.

Definition at line 1613 of file view3d_utils.cc.

References BKE_camera_params_from_object(), BKE_camera_params_init(), ED_view3d_from_m4(), and params.

Referenced by axis_set_view(), ED_view3d_camera_lock_init_ex(), ED_view3d_persp_switch_from_camera(), and ED_view3d_smooth_view_ex().

◆ ED_view3d_has_workbench_in_texture_color()

◆ ED_view3d_lastview_store()

◆ ED_view3d_lock()

◆ ED_view3d_lock_clear()

void ED_view3d_lock_clear ( View3D * v3d)

◆ ED_view3d_lock_view_from_index()

char ED_view3d_lock_view_from_index ( int index)

◆ ED_view3d_offset_distance()

float ED_view3d_offset_distance ( const float mat[4][4],
const float ofs[3],
float fallback_dist )

This function solves the problem of having to switch between camera and non-camera views.

When viewing from the perspective of mat, and having the view center ofs, this calculates a distance from ofs to the matrix mat. Using fallback_dist when the distance would be too small.

Parameters
matA matrix use for the view-point (typically the camera objects matrix).
ofsOrbit center (negated), matching RegionView3D.ofs, which is typically passed in.
fallback_distThe distance to use if the object is too near or in front of ofs.
Returns
A newly calculated distance or the fallback.

Definition at line 1342 of file view3d_utils.cc.

References add_v3_v3(), dot_v3v3(), mul_m4_v4(), normalize_v3(), and pos.

Referenced by ED_view3d_camera_lock_init_ex(), ED_view3d_persp_switch_from_camera(), and ED_view3d_smooth_view_ex().

◆ ED_view3d_offset_lock_check()

bool ED_view3d_offset_lock_check ( const View3D * v3d,
const RegionView3D * rv3d )

◆ ED_view3d_persp_ensure()

bool ED_view3d_persp_ensure ( const Depsgraph * depsgraph,
View3D * v3d,
ARegion * region )

Action to take when rotating the view, handle auto-perspective and logic for switching out of views.

shared with NDOF.

Definition at line 520 of file view3d_utils.cc.

References BLI_assert, depsgraph, ED_view3d_camera_lock_check(), ED_view3d_persp_switch_from_camera(), RegionView3D::lpersp, RegionView3D::lview, RegionView3D::persp, RV3D_CAMOB, RV3D_LOCK_ANY_TRANSFORM, RV3D_LOCK_FLAGS, RV3D_PERSP, RV3D_VIEW_IS_AXIS, USER_AUTOPERSP, and RegionView3D::view.

Referenced by ViewOpsData::init_navigation().

◆ ED_view3d_persp_switch_from_camera()

void ED_view3d_persp_switch_from_camera ( const Depsgraph * depsgraph,
View3D * v3d,
RegionView3D * rv3d,
char persp )

For viewport operators that exit camera perspective.

Note
This differs from simply setting rv3d->persp = persp because it sets the ofs and dist values of the viewport so it matches the camera, otherwise switching out of camera view may jump to a different part of the scene.

Definition at line 501 of file view3d_utils.cc.

References BLI_assert, View3D::camera, DEG_get_evaluated_object(), depsgraph, RegionView3D::dist, ED_view3d_camera_lock_check(), ED_view3d_from_object(), ED_view3d_offset_distance(), RegionView3D::ofs, RegionView3D::persp, RV3D_CAMOB, VIEW3D_DIST_FALLBACK, and RegionView3D::viewquat.

Referenced by ED_view3d_persp_ensure(), view3d_zoom_border_exec(), and viewdolly_invoke().

◆ ED_view3d_polygon_offset()

void ED_view3d_polygon_offset ( const RegionView3D * rv3d,
float dist )

Use instead of: GPU_polygon_offset(rv3d->dist, ...) see bug #37727.

Definition at line 239 of file view3d_utils.cc.

References RegionView3D::dist, fabsf, GPU_polygon_offset(), RegionView3D::is_persp, max_ff(), RegionView3D::persp, RegionView3D::rflag, RV3D_CAMOB, RV3D_ZOFFSET_DISABLED, and RegionView3D::winmat.

◆ ED_view3d_quadview_update()

◆ ED_view3d_quat_from_axis_view()

bool ED_view3d_quat_from_axis_view ( const char view,
const char view_axis_roll,
float r_quat[4] )

◆ ED_view3d_quat_to_axis_view()

bool ED_view3d_quat_to_axis_view ( const float quat[4],
const float epsilon,
char * r_view,
char * r_view_axis_roll )

◆ ED_view3d_quat_to_axis_view_and_reset_quat()

bool ED_view3d_quat_to_axis_view_and_reset_quat ( float quat[4],
float epsilon,
char * r_view,
char * r_view_axis_roll )

A version of ED_view3d_quat_to_axis_view that updates quat if it's within epsilon to an axis-view.

Note
Include the special case function since most callers need to perform these operations.

Definition at line 1518 of file view3d_utils.cc.

References BLI_assert, ED_view3d_quat_from_axis_view(), ED_view3d_quat_to_axis_view(), and RV3D_VIEW_USER.

Referenced by view_roll_angle(), and viewrotate_apply_snap().

◆ ED_view3d_radius_to_dist()

float ED_view3d_radius_to_dist ( const View3D * v3d,
const ARegion * region,
const Depsgraph * depsgraph,
char persp,
bool use_aspect,
float radius )

Return a new RegionView3D.dist value to fit the radius.

Note
Depth isn't taken into account, this will fit a flat plane exactly, but points towards the view (with a perspective projection), may be within the radius but outside the view. eg:
          +
pt --> + /^ radius
        / |
       /  |
view  +   +
       \  |
        \ |
         |
          +
Parameters
regionCan be NULL if use_aspect is false.
perspAllow the caller to tell what kind of perspective to use (ortho/view/camera)
use_aspectIncrease the distance to account for non 1:1 view aspect.
radiusThe radius will be fitted exactly, typically pre-scaled by a margin (VIEW3D_MARGIN).

Definition at line 1262 of file view3d_utils.cc.

References atanf, BKE_camera_params_from_object(), BKE_camera_params_init(), BKE_camera_sensor_size(), BLI_assert, View3D::camera, CAMERA_PARAM_ZOOM_INIT_CAMOB, CAMERA_PARAM_ZOOM_INIT_PERSP, View3D::clip_end, View3D::clip_start, DEFAULT_SENSOR_WIDTH, DEG_get_evaluated_object(), depsgraph, ED_view3d_radius_to_dist_ortho(), ED_view3d_radius_to_dist_persp(), ELEM, focallength_to_fov(), View3D::lens, params, RV3D_CAMOB, RV3D_ORTHO, RV3D_PERSP, tanf, and RegionView3D::viewcamtexcofac.

Referenced by view3d_from_minmax(), and view3d_localview_init().

◆ ED_view3d_radius_to_dist_ortho()

float ED_view3d_radius_to_dist_ortho ( const float lens,
const float radius )

Definition at line 1257 of file view3d_utils.cc.

References DEFAULT_SENSOR_WIDTH.

Referenced by ED_view3d_radius_to_dist().

◆ ED_view3d_radius_to_dist_persp()

float ED_view3d_radius_to_dist_persp ( const float angle,
const float radius )

Definition at line 1252 of file view3d_utils.cc.

References tanf.

Referenced by ED_view3d_radius_to_dist().

◆ ED_view3d_text_colors_get()

void ED_view3d_text_colors_get ( const Scene * scene,
const View3D * v3d,
float r_text_color[4],
float r_shadow_color[4] )

◆ ED_view3d_to_m4()

void ED_view3d_to_m4 ( float mat[4][4],
const float ofs[3],
const float quat[4],
float dist )

Calculate the view transformation matrix from RegionView3D input. The resulting matrix is equivalent to RegionView3D.viewinv

Parameters
matThe view 4x4 transformation matrix to calculate.
ofsThe view offset, normally from RegionView3D.ofs.
quatThe view rotation, quaternion normally from RegionView3D.viewquat.
distThe view distance from ofs, normally from RegionView3D.dist.

Definition at line 1603 of file view3d_utils.cc.

References mul_mat3_m4_v3(), quat_to_mat4(), and sub_v3_v3v3().

Referenced by ED_view3d_camera_lock_sync(), ED_view3d_cameracontrol_acquire(), ED_view3d_cameracontrol_update(), and ED_view3d_to_object().

◆ ED_view3d_to_object()

void ED_view3d_to_object ( const Depsgraph * depsgraph,
Object * ob,
const float ofs[3],
const float quat[4],
float dist )

Set the object transformation from RegionView3D members.

Parameters
depsgraphThe depsgraph to get the evaluated object parent for the transformation calculation.
obThe object which has the transformation assigned.
ofsThe view offset, normally from RegionView3D.ofs.
quatThe view rotation, quaternion normally from RegionView3D.viewquat.
distThe view distance from ofs, normally from RegionView3D.dist.

Definition at line 1627 of file view3d_utils.cc.

References BKE_object_apply_mat4_ex(), DEG_get_evaluated_object(), depsgraph, ED_view3d_to_m4(), Object::parent, and Object::parentinv.

Referenced by ED_view3d_camera_lock_sync(), and view3d_camera_to_view_exec().

◆ ED_view3d_viewplane_get()

bool ED_view3d_viewplane_get ( const Depsgraph * depsgraph,
const View3D * v3d,
const RegionView3D * rv3d,
int winx,
int winy,
rctf * r_viewplane,
float * r_clip_start,
float * r_clip_end,
float * r_pixsize )

◆ points_in_planes_minmax_fn()

static void points_in_planes_minmax_fn ( const float co[3],
int ,
int ,
int ,
void * user_data_p )
static

◆ view3d_boundbox_clip_m4()

static bool view3d_boundbox_clip_m4 ( const BoundBox * bb,
const float persmatob[4][4] )
static

Definition at line 405 of file view3d_utils.cc.

References copy_v3_v3(), flag, max, min, mul_m4_v4(), and BoundBox::vec.

Referenced by ED_view3d_boundbox_clip(), and ED_view3d_boundbox_clip_ex().

◆ view3d_boxview_clip()

◆ view3d_boxview_copy()

◆ view3d_boxview_sync()

◆ view3d_boxview_sync_axis()

static void view3d_boxview_sync_axis ( RegionView3D * rv3d_dst,
RegionView3D * rv3d_src )
static

Find which axis values are shared between both views and copy to rv3d_dst taking axis flipping into account.

Definition at line 888 of file view3d_utils.cc.

References ED_view3d_quat_from_axis_view(), fabsf, invert_qt_normalized(), mul_qt_v3(), RegionView3D::ofs, UNLIKELY, RegionView3D::view, and RegionView3D::view_axis_roll.

Referenced by view3d_boxview_sync().

◆ view3d_camera_lock_undo_ex()

static bool view3d_camera_lock_undo_ex ( const char * str,
const View3D * v3d,
const RegionView3D * rv3d,
bContext * C,
const bool undo_group )
static

Create a MEMFILE undo-step for locked camera movement when transforming the view. Edit and texture paint mode don't use MEMFILE undo so undo push is skipped for them. NDOF and trackpad navigation would create an undo step on every gesture and we may end up with unnecessary undo steps so undo push for them is not supported for now. Operators that use smooth view for navigation are supported via an optional parameter field, see: V3D_SmoothParams.undo_str.

Definition at line 746 of file view3d_utils.cc.

References ED_undo_grouped_push(), ED_undo_push(), ED_view3d_camera_lock_undo_test(), and str.

Referenced by ED_view3d_camera_lock_undo_grouped_push(), and ED_view3d_camera_lock_undo_push().

◆ view3d_camera_to_view_selected_impl()

◆ view3d_operator_needs_opengl()

◆ view3d_region_operator_needs_opengl()

◆ view_autodist_depth_margin()

static float view_autodist_depth_margin ( ARegion * region,
const int mval[2],
int margin )
static

Variable Documentation

◆ view3d_autodepth_last_id

const char* view3d_autodepth_last_id = "view3d_autodist_last"
static

◆ view3d_quat_axis

float view3d_quat_axis[6][4][4]
static

Lookup by axis-view, axis-roll.

Definition at line 1415 of file view3d_utils.cc.

Referenced by ED_view3d_quat_from_axis_view(), and ED_view3d_quat_to_axis_view().