Commit: b0c2fdd927d1478ca76a312442f0c452a704607f
Author: Campbell Barton
Date:   Sat Apr 18 03:09:16 2015 +1000
Branches: master
https://developer.blender.org/rBb0c2fdd927d1478ca76a312442f0c452a704607f

Cleanup: simplify sculpt normal accumulation

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

M       source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index 4363757..63b95aa 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2156,73 +2156,59 @@ static void calc_flatten_center(Sculpt *sd, Object *ob, 
PBVHNode **nodes, int to
                PBVHVertexIter vd;
                SculptBrushTest test;
                SculptUndoNode *unode;
-               float private_fc[3] = {0.0f, 0.0f, 0.0f};
-               float private_fc_flip[3] = {0.0f, 0.0f, 0.0f};
-               int private_count = 0;
-               int private_count_flip = 0;
+               /* 0=towards view, 1=flipped */
+               float private_co[2][3] = {{0.0f}};
+               int  private_count[2] = {0, 0};
+               bool use_original;
 
                unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS);
                sculpt_brush_test_init(ss, &test);
 
-               if (ss->cache->original && unode->co) {
-                       BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, 
PBVH_ITER_UNIQUE)
-                       {
-                               if (sculpt_brush_test_fast(&test, 
unode->co[vd.i])) {
-                                       float fno[3];
+               use_original = (ss->cache->original && unode->co);
 
-                                       normal_short_to_float_v3(fno, 
unode->no[vd.i]);
-                                       if (dot_v3v3(ss->cache->view_normal, 
fno) > 0) {
-                                               add_v3_v3(private_fc, 
unode->co[vd.i]);
-                                               private_count++;
-                                       }
-                                       else {
-                                               add_v3_v3(private_fc_flip, 
unode->co[vd.i]);
-                                               private_count_flip++;
-                                       }
-                               }
+               BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, 
PBVH_ITER_UNIQUE)
+               {
+                       const float *co;
+
+                       if (use_original) {
+                               co = unode->co[vd.i];
+                       }
+                       else {
+                               co = vd.co;
                        }
-                       BKE_pbvh_vertex_iter_end;
-               }
-               else {
-                       BKE_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, 
PBVH_ITER_UNIQUE)
-                       {
-                               if (sculpt_brush_test_fast(&test, vd.co)) {
-                                       /* for area normal */
-                                       if (vd.no) {
-                                               float fno[3];
 
-                                               normal_short_to_float_v3(fno, 
vd.no);
+                       if (sculpt_brush_test_fast(&test, co)) {
+                               float no_buf[3];
+                               const float *no;
+                               int flip_index;
 
-                                               if 
(dot_v3v3(ss->cache->view_normal, fno) > 0) {
-                                                       add_v3_v3(private_fc, 
vd.co);
-                                                       private_count++;
-                                               }
-                                               else {
-                                                       
add_v3_v3(private_fc_flip, vd.co);
-                                                       private_count_flip++;
-                                               }
+                               if (use_original) {
+                                       normal_short_to_float_v3(no_buf, 
unode->no[vd.i]);
+                                       no = no_buf;
+                               }
+                               else {
+                                       if (vd.no) {
+                                               
normal_short_to_float_v3(no_buf, vd.no);
+                                               no = no_buf;
                                        }
                                        else {
-                                               if 
(dot_v3v3(ss->cache->view_normal, vd.fno) > 0) {
-                                                       add_v3_v3(private_fc, 
vd.co);
-                                                       private_count++;
-                                               }
-                                               else {
-                                                       
add_v3_v3(private_fc_flip, vd.co);
-                                                       private_count_flip++;
-                                               }
+                                               no = vd.fno;
                                        }
                                }
+
+                               flip_index = (dot_v3v3(ss->cache->view_normal, 
no) <= 0.0f);
+                               add_v3_v3(private_co[flip_index], co);
+                               private_count[flip_index] += 1;
                        }
                        BKE_pbvh_vertex_iter_end;
                }
 
 #pragma omp critical
                {
-                       add_v3_v3(fc, private_fc);
-                       add_v3_v3(fc_flip, private_fc_flip);
-                       count += private_count;
-                       count_flip += private_count_flip;
+                       add_v3_v3(fc,      private_co[0]);
+                       add_v3_v3(fc_flip, private_co[1]);
+                       count      += private_count[0];
+                       count_flip += private_count[1];
                }
        }
        if (count != 0)

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

Reply via email to