Blender V5.3
mesh/paint_cursor.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "DNA_mesh_types.h"
12
13#include "BKE_brush.hh"
14#include "BKE_object.hh"
15#include "BKE_object_types.hh"
16#include "BKE_paint.hh"
17#include "BKE_paint_types.hh"
18
20#include "BLI_math_matrix.hh"
21#include "BLI_math_matrix_c.hh"
22#include "BLI_math_vector_c.hh"
23
24#include "ED_view3d.hh"
25
26#include "GPU_immediate.hh"
27#include "GPU_matrix.hh"
28#include "GPU_state.hh"
29
30#include "PRF_profile.hh"
31
32#include "WM_api.hh"
33
34#include "sculpt_boundary.hh"
35#include "sculpt_cloth.hh"
36#include "sculpt_expand.hh"
37#include "sculpt_intern.hh"
38#include "sculpt_pose.hh"
39
40#include "brushes/brushes.hh"
41
43
44#include "bmesh.hh"
45
47static int brush_radius_project(ViewContext *vc, float radius, const float location[3])
48{
49 float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
50
51 ED_view3d_global_to_vector(vc->rv3d, location, view);
52
53 /* Create a vector that is not orthogonal to view. */
54
55 if (fabsf(view[0]) < 0.1f) {
56 nonortho[0] = view[0] + 1.0f;
57 nonortho[1] = view[1];
58 nonortho[2] = view[2];
59 }
60 else if (fabsf(view[1]) < 0.1f) {
61 nonortho[0] = view[0];
62 nonortho[1] = view[1] + 1.0f;
63 nonortho[2] = view[2];
64 }
65 else {
66 nonortho[0] = view[0];
67 nonortho[1] = view[1];
68 nonortho[2] = view[2] + 1.0f;
69 }
70
71 /* Get a vector in the plane of the view. */
72 cross_v3_v3v3(ortho, nonortho, view);
73 normalize_v3(ortho);
74
75 /* Make a point on the surface of the brush tangent to the view. */
76 mul_v3_fl(ortho, radius);
77 add_v3_v3v3(offset, location, ortho);
78
79 /* Project the center of the brush, and the tangent point to the view onto the screen. */
84 {
85 /* The distance between these points is the size of the projected brush in pixels. */
86 return len_v2v2(p1, p2);
87 }
88 /* Assert because the code that sets up the vectors should disallow this. */
89 BLI_assert(0);
90 return 0;
91}
92
94{
95 if (pcontext.is_cursor_over_mesh) {
97 &pcontext.vc,
99 pcontext.location);
100
101 if (pcontext.pixel_radius == 0) {
102 pcontext.pixel_radius = BKE_brush_radius_get(pcontext.paint, pcontext.brush);
103 }
104
105 pcontext.scene_space_location = math::transform_point(pcontext.vc.obact->object_to_world(),
106 pcontext.location);
107 }
108 else {
109 pcontext.pixel_radius = BKE_brush_radius_get(pcontext.paint, pcontext.brush);
110 }
111}
112
113/* Special actions taken when paint cursor goes over mesh */
114/* TODO: We should not be updating data as part of the drawing callbacks. */
116 Brush &brush,
117 const ViewContext &vc,
118 const float location[3])
119{
120 const bke::PaintRuntime &paint_runtime = *paint.runtime;
121 /* Update the brush's cached 3D radius. */
123 float projected_radius;
124 /* Get 2D brush radius. */
125 if (paint_runtime.draw_anchored) {
126 projected_radius = paint_runtime.anchored_size;
127 }
128 else {
129 if (brush.stroke_method == BRUSH_STROKE_ANCHORED) {
130 projected_radius = 8;
131 }
132 else {
133 projected_radius = BKE_brush_radius_get(&paint, &brush);
134 }
135 }
136
137 /* Convert brush radius from 2D to 3D. */
138 float unprojected_radius = paint_calc_object_space_radius(vc, location, projected_radius);
139
140 /* Scale 3D brush radius by pressure. */
141 if (paint_runtime.stroke_active && BKE_brush_use_size_pressure(&brush)) {
142 unprojected_radius *= paint_runtime.size_pressure_value;
143 }
144
145 /* Set cached value in either Brush or UnifiedPaintSettings. */
146 BKE_brush_unprojected_size_set(&paint, &brush, unprojected_radius * 2.0f);
147 }
148}
149
151{
153 BLI_assert(pcontext.ss != nullptr);
154
155 SculptSession &ss = *pcontext.ss;
156 Brush &brush = *pcontext.brush;
157 bke::PaintRuntime &paint_runtime = *pcontext.paint->runtime;
158 ViewContext &vc = pcontext.vc;
159
160 const float2 mval_fl = {
161 float(pcontext.mval.x - pcontext.region->winrct.xmin),
162 float(pcontext.mval.y - pcontext.region->winrct.ymin),
163 };
164
165 /* Ensure that the PBVH is generated before we call #cursor_geometry_info_update because
166 * the PBVH is needed to do a ray-cast to find the active vertex. */
167 bke::object::pbvh_ensure(*pcontext.depsgraph, *pcontext.vc.obact);
168
169 /* This updates the active vertex, which is needed for most of the Sculpt/Vertex Colors tools to
170 * work correctly */
173 if (!paint_runtime.stroke_active) {
174 const std::optional<CursorGeometryInfo> gi = cursor_geometry_info_update(
175 *pcontext.depsgraph,
176 *pcontext.paint,
177 pcontext.sd,
178 pcontext.vc,
179 pcontext.base,
180 mval_fl,
182
183 pcontext.is_cursor_over_mesh = gi.has_value();
184 const CursorGeometryInfo info = gi.value_or(CursorGeometryInfo{});
185 pcontext.location = info.location;
186 pcontext.normal = info.normal;
187 }
188 else {
189 pcontext.is_cursor_over_mesh = paint_runtime.last_hit;
190 pcontext.location = paint_runtime.last_location;
191 }
192
194 pixel_radius_update(pcontext);
195
196 if (BKE_brush_use_locked_size(pcontext.paint, &brush)) {
197 BKE_brush_size_set(pcontext.paint, &brush, pcontext.pixel_radius * 2.0f);
198 }
199
200 if (pcontext.is_cursor_over_mesh) {
202 }
203 }
204}
205
206static void geometry_preview_lines_draw(const Depsgraph &depsgraph,
207 const uint gpuattr,
208 const Brush &brush,
209 const Object &object)
210{
211 if (!(brush.flag & BRUSH_GRAB_ACTIVE_VERTEX)) {
212 return;
213 }
214
215 const SculptSession &ss = *object.runtime->sculpt_session;
216 if (bke::object::pbvh_get(object)->type() != bke::pbvh::Type::Mesh) {
217 return;
218 }
219
220 if (!ss.deform_modifiers_active) {
221 return;
222 }
223
224 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.6f);
225
226 /* Cursor normally draws on top, but for this part we need depth tests. */
227 const GPUDepthTest depth_test = GPU_depth_test_get();
228 if (!depth_test) {
230 }
231
232 GPU_line_width(1.0f);
233 if (!ss.preview_verts.is_empty()) {
234 const Span<float3> positions = vert_positions_for_grab_active_get(depsgraph, object);
236 for (const int vert : ss.preview_verts) {
237 immVertex3fv(gpuattr, positions[vert]);
238 }
239 immEnd();
240 }
241
242 /* Restore depth test value. */
243 if (!depth_test) {
245 }
246}
247
249{
251 BLI_assert(pcontext.ss != nullptr);
252
253 SculptSession &ss = *pcontext.ss;
254 Brush &brush = *pcontext.brush;
255
256 /* Only Sculpt Mode currently has active brush overlays. */
257 if (pcontext.mode != PaintMode::Sculpt) {
258 return;
259 }
260
261 /* The cursor can be marked as active before creating the StrokeCache. */
262 if (!ss.cache) {
263 return;
264 }
265
266 /* Most of the brushes initialize the necessary data for the custom cursor drawing after the
267 * first brush step. */
269 return;
270 }
271
272 /* Setup drawing. */
273 wmViewport(&pcontext.region->winrct);
276 pcontext.win,
277 pcontext.depsgraph,
278 pcontext.scene,
279 pcontext.region,
280 pcontext.vc.v3d,
281 nullptr,
282 nullptr,
283 nullptr);
285 GPU_matrix_mul(pcontext.vc.obact->object_to_world().ptr());
286
287 switch (brush.sculpt_brush_type) {
289 geometry_preview_lines_draw(*pcontext.depsgraph, pcontext.pos, brush, *pcontext.vc.obact);
290 break;
293 pcontext.pos, brush, ss, pcontext.outline_col, pcontext.outline_alpha);
294 break;
296 if (brush.cloth_force_falloff_type == BRUSH_CLOTH_FORCE_FALLOFF_PLANE) {
297 /* By definition, the 'Plane Falloff' mode does not have drawable limits. */
299 pcontext.pos, brush, ss, pcontext.outline_col, pcontext.outline_alpha);
300 }
301 else if (brush.cloth_force_falloff_type == BRUSH_CLOTH_FORCE_FALLOFF_RADIAL &&
302 brush.cloth_simulation_area_type == BRUSH_CLOTH_SIMULATION_AREA_LOCAL)
303 {
304 /* Display the simulation limits if sculpting outside them. */
306 ss.cache->radius * (1.0f + brush.cloth_sim_limit))
307 {
308 const float3 red = {1.0f, 0.2f, 0.2f};
310 brush,
313 ss.cache->radius,
314 2.0f,
315 red,
316 0.8f);
317 }
318 }
319 break;
320 }
321 default:
322 break;
323 }
324
326
328 wmWindowViewport(pcontext.win);
329}
330
331static void screen_space_point_draw(const uint gpuattr,
332 const ARegion *region,
333 const float true_location[3],
334 const float obmat[4][4],
335 const int size)
336{
337 float translation_vertex_cursor[3], location[3];
338 copy_v3_v3(location, true_location);
339 mul_m4_v3(obmat, location);
340 ED_view3d_project_v3(region, location, translation_vertex_cursor);
341 /* Do not draw points behind the view. Z [near, far] is mapped to [-1, 1]. */
342 if (translation_vertex_cursor[2] <= 1.0f) {
344 gpuattr, translation_vertex_cursor[0], translation_vertex_cursor[1], size, 10);
345 }
346}
347
348static void tiling_preview_draw(const uint gpuattr,
349 const ARegion *region,
350 const float true_location[3],
351 const Paint &paint,
352 const Object &ob,
353 const float radius)
354{
355 BLI_assert(ob.type == OB_MESH);
357 if (!mesh) {
358 mesh = id_cast<const Mesh *>(ob.data);
359 }
360 const Bounds<float3> bounds = *mesh->bounds_min_max();
361 float orgLoc[3], location[3];
362 int tile_pass = 0;
363 int start[3];
364 int end[3];
365 int cur[3];
366 const float *step = paint.tile_offset;
367
368 copy_v3_v3(orgLoc, true_location);
369 for (int dim = 0; dim < 3; dim++) {
370 if ((paint.symmetry_flags & (PAINT_TILE_X << dim)) && step[dim] > 0) {
371 start[dim] = (bounds.min[dim] - orgLoc[dim] - radius) / step[dim];
372 end[dim] = (bounds.max[dim] - orgLoc[dim] + radius) / step[dim];
373 }
374 else {
375 start[dim] = end[dim] = 0;
376 }
377 }
378 copy_v3_v3_int(cur, start);
379 for (cur[0] = start[0]; cur[0] <= end[0]; cur[0]++) {
380 for (cur[1] = start[1]; cur[1] <= end[1]; cur[1]++) {
381 for (cur[2] = start[2]; cur[2] <= end[2]; cur[2]++) {
382 if (!cur[0] && !cur[1] && !cur[2]) {
383 /* Skip tile at orgLoc, this was already handled before all others. */
384 continue;
385 }
386 tile_pass++;
387 for (int dim = 0; dim < 3; dim++) {
388 location[dim] = cur[dim] * step[dim] + orgLoc[dim];
389 }
390 screen_space_point_draw(gpuattr, region, location, ob.object_to_world().ptr(), 3);
391 }
392 }
393 }
394 (void)tile_pass; /* Quiet set-but-unused warning (may be removed). */
395}
396
397static void point_with_symmetry_draw(const PaintMode paint_mode,
398 const Brush &brush,
399 const uint gpuattr,
400 const ARegion *region,
401 const float true_location[3],
402 const Paint &paint,
403 const Object &ob,
404 const float radius)
405{
406 const Mesh *mesh = id_cast<const Mesh *>(ob.data);
407 const char symm = mesh_symmetry_xyz_get(ob);
408 float3 location;
409 float symm_rot_mat[4][4];
410
411 for (int i = 0; i <= symm; i++) {
412 if (is_symmetry_iteration_valid(i, symm)) {
413
414 /* Axis Symmetry. */
415 location = symmetry_flip(true_location, ePaintSymmetryFlags(i));
416 screen_space_point_draw(gpuattr, region, location, ob.object_to_world().ptr(), 3);
417
418 /* Tiling. */
420 tiling_preview_draw(gpuattr, region, location, paint, ob, radius);
421 }
422
423 /* Radial Symmetry. */
424 for (char raxis = 0; raxis < 3; raxis++) {
425 for (int r = 1; r < mesh->radial_symmetry[raxis]; r++) {
426 float angle = 2 * M_PI * r / mesh->radial_symmetry[int(raxis)];
427 location = symmetry_flip(true_location, ePaintSymmetryFlags(i));
428 unit_m4(symm_rot_mat);
429 rotate_m4(symm_rot_mat, raxis + 'X', angle);
430 mul_m4_v3(symm_rot_mat, location);
431
433 tiling_preview_draw(gpuattr, region, location, paint, ob, radius);
434 }
435 screen_space_point_draw(gpuattr, region, location, ob.object_to_world().ptr(), 3);
436 }
437 }
438 }
439 }
440}
441
443{
444 const bool has_cube_tip = BKE_brush_has_cube_tip(pcontext.brush, pcontext.mode);
445 const float roundness = has_cube_tip ? pcontext.brush->tip_roundness : 1.0f;
446 const float tip_scale_x = has_cube_tip ? pcontext.brush->tip_scale_x : 1.0f;
447 const float alpha = std::clamp(BKE_brush_alpha_get(pcontext.paint, pcontext.brush), 0.0f, 1.0f);
448
449 GPU_line_width(1.0f);
450 /* Reduce alpha to increase the contrast when the cursor is over the mesh. */
451 immUniformColor3fvAlpha(pcontext.outline_col, pcontext.outline_alpha * 0.8);
453 pcontext.pos,
454 pcontext.translation[0],
455 pcontext.translation[1],
456 float2(pcontext.final_radius, pcontext.final_radius * tip_scale_x),
457 float2(pcontext.final_radius * roundness, pcontext.final_radius * roundness * tip_scale_x),
458 80);
459 immUniformColor3fvAlpha(pcontext.outline_col, pcontext.outline_alpha * 0.35f);
461 pcontext.pos,
462 pcontext.translation[0],
463 pcontext.translation[1],
464 float2(pcontext.final_radius * alpha, pcontext.final_radius * alpha * tip_scale_x),
465 float2(pcontext.final_radius * alpha * roundness,
466 pcontext.final_radius * alpha * roundness * tip_scale_x),
467 80);
468}
469
471{
473 pcontext.vc, *pcontext.paint, *pcontext.brush, pcontext.location);
474}
475
477{
478 SculptSession &ss = *pcontext.ss;
479 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.8f);
480 GPU_line_width(2.0f);
481
482 BLI_assert(ss.pose_ik_chain_preview->initial_head_coords.size() ==
483 ss.pose_ik_chain_preview->initial_orig_coords.size());
484
485 immBegin(GPU_PRIM_LINES, ss.pose_ik_chain_preview->initial_head_coords.size() * 2);
486 for (const int i : ss.pose_ik_chain_preview->initial_head_coords.index_range()) {
487 immVertex3fv(pcontext.pos, ss.pose_ik_chain_preview->initial_orig_coords[i]);
488 immVertex3fv(pcontext.pos, ss.pose_ik_chain_preview->initial_head_coords[i]);
489 }
490
491 immEnd();
492}
493
494static void pose_brush_origins_draw(const PaintCursorContext &pcontext)
495{
496
497 SculptSession &ss = *pcontext.ss;
498 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.8f);
499 for (const int i : ss.pose_ik_chain_preview->initial_orig_coords.index_range()) {
501 pcontext.region,
502 ss.pose_ik_chain_preview->initial_orig_coords[i],
503 pcontext.vc.obact->object_to_world().ptr(),
504 3);
505 }
506}
507
509{
510 if (!pcontext.ss->boundary_preview) {
511 /* There is no guarantee that a boundary preview exists as there may be no boundaries
512 * inside the brush radius. */
513 return;
514 }
515 immUniformColor4f(1.0f, 1.0f, 1.0f, 0.8f);
517 pcontext.region,
518 pcontext.ss->boundary_preview->pivot_position,
519 pcontext.vc.obact->object_to_world().ptr(),
520 3);
521}
522
523static void boundary_preview_update(const PaintCursorContext &pcontext)
524{
525 SculptSession &ss = *pcontext.ss;
526 /* Needed for updating the necessary SculptSession data in order to initialize the
527 * boundary data for the preview. */
528 BKE_sculptsession_update_for_edit(pcontext.depsgraph, pcontext.vc.obact, false);
529
531 *pcontext.depsgraph, *pcontext.vc.obact, pcontext.brush, pcontext.radius);
532}
533
535{
536 Object &active_object = *pcontext.vc.obact;
537
538 if (pcontext.mode != PaintMode::Sculpt) {
539 return pcontext.ss->active_vert_position(*pcontext.depsgraph, active_object);
540 }
541
542 const Brush &brush = *pcontext.brush;
543 const SculptSession &ss = *pcontext.ss;
544
545 if (brush.sculpt_brush_type == SCULPT_BRUSH_TYPE_GRAB && brush.flag & BRUSH_GRAB_ACTIVE_VERTEX &&
546 bke::object::pbvh_get(active_object)->type() == bke::pbvh::Type::Mesh)
547 {
549 active_object);
550 return positions[std::get<int>(ss.active_vert())];
551 }
552
553 return pcontext.ss->active_vert_position(*pcontext.depsgraph, active_object);
554}
555
557{
558 const Brush &brush = *pcontext.brush;
559 Object &active_object = *pcontext.vc.obact;
560
561 const float3 active_vertex_co = get_active_vertex_position(pcontext);
562
563 /* Cursor location symmetry points. */
564 if (math::distance(active_vertex_co, pcontext.location) < pcontext.radius) {
567 brush,
568 pcontext.pos,
569 pcontext.region,
570 active_vertex_co,
571 *pcontext.paint,
572 active_object,
573 pcontext.radius);
574 }
575
576 if (pcontext.mode != PaintMode::Sculpt) {
577 return;
578 }
579
580 /* Expand operation origin. */
581 if (pcontext.ss->expand_cache) {
582 const int vert = pcontext.ss->expand_cache->initial_active_vert;
583
585 switch (bke::object::pbvh_get(active_object)->type()) {
587 const Span<float3> positions = bke::pbvh::vert_positions_eval(*pcontext.depsgraph,
588 active_object);
589 position = positions[vert];
590 break;
591 }
593 const SubdivCCG &subdiv_ccg = *pcontext.ss->subdiv_ccg;
594 position = subdiv_ccg.positions[vert];
595 break;
596 }
598 BMesh &bm = *pcontext.ss->bm;
599 position = BM_vert_at_index(&bm, vert)->co;
600 break;
601 }
602 }
604 pcontext.pos, pcontext.region, position, active_object.object_to_world().ptr(), 2);
605 }
606
607 if (!pcontext.is_brush_active) {
608 return;
609 }
610
611 switch (brush.sculpt_brush_type) {
613 /* Pose brush updates and rotation origins. */
614 /* Just after switching to the Pose Brush, the active vertex can be the same and the
615 * cursor won't be tagged to update, so always initialize the preview chain if it is
616 * nullptr before drawing it. */
617 SculptSession &ss = *pcontext.ss;
618 const bool update_previews = pcontext.prev_active_vert_index !=
619 pcontext.ss->active_vert_index();
620 if (update_previews || !ss.pose_ik_chain_preview) {
621 BKE_sculptsession_update_for_edit(pcontext.depsgraph, &active_object, false);
622
623 /* Free the previous pose brush preview. */
624 if (ss.pose_ik_chain_preview) {
625 ss.pose_ik_chain_preview.reset();
626 }
627
628 /* Generate a new pose brush preview from the current cursor location. */
630 *pcontext.depsgraph, active_object, ss, brush, pcontext.location, pcontext.radius);
631 }
632
633 /* Draw the pose brush rotation origins. */
634 pose_brush_origins_draw(pcontext);
635 break;
636 }
638 boundary_preview_update(pcontext);
640 break;
641 default:
642 break;
643 }
644}
645
647{
648 if (pcontext.mode != PaintMode::Sculpt) {
649 return;
650 }
651
652 if (!pcontext.is_brush_active) {
653 return;
654 }
655
656 const Brush &brush = *pcontext.brush;
657 const Object &active_object = *pcontext.vc.obact;
658
659 switch (brush.sculpt_brush_type) {
661 if (brush.flag & BRUSH_GRAB_ACTIVE_VERTEX) {
663 *pcontext.depsgraph, *pcontext.vc.obact, *pcontext.ss, pcontext.radius);
665 *pcontext.depsgraph, pcontext.pos, *pcontext.brush, active_object);
666 }
667 break;
669 pose_brush_segments_draw(pcontext);
670 break;
673 pcontext.pos, *pcontext.ss, pcontext.outline_col, pcontext.outline_alpha);
674 boundary::pivot_line_preview_draw(pcontext.pos, *pcontext.ss);
675 break;
676 default:
677 break;
678 }
679}
680
682{
683 const float3 normal = bke::brush::supports_tilt(*pcontext.brush) ?
684 tilt_apply_to_normal(*pcontext.vc.obact,
685 float4x4(pcontext.vc.rv3d->viewinv),
686 pcontext.normal,
687 pcontext.tilt,
688 pcontext.brush->tilt_strength_factor) :
689 pcontext.normal;
690
691 if (BKE_brush_has_cube_tip(pcontext.brush, pcontext.mode)) {
692 float local_mat[4][4];
693 float local_mat_inv[4][4];
694
695 /* TODO: For brushes that does not support rake, we should allow users to set a starting
696 * rotation. Should be implemented after moving Rake and Rotation settings from the texture
697 * datablock. */
698 const float tip_rotation = pcontext.paint->runtime->brush_rotation;
699 const float3 motion_normal = calc_motion_normal_from_angle(
700 pcontext.vc, pcontext.location, tip_rotation);
701 calc_brush_local_mat(normal, motion_normal, pcontext.location, 1.0f, local_mat, local_mat_inv);
702
703 GPU_matrix_mul(pcontext.vc.obact->object_to_world().ptr());
704 GPU_matrix_mul(local_mat_inv);
705 return;
706 }
707
708 const float4x4 cursor_trans = math::translate(pcontext.vc.obact->object_to_world(),
709 pcontext.location);
710
711 const float3 z_axis = {0.0f, 0.0f, 1.0f};
712
713 const math::AxisAngle between_vecs(z_axis, normal);
714 const float4x4 cursor_rot = math::from_rotation<float4x4>(between_vecs);
715
716 GPU_matrix_mul(cursor_trans.ptr());
717 GPU_matrix_mul(cursor_rot.ptr());
718}
719
721{
722 bool has_cube_tip = BKE_brush_has_cube_tip(pcontext.brush, pcontext.mode);
723 const float roundness = has_cube_tip ? pcontext.brush->tip_roundness : 1.0f;
724 const float tip_scale_x = has_cube_tip ? pcontext.brush->tip_scale_x : 1.0f;
725 const float alpha = std::clamp(BKE_brush_alpha_get(pcontext.paint, pcontext.brush), 0.0f, 1.0f);
726
728 GPU_line_width(2.0f);
729
731 pcontext.pos,
732 0,
733 0,
734 float2(pcontext.radius, pcontext.radius * tip_scale_x),
735 float2(pcontext.radius * roundness, pcontext.radius * roundness * tip_scale_x),
736 80);
737
738 GPU_line_width(1.0f);
739 immUniformColor3fvAlpha(pcontext.outline_col, pcontext.outline_alpha * 0.5f);
741 pcontext.pos,
742 0,
743 0,
744 float2(pcontext.radius * alpha, pcontext.radius * alpha * tip_scale_x),
745 float2(pcontext.radius * alpha * roundness,
746 pcontext.radius * alpha * roundness * tip_scale_x),
747 80);
748}
749
750static void layer_brush_height_preview_draw(const uint gpuattr,
751 const Brush &brush,
752 const float rds,
753 const float line_width,
754 const float3 &outline_col,
755 const float alpha)
756{
757 const float4x4 cursor_trans = math::translate(float4x4::identity(),
758 float3(0.0f, 0.0f, brush.height));
760 GPU_matrix_mul(cursor_trans.ptr());
761
762 GPU_line_width(line_width);
763 immUniformColor3fvAlpha(outline_col, alpha * 0.5f);
764 imm_draw_circle_wire_3d(gpuattr, 0, 0, rds, 80);
766}
767
769{
770 const Brush &brush = *pcontext.brush;
771 /* Main inactive cursor. */
773
774 if (pcontext.mode != PaintMode::Sculpt) {
775 return;
776 }
777
778 if (!pcontext.is_brush_active) {
779 return;
780 }
781
782 switch (brush.sculpt_brush_type) {
784 /* Cloth brush local simulation areas. */
785 if (brush.cloth_simulation_area_type != BRUSH_CLOTH_SIMULATION_AREA_GLOBAL) {
786 const float3 white = {1.0f, 1.0f, 1.0f};
787 const float3 zero_v = float3(0.0f);
788 /* This functions sets its own drawing space in order to draw the simulation limits when
789 * the cursor is active. When used here, this cursor overlay is already in cursor space, so
790 * its position and normal should be set to 0. */
792 pcontext.pos, brush, zero_v, zero_v, pcontext.radius, 1.0f, white, 0.25f);
793 }
794 break;
797 brush,
798 pcontext.radius,
799 1.0f,
800 pcontext.outline_col,
801 pcontext.outline_alpha);
802 break;
803 default:
804 break;
805 }
806}
807
809{
811 if (!pcontext.is_cursor_over_mesh) {
812 inactive_cursor_draw(pcontext);
813 return;
814 }
815
816 BLI_assert(pcontext.vc.obact);
817 Object &active_object = *pcontext.vc.obact;
819
820 vert_random_access_ensure(active_object);
821
822 /* Setup drawing. */
823 wmViewport(&pcontext.region->winrct);
824
825 /* Drawing of Cursor overlays in 2D screen space. */
827
828 /* Setup 3D perspective drawing. */
831 pcontext.win,
832 pcontext.depsgraph,
833 pcontext.scene,
834 pcontext.region,
835 pcontext.vc.v3d,
836 nullptr,
837 nullptr,
838 nullptr);
839
841 GPU_matrix_mul(active_object.object_to_world().ptr());
842
843 /* Drawing Cursor overlays in 3D object space. */
845
847
848 /* Drawing Cursor overlays in Paint Cursor space (as additional info on top of the brush cursor)
849 */
853
855
856 /* Reset drawing. */
858 wmWindowViewport(pcontext.win);
859}
860
861} // namespace blender::ed::sculpt_paint
General operations, lookup, etc. for blender objects.
#define M_PI
#define PRF_scope(category)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
int64_t size() const
Definition BLI_array.hh:267
bool is_empty() const
Definition BLI_array.hh:275
#define position
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
bool supports_tilt(const Brush &brush)
Definition brush.cc:2103
pbvh::Tree & pbvh_ensure(Depsgraph &depsgraph, Object &object)
pbvh::Tree * pbvh_get(Object &object)
bool supports_symmetry_tiling(PaintMode paint_mode, const Brush &brush)
bool supports_scene_size(PaintMode paint_mode, const Brush &brush)
Span< float3 > vert_positions_eval(const Depsgraph &depsgraph, const Object &object_orig)
Definition pbvh.cc:933
void pivot_line_preview_draw(const uint gpuattr, SculptSession &ss)
std::unique_ptr< SculptBoundaryPreview > preview_data_init(const Depsgraph &depsgraph, Object &object, const Brush *brush, const float radius)
void edges_preview_draw(const uint gpuattr, SculptSession &ss, const float outline_col[3], const float outline_alpha)
void multiplane_scrape_preview_draw(uint gpuattr, const Brush &brush, const SculptSession &ss, const float outline_col[3], float outline_alpha)
void plane_falloff_preview_draw(const uint gpuattr, Brush &brush, SculptSession &ss, const float outline_col[3], float outline_alpha)
void simulation_limits_draw(const uint gpuattr, const Brush &brush, const float location[3], const float normal[3], const float rds, const float line_width, const float outline_col[3], const float alpha)
std::unique_ptr< SculptPoseIKChainPreview > preview_ik_chain_init(const Depsgraph &depsgraph, Object &ob, SculptSession &ss, const Brush &brush, const float3 &initial_location, const float radius)
void mesh_cursor_inactive_draw(PaintCursorContext &pcontext)
static void object_space_radius_update(PaintCursorContext &pcontext)
static void screen_space_overlays_draw(const PaintCursorContext &pcontext)
static void geometry_preview_lines_draw(const Depsgraph &depsgraph, const uint gpuattr, const Brush &brush, const Object &object)
void vert_random_access_ensure(Object &object)
Definition sculpt.cc:154
bool stroke_is_first_brush_step_of_symmetry_pass(const StrokeCache &cache)
Definition sculpt.cc:667
float3 symmetry_flip(const float3 &src, const ePaintSymmetryFlags symm)
static float3 get_active_vertex_position(const PaintCursorContext &pcontext)
ePaintSymmetryFlags mesh_symmetry_xyz_get(const Object &object)
Definition sculpt.cc:192
static int brush_radius_project(ViewContext *vc, float radius, const float location[3])
float3 calc_motion_normal_from_angle(const ViewContext &vc, const float3 &tip_location, const float angle)
Definition sculpt.cc:2812
static void inactive_cursor_draw(PaintCursorContext &pcontext)
void mesh_cursor_active_draw(PaintCursorContext &pcontext)
static void object_space_overlays_draw(const PaintCursorContext &pcontext)
static void pose_brush_segments_draw(const PaintCursorContext &pcontext)
float object_space_radius_get(const ViewContext &vc, const Paint &paint, const Brush &brush, const float3 &location, const float scale_factor)
Definition sculpt.cc:121
static void pixel_radius_update(PaintCursorContext &pcontext)
static void point_with_symmetry_draw(const PaintMode paint_mode, const Brush &brush, const uint gpuattr, const ARegion *region, const float true_location[3], const Paint &paint, const Object &ob, const float radius)
std::optional< CursorGeometryInfo > cursor_geometry_info_update(bContext *C, const float2 &mval, const bool use_sampled_normal)
Definition sculpt.cc:4584
static void tiling_preview_draw(const uint gpuattr, const ARegion *region, const float true_location[3], const Paint &paint, const Object &ob, const float radius)
static void cursor_space_overlays_draw(const PaintCursorContext &pcontext)
void mesh_cursor_update_and_init(PaintCursorContext &pcontext)
static void layer_brush_height_preview_draw(const uint gpuattr, const Brush &brush, const float rds, const float line_width, const float3 &outline_col, const float alpha)
static void pose_brush_origins_draw(const PaintCursorContext &pcontext)
static void main_inactive_cursor_draw(const PaintCursorContext &pcontext)
void calc_brush_local_mat(const float3 &tip_normal, const float3 &motion_normal_local, const float3 &tip_location, const float radius, float local_mat[4][4], float local_mat_inv[4][4])
Definition sculpt.cc:2830
static void boundary_preview_update(const PaintCursorContext &pcontext)
static void brush_unprojected_size_update(Paint &paint, Brush &brush, const ViewContext &vc, const float location[3])
static void cursor_space_drawing_setup(const PaintCursorContext &pcontext)
static void screen_space_point_draw(const uint gpuattr, const ARegion *region, const float true_location[3], const float obmat[4][4], const int size)
static void boundary_preview_pivot_draw(const PaintCursorContext &pcontext)
void geometry_preview_lines_update(Depsgraph &depsgraph, Object &object, SculptSession &ss, float radius)
Definition grab.cc:232
Span< float3 > vert_positions_for_grab_active_get(const Depsgraph &depsgraph, const Object &object)
Definition sculpt.cc:179
float3 tilt_apply_to_normal(const Object &object, const float4x4 &view_inverse, const float3 &normal, const float2 &tilt, const float tilt_strength)
Definition sculpt.cc:2876
bool is_symmetry_iteration_valid(const char i, const char symm)
void imm_draw_rounded_box_wire_3d(uint pos, float x, float y, float2 radius, float2 corner_radius, int nsegments)
T distance(const T &a, const T &b)
AxisAngleBase< float, AngleRadianBase< float > > AxisAngle
MatBase< T, NumCol, NumRow > translate(const MatBase< T, NumCol, NumRow > &mat, const VectorT &translation)
MatT from_rotation(const RotationT &rotation)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ V3D_PROJ_RET_OK
Definition ED_view3d.hh:273
void wmViewport(const rcti *winrct)
void immEnd()
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
@ BRUSH_STROKE_ANCHORED
void wmWindowViewport(const wmWindow *win)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
GPUDepthTest GPU_depth_test_get()
Definition gpu_state.cc:229
float BKE_brush_radius_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1366
@ PAINT_FALLOFF_SHAPE_SPHERE
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
void immBegin(GPUPrimType, uint vertex_len)
MatBase< float, 4, 4 > float4x4
void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], float r_out[3])
void GPU_matrix_mul(const float m[4][4])
MINLINE void mul_v3_fl(float r[3], float f)
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ SCULPT_BRUSH_TYPE_CLOTH
@ SCULPT_BRUSH_TYPE_GRAB
@ SCULPT_BRUSH_TYPE_POSE
@ SCULPT_BRUSH_TYPE_LAYER
@ SCULPT_BRUSH_TYPE_BOUNDARY
@ SCULPT_BRUSH_TYPE_MULTIPLANE_SCRAPE
float BKE_brush_unprojected_radius_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1412
void BKE_brush_unprojected_size_set(Paint *paint, Brush *brush, float unprojected_size)
Definition brush.cc:1390
void mul_m4_v3(const float M[4][4], float r[3])
VecBase< float, 2 > float2
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
void immUniformColor4f(float r, float g, float b, float a)
void unit_m4(float m[4][4])
bool BKE_brush_use_locked_size(const Paint *paint, const Brush *brush)
Definition brush.cc:1371
void ED_view3d_project_v3(const ARegion *region, const float world[3], float r_region_co[3])
void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments)
void BKE_brush_size_set(Paint *paint, Brush *brush, int size)
Definition brush.cc:1340
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
bool BKE_brush_use_size_pressure(const Brush *brush)
Definition brush.cc:1380
MINLINE float normalize_v3(float n[3])
void immVertex3fv(uint attr_id, const float data[3])
void rotate_m4(float mat[4][4], char axis, float angle)
void GPU_matrix_pop_projection()
bool BKE_brush_has_cube_tip(const Brush *brush, PaintMode paint_mode)
Definition brush.cc:1816
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
float paint_calc_object_space_radius(const ViewContext &vc, const float3 &center, float pixel_radius)
@ V3D_PROJ_TEST_NOP
Definition ED_view3d.hh:295
void BKE_sculptsession_update_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
@ BRUSH_GRAB_ACTIVE_VERTEX
void ED_view3d_draw_setup_view(const wmWindowManager *wm, wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *region, View3D *v3d, const float viewmat[4][4], const float winmat[4][4], const rcti *rect)
VecBase< float, 3 > float3
void GPU_matrix_pop()
void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments)
void immUniformColor3fvAlpha(const float rgb[3], float a)
void GPU_matrix_push_projection()
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
Mesh * BKE_object_get_evaluated_mesh_no_subsurf(const Object *object_eval)
Definition object.cc:4419
@ BRUSH_CLOTH_SIMULATION_AREA_GLOBAL
@ BRUSH_CLOTH_SIMULATION_AREA_LOCAL
float BKE_brush_alpha_get(const Paint *paint, const Brush *brush)
Definition brush.cc:1454
void GPU_matrix_push()
@ BRUSH_CLOTH_FORCE_FALLOFF_PLANE
@ BRUSH_CLOTH_FORCE_FALLOFF_RADIAL
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eBrushFalloffShape falloff_shape
const c_style_mat & ptr() const
bke::PaintRuntime * runtime
ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:409
float3 active_vert_position(const Depsgraph &depsgraph, const Object &object) const
std::unique_ptr< SculptBoundaryPreview > boundary_preview
Definition BKE_paint.hh:438
ed::sculpt_paint::expand::Cache * expand_cache
Definition BKE_paint.hh:411
Array< int > preview_verts
Definition BKE_paint.hh:432
std::unique_ptr< SculptPoseIKChainPreview > pose_ik_chain_preview
Definition BKE_paint.hh:435
Array< float3 > positions
RegionView3D * rv3d
Definition ED_view3d.hh:86