[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36891] trunk/blender/source/blender/ editors: fix [#27479] Missing 'Select vertex groups under the cursor' in weight paint mode

Campbell Barton ideasman42 at gmail.com
Wed May 25 12:08:00 CEST 2011


Revision: 36891
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36891
Author:   campbellbarton
Date:     2011-05-25 10:07:59 +0000 (Wed, 25 May 2011)
Log Message:
-----------
fix [#27479] Missing 'Select vertex groups under the cursor' in weight paint mode
really todo :) but still needs to be done.

Split this into 2 operators, works like 2.4x
- Ctrl+LMB samples weight.
- Shift+LMB selects vertex groups.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2011-05-25 07:06:56 UTC (rev 36890)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2011-05-25 10:07:59 UTC (rev 36891)
@@ -729,6 +729,9 @@
 	RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
 	prop= RNA_struct_find_property(&ptr, propname);
 
+	/* don't let bad properties slip through */
+	BLI_assert((prop == NULL) || (RNA_property_type(prop) == PROP_ENUM));
+
 	if(prop && RNA_property_type(prop) == PROP_ENUM) {
 		EnumPropertyItem *item;
 		int totitem, i, free;

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2011-05-25 07:06:56 UTC (rev 36890)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2011-05-25 10:07:59 UTC (rev 36891)
@@ -84,6 +84,8 @@
 void PAINT_OT_weight_paint(struct wmOperatorType *ot);
 void PAINT_OT_weight_set(struct wmOperatorType *ot);
 void PAINT_OT_weight_from_bones(struct wmOperatorType *ot);
+void PAINT_OT_weight_sample(struct wmOperatorType *ot);
+void PAINT_OT_weight_sample_group(struct wmOperatorType *ot);
 
 void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_vertex_paint(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2011-05-25 07:06:56 UTC (rev 36890)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2011-05-25 10:07:59 UTC (rev 36891)
@@ -370,6 +370,8 @@
 	WM_operatortype_append(PAINT_OT_weight_paint);
 	WM_operatortype_append(PAINT_OT_weight_set);
 	WM_operatortype_append(PAINT_OT_weight_from_bones);
+	WM_operatortype_append(PAINT_OT_weight_sample);
+	WM_operatortype_append(PAINT_OT_weight_sample_group);
 
 	/* vertex */
 	WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
@@ -589,6 +591,10 @@
 
 	WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
 
+	/* these keys are from 2.4x but could be changed */
+	WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
+	WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+
 	WM_keymap_add_item(keymap,
 			"PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c	2011-05-25 07:06:56 UTC (rev 36890)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c	2011-05-25 10:07:59 UTC (rev 36891)
@@ -61,6 +61,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_action.h"
@@ -72,6 +73,7 @@
 #include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_paint.h"
+#include "BKE_report.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -855,145 +857,194 @@
 
 /* ----------------------------------------------------- */
 
-/* used for 3d view, on active object, assumes me->dvert exists */
-/* if mode==1: */
-/*     samples cursor location, and gives menu with vertex groups to activate */
-/* else */
-/*     sets wp->weight to the closest weight value to vertex */
-/*     note: we cant sample frontbuf, weight colors are interpolated too unpredictable */
-static void sample_wpaint(Scene *scene, ARegion *ar, View3D *UNUSED(v3d), int mode)
+
+/* sets wp->weight to the closest weight value to vertex */
+/* note: we cant sample frontbuf, weight colors are interpolated too unpredictable */
+static int weight_sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
 	ViewContext vc;
-	ToolSettings *ts= scene->toolsettings;
-	Object *ob= OBACT;
-	Mesh *me= get_mesh(ob);
-	int index;
-	int mval[2] = {0, 0}, sco[2];
-	int vgroup= ob->actdef-1;
+	Mesh *me;
+	short change= FALSE;
 
-	if (!me) return;
-	
-//	getmouseco_areawin(mval);
-	index= view3d_sample_backbuf(&vc, mval[0], mval[1]);
-	
-	if(index && index<=me->totface) {
-		MFace *mface;
-		
-		mface= ((MFace *)me->mface) + index-1;
-		
-		if(mode==1) {	/* sampe which groups are in here */
-			MDeformVert *dv;
-			int a, totgroup;
-			
-			totgroup= BLI_countlist(&ob->defbase);
-			if(totgroup) {
-				int totmenu=0;
-				int *groups=MEM_callocN(totgroup*sizeof(int), "groups");
-				
-				dv= me->dvert+mface->v1;
-				for(a=0; a<dv->totweight; a++) {
-					if (dv->dw[a].def_nr<totgroup)
-						groups[dv->dw[a].def_nr]= 1;
-				}
-				dv= me->dvert+mface->v2;
-				for(a=0; a<dv->totweight; a++) {
-					if (dv->dw[a].def_nr<totgroup)
-						groups[dv->dw[a].def_nr]= 1;
-				}
-				dv= me->dvert+mface->v3;
-				for(a=0; a<dv->totweight; a++) {
-					if (dv->dw[a].def_nr<totgroup)
-						groups[dv->dw[a].def_nr]= 1;
-				}
-				if(mface->v4) {
-					dv= me->dvert+mface->v4;
-					for(a=0; a<dv->totweight; a++) {
-						if (dv->dw[a].def_nr<totgroup)
-							groups[dv->dw[a].def_nr]= 1;
-					}
-				}
-				for(a=0; a<totgroup; a++)
-					if(groups[a]) totmenu++;
-				
-				if(totmenu==0) {
-					//notice("No Vertex Group Selected");
-				}
-				else {
-					bDeformGroup *dg;
-					short val;
-					char item[40], *str= MEM_mallocN(40*totmenu+40, "menu");
-					
-					strcpy(str, "Vertex Groups %t");
-					for(a=0, dg=ob->defbase.first; dg && a<totgroup; a++, dg= dg->next) {
-						if(groups[a]) {
-							sprintf(item, "|%s %%x%d", dg->name, a);
-							strcat(str, item);
-						}
-					}
-					
-					val= 0; // XXX pupmenu(str);
-					if(val>=0) {
-						ob->actdef= val+1;
-						DAG_id_tag_update(&me->id, 0);
-					}
-					MEM_freeN(str);
-				}
-				MEM_freeN(groups);
-			}
-//			else notice("No Vertex Groups in Object");
-		}
-		else {
-			DerivedMesh *dm;
-			float w1, w2, w3, w4, co[3], fac;
-			
-			dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+	view3d_set_viewcontext(C, &vc);
+	me= get_mesh(vc.obact);
+
+	if (me && me->dvert && vc.ar->regiontype==RGN_TYPE_WINDOW) {
+		int index;
+
+		view3d_operator_needs_opengl(C);
+
+		index= view3d_sample_backbuf(&vc, event->mval[0], event->mval[1]);
+
+		if(index && index<=me->totface) {
+			DerivedMesh *dm= mesh_get_derived_final(vc.scene, vc.obact, CD_MASK_BAREMESH);
+
 			if(dm->getVertCo==NULL) {
-				//notice("Not supported yet");
+				BKE_report(op->reports, RPT_WARNING, "The modifier used does not support deformed locations");
 			}
 			else {
-				/* calc 3 or 4 corner weights */
-				dm->getVertCo(dm, mface->v1, co);
-				project_int_noclip(ar, co, sco);
-				w1= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1]));
-				
-				dm->getVertCo(dm, mface->v2, co);
-				project_int_noclip(ar, co, sco);
-				w2= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1]));
-				
-				dm->getVertCo(dm, mface->v3, co);
-				project_int_noclip(ar, co, sco);
-				w3= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1]));
-				
-				if(mface->v4) {
-					dm->getVertCo(dm, mface->v4, co);
-					project_int_noclip(ar, co, sco);
-					w4= ((mval[0]-sco[0])*(mval[0]-sco[0]) + (mval[1]-sco[1])*(mval[1]-sco[1]));
-				}
-				else w4= 1.0e10;
-				
-				fac= MIN4(w1, w2, w3, w4);
-				if(w1==fac) {
-					ts->vgroup_weight= defvert_find_weight(me->dvert+mface->v1, vgroup);
-				}
-				else if(w2==fac) {
-					ts->vgroup_weight= defvert_find_weight(me->dvert+mface->v2, vgroup);
-				}
-				else if(w3==fac) {
-					ts->vgroup_weight= defvert_find_weight(me->dvert+mface->v3, vgroup);
-				}
-				else if(w4==fac) {
-					if(mface->v4) {
-						ts->vgroup_weight= defvert_find_weight(me->dvert+mface->v4, vgroup);
+				MFace *mf= ((MFace *)me->mface) + index-1;
+				const int vgroup= vc.obact->actdef - 1;
+				ToolSettings *ts= vc.scene->toolsettings;
+				float mval_f[2];
+				int v_idx_best= -1;
+				int fidx;
+				float len_best= FLT_MAX;
+
+				mval_f[0]= (float)event->mval[0];
+				mval_f[1]= (float)event->mval[1];
+
+				fidx= mf->v4 ? 3:2;
+				do {
+					float co[3], sco[3], len;
+					const int v_idx= (*(&mf->v1 + fidx));
+					dm->getVertCo(dm, v_idx, co);
+					project_float_noclip(vc.ar, co, sco);
+					len= len_squared_v2v2(mval_f, sco);
+					if(len < len_best) {
+						len_best= len;
+						v_idx_best= v_idx;
 					}
+				} while (fidx--);
+
+				if(v_idx_best != -1) { /* should always be valid */
+					ts->vgroup_weight= defvert_find_weight(&me->dvert[v_idx_best], vgroup);
+					change= TRUE;
 				}
 			}
 			dm->release(dm);
-		}		
-		
+		}
 	}
