[Bf-blender-cvs] [39c133e] temp_custom_loop_normals: Some cleanup, add new CD layer (CD_CUSTOMLOOPNORMAL, float[2]), and a function to convert custom normals to internal data.

Bastien Montagne noreply at git.blender.org
Wed Aug 6 21:36:34 CEST 2014


Commit: 39c133e46c118b2cc18cf49366ee40ecf44ece62
Author: Bastien Montagne
Date:   Sun Jun 22 11:25:59 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rB39c133e46c118b2cc18cf49366ee40ecf44ece62

Some cleanup, add new CD layer (CD_CUSTOMLOOPNORMAL, float[2]),
and a function to convert custom normals to internal data.

WIP

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/editderivedmesh.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/makesdna/DNA_customdata_types.h
M	source/blender/makesrna/intern/rna_mesh.c
M	source/blender/makesrna/intern/rna_mesh_api.c

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index cedaf9c..78ce331 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -207,8 +207,13 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float
 void BKE_mesh_normals_loop_split(
         struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
         struct MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
-        struct MPoly *mpolys, float (*polynors)[3], const int numPolys, float split_angle,
-        MLoopsNorSpaces *r_lnor_spaces, const float (*clnors_data)[2]);
+        struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, float split_angle,
+        MLoopsNorSpaces *r_lnor_spaces, const float (*clnors_data)[2], int *r_loop_to_poly);
+
+void BKE_mesh_normals_loop_custom_set(
+        struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
+        struct MLoop *mloops, const float (*custom_loopnors)[3], const int numLoops,
+        struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, float (*r_clnors_data)[2]);
 
 void BKE_mesh_calc_poly_normal(
         struct MPoly *mpoly, struct MLoop *loopstart,
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 3ddaa84..160f0ca 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -2543,17 +2543,14 @@ void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle)
 	dm->dirty &= ~DM_DIRTY_NORMALS;
 
 	{
-		MLoopsNorSpaces lnors_spaces = {NULL};
-		int i;
-		float (*clnor_data)[2] = MEM_mallocN(sizeof(*clnor_data) * (size_t)numLoops, __func__);
-
-		for (i = 0; i < numLoops; i++) {
-			clnor_data[i][0] = 0.7f;
-			clnor_data[i][1] = 0.5f;
-		}
+		//MLoopsNorSpaces lnors_spaces = {NULL};
+		//int i;
+		const float (*clnor_data)[2] = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
 
 		BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops,
-		                            mpolys, pnors, numPolys, split_angle, &lnors_spaces, clnor_data);
+		                            mpolys, (const float (*)[3])pnors, numPolys, split_angle,
+		                            NULL /* &lnors_spaces */, clnor_data, NULL);
+#if 0
 		for (i = 0; i < numLoops; i++) {
 			if (lnors_spaces.lspaces[i]->angle != 0.0f) {
 				LinkNode *loops = lnors_spaces.lspaces[i]->loops;
@@ -2574,6 +2571,7 @@ void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle)
 			}
 		}
 		BKE_free_loops_normal_spaces(&lnors_spaces);
+#endif
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index fd43501..35db134 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1071,6 +1071,28 @@ static void layerSwap_flnor(void *data, const int *corner_indices)
 	memcpy(flnors, nors, sizeof(nors));
 }
 
