[Bf-blender-cvs] [00dc4813c38] hair_guides: Vertex array for closed curves forming 2D groom sections.

Lukas Tönne noreply at git.blender.org
Mon Dec 25 17:21:07 CET 2017


Commit: 00dc4813c3883bde18ba7e28de84c38e13cb6070
Author: Lukas Tönne
Date:   Mon Dec 25 14:34:51 2017 +0000
Branches: hair_guides
https://developer.blender.org/rB00dc4813c3883bde18ba7e28de84c38e13cb6070

Vertex array for closed curves forming 2D groom sections.

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

M	source/blender/blenkernel/intern/groom.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/draw/intern/draw_cache_impl_groom.c
M	source/blender/editors/groom/editgroom.c
M	source/blender/editors/groom/editgroom_region.c
M	source/blender/editors/groom/editgroom_select.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 3594c6e9b44..4470532d27c 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -75,6 +75,13 @@ static void groom_bundles_free(ListBase *bundles)
 {
 	for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 	{
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			if (section->verts)
+			{
+				MEM_freeN(section->verts);
+			}
+		}
 		BLI_freelistN(&bundle->sections);
 	}
 	BLI_freelistN(bundles);
@@ -115,6 +122,17 @@ void BKE_groom_copy_data(Main *UNUSED(bmain), Groom *groom_dst, const Groom *gro
 	groom_dst->bb = MEM_dupallocN(groom_src->bb);
 	
 	BLI_duplicatelist(&groom_dst->bundles, &groom_src->bundles);
+	for (GroomBundle *bundle = groom_dst->bundles.first; bundle; bundle = bundle->next)
+	{
+		BLI_duplicatelist(&bundle->sections, &bundle->sections);
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			if (section->verts)
+			{
+				section->verts = MEM_dupallocN(section->verts);
+			}
+		}
+	}
 	
 	groom_dst->editgroom = NULL;
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d259a4ebfda..33a22449b49 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8399,6 +8399,10 @@ static void direct_link_groom(FileData *fd, Groom *groom)
 	for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
 	{
 		link_list(fd, &bundle->sections);
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			section->verts = newdataadr(fd, section->verts);
+		}
 	}
 	
 	groom->bb = NULL;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 8ef3393d53b..b5a2224c65a 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3826,6 +3826,10 @@ static void write_groom(WriteData *wd, Groom *groom)
 	for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
 	{
 		writelist(wd, DATA, GroomBundleSection, &bundle->sections);
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			writestruct(wd, DATA, GroomSectionVertex, section->totverts, section->verts);
+		}
 	}
 }
 
diff --git a/source/blender/draw/intern/draw_cache_impl_groom.c b/source/blender/draw/intern/draw_cache_impl_groom.c
index 35bbe896165..d24c7b041b8 100644
--- a/source/blender/draw/intern/draw_cache_impl_groom.c
+++ b/source/blender/draw/intern/draw_cache_impl_groom.c
@@ -37,6 +37,7 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_listbase.h"
+#include "BLI_math.h"
 
 #include "DNA_groom_types.h"
 #include "DNA_scene_types.h"
@@ -215,8 +216,7 @@ static int groom_count_verts(Groom *groom, int parts, int tessellation)
 		{
 			for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
 			{
-				// TODO
-				//vert_len += ...;
+				vert_len += section->totverts;
 			}
 		}
 	}
@@ -249,8 +249,8 @@ static int groom_count_edges(Groom *groom, int parts, int tessellation)
 		{
 			for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
 			{
-				// TODO
-				//edge_len += ...;
+				// Closed edge loop, 1 edge per vertex
+				edge_len += section->totverts;
 			}
 		}
 	}
@@ -306,8 +306,30 @@ static void groom_get_verts(
 		{
 			for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
 			{
-				// TODO
-				UNUSED_VARS(idx);
+				const bool active = (bundle->flag & GM_BUNDLE_SELECT) && (section->flag & GM_SECTION_SELECT);
+				float mat[4][4];
+				unit_m4(mat); // TODO rotation
+				copy_v3_v3(mat[3], section->center); // translation
+				
+				GroomSectionVertex *vertex = section->verts;
+				for (int i = 0; i < section->totverts; ++i, ++vertex)
+				{
+					if (id_pos != GM_ATTR_ID_UNUSED)
+					{
+						float co[3];
+						copy_v2_v2(co, vertex->co);
+						co[2] = 0.0f;
+						mul_m4_v3(mat, co);
+						GWN_vertbuf_attr_set(vbo, id_pos, idx, co);
+					}
+					if (id_flag != GM_ATTR_ID_UNUSED)
+					{
+						char vflag = make_vertex_flag(active, vertex->flag & GM_VERTEX_SELECT);
+						GWN_vertbuf_attr_set(vbo, id_flag, idx, &vflag);
+					}
+					
+					++idx;
+				}
 			}
 		}
 	}
@@ -354,8 +376,17 @@ static void groom_get_edges(
 		{
 			for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
 			{
-				// TODO
-				UNUSED_VARS(idx);
+				if (section->totverts > 1)
+				{
+					for (int i = 0; i < section->totverts - 1; ++i)
+					{
+						GWN_indexbuf_add_line_verts(&elb, idx + i, idx + i + 1);
+					}
+					// close the loop
+					GWN_indexbuf_add_line_verts(&elb, idx + section->totverts - 1, idx);
+				}
+				
+				idx += section->totverts;
 			}
 		}
 	}
