[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29415] branches/branch-farsthary/source/ blender: first draft of realtime unlimited clay, currently very slow and not ready for production, but architecturally correct and target to improvement.

Raul Fernandez Hernandez farsthary at gmail.com
Fri Jun 11 22:38:51 CEST 2010


Revision: 29415
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29415
Author:   farsthary
Date:     2010-06-11 22:38:51 +0200 (Fri, 11 Jun 2010)

Log Message:
-----------
first draft of realtime unlimited clay, currently very slow and not ready for production, but architecturally correct and target to improvement.
The default is static unlimited clay, in order to use realtime, activate the Accumulate checkbox.
the two slow functions are the load_editMesh() and the BLI_pbvh_build_mesh()
Also I have simplified/cleaned the code.

Modified Paths:
--------------
    branches/branch-farsthary/source/blender/blenkernel/intern/brush.c
    branches/branch-farsthary/source/blender/blenloader/intern/readfile.c
    branches/branch-farsthary/source/blender/editors/include/ED_mesh.h
    branches/branch-farsthary/source/blender/editors/mesh/mesh_intern.h
    branches/branch-farsthary/source/blender/editors/sculpt_paint/sculpt.c

Modified: branches/branch-farsthary/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/branch-farsthary/source/blender/blenkernel/intern/brush.c	2010-06-11 18:22:33 UTC (rev 29414)
+++ branches/branch-farsthary/source/blender/blenkernel/intern/brush.c	2010-06-11 20:38:51 UTC (rev 29415)
@@ -83,7 +83,7 @@
 	brush->clone.alpha= 0.5;
 	brush->sculpt_tool = SCULPT_TOOL_DRAW;
 	brush->flag |= BRUSH_SPACE;
-	brush->detail = 0.25f;
+	brush->detail = 1.0f;
 	brush->smoothness = 0.25f;
 
 	brush_curve_preset(brush, CURVE_PRESET_SMOOTH);

