Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_image_2d.c
| Show First 20 Lines • Show All 615 Lines • ▼ Show 20 Lines | if ((x1 < x2) && (0 < y1)) { | ||||
| brush_painter_imbuf_update(painter, tile, NULL, x1, 0, x2, y1, 0, 0); | brush_painter_imbuf_update(painter, tile, NULL, x1, 0, x2, y1, 0, 0); | ||||
| } | } | ||||
| if ((x1 < x2) && (y2 < ibuf->y)) { | if ((x1 < x2) && (y2 < ibuf->y)) { | ||||
| brush_painter_imbuf_update(painter, tile, NULL, x1, y2, x2, ibuf->y, 0, 0); | brush_painter_imbuf_update(painter, tile, NULL, x1, y2, x2, ibuf->y, 0, 0); | ||||
| } | } | ||||
| } | } | ||||
| static void brush_painter_2d_tex_mapping(ImagePaintState *s, | static void brush_painter_2d_tex_mapping(ImagePaintState *s, | ||||
| ImBuf *canvas, | ImagePaintTile *tile, | ||||
| const int diameter, | const int diameter, | ||||
| const float startpos[2], | |||||
| const float pos[2], | const float pos[2], | ||||
| const float mouse[2], | const float mouse[2], | ||||
| int mapmode, | int mapmode, | ||||
| rctf *mapping) | rctf *mapping) | ||||
| { | { | ||||
| float invw = 1.0f / (float)canvas->x; | float invw = 1.0f / (float)tile->canvas->x; | ||||
| float invh = 1.0f / (float)canvas->y; | float invh = 1.0f / (float)tile->canvas->y; | ||||
| int xmin, ymin, xmax, ymax; | float start[2]; | ||||
| int ipos[2]; | |||||
| /* find start coordinate of brush in canvas */ | /* find start coordinate of brush in canvas */ | ||||
| ipos[0] = (int)floorf((pos[0] - diameter / 2) + 1.0f); | start[0] = pos[0] - diameter / 2.0f; | ||||
| ipos[1] = (int)floorf((pos[1] - diameter / 2) + 1.0f); | start[1] = pos[1] - diameter / 2.0f; | ||||
| if (mapmode == MTEX_MAP_MODE_STENCIL) { | if (mapmode == MTEX_MAP_MODE_STENCIL) { | ||||
| /* map from view coordinates of brush to region coordinates */ | /* map from view coordinates of brush to region coordinates */ | ||||
| UI_view2d_view_to_region(s->v2d, ipos[0] * invw, ipos[1] * invh, &xmin, &ymin); | float xmin, ymin, xmax, ymax; | ||||
| UI_view2d_view_to_region( | UI_view2d_view_to_region_fl(s->v2d, start[0] * invw, start[1] * invh, &xmin, &ymin); | ||||
| s->v2d, (ipos[0] + diameter) * invw, (ipos[1] + diameter) * invh, &xmax, &ymax); | UI_view2d_view_to_region_fl( | ||||
| s->v2d, (start[0] + diameter) * invw, (start[1] + diameter) * invh, &xmax, &ymax); | |||||
| /* output mapping from brush ibuf x/y to region coordinates */ | /* output mapping from brush ibuf x/y to region coordinates */ | ||||
| mapping->xmin = xmin; | |||||
| mapping->ymin = ymin; | |||||
| mapping->xmax = (xmax - xmin) / (float)diameter; | mapping->xmax = (xmax - xmin) / (float)diameter; | ||||
| mapping->ymax = (ymax - ymin) / (float)diameter; | mapping->ymax = (ymax - ymin) / (float)diameter; | ||||
| mapping->xmin = xmin + (tile->uv_origin[0] * tile->size[0] * mapping->xmax); | |||||
| mapping->ymin = ymin + (tile->uv_origin[1] * tile->size[1] * mapping->ymax); | |||||
| } | } | ||||
| else if (mapmode == MTEX_MAP_MODE_3D) { | else if (mapmode == MTEX_MAP_MODE_3D) { | ||||
| /* 3D mapping, just mapping to canvas 0..1. */ | /* 3D mapping, just mapping to canvas 0..1. */ | ||||
| mapping->xmin = 2.0f * (ipos[0] * invw - 0.5f); | mapping->xmin = 2.0f * (start[0] * invw - 0.5f); | ||||
| mapping->ymin = 2.0f * (ipos[1] * invh - 0.5f); | mapping->ymin = 2.0f * (start[1] * invh - 0.5f); | ||||
| mapping->xmax = 2.0f * invw; | mapping->xmax = 2.0f * invw; | ||||
| mapping->ymax = 2.0f * invh; | mapping->ymax = 2.0f * invh; | ||||
| } | } | ||||
| else if (ELEM(mapmode, MTEX_MAP_MODE_VIEW, MTEX_MAP_MODE_RANDOM)) { | else if (ELEM(mapmode, MTEX_MAP_MODE_VIEW, MTEX_MAP_MODE_RANDOM)) { | ||||
| /* view mapping */ | /* view mapping */ | ||||
| mapping->xmin = mouse[0] - diameter * 0.5f + 0.5f; | mapping->xmin = mouse[0] - diameter * 0.5f + 0.5f; | ||||
| mapping->ymin = mouse[1] - diameter * 0.5f + 0.5f; | mapping->ymin = mouse[1] - diameter * 0.5f + 0.5f; | ||||
| mapping->xmax = 1.0f; | mapping->xmax = 1.0f; | ||||
| mapping->ymax = 1.0f; | mapping->ymax = 1.0f; | ||||
| } | } | ||||
| else /* if (mapmode == MTEX_MAP_MODE_TILED) */ { | else /* if (mapmode == MTEX_MAP_MODE_TILED) */ { | ||||
| mapping->xmin = (int)(-diameter * 0.5) + (int)floorf(pos[0]) - (int)floorf(startpos[0]); | mapping->xmin = (int)(-diameter * 0.5) + (int)floorf(pos[0]) - | ||||
| mapping->ymin = (int)(-diameter * 0.5) + (int)floorf(pos[1]) - (int)floorf(startpos[1]); | (int)floorf(tile->start_paintpos[0]); | ||||
| mapping->ymin = (int)(-diameter * 0.5) + (int)floorf(pos[1]) - | |||||
| (int)floorf(tile->start_paintpos[1]); | |||||
| mapping->xmax = 1.0f; | mapping->xmax = 1.0f; | ||||
| mapping->ymax = 1.0f; | mapping->ymax = 1.0f; | ||||
| } | } | ||||
| } | } | ||||
| static void brush_painter_2d_refresh_cache(ImagePaintState *s, | static void brush_painter_2d_refresh_cache(ImagePaintState *s, | ||||
| BrushPainter *painter, | BrushPainter *painter, | ||||
| ImagePaintTile *tile, | ImagePaintTile *tile, | ||||
| Show All 28 Lines | if (cache->is_texbrush) { | ||||
| } | } | ||||
| 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; | do_random = true; | ||||
| } | } | ||||
| else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) { | else if (!((brush->flag & BRUSH_ANCHORED) || update_color)) { | ||||
| do_partial_update = true; | do_partial_update = true; | ||||
| } | } | ||||
| brush_painter_2d_tex_mapping(s, | brush_painter_2d_tex_mapping( | ||||
| tile->canvas, | s, tile, diameter, pos, mouse, brush->mtex.brush_map_mode, &painter->tex_mapping); | ||||
| diameter, | |||||
| tile->start_paintpos, | |||||
| pos, | |||||
| mouse, | |||||
| brush->mtex.brush_map_mode, | |||||
| &painter->tex_mapping); | |||||
| } | } | ||||
| if (cache->is_maskbrush) { | if (cache->is_maskbrush) { | ||||
| bool renew_maxmask = false; | bool renew_maxmask = false; | ||||
| bool do_partial_update_mask = false; | bool do_partial_update_mask = false; | ||||
| /* invalidate case for all mapping modes */ | /* invalidate case for all mapping modes */ | ||||
| if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { | if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { | ||||
| mask_rotation += ups->brush_rotation_sec; | mask_rotation += ups->brush_rotation_sec; | ||||
| Show All 10 Lines | if (brush->mask_pressure) { | ||||
| do_partial_update_mask = false; | do_partial_update_mask = false; | ||||
| renew_maxmask = true; | renew_maxmask = true; | ||||
| } | } | ||||
| if (diameter != cache->lastdiameter || (mask_rotation != cache->last_mask_rotation) || | if (diameter != cache->lastdiameter || (mask_rotation != cache->last_mask_rotation) || | ||||
| renew_maxmask) { | renew_maxmask) { | ||||
| MEM_SAFE_FREE(cache->tex_mask); | MEM_SAFE_FREE(cache->tex_mask); | ||||
| brush_painter_2d_tex_mapping(s, | brush_painter_2d_tex_mapping( | ||||
| tile->canvas, | s, tile, diameter, pos, mouse, brush->mask_mtex.brush_map_mode, &painter->mask_mapping); | ||||
| diameter, | |||||
| tile->start_paintpos, | |||||
| pos, | |||||
| mouse, | |||||
| 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, tile, pos, diameter); | brush_painter_mask_imbuf_partial_update(painter, tile, pos, diameter); | ||||
| } | } | ||||
| else { | else { | ||||
| cache->tex_mask = brush_painter_mask_ibuf_new(painter, diameter); | cache->tex_mask = brush_painter_mask_ibuf_new(painter, diameter); | ||||
| } | } | ||||
| cache->last_mask_rotation = mask_rotation; | cache->last_mask_rotation = mask_rotation; | ||||
| ▲ Show 20 Lines • Show All 1,348 Lines • Show Last 20 Lines | |||||