Blender  V3.3
Classes | Variables
view3d_placement.c File Reference
#include "MEM_guardedalloc.h"
#include "BKE_context.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "WM_api.h"
#include "WM_toolsystem.h"
#include "ED_gizmo_utils.h"
#include "ED_screen.h"
#include "ED_space_api.h"
#include "ED_view3d.h"
#include "UI_resources.h"
#include "GPU_immediate.h"
#include "view3d_intern.h"

Go to the source code of this file.

Classes

struct  InteractivePlaceData
 

Enumerations

Local Types
enum  ePlace_PrimType {
  PLACE_PRIMITIVE_TYPE_CUBE = 1 , PLACE_PRIMITIVE_TYPE_CYLINDER = 2 , PLACE_PRIMITIVE_TYPE_CONE = 3 , PLACE_PRIMITIVE_TYPE_SPHERE_UV = 4 ,
  PLACE_PRIMITIVE_TYPE_SPHERE_ICO = 5
}
 
enum  ePlace_Origin { PLACE_ORIGIN_BASE = 1 , PLACE_ORIGIN_CENTER = 2 }
 
enum  ePlace_Aspect { PLACE_ASPECT_FREE = 1 , PLACE_ASPECT_FIXED = 2 }
 
enum  ePlace_SnapTo { PLACE_SNAP_TO_GEOMETRY = 1 , PLACE_SNAP_TO_DEFAULT = 2 }
 

Functions

Internal Utilities
static bool view3d_win_to_3d_on_plane_maybe_fallback (const ARegion *region, const float plane[4], const float mval[2], const float *plane_fallback, float r_out[3])
 
static int dot_v3_array_find_max_index (const float dirs[][3], const int dirs_len, const float dir_test[3], bool is_signed)
 
static UNUSED_FUNCTION_WITH_RETURN_TYPE (wmGizmoGroup *, idp_gizmogroup_from_region)
 
static bool idp_snap_calc_incremental (Scene *scene, View3D *v3d, ARegion *region, const float co_relative[3], float co[3])
 
Primitive Drawing (Cube, Cone, Cylinder...)
static void draw_line_loop (const float coords[][3], int coords_len, const float color[4])
 
static void draw_line_pairs (const float coords_a[][3], float coords_b[][3], int coords_len, const float color[4])
 
static void draw_line_bounds (const BoundBox *bounds, const float color[4])
 
static bool calc_bbox (struct InteractivePlaceData *ipd, BoundBox *bounds)
 
static void draw_circle_in_quad (const float v1[3], const float v2[3], const float v3[3], const float v4[3], const int resolution, const float color[4])
 
Drawing Callbacks
static void draw_primitive_view_impl (const struct bContext *C, struct InteractivePlaceData *ipd, const float color[4], int flatten_axis)
 
static void draw_primitive_view (const struct bContext *C, ARegion *UNUSED(region), void *arg)
 
Calculate The Initial Placement Plane

Use by both the operator and placement cursor.

static bool view3d_interactive_add_calc_snap (bContext *UNUSED(C), const wmEvent *UNUSED(event), float r_co_src[3], float r_matrix_orient[3][3], bool *r_is_enabled, bool *r_is_snap_invert)
 
Placement Gizmo Group

This is currently only used for snapping before the tool is initialized, we could show a placement plane here.

static void preview_plane_free_fn (void *customdata)
 
