[Bf-blender-cvs] [b11beff03d8] temp-modifier-rm-cddm: No more DerivedMesh in mesh_calc_modifiers

Mai Lavelle noreply at git.blender.org
Fri May 11 10:40:11 CEST 2018


Commit: b11beff03d808538b5fb2b19f675b6ff146811f6
Author: Mai Lavelle
Date:   Fri May 11 03:53:52 2018 -0400
Branches: temp-modifier-rm-cddm
https://developer.blender.org/rBb11beff03d808538b5fb2b19f675b6ff146811f6

No more DerivedMesh in mesh_calc_modifiers

Also a little cleanup.

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

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

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

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 4a15305b13e..fa073e03e3e 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1987,6 +1987,32 @@ static void dm_ensure_display_normals(DerivedMesh *dm)
 	}
 }
 
+static void mesh_ensure_display_normals(Mesh *mesh)
+{
+	/* Note: mesh *may* have a poly CD_NORMAL layer (generated by a modifier needing poly normals e.g.).
+	 *       We do not use it here, though. And it should be tagged as temp!
+	 */
+	/* BLI_assert((CustomData_has_layer(&mesh->pdata, CD_NORMAL) == false)); */
+
+	if(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL || !CustomData_has_layer(&mesh->pdata, CD_NORMAL)) {
+		float (*face_nors)[3] = NULL;
+		face_nors = MEM_malloc_arrayN(mesh->totpoly, sizeof(*face_nors), "face_nors");
+
+		/* if normals are dirty we want to calculate vertex normals too */
+		bool only_face_normals = !(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL);
+
+		/* calculate face normals */
+		BKE_mesh_calc_normals_poly(
+				mesh->mvert, NULL, mesh->totvert, mesh->mloop, mesh->mpoly,
+				mesh->totloop, mesh->totpoly, face_nors,
+				only_face_normals);
+
+		CustomData_add_layer(&mesh->pdata, CD_NORMAL, CD_ASSIGN, face_nors, mesh->totpoly);
+
+		mesh->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
+	}
+}
+
 static void mesh_calc_modifiers(
         struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3],
         const bool useRenderParams, int useDeform,
