diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-08-09 04:05:25 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-08-09 04:05:25 +0300 |
commit | a9f6b272816b805aa88a232e6535ef22e24f807e (patch) | |
tree | 80871e0924ee58d9cab5c6340653676a5676eaa9 /source | |
parent | e229d66e99f8b3ae3f40bb34320507ec1be70f42 (diff) |
Use polygon normals for baking
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/render/intern/source/bake_api.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c index 5e982e84f6d..636c4db6ef3 100644 --- a/source/blender/render/intern/source/bake_api.c +++ b/source/blender/render/intern/source/bake_api.c @@ -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]); |