[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24724] trunk/blender/source/blender: [ #19930] Nurb CV select is failing because of view clipping

Campbell Barton ideasman42 at gmail.com
Sat Nov 21 17:44:05 CET 2009


Revision: 24724
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24724
Author:   campbellbarton
Date:     2009-11-21 17:44:05 +0100 (Sat, 21 Nov 2009)

Log Message:
-----------
[#19930] Nurb CV select is failing because of view clipping
- the clipping test function was using the rv3d->viewmatob where it needed to use the object matrix.
- added a local clipping member to rv3d, the clipping planes in object-space, avoids many matrix multiplications when testing verts or clipping pixels when projection painting.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/mesh/editmesh_mods.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/editors/space_view3d/space_view3d.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c
    trunk/blender/source/blender/makesdna/DNA_view3d_types.h

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2009-11-21 14:35:28 UTC (rev 24723)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2009-11-21 16:44:05 UTC (rev 24724)
@@ -104,7 +104,8 @@
 void nurbs_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, int x, int y), void *userData);
 void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData);
 
-int view3d_test_clipping(struct RegionView3D *rv3d, float *vec);
+void ED_view3d_local_clipping(struct RegionView3D *rv3d, float mat[][4]);
+int view3d_test_clipping(struct RegionView3D *rv3d, float *vec, int local);
 void view3d_align_axis_to_vector(struct View3D *v3d, struct RegionView3D *rv3d, int axisidx, float vec[3]);
 
 void drawcircball(int mode, float *cent, float rad, float tmat[][4]);
@@ -143,5 +144,7 @@
 void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
 	int winx, int winy, float viewmat[][4], float winmat[][4]);
 
+void view3d_clipping_local(struct RegionView3D *rv3d, float mat[][4]);
+
 #endif /* ED_VIEW3D_H */
 

Modified: trunk/blender/source/blender/editors/mesh/editmesh_mods.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_mods.c	2009-11-21 14:35:28 UTC (rev 24723)
+++ trunk/blender/source/blender/editors/mesh/editmesh_mods.c	2009-11-21 16:44:05 UTC (rev 24724)
@@ -482,14 +482,17 @@
 	struct { ViewContext vc; float mval[2]; int dist; EditEdge *closest; } *data = userData;
 	float v1[2], v2[2];
 	int distance;
-		
+
+	ED_view3d_local_clipping(data->vc.rv3d, data->vc.obedit->obmat); /* for local clipping lookups */
+
 	v1[0] = x0;
 	v1[1] = y0;
 	v2[0] = x1;
 	v2[1] = y1;
-		
+
 	distance= dist_to_line_segment_v2(data->mval, v1, v2);
-		
+
+
 	if(eed->f & SELECT) distance+=5;
 	if(distance < data->dist) {
 		if(data->vc.rv3d->rflag & RV3D_CLIPPING) {
@@ -499,9 +502,8 @@
 			vec[0]= eed->v1->co[0] + labda*(eed->v2->co[0] - eed->v1->co[0]);
 			vec[1]= eed->v1->co[1] + labda*(eed->v2->co[1] - eed->v1->co[1]);
 			vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]);
-			mul_m4_v3(data->vc.obedit->obmat, vec);
 
