65 std::optional<RandomNumberGenerator>
rng;
140 if (stroke && brush) {
177 float viewport_size[4];
179 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
182 const float alpha =
float(
paint->paint_cursor_col[3]) / 255.0f;
295 const float mouse_init[2],
299 bool *r_location_is_set)
303 bool location_sampled =
false;
304 bool location_success =
false;
307 bool is_dry_run =
false;
308 bool do_random =
false;
309 bool do_random_mask =
false;
310 *r_location_is_set =
false;
369 do_random_mask =
true;
399 location_sampled =
true;
400 location_success =
true;
401 *r_location_is_set =
true;
448 if ((do_random || do_random_mask) && !stroke->
rng) {
460 if (do_random_mask) {
467 if (!location_sampled) {
470 location_success =
true;
471 *r_location_is_set =
true;
474 location_success =
true;
479 location_success =
true;
484 return location_success && (is_dry_run ==
false);
511 const float pressure,
513 float r_mouse_out[2])
528 if (factor != 1.0f) {
558 if (tablet && (pressure >= 0.99f) &&
571 if (tablet && (pressure < 0.0002f) &&
585 float world_space_position[3];
601 bool is_location_is_set;
603 C, brush, mode, stroke, mval, mouse_out, pressure, location, &is_location_is_set);
604 if (is_location_is_set) {
612 bool add_step =
true;
666 r_mouse[0] =
sample->mouse[0];
667 r_mouse[1] =
sample->mouse[1];
668 *r_pressure =
sample->pressure;
678 float spacing_pressure)
683 float size_clamp = 0.0f;
687 float last_object_space_position[3];
689 stroke->
vc.
obact->world_to_object().ptr(),
707 spacing = spacing * (1.5f - spacing_pressure);
725 return max_ff(FLT_EPSILON, size_clamp * spacing / 50.0f);
727 return max_ff(stroke->
zoom_2d, size_clamp * spacing / 50.0f);
736 spacing =
max_ff(spacing, 0.1f);
738 const int n = 100 / spacing;
739 const float h = spacing / 50.0f;
740 const float x0 =
x - 1;
743 for (
int i = 0; i < n; i++) {
746 xx =
fabsf(x0 + i * h);
758 float spacing = br.
spacing * factor;
767 for (
int i = 0; i < m; i++) {
793 float q = s * dpressure / (2.0f *
length);
794 float pressure_fac = (1.0f + q) / (1.0f - q);
797 float new_size_pressure = stroke->
last_pressure * pressure_fac;
801 C, scene, stroke, last_size_pressure, pressure);
804 return 0.5f * (last_spacing + new_spacing);
816 const float final_mouse[2],
817 float final_pressure)
828 float d_world_space_position[3] = {0.0f};
838 if (use_scene_spacing) {
839 float world_space_position[3];
849 zero_v3(d_world_space_position);
859 C, scene, stroke, pressure, dpressure,
length);
865 if (use_scene_spacing) {
866 float final_world_space_position[3];
868 mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing);
871 final_world_space_position);
883 spacing / no_pressure_spacing);
914 PaintStroke *stroke = MEM_new<PaintStroke>(__func__);
997 if (stroke ==
nullptr) {
1005 if (stroke->
timer) {
1031 stroke->
redraw(
C, stroke,
true);
1035 stroke->
done(
C, stroke);
1171#define PAINT_STROKE_MODAL_CANCEL 1
1179 static const char *name =
"Paint Stroke Modal";
1192 PaintStroke *stroke,
int input_samples,
float x,
float y,
float pressure)
1199 sample->pressure = pressure;
1235 float *length_residue,
1236 const float old_pos[2],
1237 const float new_pos[2])
1247 float mouse[2], dmouse[2];
1249 float d_world_space_position[3] = {0.0f};
1250 float world_space_position_old[3], world_space_position_new[3];
1254 if (use_scene_spacing) {
1256 C, world_space_position_old, old_pos, stroke->
original);
1258 C, world_space_position_new, new_pos, stroke->
original);
1259 mul_m4_v3(stroke->
vc.
obact->object_to_world().ptr(), world_space_position_old);
1260 mul_m4_v3(stroke->
vc.
obact->object_to_world().ptr(), world_space_position_new);
1262 sub_v3_v3v3(d_world_space_position, world_space_position_new, world_space_position_old);
1268 zero_v3(d_world_space_position);
1287 float spacing_final = spacing - *length_residue;
1288 length += *length_residue;
1289 *length_residue = 0.0;
1292 if (use_scene_spacing) {
1293 float final_world_space_position[3];
1295 mul_v3_v3fl(final_world_space_position, d_world_space_position, spacing_final);
1297 final_world_space_position, world_space_position_old, final_world_space_position);
1311 spacing_final = spacing;
1318 *length_residue =
length;
1324 const float mouse[2])
1347 float length_residue = 0.0f;
1361 for (i = 0; i < pc->
tot_points - 1; i++, pcp++) {
1366 bool do_rake =
false;
1368 for (j = 0; j < 2; j++) {
1371 pcp_next->bez.vec[0][j],
1372 pcp_next->bez.vec[1][j],
1382 for (j = 0; j < 2; j++) {
1385 pcp_next->bez.vec[0][j],
1386 pcp_next->bez.vec[1][j],
1395 float rotation =
atan2f(tangents[2 * j + 1], tangents[2 * j]) +
float(0.5f *
M_PI);
1414 C, op, stroke, spacing, &length_residue,
data + 2 * j,
data + 2 * (j + 1));
1419 C, op, stroke, spacing, &length_residue,
data + 2 * j,
data + 2 * (j + 1));
1471 bool first_dab =
false;
1472 bool first_modal =
false;
1473 bool redraw =
false;
1501 stroke->
x_tilt =
event->tablet.x_tilt;
1502 stroke->
y_tilt =
event->tablet.y_tilt;
1505#ifdef WITH_INPUT_NDOF
1518 *stroke_p =
nullptr;
1581 *stroke_p =
nullptr;
1588 *stroke_p =
nullptr;
1611 else if (first_modal ||
1657 if (redraw && stroke->
redraw) {
1658 stroke->
redraw(
C, stroke,
false);
1726 stroke->
mode_data = std::move(mode_data);
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)
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
static T sum(const btAlignedObjectArray< T > &items)
static RandomNumberGenerator from_random_seed()
draw_view in_light_buf[] float
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
ccl_device_inline float average(const float2 a)
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)
VecBase< float, 2 > float2
VecBase< float, 3 > float3
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
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)