-	
+
+	if(change) {
+		/* not really correct since the brush didnt change, but redraws the toolbar */
+		WM_main_add_notifier(NC_BRUSH|NA_EDITED, NULL); /* ts->wpaint->paint.brush */
+
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
 }
 
+void PAINT_OT_weight_sample(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Weight Paint Sample Weight";
+	ot->idname= "PAINT_OT_weight_sample";
+
+	/* api callbacks */
+	ot->invoke= weight_sample_invoke;
+	ot->poll= weight_paint_mode_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_UNDO;
+}
+
+/* samples cursor location, and gives menu with vertex groups to activate */
+static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), int *free)
+{
+	if (C) {
+		wmWindow *win= CTX_wm_window(C);
+		if(win && win->eventstate) {
+			ViewContext vc;
+			Mesh *me;
+
+			view3d_set_viewcontext(C, &vc);
+			me= get_mesh(vc.obact);
+
+			if (me && me->dvert && vc.ar->regiontype==RGN_TYPE_WINDOW) {
+				int index;
+
+				view3d_operator_needs_opengl(C);
+
+				index= view3d_sample_backbuf(&vc, win->eventstate->x - vc.ar->winrct.xmin, win->eventstate->y - vc.ar->winrct.ymin);
+
+				if(index && index<=me->totface) {
+					const int totgroup= BLI_countlist(&vc.obact->defbase);
+					if(totgroup) {
+						MFace *mf= ((MFace *)me->mface) + index-1;
+						int fidx= mf->v4 ? 3:2;
+						int *groups= MEM_callocN(totgroup*sizeof(int), "groups");
+						int found= FALSE;
+
+						do {
+							MDeformVert *dvert= me->dvert + (*(&mf->v1 + fidx));
+							int i= dvert->totweight;
+							MDeformWeight *dw;
+							for(dw= dvert->dw; i > 0; dw++, i--) {
+								groups[dw->def_nr]= TRUE;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list