static void WIDGETGROUP_placement_setup (const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
 
void VIEW3D_GGT_placement (wmGizmoGroupType *gzgt)
 

Variables

static const char * view3d_gzgt_placement_id = "VIEW3D_GGT_placement"
 
static const float eps_view_align = 1e-2f
 

Add Object Modal Operator

enum  {
  PLACE_MODAL_SNAP_ON , PLACE_MODAL_SNAP_OFF , PLACE_MODAL_FIXED_ASPECT_ON , PLACE_MODAL_FIXED_ASPECT_OFF ,
  PLACE_MODAL_PIVOT_CENTER_ON , PLACE_MODAL_PIVOT_CENTER_OFF
}
 
static void view3d_interactive_add_begin (bContext *C, wmOperator *op, const wmEvent *event)
 
static int view3d_interactive_add_invoke (bContext *C, wmOperator *op, const wmEvent *event)
 
static void view3d_interactive_add_exit (bContext *C, wmOperator *op)
 
static void view3d_interactive_add_cancel (bContext *C, wmOperator *op)
 
void viewplace_modal_keymap (wmKeyConfig *keyconf)
 
static int view3d_interactive_add_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static bool view3d_interactive_add_poll (bContext *C)
 
static int idp_rna_plane_axis_get_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop))
 
static void idp_rna_plane_axis_set_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop), int value)
 
static int idp_rna_plane_depth_get_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop))
 
static void idp_rna_plane_depth_set_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop), int value)
 
static int idp_rna_plane_orient_get_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop))
 
static void idp_rna_plane_orient_set_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop), int value)
 
static int idp_rna_snap_target_get_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop))
 
static void idp_rna_snap_target_set_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop), int value)
 
static bool idp_rna_use_plane_axis_auto_get_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop))
 
static void idp_rna_use_plane_axis_auto_set_fn (struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop), bool value)
 
void VIEW3D_OT_interactive_add (struct wmOperatorType *ot)
 

Detailed Description

Operator to interactively place data.

Currently only adds meshes, but could add other kinds of data including library assets & non-mesh types.

Definition in file view3d_placement.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PLACE_MODAL_SNAP_ON 
PLACE_MODAL_SNAP_OFF 
PLACE_MODAL_FIXED_ASPECT_ON 
PLACE_MODAL_FIXED_ASPECT_OFF 
PLACE_MODAL_PIVOT_CENTER_ON 
PLACE_MODAL_PIVOT_CENTER_OFF 

Definition at line 924 of file view3d_placement.c.

◆ ePlace_Aspect

Enumerator
PLACE_ASPECT_FREE 
PLACE_ASPECT_FIXED 

Definition at line 60 of file view3d_placement.c.

◆ ePlace_Origin

Enumerator
PLACE_ORIGIN_BASE 
PLACE_ORIGIN_CENTER 

Definition at line 55 of file view3d_placement.c.

◆ ePlace_PrimType

Enumerator
PLACE_PRIMITIVE_TYPE_CUBE 
PLACE_PRIMITIVE_TYPE_CYLINDER 
PLACE_PRIMITIVE_TYPE_CONE 
PLACE_PRIMITIVE_TYPE_SPHERE_UV 
PLACE_PRIMITIVE_TYPE_SPHERE_ICO 

Definition at line 47 of file view3d_placement.c.

◆ ePlace_SnapTo

Enumerator
PLACE_SNAP_TO_GEOMETRY 
PLACE_SNAP_TO_DEFAULT 

Definition at line 65 of file view3d_placement.c.

Function Documentation

◆ calc_bbox()

static bool calc_bbox ( struct InteractivePlaceData ipd,
BoundBox bounds 
)
static

◆ dot_v3_array_find_max_index()

static int dot_v3_array_find_max_index ( const float  dirs[][3],
const int  dirs_len,
const float  dir_test[3],
bool  is_signed 
)
static

Return the index of dirs with the largest dot product compared to dir_test.

Definition at line 187 of file view3d_placement.c.

References dot_v3v3(), and fabsf.

Referenced by view3d_interactive_add_begin().

◆ draw_circle_in_quad()

static void draw_circle_in_quad ( const float  v1[3],
const float  v2[3],
const float  v3[3],
const float  v4[3],
const int  resolution,
const float  color[4] 
)
static

◆ draw_line_bounds()

static void draw_line_bounds ( const BoundBox bounds,
const float  color[4] 
)
static

