[Bf-blender-cvs] [1d26d50a466] hair_guides: Use existence of a bind value array instead of a flag to detect bound groom data.

Lukas Tönne noreply at git.blender.org
Thu Jan 4 12:09:05 CET 2018


Commit: 1d26d50a466efa26bdc91cb75eac156bf77fad30
Author: Lukas Tönne
Date:   Thu Jan 4 11:05:19 2018 +0000
Branches: hair_guides
https://developer.blender.org/rB1d26d50a466efa26bdc91cb75eac156bf77fad30

Use existence of a bind value array instead of a flag to detect bound groom data.

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

M	source/blender/blenkernel/BKE_groom.h
M	source/blender/blenkernel/intern/groom.c
M	source/blender/makesdna/DNA_groom_types.h
M	source/blender/makesrna/intern/rna_groom.c

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

diff --git a/source/blender/blenkernel/BKE_groom.h b/source/blender/blenkernel/BKE_groom.h
index 6843ff40b9a..c0a7ff1c402 100644
--- a/source/blender/blenkernel/BKE_groom.h
+++ b/source/blender/blenkernel/BKE_groom.h
@@ -34,6 +34,7 @@
 
 struct EvaluationContext;
 struct Groom;
+struct GroomBundle;
 struct Main;
 struct Object;
 struct Scene;
@@ -58,6 +59,9 @@ void BKE_groom_boundbox_calc(struct Groom *groom, float r_loc[3], float r_size[3
 /* Try to bind bundles to their scalp regions */
 void BKE_groom_bind_scalp_regions(struct Groom *groom);
 
+bool BKE_groom_bundle_bind(struct Groom *groom, struct GroomBundle *bundle);
+void BKE_groom_bundle_unbind(struct GroomBundle *bundle);
+
 
 /* === Depsgraph evaluation === */
 
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 151c19c3ad4..aea4a992365 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -237,6 +237,24 @@ void BKE_groom_boundbox_calc(Groom *groom, float r_loc[3], float r_size[3])
 
 /* === Scalp regions === */
 
+void BKE_groom_bind_scalp_regions(Groom *groom)
+{
+	if (groom->editgroom)
+	{
+		for (GroomBundle *bundle = groom->editgroom->bundles.first; bundle; bundle = bundle->next)
+		{
+			BKE_groom_bundle_bind(groom, bundle);
+		}
+	}
+	else
+	{
+		for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
+		{
+			BKE_groom_bundle_bind(groom, bundle);
+		}
+	}
+}
+
 static bool groom_region_is_valid(Groom *groom, GroomBundle *bundle)
 {
 	if (!groom->scalp_object)
@@ -252,9 +270,9 @@ static bool groom_region_is_valid(Groom *groom, GroomBundle *bundle)
 	return true;
 }
 
-static bool groom_bind_bundle(Groom *groom, GroomBundle *bundle)
+bool BKE_groom_bundle_bind(Groom *groom, GroomBundle *bundle)
 {
-	bundle->flag &= ~GM_BUNDLE_BOUND;
+	BKE_groom_bundle_unbind(bundle);
 	if (!groom_region_is_valid(groom, bundle))
 	{
 		return false;
@@ -262,25 +280,15 @@ static bool groom_bind_bundle(Groom *groom, GroomBundle *bundle)
 	
 	// see BMW_init
 	
-	bundle->flag |= GM_BUNDLE_BOUND;
-	return true;
+	return (bundle->scalp_region != NULL);
 }
 
-void BKE_groom_bind_scalp_regions(Groom *groom)
+void BKE_groom_bundle_unbind(GroomBundle *bundle)
 {
-	if (groom->editgroom)
-	{
-		for (GroomBundle *bundle = groom->editgroom->bundles.first; bundle; bundle = bundle->next)
-		{
-			groom_bind_bundle(groom, bundle);
-		}
-	}
-	else
+	if (bundle->scalp_region)
 	{
-		for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
-		{
-			groom_bind_bundle(groom, bundle);
-		}
+		MEM_freeN(bundle->scalp_region);
+		bundle->scalp_region = NULL;
 	}
 }
 
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index 7fc92bccc51..6cc2326bfa3 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -92,10 +92,11 @@ typedef struct GroomBundle {
 	int totcurvecache;                      /* Number of cached curve steps */
 	int totshapecache;                      /* Number of cached shape vectors */
 	
-	struct GroomSection *sections;          /* List of sections */
-	struct GroomSectionVertex *verts;       /* List of vertices */
-	struct GroomCurveCache *curvecache;     /* Cached center curve */
-	struct GroomShapeCache *shapecache;     /* Cached 2D shape curves */
+	struct GroomSection *sections;          /* List of sections [totsections] */
+	struct GroomSectionVertex *verts;       /* List of vertices [totsections][numloopverts] */
+	struct GroomCurveCache *curvecache;     /* Cached center curve [(totsections - 1) * groom.curve_res + 1] */
+	struct GroomShapeCache *shapecache;     /* Cached 2D shape curves [(totsections - 1) * groom.curve_res + 1][numloopverts] */
+	struct MeshSample *scalp_region;        /* Mesh samples bind to a scalp region [numloopverts] */
 	
 	/* Scalp Region */
 	/* XXX Vertex groups are used temporarily for creating regions,
@@ -106,8 +107,6 @@ typedef struct GroomBundle {
 typedef enum GroomBundleFlag
 {
 	GM_BUNDLE_SELECT        = (1 << 0),
-	
-	GM_BUNDLE_BOUND         = (1 << 8),     /* Bundle was successfully bound to a scalp region */
 } GroomBundleFlag;
 
 /* Editable groom data */
diff --git a/source/blender/makesrna/intern/rna_groom.c b/source/blender/makesrna/intern/rna_groom.c
index 95e6bc7f58c..924c44860c8 100644
--- a/source/blender/makesrna/intern/rna_groom.c
+++ b/source/blender/makesrna/intern/rna_groom.c
@@ -72,6 +72,12 @@ static void rna_Groom_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
 	WM_main_add_notifier(NC_GROOM | ND_DATA, ptr->id.data);
 }
 
+static int rna_GroomBundle_is_bound_get(PointerRNA *ptr)
+{
+	GroomBundle *bundle = (GroomBundle *)ptr->data;
+	return (bundle->scalp_region != NULL);
+}
+
 static void rna_GroomBundle_scalp_vgroup_name_set(PointerRNA *ptr, const char *value)
 {
 	Groom *groom = (Groom *)ptr->id.data;
@@ -132,7 +138,7 @@ static void rna_def_groom_bundle(BlenderRNA *brna)
 	RNA_def_struct_ui_text(srna, "Groom Bundle", "Bundle of hair originating from a scalp region");
 	
 	prop = RNA_def_property(srna, "is_bound", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", GM_BUNDLE_BOUND);
+	RNA_def_property_boolean_funcs(prop, "rna_GroomBundle_is_bound_get", NULL);
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Bound", "Bundle was successfully bound to a scalp region");
 	RNA_def_property_update(prop, NC_GROOM | ND_DRAW, NULL);



More information about the Bf-blender-cvs mailing list