-			if(view3d_test_clipping(data->vc.rv3d, vec)==0) {
+			if(view3d_test_clipping(data->vc.rv3d, vec, 1)==0) {
 				data->dist = distance;
 				data->closest = eed;
 			}

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2009-11-21 14:35:28 UTC (rev 24723)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2009-11-21 16:44:05 UTC (rev 24724)
@@ -861,8 +861,7 @@
 	if (side)	interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
 	else		interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
 	
-	mul_m4_v3(ps->ob->obmat, wco);
-	if(!view3d_test_clipping(ps->rv3d, wco)) {
+	if(!view3d_test_clipping(ps->rv3d, wco, 1)) {
 		return 1;
 	}
 	
@@ -2446,8 +2445,7 @@
 						/* a pitty we need to get the worldspace pixel location here */
 						if(ps->rv3d->rflag & RV3D_CLIPPING) {
 							interp_v3_v3v3v3(wco, ps->dm_mvert[ (*(&mf->v1 + i1)) ].co, ps->dm_mvert[ (*(&mf->v1 + i2)) ].co, ps->dm_mvert[ (*(&mf->v1 + i3)) ].co, w);
-							mul_m4_v3(ps->ob->obmat, wco);
-							if(view3d_test_clipping(ps->rv3d, wco)) {
+							if(view3d_test_clipping(ps->rv3d, wco, 1)) {
 								continue; /* Watch out that no code below this needs to run */
 							}
 						}
@@ -2663,9 +2661,8 @@
 											if(ps->rv3d->rflag & RV3D_CLIPPING) {
 												if (side)	interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
 												else		interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
-												
-												mul_m4_v3(ps->ob->obmat, wco);
-												if(view3d_test_clipping(ps->rv3d, wco)) {
+
+												if(view3d_test_clipping(ps->rv3d, wco, 1)) {
 													continue; /* Watch out that no code below this needs to run */
 												}
 											}
@@ -2934,6 +2931,8 @@
 	
 	/* ---- end defines ---- */
 	
+	ED_view3d_local_clipping(ps->rv3d, ps->ob->obmat); /* faster clipping lookups */
+
 	/* paint onto the derived mesh */
 	
 	/* Workaround for subsurf selection, try the display mesh first */

Modified: trunk/blender/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawobject.c	2009-11-21 14:35:28 UTC (rev 24723)
+++ trunk/blender/source/blender/editors/space_view3d/drawobject.c	2009-11-21 16:44:05 UTC (rev 24724)
@@ -142,7 +142,7 @@
 /* ************* only use while object drawing **************
  * or after running ED_view3d_init_mats_rv3d
  * */
-static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr)
+static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr, int local)
 {
 	RegionView3D *rv3d= ar->regiondata;
 	float fx, fy, vec4[4];
@@ -151,9 +151,7 @@
 	
 	/* clipplanes in eye space */
 	if(rv3d->rflag & RV3D_CLIPPING) {
-		VECCOPY(vec4, vec);
-		mul_m4_v3(rv3d->viewmatob, vec4);
-		if(view3d_test_clipping(rv3d, vec4))
+		if(view3d_test_clipping(rv3d, vec, local))
 			return;
 	}
 	
@@ -545,7 +543,7 @@
 	for(vos= strings->first; vos; vos= vos->next) {
 		if(mat)
 			mul_m4_v3(mat, vos->vec);
-		view3d_project_short_clip(ar, vos->vec, vos->mval);
+		view3d_project_short_clip(ar, vos->vec, vos->mval, 0);
 		if(vos->mval[0]!=IS_CLIPPED)
 			tot++;
 	}
@@ -1207,9 +1205,11 @@
 	int i, N = lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
 	short s[2] = {IS_CLIPPED, 0};
 
+	ED_view3d_local_clipping(vc->rv3d, obedit->obmat); /* for local clipping lookups */
+
 	for (i=0; i<N; i++, bp++, co+=3) {
 		if (bp->hide==0) {
-			view3d_project_short_clip(vc->ar, dl?co:bp->vec, s);
+			view3d_project_short_clip(vc->ar, dl?co:bp->vec, s, 1);
 			if (s[0] != IS_CLIPPED)
 				func(userData, bp, s[0], s[1]);
 		}
@@ -1314,7 +1314,7 @@
 		short s[2]= {IS_CLIPPED, 0};
 
 		if (data->clipVerts) {
-			view3d_project_short_clip(data->vc.ar, co, s);
+			view3d_project_short_clip(data->vc.ar, co, s, 1);
 		} else {
 			view3d_project_short_noclip(data->vc.ar, co, s);
 		}
@@ -1334,6 +1334,9 @@
 	data.userData = userData;
 	data.clipVerts = clipVerts;
 
+	if(clipVerts)
+		ED_view3d_local_clipping(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
+
 	EM_init_index_arrays(vc->em, 1, 0, 0);
 	dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
 	EM_free_index_arrays();
@@ -1349,8 +1352,8 @@
 
 	if (eed->h==0) {
 		if (data->clipVerts==1) {
-			view3d_project_short_clip(data->vc.ar, v0co, s[0]);
-			view3d_project_short_clip(data->vc.ar, v1co, s[1]);
+			view3d_project_short_clip(data->vc.ar, v0co, s[0], 1);
+			view3d_project_short_clip(data->vc.ar, v1co, s[1], 1);
 		} else {
 			view3d_project_short_noclip(data->vc.ar, v0co, s[0]);
 			view3d_project_short_noclip(data->vc.ar, v1co, s[1]);
@@ -1376,6 +1379,9 @@
 	data.userData = userData;
 	data.clipVerts = clipVerts;
 
+	if(clipVerts)
+		ED_view3d_local_clipping(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
+
 	EM_init_index_arrays(vc->em, 0, 1, 0);
 	dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
 	EM_free_index_arrays();
@@ -1390,7 +1396,7 @@
 	short s[2];
 
 	if (efa && efa->h==0 && efa->fgonf!=EM_FGON) {
-		view3d_project_short_clip(data->vc.ar, cent, s);
+		view3d_project_short_clip(data->vc.ar, cent, s, 1);
 
 		data->func(data->userData, efa, s[0], s[1], index);
 	}
@@ -1405,6 +1411,9 @@
 	data.func = func;
 	data.userData = userData;
 
+	//if(clipVerts)
+	ED_view3d_local_clipping(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
+
 	EM_init_index_arrays(vc->em, 0, 0, 1);
 	dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
 	EM_free_index_arrays();
@@ -1419,6 +1428,8 @@
 	Nurb *nu;
 	int i;
 
+	ED_view3d_local_clipping(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
+
 	for (nu= cu->editnurb->first; nu; nu=nu->next) {
 		if(nu->type == CU_BEZIER) {
 			for (i=0; i<nu->pntsu; i++) {
@@ -1427,17 +1438,17 @@
 				if(bezt->hide==0) {
 					
 					if(cu->drawflag & CU_HIDE_HANDLES) {
-						view3d_project_short_clip(vc->ar, bezt->vec[1], s);
+						view3d_project_short_clip(vc->ar, bezt->vec[1], s, 1);
 						if (s[0] != IS_CLIPPED)
 							func(userData, nu, NULL, bezt, 1, s[0], s[1]);
 					} else {
-						view3d_project_short_clip(vc->ar, bezt->vec[0], s);
+						view3d_project_short_clip(vc->ar, bezt->vec[0], s, 1);
 						if (s[0] != IS_CLIPPED)
 							func(userData, nu, NULL, bezt, 0, s[0], s[1]);
-						view3d_project_short_clip(vc->ar, bezt->vec[1], s);
+						view3d_project_short_clip(vc->ar, bezt->vec[1], s, 1);
 						if (s[0] != IS_CLIPPED)
 							func(userData, nu, NULL, bezt, 1, s[0], s[1]);
-						view3d_project_short_clip(vc->ar, bezt->vec[2], s);
+						view3d_project_short_clip(vc->ar, bezt->vec[2], s, 1);
 						if (s[0] != IS_CLIPPED)
 							func(userData, nu, NULL, bezt, 2, s[0], s[1]);
 					}
@@ -1449,7 +1460,7 @@
 				BPoint *bp = &nu->bp[i];
 
 				if(bp->hide==0) {
-					view3d_project_short_clip(vc->ar, bp->vec, s);
+					view3d_project_short_clip(vc->ar, bp->vec, s, 1);
 					if (s[0] != IS_CLIPPED)
 						func(userData, nu, bp, NULL, -1, s[0], s[1]);
 				}

Modified: trunk/blender/source/blender/editors/space_view3d/space_view3d.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/space_view3d.c	2009-11-21 14:35:28 UTC (rev 24723)
+++ trunk/blender/source/blender/editors/space_view3d/space_view3d.c	2009-11-21 16:44:05 UTC (rev 24724)
@@ -175,6 +175,9 @@
 	/* local viewmat and persmat, to calculate projections */
 	wmGetMatrix(rv3d->viewmatob);
 	wmGetSingleMatrix(rv3d->persmatob);
+
+	/* initializes object space clipping, speeds up clip tests */
+	ED_view3d_local_clipping(rv3d, ob->obmat);
 }
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list