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
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
#include <math.h>
|
2009-01-25 07:28:11 +00:00
|
|
|
#include <string.h>
|
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
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_brush_types.h"
|
2009-01-07 04:38:30 +00:00
|
|
|
#include "DNA_color_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
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 12:18:07 +00:00
|
|
|
#include "DNA_object_types.h"
|
2009-01-25 07:28:11 +00:00
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
2009-12-24 16:10:26 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2009-01-25 07:28:11 +00:00
|
|
|
#include "RNA_access.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
|
|
|
|
2011-10-27 05:34:39 +00:00
|
|
|
#include "BLI_bpath.h"
|
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"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.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"
|
2009-01-25 07:28:11 +00:00
|
|
|
#include "BKE_image.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_library.h"
|
|
|
|
|
#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
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
|
|
|
|
#include "RE_render_ext.h" /* externtex */
|
2009-01-25 07:28:11 +00:00
|
|
|
#include "RE_shader_ext.h"
|
2006-07-31 15:53:03 +00:00
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
|
/* 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 */
|
2010-01-22 04:21:46 +00:00
|
|
|
default_mtex(&brush->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;
|
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;
|
2010-07-27 16:09:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Datablock add/copy/free/make_local */
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
Brush *BKE_brush_add(const char *name)
|
2010-07-27 16:09:02 +00:00
|
|
|
{
|
|
|
|
|
Brush *brush;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brush = BKE_libblock_alloc(&G.main->brush, ID_BR, name);
|
2010-07-27 16:09:02 +00:00
|
|
|
|
2010-08-04 12:18:07 +00:00
|
|
|
/* enable fake user by default */
|
|
|
|
|
brush->id.flag |= LIB_FAKEUSER;
|
|
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
Brush *BKE_brush_copy(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;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
brushn = BKE_libblock_copy(&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
|
|
|
|
2010-07-20 13:42:27 +00:00
|
|
|
if (brush->mtex.tex)
|
2012-05-06 15:15:33 +00:00
|
|
|
id_us_plus((ID *)brush->mtex.tex);
|
2010-07-19 07:29:52 +00:00
|
|
|
|
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 */
|
2008-03-26 20:17:50 +00:00
|
|
|
if (!(brushn->id.flag & LIB_FAKEUSER)) {
|
|
|
|
|
brushn->id.flag |= LIB_FAKEUSER;
|
2010-08-04 12:18:07 +00:00
|
|
|
brushn->id.us++;
|
2008-03-26 20:17:50 +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
|
|
|
|
|
|
|
|
return brushn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* not 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
|
|
|
{
|
2010-07-20 11:32:30 +00:00
|
|
|
if (brush->mtex.tex)
|
|
|
|
|
brush->mtex.tex->id.us--;
|
|
|
|
|
|
2010-07-20 13:42:27 +00:00
|
|
|
if (brush->icon_imbuf)
|
2010-07-20 11:32:30 +00:00
|
|
|
IMB_freeImBuf(brush->icon_imbuf);
|
|
|
|
|
|
|
|
|
|
BKE_previewimg_free(&(brush->preview));
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2009-01-07 04:38:30 +00:00
|
|
|
curvemapping_free(brush->curve);
|
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-04-26 07:17:21 +00:00
|
|
|
static void extern_local_brush(Brush *brush)
|
|
|
|
|
{
|
|
|
|
|
id_lib_extern((ID *)brush->mtex.tex);
|
2011-10-23 17:52:20 +00:00
|
|
|
id_lib_extern((ID *)brush->clone.image);
|
2011-04-26 07:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_make_local(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
|
|
|
{
|
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
|
|
|
/* - only lib users: do nothing
|
2011-04-26 07:17:21 +00:00
|
|
|
* - only local users: set flag
|
|
|
|
|
* - mixed: make copy
|
|
|
|
|
*/
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
Main *bmain = G.main;
|
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
|
|
|
Scene *scene;
|
2012-05-06 15:15:33 +00:00
|
|
|
int is_local = FALSE, is_lib = FALSE;
|
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-06 15:15:33 +00:00
|
|
|
if (brush->id.lib == NULL) 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) {
|
2011-10-23 17:52:20 +00:00
|
|
|
/* special case: ima always local immediately. Clone image should only
|
2012-03-03 20:19:11 +00:00
|
|
|
* have one user anyway. */
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &brush->clone.image->id);
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_brush(brush);
|
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
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (scene = bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene = scene->id.next) {
|
|
|
|
|
if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
|
|
|
|
|
if (scene->id.lib) is_lib = TRUE;
|
|
|
|
|
else is_local = TRUE;
|
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-04-26 07:17:21 +00:00
|
|
|
}
|
2010-07-20 11:32:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (is_local && is_lib == FALSE) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &brush->id);
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_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
|
|
|
|
|
|
|
|
/* enable fake user by default */
|
2008-03-26 20:17:50 +00:00
|
|
|
if (!(brush->id.flag & LIB_FAKEUSER)) {
|
|
|
|
|
brush->id.flag |= LIB_FAKEUSER;
|
2010-08-04 12:18:07 +00:00
|
|
|
brush->id.us++;
|
2008-03-26 20:17:50 +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-03-24 06:18:31 +00:00
|
|
|
else if (is_local && is_lib) {
|
2012-05-06 15:15:33 +00:00
|
|
|
Brush *brush_new = BKE_brush_copy(brush);
|
|
|
|
|
brush_new->id.us = 1; /* only keep fake user */
|
2011-11-30 00:32:13 +00:00
|
|
|
brush_new->id.flag |= LIB_FAKEUSER;
|
2011-10-27 05:34:39 +00:00
|
|
|
|
|
|
|
|
/* Remap paths of new ID using old library as base. */
|
2011-11-30 00:32:13 +00:00
|
|
|
BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->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
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (scene = bmain->scene.first; scene; scene = scene->id.next) {
|
|
|
|
|
if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
|
|
|
|
|
if (scene->id.lib == NULL) {
|
2011-11-30 00:32:13 +00:00
|
|
|
paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
|
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-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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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_TORUS);
|
|
|
|
|
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_FIXED_TEX);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_RAKE);
|
|
|
|
|
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_TEXTURE_OVERLAY);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_EDGE_TO_EDGE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_RESTORE_MESH);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_INVERSE_SMOOTH_PRESSURE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_RANDOM_ROTATION);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_PLANE_TRIM);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_FRONTFACE);
|
|
|
|
|
BR_TEST_FLAG(BRUSH_CUSTOM_ICON);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
/* Library Operations */
|
2012-05-06 15:15:33 +00:00
|
|
|
void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/ 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);
|
2012-08-21 08:47:36 +00:00
|
|
|
curvemapping_changed(b->curve, FALSE);
|
2009-01-07 04:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
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 */
|
|
|
|
|
if (id) idtest = (ID *)BKE_texture_copy((Tex *)id);
|
|
|
|
|
else idtest = (ID *)add_texture("Tex");
|
2006-07-31 15:53:03 +00:00
|
|
|
idtest->us--;
|
|
|
|
|
}
|
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)
|
2010-01-03 08:37:18 +00:00
|
|
|
brush->mtex.tex->id.us--;
|
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) {
|
|
|
|
|
brush->clone.image->id.us--;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
/* Brush Sampling */
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
MTex *mtex = &brush->mtex;
|
2007-02-09 15:08:53 +00:00
|
|
|
|
|
|
|
|
if (mtex && mtex->tex) {
|
2006-07-31 15:53:03 +00:00
|
|
|
float co[3], tin, tr, tg, tb, ta;
|
|
|
|
|
int hasrgb;
|
2012-05-06 15:15:33 +00:00
|
|
|
const int radius = BKE_brush_size_get(scene, brush);
|
2010-07-22 18:56:46 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
co[0] = xy[0] / radius;
|
|
|
|
|
co[1] = xy[1] / radius;
|
|
|
|
|
co[2] = 0.0f;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (hasrgb) {
|
2012-05-06 15:15:33 +00:00
|
|
|
rgba[0] = tr;
|
|
|
|
|
rgba[1] = tg;
|
|
|
|
|
rgba[2] = tb;
|
|
|
|
|
rgba[3] = ta;
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
rgba[0] = tin;
|
|
|
|
|
rgba[1] = tin;
|
|
|
|
|
rgba[2] = tin;
|
|
|
|
|
rgba[3] = 1.0f;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-01-14 10:33:16 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f;
|
2012-01-14 10:33:16 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-14 10:33:16 +00:00
|
|
|
/* TODO, use define for 'texfall' arg */
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
2012-01-14 10:33:16 +00:00
|
|
|
float xy[2], rgba[4], *dstf;
|
2006-08-27 13:29:00 +00:00
|
|
|
int x, y, rowbytes, xoff, yoff, imbflag;
|
2012-05-06 15:15:33 +00:00
|
|
|
const int radius = BKE_brush_size_get(scene, brush);
|
2012-01-19 10:04:51 +00:00
|
|
|
unsigned char *dst, crgb[3];
|
2012-05-06 15:15:33 +00:00
|
|
|
const float alpha = BKE_brush_alpha_get(scene, brush);
|
2011-06-06 22:10:05 +00:00
|
|
|
float brush_rgb[3];
|
2012-09-30 06:12:47 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
imbflag = (flt) ? IB_rectfloat : IB_rect;
|
|
|
|
|
xoff = -bufsize / 2.0f + 0.5f;
|
|
|
|
|
yoff = -bufsize / 2.0f + 0.5f;
|
|
|
|
|
rowbytes = bufsize * 4;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (*outbuf)
|
2012-05-06 15:15:33 +00:00
|
|
|
ibuf = *outbuf;
|
2006-08-27 13:29:00 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
ibuf = IMB_allocImBuf(bufsize, bufsize, 32, imbflag);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (flt) {
|
2011-06-06 22:10:05 +00:00
|
|
|
copy_v3_v3(brush_rgb, brush->rgb);
|
2012-02-23 02:17:50 +00:00
|
|
|
if (use_color_correction) {
|
2011-06-06 22:10:05 +00:00
|
|
|
srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (y = 0; y < ibuf->y; y++) {
|
|
|
|
|
dstf = ibuf->rect_float + y * rowbytes;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (x = 0; x < ibuf->x; x++, dstf += 4) {
|
2006-08-27 13:29:00 +00:00
|
|
|
xy[0] = x + xoff;
|
|
|
|
|
xy[1] = y + yoff;
|
|
|
|
|
|
|
|
|
|
if (texfall == 0) {
|
2011-09-11 02:50:01 +00:00
|
|
|
copy_v3_v3(dstf, brush_rgb);
|
2012-05-06 15:15:33 +00:00
|
|
|
dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
else if (texfall == 1) {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, dstf, 0);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
|
2011-06-06 22:10:05 +00:00
|
|
|
mul_v3_v3v3(dstf, rgba, brush_rgb);
|
2012-09-30 06:12:47 +00:00
|
|
|
dstf[3] = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-01-14 10:33:16 +00:00
|
|
|
float alpha_f; /* final float alpha to convert to char */
|
2012-01-19 10:04:51 +00:00
|
|
|
rgb_float_to_uchar(crgb, brush->rgb);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (y = 0; y < ibuf->y; y++) {
|
|
|
|
|
dst = (unsigned char *)ibuf->rect + y * rowbytes;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (x = 0; x < ibuf->x; x++, dst += 4) {
|
2006-08-27 13:29:00 +00:00
|
|
|
xy[0] = x + xoff;
|
|
|
|
|
xy[1] = y + yoff;
|
|
|
|
|
|
|
|
|
|
if (texfall == 0) {
|
2012-05-05 00:58:22 +00:00
|
|
|
alpha_f = alpha * BKE_brush_curve_strength(brush, len_v2(xy), radius);
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-01-14 10:33:16 +00:00
|
|
|
dst[0] = crgb[0];
|
|
|
|
|
dst[1] = crgb[1];
|
|
|
|
|
dst[2] = crgb[2];
|
|
|
|
|
dst[3] = FTOCHAR(alpha_f);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
else if (texfall == 1) {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(dst, rgba);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2011-03-01 17:58:12 +00:00
|
|
|
else if (texfall == 2) {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
|
2012-01-14 10:33:16 +00:00
|
|
|
mul_v3_v3(rgba, brush->rgb);
|
2012-09-30 06:12:47 +00:00
|
|
|
alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
|
2011-03-01 17:58:12 +00:00
|
|
|
|
2012-01-19 10:04:51 +00:00
|
|
|
rgb_float_to_uchar(dst, rgba);
|
|
|
|
|
|
2012-01-14 10:33:16 +00:00
|
|
|
dst[3] = FTOCHAR(alpha_f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
|
2012-09-30 06:12:47 +00:00
|
|
|
alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
|
2012-01-14 10:33:16 +00:00
|
|
|
|
|
|
|
|
dst[0] = crgb[0];
|
|
|
|
|
dst[1] = crgb[1];
|
|
|
|
|
dst[2] = crgb[2];
|
|
|
|
|
dst[3] = FTOCHAR(alpha_f);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
*outbuf = ibuf;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-14 23:54:51 +00:00
|
|
|
/* Unified Size and Strength */
|
|
|
|
|
|
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
|
|
|
|
|
* available. my ussual solution to this is to use the
|
|
|
|
|
* ratio of change of the size to change the unprojected
|
|
|
|
|
* radius. Not completely convinced that is correct.
|
|
|
|
|
* In anycase, a better solution is needed to prevent
|
|
|
|
|
* inconsistency. */
|
2012-01-14 23:54:51 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_size_get(const Scene *scene, Brush *brush)
|
2012-01-14 23:54:51 +00:00
|
|
|
{
|
|
|
|
|
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
|
|
|
|
|
|
|
|
|
|
return (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_use_locked_size(const Scene *scene, 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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_use_size_pressure(const Scene *scene, 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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_use_alpha_pressure(const Scene *scene, 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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_brush_unprojected_radius_get(const Scene *scene, 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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
static void 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
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_brush_alpha_get(const Scene *scene, 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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_brush_weight_get(const Scene *scene, 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 */
|
2012-10-12 14:35:10 +00:00
|
|
|
void BKE_brush_scale_size(int *r_brush_size,
|
2012-05-05 00:58:22 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
/* Brush Painting */
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
typedef struct BrushPainterCache {
|
|
|
|
|
short enabled;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
int size; /* size override, if 0 uses 2*BKE_brush_size_get(brush) */
|
|
|
|
|
short flt; /* need float imbuf? */
|
|
|
|
|
short texonly; /* no alpha, color or fallof, only texture in imbuf */
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
int lastsize;
|
|
|
|
|
float lastalpha;
|
2009-09-18 11:25:52 +00:00
|
|
|
float lastjitter;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
ImBuf *texibuf;
|
|
|
|
|
ImBuf *maskibuf;
|
|
|
|
|
} BrushPainterCache;
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
struct BrushPainter {
|
2012-01-12 21:48:08 +00:00
|
|
|
Scene *scene;
|
2006-07-31 15:53:03 +00:00
|
|
|
Brush *brush;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
float lastmousepos[2]; /* mouse position of last paint call */
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
float accumdistance; /* accumulated distance of brush since last paint op */
|
|
|
|
|
float lastpaintpos[2]; /* position of last paint op */
|
2006-08-27 13:29:00 +00:00
|
|
|
float startpaintpos[2]; /* position of first paint */
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
double accumtime; /* accumulated time since last paint op (airbrush) */
|
|
|
|
|
double lasttime; /* time of last update */
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
float lastpressure;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
short firsttouch; /* first paint op */
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-09-12 16:53:27 +00:00
|
|
|
float startsize;
|
|
|
|
|
float startalpha;
|
2009-09-18 11:25:52 +00:00
|
|
|
float startjitter;
|
2006-09-12 16:53:27 +00:00
|
|
|
float startspacing;
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
BrushPainterCache cache;
|
2006-07-31 15:53:03 +00:00
|
|
|
};
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
BrushPainter *BKE_brush_painter_new(Scene *scene, Brush *brush)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
BrushPainter *painter = MEM_callocN(sizeof(BrushPainter), "BrushPainter");
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->brush = brush;
|
|
|
|
|
painter->scene = scene;
|
|
|
|
|
painter->firsttouch = 1;
|
|
|
|
|
painter->cache.lastsize = -1; /* force ibuf create in refresh */
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
painter->startsize = BKE_brush_size_get(scene, brush);
|
|
|
|
|
painter->startalpha = BKE_brush_alpha_get(scene, brush);
|
2009-09-18 11:25:52 +00:00
|
|
|
painter->startjitter = brush->jitter;
|
2006-09-12 16:53:27 +00:00
|
|
|
painter->startspacing = brush->spacing;
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
return painter;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly, int size)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2006-08-27 13:29:00 +00:00
|
|
|
if ((painter->cache.flt != flt) || (painter->cache.size != size) ||
|
2012-05-06 15:15:33 +00:00
|
|
|
((painter->cache.texonly != texonly) && texonly))
|
|
|
|
|
{
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf);
|
|
|
|
|
if (painter->cache.maskibuf) IMB_freeImBuf(painter->cache.maskibuf);
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->cache.ibuf = painter->cache.maskibuf = NULL;
|
|
|
|
|
painter->cache.lastsize = -1; /* force ibuf create in refresh */
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (painter->cache.flt != flt) {
|
|
|
|
|
if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf);
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->cache.texibuf = NULL;
|
|
|
|
|
painter->cache.lastsize = -1; /* force ibuf create in refresh */
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->cache.size = size;
|
|
|
|
|
painter->cache.flt = flt;
|
|
|
|
|
painter->cache.texonly = texonly;
|
|
|
|
|
painter->cache.enabled = 1;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_painter_free(BrushPainter *painter)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2006-09-12 16:53:27 +00:00
|
|
|
Brush *brush = painter->brush;
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_size_set(painter->scene, brush, painter->startsize);
|
|
|
|
|
brush_alpha_set(painter->scene, brush, painter->startalpha);
|
2009-09-18 11:25:52 +00:00
|
|
|
brush->jitter = painter->startjitter;
|
2006-09-12 16:53:27 +00:00
|
|
|
brush->spacing = painter->startspacing;
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf);
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf);
|
|
|
|
|
if (painter->cache.maskibuf) IMB_freeImBuf(painter->cache.maskibuf);
|
2006-07-31 15:53:03 +00:00
|
|
|
MEM_freeN(painter);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf,
|
|
|
|
|
int x, int y, int w, int h, int xt, int yt,
|
|
|
|
|
const float pos[2])
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Scene *scene = painter->scene;
|
|
|
|
|
Brush *brush = painter->brush;
|
2006-08-27 13:29:00 +00:00
|
|
|
ImBuf *ibuf, *maskibuf, *texibuf;
|
2012-05-06 15:15:33 +00:00
|
|
|
float *bf, *mf, *tf, *otf = NULL, xoff, yoff, xy[2], rgba[4];
|
|
|
|
|
unsigned char *b, *m, *t, *ot = NULL;
|
|
|
|
|
int dotexold, origx = x, origy = y;
|
|
|
|
|
const int radius = BKE_brush_size_get(painter->scene, brush);
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2010-07-22 18:56:46 +00:00
|
|
|
xoff = -radius + 0.5f;
|
|
|
|
|
yoff = -radius + 0.5f;
|
2006-08-27 13:29:00 +00:00
|
|
|
xoff += (int)pos[0] - (int)painter->startpaintpos[0];
|
|
|
|
|
yoff += (int)pos[1] - (int)painter->startpaintpos[1];
|
|
|
|
|
|
|
|
|
|
ibuf = painter->cache.ibuf;
|
|
|
|
|
texibuf = painter->cache.texibuf;
|
|
|
|
|
maskibuf = painter->cache.maskibuf;
|
|
|
|
|
|
|
|
|
|
dotexold = (oldtexibuf != NULL);
|
|
|
|
|
|
2011-03-08 20:31:45 +00:00
|
|
|
/* not sure if it's actually needed or it's a mistake in coords/sizes
|
2012-03-03 20:19:11 +00:00
|
|
|
* calculation in brush_painter_fixed_tex_partial_update(), but without this
|
|
|
|
|
* limitation memory gets corrupted at fast strokes with quite big spacing (sergey) */
|
2012-10-23 13:28:22 +00:00
|
|
|
w = min_ii(w, ibuf->x);
|
|
|
|
|
h = min_ii(h, ibuf->y);
|
2011-03-08 20:31:45 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.flt) {
|
|
|
|
|
for (; y < h; y++) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bf = ibuf->rect_float + (y * ibuf->x + origx) * 4;
|
|
|
|
|
tf = texibuf->rect_float + (y * texibuf->x + origx) * 4;
|
|
|
|
|
mf = maskibuf->rect_float + (y * maskibuf->x + origx) * 4;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
if (dotexold)
|
2012-05-06 15:15:33 +00:00
|
|
|
otf = oldtexibuf->rect_float + ((y - origy + yt) * oldtexibuf->x + xt) * 4;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (x = origx; x < w; x++, bf += 4, mf += 4, tf += 4) {
|
2006-08-27 13:29:00 +00:00
|
|
|
if (dotexold) {
|
2011-09-11 02:50:01 +00:00
|
|
|
copy_v3_v3(tf, otf);
|
2006-08-27 13:29:00 +00:00
|
|
|
tf[3] = otf[3];
|
|
|
|
|
otf += 4;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
xy[0] = x + xoff;
|
|
|
|
|
xy[1] = y + yoff;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, tf, 0);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bf[0] = tf[0] * mf[0];
|
|
|
|
|
bf[1] = tf[1] * mf[1];
|
|
|
|
|
bf[2] = tf[2] * mf[2];
|
|
|
|
|
bf[3] = tf[3] * mf[3];
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (; y < h; y++) {
|
2012-05-06 15:15:33 +00:00
|
|
|
b = (unsigned char *)ibuf->rect + (y * ibuf->x + origx) * 4;
|
|
|
|
|
t = (unsigned char *)texibuf->rect + (y * texibuf->x + origx) * 4;
|
|
|
|
|
m = (unsigned char *)maskibuf->rect + (y * maskibuf->x + origx) * 4;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
if (dotexold)
|
2012-05-06 15:15:33 +00:00
|
|
|
ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt) * oldtexibuf->x + xt) * 4;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (x = origx; x < w; x++, b += 4, m += 4, t += 4) {
|
2006-08-27 13:29:00 +00:00
|
|
|
if (dotexold) {
|
|
|
|
|
t[0] = ot[0];
|
|
|
|
|
t[1] = ot[1];
|
|
|
|
|
t[2] = ot[2];
|
|
|
|
|
t[3] = ot[3];
|
|
|
|
|
ot += 4;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
xy[0] = x + xoff;
|
|
|
|
|
xy[1] = y + yoff;
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
|
2012-01-19 10:04:51 +00:00
|
|
|
rgba_float_to_uchar(t, rgba);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
b[0] = t[0] * m[0] / 255;
|
|
|
|
|
b[1] = t[1] * m[1] / 255;
|
|
|
|
|
b[2] = t[2] * m[2] / 255;
|
|
|
|
|
b[3] = t[3] * m[3] / 255;
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, const float pos[2])
|
2006-08-27 13:29:00 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
const Scene *scene = painter->scene;
|
|
|
|
|
Brush *brush = painter->brush;
|
|
|
|
|
BrushPainterCache *cache = &painter->cache;
|
2006-08-27 13:29:00 +00:00
|
|
|
ImBuf *oldtexibuf, *ibuf;
|
|
|
|
|
int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2;
|
2012-05-06 15:15:33 +00:00
|
|
|
const int diameter = 2 * BKE_brush_size_get(scene, brush);
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
imbflag = (cache->flt) ? IB_rectfloat : IB_rect;
|
2006-08-27 13:29:00 +00:00
|
|
|
if (!cache->ibuf)
|
2012-05-06 15:15:33 +00:00
|
|
|
cache->ibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag);
|
|
|
|
|
ibuf = cache->ibuf;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
oldtexibuf = cache->texibuf;
|
|
|
|
|
cache->texibuf = IMB_allocImBuf(diameter, diameter, 32, imbflag);
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
if (oldtexibuf) {
|
2012-05-06 15:15:33 +00:00
|
|
|
srcx = srcy = 0;
|
|
|
|
|
destx = (int)painter->lastpaintpos[0] - (int)pos[0];
|
|
|
|
|
desty = (int)painter->lastpaintpos[1] - (int)pos[1];
|
|
|
|
|
w = oldtexibuf->x;
|
|
|
|
|
h = oldtexibuf->y;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
IMB_rectclip(cache->texibuf, oldtexibuf, &destx, &desty, &srcx, &srcy, &w, &h);
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
2006-08-27 13:29:00 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
srcx = srcy = 0;
|
|
|
|
|
destx = desty = 0;
|
|
|
|
|
w = h = 0;
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
x1 = destx;
|
|
|
|
|
y1 = desty;
|
|
|
|
|
x2 = destx + w;
|
|
|
|
|
y2 = desty + h;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
|
|
|
|
/* blend existing texture in new position */
|
|
|
|
|
if ((x1 < x2) && (y1 < y2))
|
|
|
|
|
brush_painter_do_partial(painter, oldtexibuf, x1, y1, x2, y2, srcx, srcy, pos);
|
|
|
|
|
|
|
|
|
|
if (oldtexibuf)
|
|
|
|
|
IMB_freeImBuf(oldtexibuf);
|
|
|
|
|
|
|
|
|
|
/* sample texture in new areas */
|
|
|
|
|
if ((0 < x1) && (0 < ibuf->y))
|
|
|
|
|
brush_painter_do_partial(painter, NULL, 0, 0, x1, ibuf->y, 0, 0, pos);
|
|
|
|
|
if ((x2 < ibuf->x) && (0 < ibuf->y))
|
|
|
|
|
brush_painter_do_partial(painter, NULL, x2, 0, ibuf->x, ibuf->y, 0, 0, pos);
|
|
|
|
|
if ((x1 < x2) && (0 < y1))
|
|
|
|
|
brush_painter_do_partial(painter, NULL, x1, 0, x2, y1, 0, 0, pos);
|
|
|
|
|
if ((x1 < x2) && (y2 < ibuf->y))
|
|
|
|
|
brush_painter_do_partial(painter, NULL, x1, y2, x2, ibuf->y, 0, 0, pos);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static void brush_painter_refresh_cache(BrushPainter *painter, const float pos[2], int use_color_correction)
|
2006-08-27 13:29:00 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
const Scene *scene = painter->scene;
|
|
|
|
|
Brush *brush = painter->brush;
|
|
|
|
|
BrushPainterCache *cache = &painter->cache;
|
|
|
|
|
MTex *mtex = &brush->mtex;
|
2006-08-27 13:29:00 +00:00
|
|
|
int size;
|
|
|
|
|
short flt;
|
2012-05-06 15:15:33 +00:00
|
|
|
const int diameter = 2 * BKE_brush_size_get(scene, brush);
|
|
|
|
|
const float alpha = BKE_brush_alpha_get(scene, brush);
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2010-07-24 07:18:31 +00:00
|
|
|
if (diameter != cache->lastsize ||
|
2012-05-06 15:15:33 +00:00
|
|
|
alpha != cache->lastalpha ||
|
|
|
|
|
brush->jitter != cache->lastjitter)
|
2010-07-22 18:56:46 +00:00
|
|
|
{
|
2006-08-27 13:29:00 +00:00
|
|
|
if (cache->ibuf) {
|
|
|
|
|
IMB_freeImBuf(cache->ibuf);
|
2012-05-06 15:15:33 +00:00
|
|
|
cache->ibuf = NULL;
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
if (cache->maskibuf) {
|
|
|
|
|
IMB_freeImBuf(cache->maskibuf);
|
2012-05-06 15:15:33 +00:00
|
|
|
cache->maskibuf = NULL;
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
flt = cache->flt;
|
|
|
|
|
size = (cache->size) ? cache->size : diameter;
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2011-03-01 17:58:12 +00:00
|
|
|
if (brush->flag & BRUSH_FIXED_TEX) {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_imbuf_new(scene, brush, flt, 3, size, &cache->maskibuf, use_color_correction);
|
2006-08-27 13:29:00 +00:00
|
|
|
brush_painter_fixed_tex_partial_update(painter, pos);
|
|
|
|
|
}
|
|
|
|
|
else
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_imbuf_new(scene, brush, flt, 2, size, &cache->ibuf, use_color_correction);
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
cache->lastsize = diameter;
|
|
|
|
|
cache->lastalpha = alpha;
|
|
|
|
|
cache->lastjitter = brush->jitter;
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2007-02-09 15:08:53 +00:00
|
|
|
else if ((brush->flag & BRUSH_FIXED_TEX) && mtex && mtex->tex) {
|
2006-08-27 13:29:00 +00:00
|
|
|
int dx = (int)painter->lastpaintpos[0] - (int)pos[0];
|
|
|
|
|
int dy = (int)painter->lastpaintpos[1] - (int)pos[1];
|
|
|
|
|
|
|
|
|
|
if ((dx != 0) || (dy != 0))
|
|
|
|
|
brush_painter_fixed_tex_partial_update(painter, pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_brush_painter_break_stroke(BrushPainter *painter)
|
2006-08-27 13:29:00 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->firsttouch = 1;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
static void brush_pressure_apply(BrushPainter *painter, Brush *brush, float pressure)
|
2006-09-24 19:29:25 +00:00
|
|
|
{
|
2012-05-05 00:58:22 +00:00
|
|
|
if (BKE_brush_use_alpha_pressure(painter->scene, brush))
|
2012-10-23 13:28:22 +00:00
|
|
|
brush_alpha_set(painter->scene, brush, max_ff(0.0f, painter->startalpha * pressure));
|
2012-05-05 00:58:22 +00:00
|
|
|
if (BKE_brush_use_size_pressure(painter->scene, brush))
|
2012-10-23 13:28:22 +00:00
|
|
|
BKE_brush_size_set(painter->scene, brush, max_ff(1.0f, painter->startsize * pressure));
|
2009-09-18 11:25:52 +00:00
|
|
|
if (brush->flag & BRUSH_JITTER_PRESSURE)
|
2012-10-23 13:28:22 +00:00
|
|
|
brush->jitter = max_ff(0.0f, painter->startjitter * pressure);
|
2006-09-24 19:29:25 +00:00
|
|
|
if (brush->flag & BRUSH_SPACING_PRESSURE)
|
2012-10-23 13:28:22 +00:00
|
|
|
brush->spacing = max_ff(1.0f, painter->startspacing * (1.5f - pressure));
|
2006-09-24 19:29:25 +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
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
int use_jitter = brush->jitter != 0;
|
2011-02-04 16:10:30 +00:00
|
|
|
|
2011-10-23 15:27:36 +00:00
|
|
|
/* jitter-ed brush gives weird and unpredictable result for this
|
2012-07-26 17:41:09 +00:00
|
|
|
* kinds of stroke, so manually disable jitter usage (sergey) */
|
2012-05-06 15:15:33 +00:00
|
|
|
use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH | BRUSH_ANCHORED)) == 0;
|
2011-02-04 16:10:30 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (use_jitter) {
|
2010-07-14 14:11:03 +00:00
|
|
|
float rand_pos[2];
|
2012-05-06 15:15:33 +00:00
|
|
|
const int radius = BKE_brush_size_get(scene, brush);
|
|
|
|
|
const int diameter = 2 * radius;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* find random position within a circle of diameter 1 */
|
2010-07-14 14:11:03 +00:00
|
|
|
do {
|
2012-05-06 15:15:33 +00:00
|
|
|
rand_pos[0] = BLI_frand() - 0.5f;
|
|
|
|
|
rand_pos[1] = BLI_frand() - 0.5f;
|
2010-07-14 14:11:03 +00:00
|
|
|
} while (len_v2(rand_pos) > 0.5f);
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
jitterpos[0] = pos[0] + 2 * rand_pos[0] * diameter * brush->jitter;
|
|
|
|
|
jitterpos[1] = pos[1] + 2 * rand_pos[1] * diameter * brush->jitter;
|
2009-09-18 11:25:52 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-09-11 02:50:01 +00:00
|
|
|
copy_v2_v2(jitterpos, pos);
|
2009-09-18 11:25:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2], double time, float pressure,
|
|
|
|
|
void *user, int use_color_correction)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Scene *scene = painter->scene;
|
|
|
|
|
Brush *brush = painter->brush;
|
|
|
|
|
int totpaintops = 0;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2009-09-18 11:25:52 +00:00
|
|
|
if (pressure == 0.0f) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (painter->lastpressure) // XXX - hack, operator misses
|
2012-05-06 15:15:33 +00:00
|
|
|
pressure = painter->lastpressure;
|
2009-09-18 11:25:52 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
pressure = 1.0f; /* zero pressure == not using tablet */
|
2009-09-18 11:25:52 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
if (painter->firsttouch) {
|
|
|
|
|
/* paint exactly once on first touch */
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->startpaintpos[0] = pos[0];
|
|
|
|
|
painter->startpaintpos[1] = pos[1];
|
2006-08-27 13:29:00 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_pressure_apply(painter, brush, pressure);
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.enabled)
|
2011-06-06 22:10:05 +00:00
|
|
|
brush_painter_refresh_cache(painter, pos, use_color_correction);
|
2006-07-31 15:53:03 +00:00
|
|
|
totpaintops += func(user, painter->cache.ibuf, pos, pos);
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lasttime = time;
|
|
|
|
|
painter->firsttouch = 0;
|
|
|
|
|
painter->lastpaintpos[0] = pos[0];
|
|
|
|
|
painter->lastpaintpos[1] = pos[1];
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
else if (painter->brush->flag & BRUSH_AIRBRUSH) {
|
|
|
|
|
float spacing, step, paintpos[2], dmousepos[2], len;
|
2012-05-06 15:15:33 +00:00
|
|
|
double starttime, curtime = time;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
/* compute brush spacing adapted to brush size */
|
2012-05-06 15:15:33 +00:00
|
|
|
spacing = brush->rate; //radius*brush->spacing*0.01f;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
/* setup starting time, direction vector and accumulated time */
|
2012-05-06 15:15:33 +00:00
|
|
|
starttime = painter->accumtime;
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v2_v2v2(dmousepos, pos, painter->lastmousepos);
|
2012-05-06 15:15:33 +00:00
|
|
|
len = normalize_v2(dmousepos);
|
2006-07-31 15:53:03 +00:00
|
|
|
painter->accumtime += curtime - painter->lasttime;
|
|
|
|
|
|
|
|
|
|
/* do paint op over unpainted time distance */
|
|
|
|
|
while (painter->accumtime >= spacing) {
|
2012-05-06 15:15:33 +00:00
|
|
|
step = (spacing - starttime) * len;
|
|
|
|
|
paintpos[0] = painter->lastmousepos[0] + dmousepos[0] * step;
|
|
|
|
|
paintpos[1] = painter->lastmousepos[1] + dmousepos[1] * step;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
if (painter->cache.enabled)
|
|
|
|
|
brush_painter_refresh_cache(painter);
|
|
|
|
|
totpaintops += func(user, painter->cache.ibuf,
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lastpaintpos, paintpos);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lastpaintpos[0] = paintpos[0];
|
|
|
|
|
painter->lastpaintpos[1] = paintpos[1];
|
2006-07-31 15:53:03 +00:00
|
|
|
painter->accumtime -= spacing;
|
|
|
|
|
starttime -= spacing;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lasttime = curtime;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
else {
|
2009-09-18 11:25:52 +00:00
|
|
|
float startdistance, spacing, step, paintpos[2], dmousepos[2], finalpos[2];
|
2006-09-24 19:29:25 +00:00
|
|
|
float t, len, press;
|
2012-05-06 15:15:33 +00:00
|
|
|
const int radius = BKE_brush_size_get(scene, brush);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2010-07-22 18:56:46 +00:00
|
|
|
/* compute brush spacing adapted to brush radius, spacing may depend
|
2012-03-03 20:19:11 +00:00
|
|
|
* on pressure, so update it */
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_pressure_apply(painter, brush, painter->lastpressure);
|
2012-10-23 13:28:22 +00:00
|
|
|
spacing = max_ff(1.0f, radius) * brush->spacing * 0.01f;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
/* setup starting distance, direction vector and accumulated distance */
|
2012-05-06 15:15:33 +00:00
|
|
|
startdistance = painter->accumdistance;
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v2_v2v2(dmousepos, pos, painter->lastmousepos);
|
2012-05-06 15:15:33 +00:00
|
|
|
len = normalize_v2(dmousepos);
|
2006-09-24 19:29:25 +00:00
|
|
|
painter->accumdistance += len;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2011-03-08 19:52:35 +00:00
|
|
|
if (brush->flag & BRUSH_SPACE) {
|
|
|
|
|
/* do paint op over unpainted distance */
|
|
|
|
|
while ((len > 0.0f) && (painter->accumdistance >= spacing)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
step = spacing - startdistance;
|
|
|
|
|
paintpos[0] = painter->lastmousepos[0] + dmousepos[0] * step;
|
|
|
|
|
paintpos[1] = painter->lastmousepos[1] + dmousepos[1] * step;
|
2011-03-08 19:52:35 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
t = step / len;
|
|
|
|
|
press = (1.0f - t) * painter->lastpressure + t * pressure;
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_pressure_apply(painter, brush, press);
|
2012-10-23 13:28:22 +00:00
|
|
|
spacing = max_ff(1.0f, radius) * brush->spacing * 0.01f;
|
2011-03-08 19:52:35 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_jitter_pos(scene, brush, paintpos, finalpos);
|
2011-03-08 19:52:35 +00:00
|
|
|
|
|
|
|
|
if (painter->cache.enabled)
|
2011-06-06 22:10:05 +00:00
|
|
|
brush_painter_refresh_cache(painter, finalpos, use_color_correction);
|
2011-03-08 19:52:35 +00:00
|
|
|
|
|
|
|
|
totpaintops +=
|
2012-05-06 15:15:33 +00:00
|
|
|
func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos);
|
2011-03-08 19:52:35 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lastpaintpos[0] = paintpos[0];
|
|
|
|
|
painter->lastpaintpos[1] = paintpos[1];
|
2011-03-08 19:52:35 +00:00
|
|
|
painter->accumdistance -= spacing;
|
|
|
|
|
startdistance -= spacing;
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_jitter_pos(scene, brush, pos, finalpos);
|
2009-09-18 11:25:52 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.enabled)
|
2011-06-06 22:10:05 +00:00
|
|
|
brush_painter_refresh_cache(painter, finalpos, use_color_correction);
|
2006-09-24 19:29:25 +00:00
|
|
|
|
2011-03-08 19:52:35 +00:00
|
|
|
totpaintops += func(user, painter->cache.ibuf, pos, finalpos);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lastpaintpos[0] = pos[0];
|
|
|
|
|
painter->lastpaintpos[1] = pos[1];
|
|
|
|
|
painter->accumdistance = 0;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* do airbrush paint ops, based on the number of paint ops left over
|
2012-03-03 20:19:11 +00:00
|
|
|
* from regular painting. this is a temporary solution until we have
|
|
|
|
|
* accurate time stamps for mouse move events */
|
2006-07-31 15:53:03 +00:00
|
|
|
if (brush->flag & BRUSH_AIRBRUSH) {
|
2012-05-06 15:15:33 +00:00
|
|
|
double curtime = time;
|
|
|
|
|
double painttime = brush->rate * totpaintops;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
painter->accumtime += curtime - painter->lasttime;
|
|
|
|
|
if (painter->accumtime <= painttime)
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->accumtime = 0.0;
|
2006-07-31 15:53:03 +00:00
|
|
|
else
|
|
|
|
|
painter->accumtime -= painttime;
|
|
|
|
|
|
2011-03-28 04:22:50 +00:00
|
|
|
while (painter->accumtime >= (double)brush->rate) {
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_pressure_apply(painter, brush, pressure);
|
2009-09-18 11:25:52 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
BKE_brush_jitter_pos(scene, brush, pos, finalpos);
|
2009-09-18 11:25:52 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.enabled)
|
2011-06-06 22:10:05 +00:00
|
|
|
brush_painter_refresh_cache(painter, finalpos, use_color_correction);
|
2009-09-18 11:25:52 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
totpaintops +=
|
2012-05-06 15:15:33 +00:00
|
|
|
func(user, painter->cache.ibuf, painter->lastmousepos, finalpos);
|
2011-03-28 04:22:50 +00:00
|
|
|
painter->accumtime -= (double)brush->rate;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lasttime = curtime;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
painter->lastmousepos[0] = pos[0];
|
|
|
|
|
painter->lastmousepos[1] = pos[1];
|
|
|
|
|
painter->lastpressure = pressure;
|
2006-09-24 19:29:25 +00:00
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
brush_alpha_set(scene, brush, painter->startalpha);
|
|
|
|
|
BKE_brush_size_set(scene, brush, painter->startsize);
|
2009-09-18 11:25:52 +00:00
|
|
|
brush->jitter = painter->startjitter;
|
2006-09-24 19:29:25 +00:00
|
|
|
brush->spacing = painter->startspacing;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
return totpaintops;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-25 07:28:11 +00:00
|
|
|
/* Uses the brush curve control to find a strength value between 0 and 1 */
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_brush_curve_strength_clamp(Brush *br, float p, const float len)
|
2009-09-24 01:32:23 +00:00
|
|
|
{
|
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
|
|
|
|
2012-08-21 14:43:51 +00:00
|
|
|
curvemapping_initialize(br->curve);
|
2012-05-06 15:15:33 +00:00
|
|
|
p = curvemapping_evaluateF(br->curve, 0, p);
|
2012-08-21 14:43:51 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (p < 0.0f) p = 0.0f;
|
|
|
|
|
else if (p > 1.0f) p = 1.0f;
|
2009-09-24 01:32:23 +00:00
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
/* same as above but can return negative values if the curve enables
|
|
|
|
|
* used for sculpt only */
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_brush_curve_strength(Brush *br, float p, const float len)
|
2009-01-25 07:28:11 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (p >= len)
|
2012-05-06 15:15:33 +00:00
|
|
|
p = 1.0f;
|
2011-04-21 13:11:51 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
p = p / len;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-08-21 14:43:51 +00:00
|
|
|
curvemapping_initialize(br->curve);
|
2011-04-21 13:11:51 +00:00
|
|
|
return curvemapping_evaluateF(br->curve, 0, p);
|
2009-01-25 07:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: should probably be unified with BrushPainter stuff? */
|
2012-05-05 00:58:22 +00:00
|
|
|
unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side)
|
2009-01-25 07:28:11 +00:00
|
|
|
{
|
|
|
|
|
unsigned int *texcache = NULL;
|
2010-01-03 08:37:18 +00:00
|
|
|
MTex *mtex = &br->mtex;
|
2012-05-06 15:15:33 +00:00
|
|
|
TexResult texres = {0};
|
2009-01-25 07:28:11 +00:00
|
|
|
int hasrgb, ix, iy;
|
|
|
|
|
int side = half_side * 2;
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (mtex->tex) {
|
2009-01-25 07:28:11 +00:00
|
|
|
float x, y, step = 2.0 / side, co[3];
|
|
|
|
|
|
|
|
|
|
texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache");
|
|
|
|
|
|
|
|
|
|
/*do normalized cannonical view coords for texture*/
|
2012-05-06 15:15:33 +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;
|
2009-01-25 07:28:11 +00:00
|
|
|
|
|
|
|
|
/* This is copied from displace modifier code */
|
2010-04-26 02:23:13 +00:00
|
|
|
hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres);
|
2009-01-25 07:28:11 +00:00
|
|
|
|
|
|
|
|
/* if the texture gave an RGB value, we assume it didn't give a valid
|
|
|
|
|
* intensity, so calculate one (formula from do_material_tex).
|
|
|
|
|
* if the texture didn't give an RGB value, copy the intensity across
|
|
|
|
|
*/
|
2012-03-24 06:18:31 +00:00
|
|
|
if (hasrgb & TEX_RGB)
|
2012-05-09 10:48:24 +00:00
|
|
|
texres.tin = rgb_to_grayscale(&texres.tr);
|
|
|
|
|
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4] =
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4 + 1] =
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4 + 2] =
|
|
|
|
|
((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(texres.tin * 255.0f);
|
2009-01-25 07:28:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return texcache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**** Radial Control ****/
|
2012-05-05 00:58:22 +00:00
|
|
|
struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br)
|
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;
|
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
texcache = BKE_brush_gen_texture_cache(br, half);
|
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) {
|
2012-05-22 21:16:59 +00:00
|
|
|
float magn = sqrtf(powf(i - half, 2) + powf(j - half, 2));
|
2012-05-06 15:15:33 +00:00
|
|
|
im->rect_float[i * side + j] = BKE_brush_curve_strength_clamp(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;
|
|
|
|
|
}
|