[Bf-blender-cvs] [f1234c6] alembic: Scalp animation support: copy strand root locations from the rest pose before performing a time step.

Lukas Tönne noreply at git.blender.org
Fri Apr 3 12:05:06 CEST 2015


Commit: f1234c63350365e4a7a75fa6a87319d711e4f2f1
Author: Lukas Tönne
Date:   Fri Apr 3 12:00:36 2015 +0200
Branches: alembic
https://developer.blender.org/rBf1234c63350365e4a7a75fa6a87319d711e4f2f1

Scalp animation support: copy strand root locations from the rest pose
before performing a time step.

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

M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/strands.c

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

diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index ec361b2..f720f1b 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -55,6 +55,9 @@ struct Strands *BKE_strands_new(int strands, int verts);
 void BKE_strands_free(struct Strands *strands);
 
 void BKE_strands_add_motion_state(struct Strands *strands);
+void BKE_strands_state_copy_rest_positions(Strands *strands);
+void BKE_strands_state_copy_root_positions(Strands *strands);
+void BKE_strands_state_clear_velocities(Strands *strands);
 
 void BKE_strands_ensure_normals(struct Strands *strands);
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 0a2a773..6f4d49c 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -586,6 +586,9 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx
 			
 			BKE_strands_add_motion_state(strands);
 			
+			/* scalp animation: copy motion of the roots */
+			BKE_strands_state_copy_root_positions(strands);
+			
 			solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params);
 			
 			BPH_strands_solve(strands, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, NULL);
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 2f4b9da..4cd5b68 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -50,6 +50,42 @@ void BKE_strands_free(Strands *strands)
 	}
 }
 
+/* copy the rest positions to initialize the motion state */
+void BKE_strands_state_copy_rest_positions(Strands *strands)
+{
+	if (strands->state) {
+		int i;
+		for (i = 0; i < strands->totverts; ++i) {
+			copy_v3_v3(strands->state[i].co, strands->verts[i].co);
+		}
+	}
+}
+
+/* copy the rest positions to initialize the motion state */
+void BKE_strands_state_copy_root_positions(Strands *strands)
+{
+	if (strands->state) {
+		StrandIterator it_strand;
+		int i = 0;
+		for (BKE_strand_iter_init(&it_strand, strands); BKE_strand_iter_valid(&it_strand); BKE_strand_iter_next(&it_strand)) {
+			copy_v3_v3(strands->state[i].co, strands->verts[i].co);
+			i += it_strand.curve->numverts;
+		}
+	}
+}
+
+/* copy the rest positions to initialize the motion state */
+void BKE_strands_state_clear_velocities(Strands *strands)
+{
+	if (strands->state) {
+		int i;
+		
+		for (i = 0; i < strands->totverts; ++i) {
+			zero_v3(strands->state[i].vel);
+		}
+	}
+}
+
 void BKE_strands_add_motion_state(Strands *strands)
 {
 	if (!strands->state) {
@@ -57,12 +93,11 @@ void BKE_strands_add_motion_state(Strands *strands)
 		
 		strands->state = MEM_mallocN(sizeof(StrandsMotionState) * strands->totverts, "strand motion states");
 		
-		/* XXX for now just copy from the goal state to initialize
-		 * this could be much more interesting
-		 */
+		BKE_strands_state_copy_rest_positions(strands);
+		BKE_strands_state_clear_velocities(strands);
+		
+		/* initialize normals */
 		for (i = 0; i < strands->totverts; ++i) {
-			copy_v3_v3(strands->state[i].co, strands->verts[i].co);
-			zero_v3(strands->state[i].vel);
 			copy_v3_v3(strands->state[i].nor, strands->verts[i].nor);
 		}
 	}




More information about the Bf-blender-cvs mailing list