Modified: branches/branch-farsthary/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/branch-farsthary/source/blender/blenloader/intern/readfile.c	2010-06-11 18:22:33 UTC (rev 29414)
+++ branches/branch-farsthary/source/blender/blenloader/intern/readfile.c	2010-06-11 20:38:51 UTC (rev 29415)
@@ -10774,7 +10774,7 @@
 	Brush *brush;
 	for (brush= main->brush.first; brush; brush= brush->id.next){
 		if(brush->detail == 0.0f)
-			brush->detail = 0.25f;
+			brush->detail = 1.0f;
 		if (brush->smoothness == 0.0f)
 			brush->smoothness = 0.25f;
 	

Modified: branches/branch-farsthary/source/blender/editors/include/ED_mesh.h
===================================================================
--- branches/branch-farsthary/source/blender/editors/include/ED_mesh.h	2010-06-11 18:22:33 UTC (rev 29414)
+++ branches/branch-farsthary/source/blender/editors/include/ED_mesh.h	2010-06-11 20:38:51 UTC (rev 29415)
@@ -299,9 +299,6 @@
 
 extern void rotateflag(struct EditMesh *em, short flag, float *cent, float rotmat[][3]);
 extern void translateflag(struct EditMesh *em, short flag, float *vec);
-
-extern int convex(float *v1, float *v2, float *v3, float *v4);
-
 extern struct EditFace *EM_face_from_faces(struct EditMesh *em, struct EditFace *efa1,struct EditFace *efa2, int i1, int i2, int i3, int i4);
 
 extern int EM_view3d_poll(struct bContext *C);

Modified: branches/branch-farsthary/source/blender/editors/mesh/mesh_intern.h
===================================================================
--- branches/branch-farsthary/source/blender/editors/mesh/mesh_intern.h	2010-06-11 18:22:33 UTC (rev 29414)
+++ branches/branch-farsthary/source/blender/editors/mesh/mesh_intern.h	2010-06-11 20:38:51 UTC (rev 29415)
@@ -116,6 +116,7 @@
 
 /* ******************* mesh_data.c */
 int EdgeSlide(struct EditMesh *em, struct wmOperator *op, short immediate, float imperc);
+extern int convex(float *v1, float *v2, float *v3, float *v4);
 
 
 void MESH_OT_uv_texture_add(struct wmOperatorType *ot);

Modified: branches/branch-farsthary/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/branch-farsthary/source/blender/editors/sculpt_paint/sculpt.c	2010-06-11 18:22:33 UTC (rev 29414)
+++ branches/branch-farsthary/source/blender/editors/sculpt_paint/sculpt.c	2010-06-11 20:38:51 UTC (rev 29415)
@@ -92,7 +92,7 @@
 
 /* Number of vertices to average in order to determine the flatten distance */
 #define FLATTEN_SAMPLE_SIZE 10
-
+static void unlimited_clay(SculptSession *ss, Object *ob, int is_dynamic);
 /* ===== STRUCTS =====
  *
  */
@@ -539,76 +539,7 @@
 
 /* ===== Sculpting =====
  *
- */
-  
-static void create_EditMesh_sculpt(SculptSession *ss) //Mio
-{	
-	EditEdge *eed;	
-	Object *obedit= ss->ob;
-	Mesh *me= obedit->data;
-	
-	int tempselectmode = ss->scene->toolsettings->selectmode; /* store temporal scene select mode*/
-	ss->scene->toolsettings->selectmode = SCE_SELECT_VERTEX;	
-	
-	make_editMesh(ss->scene, obedit);						
-	EditMesh *em = me->edit_mesh;	
-	
-	ss->scene->toolsettings->selectmode = tempselectmode; /* restore scene select mode*/	
-		
-	/*select all edges associated with every selected vertex*/
-	for(eed= em->edges.first; eed; eed= eed->next){
-		if(eed->v1->f&SELECT) eed->f1 = 1;
-		else if(eed->v2->f&SELECT) eed->f1 = 1;
-	}
-			
-	for(eed= em->edges.first; eed; eed= eed->next)
-		if(eed->f1 == 1) EM_select_edge(eed,1);	
-		
-	ss->em = em;
-}
- 
-static void unlimited_clay(SculptSession *ss, Object *ob)
-{
-	/*---- adaptive dynamic subdivission -- */
-		float v1co[3],v2co[3],diff[3], edgeLength; 	
-			
-		if (ss->scene != NULL && ob != NULL) 
-		{
-			create_EditMesh_sculpt(ss);
-	 		Object *obedit= ob;
-			Mesh *me= obedit->data;			
-			EditEdge *eed;
-			float detail = ss->cache->detail * ss->cache->radius;
-			float smoothness = ss->cache->smoothness;
-			 
-			for(eed = me->edit_mesh->edges.first; eed; eed = eed->next){
-				if (eed->f & SELECT)
-				{
-					sub_v3_v3v3(diff, eed->v1->co, eed->v2->co);
-					edgeLength = len_v3(diff);					  
-															
-					if (edgeLength < detail)
-						EM_select_edge(eed, 0);	
-					else	
-						EM_select_edge(eed, 1);			
-				
-				}									
-					
-			}									
-			esubdivideflag(obedit, me->edit_mesh, SELECT,smoothness,0,B_SMOOTH,1, SUBDIV_CORNER_PATH, SUBDIV_SELECT_INNER);			
-			
-			/* Clear selection */
-			for(eed = me->edit_mesh->edges.first; eed; eed = eed->next)
-				EM_select_edge(eed, 0);	 
-				
-			load_editMesh(ss->scene, ob);
-			
-			free_editMesh(me->edit_mesh);
-			DAG_id_flush_update(ob->data, OB_RECALC_DATA); //?					
-		} 	
-
-}
-
+ */ 
 /* Return modified brush strength. Includes the direction of the brush, positive
    values pull vertices, negative values push. Uses tablet pressure and a
    special multiplier found experimentally to scale the strength factor. */
@@ -938,7 +869,7 @@
 				sculpt_clip(sd, ss, vd.co, val);
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
 			}
 		}
@@ -1016,7 +947,7 @@
 			sculpt_clip(sd, ss, vd.co, val);			
 			if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
 		}
 	}
@@ -1148,7 +1079,7 @@
 				sculpt_clip(sd, ss, vd.co, val);			
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
 			}
 		}
@@ -1186,7 +1117,7 @@
 				sculpt_clip(sd, ss, vd.co, add);			
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
 			}
 		}
@@ -1257,7 +1188,7 @@
 				sculpt_clip(sd, ss, vd.co, val);
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
 			}
 		}
@@ -1298,7 +1229,7 @@
 				sculpt_clip(sd, ss, vd.co, add);
 				if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
 			}
 		}
@@ -1438,9 +1369,9 @@
 					sculpt_clip(sd, ss, vd.co, val);
 					if(vd.mvert) {
 					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
-				   }
+					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag  |= SELECT; 
 				}
