[Bf-blender-cvs] [a784604] alembic: Remove the dual "root" object at the top of Alembic archives.

Lukas Tönne noreply at git.blender.org
Thu Apr 16 12:11:17 CEST 2015


Commit: a7846047a13905ddd11c6f5337d8fcf2e9382dd2
Author: Lukas Tönne
Date:   Thu Apr 16 10:42:48 2015 +0200
Branches: alembic
https://developer.blender.org/rBa7846047a13905ddd11c6f5337d8fcf2e9382dd2

Remove the dual "root" object at the top of Alembic archives.

Using two full scene nodes for render/realtime data creates a lot of
duplication in both storage and processing time. Instead storing
specific data types like meshes in different versions keeps duplication
to the necessary minimum and allows easier fallback where available.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/alembic/abc_group.cpp
M	source/blender/pointcache/alembic/abc_object.cpp
M	source/blender/pointcache/alembic/abc_particles.cpp
M	source/blender/pointcache/alembic/abc_reader.cpp
M	source/blender/pointcache/alembic/abc_reader.h
M	source/blender/pointcache/alembic/abc_writer.cpp
M	source/blender/pointcache/alembic/abc_writer.h
M	source/blender/pointcache/intern/reader.h
M	source/blender/pointcache/intern/writer.h
M	source/blender/pointcache/util/util_types.h

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index d14231e..04b0dd8 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -102,6 +102,7 @@ struct DupliCache *BKE_dupli_cache_new(void);
 void BKE_dupli_cache_free(struct DupliCache *dupcache);
 void BKE_dupli_cache_clear(struct DupliCache *dupcache);
 void BKE_dupli_cache_clear_instances(struct DupliCache *dupcache);
+void BKE_dupli_cache_clear_data(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, bool calc_strands_base);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index bb9cb5d..ca9b0e9 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -375,6 +375,15 @@ static void cache_get_read_flags(CacheLibrary *cachelib, eCacheLibrary_EvalMode
 	}
 }
 
+static PTCPass cache_pass_from_eval_mode(eCacheLibrary_EvalMode eval_mode)
+{
+	switch (eval_mode) {
+		case CACHE_LIBRARY_EVAL_RENDER: return PTC_PASS_FINAL;
+		case CACHE_LIBRARY_EVAL_REALTIME: return PTC_PASS_PREVIEW;
+	}
+	return PTC_PASS_FINAL;
+}
+
 bool BKE_cache_read_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
                                 Scene *scene, Group *dupgroup, float frame, eCacheLibrary_EvalMode eval_mode, bool for_display)
 {
@@ -396,7 +405,7 @@ bool BKE_cache_read_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
 	if (!archive)
 		return false;
 	
-	PTC_reader_archive_use_render(archive, eval_mode == CACHE_LIBRARY_EVAL_RENDER);
+	PTC_reader_archive_set_pass(archive, cache_pass_from_eval_mode(eval_mode));
 	
 	cache_get_read_flags(cachelib, eval_mode, for_display, &read_strands_motion, &read_strands_children);
 	// TODO duplicache reader should only overwrite data that is not sequentially generated by modifiers (simulations) ...
@@ -447,7 +456,7 @@ bool BKE_cache_read_dupli_object(CacheLibrary *cachelib, DupliObjectData *data,
 	if (!archive)
 		return false;
 	
-	PTC_reader_archive_use_render(archive, eval_mode == CACHE_LIBRARY_EVAL_RENDER);
+	PTC_reader_archive_set_pass(archive, cache_pass_from_eval_mode(eval_mode));
 	
 	cache_get_read_flags(cachelib, eval_mode, for_display, &read_strands_motion, &read_strands_children);
 	reader = PTC_reader_duplicache_object(ob->id.name, ob, data, read_strands_motion, read_strands_children);
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index ff919e8..761300b 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1385,6 +1385,7 @@ void BKE_dupli_object_data_clear(DupliObjectData *data)
 		 */
 		data->dm->needsFree = true;
 		data->dm->release(data->dm);
+		data->dm = NULL;
 	}
 	
 	for (link = data->strands.first; link; link = link->next) {
@@ -1407,8 +1408,10 @@ void BKE_dupli_object_data_set_mesh(DupliObjectData *data, DerivedMesh *dm)
 	}
 	
 	data->dm = dm;
-	/* we own this dm now and need to protect it until we free it ourselves */
-	dm->needsFree = false;
+	if (dm) {
+		/* we own this dm now and need to protect it until we free it ourselves */
+		dm->needsFree = false;
+	}
 	
 	dupli_cache_calc_boundbox(data);
 }
@@ -1549,13 +1552,7 @@ void BKE_dupli_cache_free(DupliCache *dupcache)
 
 void BKE_dupli_cache_clear(DupliCache *dupcache)
 {
-	DupliObject *dob, *dob_next;
-	for (dob = dupcache->duplilist.first; dob; dob = dob_next) {
-		dob_next = dob->next;
-		
-		dupli_object_free(dob);
-	}
-	BLI_listbase_clear(&dupcache->duplilist);
+	BKE_dupli_cache_clear_instances(dupcache);
 	
 	BLI_ghash_clear(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_data_free);
 }
@@ -1571,6 +1568,19 @@ void BKE_dupli_cache_clear_instances(DupliCache *dupcache)
 	BLI_listbase_clear(&dupcache->duplilist);
 }
 
+void BKE_dupli_cache_clear_data(DupliCache *dupcache)
+{
+	GHashIterator iter;
+	
+	BKE_dupli_cache_clear_instances(dupcache);
+	
+	BLI_ghashIterator_init(&iter, dupcache->ghash);
+	for (; !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+		DupliObjectData *dobdata = BLI_ghashIterator_getValue(&iter);
+		BKE_dupli_object_data_clear(dobdata);
+	}
+}
+
 static DupliObjectData *dupli_cache_add_object_data(DupliCache *dupcache, Object *ob)
 {
 	DupliObjectData *data = MEM_callocN(sizeof(DupliObjectData), "dupli object data");
@@ -1604,8 +1614,6 @@ void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachel
 {
 	DupliObject *dob;
 	
-	BKE_dupli_cache_clear(dupcache);
-	
 	if (!(group && cachelib))
 		return;
 	
@@ -1618,62 +1626,61 @@ void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachel
 	
 	for (dob = dupcache->duplilist.first; dob; dob = dob->next) {
 		DupliObjectData *data = BKE_dupli_cache_find_data(dupcache, dob->ob);
-		if (!data) {
-			ParticleSystem *psys;
-			
+		ParticleSystem *psys;
+		
+		if (!data)
 			data = dupli_cache_add_object_data(dupcache, dob->ob);
-			
-			if (cachelib->data_types & CACHE_TYPE_DERIVED_MESH) {
-				if (dob->ob->type == OB_MESH) {
-					DerivedMesh *dm;
-					
-					if (eval_ctx->mode == DAG_EVAL_RENDER) {
-						dm = mesh_create_derived_render(scene, dob->ob, CD_MASK_BAREMESH);
-					}
-					else {
-						dm = mesh_create_derived_view(scene, dob->ob, CD_MASK_BAREMESH);
-					}
-					
-					if (dm)
-						BKE_dupli_object_data_set_mesh(data, dm);
+		
+		if (cachelib->data_types & CACHE_TYPE_DERIVED_MESH) {
+			if (dob->ob->type == OB_MESH) {
+				DerivedMesh *dm;
+				
+				if (eval_ctx->mode == DAG_EVAL_RENDER) {
+					dm = mesh_create_derived_render(scene, dob->ob, CD_MASK_BAREMESH);
+				}
+				else {
+					dm = mesh_create_derived_view(scene, dob->ob, CD_MASK_BAREMESH);
 				}
+				
+				if (dm)
+					BKE_dupli_object_data_set_mesh(data, dm);
 			}
-			
-			for (psys = dob->ob->particlesystem.first; psys; psys = psys->next) {
-				if (cachelib->data_types & CACHE_TYPE_HAIR) {
-					if (psys->part && psys->part->type == PART_HAIR) {
-						int numstrands = psys->totpart;
-						int numverts = count_hair_verts(psys);
-						ParticleData *pa;
-						HairKey *hkey;
-						int p, k;
+		}
+		
+		for (psys = dob->ob->particlesystem.first; psys; psys = psys->next) {
+			if (cachelib->data_types & CACHE_TYPE_HAIR) {
+				if (psys->part && psys->part->type == PART_HAIR) {
+					int numstrands = psys->totpart;
+					int numverts = count_hair_verts(psys);
+					ParticleData *pa;
+					HairKey *hkey;
+					int p, k;
+					
+					Strands *strands = BKE_strands_new(numstrands, numverts);
+					StrandsCurve *scurve = strands->curves;
+					StrandsVertex *svert = strands->verts;
+					
+					for (p = 0, pa = psys->particles; p < psys->totpart; ++p, ++pa) {
+						float hairmat[4][4];
+						psys_mat_hair_to_object(dob->ob, data->dm, psys->part->from, pa, hairmat);
 						
-						Strands *strands = BKE_strands_new(numstrands, numverts);
-						StrandsCurve *scurve = strands->curves;
-						StrandsVertex *svert = strands->verts;
+						scurve->numverts = pa->totkey;
+						copy_m3_m4(scurve->root_matrix, hairmat);
 						
-						for (p = 0, pa = psys->particles; p < psys->totpart; ++p, ++pa) {
-							float hairmat[4][4];
-							psys_mat_hair_to_object(dob->ob, data->dm, psys->part->from, pa, hairmat);
-							
-							scurve->numverts = pa->totkey;
-							copy_m3_m4(scurve->root_matrix, hairmat);
+						for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
+							mul_v3_m4v3(svert->co, hairmat, hkey->co);
+							if (calc_strands_base)
+								copy_v3_v3(svert->base, svert->co);
+							svert->time = hkey->time;
+							svert->weight = hkey->weight;
 							
-							for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
-								copy_v3_v3(svert->co, hkey->co);
-								if (calc_strands_base)
-									copy_v3_v3(svert->base, hkey->co);
-								svert->time = hkey->time;
-								svert->weight = hkey->weight;
-								
-								++svert;
-							}
-							
-							++scurve;
+							++svert;
 						}
 						
-						BKE_dupli_object_data_add_strands(data, psys->name, strands);
+						++scurve;
 					}
+					
+					BKE_dupli_object_data_add_strands(data, psys->name, strands);
 				}
 			}
 		}
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 090d3a5..1540d7b 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -251,42 +251,18 @@ static void cache_library_bake_set_particle_baking(Main *bmain, bool baking)
 	}
 }
 
-static void cache_library_bake_do(CacheLibraryBakeJob *data)
+static void cache_library_bake_do(CacheLibraryBakeJob *data, CacheProcessData *process_data)
 {
 	Scene *scene = data->scene;
 	int frame, frame_prev, start_frame, end_frame;
 	
-	/* === prepare === */
-	
-	CacheProcessData process_data;
-	
-	copy_m4_m4(process_data.mat, data->mat);
-	process_data.dupcache = BKE_dupli_cache_new();
-	
 	if (cache_library_bake_stop(data))
 		return;
 	
-	switch (data->cachelib->source_mode) {
-		case CACHE_LIBRARY_SOURCE_SCENE:
-			data->writer = PTC_writer_dupligroup(data->group->id.name, &data->eval_ctx, scene, data->group, data->cachelib);
-			break;
-		case CACHE_LIBRARY_SOURCE_CACHE:
-			data->writer = PTC_writer_duplicache(data->group->id.name, data->group, process_data.dupcache, data->cachelib->data_types, G.debug & G_DEBUG_SIMDATA);
-			break;
-	}
-	if (!data->writer)
-		return;
-	
-	data->cachelib->flag |= CACHE_LIBRARY_BAKING;
-	
-	PTC_writer_init(data->writer, data->archive);
-	
 	/* XXX where to get this from? */
 	start_frame = scene->r.sfra;
 	end_frame = scene->r.efra;
 	
-	/* === frame loop === */
-	
 	cache_library_bake_set_progress(data, 0.0f);
 	for (frame = frame_prev = start_frame; frame <= end_frame; frame_prev = frame++) {
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list