[Bf-blender-cvs] [53b5099] alembic: Another fix for child deformation.

Lukas Tönne noreply at git.blender.org
Tue Apr 14 15:29:48 CEST 2015


Commit: 53b5099e279594623feb0f9ae71feb9b5b4b9a7d
Author: Lukas Tönne
Date:   Tue Apr 14 15:28:48 2015 +0200
Branches: alembic
https://developer.blender.org/rB53b5099e279594623feb0f9ae71feb9b5b4b9a7d

Another fix for child deformation.

Needs the parent base shape in the rotated deformed root space, or the
child gets additional deformation from the root rotations.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/pointcache/alembic/abc_particles.cpp

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 02a22d1..d14231e 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -104,7 +104,7 @@ void BKE_dupli_cache_clear(struct DupliCache *dupcache);
 void BKE_dupli_cache_clear_instances(struct DupliCache *dupcache);
 struct DupliObjectData *BKE_dupli_cache_add_object(struct DupliCache *dupcache, struct Object *ob);
 struct DupliObject *BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
-void BKE_dupli_cache_from_group(struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib, struct DupliCache *dupcache, struct EvaluationContext *eval_ctx);
+void BKE_dupli_cache_from_group(struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib, struct DupliCache *dupcache, struct EvaluationContext *eval_ctx, bool calc_strands_base);
 
 struct DupliCacheIterator *BKE_dupli_cache_iter_new(struct DupliCache *dupcache);
 void BKE_dupli_cache_iter_free(struct DupliCacheIterator *iter);
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index a5f3761..ff919e8 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1600,7 +1600,7 @@ static int count_hair_verts(ParticleSystem *psys)
 	return numverts;
 }
 
-void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachelib, DupliCache *dupcache, EvaluationContext *eval_ctx)
+void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachelib, DupliCache *dupcache, EvaluationContext *eval_ctx, bool calc_strands_base)
 {
 	DupliObject *dob;
 	
@@ -1661,7 +1661,8 @@ void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachel
 							
 							for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
 								copy_v3_v3(svert->co, hkey->co);
-								copy_v3_v3(svert->base, hkey->co); // XXX should be base for child deform, but not accessible here */
+								if (calc_strands_base)
+									copy_v3_v3(svert->base, hkey->co);
 								svert->time = hkey->time;
 								svert->weight = hkey->weight;
 								
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 73cb76d..090d3a5 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -290,17 +290,19 @@ static void cache_library_bake_do(CacheLibraryBakeJob *data)
 	cache_library_bake_set_progress(data, 0.0f);
 	for (frame = frame_prev = start_frame; frame <= end_frame; frame_prev = frame++) {
 		
+		const bool init_strands = (frame == start_frame);
+		
 		/* XXX Ugly, but necessary to avoid particle caching of paths when not needed.
 		 * This takes a lot of time, but is only needed in the first frame.
 		 */
-		cache_library_bake_set_particle_baking(data->bmain, frame > start_frame);
+		cache_library_bake_set_particle_baking(data->bmain, !init_strands);
 		
 		scene->r.cfra = frame;
 		BKE_scene_update_for_newframe(&data->eval_ctx, data->bmain, scene, scene->lay);
 		
 		switch (data->cachelib->source_mode) {
 			case CACHE_LIBRARY_SOURCE_SCENE:
-				BKE_dupli_cache_from_group(scene, data->group, data->cachelib, process_data.dupcache, &data->eval_ctx);
+				BKE_dupli_cache_from_group(scene, data->group, data->cachelib, process_data.dupcache, &data->eval_ctx, init_strands);
 				break;
 			case CACHE_LIBRARY_SOURCE_CACHE:
 				BKE_cache_read_dupli_cache(data->cachelib, process_data.dupcache, scene, data->group, frame, data->cache_eval_mode, false);
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index e75aa8c..4e43511 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -948,6 +948,7 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 	P3fArraySamplePtr sample_co_base = sample_base.getPositions();
 	Int32ArraySamplePtr sample_numvert = sample.getCurvesNumVertices();
 	IM33fGeomParam::Sample sample_root_matrix = m_param_root_matrix.getExpandedValue(ss);
+	IM33fGeomParam::Sample sample_root_matrix_base = m_param_root_matrix.getExpandedValue(ISampleSelector((index_t)0));
 	IFloatGeomParam::Sample sample_time = m_param_times.getExpandedValue(ss);
 	IFloatGeomParam::Sample sample_weight = m_param_weights.getExpandedValue(ss);
 	
@@ -971,18 +972,15 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 	}
 	
 	const V3f *co = sample_co->get();
-	const V3f *co_base = sample_co_base->get();
 	const float32_t *time = sample_time.getVals()->get();
 	const float32_t *weight = sample_weight.getVals()->get();
 	for (int i = 0; i < sample_co->size(); ++i) {
 		StrandsVertex *svert = &m_strands->verts[i];
 		copy_v3_v3(svert->co, co->getValue());
-		copy_v3_v3(svert->base, co_base->getValue());
 		svert->time = *time;
 		svert->weight = *weight;
 		
 		++co;
-		++co_base;
 		++time;
 		++weight;
 	}
@@ -990,18 +988,36 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 	/* Correction for base coordinates: these are in object space of frame 1,
 	 * but we want the relative shape. Offset them to the current root location.
 	 */
+	const M33f *root_matrix_base = sample_root_matrix_base.getVals()->get();
+	const V3f *co_base = sample_co_base->get();
 	StrandIterator it_strand;
 	for (BKE_strand_iter_init(&it_strand, m_strands); BKE_strand_iter_valid(&it_strand); BKE_strand_iter_next(&it_strand)) {
 		if (it_strand.curve->numverts <= 0)
 			continue;
 		
-		float offset[3];
-		sub_v3_v3v3(offset, it_strand.verts[0].co, it_strand.verts[0].base);
+		float hairmat_base[4][4];
+		float tmpmat[3][3];
+		memcpy(tmpmat, root_matrix_base->getValue(), sizeof(tmpmat));
+		copy_m4_m3(hairmat_base, tmpmat);
+		copy_v3_v3(hairmat_base[3], co_base[0].getValue());
+		
+		float hairmat[4][4];
+		copy_m4_m3(hairmat, it_strand.curve->root_matrix);
+		copy_v3_v3(hairmat[3], it_strand.verts[0].co);
+		
+		float mat[4][4];
+		invert_m4_m4(mat, hairmat_base);
+		mul_m4_m4m4(mat, hairmat, mat);
 		
 		StrandVertexIterator it_vert;
 		for (BKE_strand_vertex_iter_init(&it_vert, &it_strand); BKE_strand_vertex_iter_valid(&it_vert); BKE_strand_vertex_iter_next(&it_vert)) {
-			add_v3_v3(it_vert.vertex->base, offset);
+//			mul_v3_m4v3(it_vert.vertex->base, mat, co_base->getValue());
+			copy_v3_v3(it_vert.vertex->base, it_vert.vertex->co);
+			
+			++co_base;
 		}
+		
+		++root_matrix_base;
 	}
 	
 	if (m_read_motion &&




More information about the Bf-blender-cvs mailing list