[Bf-blender-cvs] [a6fffa09aa2] hair_guides_grooming: Basic constraint for keeping the center curve attached to the scalp.

Lukas Tönne noreply at git.blender.org
Tue May 29 08:03:43 CEST 2018


Commit: a6fffa09aa2aeabf7c3e60954bf1778331121dc6
Author: Lukas Tönne
Date:   Tue May 29 07:03:00 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rBa6fffa09aa2aeabf7c3e60954bf1778331121dc6

Basic constraint for keeping the center curve attached to the scalp.

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

M	source/blender/blenkernel/BKE_groom.h
M	source/blender/blenkernel/intern/groom.c

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

diff --git a/source/blender/blenkernel/BKE_groom.h b/source/blender/blenkernel/BKE_groom.h
index 70c6628d7ad..e140c7709f0 100644
--- a/source/blender/blenkernel/BKE_groom.h
+++ b/source/blender/blenkernel/BKE_groom.h
@@ -72,6 +72,12 @@ bool BKE_groom_bundle_bind(struct Groom *groom, struct GroomBundle *bundle, bool
 void BKE_groom_bundle_unbind(struct GroomBundle *bundle);
 
 
+/* === Constraints === */
+
+/* Apply constraints on groom geometry */
+void BKE_groom_apply_constraints(struct Groom *groom, struct Mesh *scalp);
+
+
 /* === Hair System === */
 
 /* Create follicles on the scalp surface for hair fiber rendering */
@@ -83,7 +89,7 @@ void BKE_groom_hair_update_guide_curves(struct Groom *groom);
 
 /* === Depsgraph evaluation === */
 
-void BKE_groom_eval_geometry(struct Depsgraph *depsgraph, struct Groom *groom);
+void BKE_groom_eval_geometry(const struct Depsgraph *depsgraph, struct Groom *groom);
 
 
 /* === Draw Cache === */
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index 5ec60332a91..33435238bff 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -63,6 +63,7 @@
 #include "BKE_object_facemap.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
 
 #include "bmesh.h"
 
@@ -522,6 +523,28 @@ void BKE_groom_bundle_unbind(GroomBundle *bundle)
 }
 
 
+/* === Constraints === */
+
+/* Apply constraints on groom geometry */
+void BKE_groom_apply_constraints(Groom *groom, Mesh *scalp)
+{
+	ListBase *bundles = (groom->editgroom ? &groom->editgroom->bundles : &groom->bundles);
+	for (GroomBundle *bundle = bundles->first; bundle; bundle = bundle->next)
+	{
+		/* For bound regions the bundle should be attached to the scalp */
+		if (scalp && bundle->scalp_region && bundle->totsections > 0)
+		{
+			float co[3], nor[3], tang[3];
+			/* Last in scalp_region is the center curve root point */
+			if (BKE_mesh_sample_eval(scalp, &bundle->scalp_region[bundle->numshapeverts], co, nor, tang))
+			{
+				copy_v3_v3(bundle->sections[0].center, co);
+			}
+		}
+	}
+}
+
+
 /* === Hair System === */
 
 /* Set loop weights for all faces covered by the bundle region */
@@ -733,9 +756,12 @@ void BKE_groom_hair_update_guide_curves(Groom *groom)
 		}
 	}
 	
-	BLI_assert(groom->scalp_object && groom->scalp_object->type == OB_MESH);
-	Mesh *scalp = groom->scalp_object->data;
-	BKE_hair_bind_follicles(hsys, scalp);
+	if (groom->scalp_object)
+	{
+		BLI_assert(groom->scalp_object->type == OB_MESH);
+		Mesh *scalp = groom->scalp_object->data;
+		BKE_hair_bind_follicles(hsys, scalp);
+	}
 }
 
 
@@ -993,12 +1019,17 @@ void BKE_groom_curve_cache_clear(Groom *groom)
 
 /* === Depsgraph evaluation === */
 
-void BKE_groom_eval_geometry(struct Depsgraph *UNUSED(depsgraph), Groom *groom)
+void BKE_groom_eval_geometry(const struct Depsgraph *depsgraph, Groom *groom)
 {
 	if (G.debug & G_DEBUG_DEPSGRAPH) {
 		printf("%s on %s\n", __func__, groom->id.name);
 	}
 	
+	/* Apply constraints from scalp mesh to the groom geometry */
+	Mesh *scalp = groom->scalp_object ? groom->scalp_object->data : NULL;
+	Mesh *scalp_eval = (Mesh *)DEG_get_evaluated_id(depsgraph, &scalp->id);
+	BKE_groom_apply_constraints(groom, scalp_eval);
+	
 	/* calculate curves for interpolating shapes */
 	BKE_groom_curve_cache_update(groom);



More information about the Bf-blender-cvs mailing list