@@ -1994,7 +2020,7 @@ static void mesh_calc_modifiers(
         const int index, const bool useCache, const bool build_shapekey_layers,
         const bool allow_gpu,
         /* return args */
-        DerivedMesh **r_deformdm_dep, DerivedMesh **r_finaldm_dep)
+        Mesh **r_deform_mesh, Mesh **r_final_mesh)
 {
 	Mesh *me = ob->data;
 	/* Always get the vertex coordinates from the original mesh. Otherwise
@@ -2026,7 +2052,6 @@ static void mesh_calc_modifiers(
 	const bool do_mod_wmcol = do_init_wmcol;
 
 	const bool do_loop_normals = (me->flag & ME_AUTOSMOOTH) != 0;
-	const float loop_normals_split_angle = me->smoothresh;
 
 	VirtualModifierData virtualModifierData;
 
@@ -2069,10 +2094,10 @@ static void mesh_calc_modifiers(
 	datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode, previewmd, previewmask);
 	curr = datamasks;
 
-	if (r_deformdm_dep) {
-		*r_deformdm_dep = NULL;
+	if (r_deform_mesh) {
+		*r_deform_mesh = NULL;
 	}
-	*r_finaldm_dep = NULL;
+	*r_final_mesh = NULL;
 
 	if (useDeform) {
 		if (inputVertexCos)
@@ -2111,15 +2136,15 @@ static void mesh_calc_modifiers(
 		 * places that wish to use the original mesh but with deformed
 		 * coordinates (vpaint, etc.)
 		 */
-		if (r_deformdm_dep) {
-			*r_deformdm_dep = CDDM_from_mesh(me);
+		if (r_deform_mesh) {
+			BKE_id_copy_ex(NULL, &me->id, (ID**)r_deform_mesh, LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT, false);
 
 			/* XXX: Is build_shapekey_layers ever even true? This should have crashed long ago... */
-			if (build_shapekey_layers)
-				add_shapekey_layers(*r_deformdm_dep, me, ob);
+			//if (build_shapekey_layers)
+			//	add_shapekey_layers(*r_deform_mesh, me, ob);
 			
 			if (deformedVerts) {
-				CDDM_apply_vert_coords(*r_deformdm_dep, deformedVerts);
+				apply_vert_coords(*r_deform_mesh, deformedVerts);
 			}
 		}
 	}
@@ -2208,7 +2233,7 @@ static void mesh_calc_modifiers(
 		}
 
 		/* How to apply modifier depends on (a) what we already have as
-		 * a result of previous modifiers (could be a DerivedMesh or just
+		 * a result of previous modifiers (could be a Mesh or just
 		 * deformed vertices) and (b) what type the modifier is.
 		 */
 
@@ -2245,7 +2270,7 @@ static void mesh_calc_modifiers(
 			else
 				nextmask = dataMask;
 
-			/* apply vertex coordinates or build a DerivedMesh as necessary */
+			/* apply vertex coordinates or build a Mesh as necessary */
 			if (mesh) {
 				if (deformedVerts) {
 					/* XXX: What's the point of this copy?
@@ -2262,7 +2287,7 @@ static void mesh_calc_modifiers(
 
 				// XXX: port to Mesh if build_shapekey_layers can ever be true
 				//if (build_shapekey_layers)
-				//	add_shapekey_layers(dm_dep, me, ob);
+				//	add_shapekey_layers(mesh, me, ob);
 
 				if (deformedVerts) {
 					apply_vert_coords(mesh, deformedVerts);
@@ -2292,7 +2317,7 @@ static void mesh_calc_modifiers(
 			}
 
 			
-			/* set the DerivedMesh to only copy needed data */
+			/* set the Mesh to only copy needed data */
 			mask = curr->mask;
 			/* needMapping check here fixes bug [#28112], otherwise it's
 			 * possible that it won't be copied */
@@ -2331,7 +2356,7 @@ static void mesh_calc_modifiers(
 				}
 			}
 
-			/* create an orco derivedmesh in parallel */
+			/* create an orco mesh in parallel */
 			if (nextmask & CD_MASK_ORCO) {
 				if (!orco_mesh) {
 					orco_mesh = create_orco_mesh(ob, me, NULL, CD_ORCO);
@@ -2348,15 +2373,14 @@ static void mesh_calc_modifiers(
 				if (new_mesh) {
 					/* if the modifier returned a new mesh, release the old one */
 					if (orco_mesh && orco_mesh != new_mesh) {
-						BKE_mesh_free(orco_mesh);
-						MEM_freeN(orco_mesh);
+						BKE_id_free(NULL, orco_mesh);
 					}
 
 					orco_mesh = new_mesh;
 				}
 			}
 
-			/* create cloth orco derivedmesh in parallel */
+			/* create cloth orco mesh in parallel */
 			if (nextmask & CD_MASK_CLOTH_ORCO) {
 				if (!cloth_orco_mesh)
 					cloth_orco_mesh = create_orco_mesh(ob, me, NULL, CD_CLOTH_ORCO);
@@ -2370,8 +2394,7 @@ static void mesh_calc_modifiers(
 				if (new_mesh) {
 					/* if the modifier returned a new mesh, release the old one */
 					if (cloth_orco_mesh && cloth_orco_mesh != new_mesh) {
-						BKE_mesh_free(cloth_orco_mesh);
-						MEM_freeN(cloth_orco_mesh);
+						BKE_id_free(NULL, cloth_orco_mesh);
 					}
 
 					cloth_orco_mesh = new_mesh;
@@ -2388,7 +2411,7 @@ static void mesh_calc_modifiers(
 				append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
 			}
 
-			//dm_dep->deformedOnly = false; // XXX: Does Mesh need this?
+			// dm->deformedOnly = false; // XXX: Does Mesh need this? Looks to be used only by particle system
 		}
 
 		isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
@@ -2405,72 +2428,67 @@ static void mesh_calc_modifiers(
 	for (md = firstmd; md; md = md->next)
 		modifier_freeTemporaryData(md);
 
-	/* Yay, we are done. If we have a DerivedMesh and deformed vertices
-	 * need to apply these back onto the DerivedMesh. If we have no
-	 * DerivedMesh then we need to build one.
+	/* Yay, we are done. If we have a Mesh and deformed vertices
+	 * need to apply these back onto the Mesh. If we have no
+	 * Mesh then we need to build one.
 	 */
-	DerivedMesh *finaldm_dep;
+	Mesh *final_mesh;
 
 	if (mesh && deformedVerts) {
-		finaldm_dep = CDDM_from_mesh_ex(mesh, CD_DUPLICATE);
+		BKE_id_copy_ex(NULL, &mesh->id, (ID**)&final_mesh, LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT, false);
+		BKE_id_free(NULL, mesh);
 
-		BKE_mesh_free(mesh);
-		MEM_freeN(mesh);
-
-		CDDM_apply_vert_coords(finaldm_dep, deformedVerts);
+		apply_vert_coords(final_mesh, deformedVerts);
 
 #if 0 /* For later nice mod preview! */
 		/* In case we need modified weights in CD_PREVIEW_MCOL, we have to re-compute it. */
 		if (do_final_wmcol)
-			DM_update_weight_mcol(ob, finaldm_dep, draw_flag, NULL, 0, NULL);
+			mesh_update_weight_mcol(ob, final_mesh, draw_flag, NULL, 0, NULL);
 #endif
 	}
 	else if (mesh) {
-		finaldm_dep = CDDM_from_mesh_ex(mesh, CD_DUPLICATE); // XXX: originally this was just an assignment without copy
-
-		BKE_mesh_free(mesh);
-		MEM_freeN(mesh);
+		final_mesh = mesh;
 
 #if 0 /* For later nice mod preview! */
 		/* In case we need modified weights in CD_PREVIEW_MCOL, we have to re-compute it. */
 		if (do_final_wmcol)
-			DM_update_weight_mcol(ob, finaldm_dep, draw_flag, NULL, 0, NULL);
+			mesh_update_weight_mcol(ob, final_mesh, draw_flag, NULL, 0, NULL);
 #endif
 	}
 	else {
-		finaldm_dep = CDDM_from_mesh_ex(me, CD_DUPLICATE);
+		BKE_id_copy_ex(NULL, &me->id, (ID**)&final_mesh, LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT, false);
 		
-		if (build_shapekey_layers) {
-			add_shapekey_layers(finaldm_dep, me, ob);
-		}
+		//if (build_shapekey_layers) {
+		//	add_shapekey_layers(final_mesh, me, ob);
+		//}
 		
 		if (deformedVerts) {
-			CDDM_apply_vert_coords(finaldm_dep, deformedVerts);
+			apply_vert_coords(final_mesh, deformedVerts);
 		}
 
 		/* In this case, we should never have weight-modifying modifiers in stack... */
 		if (do_init_wmcol)
-			DM_update_weight_mcol(ob, finaldm_dep, draw_flag, NULL, 0, NULL);
+			mesh_update_weight_mcol(ob, final_mesh, draw_flag, NULL, 0, NULL);
 	}
 
 	/* add an orco layer if needed */
 	if (dataMask & CD_MASK_ORCO) {
-		/* TODO(mai): Right now theres a mix of Mesh and DM here, need to convert or port fully for this call. */
-		//add_orco_dm(ob, NULL, finaldm_dep, orcodm_dep, CD_ORCO);
+		add_orco_mesh(ob, NULL, final_mesh, orco_mesh, CD_ORCO);
 
-		if (r_deformdm_dep && *r_deformdm_dep)
-			add_orco_dm(ob, NULL, *r_deformdm_dep, NULL, CD_ORCO);
+		if (r_deform_mesh && *r_deform_mesh)
+			add_orco_mesh(ob, NULL, *r_deform_mesh, NULL, CD_ORCO);
 	}
 
 	if (do_loop_normals) {
 		/* Compute loop normals (note: will compute poly and vert normals as well, if needed!) */
-		DM_calc_loop_normals(finaldm_dep, do_loop_normals, loop_normals_split_angle);
+		BKE_mesh_calc_normals_split(final_mesh);
+		// dm->dirty |= DM_DIRTY_TESS_CDLAYERS; XXX
 	}
 
 	if (sculpt_dyntopo == false) {
 		/* watch this! after 2.75a we move to from tessface to looptri (by default) */
 		if (dataMask & CD_MASK_MFACE) {
-			DM_ensure_tessface(finaldm_dep);
+			// DM_ensure_tessface(final_mesh); // XXX: port?
 		}
 
 		/* without this, drawing ngon tri's faces will show ugly tessellated face
@@ -2483,25 +2501,23 @@ static void mesh_calc_modifiers(
 		 * If using loop normals, poly nors have already been computed.
 		 */
 		if (!do_loop_normals) {
-			dm_ensure_display_normals(finaldm_dep);
+			mesh_ensure_display_normals(final_mesh);
 		}
 	}
 
 	/* Some modifiers, like datatransfer, may generate those data as temp layer, we do not want to keep them,
 	 * as they a

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list