2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* 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.
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/brush.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_brush_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 12:18:07 +00:00
|
|
|
#include "DNA_object_types.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2009-09-18 11:25:52 +00:00
|
|
|
#include "BLI_rand.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
|
|
|
|
#include "BKE_brush.h"
|
2009-01-10 19:34:23 +00:00
|
|
|
#include "BKE_colortools.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_library.h"
|
2016-07-10 15:49:01 +02:00
|
|
|
#include "BKE_library_query.h"
|
|
|
|
|
#include "BKE_library_remap.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
#include "BKE_main.h"
|
2009-08-17 04:40:59 +00:00
|
|
|
#include "BKE_paint.h"
|
2006-07-31 15:53:03 +00:00
|
|
|
#include "BKE_texture.h"
|
2010-07-14 14:11:03 +00:00
|
|
|
#include "BKE_icons.h"
|
2009-12-24 16:10:26 +00:00
|
|
|
|
2013-12-03 22:13:15 +06:00
|
|
|
#include "IMB_colormanagement.h"
|
2006-07-31 15:53:03 +00:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
|
|
|
|
#include "RE_render_ext.h" /* externtex */
|
|
|
|
|
|
2013-03-19 14:25:12 +00:00
|
|
|
static RNG *brush_rng;
|
|
|
|
|
|
2013-03-19 23:17:44 +00:00
|
|
|
void BKE_brush_system_init(void)
|
|
|
|
|
{
|
2013-03-19 14:25:12 +00:00
|
|
|
brush_rng = BLI_rng_new(0);
|
|
|
|
|
BLI_rng_srandom(brush_rng, 31415682);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-19 23:17:44 +00:00
|
|
|
void BKE_brush_system_exit(void)
|
|
|
|
|
{
|
2013-03-19 14:25:12 +00:00
|
|
|
BLI_rng_free(brush_rng);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
static void brush_defaults(Brush *brush)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
2010-07-27 16:09:02 +00:00
|
|
|
brush->blend = 0;
|
|
|
|
|
brush->flag = 0;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2010-11-03 21:23:02 +00:00
|
|
|
brush->ob_mode = OB_MODE_ALL_PAINT;
|
2010-08-04 12:18:07 +00:00
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
/* BRUSH SCULPT TOOL SETTINGS */
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->weight = 1.0f; /* weight of brush 0 - 1.0 */
|
|
|
|
|
brush->size = 35; /* radius of the brush in pixels */
|
|
|
|
|
brush->alpha = 0.5f; /* brush strength/intensity probably variable should be renamed? */
|
|
|
|
|
brush->autosmooth_factor = 0.0f;
|
|
|
|
|
brush->crease_pinch_factor = 0.5f;
|
2010-07-27 16:09:02 +00:00
|
|
|
brush->sculpt_plane = SCULPT_DISP_DIR_AREA;
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->plane_offset = 0.0f; /* how far above or below the plane that is found by averaging the faces */
|
|
|
|
|
brush->plane_trim = 0.5f;
|
|
|
|
|
brush->clone.alpha = 0.5f;
|
|
|
|
|
brush->normal_weight = 0.0f;
|
2014-07-21 12:02:05 +02:00
|
|
|
brush->fill_threshold = 0.2f;
|
2010-07-27 16:09:02 +00:00
|
|
|
brush->flag |= BRUSH_ALPHA_PRESSURE;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
|
|
|
|
/* BRUSH PAINT TOOL SETTINGS */
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->rgb[0] = 1.0f; /* default rgb color of the brush when painting - white */
|
|
|
|
|
brush->rgb[1] = 1.0f;
|
|
|
|
|
brush->rgb[2] = 1.0f;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
zero_v3(brush->secondary_rgb);
|
|
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
/* BRUSH STROKE SETTINGS */
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->flag |= (BRUSH_SPACE | BRUSH_SPACE_ATTEN);
|
|
|
|
|
brush->spacing = 10; /* how far each brush dot should be spaced as a percentage of brush diameter */
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->smooth_stroke_radius = 75;
|
|
|
|
|
brush->smooth_stroke_factor = 0.9f;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->rate = 0.1f; /* time delay between dots of paint or sculpting when doing airbrush mode */
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->jitter = 0.0f;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
/* BRUSH TEXTURE SETTINGS */
|
2015-03-29 03:16:55 +11:00
|
|
|
BKE_texture_mtex_default(&brush->mtex);
|
|
|
|
|
BKE_texture_mtex_default(&brush->mask_mtex);
|
2009-01-14 17:22:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->texture_sample_bias = 0; /* value to added to texture samples */
|
|
|
|
|
brush->texture_overlay_alpha = 33;
|
2013-04-16 15:59:02 +00:00
|
|
|
brush->mask_overlay_alpha = 33;
|
|
|
|
|
brush->cursor_overlay_alpha = 33;
|
|
|
|
|
brush->overlay_flags = 0;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
|
|
|
|
/* brush appearance */
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->add_col[0] = 1.00; /* add mode color is light red */
|
|
|
|
|
brush->add_col[1] = 0.39;
|
|
|
|
|
brush->add_col[2] = 0.39;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->sub_col[0] = 0.39; /* subtract mode color is light blue */
|
|
|
|
|
brush->sub_col[1] = 0.39;
|
|
|
|
|
brush->sub_col[2] = 1.00;
|
2013-03-31 00:38:50 +00:00
|
|
|
|
|
|
|
|
brush->stencil_pos[0] = 256;
|
|
|
|
|
brush->stencil_pos[1] = 256;
|
|
|
|
|
|
|
|
|
|
brush->stencil_dimension[0] = 256;
|
|
|
|
|
brush->stencil_dimension[1] = 256;
|
2010-07-27 16:09:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Datablock add/copy/free/make_local */
|
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_brush_init(Brush *brush)
|
2010-07-27 16:09:02 +00:00
|
|
|
{
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));
|
2010-07-27 16:09:02 +00:00
|
|
|
|
2010-08-04 12:18:07 +00:00
|
|
|
/* enable fake user by default */
|
2015-11-09 20:59:42 +01:00
|
|
|
id_fake_user_set(&brush->id);
|
2010-08-04 12:18:07 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_defaults(brush);
|
2010-07-27 16:09:02 +00:00
|
|
|
|
|
|
|
|
brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
/* the default alpha falloff curve */
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
|
|
|
|
|
{
|
|
|
|
|
Brush *brush;
|
|
|
|
|
|
|
|
|
|
brush = BKE_libblock_alloc(bmain, ID_BR, name);
|
|
|
|
|
|
|
|
|
|
BKE_brush_init(brush);
|
|
|
|
|
|
|
|
|
|
brush->ob_mode = ob_mode;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
|
|
|
|
return brush;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-31 21:37:38 +03:00
|
|
|
struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode)
|
|
|
|
|
{
|
|
|
|
|
Brush *brush;
|
|
|
|
|
|
|
|
|
|
for (brush = bmain->brush.first; brush; brush = brush->id.next) {
|
|
|
|
|
if (brush->ob_mode & ob_mode)
|
|
|
|
|
return brush;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-10 14:52:00 +02:00
|
|
|
Brush *BKE_brush_copy(Main *bmain, Brush *brush)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
|
|
|
|
Brush *brushn;
|
|
|
|
|
|
2016-07-10 14:52:00 +02:00
|
|
|
brushn = BKE_libblock_copy(bmain, &brush->id);
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2016-07-11 21:27:15 +02:00
|
|
|
if (brush->mtex.tex)
|
|
|
|
|
id_us_plus((ID *)brush->mtex.tex);
|
|
|
|
|
|
|
|
|
|
if (brush->mask_mtex.tex)
|
|
|
|
|
id_us_plus((ID *)brush->mask_mtex.tex);
|
|
|
|
|
|
|
|
|
|
if (brush->paint_curve)
|
|
|
|
|
id_us_plus((ID *)brush->paint_curve);
|
|
|
|
|
|
2010-07-20 13:42:27 +00:00
|
|
|
if (brush->icon_imbuf)
|
2012-05-06 15:15:33 +00:00
|
|
|
brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
|
2010-07-20 11:32:30 +00:00
|
|
|
|
2010-09-07 03:02:03 +00:00
|
|
|
brushn->preview = NULL;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brushn->curve = curvemapping_copy(brush->curve);
|
2009-03-10 23:38:16 +00:00
|
|
|
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
/* enable fake user by default */
|
2015-11-09 20:59:42 +01:00
|
|
|
id_fake_user_set(&brush->id);
|
|
|
|
|
|
2016-07-25 16:15:37 +02:00
|
|
|
BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id);
|
2015-01-09 09:52:51 +01:00
|
|
|
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
return brushn;
|
|
|
|
|
}
|
|
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
/** Free (or release) any data used by this brush (does not free the brush itself). */
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_free(Brush *brush)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
if (brush->icon_imbuf) {
|
2010-07-20 11:32:30 +00:00
|
|
|
IMB_freeImBuf(brush->icon_imbuf);
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
}
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2009-01-07 04:38:30 +00:00
|
|
|
curvemapping_free(brush->curve);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
MEM_SAFE_FREE(brush->gradient);
|
|
|
|
|
|
|
|
|
|
BKE_previewimg_free(&(brush->preview));
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-20 19:49:45 +02:00
|
|
|
void BKE_brush_make_local(Main *bmain, Brush *brush, const bool lib_local)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
2016-07-10 15:49:01 +02:00
|
|
|
bool is_local = false, is_lib = false;
|
2011-04-26 07:17:21 +00:00
|
|
|
|
2016-07-14 13:03:22 +02:00
|
|
|
/* - only lib users: do nothing (unless force_local is set)
|
2011-04-26 07:17:21 +00:00
|
|
|
* - only local users: set flag
|
|
|
|
|
* - mixed: make copy
|
|
|
|
|
*/
|
|
|
|
|
|
2016-07-10 15:49:01 +02:00
|
|
|
if (!ID_IS_LINKED_DATABLOCK(brush)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (brush->clone.image) {
|
2016-07-10 15:49:01 +02:00
|
|
|
/* Special case: ima always local immediately. Clone image should only have one user anyway. */
|
2016-07-14 13:03:22 +02:00
|
|
|
id_make_local(bmain, &brush->clone.image->id, false, false);
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2016-07-10 15:49:01 +02:00
|
|
|
BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);
|
|
|
|
|
|
2016-07-20 19:49:45 +02:00
|
|
|
if (lib_local || is_local) {
|
2016-07-10 15:49:01 +02:00
|
|
|
if (!is_lib) {
|
|
|
|
|
id_clear_lib_data(bmain, &brush->id);
|
2017-01-30 21:41:44 +01:00
|
|
|
BKE_id_expand_local(bmain, &brush->id);
|
2016-07-10 15:49:01 +02:00
|
|
|
|
|
|
|
|
/* enable fake user by default */
|
|
|
|
|
id_fake_user_set(&brush->id);
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
}
|
2016-07-10 15:49:01 +02:00
|
|
|
else {
|
|
|
|
|
Brush *brush_new = BKE_brush_copy(bmain, brush); /* Ensures FAKE_USER is set */
|
2010-07-20 11:32:30 +00:00
|
|
|
|
2016-07-10 15:49:01 +02:00
|
|
|
brush_new->id.us = 0;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2016-11-30 15:25:54 +01:00
|
|
|
/* setting newid is mandatory for complex make_lib_local logic... */
|
|
|
|
|
ID_NEW_SET(brush, brush_new);
|
|
|
|
|
|
2016-07-20 19:49:45 +02:00
|
|
|
if (!lib_local) {
|
|
|
|
|
BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
|
|
|
|
}
|
2011-04-26 07:17:21 +00:00
|
|
|
}
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_debug_print_state(Brush *br)
|
2010-07-27 16:09:02 +00:00
|
|
|
{
|
|
|
|
|
/* create a fake brush and set it to the defaults */
|
2012-05-06 15:15:33 +00:00
|
|
|
Brush def = {{NULL}};
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_defaults(&def);
|
2010-07-27 16:09:02 +00:00
|
|
|
|
|
|
|
|
#define BR_TEST(field, t) \
|
2012-03-24 06:18:31 +00:00
|
|
|
if (br->field != def.field) \
|
2010-07-27 16:09:02 +00:00
|
|
|
printf("br->" #field " = %" #t ";\n", br->field)
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
#define BR_TEST_FLAG(_f) \
|
2012-03-24 06:18:31 +00:00
|
|
|
if ((br->flag & _f) && !(def.flag & _f)) \
|
2012-05-06 15:15:33 +00:00
|
|
|
printf("br->flag |= " #_f ";\n"); \
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (!(br->flag & _f) && (def.flag & _f)) \
|
2010-07-27 16:09:02 +00:00
|
|
|
printf("br->flag &= ~" #_f ";\n")
|
|
|
|
|
|
2013-04-16 15:02:41 +00:00
|
|
|
#define BR_TEST_FLAG_OVERLAY(_f) \
|
|
|
|
|
if ((br->overlay_flags & _f) && !(def.overlay_flags & _f)) \
|
|
|
|
|
printf("br->overlay_flags |= " #_f ";\n"); \
|
|
|
|
|
else if (!(br->overlay_flags & _f) && (def.overlay_flags & _f)) \
|
|
|
|
|
printf("br->overlay_flags &= ~" #_f ";\n")
|
2010-07-27 16:09:02 +00:00
|
|
|
|
|
|
|
|
/* print out any non-default brush state */
|
|
|
|
|
BR_TEST(normal_weight, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(blend, d);
|
|
|
|
|
BR_TEST(size, d);
|
|
|
|
|
|
|
|
|
|
/* br->flag */
|
|
|
|
|
BR_TEST_FLAG(BRUSH_AIRBRUSH);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_ALPHA_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_SIZE_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_JITTER_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_SPACING_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_ANCHORED);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_DIR_IN);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_SPACE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_SMOOTH_STROKE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_PERSISTENT);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_ACCUMULATE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_LOCK_ALPHA);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_ORIGINAL_NORMAL);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_OFFSET_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_SPACE_ATTEN);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_ADAPTIVE_SPACE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_LOCK_SIZE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_EDGE_TO_EDGE);
|
2013-12-09 22:36:33 +02:00
|
|
|
BR_TEST_FLAG(BRUSH_DRAG_DOT);
|
2010-07-27 16:09:02 +00:00
|
|
|
BR_TEST_FLAG(BRUSH_INVERSE_SMOOTH_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_PLANE_TRIM);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_FRONTFACE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_CUSTOM_ICON);
|
|
|
|
|
|
2013-04-16 15:02:41 +00:00
|
|
|
BR_TEST_FLAG_OVERLAY(BRUSH_OVERLAY_CURSOR);
|
|
|
|
|
BR_TEST_FLAG_OVERLAY(BRUSH_OVERLAY_PRIMARY);
|
|
|
|
|
BR_TEST_FLAG_OVERLAY(BRUSH_OVERLAY_SECONDARY);
|
2013-04-23 00:32:51 +00:00
|
|
|
BR_TEST_FLAG_OVERLAY(BRUSH_OVERLAY_CURSOR_OVERRIDE_ON_STROKE);
|
|
|
|
|
BR_TEST_FLAG_OVERLAY(BRUSH_OVERLAY_PRIMARY_OVERRIDE_ON_STROKE);
|
|
|
|
|
BR_TEST_FLAG_OVERLAY(BRUSH_OVERLAY_SECONDARY_OVERRIDE_ON_STROKE);
|
2013-04-16 15:02:41 +00:00
|
|
|
|
2010-07-27 16:09:02 +00:00
|
|
|
BR_TEST(jitter, f);
|
|
|
|
|
BR_TEST(spacing, d);
|
|
|
|
|
BR_TEST(smooth_stroke_radius, d);
|
|
|
|
|
BR_TEST(smooth_stroke_factor, f);
|
|
|
|
|
BR_TEST(rate, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(alpha, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(sculpt_plane, d);
|
|
|
|
|
|
|
|
|
|
BR_TEST(plane_offset, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(autosmooth_factor, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(crease_pinch_factor, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(plane_trim, f);
|
|
|
|
|
|
|
|
|
|
BR_TEST(texture_sample_bias, f);
|
|
|
|
|
BR_TEST(texture_overlay_alpha, d);
|
|
|
|
|
|
|
|
|
|
BR_TEST(add_col[0], f);
|
|
|
|
|
BR_TEST(add_col[1], f);
|
|
|
|
|
BR_TEST(add_col[2], f);
|
|
|
|
|
BR_TEST(sub_col[0], f);
|
|
|
|
|
BR_TEST(sub_col[1], f);
|
|
|
|
|
BR_TEST(sub_col[2], f);
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
#undef BR_TEST
|
|
|
|
|
#undef BR_TEST_FLAG
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_sculpt_reset(Brush *br)
|
2010-07-27 16:09:02 +00:00
|
|
|
{
|
|
|
|
|
/* enable this to see any non-default
|
2012-03-03 20:19:11 +00:00
|
|
|
* settings used by a brush: */
|
2012-05-05 00:58:22 +00:00
|
|
|
// BKE_brush_debug_print_state(br);
|
2010-07-27 16:09:02 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_defaults(br);
|
|
|
|
|
BKE_brush_curve_preset(br, CURVE_PRESET_SMOOTH);
|
2010-07-27 16:09:02 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (br->sculpt_tool) {
|
2012-05-06 15:15:33 +00:00
|
|
|
case SCULPT_TOOL_CLAY:
|
|
|
|
|
br->flag |= BRUSH_FRONTFACE;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_CREASE:
|
|
|
|
|
br->flag |= BRUSH_DIR_IN;
|
|
|
|
|
br->alpha = 0.25;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_FILL:
|
|
|
|
|
br->add_col[1] = 1;
|
|
|
|
|
br->sub_col[0] = 0.25;
|
|
|
|
|
br->sub_col[1] = 1;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_FLATTEN:
|
|
|
|
|
br->add_col[1] = 1;
|
|
|
|
|
br->sub_col[0] = 0.25;
|
|
|
|
|
br->sub_col[1] = 1;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_INFLATE:
|
|
|
|
|
br->add_col[0] = 0.750000;
|
|
|
|
|
br->add_col[1] = 0.750000;
|
|
|
|
|
br->add_col[2] = 0.750000;
|
|
|
|
|
br->sub_col[0] = 0.250000;
|
|
|
|
|
br->sub_col[1] = 0.250000;
|
|
|
|
|
br->sub_col[2] = 0.250000;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_NUDGE:
|
|
|
|
|
br->add_col[0] = 0.250000;
|
|
|
|
|
br->add_col[1] = 1.000000;
|
|
|
|
|
br->add_col[2] = 0.250000;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_PINCH:
|
|
|
|
|
br->add_col[0] = 0.750000;
|
|
|
|
|
br->add_col[1] = 0.750000;
|
|
|
|
|
br->add_col[2] = 0.750000;
|
|
|
|
|
br->sub_col[0] = 0.250000;
|
|
|
|
|
br->sub_col[1] = 0.250000;
|
|
|
|
|
br->sub_col[2] = 0.250000;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_SCRAPE:
|
|
|
|
|
br->add_col[1] = 1.000000;
|
|
|
|
|
br->sub_col[0] = 0.250000;
|
|
|
|
|
br->sub_col[1] = 1.000000;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_ROTATE:
|
|
|
|
|
br->alpha = 1.0;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_SMOOTH:
|
|
|
|
|
br->flag &= ~BRUSH_SPACE_ATTEN;
|
|
|
|
|
br->spacing = 5;
|
|
|
|
|
br->add_col[0] = 0.750000;
|
|
|
|
|
br->add_col[1] = 0.750000;
|
|
|
|
|
br->add_col[2] = 0.750000;
|
|
|
|
|
break;
|
|
|
|
|
case SCULPT_TOOL_GRAB:
|
|
|
|
|
case SCULPT_TOOL_SNAKE_HOOK:
|
|
|
|
|
case SCULPT_TOOL_THUMB:
|
|
|
|
|
br->size = 75;
|
|
|
|
|
br->flag &= ~BRUSH_ALPHA_PRESSURE;
|
|
|
|
|
br->flag &= ~BRUSH_SPACE;
|
|
|
|
|
br->flag &= ~BRUSH_SPACE_ATTEN;
|
|
|
|
|
br->add_col[0] = 0.250000;
|
|
|
|
|
br->add_col[1] = 1.000000;
|
|
|
|
|
br->add_col[2] = 0.250000;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2010-07-27 16:09:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 07:29:01 +00:00
|
|
|
/**
|
|
|
|
|
* Library Operations
|
|
|
|
|
* \param preset CurveMappingPreset
|
|
|
|
|
*/
|
|
|
|
|
void BKE_brush_curve_preset(Brush *b, int preset)
|
2009-01-07 04:38:30 +00:00
|
|
|
{
|
|
|
|
|
CurveMap *cm = NULL;
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!b->curve)
|
2009-01-07 04:38:30 +00:00
|
|
|
b->curve = curvemapping_add(1, 0, 0, 1, 1);
|
|
|
|
|
|
|
|
|
|
cm = b->curve->cm;
|
2009-02-07 03:21:28 +00:00
|
|
|
cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
|
|
|
|
|
|
2010-03-09 07:41:27 +00:00
|
|
|
b->curve->preset = preset;
|
2010-07-30 00:06:59 +00:00
|
|
|
curvemap_reset(cm, &b->curve->clipr, b->curve->preset, CURVEMAP_SLOPE_NEGATIVE);
|
2014-04-01 11:34:00 +11:00
|
|
|
curvemapping_changed(b->curve, false);
|
2009-01-07 04:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-10 14:52:00 +02:00
|
|
|
/* XXX Unused function. */
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_texture_set_nr(Brush *brush, int nr)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
ID *idtest, *id = NULL;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
id = (ID *)brush->mtex.tex;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
idtest = (ID *)BLI_findlink(&G.main->tex, nr - 1);
|
|
|
|
|
if (idtest == NULL) { /* new tex */
|
2016-07-10 14:52:00 +02:00
|
|
|
if (id) idtest = (ID *)BKE_texture_copy(G.main, (Tex *)id);
|
2015-03-29 03:16:55 +11:00
|
|
|
else idtest = (ID *)BKE_texture_add(G.main, "Tex");
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(idtest);
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
if (idtest != id) {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_texture_delete(brush);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->mtex.tex = (Tex *)idtest;
|
2006-07-31 15:53:03 +00:00
|
|
|
id_us_plus(idtest);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_texture_delete(Brush *brush)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (brush->mtex.tex)
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&brush->mtex.tex->id);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2010-01-03 08:37:18 +00:00
|
|
|
return 1;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_clone_image_set_nr(Brush *brush, int nr)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (brush && nr > 0) {
|
2012-05-06 15:15:33 +00:00
|
|
|
Image *ima = (Image *)BLI_findlink(&G.main->image, nr - 1);
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ima) {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_clone_image_delete(brush);
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->clone.image = ima;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
id_us_plus(&ima->id);
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->clone.offset[0] = brush->clone.offset[1] = 0.0f;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_clone_image_delete(Brush *brush)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
|
|
|
|
if (brush && brush->clone.image) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&brush->clone.image->id);
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->clone.image = NULL;
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-14 03:47:20 +00:00
|
|
|
/* Generic texture sampler for 3D painting systems. point has to be either in
|
2013-04-27 12:51:23 +00:00
|
|
|
* region space mouse coordinates, or 3d world coordinates for 3D mapping.
|
|
|
|
|
*
|
|
|
|
|
* rgba outputs straight alpha. */
|
2013-03-13 03:46:22 +00:00
|
|
|
float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
|
2013-03-13 05:23:53 +00:00
|
|
|
const float point[3],
|
2013-03-14 05:59:34 +00:00
|
|
|
float rgba[4], const int thread,
|
2013-03-13 05:23:53 +00:00
|
|
|
struct ImagePool *pool)
|
2013-03-13 03:46:22 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
MTex *mtex = &br->mtex;
|
|
|
|
|
float intensity = 1.0;
|
|
|
|
|
bool hasrgb = false;
|
|
|
|
|
|
|
|
|
|
if (!mtex->tex) {
|
|
|
|
|
intensity = 1;
|
|
|
|
|
}
|
|
|
|
|
else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) {
|
|
|
|
|
/* Get strength by feeding the vertex
|
|
|
|
|
* location directly into a texture */
|
|
|
|
|
hasrgb = externtex(mtex, point, &intensity,
|
2016-03-02 12:45:46 +05:00
|
|
|
rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2013-03-31 00:38:50 +00:00
|
|
|
else if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
|
|
|
|
|
float rotation = -mtex->rot;
|
|
|
|
|
float point_2d[2] = {point[0], point[1]};
|
2013-07-13 16:25:47 +00:00
|
|
|
float x, y;
|
2013-03-31 00:38:50 +00:00
|
|
|
float co[3];
|
|
|
|
|
|
|
|
|
|
x = point_2d[0] - br->stencil_pos[0];
|
|
|
|
|
y = point_2d[1] - br->stencil_pos[1];
|
|
|
|
|
|
|
|
|
|
if (rotation > 0.001f || rotation < -0.001f) {
|
|
|
|
|
const float angle = atan2f(y, x) + rotation;
|
|
|
|
|
const float flen = sqrtf(x * x + y * y);
|
|
|
|
|
|
|
|
|
|
x = flen * cosf(angle);
|
|
|
|
|
y = flen * sinf(angle);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-05 15:45:10 +00:00
|
|
|
if (fabsf(x) > br->stencil_dimension[0] || fabsf(y) > br->stencil_dimension[1]) {
|
|
|
|
|
zero_v4(rgba);
|
|
|
|
|
return 0.0f;
|
2013-03-31 00:38:50 +00:00
|
|
|
}
|
|
|
|
|
x /= (br->stencil_dimension[0]);
|
|
|
|
|
y /= (br->stencil_dimension[1]);
|
|
|
|
|
|
2014-03-02 19:40:39 +02:00
|
|
|
co[0] = x;
|
|
|
|
|
co[1] = y;
|
2013-03-31 00:38:50 +00:00
|
|
|
co[2] = 0.0f;
|
|
|
|
|
|
|
|
|
|
hasrgb = externtex(mtex, co, &intensity,
|
2016-03-02 12:45:46 +05:00
|
|
|
rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
|
2013-03-31 00:38:50 +00:00
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
else {
|
|
|
|
|
float rotation = -mtex->rot;
|
|
|
|
|
float point_2d[2] = {point[0], point[1]};
|
|
|
|
|
float x = 0.0f, y = 0.0f; /* Quite warnings */
|
2013-03-31 00:38:50 +00:00
|
|
|
float invradius = 1.0f; /* Quite warnings */
|
2013-03-13 14:19:55 +00:00
|
|
|
float co[3];
|
2013-03-13 03:46:22 +00:00
|
|
|
|
2013-03-26 22:45:06 +00:00
|
|
|
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
|
2013-03-13 03:46:22 +00:00
|
|
|
/* keep coordinates relative to mouse */
|
|
|
|
|
|
|
|
|
|
rotation += ups->brush_rotation;
|
|
|
|
|
|
2013-03-26 21:34:39 +00:00
|
|
|
x = point_2d[0] - ups->tex_mouse[0];
|
|
|
|
|
y = point_2d[1] - ups->tex_mouse[1];
|
2013-03-13 03:46:22 +00:00
|
|
|
|
|
|
|
|
/* use pressure adjusted size for fixed mode */
|
2013-03-31 03:28:46 +00:00
|
|
|
invradius = 1.0f / ups->pixel_radius;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
|
|
|
|
else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
|
|
|
|
|
/* leave the coordinates relative to the screen */
|
|
|
|
|
|
|
|
|
|
/* use unadjusted size for tiled mode */
|
2013-03-31 03:28:46 +00:00
|
|
|
invradius = 1.0f / BKE_brush_size_get(scene, br);
|
2013-03-13 03:46:22 +00:00
|
|
|
|
|
|
|
|
x = point_2d[0];
|
|
|
|
|
y = point_2d[1];
|
2013-03-26 22:45:06 +00:00
|
|
|
}
|
|
|
|
|
else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) {
|
2013-03-26 21:34:39 +00:00
|
|
|
rotation += ups->brush_rotation;
|
|
|
|
|
/* these contain a random coordinate */
|
|
|
|
|
x = point_2d[0] - ups->tex_mouse[0];
|
|
|
|
|
y = point_2d[1] - ups->tex_mouse[1];
|
|
|
|
|
|
2013-03-31 03:28:46 +00:00
|
|
|
invradius = 1.0f / ups->pixel_radius;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-31 00:38:50 +00:00
|
|
|
x *= invradius;
|
|
|
|
|
y *= invradius;
|
2013-03-13 03:46:22 +00:00
|
|
|
|
|
|
|
|
/* it is probably worth optimizing for those cases where
|
|
|
|
|
* the texture is not rotated by skipping the calls to
|
|
|
|
|
* atan2, sqrtf, sin, and cos. */
|
|
|
|
|
if (rotation > 0.001f || rotation < -0.001f) {
|
|
|
|
|
const float angle = atan2f(y, x) + rotation;
|
|
|
|
|
const float flen = sqrtf(x * x + y * y);
|
|
|
|
|
|
|
|
|
|
x = flen * cosf(angle);
|
|
|
|
|
y = flen * sinf(angle);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-02 19:40:39 +02:00
|
|
|
co[0] = x;
|
|
|
|
|
co[1] = y;
|
2013-03-13 03:46:22 +00:00
|
|
|
co[2] = 0.0f;
|
|
|
|
|
|
|
|
|
|
hasrgb = externtex(mtex, co, &intensity,
|
2016-03-02 12:45:46 +05:00
|
|
|
rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intensity += br->texture_sample_bias;
|
|
|
|
|
|
|
|
|
|
if (!hasrgb) {
|
|
|
|
|
rgba[0] = intensity;
|
|
|
|
|
rgba[1] = intensity;
|
|
|
|
|
rgba[2] = intensity;
|
|
|
|
|
rgba[3] = 1.0f;
|
|
|
|
|
}
|
2014-04-13 19:03:14 +03:00
|
|
|
/* For consistency, sampling always returns color in linear space */
|
|
|
|
|
else if (ups->do_linear_conversion) {
|
|
|
|
|
IMB_colormanagement_colorspace_to_scene_linear_v3(rgba, ups->colorspace);
|
2013-12-03 22:13:15 +06:00
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
|
|
|
|
|
return intensity;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-25 02:41:30 +00:00
|
|
|
float BKE_brush_sample_masktex(const Scene *scene, Brush *br,
|
2014-03-29 08:42:11 +11:00
|
|
|
const float point[2],
|
2013-03-25 02:41:30 +00:00
|
|
|
const int thread,
|
|
|
|
|
struct ImagePool *pool)
|
|
|
|
|
{
|
2013-03-25 01:00:16 +00:00
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
MTex *mtex = &br->mask_mtex;
|
2013-04-22 10:46:01 +00:00
|
|
|
float rgba[4], intensity;
|
2013-03-25 01:00:16 +00:00
|
|
|
|
2013-04-22 10:46:01 +00:00
|
|
|
if (!mtex->tex) {
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
|
|
|
|
if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
|
2013-03-25 01:00:16 +00:00
|
|
|
float rotation = -mtex->rot;
|
|
|
|
|
float point_2d[2] = {point[0], point[1]};
|
2013-07-13 16:25:47 +00:00
|
|
|
float x, y;
|
2013-03-25 01:00:16 +00:00
|
|
|
float co[3];
|
|
|
|
|
|
2013-04-23 00:06:22 +00:00
|
|
|
x = point_2d[0] - br->mask_stencil_pos[0];
|
|
|
|
|
y = point_2d[1] - br->mask_stencil_pos[1];
|
2013-03-25 01:00:16 +00:00
|
|
|
|
2013-04-22 10:46:01 +00:00
|
|
|
if (rotation > 0.001f || rotation < -0.001f) {
|
|
|
|
|
const float angle = atan2f(y, x) + rotation;
|
|
|
|
|
const float flen = sqrtf(x * x + y * y);
|
2013-03-25 01:00:16 +00:00
|
|
|
|
2013-04-22 10:46:01 +00:00
|
|
|
x = flen * cosf(angle);
|
|
|
|
|
y = flen * sinf(angle);
|
|
|
|
|
}
|
2013-03-25 01:00:16 +00:00
|
|
|
|
2013-04-23 00:06:22 +00:00
|
|
|
if (fabsf(x) > br->mask_stencil_dimension[0] || fabsf(y) > br->mask_stencil_dimension[1]) {
|
2013-04-22 10:46:01 +00:00
|
|
|
zero_v4(rgba);
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
2013-04-23 00:06:22 +00:00
|
|
|
x /= (br->mask_stencil_dimension[0]);
|
|
|
|
|
y /= (br->mask_stencil_dimension[1]);
|
2013-04-22 10:46:01 +00:00
|
|
|
|
2014-03-04 20:35:39 +02:00
|
|
|
co[0] = x;
|
|
|
|
|
co[1] = y;
|
2013-04-22 10:46:01 +00:00
|
|
|
co[2] = 0.0f;
|
|
|
|
|
|
|
|
|
|
externtex(mtex, co, &intensity,
|
2016-03-02 12:45:46 +05:00
|
|
|
rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
|
2013-04-22 10:46:01 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float rotation = -mtex->rot;
|
|
|
|
|
float point_2d[2] = {point[0], point[1]};
|
|
|
|
|
float x = 0.0f, y = 0.0f; /* Quite warnings */
|
|
|
|
|
float invradius = 1.0f; /* Quite warnings */
|
|
|
|
|
float co[3];
|
|
|
|
|
|
|
|
|
|
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
|
|
|
|
|
/* keep coordinates relative to mouse */
|
|
|
|
|
|
2014-12-26 23:51:27 +01:00
|
|
|
rotation += ups->brush_rotation_sec;
|
2013-04-22 10:46:01 +00:00
|
|
|
|
|
|
|
|
x = point_2d[0] - ups->mask_tex_mouse[0];
|
|
|
|
|
y = point_2d[1] - ups->mask_tex_mouse[1];
|
|
|
|
|
|
|
|
|
|
/* use pressure adjusted size for fixed mode */
|
|
|
|
|
invradius = 1.0f / ups->pixel_radius;
|
|
|
|
|
}
|
|
|
|
|
else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
|
|
|
|
|
/* leave the coordinates relative to the screen */
|
|
|
|
|
|
|
|
|
|
/* use unadjusted size for tiled mode */
|
|
|
|
|
invradius = 1.0f / BKE_brush_size_get(scene, br);
|
|
|
|
|
|
|
|
|
|
x = point_2d[0];
|
|
|
|
|
y = point_2d[1];
|
|
|
|
|
}
|
|
|
|
|
else if (mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) {
|
2014-12-26 23:51:27 +01:00
|
|
|
rotation += ups->brush_rotation_sec;
|
2013-04-22 10:46:01 +00:00
|
|
|
/* these contain a random coordinate */
|
|
|
|
|
x = point_2d[0] - ups->mask_tex_mouse[0];
|
|
|
|
|
y = point_2d[1] - ups->mask_tex_mouse[1];
|
|
|
|
|
|
|
|
|
|
invradius = 1.0f / ups->pixel_radius;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x *= invradius;
|
|
|
|
|
y *= invradius;
|
2013-03-25 01:00:16 +00:00
|
|
|
|
|
|
|
|
/* it is probably worth optimizing for those cases where
|
|
|
|
|
* the texture is not rotated by skipping the calls to
|
|
|
|
|
* atan2, sqrtf, sin, and cos. */
|
|
|
|
|
if (rotation > 0.001f || rotation < -0.001f) {
|
|
|
|
|
const float angle = atan2f(y, x) + rotation;
|
|
|
|
|
const float flen = sqrtf(x * x + y * y);
|
|
|
|
|
|
|
|
|
|
x = flen * cosf(angle);
|
|
|
|
|
y = flen * sinf(angle);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 20:35:39 +02:00
|
|
|
co[0] = x;
|
|
|
|
|
co[1] = y;
|
2013-03-25 01:00:16 +00:00
|
|
|
co[2] = 0.0f;
|
|
|
|
|
|
|
|
|
|
externtex(mtex, co, &intensity,
|
2016-03-02 12:45:46 +05:00
|
|
|
rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
|
2013-03-25 01:00:16 +00:00
|
|
|
}
|
2013-04-22 10:46:01 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
CLAMP(intensity, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
switch (br->mask_pressure) {
|
|
|
|
|
case BRUSH_MASK_PRESSURE_CUTOFF:
|
|
|
|
|
intensity = ((1.0f - intensity) < ups->size_pressure_value) ? 1.0f : 0.0f;
|
|
|
|
|
break;
|
|
|
|
|
case BRUSH_MASK_PRESSURE_RAMP:
|
|
|
|
|
intensity = ups->size_pressure_value + intensity * (1.0f - ups->size_pressure_value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 10:46:01 +00:00
|
|
|
return intensity;
|
2013-03-25 01:00:16 +00:00
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/* Unified Size / Strength / Color */
|
2012-01-14 23:54:51 +00:00
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* XXX: be careful about setting size and unprojected radius
|
|
|
|
|
* because they depend on one another
|
|
|
|
|
* these functions do not set the other corresponding value
|
|
|
|
|
* this can lead to odd behavior if size and unprojected
|
|
|
|
|
* radius become inconsistent.
|
|
|
|
|
* the biggest problem is that it isn't possible to change
|
|
|
|
|
* unprojected radius because a view context is not
|
2013-10-31 14:10:01 +00:00
|
|
|
* available. my usual solution to this is to use the
|
2012-10-20 20:20:02 +00:00
|
|
|
* ratio of change of the size to change the unprojected
|
|
|
|
|
* radius. Not completely convinced that is correct.
|
2013-02-06 14:02:19 +00:00
|
|
|
* In any case, a better solution is needed to prevent
|
2012-10-20 20:20:02 +00:00
|
|
|
* inconsistency. */
|
2012-01-14 23:54:51 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
const float *BKE_brush_color_get(const struct Scene *scene, const struct Brush *brush)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
return (ups->flag & UNIFIED_PAINT_COLOR) ? ups->rgb : brush->rgb;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
const float *BKE_brush_secondary_color_get(const struct Scene *scene, const struct Brush *brush)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
return (ups->flag & UNIFIED_PAINT_COLOR) ? ups->secondary_rgb : brush->secondary_rgb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3])
|
|
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
if (ups->flag & UNIFIED_PAINT_COLOR)
|
|
|
|
|
copy_v3_v3(ups->rgb, color);
|
|
|
|
|
else
|
|
|
|
|
copy_v3_v3(brush->rgb, color);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_size_set(Scene *scene, Brush *brush, int size)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
2016-07-08 14:51:12 +10:00
|
|
|
|
2015-02-05 19:11:00 +01:00
|
|
|
/* make sure range is sane */
|
|
|
|
|
CLAMP(size, 1, MAX_BRUSH_PIXEL_RADIUS);
|
|
|
|
|
|
2012-01-14 23:54:51 +00:00
|
|
|
if (ups->flag & UNIFIED_PAINT_SIZE)
|
2012-05-06 15:15:33 +00:00
|
|
|
ups->size = size;
|
2012-01-14 23:54:51 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->size = size;
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
int BKE_brush_size_get(const Scene *scene, const Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
2012-12-14 15:09:59 +00:00
|
|
|
int size = (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
|
|
|
|
|
|
2016-06-03 01:07:29 +10:00
|
|
|
return size;
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
int BKE_brush_use_locked_size(const Scene *scene, const Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
const short us_flag = scene->toolsettings->unified_paint_settings.flag;
|
|
|
|
|
|
|
|
|
|
return (us_flag & UNIFIED_PAINT_SIZE) ?
|
2012-05-06 15:15:33 +00:00
|
|
|
(us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) :
|
|
|
|
|
(brush->flag & BRUSH_LOCK_SIZE);
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
int BKE_brush_use_size_pressure(const Scene *scene, const Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
const short us_flag = scene->toolsettings->unified_paint_settings.flag;
|
|
|
|
|
|
|
|
|
|
return (us_flag & UNIFIED_PAINT_SIZE) ?
|
2012-05-06 15:15:33 +00:00
|
|
|
(us_flag & UNIFIED_PAINT_BRUSH_SIZE_PRESSURE) :
|
|
|
|
|
(brush->flag & BRUSH_SIZE_PRESSURE);
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
int BKE_brush_use_alpha_pressure(const Scene *scene, const Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
const short us_flag = scene->toolsettings->unified_paint_settings.flag;
|
|
|
|
|
|
|
|
|
|
return (us_flag & UNIFIED_PAINT_ALPHA) ?
|
2012-05-06 15:15:33 +00:00
|
|
|
(us_flag & UNIFIED_PAINT_BRUSH_ALPHA_PRESSURE) :
|
|
|
|
|
(brush->flag & BRUSH_ALPHA_PRESSURE);
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojected_radius)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
if (ups->flag & UNIFIED_PAINT_SIZE)
|
2012-05-06 15:15:33 +00:00
|
|
|
ups->unprojected_radius = unprojected_radius;
|
2012-01-14 23:54:51 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->unprojected_radius = unprojected_radius;
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
float BKE_brush_unprojected_radius_get(const Scene *scene, const Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
return (ups->flag & UNIFIED_PAINT_SIZE) ?
|
2012-05-06 15:15:33 +00:00
|
|
|
ups->unprojected_radius :
|
|
|
|
|
brush->unprojected_radius;
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-01 21:23:12 +00:00
|
|
|
void BKE_brush_alpha_set(Scene *scene, Brush *brush, float alpha)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
if (ups->flag & UNIFIED_PAINT_ALPHA)
|
2012-05-06 15:15:33 +00:00
|
|
|
ups->alpha = alpha;
|
2012-01-14 23:54:51 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
brush->alpha = alpha;
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
float BKE_brush_alpha_get(const Scene *scene, const Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
return (ups->flag & UNIFIED_PAINT_ALPHA) ? ups->alpha : brush->alpha;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 03:10:57 +10:00
|
|
|
float BKE_brush_weight_get(const Scene *scene, const Brush *brush)
|
2012-04-29 20:04:25 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
return (ups->flag & UNIFIED_PAINT_WEIGHT) ? ups->weight : brush->weight;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_weight_set(const Scene *scene, Brush *brush, float value)
|
2012-05-02 16:05:25 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ups->flag & UNIFIED_PAINT_WEIGHT)
|
2012-05-02 16:05:25 +00:00
|
|
|
ups->weight = value;
|
|
|
|
|
else
|
|
|
|
|
brush->weight = value;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-14 23:54:51 +00:00
|
|
|
/* scale unprojected radius to reflect a change in the brush's 2D size */
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_scale_unprojected_radius(float *unprojected_radius,
|
|
|
|
|
int new_brush_size,
|
|
|
|
|
int old_brush_size)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
float scale = new_brush_size;
|
|
|
|
|
/* avoid division by zero */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (old_brush_size != 0)
|
2012-01-14 23:54:51 +00:00
|
|
|
scale /= (float)old_brush_size;
|
|
|
|
|
(*unprojected_radius) *= scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* scale brush size to reflect a change in the brush's unprojected radius */
|
2015-04-17 03:10:57 +10:00
|
|
|
void BKE_brush_scale_size(
|
|
|
|
|
int *r_brush_size,
|
|
|
|
|
float new_unprojected_radius,
|
|
|
|
|
float old_unprojected_radius)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
float scale = new_unprojected_radius;
|
|
|
|
|
/* avoid division by zero */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (old_unprojected_radius != 0)
|
2012-01-14 23:54:51 +00:00
|
|
|
scale /= new_unprojected_radius;
|
2012-10-12 14:35:10 +00:00
|
|
|
(*r_brush_size) = (int)((float)(*r_brush_size) * scale);
|
2012-01-14 23:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2])
|
2009-09-18 11:25:52 +00:00
|
|
|
{
|
2014-09-01 21:10:17 +02:00
|
|
|
float rand_pos[2];
|
|
|
|
|
float spread;
|
|
|
|
|
int diameter;
|
2011-02-04 16:10:30 +00:00
|
|
|
|
2014-09-01 21:10:17 +02:00
|
|
|
do {
|
|
|
|
|
rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
|
|
|
|
|
rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
|
2014-10-13 15:35:41 +02:00
|
|
|
} while (len_squared_v2(rand_pos) > SQUARE(0.5f));
|
2011-02-04 16:10:30 +00:00
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2014-09-01 21:10:17 +02:00
|
|
|
if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
|
|
|
|
|
diameter = 2 * brush->jitter_absolute;
|
|
|
|
|
spread = 1.0;
|
2009-09-18 11:25:52 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2014-09-01 21:10:17 +02:00
|
|
|
diameter = 2 * BKE_brush_size_get(scene, brush);
|
|
|
|
|
spread = brush->jitter;
|
2009-09-18 11:25:52 +00:00
|
|
|
}
|
2014-09-01 21:10:17 +02:00
|
|
|
/* find random position within a circle of diameter 1 */
|
|
|
|
|
jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * spread;
|
|
|
|
|
jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * spread;
|
2009-09-18 11:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-04 14:20:31 +11:00
|
|
|
void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask)
|
2013-03-26 22:45:06 +00:00
|
|
|
{
|
2013-03-26 21:34:39 +00:00
|
|
|
/* we multiply with brush radius as an optimization for the brush
|
|
|
|
|
* texture sampling functions */
|
2013-04-22 10:46:01 +00:00
|
|
|
if (mask) {
|
|
|
|
|
ups->mask_tex_mouse[0] = BLI_rng_get_float(brush_rng) * ups->pixel_radius;
|
|
|
|
|
ups->mask_tex_mouse[1] = BLI_rng_get_float(brush_rng) * ups->pixel_radius;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ups->tex_mouse[0] = BLI_rng_get_float(brush_rng) * ups->pixel_radius;
|
|
|
|
|
ups->tex_mouse[1] = BLI_rng_get_float(brush_rng) * ups->pixel_radius;
|
|
|
|
|
}
|
2013-03-26 21:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-10 13:32:11 +02:00
|
|
|
/* Uses the brush curve control to find a strength value */
|
2014-12-31 13:11:42 +01:00
|
|
|
float BKE_brush_curve_strength(Brush *br, float p, const float len)
|
2009-09-24 01:32:23 +00:00
|
|
|
{
|
2013-05-01 19:50:37 +00:00
|
|
|
float strength;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (p >= len) return 0;
|
|
|
|
|
else p = p / len;
|
2009-09-24 01:32:23 +00:00
|
|
|
|
2013-05-01 19:50:37 +00:00
|
|
|
strength = curvemapping_evaluateF(br->curve, 0, p);
|
|
|
|
|
|
2015-06-10 13:32:11 +02:00
|
|
|
return strength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Uses the brush curve control to find a strength value between 0 and 1 */
|
|
|
|
|
float BKE_brush_curve_strength_clamped(Brush *br, float p, const float len)
|
|
|
|
|
{
|
|
|
|
|
float strength = BKE_brush_curve_strength(br, p, len);
|
|
|
|
|
|
2013-05-01 19:50:37 +00:00
|
|
|
CLAMP(strength, 0.0f, 1.0f);
|
2012-08-21 14:43:51 +00:00
|
|
|
|
2013-05-01 19:50:37 +00:00
|
|
|
return strength;
|
2009-09-24 01:32:23 +00:00
|
|
|
}
|
2009-01-25 07:28:11 +00:00
|
|
|
|
2013-03-07 12:11:38 +00:00
|
|
|
/* TODO: should probably be unified with BrushPainter stuff? */
|
2013-09-05 14:02:59 +00:00
|
|
|
unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_secondary)
|
2013-03-07 12:11:38 +00:00
|
|
|
{
|
|
|
|
|
unsigned int *texcache = NULL;
|
2013-09-05 14:02:59 +00:00
|
|
|
MTex *mtex = (use_secondary) ? &br->mask_mtex : &br->mtex;
|
2014-03-02 19:40:39 +02:00
|
|
|
float intensity;
|
|
|
|
|
float rgba[4];
|
|
|
|
|
int ix, iy;
|
2013-03-07 12:11:38 +00:00
|
|
|
int side = half_side * 2;
|
|
|
|
|
|
|
|
|
|
if (mtex->tex) {
|
|
|
|
|
float x, y, step = 2.0 / side, co[3];
|
|
|
|
|
|
|
|
|
|
texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache");
|
|
|
|
|
|
2013-03-26 22:45:06 +00:00
|
|
|
/* do normalized cannonical view coords for texture */
|
2013-03-07 12:11:38 +00:00
|
|
|
for (y = -1.0, iy = 0; iy < side; iy++, y += step) {
|
|
|
|
|
for (x = -1.0, ix = 0; ix < side; ix++, x += step) {
|
|
|
|
|
co[0] = x;
|
|
|
|
|
co[1] = y;
|
|
|
|
|
co[2] = 0.0f;
|
|
|
|
|
|
|
|
|
|
/* This is copied from displace modifier code */
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
/* TODO(sergey): brush are always cacheing with CM enabled for now. */
|
2014-03-02 19:40:39 +02:00
|
|
|
externtex(mtex, co, &intensity,
|
2016-03-02 12:45:46 +05:00
|
|
|
rgba, rgba + 1, rgba + 2, rgba + 3, 0, NULL, false, false);
|
2013-03-07 12:11:38 +00:00
|
|
|
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4] =
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4 + 1] =
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4 + 2] =
|
2014-03-02 19:40:39 +02:00
|
|
|
((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(intensity * 255.0f);
|
2013-03-07 12:11:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return texcache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-25 07:28:11 +00:00
|
|
|
/**** Radial Control ****/
|
2013-09-05 14:02:59 +00:00
|
|
|
struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary)
|
2009-01-25 07:28:11 +00:00
|
|
|
{
|
|
|
|
|
ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture");
|
|
|
|
|
unsigned int *texcache;
|
|
|
|
|
int side = 128;
|
|
|
|
|
int half = side / 2;
|
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-08-19 19:41:38 +00:00
|
|
|
curvemapping_initialize(br->curve);
|
2013-09-05 14:02:59 +00:00
|
|
|
texcache = BKE_brush_gen_texture_cache(br, half, secondary);
|
2009-01-25 07:28:11 +00:00
|
|
|
im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect");
|
|
|
|
|
im->x = im->y = side;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < side; ++i) {
|
|
|
|
|
for (j = 0; j < side; ++j) {
|
2014-11-11 18:16:20 +01:00
|
|
|
float magn = sqrtf(pow2f(i - half) + pow2f(j - half));
|
2015-06-10 13:32:11 +02:00
|
|
|
im->rect_float[i * side + j] = BKE_brush_curve_strength_clamped(br, magn, half);
|
2009-01-25 07:28:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Modulate curve with texture */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (texcache) {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < side; ++i) {
|
|
|
|
|
for (j = 0; j < side; ++j) {
|
|
|
|
|
const int col = texcache[i * side + j];
|
|
|
|
|
im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] + ((char *)&col)[2]) / 3.0f / 255.0f;
|
2009-01-25 07:28:11 +00:00
|
|
|
}
|
2009-01-29 03:50:46 +00:00
|
|
|
}
|
2009-01-25 07:28:11 +00:00
|
|
|
|
2009-01-29 03:50:46 +00:00
|
|
|
MEM_freeN(texcache);
|
|
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2009-01-25 07:28:11 +00:00
|
|
|
return im;
|
|
|
|
|
}
|