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$
|
|
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
|
|
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"
|
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
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2009-09-18 11:25:52 +00:00
|
|
|
#include "BLI_rand.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
|
|
|
|
#include "BKE_brush.h"
|
2009-01-10 19:34:23 +00:00
|
|
|
#include "BKE_colortools.h"
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
#include "BKE_global.h"
|
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"
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/* Datablock add/copy/free/make_local */
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2009-08-16 19:50:00 +00:00
|
|
|
Brush *add_brush(const char *name)
|
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 *brush;
|
|
|
|
|
|
|
|
|
|
brush= alloc_libblock(&G.main->brush, ID_BR, name);
|
|
|
|
|
|
|
|
|
|
brush->rgb[0]= 1.0f;
|
|
|
|
|
brush->rgb[1]= 1.0f;
|
|
|
|
|
brush->rgb[2]= 1.0f;
|
|
|
|
|
brush->alpha= 0.2f;
|
|
|
|
|
brush->size= 25;
|
2010-04-29 05:20:24 +00:00
|
|
|
brush->spacing= 3.5f;
|
2009-08-18 01:19:00 +00:00
|
|
|
brush->smooth_stroke_radius= 75;
|
|
|
|
|
brush->smooth_stroke_factor= 0.9;
|
2006-07-28 00:56:35 +00:00
|
|
|
brush->rate= 0.1f;
|
2009-09-18 11:25:52 +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
|
|
|
brush->clone.alpha= 0.5;
|
2009-01-14 15:29:29 +00:00
|
|
|
brush->sculpt_tool = SCULPT_TOOL_DRAW;
|
2009-11-06 16:46:35 +00:00
|
|
|
brush->flag |= BRUSH_SPACE;
|
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-01-04 17:28:37 +00:00
|
|
|
brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
|
2010-01-22 04:21:46 +00:00
|
|
|
|
|
|
|
|
default_mtex(&brush->mtex);
|
2009-01-14 17:22:30 +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
|
|
|
brush->id.flag |= LIB_FAKEUSER;
|
|
|
|
|
brush_toggled_fake_user(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
|
|
|
|
|
|
|
|
return brush;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Brush *copy_brush(Brush *brush)
|
|
|
|
|
{
|
|
|
|
|
Brush *brushn;
|
|
|
|
|
|
|
|
|
|
brushn= copy_libblock(brush);
|
|
|
|
|
|
2010-01-03 08:37:18 +00:00
|
|
|
if(brush->mtex.tex) id_us_plus((ID*)brush->mtex.tex);
|
|
|
|
|
|
2009-03-10 23:38:16 +00:00
|
|
|
brushn->curve= curvemapping_copy(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
|
|
|
/* enable fake user by default */
|
2008-03-26 20:17:50 +00:00
|
|
|
if (!(brushn->id.flag & LIB_FAKEUSER)) {
|
|
|
|
|
brushn->id.flag |= LIB_FAKEUSER;
|
|
|
|
|
brush_toggled_fake_user(brushn);
|
|
|
|
|
}
|
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 */
|
|
|
|
|
void free_brush(Brush *brush)
|
|
|
|
|
{
|
2010-01-03 08:37:18 +00:00
|
|
|
if(brush->mtex.tex) brush->mtex.tex->id.us--;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void make_local_brush(Brush *brush)
|
|
|
|
|
{
|
|
|
|
|
/* - only lib users: do nothing
|
2006-07-31 15:53:03 +00:00
|
|
|
* - only local users: set flag
|
|
|
|
|
* - mixed: make copy
|
|
|
|
|
*/
|
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;
|
|
|
|
|
Scene *scene;
|
|
|
|
|
int local= 0, lib= 0;
|
|
|
|
|
|
|
|
|
|
if(brush->id.lib==0) return;
|
|
|
|
|
|
|
|
|
|
if(brush->clone.image) {
|
2006-07-31 15:53:03 +00:00
|
|
|
/* special case: ima always local immediately */
|
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->clone.image->id.lib= 0;
|
|
|
|
|
brush->clone.image->id.flag= LIB_LOCAL;
|
|
|
|
|
new_id(0, (ID *)brush->clone.image, 0);
|
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
|
|
|
|
|
|
|
|
for(scene= G.main->scene.first; scene; scene=scene->id.next)
|
2009-08-17 04:40:59 +00:00
|
|
|
if(paint_brush(&scene->toolsettings->imapaint.paint)==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(scene->id.lib) lib= 1;
|
|
|
|
|
else local= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(local && lib==0) {
|
|
|
|
|
brush->id.lib= 0;
|
|
|
|
|
brush->id.flag= LIB_LOCAL;
|
|
|
|
|
new_id(0, (ID *)brush, 0);
|
|
|
|
|
|
|
|
|
|
/* enable fake user by default */
|
2008-03-26 20:17:50 +00:00
|
|
|
if (!(brush->id.flag & LIB_FAKEUSER)) {
|
|
|
|
|
brush->id.flag |= LIB_FAKEUSER;
|
|
|
|
|
brush_toggled_fake_user(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
|
|
|
}
|
|
|
|
|
else if(local && lib) {
|
|
|
|
|
brushn= copy_brush(brush);
|
|
|
|
|
brushn->id.us= 1; /* only keep fake user */
|
|
|
|
|
brushn->id.flag |= LIB_FAKEUSER;
|
|
|
|
|
|
|
|
|
|
for(scene= G.main->scene.first; scene; scene=scene->id.next)
|
2009-08-17 04:40:59 +00:00
|
|
|
if(paint_brush(&scene->toolsettings->imapaint.paint)==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(scene->id.lib==0) {
|
2009-08-17 04:40:59 +00:00
|
|
|
paint_brush_set(&scene->toolsettings->imapaint.paint, brushn);
|
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
|
|
|
brushn->id.us++;
|
|
|
|
|
brush->id.us--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
/* Library Operations */
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
|
2009-08-17 02:49:31 +00:00
|
|
|
int brush_set_nr(Brush **current_brush, int nr, const char *name)
|
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 *idtest, *id;
|
|
|
|
|
|
|
|
|
|
id= (ID*)(*current_brush);
|
|
|
|
|
idtest= (ID*)BLI_findlink(&G.main->brush, nr-1);
|
|
|
|
|
|
|
|
|
|
if(idtest==0) { /* new brush */
|
|
|
|
|
if(id) idtest= (ID *)copy_brush((Brush *)id);
|
2009-08-17 02:49:31 +00:00
|
|
|
else idtest= (ID *)add_brush(name);
|
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
|
|
|
idtest->us--;
|
|
|
|
|
}
|
|
|
|
|
if(idtest!=id) {
|
|
|
|
|
brush_delete(current_brush);
|
|
|
|
|
*current_brush= (Brush *)idtest;
|
|
|
|
|
id_us_plus(idtest);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int brush_delete(Brush **current_brush)
|
|
|
|
|
{
|
|
|
|
|
if (*current_brush) {
|
|
|
|
|
(*current_brush)->id.us--;
|
|
|
|
|
*current_brush= NULL;
|
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
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-26 20:17:50 +00:00
|
|
|
void brush_toggled_fake_user(Brush *brush)
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{
|
|
|
|
|
ID *id= (ID*)brush;
|
|
|
|
|
if(id) {
|
|
|
|
|
if(id->flag & LIB_FAKEUSER) {
|
|
|
|
|
id_us_plus(id);
|
2008-03-26 20:17:50 +00:00
|
|
|
} else {
|
|
|
|
|
id->us--;
|
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-01-08 02:02:52 +00:00
|
|
|
void brush_curve_preset(Brush *b, /*CurveMappingPreset*/int preset)
|
2009-01-07 04:38:30 +00:00
|
|
|
{
|
|
|
|
|
CurveMap *cm = NULL;
|
|
|
|
|
|
|
|
|
|
if(!b->curve)
|
|
|
|
|
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;
|
|
|
|
|
curvemap_reset(cm, &b->curve->clipr, b->curve->preset);
|
2009-01-07 04:38:30 +00:00
|
|
|
curvemapping_changed(b->curve, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 20:05:36 +00:00
|
|
|
static MTex *brush_active_texture(Brush *brush)
|
|
|
|
|
{
|
2010-01-03 08:37:18 +00:00
|
|
|
if(brush)
|
|
|
|
|
return &brush->mtex;
|
2009-08-13 20:05:36 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
int brush_texture_set_nr(Brush *brush, int nr)
|
|
|
|
|
{
|
|
|
|
|
ID *idtest, *id=NULL;
|
|
|
|
|
|
2010-01-03 08:37:18 +00:00
|
|
|
id= (ID *)brush->mtex.tex;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
idtest= (ID*)BLI_findlink(&G.main->tex, nr-1);
|
|
|
|
|
if(idtest==0) { /* new tex */
|
|
|
|
|
if(id) idtest= (ID *)copy_texture((Tex *)id);
|
|
|
|
|
else idtest= (ID *)add_texture("Tex");
|
|
|
|
|
idtest->us--;
|
|
|
|
|
}
|
|
|
|
|
if(idtest!=id) {
|
|
|
|
|
brush_texture_delete(brush);
|
|
|
|
|
|
2010-01-03 08:37:18 +00:00
|
|
|
brush->mtex.tex= (Tex*)idtest;
|
2006-07-31 15:53:03 +00:00
|
|
|
id_us_plus(idtest);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int brush_texture_delete(Brush *brush)
|
|
|
|
|
{
|
2010-01-03 08:37:18 +00:00
|
|
|
if(brush->mtex.tex)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
int brush_clone_image_set_nr(Brush *brush, int nr)
|
|
|
|
|
{
|
|
|
|
|
if(brush && nr > 0) {
|
|
|
|
|
Image *ima= (Image*)BLI_findlink(&G.main->image, nr-1);
|
|
|
|
|
|
|
|
|
|
if(ima) {
|
|
|
|
|
brush_clone_image_delete(brush);
|
|
|
|
|
brush->clone.image= ima;
|
|
|
|
|
id_us_plus(&ima->id);
|
|
|
|
|
brush->clone.offset[0]= brush->clone.offset[1]= 0.0f;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int brush_clone_image_delete(Brush *brush)
|
|
|
|
|
{
|
|
|
|
|
if (brush && brush->clone.image) {
|
|
|
|
|
brush->clone.image->id.us--;
|
|
|
|
|
brush->clone.image= NULL;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-17 02:49:31 +00:00
|
|
|
void brush_check_exists(Brush **brush, const char *name)
|
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==NULL)
|
2009-08-17 02:49:31 +00:00
|
|
|
brush_set_nr(brush, 1, name);
|
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
|
|
|
}
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
/* Brush Sampling */
|
2006-08-27 13:29:00 +00:00
|
|
|
void brush_sample_tex(Brush *brush, float *xy, float *rgba)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
2010-01-03 08:37:18 +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;
|
|
|
|
|
|
|
|
|
|
co[0]= xy[0]/(brush->size >> 1);
|
|
|
|
|
co[1]= xy[1]/(brush->size >> 1);
|
|
|
|
|
co[2]= 0.0f;
|
|
|
|
|
|
2007-02-09 15:08:53 +00:00
|
|
|
hasrgb= externtex(mtex, co, &tin, &tr, &tg, &tb, &ta);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (hasrgb) {
|
|
|
|
|
rgba[0]= tr;
|
|
|
|
|
rgba[1]= tg;
|
|
|
|
|
rgba[2]= tb;
|
|
|
|
|
rgba[3]= ta;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rgba[0]= tin;
|
|
|
|
|
rgba[1]= tin;
|
|
|
|
|
rgba[2]= tin;
|
|
|
|
|
rgba[3]= 1.0f;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-08-27 13:29:00 +00:00
|
|
|
else if (rgba)
|
|
|
|
|
rgba[0]= rgba[1]= rgba[2]= rgba[3]= 1.0f;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
void brush_imbuf_new(Brush *brush, short flt, short texfall, int size, ImBuf **outbuf)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
2007-02-19 16:25:44 +00:00
|
|
|
float xy[2], dist, rgba[4], *dstf;
|
2006-08-27 13:29:00 +00:00
|
|
|
int x, y, rowbytes, xoff, yoff, imbflag;
|
2009-09-18 03:11:17 +00:00
|
|
|
int maxsize = brush->size >> 1;
|
2006-08-27 13:29:00 +00:00
|
|
|
char *dst, crgb[3];
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
imbflag= (flt)? IB_rectfloat: IB_rect;
|
|
|
|
|
xoff = -size/2.0f + 0.5f;
|
|
|
|
|
yoff = -size/2.0f + 0.5f;
|
2006-07-31 15:53:03 +00:00
|
|
|
rowbytes= size*4;
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (*outbuf)
|
|
|
|
|
ibuf= *outbuf;
|
|
|
|
|
else
|
|
|
|
|
ibuf= IMB_allocImBuf(size, size, 32, imbflag, 0);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (flt) {
|
2006-07-31 15:53:03 +00:00
|
|
|
for (y=0; y < ibuf->y; y++) {
|
|
|
|
|
dstf = ibuf->rect_float + y*rowbytes;
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
VECCOPY(dstf, brush->rgb);
|
2009-09-24 01:32:23 +00:00
|
|
|
dstf[3]= brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
else if (texfall == 1) {
|
|
|
|
|
brush_sample_tex(brush, xy, dstf);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
|
|
|
|
|
|
|
|
|
|
brush_sample_tex(brush, xy, rgba);
|
|
|
|
|
|
|
|
|
|
dstf[0] = rgba[0]*brush->rgb[0];
|
|
|
|
|
dstf[1] = rgba[1]*brush->rgb[1];
|
|
|
|
|
dstf[2] = rgba[2]*brush->rgb[2];
|
2009-09-24 01:32:23 +00:00
|
|
|
dstf[3] = rgba[3]*brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize);
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2006-08-27 13:29:00 +00:00
|
|
|
crgb[0]= FTOCHAR(brush->rgb[0]);
|
|
|
|
|
crgb[1]= FTOCHAR(brush->rgb[1]);
|
|
|
|
|
crgb[2]= FTOCHAR(brush->rgb[2]);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
for (y=0; y < ibuf->y; y++) {
|
|
|
|
|
dst = (char*)ibuf->rect + y*rowbytes;
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
|
|
|
|
|
|
|
|
|
|
dst[0]= crgb[0];
|
|
|
|
|
dst[1]= crgb[1];
|
|
|
|
|
dst[2]= crgb[2];
|
2009-09-18 03:47:17 +00:00
|
|
|
dst[3]= FTOCHAR(brush->alpha*brush_curve_strength(brush, dist, maxsize));
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
|
|
|
|
else if (texfall == 1) {
|
|
|
|
|
brush_sample_tex(brush, xy, rgba);
|
|
|
|
|
dst[0]= FTOCHAR(rgba[0]);
|
|
|
|
|
dst[1]= FTOCHAR(rgba[1]);
|
|
|
|
|
dst[2]= FTOCHAR(rgba[2]);
|
|
|
|
|
dst[3]= FTOCHAR(rgba[3]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
|
|
|
|
|
|
|
|
|
|
brush_sample_tex(brush, xy, rgba);
|
|
|
|
|
dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]);
|
|
|
|
|
dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
|
|
|
|
|
dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
|
2009-09-24 01:32:23 +00:00
|
|
|
dst[3] = FTOCHAR(rgba[3]*brush->alpha*brush_curve_strength_clamp(brush, dist, maxsize));
|
2006-08-27 13:29:00 +00:00
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
*outbuf= ibuf;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Brush Painting */
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
typedef struct BrushPainterCache {
|
|
|
|
|
short enabled;
|
|
|
|
|
|
|
|
|
|
int size; /* size override, if 0 uses brush->size */
|
|
|
|
|
short flt; /* need float imbuf? */
|
|
|
|
|
short texonly; /* no alpha, color or fallof, only texture in imbuf */
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
Brush *brush;
|
|
|
|
|
|
|
|
|
|
float lastmousepos[2]; /* mouse position of last paint call */
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
double accumtime; /* accumulated time since last paint op (airbrush) */
|
|
|
|
|
double lasttime; /* time of last update */
|
|
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
float lastpressure;
|
|
|
|
|
|
2006-07-31 15:53:03 +00:00
|
|
|
short firsttouch; /* first paint op */
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BrushPainter *brush_painter_new(Brush *brush)
|
|
|
|
|
{
|
|
|
|
|
BrushPainter *painter= MEM_callocN(sizeof(BrushPainter), "BrushPainter");
|
|
|
|
|
|
|
|
|
|
painter->brush= brush;
|
|
|
|
|
painter->firsttouch= 1;
|
2006-08-27 13:29:00 +00:00
|
|
|
painter->cache.lastsize= -1; /* force ibuf create in refresh */
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-09-12 16:53:27 +00:00
|
|
|
painter->startsize = brush->size;
|
|
|
|
|
painter->startalpha = brush->alpha;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void brush_painter_require_imbuf(BrushPainter *painter, short flt, short texonly, int size)
|
|
|
|
|
{
|
2006-08-27 13:29:00 +00:00
|
|
|
if ((painter->cache.flt != flt) || (painter->cache.size != size) ||
|
|
|
|
|
((painter->cache.texonly != texonly) && texonly)) {
|
|
|
|
|
if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf);
|
|
|
|
|
if (painter->cache.maskibuf) IMB_freeImBuf(painter->cache.maskibuf);
|
|
|
|
|
painter->cache.ibuf= painter->cache.maskibuf= NULL;
|
|
|
|
|
painter->cache.lastsize= -1; /* force ibuf create in refresh */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (painter->cache.flt != flt) {
|
|
|
|
|
if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf);
|
|
|
|
|
painter->cache.texibuf= NULL;
|
|
|
|
|
painter->cache.lastsize= -1; /* force ibuf create in refresh */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->cache.size= size;
|
|
|
|
|
painter->cache.flt= flt;
|
|
|
|
|
painter->cache.texonly= texonly;
|
|
|
|
|
painter->cache.enabled= 1;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void brush_painter_free(BrushPainter *painter)
|
|
|
|
|
{
|
2006-09-12 16:53:27 +00:00
|
|
|
Brush *brush = painter->brush;
|
|
|
|
|
|
|
|
|
|
brush->size = painter->startsize;
|
|
|
|
|
brush->alpha = 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);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-27 13:29: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, float *pos)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
|
|
|
|
Brush *brush= painter->brush;
|
2006-08-27 13:29:00 +00:00
|
|
|
ImBuf *ibuf, *maskibuf, *texibuf;
|
|
|
|
|
float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
|
|
|
|
|
char *b, *m, *t, *ot= NULL;
|
|
|
|
|
int dotexold, origx= x, origy= y;
|
|
|
|
|
|
|
|
|
|
xoff = -brush->size/2.0f + 0.5f;
|
|
|
|
|
yoff = -brush->size/2.0f + 0.5f;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (painter->cache.flt) {
|
|
|
|
|
for (; y < h; y++) {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (dotexold)
|
|
|
|
|
otf = oldtexibuf->rect_float + ((y - origy + yt)*oldtexibuf->x + xt)*4;
|
|
|
|
|
|
|
|
|
|
for (x=origx; x < w; x++, bf+=4, mf+=4, tf+=4) {
|
|
|
|
|
if (dotexold) {
|
|
|
|
|
VECCOPY(tf, otf);
|
|
|
|
|
tf[3] = otf[3];
|
|
|
|
|
otf += 4;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
xy[0] = x + xoff;
|
|
|
|
|
xy[1] = y + yoff;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
brush_sample_tex(brush, xy, tf);
|
|
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (; y < h; y++) {
|
|
|
|
|
b = (char*)ibuf->rect + (y*ibuf->x + origx)*4;
|
|
|
|
|
t = (char*)texibuf->rect + (y*texibuf->x + origx)*4;
|
|
|
|
|
m = (char*)maskibuf->rect + (y*maskibuf->x + origx)*4;
|
|
|
|
|
|
|
|
|
|
if (dotexold)
|
|
|
|
|
ot = (char*)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
|
|
|
|
|
|
|
|
|
|
for (x=origx; x < w; x++, b+=4, m+=4, t+=4) {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
brush_sample_tex(brush, xy, rgba);
|
|
|
|
|
t[0]= FTOCHAR(rgba[0]);
|
|
|
|
|
t[1]= FTOCHAR(rgba[1]);
|
|
|
|
|
t[2]= FTOCHAR(rgba[2]);
|
|
|
|
|
t[3]= FTOCHAR(rgba[3]);
|
|
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-08-27 13:29:00 +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-07-31 15:53:03 +00:00
|
|
|
|
2009-09-14 16:52:06 +00:00
|
|
|
static void brush_painter_fixed_tex_partial_update(BrushPainter *painter, float *pos)
|
2006-08-27 13:29:00 +00:00
|
|
|
{
|
|
|
|
|
Brush *brush= painter->brush;
|
|
|
|
|
BrushPainterCache *cache= &painter->cache;
|
|
|
|
|
ImBuf *oldtexibuf, *ibuf;
|
|
|
|
|
int imbflag, destx, desty, srcx, srcy, w, h, x1, y1, x2, y2;
|
|
|
|
|
|
|
|
|
|
imbflag= (cache->flt)? IB_rectfloat: IB_rect;
|
|
|
|
|
if (!cache->ibuf)
|
|
|
|
|
cache->ibuf= IMB_allocImBuf(brush->size, brush->size, 32, imbflag, 0);
|
|
|
|
|
ibuf= cache->ibuf;
|
|
|
|
|
|
|
|
|
|
oldtexibuf= cache->texibuf;
|
|
|
|
|
cache->texibuf= IMB_allocImBuf(brush->size, brush->size, 32, imbflag, 0);
|
|
|
|
|
|
|
|
|
|
if (oldtexibuf) {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
srcx= srcy= 0;
|
|
|
|
|
destx= desty= 0;
|
|
|
|
|
w= h= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x1= destx;
|
|
|
|
|
y1= desty;
|
|
|
|
|
x2= destx+w;
|
|
|
|
|
y2= desty+h;
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void brush_painter_refresh_cache(BrushPainter *painter, float *pos)
|
|
|
|
|
{
|
|
|
|
|
Brush *brush= painter->brush;
|
|
|
|
|
BrushPainterCache *cache= &painter->cache;
|
2010-01-03 08:37:18 +00:00
|
|
|
MTex *mtex= &brush->mtex;
|
2006-08-27 13:29:00 +00:00
|
|
|
int size;
|
|
|
|
|
short flt;
|
|
|
|
|
|
|
|
|
|
if ((brush->size != cache->lastsize) || (brush->alpha != cache->lastalpha)
|
2010-03-22 09:30:00 +00:00
|
|
|
|| (brush->jitter != cache->lastjitter)) {
|
2006-08-27 13:29:00 +00:00
|
|
|
if (cache->ibuf) {
|
|
|
|
|
IMB_freeImBuf(cache->ibuf);
|
|
|
|
|
cache->ibuf= NULL;
|
|
|
|
|
}
|
|
|
|
|
if (cache->maskibuf) {
|
|
|
|
|
IMB_freeImBuf(cache->maskibuf);
|
|
|
|
|
cache->maskibuf= NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flt= cache->flt;
|
|
|
|
|
size= (cache->size)? cache->size: brush->size;
|
|
|
|
|
|
2007-02-09 15:08:53 +00:00
|
|
|
if (!(mtex && mtex->tex) || (mtex->tex->type==0)) {
|
2006-08-27 13:29:00 +00:00
|
|
|
brush_imbuf_new(brush, flt, 0, size, &cache->ibuf);
|
|
|
|
|
}
|
|
|
|
|
else if (brush->flag & BRUSH_FIXED_TEX) {
|
|
|
|
|
brush_imbuf_new(brush, flt, 0, size, &cache->maskibuf);
|
|
|
|
|
brush_painter_fixed_tex_partial_update(painter, pos);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
brush_imbuf_new(brush, flt, 2, size, &cache->ibuf);
|
|
|
|
|
|
|
|
|
|
cache->lastsize= brush->size;
|
|
|
|
|
cache->lastalpha= brush->alpha;
|
2009-09-18 11:25:52 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void brush_painter_break_stroke(BrushPainter *painter)
|
|
|
|
|
{
|
|
|
|
|
painter->firsttouch= 1;
|
2006-07-31 15:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
static void brush_apply_pressure(BrushPainter *painter, Brush *brush, float pressure)
|
|
|
|
|
{
|
|
|
|
|
if (brush->flag & BRUSH_ALPHA_PRESSURE)
|
|
|
|
|
brush->alpha = MAX2(0.0, painter->startalpha*pressure);
|
|
|
|
|
if (brush->flag & BRUSH_SIZE_PRESSURE)
|
|
|
|
|
brush->size = MAX2(1.0, painter->startsize*pressure);
|
2009-09-18 11:25:52 +00:00
|
|
|
if (brush->flag & BRUSH_JITTER_PRESSURE)
|
|
|
|
|
brush->jitter = MAX2(0.0, painter->startjitter*pressure);
|
2006-09-24 19:29:25 +00:00
|
|
|
if (brush->flag & BRUSH_SPACING_PRESSURE)
|
|
|
|
|
brush->spacing = MAX2(1.0, painter->startspacing*(1.5f-pressure));
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-18 11:25:52 +00:00
|
|
|
static void brush_jitter_pos(Brush *brush, float *pos, float *jitterpos)
|
|
|
|
|
{
|
|
|
|
|
if(brush->jitter){
|
|
|
|
|
jitterpos[0] = pos[0] + ((BLI_frand()-0.5f) * brush->size * brush->jitter * 2);
|
|
|
|
|
jitterpos[1] = pos[1] + ((BLI_frand()-0.5f) * brush->size * brush->jitter * 2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
VECCOPY2D(jitterpos, pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, double time, float pressure, void *user)
|
2006-07-31 15:53:03 +00:00
|
|
|
{
|
|
|
|
|
Brush *brush= painter->brush;
|
|
|
|
|
int totpaintops= 0;
|
|
|
|
|
|
2009-09-18 11:25:52 +00:00
|
|
|
if (pressure == 0.0f) {
|
|
|
|
|
if(painter->lastpressure) // XXX - hack, operator misses
|
|
|
|
|
pressure= painter->lastpressure;
|
|
|
|
|
else
|
|
|
|
|
pressure = 1.0f; /* zero pressure == not using tablet */
|
|
|
|
|
}
|
2006-07-31 15:53:03 +00:00
|
|
|
if (painter->firsttouch) {
|
|
|
|
|
/* paint exactly once on first touch */
|
2006-08-27 13:29:00 +00:00
|
|
|
painter->startpaintpos[0]= pos[0];
|
|
|
|
|
painter->startpaintpos[1]= pos[1];
|
|
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
brush_apply_pressure(painter, brush, pressure);
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.enabled)
|
|
|
|
|
brush_painter_refresh_cache(painter, pos);
|
2006-07-31 15:53:03 +00:00
|
|
|
totpaintops += func(user, painter->cache.ibuf, pos, pos);
|
|
|
|
|
|
|
|
|
|
painter->lasttime= time;
|
|
|
|
|
painter->firsttouch= 0;
|
2006-09-25 12:30:12 +00:00
|
|
|
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;
|
|
|
|
|
double starttime, curtime= time;
|
|
|
|
|
|
|
|
|
|
/* compute brush spacing adapted to brush size */
|
|
|
|
|
spacing= brush->rate; //brush->size*brush->spacing*0.01f;
|
|
|
|
|
|
|
|
|
|
/* setup starting time, direction vector and accumulated time */
|
|
|
|
|
starttime= painter->accumtime;
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v2_v2v2(dmousepos, pos, painter->lastmousepos);
|
|
|
|
|
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) {
|
|
|
|
|
step= (spacing - starttime)*len;
|
|
|
|
|
paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step;
|
|
|
|
|
paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step;
|
|
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
if (painter->cache.enabled)
|
|
|
|
|
brush_painter_refresh_cache(painter);
|
|
|
|
|
totpaintops += func(user, painter->cache.ibuf,
|
|
|
|
|
painter->lastpaintpos, paintpos);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
painter->lastpaintpos[0]= paintpos[0];
|
|
|
|
|
painter->lastpaintpos[1]= paintpos[1];
|
|
|
|
|
painter->accumtime -= spacing;
|
|
|
|
|
starttime -= spacing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->lasttime= curtime;
|
|
|
|
|
}
|
|
|
|
|
#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;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
/* compute brush spacing adapted to brush size, spacing may depend
|
|
|
|
|
on pressure, so update it */
|
|
|
|
|
brush_apply_pressure(painter, brush, painter->lastpressure);
|
2007-01-11 15:00:17 +00:00
|
|
|
spacing= MAX2(1.0f, brush->size)*brush->spacing*0.01f;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
/* setup starting distance, direction vector and accumulated distance */
|
|
|
|
|
startdistance= painter->accumdistance;
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v2_v2v2(dmousepos, pos, painter->lastmousepos);
|
|
|
|
|
len= normalize_v2(dmousepos);
|
2006-09-24 19:29:25 +00:00
|
|
|
painter->accumdistance += len;
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
/* do paint op over unpainted distance */
|
2007-01-11 15:00:17 +00:00
|
|
|
while ((len > 0.0f) && (painter->accumdistance >= spacing)) {
|
2006-07-31 15:53:03 +00:00
|
|
|
step= spacing - startdistance;
|
|
|
|
|
paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step;
|
|
|
|
|
paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step;
|
|
|
|
|
|
2006-09-24 19:29:25 +00:00
|
|
|
t = step/len;
|
2007-01-11 15:00:17 +00:00
|
|
|
press= (1.0f-t)*painter->lastpressure + t*pressure;
|
2006-09-24 19:29:25 +00:00
|
|
|
brush_apply_pressure(painter, brush, press);
|
2007-01-11 15:00:17 +00:00
|
|
|
spacing= MAX2(1.0f, brush->size)*brush->spacing*0.01f;
|
2006-09-24 19:29:25 +00:00
|
|
|
|
2009-09-18 11:25:52 +00:00
|
|
|
brush_jitter_pos(brush, paintpos, finalpos);
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.enabled)
|
2009-09-18 11:25:52 +00:00
|
|
|
brush_painter_refresh_cache(painter, finalpos);
|
2006-09-24 19:29:25 +00:00
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
totpaintops +=
|
2009-09-18 11:25:52 +00:00
|
|
|
func(user, painter->cache.ibuf, painter->lastpaintpos, finalpos);
|
2006-07-31 15:53:03 +00:00
|
|
|
|
|
|
|
|
painter->lastpaintpos[0]= paintpos[0];
|
|
|
|
|
painter->lastpaintpos[1]= paintpos[1];
|
|
|
|
|
painter->accumdistance -= spacing;
|
|
|
|
|
startdistance -= spacing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* do airbrush paint ops, based on the number of paint ops left over
|
|
|
|
|
from regular painting. this is a temporary solution until we have
|
|
|
|
|
accurate time stamps for mouse move events */
|
|
|
|
|
if (brush->flag & BRUSH_AIRBRUSH) {
|
|
|
|
|
double curtime= time;
|
|
|
|
|
double painttime= brush->rate*totpaintops;
|
|
|
|
|
|
|
|
|
|
painter->accumtime += curtime - painter->lasttime;
|
|
|
|
|
if (painter->accumtime <= painttime)
|
|
|
|
|
painter->accumtime= 0.0;
|
|
|
|
|
else
|
|
|
|
|
painter->accumtime -= painttime;
|
|
|
|
|
|
|
|
|
|
while (painter->accumtime >= brush->rate) {
|
2006-09-24 19:29:25 +00:00
|
|
|
brush_apply_pressure(painter, brush, pressure);
|
2009-09-18 11:25:52 +00:00
|
|
|
|
|
|
|
|
brush_jitter_pos(brush, pos, finalpos);
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
if (painter->cache.enabled)
|
2009-09-18 11:25:52 +00:00
|
|
|
brush_painter_refresh_cache(painter, finalpos);
|
|
|
|
|
|
2006-08-27 13:29:00 +00:00
|
|
|
totpaintops +=
|
2009-09-18 11:25:52 +00:00
|
|
|
func(user, painter->cache.ibuf, painter->lastmousepos, finalpos);
|
2006-07-31 15:53:03 +00:00
|
|
|
painter->accumtime -= brush->rate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->lasttime= curtime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->lastmousepos[0]= pos[0];
|
|
|
|
|
painter->lastmousepos[1]= pos[1];
|
2006-09-24 19:29:25 +00:00
|
|
|
painter->lastpressure= pressure;
|
|
|
|
|
|
|
|
|
|
brush->alpha = painter->startalpha;
|
|
|
|
|
brush->size = 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 */
|
2009-09-24 01:32:23 +00:00
|
|
|
float brush_curve_strength_clamp(Brush *br, float p, const float len)
|
|
|
|
|
{
|
|
|
|
|
if(p >= len) p= 1.0f;
|
|
|
|
|
else p= p/len;
|
|
|
|
|
|
|
|
|
|
p= curvemapping_evaluateF(br->curve, 0, p);
|
|
|
|
|
if(p < 0.0) p= 0.0f;
|
|
|
|
|
else if(p > 1.0f) p= 1.0f;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
/* same as above but can return negative values if the curve enables
|
|
|
|
|
* used for sculpt only */
|
2009-01-25 07:28:11 +00:00
|
|
|
float brush_curve_strength(Brush *br, float p, const float len)
|
|
|
|
|
{
|
2009-09-24 01:32:23 +00:00
|
|
|
if(p >= len) p= 1.0f;
|
|
|
|
|
else p= p/len;
|
|
|
|
|
return curvemapping_evaluateF(br->curve, 0, p);
|
2009-01-25 07:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: should probably be unified with BrushPainter stuff? */
|
|
|
|
|
unsigned int *brush_gen_texture_cache(Brush *br, int half_side)
|
|
|
|
|
{
|
|
|
|
|
unsigned int *texcache = NULL;
|
2010-01-03 08:37:18 +00:00
|
|
|
MTex *mtex = &br->mtex;
|
2009-01-25 07:28:11 +00:00
|
|
|
TexResult texres;
|
|
|
|
|
int hasrgb, ix, iy;
|
|
|
|
|
int side = half_side * 2;
|
|
|
|
|
|
|
|
|
|
memset(&texres, 0, sizeof(TexResult));
|
|
|
|
|
|
|
|
|
|
if(mtex && mtex->tex) {
|
|
|
|
|
float x, y, step = 2.0 / side, co[3];
|
|
|
|
|
|
|
|
|
|
texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache");
|
|
|
|
|
|
|
|
|
|
BKE_image_get_ibuf(mtex->tex->ima, NULL);
|
|
|
|
|
|
|
|
|
|
/*do normalized cannonical view coords for texture*/
|
|
|
|
|
for (y=-1.0, iy=0; iy<side; iy++, y += step) {
|
|
|
|
|
for (x=-1.0, ix=0; ix<side; ix++, x += step) {
|
|
|
|
|
co[0]= x;
|
|
|
|
|
co[1]= y;
|
|
|
|
|
co[2]= 0.0f;
|
|
|
|
|
|
|
|
|
|
/* This is copied from displace modifier code */
|
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
|
|
|
|
|
*/
|
|
|
|
|
if(hasrgb & TEX_RGB)
|
|
|
|
|
texres.tin = (0.35 * texres.tr + 0.45 *
|
2010-03-22 09:30:00 +00:00
|
|
|
texres.tg + 0.2 * texres.tb);
|
2009-01-25 07:28:11 +00:00
|
|
|
|
|
|
|
|
texres.tin = texres.tin * 255.0;
|
|
|
|
|
((char*)texcache)[(iy*side+ix)*4] = (char)texres.tin;
|
|
|
|
|
((char*)texcache)[(iy*side+ix)*4+1] = (char)texres.tin;
|
|
|
|
|
((char*)texcache)[(iy*side+ix)*4+2] = (char)texres.tin;
|
|
|
|
|
((char*)texcache)[(iy*side+ix)*4+3] = (char)texres.tin;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return texcache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**** Radial Control ****/
|
|
|
|
|
static struct ImBuf *brush_gen_radial_control_imbuf(Brush *br)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture");
|
|
|
|
|
unsigned int *texcache;
|
|
|
|
|
int side = 128;
|
|
|
|
|
int half = side / 2;
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
texcache = brush_gen_texture_cache(br, half);
|
|
|
|
|
im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect");
|
|
|
|
|
im->x = im->y = side;
|
|
|
|
|
|
|
|
|
|
for(i=0; i<side; ++i) {
|
|
|
|
|
for(j=0; j<side; ++j) {
|
|
|
|
|
float magn= sqrt(pow(i - half, 2) + pow(j - half, 2));
|
2009-09-24 01:32:23 +00:00
|
|
|
im->rect_float[i*side + j]= brush_curve_strength_clamp(br, magn, half);
|
2009-01-25 07:28:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Modulate curve with texture */
|
|
|
|
|
if(texcache) {
|
2009-01-29 03:50:46 +00:00
|
|
|
for(i=0; i<side; ++i) {
|
2009-01-25 07:28:11 +00:00
|
|
|
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-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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 19:31:25 +00:00
|
|
|
void brush_radial_control_invoke(wmOperator *op, Brush *br, float size_weight)
|
2009-01-25 07:28:11 +00:00
|
|
|
{
|
|
|
|
|
int mode = RNA_int_get(op->ptr, "mode");
|
2009-02-19 16:22:07 +00:00
|
|
|
float original_value= 0;
|
2009-01-25 07:28:11 +00:00
|
|
|
|
|
|
|
|
if(mode == WM_RADIALCONTROL_SIZE)
|
2009-02-22 19:31:25 +00:00
|
|
|
original_value = br->size * size_weight;
|
2009-01-25 07:28:11 +00:00
|
|
|
else if(mode == WM_RADIALCONTROL_STRENGTH)
|
|
|
|
|
original_value = br->alpha;
|
2009-08-13 20:05:36 +00:00
|
|
|
else if(mode == WM_RADIALCONTROL_ANGLE) {
|
|
|
|
|
MTex *mtex = brush_active_texture(br);
|
|
|
|
|
if(mtex)
|
|
|
|
|
original_value = mtex->rot;
|
|
|
|
|
}
|
2009-01-25 07:28:11 +00:00
|
|
|
|
|
|
|
|
RNA_float_set(op->ptr, "initial_value", original_value);
|
|
|
|
|
op->customdata = brush_gen_radial_control_imbuf(br);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 19:31:25 +00:00
|
|
|
int brush_radial_control_exec(wmOperator *op, Brush *br, float size_weight)
|
2009-01-25 07:28:11 +00:00
|
|
|
{
|
|
|
|
|
int mode = RNA_int_get(op->ptr, "mode");
|
|
|
|
|
float new_value = RNA_float_get(op->ptr, "new_value");
|
|
|
|
|
const float conv = 0.017453293;
|
|
|
|
|
|
|
|
|
|
if(mode == WM_RADIALCONTROL_SIZE)
|
2009-02-22 19:31:25 +00:00
|
|
|
br->size = new_value * size_weight;
|
2009-01-25 07:28:11 +00:00
|
|
|
else if(mode == WM_RADIALCONTROL_STRENGTH)
|
|
|
|
|
br->alpha = new_value;
|
2009-08-13 20:05:36 +00:00
|
|
|
else if(mode == WM_RADIALCONTROL_ANGLE) {
|
|
|
|
|
MTex *mtex = brush_active_texture(br);
|
|
|
|
|
if(mtex)
|
|
|
|
|
mtex->rot = new_value * conv;
|
|
|
|
|
}
|
2009-01-25 07:28:11 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|