◆ draw_line_loop()

static void draw_line_loop ( const float  coords[][3],
int  coords_len,
const float  color[4] 
)
static

◆ draw_line_pairs()

static void draw_line_pairs ( const float  coords_a[][3],
float  coords_b[][3],
int  coords_len,
const float  color[4] 
)
static

◆ draw_primitive_view()

static void draw_primitive_view ( const struct bContext C,
ARegion UNUSEDregion,
void arg 
)
static

◆ draw_primitive_view_impl()

static void draw_primitive_view_impl ( const struct bContext C,
struct InteractivePlaceData ipd,
const float  color[4],
int  flatten_axis 
)
static

◆ idp_rna_plane_axis_get_fn()

static int idp_rna_plane_axis_get_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop 
)
static

◆ idp_rna_plane_axis_set_fn()

static void idp_rna_plane_axis_set_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop,
int  value 
)
static

◆ idp_rna_plane_depth_get_fn()

static int idp_rna_plane_depth_get_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop 
)
static

◆ idp_rna_plane_depth_set_fn()

static void idp_rna_plane_depth_set_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop,
int  value 
)
static

◆ idp_rna_plane_orient_get_fn()

static int idp_rna_plane_orient_get_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop 
)
static

◆ idp_rna_plane_orient_set_fn()

static void idp_rna_plane_orient_set_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop,
int  value 
)
static

◆ idp_rna_snap_target_get_fn()

static int idp_rna_snap_target_get_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop 
)
static

◆ idp_rna_snap_target_set_fn()

static void idp_rna_snap_target_set_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop,
int  value 
)
static

◆ idp_rna_use_plane_axis_auto_get_fn()

static bool idp_rna_use_plane_axis_auto_get_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop 
)
static

◆ idp_rna_use_plane_axis_auto_set_fn()

static void idp_rna_use_plane_axis_auto_set_fn ( struct PointerRNA UNUSEDptr,
struct PropertyRNA UNUSEDprop,
bool  value 
)
static

◆ idp_snap_calc_incremental()

static bool idp_snap_calc_incremental ( Scene scene,
View3D v3d,
ARegion region,
const float  co_relative[3],
float  co[3] 
)
static

Calculate 3D view incremental (grid) snapping.

Note
This could be moved to a public function.

Definition at line 219 of file view3d_placement.c.

References add_v3_v3(), ED_view3d_grid_view_scale(), mul_v3_fl(), NULL, SCE_SNAP_ABS_GRID, SCE_SNAP_MODE_INCREMENT, scene, ToolSettings::snap_flag, ToolSettings::snap_mode, sub_v3_v3(), Scene::toolsettings, and UNLIKELY.

Referenced by view3d_interactive_add_modal().

◆ preview_plane_free_fn()

static void preview_plane_free_fn ( void customdata)
static

◆ UNUSED_FUNCTION_WITH_RETURN_TYPE()

static UNUSED_FUNCTION_WITH_RETURN_TYPE ( wmGizmoGroup ,
idp_gizmogroup_from_region   
)
static

Definition at line 207 of file view3d_placement.c.

References NULL, view3d_gzgt_placement_id, and WM_gizmomap_group_find().

◆ VIEW3D_GGT_placement()

void VIEW3D_GGT_placement ( wmGizmoGroupType gzgt)

◆ view3d_interactive_add_begin()

static void view3d_interactive_add_begin ( bContext C,
wmOperator op,
const wmEvent event 
)
static

Definition at line 707 of file view3d_placement.c.

