[Bf-blender-cvs] [5667822876c] blender2.8: Cycles: convert pointdensity from DerivedMesh to COW Mesh.

Brecht Van Lommel noreply at git.blender.org
Wed May 23 11:28:16 CEST 2018


Commit: 5667822876cb67237122bbd178f17667876bea66
Author: Brecht Van Lommel
Date:   Wed May 23 11:11:34 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB5667822876cb67237122bbd178f17667876bea66

Cycles: convert pointdensity from DerivedMesh to COW Mesh.

Fixes hang in regression tests.

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

M	source/blender/render/intern/source/pointdensity.c

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

diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c
index 51eaba3a054..53359c305dc 100644
--- a/source/blender/render/intern/source/pointdensity.c
+++ b/source/blender/render/intern/source/pointdensity.c
@@ -43,6 +43,7 @@
 
 #include "BLT_translation.h"
 
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
@@ -50,7 +51,6 @@
 
 #include "BKE_colorband.h"
 #include "BKE_deform.h"
-#include "BKE_DerivedMesh.h"
 #include "BKE_lattice.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
@@ -165,10 +165,8 @@ static void alloc_point_data(PointDensity *pd)
 static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene,
                                     PointDensity *pd,
                                     Object *ob,
-                                    ParticleSystem *psys,
-                                    const bool use_render_params)
+                                    ParticleSystem *psys)
 {
-	DerivedMesh *dm;
 	ParticleKey state;
 	ParticleCacheKey *cache;
 	ParticleSimulationData sim = {NULL};
@@ -179,25 +177,10 @@ static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene,
 	int data_used;
 	float *data_vel, *data_life;
 	float partco[3];
-
-	/* init everything */
-	if (!psys || !ob || !pd) {
-		return;
-	}
+	const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
 
 	data_used = point_data_used(pd);
 
-	if (use_render_params) {
-		dm = mesh_create_derived_render(depsgraph, scene,
-		                                ob,
-		                                CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
-	}
-	else {
-		dm = mesh_get_derived_final(depsgraph, scene,
-		                            ob,
-		                            CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
-	}
-
 	if (!psys_check_enabled(ob, psys, use_render_params)) {
 		return;
 	}
@@ -285,7 +268,6 @@ static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene,
 	}
 
 	BLI_bvhtree_balance(pd->point_tree);
-	dm->release(dm);
 
 	if (psys->lattice_deform_data) {
 		end_latt_deform(psys->lattice_deform_data);
@@ -294,20 +276,20 @@ static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene,
 }
 
 
-static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob), DerivedMesh *dm, float *data_color)
+static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob), Mesh *mesh, float *data_color)
 {
-	const MLoop *mloop = dm->getLoopArray(dm);
-	const int totloop = dm->getNumLoops(dm);
+	const MLoop *mloop = mesh->mloop;
+	const int totloop = mesh->totloop;
 	const MLoopCol *mcol;
 	char layername[MAX_CUSTOMDATA_LAYER_NAME];
 	int i;
 	
 	BLI_assert(data_color);
 	
-	if (!CustomData_has_layer(&dm->loopData, CD_MLOOPCOL))
+	if (!CustomData_has_layer(&mesh->ldata, CD_MLOOPCOL))
 		return;
-	CustomData_validate_layer_name(&dm->loopData, CD_MLOOPCOL, pd->vertex_attribute_name, layername);
-	mcol = CustomData_get_layer_named(&dm->loopData, CD_MLOOPCOL, layername);
+	CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPCOL, pd->vertex_attribute_name, layername);
+	mcol = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPCOL, layername);
 	if (!mcol)
 		return;
 	
@@ -340,16 +322,16 @@ static void pointdensity_cache_vertex_color(PointDensity *pd, Object *UNUSED(ob)
 	MEM_freeN(mcorners);
 }
 
-static void pointdensity_cache_vertex_weight(PointDensity *pd, Object *ob, DerivedMesh *dm, float *data_color)
+static void pointdensity_cache_vertex_weight(PointDensity *pd, Object *ob, Mesh *mesh, float *data_color)
 {
-	const int totvert = dm->getNumVerts(dm);
+	const int totvert = mesh->totvert;
 	const MDeformVert *mdef, *dv;
 	int mdef_index;
 	int i;
 	
 	BLI_assert(data_color);
 	
-	mdef = CustomData_get_layer(&dm->vertData, CD_MDEFORMVERT);
+	mdef = CustomData_get_layer(&mesh->vdata, CD_MDEFORMVERT);
 	if (!mdef)
 		return;
 	mdef_index = defgroup_name_index(ob, pd->vertex_attribute_name);
@@ -371,9 +353,9 @@ static void pointdensity_cache_vertex_weight(PointDensity *pd, Object *ob, Deriv
 	}
 }
 
