2009-08-19 21:24:52 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-05-09 17:14:35 +10:00
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-08-19 21:24:52 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 by Nicholas Bishop
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup edsculpt
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_listbase.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_math.h"
|
2013-03-13 03:46:22 +00:00
|
|
|
#include "BLI_rand.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
2018-06-12 17:13:23 +02:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_brush_types.h"
|
2014-07-21 12:02:05 +02:00
|
|
|
#include "DNA_curve_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2009-08-19 21:24:52 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
#include "BKE_brush.h"
|
2013-08-19 19:04:39 +00:00
|
|
|
#include "BKE_colortools.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_curve.h"
|
2014-04-13 19:03:14 +03:00
|
|
|
#include "BKE_image.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_paint.h"
|
2009-08-19 21:24:52 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2017-02-22 18:19:42 +01:00
|
|
|
#include "GPU_immediate.h"
|
2018-06-27 19:07:23 -06:00
|
|
|
#include "GPU_state.h"
|
2016-06-10 07:39:12 +10:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
2014-04-13 19:03:14 +03:00
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
#include "paint_intern.h"
|
2019-08-19 17:03:55 +02:00
|
|
|
#include "sculpt_intern.h"
|
2009-08-19 21:24:52 +00:00
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2016-01-26 21:58:54 +01:00
|
|
|
//#define DEBUG_TIME
|
2014-10-07 20:19:06 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_TIME
|
|
|
|
# include "PIL_time_utildefines.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-21 23:32:46 +00:00
|
|
|
typedef struct PaintSample {
|
|
|
|
float mouse[2];
|
2013-05-18 11:25:24 +00:00
|
|
|
float pressure;
|
2012-05-21 23:32:46 +00:00
|
|
|
} PaintSample;
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
typedef struct PaintStroke {
|
2009-08-20 05:13:07 +00:00
|
|
|
void *mode_data;
|
2014-07-21 12:02:05 +02:00
|
|
|
void *stroke_cursor;
|
2009-08-21 00:46:36 +00:00
|
|
|
wmTimer *timer;
|
2018-06-12 17:13:23 +02:00
|
|
|
struct RNG *rng;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
/* Cached values */
|
|
|
|
ViewContext vc;
|
|
|
|
Brush *brush;
|
2013-12-09 22:36:33 +02:00
|
|
|
UnifiedPaintSettings *ups;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/* used for lines and curves */
|
|
|
|
ListBase line;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-21 23:32:46 +00:00
|
|
|
/* Paint stroke can use up to PAINT_MAX_INPUT_SAMPLES prior inputs
|
|
|
|
* to smooth the stroke */
|
|
|
|
PaintSample samples[PAINT_MAX_INPUT_SAMPLES];
|
|
|
|
int num_samples;
|
|
|
|
int cur_sample;
|
2019-11-18 22:47:23 +01:00
|
|
|
int tot_samples;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
float last_mouse_position[2];
|
2019-09-06 17:16:59 +02:00
|
|
|
float last_world_space_position[3];
|
2019-08-19 17:03:55 +02:00
|
|
|
bool stroke_over_mesh;
|
2014-07-21 12:02:05 +02:00
|
|
|
/* space distance covered so far */
|
|
|
|
float stroke_distance;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-20 10:41:08 +00:00
|
|
|
/* Set whether any stroke step has yet occurred
|
2012-03-03 16:31:46 +00:00
|
|
|
* e.g. in sculpt mode, stroke doesn't start until cursor
|
|
|
|
* passes over the mesh */
|
2014-02-05 22:18:33 +11:00
|
|
|
bool stroke_started;
|
2018-01-24 14:25:59 +01:00
|
|
|
/* Set when enough motion was found for rake rotation */
|
|
|
|
bool rake_started;
|
2011-03-01 16:26:37 +00:00
|
|
|
/* event that started stroke, for modal() return */
|
|
|
|
int event_type;
|
2013-05-18 15:24:25 +00:00
|
|
|
/* check if stroke variables have been initialized */
|
|
|
|
bool stroke_init;
|
|
|
|
/* check if various brush mapping variables have been initialized */
|
2013-03-13 03:46:22 +00:00
|
|
|
bool brush_init;
|
|
|
|
float initial_mouse[2];
|
2013-05-18 09:44:30 +00:00
|
|
|
/* cached_pressure stores initial pressure for size pressure influence mainly */
|
2014-04-13 18:14:45 +03:00
|
|
|
float cached_size_pressure;
|
2013-05-18 09:44:30 +00:00
|
|
|
/* last pressure will store last pressure value for use in interpolation for space strokes */
|
|
|
|
float last_pressure;
|
2014-09-01 21:10:17 +02:00
|
|
|
int stroke_mode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-01 19:31:28 +01:00
|
|
|
float last_tablet_event_pressure;
|
|
|
|
|
2013-03-15 09:19:41 +00:00
|
|
|
float zoom_2d;
|
2013-05-18 09:44:30 +00:00
|
|
|
int pen_flip;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Sculpt: Experimental Pen Tilt Support
This adds support for pen tilt in sculpt mode. For now, pen tilt is used
by tweaking the tilt strength property, which controls how much the pen
angle affects the sculpt normal. This is available in Draw, Draw Sharp,
Flatten, Fill, Scrape and Clay Strips brushes, but it can be enabled in
more tools later.
The purpose of this patch is to have a usable implementation of pen tilt
in a painting mode, so users can test and see in which hardware and
platforms this feature is supported and how well it works. If it works
ok, more tools and features that rely on pen tilt can be implemented,
like brushes that blend between two deformations depending on the angle.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8893
2020-10-08 00:00:36 +02:00
|
|
|
/* Tilt, as read from the event. */
|
|
|
|
float x_tilt;
|
|
|
|
float y_tilt;
|
|
|
|
|
2015-02-02 11:29:01 +01:00
|
|
|
/* line constraint */
|
2015-01-30 19:47:58 +01:00
|
|
|
bool constrain_line;
|
2015-02-02 11:29:01 +01:00
|
|
|
float constrained_pos[2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-10-27 19:53:34 +00:00
|
|
|
StrokeGetLocation get_location;
|
2009-08-19 21:24:52 +00:00
|
|
|
StrokeTestStart test_start;
|
|
|
|
StrokeUpdateStep update_step;
|
2013-05-15 14:37:05 +00:00
|
|
|
StrokeRedraw redraw;
|
2009-08-19 21:24:52 +00:00
|
|
|
StrokeDone done;
|
|
|
|
} PaintStroke;
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/*** Cursors ***/
|
|
|
|
static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata)
|
2009-08-20 05:13:07 +00:00
|
|
|
{
|
Paint refactoring commit, non-disruptive (in theory :p)
* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:
Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:
These attributes/aspects are:
Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)
Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.
Properties that affect this are:
Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.
These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.
2013-04-12 17:21:31 +00:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
2009-08-20 05:13:07 +00:00
|
|
|
PaintStroke *stroke = customdata;
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (stroke && brush) {
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(true);
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_ALPHA);
|
2017-02-22 18:19:42 +01:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = stroke->vc.region;
|
2018-05-10 16:29:14 -03:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2017-02-22 18:19:42 +01:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
|
|
|
|
immUniformColor4ubv(paint->paint_cursor_col);
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
2017-02-23 02:52:36 -03:00
|
|
|
immVertex2f(pos, x, y);
|
2018-05-10 16:29:14 -03:00
|
|
|
immVertex2f(pos,
|
2020-03-06 16:56:42 +01:00
|
|
|
stroke->last_mouse_position[0] + region->winrct.xmin,
|
|
|
|
stroke->last_mouse_position[1] + region->winrct.ymin);
|
2018-05-10 16:29:14 -03:00
|
|
|
|
2017-02-22 18:19:42 +01:00
|
|
|
immEnd();
|
2017-02-23 02:52:36 -03:00
|
|
|
|
2017-02-22 18:19:42 +01:00
|
|
|
immUnbindProgram();
|
|
|
|
|
2020-08-16 15:38:34 +02:00
|
|
|
GPU_blend(GPU_BLEND_NONE);
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(false);
|
2009-08-20 05:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
|
|
|
|
{
|
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
PaintStroke *stroke = customdata;
|
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(true);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
uint shdr_pos = GPU_vertformat_attr_add(
|
|
|
|
immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2017-07-13 16:44:02 +02:00
|
|
|
immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2017-04-26 21:22:05 +02:00
|
|
|
float viewport_size[4];
|
2018-07-02 18:27:05 +02:00
|
|
|
GPU_viewport_size_get_f(viewport_size);
|
2017-04-26 21:22:05 +02:00
|
|
|
immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
|
2017-02-23 02:52:36 -03:00
|
|
|
|
2018-07-01 08:42:16 +02:00
|
|
|
immUniform1i("colors_len", 2); /* "advanced" mode */
|
2017-04-26 21:22:05 +02:00
|
|
|
const float alpha = (float)paint->paint_cursor_col[3] / 255.0f;
|
Reworked version of dashed line shader.
Using geometry shader allows us to get rid of the 'line origin' extra
vertex attribute, which means dashed shader no longer requires fiddling
with those vertex attributes definition, and, most importantly, does not
require anymore special drawing code!
As you can see, this makes code much simpler, and much less verbose,
especially in complex cases.
In addition, changed how dashes are handled, to have two 'modes', a
simple one with single color (using default "color" uniform name), and a
more advanced one allowing more complex and multi-color patterns.
Note that since GLSL 1.2 does not support geometry shaders, a hack was
added for now (which gives solid lines, but at least does not make
Blender crash).
2017-05-01 16:21:53 +02:00
|
|
|
immUniformArray4fv(
|
|
|
|
"colors", (float *)(float[][4]){{0.0f, 0.0f, 0.0f, alpha}, {1.0f, 1.0f, 1.0f, alpha}}, 2);
|
2017-04-26 21:22:05 +02:00
|
|
|
immUniform1f("dash_width", 6.0f);
|
2019-06-21 08:24:58 +10:00
|
|
|
immUniform1f("dash_factor", 0.5f);
|
2017-02-23 02:52:36 -03:00
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
immBegin(GPU_PRIM_LINES, 2);
|
2017-02-23 02:52:36 -03:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = stroke->vc.region;
|
2018-05-10 16:29:14 -03:00
|
|
|
|
2015-02-02 23:29:53 +11:00
|
|
|
if (stroke->constrain_line) {
|
2018-05-10 16:29:14 -03:00
|
|
|
immVertex2f(shdr_pos,
|
2020-03-06 16:56:42 +01:00
|
|
|
stroke->last_mouse_position[0] + region->winrct.xmin,
|
|
|
|
stroke->last_mouse_position[1] + region->winrct.ymin);
|
2018-05-10 16:29:14 -03:00
|
|
|
|
|
|
|
immVertex2f(shdr_pos,
|
2020-03-06 16:56:42 +01:00
|
|
|
stroke->constrained_pos[0] + region->winrct.xmin,
|
|
|
|
stroke->constrained_pos[1] + region->winrct.ymin);
|
2015-02-02 11:29:01 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-05-10 16:29:14 -03:00
|
|
|
immVertex2f(shdr_pos,
|
2020-03-06 16:56:42 +01:00
|
|
|
stroke->last_mouse_position[0] + region->winrct.xmin,
|
|
|
|
stroke->last_mouse_position[1] + region->winrct.ymin);
|
2018-05-10 16:29:14 -03:00
|
|
|
|
Reworked version of dashed line shader.
Using geometry shader allows us to get rid of the 'line origin' extra
vertex attribute, which means dashed shader no longer requires fiddling
with those vertex attributes definition, and, most importantly, does not
require anymore special drawing code!
As you can see, this makes code much simpler, and much less verbose,
especially in complex cases.
In addition, changed how dashes are handled, to have two 'modes', a
simple one with single color (using default "color" uniform name), and a
more advanced one allowing more complex and multi-color patterns.
Note that since GLSL 1.2 does not support geometry shaders, a hack was
added for now (which gives solid lines, but at least does not make
Blender crash).
2017-05-01 16:21:53 +02:00
|
|
|
immVertex2f(shdr_pos, x, y);
|
2015-02-02 11:29:01 +01:00
|
|
|
}
|
2017-02-23 02:52:36 -03:00
|
|
|
|
|
|
|
immEnd();
|
|
|
|
|
2017-02-22 18:19:42 +01:00
|
|
|
immUnbindProgram();
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2018-06-27 19:07:23 -06:00
|
|
|
GPU_line_smooth(false);
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2017-10-17 13:43:10 +11:00
|
|
|
static bool paint_tool_require_location(Brush *brush, ePaintMode mode)
|
2014-07-05 05:26:32 +10:00
|
|
|
{
|
2014-06-27 13:56:57 +03:00
|
|
|
switch (mode) {
|
2018-11-14 11:20:08 +11:00
|
|
|
case PAINT_MODE_SCULPT:
|
2018-07-02 18:45:26 +02:00
|
|
|
if (ELEM(brush->sculpt_tool,
|
|
|
|
SCULPT_TOOL_GRAB,
|
2019-09-06 23:14:57 +02:00
|
|
|
SCULPT_TOOL_ELASTIC_DEFORM,
|
2019-09-09 17:44:08 +02:00
|
|
|
SCULPT_TOOL_POSE,
|
Sculpt: Boundary Brush
This brush includes a set of deformation modes designed to deform and
control the shape of the mesh boundaries, which are really hard to do
with regular sculpt brushes (and even in edit mode). This is useful
for creating cloth assets and hard surface base meshes.
The brush detects the mesh boundary closest to the active vertex and
propagates the deformation using the brush falloff into the mesh.
It includes bend, expand, inflate, grab and twist deform modes.
The main use cases of this brush are the Bend and Expand deformation
modes, which depend on a grid topology to create the best results.
In order to do further adjustments and tweaks to the result of these
deformation modes, the brush also includes the Inflate, Grab and
Twist deformation modes, which do not depend that much on the topology.
Grab and Inflate are the same operation that is implemented in the
Grab and Inflate tools, they are also available in the boundary brush
as producing deformations with regular brushes in these areas is very
hard to control.
Even if this brush can produce deformations in triangle meshes and
meshes with a non-regular quad grid, the more regular and clean the
topology is, the better. Most of the assets this brush is intended to
deform are always created from a cylindrical or plane quad grid, so it
should be fine. Also, its algorithms can be improved in future versions
to handle more corner cases and topology patterns.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8356
2020-08-10 17:57:01 +02:00
|
|
|
SCULPT_TOOL_BOUNDARY,
|
2018-07-02 18:45:26 +02:00
|
|
|
SCULPT_TOOL_ROTATE,
|
|
|
|
SCULPT_TOOL_SNAKE_HOOK,
|
|
|
|
SCULPT_TOOL_THUMB)) {
|
2014-06-27 13:56:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-19 00:00:21 +02:00
|
|
|
else if (SCULPT_is_cloth_deform_brush(brush)) {
|
2020-02-28 14:40:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-07-05 05:26:32 +10:00
|
|
|
else {
|
2014-06-27 13:56:57 +03:00
|
|
|
return true;
|
2014-07-05 05:26:32 +10:00
|
|
|
}
|
2014-06-27 13:56:57 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-06-27 13:56:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
2013-03-15 22:32:44 +00:00
|
|
|
|
2019-08-19 17:03:55 +02:00
|
|
|
static bool paint_stroke_use_scene_spacing(Brush *brush, ePaintMode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case PAINT_MODE_SCULPT:
|
|
|
|
return brush->flag & BRUSH_SCENE_SPACING;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-07 01:36:17 +02:00
|
|
|
static bool paint_tool_require_inbetween_mouse_events(Brush *brush, ePaintMode mode)
|
|
|
|
{
|
2020-09-29 23:21:50 +02:00
|
|
|
if (brush->flag & BRUSH_ANCHORED) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-07 01:36:17 +02:00
|
|
|
switch (mode) {
|
|
|
|
case PAINT_MODE_SCULPT:
|
2019-09-06 23:14:57 +02:00
|
|
|
if (ELEM(brush->sculpt_tool,
|
|
|
|
SCULPT_TOOL_GRAB,
|
|
|
|
SCULPT_TOOL_ROTATE,
|
|
|
|
SCULPT_TOOL_THUMB,
|
2019-10-03 01:15:06 +02:00
|
|
|
SCULPT_TOOL_SNAKE_HOOK,
|
2019-09-09 17:44:08 +02:00
|
|
|
SCULPT_TOOL_ELASTIC_DEFORM,
|
2020-02-28 14:40:40 +01:00
|
|
|
SCULPT_TOOL_CLOTH,
|
Sculpt: Boundary Brush
This brush includes a set of deformation modes designed to deform and
control the shape of the mesh boundaries, which are really hard to do
with regular sculpt brushes (and even in edit mode). This is useful
for creating cloth assets and hard surface base meshes.
The brush detects the mesh boundary closest to the active vertex and
propagates the deformation using the brush falloff into the mesh.
It includes bend, expand, inflate, grab and twist deform modes.
The main use cases of this brush are the Bend and Expand deformation
modes, which depend on a grid topology to create the best results.
In order to do further adjustments and tweaks to the result of these
deformation modes, the brush also includes the Inflate, Grab and
Twist deformation modes, which do not depend that much on the topology.
Grab and Inflate are the same operation that is implemented in the
Grab and Inflate tools, they are also available in the boundary brush
as producing deformations with regular brushes in these areas is very
hard to control.
Even if this brush can produce deformations in triangle meshes and
meshes with a non-regular quad grid, the more regular and clean the
topology is, the better. Most of the assets this brush is intended to
deform are always created from a cylindrical or plane quad grid, so it
should be fine. Also, its algorithms can be improved in future versions
to handle more corner cases and topology patterns.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8356
2020-08-10 17:57:01 +02:00
|
|
|
SCULPT_TOOL_BOUNDARY,
|
2019-09-09 17:44:08 +02:00
|
|
|
SCULPT_TOOL_POSE)) {
|
2019-08-07 01:36:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
/* Initialize the stroke cache variants from operator properties */
|
2018-07-02 18:16:37 +02:00
|
|
|
static bool paint_brush_update(bContext *C,
|
|
|
|
Brush *brush,
|
|
|
|
ePaintMode mode,
|
|
|
|
struct PaintStroke *stroke,
|
|
|
|
const float mouse_init[2],
|
|
|
|
float mouse[2],
|
|
|
|
float pressure,
|
|
|
|
float r_location[3],
|
|
|
|
bool *r_location_is_set)
|
2013-03-13 03:46:22 +00:00
|
|
|
{
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2014-07-21 12:02:05 +02:00
|
|
|
UnifiedPaintSettings *ups = stroke->ups;
|
|
|
|
bool location_sampled = false;
|
|
|
|
bool location_success = false;
|
2017-12-18 14:35:15 +11:00
|
|
|
/* Use to perform all operations except applying the stroke,
|
|
|
|
* needed for operations that require cursor motion (rake). */
|
|
|
|
bool is_dry_run = false;
|
2014-12-26 23:51:27 +01:00
|
|
|
bool do_random = false;
|
2015-09-10 03:32:17 +10:00
|
|
|
bool do_random_mask = false;
|
2018-07-02 18:16:37 +02:00
|
|
|
*r_location_is_set = false;
|
2013-03-13 03:46:22 +00:00
|
|
|
/* XXX: Use pressure value from first brush step for brushes which don't
|
|
|
|
* support strokes (grab, thumb). They depends on initial state and
|
|
|
|
* brush coord/pressure/etc.
|
|
|
|
* It's more an events design issue, which doesn't split coordinate/pressure/angle
|
|
|
|
* changing events. We should avoid this after events system re-design */
|
2014-04-15 13:11:48 +10:00
|
|
|
if (!stroke->brush_init) {
|
2013-03-13 03:46:22 +00:00
|
|
|
copy_v2_v2(stroke->initial_mouse, mouse);
|
2014-04-13 18:14:45 +03:00
|
|
|
copy_v2_v2(ups->last_rake, mouse);
|
2013-03-13 03:46:22 +00:00
|
|
|
copy_v2_v2(ups->tex_mouse, mouse);
|
2013-04-22 10:46:01 +00:00
|
|
|
copy_v2_v2(ups->mask_tex_mouse, mouse);
|
2014-04-13 18:14:45 +03:00
|
|
|
stroke->cached_size_pressure = pressure;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-10 20:28:53 +02:00
|
|
|
ups->do_linear_conversion = false;
|
|
|
|
ups->colorspace = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-13 19:03:14 +03:00
|
|
|
/* check here if color sampling the main brush should do color conversion. This is done here
|
|
|
|
* to avoid locking up to get the image buffer during sampling */
|
|
|
|
if (brush->mtex.tex && brush->mtex.tex->type == TEX_IMAGE && brush->mtex.tex->ima) {
|
|
|
|
ImBuf *tex_ibuf = BKE_image_pool_acquire_ibuf(
|
|
|
|
brush->mtex.tex->ima, &brush->mtex.tex->iuser, NULL);
|
|
|
|
if (tex_ibuf && tex_ibuf->rect_float == NULL) {
|
|
|
|
ups->do_linear_conversion = true;
|
|
|
|
ups->colorspace = tex_ibuf->rect_colorspace;
|
|
|
|
}
|
|
|
|
BKE_image_pool_release_ibuf(brush->mtex.tex->ima, tex_ibuf, NULL);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-13 18:14:45 +03:00
|
|
|
stroke->brush_init = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-13 18:14:45 +03:00
|
|
|
if (paint_supports_dynamic_size(brush, mode)) {
|
|
|
|
copy_v2_v2(ups->tex_mouse, mouse);
|
|
|
|
copy_v2_v2(ups->mask_tex_mouse, mouse);
|
|
|
|
stroke->cached_size_pressure = pressure;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
/* Truly temporary data that isn't stored in properties */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-09 22:36:33 +02:00
|
|
|
ups->stroke_active = true;
|
2014-04-13 18:14:45 +03:00
|
|
|
ups->size_pressure_value = stroke->cached_size_pressure;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
ups->pixel_radius = BKE_brush_size_get(scene, brush);
|
2019-12-01 20:29:11 +01:00
|
|
|
ups->initial_pixel_radius = BKE_brush_size_get(scene, brush);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-11-27 02:02:18 +01:00
|
|
|
if (BKE_brush_use_size_pressure(brush) && paint_supports_dynamic_size(brush, mode)) {
|
2014-04-13 18:14:45 +03:00
|
|
|
ups->pixel_radius *= stroke->cached_size_pressure;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-30 09:57:35 +00:00
|
|
|
if (paint_supports_dynamic_tex_coords(brush, mode)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-10 03:32:17 +10:00
|
|
|
if (ELEM(brush->mtex.brush_map_mode,
|
|
|
|
MTEX_MAP_MODE_VIEW,
|
|
|
|
MTEX_MAP_MODE_AREA,
|
|
|
|
MTEX_MAP_MODE_RANDOM)) {
|
2014-12-26 23:51:27 +01:00
|
|
|
do_random = true;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) {
|
2015-01-04 14:20:31 +11:00
|
|
|
BKE_brush_randomize_texture_coords(ups, false);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2013-04-22 10:46:01 +00:00
|
|
|
else {
|
2013-03-25 01:00:16 +00:00
|
|
|
copy_v2_v2(ups->tex_mouse, mouse);
|
2013-04-22 10:46:01 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/* take care of mask texture, if any */
|
|
|
|
if (brush->mask_mtex.tex) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-10 03:32:17 +10:00
|
|
|
if (ELEM(brush->mask_mtex.brush_map_mode,
|
|
|
|
MTEX_MAP_MODE_VIEW,
|
|
|
|
MTEX_MAP_MODE_AREA,
|
|
|
|
MTEX_MAP_MODE_RANDOM)) {
|
|
|
|
do_random_mask = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (brush->mask_mtex.brush_map_mode == MTEX_MAP_MODE_RANDOM) {
|
2015-01-04 14:20:31 +11:00
|
|
|
BKE_brush_randomize_texture_coords(ups, true);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
else {
|
|
|
|
copy_v2_v2(ups->mask_tex_mouse, mouse);
|
|
|
|
}
|
2013-04-22 10:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
if (brush->flag & BRUSH_ANCHORED) {
|
|
|
|
bool hit = false;
|
|
|
|
float halfway[2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
const float dx = mouse[0] - stroke->initial_mouse[0];
|
|
|
|
const float dy = mouse[1] - stroke->initial_mouse[1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-17 14:11:37 +10:00
|
|
|
ups->anchored_size = ups->pixel_radius = sqrtf(dx * dx + dy * dy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-31 17:23:30 +11:00
|
|
|
ups->brush_rotation = ups->brush_rotation_sec = atan2f(dx, dy) + (float)M_PI;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
if (brush->flag & BRUSH_EDGE_TO_EDGE) {
|
|
|
|
halfway[0] = dx * 0.5f + stroke->initial_mouse[0];
|
|
|
|
halfway[1] = dy * 0.5f + stroke->initial_mouse[1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
if (stroke->get_location) {
|
2018-07-02 18:16:37 +02:00
|
|
|
if (stroke->get_location(C, r_location, halfway)) {
|
2013-03-13 03:46:22 +00:00
|
|
|
hit = true;
|
2014-07-21 12:02:05 +02:00
|
|
|
location_sampled = true;
|
|
|
|
location_success = true;
|
2018-07-02 18:16:37 +02:00
|
|
|
*r_location_is_set = true;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2014-06-27 13:56:57 +03:00
|
|
|
else if (!paint_tool_require_location(brush, mode)) {
|
|
|
|
hit = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-06-27 13:56:57 +03:00
|
|
|
}
|
2013-03-13 05:23:53 +00:00
|
|
|
else {
|
2013-03-13 03:46:22 +00:00
|
|
|
hit = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2013-03-13 05:23:53 +00:00
|
|
|
if (hit) {
|
2013-03-13 03:46:22 +00:00
|
|
|
copy_v2_v2(ups->anchored_initial_mouse, halfway);
|
|
|
|
copy_v2_v2(ups->tex_mouse, halfway);
|
2014-07-21 12:02:05 +02:00
|
|
|
copy_v2_v2(ups->mask_tex_mouse, halfway);
|
|
|
|
copy_v2_v2(mouse, halfway);
|
2013-03-13 03:46:22 +00:00
|
|
|
ups->anchored_size /= 2.0f;
|
|
|
|
ups->pixel_radius /= 2.0f;
|
2014-07-21 12:02:05 +02:00
|
|
|
stroke->stroke_distance = ups->pixel_radius;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
else {
|
2013-03-13 03:46:22 +00:00
|
|
|
copy_v2_v2(ups->anchored_initial_mouse, stroke->initial_mouse);
|
2015-09-17 02:08:22 +10:00
|
|
|
copy_v2_v2(mouse, stroke->initial_mouse);
|
2014-07-21 12:02:05 +02:00
|
|
|
stroke->stroke_distance = ups->pixel_radius;
|
|
|
|
}
|
|
|
|
ups->pixel_radius /= stroke->zoom_2d;
|
2013-12-09 22:36:33 +02:00
|
|
|
ups->draw_anchored = true;
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2014-12-26 23:51:27 +01:00
|
|
|
else {
|
2014-07-21 12:02:05 +02:00
|
|
|
/* here we are using the initial mouse coordinate because we do not want the rake
|
|
|
|
* result to depend on jittering */
|
2014-12-26 23:51:27 +01:00
|
|
|
if (!stroke->brush_init) {
|
2014-07-21 12:02:05 +02:00
|
|
|
copy_v2_v2(ups->last_rake, mouse_init);
|
2014-12-26 23:51:27 +01:00
|
|
|
}
|
2015-05-07 18:10:34 +02:00
|
|
|
/* curve strokes do their own rake calculation */
|
|
|
|
else if (!(brush->flag & BRUSH_CURVE)) {
|
2017-12-18 14:35:15 +11:00
|
|
|
if (!paint_calculate_rake_rotation(ups, brush, mouse_init)) {
|
|
|
|
/* Not enough motion to define an angle. */
|
2018-01-28 17:00:39 +11:00
|
|
|
if (!stroke->rake_started) {
|
2018-01-24 14:25:59 +01:00
|
|
|
is_dry_run = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stroke->rake_started = true;
|
2017-12-18 14:35:15 +11:00
|
|
|
}
|
2014-12-26 23:51:27 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-12 17:13:23 +02:00
|
|
|
if ((do_random || do_random_mask) && stroke->rng == NULL) {
|
|
|
|
/* Lazy initialization. */
|
|
|
|
uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
|
2018-09-19 12:14:36 +10:00
|
|
|
rng_seed ^= (uint)POINTER_AS_INT(brush);
|
2018-06-12 17:13:23 +02:00
|
|
|
stroke->rng = BLI_rng_new(rng_seed);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-12-26 23:51:27 +01:00
|
|
|
if (do_random) {
|
|
|
|
if (brush->mtex.brush_angle_mode & MTEX_ANGLE_RANDOM) {
|
|
|
|
ups->brush_rotation += -brush->mtex.random_angle / 2.0f +
|
2018-06-12 17:13:23 +02:00
|
|
|
brush->mtex.random_angle * BLI_rng_get_float(stroke->rng);
|
2014-12-26 23:51:27 +01:00
|
|
|
}
|
2015-09-10 03:32:17 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-10 03:32:17 +10:00
|
|
|
if (do_random_mask) {
|
2014-12-26 23:51:27 +01:00
|
|
|
if (brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RANDOM) {
|
|
|
|
ups->brush_rotation_sec += -brush->mask_mtex.random_angle / 2.0f +
|
2018-06-12 17:13:23 +02:00
|
|
|
brush->mask_mtex.random_angle * BLI_rng_get_float(stroke->rng);
|
2014-12-26 23:51:27 +01:00
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (!location_sampled) {
|
|
|
|
if (stroke->get_location) {
|
2018-07-02 18:16:37 +02:00
|
|
|
if (stroke->get_location(C, r_location, mouse)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
location_success = true;
|
2018-07-02 18:16:37 +02:00
|
|
|
*r_location_is_set = true;
|
|
|
|
}
|
2019-04-22 09:19:45 +10:00
|
|
|
else if (!paint_tool_require_location(brush, mode)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
location_success = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-07-02 18:16:37 +02:00
|
|
|
zero_v3(r_location);
|
2014-07-21 12:02:05 +02:00
|
|
|
location_success = true;
|
2018-07-02 18:16:37 +02:00
|
|
|
/* don't set 'r_location_is_set', since we don't want to use the value. */
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-12-18 14:35:15 +11:00
|
|
|
return location_success && (is_dry_run == false);
|
2013-03-13 03:46:22 +00:00
|
|
|
}
|
2013-03-15 22:32:44 +00:00
|
|
|
|
2019-11-18 22:47:23 +01:00
|
|
|
static bool paint_stroke_use_dash(Brush *brush)
|
|
|
|
{
|
|
|
|
/* Only these stroke modes support dash lines */
|
|
|
|
return brush->flag & BRUSH_SPACE || brush->flag & BRUSH_LINE || brush->flag & BRUSH_CURVE;
|
|
|
|
}
|
|
|
|
|
2017-10-17 13:43:10 +11:00
|
|
|
static bool paint_stroke_use_jitter(ePaintMode mode, Brush *brush, bool invert)
|
2014-09-01 21:10:17 +02:00
|
|
|
{
|
|
|
|
bool use_jitter = (brush->flag & BRUSH_ABSOLUTE_JITTER) ? (brush->jitter_absolute != 0) :
|
|
|
|
(brush->jitter != 0);
|
|
|
|
|
|
|
|
/* jitter-ed brush gives weird and unpredictable result for this
|
|
|
|
* kinds of stroke, so manually disable jitter usage (sergey) */
|
|
|
|
use_jitter &= (brush->flag & (BRUSH_DRAG_DOT | BRUSH_ANCHORED)) == 0;
|
2018-11-14 11:20:08 +11:00
|
|
|
use_jitter &= (!ELEM(mode, PAINT_MODE_TEXTURE_2D, PAINT_MODE_TEXTURE_3D) ||
|
2014-09-01 21:10:17 +02:00
|
|
|
!(invert && brush->imagepaint_tool == PAINT_TOOL_CLONE));
|
|
|
|
|
|
|
|
return use_jitter;
|
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
|
2013-05-18 09:44:30 +00:00
|
|
|
static void paint_brush_stroke_add_step(bContext *C,
|
|
|
|
wmOperator *op,
|
|
|
|
const float mouse_in[2],
|
|
|
|
float pressure)
|
2011-01-08 01:45:02 +00:00
|
|
|
{
|
2012-01-14 23:54:51 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
Paint refactoring commit, non-disruptive (in theory :p)
* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:
Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:
These attributes/aspects are:
Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)
Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.
Properties that affect this are:
Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.
These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.
2013-04-12 17:21:31 +00:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
2017-10-17 13:43:10 +11:00
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
Paint refactoring commit, non-disruptive (in theory :p)
* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:
Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:
These attributes/aspects are:
Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)
Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.
Properties that affect this are:
Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.
These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.
2013-04-12 17:21:31 +00:00
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
2009-08-19 21:24:52 +00:00
|
|
|
PaintStroke *stroke = op->customdata;
|
2014-07-21 12:02:05 +02:00
|
|
|
UnifiedPaintSettings *ups = stroke->ups;
|
2012-10-08 07:08:29 +00:00
|
|
|
float mouse_out[2];
|
2011-01-08 01:45:02 +00:00
|
|
|
PointerRNA itemptr;
|
|
|
|
float location[3];
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
/* the following code is adapted from texture paint. It may not be needed but leaving here
|
|
|
|
* just in case for reference (code in texpaint removed as part of refactoring).
|
|
|
|
* It's strange that only texpaint had these guards. */
|
|
|
|
#if 0
|
|
|
|
/* special exception here for too high pressure values on first touch in
|
|
|
|
* windows for some tablets, then we just skip first touch .. */
|
2018-07-02 18:45:26 +02:00
|
|
|
if (tablet && (pressure >= 0.99f) &&
|
|
|
|
((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) ||
|
2019-11-27 02:02:18 +01:00
|
|
|
BKE_brush_use_alpha_pressure(pop->s.brush) ||
|
|
|
|
BKE_brush_use_size_pressure(pop->s.brush))) {
|
2013-03-10 17:40:55 +00:00
|
|
|
return;
|
2018-07-02 18:45:26 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-10 17:40:55 +00:00
|
|
|
/* This can be removed once fixed properly in
|
2019-01-15 23:24:20 +11:00
|
|
|
* BKE_brush_painter_paint(
|
|
|
|
* BrushPainter *painter, BrushFunc func,
|
|
|
|
* float *pos, double time, float pressure, void *user);
|
|
|
|
* at zero pressure we should do nothing 1/2^12 is 0.0002
|
|
|
|
* which is the sensitivity of the most sensitive pen tablet available */
|
2018-07-02 18:45:26 +02:00
|
|
|
if (tablet && (pressure < 0.0002f) &&
|
|
|
|
((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) ||
|
2019-11-27 02:02:18 +01:00
|
|
|
BKE_brush_use_alpha_pressure(pop->s.brush) ||
|
|
|
|
BKE_brush_use_size_pressure(pop->s.brush))) {
|
2013-03-10 17:40:55 +00:00
|
|
|
return;
|
2018-07-02 18:45:26 +02:00
|
|
|
}
|
2013-03-10 17:40:55 +00:00
|
|
|
#endif
|
|
|
|
|
2013-03-10 20:05:18 +00:00
|
|
|
/* copy last position -before- jittering, or space fill code
|
|
|
|
* will create too many dabs */
|
|
|
|
copy_v2_v2(stroke->last_mouse_position, mouse_in);
|
2013-05-18 11:25:24 +00:00
|
|
|
stroke->last_pressure = pressure;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-19 17:03:55 +02:00
|
|
|
if (paint_stroke_use_scene_spacing(brush, mode)) {
|
2020-03-06 15:24:15 +01:00
|
|
|
SCULPT_stroke_get_location(C, stroke->last_world_space_position, stroke->last_mouse_position);
|
2019-09-06 17:16:59 +02:00
|
|
|
mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position);
|
2019-08-19 17:03:55 +02:00
|
|
|
}
|
|
|
|
|
2014-09-05 10:16:11 +10:00
|
|
|
if (paint_stroke_use_jitter(mode, brush, stroke->stroke_mode == BRUSH_STROKE_INVERT)) {
|
2011-09-16 06:47:01 +00:00
|
|
|
float delta[2];
|
2013-03-15 09:19:41 +00:00
|
|
|
float factor = stroke->zoom_2d;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (brush->flag & BRUSH_JITTER_PRESSURE) {
|
2013-03-15 09:19:41 +00:00
|
|
|
factor *= pressure;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-08 07:08:29 +00:00
|
|
|
BKE_brush_jitter_pos(scene, brush, mouse_in, mouse_out);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* XXX: meh, this is round about because
|
2012-05-05 00:58:22 +00:00
|
|
|
* BKE_brush_jitter_pos isn't written in the best way to
|
2012-03-03 16:31:46 +00:00
|
|
|
* be reused here */
|
2013-03-16 14:42:05 +00:00
|
|
|
if (factor != 1.0f) {
|
2012-10-08 07:08:29 +00:00
|
|
|
sub_v2_v2v2(delta, mouse_out, mouse_in);
|
2013-03-15 09:19:41 +00:00
|
|
|
mul_v2_fl(delta, factor);
|
2012-10-08 07:08:29 +00:00
|
|
|
add_v2_v2v2(mouse_out, mouse_in, delta);
|
2010-07-14 14:11:03 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-09-01 21:10:17 +02:00
|
|
|
else {
|
|
|
|
copy_v2_v2(mouse_out, mouse_in);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-02 18:16:37 +02:00
|
|
|
bool is_location_is_set;
|
|
|
|
ups->last_hit = paint_brush_update(
|
|
|
|
C, brush, mode, stroke, mouse_in, mouse_out, pressure, location, &is_location_is_set);
|
|
|
|
if (is_location_is_set) {
|
|
|
|
copy_v3_v3(ups->last_location, location);
|
|
|
|
}
|
2015-11-24 21:40:18 +01:00
|
|
|
if (!ups->last_hit) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return;
|
2014-06-18 21:40:58 +03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-11-18 22:47:23 +01:00
|
|
|
/* Dash */
|
|
|
|
bool add_step = true;
|
|
|
|
if (paint_stroke_use_dash(brush)) {
|
|
|
|
int dash_samples = stroke->tot_samples % brush->dash_samples;
|
|
|
|
float dash = (float)dash_samples / (float)brush->dash_samples;
|
|
|
|
if (dash > brush->dash_ratio) {
|
|
|
|
add_step = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
/* Add to stroke */
|
2019-11-18 22:47:23 +01:00
|
|
|
if (add_step) {
|
|
|
|
RNA_collection_add(op->ptr, "stroke", &itemptr);
|
|
|
|
RNA_float_set(&itemptr, "size", ups->pixel_radius);
|
|
|
|
RNA_float_set_array(&itemptr, "location", location);
|
2020-10-12 20:32:26 +02:00
|
|
|
/* Mouse coordinates modified by the stroke type options. */
|
2019-11-18 22:47:23 +01:00
|
|
|
RNA_float_set_array(&itemptr, "mouse", mouse_out);
|
2020-10-12 20:32:26 +02:00
|
|
|
/* Original mouse coordinates. */
|
|
|
|
RNA_float_set_array(&itemptr, "mouse_event", mouse_in);
|
2019-11-18 22:47:23 +01:00
|
|
|
RNA_boolean_set(&itemptr, "pen_flip", stroke->pen_flip);
|
|
|
|
RNA_float_set(&itemptr, "pressure", pressure);
|
Sculpt: Experimental Pen Tilt Support
This adds support for pen tilt in sculpt mode. For now, pen tilt is used
by tweaking the tilt strength property, which controls how much the pen
angle affects the sculpt normal. This is available in Draw, Draw Sharp,
Flatten, Fill, Scrape and Clay Strips brushes, but it can be enabled in
more tools later.
The purpose of this patch is to have a usable implementation of pen tilt
in a painting mode, so users can test and see in which hardware and
platforms this feature is supported and how well it works. If it works
ok, more tools and features that rely on pen tilt can be implemented,
like brushes that blend between two deformations depending on the angle.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8893
2020-10-08 00:00:36 +02:00
|
|
|
RNA_float_set(&itemptr, "x_tilt", stroke->x_tilt);
|
|
|
|
RNA_float_set(&itemptr, "y_tilt", stroke->y_tilt);
|
2019-11-18 22:47:23 +01:00
|
|
|
|
|
|
|
stroke->update_step(C, stroke, &itemptr);
|
|
|
|
|
|
|
|
/* don't record this for now, it takes up a lot of memory when doing long
|
|
|
|
* strokes with small brush size, and operators have register disabled */
|
|
|
|
RNA_collection_clear(op->ptr, "stroke");
|
|
|
|
}
|
|
|
|
|
|
|
|
stroke->tot_samples++;
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns zero if no sculpt changes should be made, non-zero otherwise */
|
2016-07-15 17:17:42 +10:00
|
|
|
static bool paint_smooth_stroke(PaintStroke *stroke,
|
2017-10-17 13:43:10 +11:00
|
|
|
const PaintSample *sample,
|
|
|
|
ePaintMode mode,
|
2016-07-15 17:17:42 +10:00
|
|
|
float r_mouse[2],
|
|
|
|
float *r_pressure)
|
2009-08-19 21:24:52 +00:00
|
|
|
{
|
2013-03-14 05:52:30 +00:00
|
|
|
if (paint_supports_smooth_stroke(stroke->brush, mode)) {
|
2013-03-16 14:42:05 +00:00
|
|
|
float radius = stroke->brush->smooth_stroke_radius * stroke->zoom_2d;
|
2016-07-15 17:17:42 +10:00
|
|
|
float u = stroke->brush->smooth_stroke_factor;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
/* If the mouse is moving within the radius of the last move,
|
2012-03-03 16:31:46 +00:00
|
|
|
* don't update the mouse position. This allows sharp turns. */
|
2020-03-06 17:18:10 +01:00
|
|
|
if (len_squared_v2v2(stroke->last_mouse_position, sample->mouse) < square_f(radius)) {
|
2016-07-15 17:17:42 +10:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-15 17:17:42 +10:00
|
|
|
interp_v2_v2v2(r_mouse, sample->mouse, stroke->last_mouse_position, u);
|
|
|
|
*r_pressure = interpf(sample->pressure, stroke->last_pressure, u);
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
else {
|
2016-07-15 17:17:42 +10:00
|
|
|
r_mouse[0] = sample->mouse[0];
|
|
|
|
r_mouse[1] = sample->mouse[1];
|
|
|
|
*r_pressure = sample->pressure;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-15 17:17:42 +10:00
|
|
|
return true;
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 17:03:55 +02:00
|
|
|
static float paint_space_stroke_spacing(bContext *C,
|
|
|
|
const Scene *scene,
|
2018-07-02 18:45:26 +02:00
|
|
|
PaintStroke *stroke,
|
|
|
|
float size_pressure,
|
|
|
|
float spacing_pressure)
|
2009-08-19 21:24:52 +00:00
|
|
|
{
|
2019-08-19 17:03:55 +02:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
|
|
|
float size_clamp = 0.0f;
|
|
|
|
float size = BKE_brush_size_get(scene, stroke->brush) * size_pressure;
|
|
|
|
if (paint_stroke_use_scene_spacing(brush, mode)) {
|
|
|
|
if (!BKE_brush_use_locked_size(scene, brush)) {
|
2019-09-06 17:16:59 +02:00
|
|
|
float last_object_space_position[3];
|
|
|
|
mul_v3_m4v3(
|
|
|
|
last_object_space_position, stroke->vc.obact->imat, stroke->last_world_space_position);
|
|
|
|
size_clamp = paint_calc_object_space_radius(&stroke->vc, last_object_space_position, size);
|
2019-08-19 17:03:55 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
size_clamp = BKE_brush_unprojected_radius_get(scene, brush) * size_pressure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* brushes can have a minimum size of 1.0 but with pressure it can be smaller than a pixel
|
2020-09-30 20:09:02 +10:00
|
|
|
* causing very high step sizes, hanging blender T32381. */
|
2019-08-19 17:03:55 +02:00
|
|
|
size_clamp = max_ff(1.0f, size);
|
|
|
|
}
|
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
float spacing = stroke->brush->spacing;
|
2013-03-13 03:46:22 +00:00
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
/* apply spacing pressure */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (stroke->brush->flag & BRUSH_SPACING_PRESSURE) {
|
2013-08-01 17:14:20 +00:00
|
|
|
spacing = spacing * (1.5f - spacing_pressure);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2009-08-19 21:24:52 +00:00
|
|
|
|
2020-08-18 21:37:39 +02:00
|
|
|
if (SCULPT_is_cloth_deform_brush(brush)) {
|
|
|
|
/* The spacing in tools that use the cloth solver should not be affected by the brush radius to
|
|
|
|
* avoid affecting the simulation update rate when changing the radius of the brush.
|
2020-10-14 15:24:42 +11:00
|
|
|
* With a value of 100 and the brush default of 10 for spacing, a simulation step runs every 2
|
|
|
|
* pixels movement of the cursor. */
|
2020-08-18 21:37:39 +02:00
|
|
|
size_clamp = 100.0f;
|
|
|
|
}
|
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
/* stroke system is used for 2d paint too, so we need to account for
|
|
|
|
* the fact that brush can be scaled there. */
|
|
|
|
spacing *= stroke->zoom_2d;
|
2013-05-18 09:44:30 +00:00
|
|
|
|
2019-08-19 17:03:55 +02:00
|
|
|
if (paint_stroke_use_scene_spacing(brush, mode)) {
|
2020-11-06 11:25:27 +11:00
|
|
|
return max_ff(0.001f, size_clamp * spacing / 50.0f);
|
2019-08-19 17:03:55 +02:00
|
|
|
}
|
2020-07-03 16:09:51 +02:00
|
|
|
return max_ff(stroke->zoom_2d, size_clamp * spacing / 50.0f);
|
2013-05-18 11:25:24 +00:00
|
|
|
}
|
2013-05-18 09:44:30 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing)
|
|
|
|
{
|
|
|
|
const int n = 100 / spacing;
|
|
|
|
const float h = spacing / 50.0f;
|
|
|
|
const float x0 = x - 1;
|
|
|
|
|
2020-09-09 18:41:07 +02:00
|
|
|
float sum = 0;
|
|
|
|
for (int i = 0; i < n; i++) {
|
2014-07-21 12:02:05 +02:00
|
|
|
float xx;
|
|
|
|
|
2014-09-17 14:11:37 +10:00
|
|
|
xx = fabsf(x0 + i * h);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (xx < 1.0f) {
|
2014-07-21 12:02:05 +02:00
|
|
|
sum += BKE_brush_curve_strength(br, xx, 1);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float paint_stroke_integrate_overlap(Brush *br, float factor)
|
|
|
|
{
|
|
|
|
float spacing = br->spacing * factor;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return 1.0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-09 18:41:07 +02:00
|
|
|
int m = 10;
|
|
|
|
float g = 1.0f / m;
|
|
|
|
float max = 0;
|
|
|
|
for (int i = 0; i < m; i++) {
|
2015-06-10 13:32:11 +02:00
|
|
|
float overlap = fabs(paint_stroke_overlapped_curve(br, i * g, spacing));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (overlap > max) {
|
2014-07-21 12:02:05 +02:00
|
|
|
max = overlap;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (max == 0.0f) {
|
2017-09-11 18:24:39 +12:00
|
|
|
return 1.0f;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2020-07-03 16:09:51 +02:00
|
|
|
return 1.0f / max;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 17:03:55 +02:00
|
|
|
static float paint_space_stroke_spacing_variable(bContext *C,
|
|
|
|
const Scene *scene,
|
|
|
|
PaintStroke *stroke,
|
|
|
|
float pressure,
|
|
|
|
float dpressure,
|
|
|
|
float length)
|
2013-05-18 11:25:24 +00:00
|
|
|
{
|
2019-11-27 02:02:18 +01:00
|
|
|
if (BKE_brush_use_size_pressure(stroke->brush)) {
|
2013-05-18 11:25:24 +00:00
|
|
|
/* use pressure to modify size. set spacing so that at 100%, the circles
|
|
|
|
* are aligned nicely with no overlap. for this the spacing needs to be
|
|
|
|
* the average of the previous and next size. */
|
2019-08-19 17:03:55 +02:00
|
|
|
float s = paint_space_stroke_spacing(C, scene, stroke, 1.0f, pressure);
|
2013-05-18 11:37:49 +00:00
|
|
|
float q = s * dpressure / (2.0f * length);
|
|
|
|
float pressure_fac = (1.0f + q) / (1.0f - q);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
float last_size_pressure = stroke->last_pressure;
|
2013-05-18 11:37:49 +00:00
|
|
|
float new_size_pressure = stroke->last_pressure * pressure_fac;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
/* average spacing */
|
2019-08-19 17:03:55 +02:00
|
|
|
float last_spacing = paint_space_stroke_spacing(
|
|
|
|
C, scene, stroke, last_size_pressure, pressure);
|
|
|
|
float new_spacing = paint_space_stroke_spacing(C, scene, stroke, new_size_pressure, pressure);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-18 11:37:49 +00:00
|
|
|
return 0.5f * (last_spacing + new_spacing);
|
2013-05-18 11:25:24 +00:00
|
|
|
}
|
2020-07-03 16:09:51 +02:00
|
|
|
|
|
|
|
/* no size pressure */
|
|
|
|
return paint_space_stroke_spacing(C, scene, stroke, 1.0f, pressure);
|
2013-05-18 11:25:24 +00:00
|
|
|
}
|
2013-05-18 09:44:30 +00:00
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
/* For brushes with stroke spacing enabled, moves mouse in steps
|
|
|
|
* towards the final mouse location. */
|
|
|
|
static int paint_space_stroke(bContext *C,
|
|
|
|
wmOperator *op,
|
|
|
|
const float final_mouse[2],
|
|
|
|
float final_pressure)
|
|
|
|
{
|
|
|
|
const Scene *scene = CTX_data_scene(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2013-05-18 11:25:24 +00:00
|
|
|
PaintStroke *stroke = op->customdata;
|
2014-07-21 12:02:05 +02:00
|
|
|
UnifiedPaintSettings *ups = stroke->ups;
|
2019-08-19 17:03:55 +02:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
2013-05-18 11:25:24 +00:00
|
|
|
int cnt = 0;
|
2013-05-18 09:44:30 +00:00
|
|
|
|
2019-09-13 16:18:18 +02:00
|
|
|
const bool use_scene_spacing = paint_stroke_use_scene_spacing(brush, mode);
|
|
|
|
float d_world_space_position[3] = {0.0f};
|
|
|
|
|
2019-08-19 17:03:55 +02:00
|
|
|
float no_pressure_spacing = paint_space_stroke_spacing(C, scene, stroke, 1.0f, 1.0f);
|
2019-09-13 16:18:18 +02:00
|
|
|
float pressure = stroke->last_pressure;
|
|
|
|
float dpressure = final_pressure - stroke->last_pressure;
|
|
|
|
|
|
|
|
float dmouse[2];
|
2019-08-19 17:03:55 +02:00
|
|
|
sub_v2_v2v2(dmouse, final_mouse, stroke->last_mouse_position);
|
2019-09-13 16:18:18 +02:00
|
|
|
float length = normalize_v2(dmouse);
|
2013-03-10 00:58:09 +00:00
|
|
|
|
2019-09-13 16:18:18 +02:00
|
|
|
if (use_scene_spacing) {
|
|
|
|
float world_space_position[3];
|
2020-03-06 15:24:15 +01:00
|
|
|
bool hit = SCULPT_stroke_get_location(C, world_space_position, final_mouse);
|
2019-09-06 17:16:59 +02:00
|
|
|
mul_m4_v3(stroke->vc.obact->obmat, world_space_position);
|
2019-08-19 17:03:55 +02:00
|
|
|
if (hit && stroke->stroke_over_mesh) {
|
2019-09-06 17:16:59 +02:00
|
|
|
sub_v3_v3v3(d_world_space_position, world_space_position, stroke->last_world_space_position);
|
|
|
|
length = len_v3(d_world_space_position);
|
2019-08-19 17:03:55 +02:00
|
|
|
stroke->stroke_over_mesh = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
length = 0.0f;
|
2019-09-13 16:18:18 +02:00
|
|
|
zero_v3(d_world_space_position);
|
2019-08-19 17:03:55 +02:00
|
|
|
stroke->stroke_over_mesh = hit;
|
|
|
|
if (stroke->stroke_over_mesh) {
|
2019-09-06 17:16:59 +02:00
|
|
|
copy_v3_v3(stroke->last_world_space_position, world_space_position);
|
2019-08-19 17:03:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
while (length > 0.0f) {
|
|
|
|
float spacing = paint_space_stroke_spacing_variable(
|
2019-08-19 17:03:55 +02:00
|
|
|
C, scene, stroke, pressure, dpressure, length);
|
2019-09-18 20:05:22 +02:00
|
|
|
float mouse[3];
|
2013-03-10 18:46:31 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (length >= spacing) {
|
2019-09-13 16:18:18 +02:00
|
|
|
if (use_scene_spacing) {
|
|
|
|
float final_world_space_position[3];
|
2019-09-06 17:16:59 +02:00
|
|
|
normalize_v3(d_world_space_position);
|
|
|
|
mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing);
|
|
|
|
add_v3_v3v3(final_world_space_position,
|
|
|
|
stroke->last_world_space_position,
|
|
|
|
final_world_space_position);
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_view3d_project(region, final_world_space_position, mouse);
|
2019-08-19 17:03:55 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * spacing;
|
|
|
|
mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * spacing;
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
pressure = stroke->last_pressure + (spacing / length) * dpressure;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
ups->overlap_factor = paint_stroke_integrate_overlap(stroke->brush,
|
|
|
|
spacing / no_pressure_spacing);
|
2009-08-19 21:24:52 +00:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
stroke->stroke_distance += spacing / stroke->zoom_2d;
|
|
|
|
paint_brush_stroke_add_step(C, op, mouse, pressure);
|
|
|
|
|
|
|
|
length -= spacing;
|
|
|
|
pressure = stroke->last_pressure;
|
|
|
|
dpressure = final_pressure - stroke->last_pressure;
|
|
|
|
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** Public API ****/
|
|
|
|
|
2018-07-02 18:45:26 +02:00
|
|
|
PaintStroke *paint_stroke_new(bContext *C,
|
|
|
|
wmOperator *op,
|
|
|
|
StrokeGetLocation get_location,
|
|
|
|
StrokeTestStart test_start,
|
|
|
|
StrokeUpdateStep update_step,
|
|
|
|
StrokeRedraw redraw,
|
|
|
|
StrokeDone done,
|
|
|
|
int event_type)
|
2009-08-19 21:24:52 +00:00
|
|
|
{
|
2019-09-18 17:19:07 +02:00
|
|
|
struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
2009-08-19 21:24:52 +00:00
|
|
|
PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
|
2013-12-09 22:36:33 +02:00
|
|
|
ToolSettings *toolsettings = CTX_data_tool_settings(C);
|
|
|
|
UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
|
2015-02-11 15:07:04 +01:00
|
|
|
Paint *p = BKE_paint_get_active_from_context(C);
|
|
|
|
Brush *br = stroke->brush = BKE_paint_brush(p);
|
2019-09-28 23:37:16 +02:00
|
|
|
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
2014-07-21 12:02:05 +02:00
|
|
|
float zoomx, zoomy;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-18 17:19:07 +02:00
|
|
|
ED_view3d_viewcontext_init(C, &stroke->vc, depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-10-27 19:53:34 +00:00
|
|
|
stroke->get_location = get_location;
|
2009-08-19 21:24:52 +00:00
|
|
|
stroke->test_start = test_start;
|
|
|
|
stroke->update_step = update_step;
|
2013-05-15 14:37:05 +00:00
|
|
|
stroke->redraw = redraw;
|
2009-08-19 21:24:52 +00:00
|
|
|
stroke->done = done;
|
2012-03-28 03:47:33 +00:00
|
|
|
stroke->event_type = event_type; /* for modal, return event */
|
2013-12-09 22:36:33 +02:00
|
|
|
stroke->ups = ups;
|
2014-09-01 21:10:17 +02:00
|
|
|
stroke->stroke_mode = RNA_enum_get(op->ptr, "mode");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
get_imapaint_zoom(C, &zoomx, &zoomy);
|
|
|
|
stroke->zoom_2d = max_ff(zoomx, zoomy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-05 05:17:25 +10:00
|
|
|
if (stroke->stroke_mode == BRUSH_STROKE_INVERT) {
|
2020-06-18 12:21:38 +10:00
|
|
|
if (br->flag & BRUSH_CURVE) {
|
2015-01-30 19:47:58 +01:00
|
|
|
RNA_enum_set(op->ptr, "mode", BRUSH_STROKE_NORMAL);
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
/* initialize here */
|
|
|
|
ups->overlap_factor = 1.0;
|
|
|
|
ups->stroke_active = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-09-28 23:37:16 +02:00
|
|
|
if (rv3d) {
|
|
|
|
rv3d->rflag |= RV3D_PAINTING;
|
|
|
|
}
|
|
|
|
|
2014-12-29 12:34:46 +01:00
|
|
|
zero_v3(ups->average_stroke_accum);
|
|
|
|
ups->average_stroke_counter = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 19:04:39 +00:00
|
|
|
/* initialize here to avoid initialization conflict with threaded strokes */
|
2020-08-01 13:02:21 +10:00
|
|
|
BKE_curvemapping_init(br->curve);
|
2019-04-22 09:19:45 +10:00
|
|
|
if (p->flags & PAINT_USE_CAVITY_MASK) {
|
2020-08-01 13:02:21 +10:00
|
|
|
BKE_curvemapping_init(p->cavity_curve);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-23 00:32:51 +00:00
|
|
|
BKE_paint_set_overlay_override(br->overlay_flags);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
return stroke;
|
|
|
|
}
|
|
|
|
|
2019-09-28 23:32:51 +02:00
|
|
|
void paint_stroke_free(bContext *C, wmOperator *op)
|
2010-01-09 17:15:02 +00:00
|
|
|
{
|
2019-09-28 23:37:16 +02:00
|
|
|
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
2019-10-02 14:40:58 +02:00
|
|
|
if (rv3d) {
|
|
|
|
rv3d->rflag &= ~RV3D_PAINTING;
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_paint_set_overlay_override(0);
|
|
|
|
|
2019-09-28 23:32:51 +02:00
|
|
|
PaintStroke *stroke = op->customdata;
|
2019-10-02 14:40:58 +02:00
|
|
|
if (stroke == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-28 23:32:51 +02:00
|
|
|
|
2019-10-02 14:40:58 +02:00
|
|
|
UnifiedPaintSettings *ups = stroke->ups;
|
2019-09-28 23:32:51 +02:00
|
|
|
ups->draw_anchored = false;
|
|
|
|
ups->stroke_active = false;
|
|
|
|
|
|
|
|
if (stroke->timer) {
|
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), stroke->timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stroke->rng) {
|
|
|
|
BLI_rng_free(stroke->rng);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stroke->stroke_cursor) {
|
2020-06-04 18:35:43 +10:00
|
|
|
WM_paint_cursor_end(stroke->stroke_cursor);
|
2019-09-28 23:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_freelistN(&stroke->line);
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
MEM_SAFE_FREE(op->customdata);
|
2012-05-03 04:11:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 23:32:51 +02:00
|
|
|
static void stroke_done(bContext *C, wmOperator *op)
|
2012-05-03 04:11:53 +00:00
|
|
|
{
|
2019-09-28 23:32:51 +02:00
|
|
|
PaintStroke *stroke = op->customdata;
|
2013-12-09 22:36:33 +02:00
|
|
|
UnifiedPaintSettings *ups = stroke->ups;
|
|
|
|
|
|
|
|
/* reset rotation here to avoid doing so in cursor display */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!(stroke->brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
|
2013-12-09 22:36:33 +02:00
|
|
|
ups->brush_rotation = 0.0f;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2012-05-03 04:11:53 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!(stroke->brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
|
2014-12-26 23:51:27 +01:00
|
|
|
ups->brush_rotation_sec = 0.0f;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-12-26 23:51:27 +01:00
|
|
|
|
2013-05-15 14:37:05 +00:00
|
|
|
if (stroke->stroke_started) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (stroke->redraw) {
|
2013-05-15 14:37:05 +00:00
|
|
|
stroke->redraw(C, stroke, true);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2013-05-15 14:37:05 +00:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (stroke->done) {
|
2013-05-15 14:37:05 +00:00
|
|
|
stroke->done(C, stroke);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2013-05-15 14:37:05 +00:00
|
|
|
}
|
2012-05-03 04:11:53 +00:00
|
|
|
|
2019-09-28 23:32:51 +02:00
|
|
|
paint_stroke_free(C, op);
|
2011-01-15 14:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns zero if the stroke dots should not be spaced, non-zero otherwise */
|
2017-10-17 13:43:10 +11:00
|
|
|
bool paint_space_stroke_enabled(Brush *br, ePaintMode mode)
|
2011-01-15 14:48:44 +00:00
|
|
|
{
|
2020-08-17 18:28:39 +02:00
|
|
|
if ((br->flag & BRUSH_SPACE) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-18 21:37:39 +02:00
|
|
|
if (br->sculpt_tool == SCULPT_TOOL_CLOTH || SCULPT_is_cloth_deform_brush(br)) {
|
2020-08-17 18:28:39 +02:00
|
|
|
/* The Cloth Brush is a special case for stroke spacing. Even if it has grab modes which do
|
|
|
|
* not support dynamic size, stroke spacing needs to be enabled so it is possible to control
|
|
|
|
* whether the simulation runs constantly or only when the brush moves when using the cloth
|
|
|
|
* grab brushes. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return paint_supports_dynamic_size(br, mode);
|
2013-01-16 19:59:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 14:55:36 +00:00
|
|
|
static bool sculpt_is_grab_tool(Brush *br)
|
|
|
|
{
|
2020-02-28 14:40:40 +01:00
|
|
|
|
|
|
|
if (br->sculpt_tool == SCULPT_TOOL_CLOTH && br->cloth_deform_type == BRUSH_CLOTH_DEFORM_GRAB) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-02 18:45:26 +02:00
|
|
|
return ELEM(br->sculpt_tool,
|
|
|
|
SCULPT_TOOL_GRAB,
|
2019-09-06 23:14:57 +02:00
|
|
|
SCULPT_TOOL_ELASTIC_DEFORM,
|
2019-09-16 17:20:51 +02:00
|
|
|
SCULPT_TOOL_POSE,
|
Sculpt: Boundary Brush
This brush includes a set of deformation modes designed to deform and
control the shape of the mesh boundaries, which are really hard to do
with regular sculpt brushes (and even in edit mode). This is useful
for creating cloth assets and hard surface base meshes.
The brush detects the mesh boundary closest to the active vertex and
propagates the deformation using the brush falloff into the mesh.
It includes bend, expand, inflate, grab and twist deform modes.
The main use cases of this brush are the Bend and Expand deformation
modes, which depend on a grid topology to create the best results.
In order to do further adjustments and tweaks to the result of these
deformation modes, the brush also includes the Inflate, Grab and
Twist deformation modes, which do not depend that much on the topology.
Grab and Inflate are the same operation that is implemented in the
Grab and Inflate tools, they are also available in the boundary brush
as producing deformations with regular brushes in these areas is very
hard to control.
Even if this brush can produce deformations in triangle meshes and
meshes with a non-regular quad grid, the more regular and clean the
topology is, the better. Most of the assets this brush is intended to
deform are always created from a cylindrical or plane quad grid, so it
should be fine. Also, its algorithms can be improved in future versions
to handle more corner cases and topology patterns.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8356
2020-08-10 17:57:01 +02:00
|
|
|
SCULPT_TOOL_BOUNDARY,
|
2018-07-02 18:45:26 +02:00
|
|
|
SCULPT_TOOL_THUMB,
|
|
|
|
SCULPT_TOOL_ROTATE,
|
|
|
|
SCULPT_TOOL_SNAKE_HOOK);
|
2013-04-15 14:55:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 19:59:55 +00:00
|
|
|
/* return true if the brush size can change during paint (normally used for pressure) */
|
2017-10-17 13:43:10 +11:00
|
|
|
bool paint_supports_dynamic_size(Brush *br, ePaintMode mode)
|
2013-01-16 19:59:55 +00:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (br->flag & BRUSH_ANCHORED) {
|
2013-03-13 03:46:22 +00:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 05:23:53 +00:00
|
|
|
switch (mode) {
|
2018-11-14 11:20:08 +11:00
|
|
|
case PAINT_MODE_SCULPT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (sculpt_is_grab_tool(br)) {
|
2013-03-14 05:52:30 +00:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-14 11:20:08 +11:00
|
|
|
case PAINT_MODE_TEXTURE_2D: /* fall through */
|
|
|
|
case PAINT_MODE_TEXTURE_3D:
|
2014-07-21 12:02:05 +02:00
|
|
|
if ((br->imagepaint_tool == PAINT_TOOL_FILL) && (br->flag & BRUSH_USE_GRADIENT)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
default:
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2013-03-14 05:52:30 +00:00
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-17 13:43:10 +11:00
|
|
|
bool paint_supports_smooth_stroke(Brush *br, ePaintMode mode)
|
2013-03-14 02:27:36 +00:00
|
|
|
{
|
2013-03-16 14:42:05 +00:00
|
|
|
if (!(br->flag & BRUSH_SMOOTH_STROKE) ||
|
2014-07-21 12:02:05 +02:00
|
|
|
(br->flag & (BRUSH_ANCHORED | BRUSH_DRAG_DOT | BRUSH_LINE))) {
|
2013-03-14 02:27:36 +00:00
|
|
|
return false;
|
2013-03-14 05:52:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-14 02:27:36 +00:00
|
|
|
switch (mode) {
|
2018-11-14 11:20:08 +11:00
|
|
|
case PAINT_MODE_SCULPT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (sculpt_is_grab_tool(br)) {
|
2013-03-14 02:27:36 +00:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2013-03-14 02:27:36 +00:00
|
|
|
default:
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2013-03-14 05:52:30 +00:00
|
|
|
}
|
2013-03-14 02:27:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-17 13:43:10 +11:00
|
|
|
bool paint_supports_texture(ePaintMode mode)
|
2013-10-10 20:23:24 +00:00
|
|
|
{
|
2014-09-29 15:51:47 +10:00
|
|
|
/* omit: PAINT_WEIGHT, PAINT_SCULPT_UV, PAINT_INVALID */
|
2018-11-14 11:20:08 +11:00
|
|
|
return ELEM(
|
|
|
|
mode, PAINT_MODE_SCULPT, PAINT_MODE_VERTEX, PAINT_MODE_TEXTURE_3D, PAINT_MODE_TEXTURE_2D);
|
2013-10-10 20:23:24 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 03:46:22 +00:00
|
|
|
/* return true if the brush size can change during paint (normally used for pressure) */
|
2017-10-17 13:43:10 +11:00
|
|
|
bool paint_supports_dynamic_tex_coords(Brush *br, ePaintMode mode)
|
2013-03-13 03:46:22 +00:00
|
|
|
{
|
2019-04-22 09:19:45 +10:00
|
|
|
if (br->flag & BRUSH_ANCHORED) {
|
2013-03-13 03:46:22 +00:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-13 05:23:53 +00:00
|
|
|
switch (mode) {
|
2018-11-14 11:20:08 +11:00
|
|
|
case PAINT_MODE_SCULPT:
|
2019-04-22 09:19:45 +10:00
|
|
|
if (sculpt_is_grab_tool(br)) {
|
2013-03-13 05:23:53 +00:00
|
|
|
return false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2013-03-13 03:46:22 +00:00
|
|
|
default:
|
2013-07-19 16:44:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-13 03:46:22 +00:00
|
|
|
return true;
|
2010-01-09 17:15:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 04:11:53 +00:00
|
|
|
#define PAINT_STROKE_MODAL_CANCEL 1
|
|
|
|
|
|
|
|
/* called in paint_ops.c, on each regeneration of keymaps */
|
|
|
|
struct wmKeyMap *paint_stroke_modal_keymap(struct wmKeyConfig *keyconf)
|
|
|
|
{
|
|
|
|
static struct EnumPropertyItem modal_items[] = {
|
|
|
|
{PAINT_STROKE_MODAL_CANCEL, "CANCEL", 0, "Cancel", "Cancel and undo a stroke in progress"},
|
|
|
|
|
|
|
|
{0}};
|
|
|
|
|
2012-05-06 22:12:26 +00:00
|
|
|
static const char *name = "Paint Stroke Modal";
|
2012-05-03 04:11:53 +00:00
|
|
|
|
2020-03-27 10:58:00 +11:00
|
|
|
struct wmKeyMap *keymap = WM_modalkeymap_find(keyconf, name);
|
2012-05-03 04:11:53 +00:00
|
|
|
|
|
|
|
/* this function is called for each spacetype, only needs to add map once */
|
|
|
|
if (!keymap) {
|
2020-03-27 10:58:00 +11:00
|
|
|
keymap = WM_modalkeymap_ensure(keyconf, name, modal_items);
|
2012-05-03 04:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return keymap;
|
|
|
|
}
|
|
|
|
|
2018-07-02 18:45:26 +02:00
|
|
|
static void paint_stroke_add_sample(
|
|
|
|
const Paint *paint, PaintStroke *stroke, float x, float y, float pressure)
|
2012-05-21 23:32:46 +00:00
|
|
|
{
|
|
|
|
PaintSample *sample = &stroke->samples[stroke->cur_sample];
|
2015-11-23 15:44:15 +11:00
|
|
|
int max_samples = CLAMPIS(paint->num_input_samples, 1, PAINT_MAX_INPUT_SAMPLES);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-21 23:32:46 +00:00
|
|
|
sample->mouse[0] = x;
|
|
|
|
sample->mouse[1] = y;
|
2013-05-18 11:25:24 +00:00
|
|
|
sample->pressure = pressure;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-21 23:32:46 +00:00
|
|
|
stroke->cur_sample++;
|
2019-04-22 09:19:45 +10:00
|
|
|
if (stroke->cur_sample >= max_samples) {
|
2012-05-21 23:32:46 +00:00
|
|
|
stroke->cur_sample = 0;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
if (stroke->num_samples < max_samples) {
|
2012-05-21 23:32:46 +00:00
|
|
|
stroke->num_samples++;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2012-05-21 23:32:46 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 18:45:26 +02:00
|
|
|
static void paint_stroke_sample_average(const PaintStroke *stroke, PaintSample *average)
|
2012-05-21 23:32:46 +00:00
|
|
|
{
|
|
|
|
memset(average, 0, sizeof(*average));
|
|
|
|
|
|
|
|
BLI_assert(stroke->num_samples > 0);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-09-09 18:41:07 +02:00
|
|
|
for (int i = 0; i < stroke->num_samples; i++) {
|
2012-05-21 23:32:46 +00:00
|
|
|
add_v2_v2(average->mouse, stroke->samples[i].mouse);
|
2013-05-18 11:25:24 +00:00
|
|
|
average->pressure += stroke->samples[i].pressure;
|
|
|
|
}
|
2012-05-21 23:32:46 +00:00
|
|
|
|
|
|
|
mul_v2_fl(average->mouse, 1.0f / stroke->num_samples);
|
2013-05-18 11:25:24 +00:00
|
|
|
average->pressure /= stroke->num_samples;
|
2012-05-21 23:32:46 +00:00
|
|
|
|
2019-01-15 23:24:20 +11:00
|
|
|
// printf("avg=(%f, %f), num=%d\n", average->mouse[0], average->mouse[1], stroke->num_samples);
|
2012-05-21 23:32:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/**
|
|
|
|
* Slightly different version of spacing for line/curve strokes,
|
|
|
|
* makes sure the dabs stay on the line path.
|
|
|
|
*/
|
|
|
|
static void paint_line_strokes_spacing(bContext *C,
|
|
|
|
wmOperator *op,
|
|
|
|
PaintStroke *stroke,
|
|
|
|
float spacing,
|
|
|
|
float *length_residue,
|
|
|
|
const float old_pos[2],
|
|
|
|
const float new_pos[2])
|
|
|
|
{
|
|
|
|
UnifiedPaintSettings *ups = stroke->ups;
|
2021-04-26 17:42:38 +02:00
|
|
|
Paint *paint = BKE_paint_get_active_from_context(C);
|
|
|
|
Brush *brush = BKE_paint_brush(paint);
|
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
|
|
|
ARegion *region = CTX_wm_region(C);
|
|
|
|
|
|
|
|
const bool use_scene_spacing = paint_stroke_use_scene_spacing(brush, mode);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2021-06-01 12:49:20 +10:00
|
|
|
float mouse[3], dmouse[2];
|
2014-07-21 12:02:05 +02:00
|
|
|
float length;
|
2021-04-26 17:42:38 +02:00
|
|
|
float d_world_space_position[3] = {0.0f};
|
|
|
|
float world_space_position_old[3], world_space_position_new[3];
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
copy_v2_v2(stroke->last_mouse_position, old_pos);
|
|
|
|
|
2021-04-26 17:42:38 +02:00
|
|
|
if (use_scene_spacing) {
|
|
|
|
bool hit_old = SCULPT_stroke_get_location(C, world_space_position_old, old_pos);
|
|
|
|
bool hit_new = SCULPT_stroke_get_location(C, world_space_position_new, new_pos);
|
|
|
|
mul_m4_v3(stroke->vc.obact->obmat, world_space_position_old);
|
|
|
|
mul_m4_v3(stroke->vc.obact->obmat, world_space_position_new);
|
|
|
|
if (hit_old && hit_new && stroke->stroke_over_mesh) {
|
|
|
|
sub_v3_v3v3(d_world_space_position, world_space_position_new, world_space_position_old);
|
|
|
|
length = len_v3(d_world_space_position);
|
|
|
|
stroke->stroke_over_mesh = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
length = 0.0f;
|
|
|
|
zero_v3(d_world_space_position);
|
|
|
|
stroke->stroke_over_mesh = hit_new;
|
|
|
|
if (stroke->stroke_over_mesh) {
|
|
|
|
copy_v3_v3(stroke->last_world_space_position, world_space_position_old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sub_v2_v2v2(dmouse, new_pos, old_pos);
|
|
|
|
length = normalize_v2(dmouse);
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
BLI_assert(length >= 0.0f);
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (length == 0.0f) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
while (length > 0.0f) {
|
|
|
|
float spacing_final = spacing - *length_residue;
|
|
|
|
length += *length_residue;
|
|
|
|
*length_residue = 0.0;
|
|
|
|
|
|
|
|
if (length >= spacing) {
|
2021-04-26 17:42:38 +02:00
|
|
|
if (use_scene_spacing) {
|
|
|
|
float final_world_space_position[3];
|
|
|
|
normalize_v3(d_world_space_position);
|
|
|
|
mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing_final);
|
|
|
|
add_v3_v3v3(
|
|
|
|
final_world_space_position, world_space_position_old, final_world_space_position);
|
|
|
|
ED_view3d_project(region, final_world_space_position, mouse);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * spacing_final;
|
|
|
|
mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * spacing_final;
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
|
|
|
ups->overlap_factor = paint_stroke_integrate_overlap(stroke->brush, 1.0);
|
|
|
|
|
|
|
|
stroke->stroke_distance += spacing / stroke->zoom_2d;
|
|
|
|
paint_brush_stroke_add_step(C, op, mouse, 1.0);
|
|
|
|
|
|
|
|
length -= spacing;
|
|
|
|
spacing_final = spacing;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*length_residue = length;
|
|
|
|
}
|
|
|
|
|
2020-08-07 22:56:13 +10:00
|
|
|
static void paint_stroke_line_end(bContext *C,
|
|
|
|
wmOperator *op,
|
|
|
|
PaintStroke *stroke,
|
|
|
|
const float mouse[2])
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
|
|
|
Brush *br = stroke->brush;
|
|
|
|
if (stroke->stroke_started && (br->flag & BRUSH_LINE)) {
|
|
|
|
stroke->ups->overlap_factor = paint_stroke_integrate_overlap(br, 1.0);
|
|
|
|
|
|
|
|
paint_brush_stroke_add_step(C, op, stroke->last_mouse_position, 1.0);
|
|
|
|
paint_space_stroke(C, op, mouse, 1.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
Brush *br = stroke->brush;
|
2014-10-07 20:19:06 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (br->flag & BRUSH_CURVE) {
|
2015-05-07 18:10:34 +02:00
|
|
|
UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings;
|
2014-07-21 12:02:05 +02:00
|
|
|
const Scene *scene = CTX_data_scene(C);
|
2019-08-19 17:03:55 +02:00
|
|
|
const float spacing = paint_space_stroke_spacing(C, scene, stroke, 1.0f, 1.0f);
|
2014-07-21 12:02:05 +02:00
|
|
|
PaintCurve *pc = br->paint_curve;
|
|
|
|
PaintCurvePoint *pcp;
|
|
|
|
float length_residue = 0.0f;
|
|
|
|
int i;
|
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (!pc) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2014-10-07 20:19:06 +02:00
|
|
|
#ifdef DEBUG_TIME
|
2016-01-27 11:48:30 +01:00
|
|
|
TIMEIT_START_AVERAGED(whole_stroke);
|
2014-10-07 20:19:06 +02:00
|
|
|
#endif
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
pcp = pc->points;
|
|
|
|
stroke->ups->overlap_factor = paint_stroke_integrate_overlap(br, 1.0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
for (i = 0; i < pc->tot_points - 1; i++, pcp++) {
|
|
|
|
int j;
|
|
|
|
float data[(PAINT_CURVE_NUM_SEGMENTS + 1) * 2];
|
2015-05-07 18:10:34 +02:00
|
|
|
float tangents[(PAINT_CURVE_NUM_SEGMENTS + 1) * 2];
|
2014-07-21 12:02:05 +02:00
|
|
|
PaintCurvePoint *pcp_next = pcp + 1;
|
2015-05-07 18:10:34 +02:00
|
|
|
bool do_rake = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-07 18:10:34 +02:00
|
|
|
for (j = 0; j < 2; j++) {
|
2014-07-21 12:02:05 +02:00
|
|
|
BKE_curve_forward_diff_bezier(pcp->bez.vec[1][j],
|
|
|
|
pcp->bez.vec[2][j],
|
|
|
|
pcp_next->bez.vec[0][j],
|
|
|
|
pcp_next->bez.vec[1][j],
|
|
|
|
data + j,
|
|
|
|
PAINT_CURVE_NUM_SEGMENTS,
|
|
|
|
sizeof(float[2]));
|
2015-05-07 18:10:34 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-07 18:10:34 +02:00
|
|
|
if ((br->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) ||
|
|
|
|
(br->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
|
|
|
|
do_rake = true;
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
BKE_curve_forward_diff_tangent_bezier(pcp->bez.vec[1][j],
|
|
|
|
pcp->bez.vec[2][j],
|
|
|
|
pcp_next->bez.vec[0][j],
|
|
|
|
pcp_next->bez.vec[1][j],
|
|
|
|
tangents + j,
|
|
|
|
PAINT_CURVE_NUM_SEGMENTS,
|
|
|
|
sizeof(float[2]));
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
for (j = 0; j < PAINT_CURVE_NUM_SEGMENTS; j++) {
|
2015-05-07 18:10:34 +02:00
|
|
|
if (do_rake) {
|
2015-05-07 18:32:35 +02:00
|
|
|
float rotation = atan2f(tangents[2 * j], tangents[2 * j + 1]);
|
|
|
|
paint_update_brush_rake_rotation(ups, br, rotation);
|
2015-05-07 18:10:34 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (!stroke->stroke_started) {
|
|
|
|
stroke->last_pressure = 1.0;
|
|
|
|
copy_v2_v2(stroke->last_mouse_position, data + 2 * j);
|
2021-04-26 17:42:38 +02:00
|
|
|
|
|
|
|
if (paint_stroke_use_scene_spacing(br, BKE_paintmode_get_active_from_context(C))) {
|
|
|
|
stroke->stroke_over_mesh = SCULPT_stroke_get_location(
|
|
|
|
C, stroke->last_world_space_position, data + 2 * j);
|
|
|
|
mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position);
|
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
stroke->stroke_started = stroke->test_start(C, op, stroke->last_mouse_position);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (stroke->stroke_started) {
|
|
|
|
paint_brush_stroke_add_step(C, op, data + 2 * j, 1.0);
|
2018-07-02 18:45:26 +02:00
|
|
|
paint_line_strokes_spacing(
|
|
|
|
C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-07-02 18:45:26 +02:00
|
|
|
paint_line_strokes_spacing(
|
|
|
|
C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
stroke_done(C, op);
|
2014-10-07 20:19:06 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_TIME
|
2016-01-27 11:48:30 +01:00
|
|
|
TIMEIT_END_AVERAGED(whole_stroke);
|
2014-10-07 20:19:06 +02:00
|
|
|
#endif
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 08:07:15 +10:00
|
|
|
static void paint_stroke_line_constrain(PaintStroke *stroke, float mouse[2])
|
2015-01-31 17:23:30 +11:00
|
|
|
{
|
2015-01-30 19:47:58 +01:00
|
|
|
if (stroke->constrain_line) {
|
|
|
|
float line[2];
|
|
|
|
float angle, len, res;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-30 19:47:58 +01:00
|
|
|
sub_v2_v2v2(line, mouse, stroke->last_mouse_position);
|
2015-04-05 06:32:25 +10:00
|
|
|
angle = atan2f(line[1], line[0]);
|
2015-01-30 19:47:58 +01:00
|
|
|
len = len_v2(line);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-02 11:29:01 +01:00
|
|
|
/* divide angle by PI/4 */
|
2015-01-31 17:23:30 +11:00
|
|
|
angle = 4.0f * angle / (float)M_PI;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-02 11:29:01 +01:00
|
|
|
/* now take residue */
|
2015-01-31 17:23:30 +11:00
|
|
|
res = angle - floorf(angle);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-02 11:29:01 +01:00
|
|
|
/* residue decides how close we are at a certain angle */
|
2015-01-31 17:23:30 +11:00
|
|
|
if (res <= 0.5f) {
|
|
|
|
angle = floorf(angle) * (float)M_PI_4;
|
2015-01-30 19:47:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-01-31 17:23:30 +11:00
|
|
|
angle = (floorf(angle) + 1.0f) * (float)M_PI_4;
|
2015-01-30 19:47:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-02 11:29:01 +01:00
|
|
|
mouse[0] = stroke->constrained_pos[0] = len * cosf(angle) + stroke->last_mouse_position[0];
|
|
|
|
mouse[1] = stroke->constrained_pos[1] = len * sinf(angle) + stroke->last_mouse_position[1];
|
2015-01-30 19:47:58 +01:00
|
|
|
}
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-08-19 21:24:52 +00:00
|
|
|
{
|
Paint refactoring commit, non-disruptive (in theory :p)
* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:
Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:
These attributes/aspects are:
Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)
Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.
Properties that affect this are:
Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.
These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.
2013-04-12 17:21:31 +00:00
|
|
|
Paint *p = BKE_paint_get_active_from_context(C);
|
2017-10-17 13:43:10 +11:00
|
|
|
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
|
2009-08-19 21:24:52 +00:00
|
|
|
PaintStroke *stroke = op->customdata;
|
2020-04-06 19:35:42 +02:00
|
|
|
Brush *br = stroke->brush = BKE_paint_brush(p);
|
2012-05-21 23:32:46 +00:00
|
|
|
PaintSample sample_average;
|
2009-08-19 21:24:52 +00:00
|
|
|
float mouse[2];
|
2013-05-18 15:24:25 +00:00
|
|
|
bool first_dab = false;
|
|
|
|
bool first_modal = false;
|
2013-05-15 14:37:05 +00:00
|
|
|
bool redraw = false;
|
2013-05-18 09:44:30 +00:00
|
|
|
float pressure;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-07 01:36:17 +02:00
|
|
|
if (event->type == INBETWEEN_MOUSEMOVE && !paint_tool_require_inbetween_mouse_events(br, mode)) {
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/* see if tablet affects event. Line, anchored and drag dot strokes do not support pressure */
|
2018-07-02 18:45:26 +02:00
|
|
|
pressure = ((br->flag & (BRUSH_LINE | BRUSH_ANCHORED | BRUSH_DRAG_DOT)) ?
|
|
|
|
1.0f :
|
|
|
|
WM_event_tablet_data(event, &stroke->pen_flip, NULL));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-01 19:31:28 +01:00
|
|
|
/* When processing a timer event the pressure from the event is 0, so use the last valid
|
|
|
|
* pressure. */
|
|
|
|
if (event->type == TIMER) {
|
|
|
|
pressure = stroke->last_tablet_event_pressure;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stroke->last_tablet_event_pressure = pressure;
|
|
|
|
}
|
|
|
|
|
2013-05-18 11:25:24 +00:00
|
|
|
paint_stroke_add_sample(p, stroke, event->mval[0], event->mval[1], pressure);
|
2012-05-21 23:32:46 +00:00
|
|
|
paint_stroke_sample_average(stroke, &sample_average);
|
|
|
|
|
Sculpt: Experimental Pen Tilt Support
This adds support for pen tilt in sculpt mode. For now, pen tilt is used
by tweaking the tilt strength property, which controls how much the pen
angle affects the sculpt normal. This is available in Draw, Draw Sharp,
Flatten, Fill, Scrape and Clay Strips brushes, but it can be enabled in
more tools later.
The purpose of this patch is to have a usable implementation of pen tilt
in a painting mode, so users can test and see in which hardware and
platforms this feature is supported and how well it works. If it works
ok, more tools and features that rely on pen tilt can be implemented,
like brushes that blend between two deformations depending on the angle.
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D8893
2020-10-08 00:00:36 +02:00
|
|
|
/* Tilt. */
|
|
|
|
if (WM_event_is_tablet(event)) {
|
|
|
|
stroke->x_tilt = event->tablet.x_tilt;
|
|
|
|
stroke->y_tilt = event->tablet.y_tilt;
|
|
|
|
}
|
|
|
|
|
2016-08-18 00:21:55 -04:00
|
|
|
#ifdef WITH_INPUT_NDOF
|
2012-10-20 20:20:02 +00:00
|
|
|
/* let NDOF motion pass through to the 3D view so we can paint and rotate simultaneously!
|
|
|
|
* this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it
|
|
|
|
* since the 2D deltas are zero -- code in this file needs to be updated to use the
|
|
|
|
* post-NDOF_MOTION MOUSEMOVE */
|
2019-04-22 09:19:45 +10:00
|
|
|
if (event->type == NDOF_MOTION) {
|
2011-07-24 08:02:42 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2016-08-18 00:21:55 -04:00
|
|
|
#endif
|
2011-07-24 08:02:42 +00:00
|
|
|
|
2013-05-18 15:24:25 +00:00
|
|
|
/* one time initialization */
|
2013-05-23 20:20:24 +00:00
|
|
|
if (!stroke->stroke_init) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (paint_stroke_curve_end(C, op, stroke)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
return OPERATOR_FINISHED;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (paint_supports_smooth_stroke(br, mode)) {
|
2020-06-04 18:35:43 +10:00
|
|
|
stroke->stroke_cursor = WM_paint_cursor_activate(
|
|
|
|
SPACE_TYPE_ANY, RGN_TYPE_ANY, paint_poll, paint_draw_smooth_cursor, stroke);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-18 15:24:25 +00:00
|
|
|
stroke->stroke_init = true;
|
|
|
|
first_modal = true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-18 15:24:25 +00:00
|
|
|
/* one time stroke initialization */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!stroke->stroke_started) {
|
2013-05-18 11:25:24 +00:00
|
|
|
stroke->last_pressure = sample_average.pressure;
|
2013-05-18 15:24:25 +00:00
|
|
|
copy_v2_v2(stroke->last_mouse_position, sample_average.mouse);
|
2019-08-19 17:03:55 +02:00
|
|
|
if (paint_stroke_use_scene_spacing(br, mode)) {
|
2020-03-06 15:24:15 +01:00
|
|
|
stroke->stroke_over_mesh = SCULPT_stroke_get_location(
|
2019-09-06 17:16:59 +02:00
|
|
|
C, stroke->last_world_space_position, sample_average.mouse);
|
|
|
|
mul_m4_v3(stroke->vc.obact->obmat, stroke->last_world_space_position);
|
2019-08-19 17:03:55 +02:00
|
|
|
}
|
2012-05-21 23:32:46 +00:00
|
|
|
stroke->stroke_started = stroke->test_start(C, op, sample_average.mouse);
|
2012-12-28 01:36:00 +00:00
|
|
|
BLI_assert((stroke->stroke_started & ~1) == 0); /* 0/1 */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->stroke_started) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (br->flag & BRUSH_AIRBRUSH) {
|
2009-10-20 13:58:53 +00:00
|
|
|
stroke->timer = WM_event_add_timer(
|
|
|
|
CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (br->flag & BRUSH_LINE) {
|
2020-06-04 18:35:43 +10:00
|
|
|
stroke->stroke_cursor = WM_paint_cursor_activate(
|
|
|
|
SPACE_TYPE_ANY, RGN_TYPE_ANY, paint_poll, paint_draw_line_cursor, stroke);
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-05-18 15:24:25 +00:00
|
|
|
first_dab = true;
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2012-05-03 04:11:53 +00:00
|
|
|
/* Cancel */
|
|
|
|
if (event->type == EVT_MODAL_MAP && event->val == PAINT_STROKE_MODAL_CANCEL) {
|
2013-10-30 23:08:53 +00:00
|
|
|
if (op->type->cancel) {
|
|
|
|
op->type->cancel(C, op);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paint_stroke_cancel(C, op);
|
|
|
|
}
|
|
|
|
return OPERATOR_CANCELLED;
|
2012-05-03 04:11:53 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
if (event->type == stroke->event_type && !first_modal) {
|
|
|
|
if (event->val == KM_RELEASE) {
|
2015-01-30 19:47:58 +01:00
|
|
|
copy_v2_fl2(mouse, event->mval[0], event->mval[1]);
|
2015-02-02 11:29:01 +01:00
|
|
|
paint_stroke_line_constrain(stroke, mouse);
|
2016-06-22 14:02:51 +10:00
|
|
|
paint_stroke_line_end(C, op, stroke, mouse);
|
2014-07-21 12:02:05 +02:00
|
|
|
stroke_done(C, op);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-03-18 10:38:37 -06:00
|
|
|
else if (ELEM(event->type, EVT_RETKEY, EVT_SPACEKEY)) {
|
2014-07-21 12:02:05 +02:00
|
|
|
paint_stroke_line_end(C, op, stroke, sample_average.mouse);
|
2012-05-03 04:11:53 +00:00
|
|
|
stroke_done(C, op);
|
2009-11-04 20:15:17 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2015-01-30 19:47:58 +01:00
|
|
|
else if (br->flag & BRUSH_LINE) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (event->alt) {
|
2015-01-30 19:47:58 +01:00
|
|
|
stroke->constrain_line = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
|
|
|
else {
|
2015-01-30 19:47:58 +01:00
|
|
|
stroke->constrain_line = false;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-30 19:47:58 +01:00
|
|
|
copy_v2_fl2(mouse, event->mval[0], event->mval[1]);
|
2015-02-02 11:29:01 +01:00
|
|
|
paint_stroke_line_constrain(stroke, mouse);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-05 05:17:25 +10:00
|
|
|
if (stroke->stroke_started &&
|
|
|
|
(first_modal || (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)))) {
|
2015-07-25 13:07:05 +10:00
|
|
|
if ((br->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) ||
|
|
|
|
(br->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
|
2015-01-30 19:47:58 +01:00
|
|
|
copy_v2_v2(stroke->ups->last_rake, stroke->last_mouse_position);
|
|
|
|
}
|
|
|
|
paint_calculate_rake_rotation(stroke->ups, br, mouse);
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
else if (first_modal ||
|
|
|
|
/* regular dabs */
|
2020-06-18 12:21:38 +10:00
|
|
|
(!(br->flag & BRUSH_AIRBRUSH) && (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE))) ||
|
2014-07-21 12:02:05 +02:00
|
|
|
/* airbrush */
|
|
|
|
((br->flag & BRUSH_AIRBRUSH) && event->type == TIMER &&
|
|
|
|
event->customdata == stroke->timer)) {
|
2016-07-15 17:17:42 +10:00
|
|
|
if (paint_smooth_stroke(stroke, &sample_average, mode, mouse, &pressure)) {
|
2013-05-18 15:24:25 +00:00
|
|
|
if (stroke->stroke_started) {
|
2014-07-21 12:02:05 +02:00
|
|
|
if (paint_space_stroke_enabled(br, mode)) {
|
2019-04-22 09:19:45 +10:00
|
|
|
if (paint_space_stroke(C, op, mouse, pressure)) {
|
2013-05-15 14:37:05 +00:00
|
|
|
redraw = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
}
|
2010-07-14 14:11:03 +00:00
|
|
|
else {
|
2014-07-21 12:02:05 +02:00
|
|
|
float dmouse[2];
|
|
|
|
sub_v2_v2v2(dmouse, mouse, stroke->last_mouse_position);
|
|
|
|
stroke->stroke_distance += len_v2(dmouse);
|
2013-05-18 09:44:30 +00:00
|
|
|
paint_brush_stroke_add_step(C, op, mouse, pressure);
|
2013-05-15 14:37:05 +00:00
|
|
|
redraw = true;
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-24 02:37:42 +00:00
|
|
|
/* we want the stroke to have the first daub at the start location
|
|
|
|
* instead of waiting till we have moved the space distance */
|
2014-07-21 12:02:05 +02:00
|
|
|
if (first_dab && paint_space_stroke_enabled(br, mode) && !(br->flag & BRUSH_SMOOTH_STROKE)) {
|
|
|
|
stroke->ups->overlap_factor = paint_stroke_integrate_overlap(br, 1.0);
|
|
|
|
paint_brush_stroke_add_step(C, op, sample_average.mouse, sample_average.pressure);
|
2013-05-15 14:37:05 +00:00
|
|
|
redraw = true;
|
2010-07-14 14:11:03 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-01 13:53:25 +10:00
|
|
|
/* do updates for redraw. if event is in between mouse-move there are more
|
2013-05-15 14:37:05 +00:00
|
|
|
* coming, so postpone potentially slow redraw updates until all are done */
|
2014-07-21 12:02:05 +02:00
|
|
|
if (event->type != INBETWEEN_MOUSEMOVE) {
|
|
|
|
wmWindow *window = CTX_wm_window(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
/* At the very least, invalidate the cursor */
|
2020-03-06 16:56:42 +01:00
|
|
|
if (region && (p->flags & PAINT_SHOW_BRUSH)) {
|
|
|
|
WM_paint_cursor_tag_redraw(window, region);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:19:45 +10:00
|
|
|
if (redraw && stroke->redraw) {
|
2013-05-15 14:37:05 +00:00
|
|
|
stroke->redraw(C, stroke, false);
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Sculpt: Multithreading & PBVH Changes
* Sculpting, normal update and bounding box code is now multithreaded
using OpenMP.
* Fix a number of update issues: normals on node boundaries, outdated
bounding boxes, partial redraw, .. . There's probably still a few
left, but should be better now.
* Clicking once now does a single paint instead of two (was also
painting on mouse up event).
* Smooth shading now is enabled for the full mesh when the first face
uses it (so it can be tested at least).
Implementation Notes:
* PBVH search can now be done either using a callback or bt gathering the
nodes in an array. The latter makes multithreading with OpenMP easier.
* Normals update code is now inside PBVH, was doing it per node before but
should do all faces first and only then vertices.
* Instead of using search modes + 1 modified flag, now nodes get 4 flags
to indicate what needs to be updated for them, found that this makes it
easier for me to understand the code and fix update bugs.
* PBVHNode is now exposed as an abstract type, I think this makes it more
clear what is happening than having it's data passed as part of callback
functions.
* Active_verts list was replaced by looping over nodes and the vertices
inside them. However the grab brush still uses the active_verts system,
will fix that later.
* Some micro-optimizations, like avoiding a few multiplications/divisions,
using local variables instead of pointers, or looping over fewer vertices
to update the bounding boxes.
2009-11-02 18:47:03 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 05:44:32 +00:00
|
|
|
int paint_stroke_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PaintStroke *stroke = op->customdata;
|
|
|
|
|
2016-02-24 00:31:46 +11:00
|
|
|
/* only when executed for the first time */
|
|
|
|
if (stroke->stroke_started == 0) {
|
|
|
|
PropertyRNA *strokeprop;
|
|
|
|
PointerRNA firstpoint;
|
|
|
|
float mouse[2];
|
|
|
|
|
|
|
|
strokeprop = RNA_struct_find_property(op->ptr, "stroke");
|
|
|
|
|
|
|
|
if (RNA_property_collection_lookup_int(op->ptr, strokeprop, 0, &firstpoint)) {
|
|
|
|
RNA_float_get_array(&firstpoint, "mouse", mouse);
|
|
|
|
stroke->stroke_started = stroke->test_start(C, op, mouse);
|
2016-02-23 23:47:30 +11:00
|
|
|
}
|
2016-02-24 00:31:46 +11:00
|
|
|
}
|
2016-02-23 23:47:30 +11:00
|
|
|
|
2016-02-24 00:31:46 +11:00
|
|
|
if (stroke->stroke_started) {
|
|
|
|
RNA_BEGIN (op->ptr, itemptr, "stroke") {
|
|
|
|
stroke->update_step(C, stroke, &itemptr);
|
|
|
|
}
|
|
|
|
RNA_END;
|
2009-08-20 05:44:32 +00:00
|
|
|
}
|
2016-02-24 00:31:46 +11:00
|
|
|
|
|
|
|
bool ok = (stroke->stroke_started != 0);
|
2009-08-20 05:44:32 +00:00
|
|
|
|
2012-05-03 04:11:53 +00:00
|
|
|
stroke_done(C, op);
|
2009-08-20 05:44:32 +00:00
|
|
|
|
2016-02-24 00:31:46 +11:00
|
|
|
return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2009-08-20 05:44:32 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
void paint_stroke_cancel(bContext *C, wmOperator *op)
|
2011-06-06 11:04:54 +00:00
|
|
|
{
|
2012-05-03 04:11:53 +00:00
|
|
|
stroke_done(C, op);
|
2011-06-06 11:04:54 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
ViewContext *paint_stroke_view_context(PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
return &stroke->vc;
|
|
|
|
}
|
|
|
|
|
2009-08-20 05:13:07 +00:00
|
|
|
void *paint_stroke_mode_data(struct PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
return stroke->mode_data;
|
|
|
|
}
|
|
|
|
|
2014-08-12 14:20:06 +02:00
|
|
|
bool paint_stroke_flipped(struct PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
return stroke->pen_flip;
|
|
|
|
}
|
|
|
|
|
2019-03-08 15:53:38 +01:00
|
|
|
bool paint_stroke_inverted(struct PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
return stroke->stroke_mode == BRUSH_STROKE_INVERT;
|
|
|
|
}
|
|
|
|
|
2014-07-21 12:02:05 +02:00
|
|
|
float paint_stroke_distance_get(struct PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
return stroke->stroke_distance;
|
|
|
|
}
|
|
|
|
|
2009-08-20 05:13:07 +00:00
|
|
|
void paint_stroke_set_mode_data(PaintStroke *stroke, void *mode_data)
|
|
|
|
{
|
|
|
|
stroke->mode_data = mode_data;
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool paint_poll(bContext *C)
|
2009-08-20 05:13:07 +00:00
|
|
|
{
|
Paint refactoring commit, non-disruptive (in theory :p)
* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:
Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:
These attributes/aspects are:
Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)
Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.
Properties that affect this are:
Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.
These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.
2013-04-12 17:21:31 +00:00
|
|
|
Paint *p = BKE_paint_get_active_from_context(C);
|
2009-08-20 05:13:07 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 13:25:03 +02:00
|
|
|
if (p && ob && BKE_paint_brush(p) &&
|
|
|
|
(area && ELEM(area->spacetype, SPACE_VIEW3D, SPACE_IMAGE)) &&
|
2020-03-06 16:56:42 +01:00
|
|
|
(region && region->regiontype == RGN_TYPE_WINDOW)) {
|
2018-08-23 12:47:32 +10:00
|
|
|
/* Check the current tool is a brush. */
|
2020-04-03 13:25:03 +02:00
|
|
|
bToolRef *tref = area->runtime.tool;
|
2018-08-23 12:47:32 +10:00
|
|
|
if (tref && tref->runtime && tref->runtime->data_block[0]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2009-08-20 05:13:07 +00:00
|
|
|
}
|