2009-08-19 21:24:52 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
2010-07-14 14:11:03 +00:00
|
|
|
* Contributor(s): Jason Wilkins, Tom Musgrove.
|
2009-08-19 21:24:52 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/sculpt_paint/paint_stroke.c
|
|
|
|
* \ingroup edsculpt
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_brush_types.h"
|
2009-08-19 21:24:52 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_paint.h"
|
2010-07-14 14:11:03 +00:00
|
|
|
#include "BKE_brush.h"
|
2009-08-19 21:24:52 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-08-20 05:13:07 +00:00
|
|
|
#include "BIF_gl.h"
|
2009-08-19 21:24:52 +00:00
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_view3d.h"
|
|
|
|
|
|
|
|
#include "paint_intern.h"
|
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
typedef struct PaintStroke {
|
2009-08-20 05:13:07 +00:00
|
|
|
void *mode_data;
|
|
|
|
void *smooth_stroke_cursor;
|
2009-08-21 00:46:36 +00:00
|
|
|
wmTimer *timer;
|
2009-08-20 05:13:07 +00:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
/* Cached values */
|
|
|
|
ViewContext vc;
|
|
|
|
bglMats mats;
|
|
|
|
Brush *brush;
|
|
|
|
|
|
|
|
float last_mouse_position[2];
|
|
|
|
|
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 */
|
2009-08-19 21:24:52 +00:00
|
|
|
int stroke_started;
|
2011-03-01 16:26:37 +00:00
|
|
|
/* event that started stroke, for modal() return */
|
|
|
|
int event_type;
|
|
|
|
|
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;
|
|
|
|
StrokeDone done;
|
|
|
|
} PaintStroke;
|
|
|
|
|
2009-08-20 05:13:07 +00:00
|
|
|
/*** Cursor ***/
|
|
|
|
static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata)
|
|
|
|
{
|
|
|
|
Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C)));
|
|
|
|
PaintStroke *stroke = customdata;
|
|
|
|
|
|
|
|
glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke && brush && (brush->flag & BRUSH_SMOOTH_STROKE)) {
|
2009-08-20 05:13:07 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
sdrawline(x, y, (int)stroke->last_mouse_position[0] - ar->winrct.xmin,
|
2012-03-28 03:47:33 +00:00
|
|
|
(int)stroke->last_mouse_position[1] - ar->winrct.ymin);
|
2009-08-20 05:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_LINE_SMOOTH);
|
|
|
|
}
|
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* if this is a tablet event, return tablet pressure and set *pen_flip
|
2012-03-03 16:31:46 +00:00
|
|
|
* to 1 if the eraser tool is being used, 0 otherwise */
|
2011-01-08 01:45:02 +00:00
|
|
|
static float event_tablet_data(wmEvent *event, int *pen_flip)
|
2009-08-19 21:24:52 +00:00
|
|
|
{
|
2011-01-08 01:45:02 +00:00
|
|
|
int erasor = 0;
|
|
|
|
float pressure = 1;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (event->custom == EVT_DATA_TABLET) {
|
2012-03-28 03:47:33 +00:00
|
|
|
wmTabletData *wmtab = event->customdata;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
erasor = (wmtab->Active == EVT_TABLET_ERASER);
|
|
|
|
pressure = (wmtab->Active != EVT_TABLET_NONE) ? wmtab->Pressure : 1;
|
|
|
|
}
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pen_flip)
|
2011-01-08 01:45:02 +00:00
|
|
|
(*pen_flip) = erasor;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
return pressure;
|
|
|
|
}
|
2010-07-14 14:11:03 +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 */
|
|
|
|
static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
|
|
|
|
{
|
2012-01-14 23:54:51 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Paint *paint = paint_get_active(scene);
|
2011-01-08 01:45:02 +00:00
|
|
|
Brush *brush = paint_brush(paint);
|
2009-08-19 21:24:52 +00:00
|
|
|
PaintStroke *stroke = op->customdata;
|
2011-01-08 01:45:02 +00:00
|
|
|
float mouse[3];
|
|
|
|
PointerRNA itemptr;
|
|
|
|
float location[3];
|
|
|
|
float pressure;
|
|
|
|
int pen_flip;
|
2009-08-19 21:24:52 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* see if tablet affects event */
|
|
|
|
pressure = event_tablet_data(event, &pen_flip);
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* TODO: as sculpt and other paint modes are unified, this
|
2012-03-03 16:31:46 +00:00
|
|
|
* separation will go away */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->vc.obact->sculpt) {
|
2011-09-16 06:47:01 +00:00
|
|
|
float delta[2];
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2012-01-14 23:54:51 +00:00
|
|
|
brush_jitter_pos(scene, brush, mouse_in, mouse);
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* XXX: meh, this is round about because
|
2012-03-03 16:31:46 +00:00
|
|
|
* brush_jitter_pos isn't written in the best way to
|
|
|
|
* be reused here */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (brush->flag & BRUSH_JITTER_PRESSURE) {
|
2011-09-16 06:47:01 +00:00
|
|
|
sub_v2_v2v2(delta, mouse, mouse_in);
|
|
|
|
mul_v2_fl(delta, pressure);
|
|
|
|
add_v2_v2v2(mouse, mouse_in, delta);
|
2010-07-14 14:11:03 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-16 06:47:01 +00:00
|
|
|
else {
|
|
|
|
copy_v2_v2(mouse, mouse_in);
|
|
|
|
}
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
/* TODO: can remove the if statement once all modes have this */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->get_location)
|
2012-01-19 03:13:01 +00:00
|
|
|
stroke->get_location(C, location, mouse);
|
2010-07-14 14:11:03 +00:00
|
|
|
else
|
|
|
|
zero_v3(location);
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
/* Add to stroke */
|
|
|
|
RNA_collection_add(op->ptr, "stroke", &itemptr);
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-08 01:45:02 +00:00
|
|
|
RNA_float_set_array(&itemptr, "location", location);
|
|
|
|
RNA_float_set_array(&itemptr, "mouse", mouse);
|
|
|
|
RNA_boolean_set(&itemptr, "pen_flip", pen_flip);
|
|
|
|
RNA_float_set(&itemptr, "pressure", pressure);
|
2009-08-19 21:24:52 +00:00
|
|
|
|
|
|
|
stroke->last_mouse_position[0] = mouse[0];
|
|
|
|
stroke->last_mouse_position[1] = mouse[1];
|
|
|
|
|
|
|
|
stroke->update_step(C, stroke, &itemptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns zero if no sculpt changes should be made, non-zero otherwise */
|
|
|
|
static int paint_smooth_stroke(PaintStroke *stroke, float output[2], wmEvent *event)
|
|
|
|
{
|
2010-07-14 14:11:03 +00:00
|
|
|
output[0] = event->x;
|
2009-08-19 21:24:52 +00:00
|
|
|
output[1] = event->y;
|
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
if ((stroke->brush->flag & BRUSH_SMOOTH_STROKE) &&
|
|
|
|
!ELEM4(stroke->brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB, SCULPT_TOOL_ROTATE, SCULPT_TOOL_SNAKE_HOOK) &&
|
|
|
|
!(stroke->brush->flag & BRUSH_ANCHORED) &&
|
|
|
|
!(stroke->brush->flag & BRUSH_RESTORE_MESH))
|
|
|
|
{
|
2011-03-27 14:59:55 +00:00
|
|
|
float u = stroke->brush->smooth_stroke_factor, v = 1.0f - u;
|
2009-08-19 21:24:52 +00:00
|
|
|
float dx = stroke->last_mouse_position[0] - event->x, dy = stroke->last_mouse_position[1] - event->y;
|
|
|
|
|
|
|
|
/* 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. */
|
2012-03-28 03:47:33 +00:00
|
|
|
if (dx * dx + dy * dy < stroke->brush->smooth_stroke_radius * stroke->brush->smooth_stroke_radius)
|
2009-08-19 21:24:52 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
output[0] = event->x * v + stroke->last_mouse_position[0] * u;
|
|
|
|
output[1] = event->y * v + stroke->last_mouse_position[1] * u;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For brushes with stroke spacing enabled, moves mouse in steps
|
2012-03-03 16:31:46 +00:00
|
|
|
* towards the final mouse location. */
|
2009-08-19 21:24:52 +00:00
|
|
|
static int paint_space_stroke(bContext *C, wmOperator *op, wmEvent *event, const float final_mouse[2])
|
|
|
|
{
|
|
|
|
PaintStroke *stroke = op->customdata;
|
|
|
|
int cnt = 0;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (paint_space_stroke_enabled(stroke->brush)) {
|
2010-07-14 14:11:03 +00:00
|
|
|
float mouse[2];
|
|
|
|
float vec[2];
|
2009-08-19 21:24:52 +00:00
|
|
|
float length, scale;
|
|
|
|
|
2010-07-14 14:11:03 +00:00
|
|
|
copy_v2_v2(mouse, stroke->last_mouse_position);
|
|
|
|
sub_v2_v2v2(vec, final_mouse, mouse);
|
|
|
|
|
|
|
|
length = len_v2(vec);
|
2009-08-19 21:24:52 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (length > FLT_EPSILON) {
|
2012-01-12 21:48:08 +00:00
|
|
|
const Scene *scene = CTX_data_scene(C);
|
2010-07-14 14:11:03 +00:00
|
|
|
int steps;
|
|
|
|
int i;
|
2012-03-28 03:47:33 +00:00
|
|
|
float pressure = 1.0f;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-11 14:01:23 +00:00
|
|
|
/* XXX mysterious :) what has 'use size' do with this here... if you don't check for it, pressure fails */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (brush_use_size_pressure(scene, stroke->brush))
|
2011-01-11 14:01:23 +00:00
|
|
|
pressure = event_tablet_data(event, NULL);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pressure > FLT_EPSILON) {
|
2012-03-28 03:47:33 +00:00
|
|
|
scale = (brush_size(scene, stroke->brush) * pressure * stroke->brush->spacing / 50.0f) / length;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (scale > FLT_EPSILON) {
|
2011-01-11 12:36:49 +00:00
|
|
|
mul_v2_fl(vec, scale);
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2011-01-11 12:36:49 +00:00
|
|
|
steps = (int)(1.0f / scale);
|
2009-08-19 21:24:52 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
for (i = 0; i < steps; ++i, ++cnt) {
|
2011-01-11 12:36:49 +00:00
|
|
|
add_v2_v2(mouse, vec);
|
|
|
|
paint_brush_stroke_add_step(C, op, event, mouse);
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** Public API ****/
|
|
|
|
|
2009-10-27 19:53:34 +00:00
|
|
|
PaintStroke *paint_stroke_new(bContext *C,
|
2012-03-28 03:47:33 +00:00
|
|
|
StrokeGetLocation get_location,
|
|
|
|
StrokeTestStart test_start,
|
|
|
|
StrokeUpdateStep update_step,
|
|
|
|
StrokeDone done, int event_type)
|
2009-08-19 21:24:52 +00:00
|
|
|
{
|
|
|
|
PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
|
|
|
|
|
|
|
|
stroke->brush = paint_brush(paint_get_active(CTX_data_scene(C)));
|
|
|
|
view3d_set_viewcontext(C, &stroke->vc);
|
2009-10-27 19:53:34 +00:00
|
|
|
view3d_get_transformation(stroke->vc.ar, stroke->vc.rv3d, stroke->vc.obact, &stroke->mats);
|
2009-08-19 21:24:52 +00: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;
|
|
|
|
stroke->done = done;
|
2012-03-28 03:47:33 +00:00
|
|
|
stroke->event_type = event_type; /* for modal, return event */
|
2011-03-01 16:26:37 +00:00
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
return stroke;
|
|
|
|
}
|
|
|
|
|
2010-01-09 17:15:02 +00:00
|
|
|
void paint_stroke_free(PaintStroke *stroke)
|
|
|
|
{
|
|
|
|
MEM_freeN(stroke);
|
2011-01-15 14:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns zero if the stroke dots should not be spaced, non-zero otherwise */
|
|
|
|
int paint_space_stroke_enabled(Brush *br)
|
|
|
|
{
|
|
|
|
return (br->flag & BRUSH_SPACE) &&
|
|
|
|
!(br->flag & BRUSH_ANCHORED) &&
|
|
|
|
!ELEM4(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB, SCULPT_TOOL_ROTATE, SCULPT_TOOL_SNAKE_HOOK);
|
2010-01-09 17:15:02 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 21:24:52 +00:00
|
|
|
int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
PaintStroke *stroke = op->customdata;
|
|
|
|
float mouse[2];
|
2012-03-28 03:47:33 +00:00
|
|
|
int first = 0;
|
2009-08-21 00:46:36 +00:00
|
|
|
|
2011-07-25 00:03:07 +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
|
2011-07-24 08:02:42 +00:00
|
|
|
if (event->type == NDOF_MOTION)
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!stroke->stroke_started) {
|
2009-08-19 21:24:52 +00:00
|
|
|
stroke->last_mouse_position[0] = event->x;
|
|
|
|
stroke->last_mouse_position[1] = event->y;
|
|
|
|
stroke->stroke_started = stroke->test_start(C, op, event);
|
2009-08-20 05:13:07 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->stroke_started) {
|
2009-08-20 05:13:07 +00:00
|
|
|
stroke->smooth_stroke_cursor =
|
2012-03-28 03:47:33 +00:00
|
|
|
WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke);
|
2009-08-20 05:13:07 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->brush->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);
|
2009-08-21 00:46:36 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 03:47:33 +00:00
|
|
|
first = 1;
|
2009-10-27 19:53:34 +00:00
|
|
|
//ED_region_tag_redraw(ar);
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (event->type == stroke->event_type && event->val == KM_RELEASE) {
|
2009-11-04 20:15:17 +00:00
|
|
|
/* exit stroke, free data */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->smooth_stroke_cursor)
|
2009-11-04 20:15:17 +00:00
|
|
|
WM_paint_cursor_end(CTX_wm_manager(C), stroke->smooth_stroke_cursor);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->timer)
|
2009-11-04 20:15:17 +00:00
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), stroke->timer);
|
|
|
|
|
|
|
|
stroke->done(C, stroke);
|
|
|
|
MEM_freeN(stroke);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2012-03-28 03:47:33 +00:00
|
|
|
else if ((first) ||
|
2011-12-24 02:37:42 +00:00
|
|
|
(ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) ||
|
|
|
|
(event->type == TIMER && (event->customdata == stroke->timer)) )
|
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->stroke_started) {
|
|
|
|
if (paint_smooth_stroke(stroke, mouse, event)) {
|
|
|
|
if (paint_space_stroke_enabled(stroke->brush)) {
|
|
|
|
if (!paint_space_stroke(C, op, event, mouse)) {
|
2010-04-24 10:08:07 +00:00
|
|
|
//ED_region_tag_redraw(ar);
|
|
|
|
}
|
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 {
|
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
|
|
|
paint_brush_stroke_add_step(C, op, event, mouse);
|
2010-07-14 14:11:03 +00:00
|
|
|
}
|
2009-08-19 21:24:52 +00:00
|
|
|
}
|
2010-08-02 16:27:41 +00:00
|
|
|
else {
|
2012-03-28 03:47:33 +00:00
|
|
|
; //ED_region_tag_redraw(ar);
|
2010-08-02 16:27:41 +00:00
|
|
|
}
|
2009-08-19 21:24:52 +00: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
|
|
|
|
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 */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (first &&
|
2012-03-28 03:47:33 +00:00
|
|
|
stroke->stroke_started &&
|
|
|
|
paint_space_stroke_enabled(stroke->brush) &&
|
|
|
|
!(stroke->brush->flag & BRUSH_ANCHORED) &&
|
|
|
|
!(stroke->brush->flag & BRUSH_SMOOTH_STROKE))
|
2010-07-14 14:11:03 +00:00
|
|
|
{
|
|
|
|
paint_brush_stroke_add_step(C, op, event, mouse);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2011-05-04 03:34:55 +00:00
|
|
|
/* only when executed for the first time */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->stroke_started == 0) {
|
2011-05-04 03:34:55 +00:00
|
|
|
/* XXX stroke->last_mouse_position is unset, this may cause problems */
|
|
|
|
stroke->test_start(C, op, NULL);
|
2012-03-28 03:47:33 +00:00
|
|
|
stroke->stroke_started = 1;
|
2011-05-04 03:34:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:14:16 +00:00
|
|
|
RNA_BEGIN (op->ptr, itemptr, "stroke") {
|
2009-08-20 05:44:32 +00:00
|
|
|
stroke->update_step(C, stroke, &itemptr);
|
|
|
|
}
|
|
|
|
RNA_END;
|
|
|
|
|
2011-05-04 03:34:55 +00:00
|
|
|
stroke->done(C, stroke);
|
|
|
|
|
2009-08-20 05:44:32 +00:00
|
|
|
MEM_freeN(stroke);
|
|
|
|
op->customdata = NULL;
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
int paint_stroke_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
PaintStroke *stroke = op->customdata;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (stroke->done)
|
2011-06-06 11:04:54 +00:00
|
|
|
stroke->done(C, stroke);
|
|
|
|
|
|
|
|
MEM_freeN(stroke);
|
|
|
|
op->customdata = NULL;
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void paint_stroke_set_mode_data(PaintStroke *stroke, void *mode_data)
|
|
|
|
{
|
|
|
|
stroke->mode_data = mode_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int paint_poll(bContext *C)
|
|
|
|
{
|
|
|
|
Paint *p = paint_get_active(CTX_data_scene(C));
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
|
|
|
return p && ob && paint_brush(p) &&
|
2012-03-28 03:47:33 +00:00
|
|
|
CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
|
|
|
|
CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
|
2009-08-20 05:13:07 +00:00
|
|
|
}
|