[Bf-blender-cvs] [bbe8311948d] hair_guides: Sparser edge drawing for grooms to reduce visual clutter.

Lukas Tönne noreply at git.blender.org
Sun Jan 7 14:03:10 CET 2018


Commit: bbe8311948d8e82df07738ad34f8e0cc25a2f9d9
Author: Lukas Tönne
Date:   Sun Jan 7 13:01:49 2018 +0000
Branches: hair_guides
https://developer.blender.org/rBbbe8311948d8e82df07738ad34f8e0cc25a2f9d9

Sparser edge drawing for grooms to reduce visual clutter.

===================================================================

M	source/blender/blenkernel/intern/groom.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/draw/intern/draw_cache_impl_groom.c
M	source/blender/editors/groom/editgroom_region.c
M	source/blender/editors/space_view3d/view3d_iterators.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/makesdna/DNA_groom_types.h

===================================================================

diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 34efda1952e..290e4bd4c0b 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -315,7 +315,7 @@ static bool groom_shape_rebuild(GroomBundle *bundle, int numshapeverts, Object *
 		shape[i][1] = dot_v3v3(co, center_tang);
 	}
 	
-	bundle->numloopverts = numshapeverts;
+	bundle->numshapeverts = numshapeverts;
 	bundle->totverts = numshapeverts * bundle->totsections;
 	bundle->verts = MEM_reallocN_id(bundle->verts, sizeof(*bundle->verts) * bundle->totverts, "groom bundle vertices");
 	/* Set the shape for all sections */