diff --git a/source/blender/editors/groom/editgroom.c b/source/blender/editors/groom/editgroom.c
index cfb129b6f64..60ad1448087 100644
--- a/source/blender/editors/groom/editgroom.c
+++ b/source/blender/editors/groom/editgroom.c
@@ -72,6 +72,13 @@ static void groom_bundles_free(ListBase *bundles)
 {
 	for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
 	{
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			if (section->verts)
+			{
+				MEM_freeN(section->verts);
+			}
+		}
 		BLI_freelistN(&bundle->sections);
 	}
 	BLI_freelistN(bundles);
@@ -83,6 +90,13 @@ static void groom_bundles_copy(ListBase *bundles_dst, ListBase *bundles_src)
 	for (GroomBundle *bundle = bundles_dst->first; bundle; bundle = bundle->next)
 	{
 		BLI_duplicatelist(&bundle->sections, &bundle->sections);
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			if (section->verts)
+			{
+				section->verts = MEM_dupallocN(section->verts);
+			}
+		}
 	}
 }
 
diff --git a/source/blender/editors/groom/editgroom_region.c b/source/blender/editors/groom/editgroom_region.c
index 7a4282bef5f..d37d91f3fb0 100644
--- a/source/blender/editors/groom/editgroom_region.c
+++ b/source/blender/editors/groom/editgroom_region.c
@@ -66,6 +66,21 @@ static GroomBundleSection* groom_add_bundle_section(float mat[4][4], float cpara
 	madd_v3_v3v3fl(section->center, mat[3], mat[2], cparam);
 	copy_v3_v3(section->normal, mat[2]);
 	
+	{
+		const int numverts = 6;
+		section->totverts = numverts;
+		section->verts = MEM_mallocN(sizeof(GroomSectionVertex) * numverts, "groom section vertices");
+		
+		const float radius = 0.5f;
+		GroomSectionVertex *vertex = section->verts;
+		for (int i = 0; i < numverts; ++i, ++vertex)
+		{
+			float angle = 2*M_PI * (float)i / (float)numverts;
+			vertex->co[0] = cos(angle) * radius;
+			vertex->co[1] = sin(angle) * radius;
+		}
+	}
+	
 	return section;
 }
 
diff --git a/source/blender/editors/groom/editgroom_select.c b/source/blender/editors/groom/editgroom_select.c
index f51d4644054..388f24cfe22 100644
--- a/source/blender/editors/groom/editgroom_select.c
+++ b/source/blender/editors/groom/editgroom_select.c
@@ -84,7 +84,20 @@ bool ED_groom_select_check_curves(const EditGroom *edit)
 
 bool ED_groom_select_check_sections(const EditGroom *edit)
 {
-	// TODO
+	for (GroomBundle* bundle = edit->bundles.first; bundle; bundle = bundle->next)
+	{
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			GroomSectionVertex *vertex = section->verts;
+			for (int i = 0; i < section->totverts; ++i, ++vertex)
+			{
+				if (vertex->flag & GM_VERTEX_SELECT)
+				{
+					return true;
+				}
+			}
+		}
+	}
 	
 	return false;
 }
@@ -126,7 +139,25 @@ void ED_groom_select_curves(EditGroom *edit, EditGroomSelectCb select_cb, void *
 
 void ED_groom_select_sections(EditGroom *edit, EditGroomSelectCb select_cb, void *userdata)
 {
-	// TODO
+	for (GroomBundle* bundle = edit->bundles.first; bundle; bundle = bundle->next)
+	{
+		for (GroomBundleSection *section = bundle->sections.first; section; section = section->next)
+		{
+			GroomSectionVertex *vertex = section->verts;
+			for (int i = 0; i < section->totverts; ++i, ++vertex)
+			{
+				const bool select = select_cb(userdata, vertex->flag & GM_VERTEX_SELECT);
+				if (select)
+				{
+					vertex->flag |= GM_VERTEX_SELECT;
+				}
+				else
+				{
+					vertex->flag &= ~GM_VERTEX_SELECT;
+				}
+			}
+		}
+	}
 }
 
 static bool groom_select_all_cb(void *UNUSED(userdata), bool UNUSED(is_selected))
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index 4752b52c05e..463637fddb7 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -40,6 +40,18 @@
 extern "C" {
 #endif
 
+/* Vertex in a closed curve for a bundle section */
+typedef struct GroomSectionVertex
+{
+	int flag;
+	float co[2];                            /* Location in the section plane */
+} GroomSectionVertex;
+
+typedef enum GroomVertexFlag
+{
+	GM_VERTEX_SELECT        = (1 << 0),
+} GroomVertexFlag;
+
 /* Cross-section of a bundle */
 typedef struct GroomBundleSection {
 	struct GroomBundleSection *next, *prev; /* Pointers for ListBase element */
@@ -49,6 +61,10 @@ typedef struct GroomBundleSection {
 	
 	float center[3];                        /* Center point */
 	float normal[3];                        /* Normal direction of the section plane */
+	
+	GroomSectionVertex *verts;
+	int totverts;
+	int pad2;
 } GroomBundleSection;
 
 typedef enum GroomBundleSectionFlag



More information about the Bf-blender-cvs mailing list