Blender  V2.93
sculpt.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2006 by Nicholas Bishop
17  * All rights reserved.
18  * Implements the Sculpt Mode tools
19  */
20 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BLI_blenlib.h"
28 #include "BLI_dial_2d.h"
29 #include "BLI_ghash.h"
30 #include "BLI_gsqueue.h"
31 #include "BLI_hash.h"
32 #include "BLI_math.h"
33 #include "BLI_math_color_blend.h"
34 #include "BLI_task.h"
35 #include "BLI_utildefines.h"
36 
37 #include "BLT_translation.h"
38 
39 #include "PIL_time.h"
40 
41 #include "DNA_brush_types.h"
42 #include "DNA_customdata_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_meshdata_types.h"
45 #include "DNA_node_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_scene_types.h"
48 
49 #include "BKE_brush.h"
50 #include "BKE_ccg.h"
51 #include "BKE_colortools.h"
52 #include "BKE_context.h"
53 #include "BKE_image.h"
54 #include "BKE_kelvinlet.h"
55 #include "BKE_key.h"
56 #include "BKE_lib_id.h"
57 #include "BKE_main.h"
58 #include "BKE_mesh.h"
59 #include "BKE_mesh_mapping.h"
60 #include "BKE_mesh_mirror.h"
61 #include "BKE_modifier.h"
62 #include "BKE_multires.h"
63 #include "BKE_node.h"
64 #include "BKE_object.h"
65 #include "BKE_paint.h"
66 #include "BKE_particle.h"
67 #include "BKE_pbvh.h"
68 #include "BKE_pointcache.h"
69 #include "BKE_report.h"
70 #include "BKE_scene.h"
71 #include "BKE_screen.h"
72 #include "BKE_subdiv_ccg.h"
73 #include "BKE_subsurf.h"
74 
75 #include "DEG_depsgraph.h"
76 
77 #include "IMB_colormanagement.h"
78 
79 #include "WM_api.h"
80 #include "WM_message.h"
81 #include "WM_toolsystem.h"
82 #include "WM_types.h"
83 
84 #include "ED_object.h"
85 #include "ED_screen.h"
86 #include "ED_sculpt.h"
87 #include "ED_view3d.h"
88 #include "paint_intern.h"
89 #include "sculpt_intern.h"
90 
91 #include "RNA_access.h"
92 #include "RNA_define.h"
93 
94 #include "UI_interface.h"
95 #include "UI_resources.h"
96 
97 #include "bmesh.h"
98 #include "bmesh_tools.h"
99 
100 #include <math.h>
101 #include <stdlib.h>
102 #include <string.h>
103 
104 /* Sculpt PBVH abstraction API
105  *
106  * This is read-only, for writing use PBVH vertex iterators. There vd.index matches
107  * the indices used here.
108  *
109  * For multi-resolution, the same vertex in multiple grids is counted multiple times, with
110  * different index for each grid. */
111 
113 {
114  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
117  }
118 }
119 
121 {
122  switch (BKE_pbvh_type(ss->pbvh)) {
123  case PBVH_FACES:
124  return ss->totvert;
125  case PBVH_BMESH:
127  case PBVH_GRIDS:
129  }
130 
131  return 0;
132 }
133 
134 const float *SCULPT_vertex_co_get(SculptSession *ss, int index)
135 {
136  switch (BKE_pbvh_type(ss->pbvh)) {
137  case PBVH_FACES: {
138  if (ss->shapekey_active || ss->deform_modifiers_active) {
139  const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
140  return mverts[index].co;
141  }
142  return ss->mvert[index].co;
143  }
144  case PBVH_BMESH:
145  return BM_vert_at_index(BKE_pbvh_get_bmesh(ss->pbvh), index)->co;
146  case PBVH_GRIDS: {
147  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
148  const int grid_index = index / key->grid_area;
149  const int vertex_index = index - grid_index * key->grid_area;
150  CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index];
151  return CCG_elem_co(key, CCG_elem_offset(key, elem, vertex_index));
152  }
153  }
154  return NULL;
155 }
156 
157 const float *SCULPT_vertex_color_get(SculptSession *ss, int index)
158 {
159  switch (BKE_pbvh_type(ss->pbvh)) {
160  case PBVH_FACES:
161  if (ss->vcol) {
162  return ss->vcol[index].color;
163  }
164  break;
165  case PBVH_BMESH:
166  case PBVH_GRIDS:
167  break;
168  }
169  return NULL;
170 }
171 
172 void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3])
173 {
174  switch (BKE_pbvh_type(ss->pbvh)) {
175  case PBVH_FACES: {
176  if (ss->shapekey_active || ss->deform_modifiers_active) {
177  const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
178  normal_short_to_float_v3(no, mverts[index].no);
179  }
180  else {
181  normal_short_to_float_v3(no, ss->mvert[index].no);
182  }
183  break;
184  }
185  case PBVH_BMESH:
187  break;
188  case PBVH_GRIDS: {
189  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
190  const int grid_index = index / key->grid_area;
191  const int vertex_index = index - grid_index * key->grid_area;
192  CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index];
193  copy_v3_v3(no, CCG_elem_no(key, CCG_elem_offset(key, elem, vertex_index)));
194  break;
195  }
196  }
197 }
198 
199 const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
200 {
201  if (ss->persistent_base) {
202  return ss->persistent_base[index].co;
203  }
204  return SCULPT_vertex_co_get(ss, index);
205 }
206 
208 {
209  /* Always grab active shape key if the sculpt happens on shapekey. */
210  if (ss->shapekey_active) {
211  const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
212  return mverts[index].co;
213  }
214 
215  /* Sculpting on the base mesh. */
216  if (ss->mvert) {
217  return ss->mvert[index].co;
218  }
219 
220  /* Everything else, such as sculpting on multires. */
221  return SCULPT_vertex_co_get(ss, index);
222 }
223 
224 void SCULPT_vertex_limit_surface_get(SculptSession *ss, int index, float r_co[3])
225 {
226  switch (BKE_pbvh_type(ss->pbvh)) {
227  case PBVH_FACES:
228  case PBVH_BMESH:
229  copy_v3_v3(r_co, SCULPT_vertex_co_get(ss, index));
230  break;
231  case PBVH_GRIDS: {
232  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
233  const int grid_index = index / key->grid_area;
234  const int vertex_index = index - grid_index * key->grid_area;
235 
236  SubdivCCGCoord coord = {.grid_index = grid_index,
237  .x = vertex_index % key->grid_size,
238  .y = vertex_index / key->grid_size};
239  BKE_subdiv_ccg_eval_limit_point(ss->subdiv_ccg, &coord, r_co);
240  break;
241  }
242  }
243 }
244 
245 void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
246 {
247  if (ss->persistent_base) {
248  copy_v3_v3(no, ss->persistent_base[index].no);
249  return;
250  }
251  SCULPT_vertex_normal_get(ss, index, no);
252 }
253 
255 {
256  BMVert *v;
257  float *mask;
258  switch (BKE_pbvh_type(ss->pbvh)) {
259  case PBVH_FACES:
260  return ss->vmask[index];
261  case PBVH_BMESH:
262  v = BM_vert_at_index(BKE_pbvh_get_bmesh(ss->pbvh), index);
264  return *mask;
265  case PBVH_GRIDS: {
266  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
267  const int grid_index = index / key->grid_area;
268  const int vertex_index = index - grid_index * key->grid_area;
269  CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index];
270  return *CCG_elem_mask(key, CCG_elem_offset(key, elem, vertex_index));
271  }
272  }
273 
274  return 0.0f;
275 }
276 
278 {
280  return ss->active_vertex_index;
281  }
282  return 0;
283 }
284 
286 {
288 }
289 
291 {
293 }
294 
296 {
297  switch (BKE_pbvh_type(ss->pbvh)) {
298  case PBVH_FACES:
299  if (ss->shapekey_active || ss->deform_modifiers_active) {
300  return BKE_pbvh_get_verts(ss->pbvh);
301  }
302  return ss->mvert;
303  case PBVH_BMESH:
304  case PBVH_GRIDS:
305  return NULL;
306  }
307  return NULL;
308 }
309 
311  const int deform_target,
312  PBVHVertexIter *iter)
313 {
314  switch (deform_target) {
316  return iter->co;
318  return ss->cache->cloth_sim->deformation_pos[iter->index];
319  }
320  return iter->co;
321 }
322 
324 {
325  const Mesh *mesh = BKE_mesh_from_object(object);
326  return mesh->symmetry;
327 }
328 
329 /* Sculpt Face Sets and Visibility. */
330 
332 {
333  switch (BKE_pbvh_type(ss->pbvh)) {
334  case PBVH_FACES:
335  return ss->face_sets[ss->active_face_index];
336  case PBVH_GRIDS: {
337  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg,
338  ss->active_grid_index);
339  return ss->face_sets[face_index];
340  }
341  case PBVH_BMESH:
342  return SCULPT_FACE_SET_NONE;
343  }
344  return SCULPT_FACE_SET_NONE;
345 }
346 
347 void SCULPT_vertex_visible_set(SculptSession *ss, int index, bool visible)
348 {
349  switch (BKE_pbvh_type(ss->pbvh)) {
350  case PBVH_FACES:
351  SET_FLAG_FROM_TEST(ss->mvert[index].flag, !visible, ME_HIDE);
352  ss->mvert[index].flag |= ME_VERT_PBVH_UPDATE;
353  break;
354  case PBVH_BMESH:
355  BM_elem_flag_set(BM_vert_at_index(ss->bm, index), BM_ELEM_HIDDEN, !visible);
356  break;
357  case PBVH_GRIDS:
358  break;
359  }
360 }
361 
363 {
364  switch (BKE_pbvh_type(ss->pbvh)) {
365  case PBVH_FACES:
366  return !(ss->mvert[index].flag & ME_HIDE);
367  case PBVH_BMESH:
368  return !BM_elem_flag_test(BM_vert_at_index(ss->bm, index), BM_ELEM_HIDDEN);
369  case PBVH_GRIDS: {
370  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
371  const int grid_index = index / key->grid_area;
372  const int vertex_index = index - grid_index * key->grid_area;
373  BLI_bitmap **grid_hidden = BKE_pbvh_get_grid_visibility(ss->pbvh);
374  if (grid_hidden && grid_hidden[grid_index]) {
375  return !BLI_BITMAP_TEST(grid_hidden[grid_index], vertex_index);
376  }
377  }
378  }
379  return true;
380 }
381 
382 void SCULPT_face_set_visibility_set(SculptSession *ss, int face_set, bool visible)
383 {
384  switch (BKE_pbvh_type(ss->pbvh)) {
385  case PBVH_FACES:
386  case PBVH_GRIDS:
387  for (int i = 0; i < ss->totfaces; i++) {
388  if (abs(ss->face_sets[i]) != face_set) {
389  continue;
390  }
391  if (visible) {
392  ss->face_sets[i] = abs(ss->face_sets[i]);
393  }
394  else {
395  ss->face_sets[i] = -abs(ss->face_sets[i]);
396  }
397  }
398  break;
399  case PBVH_BMESH:
400  break;
401  }
402 }
403 
405 {
406  switch (BKE_pbvh_type(ss->pbvh)) {
407  case PBVH_FACES:
408  case PBVH_GRIDS:
409  for (int i = 0; i < ss->totfaces; i++) {
410  ss->face_sets[i] *= -1;
411  }
412  break;
413  case PBVH_BMESH:
414  break;
415  }
416 }
417 
419 {
420  switch (BKE_pbvh_type(ss->pbvh)) {
421  case PBVH_FACES:
422  case PBVH_GRIDS:
423  for (int i = 0; i < ss->totfaces; i++) {
424 
425  /* This can run on geometry without a face set assigned, so its ID sign can't be changed to
426  * modify the visibility. Force that geometry to the ID 1 to enable changing the visibility
427  * here. */
428  if (ss->face_sets[i] == SCULPT_FACE_SET_NONE) {
429  ss->face_sets[i] = 1;
430  }
431 
432  if (visible) {
433  ss->face_sets[i] = abs(ss->face_sets[i]);
434  }
435  else {
436  ss->face_sets[i] = -abs(ss->face_sets[i]);
437  }
438  }
439  break;
440  case PBVH_BMESH:
441  break;
442  }
443 }
444 
446 {
447  switch (BKE_pbvh_type(ss->pbvh)) {
448  case PBVH_FACES: {
449  MeshElemMap *vert_map = &ss->pmap[index];
450  for (int j = 0; j < ss->pmap[index].count; j++) {
451  if (ss->face_sets[vert_map->indices[j]] > 0) {
452  return true;
453  }
454  }
455  return false;
456  }
457  case PBVH_BMESH:
458  return true;
459  case PBVH_GRIDS:
460  return true;
461  }
462  return true;
463 }
464 
466 {
467  switch (BKE_pbvh_type(ss->pbvh)) {
468  case PBVH_FACES: {
469  MeshElemMap *vert_map = &ss->pmap[index];
470  for (int j = 0; j < ss->pmap[index].count; j++) {
471  if (ss->face_sets[vert_map->indices[j]] < 0) {
472  return false;
473  }
474  }
475  return true;
476  }
477  case PBVH_BMESH:
478  return true;
479  case PBVH_GRIDS: {
480  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
481  const int grid_index = index / key->grid_area;
482  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
483  return ss->face_sets[face_index] > 0;
484  }
485  }
486  return true;
487 }
488 
489 void SCULPT_vertex_face_set_set(SculptSession *ss, int index, int face_set)
490 {
491  switch (BKE_pbvh_type(ss->pbvh)) {
492  case PBVH_FACES: {
493  MeshElemMap *vert_map = &ss->pmap[index];
494  for (int j = 0; j < ss->pmap[index].count; j++) {
495  if (ss->face_sets[vert_map->indices[j]] > 0) {
496  ss->face_sets[vert_map->indices[j]] = abs(face_set);
497  }
498  }
499  } break;
500  case PBVH_BMESH:
501  break;
502  case PBVH_GRIDS: {
503  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
504  const int grid_index = index / key->grid_area;
505  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
506  if (ss->face_sets[face_index] > 0) {
507  ss->face_sets[face_index] = abs(face_set);
508  }
509 
510  } break;
511  }
512 }
513 
515 {
516  switch (BKE_pbvh_type(ss->pbvh)) {
517  case PBVH_FACES: {
518  MeshElemMap *vert_map = &ss->pmap[index];
519  int face_set = 0;
520  for (int i = 0; i < ss->pmap[index].count; i++) {
521  if (ss->face_sets[vert_map->indices[i]] > face_set) {
522  face_set = abs(ss->face_sets[vert_map->indices[i]]);
523  }
524  }
525  return face_set;
526  }
527  case PBVH_BMESH:
528  return 0;
529  case PBVH_GRIDS: {
530  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
531  const int grid_index = index / key->grid_area;
532  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
533  return ss->face_sets[face_index];
534  }
535  }
536  return 0;
537 }
538 
539 bool SCULPT_vertex_has_face_set(SculptSession *ss, int index, int face_set)
540 {
541  switch (BKE_pbvh_type(ss->pbvh)) {
542  case PBVH_FACES: {
543  MeshElemMap *vert_map = &ss->pmap[index];
544  for (int i = 0; i < ss->pmap[index].count; i++) {
545  if (ss->face_sets[vert_map->indices[i]] == face_set) {
546  return true;
547  }
548  }
549  return false;
550  }
551  case PBVH_BMESH:
552  return true;
553  case PBVH_GRIDS: {
554  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
555  const int grid_index = index / key->grid_area;
556  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
557  return ss->face_sets[face_index] == face_set;
558  }
559  }
560  return true;
561 }
562 
564 {
565  SculptSession *ss = ob->sculpt;
567  switch (BKE_pbvh_type(ss->pbvh)) {
568  case PBVH_FACES: {
570  break;
571  }
572  case PBVH_GRIDS: {
575  break;
576  }
577  case PBVH_BMESH:
578  break;
579  }
580 }
581 
583  int index)
584 {
585  MeshElemMap *vert_map = &ss->pmap[index];
586  const bool visible = SCULPT_vertex_visible_get(ss, index);
587  for (int i = 0; i < ss->pmap[index].count; i++) {
588  if (visible) {
589  ss->face_sets[vert_map->indices[i]] = abs(ss->face_sets[vert_map->indices[i]]);
590  }
591  else {
592  ss->face_sets[vert_map->indices[i]] = -abs(ss->face_sets[vert_map->indices[i]]);
593  }
594  }
595  ss->mvert[index].flag |= ME_VERT_PBVH_UPDATE;
596 }
597 
599 {
600  if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
601  for (int i = 0; i < ss->totfaces; i++) {
602  MPoly *poly = &ss->mpoly[i];
603  bool poly_visible = true;
604  for (int l = 0; l < poly->totloop; l++) {
605  MLoop *loop = &ss->mloop[poly->loopstart + l];
606  if (!SCULPT_vertex_visible_get(ss, (int)loop->v)) {
607  poly_visible = false;
608  }
609  }
610  if (poly_visible) {
611  ss->face_sets[i] = abs(ss->face_sets[i]);
612  }
613  else {
614  ss->face_sets[i] = -abs(ss->face_sets[i]);
615  }
616  }
617  }
618 }
619 
621 {
622  MeshElemMap *vert_map = &ss->pmap[index];
623  int face_set = -1;
624  for (int i = 0; i < ss->pmap[index].count; i++) {
625  if (face_set == -1) {
626  face_set = abs(ss->face_sets[vert_map->indices[i]]);
627  }
628  else {
629  if (abs(ss->face_sets[vert_map->indices[i]]) != face_set) {
630  return false;
631  }
632  }
633  }
634  return true;
635 }
636 
642 {
643  MeshElemMap *vert_map = &ss->pmap[v1];
644  int p1 = -1, p2 = -1;
645  for (int i = 0; i < ss->pmap[v1].count; i++) {
646  MPoly *p = &ss->mpoly[vert_map->indices[i]];
647  for (int l = 0; l < p->totloop; l++) {
648  MLoop *loop = &ss->mloop[p->loopstart + l];
649  if (loop->v == v2) {
650  if (p1 == -1) {
651  p1 = vert_map->indices[i];
652  break;
653  }
654 
655  if (p2 == -1) {
656  p2 = vert_map->indices[i];
657  break;
658  }
659  }
660  }
661  }
662 
663  if (p1 != -1 && p2 != -1) {
664  return abs(ss->face_sets[p1]) == (ss->face_sets[p2]);
665  }
666  return true;
667 }
668 
670 {
671  switch (BKE_pbvh_type(ss->pbvh)) {
672  case PBVH_FACES: {
674  }
675  case PBVH_BMESH:
676  return true;
677  case PBVH_GRIDS: {
678  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
679  const int grid_index = index / key->grid_area;
680  const int vertex_index = index - grid_index * key->grid_area;
681  const SubdivCCGCoord coord = {.grid_index = grid_index,
682  .x = vertex_index % key->grid_size,
683  .y = vertex_index / key->grid_size};
684  int v1, v2;
686  ss->subdiv_ccg, &coord, ss->mloop, ss->mpoly, &v1, &v2);
687  switch (adjacency) {
693  return true;
694  }
695  }
696  }
697  return false;
698 }
699 
701 {
702  switch (BKE_pbvh_type(ss->pbvh)) {
703  case PBVH_FACES:
704  case PBVH_GRIDS: {
705  int next_face_set = 0;
706  for (int i = 0; i < ss->totfaces; i++) {
707  if (abs(ss->face_sets[i]) > next_face_set) {
708  next_face_set = abs(ss->face_sets[i]);
709  }
710  }
711  next_face_set++;
712  return next_face_set;
713  }
714  case PBVH_BMESH:
715  return 0;
716  }
717  return 0;
718 }
719 
720 /* Sculpt Neighbor Iterators */
721 
722 #define SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY 256
723 
724 static void sculpt_vertex_neighbor_add(SculptVertexNeighborIter *iter, int neighbor_index)
725 {
726  for (int i = 0; i < iter->size; i++) {
727  if (iter->neighbors[i] == neighbor_index) {
728  return;
729  }
730  }
731 
732  if (iter->size >= iter->capacity) {
734 
735  if (iter->neighbors == iter->neighbors_fixed) {
736  iter->neighbors = MEM_mallocN(iter->capacity * sizeof(int), "neighbor array");
737  memcpy(iter->neighbors, iter->neighbors_fixed, sizeof(int) * iter->size);
738  }
739  else {
740  iter->neighbors = MEM_reallocN_id(
741  iter->neighbors, iter->capacity * sizeof(int), "neighbor array");
742  }
743  }
744 
745  iter->neighbors[iter->size] = neighbor_index;
746  iter->size++;
747 }
748 
750  int index,
752 {
753  BMVert *v = BM_vert_at_index(ss->bm, index);
754  BMIter liter;
755  BMLoop *l;
756  iter->size = 0;
757  iter->num_duplicates = 0;
759  iter->neighbors = iter->neighbors_fixed;
760 
761  BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
762  const BMVert *adj_v[2] = {l->prev->v, l->next->v};
763  for (int i = 0; i < ARRAY_SIZE(adj_v); i++) {
764  const BMVert *v_other = adj_v[i];
765  if (BM_elem_index_get(v_other) != (int)index) {
767  }
768  }
769  }
770 }
771 
773  int index,
775 {
776  MeshElemMap *vert_map = &ss->pmap[index];
777  iter->size = 0;
778  iter->num_duplicates = 0;
780  iter->neighbors = iter->neighbors_fixed;
781 
782  for (int i = 0; i < ss->pmap[index].count; i++) {
783  const MPoly *p = &ss->mpoly[vert_map->indices[i]];
784  uint f_adj_v[2];
785  if (poly_get_adj_loops_from_vert(p, ss->mloop, index, f_adj_v) != -1) {
786  for (int j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
787  if (f_adj_v[j] != index) {
788  sculpt_vertex_neighbor_add(iter, f_adj_v[j]);
789  }
790  }
791  }
792  }
793 
798  }
799  }
800 }
801 
803  const int index,
804  const bool include_duplicates,
806 {
807  /* TODO: optimize this. We could fill #SculptVertexNeighborIter directly,
808  * maybe provide coordinate and mask pointers directly rather than converting
809  * back and forth between #CCGElem and global index. */
810  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
811  const int grid_index = index / key->grid_area;
812  const int vertex_index = index - grid_index * key->grid_area;
813 
814  SubdivCCGCoord coord = {.grid_index = grid_index,
815  .x = vertex_index % key->grid_size,
816  .y = vertex_index / key->grid_size};
817 
818  SubdivCCGNeighbors neighbors;
819  BKE_subdiv_ccg_neighbor_coords_get(ss->subdiv_ccg, &coord, include_duplicates, &neighbors);
820 
821  iter->size = 0;
822  iter->num_duplicates = neighbors.num_duplicates;
824  iter->neighbors = iter->neighbors_fixed;
825 
826  for (int i = 0; i < neighbors.size; i++) {
828  neighbors.coords[i].grid_index * key->grid_area +
829  neighbors.coords[i].y * key->grid_size + neighbors.coords[i].x);
830  }
831 
836  }
837  }
838 
839  if (neighbors.coords != neighbors.coords_fixed) {
840  MEM_freeN(neighbors.coords);
841  }
842 }
843 
845  const int index,
846  const bool include_duplicates,
848 {
849  switch (BKE_pbvh_type(ss->pbvh)) {
850  case PBVH_FACES:
851  sculpt_vertex_neighbors_get_faces(ss, index, iter);
852  return;
853  case PBVH_BMESH:
854  sculpt_vertex_neighbors_get_bmesh(ss, index, iter);
855  return;
856  case PBVH_GRIDS:
857  sculpt_vertex_neighbors_get_grids(ss, index, include_duplicates, iter);
858  return;
859  }
860 }
861 
862 static bool sculpt_check_boundary_vertex_in_base_mesh(const SculptSession *ss, const int index)
863 {
865  return BLI_BITMAP_TEST(ss->vertex_info.boundary, index);
866 }
867 
868 bool SCULPT_vertex_is_boundary(const SculptSession *ss, const int index)
869 {
870  switch (BKE_pbvh_type(ss->pbvh)) {
871  case PBVH_FACES: {
872  if (!SCULPT_vertex_all_face_sets_visible_get(ss, index)) {
873  return true;
874  }
876  }
877  case PBVH_BMESH: {
878  BMVert *v = BM_vert_at_index(ss->bm, index);
879  return BM_vert_is_boundary(v);
880  }
881 
882  case PBVH_GRIDS: {
883  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
884  const int grid_index = index / key->grid_area;
885  const int vertex_index = index - grid_index * key->grid_area;
886  const SubdivCCGCoord coord = {.grid_index = grid_index,
887  .x = vertex_index % key->grid_size,
888  .y = vertex_index / key->grid_size};
889  int v1, v2;
891  ss->subdiv_ccg, &coord, ss->mloop, ss->mpoly, &v1, &v2);
892  switch (adjacency) {
899  return false;
900  }
901  }
902  }
903 
904  return false;
905 }
906 
907 /* Utilities */
908 
914 {
915  return cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0 &&
916  cache->tile_pass == 0;
917 }
918 
927 {
928  return cache->first_time && cache->mirror_symmetry_pass == 0 &&
929  cache->radial_symmetry_pass == 0 && cache->tile_pass == 0;
930 }
931 
936 {
937  return cache->first_time;
938 }
939 
940 bool SCULPT_check_vertex_pivot_symmetry(const float vco[3], const float pco[3], const char symm)
941 {
942  bool is_in_symmetry_area = true;
943  for (int i = 0; i < 3; i++) {
944  char symm_it = 1 << i;
945  if (symm & symm_it) {
946  if (pco[i] == 0.0f) {
947  if (vco[i] > 0.0f) {
948  is_in_symmetry_area = false;
949  }
950  }
951  if (vco[i] * pco[i] < 0.0f) {
952  is_in_symmetry_area = false;
953  }
954  }
955  }
956  return is_in_symmetry_area;
957 }
958 
959 typedef struct NearestVertexTLSData {
963 
964 static void do_nearest_vertex_get_task_cb(void *__restrict userdata,
965  const int n,
966  const TaskParallelTLS *__restrict tls)
967 {
968  SculptThreadedTaskData *data = userdata;
969  SculptSession *ss = data->ob->sculpt;
970  NearestVertexTLSData *nvtd = tls->userdata_chunk;
971  PBVHVertexIter vd;
972 
973  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
974  float distance_squared = len_squared_v3v3(vd.co, data->nearest_vertex_search_co);
975  if (distance_squared < nvtd->nearest_vertex_distance_squared &&
976  distance_squared < data->max_distance_squared) {
977  nvtd->nearest_vertex_index = vd.index;
978  nvtd->nearest_vertex_distance_squared = distance_squared;
979  }
980  }
982 }
983 
984 static void nearest_vertex_get_reduce(const void *__restrict UNUSED(userdata),
985  void *__restrict chunk_join,
986  void *__restrict chunk)
987 {
988  NearestVertexTLSData *join = chunk_join;
989  NearestVertexTLSData *nvtd = chunk;
990  if (join->nearest_vertex_index == -1) {
993  }
997  }
998 }
999 
1001  Sculpt *sd, Object *ob, const float co[3], float max_distance, bool use_original)
1002 {
1003  SculptSession *ss = ob->sculpt;
1004  PBVHNode **nodes = NULL;
1005  int totnode;
1007  .ss = ss,
1008  .sd = sd,
1009  .radius_squared = max_distance * max_distance,
1010  .original = use_original,
1011  .center = co,
1012  };
1013  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
1014  if (totnode == 0) {
1015  return -1;
1016  }
1017 
1018  SculptThreadedTaskData task_data = {
1019  .sd = sd,
1020  .ob = ob,
1021  .nodes = nodes,
1022  .max_distance_squared = max_distance * max_distance,
1023  };
1024 
1025  copy_v3_v3(task_data.nearest_vertex_search_co, co);
1026  NearestVertexTLSData nvtd;
1027  nvtd.nearest_vertex_index = -1;
1028  nvtd.nearest_vertex_distance_squared = FLT_MAX;
1029 
1030  TaskParallelSettings settings;
1031  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
1033  settings.userdata_chunk = &nvtd;
1034  settings.userdata_chunk_size = sizeof(NearestVertexTLSData);
1035  BLI_task_parallel_range(0, totnode, &task_data, do_nearest_vertex_get_task_cb, &settings);
1036 
1037  MEM_SAFE_FREE(nodes);
1038 
1039  return nvtd.nearest_vertex_index;
1040 }
1041 
1042 bool SCULPT_is_symmetry_iteration_valid(char i, char symm)
1043 {
1044  return i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || (i != 3 && i != 5)));
1045 }
1046 
1047 /* Checks if a vertex is inside the brush radius from any of its mirrored axis. */
1049  const float br_co[3],
1050  float radius,
1051  char symm)
1052 {
1053  for (char i = 0; i <= symm; ++i) {
1054  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1055  continue;
1056  }
1057  float location[3];
1058  flip_v3_v3(location, br_co, (char)i);
1059  if (len_squared_v3v3(location, vertex) < radius * radius) {
1060  return true;
1061  }
1062  }
1063  return false;
1064 }
1065 
1067 {
1068  ARegion *region = CTX_wm_region(C);
1069  ED_region_tag_redraw(region);
1070 
1073 
1075  View3D *v3d = CTX_wm_view3d(C);
1076  if (!BKE_sculptsession_use_pbvh_draw(ob, v3d)) {
1078  }
1079 }
1080 
1081 /* Sculpt Flood Fill API
1082  *
1083  * Iterate over connected vertices, starting from one or more initial vertices. */
1084 
1086 {
1087  int vertex_count = SCULPT_vertex_count_get(ss);
1089 
1090  flood->queue = BLI_gsqueue_new(sizeof(int));
1091  flood->visited_vertices = BLI_BITMAP_NEW(vertex_count, "visited vertices");
1092 }
1093 
1095 {
1096  BLI_gsqueue_push(flood->queue, &index);
1097 }
1098 
1100 {
1101  BLI_gsqueue_push(flood->queue, &index);
1102  BLI_BITMAP_ENABLE(flood->visited_vertices, index);
1103 }
1104 
1106  Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, int index, float radius)
1107 {
1108  /* Add active vertex and symmetric vertices to the queue. */
1109  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
1110  for (char i = 0; i <= symm; ++i) {
1111  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1112  continue;
1113  }
1114  int v = -1;
1115  if (i == 0) {
1116  v = index;
1117  }
1118  else if (radius > 0.0f) {
1119  float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
1120  float location[3];
1121  flip_v3_v3(location, SCULPT_vertex_co_get(ss, index), i);
1122  v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
1123  }
1124 
1125  if (v != -1) {
1127  }
1128  }
1129 }
1130 
1132  Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, float radius)
1133 {
1134  /* Add active vertex and symmetric vertices to the queue. */
1135  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
1136  for (char i = 0; i <= symm; ++i) {
1137  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1138  continue;
1139  }
1140  int v = -1;
1141  if (i == 0) {
1143  }
1144  else if (radius > 0.0f) {
1145  float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
1146  float location[3];
1147  flip_v3_v3(location, SCULPT_active_vertex_co_get(ss), i);
1148  v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
1149  }
1150 
1151  if (v != -1) {
1153  }
1154  }
1155 }
1156 
1158  SculptSession *ss,
1159  SculptFloodFill *flood,
1160  bool (*func)(SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata),
1161  void *userdata)
1162 {
1163  while (!BLI_gsqueue_is_empty(flood->queue)) {
1164  int from_v;
1165  BLI_gsqueue_pop(flood->queue, &from_v);
1168  const int to_v = ni.index;
1169 
1170  if (BLI_BITMAP_TEST(flood->visited_vertices, to_v)) {
1171  continue;
1172  }
1173 
1174  if (!SCULPT_vertex_visible_get(ss, to_v)) {
1175  continue;
1176  }
1177 
1178  BLI_BITMAP_ENABLE(flood->visited_vertices, to_v);
1179 
1180  if (func(ss, from_v, to_v, ni.is_duplicate, userdata)) {
1181  BLI_gsqueue_push(flood->queue, &to_v);
1182  }
1183  }
1185  }
1186 }
1187 
1189 {
1191  BLI_gsqueue_free(flood->queue);
1192  flood->queue = NULL;
1193 }
1194 
1195 /* -------------------------------------------------------------------- */
1203 static bool sculpt_tool_needs_original(const char sculpt_tool)
1204 {
1205  return ELEM(sculpt_tool,
1215 }
1216 
1217 static bool sculpt_tool_is_proxy_used(const char sculpt_tool)
1218 {
1219  return ELEM(sculpt_tool,
1229 }
1230 
1231 static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush *brush)
1232 {
1233  return SCULPT_TOOL_HAS_TOPOLOGY_RAKE(brush->sculpt_tool) &&
1234  (brush->topology_rake_factor > 0.0f) && (ss->bm != NULL);
1235 }
1236 
1240 static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush)
1241 {
1242  return ((SCULPT_TOOL_HAS_NORMAL_WEIGHT(brush->sculpt_tool) &&
1243  (ss->cache->normal_weight > 0.0f)) ||
1244 
1245  ELEM(brush->sculpt_tool,
1255  SCULPT_TOOL_THUMB) ||
1256 
1257  (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA)) ||
1258  sculpt_brush_use_topology_rake(ss, brush);
1259 }
1262 static bool sculpt_brush_needs_rake_rotation(const Brush *brush)
1263 {
1264  return SCULPT_TOOL_HAS_RAKE(brush->sculpt_tool) && (brush->rake_factor != 0.0f);
1265 }
1266 
1267 typedef enum StrokeFlags {
1268  CLIP_X = 1,
1269  CLIP_Y = 2,
1270  CLIP_Z = 4,
1272 
1278 {
1279  SculptSession *ss = ob->sculpt;
1280  BMesh *bm = ss->bm;
1281 
1282  memset(data, 0, sizeof(*data));
1283  data->unode = unode;
1284 
1285  if (bm) {
1286  data->bm_log = ss->bm_log;
1287  }
1288  else {
1289  data->coords = data->unode->co;
1290  data->normals = data->unode->no;
1291  data->vmasks = data->unode->mask;
1292  data->colors = data->unode->col;
1293  }
1294 }
1295 
1301 {
1302  SculptUndoNode *unode;
1305 }
1306 
1311 {
1312  if (orig_data->unode->type == SCULPT_UNDO_COORDS) {
1313  if (orig_data->bm_log) {
1314  BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co, &orig_data->no);
1315  }
1316  else {
1317  orig_data->co = orig_data->coords[iter->i];
1318  orig_data->no = orig_data->normals[iter->i];
1319  }
1320  }
1321  else if (orig_data->unode->type == SCULPT_UNDO_COLOR) {
1322  orig_data->col = orig_data->colors[iter->i];
1323  }
1324  else if (orig_data->unode->type == SCULPT_UNDO_MASK) {
1325  if (orig_data->bm_log) {
1326  orig_data->mask = BM_log_original_mask(orig_data->bm_log, iter->bm_vert);
1327  }
1328  else {
1329  orig_data->mask = orig_data->vmasks[iter->i];
1330  }
1331  }
1332 }
1333 
1334 static void sculpt_rake_data_update(struct SculptRakeData *srd, const float co[3])
1335 {
1336  float rake_dist = len_v3v3(srd->follow_co, co);
1337  if (rake_dist > srd->follow_dist) {
1338  interp_v3_v3v3(srd->follow_co, srd->follow_co, co, rake_dist - srd->follow_dist);
1339  }
1340 }
1341 
1342 static void sculpt_rake_rotate(const SculptSession *ss,
1343  const float sculpt_co[3],
1344  const float v_co[3],
1345  float factor,
1346  float r_delta[3])
1347 {
1348  float vec_rot[3];
1349 
1350 #if 0
1351  /* lerp */
1352  sub_v3_v3v3(vec_rot, v_co, sculpt_co);
1353  mul_qt_v3(ss->cache->rake_rotation_symmetry, vec_rot);
1354  add_v3_v3(vec_rot, sculpt_co);
1355  sub_v3_v3v3(r_delta, vec_rot, v_co);
1356  mul_v3_fl(r_delta, factor);
1357 #else
1358  /* slerp */
1359  float q_interp[4];
1360  sub_v3_v3v3(vec_rot, v_co, sculpt_co);
1361 
1362  copy_qt_qt(q_interp, ss->cache->rake_rotation_symmetry);
1363  pow_qt_fl_normalized(q_interp, factor);
1364  mul_qt_v3(q_interp, vec_rot);
1365 
1366  add_v3_v3(vec_rot, sculpt_co);
1367  sub_v3_v3v3(r_delta, vec_rot, v_co);
1368 #endif
1369 }
1370 
1377  const float normal_weight,
1378  float grab_delta[3])
1379 {
1380  /* Signed to support grabbing in (to make a hole) as well as out. */
1381  const float len_signed = dot_v3v3(ss->cache->sculpt_normal_symm, grab_delta);
1382 
1383  /* This scale effectively projects the offset so dragging follows the cursor,
1384  * as the normal points towards the view, the scale increases. */
1385  float len_view_scale;
1386  {
1387  float view_aligned_normal[3];
1389  view_aligned_normal, ss->cache->sculpt_normal_symm, ss->cache->view_normal);
1390  len_view_scale = fabsf(dot_v3v3(view_aligned_normal, ss->cache->sculpt_normal_symm));
1391  len_view_scale = (len_view_scale > FLT_EPSILON) ? 1.0f / len_view_scale : 1.0f;
1392  }
1393 
1394  mul_v3_fl(grab_delta, 1.0f - normal_weight);
1395  madd_v3_v3fl(
1396  grab_delta, ss->cache->sculpt_normal_symm, (len_signed * normal_weight) * len_view_scale);
1397 }
1398 
1399 /* -------------------------------------------------------------------- */
1406 typedef struct SculptProjectVector {
1407  float plane[3];
1408  float len_sq;
1410  bool is_valid;
1411 
1413 
1417 static void sculpt_project_v3_cache_init(SculptProjectVector *spvc, const float plane[3])
1418 {
1419  copy_v3_v3(spvc->plane, plane);
1420  spvc->len_sq = len_squared_v3(spvc->plane);
1421  spvc->is_valid = (spvc->len_sq > FLT_EPSILON);
1422  spvc->len_sq_inv_neg = (spvc->is_valid) ? -1.0f / spvc->len_sq : 0.0f;
1423 }
1424 
1428 static void sculpt_project_v3(const SculptProjectVector *spvc, const float vec[3], float r_vec[3])
1429 {
1430 #if 0
1431  project_plane_v3_v3v3(r_vec, vec, spvc->plane);
1432 #else
1433  /* inline the projection, cache `-1.0 / dot_v3_v3(v_proj, v_proj)` */
1434  madd_v3_v3fl(r_vec, spvc->plane, dot_v3v3(vec, spvc->plane) * spvc->len_sq_inv_neg);
1435 #endif
1436 }
1437 
1440 /**********************************************************************/
1441 
1442 /* Returns true if the stroke will use dynamic topology, false
1443  * otherwise.
1444  *
1445  * Factors: some brushes like grab cannot do dynamic topology.
1446  * Others, like smooth, are better without.
1447  * Same goes for alt-key smoothing. */
1449 {
1450  return ((BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) &&
1451 
1452  (!ss->cache || (!ss->cache->alt_smooth)) &&
1453 
1454  /* Requires mesh restore, which doesn't work with
1455  * dynamic-topology. */
1456  !(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) &&
1457 
1459 }
1460 
1461 /*** paint mesh ***/
1462 
1463 static void paint_mesh_restore_co_task_cb(void *__restrict userdata,
1464  const int n,
1465  const TaskParallelTLS *__restrict UNUSED(tls))
1466 {
1467  SculptThreadedTaskData *data = userdata;
1468  SculptSession *ss = data->ob->sculpt;
1469 
1470  SculptUndoNode *unode;
1471  SculptUndoType type = (data->brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK :
1473 
1474  if (ss->bm) {
1475  unode = SCULPT_undo_push_node(data->ob, data->nodes[n], type);
1476  }
1477  else {
1478  unode = SCULPT_undo_get_node(data->nodes[n]);
1479  }
1480 
1481  if (!unode) {
1482  return;
1483  }
1484 
1485  PBVHVertexIter vd;
1486  SculptOrigVertData orig_data;
1487 
1488  SCULPT_orig_vert_data_unode_init(&orig_data, data->ob, unode);
1489 
1490  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
1491  SCULPT_orig_vert_data_update(&orig_data, &vd);
1492 
1493  if (orig_data.unode->type == SCULPT_UNDO_COORDS) {
1494  copy_v3_v3(vd.co, orig_data.co);
1495  if (vd.no) {
1496  copy_v3_v3_short(vd.no, orig_data.no);
1497  }
1498  else {
1499  normal_short_to_float_v3(vd.fno, orig_data.no);
1500  }
1501  }
1502  else if (orig_data.unode->type == SCULPT_UNDO_MASK) {
1503  *vd.mask = orig_data.mask;
1504  }
1505  else if (orig_data.unode->type == SCULPT_UNDO_COLOR) {
1506  copy_v4_v4(vd.col, orig_data.col);
1507  }
1508 
1509  if (vd.mvert) {
1511  }
1512  }
1514 
1515  BKE_pbvh_node_mark_update(data->nodes[n]);
1516 }
1517 
1518 static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
1519 {
1520  SculptSession *ss = ob->sculpt;
1521  Brush *brush = BKE_paint_brush(&sd->paint);
1522 
1523  PBVHNode **nodes;
1524  int totnode;
1525 
1526  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
1527 
1534  .sd = sd,
1535  .ob = ob,
1536  .brush = brush,
1537  .nodes = nodes,
1538  };
1539 
1540  TaskParallelSettings settings;
1541  BKE_pbvh_parallel_range_settings(&settings, true && !ss->bm, totnode);
1543 
1545 
1546  MEM_SAFE_FREE(nodes);
1547 }
1548 
1549 /*** BVH Tree ***/
1550 
1552 {
1553  /* Expand redraw \a rect with redraw \a rect from previous step to
1554  * prevent partial-redraw issues caused by fast strokes. This is
1555  * needed here (not in sculpt_flush_update) as it was before
1556  * because redraw rectangle should be the same in both of
1557  * optimized PBVH draw function and 3d view redraw, if not -- some
1558  * mesh parts could disappear from screen (sergey). */
1559  SculptSession *ss = ob->sculpt;
1560 
1561  if (!ss->cache) {
1562  return;
1563  }
1564 
1565  if (BLI_rcti_is_empty(&ss->cache->previous_r)) {
1566  return;
1567  }
1568 
1569  BLI_rcti_union(rect, &ss->cache->previous_r);
1570 }
1571 
1572 /* Get a screen-space rectangle of the modified area. */
1573 bool SCULPT_get_redraw_rect(ARegion *region, RegionView3D *rv3d, Object *ob, rcti *rect)
1574 {
1575  PBVH *pbvh = ob->sculpt->pbvh;
1576  float bb_min[3], bb_max[3];
1577 
1578  if (!pbvh) {
1579  return false;
1580  }
1581 
1582  BKE_pbvh_redraw_BB(pbvh, bb_min, bb_max);
1583 
1584  /* Convert 3D bounding box to screen space. */
1585  if (!paint_convert_bb_to_rect(rect, bb_min, bb_max, region, rv3d, ob)) {
1586  return false;
1587  }
1588 
1589  return true;
1590 }
1591 
1592 void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *region, Object *ob)
1593 {
1594  PBVH *pbvh = ob->sculpt->pbvh;
1595  /* Copy here, original will be used below. */
1596  rcti rect = ob->sculpt->cache->current_r;
1597 
1599 
1600  paint_calc_redraw_planes(planes, region, ob, &rect);
1601 
1602  /* We will draw this \a rect, so now we can set it as the previous partial \a rect.
1603  * Note that we don't update with the union of previous/current (\a rect), only with
1604  * the current. Thus we avoid the rectangle needlessly growing to include
1605  * all the stroke area. */
1606  ob->sculpt->cache->previous_r = ob->sculpt->cache->current_r;
1607 
1608  /* Clear redraw flag from nodes. */
1609  if (pbvh) {
1611  }
1612 }
1613 
1614 /************************ Brush Testing *******************/
1615 
1617 {
1618  RegionView3D *rv3d = ss->cache ? ss->cache->vc->rv3d : ss->rv3d;
1619  View3D *v3d = ss->cache ? ss->cache->vc->v3d : ss->v3d;
1620 
1621  test->radius_squared = ss->cache ? ss->cache->radius_squared :
1622  ss->cursor_radius * ss->cursor_radius;
1623  test->radius = sqrtf(test->radius_squared);
1624 
1625  if (ss->cache) {
1626  copy_v3_v3(test->location, ss->cache->location);
1630  }
1631  else {
1632  copy_v3_v3(test->location, ss->cursor_location);
1633  test->mirror_symmetry_pass = 0;
1634  test->radial_symmetry_pass = 0;
1635  unit_m4(test->symm_rot_mat_inv);
1636  }
1637 
1638  /* Just for initialize. */
1639  test->dist = 0.0f;
1640 
1641  /* Only for 2D projection. */
1642  zero_v4(test->plane_view);
1643  zero_v4(test->plane_tool);
1644 
1645  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
1646  test->clip_rv3d = rv3d;
1647  }
1648  else {
1649  test->clip_rv3d = NULL;
1650  }
1651 }
1652 
1653 BLI_INLINE bool sculpt_brush_test_clipping(const SculptBrushTest *test, const float co[3])
1654 {
1655  RegionView3D *rv3d = test->clip_rv3d;
1656  if (!rv3d) {
1657  return false;
1658  }
1659  float symm_co[3];
1660  flip_v3_v3(symm_co, co, test->mirror_symmetry_pass);
1661  if (test->radial_symmetry_pass) {
1662  mul_m4_v3(test->symm_rot_mat_inv, symm_co);
1663  }
1664  return ED_view3d_clipping_test(rv3d, symm_co, true);
1665 }
1666 
1667 bool SCULPT_brush_test_sphere(SculptBrushTest *test, const float co[3])
1668 {
1669  float distsq = len_squared_v3v3(co, test->location);
1670 
1671  if (distsq > test->radius_squared) {
1672  return false;
1673  }
1674 
1675  if (sculpt_brush_test_clipping(test, co)) {
1676  return false;
1677  }
1678 
1679  test->dist = sqrtf(distsq);
1680  return true;
1681 }
1682 
1683 bool SCULPT_brush_test_sphere_sq(SculptBrushTest *test, const float co[3])
1684 {
1685  float distsq = len_squared_v3v3(co, test->location);
1686 
1687  if (distsq > test->radius_squared) {
1688  return false;
1689  }
1690  if (sculpt_brush_test_clipping(test, co)) {
1691  return false;
1692  }
1693  test->dist = distsq;
1694  return true;
1695 }
1696 
1697 bool SCULPT_brush_test_sphere_fast(const SculptBrushTest *test, const float co[3])
1698 {
1699  if (sculpt_brush_test_clipping(test, co)) {
1700  return false;
1701  }
1702  return len_squared_v3v3(co, test->location) <= test->radius_squared;
1703 }
1704 
1705 bool SCULPT_brush_test_circle_sq(SculptBrushTest *test, const float co[3])
1706 {
1707  float co_proj[3];
1708  closest_to_plane_normalized_v3(co_proj, test->plane_view, co);
1709  float distsq = len_squared_v3v3(co_proj, test->location);
1710 
1711  if (distsq > test->radius_squared) {
1712  return false;
1713  }
1714 
1715  if (sculpt_brush_test_clipping(test, co)) {
1716  return false;
1717  }
1718 
1719  test->dist = distsq;
1720  return true;
1721 }
1722 
1724  const float co[3],
1725  const float local[4][4],
1726  const float roundness)
1727 {
1728  float side = M_SQRT1_2;
1729  float local_co[3];
1730 
1731  if (sculpt_brush_test_clipping(test, co)) {
1732  return false;
1733  }
1734 
1735  mul_v3_m4v3(local_co, local, co);
1736 
1737  local_co[0] = fabsf(local_co[0]);
1738  local_co[1] = fabsf(local_co[1]);
1739  local_co[2] = fabsf(local_co[2]);
1740 
1741  /* Keep the square and circular brush tips the same size. */
1742  side += (1.0f - side) * roundness;
1743 
1744  const float hardness = 1.0f - roundness;
1745  const float constant_side = hardness * side;
1746  const float falloff_side = roundness * side;
1747 
1748  if (!(local_co[0] <= side && local_co[1] <= side && local_co[2] <= side)) {
1749  /* Outside the square. */
1750  return false;
1751  }
1752  if (min_ff(local_co[0], local_co[1]) > constant_side) {
1753  /* Corner, distance to the center of the corner circle. */
1754  float r_point[3];
1755  copy_v3_fl(r_point, constant_side);
1756  test->dist = len_v2v2(r_point, local_co) / falloff_side;
1757  return true;
1758  }
1759  if (max_ff(local_co[0], local_co[1]) > constant_side) {
1760  /* Side, distance to the square XY axis. */
1761  test->dist = (max_ff(local_co[0], local_co[1]) - constant_side) / falloff_side;
1762  return true;
1763  }
1764 
1765  /* Inside the square, constant distance. */
1766  test->dist = 0.0f;
1767  return true;
1768 }
1769 
1771  SculptBrushTest *test,
1772  char falloff_shape)
1773 {
1774  SCULPT_brush_test_init(ss, test);
1775  SculptBrushTestFn sculpt_brush_test_sq_fn;
1776  if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
1777  sculpt_brush_test_sq_fn = SCULPT_brush_test_sphere_sq;
1778  }
1779  else {
1780  /* PAINT_FALLOFF_SHAPE_TUBE */
1782  sculpt_brush_test_sq_fn = SCULPT_brush_test_circle_sq;
1783  }
1784  return sculpt_brush_test_sq_fn;
1785 }
1786 
1788  char falloff_shape)
1789 {
1790  if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
1791  return ss->cache->sculpt_normal_symm;
1792  }
1793  /* PAINT_FALLOFF_SHAPE_TUBE */
1794  return ss->cache->view_normal;
1795 }
1796 
1797 static float frontface(const Brush *br,
1798  const float sculpt_normal[3],
1799  const short no[3],
1800  const float fno[3])
1801 {
1802  if (!(br->flag & BRUSH_FRONTFACE)) {
1803  return 1.0f;
1804  }
1805 
1806  float dot;
1807  if (no) {
1808  float tmp[3];
1809 
1810  normal_short_to_float_v3(tmp, no);
1811  dot = dot_v3v3(tmp, sculpt_normal);
1812  }
1813  else {
1814  dot = dot_v3v3(fno, sculpt_normal);
1815  }
1816  return dot > 0.0f ? dot : 0.0f;
1817 }
1818 
1819 #if 0
1820 
1821 static bool sculpt_brush_test_cyl(SculptBrushTest *test,
1822  float co[3],
1823  float location[3],
1824  const float area_no[3])
1825 {
1826  if (sculpt_brush_test_sphere_fast(test, co)) {
1827  float t1[3], t2[3], t3[3], dist;
1828 
1829  sub_v3_v3v3(t1, location, co);
1830  sub_v3_v3v3(t2, x2, location);
1831 
1832  cross_v3_v3v3(t3, area_no, t1);
1833 
1834  dist = len_v3(t3) / len_v3(t2);
1835 
1836  test->dist = dist;
1837 
1838  return true;
1839  }
1840 
1841  return false;
1842 }
1843 
1844 #endif
1845 
1846 /* ===== Sculpting =====
1847  */
1848 static void flip_v3(float v[3], const ePaintSymmetryFlags symm)
1849 {
1850  flip_v3_v3(v, v, symm);
1851 }
1852 
1853 static void flip_qt(float quat[3], const ePaintSymmetryFlags symm)
1854 {
1855  flip_qt_qt(quat, quat, symm);
1856 }
1857 
1858 static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle)
1859 {
1860  float mirror[3];
1861  float distsq;
1862 
1863  flip_v3_v3(mirror, cache->true_location, symm);
1864 
1865  if (axis != 0) {
1866  float mat[3][3];
1867  axis_angle_to_mat3_single(mat, axis, angle);
1868  mul_m3_v3(mat, mirror);
1869  }
1870 
1871  distsq = len_squared_v3v3(mirror, cache->true_location);
1872 
1873  if (distsq <= 4.0f * (cache->radius_squared)) {
1874  return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache->radius));
1875  }
1876  return 0.0f;
1877 }
1878 
1880  StrokeCache *cache,
1881  const char symm,
1882  const char axis)
1883 {
1884  float overlap = 0.0f;
1885 
1886  for (int i = 1; i < sd->radial_symm[axis - 'X']; i++) {
1887  const float angle = 2.0f * M_PI * i / sd->radial_symm[axis - 'X'];
1888  overlap += calc_overlap(cache, symm, axis, angle);
1889  }
1890 
1891  return overlap;
1892 }
1893 
1894 static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
1895 {
1897  return 1.0f;
1898  }
1899  float overlap;
1900  const int symm = cache->symmetry;
1901 
1902  overlap = 0.0f;
1903  for (int i = 0; i <= symm; i++) {
1904  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1905  continue;
1906  }
1907 
1908  overlap += calc_overlap(cache, i, 0, 0);
1909 
1910  overlap += calc_radial_symmetry_feather(sd, cache, i, 'X');
1911  overlap += calc_radial_symmetry_feather(sd, cache, i, 'Y');
1912  overlap += calc_radial_symmetry_feather(sd, cache, i, 'Z');
1913  }
1914  return 1.0f / overlap;
1915 }
1916 
1917 /* -------------------------------------------------------------------- */
1931 typedef struct AreaNormalCenterTLSData {
1932  /* 0 = towards view, 1 = flipped */
1933  float area_cos[2][3];
1934  float area_nos[2][3];
1935  int count_no[2];
1936  int count_co[2];
1938 
1939 static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
1940  const int n,
1941  const TaskParallelTLS *__restrict tls)
1942 {
1943  SculptThreadedTaskData *data = userdata;
1944  SculptSession *ss = data->ob->sculpt;
1945  AreaNormalCenterTLSData *anctd = tls->userdata_chunk;
1946  const bool use_area_nos = data->use_area_nos;
1947  const bool use_area_cos = data->use_area_cos;
1948 
1949  PBVHVertexIter vd;
1950  SculptUndoNode *unode = NULL;
1951 
1952  bool use_original = false;
1953  bool normal_test_r, area_test_r;
1954 
1955  if (ss->cache && ss->cache->original) {
1956  unode = SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
1957  use_original = (unode->co || unode->bm_entry);
1958  }
1959 
1960  SculptBrushTest normal_test;
1961  SculptBrushTestFn sculpt_brush_normal_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
1962  ss, &normal_test, data->brush->falloff_shape);
1963 
1964  /* Update the test radius to sample the normal using the normal radius of the brush. */
1965  if (data->brush->ob_mode == OB_MODE_SCULPT) {
1966  float test_radius = sqrtf(normal_test.radius_squared);
1967  test_radius *= data->brush->normal_radius_factor;
1968  normal_test.radius = test_radius;
1969  normal_test.radius_squared = test_radius * test_radius;
1970  }
1971 
1972  SculptBrushTest area_test;
1973  SculptBrushTestFn sculpt_brush_area_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
1974  ss, &area_test, data->brush->falloff_shape);
1975 
1976  if (data->brush->ob_mode == OB_MODE_SCULPT) {
1977  float test_radius = sqrtf(area_test.radius_squared);
1978  /* Layer brush produces artifacts with normal and area radius */
1979  /* Enable area radius control only on Scrape for now */
1980  if (ELEM(data->brush->sculpt_tool, SCULPT_TOOL_SCRAPE, SCULPT_TOOL_FILL) &&
1981  data->brush->area_radius_factor > 0.0f) {
1982  test_radius *= data->brush->area_radius_factor;
1983  if (ss->cache && data->brush->flag2 & BRUSH_AREA_RADIUS_PRESSURE) {
1984  test_radius *= ss->cache->pressure;
1985  }
1986  }
1987  else {
1988  test_radius *= data->brush->normal_radius_factor;
1989  }
1990  area_test.radius = test_radius;
1991  area_test.radius_squared = test_radius * test_radius;
1992  }
1993 
1994  /* When the mesh is edited we can't rely on original coords
1995  * (original mesh may not even have verts in brush radius). */
1996  if (use_original && data->has_bm_orco) {
1997  float(*orco_coords)[3];
1998  int(*orco_tris)[3];
1999  int orco_tris_num;
2000 
2001  BKE_pbvh_node_get_bm_orco_data(data->nodes[n], &orco_tris, &orco_tris_num, &orco_coords);
2002 
2003  for (int i = 0; i < orco_tris_num; i++) {
2004  const float *co_tri[3] = {
2005  orco_coords[orco_tris[i][0]],
2006  orco_coords[orco_tris[i][1]],
2007  orco_coords[orco_tris[i][2]],
2008  };
2009  float co[3];
2010 
2011  closest_on_tri_to_point_v3(co, normal_test.location, UNPACK3(co_tri));
2012 
2013  normal_test_r = sculpt_brush_normal_test_sq_fn(&normal_test, co);
2014  area_test_r = sculpt_brush_area_test_sq_fn(&area_test, co);
2015 
2016  if (!normal_test_r && !area_test_r) {
2017  continue;
2018  }
2019 
2020  float no[3];
2021  int flip_index;
2022 
2023  normal_tri_v3(no, UNPACK3(co_tri));
2024 
2025  flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f);
2026  if (use_area_cos && area_test_r) {
2027  /* Weight the coordinates towards the center. */
2028  float p = 1.0f - (sqrtf(area_test.dist) / area_test.radius);
2029  const float afactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
2030 
2031  float disp[3];
2032  sub_v3_v3v3(disp, co, area_test.location);
2033  mul_v3_fl(disp, 1.0f - afactor);
2034  add_v3_v3v3(co, area_test.location, disp);
2035  add_v3_v3(anctd->area_cos[flip_index], co);
2036 
2037  anctd->count_co[flip_index] += 1;
2038  }
2039  if (use_area_nos && normal_test_r) {
2040  /* Weight the normals towards the center. */
2041  float p = 1.0f - (sqrtf(normal_test.dist) / normal_test.radius);
2042  const float nfactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
2043  mul_v3_fl(no, nfactor);
2044 
2045  add_v3_v3(anctd->area_nos[flip_index], no);
2046  anctd->count_no[flip_index] += 1;
2047  }
2048  }
2049  }
2050  else {
2051  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
2052  float co[3];
2053 
2054  /* For bm_vert only. */
2055  short no_s[3];
2056 
2057  if (use_original) {
2058  if (unode->bm_entry) {
2059  const float *temp_co;
2060  const short *temp_no_s;
2061  BM_log_original_vert_data(ss->bm_log, vd.bm_vert, &temp_co, &temp_no_s);
2062  copy_v3_v3(co, temp_co);
2063  copy_v3_v3_short(no_s, temp_no_s);
2064  }
2065  else {
2066  copy_v3_v3(co, unode->co[vd.i]);
2067  copy_v3_v3_short(no_s, unode->no[vd.i]);
2068  }
2069  }
2070  else {
2071  copy_v3_v3(co, vd.co);
2072  }
2073 
2074  normal_test_r = sculpt_brush_normal_test_sq_fn(&normal_test, co);
2075  area_test_r = sculpt_brush_area_test_sq_fn(&area_test, co);
2076 
2077  if (!normal_test_r && !area_test_r) {
2078  continue;
2079  }
2080 
2081  float no[3];
2082  int flip_index;
2083 
2084  data->any_vertex_sampled = true;
2085 
2086  if (use_original) {
2087  normal_short_to_float_v3(no, no_s);
2088  }
2089  else {
2090  if (vd.no) {
2091  normal_short_to_float_v3(no, vd.no);
2092  }
2093  else {
2094  copy_v3_v3(no, vd.fno);
2095  }
2096  }
2097 
2098  flip_index = (dot_v3v3(ss->cache ? ss->cache->view_normal : ss->cursor_view_normal, no) <=
2099  0.0f);
2100 
2101  if (use_area_cos && area_test_r) {
2102  /* Weight the coordinates towards the center. */
2103  float p = 1.0f - (sqrtf(area_test.dist) / area_test.radius);
2104  const float afactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
2105 
2106  float disp[3];
2107  sub_v3_v3v3(disp, co, area_test.location);
2108  mul_v3_fl(disp, 1.0f - afactor);
2109  add_v3_v3v3(co, area_test.location, disp);
2110 
2111  add_v3_v3(anctd->area_cos[flip_index], co);
2112  anctd->count_co[flip_index] += 1;
2113  }
2114  if (use_area_nos && normal_test_r) {
2115  /* Weight the normals towards the center. */
2116  float p = 1.0f - (sqrtf(normal_test.dist) / normal_test.radius);
2117  const float nfactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
2118  mul_v3_fl(no, nfactor);
2119 
2120  add_v3_v3(anctd->area_nos[flip_index], no);
2121  anctd->count_no[flip_index] += 1;
2122  }
2123  }
2125  }
2126 }
2127 
2128 static void calc_area_normal_and_center_reduce(const void *__restrict UNUSED(userdata),
2129  void *__restrict chunk_join,
2130  void *__restrict chunk)
2131 {
2132  AreaNormalCenterTLSData *join = chunk_join;
2133  AreaNormalCenterTLSData *anctd = chunk;
2134 
2135  /* For flatten center. */
2136  add_v3_v3(join->area_cos[0], anctd->area_cos[0]);
2137  add_v3_v3(join->area_cos[1], anctd->area_cos[1]);
2138 
2139  /* For area normal. */
2140  add_v3_v3(join->area_nos[0], anctd->area_nos[0]);
2141  add_v3_v3(join->area_nos[1], anctd->area_nos[1]);
2142 
2143  /* Weights. */
2144  add_v2_v2_int(join->count_no, anctd->count_no);
2145  add_v2_v2_int(join->count_co, anctd->count_co);
2146 }
2147 
2148 static void calc_area_center(
2149  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3])
2150 {
2151  const Brush *brush = BKE_paint_brush(&sd->paint);
2152  SculptSession *ss = ob->sculpt;
2153  const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
2154  int n;
2155 
2156  /* Intentionally set 'sd' to NULL since we share logic with vertex paint. */
2158  .sd = NULL,
2159  .ob = ob,
2160  .brush = brush,
2161  .nodes = nodes,
2162  .totnode = totnode,
2163  .has_bm_orco = has_bm_orco,
2164  .use_area_cos = true,
2165  };
2166 
2167  AreaNormalCenterTLSData anctd = {{{0}}};
2168 
2169  TaskParallelSettings settings;
2170  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
2172  settings.userdata_chunk = &anctd;
2173  settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
2175 
2176  /* For flatten center. */
2177  for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) {
2178  if (anctd.count_co[n] == 0) {
2179  continue;
2180  }
2181 
2182  mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]);
2183  break;
2184  }
2185 
2186  if (n == 2) {
2187  zero_v3(r_area_co);
2188  }
2189 
2190  if (anctd.count_co[0] == 0 && anctd.count_co[1] == 0) {
2191  if (ss->cache) {
2192  copy_v3_v3(r_area_co, ss->cache->location);
2193  }
2194  }
2195 }
2196 
2198  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
2199 {
2200  const Brush *brush = BKE_paint_brush(&sd->paint);
2201  SCULPT_pbvh_calc_area_normal(brush, ob, nodes, totnode, true, r_area_no);
2202 }
2203 
2204 /* Expose 'calc_area_normal' externally. */
2206  Object *ob,
2207  PBVHNode **nodes,
2208  int totnode,
2209  bool use_threading,
2210  float r_area_no[3])
2211 {
2212  SculptSession *ss = ob->sculpt;
2213  const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
2214 
2215  /* Intentionally set 'sd' to NULL since this is used for vertex paint too. */
2217  .sd = NULL,
2218  .ob = ob,
2219  .brush = brush,
2220  .nodes = nodes,
2221  .totnode = totnode,
2222  .has_bm_orco = has_bm_orco,
2223  .use_area_nos = true,
2224  .any_vertex_sampled = false,
2225  };
2226 
2227  AreaNormalCenterTLSData anctd = {{{0}}};
2228 
2229  TaskParallelSettings settings;
2230  BKE_pbvh_parallel_range_settings(&settings, use_threading, totnode);
2232  settings.userdata_chunk = &anctd;
2233  settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
2235 
2236  /* For area normal. */
2237  for (int i = 0; i < ARRAY_SIZE(anctd.area_nos); i++) {
2238  if (normalize_v3_v3(r_area_no, anctd.area_nos[i]) != 0.0f) {
2239  break;
2240  }
2241  }
2242 
2243  return data.any_vertex_sampled;
2244 }
2245 
2246 /* This calculates flatten center and area normal together,
2247  * amortizing the memory bandwidth and loop overhead to calculate both at the same time. */
2249  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
2250 {
2251  const Brush *brush = BKE_paint_brush(&sd->paint);
2252  SculptSession *ss = ob->sculpt;
2253  const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
2254  int n;
2255 
2256  /* Intentionally set 'sd' to NULL since this is used for vertex paint too. */
2258  .sd = NULL,
2259  .ob = ob,
2260  .brush = brush,
2261  .nodes = nodes,
2262  .totnode = totnode,
2263  .has_bm_orco = has_bm_orco,
2264  .use_area_cos = true,
2265  .use_area_nos = true,
2266  };
2267 
2268  AreaNormalCenterTLSData anctd = {{{0}}};
2269 
2270  TaskParallelSettings settings;
2271  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
2273  settings.userdata_chunk = &anctd;
2274  settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
2276 
2277  /* For flatten center. */
2278  for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) {
2279  if (anctd.count_co[n] == 0) {
2280  continue;
2281  }
2282 
2283  mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]);
2284  break;
2285  }
2286 
2287  if (n == 2) {
2288  zero_v3(r_area_co);
2289  }
2290 
2291  if (anctd.count_co[0] == 0 && anctd.count_co[1] == 0) {
2292  if (ss->cache) {
2293  copy_v3_v3(r_area_co, ss->cache->location);
2294  }
2295  }
2296 
2297  /* For area normal. */
2298  for (n = 0; n < ARRAY_SIZE(anctd.area_nos); n++) {
2299  if (normalize_v3_v3(r_area_no, anctd.area_nos[n]) != 0.0f) {
2300  break;
2301  }
2302  }
2303 }
2304 
2312 static float brush_strength(const Sculpt *sd,
2313  const StrokeCache *cache,
2314  const float feather,
2315  const UnifiedPaintSettings *ups)
2316 {
2317  const Scene *scene = cache->vc->scene;
2318  const Brush *brush = BKE_paint_brush((Paint *)&sd->paint);
2319 
2320  /* Primary strength input; square it to make lower values more sensitive. */
2321  const float root_alpha = BKE_brush_alpha_get(scene, brush);
2322  const float alpha = root_alpha * root_alpha;
2323  const float dir = (brush->flag & BRUSH_DIR_IN) ? -1.0f : 1.0f;
2324  const float pressure = BKE_brush_use_alpha_pressure(brush) ? cache->pressure : 1.0f;
2325  const float pen_flip = cache->pen_flip ? -1.0f : 1.0f;
2326  const float invert = cache->invert ? -1.0f : 1.0f;
2327  float overlap = ups->overlap_factor;
2328  /* Spacing is integer percentage of radius, divide by 50 to get
2329  * normalized diameter. */
2330 
2331  float flip = dir * invert * pen_flip;
2332  if (brush->flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
2333  flip = 1.0f;
2334  }
2335 
2336  /* Pressure final value after being tweaked depending on the brush. */
2337  float final_pressure;
2338 
2339  switch (brush->sculpt_tool) {
2340  case SCULPT_TOOL_CLAY:
2341  final_pressure = pow4f(pressure);
2342  overlap = (1.0f + overlap) / 2.0f;
2343  return 0.25f * alpha * flip * final_pressure * overlap * feather;
2344  case SCULPT_TOOL_DRAW:
2346  case SCULPT_TOOL_LAYER:
2347  return alpha * flip * pressure * overlap * feather;
2349  return alpha * pressure * overlap * feather;
2350  case SCULPT_TOOL_CLOTH:
2352  /* Grab deform uses the same falloff as a regular grab brush. */
2353  return root_alpha * feather;
2354  }
2355  else if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_SNAKE_HOOK) {
2356  return root_alpha * feather * pressure * overlap;
2357  }
2358  else if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_EXPAND) {
2359  /* Expand is more sensible to strength as it keeps expanding the cloth when sculpting over
2360  * the same vertices. */
2361  return 0.1f * alpha * flip * pressure * overlap * feather;
2362  }
2363  else {
2364  /* Multiply by 10 by default to get a larger range of strength depending on the size of the
2365  * brush and object. */
2366  return 10.0f * alpha * flip * pressure * overlap * feather;
2367  }
2369  return alpha * pressure * overlap * feather;
2371  return alpha * pressure * overlap * feather * 2.0f;
2372  case SCULPT_TOOL_PAINT:
2373  final_pressure = pressure * pressure;
2374  return final_pressure * overlap * feather;
2375  case SCULPT_TOOL_SMEAR:
2377  return alpha * pressure * overlap * feather;
2379  /* Clay Strips needs less strength to compensate the curve. */
2380  final_pressure = powf(pressure, 1.5f);
2381  return alpha * flip * final_pressure * overlap * feather * 0.3f;
2383  final_pressure = pressure * pressure;
2384  return alpha * flip * final_pressure * overlap * feather * 1.3f;
2385 
2386  case SCULPT_TOOL_MASK:
2387  overlap = (1.0f + overlap) / 2.0f;
2388  switch ((BrushMaskTool)brush->mask_tool) {
2389  case BRUSH_MASK_DRAW:
2390  return alpha * flip * pressure * overlap * feather;
2391  case BRUSH_MASK_SMOOTH:
2392  return alpha * pressure * feather;
2393  }
2394  BLI_assert(!"Not supposed to happen");
2395  return 0.0f;
2396 
2397  case SCULPT_TOOL_CREASE:
2398  case SCULPT_TOOL_BLOB:
2399  return alpha * flip * pressure * overlap * feather;
2400 
2401  case SCULPT_TOOL_INFLATE:
2402  if (flip > 0.0f) {
2403  return 0.250f * alpha * flip * pressure * overlap * feather;
2404  }
2405  else {
2406  return 0.125f * alpha * flip * pressure * overlap * feather;
2407  }
2408 
2410  overlap = (1.0f + overlap) / 2.0f;
2411  return alpha * flip * pressure * overlap * feather;
2412 
2413  case SCULPT_TOOL_FILL:
2414  case SCULPT_TOOL_SCRAPE:
2415  case SCULPT_TOOL_FLATTEN:
2416  if (flip > 0.0f) {
2417  overlap = (1.0f + overlap) / 2.0f;
2418  return alpha * flip * pressure * overlap * feather;
2419  }
2420  else {
2421  /* Reduce strength for DEEPEN, PEAKS, and CONTRAST. */
2422  return 0.5f * alpha * flip * pressure * overlap * feather;
2423  }
2424 
2425  case SCULPT_TOOL_SMOOTH:
2426  return flip * alpha * pressure * feather;
2427 
2428  case SCULPT_TOOL_PINCH:
2429  if (flip > 0.0f) {
2430  return alpha * flip * pressure * overlap * feather;
2431  }
2432  else {
2433  return 0.25f * alpha * flip * pressure * overlap * feather;
2434  }
2435 
2436  case SCULPT_TOOL_NUDGE:
2437  overlap = (1.0f + overlap) / 2.0f;
2438  return alpha * pressure * overlap * feather;
2439 
2440  case SCULPT_TOOL_THUMB:
2441  return alpha * pressure * feather;
2442 
2444  return root_alpha * feather;
2445 
2446  case SCULPT_TOOL_GRAB:
2447  return root_alpha * feather;
2448 
2449  case SCULPT_TOOL_ROTATE:
2450  return alpha * pressure * feather;
2451 
2453  case SCULPT_TOOL_POSE:
2454  case SCULPT_TOOL_BOUNDARY:
2455  return root_alpha * feather;
2456 
2457  default:
2458  return 0.0f;
2459  }
2460 }
2461 
2462 /* Return a multiplier for brush strength on a particular vertex. */
2464  const Brush *br,
2465  const float brush_point[3],
2466  const float len,
2467  const short vno[3],
2468  const float fno[3],
2469  const float mask,
2470  const int vertex_index,
2471  const int thread_id)
2472 {
2473  StrokeCache *cache = ss->cache;
2474  const Scene *scene = cache->vc->scene;
2475  const MTex *mtex = &br->mtex;
2476  float avg = 1.0f;
2477  float rgba[4];
2478  float point[3];
2479 
2480  sub_v3_v3v3(point, brush_point, cache->plane_offset);
2481 
2482  if (!mtex->tex) {
2483  avg = 1.0f;
2484  }
2485  else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) {
2486  /* Get strength by feeding the vertex location directly into a texture. */
2487  avg = BKE_brush_sample_tex_3d(scene, br, point, rgba, 0, ss->tex_pool);
2488  }
2489  else if (ss->texcache) {
2490  float symm_point[3], point_2d[2];
2491  /* Quite warnings. */
2492  float x = 0.0f, y = 0.0f;
2493 
2494  /* If the active area is being applied for symmetry, flip it
2495  * across the symmetry axis and rotate it back to the original
2496  * position in order to project it. This insures that the
2497  * brush texture will be oriented correctly. */
2498  if (cache->radial_symmetry_pass) {
2499  mul_m4_v3(cache->symm_rot_mat_inv, point);
2500  }
2501  flip_v3_v3(symm_point, point, cache->mirror_symmetry_pass);
2502 
2503  ED_view3d_project_float_v2_m4(cache->vc->region, symm_point, point_2d, cache->projection_mat);
2504 
2505  /* Still no symmetry supported for other paint modes.
2506  * Sculpt does it DIY. */
2507  if (mtex->brush_map_mode == MTEX_MAP_MODE_AREA) {
2508  /* Similar to fixed mode, but projects from brush angle
2509  * rather than view direction. */
2510 
2511  mul_m4_v3(cache->brush_local_mat, symm_point);
2512 
2513  x = symm_point[0];
2514  y = symm_point[1];
2515 
2516  x *= br->mtex.size[0];
2517  y *= br->mtex.size[1];
2518 
2519  x += br->mtex.ofs[0];
2520  y += br->mtex.ofs[1];
2521 
2522  avg = paint_get_tex_pixel(&br->mtex, x, y, ss->tex_pool, thread_id);
2523 
2524  avg += br->texture_sample_bias;
2525  }
2526  else {
2527  const float point_3d[3] = {point_2d[0], point_2d[1], 0.0f};
2528  avg = BKE_brush_sample_tex_3d(scene, br, point_3d, rgba, 0, ss->tex_pool);
2529  }
2530  }
2531 
2532  /* Hardness. */
2533  float final_len = len;
2534  const float hardness = cache->paint_brush.hardness;
2535  float p = len / cache->radius;
2536  if (p < hardness) {
2537  final_len = 0.0f;
2538  }
2539  else if (hardness == 1.0f) {
2540  final_len = cache->radius;
2541  }
2542  else {
2543  p = (p - hardness) / (1.0f - hardness);
2544  final_len = p * cache->radius;
2545  }
2546 
2547  /* Falloff curve. */
2548  avg *= BKE_brush_curve_strength(br, final_len, cache->radius);
2549  avg *= frontface(br, cache->view_normal, vno, fno);
2550 
2551  /* Paint mask. */
2552  avg *= 1.0f - mask;
2553 
2554  /* Auto-masking. */
2555  avg *= SCULPT_automasking_factor_get(cache->automasking, ss, vertex_index);
2556 
2557  return avg;
2558 }
2559 
2560 /* Test AABB against sphere. */
2562 {
2563  SculptSearchSphereData *data = data_v;
2564  const float *center;
2565  float nearest[3];
2566  if (data->center) {
2567  center = data->center;
2568  }
2569  else {
2570  center = data->ss->cache ? data->ss->cache->location : data->ss->cursor_location;
2571  }
2572  float t[3], bb_min[3], bb_max[3];
2573 
2574  if (data->ignore_fully_ineffective) {
2576  return false;
2577  }
2579  return false;
2580  }
2581  }
2582 
2583  if (data->original) {
2584  BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
2585  }
2586  else {
2587  BKE_pbvh_node_get_BB(node, bb_min, bb_max);
2588  }
2589 
2590  for (int i = 0; i < 3; i++) {
2591  if (bb_min[i] > center[i]) {
2592  nearest[i] = bb_min[i];
2593  }
2594  else if (bb_max[i] < center[i]) {
2595  nearest[i] = bb_max[i];
2596  }
2597  else {
2598  nearest[i] = center[i];
2599  }
2600  }
2601 
2602  sub_v3_v3v3(t, center, nearest);
2603 
2604  return len_squared_v3(t) < data->radius_squared;
2605 }
2606 
2607 /* 2D projection (distance to line). */
2609 {
2610  SculptSearchCircleData *data = data_v;
2611  float bb_min[3], bb_max[3];
2612 
2613  if (data->ignore_fully_ineffective) {
2615  return false;
2616  }
2617  }
2618 
2619  if (data->original) {
2620  BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
2621  }
2622  else {
2623  BKE_pbvh_node_get_BB(node, bb_min, bb_min);
2624  }
2625 
2626  float dummy_co[3], dummy_depth;
2627  const float dist_sq = dist_squared_ray_to_aabb_v3(
2628  data->dist_ray_to_aabb_precalc, bb_min, bb_max, dummy_co, &dummy_depth);
2629 
2630  /* Seems like debug code.
2631  * Maybe this function can just return true if the node is not fully masked. */
2632  return dist_sq < data->radius_squared || true;
2633 }
2634 
2638 void SCULPT_clip(Sculpt *sd, SculptSession *ss, float co[3], const float val[3])
2639 {
2640  for (int i = 0; i < 3; i++) {
2641  if (sd->flags & (SCULPT_LOCK_X << i)) {
2642  continue;
2643  }
2644 
2645  bool do_clip = false;
2646  float co_clip[3];
2647  if (ss->cache && (ss->cache->flag & (CLIP_X << i))) {
2648  /* Take possible mirror object into account. */
2649  mul_v3_m4v3(co_clip, ss->cache->clip_mirror_mtx, co);
2650 
2651  if (fabsf(co_clip[i]) <= ss->cache->clip_tolerance[i]) {
2652  co_clip[i] = 0.0f;
2653  float imtx[4][4];
2654  invert_m4_m4(imtx, ss->cache->clip_mirror_mtx);
2655  mul_m4_v3(imtx, co_clip);
2656  do_clip = true;
2657  }
2658  }
2659 
2660  if (do_clip) {
2661  co[i] = co_clip[i];
2662  }
2663  else {
2664  co[i] = val[i];
2665  }
2666  }
2667 }
2668 
2670  Sculpt *sd,
2671  bool use_original,
2672  int *r_totnode)
2673 {
2674  SculptSession *ss = ob->sculpt;
2675  PBVHNode **nodes = NULL;
2677  .ss = ss,
2678  .sd = sd,
2679  .radius_squared = ss->cursor_radius,
2680  .original = use_original,
2681  .ignore_fully_ineffective = false,
2682  .center = NULL,
2683  };
2684  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
2685  return nodes;
2686 }
2687 
2689  Sculpt *sd,
2690  const Brush *brush,
2691  bool use_original,
2692  float radius_scale,
2693  int *r_totnode)
2694 {
2695  SculptSession *ss = ob->sculpt;
2696  PBVHNode **nodes = NULL;
2697 
2698  /* Build a list of all nodes that are potentially within the cursor or brush's area of influence.
2699  */
2700  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
2702  .ss = ss,
2703  .sd = sd,
2704  .radius_squared = square_f(ss->cache->radius * radius_scale),
2705  .original = use_original,
2706  .ignore_fully_ineffective = brush->sculpt_tool != SCULPT_TOOL_MASK,
2707  .center = NULL,
2708  };
2709  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
2710  }
2711  else {
2712  struct DistRayAABB_Precalc dist_ray_to_aabb_precalc;
2714  &dist_ray_to_aabb_precalc, ss->cache->location, ss->cache->view_normal);
2716  .ss = ss,
2717  .sd = sd,
2718  .radius_squared = ss->cache ? square_f(ss->cache->radius * radius_scale) :
2719  ss->cursor_radius,
2720  .original = use_original,
2721  .dist_ray_to_aabb_precalc = &dist_ray_to_aabb_precalc,
2722  .ignore_fully_ineffective = brush->sculpt_tool != SCULPT_TOOL_MASK,
2723  };
2724  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_circle_cb, &data, &nodes, r_totnode);
2725  }
2726  return nodes;
2727 }
2728 
2729 /* Calculate primary direction of movement for many brushes. */
2731  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
2732 {
2733  const Brush *brush = BKE_paint_brush(&sd->paint);
2734  const SculptSession *ss = ob->sculpt;
2735 
2736  switch (brush->sculpt_plane) {
2737  case SCULPT_DISP_DIR_VIEW:
2738  copy_v3_v3(r_area_no, ss->cache->true_view_normal);
2739  break;
2740 
2741  case SCULPT_DISP_DIR_X:
2742  ARRAY_SET_ITEMS(r_area_no, 1.0f, 0.0f, 0.0f);
2743  break;
2744 
2745  case SCULPT_DISP_DIR_Y:
2746  ARRAY_SET_ITEMS(r_area_no, 0.0f, 1.0f, 0.0f);
2747  break;
2748 
2749  case SCULPT_DISP_DIR_Z:
2750  ARRAY_SET_ITEMS(r_area_no, 0.0f, 0.0f, 1.0f);
2751  break;
2752 
2753  case SCULPT_DISP_DIR_AREA:
2754  SCULPT_calc_area_normal(sd, ob, nodes, totnode, r_area_no);
2755  break;
2756 
2757  default:
2758  break;
2759  }
2760 }
2761 
2762 static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
2763 {
2764  const Brush *brush = BKE_paint_brush(&sd->paint);
2765  StrokeCache *cache = ob->sculpt->cache;
2766  /* Grab brush does not update the sculpt normal during a stroke. */
2767  const bool update_normal =
2768  !(brush->flag & BRUSH_ORIGINAL_NORMAL) && !(brush->sculpt_tool == SCULPT_TOOL_GRAB) &&
2769  !(brush->sculpt_tool == SCULPT_TOOL_THUMB && !(brush->flag & BRUSH_ANCHORED)) &&
2770  !(brush->sculpt_tool == SCULPT_TOOL_ELASTIC_DEFORM) &&
2771  !(brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK && cache->normal_weight > 0.0f);
2772 
2773  if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0 &&
2774  (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(cache) || update_normal)) {
2775  calc_sculpt_normal(sd, ob, nodes, totnode, cache->sculpt_normal);
2776  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
2778  normalize_v3(cache->sculpt_normal);
2779  }
2781  }
2782  else {
2785  mul_m4_v3(cache->symm_rot_mat, cache->sculpt_normal_symm);
2786  }
2787 }
2788 
2789 static void calc_local_y(ViewContext *vc, const float center[3], float y[3])
2790 {
2791  Object *ob = vc->obact;
2792  float loc[3], mval_f[2] = {0.0f, 1.0f};
2793  float zfac;
2794 
2795  mul_v3_m4v3(loc, ob->imat, center);
2796  zfac = ED_view3d_calc_zfac(vc->rv3d, loc, NULL);
2797 
2798  ED_view3d_win_to_delta(vc->region, mval_f, y, zfac);
2799  normalize_v3(y);
2800 
2801  add_v3_v3(y, ob->loc);
2802  mul_m4_v3(ob->imat, y);
2803 }
2804 
2805 static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat[4][4])
2806 {
2807  const StrokeCache *cache = ob->sculpt->cache;
2808  float tmat[4][4];
2809  float mat[4][4];
2810  float scale[4][4];
2811  float angle, v[3];
2812  float up[3];
2813 
2814  /* Ensure `ob->imat` is up to date. */
2815  invert_m4_m4(ob->imat, ob->obmat);
2816 
2817  /* Initialize last column of matrix. */
2818  mat[0][3] = 0.0f;
2819  mat[1][3] = 0.0f;
2820  mat[2][3] = 0.0f;
2821  mat[3][3] = 1.0f;
2822 
2823  /* Get view's up vector in object-space. */
2824  calc_local_y(cache->vc, cache->location, up);
2825 
2826  /* Calculate the X axis of the local matrix. */
2827  cross_v3_v3v3(v, up, cache->sculpt_normal);
2828  /* Apply rotation (user angle, rake, etc.) to X axis. */
2829  angle = brush->mtex.rot - cache->special_rotation;
2830  rotate_v3_v3v3fl(mat[0], v, cache->sculpt_normal, angle);
2831 
2832  /* Get other axes. */
2833  cross_v3_v3v3(mat[1], cache->sculpt_normal, mat[0]);
2834  copy_v3_v3(mat[2], cache->sculpt_normal);
2835 
2836  /* Set location. */
2837  copy_v3_v3(mat[3], cache->location);
2838 
2839  /* Scale by brush radius. */
2840  normalize_m4(mat);
2841  scale_m4_fl(scale, cache->radius);
2842  mul_m4_m4m4(tmat, mat, scale);
2843 
2844  /* Return inverse (for converting from model-space coords to local area coords). */
2845  invert_m4_m4(local_mat, tmat);
2846 }
2847 
2848 #define SCULPT_TILT_SENSITIVITY 0.7f
2849 void SCULPT_tilt_apply_to_normal(float r_normal[3], StrokeCache *cache, const float tilt_strength)
2850 {
2851  if (!U.experimental.use_sculpt_tools_tilt) {
2852  return;
2853  }
2854  const float rot_max = M_PI_2 * tilt_strength * SCULPT_TILT_SENSITIVITY;
2855  mul_v3_mat3_m4v3(r_normal, cache->vc->obact->obmat, r_normal);
2856  float normal_tilt_y[3];
2857  rotate_v3_v3v3fl(normal_tilt_y, r_normal, cache->vc->rv3d->viewinv[0], cache->y_tilt * rot_max);
2858  float normal_tilt_xy[3];
2860  normal_tilt_xy, normal_tilt_y, cache->vc->rv3d->viewinv[1], cache->x_tilt * rot_max);
2861  mul_v3_mat3_m4v3(r_normal, cache->vc->obact->imat, normal_tilt_xy);
2862  normalize_v3(r_normal);
2863 }
2864 
2865 void SCULPT_tilt_effective_normal_get(const SculptSession *ss, const Brush *brush, float r_no[3])
2866 {
2867  copy_v3_v3(r_no, ss->cache->sculpt_normal_symm);
2869 }
2870 
2871 static void update_brush_local_mat(Sculpt *sd, Object *ob)
2872 {
2873  StrokeCache *cache = ob->sculpt->cache;
2874 
2875  if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0) {
2877  }
2878 }
2879 
2880 typedef struct {
2882  const float *ray_start;
2883  const float *ray_normal;
2884  bool hit;
2885  float depth;
2886  bool original;
2887 
2889  float *face_normal;
2890 
2892 
2893  struct IsectRayPrecalc isect_precalc;
2895 
2896 typedef struct {
2898  const float *ray_start, *ray_normal;
2899  bool hit;
2900  float depth;
2902  bool original;
2904 
2905 static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata,
2906  const int n,
2907  const TaskParallelTLS *__restrict tls)
2908 {
2909  SculptThreadedTaskData *data = userdata;
2910  SculptSession *ss = data->ob->sculpt;
2911  Sculpt *sd = data->sd;
2912  const Brush *brush = data->brush;
2913 
2914  float direction[3];
2915  copy_v3_v3(direction, ss->cache->grab_delta_symmetry);
2916 
2917  float tmp[3];
2918  mul_v3_v3fl(
2919  tmp, ss->cache->sculpt_normal_symm, dot_v3v3(ss->cache->sculpt_normal_symm, direction));
2920  sub_v3_v3(direction, tmp);
2921  normalize_v3(direction);
2922 
2923  /* Cancel if there's no grab data. */
2924  if (is_zero_v3(direction)) {
2925  return;
2926  }
2927 
2928  const float bstrength = clamp_f(data->strength, 0.0f, 1.0f);
2929 
2930  SculptBrushTest test;
2932  ss, &test, data->brush->falloff_shape);
2933  const int thread_id = BLI_task_parallel_thread_id(tls);
2934 
2935  PBVHVertexIter vd;
2936  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
2937  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
2938  continue;
2939  }
2940  const float fade =
2941  bstrength *
2943  ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, *vd.mask, vd.index, thread_id) *
2944  ss->cache->pressure;
2945 
2946  float avg[3], val[3];
2947 
2948  SCULPT_bmesh_four_neighbor_average(avg, direction, vd.bm_vert);
2949 
2950  sub_v3_v3v3(val, avg, vd.co);
2951 
2952  madd_v3_v3v3fl(val, vd.co, val, fade);
2953 
2954  SCULPT_clip(sd, ss, vd.co, val);
2955 
2956  if (vd.mvert) {
2958  }
2959  }
2961 }
2962 
2964  Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength)
2965 {
2966  Brush *brush = BKE_paint_brush(&sd->paint);
2967  const float strength = clamp_f(bstrength, 0.0f, 1.0f);
2968 
2969  /* Interactions increase both strength and quality. */
2970  const int iterations = 3;
2971 
2972  int iteration;
2973  const int count = iterations * strength + 1;
2974  const float factor = iterations * strength / count;
2975 
2976  for (iteration = 0; iteration <= count; iteration++) {
2977 
2979  .sd = sd,
2980  .ob = ob,
2981  .brush = brush,
2982  .nodes = nodes,
2983  .strength = factor,
2984  };
2985  TaskParallelSettings settings;
2986  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
2987 
2989  }
2990 }
2991 
2992 static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata,
2993  const int n,
2994  const TaskParallelTLS *__restrict tls)
2995 {
2996  SculptThreadedTaskData *data = userdata;
2997  SculptSession *ss = data->ob->sculpt;
2998  const Brush *brush = data->brush;
2999  const float bstrength = ss->cache->bstrength;
3000 
3001  PBVHVertexIter vd;
3002 
3003  SculptBrushTest test;
3005  ss, &test, data->brush->falloff_shape);
3006  const int thread_id = BLI_task_parallel_thread_id(tls);
3007 
3008  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3009  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3010  continue;
3011  }
3012 
3013  const float fade = SCULPT_brush_strength_factor(
3014  ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, vd.index, thread_id);
3015 
3016  if (bstrength > 0.0f) {
3017  (*vd.mask) += fade * bstrength * (1.0f - *vd.mask);
3018  }
3019  else {
3020  (*vd.mask) += fade * bstrength * (*vd.mask);
3021  }
3022  *vd.mask = clamp_f(*vd.mask, 0.0f, 1.0f);
3023 
3024  if (vd.mvert) {
3026  }
3028  }
3029 }
3030 
3031 static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3032 {
3033  Brush *brush = BKE_paint_brush(&sd->paint);
3034 
3035  /* Threaded loop over nodes. */
3037  .sd = sd,
3038  .ob = ob,
3039  .brush = brush,
3040  .nodes = nodes,
3041  };
3042 
3043  TaskParallelSettings settings;
3044  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3046 }
3047 
3048 static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3049 {
3050  SculptSession *ss = ob->sculpt;
3051  Brush *brush = BKE_paint_brush(&sd->paint);
3052 
3053  switch ((BrushMaskTool)brush->mask_tool) {
3054  case BRUSH_MASK_DRAW:
3055  do_mask_brush_draw(sd, ob, nodes, totnode);
3056  break;
3057  case BRUSH_MASK_SMOOTH:
3058  SCULPT_smooth(sd, ob, nodes, totnode, ss->cache->bstrength, true);
3059  break;
3060  }
3061 }
3062 
3063 /* -------------------------------------------------------------------- */
3067 static void do_displacement_eraser_brush_task_cb_ex(void *__restrict userdata,
3068  const int n,
3069  const TaskParallelTLS *__restrict tls)
3070 {
3071  SculptThreadedTaskData *data = userdata;
3072  SculptSession *ss = data->ob->sculpt;
3073  const Brush *brush = data->brush;
3074  const float bstrength = clamp_f(ss->cache->bstrength, 0.0f, 1.0f);
3075 
3076  float(*proxy)[3] = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3077 
3078  SculptBrushTest test;
3080  ss, &test, data->brush->falloff_shape);
3081  const int thread_id = BLI_task_parallel_thread_id(tls);
3082 
3083  PBVHVertexIter vd;
3084  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3085  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3086  continue;
3087  }
3088  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
3089  brush,
3090  vd.co,
3091  sqrtf(test.dist),
3092  vd.no,
3093  vd.fno,
3094  vd.mask ? *vd.mask : 0.0f,
3095  vd.index,
3096  thread_id);
3097 
3098  float limit_co[3];
3099  float disp[3];
3100  SCULPT_vertex_limit_surface_get(ss, vd.index, limit_co);
3101  sub_v3_v3v3(disp, limit_co, vd.co);
3102  mul_v3_v3fl(proxy[vd.i], disp, fade);
3103 
3104  if (vd.mvert) {
3106  }
3107  }
3109 }
3110 
3111 static void do_displacement_eraser_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3112 {
3113  Brush *brush = BKE_paint_brush(&sd->paint);
3114  BKE_curvemapping_init(brush->curve);
3115 
3116  /* Threaded loop over nodes. */
3118  .sd = sd,
3119  .ob = ob,
3120  .brush = brush,
3121  .nodes = nodes,
3122  };
3123 
3124  TaskParallelSettings settings;
3125  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3127 }
3128 
3134 static void do_displacement_smear_brush_task_cb_ex(void *__restrict userdata,
3135  const int n,
3136  const TaskParallelTLS *__restrict tls)
3137 {
3138  SculptThreadedTaskData *data = userdata;
3139  SculptSession *ss = data->ob->sculpt;
3140  const Brush *brush = data->brush;
3141  const float bstrength = clamp_f(ss->cache->bstrength, 0.0f, 1.0f);
3142 
3143  SculptBrushTest test;
3145  ss, &test, data->brush->falloff_shape);
3146  const int thread_id = BLI_task_parallel_thread_id(tls);
3147 
3148  PBVHVertexIter vd;
3149  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3150  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3151  continue;
3152  }
3153  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
3154  brush,
3155  vd.co,
3156  sqrtf(test.dist),
3157  vd.no,
3158  vd.fno,
3159  vd.mask ? *vd.mask : 0.0f,
3160  vd.index,
3161  thread_id);
3162 
3163  float current_disp[3];
3164  float current_disp_norm[3];
3165  float interp_limit_surface_disp[3];
3166 
3167  copy_v3_v3(interp_limit_surface_disp, ss->cache->prev_displacement[vd.index]);
3168 
3169  switch (brush->smear_deform_type) {
3171  sub_v3_v3v3(current_disp, ss->cache->location, ss->cache->last_location);
3172  break;
3174  sub_v3_v3v3(current_disp, ss->cache->location, vd.co);
3175  break;
3177  sub_v3_v3v3(current_disp, vd.co, ss->cache->location);
3178  break;
3179  }
3180 
3181  normalize_v3_v3(current_disp_norm, current_disp);
3182  mul_v3_v3fl(current_disp, current_disp_norm, ss->cache->bstrength);
3183 
3184  float weights_accum = 1.0f;
3185 
3188  float vertex_disp[3];
3189  float vertex_disp_norm[3];
3190  float neighbor_limit_co[3];
3191  SCULPT_vertex_limit_surface_get(ss, ni.index, neighbor_limit_co);
3192  sub_v3_v3v3(vertex_disp,
3193  ss->cache->limit_surface_co[ni.index],
3194  ss->cache->limit_surface_co[vd.index]);
3195  const float *neighbor_limit_surface_disp = ss->cache->prev_displacement[ni.index];
3196  normalize_v3_v3(vertex_disp_norm, vertex_disp);
3197 
3198  if (dot_v3v3(current_disp_norm, vertex_disp_norm) >= 0.0f) {
3199  continue;
3200  }
3201 
3202  const float disp_interp = clamp_f(
3203  -dot_v3v3(current_disp_norm, vertex_disp_norm), 0.0f, 1.0f);
3204  madd_v3_v3fl(interp_limit_surface_disp, neighbor_limit_surface_disp, disp_interp);
3205  weights_accum += disp_interp;
3206  }
3208 
3209  mul_v3_fl(interp_limit_surface_disp, 1.0f / weights_accum);
3210 
3211  float new_co[3];
3212  add_v3_v3v3(new_co, ss->cache->limit_surface_co[vd.index], interp_limit_surface_disp);
3213  interp_v3_v3v3(vd.co, vd.co, new_co, fade);
3214 
3215  if (vd.mvert) {
3217  }
3218  }
3220 }
3221 
3223  void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
3224 {
3225  SculptThreadedTaskData *data = userdata;
3226  SculptSession *ss = data->ob->sculpt;
3227 
3228  PBVHVertexIter vd;
3229  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3231  SCULPT_vertex_co_get(ss, vd.index),
3232  ss->cache->limit_surface_co[vd.index]);
3233  }
3235 }
3236 
3237 static void do_displacement_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3238 {
3239  Brush *brush = BKE_paint_brush(&sd->paint);
3240  SculptSession *ss = ob->sculpt;
3241 
3242  BKE_curvemapping_init(brush->curve);
3243 
3244  const int totvert = SCULPT_vertex_count_get(ss);
3245  if (!ss->cache->prev_displacement) {
3247  totvert, sizeof(float[3]), "prev displacement");
3248  ss->cache->limit_surface_co = MEM_malloc_arrayN(totvert, sizeof(float[3]), "limit surface co");
3249  for (int i = 0; i < totvert; i++) {
3252  SCULPT_vertex_co_get(ss, i),
3253  ss->cache->limit_surface_co[i]);
3254  }
3255  }
3256  /* Threaded loop over nodes. */
3258  .sd = sd,
3259  .ob = ob,
3260  .brush = brush,
3261  .nodes = nodes,
3262  };
3263 
3264  TaskParallelSettings settings;
3265  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3267  0, totnode, &data, do_displacement_smear_store_prev_disp_task_cb_ex, &settings);
3269 }
3270 
3273 static void do_draw_brush_task_cb_ex(void *__restrict userdata,
3274  const int n,
3275  const TaskParallelTLS *__restrict tls)
3276 {
3277  SculptThreadedTaskData *data = userdata;
3278  SculptSession *ss = data->ob->sculpt;
3279  const Brush *brush = data->brush;
3280  const float *offset = data->offset;
3281 
3282  PBVHVertexIter vd;
3283  float(*proxy)[3];
3284 
3285  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3286 
3287  SculptBrushTest test;
3289  ss, &test, data->brush->falloff_shape);
3290  const int thread_id = BLI_task_parallel_thread_id(tls);
3291 
3292  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3293  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3294  continue;
3295  }
3296  /* Offset vertex. */
3297  const float fade = SCULPT_brush_strength_factor(ss,
3298  brush,
3299  vd.co,
3300  sqrtf(test.dist),
3301  vd.no,
3302  vd.fno,
3303  vd.mask ? *vd.mask : 0.0f,
3304  vd.index,
3305  thread_id);
3306 
3307  mul_v3_v3fl(proxy[vd.i], offset, fade);
3308 
3309  if (vd.mvert) {
3311  }
3312  }
3314 }
3315 
3316 static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3317 {
3318  SculptSession *ss = ob->sculpt;
3319  Brush *brush = BKE_paint_brush(&sd->paint);
3320  float offset[3];
3321  const float bstrength = ss->cache->bstrength;
3322 
3323  /* Offset with as much as possible factored in already. */
3324  float effective_normal[3];
3325  SCULPT_tilt_effective_normal_get(ss, brush, effective_normal);
3326  mul_v3_v3fl(offset, effective_normal, ss->cache->radius);
3327  mul_v3_v3(offset, ss->cache->scale);
3328  mul_v3_fl(offset, bstrength);
3329 
3330  /* XXX - this shouldn't be necessary, but sculpting crashes in blender2.8 otherwise
3331  * initialize before threads so they can do curve mapping. */
3332  BKE_curvemapping_init(brush->curve);
3333 
3334  /* Threaded loop over nodes. */
3336  .sd = sd,
3337  .ob = ob,
3338  .brush = brush,
3339  .nodes = nodes,
3340  .offset = offset,
3341  };
3342 
3343  TaskParallelSettings settings;
3344  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3345  BLI_task_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings);
3346 }
3347 
3348 static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata,
3349  const int n,
3350  const TaskParallelTLS *__restrict tls)
3351 {
3352  SculptThreadedTaskData *data = userdata;
3353  SculptSession *ss = data->ob->sculpt;
3354  const Brush *brush = data->brush;
3355  const float *offset = data->offset;
3356 
3357  PBVHVertexIter vd;
3358  SculptOrigVertData orig_data;
3359  float(*proxy)[3];
3360 
3361  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
3362 
3363  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3364 
3365  SculptBrushTest test;
3367  ss, &test, data->brush->falloff_shape);
3368  const int thread_id = BLI_task_parallel_thread_id(tls);
3369 
3370  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3371  SCULPT_orig_vert_data_update(&orig_data, &vd);
3372  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
3373  continue;
3374  }
3375  /* Offset vertex. */
3376  const float fade = SCULPT_brush_strength_factor(ss,
3377  brush,
3378  orig_data.co,
3379  sqrtf(test.dist),
3380  orig_data.no,
3381  NULL,
3382  vd.mask ? *vd.mask : 0.0f,
3383  vd.index,
3384  thread_id);
3385 
3386  mul_v3_v3fl(proxy[vd.i], offset, fade);
3387 
3388  if (vd.mvert) {
3390  }
3391  }
3393 }
3394 
3395 static void do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3396 {
3397  SculptSession *ss = ob->sculpt;
3398  Brush *brush = BKE_paint_brush(&sd->paint);
3399  float offset[3];
3400  const float bstrength = ss->cache->bstrength;
3401 
3402  /* Offset with as much as possible factored in already. */
3403  float effective_normal[3];
3404  SCULPT_tilt_effective_normal_get(ss, brush, effective_normal);
3405  mul_v3_v3fl(offset, effective_normal, ss->cache->radius);
3406  mul_v3_v3(offset, ss->cache->scale);
3407  mul_v3_fl(offset, bstrength);
3408 
3409  /* XXX - this shouldn't be necessary, but sculpting crashes in blender2.8 otherwise
3410  * initialize before threads so they can do curve mapping. */
3411  BKE_curvemapping_init(brush->curve);
3412 
3413  /* Threaded loop over nodes. */
3415  .sd = sd,
3416  .ob = ob,
3417  .brush = brush,
3418  .nodes = nodes,
3419  .offset = offset,
3420  };
3421 
3422  TaskParallelSettings settings;
3423  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3425 }
3426 
3427 /* -------------------------------------------------------------------- */
3431 static void do_topology_slide_task_cb_ex(void *__restrict userdata,
3432  const int n,
3433  const TaskParallelTLS *__restrict tls)
3434 {
3435  SculptThreadedTaskData *data = userdata;
3436  SculptSession *ss = data->ob->sculpt;
3437  const Brush *brush = data->brush;
3438 
3439  PBVHVertexIter vd;
3440  SculptOrigVertData orig_data;
3441  float(*proxy)[3];
3442 
3443  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
3444 
3445  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3446 
3447  SculptBrushTest test;
3449  ss, &test, data->brush->falloff_shape);
3450  const int thread_id = BLI_task_parallel_thread_id(tls);
3451 
3452  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3453  SCULPT_orig_vert_data_update(&orig_data, &vd);
3454  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
3455  continue;
3456  }
3457  const float fade = SCULPT_brush_strength_factor(ss,
3458  brush,
3459  orig_data.co,
3460  sqrtf(test.dist),
3461  orig_data.no,
3462  NULL,
3463  vd.mask ? *vd.mask : 0.0f,
3464  vd.index,
3465  thread_id);
3466  float current_disp[3];
3467  float current_disp_norm[3];
3468  float final_disp[3] = {0.0f, 0.0f, 0.0f};
3469 
3470  switch (brush->slide_deform_type) {
3472  sub_v3_v3v3(current_disp, ss->cache->location, ss->cache->last_location);
3473  break;
3475  sub_v3_v3v3(current_disp, ss->cache->location, vd.co);
3476  break;
3478  sub_v3_v3v3(current_disp, vd.co, ss->cache->location);
3479  break;
3480  }
3481 
3482  normalize_v3_v3(current_disp_norm, current_disp);
3483  mul_v3_v3fl(current_disp, current_disp_norm, ss->cache->bstrength);
3484 
3487  float vertex_disp[3];
3488  float vertex_disp_norm[3];
3489  sub_v3_v3v3(vertex_disp, SCULPT_vertex_co_get(ss, ni.index), vd.co);
3490  normalize_v3_v3(vertex_disp_norm, vertex_disp);
3491  if (dot_v3v3(current_disp_norm, vertex_disp_norm) > 0.0f) {
3492  madd_v3_v3fl(final_disp, vertex_disp_norm, dot_v3v3(current_disp, vertex_disp));
3493  }
3494  }
3496 
3497  mul_v3_v3fl(proxy[vd.i], final_disp, fade);
3498 
3499  if (vd.mvert) {
3501  }
3502  }
3504 }
3505 
3507  PBVHVertexIter *vd,
3508  float factor,
3509  bool filter_boundary_face_sets,
3510  float *r_final_pos)
3511 {
3512  float smooth_pos[3];
3513  float final_disp[3];
3514  float boundary_normal[3];
3515  int avg_count = 0;
3516  int neighbor_count = 0;
3517  zero_v3(smooth_pos);
3518  zero_v3(boundary_normal);
3519  const bool is_boundary = SCULPT_vertex_is_boundary(ss, vd->index);
3520 
3523  neighbor_count++;
3524  if (!filter_boundary_face_sets ||
3525  (filter_boundary_face_sets && !SCULPT_vertex_has_unique_face_set(ss, ni.index))) {
3526 
3527  /* When the vertex to relax is boundary, use only connected boundary vertices for the average
3528  * position. */
3529  if (is_boundary) {
3530  if (!SCULPT_vertex_is_boundary(ss, ni.index)) {
3531  continue;
3532  }
3533  add_v3_v3(smooth_pos, SCULPT_vertex_co_get(ss, ni.index));
3534  avg_count++;
3535 
3536  /* Calculate a normal for the constraint plane using the edges of the boundary. */
3537  float to_neighbor[3];
3538  sub_v3_v3v3(to_neighbor, SCULPT_vertex_co_get(ss, ni.index), vd->co);
3539  normalize_v3(to_neighbor);
3540  add_v3_v3(boundary_normal, to_neighbor);
3541  }
3542  else {
3543  add_v3_v3(smooth_pos, SCULPT_vertex_co_get(ss, ni.index));
3544  avg_count++;
3545  }
3546  }
3547  }
3549 
3550  /* Don't modify corner vertices. */
3551  if (neighbor_count <= 2) {
3552  copy_v3_v3(r_final_pos, vd->co);
3553  return;
3554  }
3555 
3556  if (avg_count > 0) {
3557  mul_v3_fl(smooth_pos, 1.0f / avg_count);
3558  }
3559  else {
3560  copy_v3_v3(r_final_pos, vd->co);
3561  return;
3562  }
3563 
3564  float plane[4];
3565  float smooth_closest_plane[3];
3566  float vno[3];
3567 
3568  if (is_boundary && avg_count == 2) {
3569  normalize_v3_v3(vno, boundary_normal);
3570  }
3571  else {
3572  SCULPT_vertex_normal_get(ss, vd->index, vno);
3573  }
3574 
3575  if (is_zero_v3(vno)) {
3576  copy_v3_v3(r_final_pos, vd->co);
3577  return;
3578  }
3579 
3580  plane_from_point_normal_v3(plane, vd->co, vno);
3581  closest_to_plane_v3(smooth_closest_plane, plane, smooth_pos);
3582  sub_v3_v3v3(final_disp, smooth_closest_plane, vd->co);
3583 
3584  mul_v3_fl(final_disp, factor);
3585  add_v3_v3v3(r_final_pos, vd->co, final_disp);
3586 }
3587 
3588 static void do_topology_relax_task_cb_ex(void *__restrict userdata,
3589  const int n,
3590  const TaskParallelTLS *__restrict tls)
3591 {
3592  SculptThreadedTaskData *data = userdata;
3593  SculptSession *ss = data->ob->sculpt;
3594  const Brush *brush = data->brush;
3595  const float bstrength = ss->cache->bstrength;
3596 
3597  PBVHVertexIter vd;
3598  SculptOrigVertData orig_data;
3599 
3600  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
3601 
3602  BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n]);
3603 
3604  SculptBrushTest test;
3606  ss, &test, data->brush->falloff_shape);
3607  const int thread_id = BLI_task_parallel_thread_id(tls);
3608 
3609  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3610  SCULPT_orig_vert_data_update(&orig_data, &vd);
3611  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
3612  continue;
3613  }
3614  const float fade = SCULPT_brush_strength_factor(ss,
3615  brush,
3616  orig_data.co,
3617  sqrtf(test.dist),
3618  orig_data.no,
3619  NULL,
3620  vd.mask ? *vd.mask : 0.0f,
3621  vd.index,
3622  thread_id);
3623 
3624  SCULPT_relax_vertex(ss, &vd, fade * bstrength, false, vd.co);
3625  if (vd.mvert) {
3627  }
3628  }
3630 }
3631 
3632 static void do_slide_relax_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3633 {
3634  SculptSession *ss = ob->sculpt;
3635  Brush *brush = BKE_paint_brush(&sd->paint);
3636 
3638  return;
3639  }
3640 
3641  BKE_curvemapping_init(brush->curve);
3642 
3644  .sd = sd,
3645  .ob = ob,
3646  .brush = brush,
3647  .nodes = nodes,
3648  };
3649 
3650  TaskParallelSettings settings;
3651  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3652  if (ss->cache->alt_smooth) {
3654  for (int i = 0; i < 4; i++) {
3655  BLI_task_parallel_range(0, totnode, &data, do_topology_relax_task_cb_ex, &settings);
3656  }
3657  }
3658  else {
3659  BLI_task_parallel_range(0, totnode, &data, do_topology_slide_task_cb_ex, &settings);
3660  }
3661 }
3662 
3663 static void calc_sculpt_plane(
3664  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
3665 {
3666  SculptSession *ss = ob->sculpt;
3667  Brush *brush = BKE_paint_brush(&sd->paint);
3668 
3671  !(brush->flag & BRUSH_ORIGINAL_PLANE) || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) {
3672  switch (brush->sculpt_plane) {
3673  case SCULPT_DISP_DIR_VIEW:
3674  copy_v3_v3(r_area_no, ss->cache->true_view_normal);
3675  break;
3676 
3677  case SCULPT_DISP_DIR_X:
3678  ARRAY_SET_ITEMS(r_area_no, 1.0f, 0.0f, 0.0f);
3679  break;
3680 
3681  case SCULPT_DISP_DIR_Y:
3682  ARRAY_SET_ITEMS(r_area_no, 0.0f, 1.0f, 0.0f);
3683  break;
3684 
3685  case SCULPT_DISP_DIR_Z:
3686  ARRAY_SET_ITEMS(r_area_no, 0.0f, 0.0f, 1.0f);
3687  break;
3688 
3689  case SCULPT_DISP_DIR_AREA:
3690  calc_area_normal_and_center(sd, ob, nodes, totnode, r_area_no, r_area_co);
3691  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
3692  project_plane_v3_v3v3(r_area_no, r_area_no, ss->cache->view_normal);
3693  normalize_v3(r_area_no);
3694  }
3695  break;
3696 
3697  default:
3698  break;
3699  }
3700 
3701  /* For flatten center. */
3702  /* Flatten center has not been calculated yet if we are not using the area normal. */
3703  if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) {
3704  calc_area_center(sd, ob, nodes, totnode, r_area_co);
3705  }
3706 
3707  /* For area normal. */
3709  (brush->flag & BRUSH_ORIGINAL_NORMAL)) {
3710  copy_v3_v3(r_area_no, ss->cache->sculpt_normal);
3711  }
3712  else {
3713  copy_v3_v3(ss->cache->sculpt_normal, r_area_no);
3714  }
3715 
3716  /* For flatten center. */
3718  (brush->flag & BRUSH_ORIGINAL_PLANE)) {
3719  copy_v3_v3(r_area_co, ss->cache->last_center);
3720  }
3721  else {
3722  copy_v3_v3(ss->cache->last_center, r_area_co);
3723  }
3724  }
3725  else {
3726  /* For area normal. */
3727  copy_v3_v3(r_area_no, ss->cache->sculpt_normal);
3728 
3729  /* For flatten center. */
3730  copy_v3_v3(r_area_co, ss->cache->last_center);
3731 
3732  /* For area normal. */
3733  flip_v3(r_area_no, ss->cache->mirror_symmetry_pass);
3734 
3735  /* For flatten center. */
3736  flip_v3(r_area_co, ss->cache->mirror_symmetry_pass);
3737 
3738  /* For area normal. */
3739  mul_m4_v3(ss->cache->symm_rot_mat, r_area_no);
3740 
3741  /* For flatten center. */
3742  mul_m4_v3(ss->cache->symm_rot_mat, r_area_co);
3743 
3744  /* Shift the plane for the current tile. */
3745  add_v3_v3(r_area_co, ss->cache->plane_offset);
3746  }
3747 }
3748 
3754 static void do_crease_brush_task_cb_ex(void *__restrict userdata,
3755  const int n,
3756  const TaskParallelTLS *__restrict tls)
3757 {
3758  SculptThreadedTaskData *data = userdata;
3759  SculptSession *ss = data->ob->sculpt;
3760  const Brush *brush = data->brush;
3761  SculptProjectVector *spvc = data->spvc;
3762  const float flippedbstrength = data->flippedbstrength;
3763  const float *offset = data->offset;
3764 
3765  PBVHVertexIter vd;
3766  float(*proxy)[3];
3767 
3768  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3769 
3770  SculptBrushTest test;
3772  ss, &test, data->brush->falloff_shape);
3773  const int thread_id = BLI_task_parallel_thread_id(tls);
3774 
3775  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3776  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3777  continue;
3778  }
3779  /* Offset vertex. */
3780  const float fade = SCULPT_brush_strength_factor(ss,
3781  brush,
3782  vd.co,
3783  sqrtf(test.dist),
3784  vd.no,
3785  vd.fno,
3786  vd.mask ? *vd.mask : 0.0f,
3787  vd.index,
3788  thread_id);
3789  float val1[3];
3790  float val2[3];
3791 
3792  /* First we pinch. */
3793  sub_v3_v3v3(val1, test.location, vd.co);
3794  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
3795  project_plane_v3_v3v3(val1, val1, ss->cache->view_normal);
3796  }
3797 
3798  mul_v3_fl(val1, fade * flippedbstrength);
3799 
3800  sculpt_project_v3(spvc, val1, val1);
3801 
3802  /* Then we draw. */
3803  mul_v3_v3fl(val2, offset, fade);
3804 
3805  add_v3_v3v3(proxy[vd.i], val1, val2);
3806 
3807  if (vd.mvert) {
3809  }
3810  }
3812 }
3813 
3814 static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3815 {
3816  SculptSession *ss = ob->sculpt;
3817  const Scene *scene = ss->cache->vc->scene;
3818  Brush *brush = BKE_paint_brush(&sd->paint);
3819  float offset[3];
3820  float bstrength = ss->cache->bstrength;
3821  float flippedbstrength, crease_correction;
3822  float brush_alpha;
3823 
3824  SculptProjectVector spvc;
3825 
3826  /* Offset with as much as possible factored in already. */
3827  mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius);
3828  mul_v3_v3(offset, ss->cache->scale);
3829  mul_v3_fl(offset, bstrength);
3830 
3831  /* We divide out the squared alpha and multiply by the squared crease
3832  * to give us the pinch strength. */
3833  crease_correction = brush->crease_pinch_factor * brush->crease_pinch_factor;
3834  brush_alpha = BKE_brush_alpha_get(scene, brush);
3835  if (brush_alpha > 0.0f) {
3836  crease_correction /= brush_alpha * brush_alpha;
3837  }
3838 
3839  /* We always want crease to pinch or blob to relax even when draw is negative. */
3840  flippedbstrength = (bstrength < 0.0f) ? -crease_correction * bstrength :
3841  crease_correction * bstrength;
3842 
3843  if (brush->sculpt_tool == SCULPT_TOOL_BLOB) {
3844  flippedbstrength *= -1.0f;
3845  }
3846 
3847  /* Use surface normal for 'spvc', so the vertices are pinched towards a line instead of a single
3848  * point. Without this we get a 'flat' surface surrounding the pinch. */
3850 
3851  /* Threaded loop over nodes. */
3853  .sd = sd,
3854  .ob = ob,
3855  .brush = brush,
3856  .nodes = nodes,
3857  .spvc = &spvc,
3858  .offset = offset,
3859  .flippedbstrength = flippedbstrength,
3860  };
3861 
3862  TaskParallelSettings settings;
3863  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3864  BLI_task_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings);
3865 }
3866 
3867 static void do_pinch_brush_task_cb_ex(void *__restrict userdata,
3868  const int n,
3869  const TaskParallelTLS *__restrict tls)
3870 {
3871  SculptThreadedTaskData *data = userdata;
3872  SculptSession *ss = data->ob->sculpt;
3873  const Brush *brush = data->brush;
3874  float(*stroke_xz)[3] = data->stroke_xz;
3875 
3876  PBVHVertexIter vd;
3877  float(*proxy)[3];
3878  const float bstrength = ss->cache->bstrength;
3879 
3880  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3881 
3882  SculptBrushTest test;
3884  ss, &test, data->brush->falloff_shape);
3885  const int thread_id = BLI_task_parallel_thread_id(tls);
3886 
3887  float x_object_space[3];
3888  float z_object_space[3];
3889  copy_v3_v3(x_object_space, stroke_xz[0]);
3890  copy_v3_v3(z_object_space, stroke_xz[1]);
3891 
3892  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3893  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3894  continue;
3895  }
3896  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
3897  brush,
3898  vd.co,
3899  sqrtf(test.dist),
3900  vd.no,
3901  vd.fno,
3902  vd.mask ? *vd.mask : 0.0f,
3903  vd.index,
3904  thread_id);
3905  float disp_center[3];
3906  float x_disp[3];
3907  float z_disp[3];
3908  /* Calculate displacement from the vertex to the brush center. */
3909  sub_v3_v3v3(disp_center, test.location, vd.co);
3910 
3911  /* Project the displacement into the X vector (aligned to the stroke). */
3912  mul_v3_v3fl(x_disp, x_object_space, dot_v3v3(disp_center, x_object_space));
3913 
3914  /* Project the displacement into the Z vector (aligned to the surface normal). */
3915  mul_v3_v3fl(z_disp, z_object_space, dot_v3v3(disp_center, z_object_space));
3916 
3917  /* Add the two projected vectors to calculate the final displacement.
3918  * The Y component is removed. */
3919  add_v3_v3v3(disp_center, x_disp, z_disp);
3920 
3921  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
3922  project_plane_v3_v3v3(disp_center, disp_center, ss->cache->view_normal);
3923  }
3924  mul_v3_v3fl(proxy[vd.i], disp_center, fade);
3925 
3926  if (vd.mvert) {
3928  }
3929  }
3931 }
3932 
3933 static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
3934 {
3935  SculptSession *ss = ob->sculpt;
3936  Brush *brush = BKE_paint_brush(&sd->paint);
3937 
3938  float area_no[3];
3939  float area_co[3];
3940 
3941  float mat[4][4];
3942  calc_sculpt_plane(sd, ob, nodes, totnode, area_no, area_co);
3943 
3944  /* delay the first daub because grab delta is not setup */
3946  return;
3947  }
3948 
3949  if (is_zero_v3(ss->cache->grab_delta_symmetry)) {
3950  return;
3951  }
3952 
3953  /* Initialize `mat`. */
3954  cross_v3_v3v3(mat[0], area_no, ss->cache->grab_delta_symmetry);
3955  mat[0][3] = 0.0f;
3956  cross_v3_v3v3(mat[1], area_no, mat[0]);
3957  mat[1][3] = 0.0f;
3958  copy_v3_v3(mat[2], area_no);
3959  mat[2][3] = 0.0f;
3960  copy_v3_v3(mat[3], ss->cache->location);
3961  mat[3][3] = 1.0f;
3962  normalize_m4(mat);
3963 
3964  float stroke_xz[2][3];
3965  normalize_v3_v3(stroke_xz[0], mat[0]);
3966  normalize_v3_v3(stroke_xz[1], mat[2]);
3967 
3969  .sd = sd,
3970  .ob = ob,
3971  .brush = brush,
3972  .nodes = nodes,
3973  .stroke_xz = stroke_xz,
3974  };
3975 
3976  TaskParallelSettings settings;
3977  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3978  BLI_task_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings);
3979 }
3980 
3981 static void do_grab_brush_task_cb_ex(void *__restrict userdata,
3982  const int n,
3983  const TaskParallelTLS *__restrict tls)
3984 {
3985  SculptThreadedTaskData *data = userdata;
3986  SculptSession *ss = data->ob->sculpt;
3987  const Brush *brush = data->brush;
3988  const float *grab_delta = data->grab_delta;
3989 
3990  PBVHVertexIter vd;
3991  SculptOrigVertData orig_data;
3992  float(*proxy)[3];
3993  const float bstrength = ss->cache->bstrength;
3994 
3995  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
3996 
3997  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3998 
3999  SculptBrushTest test;
4001  ss, &test, data->brush->falloff_shape);
4002  const int thread_id = BLI_task_parallel_thread_id(tls);
4003 
4004  const bool grab_silhouette = brush->flag2 & BRUSH_GRAB_SILHOUETTE;
4005 
4006  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4007  SCULPT_orig_vert_data_update(&orig_data, &vd);
4008 
4009  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
4010  continue;
4011  }
4012  float fade = bstrength * SCULPT_brush_strength_factor(ss,
4013  brush,
4014  orig_data.co,
4015  sqrtf(test.dist),
4016  orig_data.no,
4017  NULL,
4018  vd.mask ? *vd.mask : 0.0f,
4019  vd.index,
4020  thread_id);
4021 
4022  if (grab_silhouette) {
4023  float silhouette_test_dir[3];
4024  normalize_v3_v3(silhouette_test_dir, grab_delta);
4025  if (dot_v3v3(ss->cache->initial_normal, ss->cache->grab_delta_symmetry) < 0.0f) {
4026  mul_v3_fl(silhouette_test_dir, -1.0f);
4027  }
4028  float vno[3];
4029  normal_short_to_float_v3(vno, orig_data.no);
4030  fade *= max_ff(dot_v3v3(vno, silhouette_test_dir), 0.0f);
4031  }
4032 
4033  mul_v3_v3fl(proxy[vd.i], grab_delta, fade);
4034 
4035  if (vd.mvert) {
4037  }
4038  }
4040 }
4041 
4042 static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4043 {
4044  SculptSession *ss = ob->sculpt;
4045  Brush *brush = BKE_paint_brush(&sd->paint);
4046  float grab_delta[3];
4047 
4048  copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
4049 
4050  if (ss->cache->normal_weight > 0.0f) {
4051  sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta);
4052  }
4053 
4055  .sd = sd,
4056  .ob = ob,
4057  .brush = brush,
4058  .nodes = nodes,
4059  .grab_delta = grab_delta,
4060  };
4061 
4062  TaskParallelSettings settings;
4063  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4064  BLI_task_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings);
4065 }
4066 
4067 static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata,
4068  const int n,
4069  const TaskParallelTLS *__restrict UNUSED(tls))
4070 {
4071  SculptThreadedTaskData *data = userdata;
4072  SculptSession *ss = data->ob->sculpt;
4073  const Brush *brush = data->brush;
4074  const float *grab_delta = data->grab_delta;
4075  const float *location = ss->cache->location;
4076 
4077  PBVHVertexIter vd;
4078  SculptOrigVertData orig_data;
4079  float(*proxy)[3];
4080 
4081  const float bstrength = ss->cache->bstrength;
4082 
4083  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
4084 
4085  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4086 
4087  float dir;
4088  if (ss->cache->mouse[0] > ss->cache->initial_mouse[0]) {
4089  dir = 1.0f;
4090  }
4091  else {
4092  dir = -1.0f;
4093  }
4094 
4096  int symm = ss->cache->mirror_symmetry_pass;
4097  if (ELEM(symm, 1, 2, 4, 7)) {
4098  dir = -dir;
4099  }
4100  }
4101 
4103  float force = len_v3(grab_delta) * dir * bstrength;
4105  &params, ss->cache->radius, force, 1.0f, brush->elastic_deform_volume_preservation);
4106 
4107  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4108  SCULPT_orig_vert_data_update(&orig_data, &vd);
4109  float final_disp[3];
4110  switch (brush->elastic_deform_type) {
4112  BKE_kelvinlet_grab(final_disp, &params, orig_data.co, location, grab_delta);
4113  mul_v3_fl(final_disp, bstrength * 20.0f);
4114  break;
4116  BKE_kelvinlet_grab_biscale(final_disp, &params, orig_data.co, location, grab_delta);
4117  mul_v3_fl(final_disp, bstrength * 20.0f);
4118  break;
4119  }
4121  BKE_kelvinlet_grab_triscale(final_disp, &params, orig_data.co, location, grab_delta);
4122  mul_v3_fl(final_disp, bstrength * 20.0f);
4123  break;
4124  }
4127  final_disp, &params, orig_data.co, location, ss->cache->sculpt_normal_symm);
4128  break;
4131  final_disp, &params, orig_data.co, location, ss->cache->sculpt_normal_symm);
4132  break;
4133  }
4134 
4135  if (vd.mask) {
4136  mul_v3_fl(final_disp, 1.0f - *vd.mask);
4137  }
4138 
4139  mul_v3_fl(final_disp, SCULPT_automasking_factor_get(ss->cache->automasking, ss, vd.index));
4140 
4141  copy_v3_v3(proxy[vd.i], final_disp);
4142 
4143  if (vd.mvert) {
4145  }
4146  }
4148 }
4149 
4150 static void do_elastic_deform_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4151 {
4152  SculptSession *ss = ob->sculpt;
4153  Brush *brush = BKE_paint_brush(&sd->paint);
4154  float grab_delta[3];
4155 
4156  copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
4157 
4158  if (ss->cache->normal_weight > 0.0f) {
4159  sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta);
4160  }
4161 
4163  .sd = sd,
4164  .ob = ob,
4165  .brush = brush,
4166  .nodes = nodes,
4167  .grab_delta = grab_delta,
4168  };
4169 
4170  TaskParallelSettings settings;
4171  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4173 }
4174 
4176 {
4178  if (co[0] < 0.0f) {
4179  symm_area |= PAINT_SYMM_AREA_X;
4180  }
4181  if (co[1] < 0.0f) {
4182  symm_area |= PAINT_SYMM_AREA_Y;
4183  }
4184  if (co[2] < 0.0f) {
4185  symm_area |= PAINT_SYMM_AREA_Z;
4186  }
4187  return symm_area;
4188 }
4189 
4191  const ePaintSymmetryFlags symm,
4192  const ePaintSymmetryAreas symmarea,
4193  const float pivot[3])
4194 {
4195  for (int i = 0; i < 3; i++) {
4196  ePaintSymmetryFlags symm_it = 1 << i;
4197  if (!(symm & symm_it)) {
4198  continue;
4199  }
4200  if (symmarea & symm_it) {
4201  flip_v3(v, symm_it);
4202  }
4203  if (pivot[i] < 0.0f) {
4204  flip_v3(v, symm_it);
4205  }
4206  }
4207 }
4208 
4210  const ePaintSymmetryFlags symm,
4211  const ePaintSymmetryAreas symmarea,
4212  const float pivot[3])
4213 {
4214  for (int i = 0; i < 3; i++) {
4215  ePaintSymmetryFlags symm_it = 1 << i;
4216  if (!(symm & symm_it)) {
4217  continue;
4218  }
4219  if (symmarea & symm_it) {
4220  flip_qt(quat, symm_it);
4221  }
4222  if (pivot[i] < 0.0f) {
4223  flip_qt(quat, symm_it);
4224  }
4225  }
4226 }
4227 
4229  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
4230 {
4231  SculptSession *ss = ob->sculpt;
4232  Brush *brush = BKE_paint_brush(&sd->paint);
4233 
4234  zero_v3(r_area_co);
4235  zero_v3(r_area_no);
4236 
4239  !(brush->flag & BRUSH_ORIGINAL_PLANE) || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) {
4240  switch (brush->sculpt_plane) {
4241  case SCULPT_DISP_DIR_VIEW:
4242  copy_v3_v3(r_area_no, ss->cache->true_view_normal);
4243  break;
4244 
4245  case SCULPT_DISP_DIR_X:
4246  ARRAY_SET_ITEMS(r_area_no, 1.0f, 0.0f, 0.0f);
4247  break;
4248 
4249  case SCULPT_DISP_DIR_Y:
4250  ARRAY_SET_ITEMS(r_area_no, 0.0f, 1.0f, 0.0f);
4251  break;
4252 
4253  case SCULPT_DISP_DIR_Z:
4254  ARRAY_SET_ITEMS(r_area_no, 0.0f, 0.0f, 1.0f);
4255  break;
4256 
4257  case SCULPT_DISP_DIR_AREA:
4258  calc_area_normal_and_center(sd, ob, nodes, totnode, r_area_no, r_area_co);
4259  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
4260  project_plane_v3_v3v3(r_area_no, r_area_no, ss->cache->view_normal);
4261  normalize_v3(r_area_no);
4262  }
4263  break;
4264 
4265  default:
4266  break;
4267  }
4268 
4269  /* For flatten center. */
4270  /* Flatten center has not been calculated yet if we are not using the area normal. */
4271  if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) {
4272  calc_area_center(sd, ob, nodes, totnode, r_area_co);
4273  }
4274 
4275  /* For area normal. */
4277  (brush->flag & BRUSH_ORIGINAL_NORMAL)) {
4278  copy_v3_v3(r_area_no, ss->cache->sculpt_normal);
4279  }
4280  else {
4281  copy_v3_v3(ss->cache->sculpt_normal, r_area_no);
4282  }
4283 
4284  /* For flatten center. */
4286  (brush->flag & BRUSH_ORIGINAL_PLANE)) {
4287  copy_v3_v3(r_area_co, ss->cache->last_center);
4288  }
4289  else {
4290  copy_v3_v3(ss->cache->last_center, r_area_co);
4291  }
4292  }
4293  else {
4294  /* For area normal. */
4295  copy_v3_v3(r_area_no, ss->cache->sculpt_normal);
4296 
4297  /* For flatten center. */
4298  copy_v3_v3(r_area_co, ss->cache->last_center);
4299 
4300  /* For area normal. */
4301  flip_v3(r_area_no, ss->cache->mirror_symmetry_pass);
4302 
4303  /* For flatten center. */
4304  flip_v3(r_area_co, ss->cache->mirror_symmetry_pass);
4305 
4306  /* For area normal. */
4307  mul_m4_v3(ss->cache->symm_rot_mat, r_area_no);
4308 
4309  /* For flatten center. */
4310  mul_m4_v3(ss->cache->symm_rot_mat, r_area_co);
4311 
4312  /* Shift the plane for the current tile. */
4313  add_v3_v3(r_area_co, ss->cache->plane_offset);
4314  }
4315 }
4316 
4317 static void do_nudge_brush_task_cb_ex(void *__restrict userdata,
4318  const int n,
4319  const TaskParallelTLS *__restrict tls)
4320 {
4321  SculptThreadedTaskData *data = userdata;
4322  SculptSession *ss = data->ob->sculpt;
4323  const Brush *brush = data->brush;
4324  const float *cono = data->cono;
4325 
4326  PBVHVertexIter vd;
4327  float(*proxy)[3];
4328  const float bstrength = ss->cache->bstrength;
4329 
4330  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4331 
4332  SculptBrushTest test;
4334  ss, &test, data->brush->falloff_shape);
4335  const int thread_id = BLI_task_parallel_thread_id(tls);
4336 
4337  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4338  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
4339  continue;
4340  }
4341  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
4342  brush,
4343  vd.co,
4344  sqrtf(test.dist),
4345  vd.no,
4346  vd.fno,
4347  vd.mask ? *vd.mask : 0.0f,
4348  vd.index,
4349  thread_id);
4350 
4351  mul_v3_v3fl(proxy[vd.i], cono, fade);
4352 
4353  if (vd.mvert) {
4355  }
4356  }
4358 }
4359 
4360 static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4361 {
4362  SculptSession *ss = ob->sculpt;
4363  Brush *brush = BKE_paint_brush(&sd->paint);
4364  float grab_delta[3];
4365  float tmp[3], cono[3];
4366 
4367  copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
4368 
4369  cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta);
4370  cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm);
4371 
4373  .sd = sd,
4374  .ob = ob,
4375  .brush = brush,
4376  .nodes = nodes,
4377  .cono = cono,
4378  };
4379 
4380  TaskParallelSettings settings;
4381  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4382  BLI_task_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings);
4383 }
4384 
4385 static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata,
4386  const int n,
4387  const TaskParallelTLS *__restrict tls)
4388 {
4389  SculptThreadedTaskData *data = userdata;
4390  SculptSession *ss = data->ob->sculpt;
4391  const Brush *brush = data->brush;
4392  SculptProjectVector *spvc = data->spvc;
4393  const float *grab_delta = data->grab_delta;
4394 
4395  PBVHVertexIter vd;
4396  float(*proxy)[3];
4397  const float bstrength = ss->cache->bstrength;
4398  const bool do_rake_rotation = ss->cache->is_rake_rotation_valid;
4399  const bool do_pinch = (brush->crease_pinch_factor != 0.5f);
4400  const float pinch = do_pinch ? (2.0f * (0.5f - brush->crease_pinch_factor) *
4401  (len_v3(grab_delta) / ss->cache->radius)) :
4402  0.0f;
4403 
4404  const bool do_elastic = brush->snake_hook_deform_type == BRUSH_SNAKE_HOOK_DEFORM_ELASTIC;
4405 
4406  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4407 
4408  SculptBrushTest test;
4410  ss, &test, data->brush->falloff_shape);
4411  const int thread_id = BLI_task_parallel_thread_id(tls);
4412 
4414  BKE_kelvinlet_init_params(&params, ss->cache->radius, bstrength, 1.0f, 0.4f);
4415 
4416  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4417  if (!do_elastic && !sculpt_brush_test_sq_fn(&test, vd.co)) {
4418  continue;
4419  }
4420 
4421  float fade;
4422  if (do_elastic) {
4423  fade = 1.0f;
4424  }
4425  else {
4426  fade = bstrength * SCULPT_brush_strength_factor(ss,
4427  brush,
4428  vd.co,
4429  sqrtf(test.dist),
4430  vd.no,
4431  vd.fno,
4432  vd.mask ? *vd.mask : 0.0f,
4433  vd.index,
4434  thread_id);
4435  }
4436 
4437  mul_v3_v3fl(proxy[vd.i], grab_delta, fade);
4438 
4439  /* Negative pinch will inflate, helps maintain volume. */
4440  if (do_pinch) {
4441  float delta_pinch_init[3], delta_pinch[3];
4442 
4443  sub_v3_v3v3(delta_pinch, vd.co, test.location);
4444  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
4445  project_plane_v3_v3v3(delta_pinch, delta_pinch, ss->cache->true_view_normal);
4446  }
4447 
4448  /* Important to calculate based on the grabbed location
4449  * (intentionally ignore fade here). */
4450  add_v3_v3(delta_pinch, grab_delta);
4451 
4452  sculpt_project_v3(spvc, delta_pinch, delta_pinch);
4453 
4454  copy_v3_v3(delta_pinch_init, delta_pinch);
4455 
4456  float pinch_fade = pinch * fade;
4457  /* When reducing, scale reduction back by how close to the center we are,
4458  * so we don't pinch into nothingness. */
4459  if (pinch > 0.0f) {
4460  /* Square to have even less impact for close vertices. */
4461  pinch_fade *= pow2f(min_ff(1.0f, len_v3(delta_pinch) / ss->cache->radius));
4462  }
4463  mul_v3_fl(delta_pinch, 1.0f + pinch_fade);
4464  sub_v3_v3v3(delta_pinch, delta_pinch_init, delta_pinch);
4465  add_v3_v3(proxy[vd.i], delta_pinch);
4466  }
4467 
4468  if (do_rake_rotation) {
4469  float delta_rotate[3];
4470  sculpt_rake_rotate(ss, test.location, vd.co, fade, delta_rotate);
4471  add_v3_v3(proxy[vd.i], delta_rotate);
4472  }
4473 
4474  if (do_elastic) {
4475  float disp[3];
4476  BKE_kelvinlet_grab_triscale(disp, &params, vd.co, ss->cache->location, proxy[vd.i]);
4477  mul_v3_fl(disp, bstrength * 20.0f);
4478  if (vd.mask) {
4479  mul_v3_fl(disp, 1.0f - *vd.mask);
4480  }
4482  copy_v3_v3(proxy[vd.i], disp);
4483  }
4484 
4485  if (vd.mvert) {
4487  }
4488  }
4490 }
4491 
4492 static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4493 {
4494  SculptSession *ss = ob->sculpt;
4495  Brush *brush = BKE_paint_brush(&sd->paint);
4496  const float bstrength = ss->cache->bstrength;
4497  float grab_delta[3];
4498 
4499  SculptProjectVector spvc;
4500 
4501  copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
4502 
4503  if (bstrength < 0.0f) {
4504  negate_v3(grab_delta);
4505  }
4506 
4507  if (ss->cache->normal_weight > 0.0f) {
4508  sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta);
4509  }
4510 
4511  /* Optionally pinch while painting. */
4512  if (brush->crease_pinch_factor != 0.5f) {
4513  sculpt_project_v3_cache_init(&spvc, grab_delta);
4514  }
4515 
4517  .sd = sd,
4518  .ob = ob,
4519  .brush = brush,
4520  .nodes = nodes,
4521  .spvc = &spvc,
4522  .grab_delta = grab_delta,
4523  };
4524 
4525  TaskParallelSettings settings;
4526  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4528 }
4529 
4530 static void do_thumb_brush_task_cb_ex(void *__restrict userdata,
4531  const int n,
4532  const TaskParallelTLS *__restrict tls)
4533 {
4534  SculptThreadedTaskData *data = userdata;
4535  SculptSession *ss = data->ob->sculpt;
4536  const Brush *brush = data->brush;
4537  const float *cono = data->cono;
4538 
4539  PBVHVertexIter vd;
4540  SculptOrigVertData orig_data;
4541  float(*proxy)[3];
4542  const float bstrength = ss->cache->bstrength;
4543 
4544  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
4545 
4546  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4547 
4548  SculptBrushTest test;
4550  ss, &test, data->brush->falloff_shape);
4551  const int thread_id = BLI_task_parallel_thread_id(tls);
4552 
4553  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4554  SCULPT_orig_vert_data_update(&orig_data, &vd);
4555 
4556  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
4557  continue;
4558  }
4559  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
4560  brush,
4561  orig_data.co,
4562  sqrtf(test.dist),
4563  orig_data.no,
4564  NULL,
4565  vd.mask ? *vd.mask : 0.0f,
4566  vd.index,
4567  thread_id);
4568 
4569  mul_v3_v3fl(proxy[vd.i], cono, fade);
4570 
4571  if (vd.mvert) {
4573  }
4574  }
4576 }
4577 
4578 static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4579 {
4580  SculptSession *ss = ob->sculpt;
4581  Brush *brush = BKE_paint_brush(&sd->paint);
4582  float grab_delta[3];
4583  float tmp[3], cono[3];
4584 
4585  copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry);
4586 
4587  cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta);
4588  cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm);
4589 
4591  .sd = sd,
4592  .ob = ob,
4593  .brush = brush,
4594  .nodes = nodes,
4595  .cono = cono,
4596  };
4597 
4598  TaskParallelSettings settings;
4599  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4600  BLI_task_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings);
4601 }
4602 
4603 static void do_rotate_brush_task_cb_ex(void *__restrict userdata,
4604  const int n,
4605  const TaskParallelTLS *__restrict tls)
4606 {
4607  SculptThreadedTaskData *data = userdata;
4608  SculptSession *ss = data->ob->sculpt;
4609  const Brush *brush = data->brush;
4610  const float angle = data->angle;
4611 
4612  PBVHVertexIter vd;
4613  SculptOrigVertData orig_data;
4614  float(*proxy)[3];
4615  const float bstrength = ss->cache->bstrength;
4616 
4617  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
4618 
4619  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4620 
4621  SculptBrushTest test;
4623  ss, &test, data->brush->falloff_shape);
4624  const int thread_id = BLI_task_parallel_thread_id(tls);
4625 
4626  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4627  SCULPT_orig_vert_data_update(&orig_data, &vd);
4628 
4629  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
4630  continue;
4631  }
4632  float vec[3], rot[3][3];
4633  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
4634  brush,
4635  orig_data.co,
4636  sqrtf(test.dist),
4637  orig_data.no,
4638  NULL,
4639  vd.mask ? *vd.mask : 0.0f,
4640  vd.index,
4641  thread_id);
4642 
4643  sub_v3_v3v3(vec, orig_data.co, ss->cache->location);
4645  mul_v3_m3v3(proxy[vd.i], rot, vec);
4646  add_v3_v3(proxy[vd.i], ss->cache->location);
4647  sub_v3_v3(proxy[vd.i], orig_data.co);
4648 
4649  if (vd.mvert) {
4651  }
4652  }
4654 }
4655 
4656 static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4657 {
4658  SculptSession *ss = ob->sculpt;
4659  Brush *brush = BKE_paint_brush(&sd->paint);
4660 
4661  static const int flip[8] = {1, -1, -1, 1, -1, 1, 1, -1};
4662  const float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmetry_pass];
4663 
4665  .sd = sd,
4666  .ob = ob,
4667  .brush = brush,
4668  .nodes = nodes,
4669  .angle = angle,
4670  };
4671 
4672  TaskParallelSettings settings;
4673  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4674  BLI_task_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings);
4675 }
4676 
4677 static void do_layer_brush_task_cb_ex(void *__restrict userdata,
4678  const int n,
4679  const TaskParallelTLS *__restrict tls)
4680 {
4681  SculptThreadedTaskData *data = userdata;
4682  SculptSession *ss = data->ob->sculpt;
4683  Sculpt *sd = data->sd;
4684  const Brush *brush = data->brush;
4685 
4686  const bool use_persistent_base = ss->persistent_base && brush->flag & BRUSH_PERSISTENT;
4687 
4688  PBVHVertexIter vd;
4689  SculptOrigVertData orig_data;
4690  const float bstrength = ss->cache->bstrength;
4691  SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]);
4692 
4693  SculptBrushTest test;
4695  ss, &test, data->brush->falloff_shape);
4696  const int thread_id = BLI_task_parallel_thread_id(tls);
4697 
4698  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4699  SCULPT_orig_vert_data_update(&orig_data, &vd);
4700 
4701  if (!sculpt_brush_test_sq_fn(&test, orig_data.co)) {
4702  continue;
4703  }
4704  const float fade = SCULPT_brush_strength_factor(ss,
4705  brush,
4706  vd.co,
4707  sqrtf(test.dist),
4708  vd.no,
4709  vd.fno,
4710  vd.mask ? *vd.mask : 0.0f,
4711  vd.index,
4712  thread_id);
4713 
4714  const int vi = vd.index;
4715  float *disp_factor;
4716  if (use_persistent_base) {
4717  disp_factor = &ss->persistent_base[vi].disp;
4718  }
4719  else {
4720  disp_factor = &ss->cache->layer_displacement_factor[vi];
4721  }
4722 
4723  /* When using persistent base, the layer brush (holding Control) invert mode resets the
4724  * height of the layer to 0. This makes possible to clean edges of previously added layers
4725  * on top of the base. */
4726  /* The main direction of the layers is inverted using the regular brush strength with the
4727  * brush direction property. */
4728  if (use_persistent_base && ss->cache->invert) {
4729  (*disp_factor) += fabsf(fade * bstrength * (*disp_factor)) *
4730  ((*disp_factor) > 0.0f ? -1.0f : 1.0f);
4731  }
4732  else {
4733  (*disp_factor) += fade * bstrength * (1.05f - fabsf(*disp_factor));
4734  }
4735  if (vd.mask) {
4736  const float clamp_mask = 1.0f - *vd.mask;
4737  *disp_factor = clamp_f(*disp_factor, -clamp_mask, clamp_mask);
4738  }
4739  else {
4740  *disp_factor = clamp_f(*disp_factor, -1.0f, 1.0f);
4741  }
4742 
4743  float final_co[3];
4744  float normal[3];
4745 
4746  if (use_persistent_base) {
4748  mul_v3_fl(normal, brush->height);
4749  madd_v3_v3v3fl(final_co, SCULPT_vertex_persistent_co_get(ss, vi), normal, *disp_factor);
4750  }
4751  else {
4752  normal_short_to_float_v3(normal, orig_data.no);
4753  mul_v3_fl(normal, brush->height);
4754  madd_v3_v3v3fl(final_co, orig_data.co, normal, *disp_factor);
4755  }
4756 
4757  float vdisp[3];
4758  sub_v3_v3v3(vdisp, final_co, vd.co);
4759  mul_v3_fl(vdisp, fabsf(fade));
4760  add_v3_v3v3(final_co, vd.co, vdisp);
4761 
4762  SCULPT_clip(sd, ss, vd.co, final_co);
4763 
4764  if (vd.mvert) {
4766  }
4767  }
4769 }
4770 
4771 static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4772 {
4773  SculptSession *ss = ob->sculpt;
4774  Brush *brush = BKE_paint_brush(&sd->paint);
4775 
4776  if (ss->cache->layer_displacement_factor == NULL) {
4778  "layer displacement factor");
4779  }
4780 
4782  .sd = sd,
4783  .ob = ob,
4784  .brush = brush,
4785  .nodes = nodes,
4786  };
4787 
4788  TaskParallelSettings settings;
4789  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4790  BLI_task_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings);
4791 }
4792 
4793 static void do_inflate_brush_task_cb_ex(void *__restrict userdata,
4794  const int n,
4795  const TaskParallelTLS *__restrict tls)
4796 {
4797  SculptThreadedTaskData *data = userdata;
4798  SculptSession *ss = data->ob->sculpt;
4799  const Brush *brush = data->brush;
4800 
4801  PBVHVertexIter vd;
4802  float(*proxy)[3];
4803  const float bstrength = ss->cache->bstrength;
4804 
4805  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4806 
4807  SculptBrushTest test;
4809  ss, &test, data->brush->falloff_shape);
4810  const int thread_id = BLI_task_parallel_thread_id(tls);
4811 
4812  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4813  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
4814  continue;
4815  }
4816  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
4817  brush,
4818  vd.co,
4819  sqrtf(test.dist),
4820  vd.no,
4821  vd.fno,
4822  vd.mask ? *vd.mask : 0.0f,
4823  vd.index,
4824  thread_id);
4825  float val[3];
4826 
4827  if (vd.fno) {
4828  copy_v3_v3(val, vd.fno);
4829  }
4830  else {
4831  normal_short_to_float_v3(val, vd.no);
4832  }
4833 
4834  mul_v3_fl(val, fade * ss->cache->radius);
4835  mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale);
4836 
4837  if (vd.mvert) {
4839  }
4840  }
4842 }
4843 
4844 static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4845 {
4846  Brush *brush = BKE_paint_brush(&sd->paint);
4847 
4849  .sd = sd,
4850  .ob = ob,
4851  .brush = brush,
4852  .nodes = nodes,
4853  };
4854 
4855  TaskParallelSettings settings;
4856  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4857  BLI_task_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings);
4858 }
4859 
4860 int SCULPT_plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3])
4861 {
4862  return (!(brush->flag & BRUSH_PLANE_TRIM) ||
4863  ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared)));
4864 }
4865 
4866 static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip)
4867 {
4868  float d = plane_point_side_v3(plane, co);
4869  if (flip) {
4870  d = -d;
4871  }
4872  return d <= 0.0f;
4873 }
4874 
4875 int SCULPT_plane_point_side(const float co[3], const float plane[4])
4876 {
4877  float d = plane_point_side_v3(plane, co);
4878  return d <= 0.0f;
4879 }
4880 
4882 {
4883  Brush *brush = BKE_paint_brush(&sd->paint);
4884 
4885  float rv = brush->plane_offset;
4886 
4887  if (brush->flag & BRUSH_OFFSET_PRESSURE) {
4888  rv *= ss->cache->pressure;
4889  }
4890 
4891  return rv;
4892 }
4893 
4894 static void do_flatten_brush_task_cb_ex(void *__restrict userdata,
4895  const int n,
4896  const TaskParallelTLS *__restrict tls)
4897 {
4898  SculptThreadedTaskData *data = userdata;
4899  SculptSession *ss = data->ob->sculpt;
4900  const Brush *brush = data->brush;
4901  const float *area_no = data->area_no;
4902  const float *area_co = data->area_co;
4903 
4904  PBVHVertexIter vd;
4905  float(*proxy)[3];
4906  const float bstrength = ss->cache->bstrength;
4907 
4908  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
4909 
4910  SculptBrushTest test;
4912  ss, &test, data->brush->falloff_shape);
4913  const int thread_id = BLI_task_parallel_thread_id(tls);
4914 
4915  plane_from_point_normal_v3(test.plane_tool, area_co, area_no);
4916 
4917  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
4918  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
4919  continue;
4920  }
4921  float intr[3];
4922  float val[3];
4923 
4925 
4926  sub_v3_v3v3(val, intr, vd.co);
4927 
4928  if (SCULPT_plane_trim(ss->cache, brush, val)) {
4929  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
4930  brush,
4931  vd.co,
4932  sqrtf(test.dist),
4933  vd.no,
4934  vd.fno,
4935  vd.mask ? *vd.mask : 0.0f,
4936  vd.index,
4937  thread_id);
4938 
4939  mul_v3_v3fl(proxy[vd.i], val, fade);
4940 
4941  if (vd.mvert) {
4943  }
4944  }
4945  }
4947 }
4948 
4949 static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
4950 {
4951  SculptSession *ss = ob->sculpt;
4952  Brush *brush = BKE_paint_brush(&sd->paint);
4953 
4954  const float radius = ss->cache->radius;
4955 
4956  float area_no[3];
4957  float area_co[3];
4958 
4959  float offset = SCULPT_brush_plane_offset_get(sd, ss);
4960  float displace;
4961  float temp[3];
4962 
4963  SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co);
4964 
4966 
4967  displace = radius * offset;
4968 
4969  mul_v3_v3v3(temp, area_no, ss->cache->scale);
4970  mul_v3_fl(temp, displace);
4971  add_v3_v3(area_co, temp);
4972 
4974  .sd = sd,
4975  .ob = ob,
4976  .brush = brush,
4977  .nodes = nodes,
4978  .area_no = area_no,
4979  .area_co = area_co,
4980  };
4981 
4982  TaskParallelSettings settings;
4983  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
4984  BLI_task_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings);
4985 }
4986 
4987 /* -------------------------------------------------------------------- */
4991 typedef struct ClaySampleData {
4992  float plane_dist[2];
4994 
4995 static void calc_clay_surface_task_cb(void *__restrict userdata,
4996  const int n,
4997  const TaskParallelTLS *__restrict tls)
4998 {
4999  SculptThreadedTaskData *data = userdata;
5000  SculptSession *ss = data->ob->sculpt;
5001  const Brush *brush = data->brush;
5002  ClaySampleData *csd = tls->userdata_chunk;
5003  const float *area_no = data->area_no;
5004  const float *area_co = data->area_co;
5005  float plane[4];
5006 
5007  PBVHVertexIter vd;
5008 
5009  SculptBrushTest test;
5011  ss, &test, brush->falloff_shape);
5012 
5013  /* Apply the brush normal radius to the test before sampling. */
5014  float test_radius = sqrtf(test.radius_squared);
5015  test_radius *= brush->normal_radius_factor;
5016  test.radius_squared = test_radius * test_radius;
5017  plane_from_point_normal_v3(plane, area_co, area_no);
5018 
5019  if (is_zero_v4(plane)) {
5020  return;
5021  }
5022 
5023  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5024  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
5025  continue;
5026  }
5027 
5028  float plane_dist = dist_signed_to_plane_v3(vd.co, plane);
5029  float plane_dist_abs = fabsf(plane_dist);
5030  if (plane_dist > 0.0f) {
5031  csd->plane_dist[0] = MIN2(csd->plane_dist[0], plane_dist_abs);
5032  }
5033  else {
5034  csd->plane_dist[1] = MIN2(csd->plane_dist[1], plane_dist_abs);
5035  }
5037  }
5038 }
5039 
5040 static void calc_clay_surface_reduce(const void *__restrict UNUSED(userdata),
5041  void *__restrict chunk_join,
5042  void *__restrict chunk)
5043 {
5044  ClaySampleData *join = chunk_join;
5045  ClaySampleData *csd = chunk;
5046  join->plane_dist[0] = MIN2(csd->plane_dist[0], join->plane_dist[0]);
5047  join->plane_dist[1] = MIN2(csd->plane_dist[1], join->plane_dist[1]);
5048 }
5049 
5050 static void do_clay_brush_task_cb_ex(void *__restrict userdata,
5051  const int n,
5052  const TaskParallelTLS *__restrict tls)
5053 {
5054  SculptThreadedTaskData *data = userdata;
5055  SculptSession *ss = data->ob->sculpt;
5056  const Brush *brush = data->brush;
5057  const float *area_no = data->area_no;
5058  const float *area_co = data->area_co;
5059 
5060  PBVHVertexIter vd;
5061  float(*proxy)[3];
5062  const float bstrength = fabsf(ss->cache->bstrength);
5063 
5064  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
5065 
5066  SculptBrushTest test;
5068  ss, &test, data->brush->falloff_shape);
5069  const int thread_id = BLI_task_parallel_thread_id(tls);
5070 
5071  plane_from_point_normal_v3(test.plane_tool, area_co, area_no);
5072 
5073  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5074  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
5075  continue;
5076  }
5077 
5078  float intr[3];
5079  float val[3];
5081 
5082  sub_v3_v3v3(val, intr, vd.co);
5083 
5084  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
5085  brush,
5086  vd.co,
5087  sqrtf(test.dist),
5088  vd.no,
5089  vd.fno,
5090  vd.mask ? *vd.mask : 0.0f,
5091  vd.index,
5092  thread_id);
5093 
5094  mul_v3_v3fl(proxy[vd.i], val, fade);
5095 
5096  if (vd.mvert) {
5098  }
5099  }
5101 }
5102 
5103 static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
5104 {
5105  SculptSession *ss = ob->sculpt;
5106  Brush *brush = BKE_paint_brush(&sd->paint);
5107 
5108  const float radius = fabsf(ss->cache->radius);
5109  const float initial_radius = fabsf(ss->cache->initial_radius);
5110  bool flip = ss->cache->bstrength < 0.0f;
5111 
5112  float offset = SCULPT_brush_plane_offset_get(sd, ss);
5113  float displace;
5114 
5115  float area_no[3];
5116  float area_co[3];
5117  float temp[3];
5118 
5119  SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co);
5120 
5121  SculptThreadedTaskData sample_data = {
5122  .sd = NULL,
5123  .ob = ob,
5124  .brush = brush,
5125  .nodes = nodes,
5126  .totnode = totnode,
5127  .area_no = area_no,
5128  .area_co = ss->cache->location,
5129  };
5130 
5131  ClaySampleData csd = {{0}};
5132 
5133  TaskParallelSettings sample_settings;
5134  BKE_pbvh_parallel_range_settings(&sample_settings, true, totnode);
5135  sample_settings.func_reduce = calc_clay_surface_reduce;
5136  sample_settings.userdata_chunk = &csd;
5137  sample_settings.userdata_chunk_size = sizeof(ClaySampleData);
5138 
5139  BLI_task_parallel_range(0, totnode, &sample_data, calc_clay_surface_task_cb, &sample_settings);
5140 
5141  float d_offset = (csd.plane_dist[0] + csd.plane_dist[1]);
5142  d_offset = min_ff(radius, d_offset);
5143  d_offset = d_offset / radius;
5144  d_offset = 1.0f - d_offset;
5145  displace = fabsf(initial_radius * (0.25f + offset + (d_offset * 0.15f)));
5146  if (flip) {
5147  displace = -displace;
5148  }
5149 
5150  mul_v3_v3v3(temp, area_no, ss->cache->scale);
5151  mul_v3_fl(temp, displace);
5152  copy_v3_v3(area_co, ss->cache->location);
5153  add_v3_v3(area_co, temp);
5154 
5156  .sd = sd,
5157  .ob = ob,
5158  .brush = brush,
5159  .nodes = nodes,
5160  .area_no = area_no,
5161  .area_co = area_co,
5162  };
5163 
5164  TaskParallelSettings settings;
5165  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5166  BLI_task_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings);
5167 }
5168 
5169 static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata,
5170  const int n,
5171  const TaskParallelTLS *__restrict tls)
5172 {
5173  SculptThreadedTaskData *data = userdata;
5174  SculptSession *ss = data->ob->sculpt;
5175  const Brush *brush = data->brush;
5176  float(*mat)[4] = data->mat;
5177  const float *area_no_sp = data->area_no_sp;
5178  const float *area_co = data->area_co;
5179 
5180  PBVHVertexIter vd;
5181  SculptBrushTest test;
5182  float(*proxy)[3];
5183  const bool flip = (ss->cache->bstrength < 0.0f);
5184  const float bstrength = flip ? -ss->cache->bstrength : ss->cache->bstrength;
5185 
5186  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
5187 
5188  SCULPT_brush_test_init(ss, &test);
5189  plane_from_point_normal_v3(test.plane_tool, area_co, area_no_sp);
5190  const int thread_id = BLI_task_parallel_thread_id(tls);
5191 
5192  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5193  if (!SCULPT_brush_test_cube(&test, vd.co, mat, brush->tip_roundness)) {
5194  continue;
5195  }
5196 
5197  if (!plane_point_side_flip(vd.co, test.plane_tool, flip)) {
5198  continue;
5199  }
5200 
5201  float intr[3];
5202  float val[3];
5204  sub_v3_v3v3(val, intr, vd.co);
5205 
5206  if (!SCULPT_plane_trim(ss->cache, brush, val)) {
5207  continue;
5208  }
5209  /* The normal from the vertices is ignored, it causes glitch with planes, see: T44390. */
5210  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
5211  brush,
5212  vd.co,
5213  ss->cache->radius * test.dist,
5214  vd.no,
5215  vd.fno,
5216  vd.mask ? *vd.mask : 0.0f,
5217  vd.index,
5218  thread_id);
5219 
5220  mul_v3_v3fl(proxy[vd.i], val, fade);
5221 
5222  if (vd.mvert) {
5224  }
5225  }
5227 }
5228 
5229 static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
5230 {
5231  SculptSession *ss = ob->sculpt;
5232  Brush *brush = BKE_paint_brush(&sd->paint);
5233 
5234  const bool flip = (ss->cache->bstrength < 0.0f);
5235  const float radius = flip ? -ss->cache->radius : ss->cache->radius;
5236  const float offset = SCULPT_brush_plane_offset_get(sd, ss);
5237  const float displace = radius * (0.18f + offset);
5238 
5239  /* The sculpt-plane normal (whatever its set to). */
5240  float area_no_sp[3];
5241 
5242  /* Geometry normal */
5243  float area_no[3];
5244  float area_co[3];
5245 
5246  float temp[3];
5247  float mat[4][4];
5248  float scale[4][4];
5249  float tmat[4][4];
5250 
5251  SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no_sp, area_co);
5252  SCULPT_tilt_apply_to_normal(area_no_sp, ss->cache, brush->tilt_strength_factor);
5253 
5254  if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) {
5255  SCULPT_calc_area_normal(sd, ob, nodes, totnode, area_no);
5256  }
5257  else {
5258  copy_v3_v3(area_no, area_no_sp);
5259  }
5260 
5261  /* Delay the first daub because grab delta is not setup. */
5263  return;
5264  }
5265 
5266  if (is_zero_v3(ss->cache->grab_delta_symmetry)) {
5267  return;
5268  }
5269 
5270  mul_v3_v3v3(temp, area_no_sp, ss->cache->scale);
5271  mul_v3_fl(temp, displace);
5272  add_v3_v3(area_co, temp);
5273 
5274  /* Clay Strips uses a cube test with falloff in the XY axis (not in Z) and a plane to deform the
5275  * vertices. When in Add mode, vertices that are below the plane and inside the cube are move
5276  * towards the plane. In this situation, there may be cases where a vertex is outside the cube
5277  * but below the plane, so won't be deformed, causing artifacts. In order to prevent these
5278  * artifacts, this displaces the test cube space in relation to the plane in order to
5279  * deform more vertices that may be below it. */
5280  /* The 0.7 and 1.25 factors are arbitrary and don't have any relation between them, they were set
5281  * by doing multiple tests using the default "Clay Strips" brush preset. */
5282  float area_co_displaced[3];
5283  madd_v3_v3v3fl(area_co_displaced, area_co, area_no, -radius * 0.7f);
5284 
5285  /* Initialize brush local-space matrix. */
5286  cross_v3_v3v3(mat[0], area_no, ss->cache->grab_delta_symmetry);
5287  mat[0][3] = 0.0f;
5288  cross_v3_v3v3(mat[1], area_no, mat[0]);
5289  mat[1][3] = 0.0f;
5290  copy_v3_v3(mat[2], area_no);
5291  mat[2][3] = 0.0f;
5292  copy_v3_v3(mat[3], area_co_displaced);
5293  mat[3][3] = 1.0f;
5294  normalize_m4(mat);
5295 
5296  /* Scale brush local space matrix. */
5297  scale_m4_fl(scale, ss->cache->radius);
5298  mul_m4_m4m4(tmat, mat, scale);
5299 
5300  /* Deform the local space in Z to scale the test cube. As the test cube does not have falloff in
5301  * Z this does not produce artifacts in the falloff cube and allows to deform extra vertices
5302  * during big deformation while keeping the surface as uniform as possible. */
5303  mul_v3_fl(tmat[2], 1.25f);
5304 
5305  invert_m4_m4(mat, tmat);
5306 
5308  .sd = sd,
5309  .ob = ob,
5310  .brush = brush,
5311  .nodes = nodes,
5312  .area_no_sp = area_no_sp,
5313  .area_co = area_co,
5314  .mat = mat,
5315  };
5316 
5317  TaskParallelSettings settings;
5318  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5320 }
5321 
5322 static void do_fill_brush_task_cb_ex(void *__restrict userdata,
5323  const int n,
5324  const TaskParallelTLS *__restrict tls)
5325 {
5326  SculptThreadedTaskData *data = userdata;
5327  SculptSession *ss = data->ob->sculpt;
5328  const Brush *brush = data->brush;
5329  const float *area_no = data->area_no;
5330  const float *area_co = data->area_co;
5331 
5332  PBVHVertexIter vd;
5333  float(*proxy)[3];
5334  const float bstrength = ss->cache->bstrength;
5335 
5336  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
5337 
5338  SculptBrushTest test;
5340  ss, &test, data->brush->falloff_shape);
5341  const int thread_id = BLI_task_parallel_thread_id(tls);
5342 
5343  plane_from_point_normal_v3(test.plane_tool, area_co, area_no);
5344 
5345  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5346  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
5347  continue;
5348  }
5349 
5350  if (!SCULPT_plane_point_side(vd.co, test.plane_tool)) {
5351  continue;
5352  }
5353 
5354  float intr[3];
5355  float val[3];
5357  sub_v3_v3v3(val, intr, vd.co);
5358 
5359  if (!SCULPT_plane_trim(ss->cache, brush, val)) {
5360  continue;
5361  }
5362 
5363  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
5364  brush,
5365  vd.co,
5366  sqrtf(test.dist),
5367  vd.no,
5368  vd.fno,
5369  vd.mask ? *vd.mask : 0.0f,
5370  vd.index,
5371  thread_id);
5372 
5373  mul_v3_v3fl(proxy[vd.i], val, fade);
5374 
5375  if (vd.mvert) {
5377  }
5378  }
5380 }
5381 
5382 static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
5383 {
5384  SculptSession *ss = ob->sculpt;
5385  Brush *brush = BKE_paint_brush(&sd->paint);
5386 
5387  const float radius = ss->cache->radius;
5388 
5389  float area_no[3];
5390  float area_co[3];
5391  float offset = SCULPT_brush_plane_offset_get(sd, ss);
5392 
5393  float displace;
5394 
5395  float temp[3];
5396 
5397  SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co);
5398 
5400 
5401  displace = radius * offset;
5402 
5403  mul_v3_v3v3(temp, area_no, ss->cache->scale);
5404  mul_v3_fl(temp, displace);
5405  add_v3_v3(area_co, temp);
5406 
5408  .sd = sd,
5409  .ob = ob,
5410  .brush = brush,
5411  .nodes = nodes,
5412  .area_no = area_no,
5413  .area_co = area_co,
5414  };
5415 
5416  TaskParallelSettings settings;
5417  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5418  BLI_task_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings);
5419 }
5420 
5421 static void do_scrape_brush_task_cb_ex(void *__restrict userdata,
5422  const int n,
5423  const TaskParallelTLS *__restrict tls)
5424 {
5425  SculptThreadedTaskData *data = userdata;
5426  SculptSession *ss = data->ob->sculpt;
5427  const Brush *brush = data->brush;
5428  const float *area_no = data->area_no;
5429  const float *area_co = data->area_co;
5430 
5431  PBVHVertexIter vd;
5432  float(*proxy)[3];
5433  const float bstrength = ss->cache->bstrength;
5434 
5435  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
5436 
5437  SculptBrushTest test;
5439  ss, &test, data->brush->falloff_shape);
5440  const int thread_id = BLI_task_parallel_thread_id(tls);
5441  plane_from_point_normal_v3(test.plane_tool, area_co, area_no);
5442 
5443  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5444  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
5445  continue;
5446  }
5447 
5448  if (SCULPT_plane_point_side(vd.co, test.plane_tool)) {
5449  continue;
5450  }
5451 
5452  float intr[3];
5453  float val[3];
5455  sub_v3_v3v3(val, intr, vd.co);
5456 
5457  if (!SCULPT_plane_trim(ss->cache, brush, val)) {
5458  continue;
5459  }
5460 
5461  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
5462  brush,
5463  vd.co,
5464  sqrtf(test.dist),
5465  vd.no,
5466  vd.fno,
5467  vd.mask ? *vd.mask : 0.0f,
5468  vd.index,
5469  thread_id);
5470 
5471  mul_v3_v3fl(proxy[vd.i], val, fade);
5472 
5473  if (vd.mvert) {
5475  }
5476  }
5478 }
5479 
5480 static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
5481 {
5482  SculptSession *ss = ob->sculpt;
5483  Brush *brush = BKE_paint_brush(&sd->paint);
5484 
5485  const float radius = ss->cache->radius;
5486 
5487  float area_no[3];
5488  float area_co[3];
5489  float offset = SCULPT_brush_plane_offset_get(sd, ss);
5490 
5491  float displace;
5492 
5493  float temp[3];
5494 
5495  SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no, area_co);
5496 
5498 
5499  displace = -radius * offset;
5500 
5501  mul_v3_v3v3(temp, area_no, ss->cache->scale);
5502  mul_v3_fl(temp, displace);
5503  add_v3_v3(area_co, temp);
5504 
5506  .sd = sd,
5507  .ob = ob,
5508  .brush = brush,
5509  .nodes = nodes,
5510  .area_no = area_no,
5511  .area_co = area_co,
5512  };
5513 
5514  TaskParallelSettings settings;
5515  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5516  BLI_task_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings);
5517 }
5518 
5519 /* -------------------------------------------------------------------- */
5523 static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata,
5524  const int n,
5525  const TaskParallelTLS *__restrict tls)
5526 {
5527  SculptThreadedTaskData *data = userdata;
5528  SculptSession *ss = data->ob->sculpt;
5529  const Brush *brush = data->brush;
5530  float(*mat)[4] = data->mat;
5531  const float *area_no_sp = data->area_no_sp;
5532  const float *area_co = data->area_co;
5533 
5534  PBVHVertexIter vd;
5535  float(*proxy)[3];
5536  const float bstrength = data->clay_strength;
5537 
5538  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
5539 
5540  SculptBrushTest test;
5542  ss, &test, data->brush->falloff_shape);
5543  const int thread_id = BLI_task_parallel_thread_id(tls);
5544 
5545  float plane_tilt[4];
5546  float normal_tilt[3];
5547  float imat[4][4];
5548 
5549  invert_m4_m4(imat, mat);
5550  rotate_v3_v3v3fl(normal_tilt, area_no_sp, imat[0], DEG2RADF(-ss->cache->clay_thumb_front_angle));
5551 
5552  /* Plane aligned to the geometry normal (back part of the brush). */
5553  plane_from_point_normal_v3(test.plane_tool, area_co, area_no_sp);
5554  /* Tilted plane (front part of the brush). */
5555  plane_from_point_normal_v3(plane_tilt, area_co, normal_tilt);
5556 
5557  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5558  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
5559  continue;
5560  }
5561  float local_co[3];
5562  mul_v3_m4v3(local_co, mat, vd.co);
5563  float intr[3], intr_tilt[3];
5564  float val[3];
5565 
5567  closest_to_plane_normalized_v3(intr_tilt, plane_tilt, vd.co);
5568 
5569  /* Mix the deformation of the aligned and the tilted plane based on the brush space vertex
5570  * coordinates. */
5571  /* We can also control the mix with a curve if it produces noticeable artifacts in the center
5572  * of the brush. */
5573  const float tilt_mix = local_co[1] > 0.0f ? 0.0f : 1.0f;
5574  interp_v3_v3v3(intr, intr, intr_tilt, tilt_mix);
5575  sub_v3_v3v3(val, intr_tilt, vd.co);
5576 
5577  const float fade = bstrength * SCULPT_brush_strength_factor(ss,
5578  brush,
5579  vd.co,
5580  sqrtf(test.dist),
5581  vd.no,
5582  vd.fno,
5583  vd.mask ? *vd.mask : 0.0f,
5584  vd.index,
5585  thread_id);
5586 
5587  mul_v3_v3fl(proxy[vd.i], val, fade);
5588 
5589  if (vd.mvert) {
5591  }
5592  }
5594 }
5595 
5597 {
5598  float final_pressure = 0.0f;
5599  for (int i = 0; i < SCULPT_CLAY_STABILIZER_LEN; i++) {
5600  final_pressure += cache->clay_pressure_stabilizer[i];
5601  }
5602  return final_pressure / SCULPT_CLAY_STABILIZER_LEN;
5603 }
5604 
5605 static void do_clay_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
5606 {
5607  SculptSession *ss = ob->sculpt;
5608  Brush *brush = BKE_paint_brush(&sd->paint);
5609 
5610  const float radius = ss->cache->radius;
5611  const float offset = SCULPT_brush_plane_offset_get(sd, ss);
5612  const float displace = radius * (0.25f + offset);
5613 
5614  /* Sampled geometry normal and area center. */
5615  float area_no_sp[3];
5616  float area_no[3];
5617  float area_co[3];
5618 
5619  float temp[3];
5620  float mat[4][4];
5621  float scale[4][4];
5622  float tmat[4][4];
5623 
5624  SCULPT_calc_brush_plane(sd, ob, nodes, totnode, area_no_sp, area_co);
5625 
5626  if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) {
5627  SCULPT_calc_area_normal(sd, ob, nodes, totnode, area_no);
5628  }
5629  else {
5630  copy_v3_v3(area_no, area_no_sp);
5631  }
5632 
5633  /* Delay the first daub because grab delta is not setup. */
5635  ss->cache->clay_thumb_front_angle = 0.0f;
5636  return;
5637  }
5638 
5639  /* Simulate the clay accumulation by increasing the plane angle as more samples are added to the
5640  * stroke. */
5642  ss->cache->clay_thumb_front_angle += 0.8f;
5644  }
5645 
5646  if (is_zero_v3(ss->cache->grab_delta_symmetry)) {
5647  return;
5648  }
5649 
5650  /* Displace the brush planes. */
5651  copy_v3_v3(area_co, ss->cache->location);
5652  mul_v3_v3v3(temp, area_no_sp, ss->cache->scale);
5653  mul_v3_fl(temp, displace);
5654  add_v3_v3(area_co, temp);
5655 
5656  /* Initialize brush local-space matrix. */
5657  cross_v3_v3v3(mat[0], area_no, ss->cache->grab_delta_symmetry);
5658  mat[0][3] = 0.0f;
5659  cross_v3_v3v3(mat[1], area_no, mat[0]);
5660  mat[1][3] = 0.0f;
5661  copy_v3_v3(mat[2], area_no);
5662  mat[2][3] = 0.0f;
5663  copy_v3_v3(mat[3], ss->cache->location);
5664  mat[3][3] = 1.0f;
5665  normalize_m4(mat);
5666 
5667  /* Scale brush local space matrix. */
5668  scale_m4_fl(scale, ss->cache->radius);
5669  mul_m4_m4m4(tmat, mat, scale);
5670  invert_m4_m4(mat, tmat);
5671 
5672  float clay_strength = ss->cache->bstrength *
5674 
5676  .sd = sd,
5677  .ob = ob,
5678  .brush = brush,
5679  .nodes = nodes,
5680  .area_no_sp = area_no_sp,
5681  .area_co = ss->cache->location,
5682  .mat = mat,
5683  .clay_strength = clay_strength,
5684  };
5685 
5686  TaskParallelSettings settings;
5687  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5689 }
5690 
5693 static void do_gravity_task_cb_ex(void *__restrict userdata,
5694  const int n,
5695  const TaskParallelTLS *__restrict tls)
5696 {
5697  SculptThreadedTaskData *data = userdata;
5698  SculptSession *ss = data->ob->sculpt;
5699  const Brush *brush = data->brush;
5700  float *offset = data->offset;
5701 
5702  PBVHVertexIter vd;
5703  float(*proxy)[3];
5704 
5705  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
5706 
5707  SculptBrushTest test;
5709  ss, &test, data->brush->falloff_shape);
5710  const int thread_id = BLI_task_parallel_thread_id(tls);
5711 
5712  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5713  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
5714  continue;
5715  }
5716  const float fade = SCULPT_brush_strength_factor(ss,
5717  brush,
5718  vd.co,
5719  sqrtf(test.dist),
5720  vd.no,
5721  vd.fno,
5722  vd.mask ? *vd.mask : 0.0f,
5723  vd.index,
5724  thread_id);
5725 
5726  mul_v3_v3fl(proxy[vd.i], offset, fade);
5727 
5728  if (vd.mvert) {
5730  }
5731  }
5733 }
5734 
5735 static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength)
5736 {
5737  SculptSession *ss = ob->sculpt;
5738  Brush *brush = BKE_paint_brush(&sd->paint);
5739 
5740  float offset[3];
5741  float gravity_vector[3];
5742 
5743  mul_v3_v3fl(gravity_vector, ss->cache->gravity_direction, -ss->cache->radius_squared);
5744 
5745  /* Offset with as much as possible factored in already. */
5746  mul_v3_v3v3(offset, gravity_vector, ss->cache->scale);
5747  mul_v3_fl(offset, bstrength);
5748 
5749  /* Threaded loop over nodes. */
5751  .sd = sd,
5752  .ob = ob,
5753  .brush = brush,
5754  .nodes = nodes,
5755  .offset = offset,
5756  };
5757 
5758  TaskParallelSettings settings;
5759  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5760  BLI_task_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings);
5761 }
5762 
5763 void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3])
5764 {
5765  Mesh *me = (Mesh *)ob->data;
5766  float(*ofs)[3] = NULL;
5767  int a;
5768  const int kb_act_idx = ob->shapenr - 1;
5769  KeyBlock *currkey;
5770 
5771  /* For relative keys editing of base should update other keys. */
5772  if (BKE_keyblock_is_basis(me->key, kb_act_idx)) {
5773  ofs = BKE_keyblock_convert_to_vertcos(ob, kb);
5774 
5775  /* Calculate key coord offsets (from previous location). */
5776  for (a = 0; a < me->totvert; a++) {
5777  sub_v3_v3v3(ofs[a], vertCos[a], ofs[a]);
5778  }
5779 
5780  /* Apply offsets on other keys. */
5781  for (currkey = me->key->block.first; currkey; currkey = currkey->next) {
5782  if ((currkey != kb) && (currkey->relative == kb_act_idx)) {
5783  BKE_keyblock_update_from_offset(ob, currkey, ofs);
5784  }
5785  }
5786 
5787  MEM_freeN(ofs);
5788  }
5789 
5790  /* Modifying of basis key should update mesh. */
5791  if (kb == me->key->refkey) {
5792  MVert *mvert = me->mvert;
5793 
5794  for (a = 0; a < me->totvert; a++, mvert++) {
5795  copy_v3_v3(mvert->co, vertCos[a]);
5796  }
5797 
5799  }
5800 
5801  /* Apply new coords on active key block, no need to re-allocate kb->data here! */
5802  BKE_keyblock_update_from_vertcos(ob, kb, vertCos);
5803 }
5804 
5805 /* Note: we do the topology update before any brush actions to avoid
5806  * issues with the proxies. The size of the proxy can't change, so
5807  * topology must be updated first. */
5809  Object *ob,
5810  Brush *brush,
5812 {
5813  SculptSession *ss = ob->sculpt;
5814 
5815  int n, totnode;
5816  /* Build a list of all nodes that are potentially within the brush's area of influence. */
5817  const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
5818  ss->cache->original;
5819  const float radius_scale = 1.25f;
5821  ob, sd, brush, use_original, radius_scale, &totnode);
5822 
5823  /* Only act if some verts are inside the brush area. */
5824  if (totnode == 0) {
5825  return;
5826  }
5827 
5828  /* Free index based vertex info as it will become invalid after modifying the topology during the
5829  * stroke. */
5832 
5833  PBVHTopologyUpdateMode mode = 0;
5834  float location[3];
5835 
5836  if (!(sd->flags & SCULPT_DYNTOPO_DETAIL_MANUAL)) {
5837  if (sd->flags & SCULPT_DYNTOPO_SUBDIVIDE) {
5838  mode |= PBVH_Subdivide;
5839  }
5840 
5841  if ((sd->flags & SCULPT_DYNTOPO_COLLAPSE) || (brush->sculpt_tool == SCULPT_TOOL_SIMPLIFY)) {
5842  mode |= PBVH_Collapse;
5843  }
5844  }
5845 
5846  for (n = 0; n < totnode; n++) {
5848  nodes[n],
5851  BKE_pbvh_node_mark_update(nodes[n]);
5852 
5853  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
5855  BKE_pbvh_bmesh_node_save_orig(ss->bm, nodes[n]);
5856  }
5857  }
5858 
5859  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
5861  mode,
5862  ss->cache->location,
5863  ss->cache->view_normal,
5864  ss->cache->radius,
5865  (brush->flag & BRUSH_FRONTFACE) != 0,
5867  }
5868 
5869  MEM_SAFE_FREE(nodes);
5870 
5871  /* Update average stroke position. */
5872  copy_v3_v3(location, ss->cache->true_location);
5873  mul_m4_v3(ob->obmat, location);
5874 }
5875 
5876 static void do_brush_action_task_cb(void *__restrict userdata,
5877  const int n,
5878  const TaskParallelTLS *__restrict UNUSED(tls))
5879 {
5880  SculptThreadedTaskData *data = userdata;
5881  SculptSession *ss = data->ob->sculpt;
5882 
5883  /* Face Sets modifications do a single undo push */
5884  if (data->brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS) {
5885  BKE_pbvh_node_mark_redraw(data->nodes[n]);
5886  /* Draw face sets in smooth mode moves the vertices. */
5887  if (ss->cache->alt_smooth) {
5889  BKE_pbvh_node_mark_update(data->nodes[n]);
5890  }
5891  }
5892  else if (data->brush->sculpt_tool == SCULPT_TOOL_MASK) {
5895  }
5896  else if (ELEM(data->brush->sculpt_tool, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
5899  }
5900  else {
5902  BKE_pbvh_node_mark_update(data->nodes[n]);
5903  }
5904 }
5905 
5906 static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups)
5907 {
5908  SculptSession *ss = ob->sculpt;
5909  int totnode;
5910  PBVHNode **nodes;
5911 
5912  /* Check for unsupported features. */
5914  if (brush->sculpt_tool == SCULPT_TOOL_PAINT && type != PBVH_FACES) {
5915  return;
5916  }
5917 
5918  if (brush->sculpt_tool == SCULPT_TOOL_SMEAR && type != PBVH_FACES) {
5919  return;
5920  }
5921 
5922  /* Build a list of all nodes that are potentially within the brush's area of influence */
5923 
5924  if (SCULPT_tool_needs_all_pbvh_nodes(brush)) {
5925  /* These brushes need to update all nodes as they are not constrained by the brush radius */
5926  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
5927  }
5928  else if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
5929  nodes = SCULPT_cloth_brush_affected_nodes_gather(ss, brush, &totnode);
5930  }
5931  else {
5932  const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
5933  ss->cache->original;
5934  float radius_scale = 1.0f;
5935  /* With these options enabled not all required nodes are inside the original brush radius, so
5936  * the brush can produce artifacts in some situations. */
5937  if (brush->sculpt_tool == SCULPT_TOOL_DRAW && brush->flag & BRUSH_ORIGINAL_NORMAL) {
5938  radius_scale = 2.0f;
5939  }
5940  nodes = sculpt_pbvh_gather_generic(ob, sd, brush, use_original, radius_scale, &totnode);
5941  }
5942 
5943  /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the
5944  * vertices and uses regular coords undo. */
5945  /* It also assigns the paint_face_set here as it needs to be done regardless of the stroke type
5946  * and the number of nodes under the brush influence. */
5947  if (brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS &&
5949 
5950  /* Dynamic-topology does not support Face Sets data, so it can't store/restore it from undo. */
5951  /* TODO(pablodp606): This check should be done in the undo code and not here, but the rest of
5952  * the sculpt code is not checking for unsupported undo types that may return a null node. */
5953  if (BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {
5955  }
5956 
5957  if (ss->cache->invert) {
5958  /* When inverting the brush, pick the paint face mask ID from the mesh. */
5960  }
5961  else {
5962  /* By default create a new Face Sets. */
5964  }
5965  }
5966 
5967  /* For anchored brushes with spherical falloff, we start off with zero radius, thus we have no
5968  * PBVH nodes on the first brush step. */
5969  if (totnode ||
5970  ((brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) && (brush->flag & BRUSH_ANCHORED))) {
5972  /* Initialize auto-masking cache. */
5973  if (SCULPT_is_automasking_enabled(sd, ss, brush)) {
5974  ss->cache->automasking = SCULPT_automasking_cache_init(sd, brush, ob);
5975  }
5976  /* Initialize surface smooth cache. */
5977  if ((brush->sculpt_tool == SCULPT_TOOL_SMOOTH) &&
5981  sizeof(float[3]) * SCULPT_vertex_count_get(ss), "HC smooth laplacian b");
5982  }
5983  }
5984  }
5985 
5986  /* Only act if some verts are inside the brush area. */
5987  if (totnode == 0) {
5988  return;
5989  }
5990  float location[3];
5991 
5992  SculptThreadedTaskData task_data = {
5993  .sd = sd,
5994  .ob = ob,
5995  .brush = brush,
5996  .nodes = nodes,
5997  };
5998 
5999  TaskParallelSettings settings;
6000  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
6001  BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
6002 
6003  if (sculpt_brush_needs_normal(ss, brush)) {
6004  update_sculpt_normal(sd, ob, nodes, totnode);
6005  }
6006 
6007  if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) {
6008  update_brush_local_mat(sd, ob);
6009  }
6010 
6012  SCULPT_pose_brush_init(sd, ob, ss, brush);
6013  }
6014 
6016  if (!ss->cache->cloth_sim) {
6018  ss, 1.0f, 0.0f, 0.0f, false, true);
6020  }
6023  sd, ob, nodes, totnode, ss->cache->cloth_sim, ss->cache->location, FLT_MAX);
6024  }
6025 
6026  bool invert = ss->cache->pen_flip || ss->cache->invert || brush->flag & BRUSH_DIR_IN;
6027 
6028  /* Apply one type of brush action. */
6029  switch (brush->sculpt_tool) {
6030  case SCULPT_TOOL_DRAW:
6031  do_draw_brush(sd, ob, nodes, totnode);
6032  break;
6033  case SCULPT_TOOL_SMOOTH:
6035  SCULPT_do_smooth_brush(sd, ob, nodes, totnode);
6036  }
6037  else if (brush->smooth_deform_type == BRUSH_SMOOTH_DEFORM_SURFACE) {
6038  SCULPT_do_surface_smooth_brush(sd, ob, nodes, totnode);
6039  }
6040  break;
6041  case SCULPT_TOOL_CREASE:
6042  do_crease_brush(sd, ob, nodes, totnode);
6043  break;
6044  case SCULPT_TOOL_BLOB:
6045  do_crease_brush(sd, ob, nodes, totnode);
6046  break;
6047  case SCULPT_TOOL_PINCH:
6048  do_pinch_brush(sd, ob, nodes, totnode);
6049  break;
6050  case SCULPT_TOOL_INFLATE:
6051  do_inflate_brush(sd, ob, nodes, totnode);
6052  break;
6053  case SCULPT_TOOL_GRAB:
6054  do_grab_brush(sd, ob, nodes, totnode);
6055  break;
6056  case SCULPT_TOOL_ROTATE:
6057  do_rotate_brush(sd, ob, nodes, totnode);
6058  break;
6060  do_snake_hook_brush(sd, ob, nodes, totnode);
6061  break;
6062  case SCULPT_TOOL_NUDGE:
6063  do_nudge_brush(sd, ob, nodes, totnode);
6064  break;
6065  case SCULPT_TOOL_THUMB:
6066  do_thumb_brush(sd, ob, nodes, totnode);
6067  break;
6068  case SCULPT_TOOL_LAYER:
6069  do_layer_brush(sd, ob, nodes, totnode);
6070  break;
6071  case SCULPT_TOOL_FLATTEN:
6072  do_flatten_brush(sd, ob, nodes, totnode);
6073  break;
6074  case SCULPT_TOOL_CLAY:
6075  do_clay_brush(sd, ob, nodes, totnode);
6076  break;
6078  do_clay_strips_brush(sd, ob, nodes, totnode);
6079  break;
6081  SCULPT_do_multiplane_scrape_brush(sd, ob, nodes, totnode);
6082  break;
6084  do_clay_thumb_brush(sd, ob, nodes, totnode);
6085  break;
6086  case SCULPT_TOOL_FILL:
6087  if (invert && brush->flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
6088  do_scrape_brush(sd, ob, nodes, totnode);
6089  }
6090  else {
6091  do_fill_brush(sd, ob, nodes, totnode);
6092  }
6093  break;
6094  case SCULPT_TOOL_SCRAPE:
6095  if (invert && brush->flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
6096  do_fill_brush(sd, ob, nodes, totnode);
6097  }
6098  else {
6099  do_scrape_brush(sd, ob, nodes, totnode);
6100  }
6101  break;
6102  case SCULPT_TOOL_MASK:
6103  do_mask_brush(sd, ob, nodes, totnode);
6104  break;
6105  case SCULPT_TOOL_POSE:
6106  SCULPT_do_pose_brush(sd, ob, nodes, totnode);
6107  break;
6109  do_draw_sharp_brush(sd, ob, nodes, totnode);
6110  break;
6112  do_elastic_deform_brush(sd, ob, nodes, totnode);
6113  break;
6115  do_slide_relax_brush(sd, ob, nodes, totnode);
6116  break;
6117  case SCULPT_TOOL_BOUNDARY:
6118  SCULPT_do_boundary_brush(sd, ob, nodes, totnode);
6119  break;
6120  case SCULPT_TOOL_CLOTH:
6121  SCULPT_do_cloth_brush(sd, ob, nodes, totnode);
6122  break;
6124  SCULPT_do_draw_face_sets_brush(sd, ob, nodes, totnode);
6125  break;
6127  do_displacement_eraser_brush(sd, ob, nodes, totnode);
6128  break;
6130  do_displacement_smear_brush(sd, ob, nodes, totnode);
6131  break;
6132  case SCULPT_TOOL_PAINT:
6133  SCULPT_do_paint_brush(sd, ob, nodes, totnode);
6134  break;
6135  case SCULPT_TOOL_SMEAR:
6136  SCULPT_do_smear_brush(sd, ob, nodes, totnode);
6137  break;
6138  }
6139 
6141  brush->autosmooth_factor > 0) {
6142  if (brush->flag & BRUSH_INVERSE_SMOOTH_PRESSURE) {
6143  SCULPT_smooth(
6144  sd, ob, nodes, totnode, brush->autosmooth_factor * (1.0f - ss->cache->pressure), false);
6145  }
6146  else {
6147  SCULPT_smooth(sd, ob, nodes, totnode, brush->autosmooth_factor, false);
6148  }
6149  }
6150 
6151  if (sculpt_brush_use_topology_rake(ss, brush)) {
6152  bmesh_topology_rake(sd, ob, nodes, totnode, brush->topology_rake_factor);
6153  }
6154 
6155  /* The cloth brush adds the gravity as a regular force and it is processed in the solver. */
6156  if (ss->cache->supports_gravity && !ELEM(brush->sculpt_tool,
6160  do_gravity(sd, ob, nodes, totnode, sd->gravity_factor);
6161  }
6162 
6165  SCULPT_cloth_sim_activate_nodes(ss->cache->cloth_sim, nodes, totnode);
6166  SCULPT_cloth_brush_do_simulation_step(sd, ob, ss->cache->cloth_sim, nodes, totnode);
6167  }
6168  }
6169 
6170  MEM_SAFE_FREE(nodes);
6171 
6172  /* Update average stroke position. */
6173  copy_v3_v3(location, ss->cache->true_location);
6174  mul_m4_v3(ob->obmat, location);
6175 
6176  add_v3_v3(ups->average_stroke_accum, location);
6177  ups->average_stroke_counter++;
6178  /* Update last stroke position. */
6179  ups->last_stroke_valid = true;
6180 }
6181 
6182 /* Flush displacement from deformed PBVH vertex to original mesh. */
6184 {
6185  SculptSession *ss = ob->sculpt;
6186  Mesh *me = ob->data;
6187  float disp[3], newco[3];
6188  int index = vd->vert_indices[vd->i];
6189 
6190  sub_v3_v3v3(disp, vd->co, ss->deform_cos[index]);
6191  mul_m3_v3(ss->deform_imats[index], disp);
6192  add_v3_v3v3(newco, disp, ss->orig_cos[index]);
6193 
6194  copy_v3_v3(ss->deform_cos[index], vd->co);
6195  copy_v3_v3(ss->orig_cos[index], newco);
6196 
6197  if (!ss->shapekey_active) {
6198  copy_v3_v3(me->mvert[index].co, newco);
6199  }
6200 }
6201 
6202 static void sculpt_combine_proxies_task_cb(void *__restrict userdata,
6203  const int n,
6204  const TaskParallelTLS *__restrict UNUSED(tls))
6205 {
6206  SculptThreadedTaskData *data = userdata;
6207  SculptSession *ss = data->ob->sculpt;
6208  Sculpt *sd = data->sd;
6209  Object *ob = data->ob;
6210 
6211  /* These brushes start from original coordinates. */
6212  const bool use_orco = ELEM(data->brush->sculpt_tool,
6219 
6220  PBVHVertexIter vd;
6221  PBVHProxyNode *proxies;
6222  int proxy_count;
6223  float(*orco)[3] = NULL;
6224 
6225  if (use_orco && !ss->bm) {
6226  orco = SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS)->co;
6227  }
6228 
6229  BKE_pbvh_node_get_proxies(data->nodes[n], &proxies, &proxy_count);
6230 
6231  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
6232  float val[3];
6233 
6234  if (use_orco) {
6235  if (ss->bm) {
6237  }
6238  else {
6239  copy_v3_v3(val, orco[vd.i]);
6240  }
6241  }
6242  else {
6243  copy_v3_v3(val, vd.co);
6244  }
6245 
6246  for (int p = 0; p < proxy_count; p++) {
6247  add_v3_v3(val, proxies[p].co[vd.i]);
6248  }
6249 
6250  SCULPT_clip(sd, ss, vd.co, val);
6251 
6252  if (ss->deform_modifiers_active) {
6254  }
6255  }
6257 
6258  BKE_pbvh_node_free_proxies(data->nodes[n]);
6259 }
6260 
6261 static void sculpt_combine_proxies(Sculpt *sd, Object *ob)
6262 {
6263  SculptSession *ss = ob->sculpt;
6264  Brush *brush = BKE_paint_brush(&sd->paint);
6265  PBVHNode **nodes;
6266  int totnode;
6267 
6269  /* First line is tools that don't support proxies. */
6270  return;
6271  }
6272 
6273  BKE_pbvh_gather_proxies(ss->pbvh, &nodes, &totnode);
6275  .sd = sd,
6276  .ob = ob,
6277  .brush = brush,
6278  .nodes = nodes,
6279  };
6280 
6281  TaskParallelSettings settings;
6282  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
6284  MEM_SAFE_FREE(nodes);
6285 }
6286 
6291 {
6292  SculptSession *ss = ob->sculpt;
6293  float(*vertCos)[3];
6294 
6295  /* Key-block update happens after handling deformation caused by modifiers,
6296  * so ss->orig_cos would be updated with new stroke. */
6297  if (ss->orig_cos) {
6298  vertCos = ss->orig_cos;
6299  }
6300  else {
6301  vertCos = BKE_pbvh_vert_coords_alloc(ss->pbvh);
6302  }
6303 
6304  if (!vertCos) {
6305  return;
6306  }
6307 
6308  SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos);
6309 
6310  if (vertCos != ss->orig_cos) {
6311  MEM_freeN(vertCos);
6312  }
6313 }
6314 
6315 static void SCULPT_flush_stroke_deform_task_cb(void *__restrict userdata,
6316  const int n,
6317  const TaskParallelTLS *__restrict UNUSED(tls))
6318 {
6319  SculptThreadedTaskData *data = userdata;
6320  SculptSession *ss = data->ob->sculpt;
6321  Object *ob = data->ob;
6322  float(*vertCos)[3] = data->vertCos;
6323 
6324  PBVHVertexIter vd;
6325 
6326  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
6328 
6329  if (!vertCos) {
6330  continue;
6331  }
6332 
6333  int index = vd.vert_indices[vd.i];
6334  copy_v3_v3(vertCos[index], ss->orig_cos[index]);
6335  }
6337 }
6338 
6339 /* Flush displacement from deformed PBVH to original layer. */
6340 void SCULPT_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_used)
6341 {
6342  SculptSession *ss = ob->sculpt;
6343  Brush *brush = BKE_paint_brush(&sd->paint);
6344 
6345  if (is_proxy_used && ss->deform_modifiers_active) {
6346  /* This brushes aren't using proxies, so sculpt_combine_proxies() wouldn't propagate needed
6347  * deformation to original base. */
6348 
6349  int totnode;
6350  Mesh *me = (Mesh *)ob->data;
6351  PBVHNode **nodes;
6352  float(*vertCos)[3] = NULL;
6353 
6354  if (ss->shapekey_active) {
6355  vertCos = MEM_mallocN(sizeof(*vertCos) * me->totvert, "flushStrokeDeofrm keyVerts");
6356 
6357  /* Mesh could have isolated verts which wouldn't be in BVH, to deal with this we copy old
6358  * coordinates over new ones and then update coordinates for all vertices from BVH. */
6359  memcpy(vertCos, ss->orig_cos, sizeof(*vertCos) * me->totvert);
6360  }
6361 
6362  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
6363 
6365  .sd = sd,
6366  .ob = ob,
6367  .brush = brush,
6368  .nodes = nodes,
6369  .vertCos = vertCos,
6370  };
6371 
6372  TaskParallelSettings settings;
6373  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
6375 
6376  if (vertCos) {
6377  SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos);
6378  MEM_freeN(vertCos);
6379  }
6380 
6381  MEM_SAFE_FREE(nodes);
6382 
6383  /* Modifiers could depend on mesh normals, so we should update them.
6384  * Note, then if sculpting happens on locked key, normals should be re-calculate after applying
6385  * coords from key-block on base mesh. */
6387  }
6388  else if (ss->shapekey_active) {
6390  }
6391 }
6392 
6398  const char symm,
6399  const char axis,
6400  const float angle)
6401 {
6402  flip_v3_v3(cache->location, cache->true_location, symm);
6403  flip_v3_v3(cache->last_location, cache->true_last_location, symm);
6404  flip_v3_v3(cache->grab_delta_symmetry, cache->grab_delta, symm);
6405  flip_v3_v3(cache->view_normal, cache->true_view_normal, symm);
6406 
6407  flip_v3_v3(cache->initial_location, cache->true_initial_location, symm);
6408  flip_v3_v3(cache->initial_normal, cache->true_initial_normal, symm);
6409 
6410  /* XXX This reduces the length of the grab delta if it approaches the line of symmetry
6411  * XXX However, a different approach appears to be needed. */
6412 #if 0
6414  float frac = 1.0f / max_overlap_count(sd);
6415  float reduce = (feather - frac) / (1.0f - frac);
6416 
6417  printf("feather: %f frac: %f reduce: %f\n", feather, frac, reduce);
6418 
6419  if (frac < 1.0f) {
6420  mul_v3_fl(cache->grab_delta_symmetry, reduce);
6421  }
6422  }
6423 #endif
6424 
6425  unit_m4(cache->symm_rot_mat);
6426  unit_m4(cache->symm_rot_mat_inv);
6427  zero_v3(cache->plane_offset);
6428 
6429  /* Expects XYZ. */
6430  if (axis) {
6431  rotate_m4(cache->symm_rot_mat, axis, angle);
6432  rotate_m4(cache->symm_rot_mat_inv, axis, -angle);
6433  }
6434 
6435  mul_m4_v3(cache->symm_rot_mat, cache->location);
6436  mul_m4_v3(cache->symm_rot_mat, cache->grab_delta_symmetry);
6437 
6438  if (cache->supports_gravity) {
6439  flip_v3_v3(cache->gravity_direction, cache->true_gravity_direction, symm);
6440  mul_m4_v3(cache->symm_rot_mat, cache->gravity_direction);
6441  }
6442 
6443  if (cache->is_rake_rotation_valid) {
6444  flip_qt_qt(cache->rake_rotation_symmetry, cache->rake_rotation, symm);
6445  }
6446 }
6447 
6448 typedef void (*BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups);
6449 
6450 static void do_tiled(
6451  Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action)
6452 {
6453  SculptSession *ss = ob->sculpt;
6454  StrokeCache *cache = ss->cache;
6455  const float radius = cache->radius;
6457  const float *bbMin = bb->vec[0];
6458  const float *bbMax = bb->vec[6];
6459  const float *step = sd->paint.tile_offset;
6460 
6461  /* These are integer locations, for real location: multiply with step and add orgLoc.
6462  * So 0,0,0 is at orgLoc. */
6463  int start[3];
6464  int end[3];
6465  int cur[3];
6466 
6467  /* Position of the "prototype" stroke for tiling. */
6468  float orgLoc[3];
6469  float original_initial_location[3];
6470  copy_v3_v3(orgLoc, cache->location);
6471  copy_v3_v3(original_initial_location, cache->initial_location);
6472 
6473  for (int dim = 0; dim < 3; dim++) {
6474  if ((sd->paint.symmetry_flags & (PAINT_TILE_X << dim)) && step[dim] > 0) {
6475  start[dim] = (bbMin[dim] - orgLoc[dim] - radius) / step[dim];
6476  end[dim] = (bbMax[dim] - orgLoc[dim] + radius) / step[dim];
6477  }
6478  else {
6479  start[dim] = end[dim] = 0;
6480  }
6481  }
6482 
6483  /* First do the "un-tiled" position to initialize the stroke for this location. */
6484  cache->tile_pass = 0;
6485  action(sd, ob, brush, ups);
6486 
6487  /* Now do it for all the tiles. */
6488  copy_v3_v3_int(cur, start);
6489  for (cur[0] = start[0]; cur[0] <= end[0]; cur[0]++) {
6490  for (cur[1] = start[1]; cur[1] <= end[1]; cur[1]++) {
6491  for (cur[2] = start[2]; cur[2] <= end[2]; cur[2]++) {
6492  if (!cur[0] && !cur[1] && !cur[2]) {
6493  /* Skip tile at orgLoc, this was already handled before all others. */
6494  continue;
6495  }
6496 
6497  ++cache->tile_pass;
6498 
6499  for (int dim = 0; dim < 3; dim++) {
6500  cache->location[dim] = cur[dim] * step[dim] + orgLoc[dim];
6501  cache->plane_offset[dim] = cur[dim] * step[dim];
6502  cache->initial_location[dim] = cur[dim] * step[dim] + original_initial_location[dim];
6503  }
6504  action(sd, ob, brush, ups);
6505  }
6506  }
6507  }
6508 }
6509 
6510 static void do_radial_symmetry(Sculpt *sd,
6511  Object *ob,
6512  Brush *brush,
6513  UnifiedPaintSettings *ups,
6514  BrushActionFunc action,
6515  const char symm,
6516  const int axis,
6517  const float UNUSED(feather))
6518 {
6519  SculptSession *ss = ob->sculpt;
6520 
6521  for (int i = 1; i < sd->radial_symm[axis - 'X']; i++) {
6522  const float angle = 2.0f * M_PI * i / sd->radial_symm[axis - 'X'];
6523  ss->cache->radial_symmetry_pass = i;
6524  SCULPT_cache_calc_brushdata_symm(ss->cache, symm, axis, angle);
6525  do_tiled(sd, ob, brush, ups, action);
6526  }
6527 }
6528 
6533 static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
6534 {
6535  SculptSession *ss = ob->sculpt;
6536  Brush *brush = BKE_paint_brush(&sd->paint);
6537  MTex *mtex = &brush->mtex;
6538 
6539  if (ss->multires.active && mtex->tex && mtex->tex->type == TEX_NOISE) {
6541  }
6542 }
6543 
6545  Object *ob,
6546  BrushActionFunc action,
6547  UnifiedPaintSettings *ups)
6548 {
6549  Brush *brush = BKE_paint_brush(&sd->paint);
6550  SculptSession *ss = ob->sculpt;
6551  StrokeCache *cache = ss->cache;
6552  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
6553 
6554  float feather = calc_symmetry_feather(sd, ss->cache);
6555 
6556  cache->bstrength = brush_strength(sd, cache, feather, ups);
6557  cache->symmetry = symm;
6558 
6559  /* `symm` is a bit combination of XYZ -
6560  * 1 is mirror X; 2 is Y; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ; 7 is XYZ */
6561  for (int i = 0; i <= symm; i++) {
6562  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
6563  continue;
6564  }
6565  cache->mirror_symmetry_pass = i;
6566  cache->radial_symmetry_pass = 0;
6567 
6568  SCULPT_cache_calc_brushdata_symm(cache, i, 0, 0);
6569  do_tiled(sd, ob, brush, ups, action);
6570 
6571  do_radial_symmetry(sd, ob, brush, ups, action, i, 'X', feather);
6572  do_radial_symmetry(sd, ob, brush, ups, action, i, 'Y', feather);
6573  do_radial_symmetry(sd, ob, brush, ups, action, i, 'Z', feather);
6574  }
6575 }
6576 
6577 static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss)
6578 {
6579  Brush *brush = BKE_paint_brush(&sd->paint);
6580  const int radius = BKE_brush_size_get(scene, brush);
6581 
6582  if (ss->texcache) {
6583  MEM_freeN(ss->texcache);
6584  ss->texcache = NULL;
6585  }
6586 
6587  if (ss->tex_pool) {
6589  ss->tex_pool = NULL;
6590  }
6591 
6592  /* Need to allocate a bigger buffer for bigger brush size. */
6593  ss->texcache_side = 2 * radius;
6594  if (!ss->texcache || ss->texcache_side > ss->texcache_actual) {
6595  ss->texcache = BKE_brush_gen_texture_cache(brush, radius, false);
6596  ss->texcache_actual = ss->texcache_side;
6597  ss->tex_pool = BKE_image_pool_new();
6598  }
6599 }
6600 
6602 {
6604  return ob && ob->mode & OB_MODE_SCULPT;
6605 }
6606 
6608 {
6609  if (!U.experimental.use_sculpt_vertex_colors) {
6610  return false;
6611  }
6612  return SCULPT_mode_poll(C);
6613 }
6614 
6616 {
6617  return (SCULPT_mode_poll(C) && CTX_wm_region_view3d(C));
6618 }
6619 
6621 {
6622  return (SCULPT_poll(C) && CTX_wm_region_view3d(C));
6623 }
6624 
6626 {
6627  return SCULPT_mode_poll(C) && paint_poll(C);
6628 }
6629 
6630 static const char *sculpt_tool_name(Sculpt *sd)
6631 {
6632  Brush *brush = BKE_paint_brush(&sd->paint);
6633 
6634  switch ((eBrushSculptTool)brush->sculpt_tool) {
6635  case SCULPT_TOOL_DRAW:
6636  return "Draw Brush";
6637  case SCULPT_TOOL_SMOOTH:
6638  return "Smooth Brush";
6639  case SCULPT_TOOL_CREASE:
6640  return "Crease Brush";
6641  case SCULPT_TOOL_BLOB:
6642  return "Blob Brush";
6643  case SCULPT_TOOL_PINCH:
6644  return "Pinch Brush";
6645  case SCULPT_TOOL_INFLATE:
6646  return "Inflate Brush";
6647  case SCULPT_TOOL_GRAB:
6648  return "Grab Brush";
6649  case SCULPT_TOOL_NUDGE:
6650  return "Nudge Brush";
6651  case SCULPT_TOOL_THUMB:
6652  return "Thumb Brush";
6653  case SCULPT_TOOL_LAYER:
6654  return "Layer Brush";
6655  case SCULPT_TOOL_FLATTEN:
6656  return "Flatten Brush";
6657  case SCULPT_TOOL_CLAY:
6658  return "Clay Brush";
6660  return "Clay Strips Brush";
6662  return "Clay Thumb Brush";
6663  case SCULPT_TOOL_FILL:
6664  return "Fill Brush";
6665  case SCULPT_TOOL_SCRAPE:
6666  return "Scrape Brush";
6668  return "Snake Hook Brush";
6669  case SCULPT_TOOL_ROTATE:
6670  return "Rotate Brush";
6671  case SCULPT_TOOL_MASK:
6672  return "Mask Brush";
6673  case SCULPT_TOOL_SIMPLIFY:
6674  return "Simplify Brush";
6676  return "Draw Sharp Brush";
6678  return "Elastic Deform Brush";
6679  case SCULPT_TOOL_POSE:
6680  return "Pose Brush";
6682  return "Multi-plane Scrape Brush";
6684  return "Slide/Relax Brush";
6685  case SCULPT_TOOL_BOUNDARY:
6686  return "Boundary Brush";
6687  case SCULPT_TOOL_CLOTH:
6688  return "Cloth Brush";
6690  return "Draw Face Sets";
6692  return "Multires Displacement Eraser";
6694  return "Multires Displacement Smear";
6695  case SCULPT_TOOL_PAINT:
6696  return "Paint Brush";
6697  case SCULPT_TOOL_SMEAR:
6698  return "Smear Brush";
6699  }
6700 
6701  return "Sculpting";
6702 }
6703 
6709 {
6710  MEM_SAFE_FREE(cache->dial);
6713  MEM_SAFE_FREE(cache->prev_colors);
6717 
6718  if (cache->pose_ik_chain) {
6720  }
6721 
6722  for (int i = 0; i < PAINT_SYMM_AREAS; i++) {
6723  if (cache->boundaries[i]) {
6725  }
6726  }
6727 
6728  if (cache->cloth_sim) {
6730  }
6731 
6732  MEM_freeN(cache);
6733 }
6734 
6735 /* Initialize mirror modifier clipping. */
6737 {
6738  ModifierData *md;
6739 
6741 
6742  for (md = ob->modifiers.first; md; md = md->next) {
6743  if (!(md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime))) {
6744  continue;
6745  }
6747 
6748  if (!(mmd->flag & MOD_MIR_CLIPPING)) {
6749  continue;
6750  }
6751  /* Check each axis for mirroring. */
6752  for (int i = 0; i < 3; i++) {
6753  if (!(mmd->flag & (MOD_MIR_AXIS_X << i))) {
6754  continue;
6755  }
6756  /* Enable sculpt clipping. */
6757  ss->cache->flag |= CLIP_X << i;
6758 
6759  /* Update the clip tolerance. */
6760  if (mmd->tolerance > ss->cache->clip_tolerance[i]) {
6761  ss->cache->clip_tolerance[i] = mmd->tolerance;
6762  }
6763 
6764  /* Store matrix for mirror object clipping. */
6765  if (mmd->mirror_ob) {
6766  float imtx_mirror_ob[4][4];
6767  invert_m4_m4(imtx_mirror_ob, mmd->mirror_ob->obmat);
6768  mul_m4_m4m4(ss->cache->clip_mirror_mtx, imtx_mirror_ob, ob->obmat);
6769  }
6770  }
6771  }
6772 }
6773 
6774 /* Initialize the stroke cache invariants from operator properties. */
6776  bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mouse[2])
6777 {
6778  StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
6779  Main *bmain = CTX_data_main(C);
6782  Brush *brush = BKE_paint_brush(&sd->paint);
6785  float mat[3][3];
6786  float viewDir[3] = {0.0f, 0.0f, 1.0f};
6787  float max_scale;
6788  int mode;
6789 
6790  ss->cache = cache;
6791 
6792  /* Set scaling adjustment. */
6793  max_scale = 0.0f;
6794  for (int i = 0; i < 3; i++) {
6795  max_scale = max_ff(max_scale, fabsf(ob->scale[i]));
6796  }
6797  cache->scale[0] = max_scale / ob->scale[0];
6798  cache->scale[1] = max_scale / ob->scale[1];
6799  cache->scale[2] = max_scale / ob->scale[2];
6800 
6801  cache->plane_trim_squared = brush->plane_trim * brush->plane_trim;
6802 
6803  cache->flag = 0;
6804 
6806 
6807  /* Initial mouse location. */
6808  if (mouse) {
6809  copy_v2_v2(cache->initial_mouse, mouse);
6810  }
6811  else {
6812  zero_v2(cache->initial_mouse);
6813  }
6814 
6817 
6820 
6821  mode = RNA_enum_get(op->ptr, "mode");
6822  cache->invert = mode == BRUSH_STROKE_INVERT;
6823  cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH;
6824  cache->normal_weight = brush->normal_weight;
6825 
6826  /* Interpret invert as following normal, for grab brushes. */
6828  if (cache->invert) {
6829  cache->invert = false;
6830  cache->normal_weight = (cache->normal_weight == 0.0f);
6831  }
6832  }
6833 
6834  /* Not very nice, but with current events system implementation
6835  * we can't handle brush appearance inversion hotkey separately (sergey). */
6836  if (cache->invert) {
6837  ups->draw_inverted = true;
6838  }
6839  else {
6840  ups->draw_inverted = false;
6841  }
6842 
6843  /* Alt-Smooth. */
6844  if (cache->alt_smooth) {
6845  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
6846  cache->saved_mask_brush_tool = brush->mask_tool;
6847  brush->mask_tool = BRUSH_MASK_SMOOTH;
6848  }
6849  else if (ELEM(brush->sculpt_tool,
6853  SCULPT_TOOL_SMEAR)) {
6854  /* Do nothing, this tool has its own smooth mode. */
6855  }
6856  else {
6857  Paint *p = &sd->paint;
6858  Brush *br;
6859  int size = BKE_brush_size_get(scene, brush);
6860 
6862  brush->id.name + 2,
6863  sizeof(cache->saved_active_brush_name));
6864 
6865  br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Smooth");
6866  if (br) {
6867  BKE_paint_brush_set(p, br);
6868  brush = br;
6869  cache->saved_smooth_size = BKE_brush_size_get(scene, brush);
6870  BKE_brush_size_set(scene, brush, size);
6871  BKE_curvemapping_init(brush->curve);
6872  }
6873  }
6874  }
6875 
6876  copy_v2_v2(cache->mouse, cache->initial_mouse);
6877  copy_v2_v2(cache->mouse_event, cache->initial_mouse);
6878  copy_v2_v2(ups->tex_mouse, cache->initial_mouse);
6879 
6880  /* Truly temporary data that isn't stored in properties. */
6881 
6882  cache->vc = vc;
6883 
6884  cache->brush = brush;
6885 
6886  /* Cache projection matrix. */
6887  ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat);
6888 
6889  invert_m4_m4(ob->imat, ob->obmat);
6890  copy_m3_m4(mat, cache->vc->rv3d->viewinv);
6891  mul_m3_v3(mat, viewDir);
6892  copy_m3_m4(mat, ob->imat);
6893  mul_m3_v3(mat, viewDir);
6894  normalize_v3_v3(cache->true_view_normal, viewDir);
6895 
6896  cache->supports_gravity = (!ELEM(brush->sculpt_tool,
6902  (sd->gravity_factor > 0.0f));
6903  /* Get gravity vector in world space. */
6904  if (cache->supports_gravity) {
6905  if (sd->gravity_object) {
6906  Object *gravity_object = sd->gravity_object;
6907 
6908  copy_v3_v3(cache->true_gravity_direction, gravity_object->obmat[2]);
6909  }
6910  else {
6911  cache->true_gravity_direction[0] = cache->true_gravity_direction[1] = 0.0f;
6912  cache->true_gravity_direction[2] = 1.0f;
6913  }
6914 
6915  /* Transform to sculpted object space. */
6916  mul_m3_v3(mat, cache->true_gravity_direction);
6918  }
6919 
6920  /* Make copies of the mesh vertex locations and normals for some tools. */
6921  if (brush->flag & BRUSH_ANCHORED) {
6922  cache->original = true;
6923  }
6924 
6925  /* Draw sharp does not need the original coordinates to produce the accumulate effect, so it
6926  * should work the opposite way. */
6927  if (brush->sculpt_tool == SCULPT_TOOL_DRAW_SHARP) {
6928  cache->original = true;
6929  }
6930 
6932  if (!(brush->flag & BRUSH_ACCUMULATE)) {
6933  cache->original = true;
6934  if (brush->sculpt_tool == SCULPT_TOOL_DRAW_SHARP) {
6935  cache->original = false;
6936  }
6937  }
6938  }
6939 
6940  cache->first_time = true;
6941 
6942 #define PIXEL_INPUT_THRESHHOLD 5
6943  if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) {
6945  }
6946 
6947 #undef PIXEL_INPUT_THRESHHOLD
6948 }
6949 
6950 static float sculpt_brush_dynamic_size_get(Brush *brush, StrokeCache *cache, float initial_size)
6951 {
6952  switch (brush->sculpt_tool) {
6953  case SCULPT_TOOL_CLAY:
6954  return max_ff(initial_size * 0.20f, initial_size * pow3f(cache->pressure));
6956  return max_ff(initial_size * 0.30f, initial_size * powf(cache->pressure, 1.5f));
6957  case SCULPT_TOOL_CLAY_THUMB: {
6958  float clay_stabilized_pressure = sculpt_clay_thumb_get_stabilized_pressure(cache);
6959  return initial_size * clay_stabilized_pressure;
6960  }
6961  default:
6962  return initial_size * cache->pressure;
6963  }
6964 }
6965 
6966 /* In these brushes the grab delta is calculated always from the initial stroke location, which is
6967  * generally used to create grab deformations. */
6969 {
6970  if (ELEM(brush->sculpt_tool,
6976  return true;
6977  }
6978  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH &&
6980  return true;
6981  }
6982  return false;
6983 }
6984 
6985 /* In these brushes the grab delta is calculated from the previous stroke location, which is used
6986  * to calculate to orientate the brush tip and deformation towards the stroke direction. */
6988 {
6989  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
6990  return brush->cloth_deform_type != BRUSH_CLOTH_DEFORM_GRAB;
6991  }
6992  return ELEM(brush->sculpt_tool,
6999 }
7000 
7002 {
7003  SculptSession *ss = ob->sculpt;
7004  StrokeCache *cache = ss->cache;
7005  const float mouse[2] = {
7006  cache->mouse_event[0],
7007  cache->mouse_event[1],
7008  };
7009  int tool = brush->sculpt_tool;
7010 
7011  if (!ELEM(tool,
7024  SCULPT_TOOL_THUMB) &&
7025  !sculpt_brush_use_topology_rake(ss, brush)) {
7026  return;
7027  }
7028  float grab_location[3], imat[4][4], delta[3], loc[3];
7029 
7031  if (tool == SCULPT_TOOL_GRAB && brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) {
7034  }
7035  else {
7037  }
7038  }
7039  else if (tool == SCULPT_TOOL_SNAKE_HOOK ||
7040  (tool == SCULPT_TOOL_CLOTH &&
7042  add_v3_v3(cache->true_location, cache->grab_delta);
7043  }
7044 
7045  /* Compute 3d coordinate at same z from original location + mouse. */
7046  mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location);
7047  ED_view3d_win_to_3d(cache->vc->v3d, cache->vc->region, loc, mouse, grab_location);
7048 
7049  /* Compute delta to move verts by. */
7052  sub_v3_v3v3(delta, grab_location, cache->old_grab_location);
7053  invert_m4_m4(imat, ob->obmat);
7054  mul_mat3_m4_v3(imat, delta);
7055  add_v3_v3(cache->grab_delta, delta);
7056  }
7057  else if (sculpt_needs_delta_for_tip_orientation(brush)) {
7058  if (brush->flag & BRUSH_ANCHORED) {
7059  float orig[3];
7060  mul_v3_m4v3(orig, ob->obmat, cache->orig_grab_location);
7061  sub_v3_v3v3(cache->grab_delta, grab_location, orig);
7062  }
7063  else {
7064  sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location);
7065  }
7066  invert_m4_m4(imat, ob->obmat);
7067  mul_mat3_m4_v3(imat, cache->grab_delta);
7068  }
7069  else {
7070  /* Use for 'Brush.topology_rake_factor'. */
7071  sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location);
7072  }
7073  }
7074  else {
7075  zero_v3(cache->grab_delta);
7076  }
7077 
7078  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
7080  }
7081 
7082  copy_v3_v3(cache->old_grab_location, grab_location);
7083 
7084  if (tool == SCULPT_TOOL_GRAB) {
7085  if (brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) {
7087  }
7088  else {
7089  copy_v3_v3(cache->anchored_location, cache->true_location);
7090  }
7091  }
7092  else if (tool == SCULPT_TOOL_ELASTIC_DEFORM || SCULPT_is_cloth_deform_brush(brush)) {
7093  copy_v3_v3(cache->anchored_location, cache->true_location);
7094  }
7095  else if (tool == SCULPT_TOOL_THUMB) {
7097  }
7098 
7100  /* Location stays the same for finding vertices in brush radius. */
7102 
7103  ups->draw_anchored = true;
7105  ups->anchored_size = ups->pixel_radius;
7106  }
7107 
7108  /* Handle 'rake' */
7109  cache->is_rake_rotation_valid = false;
7110 
7111  invert_m4_m4(imat, ob->obmat);
7112  mul_mat3_m4_v3(imat, grab_location);
7113 
7115  copy_v3_v3(cache->rake_data.follow_co, grab_location);
7116  }
7117 
7118  if (!sculpt_brush_needs_rake_rotation(brush)) {
7119  return;
7120  }
7122 
7123  if (!is_zero_v3(cache->grab_delta)) {
7124  const float eps = 0.00001f;
7125 
7126  float v1[3], v2[3];
7127 
7128  copy_v3_v3(v1, cache->rake_data.follow_co);
7129  copy_v3_v3(v2, cache->rake_data.follow_co);
7130  sub_v3_v3(v2, cache->grab_delta);
7131 
7132  sub_v3_v3(v1, grab_location);
7133  sub_v3_v3(v2, grab_location);
7134 
7135  if ((normalize_v3(v2) > eps) && (normalize_v3(v1) > eps) && (len_squared_v3v3(v1, v2) > eps)) {
7136  const float rake_dist_sq = len_squared_v3v3(cache->rake_data.follow_co, grab_location);
7137  const float rake_fade = (rake_dist_sq > square_f(cache->rake_data.follow_dist)) ?
7138  1.0f :
7139  sqrtf(rake_dist_sq) / cache->rake_data.follow_dist;
7140 
7141  float axis[3], angle;
7142  float tquat[4];
7143 
7145 
7146  /* Use axis-angle to scale rotation since the factor may be above 1. */
7147  quat_to_axis_angle(axis, &angle, tquat);
7148  normalize_v3(axis);
7149 
7150  angle *= brush->rake_factor * rake_fade;
7152  cache->is_rake_rotation_valid = true;
7153  }
7154  }
7155  sculpt_rake_data_update(&cache->rake_data, grab_location);
7156 }
7157 
7158 static void sculpt_update_cache_paint_variants(StrokeCache *cache, const Brush *brush)
7159 {
7160  cache->paint_brush.hardness = brush->hardness;
7163  1.0f - cache->pressure :
7164  cache->pressure;
7165  }
7166 
7167  cache->paint_brush.flow = brush->flow;
7168  if (brush->paint_flags & BRUSH_PAINT_FLOW_PRESSURE) {
7170  1.0f - cache->pressure :
7171  cache->pressure;
7172  }
7173 
7174  cache->paint_brush.wet_mix = brush->wet_mix;
7177  1.0f - cache->pressure :
7178  cache->pressure;
7179 
7180  /* This makes wet mix more sensible in higher values, which allows to create brushes that have
7181  * a wider pressure range were they only blend colors without applying too much of the brush
7182  * color. */
7183  cache->paint_brush.wet_mix = 1.0f - pow2f(1.0f - cache->paint_brush.wet_mix);
7184  }
7185 
7188  cache->paint_brush.wet_persistence = brush->paint_flags &
7190  1.0f - cache->pressure :
7191  cache->pressure;
7192  }
7193 
7194  cache->paint_brush.density = brush->density;
7197  1.0f - cache->pressure :
7198  cache->pressure;
7199  }
7200 }
7201 
7202 /* Initialize the stroke cache variants from operator properties. */
7204 {
7207  SculptSession *ss = ob->sculpt;
7208  StrokeCache *cache = ss->cache;
7209  Brush *brush = BKE_paint_brush(&sd->paint);
7210 
7212  !((brush->flag & BRUSH_ANCHORED) || (brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK) ||
7214  RNA_float_get_array(ptr, "location", cache->true_location);
7215  }
7216 
7217  cache->pen_flip = RNA_boolean_get(ptr, "pen_flip");
7218  RNA_float_get_array(ptr, "mouse", cache->mouse);
7219  RNA_float_get_array(ptr, "mouse_event", cache->mouse_event);
7220 
7221  /* XXX: Use pressure value from first brush step for brushes which don't support strokes (grab,
7222  * thumb). They depends on initial state and brush coord/pressure/etc.
7223  * It's more an events design issue, which doesn't split coordinate/pressure/angle changing
7224  * events. We should avoid this after events system re-design. */
7226  cache->pressure = RNA_float_get(ptr, "pressure");
7227  }
7228 
7229  cache->x_tilt = RNA_float_get(ptr, "x_tilt");
7230  cache->y_tilt = RNA_float_get(ptr, "y_tilt");
7231 
7232  /* Truly temporary data that isn't stored in properties. */
7234  if (!BKE_brush_use_locked_size(scene, brush)) {
7236  cache->vc, cache->true_location, BKE_brush_size_get(scene, brush));
7238  }
7239  else {
7241  }
7242  }
7243 
7244  /* Clay stabilized pressure. */
7245  if (brush->sculpt_tool == SCULPT_TOOL_CLAY_THUMB) {
7247  for (int i = 0; i < SCULPT_CLAY_STABILIZER_LEN; i++) {
7248  ss->cache->clay_pressure_stabilizer[i] = 0.0f;
7249  }
7251  }
7252  else {
7254  cache->clay_pressure_stabilizer_index += 1;
7256  cache->clay_pressure_stabilizer_index = 0;
7257  }
7258  }
7259  }
7260 
7261  if (BKE_brush_use_size_pressure(brush) &&
7263  cache->radius = sculpt_brush_dynamic_size_get(brush, cache, cache->initial_radius);
7265  brush, cache, ups->initial_pixel_radius);
7266  }
7267  else {
7268  cache->radius = cache->initial_radius;
7270  }
7271 
7272  sculpt_update_cache_paint_variants(cache, brush);
7273 
7274  cache->radius_squared = cache->radius * cache->radius;
7275 
7276  if (brush->flag & BRUSH_ANCHORED) {
7277  /* True location has been calculated as part of the stroke system already here. */
7278  if (brush->flag & BRUSH_EDGE_TO_EDGE) {
7279  RNA_float_get_array(ptr, "location", cache->true_location);
7280  }
7281 
7283  cache->vc, cache->true_location, ups->pixel_radius);
7284  cache->radius_squared = cache->radius * cache->radius;
7285 
7286  copy_v3_v3(cache->anchored_location, cache->true_location);
7287  }
7288 
7289  sculpt_update_brush_delta(ups, ob, brush);
7290 
7291  if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) {
7292  cache->vertex_rotation = -BLI_dial_angle(cache->dial, cache->mouse) * cache->bstrength;
7293 
7294  ups->draw_anchored = true;
7296  copy_v3_v3(cache->anchored_location, cache->true_location);
7297  ups->anchored_size = ups->pixel_radius;
7298  }
7299 
7300  cache->special_rotation = ups->brush_rotation;
7301 
7302  cache->iteration_count++;
7303 }
7304 
7305 /* Returns true if any of the smoothing modes are active (currently
7306  * one of smooth brush, autosmooth, mask smooth, or shift-key
7307  * smooth). */
7309  const Brush *brush,
7310  SculptSession *ss,
7311  int stroke_mode)
7312 {
7313  if (ss && ss->pbvh && SCULPT_is_automasking_enabled(sd, ss, brush)) {
7314  return true;
7315  }
7316  return ((stroke_mode == BRUSH_STROKE_SMOOTH) || (ss && ss->cache && ss->cache->alt_smooth) ||
7317  (brush->sculpt_tool == SCULPT_TOOL_SMOOTH) || (brush->autosmooth_factor > 0) ||
7318  ((brush->sculpt_tool == SCULPT_TOOL_MASK) && (brush->mask_tool == BRUSH_MASK_SMOOTH)) ||
7319  (brush->sculpt_tool == SCULPT_TOOL_POSE) ||
7320  (brush->sculpt_tool == SCULPT_TOOL_BOUNDARY) ||
7321  (brush->sculpt_tool == SCULPT_TOOL_SLIDE_RELAX) ||
7322  (brush->sculpt_tool == SCULPT_TOOL_CLOTH) || (brush->sculpt_tool == SCULPT_TOOL_SMEAR) ||
7325 }
7326 
7327 void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush)
7328 {
7329  SculptSession *ss = ob->sculpt;
7330  View3D *v3d = CTX_wm_view3d(C);
7332 
7333  bool need_pmap = sculpt_needs_connectivity_info(sd, brush, ss, 0);
7334  if (ss->shapekey_active || ss->deform_modifiers_active ||
7335  (!BKE_sculptsession_use_pbvh_draw(ob, v3d) && need_pmap)) {
7337  BKE_sculpt_update_object_for_edit(depsgraph, ob, need_pmap, false, false);
7338  }
7339 }
7340 
7341 static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
7342 {
7343  if (BKE_pbvh_node_get_tmin(node) >= *tmin) {
7344  return;
7345  }
7346  SculptRaycastData *srd = data_v;
7347  float(*origco)[3] = NULL;
7348  bool use_origco = false;
7349 
7350  if (srd->original && srd->ss->cache) {
7351  if (BKE_pbvh_type(srd->ss->pbvh) == PBVH_BMESH) {
7352  use_origco = true;
7353  }
7354  else {
7355  /* Intersect with coordinates from before we started stroke. */
7357  origco = (unode) ? unode->co : NULL;
7358  use_origco = origco ? true : false;
7359  }
7360  }
7361 
7362  if (BKE_pbvh_node_raycast(srd->ss->pbvh,
7363  node,
7364  origco,
7365  use_origco,
7366  srd->ray_start,
7367  srd->ray_normal,
7368  &srd->isect_precalc,
7369  &srd->depth,
7370  &srd->active_vertex_index,
7371  &srd->active_face_grid_index,
7372  srd->face_normal)) {
7373  srd->hit = true;
7374  *tmin = srd->depth;
7375  }
7376 }
7377 
7378 static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *tmin)
7379 {
7380  if (BKE_pbvh_node_get_tmin(node) >= *tmin) {
7381  return;
7382  }
7383  SculptFindNearestToRayData *srd = data_v;
7384  float(*origco)[3] = NULL;
7385  bool use_origco = false;
7386 
7387  if (srd->original && srd->ss->cache) {
7388  if (BKE_pbvh_type(srd->ss->pbvh) == PBVH_BMESH) {
7389  use_origco = true;
7390  }
7391  else {
7392  /* Intersect with coordinates from before we started stroke. */
7394  origco = (unode) ? unode->co : NULL;
7395  use_origco = origco ? true : false;
7396  }
7397  }
7398 
7400  node,
7401  origco,
7402  use_origco,
7403  srd->ray_start,
7404  srd->ray_normal,
7405  &srd->depth,
7406  &srd->dist_sq_to_ray)) {
7407  srd->hit = true;
7408  *tmin = srd->dist_sq_to_ray;
7409  }
7410 }
7411 
7413  const float mouse[2],
7414  float ray_start[3],
7415  float ray_end[3],
7416  float ray_normal[3],
7417  bool original)
7418 {
7419  float obimat[4][4];
7420  float dist;
7421  Object *ob = vc->obact;
7422  RegionView3D *rv3d = vc->region->regiondata;
7423  View3D *v3d = vc->v3d;
7424 
7425  /* TODO: what if the segment is totally clipped? (return == 0). */
7427  vc->depsgraph, vc->region, vc->v3d, mouse, ray_start, ray_end, true);
7428 
7429  invert_m4_m4(obimat, ob->obmat);
7430  mul_m4_v3(obimat, ray_start);
7431  mul_m4_v3(obimat, ray_end);
7432 
7433  sub_v3_v3v3(ray_normal, ray_end, ray_start);
7434  dist = normalize_v3(ray_normal);
7435 
7436  if ((rv3d->is_persp == false) &&
7437  /* If the ray is clipped, don't adjust its start/end. */
7438  !RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
7439  BKE_pbvh_raycast_project_ray_root(ob->sculpt->pbvh, original, ray_start, ray_end, ray_normal);
7440 
7441  /* rRecalculate the normal. */
7442  sub_v3_v3v3(ray_normal, ray_end, ray_start);
7443  dist = normalize_v3(ray_normal);
7444  }
7445 
7446  return dist;
7447 }
7448 
7449 /* Gets the normal, location and active vertex location of the geometry under the cursor. This also
7450  * updates the active vertex and cursor related data of the SculptSession using the mouse position
7451  */
7454  const float mouse[2],
7455  bool use_sampled_normal)
7456 {
7459  Sculpt *sd = scene->toolsettings->sculpt;
7460  Object *ob;
7461  SculptSession *ss;
7462  ViewContext vc;
7464  float ray_start[3], ray_end[3], ray_normal[3], depth, face_normal[3], sampled_normal[3],
7465  mat[3][3];
7466  float viewDir[3] = {0.0f, 0.0f, 1.0f};
7467  int totnode;
7468  bool original = false;
7469 
7471 
7472  ob = vc.obact;
7473  ss = ob->sculpt;
7474 
7475  if (!ss->pbvh) {
7476  zero_v3(out->location);
7477  zero_v3(out->normal);
7478  zero_v3(out->active_vertex_co);
7479  return false;
7480  }
7481 
7482  /* PBVH raycast to get active vertex and face normal. */
7483  depth = SCULPT_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, original);
7484  SCULPT_stroke_modifiers_check(C, ob, brush);
7485 
7486  SculptRaycastData srd = {
7487  .original = original,
7488  .ss = ob->sculpt,
7489  .hit = false,
7490  .ray_start = ray_start,
7491  .ray_normal = ray_normal,
7492  .depth = depth,
7493  .face_normal = face_normal,
7494  };
7496  BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, ray_start, ray_normal, srd.original);
7497 
7498  /* Cursor is not over the mesh, return default values. */
7499  if (!srd.hit) {
7500  zero_v3(out->location);
7501  zero_v3(out->normal);
7502  zero_v3(out->active_vertex_co);
7503  return false;
7504  }
7505 
7506  /* Update the active vertex of the SculptSession. */
7510 
7511  switch (BKE_pbvh_type(ss->pbvh)) {
7512  case PBVH_FACES:
7514  ss->active_grid_index = 0;
7515  break;
7516  case PBVH_GRIDS:
7517  ss->active_face_index = 0;
7519  break;
7520  case PBVH_BMESH:
7521  ss->active_face_index = 0;
7522  ss->active_grid_index = 0;
7523  break;
7524  }
7525 
7526  copy_v3_v3(out->location, ray_normal);
7527  mul_v3_fl(out->location, srd.depth);
7528  add_v3_v3(out->location, ray_start);
7529 
7530  /* Option to return the face normal directly for performance o accuracy reasons. */
7531  if (!use_sampled_normal) {
7532  copy_v3_v3(out->normal, srd.face_normal);
7533  return srd.hit;
7534  }
7535 
7536  /* Sampled normal calculation. */
7537  float radius;
7538 
7539  /* Update cursor data in SculptSession. */
7540  invert_m4_m4(ob->imat, ob->obmat);
7541  copy_m3_m4(mat, vc.rv3d->viewinv);
7542  mul_m3_v3(mat, viewDir);
7543  copy_m3_m4(mat, ob->imat);
7544  mul_m3_v3(mat, viewDir);
7545  normalize_v3_v3(ss->cursor_view_normal, viewDir);
7547  copy_v3_v3(ss->cursor_location, out->location);
7548  ss->rv3d = vc.rv3d;
7549  ss->v3d = vc.v3d;
7550 
7551  if (!BKE_brush_use_locked_size(scene, brush)) {
7552  radius = paint_calc_object_space_radius(&vc, out->location, BKE_brush_size_get(scene, brush));
7553  }
7554  else {
7555  radius = BKE_brush_unprojected_radius_get(scene, brush);
7556  }
7557  ss->cursor_radius = radius;
7558 
7559  PBVHNode **nodes = sculpt_pbvh_gather_cursor_update(ob, sd, original, &totnode);
7560 
7561  /* In case there are no nodes under the cursor, return the face normal. */
7562  if (!totnode) {
7563  MEM_SAFE_FREE(nodes);
7564  copy_v3_v3(out->normal, srd.face_normal);
7565  return true;
7566  }
7567 
7568  /* Calculate the sampled normal. */
7569  if (SCULPT_pbvh_calc_area_normal(brush, ob, nodes, totnode, true, sampled_normal)) {
7570  copy_v3_v3(out->normal, sampled_normal);
7571  copy_v3_v3(ss->cursor_sampled_normal, sampled_normal);
7572  }
7573  else {
7574  /* Use face normal when there are no vertices to sample inside the cursor radius. */
7575  copy_v3_v3(out->normal, srd.face_normal);
7576  }
7577  MEM_SAFE_FREE(nodes);
7578  return true;
7579 }
7580 
7581 /* Do a raycast in the tree to find the 3d brush location
7582  * (This allows us to ignore the GL depth buffer)
7583  * Returns 0 if the ray doesn't hit the mesh, non-zero otherwise. */
7584 bool SCULPT_stroke_get_location(bContext *C, float out[3], const float mouse[2])
7585 {
7587  Object *ob;
7588  SculptSession *ss;
7589  StrokeCache *cache;
7590  float ray_start[3], ray_end[3], ray_normal[3], depth, face_normal[3];
7591  bool original;
7592  ViewContext vc;
7593 
7595 
7596  ob = vc.obact;
7597 
7598  ss = ob->sculpt;
7599  cache = ss->cache;
7600  original = (cache) ? cache->original : false;
7601 
7603 
7604  SCULPT_stroke_modifiers_check(C, ob, brush);
7605 
7606  depth = SCULPT_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, original);
7607 
7608  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
7611  }
7612 
7613  bool hit = false;
7614  {
7615  SculptRaycastData srd;
7616  srd.ss = ob->sculpt;
7617  srd.ray_start = ray_start;
7618  srd.ray_normal = ray_normal;
7619  srd.hit = false;
7620  srd.depth = depth;
7621  srd.original = original;
7622  srd.face_normal = face_normal;
7624 
7625  BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, ray_start, ray_normal, srd.original);
7626  if (srd.hit) {
7627  hit = true;
7628  copy_v3_v3(out, ray_normal);
7629  mul_v3_fl(out, srd.depth);
7630  add_v3_v3(out, ray_start);
7631  }
7632  }
7633 
7634  if (hit) {
7635  return hit;
7636  }
7637 
7639  return hit;
7640  }
7641 
7643  .original = original,
7644  .ss = ob->sculpt,
7645  .hit = false,
7646  .ray_start = ray_start,
7647  .ray_normal = ray_normal,
7648  .depth = FLT_MAX,
7649  .dist_sq_to_ray = FLT_MAX,
7650  };
7652  ss->pbvh, sculpt_find_nearest_to_ray_cb, &srd, ray_start, ray_normal, srd.original);
7653  if (srd.hit) {
7654  hit = true;
7655  copy_v3_v3(out, ray_normal);
7656  mul_v3_fl(out, srd.depth);
7657  add_v3_v3(out, ray_start);
7658  }
7659 
7660  return hit;
7661 }
7662 
7664 {
7665  Brush *brush = BKE_paint_brush(&sd->paint);
7666  MTex *mtex = &brush->mtex;
7667 
7668  /* Init mtex nodes. */
7669  if (mtex->tex && mtex->tex->nodetree) {
7670  /* Has internal flag to detect it only does it once. */
7672  }
7673 
7674  /* TODO: Shouldn't really have to do this at the start of every stroke, but sculpt would need
7675  * some sort of notification when changes are made to the texture. */
7676  sculpt_update_tex(scene, sd, ss);
7677 }
7678 
7680 {
7685  Brush *brush = BKE_paint_brush(&sd->paint);
7686  int mode = RNA_enum_get(op->ptr, "mode");
7687  bool is_smooth, needs_colors;
7688  bool need_mask = false;
7689 
7690  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
7691  need_mask = true;
7692  }
7693 
7694  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH ||
7696  need_mask = true;
7697  }
7698 
7700  sculpt_brush_init_tex(scene, sd, ss);
7701 
7702  is_smooth = sculpt_needs_connectivity_info(sd, brush, ss, mode);
7703  needs_colors = ELEM(brush->sculpt_tool, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR);
7704 
7705  if (needs_colors) {
7707  }
7708 
7709  /* CTX_data_ensure_evaluated_depsgraph should be used at the end to include the updates of
7710  * earlier steps modifying the data. */
7712  BKE_sculpt_update_object_for_edit(depsgraph, ob, is_smooth, need_mask, needs_colors);
7713 }
7714 
7715 static void sculpt_restore_mesh(Sculpt *sd, Object *ob)
7716 {
7717  SculptSession *ss = ob->sculpt;
7718  Brush *brush = BKE_paint_brush(&sd->paint);
7719 
7720  /* For the cloth brush it makes more sense to not restore the mesh state to keep running the
7721  * simulation from the previous state. */
7722  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
7723  return;
7724  }
7725 
7726  /* Restore the mesh before continuing with anchored stroke. */
7727  if ((brush->flag & BRUSH_ANCHORED) ||
7728  ((brush->sculpt_tool == SCULPT_TOOL_GRAB ||
7730  BKE_brush_use_size_pressure(brush)) ||
7731  (brush->flag & BRUSH_DRAG_DOT)) {
7732 
7734  if (unode && unode->type == SCULPT_UNDO_FACE_SETS) {
7735  for (int i = 0; i < ss->totfaces; i++) {
7736  ss->face_sets[i] = unode->face_sets[i];
7737  }
7738  }
7739 
7740  paint_mesh_restore_co(sd, ob);
7741 
7742  if (ss->cache) {
7744  }
7745  }
7746 }
7747 
7748 /* Copy the PBVH bounding box into the object's bounding box. */
7750 {
7751  if (ob->runtime.bb) {
7752  float bb_min[3], bb_max[3];
7753 
7754  BKE_pbvh_bounding_box(ob->sculpt->pbvh, bb_min, bb_max);
7755  BKE_boundbox_init_from_minmax(ob->runtime.bb, bb_min, bb_max);
7756  }
7757 }
7758 
7760 {
7763  SculptSession *ss = ob->sculpt;
7764  ARegion *region = CTX_wm_region(C);
7766  View3D *v3d = CTX_wm_view3d(C);
7768 
7769  if (rv3d) {
7770  /* Mark for faster 3D viewport redraws. */
7771  rv3d->rflag |= RV3D_PAINTING;
7772  }
7773 
7774  if (mmd != NULL) {
7776  }
7777 
7779 
7780  /* Only current viewport matters, slower update for all viewports will
7781  * be done in sculpt_flush_update_done. */
7782  if (!BKE_sculptsession_use_pbvh_draw(ob, v3d)) {
7783  /* Slow update with full dependency graph update and all that comes with it.
7784  * Needed when there are modifiers or full shading in the 3D viewport. */
7786  ED_region_tag_redraw(region);
7787  }
7788  else {
7789  /* Fast path where we just update the BVH nodes that changed, and redraw
7790  * only the part of the 3D viewport where changes happened. */
7791  rcti r;
7792 
7793  if (update_flags & SCULPT_UPDATE_COORDS) {
7795  /* Update the object's bounding box too so that the object
7796  * doesn't get incorrectly clipped during drawing in
7797  * draw_mesh_object(). T33790. */
7799  }
7800 
7801  if (SCULPT_get_redraw_rect(region, CTX_wm_region_view3d(C), ob, &r)) {
7802  if (ss->cache) {
7803  ss->cache->current_r = r;
7804  }
7805 
7806  /* previous is not set in the current cache else
7807  * the partial rect will always grow */
7809 
7810  r.xmin += region->winrct.xmin - 2;
7811  r.xmax += region->winrct.xmin + 2;
7812  r.ymin += region->winrct.ymin - 2;
7813  r.ymax += region->winrct.ymin + 2;
7814  ED_region_tag_redraw_partial(region, &r, true);
7815  }
7816  }
7817 }
7818 
7820 {
7821  /* After we are done drawing the stroke, check if we need to do a more
7822  * expensive depsgraph tag to update geometry. */
7824  View3D *current_v3d = CTX_wm_view3d(C);
7826  SculptSession *ss = ob->sculpt;
7827  Mesh *mesh = ob->data;
7828 
7829  /* Always needed for linked duplicates. */
7830  bool need_tag = (ID_REAL_USERS(&mesh->id) > 1);
7831 
7832  if (rv3d) {
7833  rv3d->rflag &= ~RV3D_PAINTING;
7834  }
7835 
7836  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
7837  bScreen *screen = WM_window_get_active_screen(win);
7838  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
7839  SpaceLink *sl = area->spacedata.first;
7840  if (sl->spacetype != SPACE_VIEW3D) {
7841  continue;
7842  }
7843  View3D *v3d = (View3D *)sl;
7844  if (v3d != current_v3d) {
7845  need_tag |= !BKE_sculptsession_use_pbvh_draw(ob, v3d);
7846  }
7847 
7848  /* Tag all 3D viewports for redraw now that we are done. Others
7849  * viewports did not get a full redraw, and anti-aliasing for the
7850  * current viewport was deactivated. */
7851  LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
7852  if (region->regiontype == RGN_TYPE_WINDOW) {
7853  ED_region_tag_redraw(region);
7854  }
7855  }
7856  }
7857  }
7858 
7859  if (update_flags & SCULPT_UPDATE_COORDS) {
7861 
7862  /* Coordinates were modified, so fake neighbors are not longer valid. */
7864  }
7865 
7866  if (update_flags & SCULPT_UPDATE_MASK) {
7868  }
7869 
7870  if (update_flags & SCULPT_UPDATE_COLOR) {
7872  }
7873 
7874  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
7876  }
7877 
7878  /* Optimization: if there is locked key and active modifiers present in */
7879  /* the stack, keyblock is updating at each step. otherwise we could update */
7880  /* keyblock only when stroke is finished. */
7881  if (ss->shapekey_active && !ss->deform_modifiers_active) {
7883  }
7884 
7885  if (need_tag) {
7887  }
7888 }
7889 
7890 /* Returns whether the mouse/stylus is over the mesh (1)
7891  * or over the background (0). */
7892 static bool over_mesh(bContext *C, struct wmOperator *UNUSED(op), float x, float y)
7893 {
7894  float mouse[2], co[3];
7895 
7896  mouse[0] = x;
7897  mouse[1] = y;
7898 
7899  return SCULPT_stroke_get_location(C, co, mouse);
7900 }
7901 
7902 static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const float mouse[2])
7903 {
7904  /* Don't start the stroke until mouse goes over the mesh.
7905  * note: mouse will only be null when re-executing the saved stroke.
7906  * We have exception for 'exec' strokes since they may not set 'mouse',
7907  * only 'location', see: T52195. */
7908  if (((op->flag & OP_IS_INVOKE) == 0) || (mouse == NULL) ||
7909  over_mesh(C, op, mouse[0], mouse[1])) {
7911  SculptSession *ss = ob->sculpt;
7913 
7915 
7916  sculpt_update_cache_invariants(C, sd, ss, op, mouse);
7917 
7919 
7920  return true;
7921  }
7922  return false;
7923 }
7924 
7926  struct PaintStroke *UNUSED(stroke),
7927  PointerRNA *itemptr)
7928 {
7932  SculptSession *ss = ob->sculpt;
7933  const Brush *brush = BKE_paint_brush(&sd->paint);
7934 
7935  SCULPT_stroke_modifiers_check(C, ob, brush);
7936  sculpt_update_cache_variants(C, sd, ob, itemptr);
7937  sculpt_restore_mesh(sd, ob);
7938 
7940  float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat));
7941  BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail);
7942  }
7943  else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) {
7945  }
7946  else {
7948  (ss->cache->radius / ss->cache->dyntopo_pixel_radius) *
7949  (sd->detail_size * U.pixelsize) / 0.4f);
7950  }
7951 
7952  if (SCULPT_stroke_is_dynamic_topology(ss, brush)) {
7954  }
7955 
7957  sculpt_combine_proxies(sd, ob);
7958 
7959  /* Hack to fix noise texture tearing mesh. */
7960  sculpt_fix_noise_tear(sd, ob);
7961 
7962  /* TODO(sergey): This is not really needed for the solid shading,
7963  * which does use pBVH drawing anyway, but texture and wireframe
7964  * requires this.
7965  *
7966  * Could be optimized later, but currently don't think it's so
7967  * much common scenario.
7968  *
7969  * Same applies to the DEG_id_tag_update() invoked from
7970  * sculpt_flush_update_step().
7971  */
7972  if (ss->deform_modifiers_active) {
7974  }
7975  else if (ss->shapekey_active) {
7977  }
7978 
7979  ss->cache->first_time = false;
7981 
7982  /* Cleanup. */
7983  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
7985  }
7986  else if (ELEM(brush->sculpt_tool, SCULPT_TOOL_PAINT, SCULPT_TOOL_SMEAR)) {
7988  }
7989  else {
7991  }
7992 }
7993 
7995 {
7996  Brush *brush = BKE_paint_brush(&sd->paint);
7997  MTex *mtex = &brush->mtex;
7998 
7999  if (mtex->tex && mtex->tex->nodetree) {
8001  }
8002 }
8003 
8004 static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke))
8005 {
8006  Main *bmain = CTX_data_main(C);
8009  SculptSession *ss = ob->sculpt;
8011 
8012  /* Finished. */
8013  if (!ss->cache) {
8015  return;
8016  }
8018  Brush *brush = BKE_paint_brush(&sd->paint);
8019  BLI_assert(brush == ss->cache->brush); /* const, so we shouldn't change. */
8020  ups->draw_inverted = false;
8021 
8022  SCULPT_stroke_modifiers_check(C, ob, brush);
8023 
8024  /* Alt-Smooth. */
8025  if (ss->cache->alt_smooth) {
8026  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
8027  brush->mask_tool = ss->cache->saved_mask_brush_tool;
8028  }
8029  else if (ELEM(brush->sculpt_tool,
8033  SCULPT_TOOL_SMEAR)) {
8034  /* Do nothing. */
8035  }
8036  else {
8039  if (brush) {
8040  BKE_paint_brush_set(&sd->paint, brush);
8041  }
8042  }
8043  }
8044 
8045  if (SCULPT_is_automasking_enabled(sd, ss, brush)) {
8047  }
8048 
8050  SCULPT_cache_free(ss->cache);
8051  ss->cache = NULL;
8052 
8054 
8055  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
8057  }
8058  else {
8060  }
8061 
8064 }
8065 
8066 static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
8067 {
8068  struct PaintStroke *stroke;
8069  int ignore_background_click;
8070  int retval;
8071 
8073 
8074  stroke = paint_stroke_new(C,
8075  op,
8079  NULL,
8081  event->type);
8082 
8083  op->customdata = stroke;
8084 
8085  /* For tablet rotation. */
8086  ignore_background_click = RNA_boolean_get(op->ptr, "ignore_background_click");
8087 
8088  if (ignore_background_click && !over_mesh(C, op, event->x, event->y)) {
8089  paint_stroke_free(C, op);
8090  return OPERATOR_PASS_THROUGH;
8091  }
8092 
8093  if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
8094  paint_stroke_free(C, op);
8095  return OPERATOR_FINISHED;
8096  }
8097  /* Add modal handler. */
8099 
8100  OPERATOR_RETVAL_CHECK(retval);
8102 
8103  return OPERATOR_RUNNING_MODAL;
8104 }
8105 
8107 {
8109 
8111  op,
8115  NULL,
8117  0);
8118 
8119  /* Frees op->customdata. */
8120  paint_stroke_exec(C, op);
8121 
8122  return OPERATOR_FINISHED;
8123 }
8124 
8126 {
8128  SculptSession *ss = ob->sculpt;
8130  const Brush *brush = BKE_paint_brush(&sd->paint);
8131 
8132  /* XXX Canceling strokes that way does not work with dynamic topology,
8133  * user will have to do real undo for now. See T46456. */
8134  if (ss->cache && !SCULPT_stroke_is_dynamic_topology(ss, brush)) {
8135  paint_mesh_restore_co(sd, ob);
8136  }
8137 
8138  paint_stroke_cancel(C, op);
8139 
8140  if (ss->cache) {
8141  SCULPT_cache_free(ss->cache);
8142  ss->cache = NULL;
8143  }
8144 
8146 }
8147 
8149 {
8150  /* Identifiers. */
8151  ot->name = "Sculpt";
8152  ot->idname = "SCULPT_OT_brush_stroke";
8153  ot->description = "Sculpt a stroke into the geometry";
8154 
8155  /* API callbacks. */
8159  ot->poll = SCULPT_poll;
8161 
8162  /* Flags (sculpt does own undo? (ton)). */
8163  ot->flag = OPTYPE_BLOCKING;
8164 
8165  /* Properties. */
8166 
8168 
8170  "ignore_background_click",
8171  0,
8172  "Ignore Background Click",
8173  "Clicks on the background do not start the stroke");
8174 }
8175 
8176 /* Reset the copy of the mesh that is being sculpted on (currently just for the layer brush). */
8177 
8179 {
8182  SculptSession *ss = ob->sculpt;
8183 
8184  if (!ss) {
8185  return OPERATOR_FINISHED;
8186  }
8188  BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false);
8189 
8191 
8192  const int totvert = SCULPT_vertex_count_get(ss);
8193  ss->persistent_base = MEM_mallocN(sizeof(SculptPersistentBase) * totvert,
8194  "layer persistent base");
8195 
8196  for (int i = 0; i < totvert; i++) {
8199  ss->persistent_base[i].disp = 0.0f;
8200  }
8201 
8202  return OPERATOR_FINISHED;
8203 }
8204 
8206 {
8207  /* Identifiers. */
8208  ot->name = "Set Persistent Base";
8209  ot->idname = "SCULPT_OT_set_persistent_base";
8210  ot->description = "Reset the copy of the mesh that is being sculpted on";
8211 
8212  /* API callbacks. */
8215 
8217 }
8218 
8219 /************************* SCULPT_OT_optimize *************************/
8220 
8222 {
8224 
8225  SCULPT_pbvh_clear(ob);
8227 
8228  return OPERATOR_FINISHED;
8229 }
8230 
8231 /* The BVH gets less optimal more quickly with dynamic topology than
8232  * regular sculpting. There is no doubt more clever stuff we can do to
8233  * optimize it on the fly, but for now this gives the user a nicer way
8234  * to recalculate it than toggling modes. */
8236 {
8237  /* Identifiers. */
8238  ot->name = "Rebuild BVH";
8239  ot->idname = "SCULPT_OT_optimize";
8240  ot->description = "Recalculate the sculpt BVH to improve performance";
8241 
8242  /* API callbacks. */
8245 
8247 }
8248 
8249 /********************* Dynamic topology symmetrize ********************/
8250 
8252 {
8254  if (SCULPT_mode_poll(C) && ob->sculpt && ob->sculpt->pbvh) {
8255  return BKE_pbvh_type(ob->sculpt->pbvh) != PBVH_GRIDS;
8256  }
8257  return false;
8258 }
8259 
8261 {
8262  Main *bmain = CTX_data_main(C);
8264  const Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
8265  SculptSession *ss = ob->sculpt;
8266  PBVH *pbvh = ss->pbvh;
8267  const float dist = RNA_float_get(op->ptr, "merge_tolerance");
8268 
8269  if (!pbvh) {
8270  return OPERATOR_CANCELLED;
8271  }
8272 
8273  switch (BKE_pbvh_type(pbvh)) {
8274  case PBVH_BMESH:
8275  /* Dyntopo Symmetrize. */
8276 
8277  /* To simplify undo for symmetrize, all BMesh elements are logged
8278  * as deleted, then after symmetrize operation all BMesh elements
8279  * are logged as added (as opposed to attempting to store just the
8280  * parts that symmetrize modifies). */
8281  SCULPT_undo_push_begin(ob, "Dynamic topology symmetrize");
8284 
8285  BM_mesh_toolflags_set(ss->bm, true);
8286 
8287  /* Symmetrize and re-triangulate. */
8288  BMO_op_callf(ss->bm,
8290  "symmetrize input=%avef direction=%i dist=%f use_shapekey=%b",
8292  dist,
8293  true);
8295 
8296  /* Bisect operator flags edges (keep tags clean for edge queue). */
8298 
8299  BM_mesh_toolflags_set(ss->bm, false);
8300 
8301  /* Finish undo. */
8302  BM_log_all_added(ss->bm, ss->bm_log);
8304 
8305  break;
8306  case PBVH_FACES:
8307  /* Mesh Symmetrize. */
8308  ED_sculpt_undo_geometry_begin(ob, "mesh symmetrize");
8309  Mesh *mesh = ob->data;
8310 
8312 
8316 
8317  break;
8318  case PBVH_GRIDS:
8319  return OPERATOR_CANCELLED;
8320  }
8321 
8322  /* Redraw. */
8323  SCULPT_pbvh_clear(ob);
8325 
8326  return OPERATOR_FINISHED;
8327 }
8328 
8330 {
8331  /* Identifiers. */
8332  ot->name = "Symmetrize";
8333  ot->idname = "SCULPT_OT_symmetrize";
8334  ot->description = "Symmetrize the topology modifications";
8335 
8336  /* API callbacks. */
8339 
8341  "merge_tolerance",
8342  0.001f,
8343  0.0f,
8344  FLT_MAX,
8345  "Merge Distance",
8346  "Distance within which symmetrical vertices are merged",
8347  0.0f,
8348  1.0f);
8349 }
8350 
8351 /**** Toggle operator for turning sculpt mode on or off ****/
8352 
8354 {
8355  /* Create persistent sculpt mode data. */
8357 
8358  /* Create sculpt mode session data. */
8359  if (ob->sculpt != NULL) {
8361  }
8362  ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
8364 
8366 
8368 
8369  /* This function expects a fully evaluated depsgraph. */
8370  BKE_sculpt_update_object_for_edit(depsgraph, ob, false, false, false);
8371 
8372  /* Here we can detect geometry that was just added to Sculpt Mode as it has the
8373  * SCULPT_FACE_SET_NONE assigned, so we can create a new Face Set for it. */
8374  /* In sculpt mode all geometry that is assigned to SCULPT_FACE_SET_NONE is considered as not
8375  * initialized, which is used is some operators that modify the mesh topology to perform certain
8376  * actions in the new polys. After these operations are finished, all polys should have a valid
8377  * face set ID assigned (different from SCULPT_FACE_SET_NONE) to manage their visibility
8378  * correctly. */
8379  /* TODO(pablodp606): Based on this we can improve the UX in future tools for creating new
8380  * objects, like moving the transform pivot position to the new area or masking existing
8381  * geometry. */
8382  SculptSession *ss = ob->sculpt;
8383  const int new_face_set = SCULPT_face_set_next_available_get(ss);
8384  for (int i = 0; i < ss->totfaces; i++) {
8385  if (ss->face_sets[i] == SCULPT_FACE_SET_NONE) {
8386  ss->face_sets[i] = new_face_set;
8387  }
8388  }
8389 }
8390 
8393  Scene *scene,
8394  Object *ob,
8395  const bool force_dyntopo,
8396  ReportList *reports)
8397 {
8398  const int mode_flag = OB_MODE_SCULPT;
8399  Mesh *me = BKE_mesh_from_object(ob);
8400 
8401  /* Enter sculpt mode. */
8402  ob->mode |= mode_flag;
8403 
8404  sculpt_init_session(bmain, depsgraph, scene, ob);
8405 
8406  if (!(fabsf(ob->scale[0] - ob->scale[1]) < 1e-4f &&
8407  fabsf(ob->scale[1] - ob->scale[2]) < 1e-4f)) {
8408  BKE_report(
8409  reports, RPT_WARNING, "Object has non-uniform scale, sculpting may be unpredictable");
8410  }
8411  else if (is_negative_m4(ob->obmat)) {
8412  BKE_report(reports, RPT_WARNING, "Object has negative scale, sculpting may be unpredictable");
8413  }
8414 
8417 
8419 
8420  /* Check dynamic-topology flag; re-enter dynamic-topology mode when changing modes,
8421  * As long as no data was added that is not supported. */
8422  if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) {
8424 
8425  const char *message_unsupported = NULL;
8426  if (me->totloop != me->totpoly * 3) {
8427  message_unsupported = TIP_("non-triangle face");
8428  }
8429  else if (mmd != NULL) {
8430  message_unsupported = TIP_("multi-res modifier");
8431  }
8432  else {
8434  if (flag == 0) {
8435  /* pass */
8436  }
8437  else if (flag & DYNTOPO_WARN_VDATA) {
8438  message_unsupported = TIP_("vertex data");
8439  }
8440  else if (flag & DYNTOPO_WARN_EDATA) {
8441  message_unsupported = TIP_("edge data");
8442  }
8443  else if (flag & DYNTOPO_WARN_LDATA) {
8444  message_unsupported = TIP_("face data");
8445  }
8446  else if (flag & DYNTOPO_WARN_MODIFIER) {
8447  message_unsupported = TIP_("constructive modifier");
8448  }
8449  else {
8450  BLI_assert(0);
8451  }
8452  }
8453 
8454  if ((message_unsupported == NULL) || force_dyntopo) {
8455  /* Needed because we may be entering this mode before the undo system loads. */
8456  wmWindowManager *wm = bmain->wm.first;
8457  bool has_undo = wm->undo_stack != NULL;
8458  /* Undo push is needed to prevent memory leak. */
8459  if (has_undo) {
8460  SCULPT_undo_push_begin(ob, "Dynamic topology enable");
8461  }
8463  if (has_undo) {
8466  }
8467  }
8468  else {
8469  BKE_reportf(
8470  reports, RPT_WARNING, "Dynamic Topology found: %s, disabled", message_unsupported);
8472  }
8473  }
8474 
8475  /* Flush object mode. */
8477 }
8478 
8480 {
8481  Main *bmain = CTX_data_main(C);
8483  ViewLayer *view_layer = CTX_data_view_layer(C);
8484  Object *ob = OBACT(view_layer);
8485  ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, false, reports);
8486 }
8487 
8489 {
8490  const int mode_flag = OB_MODE_SCULPT;
8491  Mesh *me = BKE_mesh_from_object(ob);
8492 
8494 
8495  /* Not needed for now. */
8496 #if 0
8498  const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd);
8499 #endif
8500 
8501  /* Always for now, so leaving sculpt mode always ensures scene is in
8502  * a consistent state. */
8503  if (true || /* flush_recalc || */ (ob->sculpt && ob->sculpt->bm)) {
8505  }
8506 
8507  if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) {
8508  /* Dynamic topology must be disabled before exiting sculpt
8509  * mode to ensure the undo stack stays in a consistent
8510  * state. */
8512 
8513  /* Store so we know to re-enable when entering sculpt mode. */
8515  }
8516 
8517  /* Leave sculpt mode. */
8518  ob->mode &= ~mode_flag;
8519 
8521 
8523 
8524  /* Never leave derived meshes behind. */
8526 
8527  /* Flush object mode. */
8529 }
8530 
8532 {
8533  Main *bmain = CTX_data_main(C);
8535  ViewLayer *view_layer = CTX_data_view_layer(C);
8536  Object *ob = OBACT(view_layer);
8538 }
8539 
8541 {
8542  struct wmMsgBus *mbus = CTX_wm_message_bus(C);
8543  Main *bmain = CTX_data_main(C);
8547  ViewLayer *view_layer = CTX_data_view_layer(C);
8548  Object *ob = OBACT(view_layer);
8549  const int mode_flag = OB_MODE_SCULPT;
8550  const bool is_mode_set = (ob->mode & mode_flag) != 0;
8551 
8552  if (!is_mode_set) {
8553  if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
8554  return OPERATOR_CANCELLED;
8555  }
8556  }
8557 
8558  if (is_mode_set) {
8560  }
8561  else {
8562  if (depsgraph) {
8564  }
8565  ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, false, op->reports);
8567 
8568  if (ob->mode & mode_flag) {
8569  Mesh *me = ob->data;
8570  /* Dyntopo adds its own undo step. */
8571  if ((me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) == 0) {
8572  /* Without this the memfile undo step is used,
8573  * while it works it causes lag when undoing the first undo step, see T71564. */
8575  if (wm->op_undo_depth <= 1) {
8576  SCULPT_undo_push_begin(ob, op->type->name);
8577  }
8578  }
8579  }
8580  }
8581 
8583 
8584  WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode);
8585 
8587 
8588  return OPERATOR_FINISHED;
8589 }
8590 
8592 {
8593  /* Identifiers. */
8594  ot->name = "Sculpt Mode";
8595  ot->idname = "SCULPT_OT_sculptmode_toggle";
8596  ot->description = "Toggle sculpt mode in 3D view";
8597 
8598  /* API callbacks. */
8601 
8603 }
8604 
8606 {
8609 
8610  ss->preview_vert_index_count = 0;
8611  int totpoints = 0;
8612 
8613  /* This function is called from the cursor drawing code, so the PBVH may not be build yet. */
8614  if (!ss->pbvh) {
8615  return;
8616  }
8617 
8618  if (!ss->deform_modifiers_active) {
8619  return;
8620  }
8621 
8622  if (BKE_pbvh_type(ss->pbvh) == PBVH_GRIDS) {
8623  return;
8624  }
8625 
8626  BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false);
8627 
8628  if (!ss->pmap) {
8629  return;
8630  }
8631 
8632  float brush_co[3];
8633  copy_v3_v3(brush_co, SCULPT_active_vertex_co_get(ss));
8634 
8635  BLI_bitmap *visited_vertices = BLI_BITMAP_NEW(SCULPT_vertex_count_get(ss), "visited_vertices");
8636 
8637  /* Assuming an average of 6 edges per vertex in a triangulated mesh. */
8638  const int max_preview_vertices = SCULPT_vertex_count_get(ss) * 3 * 2;
8639 
8640  if (ss->preview_vert_index_list == NULL) {
8641  ss->preview_vert_index_list = MEM_callocN(max_preview_vertices * sizeof(int), "preview lines");
8642  }
8643 
8644  GSQueue *not_visited_vertices = BLI_gsqueue_new(sizeof(int));
8645  int active_v = SCULPT_active_vertex_get(ss);
8646  BLI_gsqueue_push(not_visited_vertices, &active_v);
8647 
8648  while (!BLI_gsqueue_is_empty(not_visited_vertices)) {
8649  int from_v;
8650  BLI_gsqueue_pop(not_visited_vertices, &from_v);
8652  SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, from_v, ni) {
8653  if (totpoints + (ni.size * 2) < max_preview_vertices) {
8654  int to_v = ni.index;
8655  ss->preview_vert_index_list[totpoints] = from_v;
8656  totpoints++;
8657  ss->preview_vert_index_list[totpoints] = to_v;
8658  totpoints++;
8659  if (BLI_BITMAP_TEST(visited_vertices, to_v)) {
8660  continue;
8661  }
8662  BLI_BITMAP_ENABLE(visited_vertices, to_v);
8663  const float *co = SCULPT_vertex_co_for_grab_active_get(ss, to_v);
8664  if (len_squared_v3v3(brush_co, co) < radius * radius) {
8665  BLI_gsqueue_push(not_visited_vertices, &to_v);
8666  }
8667  }
8668  }
8670  }
8671 
8672  BLI_gsqueue_free(not_visited_vertices);
8673 
8674  MEM_freeN(visited_vertices);
8675 
8676  ss->preview_vert_index_count = totpoints;
8677 }
8678 
8680 {
8682 
8683  ID *data;
8684  data = ob->data;
8685  if (data && ID_IS_LINKED(data)) {
8686  return OPERATOR_CANCELLED;
8687  }
8688 
8689  if (ob->type != OB_MESH) {
8690  return OPERATOR_CANCELLED;
8691  }
8692 
8693  Mesh *mesh = ob->data;
8694 
8695  const int mloopcol_layer_n = CustomData_get_active_layer(&mesh->ldata, CD_MLOOPCOL);
8696  if (mloopcol_layer_n == -1) {
8697  return OPERATOR_CANCELLED;
8698  }
8699  MLoopCol *loopcols = CustomData_get_layer_n(&mesh->ldata, CD_MLOOPCOL, mloopcol_layer_n);
8700 
8701  const int MPropCol_layer_n = CustomData_get_active_layer(&mesh->vdata, CD_PROP_COLOR);
8702  if (MPropCol_layer_n == -1) {
8703  return OPERATOR_CANCELLED;
8704  }
8705  MPropCol *vertcols = CustomData_get_layer_n(&mesh->vdata, CD_PROP_COLOR, MPropCol_layer_n);
8706 
8708  MPoly *polys = CustomData_get_layer(&mesh->pdata, CD_MPOLY);
8709 
8710  for (int i = 0; i < mesh->totpoly; i++) {
8711  MPoly *c_poly = &polys[i];
8712  for (int j = 0; j < c_poly->totloop; j++) {
8713  int loop_index = c_poly->loopstart + j;
8714  MLoop *c_loop = &loops[c_poly->loopstart + j];
8715  loopcols[loop_index].r = (char)(vertcols[c_loop->v].color[0] * 255);
8716  loopcols[loop_index].g = (char)(vertcols[c_loop->v].color[1] * 255);
8717  loopcols[loop_index].b = (char)(vertcols[c_loop->v].color[2] * 255);
8718  loopcols[loop_index].a = (char)(vertcols[c_loop->v].color[3] * 255);
8719  }
8720  }
8721 
8724 
8725  return OPERATOR_FINISHED;
8726 }
8727 
8729 {
8730  /* identifiers */
8731  ot->name = "Sculpt Vertex Color to Vertex Color";
8732  ot->description = "Copy the Sculpt Vertex Color to a regular color layer";
8733  ot->idname = "SCULPT_OT_vertex_to_loop_colors";
8734 
8735  /* api callbacks */
8738 
8740 }
8741 
8743 {
8745 
8746  ID *data;
8747  data = ob->data;
8748  if (data && ID_IS_LINKED(data)) {
8749  return OPERATOR_CANCELLED;
8750  }
8751 
8752  if (ob->type != OB_MESH) {
8753  return OPERATOR_CANCELLED;
8754  }
8755 
8756  Mesh *mesh = ob->data;
8757 
8758  const int mloopcol_layer_n = CustomData_get_active_layer(&mesh->ldata, CD_MLOOPCOL);
8759  if (mloopcol_layer_n == -1) {
8760  return OPERATOR_CANCELLED;
8761  }
8762  MLoopCol *loopcols = CustomData_get_layer_n(&mesh->ldata, CD_MLOOPCOL, mloopcol_layer_n);
8763 
8764  const int MPropCol_layer_n = CustomData_get_active_layer(&mesh->vdata, CD_PROP_COLOR);
8765  if (MPropCol_layer_n == -1) {
8766  return OPERATOR_CANCELLED;
8767  }
8768  MPropCol *vertcols = CustomData_get_layer_n(&mesh->vdata, CD_PROP_COLOR, MPropCol_layer_n);
8769 
8771  MPoly *polys = CustomData_get_layer(&mesh->pdata, CD_MPOLY);
8772 
8773  for (int i = 0; i < mesh->totpoly; i++) {
8774  MPoly *c_poly = &polys[i];
8775  for (int j = 0; j < c_poly->totloop; j++) {
8776  int loop_index = c_poly->loopstart + j;
8777  MLoop *c_loop = &loops[c_poly->loopstart + j];
8778  vertcols[c_loop->v].color[0] = (loopcols[loop_index].r / 255.0f);
8779  vertcols[c_loop->v].color[1] = (loopcols[loop_index].g / 255.0f);
8780  vertcols[c_loop->v].color[2] = (loopcols[loop_index].b / 255.0f);
8781  vertcols[c_loop->v].color[3] = (loopcols[loop_index].a / 255.0f);
8782  }
8783  }
8784 
8787 
8788  return OPERATOR_FINISHED;
8789 }
8790 
8792 {
8793  /* identifiers */
8794  ot->name = "Vertex Color to Sculpt Vertex Color";
8795  ot->description = "Copy the active loop color layer to the vertex color";
8796  ot->idname = "SCULPT_OT_loop_to_vertex_colors";
8797 
8798  /* api callbacks */
8801 
8803 }
8804 
8806  wmOperator *UNUSED(op),
8807  const wmEvent *UNUSED(e))
8808 {
8812  Brush *brush = BKE_paint_brush(&sd->paint);
8813  SculptSession *ss = ob->sculpt;
8814  int active_vertex = SCULPT_active_vertex_get(ss);
8815  const float *active_vertex_color = SCULPT_vertex_color_get(ss, active_vertex);
8816  if (!active_vertex_color) {
8817  return OPERATOR_CANCELLED;
8818  }
8819 
8820  float color_srgb[3];
8821  copy_v3_v3(color_srgb, active_vertex_color);
8823  BKE_brush_color_set(scene, brush, color_srgb);
8824 
8826 
8827  return OPERATOR_FINISHED;
8828 }
8829 
8831 {
8832  /* identifiers */
8833  ot->name = "Sample Color";
8834  ot->idname = "SCULPT_OT_sample_color";
8835  ot->description = "Sample the vertex color of the active vertex";
8836 
8837  /* api callbacks */
8840 
8841  ot->flag = OPTYPE_REGISTER;
8842 }
8843 
8844 /* Fake Neighbors. */
8845 /* This allows the sculpt tools to work on meshes with multiple connected components as they had
8846  * only one connected component. When initialized and enabled, the sculpt API will return extra
8847  * connectivity neighbors that are not in the real mesh. These neighbors are calculated for each
8848  * vertex using the minimum distance to a vertex that is in a different connected component. */
8849 
8850 /* The fake neighbors first need to be ensured to be initialized.
8851  * After that tools which needs fake neighbors functionality need to
8852  * temporarily enable it:
8853  *
8854  * void my_awesome_sculpt_tool() {
8855  * SCULPT_fake_neighbors_ensure(sd, object, brush->disconnected_distance_max);
8856  * SCULPT_fake_neighbors_enable(ob);
8857  *
8858  * ... Logic of the tool ...
8859  * SCULPT_fake_neighbors_disable(ob);
8860  * }
8861  *
8862  * Such approach allows to keep all the connectivity information ready for reuse
8863  * (without having lag prior to every stroke), but also makes it so the affect
8864  * is localized to a specific brushes and tools only. */
8865 
8866 enum {
8869 };
8870 
8872 {
8873  if (ss->vertex_info.connected_component) {
8874  return ss->vertex_info.connected_component[index];
8875  }
8877 }
8878 
8879 static void SCULPT_fake_neighbor_init(SculptSession *ss, const float max_dist)
8880 {
8881  const int totvert = SCULPT_vertex_count_get(ss);
8883  totvert, sizeof(int), "fake neighbor");
8884  for (int i = 0; i < totvert; i++) {
8886  }
8887 
8888  ss->fake_neighbors.current_max_distance = max_dist;
8889 }
8890 
8891 static void SCULPT_fake_neighbor_add(SculptSession *ss, int v_index_a, int v_index_b)
8892 {
8893  if (ss->fake_neighbors.fake_neighbor_index[v_index_a] == FAKE_NEIGHBOR_NONE) {
8894  ss->fake_neighbors.fake_neighbor_index[v_index_a] = v_index_b;
8895  ss->fake_neighbors.fake_neighbor_index[v_index_b] = v_index_a;
8896  }
8897 }
8898 
8900 {
8902 }
8903 
8909 
8910 static void do_fake_neighbor_search_task_cb(void *__restrict userdata,
8911  const int n,
8912  const TaskParallelTLS *__restrict tls)
8913 {
8914  SculptThreadedTaskData *data = userdata;
8915  SculptSession *ss = data->ob->sculpt;
8916  NearestVertexFakeNeighborTLSData *nvtd = tls->userdata_chunk;
8917  PBVHVertexIter vd;
8918 
8919  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
8920  int vd_topology_id = SCULPT_vertex_get_connected_component(ss, vd.index);
8921  if (vd_topology_id != nvtd->current_topology_id &&
8923  float distance_squared = len_squared_v3v3(vd.co, data->nearest_vertex_search_co);
8924  if (distance_squared < nvtd->nearest_vertex_distance_squared &&
8925  distance_squared < data->max_distance_squared) {
8926  nvtd->nearest_vertex_index = vd.index;
8927  nvtd->nearest_vertex_distance_squared = distance_squared;
8928  }
8929  }
8930  }
8932 }
8933 
8934 static void fake_neighbor_search_reduce(const void *__restrict UNUSED(userdata),
8935  void *__restrict chunk_join,
8936  void *__restrict chunk)
8937 {
8938  NearestVertexFakeNeighborTLSData *join = chunk_join;
8939  NearestVertexFakeNeighborTLSData *nvtd = chunk;
8940  if (join->nearest_vertex_index == -1) {
8943  }
8947  }
8948 }
8949 
8950 static int SCULPT_fake_neighbor_search(Sculpt *sd, Object *ob, const int index, float max_distance)
8951 {
8952  SculptSession *ss = ob->sculpt;
8953  PBVHNode **nodes = NULL;
8954  int totnode;
8956  .ss = ss,
8957  .sd = sd,
8958  .radius_squared = max_distance * max_distance,
8959  .original = false,
8960  .center = SCULPT_vertex_co_get(ss, index),
8961  };
8962  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
8963 
8964  if (totnode == 0) {
8965  return -1;
8966  }
8967 
8968  SculptThreadedTaskData task_data = {
8969  .sd = sd,
8970  .ob = ob,
8971  .nodes = nodes,
8972  .max_distance_squared = max_distance * max_distance,
8973  };
8974 
8976 
8978  nvtd.nearest_vertex_index = -1;
8979  nvtd.nearest_vertex_distance_squared = FLT_MAX;
8981 
8982  TaskParallelSettings settings;
8983  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
8985  settings.userdata_chunk = &nvtd;
8987  BLI_task_parallel_range(0, totnode, &task_data, do_fake_neighbor_search_task_cb, &settings);
8988 
8989  MEM_SAFE_FREE(nodes);
8990 
8991  return nvtd.nearest_vertex_index;
8992 }
8993 
8995  int next_id;
8997 
8999  SculptSession *ss, int from_v, int to_v, bool UNUSED(is_duplicate), void *userdata)
9000 {
9001  SculptTopologyIDFloodFillData *data = userdata;
9002  ss->vertex_info.connected_component[from_v] = data->next_id;
9003  ss->vertex_info.connected_component[to_v] = data->next_id;
9004  return true;
9005 }
9006 
9008 {
9009  SculptSession *ss = ob->sculpt;
9010 
9011  /* Topology IDs already initialized. They only need to be recalculated when the PBVH is rebuild.
9012  */
9013  if (ss->vertex_info.connected_component) {
9014  return;
9015  }
9016 
9017  const int totvert = SCULPT_vertex_count_get(ss);
9018  ss->vertex_info.connected_component = MEM_malloc_arrayN(totvert, sizeof(int), "topology ID");
9019 
9020  for (int i = 0; i < totvert; i++) {
9022  }
9023 
9024  int next_id = 0;
9025  for (int i = 0; i < totvert; i++) {
9027  SculptFloodFill flood;
9028  SCULPT_floodfill_init(ss, &flood);
9029  SCULPT_floodfill_add_initial(&flood, i);
9031  data.next_id = next_id;
9033  SCULPT_floodfill_free(&flood);
9034  next_id++;
9035  }
9036  }
9037 }
9038 
9040 {
9041  SculptSession *ss = object->sculpt;
9042  if (ss->vertex_info.boundary) {
9043  return;
9044  }
9045 
9046  Mesh *base_mesh = BKE_mesh_from_object(object);
9047  ss->vertex_info.boundary = BLI_BITMAP_NEW(base_mesh->totvert, "Boundary info");
9048  int *adjacent_faces_edge_count = MEM_calloc_arrayN(
9049  base_mesh->totedge, sizeof(int), "Adjacent face edge count");
9050 
9051  for (int p = 0; p < base_mesh->totpoly; p++) {
9052  MPoly *poly = &base_mesh->mpoly[p];
9053  for (int l = 0; l < poly->totloop; l++) {
9054  MLoop *loop = &base_mesh->mloop[l + poly->loopstart];
9055  adjacent_faces_edge_count[loop->e]++;
9056  }
9057  }
9058 
9059  for (int e = 0; e < base_mesh->totedge; e++) {
9060  if (adjacent_faces_edge_count[e] < 2) {
9061  MEdge *edge = &base_mesh->medge[e];
9062  BLI_BITMAP_SET(ss->vertex_info.boundary, edge->v1, true);
9063  BLI_BITMAP_SET(ss->vertex_info.boundary, edge->v2, true);
9064  }
9065  }
9066 
9067  MEM_freeN(adjacent_faces_edge_count);
9068 }
9069 
9070 void SCULPT_fake_neighbors_ensure(Sculpt *sd, Object *ob, const float max_dist)
9071 {
9072  SculptSession *ss = ob->sculpt;
9073  const int totvert = SCULPT_vertex_count_get(ss);
9074 
9075  /* Fake neighbors were already initialized with the same distance, so no need to be recalculated.
9076  */
9078  ss->fake_neighbors.current_max_distance == max_dist) {
9079  return;
9080  }
9081 
9083  SCULPT_fake_neighbor_init(ss, max_dist);
9084 
9085  for (int i = 0; i < totvert; i++) {
9086  const int from_v = i;
9087 
9088  /* This vertex does not have a fake neighbor yet, search one for it. */
9090  const int to_v = SCULPT_fake_neighbor_search(sd, ob, from_v, max_dist);
9091  if (to_v != -1) {
9092  /* Add the fake neighbor if available. */
9093  SCULPT_fake_neighbor_add(ss, from_v, to_v);
9094  }
9095  }
9096  }
9097 }
9098 
9100 {
9101  SculptSession *ss = ob->sculpt;
9104 }
9105 
9107 {
9108  SculptSession *ss = ob->sculpt;
9110  ss->fake_neighbors.use_fake_neighbors = false;
9111 }
9112 
9114 {
9115  SculptSession *ss = ob->sculpt;
9117 }
9118 
9128 #define MASK_BY_COLOR_SLOPE 0.25f
9129 
9130 static float sculpt_mask_by_color_delta_get(const float *color_a,
9131  const float *color_b,
9132  const float threshold,
9133  const bool invert)
9134 {
9135  float len = len_v3v3(color_a, color_b);
9136  /* Normalize len to the (0, 1) range. */
9137  len = len / M_SQRT3;
9138 
9139  if (len < threshold - MASK_BY_COLOR_SLOPE) {
9140  len = 1.0f;
9141  }
9142  else if (len >= threshold) {
9143  len = 0.0f;
9144  }
9145  else {
9146  len = (-len + threshold) / MASK_BY_COLOR_SLOPE;
9147  }
9148 
9149  if (invert) {
9150  return 1.0f - len;
9151  }
9152  return len;
9153 }
9154 
9155 static float sculpt_mask_by_color_final_mask_get(const float current_mask,
9156  const float new_mask,
9157  const bool invert,
9158  const bool preserve_mask)
9159 {
9160  if (preserve_mask) {
9161  if (invert) {
9162  return min_ff(current_mask, new_mask);
9163  }
9164  return max_ff(current_mask, new_mask);
9165  }
9166  return new_mask;
9167 }
9168 
9170  float threshold;
9171  bool invert;
9172  float *new_mask;
9173  float initial_color[3];
9175 
9177  void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
9178 {
9179  SculptThreadedTaskData *data = userdata;
9180  SculptSession *ss = data->ob->sculpt;
9181 
9183  bool update_node = false;
9184 
9185  const bool invert = data->mask_by_color_invert;
9186  const bool preserve_mask = data->mask_by_color_preserve_mask;
9187 
9188  PBVHVertexIter vd;
9189  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
9190  const float current_mask = *vd.mask;
9191  const float new_mask = data->mask_by_color_floodfill[vd.index];
9192  *vd.mask = sculpt_mask_by_color_final_mask_get(current_mask, new_mask, invert, preserve_mask);
9193  if (current_mask == *vd.mask) {
9194  continue;
9195  }
9196  update_node = true;
9197  if (vd.mvert) {
9199  }
9200  }
9202  if (update_node) {
9203  BKE_pbvh_node_mark_redraw(data->nodes[n]);
9204  }
9205 }
9206 
9208  SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata)
9209 {
9211  const float *current_color = SCULPT_vertex_color_get(ss, to_v);
9212  float new_vertex_mask = sculpt_mask_by_color_delta_get(
9213  current_color, data->initial_color, data->threshold, data->invert);
9214  data->new_mask[to_v] = new_vertex_mask;
9215 
9216  if (is_duplicate) {
9217  data->new_mask[to_v] = data->new_mask[from_v];
9218  }
9219 
9220  float len = len_v3v3(current_color, data->initial_color);
9221  len = len / M_SQRT3;
9222  return len <= data->threshold;
9223 }
9224 
9226  const int vertex,
9227  const float threshold,
9228  const bool invert,
9229  const bool preserve_mask)
9230 {
9231  SculptSession *ss = object->sculpt;
9232  const int totvert = SCULPT_vertex_count_get(ss);
9233 
9234  float *new_mask = MEM_calloc_arrayN(totvert, sizeof(float), "new mask");
9235 
9236  if (invert) {
9237  for (int i = 0; i < totvert; i++) {
9238  new_mask[i] = 1.0f;
9239  }
9240  }
9241 
9242  SculptFloodFill flood;
9243  SCULPT_floodfill_init(ss, &flood);
9244  SCULPT_floodfill_add_initial(&flood, vertex);
9245 
9247  ffd.threshold = threshold;
9248  ffd.invert = invert;
9249  ffd.new_mask = new_mask;
9251 
9253  SCULPT_floodfill_free(&flood);
9254 
9255  int totnode;
9256  PBVHNode **nodes;
9257  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
9258 
9260  .ob = object,
9261  .nodes = nodes,
9262  .mask_by_color_floodfill = new_mask,
9263  .mask_by_color_vertex = vertex,
9264  .mask_by_color_threshold = threshold,
9265  .mask_by_color_invert = invert,
9266  .mask_by_color_preserve_mask = preserve_mask,
9267  };
9268 
9269  TaskParallelSettings settings;
9270  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
9272  0, totnode, &data, do_mask_by_color_contiguous_update_nodes_cb, &settings);
9273 
9274  MEM_SAFE_FREE(nodes);
9275 
9276  MEM_freeN(new_mask);
9277 }
9278 
9279 static void do_mask_by_color_task_cb(void *__restrict userdata,
9280  const int n,
9281  const TaskParallelTLS *__restrict UNUSED(tls))
9282 {
9283  SculptThreadedTaskData *data = userdata;
9284  SculptSession *ss = data->ob->sculpt;
9285 
9287  bool update_node = false;
9288 
9289  const float threshold = data->mask_by_color_threshold;
9290  const bool invert = data->mask_by_color_invert;
9291  const bool preserve_mask = data->mask_by_color_preserve_mask;
9292  const float *active_color = SCULPT_vertex_color_get(ss, data->mask_by_color_vertex);
9293 
9294  PBVHVertexIter vd;
9295  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
9296  const float current_mask = *vd.mask;
9297  const float new_mask = sculpt_mask_by_color_delta_get(active_color, vd.col, threshold, invert);
9298  *vd.mask = sculpt_mask_by_color_final_mask_get(current_mask, new_mask, invert, preserve_mask);
9299 
9300  if (current_mask == *vd.mask) {
9301  continue;
9302  }
9303  update_node = true;
9304  if (vd.mvert) {
9306  }
9307  }
9309  if (update_node) {
9310  BKE_pbvh_node_mark_redraw(data->nodes[n]);
9311  }
9312 }
9313 
9315  const int vertex,
9316  const float threshold,
9317  const bool invert,
9318  const bool preserve_mask)
9319 {
9320  SculptSession *ss = object->sculpt;
9321 
9322  int totnode;
9323  PBVHNode **nodes;
9324  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
9325 
9327  .ob = object,
9328  .nodes = nodes,
9329  .mask_by_color_vertex = vertex,
9330  .mask_by_color_threshold = threshold,
9331  .mask_by_color_invert = invert,
9332  .mask_by_color_preserve_mask = preserve_mask,
9333  };
9334 
9335  TaskParallelSettings settings;
9336  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
9337  BLI_task_parallel_range(0, totnode, &data, do_mask_by_color_task_cb, &settings);
9338 
9339  MEM_SAFE_FREE(nodes);
9340 }
9341 
9343 {
9346  SculptSession *ss = ob->sculpt;
9347 
9348  BKE_sculpt_update_object_for_edit(depsgraph, ob, true, true, false);
9349 
9350  /* Color data is not available in Multires. */
9351  if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES) {
9352  return OPERATOR_CANCELLED;
9353  }
9354 
9355  if (!ss->vcol) {
9356  return OPERATOR_CANCELLED;
9357  }
9358 
9360 
9361  /* Tools that are not brushes do not have the brush gizmo to update the vertex as the mouse move,
9362  * so it needs to be updated here. */
9364  float mouse[2];
9365  mouse[0] = event->mval[0];
9366  mouse[1] = event->mval[1];
9367  SCULPT_cursor_geometry_info_update(C, &sgi, mouse, false);
9368 
9369  SCULPT_undo_push_begin(ob, "Mask by color");
9370 
9371  const int active_vertex = SCULPT_active_vertex_get(ss);
9372  const float threshold = RNA_float_get(op->ptr, "threshold");
9373  const bool invert = RNA_boolean_get(op->ptr, "invert");
9374  const bool preserve_mask = RNA_boolean_get(op->ptr, "preserve_previous_mask");
9375 
9376  if (RNA_boolean_get(op->ptr, "contiguous")) {
9377  sculpt_mask_by_color_contiguous(ob, active_vertex, threshold, invert, preserve_mask);
9378  }
9379  else {
9380  sculpt_mask_by_color_full_mesh(ob, active_vertex, threshold, invert, preserve_mask);
9381  }
9382 
9385 
9387 
9388  return OPERATOR_FINISHED;
9389 }
9390 
9392 {
9393  /* identifiers */
9394  ot->name = "Mask by Color";
9395  ot->idname = "SCULPT_OT_mask_by_color";
9396  ot->description = "Creates a mask based on the sculpt vertex colors";
9397 
9398  /* api callbacks */
9401 
9402  ot->flag = OPTYPE_REGISTER;
9403 
9404  ot->prop = RNA_def_boolean(
9405  ot->srna, "contiguous", false, "Contiguous", "Mask only contiguous color areas");
9406 
9407  ot->prop = RNA_def_boolean(ot->srna, "invert", false, "Invert", "Invert the generated mask");
9408  ot->prop = RNA_def_boolean(
9409  ot->srna,
9410  "preserve_previous_mask",
9411  false,
9412  "Preserve Previous Mask",
9413  "Preserve the previous mask and add or subtract the new one generated by the colors");
9414 
9416  "threshold",
9417  0.35f,
9418  0.0f,
9419  1.0f,
9420  "Threshold",
9421  "How much changes in color affect the mask generation",
9422  0.0f,
9423  1.0f);
9424 }
9425 
9427 {
9453 
9461 
9463 }
typedef float(TangentPoint)[2]
unsigned int * BKE_brush_gen_texture_cache(struct Brush *br, int half_side, bool use_secondary)
Definition: brush.c:2474
void BKE_brush_size_set(struct Scene *scene, struct Brush *brush, int size)
Definition: brush.c:2234
bool BKE_brush_use_size_pressure(const struct Brush *brush)
float BKE_brush_alpha_get(const struct Scene *scene, const struct Brush *brush)
float BKE_brush_curve_strength(const struct Brush *br, float p, const float len)
int BKE_brush_size_get(const struct Scene *scene, const struct Brush *brush)
float BKE_brush_unprojected_radius_get(const struct Scene *scene, const struct Brush *brush)
void BKE_brush_unprojected_radius_set(struct Scene *scene, struct Brush *brush, float unprojected_radius)
Definition: brush.c:2294
bool BKE_brush_use_locked_size(const struct Scene *scene, const struct Brush *brush)
void BKE_brush_color_set(struct Scene *scene, struct Brush *brush, const float color[3])
Definition: brush.c:2222
float BKE_brush_sample_tex_3d(const struct Scene *scene, const struct Brush *br, const float point[3], float rgba[4], const int thread, struct ImagePool *pool)
bool BKE_brush_use_alpha_pressure(const struct Brush *brush)
BLI_INLINE float * CCG_elem_mask(const CCGKey *key, CCGElem *elem)
Definition: BKE_ccg.h:113
BLI_INLINE CCGElem * CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:119
BLI_INLINE float * CCG_elem_no(const CCGKey *key, CCGElem *elem)
Definition: BKE_ccg.h:107
struct CCGElem CCGElem
Definition: BKE_ccg.h:46
BLI_INLINE float * CCG_elem_co(const CCGKey *key, CCGElem *elem)
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1200
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:689
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Depsgraph * CTX_data_depsgraph_on_load(const bContext *C)
Definition: context.c:1432
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1279
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:746
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
struct Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Definition: context.c:1401
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
Definition: context.c:1208
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:769
int CustomData_get_active_layer(const struct CustomData *data, int type)
void * CustomData_get_layer_n(const struct CustomData *data, int type, int n)
void * CustomData_get_layer(const struct CustomData *data, int type)
int CustomData_get_offset(const struct CustomData *data, int type)
struct ImagePool * BKE_image_pool_new(void)
Definition: image.c:5173
void BKE_image_pool_free(struct ImagePool *pool)
Definition: image.c:5181
void BKE_kelvinlet_grab(float radius_elem_disp[3], const KelvinletParams *params, const float elem_orig_co[3], const float brush_location[3], const float brush_delta[3])
Definition: kelvinlet.c:67
void BKE_kelvinlet_grab_triscale(float radius_elem_disp[3], const KelvinletParams *params, const float elem_orig_co[3], const float brush_location[3], const float brush_delta[3])
Definition: kelvinlet.c:103
void BKE_kelvinlet_init_params(KelvinletParams *params, float radius, float force, float shear_modulus, float poisson_ratio)
Definition: kelvinlet.c:29
void BKE_kelvinlet_grab_biscale(float radius_elem_disp[3], const KelvinletParams *params, const float elem_orig_co[3], const float brush_location[3], const float brush_delta[3])
Definition: kelvinlet.c:84
void BKE_kelvinlet_scale(float radius_elem_disp[3], const KelvinletParams *params, const float elem_orig_co[3], const float brush_location[3], const float surface_normal[3])
Definition: kelvinlet.c:179
void BKE_kelvinlet_twist(float radius_elem_disp[3], const KelvinletParams *params, const float elem_orig_co[3], const float brush_location[3], const float surface_normal[3])
Definition: kelvinlet.c:207
float(* BKE_keyblock_convert_to_vertcos(struct Object *ob, struct KeyBlock *kb))[3]
Definition: key.c:2413
void BKE_keyblock_update_from_offset(struct Object *ob, struct KeyBlock *kb, const float(*ofs)[3])
Definition: key.c:2473
bool BKE_keyblock_is_basis(struct Key *key, const int index)
Definition: key.c:2600
void BKE_keyblock_update_from_vertcos(struct Object *ob, struct KeyBlock *kb, const float(*vertCos)[3])
Definition: key.c:2320
struct ID * BKE_libblock_find_name(struct Main *bmain, const short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1333
int poly_get_adj_loops_from_vert(const struct MPoly *poly, const struct MLoop *mloop, unsigned int vert, unsigned int r_adj[2])
struct Mesh * BKE_mesh_from_object(struct Object *ob)
Definition: mesh.c:1271
void BKE_mesh_calc_normals(struct Mesh *me)
void BKE_mesh_batch_cache_dirty_tag(struct Mesh *me, eMeshBatchDirtyMode mode)
Definition: mesh_runtime.c:251
void BKE_mesh_mirror_apply_mirror_on_axis(struct Main *bmain, struct Mesh *mesh, const int axis, const float dist)
@ BKE_MESH_BATCH_DIRTY_ALL
void multires_stitch_grids(struct Object *)
Definition: multires.c:1205
void multires_flush_sculpt_updates(struct Object *object)
Definition: multires.c:427
void multires_mark_as_modified(struct Depsgraph *depsgraph, struct Object *object, enum MultiresModifiedFlags flags)
Definition: multires.c:406
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
General operations, lookup, etc. for blender objects.
struct Mesh * BKE_object_get_original_mesh(struct Object *object)
Definition: object.c:4493
void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3])
Definition: object.c:3778
void BKE_object_free_derived_caches(struct Object *ob)
Definition: object.c:1719
struct BoundBox * BKE_object_boundbox_get(struct Object *ob)
Definition: object.c:3817
#define PAINT_SYMM_AREAS
Definition: BKE_paint.h:126
void BKE_paint_brush_set(struct Paint *paint, struct Brush *br)
Definition: paint.c:609
#define PAINT_SYMM_AREA_DEFAULT
Definition: BKE_paint.h:118
void BKE_sculpt_sync_face_sets_visibility_to_base_mesh(struct Mesh *mesh)
Definition: paint.c:1998
struct Paint * BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode)
Definition: paint.c:354
void BKE_sculpt_sync_face_sets_visibility_to_grids(struct Mesh *mesh, struct SubdivCCG *subdiv_ccg)
Definition: paint.c:2013
void BKE_sculpt_toolsettings_data_ensure(struct Scene *scene)
Definition: paint.c:1895
ePaintSymmetryAreas
Definition: BKE_paint.h:120
@ PAINT_SYMM_AREA_Z
Definition: BKE_paint.h:123
@ PAINT_SYMM_AREA_X
Definition: BKE_paint.h:121
@ PAINT_SYMM_AREA_Y
Definition: BKE_paint.h:122
void BKE_sculpt_update_object_for_edit(struct Depsgraph *depsgraph, struct Object *ob_orig, bool need_pmap, bool need_mask, bool need_colors)
Definition: paint.c:1817
const char PAINT_CURSOR_SCULPT[3]
Definition: paint.c:232
struct Brush * BKE_paint_brush(struct Paint *paint)
Definition: paint.c:604
void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3])
Definition: paint.c:1115
#define SCULPT_FACE_SET_NONE
Definition: BKE_paint.h:230
void BKE_sculptsession_free(struct Object *ob)
Definition: paint.c:1466
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Paint *paint)
@ PAINT_MODE_SCULPT
Definition: BKE_paint.h:79
void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
Definition: paint.c:1800
struct MultiresModifierData * BKE_sculpt_multires_active(struct Scene *scene, struct Object *ob)
Definition: paint.c:1527
bool BKE_sculptsession_use_pbvh_draw(const struct Object *ob, const struct View3D *v3d)
void BKE_sculpt_ensure_orig_mesh_data(struct Scene *scene, struct Object *object)
Definition: paint.c:2057
A BVH for high poly meshes.
bool BKE_pbvh_node_fully_masked_get(PBVHNode *node)
Definition: pbvh.c:1798
void BKE_pbvh_node_free_proxies(PBVHNode *node)
Definition: pbvh.c:2869
void BKE_pbvh_node_mark_update(PBVHNode *node)
Definition: pbvh.c:1732
BLI_bitmap ** BKE_pbvh_get_grid_visibility(const PBVH *pbvh)
Definition: pbvh.c:1706
void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node, int(**r_orco_tris)[3], int *r_orco_tris_num, float(**r_orco_coords)[3])
Definition: pbvh.c:1947
#define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode)
Definition: BKE_pbvh.h:384
void BKE_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
Definition: pbvh.c:1921
struct CCGElem ** BKE_pbvh_get_grids(const PBVH *pbvh)
Definition: pbvh.c:1700
void BKE_pbvh_node_mark_update_color(PBVHNode *node)
Definition: pbvh.c:1743
void BKE_pbvh_raycast_project_ray_root(PBVH *pbvh, bool original, float ray_start[3], float ray_end[3], float ray_normal[3])
Definition: pbvh.c:2353
void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
Definition: pbvh.c:2882
void BKE_pbvh_redraw_BB(PBVH *pbvh, float bb_min[3], float bb_max[3])
Definition: pbvh.c:1592
void BKE_pbvh_find_nearest_to_ray(PBVH *pbvh, BKE_pbvh_HitOccludedCallback cb, void *data, const float ray_start[3], const float ray_normal[3], bool original)
Definition: pbvh.c:2430
void BKE_pbvh_bmesh_node_save_orig(struct BMesh *bm, PBVHNode *node)
Definition: pbvh_bmesh.c:2038
float(* BKE_pbvh_vert_coords_alloc(struct PBVH *pbvh))[3]
Definition: pbvh.c:2780
void BKE_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
Definition: pbvh.c:1915
void BKE_pbvh_node_color_buffer_free(PBVH *pbvh)
Definition: pbvh.c:2920
PBVHType BKE_pbvh_type(const PBVH *pbvh)
Definition: pbvh.c:1661
float BKE_pbvh_node_get_tmin(PBVHNode *node)
Definition: pbvh.c:954
bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh, PBVHTopologyUpdateMode mode, const float center[3], const float view_normal[3], float radius, const bool use_frontface, const bool use_projected)
Definition: pbvh_bmesh.c:1957
struct BMesh * BKE_pbvh_get_bmesh(PBVH *pbvh)
Definition: pbvh.c:1724
bool BKE_pbvh_node_raycast(PBVH *pbvh, PBVHNode *node, float(*origco)[3], bool use_origco, const float ray_start[3], const float ray_normal[3], struct IsectRayPrecalc *isect_precalc, float *depth, int *active_vertex_index, int *active_face_grid_index, float *face_normal)
Definition: pbvh.c:2294
void BKE_pbvh_raycast(PBVH *pbvh, BKE_pbvh_HitOccludedCallback cb, void *data, const float ray_start[3], const float ray_normal[3], bool original)
Definition: pbvh.c:2006
#define BKE_pbvh_vertex_iter_end
Definition: BKE_pbvh.h:457
#define PBVH_ITER_UNIQUE
Definition: BKE_pbvh.h:335
int BKE_pbvh_get_grid_num_vertices(const PBVH *pbvh)
Definition: pbvh.c:1712
PBVHTopologyUpdateMode
Definition: BKE_pbvh.h:243
@ PBVH_Collapse
Definition: BKE_pbvh.h:245
@ PBVH_Subdivide
Definition: BKE_pbvh.h:244
const struct CCGKey * BKE_pbvh_get_grid_key(const PBVH *pbvh)
Definition: pbvh.c:1694
PBVHType
Definition: BKE_pbvh.h:209
@ PBVH_GRIDS
Definition: BKE_pbvh.h:211
@ PBVH_BMESH
Definition: BKE_pbvh.h:212
@ PBVH_FACES
Definition: BKE_pbvh.h:210
bool BKE_pbvh_node_find_nearest_to_ray(PBVH *pbvh, PBVHNode *node, float(*origco)[3], bool use_origco, const float ray_start[3], const float ray_normal[3], float *depth, float *dist_sq)
Definition: pbvh.c:2554
PBVHProxyNode * BKE_pbvh_node_add_proxy(PBVH *pbvh, PBVHNode *node)
Definition: pbvh.c:2848
bool BKE_pbvh_node_fully_hidden_get(PBVHNode *node)
Definition: pbvh.c:1781
void BKE_pbvh_parallel_range_settings(struct TaskParallelSettings *settings, bool use_threading, int totnode)
Definition: pbvh.c:3042
struct MVert * BKE_pbvh_get_verts(const PBVH *pbvh)
Definition: pbvh.c:3050
void BKE_pbvh_update_vertex_data(PBVH *pbvh, int flags)
Definition: pbvh.c:1432
void BKE_pbvh_bmesh_after_stroke(PBVH *pbvh)
Definition: pbvh_bmesh.c:2095
void BKE_pbvh_node_mark_update_mask(PBVHNode *node)
Definition: pbvh.c:1738
void BKE_pbvh_update_bounds(PBVH *pbvh, int flags)
Definition: pbvh.c:1410
void BKE_pbvh_bounding_box(const PBVH *pbvh, float min[3], float max[3])
Definition: pbvh.c:1675
void BKE_pbvh_node_mark_redraw(PBVHNode *node)
Definition: pbvh.c:1759
void BKE_pbvh_bmesh_detail_size_set(PBVH *pbvh, float detail_size)
Definition: pbvh_bmesh.c:2110
void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *proxy_count)
Definition: pbvh.c:1927
void BKE_pbvh_node_mark_topology_update(PBVHNode *node)
Definition: pbvh_bmesh.c:2116
void BKE_pbvh_search_gather(PBVH *pbvh, BKE_pbvh_SearchCallback scb, void *search_data, PBVHNode ***array, int *tot)
Definition: pbvh.c:843
@ PBVH_UpdateMask
Definition: BKE_pbvh.h:71
@ PBVH_UpdateColor
Definition: BKE_pbvh.h:80
@ PBVH_UpdateBB
Definition: BKE_pbvh.h:67
@ PBVH_UpdateOriginalBB
Definition: BKE_pbvh.h:68
@ PBVH_UpdateRedraw
Definition: BKE_pbvh.h:70
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_scene_graph_evaluated_ensure(struct Depsgraph *depsgraph, struct Main *bmain)
Definition: scene.c:2718
SubdivCCGAdjacencyType BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(const SubdivCCG *subdiv_ccg, const SubdivCCGCoord *coord, const MLoop *mloop, const MPoly *mpoly, int *r_v1, int *r_v2)
Definition: subdiv_ccg.c:1893
void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg, const SubdivCCGCoord *coord, const bool include_duplicates, SubdivCCGNeighbors *r_neighbors)
Definition: subdiv_ccg.c:1803
void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg, const SubdivCCGCoord *coord, float r_point[3])
Definition: subdiv_ccg.c:1970
SubdivCCGAdjacencyType
@ SUBDIV_CCG_ADJACENT_EDGE
@ SUBDIV_CCG_ADJACENT_VERTEX
@ SUBDIV_CCG_ADJACENT_NONE
int BKE_subdiv_ccg_grid_to_face_index(const SubdivCCG *subdiv_ccg, const int grid_index)
Definition: subdiv_ccg.c:1832
@ MULTIRES_COORDS_MODIFIED
Definition: BKE_subsurf.h:92
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:63
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition: BLI_bitmap.h:78
#define BLI_BITMAP_NEW(_tot, _alloc_string)
Definition: BLI_bitmap.h:50
#define BLI_BITMAP_SET(_bitmap, _index, _set)
Definition: BLI_bitmap.h:93
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
#define BLI_INLINE
Dial * BLI_dial_init(const float start_position[2], float threshold)
Definition: BLI_dial_2d.c:48
float BLI_dial_angle(Dial *dial, const float current_position[2])
Definition: BLI_dial_2d.c:58
void BLI_gsqueue_free(GSQueue *queue)
Definition: gsqueue.c:107
void BLI_gsqueue_push(GSQueue *queue, const void *item)
Definition: gsqueue.c:122
GSQueue * BLI_gsqueue_new(const size_t elem_size)
Definition: gsqueue.c:83
void BLI_gsqueue_pop(GSQueue *queue, void *r_item)
Definition: gsqueue.c:162
bool BLI_gsqueue_is_empty(const GSQueue *queue)
Definition: gsqueue.c:193
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
#define M_SQRT3
Definition: BLI_math_base.h:53
MINLINE float max_ff(float a, float b)
MINLINE float pow2f(float x)
MINLINE float clamp_f(float value, float min, float max)
MINLINE float min_ff(float a, float b)
#define M_PI_2
Definition: BLI_math_base.h:41
MINLINE float square_f(float a)
MINLINE float pow3f(float x)
#define M_SQRT1_2
Definition: BLI_math_base.h:50
#define M_PI
Definition: BLI_math_base.h:38
MINLINE float pow4f(float x)
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
Definition: math_geom.c:243
void isect_ray_tri_watertight_v3_precalc(struct IsectRayPrecalc *isect_precalc, const float ray_direction[3])
Definition: math_geom.c:1879
MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
void closest_to_plane_normalized_v3(float r_close[3], const float plane[4], const float pt[3])
Definition: math_geom.c:412
void dist_squared_ray_to_aabb_v3_precalc(struct DistRayAABB_Precalc *neasrest_precalc, const float ray_origin[3], const float ray_direction[3])
Definition: math_geom.c:696
void closest_on_tri_to_point_v3(float r[3], const float p[3], const float v1[3], const float v2[3], const float v3[3])
Definition: math_geom.c:1023
float dist_signed_to_plane_v3(const float p[3], const float plane[4])
Definition: math_geom.c:468
float dist_squared_ray_to_aabb_v3(const struct DistRayAABB_Precalc *data, const float bb_min[3], const float bb_max[3], float r_point[3], float *r_depth)
Definition: math_geom.c:713
void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[3])
Definition: math_geom.c:405
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition: math_geom.c:51
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void unit_m4(float m[4][4])
Definition: rct.c:1140
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:794
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1278
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void scale_m4_fl(float R[4][4], float scale)
Definition: math_matrix.c:2309
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
bool is_negative_m4(const float mat[4][4])
Definition: math_matrix.c:2590
float mat4_to_scale(const float M[4][4])
Definition: math_matrix.c:2196
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:901
void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:804
void rotate_m4(float mat[4][4], const char axis, const float angle)
Definition: math_matrix.c:2352
void normalize_m4(float R[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1952
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle)
#define DEG2RADF(_deg)
void mul_qt_v3(const float q[4], float r[3])
Definition: math_rotation.c:97
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], const float angle)
void axis_angle_normalized_to_quat(float r[4], const float axis[3], const float angle)
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:52
void pow_qt_fl_normalized(float q[4], const float f)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
Definition: math_vector.c:49
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3(float r[3])
MINLINE void mul_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void normal_short_to_float_v3(float r[3], const short n[3])
MINLINE bool is_zero_v4(const float a[4]) ATTR_WARN_UNUSED_RESULT
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 bool is_zero_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
void project_plane_v3_v3v3(float out[3], const float p[3], const float v_plane[3])
Definition: math_vector.c:740
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void rotate_v3_v3v3fl(float r[3], const float p[3], const float axis[3], const float angle)
Definition: math_vector.c:953
MINLINE void copy_v3_v3_short(short r[3], const short a[3])
MINLINE void negate_v3(float r[3])
MINLINE void zero_v4(float r[4])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void zero_v2(float r[2])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE float len_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v2_v2_int(int r[2], const int a[2])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void BLI_rcti_union(struct rcti *rct1, const struct rcti *rct2)
bool BLI_rcti_is_empty(const struct rcti *rect)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
unsigned int uint
Definition: BLI_sys_types.h:83
void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
Definition: task_range.cc:110
int BLI_task_parallel_thread_id(const TaskParallelTLS *tls)
#define UNUSED_FUNCTION(x)
#define ARRAY_SIZE(arr)
#define ARRAY_SET_ITEMS(...)
#define UNUSED(x)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define UNPACK3(a)
#define ELEM(...)
#define MIN2(a, b)
#define TIP_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ ID_RECALC_SHADING
Definition: DNA_ID.h:631
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:413
@ ID_BR
Definition: DNA_ID_enums.h:81
#define SCULPT_TOOL_HAS_DYNTOPO(t)
#define SCULPT_TOOL_HAS_ACCUMULATE(t)
@ BRUSH_DEFORM_TARGET_CLOTH_SIM
@ BRUSH_DEFORM_TARGET_GEOMETRY
@ BRUSH_SMEAR_DEFORM_PINCH
@ BRUSH_SMEAR_DEFORM_EXPAND
@ BRUSH_SMEAR_DEFORM_DRAG
#define SCULPT_TOOL_HAS_TOPOLOGY_RAKE(t)
@ BRUSH_OFFSET_PRESSURE
@ BRUSH_ORIGINAL_NORMAL
@ BRUSH_FRONTFACE
@ BRUSH_DRAG_DOT
@ BRUSH_GRAB_ACTIVE_VERTEX
@ BRUSH_EDGE_TO_EDGE
@ BRUSH_ORIGINAL_PLANE
@ BRUSH_ACCUMULATE
@ BRUSH_DIR_IN
@ BRUSH_ANCHORED
@ BRUSH_PLANE_TRIM
@ BRUSH_INVERSE_SMOOTH_PRESSURE
@ BRUSH_PERSISTENT
@ BRUSH_INVERT_TO_SCRAPE_FILL
@ BRUSH_CLOTH_DEFORM_EXPAND
@ BRUSH_CLOTH_DEFORM_GRAB
@ BRUSH_CLOTH_DEFORM_SNAKE_HOOK
@ BRUSH_SNAKE_HOOK_DEFORM_ELASTIC
eBrushSculptTool
@ SCULPT_TOOL_SMOOTH
@ SCULPT_TOOL_CLOTH
@ SCULPT_TOOL_DRAW_SHARP
@ SCULPT_TOOL_NUDGE
@ SCULPT_TOOL_SCRAPE
@ SCULPT_TOOL_THUMB
@ SCULPT_TOOL_SIMPLIFY
@ SCULPT_TOOL_DRAW_FACE_SETS
@ SCULPT_TOOL_GRAB
@ SCULPT_TOOL_INFLATE
@ SCULPT_TOOL_CLAY_THUMB
@ SCULPT_TOOL_DRAW
@ SCULPT_TOOL_FLATTEN
@ SCULPT_TOOL_BOUNDARY
@ SCULPT_TOOL_PAINT
@ SCULPT_TOOL_PINCH
@ SCULPT_TOOL_BLOB
@ SCULPT_TOOL_FILL
@ SCULPT_TOOL_POSE
@ SCULPT_TOOL_LAYER
@ SCULPT_TOOL_DISPLACEMENT_ERASER
@ SCULPT_TOOL_SLIDE_RELAX
@ SCULPT_TOOL_SMEAR
@ SCULPT_TOOL_DISPLACEMENT_SMEAR
@ SCULPT_TOOL_CLAY
@ SCULPT_TOOL_MASK
@ SCULPT_TOOL_MULTIPLANE_SCRAPE
@ SCULPT_TOOL_ROTATE
@ SCULPT_TOOL_ELASTIC_DEFORM
@ SCULPT_TOOL_SNAKE_HOOK
@ SCULPT_TOOL_CLAY_STRIPS
@ SCULPT_TOOL_CREASE
@ BRUSH_ELASTIC_DEFORM_SCALE
@ BRUSH_ELASTIC_DEFORM_GRAB
@ BRUSH_ELASTIC_DEFORM_TWIST
@ BRUSH_ELASTIC_DEFORM_GRAB_BISCALE
@ BRUSH_ELASTIC_DEFORM_GRAB_TRISCALE
@ BRUSH_SMOOTH_DEFORM_SURFACE
@ BRUSH_SMOOTH_DEFORM_LAPLACIAN
@ BRUSH_PAINT_WET_MIX_PRESSURE
@ BRUSH_PAINT_HARDNESS_PRESSURE
@ BRUSH_PAINT_FLOW_PRESSURE
@ BRUSH_PAINT_DENSITY_PRESSURE
@ BRUSH_PAINT_WET_PERSISTENCE_PRESSURE
@ BRUSH_PAINT_WET_MIX_PRESSURE_INVERT
@ BRUSH_PAINT_HARDNESS_PRESSURE_INVERT
@ BRUSH_PAINT_FLOW_PRESSURE_INVERT
@ BRUSH_PAINT_DENSITY_PRESSURE_INVERT
@ BRUSH_PAINT_WET_PERSISTENCE_PRESSURE_INVERT
@ PAINT_FALLOFF_SHAPE_SPHERE
@ PAINT_FALLOFF_SHAPE_TUBE
@ SCULPT_DISP_DIR_VIEW
@ SCULPT_DISP_DIR_X
@ SCULPT_DISP_DIR_Z
@ SCULPT_DISP_DIR_Y
@ SCULPT_DISP_DIR_AREA
@ BRUSH_GRAB_SILHOUETTE
@ BRUSH_AREA_RADIUS_PRESSURE
BrushMaskTool
@ BRUSH_MASK_DRAW
@ BRUSH_MASK_SMOOTH
#define SCULPT_TOOL_HAS_NORMAL_WEIGHT(t)
#define SCULPT_TOOL_HAS_RAKE(t)
@ BRUSH_SLIDE_DEFORM_DRAG
@ BRUSH_SLIDE_DEFORM_EXPAND
@ BRUSH_SLIDE_DEFORM_PINCH
@ CD_PAINT_MASK
@ CD_PROP_COLOR
@ CD_MLOOPCOL
@ ME_SCULPT_DYNAMIC_TOPOLOGY
@ ME_HIDE
@ ME_VERT_PBVH_UPDATE
@ eModifierMode_Realtime
@ eModifierType_Mirror
@ MOD_MIR_CLIPPING
@ MOD_MIR_AXIS_X
@ OB_MODE_SCULPT
Object is a sort of wrapper for general info.
@ OB_MESH
@ SCULPT_DYNTOPO_SUBDIVIDE
@ SCULPT_DYNTOPO_DETAIL_MANUAL
@ SCULPT_LOCK_X
@ SCULPT_DYNTOPO_DETAIL_CONSTANT
@ SCULPT_DYNTOPO_COLLAPSE
@ SCULPT_DYNTOPO_DETAIL_BRUSH
#define OBACT(_view_layer)
ePaintSymmetryFlags
@ PAINT_SYMMETRY_FEATHER
@ PAINT_TILE_X
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
#define MTEX_MAP_MODE_3D
#define MTEX_MAP_MODE_AREA
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
#define RV3D_PAINTING
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
@ OPERATOR_PASS_THROUGH
#define OPERATOR_RETVAL_CHECK(ret)
bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMode mode, struct ReportList *reports)
Definition: object_modes.c:165
void ED_region_tag_redraw_partial(struct ARegion *region, const struct rcti *rct, bool rebuild)
bool ED_operator_object_active_editable_mesh(struct bContext *C)
Definition: screen_ops.c:384
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:667
void ED_sculpt_undo_geometry_begin(struct Object *ob, const char *name)
Definition: sculpt_undo.c:1591
void ED_sculpt_undo_geometry_end(struct Object *ob)
Definition: sculpt_undo.c:1597
bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph, const struct ARegion *region, struct View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], const bool do_clip)
void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d)
Definition: space_view3d.c:190
void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct Object *ob, float r_pmat[4][4])
void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc, struct Depsgraph *depsgraph)
void ED_view3d_win_to_delta(const struct ARegion *region, const float mval[2], float out[3], const float zfac)
void ED_view3d_project_float_v2_m4(const struct ARegion *region, const float co[3], float r_co[2], float mat[4][4])
void ED_view3d_win_to_3d(const struct View3D *v3d, const struct ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
void view3d_operator_needs_opengl(const struct bContext *C)
bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, const float co[3], const bool is_local)
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip)
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3])
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky TEX_NOISE
Platform independent time functions.
#define C
Definition: RandGen.cpp:39
#define NC_GEOM
Definition: WM_types.h:294
#define ND_DRAW
Definition: WM_types.h:362
#define NC_BRUSH
Definition: WM_types.h:286
@ OPTYPE_BLOCKING
Definition: WM_types.h:157
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_DATA
Definition: WM_types.h:408
#define ND_MODE
Definition: WM_types.h:345
#define NC_SCENE
Definition: WM_types.h:279
#define NA_EDITED
Definition: WM_types.h:462
#define NC_OBJECT
Definition: WM_types.h:280
@ BM_VERT
Definition: bmesh_class.h:383
@ BM_EDGE
Definition: bmesh_class.h:384
@ BM_ELEM_HIDDEN
Definition: bmesh_class.h:472
@ BM_ELEM_TAG
Definition: bmesh_class.h:484
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:530
#define BM_elem_index_get(ele)
Definition: bmesh_inline.h:124
#define BM_elem_flag_set(ele, hflag, val)
Definition: bmesh_inline.h:30
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:26
#define BM_ITER_ELEM(ele, iter, data, itype)
@ BM_LOOPS_OF_VERT
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_log_all_added(BMesh *bm, BMLog *log)
Definition: bmesh_log.c:987
void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const short **r_no)
Definition: bmesh_log.c:1087
float BM_log_original_mask(BMLog *log, BMVert *v)
Definition: bmesh_log.c:1072
const float * BM_log_original_vert_co(BMLog *log, BMVert *v)
Definition: bmesh_log.c:1036
void BM_log_before_all_removed(BMesh *bm, BMLog *log)
Definition: bmesh_log.c:1015
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
void BM_mesh_toolflags_set(BMesh *bm, bool use_toolflags)
Definition: bmesh_mesh.c:3016
int BM_mesh_elem_count(BMesh *bm, const char htype)
Definition: bmesh_mesh.c:2444
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
Definition: bmesh_mesh.c:2276
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
Definition: bmesh_mesh.c:2152
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:98
#define BMO_FLAG_DEFAULTS
@ BMO_FLAG_RESPECT_HIDE
bool BMO_op_callf(BMesh *bm, const int flag, const char *fmt,...)
bool BM_vert_is_boundary(const BMVert *v)
Definition: bmesh_query.c:1168
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
OperationNode * node
Scene scene
const Depsgraph * depsgraph
static CCL_NAMESPACE_BEGIN const double alpha
#define rot(x, k)
IconTextureDrawCall normal
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
int count
#define powf(x, y)
#define fabsf(x)
#define sqrtf(x)
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:48
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:46
void *(* MEM_reallocN_id)(void *vmemh, size_t len, const char *str)
Definition: mallocn.c:43
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
ccl_device_inline float frac(float x, int *ix)
static unsigned a[3]
Definition: RandGen.cpp:92
static void area(int d1, int d2, int e1, int e2, float weights[2])
void paint_cursor_delete_textures(void)
Definition: paint_cursor.c:102
void paint_cursor_start(Paint *p, bool(*poll)(bContext *C))
bool paint_poll(struct bContext *C)
struct PaintStroke * paint_stroke_new(struct bContext *C, struct wmOperator *op, StrokeGetLocation get_location, StrokeTestStart test_start, StrokeUpdateStep update_step, StrokeRedraw redraw, StrokeDone done, int event_type)
Definition: paint_stroke.c:889
int paint_stroke_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event)
@ BRUSH_STROKE_SMOOTH
Definition: paint_intern.h:313
@ BRUSH_STROKE_INVERT
Definition: paint_intern.h:312
void flip_qt_qt(float out[3], const float in[3], const enum ePaintSymmetryFlags symm)
bool paint_convert_bb_to_rect(struct rcti *rect, const float bb_min[3], const float bb_max[3], const struct ARegion *region, struct RegionView3D *rv3d, struct Object *ob)
int paint_stroke_exec(struct bContext *C, struct wmOperator *op)
void paint_stroke_free(struct bContext *C, struct wmOperator *op)
Definition: paint_stroke.c:948
float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius)
Definition: paint_utils.c:151
void paint_calc_redraw_planes(float planes[4][4], const struct ARegion *region, struct Object *ob, const struct rcti *screen_rect)
bool paint_supports_dynamic_size(struct Brush *br, enum ePaintMode mode)
float paint_get_tex_pixel(const struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread)
void flip_v3_v3(float out[3], const float in[3], const enum ePaintSymmetryFlags symm)
Definition: paint_utils.c:407
struct ViewContext * paint_stroke_view_context(struct PaintStroke *stroke)
void paint_stroke_cancel(struct bContext *C, struct wmOperator *op)
void paint_stroke_operator_properties(struct wmOperatorType *ot)
Definition: paint_utils.c:210
void SCULPT_OT_trim_box_gesture(wmOperatorType *ot)
Definition: paint_mask.c:1763
void SCULPT_OT_face_set_box_gesture(wmOperatorType *ot)
Definition: paint_mask.c:1723
void SCULPT_OT_project_line_gesture(wmOperatorType *ot)
Definition: paint_mask.c:1784
void SCULPT_OT_trim_lasso_gesture(wmOperatorType *ot)
Definition: paint_mask.c:1742
void SCULPT_OT_face_set_lasso_gesture(wmOperatorType *ot)
Definition: paint_mask.c:1706
const btScalar eps
Definition: poly34.cpp:11
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3825
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
static const char * sculpt_tool_name(Sculpt *sd)
Definition: sculpt.c:6630
const float * SCULPT_vertex_co_get(SculptSession *ss, int index)
Definition: sculpt.c:134
static void sculpt_project_v3_normal_align(SculptSession *ss, const float normal_weight, float grab_delta[3])
Definition: sculpt.c:1376
static void sculpt_project_v3(const SculptProjectVector *spvc, const float vec[3], float r_vec[3])
Definition: sculpt.c:1428
bool SCULPT_brush_test_sphere(SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1667
static bool sculpt_mask_by_color_contiguous_floodfill_cb(SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata)
Definition: sculpt.c:9207
static void do_slide_relax_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3632
int SCULPT_vertex_count_get(SculptSession *ss)
Definition: sculpt.c:120
static void do_fill_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5322
static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4656
static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:2992
static void flip_qt(float quat[3], const ePaintSymmetryFlags symm)
Definition: sculpt.c:1853
void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter *iter)
Definition: sculpt.c:1310
void SCULPT_floodfill_add_and_skip_initial(SculptFloodFill *flood, int index)
Definition: sculpt.c:1099
static void flip_v3(float v[3], const ePaintSymmetryFlags symm)
Definition: sculpt.c:1848
static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip)
Definition: sculpt.c:4866
void SCULPT_floodfill_add_initial_with_symmetry(Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, int index, float radius)
Definition: sculpt.c:1105
static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mouse[2])
Definition: sculpt.c:6775
static bool sculpt_no_multires_poll(bContext *C)
Definition: sculpt.c:8251
void SCULPT_boundary_info_ensure(Object *object)
Definition: sculpt.c:9039
void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float(*vertCos)[3])
Definition: sculpt.c:5763
static void do_displacement_eraser_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3111
static void calc_area_normal_and_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
Definition: sculpt.c:2248
bool SCULPT_stroke_get_location(bContext *C, float out[3], const float mouse[2])
Definition: sculpt.c:7584
void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *region, Object *ob)
Definition: sculpt.c:1592
static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect)
Definition: sculpt.c:1551
int SCULPT_active_vertex_get(SculptSession *ss)
Definition: sculpt.c:277
static void SCULPT_OT_mask_by_color(wmOperatorType *ot)
Definition: sculpt.c:9391
static void do_elastic_deform_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4150
int SCULPT_nearest_vertex_get(Sculpt *sd, Object *ob, const float co[3], float max_distance, bool use_original)
Definition: sculpt.c:1000
static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4360
static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *UNUSED(stroke), PointerRNA *itemptr)
Definition: sculpt.c:7925
bool SCULPT_cursor_geometry_info_update(bContext *C, SculptCursorGeometryInfo *out, const float mouse[2], bool use_sampled_normal)
Definition: sculpt.c:7452
static int sculpt_optimize_exec(bContext *C, wmOperator *UNUSED(op))
Definition: sculpt.c:8221
static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength)
Definition: sculpt.c:5735
bool SCULPT_pbvh_calc_area_normal(const Brush *brush, Object *ob, PBVHNode **nodes, int totnode, bool use_threading, float r_area_no[3])
Definition: sculpt.c:2205
void SCULPT_floodfill_init(SculptSession *ss, SculptFloodFill *flood)
Definition: sculpt.c:1085
int SCULPT_plane_point_side(const float co[3], const float plane[4])
Definition: sculpt.c:4875
void SCULPT_face_set_visibility_set(SculptSession *ss, int face_set, bool visible)
Definition: sculpt.c:382
static int SCULPT_fake_neighbor_search(Sculpt *sd, Object *ob, const int index, float max_distance)
Definition: sculpt.c:8950
void SCULPT_fake_neighbors_ensure(Sculpt *sd, Object *ob, const float max_dist)
Definition: sculpt.c:9070
static void fake_neighbor_search_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:8934
bool SCULPT_vertex_has_face_set(SculptSession *ss, int index, int face_set)
Definition: sculpt.c:539
void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
Definition: sculpt.c:245
static void calc_area_normal_and_center_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:2128
static int SCULPT_vertex_get_connected_component(SculptSession *ss, int index)
Definition: sculpt.c:8871
struct NearestVertexTLSData NearestVertexTLSData
static void sculpt_mask_by_color_contiguous(Object *object, const int vertex, const float threshold, const bool invert, const bool preserve_mask)
Definition: sculpt.c:9225
static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush *brush)
Definition: sculpt.c:1231
static void do_clay_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5050
static void SCULPT_OT_set_persistent_base(wmOperatorType *ot)
Definition: sculpt.c:8205
static void SCULPT_OT_sculptmode_toggle(wmOperatorType *ot)
Definition: sculpt.c:8591
static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4578
static void sculpt_combine_proxies(Sculpt *sd, Object *ob)
Definition: sculpt.c:6261
static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4385
static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush)
Definition: sculpt.c:1240
bool SCULPT_vertex_has_unique_face_set(SculptSession *ss, int index)
Definition: sculpt.c:669
void SCULPT_cache_calc_brushdata_symm(StrokeCache *cache, const char symm, const char axis, const float angle)
Definition: sculpt.c:6397
void SCULPT_relax_vertex(SculptSession *ss, PBVHVertexIter *vd, float factor, bool filter_boundary_face_sets, float *r_final_pos)
Definition: sculpt.c:3506
static void do_topology_slide_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3431
static int sculpt_symmetrize_exec(bContext *C, wmOperator *op)
Definition: sculpt.c:8260
const float * SCULPT_brush_frontface_normal_from_falloff_shape(SculptSession *ss, char falloff_shape)
Definition: sculpt.c:1787
static void do_nearest_vertex_get_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:964
SculptBrushTestFn SCULPT_brush_test_init_with_falloff_shape(SculptSession *ss, SculptBrushTest *test, char falloff_shape)
Definition: sculpt.c:1770
void SCULPT_tilt_effective_normal_get(const SculptSession *ss, const Brush *brush, float r_no[3])
Definition: sculpt.c:2865
static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:5103
static void sculpt_project_v3_cache_init(SculptProjectVector *spvc, const float plane[3])
Definition: sculpt.c:1417
static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5169
static float sculpt_clay_thumb_get_stabilized_pressure(StrokeCache *cache)
Definition: sculpt.c:5596
struct NearestVertexFakeNeighborTLSData NearestVertexFakeNeighborTLSData
static void do_brush_action_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:5876
void SCULPT_fake_neighbors_free(Object *ob)
Definition: sculpt.c:9113
static void do_rotate_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4603
bool SCULPT_vertex_any_face_set_visible_get(SculptSession *ss, int index)
Definition: sculpt.c:445
const float * SCULPT_vertex_co_for_grab_active_get(SculptSession *ss, int index)
Definition: sculpt.c:207
BLI_INLINE bool sculpt_brush_test_clipping(const SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1653
static void sculpt_vertex_neighbor_add(SculptVertexNeighborIter *iter, int neighbor_index)
Definition: sculpt.c:724
static void do_displacement_smear_store_prev_disp_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:3222
void SCULPT_vertex_face_set_set(SculptSession *ss, int index, int face_set)
Definition: sculpt.c:489
bool SCULPT_brush_test_circle_sq(SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1705
static void do_pinch_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3867
void SCULPT_floodfill_add_initial(SculptFloodFill *flood, int index)
Definition: sculpt.c:1094
static void sculpt_rake_rotate(const SculptSession *ss, const float sculpt_co[3], const float v_co[3], float factor, float r_delta[3])
Definition: sculpt.c:1342
void(* BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups)
Definition: sculpt.c:6448
static void SCULPT_OT_loop_to_vertex_colors(wmOperatorType *ot)
Definition: sculpt.c:8791
static void do_elastic_deform_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:4067
bool SCULPT_is_symmetry_iteration_valid(char i, char symm)
Definition: sculpt.c:1042
static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd)
Definition: sculpt.c:6183
void SCULPT_connected_components_ensure(Object *ob)
Definition: sculpt.c:9007
static void do_crease_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3754
const float * SCULPT_active_vertex_co_get(SculptSession *ss)
Definition: sculpt.c:285
static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const float mouse[2])
Definition: sculpt.c:7902
static void calc_area_normal_and_center_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:1939
static void SCULPT_OT_sample_color(wmOperatorType *ot)
Definition: sculpt.c:8830
void SCULPT_vertex_random_access_ensure(SculptSession *ss)
Definition: sculpt.c:112
void SCULPT_geometry_preview_lines_update(bContext *C, SculptSession *ss, float radius)
Definition: sculpt.c:8605
static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3814
static void do_nudge_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4317
static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4042
void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType update_flags)
Definition: sculpt.c:7819
struct SculptProjectVector SculptProjectVector
static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op)
Definition: sculpt.c:8106
bool SCULPT_brush_test_cube(SculptBrushTest *test, const float co[3], const float local[4][4], const float roundness)
Definition: sculpt.c:1723
bool SCULPT_search_sphere_cb(PBVHNode *node, void *data_v)
Definition: sculpt.c:2561
static void sculpt_combine_proxies_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:6202
void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush)
Definition: sculpt.c:7327
void SCULPT_vertex_visible_set(SculptSession *ss, int index, bool visible)
Definition: sculpt.c:347
static void sculpt_vertex_neighbors_get_grids(SculptSession *ss, const int index, const bool include_duplicates, SculptVertexNeighborIter *iter)
Definition: sculpt.c:802
bool SCULPT_vertex_visible_get(SculptSession *ss, int index)
Definition: sculpt.c:362
static void calc_clay_surface_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:5040
static void SCULPT_flush_stroke_deform_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:6315
static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups)
Definition: sculpt.c:5906
static void UNUSED_FUNCTION() sculpt_visibility_sync_vertex_to_face_sets(SculptSession *ss, int index)
Definition: sculpt.c:582
void ED_object_sculptmode_exit(bContext *C, Depsgraph *depsgraph)
Definition: sculpt.c:8531
static int sculpt_sample_color_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(e))
Definition: sculpt.c:8805
void SCULPT_face_sets_visibility_all_set(SculptSession *ss, bool visible)
Definition: sculpt.c:418
static void paint_mesh_restore_co_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:1463
float * SCULPT_brush_deform_target_vertex_co_get(SculptSession *ss, const int deform_target, PBVHVertexIter *iter)
Definition: sculpt.c:310
static void sculpt_init_session(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: sculpt.c:8353
static void do_scrape_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5421
static bool over_mesh(bContext *C, struct wmOperator *UNUSED(op), float x, float y)
Definition: sculpt.c:7892
static void SCULPT_OT_optimize(wmOperatorType *ot)
Definition: sculpt.c:8235
static bool sculpt_check_unique_face_set_for_edge_in_base_mesh(SculptSession *ss, int v1, int v2)
Definition: sculpt.c:641
static void do_grab_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3981
static void do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3395
static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
Definition: sculpt.c:7341
void SCULPT_face_sets_visibility_invert(SculptSession *ss)
Definition: sculpt.c:404
static void sculpt_restore_mesh(Sculpt *sd, Object *ob)
Definition: sculpt.c:7715
static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, PointerRNA *ptr)
Definition: sculpt.c:7203
static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4949
void SCULPT_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, SculptUndoNode *unode)
Definition: sculpt.c:1277
static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: sculpt.c:8066
static void do_layer_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4677
StrokeFlags
Definition: sculpt.c:1267
@ CLIP_Z
Definition: sculpt.c:1270
@ CLIP_Y
Definition: sculpt.c:1269
@ CLIP_X
Definition: sculpt.c:1268
void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags)
Definition: sculpt.c:7759
static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4771
void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3])
Definition: sculpt.c:172
static void sculpt_update_keyblock(Object *ob)
Definition: sculpt.c:6290
static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:5382
static void calc_sculpt_plane(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
Definition: sculpt.c:3663
void SCULPT_vertex_limit_surface_get(SculptSession *ss, int index, float r_co[3])
Definition: sculpt.c:224
static PBVHNode ** sculpt_pbvh_gather_cursor_update(Object *ob, Sculpt *sd, bool use_original, int *r_totnode)
Definition: sculpt.c:2669
struct SculptTopologyIDFloodFillData SculptTopologyIDFloodFillData
static void do_thumb_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4530
static void bmesh_topology_rake(Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength)
Definition: sculpt.c:2963
bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *brush)
Definition: sculpt.c:1448
bool SCULPT_vertex_is_boundary(const SculptSession *ss, const int index)
Definition: sculpt.c:868
static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
Definition: sculpt.c:6533
static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op))
Definition: sculpt.c:8178
void SCULPT_flip_v3_by_symm_area(float v[3], const ePaintSymmetryFlags symm, const ePaintSymmetryAreas symmarea, const float pivot[3])
Definition: sculpt.c:4190
static void SCULPT_OT_vertex_to_loop_colors(wmOperatorType *ot)
Definition: sculpt.c:8728
bool SCULPT_vertex_colors_poll(bContext *C)
Definition: sculpt.c:6607
static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:5229
static void SCULPT_OT_brush_stroke(wmOperatorType *ot)
Definition: sculpt.c:8148
static bool sculpt_tool_is_proxy_used(const char sculpt_tool)
Definition: sculpt.c:1217
static void sculpt_brush_stroke_cancel(bContext *C, wmOperator *op)
Definition: sculpt.c:8125
static void do_draw_sharp_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3348
bool SCULPT_mode_poll_view3d(bContext *C)
Definition: sculpt.c:6615
float SCULPT_brush_plane_offset_get(Sculpt *sd, SculptSession *ss)
Definition: sculpt.c:4881
void SCULPT_floodfill_free(SculptFloodFill *flood)
Definition: sculpt.c:1188
static float calc_radial_symmetry_feather(Sculpt *sd, StrokeCache *cache, const char symm, const char axis)
Definition: sculpt.c:1879
void ED_object_sculptmode_exit_ex(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: sculpt.c:8488
static float sculpt_mask_by_color_delta_get(const float *color_a, const float *color_b, const float threshold, const bool invert)
Definition: sculpt.c:9130
static int vertex_to_loop_colors_exec(bContext *C, wmOperator *UNUSED(op))
Definition: sculpt.c:8679
bool SCULPT_mode_poll(bContext *C)
Definition: sculpt.c:6601
void SCULPT_fake_neighbors_enable(Object *ob)
Definition: sculpt.c:9099
bool SCULPT_stroke_is_main_symmetry_pass(StrokeCache *cache)
Definition: sculpt.c:913
static float brush_strength(const Sculpt *sd, const StrokeCache *cache, const float feather, const UnifiedPaintSettings *ups)
Definition: sculpt.c:2312
static void sculpt_update_cache_paint_variants(StrokeCache *cache, const Brush *brush)
Definition: sculpt.c:7158
static void sculpt_mask_by_color_full_mesh(Object *object, const int vertex, const float threshold, const bool invert, const bool preserve_mask)
Definition: sculpt.c:9314
#define SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY
Definition: sculpt.c:722
static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:2905
static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3933
static void do_mask_by_color_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:9279
void SCULPT_active_vertex_normal_get(SculptSession *ss, float normal[3])
Definition: sculpt.c:290
static bool sculpt_needs_delta_from_anchored_origin(Brush *brush)
Definition: sculpt.c:6968
static void do_mask_by_color_contiguous_update_nodes_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:9176
static void SCULPT_fake_neighbor_add(SculptSession *ss, int v_index_a, int v_index_b)
Definition: sculpt.c:8891
float SCULPT_brush_strength_factor(SculptSession *ss, const Brush *br, const float brush_point[3], const float len, const short vno[3], const float fno[3], const float mask, const int vertex_index, const int thread_id)
Definition: sculpt.c:2463
void SCULPT_flip_quat_by_symm_area(float quat[3], const ePaintSymmetryFlags symm, const ePaintSymmetryAreas symmarea, const float pivot[3])
Definition: sculpt.c:4209
bool SCULPT_vertex_all_face_sets_visible_get(const SculptSession *ss, int index)
Definition: sculpt.c:465
static void do_displacement_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3237
static void do_displacement_smear_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3134
const float * SCULPT_vertex_color_get(SculptSession *ss, int index)
Definition: sculpt.c:157
#define SCULPT_TILT_SENSITIVITY
Definition: sculpt.c:2848
static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat[4][4])
Definition: sculpt.c:2805
static bool sculpt_needs_connectivity_info(const Sculpt *sd, const Brush *brush, SculptSession *ss, int stroke_mode)
Definition: sculpt.c:7308
void SCULPT_brush_test_init(SculptSession *ss, SculptBrushTest *test)
Definition: sculpt.c:1616
bool SCULPT_brush_test_sphere_sq(SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1683
static void calc_area_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3])
Definition: sculpt.c:2148
void SCULPT_tilt_apply_to_normal(float r_normal[3], StrokeCache *cache, const float tilt_strength)
Definition: sculpt.c:2849
int SCULPT_vertex_face_set_get(SculptSession *ss, int index)
Definition: sculpt.c:514
static void calc_local_y(ViewContext *vc, const float center[3], float y[3])
Definition: sculpt.c:2789
static PBVHNode ** sculpt_pbvh_gather_generic(Object *ob, Sculpt *sd, const Brush *brush, bool use_original, float radius_scale, int *r_totnode)
Definition: sculpt.c:2688
static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
Definition: sculpt.c:1518
static bool sculpt_needs_delta_for_tip_orientation(Brush *brush)
Definition: sculpt.c:6987
static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
Definition: sculpt.c:8540
static void sculpt_pose_fake_neighbors_free(SculptSession *ss)
Definition: sculpt.c:8899
static void do_displacement_eraser_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3067
void SCULPT_visibility_sync_all_vertex_to_face_sets(SculptSession *ss)
Definition: sculpt.c:598
bool SCULPT_stroke_is_first_brush_step_of_symmetry_pass(StrokeCache *cache)
Definition: sculpt.c:935
static void do_topology_relax_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3588
static void sculpt_rake_data_update(struct SculptRakeData *srd, const float co[3])
Definition: sculpt.c:1334
static void sculpt_vertex_neighbors_get_bmesh(SculptSession *ss, int index, SculptVertexNeighborIter *iter)
Definition: sculpt.c:749
float SCULPT_vertex_mask_get(SculptSession *ss, int index)
Definition: sculpt.c:254
static void update_brush_local_mat(Sculpt *sd, Object *ob)
Definition: sculpt.c:2871
static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Brush *brush)
Definition: sculpt.c:7001
static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
Definition: sculpt.c:1894
void SCULPT_fake_neighbors_disable(Object *ob)
Definition: sculpt.c:9106
static void do_inflate_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4793
static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: sculpt.c:9342
static float frontface(const Brush *br, const float sculpt_normal[3], const short no[3], const float fno[3])
Definition: sculpt.c:1797
static void do_draw_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3273
static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *tmin)
Definition: sculpt.c:7378
#define MASK_BY_COLOR_SLOPE
Definition: sculpt.c:9128
static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4492
int SCULPT_face_set_next_available_get(SculptSession *ss)
Definition: sculpt.c:700
static void do_symmetrical_brush_actions(Sculpt *sd, Object *ob, BrushActionFunc action, UnifiedPaintSettings *ups)
Definition: sculpt.c:6544
static bool sculpt_check_unique_face_set_in_base_mesh(SculptSession *ss, int index)
Definition: sculpt.c:620
static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action, const char symm, const int axis, const float UNUSED(feather))
Definition: sculpt.c:6510
static void SCULPT_fake_neighbor_init(SculptSession *ss, const float max_dist)
Definition: sculpt.c:8879
static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss)
Definition: sculpt.c:6736
int SCULPT_plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3])
Definition: sculpt.c:4860
static void sculpt_topology_update(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *UNUSED(ups))
Definition: sculpt.c:5808
static void sculpt_brush_exit_tex(Sculpt *sd)
Definition: sculpt.c:7994
char SCULPT_mesh_symmetry_xyz_get(Object *object)
Definition: sculpt.c:323
void SCULPT_calc_brush_plane(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
Definition: sculpt.c:4228
static bool sculpt_tool_needs_original(const char sculpt_tool)
Definition: sculpt.c:1203
bool SCULPT_is_vertex_inside_brush_radius_symm(const float vertex[3], const float br_co[3], float radius, char symm)
Definition: sculpt.c:1048
static void do_clay_thumb_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5523
void SCULPT_vertex_neighbors_get(SculptSession *ss, const int index, const bool include_duplicates, SculptVertexNeighborIter *iter)
Definition: sculpt.c:844
bool SCULPT_search_circle_cb(PBVHNode *node, void *data_v)
Definition: sculpt.c:2608
void SCULPT_update_object_bounding_box(Object *ob)
Definition: sculpt.c:7749
bool SCULPT_check_vertex_pivot_symmetry(const float vco[3], const float pco[3], const char symm)
Definition: sculpt.c:940
static void do_fake_neighbor_search_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:8910
static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:2762
void SCULPT_cache_free(StrokeCache *cache)
Definition: sculpt.c:6708
void SCULPT_floodfill_add_active(Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, float radius)
Definition: sculpt.c:1131
void SCULPT_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_used)
Definition: sculpt.c:6340
static float sculpt_brush_dynamic_size_get(Brush *brush, StrokeCache *cache, float initial_size)
Definition: sculpt.c:6950
void SCULPT_calc_area_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
Definition: sculpt.c:2197
bool SCULPT_stroke_is_first_brush_step(StrokeCache *cache)
Definition: sculpt.c:926
void ED_object_sculptmode_enter_ex(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, const bool force_dyntopo, ReportList *reports)
Definition: sculpt.c:8391
void ED_operatortypes_sculpt(void)
Definition: sculpt.c:9426
static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession *ss)
Definition: sculpt.c:7663
const float * SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
Definition: sculpt.c:199
bool SCULPT_get_redraw_rect(ARegion *region, RegionView3D *rv3d, Object *ob, rcti *rect)
Definition: sculpt.c:1573
MVert * SCULPT_mesh_deformed_mverts_get(SculptSession *ss)
Definition: sculpt.c:295
static void nearest_vertex_get_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:984
static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:4844
bool SCULPT_poll_view3d(bContext *C)
Definition: sculpt.c:6620
static int loop_to_vertex_colors_exec(bContext *C, wmOperator *UNUSED(op))
Definition: sculpt.c:8742
@ SCULPT_TOPOLOGY_ID_DEFAULT
Definition: sculpt.c:8868
@ SCULPT_TOPOLOGY_ID_NONE
Definition: sculpt.c:8867
static void SCULPT_OT_symmetrize(wmOperatorType *ot)
Definition: sculpt.c:8329
static bool sculpt_brush_needs_rake_rotation(const Brush *brush)
Definition: sculpt.c:1262
bool SCULPT_poll(bContext *C)
Definition: sculpt.c:6625
ePaintSymmetryAreas SCULPT_get_vertex_symm_area(const float co[3])
Definition: sculpt.c:4175
static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle)
Definition: sculpt.c:1858
void ED_object_sculptmode_enter(struct bContext *C, Depsgraph *depsgraph, ReportList *reports)
Definition: sculpt.c:8479
static void do_gravity_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5693
static void do_flatten_brush_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4894
int SCULPT_active_face_set_get(SculptSession *ss)
Definition: sculpt.c:331
static bool SCULPT_connected_components_floodfill_cb(SculptSession *ss, int from_v, int to_v, bool UNUSED(is_duplicate), void *userdata)
Definition: sculpt.c:8998
static void calc_clay_surface_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:4995
static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3048
void SCULPT_floodfill_execute(SculptSession *ss, SculptFloodFill *flood, bool(*func)(SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata), void *userdata)
Definition: sculpt.c:1157
struct ClaySampleData ClaySampleData
static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3316
static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke))
Definition: sculpt.c:8004
struct MaskByColorContiguousFloodFillData MaskByColorContiguousFloodFillData
void SCULPT_clip(Sculpt *sd, SculptSession *ss, float co[3], const float val[3])
Definition: sculpt.c:2638
static bool sculpt_check_boundary_vertex_in_base_mesh(const SculptSession *ss, const int index)
Definition: sculpt.c:862
void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node)
Definition: sculpt.c:1300
void SCULPT_visibility_sync_all_face_sets_to_vertices(Object *ob)
Definition: sculpt.c:563
static void do_clay_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:5605
static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:3031
static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss)
Definition: sculpt.c:6577
static void sculpt_brush_stroke_init(bContext *C, wmOperator *op)
Definition: sculpt.c:7679
static float sculpt_mask_by_color_final_mask_get(const float current_mask, const float new_mask, const bool invert, const bool preserve_mask)
Definition: sculpt.c:9155
static void calc_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
Definition: sculpt.c:2730
static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:5480
struct AreaNormalCenterTLSData AreaNormalCenterTLSData
#define PIXEL_INPUT_THRESHHOLD
static void do_tiled(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action)
Definition: sculpt.c:6450
void SCULPT_tag_update_overlays(bContext *C)
Definition: sculpt.c:1066
bool SCULPT_brush_test_sphere_fast(const SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1697
static void sculpt_vertex_neighbors_get_faces(SculptSession *ss, int index, SculptVertexNeighborIter *iter)
Definition: sculpt.c:772
float SCULPT_raycast_init(ViewContext *vc, const float mouse[2], float ray_start[3], float ray_end[3], float ray_normal[3], bool original)
Definition: sculpt.c:7412
void SCULPT_automasking_cache_free(AutomaskingCache *automasking)
float SCULPT_automasking_factor_get(AutomaskingCache *automasking, SculptSession *ss, int vert)
AutomaskingCache * SCULPT_automasking_cache_init(Sculpt *sd, Brush *brush, Object *ob)
bool SCULPT_is_automasking_enabled(const Sculpt *sd, const SculptSession *ss, const Brush *br)
void SCULPT_boundary_data_free(SculptBoundary *boundary)
void SCULPT_do_boundary_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_cloth_brush_ensure_nodes_constraints(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, SculptClothSimulation *cloth_sim, float initial_location[3], const float radius)
PBVHNode ** SCULPT_cloth_brush_affected_nodes_gather(SculptSession *ss, Brush *brush, int *r_totnode)
Definition: sculpt_cloth.c:122
void SCULPT_cloth_sim_activate_nodes(SculptClothSimulation *cloth_sim, PBVHNode **nodes, int totnode)
SculptClothSimulation * SCULPT_cloth_brush_simulation_create(SculptSession *ss, const float cloth_mass, const float cloth_damping, const float cloth_softbody_strength, const bool use_collisions, const bool needs_deform_coords)
void SCULPT_cloth_simulation_free(struct SculptClothSimulation *cloth_sim)
void SCULPT_cloth_brush_store_simulation_state(SculptSession *ss, SculptClothSimulation *cloth_sim)
void SCULPT_cloth_brush_do_simulation_step(Sculpt *sd, Object *ob, SculptClothSimulation *cloth_sim, PBVHNode **nodes, int totnode)
Definition: sculpt_cloth.c:927
void SCULPT_OT_cloth_filter(struct wmOperatorType *ot)
void SCULPT_cloth_brush_simulation_init(SculptSession *ss, SculptClothSimulation *cloth_sim)
void SCULPT_do_cloth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_OT_sample_detail_size(wmOperatorType *ot)
void SCULPT_OT_detail_flood_fill(wmOperatorType *ot)
void SCULPT_OT_set_detail_size(wmOperatorType *ot)
void SCULPT_OT_dyntopo_detail_size_edit(wmOperatorType *ot)
enum eDynTopoWarnFlag SCULPT_dynamic_topology_check(Scene *scene, Object *ob)
void SCULPT_pbvh_clear(Object *ob)
void SCULPT_OT_dynamic_topology_toggle(wmOperatorType *ot)
void sculpt_dynamic_topology_disable_with_undo(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void SCULPT_dynamic_topology_enable_ex(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void SCULPT_dynamic_topology_triangulate(BMesh *bm)
void SCULPT_OT_expand(wmOperatorType *ot)
void SCULPT_OT_face_sets_change_visibility(wmOperatorType *ot)
void SCULPT_OT_face_sets_init(wmOperatorType *ot)
void SCULPT_OT_face_sets_create(wmOperatorType *ot)
void SCULPT_OT_face_sets_edit(struct wmOperatorType *ot)
void SCULPT_OT_face_sets_randomize_colors(wmOperatorType *ot)
void SCULPT_do_draw_face_sets_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_OT_color_filter(struct wmOperatorType *ot)
void SCULPT_OT_mask_filter(struct wmOperatorType *ot)
void SCULPT_OT_dirty_mask(struct wmOperatorType *ot)
void SCULPT_OT_mesh_filter(struct wmOperatorType *ot)
void SCULPT_undo_push_begin(struct Object *ob, const char *name)
Definition: sculpt_undo.c:1383
#define SCULPT_RAKE_BRUSH_FACTOR
#define FAKE_NEIGHBOR_NONE
void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
#define SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN(ss, v_index, neighbor_iterator)
SculptUndoNode * SCULPT_undo_get_node(PBVHNode *node)
Definition: sculpt_undo.c:930
void SCULPT_pose_brush_init(struct Sculpt *sd, struct Object *ob, struct SculptSession *ss, struct Brush *br)
Definition: sculpt_pose.c:980
BLI_INLINE bool SCULPT_is_cloth_deform_brush(const Brush *brush)
void SCULPT_OT_set_pivot_position(struct wmOperatorType *ot)
BLI_INLINE bool SCULPT_tool_needs_all_pbvh_nodes(const Brush *brush)
void SCULPT_do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_smooth(Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength, const bool smooth_mask)
void SCULPT_do_multiplane_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
bool(* SculptBrushTestFn)(SculptBrushTest *test, const float co[3])
SculptUndoNode * SCULPT_undo_get_first_node(void)
Definition: sculpt_undo.c:941
#define SCULPT_CLAY_STABILIZER_LEN
void SCULPT_bmesh_four_neighbor_average(float avg[3], float direction[3], struct BMVert *v)
SculptUpdateType
Definition: sculpt_intern.h:57
@ SCULPT_UPDATE_COLOR
Definition: sculpt_intern.h:61
@ SCULPT_UPDATE_MASK
Definition: sculpt_intern.h:59
@ SCULPT_UPDATE_COORDS
Definition: sculpt_intern.h:58
#define SCULPT_VERTEX_NEIGHBORS_ITER_END(neighbor_iterator)
void SCULPT_do_pose_brush(struct Sculpt *sd, struct Object *ob, struct PBVHNode **nodes, int totnode)
Definition: sculpt_pose.c:1136
void SCULPT_undo_push_end(void)
Definition: sculpt_undo.c:1400
eDynTopoWarnFlag
@ DYNTOPO_WARN_LDATA
@ DYNTOPO_WARN_MODIFIER
@ DYNTOPO_WARN_VDATA
@ DYNTOPO_WARN_EDATA
void SCULPT_do_surface_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
SculptUndoNode * SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType type)
Definition: sculpt_undo.c:1292
void SCULPT_do_paint_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
#define SCULPT_VERTEX_DUPLICATES_AND_NEIGHBORS_ITER_BEGIN(ss, v_index, neighbor_iterator)
void SCULPT_OT_mask_init(struct wmOperatorType *ot)
void SCULPT_pose_ik_chain_free(struct SculptPoseIKChain *ik_chain)
Definition: sculpt_pose.c:1233
SculptUndoType
@ SCULPT_UNDO_FACE_SETS
@ SCULPT_UNDO_COORDS
@ SCULPT_UNDO_DYNTOPO_SYMMETRIZE
@ SCULPT_UNDO_COLOR
@ SCULPT_UNDO_DYNTOPO_BEGIN
@ SCULPT_UNDO_MASK
void SCULPT_OT_mask_expand(struct wmOperatorType *ot)
void * regiondata
float area_nos[2][3]
Definition: sculpt.c:1934
float area_cos[2][3]
Definition: sculpt.c:1933
struct BMVert * v
Definition: bmesh_class.h:165
struct BMLoop * prev
Definition: bmesh_class.h:245
struct BMLoop * next
Definition: bmesh_class.h:245
float co[3]
Definition: bmesh_class.h:99
float no[3]
Definition: bmesh_class.h:100
CustomData vdata
Definition: bmesh_class.h:337
float vec[8][3]
float topology_rake_factor
int sculpt_plane
int cloth_deform_type
int snake_hook_deform_type
float density
int slide_deform_type
int elastic_deform_type
float normal_radius_factor
struct MTex mtex
float normal_weight
float rake_factor
float elastic_deform_volume_preservation
struct CurveMapping * curve
float texture_sample_bias
float plane_trim
char falloff_shape
float tilt_strength_factor
float hardness
float flow
float height
float crease_pinch_factor
char mask_tool
char sculpt_tool
int smooth_deform_type
float wet_mix
float wet_persistence
int deform_target
float plane_offset
int smear_deform_type
float tip_roundness
float autosmooth_factor
int paint_flags
Definition: BKE_ccg.h:48
int grid_size
Definition: BKE_ccg.h:56
int grid_area
Definition: BKE_ccg.h:58
float plane_dist[2]
Definition: sculpt.c:4992
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
struct KeyBlock * next
Definition: DNA_key_types.h:41
short relative
Definition: DNA_key_types.h:57
ListBase block
KeyBlock * refkey
Definition: DNA_key_types.h:88
void * first
Definition: DNA_listBase.h:47
unsigned int v1
unsigned int v2
unsigned char a
unsigned char b
unsigned char r
unsigned char g
unsigned int e
unsigned int v
float color[4]
char brush_map_mode
float rot
float ofs[3]
float size[3]
struct Tex * tex
float co[3]
short no[3]
Definition: BKE_main.h:116
ListBase wm
Definition: BKE_main.h:175
struct MEdge * medge
struct CustomData pdata ldata
char symmetry
struct MVert * mvert
int totedge
int totvert
short flag
struct MLoop * mloop
int totpoly
int totloop
struct Key * key
struct MPoly * mpoly
struct Object * mirror_ob
struct ModifierData * next
float nearest_vertex_distance_squared
Definition: sculpt.c:961
int nearest_vertex_index
Definition: sculpt.c:960
struct BoundBox * bb
ListBase modifiers
float loc[3]
float scale[3]
float imat[4][4]
short shapenr
Object_Runtime runtime
float obmat[4][4]
struct SculptSession * sculpt
void * data
float(* co)[3]
Definition: BKE_pbvh.h:56
struct MVert * mvert
Definition: BKE_pbvh.h:372
short * no
Definition: BKE_pbvh.h:375
float * co
Definition: BKE_pbvh.h:374
float * fno
Definition: BKE_pbvh.h:376
float * col
Definition: BKE_pbvh.h:378
struct BMVert * bm_vert
Definition: BKE_pbvh.h:373
float * mask
Definition: BKE_pbvh.h:377
const int * vert_indices
Definition: BKE_pbvh.h:360
Brush * brush
Definition: paint_stroke.c:83
float tile_offset[3]
int symmetry_flags
float viewinv[4][4]
struct ToolSettings * toolsettings
struct RegionView3D * clip_rv3d
float plane_view[4]
float plane_tool[4]
float symm_rot_mat_inv[4][4]
float(* deformation_pos)[3]
Definition: BKE_paint.h:325
int * fake_neighbor_index
Definition: BKE_paint.h:443
float current_max_distance
Definition: BKE_paint.h:440
const float * ray_normal
Definition: sculpt.c:2898
SculptSession * ss
Definition: sculpt.c:2897
const float * ray_start
Definition: sculpt.c:2898
BLI_bitmap * visited_vertices
const float * co
short(* normals)[3]
struct SculptUndoNode * unode
struct BMLog * bm_log
const float * vmasks
const float * col
float(* colors)[4]
float(* coords)[3]
const short * no
float plane[3]
Definition: sculpt.c:1407
float len_sq_inv_neg
Definition: sculpt.c:1409
float follow_co[3]
int active_face_grid_index
Definition: sculpt.c:2891
const float * ray_normal
Definition: sculpt.c:2883
float * face_normal
Definition: sculpt.c:2889
int active_vertex_index
Definition: sculpt.c:2888
const float * ray_start
Definition: sculpt.c:2882
struct IsectRayPrecalc isect_precalc
Definition: sculpt.c:2893
SculptSession * ss
Definition: sculpt.c:2881
float cursor_normal[3]
Definition: BKE_paint.h:533
unsigned int texcache_side
Definition: BKE_paint.h:515
struct SubdivCCG * subdiv_ccg
Definition: BKE_paint.h:501
struct ImagePool * tex_pool
Definition: BKE_paint.h:516
float cursor_view_normal[3]
Definition: BKE_paint.h:535
int preview_vert_index_count
Definition: BKE_paint.h:550
SculptVertexInfo vertex_info
Definition: BKE_paint.h:563
float cursor_location[3]
Definition: BKE_paint.h:532
struct RegionView3D * rv3d
Definition: BKE_paint.h:544
float(* orig_cos)[3]
Definition: BKE_paint.h:510
int * face_sets
Definition: BKE_paint.h:490
float cursor_radius
Definition: BKE_paint.h:531
struct MVert * mvert
Definition: BKE_paint.h:461
struct MPropCol * vcol
Definition: BKE_paint.h:469
struct KeyBlock * shapekey_active
Definition: BKE_paint.h:468
struct BMesh * bm
Definition: BKE_paint.h:493
int * preview_vert_index_list
Definition: BKE_paint.h:549
int active_face_index
Definition: BKE_paint.h:525
struct BMLog * bm_log
Definition: BKE_paint.h:498
int active_vertex_index
Definition: BKE_paint.h:523
float * vmask
Definition: BKE_paint.h:470
struct MeshElemMap * pmap
Definition: BKE_paint.h:474
struct MLoop * mloop
Definition: BKE_paint.h:463
struct MPoly * mpoly
Definition: BKE_paint.h:462
eObjectMode mode_type
Definition: BKE_paint.h:600
struct MultiresModifierData * modifier
Definition: BKE_paint.h:453
float(* deform_imats)[3][3]
Definition: BKE_paint.h:512
float cursor_sampled_normal[3]
Definition: BKE_paint.h:534
struct StrokeCache * cache
Definition: BKE_paint.h:518
struct SculptSession::@53 multires
struct View3D * v3d
Definition: BKE_paint.h:545
float(* deform_cos)[3]
Definition: BKE_paint.h:511
unsigned int texcache_actual
Definition: BKE_paint.h:515
int active_grid_index
Definition: BKE_paint.h:526
SculptFakeNeighbors fake_neighbors
Definition: BKE_paint.h:564
unsigned int * texcache
Definition: BKE_paint.h:515
SculptPersistentBase * persistent_base
Definition: BKE_paint.h:561
struct PBVH * pbvh
Definition: BKE_paint.h:504
bool deform_modifiers_active
Definition: BKE_paint.h:509
struct Sculpt * sd
float nearest_vertex_search_co[3]
struct BMLogEntry * bm_entry
float(* co)[3]
short(* no)[3]
SculptUndoType type
int * connected_component
Definition: BKE_paint.h:355
BLI_bitmap * boundary
Definition: BKE_paint.h:358
int neighbors_fixed[SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY]
struct Object * gravity_object
float detail_percent
Paint paint
int radial_symm[3]
int symmetrize_direction
float detail_size
float gravity_factor
float constant_detail
float orig_grab_location[3]
float old_grab_location[3]
float true_location[3]
float initial_radius
float initial_mouse[2]
const struct Brush * brush
float sculpt_normal[3]
float brush_local_mat[4][4]
float special_rotation
float mouse[2]
float symm_rot_mat_inv[4][4]
float scale[3]
float plane_offset[3]
float initial_location[3]
float clip_mirror_mtx[4][4]
float true_view_normal[3]
float radius_squared
float projection_mat[4][4]
float last_location[3]
float anchored_location[3]
float clip_tolerance[3]
float initial_normal[3]
char saved_active_brush_name[MAX_ID_NAME]
int mirror_symmetry_pass
struct SculptPoseIKChain * pose_ik_chain
float view_normal[3]
struct SculptBoundary * boundaries[PAINT_SYMM_AREAS]
float rake_rotation[4]
struct ViewContext * vc
float sculpt_normal_symm[3]
float(* limit_surface_co)[3]
struct SculptRakeData rake_data
float(* surface_smooth_laplacian_disp)[3]
float true_initial_location[3]
float last_center[3]
float grab_delta_symmetry[3]
float location[3]
AutomaskingCache * automasking
struct SculptClothSimulation * cloth_sim
int radial_symmetry_pass
float true_last_location[3]
float true_initial_normal[3]
struct StrokeCache::@489 paint_brush
struct Dial * dial
float(* prev_displacement)[3]
bool is_rake_rotation_valid
float gravity_direction[3]
float plane_trim_squared
float normal_weight
float vertex_rotation
float(* detail_directions)[3]
float true_gravity_direction[3]
float mouse_event[2]
float * layer_displacement_factor
char saved_mask_brush_tool
float clay_pressure_stabilizer[SCULPT_CLAY_STABILIZER_LEN]
float(* prev_colors)[4]
int clay_pressure_stabilizer_index
float wet_persistence
float clay_thumb_front_angle
bool supports_gravity
float rake_rotation_symmetry[4]
float grab_delta[3]
float symm_rot_mat[4][4]
float dyntopo_pixel_radius
SubdivCCGCoord * coords
SubdivCCGCoord coords_fixed[256]
TaskParallelReduceFunc func_reduce
Definition: BLI_task.h:158
size_t userdata_chunk_size
Definition: BLI_task.h:150
short type
struct bNodeTree * nodetree
struct UnifiedPaintSettings unified_paint_settings
struct Depsgraph * depsgraph
Definition: ED_view3d.h:75
struct Scene * scene
Definition: ED_view3d.h:76
struct ARegion * region
Definition: ED_view3d.h:80
struct Object * obact
Definition: ED_view3d.h:78
struct View3D * v3d
Definition: ED_view3d.h:81
struct RegionView3D * rv3d
Definition: ED_view3d.h:83
struct bNodeTreeExec * execdata
ListBase areabase
int ymin
Definition: DNA_vec_types.h:80
int xmin
Definition: DNA_vec_types.h:79
int y
Definition: WM_types.h:581
int x
Definition: WM_types.h:581
short type
Definition: WM_types.h:577
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:768
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:760
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
struct UndoStack * undo_stack
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19
CCL_NAMESPACE_BEGIN ccl_device float fade(float t)
Definition: svm_noise.h:37
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
ccl_device_inline float dot(const float2 &a, const float2 &b)
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
uint len
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void WM_toolsystem_update_from_context_view3d(bContext *C)
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2372