[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59300] trunk/blender/source/blender: Dyntopo:

Antony Riakiotakis kalast at gmail.com
Mon Aug 19 16:08:59 CEST 2013


Revision: 59300
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59300
Author:   psy-fi
Date:     2013-08-19 14:08:59 +0000 (Mon, 19 Aug 2013)
Log Message:
-----------
Dyntopo:

Turn off pbvh normal update flag after recalculation, saves
recalculating normals every frame when not stroking the mesh.

For this to work reliably with undo we need to support original normals
in the bm_log (was marked as a TODO already in the code), so that
undoing avoids having invalid normals in the mesh (since we don't update
every frame anymore). This was added in this commit as well.

Also added some (disabled) quite paranoid checks in the bmesh valication
code for dyntopo hoping to catch the real normal update issue. No luck
there yet.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/pbvh_bmesh.c
    trunk/blender/source/blender/bmesh/intern/bmesh_log.c
    trunk/blender/source/blender/bmesh/intern/bmesh_log.h
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c

Modified: trunk/blender/source/blender/blenkernel/intern/pbvh_bmesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pbvh_bmesh.c	2013-08-19 14:03:44 UTC (rev 59299)
+++ trunk/blender/source/blender/blenkernel/intern/pbvh_bmesh.c	2013-08-19 14:08:59 UTC (rev 59300)
@@ -1026,9 +1026,11 @@
 		GHASH_ITER (gh_iter, node->bm_unique_verts) {
 			BM_vert_normal_update(BLI_ghashIterator_getKey(&gh_iter));
 		}
+		/* This should be unneeded normally */
 		GHASH_ITER (gh_iter, node->bm_other_verts) {
 			BM_vert_normal_update(BLI_ghashIterator_getKey(&gh_iter));
 		}
+		node->flag &= ~PBVH_UpdateNormals;
 	}
 }
 
@@ -1365,7 +1367,9 @@
 void pbvh_bmesh_verify(PBVH *bvh)
 {
 	GHashIterator gh_iter;
-	int i;
+	int i, vert_count = 0;
+	BMIter iter;
+	BMVert *vi;
 
 	/* Check faces */
 	BLI_assert(bvh->bm->totface == BLI_ghash_size(bvh->bm_face_to_node));
@@ -1431,8 +1435,37 @@
 			}
 		}
 		BLI_assert(found);
+
+		#if 0
+		/* total freak stuff, check if node exists somewhere else */
+		/* Slow */
+		for (i = 0; i < bvh->totnode; i++) {
+			PBVHNode *n = &bvh->nodes[i];
+			if (i != ni && n->bm_unique_verts)
+				BLI_assert(!BLI_ghash_haskey(n->bm_unique_verts, v));
+		}
+
+		#endif
 	}
 
+	#if 0
+	/* check that every vert belongs somewhere */
+	/* Slow */
+	BM_ITER_MESH (vi, &iter, bvh->bm, BM_VERTS_OF_MESH) {
+		bool has_unique = false;
+		for (i = 0; i < bvh->totnode; i++) {
+			PBVHNode *n = &bvh->nodes[i];
+			if ((n->bm_unique_verts != NULL) && BLI_ghash_haskey(n->bm_unique_verts, vi))
+				has_unique = true;
+		}
+		BLI_assert(has_unique);
+		vert_count++;
+	}
+
+	/* if totvert differs from number of verts inside the hash. hash-totvert is checked above  */
+	BLI_assert(vert_count == bvh->bm->totvert);
+	#endif
+
 	/* Check that node elements are recorded in the top level */
 	for (i = 0; i < bvh->totnode; i++) {
 		PBVHNode *n = &bvh->nodes[i];

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_log.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_log.c	2013-08-19 14:03:44 UTC (rev 59299)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_log.c	2013-08-19 14:08:59 UTC (rev 59300)
@@ -95,6 +95,7 @@
 
 typedef struct {
 	float co[3];
+	short no[3];
 	float mask;
 	char hflag;
 } BMLogVert;
@@ -187,6 +188,7 @@
 static void bm_log_vert_bmvert_copy(BMesh *bm, BMLogVert *lv, BMVert *v)
 {
 	copy_v3_v3(lv->co, v->co);
+	normal_float_to_short_v3(lv->no, v->no);
 	lv->mask = vert_mask_get(bm, v);
 	lv->hflag = v->head.hflag;
 }
@@ -276,6 +278,7 @@
 		BMVert *v = BM_vert_create(bm, lv->co, NULL, 0);
 		v->head.hflag = lv->hflag;
 		vert_mask_set(bm, v, lv->mask);
+		normal_short_to_float_v3(v->no, lv->no);
 		bm_log_vert_id_set(log, v, GET_INT_FROM_POINTER(key));
 	}
 }
@@ -305,8 +308,12 @@
 		unsigned int id = GET_INT_FROM_POINTER(key);
 		BMVert *v = bm_log_vert_from_id(log, id);
 		float mask;
+		short normal[3];
 
 		swap_v3_v3(v->co, lv->co);
+		copy_v3_v3_short(normal, lv->no);
+		normal_float_to_short_v3(lv->no, v->no);
+		normal_short_to_float_v3(v->no, normal);
 		SWAP(char, v->head.hflag, lv->hflag);
 		mask = lv->mask;
 		lv->mask = vert_mask_get(bm, v);
@@ -927,6 +934,24 @@
 	return lv->co;
 }
 
+/* Get the logged normal of a vertex
+ *
+ * Does not modify the log or the vertex */
+const short *BM_log_original_vert_no(BMLog *log, BMVert *v)
+{
+	BMLogEntry *entry = log->current_entry;
+	const BMLogVert *lv;
+	unsigned v_id = bm_log_vert_id_get(log, v);
+	void *key = SET_INT_IN_POINTER(v_id);
+
+	BLI_assert(entry);
+
+	BLI_assert(BLI_ghash_haskey(entry->modified_verts, key));
+
+	lv = BLI_ghash_lookup(entry->modified_verts, key);
+	return lv->no;
+}
+
 /* Get the logged mask of a vertex
  *
  * Does not modify the log or the vertex */

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_log.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_log.h	2013-08-19 14:03:44 UTC (rev 59299)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_log.h	2013-08-19 14:08:59 UTC (rev 59300)
@@ -92,6 +92,9 @@
 /* Get the logged coordinates of a vertex */
 const float *BM_log_original_vert_co(BMLog *log, BMVert *v);
 
+/* Get the logged normal of a vertex */
+const short *BM_log_original_vert_no(BMLog *log, BMVert *v);
+
 /* Get the logged mask of a vertex */
 float BM_log_original_mask(BMLog *log, BMVert *v);
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-08-19 14:03:44 UTC (rev 59299)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-08-19 14:08:59 UTC (rev 59300)
@@ -330,7 +330,7 @@
 	/* Original coordinate, normal, and mask */
 	const float *co;
 	float mask;
-	short no[3];
+	const short *no;
 } SculptOrigVertData;
 
 
@@ -381,11 +381,10 @@
 		}
 
 		if (orig_data->normals) {
-			copy_v3_v3_short(orig_data->no, orig_data->normals[iter->i]);
+			orig_data->no = orig_data->normals[iter->i];
 		}
 		else {
-			/* TODO: log doesn't store normals yet */
-			normal_float_to_short_v3(orig_data->no, iter->bm_vert->no);
+			orig_data->no = BM_log_original_vert_no(orig_data->bm_log, iter->bm_vert);
 		}
 	}
 	else if (orig_data->unode->type == SCULPT_UNDO_MASK) {




More information about the Bf-blender-cvs mailing list