diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_solidify_extrude.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_solidify_extrude.c | 57 |
1 files changed, 15 insertions, 42 deletions
diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c index 20d65b9d9f8..fa8d08bf839 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.c +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c @@ -43,20 +43,6 @@ #endif /* -------------------------------------------------------------------- */ -/** \name Local Utilities - * \{ */ - -/* specific function for solidify - define locally */ -BLI_INLINE void madd_v3v3short_fl(float r[3], const short a[3], const float f) -{ - r[0] += (float)a[0] * f; - r[1] += (float)a[1] * f; - r[2] += (float)a[2] * f; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name High Quality Normal Calculation Function * \{ */ @@ -81,20 +67,18 @@ BLI_INLINE bool edgeref_is_init(const EdgeFaceRef *edge_ref) * \param poly_nors: Precalculated face normals. * \param r_vert_nors: Return vert normals. */ -static void mesh_calc_hq_normal(Mesh *mesh, float (*poly_nors)[3], float (*r_vert_nors)[3]) +static void mesh_calc_hq_normal(Mesh *mesh, const float (*poly_nors)[3], float (*r_vert_nors)[3]) { int i, numVerts, numEdges, numPolys; MPoly *mpoly, *mp; MLoop *mloop, *ml; MEdge *medge, *ed; - MVert *mvert, *mv; numVerts = mesh->totvert; numEdges = mesh->totedge; numPolys = mesh->totpoly; mpoly = mesh->mpoly; medge = mesh->medge; - mvert = mesh->mvert; mloop = mesh->mloop; /* we don't want to overwrite any referenced layers */ @@ -105,7 +89,6 @@ static void mesh_calc_hq_normal(Mesh *mesh, float (*poly_nors)[3], float (*r_ver cddm->mvert = mv; #endif - mv = mvert; mp = mpoly; { @@ -171,9 +154,10 @@ static void mesh_calc_hq_normal(Mesh *mesh, float (*poly_nors)[3], float (*r_ver } /* normalize vertex normals and assign */ - for (i = 0; i < numVerts; i++, mv++) { + const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); + for (i = 0; i < numVerts; i++) { if (normalize_v3(r_vert_nors[i]) == 0.0f) { - normal_short_to_float_v3(r_vert_nors[i], mv->no); + copy_v3_v3(r_vert_nors[i], vert_normals[i]); } } } @@ -220,7 +204,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex int *edge_order = NULL; float(*vert_nors)[3] = NULL; - float(*poly_nors)[3] = NULL; + const float(*poly_nors)[3] = NULL; const bool need_poly_normals = (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) || (smd->flag & MOD_SOLIDIFY_EVEN) || @@ -249,6 +233,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* array size is doubled in case of using a shell */ const uint stride = do_shell ? 2 : 1; + const float(*mesh_vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); + MOD_get_vgroup(ctx->object, mesh, smd->defgrp_name, &dvert, &defgrp_index); orig_mvert = mesh->mvert; @@ -258,14 +244,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (need_poly_normals) { /* calculate only face normals */ - poly_nors = MEM_malloc_arrayN(numPolys, sizeof(*poly_nors), __func__); - BKE_mesh_calc_normals_poly(orig_mvert, - (int)numVerts, - orig_mloop, - (int)numLoops, - orig_mpoly, - (int)numPolys, - poly_nors); + poly_nors = BKE_mesh_poly_normals_ensure(mesh); } STACK_INIT(new_vert_arr, numVerts * 2); @@ -636,7 +615,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup); } else { - madd_v3v3short_fl(mv->co, mv->no, ofs_new_vgroup / 32767.0f); + madd_v3_v3fl(mv->co, mesh_vert_normals[i], ofs_new_vgroup); } } } @@ -687,7 +666,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex madd_v3_v3fl(mv->co, vert_nors[i], ofs_new_vgroup); } else { - madd_v3v3short_fl(mv->co, mv->no, ofs_new_vgroup / 32767.0f); + madd_v3_v3fl(mv->co, mesh_vert_normals[i], ofs_new_vgroup); } } } @@ -740,7 +719,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (vert_nors == NULL) { vert_nors = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "mod_solid_vno"); for (i = 0, mv = mvert; i < numVerts; i++, mv++) { - normal_short_to_float_v3(vert_nors[i], mv->no); + copy_v3_v3(vert_nors[i], mesh_vert_normals[i]); } } @@ -995,8 +974,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex uint i; /* flip vertex normals for copied verts */ mv = mvert + numVerts; - for (i = 0; i < numVerts; i++, mv++) { - negate_v3_short(mv->no); + for (i = 0; i < numVerts; i++) { + negate_v3((float *)mesh_vert_normals[i]); } } @@ -1201,7 +1180,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ed = medge + (numEdges * stride); for (i = 0; i < rimVerts; i++, ed++, ed_orig++) { float nor_cpy[3]; - short *nor_short; int k; /* NOTE: only the first vertex (lower half of the index) is calculated. */ @@ -1209,11 +1187,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex normalize_v3_v3(nor_cpy, edge_vert_nos[ed_orig->v1]); for (k = 0; k < 2; k++) { /* loop over both verts of the edge */ - nor_short = mvert[*(&ed->v1 + k)].no; - normal_short_to_float_v3(nor, nor_short); + copy_v3_v3(nor, mesh_vert_normals[*(&ed->v1 + k)]); add_v3_v3(nor, nor_cpy); normalize_v3(nor); - normal_float_to_short_v3(nor_short, nor); + copy_v3_v3((float *)mesh_vert_normals[*(&ed->v1 + k)], nor); } } @@ -1232,10 +1209,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex MEM_freeN(old_vert_arr); } - if (poly_nors) { - MEM_freeN(poly_nors); - } - return result; } |