[Bf-blender-cvs] [50a8b15] alembic: Fix for shifted sample-to-frame mapping in Alembic files with hair simulation.

Lukas Tönne noreply at git.blender.org
Fri May 1 10:27:37 CEST 2015


Commit: 50a8b15f474de7aefe89f8f3e375de178d967c7f
Author: Lukas Tönne
Date:   Fri May 1 10:24:32 2015 +0200
Branches: alembic
https://developer.blender.org/rB50a8b15f474de7aefe89f8f3e375de178d967c7f

Fix for shifted sample-to-frame mapping in Alembic files with hair
simulation.

The hair sim skips the first frame (velocities are undefined there), but
still has to create the motion state data in order to have it written
as a sample. Otherwise the strands motion state samples start one sample
short and frames get mapped to one sample in the past. This then leads
to incorrect movement of all hair vertices other than the roots (which
are always clamped to the animated positions).

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

M	source/blender/blenkernel/intern/cache_library.c

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

diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 849e57b..b9ac9cd 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -949,31 +949,35 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx
 //	if (eval_mode != CACHE_LIBRARY_EVAL_REALTIME)
 //		return;
 	
-	/* skip first step and potential backward steps */
-	if (frame <= frame_prev)
-		return;
-	
 	if (!BKE_cache_modifier_find_strands(data->dupcache, ob, hsmd->hair_system, NULL, &strands))
 		return;
 	
-	if (hsmd->sim_params.flag & eHairSimParams_Flag_UseGoalStiffnessCurve)
-		curvemapping_changed_all(hsmd->sim_params.goal_stiffness_mapping);
-	
-	if (ob)
-		mul_m4_m4m4(mat, data->mat, ob->obmat);
-	else
-		copy_m4_m4(mat, data->mat);
-		
+	/* Note: motion state data should always be created regardless of actual sim.
+	 * This is necessary so the cache writer actually writes the first (empty) sample
+	 * and the samples get mapped correctly to frames when reading.
+	 */
 	BKE_strands_add_motion_state(strands);
-	solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params);
-	effectors = pdInitEffectors_ex(ctx->scene, ob, NULL, data->lay, hsmd->sim_params.effector_weights, true);
-	tot_cache_effectors = BKE_cache_effectors_get(cache_effectors, MAX_CACHE_EFFECTORS, ctx->cachelib, data->dupcache, data->mat);
 	
-	BPH_strands_solve(strands, mat, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, effectors, cache_effectors, tot_cache_effectors);
-	
-	pdEndEffectors(&effectors);
-	BKE_cache_effectors_free(cache_effectors, tot_cache_effectors);
-	BPH_mass_spring_solver_free(solver_data);
+	/* skip first step and potential backward steps */
+	if (frame > frame_prev) {
+		if (hsmd->sim_params.flag & eHairSimParams_Flag_UseGoalStiffnessCurve)
+			curvemapping_changed_all(hsmd->sim_params.goal_stiffness_mapping);
+		
+		if (ob)
+			mul_m4_m4m4(mat, data->mat, ob->obmat);
+		else
+			copy_m4_m4(mat, data->mat);
+		
+		solver_data = BPH_strands_solver_create(strands, &hsmd->sim_params);
+		effectors = pdInitEffectors_ex(ctx->scene, ob, NULL, data->lay, hsmd->sim_params.effector_weights, true);
+		tot_cache_effectors = BKE_cache_effectors_get(cache_effectors, MAX_CACHE_EFFECTORS, ctx->cachelib, data->dupcache, data->mat);
+		
+		BPH_strands_solve(strands, mat, solver_data, &hsmd->sim_params, (float)frame, (float)frame_prev, ctx->scene, effectors, cache_effectors, tot_cache_effectors);
+		
+		pdEndEffectors(&effectors);
+		BKE_cache_effectors_free(cache_effectors, tot_cache_effectors);
+		BPH_mass_spring_solver_free(solver_data);
+	}
 	
 #undef MAX_CACHE_EFFECTORS
 }




More information about the Bf-blender-cvs mailing list