diff options
author | Darshan Kadu <darsh7807@gmail.com> | 2017-06-23 22:03:33 +0300 |
---|---|---|
committer | Darshan Kadu <darsh7807@gmail.com> | 2017-06-23 22:03:33 +0300 |
commit | 444ad728cd4df291bd19b814f390f6977ee3ddb6 (patch) | |
tree | fdac4a68c0782ac10079d5f71624ffd3bc61d844 | |
parent | 39a2294d38b0e740dbef47b423b78141d5a6d5a0 (diff) |
added non-occluded mode for the weight painting
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d_toolbar.py | 1 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 68 |
2 files changed, 38 insertions, 31 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index c4085e4867d..b54557250fd 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -1759,6 +1759,7 @@ class VIEW3D_PT_tools_weightpaint_options(Panel, View3DPaintPanel): row = col.row() row.prop(wpaint, "use_normal") + row.prop(wpaint, "use_occlude") col = layout.column() row = col.row() row.prop(wpaint, "use_spray") diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 75f7b2745ca..e9384687888 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -2673,6 +2673,19 @@ static void get_brush_alpha_data( (BKE_brush_use_alpha_pressure(scene, brush) ? ss->cache->pressure : 1.0f); } +static bool is_non_occluded(StrokeCache *cache, PBVHVertexIter vd, const float radius, const bool do_occlude) +{ + if (cache->vc->ar && !do_occlude) { + float sco[2]; + ED_view3d_project_float_v2_m4(cache->vc->ar, vd.co, sco, cache->projection_mat); + const float dist_sq = len_squared_v2v2(cache->mouse, sco); + if (dist_sq <= radius*radius) { + return true; + } + } + return false; +} + static void do_wpaint_brush_blur_task_cb_ex( void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id)) { @@ -2688,6 +2701,8 @@ static void do_wpaint_brush_blur_task_cb_ex( get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure); const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; + bool non_occlude; + const float radius = BKE_brush_size_get(scene, brush); SculptBrushTest test; sculpt_brush_test_init(ss, &test); @@ -2696,15 +2711,17 @@ static void do_wpaint_brush_blur_task_cb_ex( PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { + const bool do_occlude = data->vp->flag&VP_OCCLUDE ? 1 : 0; + non_occlude = is_non_occluded(cache, vd, radius, do_occlude); /* Test to see if the vertex coordinates are within the spherical brush region. */ - if (sculpt_brush_test_sq(&test, vd.co)) { + if (sculpt_brush_test_sq(&test, vd.co) || non_occlude) { /* For grid based pbvh, take the vert whose loop coopresponds to the current grid. * Otherwise, take the current vert. */ const int v_index = ccgdm ? data->me->mloop[vd.grid_indices[vd.g]].v : vd.vert_indices[vd.i]; const float grid_alpha = ccgdm ? 1.0f / vd.gridsize : 1.0f; const char v_flag = data->me->mvert[v_index].flag; /* If the vertex is selected */ - if (!(use_face_sel || use_vert_sel) || v_flag & SELECT) { + if (!(use_face_sel || use_vert_sel) || v_flag & SELECT || non_occlude) { /* Get the average poly weight */ int total_hit_loops = 0; float weight_final = 0.0f; @@ -2759,6 +2776,8 @@ static void do_wpaint_brush_smear_task_cb_ex( const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; float brush_dir[3]; + bool non_occlude; + const float radius = BKE_brush_size_get(scene, brush); sub_v3_v3v3(brush_dir, cache->location, cache->last_location); if (normalize_v3(brush_dir) != 0.0f) { @@ -2770,9 +2789,11 @@ static void do_wpaint_brush_smear_task_cb_ex( PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { + const bool do_occlude = data->vp->flag&VP_OCCLUDE ? 1 : 0; + non_occlude = is_non_occluded(cache, vd, radius, do_occlude); /* Test to see if the vertex coordinates are within the spherical brush region. */ - if (sculpt_brush_test_fast(&test, vd.co)) { - const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0; + if (sculpt_brush_test_fast(&test, vd.co) || non_occlude) { + const float view_dot = (vd.no && !non_occlude) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0; if (view_dot > 0.0f) { bool do_color = false; @@ -2784,7 +2805,7 @@ static void do_wpaint_brush_smear_task_cb_ex( const char v_flag = data->me->mvert[v_index].flag; /* If the vertex is selected */ - if (!(use_face_sel || use_vert_sel) || v_flag & SELECT) { + if (!(use_face_sel || use_vert_sel) || v_flag & SELECT || non_occlude) { /* Minimum dot product between brush direction and current * to neighbor direction is 0.0, meaning orthogonal. */ float stroke_dot_max = 0.0f; @@ -2851,6 +2872,8 @@ static void do_wpaint_brush_draw_task_cb_ex( get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure); const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; + bool non_occlude; + const float radius = BKE_brush_size_get(scene, brush); SculptBrushTest test; sculpt_brush_test_init(ss, &test); @@ -2859,8 +2882,10 @@ static void do_wpaint_brush_draw_task_cb_ex( PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { + const bool do_occlude = data->vp->flag&VP_OCCLUDE ? 1 : 0; + non_occlude = is_non_occluded(cache, vd, radius, do_occlude); /* Test to see if the vertex coordinates are within the spherical brush region. */ - if (sculpt_brush_test_sq(&test, vd.co)) { + if (sculpt_brush_test_sq(&test, vd.co) || non_occlude) { /* Note: grids are 1:1 with corners (aka loops). * For multires, take the vert whose loop cooresponds to the current grid. * Otherwise, take the current vert. */ @@ -2869,8 +2894,8 @@ static void do_wpaint_brush_draw_task_cb_ex( const char v_flag = data->me->mvert[v_index].flag; /* If the vertex is selected */ - if (!(use_face_sel || use_vert_sel) || v_flag & SELECT) { - const float view_dot = (vd.no) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0; + if (!(use_face_sel || use_vert_sel) || v_flag & SELECT || non_occlude) { + const float view_dot = (vd.no && !non_occlude) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0; if (view_dot > 0.0f) { const float brush_fade = BKE_brush_curve_strength(brush, sqrtf(test.dist), cache->radius); float final_alpha = view_dot * brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; @@ -3617,21 +3642,6 @@ static void handle_texture_brush( rgb_float_to_uchar((unsigned char *)r_color, rgba_br); } -static bool is_non_occluded(StrokeCache *cache, PBVHVertexIter vd, - float *dist, const float radius, const bool do_occlude) -{ - if (cache->vc->ar && !do_occlude) { - float sco[2]; - ED_view3d_project_float_v2_m4(cache->vc->ar, vd.co, sco, cache->projection_mat); - const float dist_sq = len_squared_v2v2(cache->mouse, sco); - *dist = sqrtf(dist_sq); - if (dist_sq <= radius*radius) { - return true; - } - } - return false; -} - static void do_vpaint_brush_draw_task_cb_ex( void *userdata, void *UNUSED(userdata_chunk), const int n, const int UNUSED(thread_id)) { @@ -3648,7 +3658,6 @@ static void do_vpaint_brush_draw_task_cb_ex( get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure); const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; - float dist; bool non_occlude; const float radius = BKE_brush_size_get(scene, brush); @@ -3660,7 +3669,7 @@ static void do_vpaint_brush_draw_task_cb_ex( BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { const bool do_occlude = data->vp->flag&VP_OCCLUDE ? 1 : 0; - non_occlude = is_non_occluded(cache, vd, &dist, radius, do_occlude); + non_occlude = is_non_occluded(cache, vd, radius, do_occlude); /* Test to see if the vertex coordinates are within the spherical brush region or * occluded vertex for non-occluded mode. */ if (sculpt_brush_test(&test, vd.co) || non_occlude) { @@ -3678,9 +3687,8 @@ static void do_vpaint_brush_draw_task_cb_ex( * (ie splash prevention factor), and only paint front facing verts. */ float view_dot = (vd.no && !non_occlude) ? dot_vf3vs3(cache->sculpt_normal_symm, vd.no) : 1.0; if (view_dot > 0.0f) { - const float brush_fade = BKE_brush_curve_strength(brush, dist, radius); + const float brush_fade = BKE_brush_curve_strength(brush, test.dist, radius); unsigned int color_final = data->vpd->paintcol; - dist = non_occlude ? dist : test.dist; /* If we're painting with a texture, sample the texture color and alpha. */ float tex_alpha = 1.0; @@ -3742,7 +3750,6 @@ static void do_vpaint_brush_blur_task_cb_ex( get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure); const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; - float dist; bool non_occlude; const float radius = BKE_brush_size_get(scene, brush); @@ -3754,7 +3761,7 @@ static void do_vpaint_brush_blur_task_cb_ex( BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { const bool do_occlude = data->vp->flag&VP_OCCLUDE ? 1 : 0; - non_occlude = is_non_occluded(cache, vd, &dist, radius, do_occlude); + non_occlude = is_non_occluded(cache, vd, radius, do_occlude); /* Test to see if the vertex coordinates are within the spherical brush region or * occluded vertex for non-occluded mode. */ if (sculpt_brush_test(&test, vd.co) || non_occlude) { @@ -3846,7 +3853,6 @@ static void do_vpaint_brush_smear_task_cb_ex( float brush_dir[3]; const bool use_face_sel = (data->me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (data->me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; - float dist; bool non_occlude; const float radius = BKE_brush_size_get(scene, brush); @@ -3861,7 +3867,7 @@ static void do_vpaint_brush_smear_task_cb_ex( BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { const bool do_occlude = data->vp->flag&VP_OCCLUDE ? 1 : 0; - non_occlude = is_non_occluded(cache, vd, &dist, radius, do_occlude); + non_occlude = is_non_occluded(cache, vd, radius, do_occlude); /* Test to see if the vertex coordinates are within the spherical brush region or * occluded vertex for non-occluded mode. */ if (sculpt_brush_test(&test, vd.co) || non_occlude) { |