[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18728] branches/blender2.5/blender/source /blender: * Brought back special normal recalc for sculpt ( only recalculates modified faces/verts)

Nicholas Bishop nicholasbishop at gmail.com
Thu Jan 29 04:50:52 CET 2009


Revision: 18728
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18728
Author:   nicholasbishop
Date:     2009-01-29 04:50:46 +0100 (Thu, 29 Jan 2009)

Log Message:
-----------
* Brought back special normal recalc for sculpt (only recalculates modified faces/verts)
* Means that full object recalc isn't done, so multires works more as expected now
* Moved mesh element cache back to sculpt session (from sculpt cache), really makes more sense there

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_sculpt.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c
    branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_sculpt.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_sculpt.h	2009-01-29 03:43:04 UTC (rev 18727)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_sculpt.h	2009-01-29 03:50:46 UTC (rev 18728)
@@ -30,16 +30,22 @@
 #ifndef BKE_SCULPT_H
 #define BKE_SCULPT_H
 
-struct NumInput;
-struct RadialControl;
-struct Scene;
+struct MFace;
+struct MultireModifierData;
+struct MVert;
 struct Sculpt;
-struct SculptSession;
 struct StrokeCache;
 
 typedef struct SculptSession {
 	struct ProjVert *projverts;
 
+	/* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
+	struct MultiresModifierData *multires; /* Special handling for multires meshes */
+	struct MVert *mvert;
+	struct MFace *mface;
+	int totvert, totface;
+	float *face_normals;
+	
 	/* Mesh connectivity */
 	struct ListBase *fmap;
 	struct IndexNode *fmap_mem;
@@ -55,8 +61,6 @@
 
 	void *cursor; /* wm handle */
 
-	struct RadialControl *radialcontrol;
-	
 	struct SculptStroke *stroke;
 
 	struct StrokeCache *cache;

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c	2009-01-29 03:43:04 UTC (rev 18727)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c	2009-01-29 03:50:46 UTC (rev 18728)
@@ -1018,15 +1018,16 @@
 
 	/* Modulate curve with texture */
 	if(texcache) {
-		for(i=0; i<side; ++i)
+		for(i=0; i<side; ++i) {
 			for(j=0; j<side; ++j) {
 				const int col= texcache[i*side+j];
 				im->rect_float[i*side+j]*= (((char*)&col)[0]+((char*)&col)[1]+((char*)&col)[2])/3.0f/255.0f;
 			}
+		}
+
+		MEM_freeN(texcache);
 	}
 
-	MEM_freeN(texcache);
-
 	return im;
 }
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c	2009-01-29 03:43:04 UTC (rev 18727)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/scene.c	2009-01-29 03:50:46 UTC (rev 18728)
@@ -658,9 +658,6 @@
 		if(ss->projverts)
 			MEM_freeN(ss->projverts);
 
-		if(ss->radialcontrol)
-			MEM_freeN(ss->radialcontrol);
-
 		if(ss->fmap)
 			MEM_freeN(ss->fmap);
 

Modified: branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-29 03:43:04 UTC (rev 18727)
+++ branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-29 03:50:46 UTC (rev 18728)
@@ -145,13 +145,6 @@
 	ViewContext vc;
 	bglMats *mats;
 
-	/* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
-	int multires; /* Special handling for multires meshes */
-	MVert *mvert;
-	MFace *mface;
-	int totvert, totface;
-	float *face_normals;
-
 	float *layer_disps; /* Displacements for each vertex */
  	float (*mesh_store)[3]; /* Copy of the mesh vertices' locations */
 	short (*orig_norms)[3]; /* Copy of the mesh vertices' normals */
