diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-01-31 22:33:31 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-01-31 22:33:31 +0400 |
commit | db79c8b01e67e8707aa3810cb727997c9ea3c250 (patch) | |
tree | 9901a0588df91f92ed4a631a46d81cdcd89ec563 /source | |
parent | 23db21e2c17052ba756a68eb7450fedacc14c555 (diff) |
Implemented general functions to store view context like viewport width/height
and projection matrix, so operators which depends on such things can easily save
settings in operator properties in invoke and then reuse them in exec callback.
This will fix: #24767: Knife tool last operations panel doesn't cause changes even though F6 pop-up does.
#27129: Problem with knife cuts/midpoint type in quad view
Usage is pretty simple:
- From operator template declaration function call ED_view3d_operator_properties_viewmat()
to register all needed properties in operator.
- From invoke callback call ED_view3d_operator_properties_viewmat_set to
store all needed settings in operator properties().
- To access this settings from exec callback, use function
ED_view3d_operator_properties_viewmat_get().
Additional change:
added function apply_project_float() which does the same as
project_float() but accepts actual values for viewport width/height and
projection matrix.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 9 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_loop.c | 20 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 67 |
3 files changed, 83 insertions, 13 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index f087cdc7442..7616e25cbe9 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -52,7 +52,8 @@ struct View3D; struct ViewContext; struct wmWindow; struct MVert; - +struct wmOperatorType; +struct wmOperator; /* for derivedmesh drawing callbacks, for view3d_select, .... */ typedef struct ViewContext { @@ -209,6 +210,7 @@ void project_short_noclip(struct ARegion *ar, const float vec[3], short adr[2]); void project_int(struct ARegion *ar, const float vec[3], int adr[2]); void project_int_noclip(struct ARegion *ar, const float vec[3], int adr[2]); +void apply_project_float(float persmat[4][4], int winx, int winy, const float vec[], float adr[2]); void project_float(struct ARegion *ar, const float vec[3], float adr[2]); void project_float_noclip(struct ARegion *ar, const float vec[3], float adr[2]); @@ -301,4 +303,9 @@ struct BGpic *ED_view3D_background_image_new(struct View3D *v3d); void ED_view3D_background_image_remove(struct View3D *v3d, struct BGpic *bgpic); void ED_view3D_background_image_clear(struct View3D *v3d); +/* view matrix properties utilities */ +void ED_view3d_operator_properties_viewmat(struct wmOperatorType *ot); +void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOperator *op); +void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op, int *winx, int *winy, float persmat[4][4]); + #endif /* ED_VIEW3D_H */ diff --git a/source/blender/editors/mesh/editmesh_loop.c b/source/blender/editors/mesh/editmesh_loop.c index 19adaa977bf..01695331542 100644 --- a/source/blender/editors/mesh/editmesh_loop.c +++ b/source/blender/editors/mesh/editmesh_loop.c @@ -288,11 +288,17 @@ static float seg_intersect(EditEdge *e, CutCurve *c, int len, char mode, struct /* for amount of edges */ #define MAX_CUT_EDGES 1024 +static int knife_cut_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ED_view3d_operator_properties_viewmat_set(C, op); + + return WM_gesture_lines_invoke(C, op, event); +} + static int knife_cut_exec(bContext *C, wmOperator *op) { Object *obedit= CTX_data_edit_object(C); EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data)); - ARegion *ar= CTX_wm_region(C); EditEdge *eed; EditVert *eve; CutCurve curve[MAX_CUT_EDGES]; @@ -302,10 +308,12 @@ static int knife_cut_exec(bContext *C, wmOperator *op) int len=0; short numcuts= RNA_int_get(op->ptr, "num_cuts"); short mode= RNA_enum_get(op->ptr, "type"); + int winx, winy; + float persmat[4][4]; // int corner_cut_pattern= RNA_enum_get(op->ptr,"corner_cut_pattern"); /* edit-object needed for matrix, and ar->regiondata for projections to work */ - if (ELEM3(NULL, obedit, ar, ar->regiondata)) + if (obedit == NULL) return OPERATOR_CANCELLED; if (EM_nvertices_selected(em) < 2) { @@ -328,6 +336,8 @@ static int knife_cut_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + ED_view3d_operator_properties_viewmat_get(op, &winx, &winy, persmat); + /*store percentage of edge cut for KNIFE_EXACT here.*/ for(eed=em->edges.first; eed; eed= eed->next) eed->tmp.fp = 0.0; @@ -339,7 +349,7 @@ static int knife_cut_exec(bContext *C, wmOperator *op) VECCOPY(co, eve->co); co[3]= 1.0; mul_m4_v4(obedit->obmat, co); - project_float(ar, co, scr); + apply_project_float(persmat, winx, winy, co, scr); BLI_ghash_insert(gh, eve, scr); eve->f1 = 0; /*store vertex intersection flag here*/ @@ -390,7 +400,7 @@ void MESH_OT_knife_cut(wmOperatorType *ot) ot->description= "Cut selected edges and faces into parts"; ot->idname= "MESH_OT_knife_cut"; - ot->invoke= WM_gesture_lines_invoke; + ot->invoke= knife_cut_invoke; ot->modal= WM_gesture_lines_modal; ot->exec= knife_cut_exec; ot->cancel= WM_gesture_lines_cancel; @@ -409,6 +419,8 @@ void MESH_OT_knife_cut(wmOperatorType *ot) /* internal */ prop = RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); RNA_def_property_flag(prop, PROP_HIDDEN); + + ED_view3d_operator_properties_viewmat(ot); } /* ******************************************************* */ diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index f57d8a5ec1b..05e8cb45611 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -68,6 +68,9 @@ #include "BL_System.h" #endif +#include "RNA_access.h" +#include "RNA_define.h" + #include "view3d_intern.h" // own include /* use this call when executing an operator, @@ -947,23 +950,30 @@ void project_short_noclip(ARegion *ar, const float vec[3], short adr[2]) } } -void project_float(ARegion *ar, const float vec[3], float adr[2]) +void apply_project_float(float persmat[4][4], int winx, int winy, const float vec[3], float adr[2]) { - RegionView3D *rv3d= ar->regiondata; float vec4[4]; - + copy_v3_v3(vec4, vec); vec4[3]= 1.0; adr[0]= IS_CLIPPED; - - mul_m4_v4(rv3d->persmat, vec4); - + + mul_m4_v4(persmat, vec4); + if(vec4[3] > (float)BL_NEAR_CLIP) { - adr[0] = (float)(ar->winx/2.0f)+(ar->winx/2.0f)*vec4[0]/vec4[3]; - adr[1] = (float)(ar->winy/2.0f)+(ar->winy/2.0f)*vec4[1]/vec4[3]; + adr[0] = (float)(winx/2.0f)+(winx/2.0f)*vec4[0]/vec4[3]; + adr[1] = (float)(winy/2.0f)+(winy/2.0f)*vec4[1]/vec4[3]; } } +void project_float(ARegion *ar, const float vec[3], float adr[2]) +{ + RegionView3D *rv3d= ar->regiondata; + float vec4[4]; + + apply_project_float(rv3d->persmat, ar->winx, ar->winy, vec, adr); +} + void project_float_noclip(ARegion *ar, const float vec[3], float adr[2]) { RegionView3D *rv3d= ar->regiondata; @@ -1854,3 +1864,44 @@ float ED_view3d_pixel_size(struct RegionView3D *rv3d, const float co[3]) rv3d->persmat[2][3]*co[2]) ) * rv3d->pixsize; } + +/* view matrix properties utilities */ + +void ED_view3d_operator_properties_viewmat(wmOperatorType *ot) +{ + PropertyRNA *prop; + + prop = RNA_def_int(ot->srna, "region_width", 0, 0, INT_MAX, "Region Width", "", 0, INT_MAX); + RNA_def_property_flag(prop, PROP_HIDDEN); + + prop = RNA_def_int(ot->srna, "region_height", 0, 0, INT_MAX, "Region height", "", 0, INT_MAX); + RNA_def_property_flag(prop, PROP_HIDDEN); + + prop = RNA_def_float_matrix(ot->srna, "perspective_matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Perspective Matrix", 0.0f, 0.0f); + RNA_def_property_flag(prop, PROP_HIDDEN); +} + +void ED_view3d_operator_properties_viewmat_set(bContext *C, wmOperator *op) +{ + ARegion *ar= CTX_wm_region(C); + RegionView3D *rv3d= ED_view3d_context_rv3d(C); + + if(!RNA_struct_property_is_set(op->ptr, "region_width")) + RNA_int_set(op->ptr, "region_width", ar->winx); + + if(!RNA_struct_property_is_set(op->ptr, "region_height")) + RNA_int_set(op->ptr, "region_height", ar->winy); + + if(!RNA_struct_property_is_set(op->ptr, "perspective_matrix")) + RNA_float_set_array(op->ptr, "perspective_matrix", (float *)rv3d->persmat); +} + +void ED_view3d_operator_properties_viewmat_get(wmOperator *op, int *winx, int *winy, float persmat[4][4]) +{ + float values[16]; + + *winx = RNA_int_get(op->ptr, "region_width"); + *winy = RNA_int_get(op->ptr, "region_height"); + + RNA_float_get_array(op->ptr, "perspective_matrix", (float *)persmat); +} |