@@ -583,7 +583,7 @@ static void groom_eval_shape_cache_section(
 	BLI_assert(isection < bundle->totsections - 1);
 	BLI_assert(curve_res >= 1);
 	
-	const int numloopverts = bundle->numloopverts;
+	const int numloopverts = bundle->numshapeverts;
 	GroomSectionVertex *loop0 = &bundle->verts[numloopverts * (isection-1)];
 	GroomSectionVertex *loop1 = &bundle->verts[numloopverts * isection];
 	GroomSectionVertex *loop2 = &bundle->verts[numloopverts * (isection+1)];
@@ -689,7 +689,7 @@ void BKE_groom_eval_curve_cache(const EvaluationContext *UNUSED(eval_ctx), Scene
 		}
 		
 		bundle->totcurvecache = (totsections-1) * groom->curve_res + 1;
-		bundle->totshapecache = bundle->totcurvecache * bundle->numloopverts;
+		bundle->totshapecache = bundle->totcurvecache * bundle->numshapeverts;
 		bundle->curvecache = MEM_reallocN_id(bundle->curvecache, sizeof(GroomCurveCache) * bundle->totcurvecache, "groom bundle curve cache");
 		bundle->shapecache = MEM_reallocN_id(bundle->shapecache, sizeof(GroomShapeCache) * bundle->totshapecache, "groom bundle shape cache");
 		
@@ -697,7 +697,7 @@ void BKE_groom_eval_curve_cache(const EvaluationContext *UNUSED(eval_ctx), Scene
 		{
 			/* degenerate case */
 			copy_v3_v3(bundle->curvecache[0].co, bundle->sections[0].center);
-			for (int i = 0; i < bundle->numloopverts; ++i)
+			for (int i = 0; i < bundle->numshapeverts; ++i)
 			{
 				copy_v2_v2(bundle->shapecache[i].co, bundle->verts[i].co);
 			}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 9d4e84d2bf0..ea305c72f01 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3827,7 +3827,7 @@ static void write_groom(WriteData *wd, Groom *groom)
 	{
 		writestruct(wd, DATA, GroomSection, bundle->totsections, bundle->sections);
 		writestruct(wd, DATA, GroomSectionVertex, bundle->totverts, bundle->verts);
-		writestruct(wd, DATA, MeshSample, bundle->numloopverts + 1, bundle->scalp_region);
+		writestruct(wd, DATA, MeshSample, bundle->numshapeverts + 1, bundle->scalp_region);
 	}
 	
 	if (groom->hair_system) {
diff --git a/source/blender/draw/intern/draw_cache_impl_groom.c b/source/blender/draw/intern/draw_cache_impl_groom.c
index 25a02af6384..d205005da22 100644
--- a/source/blender/draw/intern/draw_cache_impl_groom.c
+++ b/source/blender/draw/intern/draw_cache_impl_groom.c
@@ -265,12 +265,16 @@ static int groom_count_edges(Groom *groom, int parts, bool use_curve_cache)
 	{
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			if (bundle->numloopverts > 1)
+			if (bundle->numshapeverts > 1)
 			{
 				// Closed edge loop, 1 edge per vertex
 				if (use_curve_cache)
 				{
-					edge_len += 2 * bundle->totshapecache - bundle->numloopverts;
+					/* a curve for each shape vertex */
+					int numedges_curves = (bundle->totcurvecache - 1) * bundle->numshapeverts;
+					/* a loop for each section */
+					int numedges_sections = bundle->numshapeverts * bundle->totsections;
+					edge_len += numedges_curves + numedges_sections;
 				}
 				else
 				{
@@ -356,7 +360,7 @@ static void groom_get_verts(
 				GroomCurveCache *cache = bundle->curvecache;
 				for (int i = 0; i < bundle->totcurvecache; ++i, ++cache)
 				{
-					for (int j = 0; j < bundle->numloopverts; ++j, ++shape)
+					for (int j = 0; j < bundle->numshapeverts; ++j, ++shape)
 					{
 						if (id_pos != GM_ATTR_ID_UNUSED)
 						{
@@ -383,7 +387,7 @@ static void groom_get_verts(
 				{
 					const bool active = (bundle->flag & GM_BUNDLE_SELECT) && (section->flag & GM_SECTION_SELECT);
 					
-					for (int j = 0; j < bundle->numloopverts; ++j, ++vertex)
+					for (int j = 0; j < bundle->numshapeverts; ++j, ++vertex)
 					{
 						if (id_pos != GM_ATTR_ID_UNUSED)
 						{
@@ -451,30 +455,36 @@ static void groom_get_edges(
 	}
 	if (parts & GM_RENDER_SECTIONS)
 	{
+		const int curve_res = groom->curve_res;
 		for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 		{
-			const int numloopverts = bundle->numloopverts;
-			if (numloopverts > 1)
+			const int numshapeverts = bundle->numshapeverts;
+			if (numshapeverts > 1)
 			{
 				if (use_curve_cache)
 				{
-					for (int i = 0; i < bundle->totcurvecache; ++i)
+					/* a curve for each shape vertex */
+					for (int i = 0; i < numshapeverts; ++i)
 					{
-						uint idx0 = idx + i * numloopverts;
-						for (int j = 0; j < numloopverts - 1; ++j)
+						uint idx0 = idx + i;
+						for (int j = 0; j < bundle->totcurvecache - 1; ++j)
 						{
-							GWN_indexbuf_add_line_verts(&elb, idx0 + j, idx0 + j + 1);
-							if (i < bundle->totcurvecache - 1)
-							{
-								GWN_indexbuf_add_line_verts(&elb, idx0 + j, idx0 + j + numloopverts);
-							}
+							GWN_indexbuf_add_line_verts(
+							            &elb,
+							            idx0 +  j    * numshapeverts,
+							            idx0 + (j+1) * numshapeverts);
 						}
-						// close the loop
-						GWN_indexbuf_add_line_verts(&elb, idx0 + (numloopverts-1), idx0);
-						if (i < bundle->totcurvecache - 1)
+					}
+					/* a loop for each section */
+					for (int i = 0; i < bundle->totsections; ++i)
+					{
+						uint idx0 = idx + i * curve_res * numshapeverts;
+						for (int j = 0; j < numshapeverts - 1; ++j)
 						{
-							GWN_indexbuf_add_line_verts(&elb, idx0 + (numloopverts-1), idx0 + (numloopverts-1) + numloopverts);
+							GWN_indexbuf_add_line_verts(&elb, idx0 + j, idx0 + j + 1);
 						}
+						// close the loop
+						GWN_indexbuf_add_line_verts(&elb, idx0 + (numshapeverts-1), idx0);
 					}
 					
 					idx += bundle->totshapecache;
@@ -483,13 +493,13 @@ static void groom_get_edges(
 				{
 					for (int i = 0; i < bundle->totsections; ++i)
 					{
-						uint idx0 = idx + i * numloopverts;
-						for (int j = 0; j < numloopverts - 1; ++j)
+						uint idx0 = idx + i * numshapeverts;
+						for (int j = 0; j < numshapeverts - 1; ++j)
 						{
 							GWN_indexbuf_add_line_verts(&elb, idx0 + j, idx0 + j + 1);
 						}
 						// close the loop
-						GWN_indexbuf_add_line_verts(&elb, idx0 + (numloopverts-1), idx0);
+						GWN_indexbuf_add_line_verts(&elb, idx0 + (numshapeverts-1), idx0);
 					}
 					
 					idx += bundle->totverts;
diff --git a/source/blender/editors/groom/editgroom_region.c b/source/blender/editors/groom/editgroom_region.c
index 479b434ae44..a535091915b 100644
--- a/source/blender/editors/groom/editgroom_region.c
+++ b/source/blender/editors/groom/editgroom_region.c
@@ -89,13 +89,13 @@ static GroomBundle* groom_add_bundle(float mat[4][4])
 {
 	GroomBundle *bundle = MEM_callocN(sizeof(GroomBundle), "groom bundle");
 	
-	bundle->numloopverts = 6;
+	bundle->numshapeverts = 6;
 	bundle->totsections = 4;
-	bundle->totverts = bundle->numloopverts * bundle->totsections;
+	bundle->totverts = bundle->numshapeverts * bundle->totsections;
 	bundle->sections = MEM_mallocN(sizeof(GroomSection) * bundle->totsections, "groom bundle sections");
 	bundle->verts = MEM_mallocN(sizeof(GroomSectionVertex) * bundle->totverts, "groom bundle vertices");
 	
-	int numverts = bundle->numloopverts;
+	int numverts = bundle->numshapeverts;
 	groom_bundle_section_init(&bundle->sections[0], &bundle->verts[numverts * 0], numverts, mat, 0.0, 0.0, 0.0);
 	groom_bundle_section_init(&bundle->sections[1], &bundle->verts[numverts * 1], numverts, mat, 0.0, 0.0, 1.0);
 	groom_bundle_section_init(&bundle->sections[2], &bundle->verts[numverts * 2], numverts, mat, 0.4, -0.2, 1.2);
diff --git a/source/blender/editors/space_view3d/view3d_iterators.c b/source/blender/editors/space_view3d/view3d_iterators.c
index 945d4aa4a88..d3bee637fd7 100644
--- a/source/blender/editors/space_view3d/view3d_iterators.c
+++ b/source/blender/editors/space_view3d/view3d_iterators.c
@@ -451,7 +451,7 @@ void groom_foreachScreenVert(
 				GroomSection *section = bundle->sections;
 				for (int i = 0; i < bundle->totsections; ++i, ++section)
 				{
-					for (int j = 0; j < bundle->numloopverts; ++j, ++vertex)
+					for (int j = 0; j < bundle->numshapeverts; ++j, ++vertex)
 					{
 						float co[3] = {vertex->co[0], vertex->co[1], 0.0f};
 						mul_m3_v3(section->mat, co);
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index fe461f5ff20..25c1f9eaddc 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -2021,7 +2021,7 @@ static void groom_transdata_init_verts(
 			mul_m3_m3m3(mtx, obmat3, section->mat);
 			pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
 			
-			for (int j = 0; j < bundle->numloopverts; ++j, ++vertex)
+			for (int j = 0; j < bundle->numshapeverts; ++j, ++vertex)
 			{
 				if (is_prop_edit || (vertex->flag & GM_VERTEX_SELECT))
 				{
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index 70683358449..a5133d38705 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -86,7 +86,7 @@ typedef struct GroomBundle {
 	
 	int flag;
 	
-	int numloopverts;                       /* Vertices per section loop */
+	int numshapeverts;                       /* Vertices per section loop */
 	int totsections;                        /* Number of sections along the curve */
 	int totverts;                           /* Number of vertices of all sections combined */
 	int totcurvecache;                      /* Number of cached curve steps */



More information about the Bf-blender-cvs mailing list