@@ -331,7 +324,7 @@
 	}
 	else {
 		for(; node; node = node->next)
-			add_norm_if(out_dir, out, out_flip, cache->mvert[node->Index].no);
+			add_norm_if(out_dir, out, out_flip, sd->session->mvert[node->Index].no);
 	}
 
 	if (out[0]==0.0 && out[1]==0.0 && out[2]==0.0) {
@@ -359,7 +352,7 @@
 	sculpt_axislock(sd, area_normal);
 	
 	while(node){
-		float *co= ss->cache->mvert[node->Index].co;
+		float *co= ss->mvert[node->Index].co;
 		
 		const float val[3]= {co[0]+area_normal[0]*node->Fade*ss->cache->scale[0],
 		                     co[1]+area_normal[1]*node->Fade*ss->cache->scale[1],
@@ -385,12 +378,12 @@
 		
 	/* Don't modify corner vertices */
 	if(ncount==1) {
-		VecCopyf(avg, ss->cache->mvert[vert].co);
+		VecCopyf(avg, ss->mvert[vert].co);
 		return;
 	}
 
 	while(node){
-		f= &ss->cache->mface[node->index];
+		f= &ss->mface[node->index];
 		
 		if(f->v4) {
 			skip= (f->v1==vert?2:
@@ -401,7 +394,7 @@
 
 		for(i=0; i<(f->v4?4:3); ++i) {
 			if(i != skip && (ncount!=2 || BLI_countlist(&ss->fmap[(&f->v1)[i]]) <= 2)) {
-				VecAddf(avg, avg, ss->cache->mvert[(&f->v1)[i]].co);
+				VecAddf(avg, avg, ss->mvert[(&f->v1)[i]].co);
 				++total;
 			}
 		}
@@ -412,7 +405,7 @@
 	if(total>0)
 		VecMulf(avg, 1.0f / total);
 	else
-		VecCopyf(avg, ss->cache->mvert[vert].co);
+		VecCopyf(avg, ss->mvert[vert].co);
 }
 
 static void do_smooth_brush(SculptSession *ss, const ListBase* active_verts)
@@ -420,7 +413,7 @@
 	ActiveData *node= active_verts->first;
 
 	while(node){
-		float *co= ss->cache->mvert[node->Index].co;
+		float *co= ss->mvert[node->Index].co;
 		float avg[3], val[3];
 
 		neighbor_average(ss, avg, node->Index);
@@ -438,7 +431,7 @@
  	ActiveData *node= active_verts->first;
 
 	while(node) {
-		float *co= ss->cache->mvert[node->Index].co;
+		float *co= ss->mvert[node->Index].co;
 		const float val[3]= {co[0]+(ss->cache->location[0]-co[0])*node->Fade,
 		                     co[1]+(ss->cache->location[1]-co[1])*node->Fade,
 		                     co[2]+(ss->cache->location[2]-co[2])*node->Fade};
@@ -457,7 +450,7 @@
 	sculpt_axislock(sd, grab_delta);
 	
 	while(node) {
-		float *co= ss->cache->mvert[node->Index].co;
+		float *co= ss->mvert[node->Index].co;
 		
 		VecCopyf(add, grab_delta);
 		VecMulf(add, node->Fade);
@@ -482,7 +475,7 @@
 		
 		if((bstr > 0 && *disp < bstr) ||
 		  (bstr < 0 && *disp > bstr)) {
-		  	float *co= ss->cache->mvert[node->Index].co;
+		  	float *co= ss->mvert[node->Index].co;
 		  	
 			*disp+= node->Fade;
 
@@ -512,8 +505,8 @@
 	float add[3];
 	
 	while(node) {
-		float *co= ss->cache->mvert[node->Index].co;
-		short *no= ss->cache->mvert[node->Index].no;
+		float *co= ss->mvert[node->Index].co;
+		short *no= ss->mvert[node->Index].no;
 
 		add[0]= no[0]/ 32767.0f;
 		add[1]= no[1]/ 32767.0f;
@@ -549,7 +542,7 @@
 	
 	co[0] = co[1] = co[2] = 0.0f;
 	for(i = 0; i < FLATTEN_SAMPLE_SIZE; ++i)
-		VecAddf(co, co, ss->cache->mvert[outer[i]->Index].co);
+		VecAddf(co, co, ss->mvert[outer[i]->Index].co);
 	VecMulf(co, 1.0f / FLATTEN_SAMPLE_SIZE);
 }
 
@@ -564,7 +557,7 @@
 	calc_flatten_center(ss, node, cntr);
 
 	while(node){
-		float *co= ss->cache->mvert[node->Index].co;
+		float *co= ss->mvert[node->Index].co;
 		float p1[3], sub1[3], sub2[3], intr[3], val[3];
 		
 		/* Find the intersection between squash-plane and vertex (along the area normal) */
@@ -743,7 +736,7 @@
 	BLI_addtail(&ss->damaged_rects, rn);
 
 	/* Update insides */
-	for(i=0; i<ss->cache->totvert; ++i) {
+	for(i=0; i<ss->totvert; ++i) {
 		if(!ss->projverts[i].inside) {
 			if(ss->projverts[i].co[0] > rn->r.xmin && ss->projverts[i].co[1] > rn->r.ymin &&
 			   ss->projverts[i].co[0] < rn->r.xmax && ss->projverts[i].co[1] < rn->r.ymax) {
@@ -757,6 +750,7 @@
 }
 
 /* Clears the depth buffer in each modified area. */
+#if 0
 static void sculpt_clear_damaged_areas(SculptSession *ss)
 {
 	RectNode *rn= NULL;
@@ -785,7 +779,7 @@
 		glClear(GL_DEPTH_BUFFER_BIT);
 	}
 }
-
+#endif
 static void do_brush_action(Sculpt *sd, StrokeCache *cache)
 {
 	SculptSession *ss = sd->session;
@@ -805,11 +799,11 @@
 	/* Build a list of all vertices that are potentially within the brush's
 	   area of influence. Only do this once for the grab brush. */
 	if((b->sculpt_tool != SCULPT_TOOL_GRAB) || cache->first_time) {
-		for(i=0; i<cache->totvert; ++i) {
+		for(i=0; i<ss->totvert; ++i) {
 			/* Projverts.inside provides a rough bounding box */
-			if(cache->multires || ss->projverts[i].inside) {
+			if(ss->multires || ss->projverts[i].inside) {
 				//vert= ss->vertexcosnos ? &ss->vertexcosnos[i*6] : a->verts[i].co;
-				vert= cache->mvert[i].co;
+				vert= ss->mvert[i].co;
 				av_dist= VecLenf(ss->cache->location, vert);
 				if(av_dist < cache->radius) {
 					adata= (ActiveData*)MEM_mallocN(sizeof(ActiveData), "ActiveData");
@@ -857,7 +851,7 @@
 		}
 	
 		/* Copy the modified vertices from mesh to the active key */
-		if(keyblock && !cache->multires) {
+		if(keyblock && !ss->multires) {
 			float *co= keyblock->data;
 			if(co) {
 				if(b->sculpt_tool == SCULPT_TOOL_GRAB)
@@ -871,7 +865,7 @@
 			}
 		}
 
-		if(ss->vertexcosnos && !cache->multires)
+		if(ss->vertexcosnos && !ss->multires)
 			BLI_freelistN(&active_verts);
 		else {
 			if(b->sculpt_tool != SCULPT_TOOL_GRAB)
@@ -952,16 +946,16 @@
 
 		while(face){
 			float *fn = NULL;
-			if(ss->cache->face_normals)
-				fn = &ss->cache->face_normals[face->index*3];
-			add_face_normal(&norm, ss->cache->mvert, &ss->cache->mface[face->index], fn);
+			if(ss->face_normals)
+				fn = &ss->face_normals[face->index*3];
+			add_face_normal(&norm, ss->mvert, &ss->mface[face->index], fn);
 			face= face->next;
 		}
 		Normalize(&norm.x);
 		
-		ss->cache->mvert[vert->Index].no[0]=norm.x*32767;
-		ss->cache->mvert[vert->Index].no[1]=norm.y*32767;
-		ss->cache->mvert[vert->Index].no[2]=norm.z*32767;
+		ss->mvert[vert->Index].no[0]=norm.x*32767;
+		ss->mvert[vert->Index].no[1]=norm.y*32767;
+		ss->mvert[vert->Index].no[2]=norm.z*32767;
 	}
 }
 
@@ -971,18 +965,19 @@
 	
 	for(i=0; i<8; ++i)
 		update_damaged_vert(ss, &ss->cache->grab_active_verts[i]);
-
 	update_damaged_vert(ss, &ss->damaged_verts);
 	BLI_freelistN(&ss->damaged_verts);
 	ss->damaged_verts.first = ss->damaged_verts.last = NULL;
 }
 
+#if 0
 static void projverts_clear_inside(SculptSession *ss)
 {
 	int i;
-	for(i = 0; i < ss->cache->totvert; ++i)
+	for(i = 0; i < ss->totvert; ++i)
 		ss->projverts[i].inside = 0;
 }
+#endif
 
 static void sculpt_update_tex(Sculpt *sd)
 {
@@ -1027,10 +1022,10 @@
 	unsigned i;
 
 	if(!ss->projverts)
-		ss->projverts = MEM_mallocN(sizeof(ProjVert)*ss->cache->totvert,"ProjVerts");
+		ss->projverts = MEM_mallocN(sizeof(ProjVert)*ss->totvert,"ProjVerts");
 
-	for(i=0; i<ss->cache->totvert; ++i) {
-		project(ss->cache->mats, ss->vertexcosnos ? &ss->vertexcosnos[i * 6] : ss->cache->mvert[i].co,
+	for(i=0; i<ss->totvert; ++i) {
+		project(ss->cache->mats, ss->vertexcosnos ? &ss->vertexcosnos[i * 6] : ss->mvert[i].co,
 			ss->projverts[i].co);
 		ss->projverts[i].inside= 0;
 	}
@@ -1066,32 +1061,31 @@
 	return NULL;
 }
 
-static void sculpt_update_mesh_elements(SculptSession *ss, Object *ob)
+static void sculpt_update_mesh_elements(bContext *C)
 {
-	StrokeCache *cache = ss->cache;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list