[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18535] branches/blender2.5/blender/source /blender/editors: Added a view3d function to read cached depth buffer, before was in sculpt.c where it didn't belong.

Nicholas Bishop nicholasbishop at gmail.com
Fri Jan 16 02:56:11 CET 2009


Revision: 18535
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18535
Author:   nicholasbishop
Date:     2009-01-16 02:56:11 +0100 (Fri, 16 Jan 2009)

Log Message:
-----------
Added a view3d function to read cached depth buffer, before was in sculpt.c where it didn't belong.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/ED_view3d.h
    branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c

Modified: branches/blender2.5/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_view3d.h	2009-01-16 01:19:08 UTC (rev 18534)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_view3d.h	2009-01-16 01:56:11 UTC (rev 18535)
@@ -61,6 +61,8 @@
 
 /* Projection */
 
+float read_cached_depth(struct ViewContext *vc, int x, int y);
+
 void project_short(struct ARegion *ar, struct View3D *v3d, float *vec, short *adr);
 void project_short_noclip(struct ARegion *ar, struct View3D *v3d, float *vec, short *adr);
 

Modified: branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-16 01:19:08 UTC (rev 18534)
+++ branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-16 01:56:11 UTC (rev 18535)
@@ -145,6 +145,8 @@
 
 	int first_time; /* Beginning of stroke may do some things special */
 
+	ViewContext vc;
+
 	/* Mesh data can either come directly from a Mesh, or from a MultiresDM */
 	int multires; /* Special handling for multires meshes */
 	MVert *mvert;
@@ -234,32 +236,6 @@
  * Simple functions to get data from the GL
  */
 
-/* Uses window coordinates (x,y) to find the depth in the GL depth buffer. If
-   available, G.vd->depths is used so that the brush doesn't sculpt on top of
-   itself (G.vd->depths is only updated at the end of a brush stroke.) */
-static float get_depth(bContext *C, short x, short y)
-{
-	ScrArea *sa= CTX_wm_area(C);
-
-	if(sa->spacetype==SPACE_VIEW3D) { // should check this in context instead?
-		ViewDepths *vd = ((View3D*)sa->spacedata.first)->depths;
-		
-		y -= CTX_wm_region(C)->winrct.ymin;
-
-		if(vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h)
-			return vd->depths[y * vd->w + x];
-
-		if(!vd)
-			fprintf(stderr, "Error: Bad view3d!\n");
-		else if(!vd->depths)
-			fprintf(stderr, "Error: Bad depths copy!\n");
-		else
-			fprintf(stderr, "Error: Out of range: (%d,%d)\n", x, y);
-	}
-
-	return 1;
-}
-
 /* Uses window coordinates (x,y) and depth component z to find a point in
    modelspace */
 static void unproject(SculptSession *ss, float out[3], const short x, const short y, const float z)
@@ -1692,7 +1668,7 @@
 	SculptData *sd = &CTX_data_scene(C)->sculptdata;
 	Object *ob= CTX_data_active_object(C);
 	ModifierData *md;
-	float depth = get_depth(C, event->x, event->y);
+	ViewContext vc;
 	float scale[3], clip_tolerance[3] = {0,0,0};
 	int mouse[2], flag = 0;
 
@@ -1724,9 +1700,11 @@
 	RNA_int_set_array(op->ptr, "initial_mouse", mouse);
 
 	/* Initial screen depth under the mouse */
-	RNA_float_set(op->ptr, "depth", depth);
+	view3d_set_viewcontext(C, &vc);
+	RNA_float_set(op->ptr, "depth", read_cached_depth(&vc, event->x, event->y));
 
 	sculpt_update_cache_invariants(sd, op, ob);
+	sd->session->cache->vc = vc;
 }
 
 static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
@@ -1776,7 +1754,8 @@
 	float center[3];
 	int mouse[2] = {event->x, event->y};
 
-	unproject(sd->session, center, event->x, event->y, get_depth(C, event->x, event->y));
+	unproject(sd->session, center, event->x, event->y,
+		  read_cached_depth(&sd->session->cache->vc, event->x, event->y));
 
 	/* Add to stroke */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);

Modified: branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c	2009-01-16 01:19:08 UTC (rev 18534)
+++ branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_view.c	2009-01-16 01:56:11 UTC (rev 18535)
@@ -497,6 +497,18 @@
 	vec[2]= (v3d->persinv[0][2]*dx + v3d->persinv[1][2]*dy);
 }
 
+float read_cached_depth(ViewContext *vc, int x, int y)
+{
+	ViewDepths *vd = vc->v3d->depths;
+		
+	y -= vc->ar->winrct.ymin;
+
+	if(vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h)
+		return vd->depths[y * vd->w + x];
+	else
+		return 1;
+}
+
 void view3d_get_object_project_mat(View3D *v3d, Object *ob, float pmat[4][4], float vmat[4][4])
 {
 	Mat4MulMat4(vmat, ob->obmat, v3d->viewmat);





More information about the Bf-blender-cvs mailing list