From 0eee776e454f6b78ffa33b2ed8b19c747d8193ec Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 22 Feb 2018 15:00:42 +0100 Subject: Fix (unreported) meshes changing shading when creating empty clnors data. When you were using autosmooth to generate some custom normals, and created empty custom loop normal data, you would go back to an 'all smooth' shading, cancelling some sharp edges generated by the mesh's smooth threshold. Now we will first tag such edges as sharp, such that shading remains the same. This is not crucial in current master, but it is for clnors editing gsoc branch! --- source/blender/editors/mesh/mesh_data.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source/blender/editors') diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index bd7aaec075b..cfeda36214c 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -903,9 +903,38 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator CustomData *data = GET_CD_DATA(me, ldata); if (me->edit_btmesh) { + /* Tag edges as sharp according to smooth threshold if needed, to preserve autosmooth shading. */ + if (me->flag & ME_AUTOSMOOTH) { + BM_edges_sharp_from_angle_set(me->edit_btmesh->bm, me->smoothresh); + + me->drawflag |= ME_DRAWSHARP; + } + BM_data_layer_add(me->edit_btmesh->bm, data, CD_CUSTOMLOOPNORMAL); } else { + /* Tag edges as sharp according to smooth threshold if needed, to preserve autosmooth shading. */ + if (me->flag & ME_AUTOSMOOTH) { + float (*polynors)[3] = MEM_mallocN(sizeof(*polynors) * (size_t)me->totpoly, __func__); + + BKE_mesh_calc_normals_poly( + me->mvert, NULL, me->totvert, + me->mloop, me->mpoly, + me->totloop, me->totpoly, + polynors, true); + + BKE_edges_sharp_from_angle_set( + me->mvert, me->totvert, + me->medge, me->totedge, + me->mloop, me->totloop, + me->mpoly, polynors, me->totpoly, + me->smoothresh); + + MEM_freeN(polynors); + + me->drawflag |= ME_DRAWSHARP; + } + CustomData_add_layer(data, CD_CUSTOMLOOPNORMAL, CD_DEFAULT, NULL, me->totloop); } -- cgit v1.2.3