[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28117] trunk/blender/source/blender/ blenkernel: Solidify Modifier

Campbell Barton ideasman42 at gmail.com
Sun Apr 11 00:12:10 CEST 2010


Revision: 28117
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28117
Author:   campbellbarton
Date:     2010-04-11 00:12:10 +0200 (Sun, 11 Apr 2010)

Log Message:
-----------
Solidify Modifier
- vertex normals were not being flipped (though faces are)
- rim faces didnt influence edge vertex normals

apply solidify on top of solidify modifier now works correctly

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h
    trunk/blender/source/blender/blenkernel/BKE_customdata.h
    trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
    trunk/blender/source/blender/blenkernel/intern/customdata.c
    trunk/blender/source/blender/blenkernel/intern/modifier.c

Modified: trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h	2010-04-10 19:06:18 UTC (rev 28116)
+++ trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h	2010-04-10 22:12:10 UTC (rev 28117)
@@ -456,7 +456,7 @@
 						 float *weights, FaceVertWeight *vert_weights,
 						 int count, int dest_index);
 
-void DM_swap_face_data(struct DerivedMesh *dm, int index, int *corner_indices);
+void DM_swap_face_data(struct DerivedMesh *dm, int index, const int *corner_indices);
 
 /* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
 void vDM_ColorBand_store(struct ColorBand *coba);

Modified: trunk/blender/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_customdata.h	2010-04-10 19:06:18 UTC (rev 28116)
+++ trunk/blender/source/blender/blenkernel/BKE_customdata.h	2010-04-10 22:12:10 UTC (rev 28117)
@@ -174,7 +174,7 @@
 /* swaps the data in the element corners, to new corners with indices as
    specified in corner_indices. for edges this is an array of length 2, for
    faces an array of length 4 */
-void CustomData_swap(struct CustomData *data, int index, int *corner_indices);
+void CustomData_swap(struct CustomData *data, int index, const int *corner_indices);
 
 /* gets a pointer to the data element at index from the first layer of type
  * returns NULL if there is no layer of type

Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c	2010-04-10 19:06:18 UTC (rev 28116)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c	2010-04-10 22:12:10 UTC (rev 28117)
@@ -416,7 +416,7 @@
 					  weights, (float*)vert_weights, count, dest_index);
 }
 
-void DM_swap_face_data(DerivedMesh *dm, int index, int *corner_indices)
+void DM_swap_face_data(DerivedMesh *dm, int index, const int *corner_indices)
 {
 	CustomData_swap(&dm->faceData, index, corner_indices);
 }

Modified: trunk/blender/source/blender/blenkernel/intern/customdata.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/customdata.c	2010-04-10 19:06:18 UTC (rev 28116)
+++ trunk/blender/source/blender/blenkernel/intern/customdata.c	2010-04-10 22:12:10 UTC (rev 28117)
@@ -85,7 +85,7 @@
 				   int count, void *dest);
 
 	/* a function to swap the data in corners of the element */
-	void (*swap)(void *data, int *corner_indices);
+	void (*swap)(void *data, const int *corner_indices);
 
 	/* a function to set a layer's data to default values. if NULL, the
 	   default is assumed to be all zeros */
@@ -273,7 +273,7 @@
 	}
 }
 
-static void layerSwap_tface(void *data, int *corner_indices)
+static void layerSwap_tface(void *data, const int *corner_indices)
 {
 	MTFace *tf = data;
 	float uv[4][2];
@@ -368,7 +368,7 @@
 	}
 }
 
-static void layerSwap_origspace_face(void *data, int *corner_indices)
+static void layerSwap_origspace_face(void *data, const int *corner_indices)
 {
 	OrigSpaceFace *osf = data;
 	float uv[4][2];
@@ -735,7 +735,7 @@
 	}
 }
 
-static void layerSwap_mcol(void *data, int *corner_indices)
+static void layerSwap_mcol(void *data, const int *corner_indices)
 {
 	MCol *mcol = data;
 	MCol col[4];
@@ -1533,7 +1533,7 @@
 	if(count > SOURCE_BUF_SIZE) MEM_freeN(sources);
 }
 
-void CustomData_swap(struct CustomData *data, int index, int *corner_indices)
+void CustomData_swap(struct CustomData *data, int index, const int *corner_indices)
 {
 	const LayerTypeInfo *typeInfo;
 	int i;

Modified: trunk/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/modifier.c	2010-04-10 19:06:18 UTC (rev 28116)
+++ trunk/blender/source/blender/blenkernel/intern/modifier.c	2010-04-10 22:12:10 UTC (rev 28117)
@@ -5900,6 +5900,7 @@
 		ed->v2 += numVerts;
 	}
 
+	/* note, copied vertex layers dont have flipped normals yet. do this after applying offset */
 	if((smd->flag & MOD_SOLIDIFY_EVEN) == 0) {
 		/* no even thickness, very simple */
 		float scalar_short;
@@ -6026,8 +6027,32 @@
 	if(vert_nors)
 		MEM_freeN(vert_nors);
 
+	/* flip vertex normals for copied verts */
+	mv= mvert + numVerts;
+	for(i=0; i<numVerts; i++, mv++) {
+		mv->no[0]= -mv->no[0];
+		mv->no[1]= -mv->no[1];
+		mv->no[2]= -mv->no[2];
+	}
+
 	if(smd->flag & MOD_SOLIDIFY_RIM) {
 
+		
+		/* bugger, need to re-calculate the normals for the new edge faces.
+		 * This could be done in many ways, but probably the quickest way is to calculate the average normals for side faces only.
+		 * Then blend them with the normals of the edge verts.
+		 * 
+		 * at the moment its easiest to allocate an entire array for every vertex, even though we only need edge verts - campbell
+		 */
+		
+#define SOLIDIFY_SIDE_NORMALS
+
+#ifdef SOLIDIFY_SIDE_NORMALS
+		/* annoying to allocate these since we only need the edge verts, */
+		float (*edge_vert_nos)[3]= MEM_callocN(sizeof(float) * numVerts * 3, "solidify_edge_nos");
+		float nor[3];
+#endif
+
 		const unsigned char crease_rim= smd->crease_rim * 255.0f;
 		const unsigned char crease_outer= smd->crease_outer * 255.0f;
 		const unsigned char crease_inner= smd->crease_inner * 255.0f;
@@ -6092,8 +6117,37 @@
 			if(crease_inner) {
 				medge[numEdges + eidx].crease= crease_inner;
 			}
+			
+#ifdef SOLIDIFY_SIDE_NORMALS
+			normal_quad_v3(nor, mvert[mf->v1].co, mvert[mf->v2].co, mvert[mf->v3].co, mvert[mf->v4].co);
+
+			add_v3_v3(edge_vert_nos[ed->v1], nor);
+			add_v3_v3(edge_vert_nos[ed->v2], nor);
+#endif
 		}
+		
+#ifdef SOLIDIFY_SIDE_NORMALS
+		ed= medge + (numEdges * 2);
+		for(i=0; i<newEdges; i++, ed++) {
+			float nor_cpy[3];
+			short *nor_short;
+			int j;
+			
+			/* note, only the first vertex (lower half of the index) is calculated */
+			normalize_v3_v3(nor_cpy, edge_vert_nos[ed->v1]);
+			
+			for(j=0; j<2; j++) { /* loop over both verts of the edge */
+				nor_short= mvert[*(&ed->v1 + j)].no;
+				normal_short_to_float_v3(nor, nor_short);
+				add_v3_v3(nor, nor_cpy);
+				normalize_v3(nor);
+				normal_float_to_short_v3(nor_short, nor);
+			}
+		}
 
+		MEM_freeN(edge_vert_nos);
+#endif
+
 		MEM_freeN(new_vert_arr);
 		MEM_freeN(new_edge_arr);
 		MEM_freeN(edge_users);
@@ -6103,6 +6157,8 @@
 	return result;
 }
 
+#undef SOLIDIFY_SIDE_NORMALS
+
 static DerivedMesh *solidifyModifier_applyModifierEM(ModifierData *md,
 							 Object *ob,
 							 EditMesh *editData,





More information about the Bf-blender-cvs mailing list