[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38124] branches/soc-2011-radish/source/ blender: Added Selection support to weight paint.

Jason Hays jason_hays22 at mymail.eku.edu
Tue Jul 5 20:03:31 CEST 2011


Revision: 38124
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38124
Author:   jason_hays22
Date:     2011-07-05 18:03:31 +0000 (Tue, 05 Jul 2011)
Log Message:
-----------
Added Selection support to weight paint.
"Started" putting in wp's circle select, but it isn't there yet.

Modified Paths:
--------------
    branches/soc-2011-radish/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2011-radish/source/blender/editors/include/ED_mesh.h
    branches/soc-2011-radish/source/blender/editors/include/ED_view3d.h
    branches/soc-2011-radish/source/blender/editors/mesh/editmesh.c
    branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2011-radish/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2011-radish/source/blender/editors/space_view3d/view3d_select.c

Modified: branches/soc-2011-radish/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2011-radish/source/blender/blenkernel/intern/cdderivedmesh.c	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/blenkernel/intern/cdderivedmesh.c	2011-07-05 18:03:31 UTC (rev 38124)
@@ -277,12 +277,14 @@
 	if( GPU_buffer_legacy(dm) ) {
 		glBegin(GL_POINTS);
 		for(i = 0; i < dm->numVertData; i++, mv++) {
-			if(mv->flag & 1) {//TODO define selected
+			if((mv->flag & 1)) {//TODO define selected
 				glColor3f(1.0f, 1.0f, 0.0f);
 			}else {
 				glColor3f(0.0f, 0.0f, 0.0f);
 			}
-			glVertex3fv(mv->co);
+			if(!(mv->flag & ME_HIDE)) {
+				glVertex3fv(mv->co);
+			}
 		}
 		glEnd();
 	}

Modified: branches/soc-2011-radish/source/blender/editors/include/ED_mesh.h
===================================================================
--- branches/soc-2011-radish/source/blender/editors/include/ED_mesh.h	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/editors/include/ED_mesh.h	2011-07-05 18:03:31 UTC (rev 38124)
@@ -122,8 +122,9 @@
 int			EM_vertColorCheck(struct EditMesh *em);
 
 void		undo_push_mesh(struct bContext *C, const char *name);
+/* Jason */
+void		paintvert_flush_flags(struct Object *ob);
 
-
 /* editmesh_lib.c */
 
 struct EditFace	*EM_get_actFace(struct EditMesh *em, int sloppy);

Modified: branches/soc-2011-radish/source/blender/editors/include/ED_view3d.h
===================================================================
--- branches/soc-2011-radish/source/blender/editors/include/ED_view3d.h	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/editors/include/ED_view3d.h	2011-07-05 18:03:31 UTC (rev 38124)
@@ -215,6 +215,9 @@
 void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift);
 
 /* drawobject.c iterators */
+/*Jason*/
+void mesh_obmode_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct MVert *mv, int x, int y, int index), void *userData, int clipVerts);
+
 void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts);
 void mesh_foreachScreenEdge(struct ViewContext *vc, void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts);
 void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData);

Modified: branches/soc-2011-radish/source/blender/editors/mesh/editmesh.c
===================================================================
--- branches/soc-2011-radish/source/blender/editors/mesh/editmesh.c	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/editors/mesh/editmesh.c	2011-07-05 18:03:31 UTC (rev 38124)
@@ -1959,3 +1959,37 @@
 		vc->em= me->edit_mesh;
 	}
 }
+
+
+/* Jason (similar to void paintface_flush_flags(Object *ob))
+ * copy the vertex flags, most importantly selection from the mesh to the final derived mesh,
+ * use in object mode when selecting vertices (while painting) */
+void paintvert_flush_flags(Object *ob)
+{
+	Mesh *me= get_mesh(ob);
+	DerivedMesh *dm= ob->derivedFinal;
+	MVert *verts, *mv, *mv_orig;
+	int *index_array = NULL;
+	int totvert;
+	int i;
+	
+	if(me==NULL || dm==NULL)
+		return;
+
+	index_array = dm->getVertDataArray(dm, CD_ORIGINDEX);
+	
+	verts = dm->getVertArray(dm);
+	totvert = dm->getNumVerts(dm);
+	
+	mv= verts;
+	
+	for (i= 0; i<totvert; i++, mv++) { /* loop over derived mesh faces */
+		if(index_array) {
+			mv_orig= me->mvert + index_array[i];
+			mv->flag= mv_orig->flag;
+		} else {
+			mv_orig= me->mvert + i;
+			mv->flag= mv_orig->flag;
+		}
+	}
+}
\ No newline at end of file

Modified: branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/editors/sculpt_paint/paint_vertex.c	2011-07-05 18:03:31 UTC (rev 38124)
@@ -1204,6 +1204,7 @@
 			if(dw && dw->weight) {
 				val = dw->weight * change;
 				if(val > 1) {
+					// Jason TODO: when the change is reduced, you need to recheck the earlier values to make sure they are not 0 (precision error)
 					change = 1.0f/dw->weight;
 				}
 				if(val <= 0) {

Modified: branches/soc-2011-radish/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2011-radish/source/blender/editors/space_view3d/drawobject.c	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/editors/space_view3d/drawobject.c	2011-07-05 18:03:31 UTC (rev 38124)
@@ -58,6 +58,7 @@
 #include "BKE_anim.h"			//for the where_on_path function
 #include "BKE_constraint.h" // for the get_constraint_target function
 #include "BKE_DerivedMesh.h"
+
 #include "BKE_deform.h"
 #include "BKE_displist.h"
 #include "BKE_font.h"
@@ -1657,7 +1658,45 @@
 
 	dm->release(dm);
 }
+/*Jason */
+static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
+{
+	struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData;
+	Mesh *me = data->vc.obact->data;
+	MVert *mv = me->mvert+index;
+	//MVert *dmv = CDDM_get_verts(data->vc.obact->derivedFinal)+index;
+	//MVert *mv = CDDM_get_verts(data->vc.obact->derivedFinal)+index;
+	if ((mv->flag & ME_HIDE)==0) {
+		short s[2]= {IS_CLIPPED, 0};
 
+		if (data->clipVerts) {
+			view3d_project_short_clip(data->vc.ar, co, s, 1);
+		} else {
+			view3d_project_short_noclip(data->vc.ar, co, s);
+		}
+
+		if (s[0]!=IS_CLIPPED)
+			data->func(data->userData, me->mvert, s[0], s[1], index);
+	}
+}
+/*Jason*/
+void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, MVert *mv, int x, int y, int index), void *userData, int clipVerts)
+{
+	struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } data;
+	DerivedMesh *dm = mesh_get_derived_final(vc->scene, vc->obact, CD_MASK_BAREMESH);
+
+	data.vc= *vc;
+	data.func = func;
+	data.userData = userData;
+	data.clipVerts = clipVerts;
+	
+	if(clipVerts)
+		ED_view3d_local_clipping(vc->rv3d, vc->obact->obmat); /* for local clipping lookups */
+
+	dm->foreachMappedVert(dm, mesh_obmode_foreachScreenVert__mapFunc, &data);
+
+	dm->release(dm);
+}
 static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co)
 {
 	struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData;
@@ -2744,6 +2783,7 @@
 					dm->drawEdges(dm, (dt==OB_WIRE || totface==0), me->drawflag);
 					glPointSize(3.0f);
 					dm->drawSelectedVerts(dm);
+					//draw_obmode_dm_verts(dm, 1);
 					glPointSize(1.0f);
 				}
 			}

Modified: branches/soc-2011-radish/source/blender/editors/space_view3d/view3d_select.c
===================================================================
--- branches/soc-2011-radish/source/blender/editors/space_view3d/view3d_select.c	2011-07-05 18:02:08 UTC (rev 38123)
+++ branches/soc-2011-radish/source/blender/editors/space_view3d/view3d_select.c	2011-07-05 18:03:31 UTC (rev 38124)
@@ -197,7 +197,23 @@
 		}
 	}
 }