References add_v3_v3v3(), InteractivePlaceData::area, C, InteractivePlaceData::co_dst, InteractivePlaceData::co_src, copy_v3_v3(), wmOperator::customdata, InteractivePlaceData::degenerate_axis, InteractivePlaceData::degenerate_diagonal, InteractivePlaceData::degenerate_diagonal_display, dot_v3_array_find_max_index(), dot_v3v3(), InteractivePlaceData::draw_handle_view, V3DSnapCursorState::draw_plane, V3DSnapCursorState::draw_point, draw_primitive_view(), ED_region_draw_cb_activate(), ED_region_tag_redraw(), ED_view3d_cursor_snap_active(), ED_view3d_cursor_snap_data_update(), ED_view3d_cursor_snap_prevpoint_set(), ED_view3d_cursor_snap_state_get(), eps_view_align, fabsf, V3DSnapCursorState::flag, bToolRef::idname, InteractivePlaceData::is_centered, InteractivePlaceData::is_centered_init, InteractivePlaceData::is_degenerate_view_align, InteractivePlaceData::is_fixed_aspect, InteractivePlaceData::is_fixed_aspect_init, InteractivePlaceData::is_snap_found, InteractivePlaceData::is_snap_invert, KM_CLICK_DRAG, InteractivePlaceData::launch_event, InteractivePlaceData::matrix_orient, negate_v3(), negate_v3_v3(), normalize_v3(), normalize_v3_v3(), InteractivePlaceData::orient_axis, PLACE_ASPECT_FIXED, PLACE_ORIGIN_CENTER, PLACE_PRIMITIVE_TYPE_CONE, PLACE_PRIMITIVE_TYPE_CUBE, PLACE_PRIMITIVE_TYPE_CYLINDER, PLACE_PRIMITIVE_TYPE_SPHERE_ICO, PLACE_PRIMITIVE_TYPE_SPHERE_UV, InteractivePlaceData::plane, V3DSnapCursorState::plane_axis, plane_from_point_normal_v3(), InteractivePlaceData::primitive_type, wmOperator::ptr, InteractivePlaceData::region, REGION_DRAW_POST_VIEW, ARegion::regiondata, RNA_enum_get(), RNA_property_enum_get(), RNA_property_is_set(), RNA_struct_find_property(), ScrArea::runtime, InteractivePlaceData::snap_state, InteractivePlaceData::snap_to, InteractivePlaceData::step, InteractivePlaceData::STEP_BASE, InteractivePlaceData::STEP_DEPTH, InteractivePlaceData::step_index, STREQ, sub_v3_v3v3(), ScrArea_Runtime::tool, ARegion::type, wmEvent::type, InteractivePlaceData::use_snap, InteractivePlaceData::use_tool, V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE, wmEvent::val, view3d_interactive_add_calc_snap(), InteractivePlaceData::view_plane, RegionView3D::viewinv, WM_event_drag_start_mval(), and WM_userdef_event_type_from_keymap_type().

Referenced by view3d_interactive_add_invoke(), and view3d_interactive_add_modal().

◆ view3d_interactive_add_calc_snap()

static bool view3d_interactive_add_calc_snap ( bContext UNUSEDC,
const wmEvent UNUSEDevent,
float  r_co_src[3],
float  r_matrix_orient[3][3],
bool r_is_enabled,
bool r_is_snap_invert 
)
static

◆ view3d_interactive_add_cancel()

static void view3d_interactive_add_cancel ( bContext C,
wmOperator op 
)
static

Definition at line 919 of file view3d_placement.c.

References C, and view3d_interactive_add_exit().

Referenced by VIEW3D_OT_interactive_add().

◆ view3d_interactive_add_exit()

static void view3d_interactive_add_exit ( bContext C,
wmOperator op 
)
static

◆ view3d_interactive_add_invoke()

static int view3d_interactive_add_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ view3d_interactive_add_modal()

static int view3d_interactive_add_modal ( bContext C,
wmOperator op,
const wmEvent event 
)
static

Definition at line 958 of file view3d_placement.c.