+				}
 			}
 		}
 		BLI_pbvh_vertex_iter_end;
@@ -2146,6 +2077,7 @@
 {
 	Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
 	SculptSession *ss = CTX_data_active_object(C)->sculpt;
+	Brush *brush = paint_brush(&sd->paint);
 
 	sculpt_stroke_modifiers_check(C, ss);
 	sculpt_update_cache_variants(sd, ss, stroke, itemptr);
@@ -2154,6 +2086,7 @@
 
 	/* Cleanup */
 	sculpt_flush_update(C);
+	if(brush->flag & BRUSH_SUBDIV && brush->flag & BRUSH_ACCUMULATE) unlimited_clay(ss, CTX_data_active_object(C),1);
 }
 
 static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke)
@@ -2167,7 +2100,7 @@
 	if(ss->cache) {
 		sculpt_stroke_modifiers_check(C, ss);
 		
-		if(brush->flag & BRUSH_SUBDIV) unlimited_clay(ss, ob);
+		if(brush->flag & BRUSH_SUBDIV && !(brush->flag & BRUSH_ACCUMULATE)) unlimited_clay(ss, CTX_data_active_object(C),0);
 
 		sculpt_cache_free(ss->cache);
 		ss->cache = NULL;
@@ -2188,6 +2121,75 @@
 	}
 }
 
+/* unlimited clay , adaptive dynamic subdivission */
+static void unlimited_clay(SculptSession *ss, Object *ob, int is_dynamic)
+{
+	/*---- adaptive dynamic subdivission -- */
+	float v1co[3],v2co[3],diff[3], edgeLength; 	
+	Object *obedit= ob;
+	Mesh *me= obedit->data;
+	EditMesh *em;			
+	EditEdge *eed;
+	float detail = ss->cache->detail * ss->cache->radius;
+	float smoothness = ss->cache->smoothness;
+	int tempselectmode = ss->scene->toolsettings->selectmode; /* store temporal scene select mode*/
+	ss->scene->toolsettings->selectmode = SCE_SELECT_VERTEX;	
+	
+	 make_editMesh(ss->scene, obedit);	
+	em= me->edit_mesh;		
+	ss->scene->toolsettings->selectmode = tempselectmode; /* restore scene select mode*/	
+		
+	/*select all edges associated with every selected vertex*/
+	for(eed= em->edges.first; eed; eed= eed->next){
+		if(eed->v1->f&SELECT) eed->f1 = 1;
+		else if(eed->v2->f&SELECT) eed->f1 = 1;
+	}
+			
+	for(eed= em->edges.first; eed; eed= eed->next)
+		if(eed->f1 == 1) EM_select_edge(eed,1);	
+
+	
+	/* If edge length is larger than detail, mark for subdivide */ 				 
+	for(eed = em->edges.first; eed; eed = eed->next){
+		if (eed->f & SELECT)
+		{
+			sub_v3_v3v3(diff, eed->v1->co, eed->v2->co);
+			edgeLength = len_v3(diff);  
+													
+			if (edgeLength < detail)
+				EM_select_edge(eed, 0);	
+			else	
+				EM_select_edge(eed, 1);						
+		
+		}									
+			
+	}									
+	esubdivideflag(obedit, em, SELECT,smoothness,0,B_SMOOTH,1, SUBDIV_CORNER_PATH, SUBDIV_SELECT_INNER);			
+		
+	/* Clear selection */
+	EM_deselect_all(em);					
+	load_editMesh(ss->scene, ob);
+	
+	free_editMesh(em);
+	MEM_freeN(me->edit_mesh);
+	me->edit_mesh = NULL;
+			
+	/* rebuild or update the PBVH structure, very slow step :( */
+	if (is_dynamic){
+		if (ss->pbvh) BLI_pbvh_free(ss->pbvh);
+		ss->pbvh= BLI_pbvh_new(); 	
+		BLI_pbvh_build_mesh(ss->pbvh, me->mface, me->mvert, me->totface, me->totvert);
+		ss->totvert = me->totvert;
+		ss->totface = me->totface;
+		ss->mvert = me->mvert;
+		ss->mface = me->mface;
+		ss->face_normals = NULL;	
+		ss->fmap =  NULL;
+		ss->cache->original = 0;	
+	}	
+	DAG_id_flush_update(ob->data, OB_RECALC_DATA); 					
+}
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list