30static bool ndof_orbit_center_is_used_no_viewport();
41static bool is_bounding_box_in_frustum(
const float projmat[4][4],
52 HAS_TRANSLATE = (1 << 0),
53 HAS_ROTATE = (1 << 0),
56static bool ndof_has_translate(
const wmNDOFMotionData &ndof,
63static bool ndof_has_translate_pan(
const wmNDOFMotionData &ndof,
70static bool ndof_has_rotate(
const wmNDOFMotionData &ndof,
const RegionView3D *rv3d)
78static float view3d_ndof_pan_speed_calc_ex(
RegionView3D *rv3d,
const float depth_pt[3])
89static float view3d_ndof_pan_speed_calc_from_dist(
RegionView3D *rv3d,
const float dist)
105 return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
108static float view3d_ndof_pan_speed_calc(
RegionView3D *rv3d)
118 return view3d_ndof_pan_speed_calc_ex(rv3d, tvec);
127static void view3d_ndof_pan_zoom(
const wmNDOFMotionData &ndof,
130 const bool has_translate,
135 if (has_translate ==
false && has_zoom ==
false) {
139 float3 pan_vec = WM_event_ndof_translation_get_for_navigation(ndof);
145 float zoom_distance = rv3d->dist * ndof.time_delta * pan_vec[2];
146 rv3d->dist += zoom_distance;
173 const float eps_yz_swap = 0.02f;
177 float zvec[3] = {0, 0, 1};
180 if (std::abs(zvec[2]) > (1.0f - eps_yz_swap)) {
181 std::swap(pan_vec.
z, pan_vec.
y);
188 const float pan_vec_y_prev = pan_vec.
y;
193 pan_vec.
z = pan_vec_y_prev;
196 float yvec[3] = {0, 1, 0};
199 if (yvec[2] < 0.0f) {
208 const float speed = view3d_ndof_pan_speed_calc(rv3d);
209 pan_vec *= speed * ndof.time_delta;
225static void view3d_ndof_orbit(
const wmNDOFMotionData &ndof,
229 const bool apply_dyn_ofs)
247 float angle, quat[4];
248 float xvec[3] = {1, 0, 0};
249 float yvec[3] = {0, 1, 0};
252 float3 rot = WM_event_ndof_rotation_get_for_navigation(ndof);
261 const float horizon_plane[3] = {0.0f, 0.0f, 1.0f};
273 if (yvec[2] < 0.0f) {
278 rv3d->ndof_rot_angle =
angle;
279 rv3d->ndof_rot_axis[0] = 0;
280 rv3d->ndof_rot_axis[1] = 0;
281 rv3d->ndof_rot_axis[2] = 1;
289 float angle = ndof.time_delta *
290 WM_event_ndof_rotation_get_axis_angle_for_navigation(ndof, axis);
296 rv3d->ndof_rot_angle =
angle;
307 if (ndof_orbit_center_is_used(v3d, rv3d)) {
309 if (ndof_orbit_center_is_valid(vod->rv3d, -
float3(rv3d->ndof_ofs))) {
310 vod->use_dyn_ofs =
true;
322void view3d_ndof_fly(
const wmNDOFMotionData &ndof,
325 const bool use_precision,
326 const short protectflag,
327 bool *r_has_translate,
330 bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
331 bool has_rotate = ndof_has_rotate(ndof, rv3d);
336 rv3d->ndof_rot_angle = 0.0f;
341 float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f);
348 float3 trans = (speed * ndof.time_delta) * WM_event_ndof_translation_get(ndof);
349 trans_orig_y = trans[1];
360 trans[2] = trans_orig_y;
380 has_translate =
true;
383 has_translate =
false;
390 float angle = ndof.time_delta * WM_event_ndof_rotation_get_axis_angle(ndof, axis);
404 mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation);
409 const float horizon_plane[3] = {0.0f, 0.0f, 1.0f};
420 *r_has_translate = has_translate;
421 *r_has_rotate = has_rotate;
430static bool ndof_orbit_center_is_used_no_viewport()
447 if (!ndof_orbit_center_is_used_no_viewport()) {
450 if (v3d->ob_center_cursor || v3d->ob_center) {
457 "This test should not run from a camera view unless the camera is locked to the viewport");
479 if (rv3d->is_persp) {
489static std::optional<float3> ndof_orbit_center_calc_from_bounds(Depsgraph *depsgraph,
493 std::optional<Bounds<float3>> bounding_box = std::nullopt;
496 bool do_zoom =
false;
503 if (bounding_box.has_value()) {
507 bounding_box->scale_from_center(
float3(0.8));
509 if (is_bounding_box_in_frustum(rv3d->persmat, *bounding_box)) {
513 const float3 center = bounding_box->center();
514 if (ndof_orbit_center_is_valid(rv3d, center)) {
522static float ndof_read_zbuf_rect(
ARegion *region,
const rcti &rect,
int r_xy[2])
539 MEM_SAFE_DELETE(depth_temp.depths);
550static std::optional<float3> ndof_get_min_depth_pt(
ARegion *region,
const rcti &rect)
553 const float depth_near = ndof_read_zbuf_rect(region, rect, xy);
561static std::optional<float3> ndof_orbit_center_calc_from_zbuf(Depsgraph *depsgraph,
569 sample_rect.xmin = 0.3f * region->winx;
570 sample_rect.xmax = 0.7f * region->winx;
571 sample_rect.ymin = 0.2f * region->winy;
572 sample_rect.ymax = 0.6f * region->winy;
575 int view_center[2] = {region->winx / 2, region->winy / 2};
579 const std::optional<float3> min_depth_pt = ndof_get_min_depth_pt(region, sample_rect);
591 const float scale_margin = 1.05f;
608 *
DEG_get_bmain(depsgraph), scene, view_layer, view_layer->active_collection))
622static std::optional<float3> ndof_orbit_center_calc(Depsgraph *depsgraph,
641 std::optional<float3> center_test = ndof_orbit_center_calc_from_bounds(depsgraph, area, region);
642 if (!center_test.has_value()) {
643 center_test = ndof_orbit_center_calc_from_zbuf(depsgraph, area, region);
659 const wmNDOFMotionData &ndof)
672 float3 pan_vec = WM_event_ndof_translation_get_for_navigation(ndof);
674 const bool has_translate = !
is_zero_v2(pan_vec);
675 const bool has_zoom = pan_vec[2] != 0.0f;
677 pan_vec *= ndof.time_delta;
690 if (!(has_translate || has_zoom)) {
694 bool changed =
false;
731 const Depsgraph *depsgraph = vod->depsgraph;
736 const wmNDOFMotionData &ndof = *
static_cast<const wmNDOFMotionData *
>(
event->customdata);
742 const bool has_rotation = ndof_has_rotate(ndof, rv3d);
745 ndof_has_translate(ndof, v3d, rv3d);
746 const bool has_zoom = (rv3d->is_persp ==
false) && WM_event_ndof_translation_has_zoom(ndof);
748 if (has_translate || has_zoom) {
749 view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom);
750 xform_flag |= HAS_TRANSLATE;
754 view3d_ndof_orbit(ndof, vod->area, vod->region, vod,
true);
755 xform_flag |= HAS_ROTATE;
762 v3d, rv3d,
C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
782 ot->name =
"NDOF Orbit View";
783 ot->description =
"Orbit the view using the 3D mouse";
784 ot->idname = ViewOpsType_ndof_orbit.idname;
787 ot->invoke = ndof_orbit_invoke;
809 const wmNDOFMotionData &ndof = *
static_cast<const wmNDOFMotionData *
>(
event->customdata);
812 const wmOperatorStatus camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof);
814 return camera_retval;
829 if (ndof_orbit_center_is_used(v3d, rv3d)) {
831 if (std::optional<float3> center_test = ndof_orbit_center_calc(
832 vod->depsgraph, vod->area, vod->region))
837 if (rv3d->is_persp) {
849 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
850 const bool has_zoom = WM_event_ndof_translation_has_zoom(ndof) &&
853 if (has_translate || has_zoom) {
854 view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate,
true);
855 xform_flag |= HAS_TRANSLATE;
864 const bool has_rotation = ndof_has_rotate(ndof, rv3d);
865 bool has_translate, has_zoom;
867 if (is_orbit_around_pivot) {
869 has_translate = ndof_has_translate_pan(ndof, v3d, rv3d);
870 has_zoom = WM_event_ndof_translation_has_zoom(ndof);
874 has_translate = ndof_has_translate(ndof, v3d, rv3d);
880 const float dist_backup = rv3d->dist;
881 if (!is_orbit_around_pivot) {
884 view3d_ndof_orbit(ndof, vod->area, vod->region, vod, is_orbit_around_pivot);
885 xform_flag |= HAS_ROTATE;
886 if (!is_orbit_around_pivot) {
891 if (has_translate || has_zoom) {
892 view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom);
893 xform_flag |= HAS_TRANSLATE;
900 v3d, rv3d,
C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE);
920 ot->name =
"NDOF Orbit View with Zoom";
921 ot->description =
"Orbit and zoom the view using the 3D mouse";
922 ot->idname = ViewOpsType_ndof_orbit_zoom.idname;
925 ot->invoke = ndof_orbit_zoom_invoke;
947 const wmNDOFMotionData &ndof = *
static_cast<const wmNDOFMotionData *
>(
event->customdata);
950 const wmOperatorStatus camera_retval = view3d_ndof_cameraview_pan_zoom(vod, ndof);
952 return camera_retval;
956 const Depsgraph *depsgraph = vod->depsgraph;
962 const bool has_translate = ndof_has_translate(ndof, v3d, rv3d);
963 const bool has_zoom = (rv3d->is_persp ==
false) && WM_event_ndof_translation_has_zoom(ndof);
966 rv3d->ndof_rot_angle = 0.0f;
968 if (!(has_translate || has_zoom)) {
977 if (has_translate || has_zoom) {
978 view3d_ndof_pan_zoom(ndof, area, region, has_translate, has_zoom);
979 xform_flag |= HAS_TRANSLATE;
1005 ot->name =
"NDOF Pan View";
1006 ot->description =
"Pan the view with the 3D mouse";
1007 ot->idname = ViewOpsType_ndof_pan.idname;
1010 ot->invoke = ndof_pan_invoke;
1038 ret = ndof_orbit_zoom_invoke_impl(
C, vod, event,
nullptr);
1040 U.ndof_navigation_mode = ndof_navigation_mode_backup;
1057 ot->name =
"NDOF Transform View";
1058 ot->description =
"Pan and rotate the view with the 3D mouse";
1059 ot->idname = ViewOpsType_ndof_all.idname;
1062 ot->invoke = ndof_all_invoke;
1071 "VIEW3D_OT_ndof_orbit",
1073 ndof_orbit_invoke_impl,
1079 "VIEW3D_OT_ndof_orbit_zoom",
1081 ndof_orbit_zoom_invoke_impl,
1087 "VIEW3D_OT_ndof_pan",
1089 ndof_pan_invoke_impl,
1095 "VIEW3D_OT_ndof_all",
1097 ndof_all_invoke_impl,
#define ISECT_AABB_PLANE_IN_FRONT_ALL
#define NDOF_IS_ORBIT_AROUND_CENTER_MODE(userdef)
#define NDOF_PIXELS_PER_SECOND
#define NDOF_IS_HORIZON_LOCKED(userdef)
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_LOCK_FLAGS(rv3d)
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
constexpr StringRefNull rotation
bool ED_view3d_camera_lock_autokey(View3D *v3d, RegionView3D *rv3d, bContext *C, bool do_rotate, bool do_translate)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4])
int isect_aabb_planes_v3(const float(*planes)[4], int totplane, const float bbmin[3], const float bbmax[3])
void ED_view3d_distance_set(RegionView3D *rv3d, float dist)
MINLINE void mul_v2_fl(float r[2], float f)
bool ED_view3d_camera_view_zoom_scale(RegionView3D *rv3d, const float scale)
@ NDOF_ORBIT_CENTER_SELECTED
void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d)
MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT
bool ED_view3d_persp_ensure(const Depsgraph *depsgraph, View3D *v3d, ARegion *region)
void planes_from_projmat(const float mat[4][4], float left[4], float right[4], float bottom[4], float top[4], float near[4], float far[4])
float view3d_depth_near_ex(ViewDepths *d, int r_xy[2])
bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
bool ED_view3d_distance_set_from_location(RegionView3D *rv3d, const float dist_co[3], float dist_min)
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
void ED_region_tag_redraw(ARegion *region)
bool ED_view3d_unproject_v3(const ARegion *region, float regionx, float regiony, float regionz, float world[3])
float ED_view3d_dist_soft_min_get(const View3D *v3d, bool use_persp_range)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void mul_qt_v3(const float q[4], float r[3])
wmOperatorStatus view3d_navigate_invoke_impl(bContext *C, wmOperator *op, const wmEvent *event, const ViewOpsType *nav_type)
Main * DEG_get_bmain(const Depsgraph *graph)
bool ED_view3d_camera_view_pan(ARegion *region, const float event_ofs[2])
void axis_angle_to_quat_single(float q[4], char axis, float angle)
bool view3d_calc_point_in_selected_bounds(Depsgraph *depsgraph, struct ViewLayer *view_layer_eval, const View3D *v3d, const float3 &point, const float scale_margin)
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
bool ED_operator_view3d_active(bContext *C)
float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3])
std::optional< Bounds< float3 > > view3d_calc_minmax_visible(Depsgraph *depsgraph, ScrArea *area, ARegion *region, bool use_all_regions, bool clip_bounds)
std::optional< Bounds< float3 > > view3d_calc_minmax_selected(Depsgraph *depsgraph, ScrArea *area, ARegion *region, bool use_all_regions, bool clip_bounds, bool *r_do_zoom)
@ VIEWOPS_FLAG_ORBIT_SELECT
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
bool ED_view3d_offset_lock_check(const View3D *v3d, const RegionView3D *rv3d)
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
@ NDOF_NAVIGATION_MODE_FLY
@ NDOF_NAVIGATION_MODE_DRONE
MINLINE float max_ff(float a, float b)
void ED_view3d_camera_lock_init_ex(const Depsgraph *depsgraph, View3D *v3d, RegionView3D *rv3d, bool calc_dist)
Scene * DEG_get_input_scene(const Depsgraph *graph)
float view3d_depth_near(ViewDepths *d)
void invert_qt_qt_normalized(float q1[4], const float q2[4])
VecBase< float, 3 > float3
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
void view3d_boxview_sync(ScrArea *area, ARegion *region)
float view3d_horizon_correct_quat(float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float axis_fallback[3], const float angle_target, const float factor)
bool BKE_layer_collection_has_selected_objects(const Main &bmain, const Scene *scene, ViewLayer *view_layer, LayerCollection *lc)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
float view3d_horizon_correct_quat_ease_out(float quat[4], const float horizon_plane[3], const bool horizon_plane_no_flip, const float factor)
ccl_device_inline int4 rect_clip(const int4 a, const int4 b)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float