+/* Jason */
+static void EM_backbuf_checkAndSelectTVerts(Mesh *me, int select)
+{
+	MVert *mv = me->mvert;
+	int a;
 
+	if (mv) {
+		for(a=1; a<=me->totvert; a++, mv++) {
+			if(EM_check_backbuf(a)) {
+				if(!(mv->flag & ME_HIDE)) {
+					mv->flag = select?(mv->flag|SELECT):(mv->flag&~SELECT);
+				}
+			}
+		}
+	}
+}
+
 static void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select)
 {
 	MFace *mface = me->mface;
@@ -1827,7 +1843,70 @@
 	/* rna */
 	WM_operator_properties_gesture_border(ot, TRUE);
 }
+/*Jason*/
+static void findnearestWPvert__doClosest(void *userData, MVert *mv, int x, int y, int index)
+{
+	struct { MVert *mv; short dist, select; int mval[2]; } *data = userData;
+	float temp = abs(data->mval[0]-x) + abs(data->mval[1]-y);
+	mv = mv+index;
+	if((mv->flag & SELECT)==data->select)
+		temp += 5;
 
+	if(temp<data->dist) {
+		data->dist = temp;
+
+		data->mv = mv;
+	}
+}
+/*Jason*/
+static MVert *findnearestWPvert(ViewContext *vc, Object *obact, Mesh *me, const int mval[2], int sel)
+{
+	/* sel==1: selected gets a disadvantage */
+	struct { MVert *mv; short dist, select; int mval[2]; } data = {NULL};
+
+	data.dist = 100;
+	data.select = sel;
+	data.mval[0]= mval[0];
+	data.mval[1]= mval[1];
+
+	mesh_obmode_foreachScreenVert(vc, findnearestWPvert__doClosest, &data, 1);
+
+	return data.mv;
+}
+/* Jason */
+/* mouse selection in weight paint */
+/* gets called via generic mouse select operator */
+int mouse_wp_select(bContext *C, const int mval[2], short extend, Object *obact, Mesh* me)
+{
+	MVert *mv;
+	ViewContext *vc = NULL;
+	vc = MEM_callocN(sizeof(ViewContext), "wp_m_sel_viewcontext");
+	vc->ar= CTX_wm_region(C);
+	vc->scene= CTX_data_scene(C);
+	vc->v3d= CTX_wm_view3d(C);
+	vc->rv3d= CTX_wm_region_view3d(C);
+	vc->obact= obact;
+	vc->mval[0] = mval[0];
+	vc->mval[1] = mval[1];
+
+	ED_view3d_init_mats_rv3d(obact, vc->rv3d);
+
+	if(mv = findnearestWPvert(vc, obact, me, mval, 1)) {
+		if(extend) {
+			mv->flag ^= 1;
+		} else {
+			mv->flag |= 1;
+		}
+		paintvert_flush_flags(vc->obact);
+		WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data);
+
+		MEM_freeN(vc);
+		return 1;
+	}
+	MEM_freeN(vc);
+	return 0;
+}
+
 /* ****** Mouse Select ****** */
 
 
@@ -1839,9 +1918,11 @@
 	short center= RNA_boolean_get(op->ptr, "center");
 	short enumerate= RNA_boolean_get(op->ptr, "enumerate");
 	int	retval = 0;
+	// Jason
+	Mesh *me;
+	Scene *scene = CTX_data_scene(C);
 
 	view3d_operator_needs_opengl(C);
-	
 	if(obedit) {
 		if(obedit->type==OB_MESH)
 			retval = mouse_mesh(C, event->mval, extend);
@@ -1861,8 +1942,12 @@
 		return PE_mouse_particles(C, event->mval, extend);
 	else if(obact && paint_facesel_test(obact))
 		retval = paintface_mouse_select(C, obact, event->mval, extend);
-	else
+	/*Jason*/

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list