Use polygon normals for baking
This commit is contained in:
@@ -64,6 +64,8 @@
|
||||
* For a complete implementation example look at the Cycles Bake commit.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
@@ -364,6 +366,9 @@ static void mesh_calc_tri_tessface(
|
||||
bool calculate_normal;
|
||||
const int tottri = poly_to_tri_count(me->totpoly, me->totloop);
|
||||
MLoopTri *looptri;
|
||||
/* calculate normal for each polygon only once */
|
||||
unsigned int mpoly_prev = UINT_MAX;
|
||||
float no[3];
|
||||
|
||||
mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
|
||||
looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
|
||||
@@ -400,10 +405,12 @@ static void mesh_calc_tri_tessface(
|
||||
triangles[i].tspace[2] = &tspace[lt->tri[2]];
|
||||
|
||||
if (calculate_normal) {
|
||||
normal_tri_v3(triangles[i].normal,
|
||||
triangles[i].mverts[0]->co,
|
||||
triangles[i].mverts[1]->co,
|
||||
triangles[i].mverts[2]->co);
|
||||
if (lt->poly != mpoly_prev) {
|
||||
const MPoly *mp = &me->mpoly[lt->poly];
|
||||
BKE_mesh_calc_poly_normal(mp, &me->mloop[mp->loopstart], me->mvert, no);
|
||||
mpoly_prev = lt->poly;
|
||||
}
|
||||
copy_v3_v3(triangles[i].normal, no);
|
||||
}
|
||||
else {
|
||||
copy_v3_v3(triangles[i].normal, &precomputed_normals[lt->poly]);
|
||||
|
||||
Reference in New Issue
Block a user