2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-02-19 23:53:40 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-19 23:53:40 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: some of this file.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edsculpt
|
|
|
|
* \brief Functions to paint images in 2D and 3D.
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2016-05-14 10:00:52 +02:00
|
|
|
#include "BLT_translation.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
2011-03-03 18:53:07 +00:00
|
|
|
#include "DNA_brush_types.h"
|
2018-06-26 12:31:06 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "DNA_node_types.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_brush.h"
|
2017-12-07 15:36:26 +11:00
|
|
|
#include "BKE_colorband.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "BKE_context.h"
|
2019-05-14 17:28:13 +02:00
|
|
|
#include "BKE_image.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "BKE_main.h"
|
2014-07-21 12:02:05 +02:00
|
|
|
#include "BKE_material.h"
|
2018-06-26 12:31:06 +02:00
|
|
|
#include "BKE_mesh.h"
|
2011-03-03 18:53:07 +00:00
|
|
|
#include "BKE_node.h"
|
2009-08-17 04:40:59 +00:00
|
|
|
#include "BKE_paint.h"
|
2018-03-19 14:17:59 +01:00
|
|
|
#include "BKE_undo_system.h"
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2016-05-14 10:00:52 +02:00
|
|
|
#include "UI_interface.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "UI_view2d.h"
|
|
|
|
|
|
|
|
#include "ED_image.h"
|
2013-08-29 10:34:09 +00:00
|
|
|
#include "ED_object.h"
|
2014-06-23 21:59:34 +10:00
|
|
|
#include "ED_paint.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
2018-05-08 07:22:52 +02:00
|
|
|
#include "WM_message.h"
|
2018-05-23 08:20:46 +02:00
|
|
|
#include "WM_toolsystem.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "WM_types.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#include "GPU_draw.h"
|
2016-11-08 11:06:30 -05:00
|
|
|
#include "GPU_immediate.h"
|
2018-06-27 19:07:23 -06:00
|
|
|
#include "GPU_state.h"
|
2009-02-19 23:53:40 +00:00
|
|
|
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
#include "paint_intern.h"
|
|
|
|
|
2019-04-22 00:18:34 +10:00
|
|
|
/**
|
|
|
|
* This is a static resource for non-global access.
|
|
|
|
* Maybe it should be exposed as part of the paint operation,
|
|
|
|
* but for now just give a public interface.
|
2019-04-10 00:06:53 +10:00
|
|
|
*/
|
2009-02-19 23:53:40 +00:00
|
|
|
static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
|
|
|
|
|
2013-03-08 04:00:06 +00:00
|
|
|
ImagePaintPartialRedraw *get_imapaintpartial(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return &imapaintpartial;
|
2013-03-07 12:11:38 +00:00
|
|
|
}
|
|
|
|
|
2013-03-08 04:00:06 +00:00
|
|
|
void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
imapaintpartial = *ippr;
|
2013-03-07 12:11:38 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
/* Imagepaint Partial Redraw & Dirty Region */
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2013-12-05 22:28:14 +02:00
|
|
|
void ED_imapaint_clear_partial_redraw(void)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(&imapaintpartial, 0, sizeof(imapaintpartial));
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void imapaint_region_tiles(
|
|
|
|
ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th)
|
2013-04-30 06:07:42 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int srcx = 0, srcy = 0;
|
2013-04-30 06:07:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
|
2013-04-30 06:07:42 +00:00
|
|
|
|
2019-10-02 01:54:58 +10:00
|
|
|
*tw = ((x + w - 1) >> ED_IMAGE_UNDO_TILE_BITS);
|
|
|
|
*th = ((y + h - 1) >> ED_IMAGE_UNDO_TILE_BITS);
|
|
|
|
*tx = (x >> ED_IMAGE_UNDO_TILE_BITS);
|
|
|
|
*ty = (y >> ED_IMAGE_UNDO_TILE_BITS);
|
2013-04-30 06:07:42 +00:00
|
|
|
}
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
void ED_imapaint_dirty_region(
|
2020-03-04 14:40:21 +01:00
|
|
|
Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *tmpibuf = NULL;
|
|
|
|
int tilex, tiley, tilew, tileh, tx, ty;
|
|
|
|
int srcx = 0, srcy = 0;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_rectclip(ibuf, NULL, &x, &y, &srcx, &srcy, &w, &h);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (w == 0 || h == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-03-23 07:51:56 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!imapaintpartial.enabled) {
|
|
|
|
imapaintpartial.x1 = x;
|
|
|
|
imapaintpartial.y1 = y;
|
|
|
|
imapaintpartial.x2 = x + w;
|
|
|
|
imapaintpartial.y2 = y + h;
|
|
|
|
imapaintpartial.enabled = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
imapaintpartial.x1 = min_ii(imapaintpartial.x1, x);
|
|
|
|
imapaintpartial.y1 = min_ii(imapaintpartial.y1, y);
|
|
|
|
imapaintpartial.x2 = max_ii(imapaintpartial.x2, x + w);
|
|
|
|
imapaintpartial.y2 = max_ii(imapaintpartial.y2, y + h);
|
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
imapaint_region_tiles(ibuf, x, y, w, h, &tilex, &tiley, &tilew, &tileh);
|
2013-04-30 06:07:42 +00:00
|
|
|
|
2019-10-02 01:54:58 +10:00
|
|
|
ListBase *undo_tiles = ED_image_paint_tile_list_get();
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
for (ty = tiley; ty <= tileh; ty++) {
|
|
|
|
for (tx = tilex; tx <= tilew; tx++) {
|
2019-10-02 01:54:58 +10:00
|
|
|
ED_image_paint_tile_push(
|
2020-03-04 14:40:21 +01:00
|
|
|
undo_tiles, ima, ibuf, &tmpibuf, iuser, tx, ty, NULL, NULL, false, find_old);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-05-14 17:28:13 +02:00
|
|
|
BKE_image_mark_dirty(ima, ibuf);
|
2018-03-23 07:51:56 +01:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (tmpibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(tmpibuf);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
void imapaint_image_update(
|
|
|
|
SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (imapaintpartial.x1 != imapaintpartial.x2 && imapaintpartial.y1 != imapaintpartial.y2) {
|
|
|
|
IMB_partial_display_buffer_update_delayed(
|
|
|
|
ibuf, imapaintpartial.x1, imapaintpartial.y1, imapaintpartial.x2, imapaintpartial.y2);
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ibuf->mipmap[0]) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf->userflags |= IB_MIPMAP_INVALID;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* todo: should set_tpage create ->rect? */
|
|
|
|
if (texpaint || (sima && sima->lock)) {
|
|
|
|
int w = imapaintpartial.x2 - imapaintpartial.x1;
|
|
|
|
int h = imapaintpartial.y2 - imapaintpartial.y1;
|
|
|
|
if (w && h) {
|
|
|
|
/* Testing with partial update in uv editor too */
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
GPU_paint_update_image(image, iuser, imapaintpartial.x1, imapaintpartial.y1, w, h);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 15:07:57 +02:00
|
|
|
/* paint blur kernels. Projective painting enforces use of a 2x2 kernel due to lagging */
|
|
|
|
BlurKernel *paint_new_blur_kernel(Brush *br, bool proj)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i, j;
|
|
|
|
BlurKernel *kernel = MEM_mallocN(sizeof(BlurKernel), "blur kernel");
|
|
|
|
float radius;
|
|
|
|
int side;
|
|
|
|
eBlurKernelType type = br->blur_mode;
|
|
|
|
|
|
|
|
if (proj) {
|
|
|
|
radius = 0.5f;
|
|
|
|
|
|
|
|
side = kernel->side = 2;
|
|
|
|
kernel->side_squared = kernel->side * kernel->side;
|
|
|
|
kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
|
|
|
|
kernel->pixel_len = radius;
|
|
|
|
}
|
|
|
|
else {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (br->blur_kernel_radius <= 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
br->blur_kernel_radius = 1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
radius = br->blur_kernel_radius;
|
|
|
|
|
|
|
|
side = kernel->side = radius * 2 + 1;
|
|
|
|
kernel->side_squared = kernel->side * kernel->side;
|
|
|
|
kernel->wdata = MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data");
|
|
|
|
kernel->pixel_len = br->blur_kernel_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case KERNEL_BOX:
|
2019-04-22 09:19:45 +10:00
|
|
|
for (i = 0; i < kernel->side_squared; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
kernel->wdata[i] = 1.0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KERNEL_GAUSSIAN: {
|
|
|
|
/* at 3.0 standard deviations distance, kernel is about zero */
|
|
|
|
float standard_dev = radius / 3.0f;
|
|
|
|
|
|
|
|
/* make the necessary adjustment to the value for use in the normal distribution formula */
|
|
|
|
standard_dev = -standard_dev * standard_dev * 2;
|
|
|
|
|
|
|
|
for (i = 0; i < side; i++) {
|
|
|
|
for (j = 0; j < side; j++) {
|
|
|
|
float idist = radius - i;
|
|
|
|
float jdist = radius - j;
|
|
|
|
float value = exp((idist * idist + jdist * jdist) / standard_dev);
|
|
|
|
|
|
|
|
kernel->wdata[i + j * side] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("unidentified kernel type, aborting\n");
|
|
|
|
MEM_freeN(kernel->wdata);
|
|
|
|
MEM_freeN(kernel);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kernel;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void paint_delete_blur_kernel(BlurKernel *kernel)
|
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (kernel->wdata) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(kernel->wdata);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
/************************ image paint poll ************************/
|
|
|
|
|
|
|
|
static Brush *image_paint_brush(bContext *C)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ToolSettings *settings = scene->toolsettings;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_paint_brush(&settings->imapaint.paint);
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 12:03:56 +02:00
|
|
|
static bool image_paint_poll_ex(bContext *C, bool check_tool)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *obact;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!image_paint_brush(C)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
obact = CTX_data_active_object(C);
|
|
|
|
if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) {
|
|
|
|
if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SpaceImage *sima = CTX_wm_space_image(C);
|
|
|
|
|
|
|
|
if (sima) {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
if ((sima->mode == SI_MODE_PAINT) && region->regiontype == RGN_TYPE_WINDOW) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 12:03:56 +02:00
|
|
|
static bool image_paint_poll(bContext *C)
|
2018-05-01 11:42:25 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return image_paint_poll_ex(C, true);
|
2018-05-01 11:42:25 +02:00
|
|
|
}
|
|
|
|
|
2019-01-04 08:02:17 +11:00
|
|
|
static bool image_paint_poll_ignore_tool(bContext *C)
|
2018-05-01 11:42:25 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return image_paint_poll_ex(C, false);
|
2018-05-01 11:42:25 +02:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool image_paint_2d_clone_poll(bContext *C)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Brush *brush = image_paint_brush(C);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!CTX_wm_region_view3d(C) && image_paint_poll(C)) {
|
|
|
|
if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
|
|
|
|
if (brush->clone.image) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ paint operator ************************/
|
2017-10-17 13:43:10 +11:00
|
|
|
typedef enum eTexPaintMode {
|
2019-04-17 06:17:24 +02:00
|
|
|
PAINT_MODE_2D,
|
|
|
|
PAINT_MODE_3D_PROJECT,
|
2017-10-17 13:43:10 +11:00
|
|
|
} eTexPaintMode;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
typedef struct PaintOperation {
|
2019-04-17 06:17:24 +02:00
|
|
|
eTexPaintMode mode;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void *custom_paint;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float prevmouse[2];
|
|
|
|
float startmouse[2];
|
|
|
|
double starttime;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void *cursor;
|
|
|
|
ViewContext vc;
|
2009-02-19 23:53:40 +00:00
|
|
|
} PaintOperation;
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
bool paint_use_opacity_masking(Brush *brush)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((brush->flag & BRUSH_AIRBRUSH) || (brush->flag & BRUSH_DRAG_DOT) ||
|
|
|
|
(brush->flag & BRUSH_ANCHORED) || (brush->imagepaint_tool == PAINT_TOOL_SMEAR) ||
|
|
|
|
(brush->imagepaint_tool == PAINT_TOOL_SOFTEN) ||
|
|
|
|
(brush->imagepaint_tool == PAINT_TOOL_FILL) ||
|
|
|
|
(brush->flag & BRUSH_USE_GRADIENT) ||
|
|
|
|
(brush->mtex.tex && !ELEM(brush->mtex.brush_map_mode,
|
|
|
|
MTEX_MAP_MODE_TILED,
|
|
|
|
MTEX_MAP_MODE_STENCIL,
|
|
|
|
MTEX_MAP_MODE_3D)) ?
|
|
|
|
false :
|
|
|
|
true);
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void paint_brush_color_get(struct Scene *scene,
|
|
|
|
struct Brush *br,
|
|
|
|
bool color_correction,
|
|
|
|
bool invert,
|
|
|
|
float distance,
|
|
|
|
float pressure,
|
|
|
|
float color[3],
|
|
|
|
struct ColorManagedDisplay *display)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (invert) {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_v3_v3(color, BKE_brush_secondary_color_get(scene, br));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else {
|
|
|
|
if (br->flag & BRUSH_USE_GRADIENT) {
|
|
|
|
float color_gr[4];
|
|
|
|
switch (br->gradient_stroke_mode) {
|
|
|
|
case BRUSH_GRADIENT_PRESSURE:
|
|
|
|
BKE_colorband_evaluate(br->gradient, pressure, color_gr);
|
|
|
|
break;
|
|
|
|
case BRUSH_GRADIENT_SPACING_REPEAT: {
|
|
|
|
float coord = fmod(distance / br->gradient_spacing, 1.0);
|
|
|
|
BKE_colorband_evaluate(br->gradient, coord, color_gr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BRUSH_GRADIENT_SPACING_CLAMP: {
|
|
|
|
BKE_colorband_evaluate(br->gradient, distance / br->gradient_spacing, color_gr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
copy_v3_v3(color, color_gr);
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_v3_v3(color, BKE_brush_color_get(scene, br));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
if (color_correction) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_colormanagement_display_to_scene_linear_v3(color, display);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
void paint_brush_init_tex(Brush *brush)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* init mtex nodes */
|
|
|
|
if (brush) {
|
|
|
|
MTex *mtex = &brush->mtex;
|
|
|
|
if (mtex->tex && mtex->tex->nodetree) {
|
|
|
|
/* has internal flag to detect it only does it once */
|
|
|
|
ntreeTexBeginExecTree(mtex->tex->nodetree);
|
|
|
|
}
|
|
|
|
mtex = &brush->mask_mtex;
|
|
|
|
if (mtex->tex && mtex->tex->nodetree) {
|
|
|
|
ntreeTexBeginExecTree(mtex->tex->nodetree);
|
|
|
|
}
|
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
void paint_brush_exit_tex(Brush *brush)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (brush) {
|
|
|
|
MTex *mtex = &brush->mtex;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (mtex->tex && mtex->tex->nodetree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeTexEndExecTree(mtex->tex->nodetree->execdata);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
mtex = &brush->mask_mtex;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (mtex->tex && mtex->tex->nodetree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeTexEndExecTree(mtex->tex->nodetree->execdata);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-10 17:40:55 +00:00
|
|
|
}
|
2010-03-14 22:43:44 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customdata)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PaintOperation *pop = (PaintOperation *)customdata;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (pop) {
|
|
|
|
GPU_line_smooth(true);
|
|
|
|
GPU_blend(true);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPUVertFormat *format = immVertexFormat();
|
|
|
|
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
|
2016-11-08 11:06:30 -05:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = pop->vc.region;
|
2019-04-16 13:36:44 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
2016-11-08 11:06:30 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_line_width(4.0);
|
|
|
|
immUniformColor4ub(0, 0, 0, 255);
|
2016-11-08 11:06:30 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
|
|
|
immVertex2i(pos, x, y);
|
2020-03-06 16:56:42 +01:00
|
|
|
immVertex2i(
|
|
|
|
pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin);
|
2019-04-17 06:17:24 +02:00
|
|
|
immEnd();
|
2016-11-08 11:06:30 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_line_width(2.0);
|
|
|
|
immUniformColor4ub(255, 255, 255, 255);
|
2016-11-08 11:06:30 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
|
|
|
immVertex2i(pos, x, y);
|
2020-03-06 16:56:42 +01:00
|
|
|
immVertex2i(
|
|
|
|
pos, pop->startmouse[0] + region->winrct.xmin, pop->startmouse[1] + region->winrct.ymin);
|
2019-04-17 06:17:24 +02:00
|
|
|
immEnd();
|
2016-11-08 11:06:30 -05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
immUnbindProgram();
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_blend(false);
|
|
|
|
GPU_line_smooth(false);
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const float mouse[2])
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-09-18 17:19:07 +02:00
|
|
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ToolSettings *settings = scene->toolsettings;
|
|
|
|
PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
|
|
|
|
Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
|
|
|
|
int mode = RNA_enum_get(op->ptr, "mode");
|
2019-09-18 17:19:07 +02:00
|
|
|
ED_view3d_viewcontext_init(C, &pop->vc, depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
copy_v2_v2(pop->prevmouse, mouse);
|
|
|
|
copy_v2_v2(pop->startmouse, mouse);
|
|
|
|
|
|
|
|
/* initialize from context */
|
|
|
|
if (CTX_wm_region_view3d(C)) {
|
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
Object *ob = OBACT(view_layer);
|
|
|
|
bool uvs, mat, tex, stencil;
|
|
|
|
if (!BKE_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) {
|
|
|
|
BKE_paint_data_warning(op->reports, uvs, mat, tex, stencil);
|
|
|
|
MEM_freeN(pop);
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pop->mode = PAINT_MODE_3D_PROJECT;
|
|
|
|
pop->custom_paint = paint_proj_new_stroke(C, ob, mouse, mode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pop->mode = PAINT_MODE_2D;
|
|
|
|
pop->custom_paint = paint_2d_new_stroke(C, op, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pop->custom_paint) {
|
|
|
|
MEM_freeN(pop);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
|
|
|
|
pop->cursor = WM_paint_cursor_activate(CTX_wm_manager(C),
|
|
|
|
SPACE_TYPE_ANY,
|
|
|
|
RGN_TYPE_ANY,
|
|
|
|
image_paint_poll,
|
|
|
|
gradient_draw_line,
|
|
|
|
pop);
|
|
|
|
}
|
|
|
|
|
|
|
|
settings->imapaint.flag |= IMAGEPAINT_DRAWING;
|
|
|
|
ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_2D);
|
|
|
|
|
|
|
|
return pop;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PaintOperation *pop = paint_stroke_mode_data(stroke);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ToolSettings *toolsettings = CTX_data_tool_settings(C);
|
|
|
|
UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
|
|
|
|
Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
|
|
|
|
|
|
|
|
float alphafac = (brush->flag & BRUSH_ACCUMULATE) ? ups->overlap_factor : 1.0f;
|
|
|
|
|
|
|
|
/* initial brush values. Maybe it should be considered moving these to stroke system */
|
|
|
|
float startalpha = BKE_brush_alpha_get(scene, brush);
|
|
|
|
|
|
|
|
float mouse[2];
|
|
|
|
float pressure;
|
|
|
|
float size;
|
|
|
|
float distance = paint_stroke_distance_get(stroke);
|
|
|
|
int eraser;
|
|
|
|
|
|
|
|
RNA_float_get_array(itemptr, "mouse", mouse);
|
|
|
|
pressure = RNA_float_get(itemptr, "pressure");
|
|
|
|
eraser = RNA_boolean_get(itemptr, "pen_flip");
|
2019-10-07 19:34:15 +02:00
|
|
|
size = RNA_float_get(itemptr, "size");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* stroking with fill tool only acts on stroke end */
|
|
|
|
if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
|
|
|
|
copy_v2_v2(pop->prevmouse, mouse);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-27 02:02:18 +01:00
|
|
|
if (BKE_brush_use_alpha_pressure(brush)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac));
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) {
|
|
|
|
UndoStack *ustack = CTX_wm_manager(C)->undo_stack;
|
|
|
|
ED_image_undo_restore(ustack->step_init);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pop->mode == PAINT_MODE_3D_PROJECT) {
|
|
|
|
paint_proj_stroke(
|
|
|
|
C, pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_v2_v2(pop->prevmouse, mouse);
|
|
|
|
|
|
|
|
/* restore brush values */
|
|
|
|
BKE_brush_alpha_set(scene, brush, startalpha);
|
2013-05-15 14:37:05 +00:00
|
|
|
}
|
2013-03-10 17:40:55 +00:00
|
|
|
|
2013-05-15 14:37:05 +00:00
|
|
|
static void paint_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PaintOperation *pop = paint_stroke_mode_data(stroke);
|
|
|
|
|
|
|
|
if (pop->mode == PAINT_MODE_3D_PROJECT) {
|
|
|
|
paint_proj_redraw(C, pop->custom_paint, final);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_2d_redraw(C, pop->custom_paint, final);
|
|
|
|
}
|
2011-03-03 18:53:07 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ToolSettings *toolsettings = scene->toolsettings;
|
|
|
|
PaintOperation *pop = paint_stroke_mode_data(stroke);
|
|
|
|
Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
|
|
|
|
|
|
|
|
toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
|
|
|
|
|
|
|
|
if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
|
|
|
|
if (brush->flag & BRUSH_USE_GRADIENT) {
|
|
|
|
if (pop->mode == PAINT_MODE_2D) {
|
|
|
|
paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_proj_stroke(C,
|
|
|
|
pop->custom_paint,
|
|
|
|
pop->startmouse,
|
|
|
|
pop->prevmouse,
|
|
|
|
paint_stroke_flipped(stroke),
|
|
|
|
1.0,
|
|
|
|
0.0,
|
|
|
|
BKE_brush_size_get(scene, brush));
|
|
|
|
/* two redraws, one for GPU update, one for notification */
|
|
|
|
paint_proj_redraw(C, pop->custom_paint, false);
|
|
|
|
paint_proj_redraw(C, pop->custom_paint, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (pop->mode == PAINT_MODE_2D) {
|
|
|
|
float color[3];
|
|
|
|
if (paint_stroke_inverted(stroke)) {
|
|
|
|
srgb_to_linearrgb_v3_v3(color, BKE_brush_secondary_color_get(scene, brush));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
srgb_to_linearrgb_v3_v3(color, BKE_brush_color_get(scene, brush));
|
|
|
|
}
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
paint_2d_bucket_fill(C, color, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_proj_stroke(C,
|
|
|
|
pop->custom_paint,
|
|
|
|
pop->startmouse,
|
|
|
|
pop->prevmouse,
|
|
|
|
paint_stroke_flipped(stroke),
|
|
|
|
1.0,
|
|
|
|
0.0,
|
|
|
|
BKE_brush_size_get(scene, brush));
|
|
|
|
/* two redraws, one for GPU update, one for notification */
|
|
|
|
paint_proj_redraw(C, pop->custom_paint, false);
|
|
|
|
paint_proj_redraw(C, pop->custom_paint, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pop->mode == PAINT_MODE_3D_PROJECT) {
|
|
|
|
paint_proj_stroke_done(pop->custom_paint);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_2d_stroke_done(pop->custom_paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pop->cursor) {
|
|
|
|
WM_paint_cursor_end(CTX_wm_manager(C), pop->cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_image_undo_push_end();
|
|
|
|
|
|
|
|
/* duplicate warning, see texpaint_init */
|
2013-06-06 06:02:46 +00:00
|
|
|
#if 0
|
2019-05-31 23:21:16 +10:00
|
|
|
if (pop->s.warnmultifile) {
|
2019-04-17 08:24:14 +02:00
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Image requires 4 color channels to paint: %s",
|
|
|
|
pop->s.warnmultifile);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
|
|
|
if (pop->s.warnpackedfile) {
|
2019-04-17 08:24:14 +02:00
|
|
|
BKE_reportf(op->reports,
|
|
|
|
RPT_WARNING,
|
|
|
|
"Packed MultiLayer files cannot be painted: %s",
|
|
|
|
pop->s.warnpackedfile);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2013-06-06 06:02:46 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(pop);
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
static bool paint_stroke_test_start(bContext *C, wmOperator *op, const float mouse[2])
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PaintOperation *pop;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO Should avoid putting this here. Instead, last position should be requested
|
|
|
|
* from stroke system. */
|
2013-05-15 22:55:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!(pop = texture_paint_init(C, op, mouse))) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-17 04:24:22 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
paint_stroke_set_mode_data(op->customdata, pop);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int paint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
op->customdata = paint_stroke_new(C,
|
|
|
|
op,
|
|
|
|
NULL,
|
|
|
|
paint_stroke_test_start,
|
|
|
|
paint_stroke_update_step,
|
|
|
|
paint_stroke_redraw,
|
|
|
|
paint_stroke_done,
|
|
|
|
event->type);
|
|
|
|
|
|
|
|
if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
|
2019-09-28 23:32:51 +02:00
|
|
|
paint_stroke_free(C, op);
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
/* add modal handler */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
OPERATOR_RETVAL_CHECK(retval);
|
|
|
|
BLI_assert(retval == OPERATOR_RUNNING_MODAL);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-15 22:55:30 +00:00
|
|
|
static int paint_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PropertyRNA *strokeprop;
|
|
|
|
PointerRNA firstpoint;
|
|
|
|
float mouse[2];
|
|
|
|
|
|
|
|
strokeprop = RNA_struct_find_property(op->ptr, "stroke");
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
RNA_float_get_array(&firstpoint, "mouse", mouse);
|
|
|
|
|
|
|
|
op->customdata = paint_stroke_new(C,
|
|
|
|
op,
|
|
|
|
NULL,
|
|
|
|
paint_stroke_test_start,
|
|
|
|
paint_stroke_update_step,
|
|
|
|
paint_stroke_redraw,
|
|
|
|
paint_stroke_done,
|
|
|
|
0);
|
|
|
|
/* frees op->customdata */
|
|
|
|
return paint_stroke_exec(C, op);
|
2013-05-15 22:55:30 +00:00
|
|
|
}
|
2009-02-19 23:53:40 +00:00
|
|
|
|
|
|
|
void PAINT_OT_image_paint(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Image Paint";
|
|
|
|
ot->idname = "PAINT_OT_image_paint";
|
|
|
|
ot->description = "Paint a stroke into the image";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = paint_invoke;
|
|
|
|
ot->modal = paint_stroke_modal;
|
|
|
|
ot->exec = paint_exec;
|
|
|
|
ot->poll = image_paint_poll;
|
|
|
|
ot->cancel = paint_stroke_cancel;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
|
|
|
|
|
|
|
paint_stroke_operator_properties(ot);
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 01:25:23 +11:00
|
|
|
bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
|
2009-02-22 19:31:25 +00:00
|
|
|
{
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
|
|
|
if (area && area->spacetype == SPACE_IMAGE) {
|
|
|
|
SpaceImage *sima = area->spacedata.first;
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sima->mode == SI_MODE_PAINT) {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
|
|
|
ED_space_image_get_zoom(sima, region, zoomx, zoomy);
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2009-02-22 19:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*zoomx = *zoomy = 1;
|
2009-02-22 19:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2009-02-22 19:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ cursor drawing *******************************/
|
|
|
|
|
|
|
|
static void toggle_paint_cursor(bContext *C, int enable)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
ToolSettings *settings = scene->toolsettings;
|
|
|
|
|
|
|
|
if (settings->imapaint.paintcursor && !enable) {
|
|
|
|
WM_paint_cursor_end(wm, settings->imapaint.paintcursor);
|
|
|
|
settings->imapaint.paintcursor = NULL;
|
|
|
|
paint_cursor_delete_textures();
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else if (enable) {
|
2019-04-17 06:17:24 +02:00
|
|
|
paint_cursor_start(C, image_paint_poll);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-02-22 19:31:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-20 00:42:19 +00:00
|
|
|
/* enable the paint cursor if it isn't already.
|
2012-03-03 16:31:46 +00:00
|
|
|
*
|
|
|
|
* purpose is to make sure the paint cursor is shown if paint
|
|
|
|
* mode is enabled in the image editor. the paint poll will
|
|
|
|
* ensure that the cursor is hidden when not in paint mode */
|
2018-06-11 11:05:37 +02:00
|
|
|
void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene)
|
2010-10-20 00:42:19 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ToolSettings *settings = scene->toolsettings;
|
|
|
|
ImagePaintSettings *imapaint = &settings->imapaint;
|
|
|
|
bool enabled = false;
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bScreen *screen = WM_window_get_active_screen(win);
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
2020-04-03 13:25:03 +02:00
|
|
|
if (area->spacetype == SPACE_IMAGE) {
|
|
|
|
if (((SpaceImage *)area->spacedata.first)->mode == SI_MODE_PAINT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_2D, PAINT_CURSOR_TEXTURE_PAINT);
|
|
|
|
|
|
|
|
paint_cursor_start_explicit(&imapaint->paint, wm, image_paint_poll);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_cursor_delete_textures();
|
|
|
|
}
|
2010-10-20 00:42:19 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
/************************ grab clone operator ************************/
|
|
|
|
|
|
|
|
typedef struct GrabClone {
|
2019-04-17 06:17:24 +02:00
|
|
|
float startoffset[2];
|
|
|
|
int startx, starty;
|
2009-02-19 23:53:40 +00:00
|
|
|
} GrabClone;
|
|
|
|
|
|
|
|
static void grab_clone_apply(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Brush *brush = image_paint_brush(C);
|
|
|
|
float delta[2];
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_float_get_array(op->ptr, "delta", delta);
|
|
|
|
add_v2_v2(brush->clone.offset, delta);
|
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int grab_clone_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
grab_clone_apply(C, op);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int grab_clone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Brush *brush = image_paint_brush(C);
|
|
|
|
GrabClone *cmv;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
cmv = MEM_callocN(sizeof(GrabClone), "GrabClone");
|
|
|
|
copy_v2_v2(cmv->startoffset, brush->clone.offset);
|
|
|
|
cmv->startx = event->x;
|
|
|
|
cmv->starty = event->y;
|
|
|
|
op->customdata = cmv;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_modal_handler(C, op);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int grab_clone_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Brush *brush = image_paint_brush(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
GrabClone *cmv = op->customdata;
|
|
|
|
float startfx, startfy, fx, fy, delta[2];
|
2020-03-06 16:56:42 +01:00
|
|
|
int xmin = region->winrct.xmin, ymin = region->winrct.ymin;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case LEFTMOUSE:
|
|
|
|
case MIDDLEMOUSE:
|
|
|
|
case RIGHTMOUSE: // XXX hardcoded
|
|
|
|
MEM_freeN(op->customdata);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
case MOUSEMOVE:
|
|
|
|
/* mouse moved, so move the clone image */
|
|
|
|
UI_view2d_region_to_view(
|
2020-03-06 16:56:42 +01:00
|
|
|
®ion->v2d, cmv->startx - xmin, cmv->starty - ymin, &startfx, &startfy);
|
|
|
|
UI_view2d_region_to_view(®ion->v2d, event->x - xmin, event->y - ymin, &fx, &fy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
delta[0] = fx - startfx;
|
|
|
|
delta[1] = fy - startfy;
|
|
|
|
RNA_float_set_array(op->ptr, "delta", delta);
|
|
|
|
|
|
|
|
copy_v2_v2(brush->clone.offset, cmv->startoffset);
|
|
|
|
|
|
|
|
grab_clone_apply(C, op);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void grab_clone_cancel(bContext *UNUSED(C), wmOperator *op)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(op->customdata);
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_grab_clone(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Grab Clone";
|
|
|
|
ot->idname = "PAINT_OT_grab_clone";
|
|
|
|
ot->description = "Move the clone source image";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = grab_clone_exec;
|
|
|
|
ot->invoke = grab_clone_invoke;
|
|
|
|
ot->modal = grab_clone_modal;
|
|
|
|
ot->cancel = grab_clone_cancel;
|
|
|
|
ot->poll = image_paint_2d_clone_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_float_vector(ot->srna,
|
|
|
|
"delta",
|
|
|
|
2,
|
|
|
|
NULL,
|
|
|
|
-FLT_MAX,
|
|
|
|
FLT_MAX,
|
|
|
|
"Delta",
|
|
|
|
"Delta offset of clone image in 0.0..1.0 coordinates",
|
|
|
|
-1.0f,
|
|
|
|
1.0f);
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************** sample color operator ********************/
|
2013-10-11 02:23:20 +00:00
|
|
|
typedef struct {
|
2019-04-17 06:17:24 +02:00
|
|
|
bool show_cursor;
|
2020-01-21 02:52:20 +11:00
|
|
|
short launch_event;
|
2019-04-17 06:17:24 +02:00
|
|
|
float initcolor[3];
|
|
|
|
bool sample_palette;
|
|
|
|
} SampleColorData;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
static void sample_color_update_header(SampleColorData *data, bContext *C)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char msg[UI_MAX_DRAW_STR];
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 13:25:03 +02:00
|
|
|
if (area) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_snprintf(msg,
|
|
|
|
sizeof(msg),
|
2019-06-11 22:25:01 +02:00
|
|
|
TIP_("Sample color for %s"),
|
2019-04-17 06:17:24 +02:00
|
|
|
!data->sample_palette ?
|
2019-06-11 22:25:01 +02:00
|
|
|
TIP_("Brush. Use Left Click to sample for palette instead") :
|
|
|
|
TIP_("Palette. Use Left Click to sample more colors"));
|
2019-04-17 06:17:24 +02:00
|
|
|
ED_workspace_status_text(C, msg);
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
2013-10-11 02:23:20 +00:00
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
static int sample_color_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
const bool show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
|
|
|
|
int location[2];
|
|
|
|
paint->flags &= ~PAINT_SHOW_BRUSH;
|
2013-10-15 13:45:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* force redraw without cursor */
|
2020-03-06 16:56:42 +01:00
|
|
|
WM_paint_cursor_tag_redraw(win, region);
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_redraw_windows(C);
|
2013-10-15 13:45:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_int_get_array(op->ptr, "location", location);
|
|
|
|
const bool use_palette = RNA_boolean_get(op->ptr, "palette");
|
|
|
|
const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
|
|
|
|
!RNA_boolean_get(op->ptr, "merged");
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
paint_sample_color(C, region, location[0], location[1], use_sample_texture, use_palette);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (show_cursor) {
|
|
|
|
paint->flags |= PAINT_SHOW_BRUSH;
|
|
|
|
}
|
2013-10-15 13:45:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
|
|
|
SampleColorData *data = MEM_mallocN(sizeof(SampleColorData), "sample color custom data");
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
2013-10-11 02:23:20 +00:00
|
|
|
|
2020-01-21 02:52:20 +11:00
|
|
|
data->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0);
|
|
|
|
copy_v3_v3(data->initcolor, BKE_brush_color_get(scene, brush));
|
|
|
|
data->sample_palette = false;
|
|
|
|
op->customdata = data;
|
|
|
|
paint->flags &= ~PAINT_SHOW_BRUSH;
|
2013-10-11 02:23:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sample_color_update_header(data, C);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_modal_handler(C, op);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* force redraw without cursor */
|
2020-03-06 16:56:42 +01:00
|
|
|
WM_paint_cursor_tag_redraw(win, region);
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_redraw_windows(C);
|
2013-10-15 13:45:27 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_int_set_array(op->ptr, "location", event->mval);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
|
|
|
const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
|
|
|
|
!RNA_boolean_get(op->ptr, "merged");
|
2016-03-30 17:28:01 +11:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, false);
|
2019-09-26 14:31:48 +02:00
|
|
|
WM_cursor_modal_set(win, WM_CURSOR_EYEDROPPER);
|
2010-09-16 21:03:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2010-09-16 21:03:07 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2010-09-16 21:03:07 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
SampleColorData *data = op->customdata;
|
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
|
|
|
|
2020-01-21 02:52:20 +11:00
|
|
|
if ((event->type == data->launch_event) && (event->val == KM_RELEASE)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (data->show_cursor) {
|
|
|
|
paint->flags |= PAINT_SHOW_BRUSH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->sample_palette) {
|
|
|
|
BKE_brush_color_set(scene, brush, data->initcolor);
|
|
|
|
RNA_boolean_set(op->ptr, "palette", true);
|
|
|
|
}
|
|
|
|
WM_cursor_modal_restore(CTX_wm_window(C));
|
|
|
|
MEM_freeN(data);
|
|
|
|
ED_workspace_status_text(C, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
|
|
|
const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) &&
|
|
|
|
!RNA_boolean_get(op->ptr, "merged");
|
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case MOUSEMOVE: {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_int_set_array(op->ptr, "location", event->mval);
|
2020-03-06 16:56:42 +01:00
|
|
|
paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
if (event->val == KM_PRESS) {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_int_set_array(op->ptr, "location", event->mval);
|
2020-03-06 16:56:42 +01:00
|
|
|
paint_sample_color(C, region, event->mval[0], event->mval[1], use_sample_texture, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!data->sample_palette) {
|
|
|
|
data->sample_palette = true;
|
|
|
|
sample_color_update_header(data, C);
|
|
|
|
}
|
|
|
|
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 08:02:17 +11:00
|
|
|
static bool sample_color_poll(bContext *C)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (image_paint_poll_ignore_tool(C) || vertex_paint_poll_ignore_tool(C));
|
2019-01-04 08:02:17 +11:00
|
|
|
}
|
|
|
|
|
2009-02-19 23:53:40 +00:00
|
|
|
void PAINT_OT_sample_color(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Sample Color";
|
|
|
|
ot->idname = "PAINT_OT_sample_color";
|
|
|
|
ot->description = "Use the mouse to sample a color in the image";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = sample_color_exec;
|
|
|
|
ot->invoke = sample_color_invoke;
|
|
|
|
ot->modal = sample_color_modal;
|
|
|
|
ot->poll = sample_color_poll;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* properties */
|
|
|
|
PropertyRNA *prop;
|
2016-02-04 15:26:07 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
prop = RNA_def_int_vector(ot->srna, "location", 2, NULL, 0, INT_MAX, "Location", "", 0, 16384);
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
|
2016-02-04 15:26:07 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_def_boolean(ot->srna, "merged", 0, "Sample Merged", "Sample the output display color");
|
|
|
|
RNA_def_boolean(ot->srna, "palette", 0, "Add to Palette", "");
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************** texture paint toggle operator ********************/
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool texture_paint_toggle_poll(bContext *C)
|
2009-02-19 23:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ob == NULL || ob->type != OB_MESH) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (!ob->data || ID_IS_LINKED(ob->data)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (CTX_data_edit_object(C)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return 1;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct wmMsgBus *mbus = CTX_wm_message_bus(C);
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
const int mode_flag = OB_MODE_TEXTURE_PAINT;
|
|
|
|
const bool is_mode_set = (ob->mode & mode_flag) != 0;
|
|
|
|
|
|
|
|
if (!is_mode_set) {
|
|
|
|
if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->mode & mode_flag) {
|
|
|
|
ob->mode &= ~mode_flag;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (U.glreslimit != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_free_images(bmain);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_paint_set_mipmap(bmain, 1);
|
|
|
|
|
|
|
|
toggle_paint_cursor(C, 0);
|
|
|
|
}
|
|
|
|
else {
|
2020-04-03 14:23:21 +02:00
|
|
|
bScreen *screen;
|
2019-04-17 06:17:24 +02:00
|
|
|
Image *ima = NULL;
|
|
|
|
ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
|
|
|
|
|
|
|
|
/* This has to stay here to regenerate the texture paint
|
|
|
|
* cache in case we are loading a file */
|
|
|
|
BKE_texpaint_slots_refresh_object(scene, ob);
|
|
|
|
|
|
|
|
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/* entering paint mode also sets image to editors */
|
|
|
|
if (imapaint->mode == IMAGEPAINT_MODE_MATERIAL) {
|
|
|
|
/* set the current material active paint slot on image editor */
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, ob->actcol);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ma && ma->texpaintslot) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ima = ma->texpaintslot[ma->paint_active_slot].ima;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (imapaint->mode == IMAGEPAINT_MODE_IMAGE) {
|
|
|
|
ima = imapaint->canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ima) {
|
2020-04-03 14:23:21 +02:00
|
|
|
for (screen = bmain->screens.first; screen; screen = screen->id.next) {
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area;
|
2020-04-03 14:23:21 +02:00
|
|
|
for (area = screen->areabase.first; area; area = area->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
SpaceLink *sl;
|
2020-04-03 13:25:03 +02:00
|
|
|
for (sl = area->spacedata.first; sl; sl = sl->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sl->spacetype == SPACE_IMAGE) {
|
|
|
|
SpaceImage *sima = (SpaceImage *)sl;
|
|
|
|
|
|
|
|
if (!sima->pin) {
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
|
|
|
ED_space_image_set(bmain, sima, obedit, ima, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ob->mode |= mode_flag;
|
|
|
|
|
|
|
|
BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_3D, PAINT_CURSOR_TEXTURE_PAINT);
|
|
|
|
|
|
|
|
BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (U.glreslimit != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_free_images(bmain);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
GPU_paint_set_mipmap(bmain, 0);
|
|
|
|
|
|
|
|
toggle_paint_cursor(C, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Mesh *me = BKE_mesh_from_object(ob);
|
|
|
|
BLI_assert(me != NULL);
|
|
|
|
DEG_id_tag_update(&me->id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
|
|
|
|
|
|
|
|
WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
|
|
|
|
|
|
|
|
WM_toolsystem_update_from_context_view3d(C);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_texture_paint_toggle(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Texture Paint Toggle";
|
|
|
|
ot->idname = "PAINT_OT_texture_paint_toggle";
|
|
|
|
ot->description = "Toggle texture paint mode in 3D view";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = texture_paint_toggle_exec;
|
|
|
|
ot->poll = texture_paint_toggle_poll;
|
2009-02-19 23:53:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
2019-07-25 16:36:22 +02:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-02-19 23:53:40 +00:00
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
2019-07-30 15:37:45 +10:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
Brush *br = BKE_paint_brush(paint);
|
|
|
|
|
|
|
|
if (ups->flag & UNIFIED_PAINT_COLOR) {
|
|
|
|
swap_v3_v3(ups->rgb, ups->secondary_rgb);
|
|
|
|
}
|
|
|
|
else if (br) {
|
|
|
|
swap_v3_v3(br->rgb, br->secondary_rgb);
|
|
|
|
}
|
2019-07-30 15:37:45 +10:00
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, br);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool brush_colors_flip_poll(bContext *C)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (image_paint_poll(C)) {
|
|
|
|
Brush *br = image_paint_brush(C);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (ELEM(br->imagepaint_tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
if (ob != NULL) {
|
|
|
|
if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_TEXTURE_PAINT)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
2020-04-13 07:49:21 +02:00
|
|
|
ot->name = "Swap Colors";
|
2019-04-17 06:17:24 +02:00
|
|
|
ot->idname = "PAINT_OT_brush_colors_flip";
|
2020-04-13 07:49:21 +02:00
|
|
|
ot->description = "Swap primary and secondary brush colors";
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = brush_colors_flip_exec;
|
|
|
|
ot->poll = brush_colors_flip_poll;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
void ED_imapaint_bucket_fill(struct bContext *C,
|
|
|
|
float color[3],
|
|
|
|
wmOperator *op,
|
|
|
|
const int mouse[2])
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
SpaceImage *sima = CTX_wm_space_image(C);
|
2014-09-20 23:47:10 +02:00
|
|
|
|
2020-04-27 16:43:35 +10:00
|
|
|
if (sima && sima->image) {
|
|
|
|
Image *ima = sima->image;
|
2018-03-19 14:17:59 +01:00
|
|
|
|
2020-04-27 16:43:35 +10:00
|
|
|
ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_2D);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2020-04-27 16:43:35 +10:00
|
|
|
float mouse_init[2] = {mouse[0], mouse[1]};
|
|
|
|
paint_2d_bucket_fill(C, color, NULL, mouse_init, NULL, NULL);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2020-04-27 16:43:35 +10:00
|
|
|
ED_image_undo_push_end();
|
2014-09-20 23:47:10 +02:00
|
|
|
|
2020-04-27 16:43:35 +10:00
|
|
|
DEG_id_tag_update(&ima->id, 0);
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool texture_paint_poll(bContext *C)
|
2009-02-23 16:31:58 +00:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (texture_paint_toggle_poll(C)) {
|
|
|
|
if (CTX_data_active_object(C)->mode & OB_MODE_TEXTURE_PAINT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2009-02-23 16:31:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool image_texture_paint_poll(bContext *C)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (texture_paint_poll(C) || image_paint_poll(C));
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool facemask_paint_poll(bContext *C)
|
2009-11-01 00:06:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_paint_select_face_test(CTX_data_active_object(C));
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
2009-11-04 20:19:41 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool vert_paint_poll(bContext *C)
|
2011-07-12 19:06:06 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_paint_select_vert_test(CTX_data_active_object(C));
|
2011-07-12 19:06:06 +00:00
|
|
|
}
|
2011-09-18 17:10:28 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool mask_paint_poll(bContext *C)
|
2011-07-18 17:38:17 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_paint_select_elem_test(CTX_data_active_object(C));
|
2011-07-18 17:38:17 +00:00
|
|
|
}
|