Fix T70561: bad custom normals in mirrored geometry.

Original code from rB1a9e698099b5 used a rather naive approach, now use
proper transpose of inverse of geometry transform for the normals.
This commit is contained in:
Bastien Montagne 2019-10-08 20:16:07 +02:00
parent d98ae27f02
commit 47b95a2957
Notes: blender-bot 2023-02-14 00:57:33 +01:00
Referenced by issue #70561, black render of mirrored object - cycles
1 changed files with 7 additions and 1 deletions

View File

@ -321,6 +321,12 @@ Mesh *BKE_mirror_apply_mirror_on_axis(MirrorModifierData *mmd,
MLoopNorSpaceArray lnors_spacearr = {NULL};
float(*poly_normals)[3] = MEM_mallocN(sizeof(*poly_normals) * totpoly, __func__);
/* The transform matrix of a normal must be
* the transpose of inverse of transform matrix of the geometry... */
float mtx_nor[4][4];
invert_m4_m4(mtx_nor, mtx);
transpose_m4(mtx_nor);
/* calculate custom normals into loop_normals, then mirror first half into second half */
BKE_mesh_calc_normals_poly(result->mvert,
@ -361,7 +367,7 @@ Mesh *BKE_mirror_apply_mirror_on_axis(MirrorModifierData *mmd,
mirrorj += mpmirror->totloop - (j - mp->loopstart);
}
copy_v3_v3(loop_normals[mirrorj], loop_normals[j]);
loop_normals[mirrorj][axis] = -loop_normals[j][axis];
mul_m4_v3(mtx_nor, loop_normals[mirrorj]);
BKE_lnor_space_custom_normal_to_data(
lnors_spacearr.lspacearr[mirrorj], loop_normals[mirrorj], clnors[mirrorj]);
}