-static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob), DerivedMesh *dm, float *data_color)
+static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob), Mesh *mesh, float *data_color)
 {
-	MVert *mvert = dm->getVertArray(dm), *mv;
+	MVert *mvert = mesh->mvert, *mv;
 	int i;
 	
 	BLI_assert(data_color);
@@ -383,16 +365,14 @@ static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob
 	}
 }
 
-static void pointdensity_cache_object(Depsgraph *depsgraph, Scene *scene,
-                                      PointDensity *pd,
-                                      Object *ob,
-                                      const bool use_render_params)
+static void pointdensity_cache_object(PointDensity *pd,
+                                      Object *ob)
 {
 	float *data_color;
 	int i;
-	DerivedMesh *dm;
 	CustomDataMask mask = CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL;
 	MVert *mvert = NULL, *mv;
+	Mesh *mesh = ob->data;
 
 	switch (pd->ob_color_source) {
 		case TEX_PD_COLOR_VERTCOL:
@@ -403,15 +383,8 @@ static void pointdensity_cache_object(Depsgraph *depsgraph, Scene *scene,
 			break;
 	}
 
-	if (use_render_params) {
-		dm = mesh_create_derived_render(depsgraph, scene, ob, mask);
-	}
-	else {
-		dm = mesh_get_derived_final(depsgraph, scene, ob, mask);
-	}
-
-	mvert = dm->getVertArray(dm);	/* local object space */
-	pd->totpoints = dm->getNumVerts(dm);
+	mvert = mesh->mvert; /* local object space */
+	pd->totpoints = mesh->totvert;
 	if (pd->totpoints == 0) {
 		return;
 	}
@@ -443,25 +416,22 @@ static void pointdensity_cache_object(Depsgraph *depsgraph, Scene *scene,
 	
 	switch (pd->ob_color_source) {
 		case TEX_PD_COLOR_VERTCOL:
-			pointdensity_cache_vertex_color(pd, ob, dm, data_color);
+			pointdensity_cache_vertex_color(pd, ob, mesh, data_color);
 			break;
 		case TEX_PD_COLOR_VERTWEIGHT:
-			pointdensity_cache_vertex_weight(pd, ob, dm, data_color);
+			pointdensity_cache_vertex_weight(pd, ob, mesh, data_color);
 			break;
 		case TEX_PD_COLOR_VERTNOR:
-			pointdensity_cache_vertex_normal(pd, ob, dm, data_color);
+			pointdensity_cache_vertex_normal(pd, ob, mesh, data_color);
 			break;
 	}
 
 	BLI_bvhtree_balance(pd->point_tree);
-	dm->release(dm);
-
 }
 
 static void cache_pointdensity(Depsgraph *depsgraph,
                                Scene *scene,
-                               PointDensity *pd,
-                               const bool use_render_params)
+                               PointDensity *pd)
 {
 	if (pd == NULL) {
 		return;
@@ -489,13 +459,12 @@ static void cache_pointdensity(Depsgraph *depsgraph,
 		                        scene,
 		                        pd,
 		                        ob,
-		                        psys,
-		                        use_render_params);
+		                        psys);
 	}
 	else if (pd->source == TEX_PD_OBJECT) {
 		Object *ob = pd->object;
 		if (ob && ob->type == OB_MESH)
-			pointdensity_cache_object(depsgraph, scene, pd, ob, use_render_params);
+			pointdensity_cache_object(pd, ob);
 	}
 }
 
@@ -828,13 +797,11 @@ void RE_point_density_cache(
         struct Depsgraph *depsgraph,
         PointDensity *pd)
 {
-	const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
-
 	Scene *scene = DEG_get_evaluated_scene(depsgraph);
 
 	/* Same matricies/resolution as dupli_render_particle_set(). */
 	BLI_mutex_lock(&sample_mutex);
-	cache_pointdensity(depsgraph, scene, pd, use_render_params);
+	cache_pointdensity(depsgraph, scene, pd);
 	BLI_mutex_unlock(&sample_mutex);
 }



More information about the Bf-blender-cvs mailing list