References InteractivePlaceData::area, ATTR_FALLTHROUGH, BLI_assert, bounds(), C, calc_bbox(), closest_to_plane_normalized_v3(), InteractivePlaceData::co_dst, InteractivePlaceData::co_src, copy_m3_m3(), copy_v3_v3(), cross_v3_v3v3(), wmOperator::customdata, InteractivePlaceData::degenerate_diagonal, dot_v3v3(), ED_region_tag_redraw(), ED_view3d_cursor_snap_prevpoint_set(), ELEM, EVT_ESCKEY, EVT_MODAL_MAP, idp_snap_calc_incremental(), InteractivePlaceData::is_centered, InteractivePlaceData::is_centered_init, InteractivePlaceData::is_degenerate_view_align, InteractivePlaceData::is_fixed_aspect, InteractivePlaceData::is_fixed_aspect_init, InteractivePlaceData::is_snap_found, InteractivePlaceData::is_snap_invert, KM_PRESS, KM_RELEASE, InteractivePlaceData::launch_event, LEFTMOUSE, len_v3v3(), mat3_to_eul(), InteractivePlaceData::matrix_orient, mid_v3_v3v3(), MOUSEMOVE, negate_v3(), normalize_v3(), NULL, OPERATOR_CANCELLED, OPERATOR_FINISHED, OPERATOR_RUNNING_MODAL, InteractivePlaceData::orient_axis, ot, PLACE_MODAL_FIXED_ASPECT_OFF, PLACE_MODAL_FIXED_ASPECT_ON, PLACE_MODAL_PIVOT_CENTER_OFF, PLACE_MODAL_PIVOT_CENTER_ON, PLACE_MODAL_SNAP_OFF, PLACE_MODAL_SNAP_ON, PLACE_PRIMITIVE_TYPE_CONE, PLACE_PRIMITIVE_TYPE_CUBE, PLACE_PRIMITIVE_TYPE_CYLINDER, PLACE_PRIMITIVE_TYPE_SPHERE_ICO, PLACE_PRIMITIVE_TYPE_SPHERE_UV, PLACE_SNAP_TO_DEFAULT, InteractivePlaceData::plane, plane_from_point_normal_v3(), InteractivePlaceData::primitive_type, InteractivePlaceData::region, ARegion::regiondata, RIGHTMOUSE, RNA_float_set(), RNA_float_set_array(), ScrArea::runtime, SCE_SNAP, InteractivePlaceData::scene, InteractivePlaceData::snap_co, ToolSettings::snap_flag, InteractivePlaceData::snap_state, InteractivePlaceData::snap_to, InteractivePlaceData::step, InteractivePlaceData::STEP_BASE, InteractivePlaceData::STEP_DEPTH, InteractivePlaceData::step_index, sub_v3_v3(), sub_v3_v3v3(), SWAP, swap_v3_v3(), ScrArea_Runtime::tool, Scene::toolsettings, wmEvent::type, UNUSED_VARS, InteractivePlaceData::use_snap, InteractivePlaceData::use_tool, InteractivePlaceData::v3d, wmEvent::val, view3d_interactive_add_begin(), view3d_interactive_add_calc_snap(), view3d_interactive_add_exit(), view3d_win_to_3d_on_plane_maybe_fallback(), InteractivePlaceData::view_plane, RegionView3D::viewinv, InteractivePlaceData::wait_for_input, WM_event_drag_start_mval_fl(), WM_OP_EXEC_DEFAULT, WM_operator_name_call_ptr(), WM_operator_properties_create_ptr(), WM_operator_properties_free(), WM_operatortype_find(), and WM_toolsystem_ref_properties_init_for_keymap().

Referenced by VIEW3D_OT_interactive_add().

◆ view3d_interactive_add_poll()

static bool view3d_interactive_add_poll ( bContext C)
static

Definition at line 1248 of file view3d_placement.c.

References C, CTX_data_mode_enum(), CTX_MODE_EDIT_MESH, CTX_MODE_OBJECT, and ELEM.

Referenced by VIEW3D_OT_interactive_add().

