diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_cursor.c | 102 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_curve.c | 60 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_hide.c | 42 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 90 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_2d.c | 225 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_proj.c | 276 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_mask.c | 45 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 51 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 102 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_utils.c | 42 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 87 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex_color_ops.c | 9 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 303 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_undo.c | 105 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_uv.c | 24 |
15 files changed, 1042 insertions, 521 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index f69ee66e15c..697622aae96 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -96,12 +96,15 @@ static CursorSnapshot cursor_snap = {0}; /* delete overlay cursor textures to preserve memory and invalidate all overlay flags */ void paint_cursor_delete_textures(void) { - if (primary_snap.overlay_texture) + if (primary_snap.overlay_texture) { glDeleteTextures(1, &primary_snap.overlay_texture); - if (secondary_snap.overlay_texture) + } + if (secondary_snap.overlay_texture) { glDeleteTextures(1, &secondary_snap.overlay_texture); - if (cursor_snap.overlay_texture) + } + if (cursor_snap.overlay_texture) { glDeleteTextures(1, &cursor_snap.overlay_texture); + } memset(&primary_snap, 0, sizeof(TexSnapshot)); memset(&secondary_snap, 0, sizeof(TexSnapshot)); @@ -271,16 +274,19 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima int s = BKE_brush_size_get(vc->scene, br); int r = 1; - for (s >>= 1; s > 0; s >>= 1) + for (s >>= 1; s > 0; s >>= 1) { r++; + } size = (1 << r); - if (size < 256) + if (size < 256) { size = 256; + } - if (size < target->old_size) + if (size < target->old_size) { size = target->old_size; + } } else { size = 512; @@ -296,10 +302,12 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima target->old_size = size; } - if (col) + if (col) { buffer = MEM_mallocN(sizeof(GLubyte) * size * size * 4, "load_tex"); - else + } + else { buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex"); + } pool = BKE_image_pool_new(); @@ -324,14 +332,17 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, size, &data, load_tex_task_cb_ex, &settings); - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } - if (pool) + if (pool) { BKE_image_pool_free(pool); + } - if (!target->overlay_texture) + if (!target->overlay_texture) { glGenTextures(1, &target->overlay_texture); + } } else { size = target->old_size; @@ -352,8 +363,9 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, format, GL_UNSIGNED_BYTE, buffer); } - if (buffer) + if (buffer) { MEM_freeN(buffer); + } target->old_col = col; } @@ -422,16 +434,19 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) s = BKE_brush_size_get(vc->scene, br); r = 1; - for (s >>= 1; s > 0; s >>= 1) + for (s >>= 1; s > 0; s >>= 1) { r++; + } size = (1 << r); - if (size < 256) + if (size < 256) { size = 256; + } - if (size < cursor_snap.size) + if (size < cursor_snap.size) { size = cursor_snap.size; + } if (cursor_snap.size != size) { if (cursor_snap.overlay_texture) { @@ -457,8 +472,9 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, size, &data, load_tex_cursor_task_cb, &settings); - if (!cursor_snap.overlay_texture) + if (!cursor_snap.overlay_texture) { glGenTextures(1, &cursor_snap.overlay_texture); + } } else { size = cursor_snap.size; @@ -475,8 +491,9 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_RED, GL_UNSIGNED_BYTE, buffer); } - if (buffer) + if (buffer) { MEM_freeN(buffer); + } } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -567,8 +584,9 @@ static bool sculpt_get_brush_geometry(bContext *C, *pixel_radius = project_brush_radius( vc, BKE_brush_unprojected_radius_get(scene, brush), location); - if (*pixel_radius == 0) + if (*pixel_radius == 0) { *pixel_radius = BKE_brush_size_get(scene, brush); + } mul_m4_v3(vc->obact->obmat, location); } @@ -665,10 +683,12 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, quad.ymax = brush->mask_stencil_dimension[1]; } GPU_matrix_push(); - if (primary) + if (primary) { GPU_matrix_translate_2fv(brush->stencil_pos); - else + } + else { GPU_matrix_translate_2fv(brush->mask_stencil_pos); + } GPU_matrix_rotate_2d(RAD2DEGF(mtex->rot)); } @@ -787,8 +807,9 @@ static void paint_draw_cursor_overlay( GPU_blend_set_func(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); - if (do_pop) + if (do_pop) { GPU_matrix_pop(); + } } } @@ -814,18 +835,23 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, /* coloured overlay should be drawn separately */ if (col) { - if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY)) + if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY)) { paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, true, true); - if (!(flags & PAINT_OVERLAY_OVERRIDE_SECONDARY)) + } + if (!(flags & PAINT_OVERLAY_OVERRIDE_SECONDARY)) { paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, false, false); - if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) + } + if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) { paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom); + } } else { - if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY) && (mode != PAINT_MODE_WEIGHT)) + if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY) && (mode != PAINT_MODE_WEIGHT)) { paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, false, true); - if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) + } + if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR)) { paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom); + } } GPU_matrix_pop(); @@ -954,7 +980,7 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) draw_rect_point( pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2); - for (j = 0; j < 2; j++) + for (j = 0; j < 2; j++) { BKE_curve_forward_diff_bezier(cp->bez.vec[1][j], cp->bez.vec[2][j], cp_next->bez.vec[0][j], @@ -962,6 +988,7 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) data + j, PAINT_CURVE_NUM_SEGMENTS, sizeof(float[2])); + } float(*v)[2] = (float(*)[2])data; @@ -1010,21 +1037,25 @@ static void paint_cursor_on_hit(UnifiedPaintSettings *ups, /* update the brush's cached 3D radius */ if (!BKE_brush_use_locked_size(vc->scene, brush)) { /* get 2D brush radius */ - if (ups->draw_anchored) + if (ups->draw_anchored) { projected_radius = ups->anchored_size; + } else { - if (brush->flag & BRUSH_ANCHORED) + if (brush->flag & BRUSH_ANCHORED) { projected_radius = 8; - else + } + else { projected_radius = BKE_brush_size_get(vc->scene, brush); + } } /* convert brush radius from 2D to 3D */ unprojected_radius = paint_calc_object_space_radius(vc, location, projected_radius); /* scale 3D brush radius by pressure */ - if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) + if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) { unprojected_radius *= ups->size_pressure_value; + } /* set cached value in either Brush or UnifiedPaintSettings */ BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius); @@ -1053,8 +1084,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) ePaintMode mode = BKE_paintmode_get_active_from_context(C); /* check that brush drawing is enabled */ - if (ommit_cursor_drawing(paint, mode, brush)) + if (ommit_cursor_drawing(paint, mode, brush)) { return; + } /* can't use stroke vc here because this will be called during * mouse over too, not just during a stroke */ @@ -1100,8 +1132,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) /* test if brush is over the mesh */ bool hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups); - if (BKE_brush_use_locked_size(scene, brush)) + if (BKE_brush_use_locked_size(scene, brush)) { BKE_brush_size_set(scene, brush, pixel_radius); + } /* check if brush is subtracting, use different color then */ /* TODO: no way currently to know state of pen flip or @@ -1112,8 +1145,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) } /* only do if brush is over the mesh */ - if (hit) + if (hit) { paint_cursor_on_hit(ups, brush, &vc, location); + } } if (ups->draw_anchored) { diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index bc6e019142a..d9fd194e96f 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -60,13 +60,15 @@ bool paint_curve_poll(bContext *C) RegionView3D *rv3d = CTX_wm_region_view3d(C); SpaceImage *sima; - if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) + if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) { return false; + } sima = CTX_wm_space_image(C); - if (sima && sima->mode != SI_MODE_PAINT) + if (sima && sima->mode != SI_MODE_PAINT) { return false; + } p = BKE_paint_get_active_from_context(C); @@ -95,8 +97,9 @@ static PaintCurvePoint *paintcurve_point_get_closest( if (dist < closest_dist) { closest = pcp; closest_dist = dist; - if (point) + if (point) { *point = SEL_F1; + } } } if (!ignore_pivot) { @@ -105,8 +108,9 @@ static PaintCurvePoint *paintcurve_point_get_closest( if (dist < closest_dist) { closest = pcp; closest_dist = dist; - if (point) + if (point) { *point = SEL_F2; + } } } } @@ -115,8 +119,9 @@ static PaintCurvePoint *paintcurve_point_get_closest( if (dist < closest_dist) { closest = pcp; closest_dist = dist; - if (point) + if (point) { *point = SEL_F3; + } } } } @@ -213,12 +218,14 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) add_index = pc->add_index; if (pc->points) { - if (add_index > 0) + if (add_index > 0) { memcpy(pcp, pc->points, add_index * sizeof(PaintCurvePoint)); - if (add_index < pc->tot_points) + } + if (add_index < pc->tot_points) { memcpy(pcp + add_index + 1, pc->points + add_index, (pc->tot_points - add_index) * sizeof(PaintCurvePoint)); + } MEM_freeN(pc->points); } @@ -332,8 +339,9 @@ static int paintcurve_delete_point_exec(bContext *C, wmOperator *op) int j = 0; int new_tot = pc->tot_points - tot_del; PaintCurvePoint *points_new = NULL; - if (new_tot > 0) + if (new_tot > 0) { points_new = MEM_mallocN(new_tot * sizeof(PaintCurvePoint), "PaintCurvePoint"); + } for (i = 0, pcp = pc->points; i < pc->tot_points; i++, pcp++) { if (!(pcp->bez.f2 & DELETE_TAG)) { @@ -392,8 +400,9 @@ static bool paintcurve_point_select( pc = br->paint_curve; - if (!pc) + if (!pc) { return false; + } ED_paintcurve_undo_push_begin(op->type->name); @@ -429,22 +438,28 @@ static bool paintcurve_point_select( BKE_paint_curve_clamp_endpoint_add_index(pc, pcp - pc->points); if (selflag == SEL_F2) { - if (extend) + if (extend) { pcp->bez.f2 ^= SELECT; - else + } + else { pcp->bez.f2 |= SELECT; + } } else if (selflag == SEL_F1) { - if (extend) + if (extend) { pcp->bez.f1 ^= SELECT; - else + } + else { pcp->bez.f1 |= SELECT; + } } else if (selflag == SEL_F3) { - if (extend) + if (extend) { pcp->bez.f3 ^= SELECT; - else + } + else { pcp->bez.f3 |= SELECT; + } } } @@ -495,8 +510,9 @@ static int paintcurve_select_point_exec(bContext *C, wmOperator *op) bool toggle = RNA_boolean_get(op->ptr, "toggle"); bool extend = RNA_boolean_get(op->ptr, "extend"); RNA_int_get_array(op->ptr, "location", loc); - if (paintcurve_point_select(C, op, loc, toggle, extend)) + if (paintcurve_point_select(C, op, loc, toggle, extend)) { return OPERATOR_FINISHED; + } } return OPERATOR_CANCELLED; @@ -557,8 +573,9 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e PaintCurve *pc = br->paint_curve; PaintCurvePoint *pcp; - if (!pc) + if (!pc) { return OPERATOR_PASS_THROUGH; + } if (do_select) { pcp = paintcurve_point_get_closest(pc, loc_fl, align, PAINT_CURVE_SELECT_THRESHOLD, &select); @@ -589,8 +606,9 @@ static int paintcurve_slide_invoke(bContext *C, wmOperator *op, const wmEvent *e op->customdata = psd; /* first, clear all selection from points */ - for (i = 0; i < pc->tot_points; i++) + for (i = 0; i < pc->tot_points; i++) { pc->points[i].bez.f1 = pc->points[i].bez.f3 = pc->points[i].bez.f2 = 0; + } /* only select the active point */ PAINT_CURVE_POINT_SELECT(pcp, psd->select); @@ -622,8 +640,9 @@ static int paintcurve_slide_modal(bContext *C, wmOperator *op, const wmEvent *ev float diff[2] = {event->mval[0] - psd->initial_loc[0], event->mval[1] - psd->initial_loc[1]}; if (psd->select == 1) { int i; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { add_v2_v2v2(psd->pcp->bez.vec[i], diff, psd->point_initial_loc[i]); + } } else { add_v2_v2(diff, psd->point_initial_loc[psd->select]); @@ -718,8 +737,9 @@ static int paintcurve_cursor_invoke(bContext *C, wmOperator *UNUSED(op), const w SpaceImage *sima = CTX_wm_space_image(C); float location[2]; - if (!sima) + if (!sima) { return OPERATOR_CANCELLED; + } UI_view2d_region_to_view( &ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]); diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index c1f87f676e2..dded9fcf45a 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -66,8 +66,9 @@ static bool is_effected(PartialVisArea area, const float co[3], const float mask) { - if (area == PARTIALVIS_ALL) + if (area == PARTIALVIS_ALL) { return 1; + } else if (area == PARTIALVIS_MASKED) { return mask > 0.5f; } @@ -103,15 +104,18 @@ static void partialvis_update_mesh(Object *ob, /* hide vertex if in the hide volume */ if (is_effected(area, planes, v->co, vmask)) { - if (action == PARTIALVIS_HIDE) + if (action == PARTIALVIS_HIDE) { v->flag |= ME_HIDE; - else + } + else { v->flag &= ~ME_HIDE; + } any_changed = true; } - if (!(v->flag & ME_HIDE)) + if (!(v->flag & ME_HIDE)) { any_visible = true; + } } if (any_changed) { @@ -183,10 +187,12 @@ static void partialvis_update_grids(Object *ob, } /* keep track of whether any elements are still hidden */ - if (BLI_BITMAP_TEST(gh, y * key.grid_size + x)) + if (BLI_BITMAP_TEST(gh, y * key.grid_size + x)) { any_hidden = true; - else + } + else { any_visible = true; + } } } @@ -222,15 +228,18 @@ static void partialvis_update_bmesh_verts(BMesh *bm, /* hide vertex if in the hide volume */ if (is_effected(area, planes, v->co, *vmask)) { - if (action == PARTIALVIS_HIDE) + if (action == PARTIALVIS_HIDE) { BM_elem_flag_enable(v, BM_ELEM_HIDDEN); - else + } + else { BM_elem_flag_disable(v, BM_ELEM_HIDDEN); + } (*any_changed) = true; } - if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) + if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { (*any_visible) = true; + } } } @@ -241,10 +250,12 @@ static void partialvis_update_bmesh_faces(GSet *faces) GSET_ITER (gs_iter, faces) { BMFace *f = BLI_gsetIterator_getKey(&gs_iter); - if (paint_is_bmesh_face_hidden(f)) + if (paint_is_bmesh_face_hidden(f)) { BM_elem_flag_enable(f, BM_ELEM_HIDDEN); - else + } + else { BM_elem_flag_disable(f, BM_ELEM_HIDDEN); + } } } @@ -375,8 +386,9 @@ static int hide_show_exec(bContext *C, wmOperator *op) } } - if (nodes) + if (nodes) { MEM_freeN(nodes); + } /* end undo */ sculpt_undo_push_end(); @@ -396,10 +408,12 @@ static int hide_show_invoke(bContext *C, wmOperator *op, const wmEvent *event) { PartialVisArea area = RNA_enum_get(op->ptr, "area"); - if (!ELEM(area, PARTIALVIS_ALL, PARTIALVIS_MASKED)) + if (!ELEM(area, PARTIALVIS_ALL, PARTIALVIS_MASKED)) { return WM_gesture_box_invoke(C, op, event); - else + } + else { return op->type->exec(C, op); + } } void PAINT_OT_hide_show(struct wmOperatorType *ot) diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index b82014dcfec..5a45f4946f2 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -126,8 +126,9 @@ void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h); - if (w == 0 || h == 0) + if (w == 0 || h == 0) { return; + } if (!imapaintpartial.enabled) { imapaintpartial.x1 = x; @@ -147,14 +148,17 @@ void ED_imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int ListBase *undo_tiles = ED_image_undo_get_tiles(); - for (ty = tiley; ty <= tileh; ty++) - for (tx = tilex; tx <= tilew; tx++) + for (ty = tiley; ty <= tileh; ty++) { + for (tx = tilex; tx <= tilew; tx++) { image_undo_push_tile(undo_tiles, ima, ibuf, &tmpibuf, tx, ty, NULL, NULL, false, find_old); + } + } ibuf->userflags |= IB_BITMAPDIRTY; - if (tmpibuf) + if (tmpibuf) { IMB_freeImBuf(tmpibuf); + } } void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint) @@ -164,8 +168,9 @@ void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short te ibuf, imapaintpartial.x1, imapaintpartial.y1, imapaintpartial.x2, imapaintpartial.y2); } - if (ibuf->mipmap[0]) + if (ibuf->mipmap[0]) { ibuf->userflags |= IB_MIPMAP_INVALID; + } /* todo: should set_tpage create ->rect? */ if (texpaint || (sima && sima->lock)) { @@ -197,8 +202,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) kernel->pixel_len = radius; } else { - if (br->blur_kernel_radius <= 0) + if (br->blur_kernel_radius <= 0) { br->blur_kernel_radius = 1; + } radius = br->blur_kernel_radius; @@ -210,8 +216,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) switch (type) { case KERNEL_BOX: - for (i = 0; i < kernel->side_squared; i++) + for (i = 0; i < kernel->side_squared; i++) { kernel->wdata[i] = 1.0; + } break; case KERNEL_GAUSSIAN: { @@ -246,8 +253,9 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) void paint_delete_blur_kernel(BlurKernel *kernel) { - if (kernel->wdata) + if (kernel->wdata) { MEM_freeN(kernel->wdata); + } } /************************ image paint poll ************************/ @@ -264,8 +272,9 @@ static bool image_paint_poll_ex(bContext *C, bool check_tool) { Object *obact; - if (!image_paint_brush(C)) + if (!image_paint_brush(C)) { return 0; + } obact = CTX_data_active_object(C); if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { @@ -302,10 +311,13 @@ static bool image_paint_2d_clone_poll(bContext *C) { Brush *brush = image_paint_brush(C); - if (!CTX_wm_region_view3d(C) && image_paint_poll(C)) - if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) - if (brush->clone.image) + if (!CTX_wm_region_view3d(C) && image_paint_poll(C)) { + if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) { + if (brush->clone.image) { return 1; + } + } + } return 0; } @@ -353,8 +365,9 @@ void paint_brush_color_get(struct Scene *scene, float color[3], struct ColorManagedDisplay *display) { - if (invert) + if (invert) { copy_v3_v3(color, BKE_brush_secondary_color_get(scene, br)); + } else { if (br->flag & BRUSH_USE_GRADIENT) { float color_gr[4]; @@ -374,11 +387,13 @@ void paint_brush_color_get(struct Scene *scene, } copy_v3_v3(color, color_gr); } - else + else { copy_v3_v3(color, BKE_brush_color_get(scene, br)); + } } - if (color_correction) + if (color_correction) { IMB_colormanagement_display_to_scene_linear_v3(color, display); + } } void paint_brush_init_tex(Brush *brush) @@ -401,11 +416,13 @@ void paint_brush_exit_tex(Brush *brush) { if (brush) { MTex *mtex = &brush->mtex; - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } mtex = &brush->mask_mtex; - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } } } @@ -528,10 +545,12 @@ static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, Po return; } - if (BKE_brush_use_alpha_pressure(scene, brush)) + if (BKE_brush_use_alpha_pressure(scene, brush)) { BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac)); - else + } + else { BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac)); + } if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) { UndoStack *ustack = CTX_wm_manager(C)->undo_stack; @@ -697,8 +716,9 @@ static int paint_exec(bContext *C, wmOperator *op) strokeprop = RNA_struct_find_property(op->ptr, "stroke"); - if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) + if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) { return OPERATOR_CANCELLED; + } RNA_float_get_array(&firstpoint, "mouse", mouse); @@ -767,8 +787,9 @@ static void toggle_paint_cursor(bContext *C, int enable) settings->imapaint.paintcursor = NULL; paint_cursor_delete_textures(); } - else if (enable) + else if (enable) { paint_cursor_start(C, image_paint_poll); + } } /* enable the paint cursor if it isn't already. @@ -1094,12 +1115,15 @@ void PAINT_OT_sample_color(wmOperatorType *ot) static bool texture_paint_toggle_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if (ob == NULL || ob->type != OB_MESH) + if (ob == NULL || ob->type != OB_MESH) { return 0; - if (!ob->data || ID_IS_LINKED(ob->data)) + } + if (!ob->data || ID_IS_LINKED(ob->data)) { return 0; - if (CTX_data_edit_object(C)) + } + if (CTX_data_edit_object(C)) { return 0; + } return 1; } @@ -1122,8 +1146,9 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) if (ob->mode & mode_flag) { ob->mode &= ~mode_flag; - if (U.glreslimit != 0) + if (U.glreslimit != 0) { GPU_free_images(bmain); + } GPU_paint_set_mipmap(bmain, 1); toggle_paint_cursor(C, 0); @@ -1144,8 +1169,9 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) /* set the current material active paint slot on image editor */ Material *ma = give_current_material(ob, ob->actcol); - if (ma && ma->texpaintslot) + if (ma && ma->texpaintslot) { ima = ma->texpaintslot[ma->paint_active_slot].ima; + } } else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) { ima = imapaint->canvas; @@ -1176,8 +1202,9 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint); - if (U.glreslimit != 0) + if (U.glreslimit != 0) { GPU_free_images(bmain); + } GPU_paint_set_mipmap(bmain, 0); toggle_paint_cursor(C, 1); @@ -1235,8 +1262,9 @@ static bool brush_colors_flip_poll(bContext *C) { if (image_paint_poll(C)) { Brush *br = image_paint_brush(C); - if (ELEM(br->imagepaint_tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) + if (ELEM(br->imagepaint_tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) { return true; + } } else { Object *ob = CTX_data_active_object(C); @@ -1283,9 +1311,11 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op) static bool texture_paint_poll(bContext *C) { - if (texture_paint_toggle_poll(C)) - if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT) + if (texture_paint_toggle_poll(C)) { + if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT) { return 1; + } + } return 0; } diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 5390f18304a..78832bbbd8f 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -158,14 +158,18 @@ static void brush_painter_2d_require_imbuf(BrushPainter *painter, Brush *brush = painter->brush; if ((painter->cache.use_float != use_float)) { - if (painter->cache.ibuf) + if (painter->cache.ibuf) { IMB_freeImBuf(painter->cache.ibuf); - if (painter->cache.curve_mask) + } + if (painter->cache.curve_mask) { MEM_freeN(painter->cache.curve_mask); - if (painter->cache.tex_mask) + } + if (painter->cache.tex_mask) { MEM_freeN(painter->cache.tex_mask); - if (painter->cache.tex_mask_old) + } + if (painter->cache.tex_mask_old) { MEM_freeN(painter->cache.tex_mask_old); + } painter->cache.ibuf = NULL; painter->cache.curve_mask = NULL; painter->cache.tex_mask = NULL; @@ -182,16 +186,21 @@ static void brush_painter_2d_require_imbuf(BrushPainter *painter, static void brush_painter_2d_free(BrushPainter *painter) { - if (painter->cache.ibuf) + if (painter->cache.ibuf) { IMB_freeImBuf(painter->cache.ibuf); - if (painter->cache.texibuf) + } + if (painter->cache.texibuf) { IMB_freeImBuf(painter->cache.texibuf); - if (painter->cache.curve_mask) + } + if (painter->cache.curve_mask) { MEM_freeN(painter->cache.curve_mask); - if (painter->cache.tex_mask) + } + if (painter->cache.tex_mask) { MEM_freeN(painter->cache.tex_mask); - if (painter->cache.tex_mask_old) + } + if (painter->cache.tex_mask_old) { MEM_freeN(painter->cache.tex_mask_old); + } MEM_freeN(painter); } @@ -297,9 +306,10 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, int destx, desty, srcx, srcy, w, h, x1, y1, x2, y2; /* create brush image buffer if it didn't exist yet */ - if (!cache->tex_mask) + if (!cache->tex_mask) { cache->tex_mask = MEM_mallocN(sizeof(unsigned short) * diameter * diameter, "brush_painter_mask"); + } /* create new texture image buffer with coordinates relative to old */ tex_mask_old = cache->tex_mask_old; @@ -334,21 +344,27 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, y2 = min_ii(desty + h, diameter); /* blend existing texture in new position */ - if ((x1 < x2) && (y1 < y2)) + if ((x1 < x2) && (y1 < y2)) { brush_painter_mask_imbuf_update(painter, tex_mask_old, x1, y1, x2, y2, srcx, srcy, diameter); + } - if (tex_mask_old) + if (tex_mask_old) { MEM_freeN(tex_mask_old); + } /* sample texture in new areas */ - if ((0 < x1) && (0 < diameter)) + if ((0 < x1) && (0 < diameter)) { brush_painter_mask_imbuf_update(painter, NULL, 0, 0, x1, diameter, 0, 0, diameter); - if ((x2 < diameter) && (0 < diameter)) + } + if ((x2 < diameter) && (0 < diameter)) { brush_painter_mask_imbuf_update(painter, NULL, x2, 0, diameter, diameter, 0, 0, diameter); - if ((x1 < x2) && (0 < y1)) + } + if ((x1 < x2) && (0 < y1)) { brush_painter_mask_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0, diameter); - if ((x1 < x2) && (y2 < diameter)) + } + if ((x1 < x2) && (y2 < diameter)) { brush_painter_mask_imbuf_update(painter, NULL, x1, y2, x2, diameter, 0, 0, diameter); + } /* through with sampling, now update sizes */ cache->tex_mask_old_w = diameter; @@ -556,8 +572,9 @@ static void brush_painter_imbuf_update( crgba[2] = ot[2]; crgba[3] = ot[3]; } - else + else { rgba_float_to_uchar(crgba, rgba); + } /* write to new texture buffer */ t[0] = crgba[0]; @@ -588,8 +605,9 @@ static void brush_painter_imbuf_partial_update(BrushPainter *painter, /* create brush image buffer if it didn't exist yet */ imbflag = (cache->use_float) ? IB_rectfloat : IB_rect; - if (!cache->ibuf) + if (!cache->ibuf) { cache->ibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag); + } ibuf = cache->ibuf; /* create new texture image buffer with coordinates relative to old */ @@ -617,21 +635,27 @@ static void brush_painter_imbuf_partial_update(BrushPainter *painter, y2 = min_ii(desty + h, ibuf->y); /* blend existing texture in new position */ - if ((x1 < x2) && (y1 < y2)) + if ((x1 < x2) && (y1 < y2)) { brush_painter_imbuf_update(painter, oldtexibuf, x1, y1, x2, y2, srcx, srcy); + } - if (oldtexibuf) + if (oldtexibuf) { IMB_freeImBuf(oldtexibuf); + } /* sample texture in new areas */ - if ((0 < x1) && (0 < ibuf->y)) + if ((0 < x1) && (0 < ibuf->y)) { brush_painter_imbuf_update(painter, NULL, 0, 0, x1, ibuf->y, 0, 0); - if ((x2 < ibuf->x) && (0 < ibuf->y)) + } + if ((x2 < ibuf->x) && (0 < ibuf->y)) { brush_painter_imbuf_update(painter, NULL, x2, 0, ibuf->x, ibuf->y, 0, 0); - if ((x1 < x2) && (0 < y1)) + } + if ((x1 < x2) && (0 < y1)) { brush_painter_imbuf_update(painter, NULL, x1, 0, x2, y1, 0, 0); - if ((x1 < x2) && (y2 < ibuf->y)) + } + if ((x1 < x2) && (y2 < ibuf->y)) { brush_painter_imbuf_update(painter, NULL, x1, y2, x2, ibuf->y, 0, 0); + } } static void brush_painter_2d_tex_mapping(ImagePaintState *s, @@ -716,10 +740,12 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s, if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { tex_rotation += ups->brush_rotation; } - else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) + else if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) { do_random = true; - else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) + } + else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) { do_partial_update = true; + } brush_painter_2d_tex_mapping(s, diameter, @@ -765,10 +791,12 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s, brush->mask_mtex.brush_map_mode, &painter->mask_mapping); - if (do_partial_update_mask) + if (do_partial_update_mask) { brush_painter_mask_imbuf_partial_update(painter, pos, diameter); - else + } + else { cache->tex_mask = brush_painter_mask_ibuf_new(painter, diameter); + } cache->last_mask_rotation = mask_rotation; } } @@ -835,11 +863,13 @@ static void paint_2d_ibuf_rgb_set( { if (is_torus) { x %= ibuf->x; - if (x < 0) + if (x < 0) { x += ibuf->x; + } y %= ibuf->y; - if (y < 0) + if (y < 0) { y += ibuf->y; + } } if (ibuf->rect_float) { @@ -865,13 +895,15 @@ static void paint_2d_ibuf_tile_convert(ImBuf *ibuf, int *x, int *y, short tile) { if (tile & PAINT_TILE_X) { *x %= ibuf->x; - if (*x < 0) + if (*x < 0) { *x += ibuf->x; + } } if (tile & PAINT_TILE_Y) { *y %= ibuf->y; - if (*y < 0) + if (*y < 0) { *y += ibuf->y; + } } } @@ -879,15 +911,17 @@ static float paint_2d_ibuf_add_if(ImBuf *ibuf, int x, int y, float *outrgb, shor { float inrgb[4]; - if (tile) + if (tile) { paint_2d_ibuf_tile_convert(ibuf, &x, &y, tile); + } /* need to also do clipping here always since tiled coordinates * are not always within bounds */ if (x < ibuf->x && x >= 0 && y < ibuf->y && y >= 0) { paint_2d_ibuf_rgb_get(ibuf, x, y, inrgb); } - else + else { return 0; + } mul_v4_fl(inrgb, w); add_v4_v4(outrgb, inrgb); @@ -917,8 +951,9 @@ static void paint_2d_lift_soften( if (!tile) { IMB_rectclip(ibuf, ibufb, &in_off[0], &in_off[1], &out_off[0], &out_off[1], &dim[0], &dim[1]); - if ((dim[0] == 0) || (dim[1] == 0)) + if ((dim[0] == 0) || (dim[1] == 0)) { return; + } } /* find offset inside mask buffers to sample them */ @@ -933,10 +968,12 @@ static void paint_2d_lift_soften( count = 0.0; if (tile) { paint_2d_ibuf_tile_convert(ibuf, &xi, &yi, tile); - if (xi < ibuf->x && xi >= 0 && yi < ibuf->y && yi >= 0) + if (xi < ibuf->x && xi >= 0 && yi < ibuf->y && yi >= 0) { paint_2d_ibuf_rgb_get(ibuf, xi, yi, rgba); - else + } + else { zero_v4(rgba); + } } else { /* coordinates have been clipped properly here, it should be safe to do this */ @@ -974,12 +1011,14 @@ static void paint_2d_lift_soften( blend_color_add_float(outrgb, rgba, outrgb); outrgb[3] = alpha; } - else + else { copy_v4_v4(outrgb, rgba); + } } } - else + else { copy_v4_v4(outrgb, rgba); + } /* write into brush buffer */ xo = out_off[0] + x; yo = out_off[1] + y; @@ -1015,19 +1054,23 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4], /* convert destination and source coordinates to be within image */ if (tile & PAINT_TILE_X) { destx = destx % dbuf->x; - if (destx < 0) + if (destx < 0) { destx += dbuf->x; + } srcx = srcx % sbuf->x; - if (srcx < 0) + if (srcx < 0) { srcx += sbuf->x; + } } if (tile & PAINT_TILE_Y) { desty = desty % dbuf->y; - if (desty < 0) + if (desty < 0) { desty += dbuf->y; + } srcy = srcy % sbuf->y; - if (srcy < 0) + if (srcy < 0) { srcy += sbuf->y; + } } /* clip width of blending area to destination imbuf, to avoid writing the * same pixel twice */ @@ -1039,13 +1082,15 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4], paint_2d_set_region(®ion[tot++], destx, desty, srcx, srcy, w, h); /* do 3 other rects if needed */ - if ((tile & PAINT_TILE_X) && w < origw) + if ((tile & PAINT_TILE_X) && w < origw) { paint_2d_set_region( ®ion[tot++], (destx + w) % dbuf->x, desty, (srcx + w) % sbuf->x, srcy, origw - w, h); - if ((tile & PAINT_TILE_Y) && h < origh) + } + if ((tile & PAINT_TILE_Y) && h < origh) { paint_2d_set_region( ®ion[tot++], destx, (desty + h) % dbuf->y, srcx, (srcy + h) % sbuf->y, w, origh - h); - if ((tile & PAINT_TILE_X) && (tile & PAINT_TILE_Y) && (w < origw) && (h < origh)) + } + if ((tile & PAINT_TILE_X) && (tile & PAINT_TILE_Y) && (w < origw) && (h < origh)) { paint_2d_set_region(®ion[tot++], (destx + w) % dbuf->x, (desty + h) % dbuf->y, @@ -1053,6 +1098,7 @@ static int paint_2d_torus_split_region(ImagePaintRegion region[4], (srcy + h) % sbuf->y, origw - w, origh - h); + } return tot; } @@ -1065,7 +1111,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos, short tile) paint_2d_set_region(region, 0, 0, pos[0], pos[1], ibufb->x, ibufb->y); tot = paint_2d_torus_split_region(region, ibufb, ibuf, tile); - for (a = 0; a < tot; a++) + for (a = 0; a < tot; a++) { IMB_rectblend(ibufb, ibufb, ibuf, @@ -1083,6 +1129,7 @@ static void paint_2d_lift_smear(ImBuf *ibuf, ImBuf *ibufb, int *pos, short tile) region[a].height, IMB_BLEND_COPY, false); + } } static ImBuf *paint_2d_lift_clone(ImBuf *ibuf, ImBuf *ibufb, int *pos) @@ -1161,11 +1208,13 @@ static void paint_2d_do_making_brush(ImagePaintState *s, int origx = region->destx - tx * IMAPAINT_TILE_SIZE; int origy = region->desty - ty * IMAPAINT_TILE_SIZE; - if (s->canvas->rect_float) + if (s->canvas->rect_float) { tmpbuf.rect_float = image_undo_find_tile( undo_tiles, s->image, s->canvas, tx, ty, &mask, false); - else + } + else { tmpbuf.rect = image_undo_find_tile(undo_tiles, s->image, s->canvas, tx, ty, &mask, false); + } IMB_rectblend(s->canvas, &tmpbuf, @@ -1244,8 +1293,9 @@ static int paint_2d_op(void *state, blend = IMB_BLEND_INTERPOLATE; } else if (s->tool == PAINT_TOOL_SMEAR) { - if (lastpos[0] == pos[0] && lastpos[1] == pos[1]) + if (lastpos[0] == pos[0] && lastpos[1] == pos[1]) { return 0; + } paint_2d_convert_brushco(ibufb, lastpos, blastpos); paint_2d_lift_smear(s->canvas, ibufb, blastpos, tile); @@ -1337,8 +1387,9 @@ static int paint_2d_op(void *state, } } - if (clonebuf) + if (clonebuf) { IMB_freeImBuf(clonebuf); + } return 1; } @@ -1359,8 +1410,9 @@ static int paint_2d_canvas_set(ImagePaintState *s, Image *ima) s->warnmultifile = ima->id.name + 2; return 0; } - else if (!ibuf || !(ibuf->rect || ibuf->rect_float)) + else if (!ibuf || !(ibuf->rect || ibuf->rect_float)) { return 0; + } s->image = ima; s->canvas = ibuf; @@ -1382,8 +1434,9 @@ static int paint_2d_canvas_set(ImagePaintState *s, Image *ima) if (s->canvas->rect_float && !s->clonecanvas->rect_float) { IMB_float_from_rect(s->clonecanvas); } - else if (!s->canvas->rect_float && !s->clonecanvas->rect) + else if (!s->canvas->rect_float && !s->clonecanvas->rect) { IMB_rect_from_float(s->clonecanvas); + } } /* set masking */ @@ -1419,12 +1472,14 @@ void paint_2d_stroke(void *ps, ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL); const bool is_data = (ibuf && ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA); - if (!ibuf) + if (!ibuf) { return; + } s->blend = s->brush->blend; - if (eraser) + if (eraser) { s->blend = IMB_BLEND_ERASE_ALPHA; + } UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]); UI_view2d_region_to_view(s->v2d, prev_mval[0], prev_mval[1], &olduv[0], &olduv[1]); @@ -1463,8 +1518,9 @@ void paint_2d_stroke(void *ps, painter->cache.curve_mask, painter->cache.tex_mask, olduv, - newuv)) + newuv)) { s->need_redraw = true; + } BKE_image_release_ibuf(s->image, ibuf, NULL); } @@ -1490,10 +1546,12 @@ void *paint_2d_new_stroke(bContext *C, wmOperator *op, int mode) s->symmetry = settings->imapaint.paint.symmetry_flags; if (!paint_2d_canvas_set(s, s->image)) { - if (s->warnmultifile) + if (s->warnmultifile) { BKE_report(op->reports, RPT_WARNING, "Image requires 4 color channels to paint"); - if (s->warnpackedfile) + } + if (s->warnpackedfile) { BKE_report(op->reports, RPT_WARNING, "Packed MultiLayer files cannot be painted"); + } MEM_freeN(s); return NULL; @@ -1530,18 +1588,21 @@ void paint_2d_redraw(const bContext *C, void *ps, bool final) } if (final) { - if (s->image && !(s->sima && s->sima->lock)) + if (s->image && !(s->sima && s->sima->lock)) { GPU_free_image(s->image); + } /* compositor listener deals with updating */ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image); DEG_id_tag_update(&s->image->id, 0); } else { - if (!s->sima || !s->sima->lock) + if (!s->sima || !s->sima->lock) { ED_region_tag_redraw(CTX_wm_region(C)); - else + } + else { WM_event_add_notifier(C, NC_IMAGE | NA_PAINTING, s->image); + } } } @@ -1566,8 +1627,9 @@ static void paint_2d_fill_add_pixel_byte(const int x_px, { size_t coordinate; - if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) + if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) { return; + } coordinate = ((size_t)y_px) * ibuf->x + x_px; @@ -1594,8 +1656,9 @@ static void paint_2d_fill_add_pixel_float(const int x_px, { size_t coordinate; - if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) + if (x_px >= ibuf->x || x_px < 0 || y_px >= ibuf->y || y_px < 0) { return; + } coordinate = ((size_t)y_px) * ibuf->x + x_px; @@ -1624,13 +1687,15 @@ void paint_2d_bucket_fill( bool do_float; - if (!ima) + if (!ima) { return; + } ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL); - if (!ibuf) + if (!ibuf) { return; + } do_float = (ibuf->rect_float != NULL); /* first check if our image is float. If it is not we should correct the color to @@ -1742,14 +1807,18 @@ void paint_2d_bucket_fill( paint_2d_fill_add_pixel_float( x_px + 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq); - if (x_px > maxx) + if (x_px > maxx) { maxx = x_px; - if (x_px < minx) + } + if (x_px < minx) { minx = x_px; - if (y_px > maxy) + } + if (y_px > maxy) { maxy = y_px; - if (x_px > miny) + } + if (x_px > miny) { miny = y_px; + } } } else { @@ -1782,14 +1851,18 @@ void paint_2d_bucket_fill( paint_2d_fill_add_pixel_byte( x_px + 1, y_px + 1, ibuf, stack, touched, pixel_color, threshold_sq); - if (x_px > maxx) + if (x_px > maxx) { maxx = x_px; - if (x_px < minx) + } + if (x_px < minx) { minx = x_px; - if (y_px > maxy) + } + if (y_px > maxy) { maxy = y_px; - if (x_px > miny) + } + if (x_px > miny) { miny = y_px; + } } } @@ -1822,13 +1895,15 @@ void paint_2d_gradient_fill( bool do_float; - if (!ima) + if (!ima) { return; + } ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL); - if (!ibuf) + if (!ibuf) { return; + } UI_view2d_region_to_view( s->v2d, mouse_final[0], mouse_final[1], &image_final[0], &image_final[1]); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 6b4951d1ca4..5436c5912bc 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -627,8 +627,9 @@ static float VecZDepthPersp( w_tmp[1] = w_tmp[1] * wtot_inv; w_tmp[2] = w_tmp[2] * wtot_inv; } - else /* dummy values for zero area face */ + else { /* dummy values for zero area face */ w_tmp[0] = w_tmp[1] = w_tmp[2] = 1.0f / 3.0f; + } /* done mimicking barycentric_weights_v2() */ return (v1[2] * w_tmp[0]) + (v2[2] * w_tmp[1]) + (v3[2] * w_tmp[2]); @@ -644,8 +645,9 @@ static int project_paint_PickFace(const ProjPaintState *ps, const float pt[2], f float z_depth_best = FLT_MAX, z_depth; bucket_index = project_bucket_offset_safe(ps, pt); - if (bucket_index == -1) + if (bucket_index == -1) { return -1; + } /* we could return 0 for 1 face buckets, as long as this function assumes * that the point its testing is only every originated from an existing face */ @@ -686,10 +688,12 @@ static void uvco_to_wrapped_pxco(const float uv[2], int ibuf_x, int ibuf_y, floa *x = fmodf(uv[0], 1.0f); *y = fmodf(uv[1], 1.0f); - if (*x < 0.0f) + if (*x < 0.0f) { *x += 1.0f; - if (*y < 0.0f) + } + if (*y < 0.0f) { *y += 1.0f; + } *x = *x * ibuf_x - 0.5f; *y = *y * ibuf_y - 0.5f; @@ -713,8 +717,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps, tri_index = project_paint_PickFace(ps, pt, w); - if (tri_index == -1) + if (tri_index == -1) { return 0; + } lt = &ps->mlooptri_eval[tri_index]; PS_LOOPTRI_ASSIGN_UV_3(lt_tri_uv, ps->poly_to_loop_uv, lt); @@ -724,8 +729,9 @@ static bool project_paint_PickColor(const ProjPaintState *ps, ima = project_paint_face_paint_image(ps, tri_index); /** we must have got the imbuf before getting here. */ ibuf = BKE_image_get_first_ibuf(ima); - if (!ibuf) + if (!ibuf) { return 0; + } if (interp) { float x, y; @@ -802,12 +808,14 @@ static int project_paint_occlude_ptv(const float pt[3], const bool is_ortho) { /* if all are behind us, return false */ - if (v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2]) + if (v1[2] > pt[2] && v2[2] > pt[2] && v3[2] > pt[2]) { return 0; + } /* do a 2D point in try intersection */ - if (!isect_point_tri_v2(pt, v1, v2, v3)) + if (!isect_point_tri_v2(pt, v1, v2, v3)) { return 0; + } /* From here on we know there IS an intersection */ /* if ALL of the verts are infront of us then we know it intersects ? */ @@ -818,12 +826,14 @@ static int project_paint_occlude_ptv(const float pt[3], /* we intersect? - find the exact depth at the point of intersection */ /* Is this point is occluded by another face? */ if (is_ortho) { - if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) + if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) { return 2; + } } else { - if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) + if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) { return 2; + } } } return -1; @@ -843,8 +853,9 @@ static int project_paint_occlude_ptv_clip(const float pt[3], float wco[3]; int ret = project_paint_occlude_ptv(pt, v1, v2, v3, w, is_ortho); - if (ret <= 0) + if (ret <= 0) { return ret; + } if (ret == 1) { /* weights not calculated */ if (is_ortho) { @@ -1009,15 +1020,19 @@ static bool cmp_uv(const float vec2a[2], const float vec2b[2]) float xb = fmodf(vec2b[0], 1.0f); float yb = fmodf(vec2b[1], 1.0f); - if (xa < 0.0f) + if (xa < 0.0f) { xa += 1.0f; - if (ya < 0.0f) + } + if (ya < 0.0f) { ya += 1.0f; + } - if (xb < 0.0f) + if (xb < 0.0f) { xb += 1.0f; - if (yb < 0.0f) + } + if (yb < 0.0f) { yb += 1.0f; + } return ((fabsf(xa - xb) < PROJ_GEOM_TOLERANCE) && (fabsf(ya - yb) < PROJ_GEOM_TOLERANCE)) ? 1 : 0; @@ -1093,8 +1108,9 @@ static void project_face_winding_init(const ProjPaintState *ps, const int tri_in const float *lt_tri_uv[3] = {PS_LOOPTRI_AS_UV_3(ps->poly_to_loop_uv, lt)}; float winding = cross_tri_v2(lt_tri_uv[0], lt_tri_uv[1], lt_tri_uv[2]); - if (winding > 0) + if (winding > 0) { ps->faceWindingFlags[tri_index] |= PROJ_FACE_WINDING_CW; + } ps->faceWindingFlags[tri_index] |= PROJ_FACE_WINDING_INIT; } @@ -1149,8 +1165,9 @@ static bool check_seam(const ProjPaintState *ps, *orig_fidx = (i1_fidx < i2_fidx && (i2_fidx - i1_fidx == 1)) ? i1_fidx : i2_fidx; /* initialize face winding if needed */ - if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) + if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) { project_face_winding_init(ps, tri_index); + } /* first test if they have the same image */ if ((orig_tpage == tpage) && cmp_uv(orig_lt_tri_uv[orig_i1_fidx], lt_tri_uv[i1_fidx]) && @@ -1415,8 +1432,9 @@ static void project_face_seams_init(const ProjPaintState *ps, LinkNode *node; /* initialize face winding if needed */ - if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) + if ((ps->faceWindingFlags[tri_index] & PROJ_FACE_WINDING_INIT) == 0) { project_face_winding_init(ps, tri_index); + } do { if (init_all || (ps->mloop_eval[lt->tri[fidx[0]]].v == vert_index) || @@ -1779,14 +1797,16 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty) /* double check lock to avoid locking */ if (UNLIKELY(!pjIma->undoRect[tile_index])) { - if (tinf->lock) + if (tinf->lock) { BLI_spin_lock(tinf->lock); + } if (LIKELY(!pjIma->undoRect[tile_index])) { pjIma->undoRect[tile_index] = TILE_PENDING; generate_tile = true; } - if (tinf->lock) + if (tinf->lock) { BLI_spin_unlock(tinf->lock); + } } if (generate_tile) { @@ -1819,11 +1839,13 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty) pjIma->ibuf->userflags |= IB_BITMAPDIRTY; /* tile ready, publish */ - if (tinf->lock) + if (tinf->lock) { BLI_spin_lock(tinf->lock); + } pjIma->undoRect[tile_index] = undorect; - if (tinf->lock) + if (tinf->lock) { BLI_spin_unlock(tinf->lock); + } } return tile_index; @@ -1872,8 +1894,9 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps, tile_index = project_paint_undo_subtiles(tinf, x_tile, y_tile); /* other thread may be initializing the tile so wait here */ - while (projima->undoRect[tile_index] == TILE_PENDING) + while (projima->undoRect[tile_index] == TILE_PENDING) { ; + } BLI_assert(tile_index < (IMAPAINT_TILE_NUMBER(ibuf->x) * IMAPAINT_TILE_NUMBER(ibuf->y))); BLI_assert(tile_offset < (IMAPAINT_TILE_SIZE * IMAPAINT_TILE_SIZE)); @@ -1902,10 +1925,12 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps, projPixel->y_px = y_px; projPixel->mask = (unsigned short)(mask * 65535); - if (ps->do_masking) + if (ps->do_masking) { projPixel->mask_accum = projima->maskRect[tile_index] + tile_offset; - else + } + else { projPixel->mask_accum = NULL; + } /* which bounding box cell are we in?, needed for undo */ projPixel->bb_cell_index = ((int)(((float)x_px / (float)ibuf->x) * PROJ_BOUNDBOX_DIV)) + @@ -1995,10 +2020,12 @@ static ProjPixel *project_paint_uvpixel_init(const ProjPaintState *ps, } #ifdef PROJ_DEBUG_PAINT - if (ibuf->rect_float) + if (ibuf->rect_float) { projPixel->pixel.f_pt[0] = 0; - else + } + else { projPixel->pixel.ch_pt[0] = 0; + } #endif /* pointer arithmetic */ projPixel->image_index = projima - ps->projImages; @@ -2091,8 +2118,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } /* line inside rect */ - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } /* top/bottom */ if (line_isect_y(l1, l2, rect->ymin, &isect) && (isect >= cliprect->xmin) && @@ -2109,8 +2137,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } } - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } if (line_isect_y(l1, l2, rect->ymax, &isect) && (isect >= cliprect->xmin) && (isect <= cliprect->xmax)) { @@ -2126,8 +2155,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } } - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } /* left/right */ if (line_isect_x(l1, l2, rect->xmin, &isect) && (isect >= cliprect->ymin) && @@ -2144,8 +2174,9 @@ static bool line_clip_rect2f(const rctf *cliprect, } } - if (ok1 && ok2) + if (ok1 && ok2) { return 1; + } if (line_isect_x(l1, l2, rect->xmax, &isect) && (isect >= cliprect->ymin) && (isect <= cliprect->ymax)) { @@ -2430,8 +2461,9 @@ static bool line_rect_clip(const rctf *rect, } } - if (min == FLT_MAX) + if (min == FLT_MAX) { return false; + } tmp = (is_ortho) ? 1.0f : (l1[3] + min * (l2[3] - l1[3])); @@ -2504,8 +2536,9 @@ static void project_bucket_clip_face(const bool is_ortho, (*tot) = 0; - if (cull) + if (cull) { return; + } if (inside_bucket_flag & ISECT_1) { copy_v2_v2(bucket_bounds_uv[*tot], uv1co); @@ -2515,8 +2548,9 @@ static void project_bucket_clip_face(const bool is_ortho, flag = inside_bucket_flag & (ISECT_1 | ISECT_2); if (flag && flag != (ISECT_1 | ISECT_2)) { if (line_rect_clip( - bucket_bounds, v1coSS, v2coSS, uv1co, uv2co, bucket_bounds_uv[*tot], is_ortho)) + bucket_bounds, v1coSS, v2coSS, uv1co, uv2co, bucket_bounds_uv[*tot], is_ortho)) { (*tot)++; + } } if (inside_bucket_flag & ISECT_2) { @@ -2527,8 +2561,9 @@ static void project_bucket_clip_face(const bool is_ortho, flag = inside_bucket_flag & (ISECT_2 | ISECT_3); if (flag && flag != (ISECT_2 | ISECT_3)) { if (line_rect_clip( - bucket_bounds, v2coSS, v3coSS, uv2co, uv3co, bucket_bounds_uv[*tot], is_ortho)) + bucket_bounds, v2coSS, v3coSS, uv2co, uv3co, bucket_bounds_uv[*tot], is_ortho)) { (*tot)++; + } } if (inside_bucket_flag & ISECT_3) { @@ -2539,8 +2574,9 @@ static void project_bucket_clip_face(const bool is_ortho, flag = inside_bucket_flag & (ISECT_3 | ISECT_1); if (flag && flag != (ISECT_3 | ISECT_1)) { if (line_rect_clip( - bucket_bounds, v3coSS, v1coSS, uv3co, uv1co, bucket_bounds_uv[*tot], is_ortho)) + bucket_bounds, v3coSS, v1coSS, uv3co, uv1co, bucket_bounds_uv[*tot], is_ortho)) { (*tot)++; + } } if ((*tot) < 3) { @@ -2743,10 +2779,12 @@ static void project_bucket_clip_face(const bool is_ortho, v1_clipSS[0] * v2_clipSS[0] + v1_clipSS[1] * v2_clipSS[1]); } - if (flip) + if (flip) { qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort_flip); - else + } + else { qsort(isectVCosSS, *tot, sizeof(float) * 3, float_z_sort); + } doubles = true; while (doubles == true) { @@ -2795,12 +2833,14 @@ static void project_bucket_clip_face(const bool is_ortho, /* If there are ever any problems, */ float test_uv[4][2]; int i; - if (is_ortho) + if (is_ortho) { rect_to_uvspace_ortho( bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip); - else + } + else { rect_to_uvspace_persp( bucket_bounds, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, test_uv, flip); + } printf("( [(%f,%f), (%f,%f), (%f,%f), (%f,%f)], ", test_uv[0][0], test_uv[0][1], @@ -2886,12 +2926,14 @@ static void project_bucket_clip_face(const bool is_ortho, static bool IsectPoly2Df(const float pt[2], float uv[][2], const int tot) { int i; - if (line_point_side_v2(uv[tot - 1], uv[0], pt) < 0.0f) + if (line_point_side_v2(uv[tot - 1], uv[0], pt) < 0.0f) { return 0; + } for (i = 1; i < tot; i++) { - if (line_point_side_v2(uv[i - 1], uv[i], pt) < 0.0f) + if (line_point_side_v2(uv[i - 1], uv[i], pt) < 0.0f) { return 0; + } } return 1; @@ -2902,8 +2944,9 @@ static bool IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot bool side = (line_point_side_v2(uv[tot - 1], uv[0], pt) > 0.0f); for (i = 1; i < tot; i++) { - if ((line_point_side_v2(uv[i - 1], uv[i], pt) > 0.0f) != side) + if ((line_point_side_v2(uv[i - 1], uv[i], pt) > 0.0f) != side) { return 0; + } } return 1; @@ -3067,12 +3110,14 @@ static void project_paint_face_init(const ProjPaintState *ps, has_x_isect = has_isect = 1; - if (is_ortho) + if (is_ortho) { screen_px_from_ortho( uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w); - else + } + else { screen_px_from_persp( uv, v1coSS, v2coSS, v3coSS, uv1co, uv2co, uv3co, pixelScreenCo, w); + } /* a pity we need to get the worldspace pixel location here */ if (do_clip || do_3d_mapping) { @@ -3488,8 +3533,9 @@ static void project_bucket_init(const ProjPaintState *ps, } } - if (tmpibuf) + if (tmpibuf) { IMB_freeImBuf(tmpibuf); + } ps->bucketFlags[bucket_index] |= PROJ_BUCKET_INIT; } @@ -3834,8 +3880,9 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps) /* augment the diffe*/ cavities[a] = saacos(10.0f * dot_v3v3(no, edges[a])) * (float)M_1_PI; } - else + else { cavities[a] = 0.0; + } } MEM_freeN(counter); @@ -3871,8 +3918,9 @@ static void proj_paint_state_thread_init(ProjPaintState *ps, const bool reset_th /* workaround for #35057, disable threading if diameter is less than is possible for * optimum bucket number generation */ - if (reset_threads) + if (reset_threads) { ps->thread_tot = 1; + } if (ps->is_shared_user == false) { if (ps->thread_tot > 1) { @@ -4048,8 +4096,9 @@ static void proj_paint_layer_clone_init(ProjPaintState *ps, ProjPaintLayerClone ps->poly_to_loop_uv_clone = MEM_mallocN(ps->totpoly_eval * sizeof(MLoopUV *), "proj_paint_mtfaces"); - if (layer_num != -1) + if (layer_num != -1) { mloopuv_clone_base = CustomData_get_layer_n(&ps->me_eval->ldata, CD_MLOOPUV, layer_num); + } if (mloopuv_clone_base == NULL) { /* get active instead */ @@ -4071,11 +4120,13 @@ static bool project_paint_clone_face_skip(ProjPaintState *ps, if (ps->do_material_slots) { lc->slot_clone = project_paint_face_clone_slot(ps, tri_index); /* all faces should have a valid slot, reassert here */ - if (ELEM(lc->slot_clone, NULL, slot)) + if (ELEM(lc->slot_clone, NULL, slot)) { return true; + } } - else if (ps->clone_ima == ps->canvas_ima) + else if (ps->clone_ima == ps->canvas_ima) { return true; + } if (ps->do_material_slots) { if (lc->slot_clone != lc->slot_last_clone) { @@ -4242,8 +4293,9 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps, else { if (slot != slot_last) { if (!slot->uvname || !(mloopuv_base = CustomData_get_layer_named( - &ps->me_eval->ldata, CD_MLOOPUV, slot->uvname))) + &ps->me_eval->ldata, CD_MLOOPUV, slot->uvname))) { mloopuv_base = CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV); + } slot_last = slot; } @@ -4398,17 +4450,19 @@ static void project_paint_begin(const bContext *C, if (ps->do_layer_stencil || ps->do_stencil_brush) { //int layer_num = CustomData_get_stencil_layer(&ps->me_eval->ldata, CD_MLOOPUV); int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV); - if (layer_num != -1) + if (layer_num != -1) { ps->mloopuv_stencil_eval = CustomData_get_layer_n( &ps->me_eval->ldata, CD_MLOOPUV, layer_num); + } if (ps->mloopuv_stencil_eval == NULL) { /* get active instead */ ps->mloopuv_stencil_eval = CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV); } - if (ps->do_stencil_brush) + if (ps->do_stencil_brush) { mloopuv_base = ps->mloopuv_stencil_eval; + } } /* when using subsurf or multires, mface arrays are thrown away, we need to keep a copy */ @@ -4513,11 +4567,13 @@ static void project_paint_end(ProjPaintState *ps) /* must be set for non-shared */ BLI_assert(ps->poly_to_loop_uv || ps->is_shared_user); - if (ps->poly_to_loop_uv) + if (ps->poly_to_loop_uv) { MEM_freeN((void *)ps->poly_to_loop_uv); + } - if (ps->do_layer_clone) + if (ps->do_layer_clone) { MEM_freeN((void *)ps->poly_to_loop_uv_clone); + } if (ps->thread_tot > 1) { BLI_spin_end(ps->tile_lock); MEM_freeN((void *)ps->tile_lock); @@ -4550,8 +4606,9 @@ static void project_paint_end(ProjPaintState *ps) MEM_freeN(ps->blurkernel); } - if (ps->vertFlags) + if (ps->vertFlags) { MEM_freeN(ps->vertFlags); + } for (a = 0; a < ps->thread_tot; a++) { BLI_memarena_free(ps->arena_mt[a]); @@ -4591,8 +4648,9 @@ static bool partial_redraw_array_merge(ImagePaintPartialRedraw *pr, pr->x2 = max_ii(pr->x2, pr_other->x2); pr->y2 = max_ii(pr->y2, pr_other->y2); - if (pr->x2 != -1) + if (pr->x2 != -1) { touch = 1; + } pr++; pr_other++; @@ -4678,8 +4736,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps, { const int diameter = 2 * ps->brush_size; - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_thread_lock(LOCK_CUSTOM1); + } //printf("%d %d\n", ps->context_bucket_x, ps->context_bucket_y); @@ -4694,8 +4753,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps, *bucket_index = ps->context_bucket_x + (ps->context_bucket_y * ps->buckets_x); ps->context_bucket_x++; - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_thread_unlock(LOCK_CUSTOM1); + } return 1; } @@ -4703,8 +4763,9 @@ static bool project_bucket_iter_next(ProjPaintState *ps, ps->context_bucket_x = ps->bucketMin[0]; } - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_thread_unlock(LOCK_CUSTOM1); + } return 0; } @@ -4782,8 +4843,9 @@ static void do_projectpaint_smear(ProjPaintState *ps, { unsigned char rgba_ub[4]; - if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1) == 0) + if (project_paint_PickColor(ps, co, NULL, rgba_ub, 1) == 0) { return; + } blend_color_interpolate_byte( ((ProjPixelClone *)projPixel)->clonepx.ch, projPixel->pixel.ch_pt, rgba_ub, mask); @@ -4799,8 +4861,9 @@ static void do_projectpaint_smear_f(ProjPaintState *ps, { float rgba[4]; - if (project_paint_PickColor(ps, co, rgba, NULL, 1) == 0) + if (project_paint_PickColor(ps, co, rgba, NULL, 1) == 0) { return; + } blend_color_interpolate_float( ((ProjPixelClone *)projPixel)->clonepx.f, projPixel->pixel.f_pt, rgba, mask); @@ -4855,8 +4918,9 @@ static void do_projectpaint_soften_f(ProjPaintState *ps, blend_color_add_float(rgba, projPixel->pixel.f_pt, rgba); rgba[3] = alpha; } - else + else { return; + } } else { blend_color_interpolate_float(rgba, projPixel->pixel.f_pt, rgba, mask); @@ -4922,8 +4986,9 @@ static void do_projectpaint_soften(ProjPaintState *ps, rgba[3] = alpha; premul_float_to_straight_uchar(rgba_ub, rgba); } - else + else { return; + } } else { premul_float_to_straight_uchar(rgba_ub, rgba); @@ -4983,8 +5048,9 @@ static void do_projectpaint_draw_f(ProjPaintState *ps, copy_v3_v3(rgba, ps->paint_color_linear); - if (ps->is_texbrush) + if (ps->is_texbrush) { mul_v3_v3(rgba, texrgb); + } mul_v3_fl(rgba, mask); rgba[3] = mask; @@ -5330,10 +5396,12 @@ static void *do_projectpaint_thread(void *ph_v) float mask_accum = *projPixel->mask_accum; float max_mask = brush_alpha * custom_mask * falloff * 65535.0f; - if (brush->flag & BRUSH_ACCUMULATE) + if (brush->flag & BRUSH_ACCUMULATE) { mask = mask_accum + max_mask; - else + } + else { mask = mask_accum + (max_mask - mask_accum * falloff); + } mask = min_ff(mask, 65535.0f); mask_short = (unsigned short)mask; @@ -5372,37 +5440,47 @@ static void *do_projectpaint_thread(void *ph_v) /* texrgb is not used for clone, smear or soften */ switch (tool) { case PAINT_TOOL_CLONE: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_clone_f(ps, projPixel, mask); - else + } + else { do_projectpaint_clone(ps, projPixel, mask); + } break; case PAINT_TOOL_SMEAR: sub_v2_v2v2(co, projPixel->projCoSS, pos_ofs); - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_smear_f(ps, projPixel, mask, smearArena, &smearPixels_f, co); - else + } + else { do_projectpaint_smear(ps, projPixel, mask, smearArena, &smearPixels, co); + } break; case PAINT_TOOL_SOFTEN: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_soften_f(ps, projPixel, mask, softenArena, &softenPixels_f); - else + } + else { do_projectpaint_soften(ps, projPixel, mask, softenArena, &softenPixels); + } break; case PAINT_TOOL_MASK: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_mask_f(ps, projPixel, mask); - else + } + else { do_projectpaint_mask(ps, projPixel, mask); + } break; default: - if (is_floatbuf) + if (is_floatbuf) { do_projectpaint_draw_f(ps, projPixel, texrgb, mask); - else + } + else { do_projectpaint_draw( ps, projPixel, texrgb, mask, ps->dither, projPixel->x_px, projPixel->y_px); + } break; } @@ -5476,8 +5554,9 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po return touch_any; } - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_threadpool_init(&threads, do_projectpaint_thread, ps->thread_tot); + } pool = BKE_image_pool_new(); @@ -5510,14 +5589,17 @@ static bool project_paint_op(void *state, const float lastpos[2], const float po handles[a].pool = pool; - if (ps->thread_tot > 1) + if (ps->thread_tot > 1) { BLI_threadpool_insert(&threads, &handles[a]); + } } - if (ps->thread_tot > 1) /* wait for everything to be done */ + if (ps->thread_tot > 1) { /* wait for everything to be done */ BLI_threadpool_end(&threads); - else + } + else { do_projectpaint_thread(&handles[0]); + } BKE_image_pool_free(pool); @@ -5582,8 +5664,9 @@ static void paint_proj_stroke_ps(const bContext *UNUSED(C), ps->brush_size = size; ps->blend = brush->blend; - if (eraser) + if (eraser) { ps->blend = IMB_BLEND_ERASE_ALPHA; + } /* handle gradient and inverted stroke color here */ if (ELEM(ps->tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) { @@ -5723,8 +5806,9 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int ps->do_backfacecull = ps->do_occlude = ps->do_mask_normal = 0; } - if (ps->tool == PAINT_TOOL_CLONE) + if (ps->tool == PAINT_TOOL_CLONE) { ps->do_layer_clone = (settings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) ? 1 : 0; + } ps->do_stencil_brush = (ps->brush && ps->brush->imagepaint_tool == PAINT_TOOL_MASK); /* deactivate stenciling for the stencil brush :) */ @@ -5827,8 +5911,9 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m } /* Don't allow brush size below 2 */ - if (BKE_brush_size_get(scene, ps_handle->brush) < 2) + if (BKE_brush_size_get(scene, ps_handle->brush) < 2) { BKE_brush_size_set(scene, ps_handle->brush, 2 * U.pixelsize); + } /* allocate and initialize spatial data structures */ @@ -6087,10 +6172,12 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) maxsize = GPU_max_texture_size(); - if (w > maxsize) + if (w > maxsize) { w = maxsize; - if (h > maxsize) + } + if (h > maxsize) { h = maxsize; + } ibuf = ED_view3d_draw_offscreen_imbuf(depsgraph, scene, @@ -6255,14 +6342,18 @@ bool BKE_paint_proj_mesh_data_check( } } - if (!hasuvs) + if (!hasuvs) { imapaint->missing_data |= IMAGEPAINT_MISSING_UVS; - if (!hasmat) + } + if (!hasmat) { imapaint->missing_data |= IMAGEPAINT_MISSING_MATERIAL; - if (!hastex) + } + if (!hastex) { imapaint->missing_data |= IMAGEPAINT_MISSING_TEX; - if (!hasstencil) + } + if (!hasstencil) { imapaint->missing_data |= IMAGEPAINT_MISSING_STENCIL; + } if (uvs) { *uvs = hasuvs; @@ -6386,8 +6477,9 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op) Material *ma; Image *ima = NULL; - if (!ob) + if (!ob) { return false; + } ma = give_current_material(ob, ob->actcol); diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index 4a4dbe364a0..79d09967b75 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -121,8 +121,9 @@ static void mask_flood_fill_task_cb(void *__restrict userdata, BKE_pbvh_vertex_iter_end; BKE_pbvh_node_mark_redraw(node); - if (data->multires) + if (data->multires) { BKE_pbvh_node_mark_normals_update(node); + } } static int mask_flood_fill_exec(bContext *C, wmOperator *op) @@ -166,13 +167,15 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) 0, totnode, &data, mask_flood_fill_task_cb, &settings); - if (multires) + if (multires) { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } sculpt_undo_push_end(); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } ED_region_tag_redraw(ar); @@ -217,18 +220,24 @@ static bool is_effected(float planes[4][4], const float co[3]) static void flip_plane(float out[4], const float in[4], const char symm) { - if (symm & PAINT_SYMM_X) + if (symm & PAINT_SYMM_X) { out[0] = -in[0]; - else + } + else { out[0] = in[0]; - if (symm & PAINT_SYMM_Y) + } + if (symm & PAINT_SYMM_Y) { out[1] = -in[1]; - else + } + else { out[1] = in[1]; - if (symm & PAINT_SYMM_Z) + } + if (symm & PAINT_SYMM_Z) { out[2] = -in[2]; - else + } + else { out[2] = in[2]; + } out[3] = in[3]; } @@ -257,8 +266,9 @@ static void mask_box_select_task_cb(void *__restrict userdata, sculpt_undo_push_node(data->ob, node, SCULPT_UNDO_MASK); BKE_pbvh_node_mark_redraw(node); - if (data->multires) + if (data->multires) { BKE_pbvh_node_mark_normals_update(node); + } } mask_flood_fill_set_elem(vi.mask, mode, value); } @@ -326,13 +336,15 @@ bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti * totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, mask_box_select_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } } - if (multires) + if (multires) { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } sculpt_undo_push_end(); @@ -417,8 +429,9 @@ static void mask_gesture_lasso_task_cb(void *__restrict userdata, sculpt_undo_push_node(data->ob, node, SCULPT_UNDO_MASK); BKE_pbvh_node_mark_redraw(node); - if (data->multires) + if (data->multires) { BKE_pbvh_node_mark_normals_update(node); + } } mask_flood_fill_set_elem(vi.mask, mode, value); @@ -511,13 +524,15 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) (totnode > SCULPT_THREADED_LIMIT)); BLI_task_parallel_range(0, totnode, &data, mask_gesture_lasso_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } } - if (multires) + if (multires) { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } sculpt_undo_push_end(); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 6686e255b08..e15912efdd4 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -168,8 +168,9 @@ static int brush_scale_size_exec(bContext *C, wmOperator *op) { float unprojected_radius = scalar * BKE_brush_unprojected_radius_get(scene, brush); - if (unprojected_radius < 0.001f) // XXX magic number + if (unprojected_radius < 0.001f) { // XXX magic number unprojected_radius = 0.001f; + } BKE_brush_unprojected_radius_set(scene, brush, unprojected_radius); } @@ -229,8 +230,9 @@ static bool palette_poll(bContext *C) { Paint *paint = BKE_paint_get_active_from_context(C); - if (paint && paint->palette != NULL) + if (paint && paint->palette != NULL) { return true; + } return false; } @@ -306,8 +308,9 @@ static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) Brush *brush = BKE_paint_brush(paint); Object *ob = CTX_data_active_object(C); - if (!ob || !brush) + if (!ob || !brush) { return OPERATOR_CANCELLED; + } /* TODO: other modes */ if (ob->mode & OB_MODE_SCULPT) { @@ -396,8 +399,9 @@ static Brush *brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, co * for one that is */ br = brush_tool_cycle(bmain, paint, brush_orig, tool); /* store the previously-selected brush */ - if (br) + if (br) { br->toggle_brush = brush_orig; + } return br; } @@ -406,8 +410,9 @@ static Brush *brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, co * back to the previously selected brush. */ return brush_orig->toggle_brush; } - else + else { return NULL; + } } static int brush_generic_tool_set(Main *bmain, @@ -628,12 +633,14 @@ static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *ev int mask = RNA_enum_get(op->ptr, "texmode"); if (mask) { - if (br->mask_mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) + if (br->mask_mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) { return OPERATOR_CANCELLED; + } } else { - if (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) + if (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) { return OPERATOR_CANCELLED; + } } scd = MEM_mallocN(sizeof(StencilControlData), "stencil_control"); @@ -695,10 +702,12 @@ static void stencil_control_calculate(StencilControlData *scd, const int mval[2] len = len_v2(mdiff); factor = len / scd->lenorig; copy_v2_v2(mdiff, scd->init_sdim); - if (scd->constrain_mode != STENCIL_CONSTRAINT_Y) + if (scd->constrain_mode != STENCIL_CONSTRAINT_Y) { mdiff[0] = factor * scd->init_sdim[0]; - if (scd->constrain_mode != STENCIL_CONSTRAINT_X) + } + if (scd->constrain_mode != STENCIL_CONSTRAINT_X) { mdiff[1] = factor * scd->init_sdim[1]; + } CLAMP(mdiff[0], 5.0f, 10000.0f); CLAMP(mdiff[1], 5.0f, 10000.0f); copy_v2_v2(scd->dim_target, mdiff); @@ -709,10 +718,12 @@ static void stencil_control_calculate(StencilControlData *scd, const int mval[2] sub_v2_v2v2(mdiff, mvalf, scd->pos_target); angle = atan2f(mdiff[1], mdiff[0]); angle = scd->init_rot + angle - scd->init_angle; - if (angle < 0.0f) + if (angle < 0.0f) { angle += (float)(2 * M_PI); - if (angle > (float)(2 * M_PI)) + } + if (angle > (float)(2 * M_PI)) { angle -= (float)(2 * M_PI); + } *scd->rot_target = angle; break; } @@ -744,20 +755,24 @@ static int stencil_control_modal(bContext *C, wmOperator *op, const wmEvent *eve case XKEY: if (event->val == KM_PRESS) { - if (scd->constrain_mode == STENCIL_CONSTRAINT_X) + if (scd->constrain_mode == STENCIL_CONSTRAINT_X) { scd->constrain_mode = 0; - else + } + else { scd->constrain_mode = STENCIL_CONSTRAINT_X; + } stencil_control_calculate(scd, event->mval); } break; case YKEY: if (event->val == KM_PRESS) { - if (scd->constrain_mode == STENCIL_CONSTRAINT_Y) + if (scd->constrain_mode == STENCIL_CONSTRAINT_Y) { scd->constrain_mode = 0; - else + } + else { scd->constrain_mode = STENCIL_CONSTRAINT_Y; + } stencil_control_calculate(scd, event->mval); } @@ -778,8 +793,9 @@ static bool stencil_control_poll(bContext *C) Paint *paint; Brush *br; - if (!paint_supports_texture(mode)) + if (!paint_supports_texture(mode)) { return false; + } paint = BKE_paint_get_active_from_context(C); br = BKE_paint_brush(paint); @@ -905,8 +921,9 @@ static int stencil_reset_transform_exec(bContext *C, wmOperator *op) Brush *br = BKE_paint_brush(paint); bool do_mask = RNA_boolean_get(op->ptr, "mask"); - if (!br) + if (!br) { return OPERATOR_CANCELLED; + } if (do_mask) { br->mask_stencil_pos[0] = 256; diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 8c1ba213ba0..9a46dab8c20 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -309,8 +309,9 @@ static bool paint_brush_update(bContext *C, do_random = true; } - if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) + if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) { BKE_brush_randomize_texture_coords(ups, false); + } else { copy_v2_v2(ups->tex_mouse, mouse); } @@ -325,8 +326,9 @@ static bool paint_brush_update(bContext *C, do_random_mask = true; } - if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) + if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) { BKE_brush_randomize_texture_coords(ups, true); + } else { copy_v2_v2(ups->mask_tex_mouse, mouse); } @@ -427,8 +429,9 @@ static bool paint_brush_update(bContext *C, location_success = true; *r_location_is_set = true; } - else if (!paint_tool_require_location(brush, mode)) + else if (!paint_tool_require_location(brush, mode)) { location_success = true; + } } else { zero_v3(r_location); @@ -506,8 +509,9 @@ static void paint_brush_stroke_add_step(bContext *C, float delta[2]; float factor = stroke->zoom_2d; - if (brush->flag & BRUSH_JITTER_PRESSURE) + if (brush->flag & BRUSH_JITTER_PRESSURE) { factor *= pressure; + } BKE_brush_jitter_pos(scene, brush, mouse_in, mouse_out); @@ -589,8 +593,9 @@ static float paint_space_stroke_spacing(const Scene *scene, float spacing = stroke->brush->spacing; /* apply spacing pressure */ - if (stroke->brush->flag & BRUSH_SPACING_PRESSURE) + if (stroke->brush->flag & BRUSH_SPACING_PRESSURE) { spacing = spacing * (1.5f - spacing_pressure); + } /* stroke system is used for 2d paint too, so we need to account for * the fact that brush can be scaled there. */ @@ -614,8 +619,9 @@ static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing) xx = fabsf(x0 + i * h); - if (xx < 1.0f) + if (xx < 1.0f) { sum += BKE_brush_curve_strength(br, xx, 1); + } } return sum; @@ -630,8 +636,9 @@ static float paint_stroke_integrate_overlap(Brush *br, float factor) float spacing = br->spacing * factor; - if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) + if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) { return 1.0; + } m = 10; g = 1.0f / m; @@ -639,14 +646,17 @@ static float paint_stroke_integrate_overlap(Brush *br, float factor) for (i = 0; i < m; i++) { float overlap = fabs(paint_stroke_overlapped_curve(br, i * g, spacing)); - if (overlap > max) + if (overlap > max) { max = overlap; + } } - if (max == 0.0f) + if (max == 0.0f) { return 1.0f; - else + } + else { return 1.0f / max; + } } static float paint_space_stroke_spacing_variable( @@ -774,8 +784,9 @@ PaintStroke *paint_stroke_new(bContext *C, /* initialize here to avoid initialization conflict with threaded strokes */ curvemapping_initialize(br->curve); - if (p->flags & PAINT_USE_CAVITY_MASK) + if (p->flags & PAINT_USE_CAVITY_MASK) { curvemapping_initialize(p->cavity_curve); + } BKE_paint_set_overlay_override(br->overlay_flags); @@ -797,18 +808,22 @@ static void stroke_done(struct bContext *C, struct wmOperator *op) ups->stroke_active = false; /* reset rotation here to avoid doing so in cursor display */ - if (!(stroke->brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) + if (!(stroke->brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) { ups->brush_rotation = 0.0f; + } - if (!(stroke->brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) + if (!(stroke->brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) { ups->brush_rotation_sec = 0.0f; + } if (stroke->stroke_started) { - if (stroke->redraw) + if (stroke->redraw) { stroke->redraw(C, stroke, true); + } - if (stroke->done) + if (stroke->done) { stroke->done(C, stroke); + } } if (stroke->timer) { @@ -819,8 +834,9 @@ static void stroke_done(struct bContext *C, struct wmOperator *op) BLI_rng_free(stroke->rng); } - if (stroke->stroke_cursor) + if (stroke->stroke_cursor) { WM_paint_cursor_end(CTX_wm_manager(C), stroke->stroke_cursor); + } BLI_freelistN(&stroke->line); @@ -845,13 +861,15 @@ static bool sculpt_is_grab_tool(Brush *br) /* return true if the brush size can change during paint (normally used for pressure) */ bool paint_supports_dynamic_size(Brush *br, ePaintMode mode) { - if (br->flag & BRUSH_ANCHORED) + if (br->flag & BRUSH_ANCHORED) { return false; + } switch (mode) { case PAINT_MODE_SCULPT: - if (sculpt_is_grab_tool(br)) + if (sculpt_is_grab_tool(br)) { return false; + } break; case PAINT_MODE_TEXTURE_2D: /* fall through */ @@ -876,8 +894,9 @@ bool paint_supports_smooth_stroke(Brush *br, ePaintMode mode) switch (mode) { case PAINT_MODE_SCULPT: - if (sculpt_is_grab_tool(br)) + if (sculpt_is_grab_tool(br)) { return false; + } break; default: break; @@ -895,13 +914,15 @@ bool paint_supports_texture(ePaintMode mode) /* return true if the brush size can change during paint (normally used for pressure) */ bool paint_supports_dynamic_tex_coords(Brush *br, ePaintMode mode) { - if (br->flag & BRUSH_ANCHORED) + if (br->flag & BRUSH_ANCHORED) { return false; + } switch (mode) { case PAINT_MODE_SCULPT: - if (sculpt_is_grab_tool(br)) + if (sculpt_is_grab_tool(br)) { return false; + } break; default: break; @@ -942,10 +963,12 @@ static void paint_stroke_add_sample( sample->pressure = pressure; stroke->cur_sample++; - if (stroke->cur_sample >= max_samples) + if (stroke->cur_sample >= max_samples) { stroke->cur_sample = 0; - if (stroke->num_samples < max_samples) + } + if (stroke->num_samples < max_samples) { stroke->num_samples++; + } } static void paint_stroke_sample_average(const PaintStroke *stroke, PaintSample *average) @@ -991,8 +1014,9 @@ static void paint_line_strokes_spacing(bContext *C, BLI_assert(length >= 0.0f); - if (length == 0.0f) + if (length == 0.0f) { return; + } while (length > 0.0f) { float spacing_final = spacing - *length_residue; @@ -1043,8 +1067,9 @@ static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *str float length_residue = 0.0f; int i; - if (!pc) + if (!pc) { return true; + } #ifdef DEBUG_TIME TIMEIT_START_AVERAGED(whole_stroke); @@ -1175,22 +1200,25 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) * this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it * since the 2D deltas are zero -- code in this file needs to be updated to use the * post-NDOF_MOTION MOUSEMOVE */ - if (event->type == NDOF_MOTION) + if (event->type == NDOF_MOTION) { return OPERATOR_PASS_THROUGH; + } #endif /* one time initialization */ if (!stroke->stroke_init) { - if (paint_stroke_curve_end(C, op, stroke)) + if (paint_stroke_curve_end(C, op, stroke)) { return OPERATOR_FINISHED; + } - if (paint_supports_smooth_stroke(br, mode)) + if (paint_supports_smooth_stroke(br, mode)) { stroke->stroke_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), SPACE_TYPE_ANY, RGN_TYPE_ANY, paint_poll, paint_draw_smooth_cursor, stroke); + } stroke->stroke_init = true; first_modal = true; @@ -1204,9 +1232,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) BLI_assert((stroke->stroke_started & ~1) == 0); /* 0/1 */ if (stroke->stroke_started) { - if (br->flag & BRUSH_AIRBRUSH) + if (br->flag & BRUSH_AIRBRUSH) { stroke->timer = WM_event_add_timer( CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate); + } if (br->flag & BRUSH_LINE) { stroke->stroke_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), @@ -1247,10 +1276,12 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_FINISHED; } else if (br->flag & BRUSH_LINE) { - if (event->alt) + if (event->alt) { stroke->constrain_line = true; - else + } + else { stroke->constrain_line = false; + } copy_v2_fl2(mouse, event->mval[0], event->mval[1]); paint_stroke_line_constrain(stroke, mouse); @@ -1274,8 +1305,9 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) if (paint_smooth_stroke(stroke, &sample_average, mode, mouse, &pressure)) { if (stroke->stroke_started) { if (paint_space_stroke_enabled(br, mode)) { - if (paint_space_stroke(C, op, mouse, pressure)) + if (paint_space_stroke(C, op, mouse, pressure)) { redraw = true; + } } else { float dmouse[2]; @@ -1303,11 +1335,13 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) ARegion *ar = CTX_wm_region(C); /* At the very least, invalidate the cursor */ - if (ar && (p->flags & PAINT_SHOW_BRUSH)) + if (ar && (p->flags & PAINT_SHOW_BRUSH)) { WM_paint_cursor_tag_redraw(window, ar); + } - if (redraw && stroke->redraw) + if (redraw && stroke->redraw) { stroke->redraw(C, stroke, false); + } } return OPERATOR_RUNNING_MODAL; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 098e38dbdb5..91a2ebd0603 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -93,8 +93,9 @@ bool paint_convert_bb_to_rect(rcti *rect, BLI_rcti_init_minmax(rect); /* return zero if the bounding box has non-positive volume */ - if (bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) + if (bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) { return 0; + } ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat); @@ -195,8 +196,9 @@ void paint_get_tex_pixel_col(const MTex *mtex, rgba[3] = 1.0f; } - if (convert_to_linear) + if (convert_to_linear) { IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, colorspace); + } linearrgb_to_srgb_v3_v3(rgba, rgba); @@ -382,8 +384,9 @@ static int imapaint_pick_face(ViewContext *vc, unsigned int *r_index, unsigned int totpoly) { - if (totpoly == 0) + if (totpoly == 0) { return 0; + } /* sample only on the exact position */ *r_index = ED_view3d_select_id_sample(vc, mval[0], mval[1]); @@ -410,18 +413,24 @@ static Image *imapaint_face_image(Object *ob, Mesh *me, int face_index) /* Uses symm to selectively flip any axis of a coordinate. */ void flip_v3_v3(float out[3], const float in[3], const char symm) { - if (symm & PAINT_SYMM_X) + if (symm & PAINT_SYMM_X) { out[0] = -in[0]; - else + } + else { out[0] = in[0]; - if (symm & PAINT_SYMM_Y) + } + if (symm & PAINT_SYMM_Y) { out[1] = -in[1]; - else + } + else { out[1] = in[1]; - if (symm & PAINT_SYMM_Z) + } + if (symm & PAINT_SYMM_Z) { out[2] = -in[2]; - else + } + else { out[2] = in[2]; + } } void flip_qt_qt(float out[4], const float in[4], const char symm) @@ -501,10 +510,12 @@ void paint_sample_color( if (imapaint_pick_face(&vc, mval, &faceindex, totpoly)) { Image *image; - if (use_material) + if (use_material) { image = imapaint_face_image(ob_eval, me_eval, faceindex); - else + } + else { image = imapaint->canvas; + } if (image) { ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); @@ -517,10 +528,12 @@ void paint_sample_color( u = fmodf(uv[0], 1.0f); v = fmodf(uv[1], 1.0f); - if (u < 0.0f) + if (u < 0.0f) { u += 1.0f; - if (v < 0.0f) + } + if (v < 0.0f) { v += 1.0f; + } u = u * ibuf->x; v = v * ibuf->y; @@ -563,8 +576,9 @@ void paint_sample_color( x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col); glReadBuffer(GL_BACK); } - else + else { return; + } } else { glReadBuffer(GL_FRONT); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index cc32d0a44f3..7852cd61ae1 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -312,16 +312,20 @@ static uint vpaint_blend(const VPaint *vp, for (a = 0; a < 4; a++) { if (ct[a] < co[a]) { - if (cp[a] < ct[a]) + if (cp[a] < ct[a]) { cp[a] = ct[a]; - else if (cp[a] > co[a]) + } + else if (cp[a] > co[a]) { cp[a] = co[a]; + } } else { - if (cp[a] < co[a]) + if (cp[a] < co[a]) { cp[a] = co[a]; - else if (cp[a] > ct[a]) + } + else if (cp[a] > ct[a]) { cp[a] = ct[a]; + } } } } @@ -400,12 +404,15 @@ static float wpaint_blend(const VPaint *wp, static float wpaint_clamp_monotonic(float oldval, float curval, float newval) { - if (newval < oldval) + if (newval < oldval) { return MIN2(newval, curval); - else if (newval > oldval) + } + else if (newval > oldval) { return MAX2(newval, curval); - else + } + else { return newval; + } } /* ----------------------------------------------------- */ @@ -1326,12 +1333,15 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) static bool paint_poll_test(bContext *C) { Object *ob = CTX_data_active_object(C); - if (ob == NULL || ob->type != OB_MESH) + if (ob == NULL || ob->type != OB_MESH) { return 0; - if (!ob->data || ID_IS_LINKED(ob->data)) + } + if (!ob->data || ID_IS_LINKED(ob->data)) { return 0; - if (CTX_data_edit_object(C)) + } + if (CTX_data_edit_object(C)) { return 0; + } return 1; } @@ -1399,20 +1409,24 @@ static void vwpaint_update_cache_invariants( } /* Initial mouse location */ - if (mouse) + if (mouse) { copy_v2_v2(cache->initial_mouse, mouse); - else + } + else { zero_v2(cache->initial_mouse); + } mode = RNA_enum_get(op->ptr, "mode"); cache->invert = mode == BRUSH_STROKE_INVERT; cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH; /* not very nice, but with current events system implementation * we can't handle brush appearance inversion hotkey separately (sergey) */ - if (cache->invert) + if (cache->invert) { ups->draw_inverted = true; - else + } + else { ups->draw_inverted = false; + } copy_v2_v2(cache->mouse, cache->initial_mouse); /* Truly temporary data that isn't stored in properties */ @@ -1669,8 +1683,9 @@ static void do_wpaint_precompute_weight_cb_ex(void *__restrict userdata, static void precompute_weight_values( bContext *C, Object *ob, Brush *brush, struct WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me) { - if (wpd->precomputed_weight_ready && !brush_use_accumulate_ex(brush, ob->mode)) + if (wpd->precomputed_weight_ready && !brush_use_accumulate_ex(brush, ob->mode)) { return; + } /* threaded loop over vertices */ SculptThreadedTaskData data = { @@ -1876,8 +1891,9 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata, const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; - if (final_alpha <= 0.0f) + if (final_alpha <= 0.0f) { continue; + } do_weight_paint_vertex( data->vp, data->ob, data->wpi, v_index, final_alpha, (float)weight_final); @@ -2160,8 +2176,9 @@ static void wpaint_do_paint(bContext *C, wpaint_paint_leaves(C, ob, sd, wp, wpd, wpi, me, nodes, totnode); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } static void wpaint_do_radial_symmetry(bContext *C, @@ -2310,8 +2327,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* previous is not set in the current cache else * the partial rect will always grow */ if (ss->cache) { - if (!BLI_rcti_is_empty(&ss->cache->previous_r)) + if (!BLI_rcti_is_empty(&ss->cache->previous_r)) { BLI_rcti_union(&r, &ss->cache->previous_r); + } } r.xmin += vc->ar->winrct.xmin - 2; @@ -2330,18 +2348,24 @@ static void wpaint_stroke_done(const bContext *C, struct PaintStroke *stroke) struct WPaintData *wpd = paint_stroke_mode_data(stroke); if (wpd) { - if (wpd->defbase_sel) + if (wpd->defbase_sel) { MEM_freeN((void *)wpd->defbase_sel); - if (wpd->vgroup_validmap) + } + if (wpd->vgroup_validmap) { MEM_freeN((void *)wpd->vgroup_validmap); - if (wpd->lock_flags) + } + if (wpd->lock_flags) { MEM_freeN((void *)wpd->lock_flags); - if (wpd->active.lock) + } + if (wpd->active.lock) { MEM_freeN((void *)wpd->active.lock); - if (wpd->mirror.lock) + } + if (wpd->mirror.lock) { MEM_freeN((void *)wpd->mirror.lock); - if (wpd->precomputed_weight) + } + if (wpd->precomputed_weight) { MEM_freeN(wpd->precomputed_weight); + } MEM_freeN(wpd); } @@ -2572,12 +2596,14 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f /* context checks could be a poll() */ me = BKE_mesh_from_object(ob); - if (me == NULL || me->totpoly == 0) + if (me == NULL || me->totpoly == 0) { return false; + } ED_mesh_color_ensure(me, NULL); - if (me->mloopcol == NULL) + if (me->mloopcol == NULL) { return false; + } /* make mode data storage */ vpd = MEM_callocN(sizeof(*vpd), "VPaintData"); @@ -3282,12 +3308,15 @@ static void vpaint_stroke_done(const bContext *C, struct PaintStroke *stroke) ED_vpaint_proj_handle_free(vpd->vp_handle); } - if (vpd->mlooptag) + if (vpd->mlooptag) { MEM_freeN(vpd->mlooptag); - if (vpd->smear.color_prev) + } + if (vpd->smear.color_prev) { MEM_freeN(vpd->smear.color_prev); - if (vpd->smear.color_curr) + } + if (vpd->smear.color_curr) { MEM_freeN(vpd->smear.color_curr); + } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c index 7df9ccc0e50..fed477ace14 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c @@ -82,8 +82,9 @@ static bool vertex_color_set(Object *ob, uint paintcol) for (i = 0; i < me->totpoly; i++, mp++) { MLoopCol *lcol = me->mloopcol + mp->loopstart; - if (use_face_sel && !(mp->flag & ME_FACE_SEL)) + if (use_face_sel && !(mp->flag & ME_FACE_SEL)) { continue; + } j = 0; do { @@ -220,8 +221,9 @@ static void vertex_color_smooth_looptag(Mesh *me, bool *mlooptag) /* if no mloopcol: do not do */ /* if mtexpoly: only the involved faces, otherwise all */ - if (me->mloopcol == NULL || me->totvert == 0 || me->totpoly == 0) + if (me->mloopcol == NULL || me->totvert == 0 || me->totpoly == 0) { return; + } scol = MEM_callocN(sizeof(int) * me->totvert * 5, "scol"); @@ -289,8 +291,9 @@ static bool vertex_color_smooth(Object *ob) const MLoop *ml = me->mloop + mp->loopstart; int ml_index = mp->loopstart; - if (use_face_sel && !(mp->flag & ME_FACE_SEL)) + if (use_face_sel && !(mp->flag & ME_FACE_SEL)) { continue; + } for (j = 0; j < mp->totloop; j++, ml_index++, ml++) { mlooptag[ml_index] = true; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 9ac44c5114d..5ae004fde5f 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -109,8 +109,9 @@ static bool sculpt_has_active_modifiers(Scene *scene, Object *ob) /* exception for shape keys because we can edit those */ for (; md; md = md->next) { - if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) + if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) { return 1; + } } return 0; @@ -394,17 +395,20 @@ static void paint_mesh_restore_co_task_cb(void *__restrict userdata, if (orig_data.unode->type == SCULPT_UNDO_COORDS) { copy_v3_v3(vd.co, orig_data.co); - if (vd.no) + if (vd.no) { copy_v3_v3_short(vd.no, orig_data.no); - else + } + else { normal_short_to_float_v3(vd.fno, orig_data.no); + } } else if (orig_data.unode->type == SCULPT_UNDO_MASK) { *vd.mask = orig_data.mask; } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } BKE_pbvh_vertex_iter_end; @@ -439,8 +443,9 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob) totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } /*** BVH Tree ***/ @@ -456,8 +461,9 @@ static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect) SculptSession *ss = ob->sculpt; if (ss->cache) { - if (!BLI_rcti_is_empty(&ss->cache->previous_r)) + if (!BLI_rcti_is_empty(&ss->cache->previous_r)) { BLI_rcti_union(rect, &ss->cache->previous_r); + } } } @@ -467,8 +473,9 @@ bool sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, Object *ob, rcti *r PBVH *pbvh = ob->sculpt->pbvh; float bb_min[3], bb_max[3]; - if (!pbvh) + if (!pbvh) { return 0; + } BKE_pbvh_redraw_BB(pbvh, bb_min, bb_max); @@ -497,8 +504,9 @@ void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, Object *ob) ob->sculpt->cache->previous_r = ob->sculpt->cache->current_r; /* clear redraw flag from nodes */ - if (pbvh) + if (pbvh) { BKE_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL); + } } /************************ Brush Testing *******************/ @@ -726,10 +734,12 @@ static float calc_overlap(StrokeCache *cache, const char symm, const char axis, /* distsq = len_squared_v3v3(mirror, cache->traced_location); */ distsq = len_squared_v3v3(mirror, cache->true_location); - if (distsq <= 4.0f * (cache->radius_squared)) + if (distsq <= 4.0f * (cache->radius_squared)) { return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache->radius)); - else + } + else { return 0; + } } static float calc_radial_symmetry_feather(Sculpt *sd, @@ -841,10 +851,12 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, normal_tri_v3(no, UNPACK3(co_tri)); flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f); - if (area_cos) + if (area_cos) { add_v3_v3(private_co[flip_index], co); - if (area_nos) + } + if (area_nos) { add_v3_v3(private_no[flip_index], no); + } private_count[flip_index] += 1; } } @@ -888,10 +900,12 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, } flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f); - if (area_cos) + if (area_cos) { add_v3_v3(private_co[flip_index], co); - if (area_nos) + } + if (area_nos) { add_v3_v3(private_no[flip_index], no); + } private_count[flip_index] += 1; } } @@ -1212,8 +1226,9 @@ float tex_strength(SculptSession *ss, flip_v3_v3(symm_point, point, cache->mirror_symmetry_pass); - if (cache->radial_symmetry_pass) + if (cache->radial_symmetry_pass) { mul_m4_v3(cache->symm_rot_mat_inv, symm_point); + } ED_view3d_project_float_v2_m4(cache->vc->ar, symm_point, point_2d, cache->projection_mat); @@ -1263,18 +1278,23 @@ bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v) float t[3], bb_min[3], bb_max[3]; int i; - if (data->original) + if (data->original) { BKE_pbvh_node_get_original_BB(node, bb_min, bb_max); - else + } + else { BKE_pbvh_node_get_BB(node, bb_min, bb_max); + } for (i = 0; i < 3; ++i) { - if (bb_min[i] > center[i]) + if (bb_min[i] > center[i]) { nearest[i] = bb_min[i]; - else if (bb_max[i] < center[i]) + } + else if (bb_max[i] < center[i]) { nearest[i] = bb_max[i]; - else + } + else { nearest[i] = center[i]; + } } sub_v3_v3v3(t, center, nearest); @@ -1288,10 +1308,12 @@ bool sculpt_search_circle_cb(PBVHNode *node, void *data_v) SculptSearchCircleData *data = data_v; float bb_min[3], bb_max[3]; - if (data->original) + if (data->original) { BKE_pbvh_node_get_original_BB(node, bb_min, bb_max); - else + } + else { BKE_pbvh_node_get_BB(node, bb_min, bb_min); + } float dummy_co[3], dummy_depth; const float dist_sq = dist_squared_ray_to_aabb_v3( @@ -1306,13 +1328,16 @@ static void sculpt_clip(Sculpt *sd, SculptSession *ss, float co[3], const float int i; for (i = 0; i < 3; ++i) { - if (sd->flags & (SCULPT_LOCK_X << i)) + if (sd->flags & (SCULPT_LOCK_X << i)) { continue; + } - if ((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->cache->clip_tolerance[i])) + if ((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->cache->clip_tolerance[i])) { co[i] = 0.0f; - else + } + else { co[i] = val[i]; + } } } @@ -1537,10 +1562,12 @@ static float neighbor_average_mask(SculptSession *ss, unsigned vert) } } - if (total > 0) + if (total > 0) { return avg / (float)total; - else + } + else { return vmask[vert]; + } } /* Same logic as neighbor_average(), but for bmesh rather than mesh */ @@ -1771,8 +1798,9 @@ static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -1825,8 +1853,9 @@ static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -1881,8 +1910,9 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -1924,20 +1954,24 @@ static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, grid_hidden = BKE_pbvh_grid_hidden(ss->pbvh); - if (smooth_mask) + if (smooth_mask) { tmpgrid_mask = (void *)(data_chunk + 1); - else + } + else { tmpgrid_co = (void *)(data_chunk + 1); + } for (i = 0; i < totgrid; i++) { int gi = grid_indices[i]; const BLI_bitmap *gh = grid_hidden[gi]; gddata = griddata[gi]; - if (smooth_mask) + if (smooth_mask) { memset(tmpgrid_mask, 0, data_chunk->tmpgrid_size); - else + } + else { memset(tmpgrid_co, 0, data_chunk->tmpgrid_size); + } for (y = 0; y < gridsize - 1; y++) { const int v = y * gridsize; @@ -1994,8 +2028,9 @@ static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, const int index = y * gridsize + x; if (gh) { - if (BLI_BITMAP_TEST(gh, index)) + if (BLI_BITMAP_TEST(gh, index)) { continue; + } } co = CCG_elem_offset_co(&key, gddata, index); @@ -2010,11 +2045,13 @@ static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, ss, brush, co, sqrtf(test.dist), NULL, fno, strength_mask, tls->thread_id); float f = 1.0f / 16.0f; - if (x == 0 || x == gridsize - 1) + if (x == 0 || x == gridsize - 1) { f *= 2.0f; + } - if (y == 0 || y == gridsize - 1) + if (y == 0 || y == gridsize - 1) { f *= 2.0f; + } if (smooth_mask) { *mask += ((tmpgrid_mask[index] * f) - *mask) * fade; @@ -2105,8 +2142,9 @@ static void smooth(Sculpt *sd, break; } - if (ss->multires) + if (ss->multires) { multires_stitch_grids(ob); + } } } @@ -2170,8 +2208,9 @@ static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, (*vd.mask) += fade * bstrength; CLAMP(*vd.mask, 0, 1); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } BKE_pbvh_vertex_iter_end; } @@ -2243,8 +2282,9 @@ static void do_draw_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], offset, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2334,8 +2374,9 @@ static void do_crease_brush_task_cb_ex(void *__restrict userdata, add_v3_v3v3(proxy[vd.i], val1, val2); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2362,15 +2403,17 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod * to give us the pinch strength. */ crease_correction = brush->crease_pinch_factor * brush->crease_pinch_factor; brush_alpha = BKE_brush_alpha_get(scene, brush); - if (brush_alpha > 0.0f) + if (brush_alpha > 0.0f) { crease_correction /= brush_alpha * brush_alpha; + } /* we always want crease to pinch or blob to relax even when draw is negative */ flippedbstrength = (bstrength < 0) ? -crease_correction * bstrength : crease_correction * bstrength; - if (brush->sculpt_tool == SCULPT_TOOL_BLOB) + if (brush->sculpt_tool == SCULPT_TOOL_BLOB) { flippedbstrength *= -1.0f; + } /* Use surface normal for 'spvc', * so the vertices are pinched towards a line instead of a single point. @@ -2431,8 +2474,9 @@ static void do_pinch_brush_task_cb_ex(void *__restrict userdata, } mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2493,8 +2537,9 @@ static void do_grab_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], grab_delta, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2559,8 +2604,9 @@ static void do_nudge_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], cono, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2666,8 +2712,9 @@ static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, add_v3_v3(proxy[vd.i], delta_rotate); } - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2684,8 +2731,9 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); - if (bstrength < 0) + if (bstrength < 0) { negate_v3(grab_delta); + } if (ss->cache->normal_weight > 0.0f) { sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta); @@ -2749,8 +2797,9 @@ static void do_thumb_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], cono, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2825,8 +2874,9 @@ static void do_rotate_brush_task_cb_ex(void *__restrict userdata, add_v3_v3(proxy[vd.i], ss->cache->location); sub_v3_v3(proxy[vd.i], orig_data.co); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2902,8 +2952,9 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata, *disp += fade; /* Don't let the displacement go past the limit */ - if ((lim < 0.0f && *disp < lim) || (lim >= 0.0f && *disp > lim)) + if ((lim < 0.0f && *disp < lim) || (lim >= 0.0f && *disp > lim)) { *disp = lim; + } mul_v3_v3fl(val, offset, *disp); @@ -2919,8 +2970,9 @@ static void do_layer_brush_task_cb_ex(void *__restrict userdata, sculpt_clip(sd, ss, vd.co, val); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -2982,16 +3034,19 @@ static void do_inflate_brush_task_cb_ex(void *__restrict userdata, tls->thread_id); float val[3]; - if (vd.fno) + if (vd.fno) { copy_v3_v3(val, vd.fno); - else + } + else { normal_short_to_float_v3(val, vd.no); + } mul_v3_fl(val, fade * ss->cache->radius); mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -3054,8 +3109,9 @@ static void calc_sculpt_plane( /* for flatten center */ /* flatten center has not been calculated yet if we are not using the area normal */ - if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) + if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) { calc_area_center(sd, ob, nodes, totnode, r_area_co); + } /* for area normal */ copy_v3_v3(ss->cache->sculpt_normal, r_area_no); @@ -3096,8 +3152,9 @@ static int plane_trim(const StrokeCache *cache, const Brush *brush, const float static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip) { float d = plane_point_side_v3(plane, co); - if (flip) + if (flip) { d = -d; + } return d <= 0.0f; } @@ -3164,8 +3221,9 @@ static void do_flatten_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3257,8 +3315,9 @@ static void do_clay_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3353,8 +3412,9 @@ static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3383,14 +3443,17 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t calc_sculpt_plane(sd, ob, nodes, totnode, area_no_sp, area_co); - if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) + if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) { calc_area_normal(sd, ob, nodes, totnode, area_no); - else + } + else { copy_v3_v3(area_no, area_no_sp); + } /* delay the first daub because grab delta is not setup */ - if (ss->cache->first_time) + if (ss->cache->first_time) { return; + } mul_v3_v3v3(temp, area_no_sp, ss->cache->scale); mul_v3_fl(temp, displace); @@ -3473,8 +3536,9 @@ static void do_fill_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3564,8 +3628,9 @@ static void do_scrape_brush_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], val, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } } @@ -3643,8 +3708,9 @@ static void do_gravity_task_cb_ex(void *__restrict userdata, mul_v3_v3fl(proxy[vd.i], offset, fade); - if (vd.mvert) + if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; + } } } BKE_pbvh_vertex_iter_end; @@ -3710,8 +3776,9 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) if (kb == me->key->refkey) { MVert *mvert = me->mvert; - for (a = 0; a < me->totvert; a++, mvert++) + for (a = 0; a < me->totvert; a++, mvert++) { copy_v3_v3(mvert->co, vertCos[a]); + } BKE_mesh_calc_normals(me); } @@ -3825,11 +3892,13 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings); - if (sculpt_brush_needs_normal(ss, brush)) + if (sculpt_brush_needs_normal(ss, brush)) { update_sculpt_normal(sd, ob, nodes, totnode); + } - if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) + if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) { update_brush_local_mat(sd, ob); + } /* Apply one type of brush action */ switch (brush->sculpt_tool) { @@ -3904,8 +3973,9 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe bmesh_topology_rake(sd, ob, nodes, totnode, brush->topology_rake_factor); } - if (ss->cache->supports_gravity) + if (ss->cache->supports_gravity) { do_gravity(sd, ob, nodes, totnode, sd->gravity_factor); + } MEM_freeN(nodes); @@ -3935,8 +4005,9 @@ static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd) copy_v3_v3(ss->deform_cos[index], vd->co); copy_v3_v3(ss->orig_cos[index], newco); - if (!ss->kb) + if (!ss->kb) { copy_v3_v3(me->mvert[index].co, newco); + } } static void sculpt_combine_proxies_task_cb(void *__restrict userdata, @@ -3957,8 +4028,9 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata, int proxy_count; float(*orco)[3] = NULL; - if (use_orco && !ss->bm) + if (use_orco && !ss->bm) { orco = sculpt_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS)->co; + } BKE_pbvh_node_get_proxies(data->nodes[n], &proxies, &proxy_count); @@ -3979,13 +4051,15 @@ static void sculpt_combine_proxies_task_cb(void *__restrict userdata, copy_v3_v3(val, vd.co); } - for (p = 0; p < proxy_count; p++) + for (p = 0; p < proxy_count; p++) { add_v3_v3(val, proxies[p].co[vd.i]); + } sculpt_clip(sd, ss, vd.co, val); - if (ss->modifiers_active) + if (ss->modifiers_active) { sculpt_flush_pbvhvert_deform(ob, &vd); + } } BKE_pbvh_vertex_iter_end; @@ -4016,8 +4090,9 @@ static void sculpt_combine_proxies(Sculpt *sd, Object *ob) BLI_task_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings); } - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } /* copy the modified vertices from bvh to the active key */ @@ -4028,16 +4103,19 @@ static void sculpt_update_keyblock(Object *ob) /* Keyblock update happens after handling deformation caused by modifiers, * so ss->orig_cos would be updated with new stroke */ - if (ss->orig_cos) + if (ss->orig_cos) { vertCos = ss->orig_cos; - else + } + else { vertCos = BKE_pbvh_get_vertCos(ss->pbvh); + } if (vertCos) { sculpt_vertcos_to_key(ob, ss->kb, vertCos); - if (vertCos != ss->orig_cos) + if (vertCos != ss->orig_cos) { MEM_freeN(vertCos); + } } } @@ -4197,8 +4275,9 @@ static void do_tiled( start[dim] = (bbMin[dim] - orgLoc[dim] - radius) / step[dim]; end[dim] = (bbMax[dim] - orgLoc[dim] + radius) / step[dim]; } - else + else { start[dim] = end[dim] = 0; + } } /* first do the "untiled" position to initialize the stroke for this location */ @@ -4210,8 +4289,9 @@ static void do_tiled( for (cur[0] = start[0]; cur[0] <= end[0]; ++cur[0]) { for (cur[1] = start[1]; cur[1] <= end[1]; ++cur[1]) { for (cur[2] = start[2]; cur[2] <= end[2]; ++cur[2]) { - if (!cur[0] && !cur[1] && !cur[2]) + if (!cur[0] && !cur[1] && !cur[2]) { continue; /* skip tile at orgLoc, this was already handled before all others */ + } ++cache->tile_pass; @@ -4254,8 +4334,9 @@ static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob) Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; - if (ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) + if (ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) { multires_stitch_grids(ob); + } } static void do_symmetrical_brush_actions(Sculpt *sd, @@ -4390,8 +4471,9 @@ static const char *sculpt_tool_name(Sculpt *sd) void sculpt_cache_free(StrokeCache *cache) { - if (cache->dial) + if (cache->dial) { MEM_freeN(cache->dial); + } MEM_freeN(cache); } @@ -4463,10 +4545,12 @@ static void sculpt_update_cache_invariants( sculpt_init_mirror_clipping(ob, ss); /* Initial mouse location */ - if (mouse) + if (mouse) { copy_v2_v2(cache->initial_mouse, mouse); - else + } + else { zero_v2(cache->initial_mouse); + } mode = RNA_enum_get(op->ptr, "mode"); cache->invert = mode == BRUSH_STROKE_INVERT; @@ -4483,10 +4567,12 @@ static void sculpt_update_cache_invariants( /* not very nice, but with current events system implementation * we can't handle brush appearance inversion hotkey separately (sergey) */ - if (cache->invert) + if (cache->invert) { ups->draw_inverted = true; - else + } + else { ups->draw_inverted = false; + } /* Alt-Smooth */ if (cache->alt_smooth) { @@ -4557,8 +4643,9 @@ static void sculpt_update_cache_invariants( if (brush->sculpt_tool == SCULPT_TOOL_LAYER) { /* not supported yet for multires or dynamic topology */ if (!ss->multires && !ss->bm && !ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) { - if (!ss->layer_co) + if (!ss->layer_co) { ss->layer_co = MEM_mallocN(sizeof(float) * 3 * ss->totvert, "sculpt mesh vertices copy"); + } if (ss->deform_cos) { memcpy(ss->layer_co, ss->deform_cos, ss->totvert); @@ -4592,8 +4679,9 @@ static void sculpt_update_cache_invariants( cache->first_time = 1; #define PIXEL_INPUT_THRESHHOLD 5 - if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) + if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) { cache->dial = BLI_dial_initialize(cache->initial_mouse, PIXEL_INPUT_THRESHHOLD); + } #undef PIXEL_INPUT_THRESHHOLD } @@ -4620,8 +4708,9 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru if (cache->first_time) { copy_v3_v3(cache->orig_grab_location, cache->true_location); } - else if (tool == SCULPT_TOOL_SNAKE_HOOK) + else if (tool == SCULPT_TOOL_SNAKE_HOOK) { add_v3_v3(cache->true_location, cache->grab_delta); + } /* compute 3d coordinate at same z from original location + mouse */ mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location); @@ -4667,10 +4756,12 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru copy_v3_v3(cache->old_grab_location, grab_location); - if (tool == SCULPT_TOOL_GRAB) + if (tool == SCULPT_TOOL_GRAB) { copy_v3_v3(cache->anchored_location, cache->true_location); - else if (tool == SCULPT_TOOL_THUMB) + } + else if (tool == SCULPT_TOOL_THUMB) { copy_v3_v3(cache->anchored_location, cache->orig_grab_location); + } if (ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) { /* location stays the same for finding vertices in brush radius */ @@ -5186,8 +5277,9 @@ static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const f return 1; } - else + else { return 0; + } } static void sculpt_stroke_update_step(bContext *C, @@ -5256,8 +5348,9 @@ static void sculpt_brush_exit_tex(Sculpt *sd) Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; - if (mtex->tex && mtex->tex->nodetree) + if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); + } } static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke)) @@ -5298,20 +5391,23 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str BKE_pbvh_update(ss->pbvh, PBVH_UpdateOriginalBB, NULL); - if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) + if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { BKE_pbvh_bmesh_after_stroke(ss->pbvh); + } /* optimization: if there is locked key and active modifiers present in */ /* the stack, keyblock is updating at each step. otherwise we could update */ /* keyblock only when stroke is finished */ - if (ss->kb && !ss->modifiers_active) + if (ss->kb && !ss->modifiers_active) { sculpt_update_keyblock(ob); + } ss->partial_redraw = 0; /* try to avoid calling this, only for e.g. linked duplicates now */ - if (((Mesh *)ob->data)->id.us > 1) + if (((Mesh *)ob->data)->id.us > 1) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); } @@ -5436,8 +5532,9 @@ static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op)) SculptSession *ss = CTX_data_active_object(C)->sculpt; if (ss) { - if (ss->layer_co) + if (ss->layer_co) { MEM_freeN(ss->layer_co); + } ss->layer_co = NULL; } @@ -5765,8 +5862,9 @@ static enum eDynTopoWarnFlag sculpt_dynamic_topology_check(Scene *scene, Object /* exception for shape keys because we can edit those */ for (; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) + if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) { continue; + } if (mti->type == eModifierTypeType_Constructive) { flag |= DYNTOPO_WARN_MODIFIER; @@ -5945,8 +6043,9 @@ void ED_object_sculptmode_enter_ex(Main *bmain, const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd); - if (flush_recalc) + if (flush_recalc) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + } /* Create sculpt mode session data */ if (ob->sculpt) { @@ -6173,8 +6272,9 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op)) BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnodes); - if (!totnodes) + if (!totnodes) { return OPERATOR_CANCELLED; + } for (i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); @@ -6195,8 +6295,9 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op)) while (BKE_pbvh_bmesh_update_topology( ss->pbvh, PBVH_Collapse | PBVH_Subdivide, center, NULL, size, false, false)) { - for (i = 0; i < totnodes; i++) + for (i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); + } } MEM_freeN(nodes); diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 0b995860feb..c66c1d91a77 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -81,8 +81,9 @@ static UndoSculpt *sculpt_undo_get_nodes(void); static void update_cb(PBVHNode *node, void *rebuild) { BKE_pbvh_node_mark_update(node); - if (*((bool *)rebuild)) + if (*((bool *)rebuild)) { BKE_pbvh_node_mark_rebuild_draw(node); + } BKE_pbvh_node_fully_hidden_set(node, 0); } @@ -314,8 +315,9 @@ static bool sculpt_undo_restore_mask(bContext *C, SculptUndoNode *unode) for (j = 0; j < unode->totgrid; j++) { grid = grids[unode->grids[j]]; - for (i = 0; i < gridsize * gridsize; i++, mask++) + for (i = 0; i < gridsize * gridsize; i++, mask++) { SWAP(float, *CCG_elem_offset_mask(&key, grid, i), *mask); + } } } @@ -357,8 +359,9 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C, BLI_task_parallel_range( 0, totnode, nodes, sculpt_undo_bmesh_restore_generic_task_cb, &settings); - if (nodes) + if (nodes) { MEM_freeN(nodes); + } } else { sculpt_pbvh_clear(ob); @@ -483,18 +486,21 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, need_mask); - if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss)) + if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss)) { return; + } for (unode = lb->first; unode; unode = unode->next) { - if (!STREQ(unode->idname, ob->id.name)) + if (!STREQ(unode->idname, ob->id.name)) { continue; + } /* check if undo data matches current data well enough to * continue */ if (unode->maxvert) { - if (ss->totvert != unode->maxvert) + if (ss->totvert != unode->maxvert) { continue; + } } else if (unode->maxgrid && subdiv_ccg != NULL) { if ((subdiv_ccg->num_grids != unode->maxgrid) || @@ -508,16 +514,19 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) switch (unode->type) { case SCULPT_UNDO_COORDS: - if (sculpt_undo_restore_coords(C, unode)) + if (sculpt_undo_restore_coords(C, unode)) { update = true; + } break; case SCULPT_UNDO_HIDDEN: - if (sculpt_undo_restore_hidden(C, unode)) + if (sculpt_undo_restore_hidden(C, unode)) { rebuild = true; + } break; case SCULPT_UNDO_MASK: - if (sculpt_undo_restore_mask(C, unode)) + if (sculpt_undo_restore_mask(C, unode)) { update = true; + } break; case SCULPT_UNDO_DYNTOPO_BEGIN: @@ -548,10 +557,12 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) NULL); if (BKE_sculpt_multires_active(scene, ob)) { - if (rebuild) + if (rebuild) { multires_mark_as_modified(ob, MULTIRES_HIDDEN_MODIFIED); - else + } + else { multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); + } } tag_update |= ((Mesh *)ob->data)->id.us > 1; @@ -578,40 +589,52 @@ static void sculpt_undo_free_list(ListBase *lb) SculptUndoNode *unode = lb->first; while (unode != NULL) { SculptUndoNode *unode_next = unode->next; - if (unode->co) + if (unode->co) { MEM_freeN(unode->co); - if (unode->no) + } + if (unode->no) { MEM_freeN(unode->no); - if (unode->index) + } + if (unode->index) { MEM_freeN(unode->index); - if (unode->grids) + } + if (unode->grids) { MEM_freeN(unode->grids); - if (unode->orig_co) + } + if (unode->orig_co) { MEM_freeN(unode->orig_co); - if (unode->vert_hidden) + } + if (unode->vert_hidden) { MEM_freeN(unode->vert_hidden); + } if (unode->grid_hidden) { for (int i = 0; i < unode->totgrid; i++) { - if (unode->grid_hidden[i]) + if (unode->grid_hidden[i]) { MEM_freeN(unode->grid_hidden[i]); + } } MEM_freeN(unode->grid_hidden); } - if (unode->mask) + if (unode->mask) { MEM_freeN(unode->mask); + } if (unode->bm_entry) { BM_log_entry_drop(unode->bm_entry); } - if (unode->bm_enter_totvert) + if (unode->bm_enter_totvert) { CustomData_free(&unode->bm_enter_vdata, unode->bm_enter_totvert); - if (unode->bm_enter_totedge) + } + if (unode->bm_enter_totedge) { CustomData_free(&unode->bm_enter_edata, unode->bm_enter_totedge); - if (unode->bm_enter_totloop) + } + if (unode->bm_enter_totloop) { CustomData_free(&unode->bm_enter_ldata, unode->bm_enter_totloop); - if (unode->bm_enter_totpoly) + } + if (unode->bm_enter_totpoly) { CustomData_free(&unode->bm_enter_pdata, unode->bm_enter_totpoly); + } MEM_freeN(unode); @@ -665,10 +688,12 @@ static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, SculptUndoNode *unode unode->grid_hidden = MEM_mapallocN(sizeof(*unode->grid_hidden) * totgrid, "unode->grid_hidden"); for (i = 0; i < totgrid; i++) { - if (grid_hidden[grid_indices[i]]) + if (grid_hidden[grid_indices[i]]) { unode->grid_hidden[i] = MEM_dupallocN(grid_hidden[grid_indices[i]]); - else + } + else { unode->grid_hidden[i] = NULL; + } } } @@ -690,8 +715,9 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt unode->totvert = totvert; } - else + else { maxgrid = 0; + } /* we will use this while sculpting, is mapalloc slow to access then? */ @@ -704,10 +730,12 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt usculpt->undo_size = (sizeof(float[3]) + sizeof(short[3]) + sizeof(int)) * allvert; break; case SCULPT_UNDO_HIDDEN: - if (maxgrid) + if (maxgrid) { sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode); - else + } + else { unode->vert_hidden = BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden"); + } break; case SCULPT_UNDO_MASK: @@ -738,8 +766,9 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt unode->index = MEM_mapallocN(sizeof(int) * allvert, "SculptUndoNode.index"); } - if (ss->modifiers_active) + if (ss->modifiers_active) { unode->orig_co = MEM_callocN(allvert * sizeof(*unode->orig_co), "undoSculpt orig_cos"); + } return unode; } @@ -752,13 +781,16 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode) BKE_pbvh_vertex_iter_begin(ss->pbvh, unode->node, vd, PBVH_ITER_ALL) { copy_v3_v3(unode->co[vd.i], vd.co); - if (vd.no) + if (vd.no) { copy_v3_v3_short(unode->no[vd.i], vd.no); - else + } + else { normal_float_to_short_v3(unode->no[vd.i], vd.fno); + } - if (ss->modifiers_active) + if (ss->modifiers_active) { copy_v3_v3(unode->orig_co[vd.i], ss->orig_cos[unode->index[vd.i]]); + } } BKE_pbvh_vertex_iter_end; } @@ -944,10 +976,12 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType } /* store active shape key */ - if (ss->kb) + if (ss->kb) { BLI_strncpy(unode->shapeName, ss->kb->name, sizeof(ss->kb->name)); - else + } + else { unode->shapeName[0] = '\0'; + } BLI_thread_unlock(LOCK_CUSTOM1); @@ -973,8 +1007,9 @@ void sculpt_undo_push_end(void) unode->no = NULL; } - if (unode->node) + if (unode->node) { BKE_pbvh_node_layer_disp_free(unode->node); + } } /* We could remove this and enforce all callers run in an operator using 'OPTYPE_UNDO'. */ diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 826db204fd0..3cda90ea3f9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -144,8 +144,9 @@ static Brush *uv_sculpt_brush(bContext *C) Scene *scene = CTX_data_scene(C); ToolSettings *settings = scene->toolsettings; - if (!settings->uvsculpt) + if (!settings->uvsculpt) { return NULL; + } return BKE_paint_brush(&settings->uvsculpt->paint); } @@ -335,8 +336,9 @@ static void HC_relaxation_iteration_uv(BMEditMesh *em, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[i].element) + if (element->separate && element != sculptdata->uv[i].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -408,8 +410,9 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[i].element) + if (element->separate && element != sculptdata->uv[i].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -487,8 +490,9 @@ static void uv_sculpt_stroke_apply(bContext *C, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[i].element) + if (element->separate && element != sculptdata->uv[i].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -532,8 +536,9 @@ static void uv_sculpt_stroke_apply(bContext *C, MLoopUV *luv; BMLoop *l; - if (element->separate && element != sculptdata->uv[uvindex].element) + if (element->separate && element != sculptdata->uv[uvindex].element) { break; + } l = element->l; luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); @@ -708,8 +713,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm if (element->separate) { if (do_island_optimization && (element->island != island_index)) { /* skip this uv if not on the active island */ - for (; element->next && !(element->next->separate); element = element->next) + for (; element->next && !(element->next->separate); element = element->next) { ; + } continue; } @@ -737,8 +743,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm char *flag; /* Skip edge if not found(unlikely) or not on valid island */ - if (itmp1 == -1 || itmp2 == -1) + if (itmp1 == -1 || itmp2 == -1) { continue; + } offset1 = uniqueUv[itmp1]; offset2 = uniqueUv[itmp2]; @@ -905,8 +912,9 @@ static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, const wmEvent *ev uv_sculpt_stroke_apply(C, op, event, obedit); break; case TIMER: - if (event->customdata == data->timer) + if (event->customdata == data->timer) { uv_sculpt_stroke_apply(C, op, event, obedit); + } break; default: return OPERATOR_RUNNING_MODAL; |