+static void layerInterp_clnor(void **UNUSED(sources), const float *UNUSED(weights), const float *UNUSED(sub_weights),
+                              int UNUSED(count), void *dest)
+{
+	/* For now, we simply restore interpolated custom normals to NOP ones, since real interpolation
+	 * would also imply we check all new custom normals are coherent (all loops of a same vert/same smooth fan
+	 * *must* have the same custom normal!!!).
+	 */
+	static float default_clnor[2] = {1.0f, 0.0f};
+	copy_v2_v2((float *)dest, default_clnor);
+}
+
+static void layerDefault_clnor(void *data, int count)
+{
+	static float default_clnor[2] = {1.0f, 0.0f};
+	float (*clnor)[2] = (float (*)[2])data;
+	int i;
+
+	for (i = 0; i < count; i++, clnor++) {
+		copy_v2_v2(*clnor, default_clnor);
+	}
+}
+
 static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
 	/* 0: CD_MVERT */
 	{sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -1184,6 +1206,8 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
 	{sizeof(float[4]), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
 	/* 40: CD_TESSLOOPNORMAL */
 	{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, NULL},
+	/* 41: CD_CUSTOMLOOPNORMAL */
+	{sizeof(float[2]), "vec3f", 1, NULL, NULL, NULL, layerInterp_clnor, NULL, layerDefault_clnor},
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
@@ -1199,38 +1223,42 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
 	/* 25-29 */ "CDMPoly", "CDMLoop", "CDShapeKeyIndex", "CDShapeKey", "CDBevelWeight",
 	/* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask",
 	/* 35-36 */ "CDGridPaintMask", "CDMVertSkin",
-	/* 37-40 */ "CDFreestyleEdge", "CDFreestyleFace", "CDMLoopTangent", "CDTessLoopNormal",
+	/* 37-38 */ "CDFreestyleEdge", "CDFreestyleFace",
+	/* 39-41 */ "CDMLoopTangent", "CDTessLoopNormal", "CDCustomLoopNormal",
 };
 
 
 const CustomDataMask CD_MASK_BAREMESH =
     CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_MLOOP | CD_MASK_MPOLY | CD_MASK_BWEIGHT;
 const CustomDataMask CD_MASK_MESH =
-    CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE |
+    CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE | CD_MASK_NORMAL |
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL |
     CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS |
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP |
     CD_MASK_MTEXPOLY | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
+    CD_MASK_CUSTOMLOOPNORMAL;
 const CustomDataMask CD_MASK_EDITMESH =
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX |
     CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR |
     CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_CUSTOMLOOPNORMAL;
 const CustomDataMask CD_MASK_DERIVEDMESH =
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE |
     CD_MASK_MCOL | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO |
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL |
     CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT |
     CD_MASK_PREVIEW_MCOL | CD_MASK_SHAPEKEY | CD_MASK_RECAST |
-    CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
+    CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
+    CD_MASK_CUSTOMLOOPNORMAL;
 const CustomDataMask CD_MASK_BMESH =
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT |
     CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS |
     CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
-    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
+    CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
+    CD_MASK_CUSTOMLOOPNORMAL;
 const CustomDataMask CD_MASK_FACECORNERS =  /* XXX Not used anywhere! */
     CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_NORMAL | CD_MASK_MLOOPTANGENT;
@@ -1245,7 +1273,7 @@ const CustomDataMask CD_MASK_EVERYTHING =
     /* BMESH ONLY END */
     CD_MASK_PAINT_MASK | CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN |
     CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
-    CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL;
+    CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_CUSTOMLOOPNORMAL;
 
 static const LayerTypeInfo *layerType_getInfo(int type)
 {
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 681a540..5d3df07 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -193,17 +193,31 @@ static void emDM_calcLoopNormals(DerivedMesh *dm, const float split_angle)
 	}
 
 	{
-		MLoopsNorSpaces lnors_spaces = {NULL};
-		int i;
+		//MLoopsNorSpaces lnors_spaces = {NULL};
+		//int i;
+		/* XXX All this is really dirty!!! */
 		const int numLoops = dm->getNumLoops(dm);
-		float (*clnor_data)[2] = MEM_mallocN(sizeof(*clnor_data) * (size_t)numLoops, __func__);
-
-		for (i = 0; i < numLoops; i++) {
-			clnor_data[i][0] = 0.7f;
-			clnor_data[i][1] = 0.5f;
+		float (*clnor_data)[2] = NULL;
+		CustomData *ldata = dm->getLoopDataLayout(dm);
+
+		if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
+			float (*clnor)[2] = clnor_data = MEM_mallocN(sizeof(float[2]) * (size_t)numLoops, __func__);
+			BMIter iter;
+			BMFace *efa;
+
+			BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+				BMLoop *l_iter, *l_first;
+				l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
+				do {
+					copy_v2_v2(*clnor, CustomData_bmesh_get(ldata, l_iter->head.data, CD_CUSTOMLOOPNORMAL));
+					++clnor;
+				} while ((l_iter = l_iter->next) != l_first);
+			}
 		}
 
-		BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, split_angle, loopNos, &lnors_spaces, clnor_data);
+		BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, split_angle, loopNos,
+		                          NULL /* &lnors_spaces */, (const float (*)[2])clnor_data);
+#if 0
 		for (i = 0; i < numLoops; i++) {
 			if (lnors_spaces.lspaces[i]->angle != 0.0f) {
 				LinkNode *loops = lnors_spaces.lspaces[i]->loops;
@@ -224,6 +238,9 @@ static void emDM_calcLoopNormals(DerivedMesh *dm, const float split_angle)
 			}
 		}
 		BKE_free_loops_normal_spaces(&lnors_spaces);
+#endif
+
+		MEM_SAFE_FREE(clnor_data);
 	}
 }
 
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/so

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list