◆ VIEW3D_OT_interactive_add()

void VIEW3D_OT_interactive_add ( struct wmOperatorType ot)

Definition at line 1346 of file view3d_placement.c.

References wmOperatorType::cancel, wmOperatorType::description, wmOperatorType::flag, wmOperatorType::idname, idp_rna_plane_axis_get_fn(), idp_rna_plane_axis_set_fn(), idp_rna_plane_depth_get_fn(), idp_rna_plane_depth_set_fn(), idp_rna_plane_orient_get_fn(), idp_rna_plane_orient_set_fn(), idp_rna_snap_target_get_fn(), idp_rna_snap_target_set_fn(), idp_rna_use_plane_axis_auto_get_fn(), idp_rna_use_plane_axis_auto_set_fn(), wmOperatorType::invoke, wmOperatorType::modal, wmOperatorType::name, NULL, ot, PLACE_ASPECT_FIXED, PLACE_ASPECT_FREE, PLACE_ORIGIN_BASE, PLACE_ORIGIN_CENTER, PLACE_PRIMITIVE_TYPE_CONE, PLACE_PRIMITIVE_TYPE_CUBE, PLACE_PRIMITIVE_TYPE_CYLINDER, PLACE_PRIMITIVE_TYPE_SPHERE_ICO, PLACE_PRIMITIVE_TYPE_SPHERE_UV, PLACE_SNAP_TO_DEFAULT, PLACE_SNAP_TO_GEOMETRY, wmOperatorType::poll, InteractivePlaceData::primitive_type, PROP_ENUM, PROP_HIDDEN, PROP_IDPROPERTY, PROP_NONE, PROP_PTR_NO_OWNERSHIP, PROP_SKIP_SAVE, RNA_def_boolean(), RNA_def_property(), RNA_def_property_boolean_funcs_runtime(), RNA_def_property_enum_default(), RNA_def_property_enum_funcs_runtime(), RNA_def_property_enum_items(), RNA_def_property_flag(), RNA_def_property_ui_text(), rna_enum_axis_xyz_items, wmOperatorType::srna, V3D_PLACE_DEPTH_CURSOR_PLANE, V3D_PLACE_DEPTH_CURSOR_VIEW, V3D_PLACE_DEPTH_SURFACE, V3D_PLACE_ORIENT_DEFAULT, V3D_PLACE_ORIENT_SURFACE, view3d_interactive_add_cancel(), view3d_interactive_add_invoke(), view3d_interactive_add_modal(), and view3d_interactive_add_poll().

Referenced by view3d_operatortypes().

◆ view3d_win_to_3d_on_plane_maybe_fallback()

static bool view3d_win_to_3d_on_plane_maybe_fallback ( const ARegion region,
const float  plane[4],
const float  mval[2],
const float plane_fallback,
float  r_out[3] 
)
static

Convenience wrapper to avoid duplicating arguments.

Definition at line 169 of file view3d_placement.c.

References ED_view3d_win_to_3d_on_plane(), ED_view3d_win_to_3d_on_plane_with_fallback(), RegionView3D::is_persp, NULL, and ARegion::regiondata.

Referenced by view3d_interactive_add_modal().

◆ viewplace_modal_keymap()

void viewplace_modal_keymap ( wmKeyConfig keyconf)

◆ WIDGETGROUP_placement_setup()

static void WIDGETGROUP_placement_setup ( const bContext UNUSEDC,
wmGizmoGroup gzgroup 
)
static

Variable Documentation

◆ eps_view_align

const float eps_view_align = 1e-2f
static

Dot products below this will be considered view aligned. In this case we can't usefully project the mouse cursor onto the plane, so use a fall-back plane instead.

Definition at line 41 of file view3d_placement.c.

Referenced by view3d_interactive_add_begin().

◆ view3d_gzgt_placement_id

const char* view3d_gzgt_placement_id = "VIEW3D_GGT_placement"
static