Revision: 30234 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30234 Author: jwilkins Date: 2010-07-12 19:25:48 +0200 (Mon, 12 Jul 2010)
Log Message: ----------- * bug fix: clay tubes wasn't working when 'use_original_normal' was enabled * renamed 'calc_area_normal' to 'calc_sculpt_normal' and 'calc_area_normal_and_flatten_center' to 'calc_sculpt_plane' * factored out the code for calculating area normal and flatten center to functions and gave them the old names Modified Paths: -------------- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c =================================================================== --- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c 2010-07-12 16:24:43 UTC (rev 30233) +++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c 2010-07-12 17:25:48 UTC (rev 30234) @@ -918,9 +918,69 @@ } } +static void calc_area_normal(Sculpt *sd, SculptSession *ss, float an[3], PBVHNode **nodes, int totnode) +{ + int n; + + float out_flip[3] = {0.0f, 0.0f, 0.0f}; + + zero_v3(an); + + #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) + for(n=0; n<totnode; n++) { + PBVHVertexIter vd; + SculptBrushTest test; + SculptUndoNode *unode; + float private_an[3] = {0.0f, 0.0f, 0.0f}; + float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; + + unode = sculpt_undo_push_node(ss, nodes[n]); + sculpt_brush_test_init(ss, &test); + + if(ss->cache->original) { + BLI_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]; + + normal_short_to_float_v3(fno, unode->no[vd.i]); + add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); + } + } + BLI_pbvh_vertex_iter_end; + } + else { + BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { + if(sculpt_brush_test_fast(&test, vd.co)) { + if(vd.no) { + float fno[3]; + + normal_short_to_float_v3(fno, vd.no); + add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); + } + else { + add_norm_if(ss->cache->view_normal, private_an, private_out_flip, vd.fno); + } + } + } + BLI_pbvh_vertex_iter_end; + } + + #pragma omp critical + { + add_v3_v3(an, private_an); + add_v3_v3(out_flip, private_out_flip); + } + } + + if (is_zero_v3(an)) + copy_v3_v3(an, out_flip); + + normalize_v3(an); +} + /* This initializes the faces to be moved for this sculpt for draw/layer/flatten; then it finds average normal for all active vertices - note that this is called once for each mirroring direction */ -static void calc_area_normal(Sculpt *sd, SculptSession *ss, float an[3], PBVHNode **nodes, int totnode) +static void calc_sculpt_normal(Sculpt *sd, SculptSession *ss, float an[3], PBVHNode **nodes, int totnode) { Brush *brush = paint_brush(&sd->paint); @@ -952,67 +1012,8 @@ break; case SCULPT_DISP_DIR_AREA: - /* this calculates flatten center and area normal together, - amortizing the memory bandwidth and loop overhead to calculate both at the same time */ - { - int n; + calc_area_normal(sd, ss, an, nodes, totnode); - float out_flip[3] = {0.0f, 0.0f, 0.0f}; - - zero_v3(an); - - #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) - for(n=0; n<totnode; n++) { - PBVHVertexIter vd; - SculptBrushTest test; - SculptUndoNode *unode; - float private_an[3] = {0.0f, 0.0f, 0.0f}; - float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; - - unode = sculpt_undo_push_node(ss, nodes[n]); - sculpt_brush_test_init(ss, &test); - - if(ss->cache->original) { - BLI_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]; - - normal_short_to_float_v3(fno, unode->no[vd.i]); - add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); - } - } - BLI_pbvh_vertex_iter_end; - } - else { - BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { - if(sculpt_brush_test_fast(&test, vd.co)) { - if(vd.no) { - float fno[3]; - - normal_short_to_float_v3(fno, vd.no); - add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); - } - else { - add_norm_if(ss->cache->view_normal, private_an, private_out_flip, vd.fno); - } - } - } - BLI_pbvh_vertex_iter_end; - } - - #pragma omp critical - { - add_v3_v3(an, private_an); - add_v3_v3(out_flip, private_out_flip); - } - } - - if (is_zero_v3(an)) - copy_v3_v3(an, out_flip); - - normalize_v3(an); - } - default: break; } @@ -1247,7 +1248,7 @@ float bstrength= ss->cache->bstrength; int n; - calc_area_normal(sd, ss, area_normal, nodes, totnode); + calc_sculpt_normal(sd, ss, area_normal, nodes, totnode); /* offset with as much as possible factored in already */ mul_v3_v3fl(offset, area_normal, ss->cache->radius); @@ -1290,7 +1291,7 @@ float flippedbstrength, crease_correction; int n; - calc_area_normal(sd, ss, area_normal, nodes, totnode); + calc_sculpt_normal(sd, ss, area_normal, nodes, totnode); /* offset with as much as possible factored in already */ mul_v3_v3fl(offset, area_normal, ss->cache->radius); @@ -1388,7 +1389,7 @@ float len; if (brush->normal_weight > 0) - calc_area_normal(sd, ss, an, nodes, totnode); + calc_sculpt_normal(sd, ss, an, nodes, totnode); copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); @@ -1438,7 +1439,7 @@ copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); - calc_area_normal(sd, ss, an, nodes, totnode); + calc_sculpt_normal(sd, ss, an, nodes, totnode); cross_v3_v3v3(tmp, an, grab_delta); cross_v3_v3v3(cono, tmp, an); @@ -1476,7 +1477,7 @@ float len; if (brush->normal_weight > 0) - calc_area_normal(sd, ss, an, nodes, totnode); + calc_sculpt_normal(sd, ss, an, nodes, totnode); copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); @@ -1526,7 +1527,7 @@ copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); - calc_area_normal(sd, ss, an, nodes, totnode); + calc_sculpt_normal(sd, ss, an, nodes, totnode); cross_v3_v3v3(tmp, an, grab_delta); cross_v3_v3v3(cono, tmp, an); @@ -1568,7 +1569,7 @@ static const int flip[8] = { 1, -1, -1, 1, -1, 1, 1, -1 }; float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmetry_pass]; - calc_area_normal(sd, ss, an, nodes, totnode); + calc_sculpt_normal(sd, ss, an, nodes, totnode); axis_angle_to_mat3(m, an, angle); @@ -1612,7 +1613,7 @@ if(bstrength < 0) lim = -lim; - calc_area_normal(sd, ss, area_normal, nodes, totnode); + calc_sculpt_normal(sd, ss, area_normal, nodes, totnode); mul_v3_v3v3(offset, ss->cache->scale, area_normal); @@ -1755,8 +1756,99 @@ mul_v3_fl(fc, 1.0f / count); } +/* this calculates flatten center and area normal together, +amortizing the memory bandwidth and loop overhead to calculate both at the same time */ static void calc_area_normal_and_flatten_center(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode, float an[3], float fc[3]) { + int n; + + // an + float out_flip[3] = {0.0f, 0.0f, 0.0f}; + + // fc + float count = 0; + + // an + zero_v3(an); + + // fc + zero_v3(fc); + + #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) + for(n=0; n<totnode; n++) { + PBVHVertexIter vd; + SculptBrushTest test; + SculptUndoNode *unode; + float private_an[3] = {0.0f, 0.0f, 0.0f}; + float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; + float private_fc[3] = {0.0f, 0.0f, 0.0f}; + int private_count = 0; + + unode = sculpt_undo_push_node(ss, nodes[n]); + sculpt_brush_test_init(ss, &test); + + if(ss->cache->original) { + BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { + if(sculpt_brush_test_fast(&test, unode->co[vd.i])) { + // an + float fno[3]; + + normal_short_to_float_v3(fno, unode->no[vd.i]); + add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); + + // fc + add_v3_v3(private_fc, vd.co); + private_count++; + } + } + BLI_pbvh_vertex_iter_end; + } + else { + BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { + if(sculpt_brush_test_fast(&test, vd.co)) { + // an + if(vd.no) { + float fno[3]; + + normal_short_to_float_v3(fno, vd.no); + add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); + } + else { + add_norm_if(ss->cache->view_normal, private_an, private_out_flip, vd.fno); + } + + // fc + add_v3_v3(private_fc, vd.co); + private_count++; + } + } + BLI_pbvh_vertex_iter_end; + } + + #pragma omp critical + { + // an + add_v3_v3(an, private_an); + add_v3_v3(out_flip, private_out_flip); + + // fc + add_v3_v3(fc, private_fc); + count += private_count; + } + } + + // an + if (is_zero_v3(an)) + copy_v3_v3(an, out_flip); + + normalize_v3(an); + + // fc + mul_v3_fl(fc, 1.0f / count); +} + +static void calc_sculpt_plane(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode, float an[3], float fc[3]) +{ Brush *brush = paint_brush(&sd->paint); if (ss->cache->mirror_symmetry_pass == 0 && @@ -1787,96 +1879,8 @@ break; case SCULPT_DISP_DIR_AREA: - /* this calculates flatten center and area normal together, - amortizing the memory bandwidth and loop overhead to calculate both at the same time */ - { - int n; + calc_area_normal_and_flatten_center(sd, ss, nodes, totnode, an, fc); - // an - float out_flip[3] = {0.0f, 0.0f, 0.0f}; - - // fc - float count = 0; - - // an - zero_v3(an); - - // fc - zero_v3(fc); - - #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) - for(n=0; n<totnode; n++) { - PBVHVertexIter vd; - SculptBrushTest test; - SculptUndoNode *unode; - float private_an[3] = {0.0f, 0.0f, 0.0f}; - float private_out_flip[3] = {0.0f, 0.0f, 0.0f}; - float private_fc[3] = {0.0f, 0.0f, 0.0f}; - int private_count = 0; - - unode = sculpt_undo_push_node(ss, nodes[n]); - sculpt_brush_test_init(ss, &test); - - if(ss->cache->original) { - BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { - if(sculpt_brush_test_fast(&test, unode->co[vd.i])) { - // an - float fno[3]; - - normal_short_to_float_v3(fno, unode->no[vd.i]); - add_norm_if(ss->cache->view_normal, private_an, private_out_flip, fno); - - // fc - add_v3_v3(private_fc, vd.co); - private_count++; - } - } - BLI_pbvh_vertex_iter_end; - } - else { - BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { - if(sculpt_brush_test_fast(&test, vd.co)) { - // an @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs