Commit: cfdb5b9a8b07bcea1c490e52570eb129c7f3ad43 Author: Bastien Montagne Date: Wed Feb 19 12:22:58 2020 +0100 Branches: master https://developer.blender.org/rBcfdb5b9a8b07bcea1c490e52570eb129c7f3ad43
Fix T73941: Custom normals from normal edit modifier ignored by further modifiers. This commit actually fixes several issues in this modifier, but main one from the report was caused by adding a `CD_NORMAL` layer to loops to store temp real clnors. Unless we plan on modifying the topology itself, this is useless, and would require some additional 'dirty normals' tagging to work properly, so just switched to simpler, cleaner solution of having a local array of computed clnors. =================================================================== M source/blender/modifiers/intern/MOD_normal_edit.c =================================================================== diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c index b57fb7b398a..4e84d9a5ec7 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.c +++ b/source/blender/modifiers/intern/MOD_normal_edit.c @@ -502,7 +502,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, if (mesh->medge == ((Mesh *)ob->data)->medge) { /* We need to duplicate data here, otherwise setting custom normals * (which may also affect sharp edges) could - * modify org mesh, see T43671. */ + * modify original mesh, see T43671. */ BKE_id_copy_ex(NULL, &mesh->id, (ID **)&result, LIB_ID_COPY_LOCALIZE); } else { @@ -527,18 +527,14 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, float(*polynors)[3]; CustomData *ldata = &result->ldata; - if (CustomData_has_layer(ldata, CD_NORMAL)) { - loopnors = CustomData_get_layer(ldata, CD_NORMAL); - } - else { - loopnors = CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, num_loops); - } + loopnors = MEM_malloc_arrayN((size_t)num_loops, sizeof(*loopnors), __func__); /* Compute poly (always needed) and vert normals. */ CustomData *pdata = &result->pdata; polynors = CustomData_get_layer(pdata, CD_NORMAL); if (!polynors) { polynors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, num_polys); + CustomData_set_layer_flag(pdata, CD_NORMAL, CD_FLAG_TEMPORARY); } BKE_mesh_calc_normals_poly(mvert, NULL, @@ -552,6 +548,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, result->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL; + clnors = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL); if (use_current_clnors) { clnors = CustomData_duplicate_referenced_layer(ldata, CD_CUSTOMLOOPNORMAL, num_loops); @@ -572,7 +569,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, NULL); } - if (!clnors) { + if (clnors == NULL) { clnors = CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, num_loops); } @@ -625,6 +622,10 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, num_polys); } + /* Currently Modifier stack assumes there is no poly normal data passed around... */ + CustomData_free_layers(pdata, CD_NORMAL, num_polys); + MEM_freeN(loopnors); + return result; } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs