diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-04-11 02:12:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-04-11 02:12:10 +0400 |
commit | 4d2f5a275d402bd732bd52887d7aed5fce7276c4 (patch) | |
tree | abfef56567ad03bc1d1f8e06136450d7faa2de35 /source/blender | |
parent | 9eb838ce24e28b0f21cff014b8f5f83a4d501b29 (diff) |
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
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_customdata.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 56 |
5 files changed, 64 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 965bad31991..33852a1b923 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -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); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index c07b26fd372..7ca6bbe67a7 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -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 diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index f4e3a60803e..44757a09d42 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -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); } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 0afb9a450dd..71be2ce7b78 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -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; diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 7ec41aef323..c8f98bbac56 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -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,8 +6117,37 @@ 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); MEM_freeN(edge_users); @@ -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, |