[Bf-blender-cvs] [2a40c6ee2bb] master: Modifier eval: add support for request poly normals layer.

Bastien Montagne noreply at git.blender.org
Fri Mar 8 17:53:45 CET 2019


Commit: 2a40c6ee2bba46b4e4475c45c2d2332cb417a541
Author: Bastien Montagne
Date:   Fri Mar 8 11:42:45 2019 +0100
Branches: master
https://developer.blender.org/rB2a40c6ee2bba46b4e4475c45c2d2332cb417a541

Modifier eval: add support for request poly normals layer.

Ensure we do get poly normals if they are requested in given cddata mask.

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

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

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

diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 1fe72ce95a7..574333be70c 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1178,6 +1178,10 @@ static void mesh_calc_modifiers(
 	const bool do_mod_mcol = (ob->mode == OB_MODE_OBJECT);
 	const bool do_loop_normals = ((((Mesh *)ob->data)->flag & ME_AUTOSMOOTH) != 0 ||
 	                              (dataMask->lmask & CD_MASK_NORMAL) != 0);
+	/* Some modifiers may need this info from their target (other) object, simpler to generate it here as well.
+	 * Note that they will always be generated when no loop normals are comptuted,
+	 * since they are needed by drawing code. */
+	const bool do_poly_normals = ((dataMask->pmask & CD_MASK_NORMAL) != 0);
 
 	VirtualModifierData virtualModifierData;
 
@@ -1580,6 +1584,12 @@ static void mesh_calc_modifiers(
 	}
 
 	if (do_loop_normals) {
+		/* In case we also need poly normals, add the layer here, then BKE_mesh_calc_normals_split() will fill it. */
+		if (do_poly_normals) {
+			if (!CustomData_has_layer(&(*r_final)->pdata, CD_NORMAL)) {
+				CustomData_add_layer(&(*r_final)->pdata, CD_NORMAL, CD_CALLOC, NULL, (*r_final)->totpoly);
+			}
+		}
 		/* Compute loop normals (note: will compute poly and vert normals as well, if needed!) */
 		BKE_mesh_calc_normals_split(*r_final);
 		BKE_mesh_tessface_clear(*r_final);
@@ -1708,6 +1718,8 @@ static void editbmesh_calc_modifiers(
 
 	const bool do_loop_normals = ((((Mesh *)(ob->data))->flag & ME_AUTOSMOOTH) != 0 ||
 	                              (dataMask->lmask & CD_MASK_NORMAL) != 0);
+	/* Some modifiers may need this info from their target (other) object, simpler to generate it here as well. */
+	const bool do_poly_normals = ((dataMask->pmask & CD_MASK_NORMAL) != 0);
 
 	modifiers_clearErrors(ob);
 
@@ -1920,6 +1932,17 @@ static void editbmesh_calc_modifiers(
 	}
 
 	if (do_loop_normals) {
+		/* In case we also need poly normals, add the layer here, then BKE_mesh_calc_normals_split() will fill it. */
+		if (do_poly_normals) {
+			if (!CustomData_has_layer(&(*r_final)->pdata, CD_NORMAL)) {
+				CustomData_add_layer(&(*r_final)->pdata, CD_NORMAL, CD_CALLOC, NULL, (*r_final)->totpoly);
+			}
+			if (r_cage && *r_cage && (*r_cage != *r_final)) {
+				if (!CustomData_has_layer(&(*r_cage)->pdata, CD_NORMAL)) {
+					CustomData_add_layer(&(*r_cage)->pdata, CD_NORMAL, CD_CALLOC, NULL, (*r_cage)->totpoly);
+				}
+			}
+		}
 		/* Compute loop normals */
 		BKE_mesh_calc_normals_split(*r_final);
 		BKE_mesh_tessface_clear(*r_final);



More information about the Bf-blender-cvs mailing list