65 std::optional<RandomNumberGenerator>
rng;
135 if (stroke && brush) {
172 float viewport_size[4];
174 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
290 const float mouse_init[2],
294 bool *r_location_is_set)
298 bool location_sampled =
false;
299 bool location_success =
false;
302 bool is_dry_run =
false;
303 bool do_random =
false;
304 bool do_random_mask =
false;
305 *r_location_is_set =
false;
364 do_random_mask =
true;
394 location_sampled =
true;
395 location_success =
true;
396 *r_location_is_set =
true;
443 if ((do_random || do_random_mask) && !stroke->
rng) {
455 if (do_random_mask) {
462 if (!location_sampled) {
465 location_success =
true;
466 *r_location_is_set =
true;
469 location_success =
true;
474 location_success =
true;
479 return location_success && (is_dry_run ==
false);
506 const float pressure,
508 float r_mouse_out[2])
523 if (factor != 1.0f) {
553 if (tablet && (pressure >= 0.99f) &&
566 if (tablet && (pressure < 0.0002f) &&
580 float world_space_position[3];
596 bool is_location_is_set;
598 C, brush, mode, stroke, mval, mouse_out, pressure, location, &is_location_is_set);
599 if (is_location_is_set) {
607 bool add_step =
true;
661 r_mouse[0] =
sample->mouse[0];
662 r_mouse[1] =
sample->mouse[1];
663 *r_pressure =
sample->pressure;
673 float spacing_pressure)
678 float size_clamp = 0.0f;
682 float last_object_space_position[3];
684 stroke->
vc.
obact->world_to_object().ptr(),
695 size_clamp =
max_ff(1.0f, size);
702 spacing = spacing * (1.5f - spacing_pressure);
720 return max_ff(FLT_EPSILON, size_clamp * spacing / 50.0f);
722 return max_ff(stroke->
zoom_2d, size_clamp * spacing / 50.0f);
731 spacing =
max_ff(spacing, 0.1f);
733 const int n = 100 / spacing;
734 const float h = spacing / 50.0f;
735 const float x0 = x - 1;
738 for (
int i = 0; i < n; i++) {
741 xx =
fabsf(x0 + i * h);
753 float spacing = br.
spacing * factor;
762 for (
int i = 0; i < m; i++) {
788 float q = s * dpressure / (2.0f *
length);
789 float pressure_fac = (1.0f + q) / (1.0f - q);
792 float new_size_pressure = stroke->
last_pressure * pressure_fac;
796 C, scene, stroke, last_size_pressure, pressure);
799 return 0.5f * (last_spacing + new_spacing);
811 const float final_mouse[2],
812 float final_pressure)
823 float d_world_space_position[3] = {0.0f};
833 if (use_scene_spacing) {
834 float world_space_position[3];
839 length =
len_v3(d_world_space_position);
844 zero_v3(d_world_space_position);
852 while (length > 0.0f) {
854 C, scene, stroke, pressure, dpressure, length);
859 if (length >= spacing) {
860 if (use_scene_spacing) {
861 float final_world_space_position[3];
863 mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing);
866 final_world_space_position);
878 spacing / no_pressure_spacing);
909 PaintStroke *stroke = MEM_new<PaintStroke>(__func__);
987 rv3d->
rflag &= ~RV3D_PAINTING;
992 if (stroke ==
nullptr) {
1000 if (stroke->
timer) {
1026 stroke->
redraw(C, stroke,
true);
1030 stroke->
done(C, stroke);
1166#define PAINT_STROKE_MODAL_CANCEL 1
1174 static const char *name =
"Paint Stroke Modal";
1187 PaintStroke *stroke,
int input_samples,
float x,
float y,
float pressure)
1194 sample->pressure = pressure;
1207 memset(average, 0,
sizeof(*average));
1230 float *length_residue,
1231 const float old_pos[2],
1232 const float new_pos[2])
1242 float mouse[2], dmouse[2];
1244 float d_world_space_position[3] = {0.0f};
1245 float world_space_position_old[3], world_space_position_new[3];
1249 if (use_scene_spacing) {
1251 C, world_space_position_old, old_pos, stroke->
original);
1253 C, world_space_position_new, new_pos, stroke->
original);
1254 mul_m4_v3(stroke->
vc.
obact->object_to_world().ptr(), world_space_position_old);
1255 mul_m4_v3(stroke->
vc.
obact->object_to_world().ptr(), world_space_position_new);
1257 sub_v3_v3v3(d_world_space_position, world_space_position_new, world_space_position_old);
1258 length =
len_v3(d_world_space_position);
1263 zero_v3(d_world_space_position);
1277 if (length == 0.0f) {
1281 while (length > 0.0f) {
1282 float spacing_final = spacing - *length_residue;
1283 length += *length_residue;
1284 *length_residue = 0.0;
1286 if (length >= spacing) {
1287 if (use_scene_spacing) {
1288 float final_world_space_position[3];
1290 mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing_final);
1292 final_world_space_position, world_space_position_old, final_world_space_position);
1306 spacing_final = spacing;
1313 *length_residue =
length;
1319 const float mouse[2])
1342 float length_residue = 0.0f;
1356 for (i = 0; i < pc->
tot_points - 1; i++, pcp++) {
1361 bool do_rake =
false;
1363 for (j = 0; j < 2; j++) {
1366 pcp_next->bez.vec[0][j],
1367 pcp_next->bez.vec[1][j],
1377 for (j = 0; j < 2; j++) {
1380 pcp_next->bez.vec[0][j],
1381 pcp_next->bez.vec[1][j],
1390 float rotation =
atan2f(tangents[2 * j + 1], tangents[2 * j]) +
float(0.5f *
M_PI);
1409 C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
1414 C, op, stroke, spacing, &length_residue, data + 2 * j, data + 2 * (j + 1));
1435 angle =
atan2f(line[1], line[0]);
1442 res = angle -
floorf(angle);
1466 bool first_dab =
false;
1467 bool first_modal =
false;
1468 bool redraw =
false;
1496 stroke->
x_tilt =
event->tablet.x_tilt;
1497 stroke->
y_tilt =
event->tablet.y_tilt;
1500#ifdef WITH_INPUT_NDOF
1513 *stroke_p =
nullptr;
1576 *stroke_p =
nullptr;
1583 *stroke_p =
nullptr;
1606 else if (first_modal ||
1652 if (redraw && stroke->
redraw) {
1653 stroke->
redraw(C, stroke,
false);
1721 stroke->
mode_data = std::move(mode_data);
1740 if (area->runtime.tool && area->runtime.tool->runtime &&
1743 return area->runtime.tool;
void BKE_brush_jitter_pos(const Scene &scene, const Brush &brush, const float pos[2], float jitterpos[2])
bool BKE_brush_use_alpha_pressure(const Brush *brush)
void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask)
float BKE_brush_unprojected_radius_get(const Scene *scene, const Brush *brush)
int BKE_brush_size_get(const Scene *scene, const Brush *brush)
float BKE_brush_curve_strength(eBrushCurvePreset preset, const CurveMapping *cumap, float distance, float brush_radius)
bool BKE_brush_use_size_pressure(const Brush *brush)
bool BKE_brush_use_locked_size(const Scene *scene, const Brush *brush)
int BKE_brush_input_samples_get(const Scene *scene, const Brush *brush)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
void BKE_curve_forward_diff_tangent_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
ImBuf * BKE_image_pool_acquire_ibuf(Image *ima, ImageUser *iuser, ImagePool *pool)
void BKE_image_pool_release_ibuf(Image *ima, ImBuf *ibuf, ImagePool *pool)
void BKE_paint_set_overlay_override(enum eOverlayFlags flag)
void paint_update_brush_rake_rotation(UnifiedPaintSettings &ups, const Brush &brush, float rotation)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Paint * BKE_paint_get_active_from_context(const bContext *C)
Brush * BKE_paint_brush(Paint *paint)
bool paint_calculate_rake_rotation(UnifiedPaintSettings &ups, const Brush &brush, const float mouse_pos[2], PaintMode paint_mode, bool stroke_has_started)
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
MINLINE float max_ff(float a, float b)
MINLINE float square_f(float a)
MINLINE float interpf(float target, float origin, float t)
void mul_m4_v3(const float M[4][4], float r[3])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v2_fl2(float v[2], float x, float y)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v2_fl(float r[2], float f)
void interp_v2_v2v2(float r[2], const float a[2], const float b[2], float t)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v2(float n[2])
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
Utility defines for timing/benchmarks.
#define TIMEIT_START_AVERAGED(var)
#define TIMEIT_END_AVERAGED(var)
@ SCULPT_BRUSH_TYPE_THUMB
@ SCULPT_BRUSH_TYPE_BOUNDARY
@ SCULPT_BRUSH_TYPE_CLOTH
@ SCULPT_BRUSH_TYPE_SNAKE_HOOK
@ SCULPT_BRUSH_TYPE_ELASTIC_DEFORM
@ SCULPT_BRUSH_TYPE_ROTATE
@ IMAGE_PAINT_BRUSH_TYPE_FILL
@ IMAGE_PAINT_BRUSH_TYPE_CLONE
@ BRUSH_CLOTH_DEFORM_GRAB
@ CURVES_SCULPT_BRUSH_TYPE_ADD
@ CURVES_SCULPT_BRUSH_TYPE_DENSITY
Object is a sort of wrapper for general info.
#define PAINT_MAX_INPUT_SAMPLES
@ TOOLREF_FLAG_USE_BRUSHES
void ED_view3d_project_v2(const ARegion *region, const float world[3], float r_region_co[2])
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_blend(eGPUBlend blend)
void GPU_line_smooth(bool enable)
void GPU_viewport_size_get_f(float coords[4])
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
#define RNA_BEGIN(sptr, itemptr, propname)
static T sum(const btAlignedObjectArray< T > &items)
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
static RandomNumberGenerator from_random_seed()
const Depsgraph * depsgraph
draw_view in_light_buf[] float
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
ccl_device_inline float2 fabs(const float2 a)
bool is_cloth_deform_brush(const Brush &brush)
static void paint_stroke_add_sample(PaintStroke *stroke, int input_samples, float x, float y, float pressure)
int paint_stroke_exec(bContext *C, wmOperator *op, PaintStroke *stroke)
static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, PaintStroke *stroke, const float mval[2], float pressure)
static void paint_stroke_line_constrain(PaintStroke *stroke, float mouse[2])
bool paint_supports_texture(PaintMode mode)
static const bToolRef * brush_tool_get(const bContext *C)
void(*)(const bContext *C, PaintStroke *stroke, bool final) StrokeRedraw
static bool paint_smooth_stroke(PaintStroke *stroke, const PaintSample *sample, PaintMode mode, float r_mouse[2], float *r_pressure)
bool paint_stroke_started(PaintStroke *stroke)
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])
static bool sculpt_is_grab_tool(const Brush &br)
void paint_stroke_jitter_pos(Scene &scene, const PaintStroke &stroke, const PaintMode mode, const Brush &brush, const float pressure, const float mval[2], float r_mouse_out[2])
void paint_stroke_cancel(bContext *C, wmOperator *op, PaintStroke *stroke)
bool paint_supports_dynamic_tex_coords(const Brush &br, PaintMode mode)
bool paint_supports_dynamic_size(const Brush &br, PaintMode mode)
static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
void(*)(bContext *C, wmOperator *op, PaintStroke *stroke, PointerRNA *itemptr) StrokeUpdateStep
static float paint_stroke_integrate_overlap(const Brush &br, float factor)
static void stroke_done(const bContext *C, PaintStroke *stroke)
static bool paint_stroke_curve_end(bContext *C, wmOperator *op, PaintStroke *stroke)
bool paint_stroke_flipped(PaintStroke *stroke)
static void paint_stroke_sample_average(const PaintStroke *stroke, PaintSample *average)
static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata)
static float paint_space_stroke_spacing_variable(bContext *C, const Scene *scene, PaintStroke *stroke, float pressure, float dpressure, float length)
static void paint_stroke_line_end(bContext *C, wmOperator *op, PaintStroke *stroke, const float mouse[2])
static int paint_space_stroke(bContext *C, wmOperator *op, PaintStroke *stroke, const float final_mouse[2], float final_pressure)
static bool paint_stroke_use_jitter(PaintMode mode, const Brush &brush, bool invert)
static bool paint_stroke_use_dash(const Brush &brush)
ViewContext * paint_stroke_view_context(PaintStroke *stroke)
bool paint_brush_cursor_poll(bContext *C)
static bool image_paint_brush_type_require_inbetween_mouse_events(const Brush &brush, const PaintMode mode)
int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event, PaintStroke **stroke_p)
bool(*)(bContext *C, float location[3], const float mouse[2], bool force_original) StrokeGetLocation
static bool image_paint_brush_type_require_location(const Brush &brush, const PaintMode mode)
static bool curves_sculpt_brush_uses_spacing(const eBrushCurvesSculptType tool)
wmKeyMap * paint_stroke_modal_keymap(wmKeyConfig *keyconf)
bool(*)(bContext *C, wmOperator *op, const float mouse[2]) StrokeTestStart
bool paint_brush_update(bContext *C, const Brush &brush, PaintMode mode, PaintStroke *stroke, const float mouse_init[2], float mouse[2], float pressure, float r_location[3], bool *r_location_is_set)
void * paint_stroke_mode_data(PaintStroke *stroke)
float paint_stroke_distance_get(PaintStroke *stroke)
bool paint_space_stroke_enabled(const Brush &br, PaintMode mode)
void paint_stroke_free(bContext *C, wmOperator *op, PaintStroke *stroke)
PaintStroke * paint_stroke_new(bContext *C, wmOperator *op, StrokeGetLocation get_location, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeRedraw redraw, StrokeDone done, int event_type)
static bool paint_stroke_use_scene_spacing(const Brush &brush, const PaintMode mode)
static float paint_space_stroke_spacing(bContext *C, const Scene *scene, PaintStroke *stroke, float size_pressure, float spacing_pressure)
static float paint_stroke_overlapped_curve(const Brush &br, float x, float spacing)
void(*)(const bContext *C, PaintStroke *stroke) StrokeDone
static bool image_paint_brush_type_raycast_original(const Brush &brush, PaintMode)
bool paint_stroke_inverted(PaintStroke *stroke)
bool paint_brush_tool_poll(bContext *C)
void paint_stroke_set_mode_data(PaintStroke *stroke, std::unique_ptr< PaintModeData > mode_data)
bool paint_supports_smooth_stroke(PaintStroke *stroke, const Brush &br, PaintMode mode)
bool get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy)
float paint_calc_object_space_radius(const ViewContext &vc, const blender::float3 ¢er, float pixel_radius)
#define PAINT_CURVE_NUM_SEGMENTS
#define PAINT_STROKE_MODAL_CANCEL
void RNA_collection_clear(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
int RNA_enum_get(PointerRNA *ptr, const char *name)
bool SCULPT_stroke_get_location(bContext *C, float out[3], const float mval[2], bool force_original)
float smooth_stroke_factor
struct CurveMapping * curve
char curves_sculpt_brush_type
struct PaintCurve * paint_curve
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
unsigned char paint_cursor_col[4]
struct CurveMapping * cavity_curve
float average_stroke_accum[3]
char do_linear_conversion
float anchored_initial_mouse[2]
float initial_pixel_radius
int average_stroke_counter
float size_pressure_value
struct ColorSpace * colorspace
float cached_size_pressure
UnifiedPaintSettings * ups
StrokeUpdateStep update_step
std::unique_ptr< PaintModeData > mode_data
StrokeGetLocation get_location
StrokeTestStart test_start
float3 last_world_space_position
float last_tablet_event_pressure
float3 last_scene_spacing_delta
std::optional< RandomNumberGenerator > rng
PaintSample samples[PAINT_MAX_INPUT_SAMPLES]
float2 last_mouse_position
void(* cancel)(bContext *C, wmOperator *op)
struct wmOperatorType * type
void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *)
float WM_event_tablet_data(const wmEvent *event, bool *r_pen_flip, float r_tilt[2])
bool WM_event_is_tablet(const wmEvent *event)
#define ISMOUSE_MOTION(event_type)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
bool WM_paint_cursor_end(wmPaintCursor *handle)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, bool(*poll)(bContext *C), wmPaintCursorDraw draw, void *customdata)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const int event_type, const double time_step)