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
This commit is contained in:
Campbell Barton 2010-04-10 22:12:10 +00:00
parent 9eb838ce24
commit 4d2f5a275d
5 changed files with 64 additions and 8 deletions

View File

@ -456,7 +456,7 @@ void DM_interp_face_data(struct DerivedMesh *source, struct DerivedMesh *dest,
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);

View File

@ -174,7 +174,7 @@ void CustomData_bmesh_interp(struct CustomData *data, void **src_blocks,
/* 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

View File

@ -416,7 +416,7 @@ void DM_interp_face_data(DerivedMesh *source, DerivedMesh *dest,
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);
}

View File

@ -85,7 +85,7 @@ typedef struct LayerTypeInfo {
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 layerInterp_tface(void **sources, float *weights,
}
}
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 layerInterp_origspace_face(void **sources, float *weights,
}
}
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 layerInterp_mcol(void **sources, float *weights,
}
}
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 @@ void CustomData_interp(const CustomData *source, CustomData *dest,
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;

View File

@ -5900,6 +5900,7 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md,
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 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md,
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,7 +6117,36 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md,
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);
@ -6103,6 +6157,8 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md,
return result;
}
#undef SOLIDIFY_SIDE_NORMALS
static DerivedMesh *solidifyModifier_applyModifierEM(ModifierData *md,
Object *ob,
EditMesh *editData,