[Bf-blender-cvs] [22e7d5cbafa] hair_guides: Validity flag in bundles to indicate when they are validly bound to the scalp.

Lukas Tönne noreply at git.blender.org
Thu Jan 4 10:42:58 CET 2018


Commit: 22e7d5cbafa7d4ecb011aa15481d26f341ff515b
Author: Lukas Tönne
Date:   Thu Jan 4 09:40:56 2018 +0000
Branches: hair_guides
https://developer.blender.org/rB22e7d5cbafa7d4ecb011aa15481d26f341ff515b

Validity flag in bundles to indicate when they are validly bound to the scalp.

This is updated through the depsgraph. Currently just checks for existing scalp
object and vertex groups, eventually will perform actual tracking of the mesh
surface to ensure the groom follows changes of the scalp mesh.

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

M	release/scripts/startup/bl_ui/properties_data_groom.py
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/release/scripts/startup/bl_ui/properties_data_groom.py b/release/scripts/startup/bl_ui/properties_data_groom.py
index f13bee081a1..0cb6a8e138b 100644
--- a/release/scripts/startup/bl_ui/properties_data_groom.py
+++ b/release/scripts/startup/bl_ui/properties_data_groom.py
@@ -29,6 +29,8 @@ class GROOM_UL_bundles(bpy.types.UIList):
 
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
             row = layout.row(align=True)
+            if not bundle.is_bound:
+                row.label(icon='ERROR')
             if groom.scalp_object:
                 row.prop_search(bundle, "scalp_vertex_group", groom.scalp_object, "vertex_groups", text="")
             else:
diff --git a/source/blender/blenkernel/BKE_groom.h b/source/blender/blenkernel/BKE_groom.h
index 4ca88426cd6..6843ff40b9a 100644
--- a/source/blender/blenkernel/BKE_groom.h
+++ b/source/blender/blenkernel/BKE_groom.h
@@ -53,6 +53,12 @@ bool BKE_groom_minmax(struct Groom *groom, float min[3], float max[3]);
 void BKE_groom_boundbox_calc(struct Groom *groom, float r_loc[3], float r_size[3]);
 
 
+/* === Scalp regions === */
+
+/* Try to bind bundles to their scalp regions */
+void BKE_groom_bind_scalp_regions(struct Groom *groom);
+
+
 /* === Depsgraph evaluation === */
 
 void BKE_groom_eval_curve_cache(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob);
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index bb08e31fa72..151c19c3ad4 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -48,6 +48,7 @@
 #include "DNA_scene_types.h"
 
 #include "BKE_animsys.h"
+#include "BKE_deform.h"
 #include "BKE_global.h"
 #include "BKE_groom.h"
 #include "BKE_hair.h"
@@ -234,6 +235,56 @@ void BKE_groom_boundbox_calc(Groom *groom, float r_loc[3], float r_size[3])
 }
 
 
+/* === Scalp regions === */
+
+static bool groom_region_is_valid(Groom *groom, GroomBundle *bundle)
+{
+	if (!groom->scalp_object)
+	{
+		return false;
+	}
+	
+	if (!defgroup_find_name(groom->scalp_object, bundle->scalp_vgroup_name))
+	{
+		return false;
+	}
+	
+	return true;
+}
+
+static bool groom_bind_bundle(Groom *groom, GroomBundle *bundle)
+{
+	bundle->flag &= ~GM_BUNDLE_BOUND;
+	if (!groom_region_is_valid(groom, bundle))
+	{
+		return false;
+	}
+	
+	// see BMW_init
+	
+	bundle->flag |= GM_BUNDLE_BOUND;
+	return true;
+}
+
+void BKE_groom_bind_scalp_regions(Groom *groom)
+{
+	if (groom->editgroom)
+	{
+		for (GroomBundle *bundle = groom->editgroom->bundles.first; bundle; bundle = bundle->next)
+		{
+			groom_bind_bundle(groom, bundle);
+		}
+	}
+	else
+	{
+		for (GroomBundle *bundle = groom->bundles.first; bundle; bundle = bundle->next)
+		{
+			groom_bind_bundle(groom, bundle);
+		}
+	}
+}
+
+
 /* === Depsgraph evaluation === */
 
 /* forward differencing method for cubic polynomial eval */
@@ -515,6 +566,8 @@ void BKE_groom_eval_geometry(const EvaluationContext *UNUSED(eval_ctx), Groom *g
 		printf("%s on %s\n", __func__, groom->id.name);
 	}
 	
+	BKE_groom_bind_scalp_regions(groom);
+	
 	if (groom->bb == NULL || (groom->bb->flag & BOUNDBOX_DIRTY)) {
 		BKE_groom_boundbox_calc(groom, NULL, NULL);
 	}
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index a69348f1574..7fc92bccc51 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -106,6 +106,8 @@ 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 55efa8169c7..95e6bc7f58c 100644
--- a/source/blender/makesrna/intern/rna_groom.c
+++ b/source/blender/makesrna/intern/rna_groom.c
@@ -131,6 +131,12 @@ static void rna_def_groom_bundle(BlenderRNA *brna)
 	RNA_def_struct_sdna(srna, "GroomBundle");
 	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_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);
+	
 	prop = RNA_def_property(srna, "scalp_vertex_group", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "scalp_vgroup_name");
 	RNA_def_property_ui_text(prop, "Scalp Vertex Group", "Vertex group name of the scalp region");



More information about the Bf-blender-cvs mailing list