Manipulator: grab3d option to align to view
Use for lamp-target, makes it easier to click on.
This commit is contained in:
parent
8520cb4af0
commit
464c045b31
Notes:
blender-bot
2023-02-14 09:33:11 +01:00
Referenced by issue #51844, Custom Manipulators: Where to take advantage of manipulators
|
@ -116,6 +116,7 @@ enum {
|
|||
ED_MANIPULATOR_GRAB_DRAW_FLAG_NOP = 0,
|
||||
/* only for solid shapes */
|
||||
ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL = (1 << 0),
|
||||
ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW = (1 << 1),
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
|
@ -87,14 +87,13 @@ typedef struct GrabInteraction {
|
|||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static void grab_geom_draw(
|
||||
const wmManipulator *mpr, const float color[4], const bool select)
|
||||
const wmManipulator *mpr, const float color[4], const bool select, const int draw_options)
|
||||
{
|
||||
#ifdef USE_MANIPULATOR_CUSTOM_DIAL
|
||||
UNUSED_VARS(grab3d, col, axis_modal_mat);
|
||||
wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_grab3d, select);
|
||||
#else
|
||||
const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
|
||||
const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
|
||||
const bool filled = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL) != 0;
|
||||
|
||||
glLineWidth(mpr->line_width);
|
||||
|
@ -151,11 +150,14 @@ static void grab3d_get_translate(
|
|||
}
|
||||
|
||||
static void grab3d_draw_intern(
|
||||
const bContext *UNUSED(C), wmManipulator *mpr,
|
||||
const bContext *C, wmManipulator *mpr,
|
||||
const bool select, const bool highlight)
|
||||
{
|
||||
const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
|
||||
const bool align_view = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW) != 0;
|
||||
float color[4];
|
||||
float matrix_final[4][4];
|
||||
float matrix_align[4][4];
|
||||
|
||||
manipulator_color_get(mpr, highlight, color);
|
||||
|
||||
|
@ -163,9 +165,19 @@ static void grab3d_draw_intern(
|
|||
|
||||
gpuPushMatrix();
|
||||
gpuMultMatrix(matrix_final);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
grab_geom_draw(mpr, color, select);
|
||||
if (align_view) {
|
||||
float matrix_final_unit[4][4];
|
||||
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||
normalize_m4_m4(matrix_final_unit, matrix_final);
|
||||
mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
|
||||
zero_v3(matrix_align[3]);
|
||||
transpose_m4(matrix_align);
|
||||
gpuMultMatrix(matrix_align);
|
||||
}
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
grab_geom_draw(mpr, color, select, draw_options);
|
||||
glDisable(GL_BLEND);
|
||||
gpuPopMatrix();
|
||||
|
||||
|
@ -180,8 +192,13 @@ static void grab3d_draw_intern(
|
|||
|
||||
gpuPushMatrix();
|
||||
gpuMultMatrix(matrix_final);
|
||||
|
||||
if (align_view) {
|
||||
gpuMultMatrix(matrix_align);
|
||||
}
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
grab_geom_draw(mpr, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f}, select);
|
||||
grab_geom_draw(mpr, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f}, select, draw_options);
|
||||
glDisable(GL_BLEND);
|
||||
gpuPopMatrix();
|
||||
}
|
||||
|
@ -313,6 +330,7 @@ static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt)
|
|||
};
|
||||
static EnumPropertyItem rna_enum_draw_options[] = {
|
||||
{ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
|
||||
{ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW, "ALIGN_VIEW", 0, "Align View", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -260,9 +260,13 @@ static void WIDGETGROUP_lamp_target_setup(const bContext *UNUSED(C), wmManipulat
|
|||
UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
|
||||
UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
|
||||
|
||||
mpr->scale_basis = 0.05f;
|
||||
mpr->scale_basis = 0.06f;
|
||||
|
||||
wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_transform_axis_target", true);
|
||||
|
||||
RNA_enum_set(mpr->ptr, "draw_options",
|
||||
ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL | ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW);
|
||||
|
||||
WM_manipulator_set_operator(mpr, ot, NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue