[Bf-blender-cvs] [6534a7b] alembic: Fix for threaded dupli cache generation from groups.

Sergey Sharybin noreply at git.blender.org
Wed May 6 11:15:36 CEST 2015


Commit: 6534a7b9edfb563857f565a6c301d132e2c0b173
Author: Sergey Sharybin
Date:   Wed May 6 10:12:46 2015 +0200
Branches: alembic
https://developer.blender.org/rB6534a7b9edfb563857f565a6c301d132e2c0b173

Fix for threaded dupli cache generation from groups.

Strands require a valid DerivedMesh for calculating their root matrix
and surface mapping. The scheduler tasks were created such that strands
would be calculated while the DM task was not finished yet, leading to
missing DM data.

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

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

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

diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index b652128..83985d4 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1601,13 +1601,55 @@ static int count_hair_verts(ParticleSystem *psys)
 	return numverts;
 }
 
+static void dupli_strands_data_update(CacheLibrary *cachelib, DupliObjectData *data,
+                                      DupliObject *dob, bool calc_strands_base) {
+	ParticleSystem *psys;
+	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);
+
+					scurve->numverts = pa->totkey;
+					copy_m3_m4(scurve->root_matrix, hairmat);
+
+					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;
+				}
+
+				BKE_dupli_object_data_add_strands(data, psys->name, strands);
+			}
+		}
+	}
+}
+
 typedef struct DupliObjectDataFromGroupState {
 	EvaluationContext *eval_ctx;
 	Scene *scene;
+	CacheLibrary *cachelib;
+	bool calc_strands_base;
 } DupliObjectDataFromGroupState;
 
 typedef struct DupliObjectDataFromGroupTask {
-	Object *object;
+	DupliObject *dob;
 	DupliObjectData *data;
 } DupliObjectDataFromGroupTask;
 
@@ -1615,18 +1657,21 @@ static void dupli_object_data_from_group_func(TaskPool *pool, void *taskdata, in
 {
 	DupliObjectDataFromGroupState *state = (DupliObjectDataFromGroupState *)BLI_task_pool_userdata(pool);
 	DupliObjectDataFromGroupTask *task = (DupliObjectDataFromGroupTask *)taskdata;
+	Object *object = task->dob->ob;
 	DerivedMesh *dm;
 
 	if (state->eval_ctx->mode == DAG_EVAL_RENDER) {
-		dm = mesh_create_derived_render(state->scene, task->object, CD_MASK_BAREMESH);
+		dm = mesh_create_derived_render(state->scene, object, CD_MASK_BAREMESH);
 	}
 	else {
-		dm = mesh_create_derived_view(state->scene, task->object, CD_MASK_BAREMESH);
+		dm = mesh_create_derived_view(state->scene, object, CD_MASK_BAREMESH);
 	}
 
 	if (dm != NULL) {
 		BKE_dupli_object_data_set_mesh(task->data, dm);
 	}
+
+	dupli_strands_data_update(state->cachelib, task->data, task->dob, state->calc_strands_base);
 }
 
 void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachelib, DupliCache *dupcache, EvaluationContext *eval_ctx, bool calc_strands_base)
@@ -1651,62 +1696,29 @@ void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachel
 
 	state.eval_ctx = eval_ctx;
 	state.scene = scene;
+	state.cachelib = cachelib;
+	state.calc_strands_base = calc_strands_base;
 	task_pool = BLI_task_pool_create(task_scheduler, &state);
 
 	for (dob = dupcache->duplilist.first; dob; dob = dob->next) {
 		DupliObjectData *data = BKE_dupli_cache_find_data(dupcache, dob->ob);
 		if (!data) {
-			ParticleSystem *psys;
-			
+			bool strands_handled = false;
 			data = dupli_cache_add_object_data(dupcache, dob->ob);
-			
 			if (cachelib->data_types & CACHE_TYPE_DERIVED_MESH) {
 				if (dob->ob->type == OB_MESH) {
 					/* TODO(sergey): Consider using memory pool instead. */
 					DupliObjectDataFromGroupTask *task = MEM_mallocN(sizeof(DupliObjectDataFromGroupTask),
-					                                            "dupcache task");
-					task->object = dob->ob;
+					                                                 "dupcache task");
+					task->dob = dob;
 					task->data = data;
 					BLI_task_pool_push(task_pool, dupli_object_data_from_group_func, task, true, TASK_PRIORITY_LOW);
+					/* Task is getting care of strands as well. */
+					strands_handled = true;
 				}
 			}
-			
-			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);
-							
-							scurve->numverts = pa->totkey;
-							copy_m3_m4(scurve->root_matrix, hairmat);
-							
-							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;
-						}
-						
-						BKE_dupli_object_data_add_strands(data, psys->name, strands);
-					}
-				}
+			if (!strands_handled) {
+				dupli_strands_data_update(cachelib, data, dob, calc_strands_base);
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list