[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43797] trunk/blender/source/blender/ editors: Implemented general functions to store view context like viewport width/ height

Sergey Sharybin sergey.vfx at gmail.com
Tue Jan 31 19:33:36 CET 2012


Revision: 43797
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43797
Author:   nazgul
Date:     2012-01-31 18:33:31 +0000 (Tue, 31 Jan 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/mesh/editmesh_loop.c
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2012-01-31 18:00:41 UTC (rev 43796)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2012-01-31 18:33:31 UTC (rev 43797)
@@ -52,8 +52,9 @@
 struct ViewContext;
 struct wmWindow;
 struct MVert;
+struct wmOperatorType;
+struct wmOperator;
 
-
 /* for derivedmesh drawing callbacks, for view3d_select, .... */
 typedef struct ViewContext {
 	struct Scene *scene;
@@ -209,6 +210,7 @@
 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 @@
 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 */

Modified: trunk/blender/source/blender/editors/mesh/editmesh_loop.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_loop.c	2012-01-31 18:00:41 UTC (rev 43796)
+++ trunk/blender/source/blender/editors/mesh/editmesh_loop.c	2012-01-31 18:33:31 UTC (rev 43797)
@@ -288,11 +288,17 @@
 /* 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 @@
 	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 @@
 		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 @@
 		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 @@
 	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 @@
 	/* 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);
 }
 
 /* ******************************************************* */

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2012-01-31 18:00:41 UTC (rev 43796)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c	2012-01-31 18:33:31 UTC (rev 43797)
@@ -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_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 @@
 				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);
+}



More information about the Bf-blender-cvs mailing list