code cleanup: de-duplicate view clipping function for paint and knife tool, minor changes to knife initialization.
This commit is contained in:
@@ -212,10 +212,16 @@ void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, cons
|
||||
|
||||
|
||||
|
||||
int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
|
||||
int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend);
|
||||
void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short no_shift);
|
||||
void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]);
|
||||
bool ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d,
|
||||
float *r_clipsta, float *r_clipend, const bool use_ortho_factor);
|
||||
bool ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi,
|
||||
struct rctf *r_viewplane, float *r_clipsta, float *r_clipend);
|
||||
void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar,
|
||||
struct View3D *v3d, struct RegionView3D *rv3d,
|
||||
struct rctf *viewborder_r, const bool no_shift);
|
||||
void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar,
|
||||
struct View3D *v3d, struct RegionView3D *rv3d,
|
||||
float r_size[2]);
|
||||
|
||||
void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect);
|
||||
void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[4][4]);
|
||||
|
||||
@@ -174,9 +174,9 @@ typedef struct KnifeTool_OpData {
|
||||
KnifeColors colors;
|
||||
|
||||
/* operatpr options */
|
||||
char cut_through; /* preference, can be modified at runtime (that feature may go) */
|
||||
char only_select; /* set on initialization */
|
||||
char select_result; /* set on initialization */
|
||||
bool cut_through; /* preference, can be modified at runtime (that feature may go) */
|
||||
bool only_select; /* set on initialization */
|
||||
bool select_result; /* set on initialization */
|
||||
|
||||
short is_ortho;
|
||||
float ortho_extent;
|
||||
@@ -2867,28 +2867,14 @@ static void knifetool_finish(wmOperator *op)
|
||||
EDBM_update_generic(kcd->em, TRUE, TRUE);
|
||||
}
|
||||
|
||||
/* copied from paint_image.c */
|
||||
static int project_knife_view_clip(View3D *v3d, RegionView3D *rv3d, float *clipsta, float *clipend)
|
||||
{
|
||||
int orth = ED_view3d_clip_range_get(v3d, rv3d, clipsta, clipend);
|
||||
|
||||
if (orth) { /* only needed for ortho */
|
||||
float fac = 2.0f / ((*clipend) - (*clipsta));
|
||||
*clipsta *= fac;
|
||||
*clipend *= fac;
|
||||
}
|
||||
|
||||
return orth;
|
||||
}
|
||||
|
||||
static void knife_recalc_projmat(KnifeTool_OpData *kcd)
|
||||
{
|
||||
invert_m4_m4(kcd->ob->imat, kcd->ob->obmat);
|
||||
ED_view3d_ob_project_mat_get(kcd->ar->regiondata, kcd->ob, kcd->projmat);
|
||||
//mult_m4_m4m4(kcd->projmat, kcd->vc.rv3d->winmat, kcd->vc.rv3d->viewmat);
|
||||
|
||||
kcd->is_ortho = project_knife_view_clip(kcd->vc.v3d, kcd->vc.rv3d,
|
||||
&kcd->clipsta, &kcd->clipend);
|
||||
kcd->is_ortho = ED_view3d_clip_range_get(kcd->vc.v3d, kcd->vc.rv3d,
|
||||
&kcd->clipsta, &kcd->clipend, true);
|
||||
}
|
||||
|
||||
/* called when modal loop selection is done... */
|
||||
@@ -2956,18 +2942,14 @@ static void knifetool_update_mval(KnifeTool_OpData *kcd, const int mval_i[2])
|
||||
}
|
||||
|
||||
/* called when modal loop selection gets set up... */
|
||||
static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut))
|
||||
static void knifetool_init(bContext *C, KnifeTool_OpData *kcd,
|
||||
const bool only_select, const bool cut_through)
|
||||
{
|
||||
KnifeTool_OpData *kcd;
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *obedit = CTX_data_edit_object(C);
|
||||
DerivedMesh *cage, *final;
|
||||
SmallHash shash;
|
||||
void *data[3];
|
||||
const short only_select = RNA_boolean_get(op->ptr, "only_selected");
|
||||
|
||||
/* alloc new customdata */
|
||||
kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), "knifetool Modal Op Data");
|
||||
|
||||
/* assign the drawing handle for drawing preview line... */
|
||||
kcd->ob = obedit;
|
||||
@@ -3013,7 +2995,7 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut))
|
||||
kcd->kedgefacemap = BLI_ghash_ptr_new("knife origvertmap");
|
||||
|
||||
/* cut all the way through the mesh if use_occlude_geometry button not pushed */
|
||||
kcd->cut_through = !RNA_boolean_get(op->ptr, "use_occlude_geometry");
|
||||
kcd->cut_through = cut_through;
|
||||
kcd->only_select = only_select;
|
||||
|
||||
/* can't usefully select resulting edges in face mode */
|
||||
@@ -3023,8 +3005,6 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut))
|
||||
knife_pos_data_clear(&kcd->prev);
|
||||
|
||||
knife_init_colors(&kcd->colors);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int knifetool_cancel(bContext *C, wmOperator *op)
|
||||
@@ -3036,12 +3016,17 @@ static int knifetool_cancel(bContext *C, wmOperator *op)
|
||||
|
||||
static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
const bool only_select = RNA_boolean_get(op->ptr, "only_selected");
|
||||
const bool cut_through = !RNA_boolean_get(op->ptr, "use_occlude_geometry");
|
||||
|
||||
KnifeTool_OpData *kcd;
|
||||
|
||||
view3d_operator_needs_opengl(C);
|
||||
|
||||
if (!knifetool_init(C, op, 0))
|
||||
return OPERATOR_CANCELLED;
|
||||
/* alloc new customdata */
|
||||
kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
|
||||
|
||||
knifetool_init(C, kcd, only_select, cut_through);
|
||||
|
||||
/* add a modal handler for this operator - handles loop selection */
|
||||
WM_cursor_modal(CTX_wm_window(C), BC_KNIFECURSOR);
|
||||
|
||||
@@ -2763,19 +2763,6 @@ static void project_paint_delayed_face_init(ProjPaintState *ps, const MFace *mf,
|
||||
#endif
|
||||
}
|
||||
|
||||
static int project_paint_view_clip(View3D *v3d, RegionView3D *rv3d, float *clipsta, float *clipend)
|
||||
{
|
||||
int orth = ED_view3d_clip_range_get(v3d, rv3d, clipsta, clipend);
|
||||
|
||||
if (orth) { /* only needed for ortho */
|
||||
float fac = 2.0f / ((*clipend) - (*clipsta));
|
||||
*clipsta *= fac;
|
||||
*clipend *= fac;
|
||||
}
|
||||
|
||||
return orth;
|
||||
}
|
||||
|
||||
/* run once per stroke before projection painting */
|
||||
static void project_paint_begin(ProjPaintState *ps)
|
||||
{
|
||||
@@ -2906,7 +2893,7 @@ static void project_paint_begin(ProjPaintState *ps)
|
||||
|
||||
ED_view3d_ob_project_mat_get(ps->rv3d, ps->ob, ps->projectMat);
|
||||
|
||||
ps->is_ortho = project_paint_view_clip(ps->v3d, ps->rv3d, &ps->clipsta, &ps->clipend);
|
||||
ps->is_ortho = ED_view3d_clip_range_get(ps->v3d, ps->rv3d, &ps->clipsta, &ps->clipend, true);
|
||||
}
|
||||
else {
|
||||
/* re-projection */
|
||||
@@ -4412,7 +4399,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
|
||||
IDPropertyTemplate val;
|
||||
IDProperty *idgroup = IDP_GetProperties(&image->id, 1);
|
||||
IDProperty *view_data;
|
||||
int orth;
|
||||
bool is_ortho;
|
||||
float *array;
|
||||
|
||||
val.array.len = PROJ_VIEW_DATA_SIZE;
|
||||
@@ -4422,8 +4409,8 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
|
||||
array = (float *)IDP_Array(view_data);
|
||||
memcpy(array, rv3d->winmat, sizeof(rv3d->winmat)); array += sizeof(rv3d->winmat) / sizeof(float);
|
||||
memcpy(array, rv3d->viewmat, sizeof(rv3d->viewmat)); array += sizeof(rv3d->viewmat) / sizeof(float);
|
||||
orth = project_paint_view_clip(v3d, rv3d, &array[0], &array[1]);
|
||||
array[2] = orth ? 1.0f : 0.0f; /* using float for a bool is dodgy but since its an extra member in the array... easier then adding a single bool prop */
|
||||
is_ortho = ED_view3d_clip_range_get(v3d, rv3d, &array[0], &array[1], true);
|
||||
array[2] = is_ortho ? 1.0f : 0.0f; /* using float for a bool is dodgy but since its an extra member in the array... easier then adding a single bool prop */
|
||||
|
||||
IDP_AddToGroup(idgroup, view_data);
|
||||
|
||||
|
||||
@@ -968,7 +968,7 @@ static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
|
||||
}
|
||||
|
||||
static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d,
|
||||
rctf *viewborder_r, short no_shift, short no_zoom)
|
||||
rctf *r_viewborder, const bool no_shift, const bool no_zoom)
|
||||
{
|
||||
CameraParams params;
|
||||
rctf rect_view, rect_camera;
|
||||
@@ -992,25 +992,25 @@ static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionV
|
||||
rect_camera = params.viewplane;
|
||||
|
||||
/* get camera border within viewport */
|
||||
viewborder_r->xmin = ((rect_camera.xmin - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) * ar->winx;
|
||||
viewborder_r->xmax = ((rect_camera.xmax - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) * ar->winx;
|
||||
viewborder_r->ymin = ((rect_camera.ymin - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) * ar->winy;
|
||||
viewborder_r->ymax = ((rect_camera.ymax - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) * ar->winy;
|
||||
r_viewborder->xmin = ((rect_camera.xmin - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) * ar->winx;
|
||||
r_viewborder->xmax = ((rect_camera.xmax - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) * ar->winx;
|
||||
r_viewborder->ymin = ((rect_camera.ymin - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) * ar->winy;
|
||||
r_viewborder->ymax = ((rect_camera.ymax - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) * ar->winy;
|
||||
}
|
||||
|
||||
void ED_view3d_calc_camera_border_size(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, float size_r[2])
|
||||
void ED_view3d_calc_camera_border_size(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, float r_size[2])
|
||||
{
|
||||
rctf viewborder;
|
||||
|
||||
view3d_camera_border(scene, ar, v3d, rv3d, &viewborder, TRUE, TRUE);
|
||||
size_r[0] = BLI_rctf_size_x(&viewborder);
|
||||
size_r[1] = BLI_rctf_size_y(&viewborder);
|
||||
r_size[0] = BLI_rctf_size_x(&viewborder);
|
||||
r_size[1] = BLI_rctf_size_y(&viewborder);
|
||||
}
|
||||
|
||||
void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d,
|
||||
rctf *viewborder_r, short no_shift)
|
||||
rctf *viewborder_r, const bool no_shift)
|
||||
{
|
||||
view3d_camera_border(scene, ar, v3d, rv3d, viewborder_r, no_shift, FALSE);
|
||||
view3d_camera_border(scene, ar, v3d, rv3d, viewborder_r, no_shift, false);
|
||||
}
|
||||
|
||||
static void drawviewborder_grid3(float x1, float x2, float y1, float y2, float fac)
|
||||
|
||||
@@ -667,22 +667,29 @@ void ED_view3d_depth_tag_update(RegionView3D *rv3d)
|
||||
}
|
||||
|
||||
/* copies logic of get_view3d_viewplane(), keep in sync */
|
||||
int ED_view3d_clip_range_get(View3D *v3d, RegionView3D *rv3d, float *clipsta, float *clipend)
|
||||
bool ED_view3d_clip_range_get(View3D *v3d, RegionView3D *rv3d, float *r_clipsta, float *r_clipend,
|
||||
const bool use_ortho_factor)
|
||||
{
|
||||
CameraParams params;
|
||||
|
||||
BKE_camera_params_init(¶ms);
|
||||
BKE_camera_params_from_view3d(¶ms, v3d, rv3d);
|
||||
|
||||
if (clipsta) *clipsta = params.clipsta;
|
||||
if (clipend) *clipend = params.clipend;
|
||||
if (use_ortho_factor && params.is_ortho) {
|
||||
const float fac = 2.0f / (params.clipend - params.clipsta);
|
||||
params.clipsta *= fac;
|
||||
params.clipend *= fac;
|
||||
}
|
||||
|
||||
if (r_clipsta) *r_clipsta = params.clipsta;
|
||||
if (r_clipend) *r_clipend = params.clipend;
|
||||
|
||||
return params.is_ortho;
|
||||
}
|
||||
|
||||
/* also exposed in previewrender.c */
|
||||
int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy,
|
||||
rctf *viewplane, float *clipsta, float *clipend)
|
||||
bool ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy,
|
||||
rctf *r_viewplane, float *r_clipsta, float *r_clipend)
|
||||
{
|
||||
CameraParams params;
|
||||
|
||||
@@ -690,9 +697,9 @@ int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy,
|
||||
BKE_camera_params_from_view3d(¶ms, v3d, rv3d);
|
||||
BKE_camera_params_compute_viewplane(¶ms, winx, winy, 1.0f, 1.0f);
|
||||
|
||||
if (viewplane) *viewplane = params.viewplane;
|
||||
if (clipsta) *clipsta = params.clipsta;
|
||||
if (clipend) *clipend = params.clipend;
|
||||
if (r_viewplane) *r_viewplane = params.viewplane;
|
||||
if (r_clipsta) *r_clipsta = params.clipsta;
|
||||
if (r_clipend) *r_clipend = params.clipend;
|
||||
|
||||
return params.is_ortho;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user