Commit: 934067619c96509732eee6f1ff65eb0d13b78892
Author: Campbell Barton
Date:   Fri Jul 17 00:46:41 2015 +1000
Branches: temp-derivedmesh-looptri
https://developer.blender.org/rB934067619c96509732eee6f1ff65eb0d13b78892

Refactor cdDM_buffer_copy_normal to avoid array allocation

===================================================================

M       source/blender/blenkernel/intern/cdderivedmesh.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c 
b/source/blender/blenkernel/intern/cdderivedmesh.c
index ae8308f..a26aa36 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -38,7 +38,6 @@
 #include "BLI_edgehash.h"
 #include "BLI_utildefines.h"
 #include "BLI_stackdefines.h"
-#include "BLI_array.h"
 
 #include "BKE_pbvh.h"
 #include "BKE_cdderivedmesh.h"
@@ -1286,20 +1285,13 @@ static void cdDM_buffer_copy_normal(
        int i, j, totpoly;
        int start;
 
-       const float **v_coords = NULL;
-       BLI_array_staticdeclare(v_coords, BM_DEFAULT_NGON_STACK_SIZE);
-
        const float (*nors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
        const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
 
-       const bool normal_loop_face = (nors || lnors) != 0;
-
        const MVert *mvert;
        const MPoly *mpoly;
        const MLoop *mloop;
 
-       short f_no_s[3];
-
        mvert = dm->getVertArray(dm);
        mpoly = dm->getPolyArray(dm);
        mloop = dm->getLoopArray(dm);
@@ -1309,44 +1301,36 @@ static void cdDM_buffer_copy_normal(
        for (i = 0; i < totpoly; i++, mpoly++) {
                const bool smoothnormal = (mpoly->flag & ME_SMOOTH) != 0;
 
-               /* if needed calculate the face normal now */
-               if (!(normal_loop_face || smoothnormal)) {
-                       /* calculate face normal */
-                       float f_no[3];
-
-                       for (j = 0; j < mpoly->totloop; j++)
-                               BLI_array_append(v_coords, 
mvert[mloop[mpoly->loopstart + j].v].co);
-                       normal_poly_v3(f_no, (const float (*)[3]) v_coords, 
mpoly->totloop);
-
-                       normal_float_to_short_v3(f_no_s, f_no);
-                       BLI_array_empty(v_coords);
-               }
-
-               for (j = 0; j < mpoly->totloop; j++) {
-                       if (lnors) {
-                               /* Copy loop normals */
+               if (lnors) {
+                       /* Copy loop normals */
+                       for (j = 0; j < mpoly->totloop; j++, start += 4) {
                                normal_float_to_short_v3(&varray[start], 
lnors[mpoly->loopstart + j]);
                        }
-                       else if (smoothnormal) {
-                               /* copy vertex normal */
+               }
+               else if (smoothnormal) {
+                       /* Copy vertex normal */
+                       for (j = 0; j < mpoly->totloop; j++, start += 4) {
                                copy_v3_v3_short(&varray[start], 
mvert[mloop[mpoly->loopstart + j].v].no);
                        }
-                       else if (nors) {
-                               /* copy cached face normal */
-                               short f_no_s[3];
+               }
+               else {
+                       /* Copy cached face normal */
+                       short f_no_s[3];
 
+                       if (nors) {
                                normal_float_to_short_v3(f_no_s, nors[i]);
-
-                               copy_v3_v3_short(&varray[start], f_no_s);
                        }
                        else {
+                               float f_no[3];
+                               BKE_mesh_calc_poly_normal(mpoly, 
&mloop[mpoly->loopstart], mvert, f_no);
+                               normal_float_to_short_v3(f_no_s, f_no);
+                       }
+
+                       for (j = 0; j < mpoly->totloop; j++, start += 4) {
                                copy_v3_v3_short(&varray[start], f_no_s);
                        }
-                       start += 4;
                }
        }
-
-       BLI_array_free(v_coords);
 }
 
 static void cdDM_buffer_copy_uv(

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to