Blender  V3.3
sculpt.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 by Nicholas Bishop. All rights reserved. */
3 
9 #include "MEM_guardedalloc.h"
10 
11 #include "BLI_blenlib.h"
12 #include "BLI_dial_2d.h"
13 #include "BLI_ghash.h"
14 #include "BLI_gsqueue.h"
15 #include "BLI_hash.h"
16 #include "BLI_math.h"
17 #include "BLI_math_color.h"
18 #include "BLI_math_color_blend.h"
19 #include "BLI_task.h"
20 #include "BLI_utildefines.h"
21 
22 #include "BLT_translation.h"
23 
24 #include "PIL_time.h"
25 
26 #include "DNA_brush_types.h"
27 #include "DNA_customdata_types.h"
28 #include "DNA_mesh_types.h"
29 #include "DNA_meshdata_types.h"
30 #include "DNA_node_types.h"
31 #include "DNA_object_types.h"
32 #include "DNA_scene_types.h"
33 
34 #include "BKE_attribute.h"
35 #include "BKE_brush.h"
36 #include "BKE_ccg.h"
37 #include "BKE_colortools.h"
38 #include "BKE_context.h"
39 #include "BKE_image.h"
40 #include "BKE_kelvinlet.h"
41 #include "BKE_key.h"
42 #include "BKE_lib_id.h"
43 #include "BKE_main.h"
44 #include "BKE_mesh.h"
45 #include "BKE_mesh_mapping.h"
46 #include "BKE_mesh_mirror.h"
47 #include "BKE_modifier.h"
48 #include "BKE_multires.h"
49 #include "BKE_node.h"
50 #include "BKE_object.h"
51 #include "BKE_paint.h"
52 #include "BKE_particle.h"
53 #include "BKE_pbvh.h"
54 #include "BKE_pointcache.h"
55 #include "BKE_report.h"
56 #include "BKE_scene.h"
57 #include "BKE_screen.h"
58 #include "BKE_subdiv_ccg.h"
59 #include "BKE_subsurf.h"
60 
61 #include "NOD_texture.h"
62 
63 #include "DEG_depsgraph.h"
64 
65 #include "IMB_colormanagement.h"
66 
67 #include "WM_api.h"
68 #include "WM_message.h"
69 #include "WM_toolsystem.h"
70 #include "WM_types.h"
71 
72 #include "ED_object.h"
73 #include "ED_paint.h"
74 #include "ED_screen.h"
75 #include "ED_sculpt.h"
76 #include "ED_view3d.h"
77 #include "paint_intern.h"
78 #include "sculpt_intern.h"
79 
80 #include "RNA_access.h"
81 #include "RNA_define.h"
82 
83 #include "UI_interface.h"
84 #include "UI_resources.h"
85 
86 #include "bmesh.h"
87 #include "bmesh_tools.h"
88 
89 #include <math.h>
90 #include <stdlib.h>
91 #include <string.h>
92 
93 /* -------------------------------------------------------------------- */
104 {
105  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
108  }
109 }
110 
112 {
113  switch (BKE_pbvh_type(ss->pbvh)) {
114  case PBVH_FACES:
115  return ss->totvert;
116  case PBVH_BMESH:
118  case PBVH_GRIDS:
120  }
121 
122  return 0;
123 }
124 
125 const float *SCULPT_vertex_co_get(SculptSession *ss, int index)
126 {
127  switch (BKE_pbvh_type(ss->pbvh)) {
128  case PBVH_FACES: {
129  if (ss->shapekey_active || ss->deform_modifiers_active) {
130  const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
131  return mverts[index].co;
132  }
133  return ss->mvert[index].co;
134  }
135  case PBVH_BMESH:
136  return BM_vert_at_index(BKE_pbvh_get_bmesh(ss->pbvh), index)->co;
137  case PBVH_GRIDS: {
138  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
139  const int grid_index = index / key->grid_area;
140  const int vertex_index = index - grid_index * key->grid_area;
141  CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index];
142  return CCG_elem_co(key, CCG_elem_offset(key, elem, vertex_index));
143  }
144  }
145  return NULL;
146 }
147 
149 {
152 
153  return layer && BKE_id_attribute_domain(&me->id, layer) == ATTR_DOMAIN_CORNER;
154 }
155 
157 {
158  return ss->vcol || ss->mcol;
159 }
160 
161 void SCULPT_vertex_color_get(const SculptSession *ss, int index, float r_color[4])
162 {
163  BKE_pbvh_vertex_color_get(ss->pbvh, index, r_color);
164 }
165 
166 void SCULPT_vertex_color_set(SculptSession *ss, int index, const float color[4])
167 {
168  BKE_pbvh_vertex_color_set(ss->pbvh, index, color);
169 }
170 
171 void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3])
172 {
173  switch (BKE_pbvh_type(ss->pbvh)) {
174  case PBVH_FACES: {
175  const float(*vert_normals)[3] = BKE_pbvh_get_vert_normals(ss->pbvh);
176  copy_v3_v3(no, vert_normals[index]);
177  break;
178  }
179  case PBVH_BMESH:
181  break;
182  case PBVH_GRIDS: {
183  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
184  const int grid_index = index / key->grid_area;
185  const int vertex_index = index - grid_index * key->grid_area;
186  CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index];
187  copy_v3_v3(no, CCG_elem_no(key, CCG_elem_offset(key, elem, vertex_index)));
188  break;
189  }
190  }
191 }
192 
193 const float *SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
194 {
195  if (ss->persistent_base) {
196  return ss->persistent_base[index].co;
197  }
198  return SCULPT_vertex_co_get(ss, index);
199 }
200 
202 {
203  /* Always grab active shape key if the sculpt happens on shapekey. */
204  if (ss->shapekey_active) {
205  const MVert *mverts = BKE_pbvh_get_verts(ss->pbvh);
206  return mverts[index].co;
207  }
208 
209  /* Sculpting on the base mesh. */
210  if (ss->mvert) {
211  return ss->mvert[index].co;
212  }
213 
214  /* Everything else, such as sculpting on multires. */
215  return SCULPT_vertex_co_get(ss, index);
216 }
217 
218 void SCULPT_vertex_limit_surface_get(SculptSession *ss, int index, float r_co[3])
219 {
220  switch (BKE_pbvh_type(ss->pbvh)) {
221  case PBVH_FACES:
222  case PBVH_BMESH:
223  copy_v3_v3(r_co, SCULPT_vertex_co_get(ss, index));
224  break;
225  case PBVH_GRIDS: {
226  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
227  const int grid_index = index / key->grid_area;
228  const int vertex_index = index - grid_index * key->grid_area;
229 
230  SubdivCCGCoord coord = {.grid_index = grid_index,
231  .x = vertex_index % key->grid_size,
232  .y = vertex_index / key->grid_size};
233  BKE_subdiv_ccg_eval_limit_point(ss->subdiv_ccg, &coord, r_co);
234  break;
235  }
236  }
237 }
238 
239 void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
240 {
241  if (ss->persistent_base) {
242  copy_v3_v3(no, ss->persistent_base[index].no);
243  return;
244  }
245  SCULPT_vertex_normal_get(ss, index, no);
246 }
247 
249 {
250  BMVert *v;
251  float *mask;
252  switch (BKE_pbvh_type(ss->pbvh)) {
253  case PBVH_FACES:
254  return ss->vmask[index];
255  case PBVH_BMESH:
256  v = BM_vert_at_index(BKE_pbvh_get_bmesh(ss->pbvh), index);
258  return *mask;
259  case PBVH_GRIDS: {
260  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
261  const int grid_index = index / key->grid_area;
262  const int vertex_index = index - grid_index * key->grid_area;
263  CCGElem *elem = BKE_pbvh_get_grids(ss->pbvh)[grid_index];
264  return *CCG_elem_mask(key, CCG_elem_offset(key, elem, vertex_index));
265  }
266  }
267 
268  return 0.0f;
269 }
270 
272 {
274  return ss->active_vertex_index;
275  }
276  return 0;
277 }
278 
280 {
282 }
283 
285 {
287 }
288 
290 {
291  switch (BKE_pbvh_type(ss->pbvh)) {
292  case PBVH_FACES:
293  if (ss->shapekey_active || ss->deform_modifiers_active) {
294  return BKE_pbvh_get_verts(ss->pbvh);
295  }
296  return ss->mvert;
297  case PBVH_BMESH:
298  case PBVH_GRIDS:
299  return NULL;
300  }
301  return NULL;
302 }
303 
305  const int deform_target,
306  PBVHVertexIter *iter)
307 {
308  switch (deform_target) {
310  return iter->co;
312  return ss->cache->cloth_sim->deformation_pos[iter->index];
313  }
314  return iter->co;
315 }
316 
318 {
319  const Mesh *mesh = BKE_mesh_from_object(object);
320  return mesh->symmetry;
321 }
322 
323 /* Sculpt Face Sets and Visibility. */
324 
326 {
327  switch (BKE_pbvh_type(ss->pbvh)) {
328  case PBVH_FACES:
329  return ss->face_sets[ss->active_face_index];
330  case PBVH_GRIDS: {
331  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg,
332  ss->active_grid_index);
333  return ss->face_sets[face_index];
334  }
335  case PBVH_BMESH:
336  return SCULPT_FACE_SET_NONE;
337  }
338  return SCULPT_FACE_SET_NONE;
339 }
340 
341 void SCULPT_vertex_visible_set(SculptSession *ss, int index, bool visible)
342 {
343  switch (BKE_pbvh_type(ss->pbvh)) {
344  case PBVH_FACES:
345  SET_FLAG_FROM_TEST(ss->mvert[index].flag, !visible, ME_HIDE);
347  break;
348  case PBVH_BMESH:
349  BM_elem_flag_set(BM_vert_at_index(ss->bm, index), BM_ELEM_HIDDEN, !visible);
350  break;
351  case PBVH_GRIDS:
352  break;
353  }
354 }
355 
357 {
358  switch (BKE_pbvh_type(ss->pbvh)) {
359  case PBVH_FACES:
360  return !(ss->mvert[index].flag & ME_HIDE);
361  case PBVH_BMESH:
362  return !BM_elem_flag_test(BM_vert_at_index(ss->bm, index), BM_ELEM_HIDDEN);
363  case PBVH_GRIDS: {
364  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
365  const int grid_index = index / key->grid_area;
366  const int vertex_index = index - grid_index * key->grid_area;
367  BLI_bitmap **grid_hidden = BKE_pbvh_get_grid_visibility(ss->pbvh);
368  if (grid_hidden && grid_hidden[grid_index]) {
369  return !BLI_BITMAP_TEST(grid_hidden[grid_index], vertex_index);
370  }
371  }
372  }
373  return true;
374 }
375 
376 void SCULPT_face_set_visibility_set(SculptSession *ss, int face_set, bool visible)
377 {
378  switch (BKE_pbvh_type(ss->pbvh)) {
379  case PBVH_FACES:
380  case PBVH_GRIDS:
381  for (int i = 0; i < ss->totfaces; i++) {
382  if (abs(ss->face_sets[i]) != face_set) {
383  continue;
384  }
385  if (visible) {
386  ss->face_sets[i] = abs(ss->face_sets[i]);
387  }
388  else {
389  ss->face_sets[i] = -abs(ss->face_sets[i]);
390  }
391  }
392  break;
393  case PBVH_BMESH:
394  break;
395  }
396 }
397 
399 {
400  switch (BKE_pbvh_type(ss->pbvh)) {
401  case PBVH_FACES:
402  case PBVH_GRIDS:
403  for (int i = 0; i < ss->totfaces; i++) {
404  ss->face_sets[i] *= -1;
405  }
406  break;
407  case PBVH_BMESH:
408  break;
409  }
410 }
411 
413 {
414  switch (BKE_pbvh_type(ss->pbvh)) {
415  case PBVH_FACES:
416  case PBVH_GRIDS:
417  for (int i = 0; i < ss->totfaces; i++) {
418 
419  /* This can run on geometry without a face set assigned, so its ID sign can't be changed to
420  * modify the visibility. Force that geometry to the ID 1 to enable changing the visibility
421  * here. */
422  if (ss->face_sets[i] == SCULPT_FACE_SET_NONE) {
423  ss->face_sets[i] = 1;
424  }
425 
426  if (visible) {
427  ss->face_sets[i] = abs(ss->face_sets[i]);
428  }
429  else {
430  ss->face_sets[i] = -abs(ss->face_sets[i]);
431  }
432  }
433  break;
434  case PBVH_BMESH:
435  break;
436  }
437 }
438 
440 {
441  switch (BKE_pbvh_type(ss->pbvh)) {
442  case PBVH_FACES: {
443  MeshElemMap *vert_map = &ss->pmap[index];
444  for (int j = 0; j < ss->pmap[index].count; j++) {
445  if (ss->face_sets[vert_map->indices[j]] > 0) {
446  return true;
447  }
448  }
449  return false;
450  }
451  case PBVH_BMESH:
452  return true;
453  case PBVH_GRIDS:
454  return true;
455  }
456  return true;
457 }
458 
460 {
461  switch (BKE_pbvh_type(ss->pbvh)) {
462  case PBVH_FACES: {
463  MeshElemMap *vert_map = &ss->pmap[index];
464  for (int j = 0; j < ss->pmap[index].count; j++) {
465  if (ss->face_sets[vert_map->indices[j]] < 0) {
466  return false;
467  }
468  }
469  return true;
470  }
471  case PBVH_BMESH:
472  return true;
473  case PBVH_GRIDS: {
474  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
475  const int grid_index = index / key->grid_area;
476  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
477  return ss->face_sets[face_index] > 0;
478  }
479  }
480  return true;
481 }
482 
483 void SCULPT_vertex_face_set_set(SculptSession *ss, int index, int face_set)
484 {
485  switch (BKE_pbvh_type(ss->pbvh)) {
486  case PBVH_FACES: {
487  MeshElemMap *vert_map = &ss->pmap[index];
488  for (int j = 0; j < ss->pmap[index].count; j++) {
489  if (ss->face_sets[vert_map->indices[j]] > 0) {
490  ss->face_sets[vert_map->indices[j]] = abs(face_set);
491  }
492  }
493  } break;
494  case PBVH_BMESH:
495  break;
496  case PBVH_GRIDS: {
497  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
498  const int grid_index = index / key->grid_area;
499  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
500  if (ss->face_sets[face_index] > 0) {
501  ss->face_sets[face_index] = abs(face_set);
502  }
503 
504  } break;
505  }
506 }
507 
509 {
510  switch (BKE_pbvh_type(ss->pbvh)) {
511  case PBVH_FACES: {
512  MeshElemMap *vert_map = &ss->pmap[index];
513  int face_set = 0;
514  for (int i = 0; i < ss->pmap[index].count; i++) {
515  if (ss->face_sets[vert_map->indices[i]] > face_set) {
516  face_set = abs(ss->face_sets[vert_map->indices[i]]);
517  }
518  }
519  return face_set;
520  }
521  case PBVH_BMESH:
522  return 0;
523  case PBVH_GRIDS: {
524  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
525  const int grid_index = index / key->grid_area;
526  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
527  return ss->face_sets[face_index];
528  }
529  }
530  return 0;
531 }
532 
533 bool SCULPT_vertex_has_face_set(SculptSession *ss, int index, int face_set)
534 {
535  switch (BKE_pbvh_type(ss->pbvh)) {
536  case PBVH_FACES: {
537  MeshElemMap *vert_map = &ss->pmap[index];
538  for (int i = 0; i < ss->pmap[index].count; i++) {
539  if (ss->face_sets[vert_map->indices[i]] == face_set) {
540  return true;
541  }
542  }
543  return false;
544  }
545  case PBVH_BMESH:
546  return true;
547  case PBVH_GRIDS: {
548  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
549  const int grid_index = index / key->grid_area;
550  const int face_index = BKE_subdiv_ccg_grid_to_face_index(ss->subdiv_ccg, grid_index);
551  return ss->face_sets[face_index] == face_set;
552  }
553  }
554  return true;
555 }
556 
558 {
559  SculptSession *ss = ob->sculpt;
561  switch (BKE_pbvh_type(ss->pbvh)) {
562  case PBVH_FACES: {
564  break;
565  }
566  case PBVH_GRIDS: {
569  break;
570  }
571  case PBVH_BMESH:
572  break;
573  }
574 }
575 
577  int index)
578 {
579  MeshElemMap *vert_map = &ss->pmap[index];
580  const bool visible = SCULPT_vertex_visible_get(ss, index);
581  for (int i = 0; i < ss->pmap[index].count; i++) {
582  if (visible) {
583  ss->face_sets[vert_map->indices[i]] = abs(ss->face_sets[vert_map->indices[i]]);
584  }
585  else {
586  ss->face_sets[vert_map->indices[i]] = -abs(ss->face_sets[vert_map->indices[i]]);
587  }
588  }
589 }
590 
592 {
593  if (BKE_pbvh_type(ss->pbvh) == PBVH_FACES) {
594  for (int i = 0; i < ss->totfaces; i++) {
595  MPoly *poly = &ss->mpoly[i];
596  bool poly_visible = true;
597  for (int l = 0; l < poly->totloop; l++) {
598  MLoop *loop = &ss->mloop[poly->loopstart + l];
599  if (!SCULPT_vertex_visible_get(ss, (int)loop->v)) {
600  poly_visible = false;
601  }
602  }
603  if (poly_visible) {
604  ss->face_sets[i] = abs(ss->face_sets[i]);
605  }
606  else {
607  ss->face_sets[i] = -abs(ss->face_sets[i]);
608  }
609  }
610  }
611 }
612 
614 {
615  MeshElemMap *vert_map = &ss->pmap[index];
616  int face_set = -1;
617  for (int i = 0; i < ss->pmap[index].count; i++) {
618  if (face_set == -1) {
619  face_set = abs(ss->face_sets[vert_map->indices[i]]);
620  }
621  else {
622  if (abs(ss->face_sets[vert_map->indices[i]]) != face_set) {
623  return false;
624  }
625  }
626  }
627  return true;
628 }
629 
635 {
636  MeshElemMap *vert_map = &ss->pmap[v1];
637  int p1 = -1, p2 = -1;
638  for (int i = 0; i < ss->pmap[v1].count; i++) {
639  MPoly *p = &ss->mpoly[vert_map->indices[i]];
640  for (int l = 0; l < p->totloop; l++) {
641  MLoop *loop = &ss->mloop[p->loopstart + l];
642  if (loop->v == v2) {
643  if (p1 == -1) {
644  p1 = vert_map->indices[i];
645  break;
646  }
647 
648  if (p2 == -1) {
649  p2 = vert_map->indices[i];
650  break;
651  }
652  }
653  }
654  }
655 
656  if (p1 != -1 && p2 != -1) {
657  return abs(ss->face_sets[p1]) == (ss->face_sets[p2]);
658  }
659  return true;
660 }
661 
663 {
664  switch (BKE_pbvh_type(ss->pbvh)) {
665  case PBVH_FACES: {
667  }
668  case PBVH_BMESH:
669  return true;
670  case PBVH_GRIDS: {
671  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
672  const int grid_index = index / key->grid_area;
673  const int vertex_index = index - grid_index * key->grid_area;
674  const SubdivCCGCoord coord = {.grid_index = grid_index,
675  .x = vertex_index % key->grid_size,
676  .y = vertex_index / key->grid_size};
677  int v1, v2;
679  ss->subdiv_ccg, &coord, ss->mloop, ss->mpoly, &v1, &v2);
680  switch (adjacency) {
686  return true;
687  }
688  }
689  }
690  return false;
691 }
692 
694 {
695  switch (BKE_pbvh_type(ss->pbvh)) {
696  case PBVH_FACES:
697  case PBVH_GRIDS: {
698  int next_face_set = 0;
699  for (int i = 0; i < ss->totfaces; i++) {
700  if (abs(ss->face_sets[i]) > next_face_set) {
701  next_face_set = abs(ss->face_sets[i]);
702  }
703  }
704  next_face_set++;
705  return next_face_set;
706  }
707  case PBVH_BMESH:
708  return 0;
709  }
710  return 0;
711 }
712 
713 /* Sculpt Neighbor Iterators */
714 
715 #define SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY 256
716 
717 static void sculpt_vertex_neighbor_add(SculptVertexNeighborIter *iter, int neighbor_index)
718 {
719  for (int i = 0; i < iter->size; i++) {
720  if (iter->neighbors[i] == neighbor_index) {
721  return;
722  }
723  }
724 
725  if (iter->size >= iter->capacity) {
727 
728  if (iter->neighbors == iter->neighbors_fixed) {
729  iter->neighbors = MEM_mallocN(iter->capacity * sizeof(int), "neighbor array");
730  memcpy(iter->neighbors, iter->neighbors_fixed, sizeof(int) * iter->size);
731  }
732  else {
733  iter->neighbors = MEM_reallocN_id(
734  iter->neighbors, iter->capacity * sizeof(int), "neighbor array");
735  }
736  }
737 
738  iter->neighbors[iter->size] = neighbor_index;
739  iter->size++;
740 }
741 
743  int index,
745 {
746  BMVert *v = BM_vert_at_index(ss->bm, index);
747  BMIter liter;
748  BMLoop *l;
749  iter->size = 0;
750  iter->num_duplicates = 0;
752  iter->neighbors = iter->neighbors_fixed;
753 
754  BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
755  const BMVert *adj_v[2] = {l->prev->v, l->next->v};
756  for (int i = 0; i < ARRAY_SIZE(adj_v); i++) {
757  const BMVert *v_other = adj_v[i];
758  if (BM_elem_index_get(v_other) != (int)index) {
760  }
761  }
762  }
763 }
764 
766  int index,
768 {
769  MeshElemMap *vert_map = &ss->pmap[index];
770  iter->size = 0;
771  iter->num_duplicates = 0;
773  iter->neighbors = iter->neighbors_fixed;
774 
775  for (int i = 0; i < ss->pmap[index].count; i++) {
776  if (ss->face_sets[vert_map->indices[i]] < 0) {
777  /* Skip connectivity from hidden faces. */
778  continue;
779  }
780  const MPoly *p = &ss->mpoly[vert_map->indices[i]];
781  uint f_adj_v[2];
782  if (poly_get_adj_loops_from_vert(p, ss->mloop, index, f_adj_v) != -1) {
783  for (int j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
784  if (f_adj_v[j] != index) {
785  sculpt_vertex_neighbor_add(iter, f_adj_v[j]);
786  }
787  }
788  }
789  }
790 
795  }
796  }
797 }
798 
800  const int index,
801  const bool include_duplicates,
803 {
804  /* TODO: optimize this. We could fill #SculptVertexNeighborIter directly,
805  * maybe provide coordinate and mask pointers directly rather than converting
806  * back and forth between #CCGElem and global index. */
807  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
808  const int grid_index = index / key->grid_area;
809  const int vertex_index = index - grid_index * key->grid_area;
810 
811  SubdivCCGCoord coord = {.grid_index = grid_index,
812  .x = vertex_index % key->grid_size,
813  .y = vertex_index / key->grid_size};
814 
815  SubdivCCGNeighbors neighbors;
816  BKE_subdiv_ccg_neighbor_coords_get(ss->subdiv_ccg, &coord, include_duplicates, &neighbors);
817 
818  iter->size = 0;
819  iter->num_duplicates = neighbors.num_duplicates;
821  iter->neighbors = iter->neighbors_fixed;
822 
823  for (int i = 0; i < neighbors.size; i++) {
825  neighbors.coords[i].grid_index * key->grid_area +
826  neighbors.coords[i].y * key->grid_size + neighbors.coords[i].x);
827  }
828 
833  }
834  }
835 
836  if (neighbors.coords != neighbors.coords_fixed) {
837  MEM_freeN(neighbors.coords);
838  }
839 }
840 
842  const int index,
843  const bool include_duplicates,
845 {
846  switch (BKE_pbvh_type(ss->pbvh)) {
847  case PBVH_FACES:
848  sculpt_vertex_neighbors_get_faces(ss, index, iter);
849  return;
850  case PBVH_BMESH:
851  sculpt_vertex_neighbors_get_bmesh(ss, index, iter);
852  return;
853  case PBVH_GRIDS:
854  sculpt_vertex_neighbors_get_grids(ss, index, include_duplicates, iter);
855  return;
856  }
857 }
858 
859 static bool sculpt_check_boundary_vertex_in_base_mesh(const SculptSession *ss, const int index)
860 {
862  return BLI_BITMAP_TEST(ss->vertex_info.boundary, index);
863 }
864 
865 bool SCULPT_vertex_is_boundary(const SculptSession *ss, const int index)
866 {
867  switch (BKE_pbvh_type(ss->pbvh)) {
868  case PBVH_FACES: {
869  if (!SCULPT_vertex_all_face_sets_visible_get(ss, index)) {
870  return true;
871  }
873  }
874  case PBVH_BMESH: {
875  BMVert *v = BM_vert_at_index(ss->bm, index);
876  return BM_vert_is_boundary(v);
877  }
878 
879  case PBVH_GRIDS: {
880  const CCGKey *key = BKE_pbvh_get_grid_key(ss->pbvh);
881  const int grid_index = index / key->grid_area;
882  const int vertex_index = index - grid_index * key->grid_area;
883  const SubdivCCGCoord coord = {.grid_index = grid_index,
884  .x = vertex_index % key->grid_size,
885  .y = vertex_index / key->grid_size};
886  int v1, v2;
888  ss->subdiv_ccg, &coord, ss->mloop, ss->mpoly, &v1, &v2);
889  switch (adjacency) {
896  return false;
897  }
898  }
899  }
900 
901  return false;
902 }
903 
904 /* Utilities */
905 
907 {
908  return cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0 &&
909  cache->tile_pass == 0;
910 }
911 
913 {
914  return cache->first_time && cache->mirror_symmetry_pass == 0 &&
915  cache->radial_symmetry_pass == 0 && cache->tile_pass == 0;
916 }
917 
919 {
920  return cache->first_time;
921 }
922 
923 bool SCULPT_check_vertex_pivot_symmetry(const float vco[3], const float pco[3], const char symm)
924 {
925  bool is_in_symmetry_area = true;
926  for (int i = 0; i < 3; i++) {
927  char symm_it = 1 << i;
928  if (symm & symm_it) {
929  if (pco[i] == 0.0f) {
930  if (vco[i] > 0.0f) {
931  is_in_symmetry_area = false;
932  }
933  }
934  if (vco[i] * pco[i] < 0.0f) {
935  is_in_symmetry_area = false;
936  }
937  }
938  }
939  return is_in_symmetry_area;
940 }
941 
942 typedef struct NearestVertexTLSData {
946 
947 static void do_nearest_vertex_get_task_cb(void *__restrict userdata,
948  const int n,
949  const TaskParallelTLS *__restrict tls)
950 {
951  SculptThreadedTaskData *data = userdata;
952  SculptSession *ss = data->ob->sculpt;
953  NearestVertexTLSData *nvtd = tls->userdata_chunk;
954  PBVHVertexIter vd;
955 
956  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
957  float distance_squared = len_squared_v3v3(vd.co, data->nearest_vertex_search_co);
958  if (distance_squared < nvtd->nearest_vertex_distance_squared &&
959  distance_squared < data->max_distance_squared) {
960  nvtd->nearest_vertex_index = vd.index;
962  }
963  }
965 }
966 
967 static void nearest_vertex_get_reduce(const void *__restrict UNUSED(userdata),
968  void *__restrict chunk_join,
969  void *__restrict chunk)
970 {
971  NearestVertexTLSData *join = chunk_join;
972  NearestVertexTLSData *nvtd = chunk;
973  if (join->nearest_vertex_index == -1) {
976  }
980  }
981 }
982 
984  Sculpt *sd, Object *ob, const float co[3], float max_distance, bool use_original)
985 {
986  SculptSession *ss = ob->sculpt;
987  PBVHNode **nodes = NULL;
988  int totnode;
990  .ss = ss,
991  .sd = sd,
992  .radius_squared = max_distance * max_distance,
993  .original = use_original,
994  .center = co,
995  };
996  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
997  if (totnode == 0) {
998  return -1;
999  }
1000 
1001  SculptThreadedTaskData task_data = {
1002  .sd = sd,
1003  .ob = ob,
1004  .nodes = nodes,
1005  .max_distance_squared = max_distance * max_distance,
1006  };
1007 
1008  copy_v3_v3(task_data.nearest_vertex_search_co, co);
1009  NearestVertexTLSData nvtd;
1010  nvtd.nearest_vertex_index = -1;
1011  nvtd.nearest_vertex_distance_squared = FLT_MAX;
1012 
1013  TaskParallelSettings settings;
1014  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
1016  settings.userdata_chunk = &nvtd;
1017  settings.userdata_chunk_size = sizeof(NearestVertexTLSData);
1018  BLI_task_parallel_range(0, totnode, &task_data, do_nearest_vertex_get_task_cb, &settings);
1019 
1020  MEM_SAFE_FREE(nodes);
1021 
1022  return nvtd.nearest_vertex_index;
1023 }
1024 
1025 bool SCULPT_is_symmetry_iteration_valid(char i, char symm)
1026 {
1027  return i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || (!ELEM(i, 3, 5))));
1028 }
1029 
1031  const float br_co[3],
1032  float radius,
1033  char symm)
1034 {
1035  for (char i = 0; i <= symm; ++i) {
1036  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1037  continue;
1038  }
1039  float location[3];
1040  flip_v3_v3(location, br_co, (char)i);
1041  if (len_squared_v3v3(location, vertex) < radius * radius) {
1042  return true;
1043  }
1044  }
1045  return false;
1046 }
1047 
1049 {
1050  ARegion *region = CTX_wm_region(C);
1051  ED_region_tag_redraw(region);
1052 
1055 
1057 
1059  if (!BKE_sculptsession_use_pbvh_draw(ob, rv3d)) {
1061  }
1062 }
1063 
1066 /* -------------------------------------------------------------------- */
1073 {
1074  int vertex_count = SCULPT_vertex_count_get(ss);
1076 
1077  flood->queue = BLI_gsqueue_new(sizeof(int));
1078  flood->visited_vertices = BLI_BITMAP_NEW(vertex_count, "visited vertices");
1079 }
1080 
1082 {
1083  BLI_gsqueue_push(flood->queue, &index);
1084 }
1085 
1087 {
1088  BLI_gsqueue_push(flood->queue, &index);
1089  BLI_BITMAP_ENABLE(flood->visited_vertices, index);
1090 }
1091 
1093  Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, int index, float radius)
1094 {
1095  /* Add active vertex and symmetric vertices to the queue. */
1096  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
1097  for (char i = 0; i <= symm; ++i) {
1098  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1099  continue;
1100  }
1101  int v = -1;
1102  if (i == 0) {
1103  v = index;
1104  }
1105  else if (radius > 0.0f) {
1106  float radius_squared = (radius == FLT_MAX) ? FLT_MAX : radius * radius;
1107  float location[3];
1108  flip_v3_v3(location, SCULPT_vertex_co_get(ss, index), i);
1109  v = SCULPT_nearest_vertex_get(sd, ob, location, radius_squared, false);
1110  }
1111 
1112  if (v != -1) {
1114  }
1115  }
1116 }
1117 
1119  Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, float radius)
1120 {
1121  /* Add active vertex and symmetric vertices to the queue. */
1122  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
1123  for (char i = 0; i <= symm; ++i) {
1124  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1125  continue;
1126  }
1127  int v = -1;
1128  if (i == 0) {
1130  }
1131  else if (radius > 0.0f) {
1132  float location[3];
1133  flip_v3_v3(location, SCULPT_active_vertex_co_get(ss), i);
1134  v = SCULPT_nearest_vertex_get(sd, ob, location, radius, false);
1135  }
1136 
1137  if (v != -1) {
1139  }
1140  }
1141 }
1142 
1144  SculptSession *ss,
1145  SculptFloodFill *flood,
1146  bool (*func)(SculptSession *ss, int from_v, int to_v, bool is_duplicate, void *userdata),
1147  void *userdata)
1148 {
1149  while (!BLI_gsqueue_is_empty(flood->queue)) {
1150  int from_v;
1151  BLI_gsqueue_pop(flood->queue, &from_v);
1154  const int to_v = ni.index;
1155 
1156  if (BLI_BITMAP_TEST(flood->visited_vertices, to_v)) {
1157  continue;
1158  }
1159 
1160  if (!SCULPT_vertex_visible_get(ss, to_v)) {
1161  continue;
1162  }
1163 
1164  BLI_BITMAP_ENABLE(flood->visited_vertices, to_v);
1165 
1166  if (func(ss, from_v, to_v, ni.is_duplicate, userdata)) {
1167  BLI_gsqueue_push(flood->queue, &to_v);
1168  }
1169  }
1171  }
1172 }
1173 
1175 {
1177  BLI_gsqueue_free(flood->queue);
1178  flood->queue = NULL;
1179 }
1180 
1183 static bool sculpt_tool_has_cube_tip(const char sculpt_tool)
1184 {
1185  return ELEM(
1187 }
1188 
1189 /* -------------------------------------------------------------------- */
1196 static bool sculpt_tool_needs_original(const char sculpt_tool)
1197 {
1198  return ELEM(sculpt_tool,
1208 }
1209 
1210 static bool sculpt_tool_is_proxy_used(const char sculpt_tool)
1211 {
1212  return ELEM(sculpt_tool,
1222 }
1223 
1224 static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush *brush)
1225 {
1226  return SCULPT_TOOL_HAS_TOPOLOGY_RAKE(brush->sculpt_tool) &&
1227  (brush->topology_rake_factor > 0.0f) && (ss->bm != NULL);
1228 }
1229 
1233 static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush)
1234 {
1235  return ((SCULPT_TOOL_HAS_NORMAL_WEIGHT(brush->sculpt_tool) &&
1236  (ss->cache->normal_weight > 0.0f)) ||
1237 
1238  ELEM(brush->sculpt_tool,
1248  SCULPT_TOOL_THUMB) ||
1249 
1250  (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA)) ||
1251  sculpt_brush_use_topology_rake(ss, brush);
1252 }
1253 
1254 static bool sculpt_brush_needs_rake_rotation(const Brush *brush)
1255 {
1256  return SCULPT_TOOL_HAS_RAKE(brush->sculpt_tool) && (brush->rake_factor != 0.0f);
1257 }
1258 
1261 /* -------------------------------------------------------------------- */
1265 typedef enum StrokeFlags {
1266  CLIP_X = 1,
1267  CLIP_Y = 2,
1268  CLIP_Z = 4,
1270 
1272 {
1273  SculptSession *ss = ob->sculpt;
1274  BMesh *bm = ss->bm;
1275 
1276  memset(data, 0, sizeof(*data));
1277  data->unode = unode;
1278 
1279  if (bm) {
1280  data->bm_log = ss->bm_log;
1281  }
1282  else {
1283  data->coords = data->unode->co;
1284  data->normals = data->unode->no;
1285  data->vmasks = data->unode->mask;
1286  data->colors = data->unode->col;
1287  }
1288 }
1289 
1291  Object *ob,
1292  PBVHNode *node,
1294 {
1295  SculptUndoNode *unode;
1296  unode = SCULPT_undo_push_node(ob, node, type);
1298 }
1299 
1301 {
1302  if (orig_data->unode->type == SCULPT_UNDO_COORDS) {
1303  if (orig_data->bm_log) {
1304  BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co, &orig_data->no);
1305  }
1306  else {
1307  orig_data->co = orig_data->coords[iter->i];
1308  orig_data->no = orig_data->normals[iter->i];
1309  }
1310  }
1311  else if (orig_data->unode->type == SCULPT_UNDO_COLOR) {
1312  orig_data->col = orig_data->colors[iter->i];
1313  }
1314  else if (orig_data->unode->type == SCULPT_UNDO_MASK) {
1315  if (orig_data->bm_log) {
1316  orig_data->mask = BM_log_original_mask(orig_data->bm_log, iter->bm_vert);
1317  }
1318  else {
1319  orig_data->mask = orig_data->vmasks[iter->i];
1320  }
1321  }
1322 }
1323 
1324 static void sculpt_rake_data_update(struct SculptRakeData *srd, const float co[3])
1325 {
1326  float rake_dist = len_v3v3(srd->follow_co, co);
1327  if (rake_dist > srd->follow_dist) {
1328  interp_v3_v3v3(srd->follow_co, srd->follow_co, co, rake_dist - srd->follow_dist);
1329  }
1330 }
1331 
1334 /* -------------------------------------------------------------------- */
1339 {
1340  return ((BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) &&
1341 
1342  (!ss->cache || (!ss->cache->alt_smooth)) &&
1343 
1344  /* Requires mesh restore, which doesn't work with
1345  * dynamic-topology. */
1346  !(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) &&
1347 
1349 }
1350 
1353 /* -------------------------------------------------------------------- */
1357 static void paint_mesh_restore_co_task_cb(void *__restrict userdata,
1358  const int n,
1359  const TaskParallelTLS *__restrict UNUSED(tls))
1360 {
1361  SculptThreadedTaskData *data = userdata;
1362  SculptSession *ss = data->ob->sculpt;
1363 
1364  SculptUndoNode *unode;
1366 
1367  switch (data->brush->sculpt_tool) {
1368  case SCULPT_TOOL_MASK:
1370  break;
1371  case SCULPT_TOOL_PAINT:
1372  case SCULPT_TOOL_SMEAR:
1374  break;
1375  default:
1377  break;
1378  }
1379 
1380  if (ss->bm) {
1381  unode = SCULPT_undo_push_node(data->ob, data->nodes[n], type);
1382  }
1383  else {
1384  unode = SCULPT_undo_get_node(data->nodes[n], type);
1385  }
1386 
1387  if (!unode) {
1388  return;
1389  }
1390 
1391  switch (type) {
1392  case SCULPT_UNDO_MASK:
1394  break;
1395  case SCULPT_UNDO_COLOR:
1397  break;
1398  case SCULPT_UNDO_COORDS:
1399  BKE_pbvh_node_mark_update(data->nodes[n]);
1400  break;
1401  default:
1402  break;
1403  }
1404 
1405  PBVHVertexIter vd;
1406  SculptOrigVertData orig_data;
1407 
1408  SCULPT_orig_vert_data_unode_init(&orig_data, data->ob, unode);
1409 
1410  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
1411  SCULPT_orig_vert_data_update(&orig_data, &vd);
1412 
1413  if (orig_data.unode->type == SCULPT_UNDO_COORDS) {
1414  copy_v3_v3(vd.co, orig_data.co);
1415  if (vd.no) {
1416  copy_v3_v3(vd.no, orig_data.no);
1417  }
1418  else {
1419  copy_v3_v3(vd.fno, orig_data.no);
1420  }
1421  if (vd.mvert) {
1423  }
1424  }
1425  else if (orig_data.unode->type == SCULPT_UNDO_MASK) {
1426  *vd.mask = orig_data.mask;
1427  }
1428  else if (orig_data.unode->type == SCULPT_UNDO_COLOR) {
1429  SCULPT_vertex_color_set(ss, vd.index, orig_data.col);
1430  }
1431  }
1433 }
1434 
1435 static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
1436 {
1437  SculptSession *ss = ob->sculpt;
1438  Brush *brush = BKE_paint_brush(&sd->paint);
1439 
1440  PBVHNode **nodes;
1441  int totnode;
1442 
1443  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
1444 
1451  .sd = sd,
1452  .ob = ob,
1453  .brush = brush,
1454  .nodes = nodes,
1455  };
1456 
1457  TaskParallelSettings settings;
1458  BKE_pbvh_parallel_range_settings(&settings, true && !ss->bm, totnode);
1460 
1462 
1463  MEM_SAFE_FREE(nodes);
1464 }
1465 
1466 /*** BVH Tree ***/
1467 
1469 {
1470  /* Expand redraw \a rect with redraw \a rect from previous step to
1471  * prevent partial-redraw issues caused by fast strokes. This is
1472  * needed here (not in sculpt_flush_update) as it was before
1473  * because redraw rectangle should be the same in both of
1474  * optimized PBVH draw function and 3d view redraw, if not -- some
1475  * mesh parts could disappear from screen (sergey). */
1476  SculptSession *ss = ob->sculpt;
1477 
1478  if (!ss->cache) {
1479  return;
1480  }
1481 
1482  if (BLI_rcti_is_empty(&ss->cache->previous_r)) {
1483  return;
1484  }
1485 
1486  BLI_rcti_union(rect, &ss->cache->previous_r);
1487 }
1488 
1489 bool SCULPT_get_redraw_rect(ARegion *region, RegionView3D *rv3d, Object *ob, rcti *rect)
1490 {
1491  PBVH *pbvh = ob->sculpt->pbvh;
1492  float bb_min[3], bb_max[3];
1493 
1494  if (!pbvh) {
1495  return false;
1496  }
1497 
1498  BKE_pbvh_redraw_BB(pbvh, bb_min, bb_max);
1499 
1500  /* Convert 3D bounding box to screen space. */
1501  if (!paint_convert_bb_to_rect(rect, bb_min, bb_max, region, rv3d, ob)) {
1502  return false;
1503  }
1504 
1505  return true;
1506 }
1507 
1508 void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *region, Object *ob)
1509 {
1510  PBVH *pbvh = ob->sculpt->pbvh;
1511  /* Copy here, original will be used below. */
1512  rcti rect = ob->sculpt->cache->current_r;
1513 
1515 
1516  paint_calc_redraw_planes(planes, region, ob, &rect);
1517 
1518  /* We will draw this \a rect, so now we can set it as the previous partial \a rect.
1519  * Note that we don't update with the union of previous/current (\a rect), only with
1520  * the current. Thus we avoid the rectangle needlessly growing to include
1521  * all the stroke area. */
1522  ob->sculpt->cache->previous_r = ob->sculpt->cache->current_r;
1523 
1524  /* Clear redraw flag from nodes. */
1525  if (pbvh) {
1527  }
1528 }
1529 
1530 /************************ Brush Testing *******************/
1531 
1533 {
1534  RegionView3D *rv3d = ss->cache ? ss->cache->vc->rv3d : ss->rv3d;
1535  View3D *v3d = ss->cache ? ss->cache->vc->v3d : ss->v3d;
1536 
1537  test->radius_squared = ss->cache ? ss->cache->radius_squared :
1538  ss->cursor_radius * ss->cursor_radius;
1539  test->radius = sqrtf(test->radius_squared);
1540 
1541  if (ss->cache) {
1542  copy_v3_v3(test->location, ss->cache->location);
1546  }
1547  else {
1548  copy_v3_v3(test->location, ss->cursor_location);
1549  test->mirror_symmetry_pass = 0;
1550  test->radial_symmetry_pass = 0;
1551  unit_m4(test->symm_rot_mat_inv);
1552  }
1553 
1554  /* Just for initialize. */
1555  test->dist = 0.0f;
1556 
1557  /* Only for 2D projection. */
1558  zero_v4(test->plane_view);
1559  zero_v4(test->plane_tool);
1560 
1561  if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
1562  test->clip_rv3d = rv3d;
1563  }
1564  else {
1565  test->clip_rv3d = NULL;
1566  }
1567 }
1568 
1569 BLI_INLINE bool sculpt_brush_test_clipping(const SculptBrushTest *test, const float co[3])
1570 {
1571  RegionView3D *rv3d = test->clip_rv3d;
1572  if (!rv3d) {
1573  return false;
1574  }
1575  float symm_co[3];
1576  flip_v3_v3(symm_co, co, test->mirror_symmetry_pass);
1577  if (test->radial_symmetry_pass) {
1578  mul_m4_v3(test->symm_rot_mat_inv, symm_co);
1579  }
1580  return ED_view3d_clipping_test(rv3d, symm_co, true);
1581 }
1582 
1583 bool SCULPT_brush_test_sphere(SculptBrushTest *test, const float co[3])
1584 {
1585  float distsq = len_squared_v3v3(co, test->location);
1586 
1587  if (distsq > test->radius_squared) {
1588  return false;
1589  }
1590 
1591  if (sculpt_brush_test_clipping(test, co)) {
1592  return false;
1593  }
1594 
1595  test->dist = sqrtf(distsq);
1596  return true;
1597 }
1598 
1599 bool SCULPT_brush_test_sphere_sq(SculptBrushTest *test, const float co[3])
1600 {
1601  float distsq = len_squared_v3v3(co, test->location);
1602 
1603  if (distsq > test->radius_squared) {
1604  return false;
1605  }
1606  if (sculpt_brush_test_clipping(test, co)) {
1607  return false;
1608  }
1609  test->dist = distsq;
1610  return true;
1611 }
1612 
1613 bool SCULPT_brush_test_sphere_fast(const SculptBrushTest *test, const float co[3])
1614 {
1615  if (sculpt_brush_test_clipping(test, co)) {
1616  return false;
1617  }
1618  return len_squared_v3v3(co, test->location) <= test->radius_squared;
1619 }
1620 
1621 bool SCULPT_brush_test_circle_sq(SculptBrushTest *test, const float co[3])
1622 {
1623  float co_proj[3];
1624  closest_to_plane_normalized_v3(co_proj, test->plane_view, co);
1625  float distsq = len_squared_v3v3(co_proj, test->location);
1626 
1627  if (distsq > test->radius_squared) {
1628  return false;
1629  }
1630 
1631  if (sculpt_brush_test_clipping(test, co)) {
1632  return false;
1633  }
1634 
1635  test->dist = distsq;
1636  return true;
1637 }
1638 
1640  const float co[3],
1641  const float local[4][4],
1642  const float roundness)
1643 {
1644  float side = 1.0f;
1645  float local_co[3];
1646 
1647  if (sculpt_brush_test_clipping(test, co)) {
1648  return false;
1649  }
1650 
1651  mul_v3_m4v3(local_co, local, co);
1652 
1653  local_co[0] = fabsf(local_co[0]);
1654  local_co[1] = fabsf(local_co[1]);
1655  local_co[2] = fabsf(local_co[2]);
1656 
1657  /* Keep the square and circular brush tips the same size. */
1658  side += (1.0f - side) * roundness;
1659 
1660  const float hardness = 1.0f - roundness;
1661  const float constant_side = hardness * side;
1662  const float falloff_side = roundness * side;
1663 
1664  if (!(local_co[0] <= side && local_co[1] <= side && local_co[2] <= side)) {
1665  /* Outside the square. */
1666  return false;
1667  }
1668  if (min_ff(local_co[0], local_co[1]) > constant_side) {
1669  /* Corner, distance to the center of the corner circle. */
1670  float r_point[3];
1671  copy_v3_fl(r_point, constant_side);
1672  test->dist = len_v2v2(r_point, local_co) / falloff_side;
1673  return true;
1674  }
1675  if (max_ff(local_co[0], local_co[1]) > constant_side) {
1676  /* Side, distance to the square XY axis. */
1677  test->dist = (max_ff(local_co[0], local_co[1]) - constant_side) / falloff_side;
1678  return true;
1679  }
1680 
1681  /* Inside the square, constant distance. */
1682  test->dist = 0.0f;
1683  return true;
1684 }
1685 
1687  SculptBrushTest *test,
1688  char falloff_shape)
1689 {
1690  SCULPT_brush_test_init(ss, test);
1691  SculptBrushTestFn sculpt_brush_test_sq_fn;
1692  if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
1693  sculpt_brush_test_sq_fn = SCULPT_brush_test_sphere_sq;
1694  }
1695  else {
1696  /* PAINT_FALLOFF_SHAPE_TUBE */
1698  sculpt_brush_test_sq_fn = SCULPT_brush_test_circle_sq;
1699  }
1700  return sculpt_brush_test_sq_fn;
1701 }
1702 
1704  char falloff_shape)
1705 {
1706  if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
1707  return ss->cache->sculpt_normal_symm;
1708  }
1709  /* PAINT_FALLOFF_SHAPE_TUBE */
1710  return ss->cache->view_normal;
1711 }
1712 
1713 static float frontface(const Brush *br,
1714  const float sculpt_normal[3],
1715  const float no[3],
1716  const float fno[3])
1717 {
1718  if (!(br->flag & BRUSH_FRONTFACE)) {
1719  return 1.0f;
1720  }
1721 
1722  float dot;
1723  if (no) {
1724  dot = dot_v3v3(no, sculpt_normal);
1725  }
1726  else {
1727  dot = dot_v3v3(fno, sculpt_normal);
1728  }
1729  return dot > 0.0f ? dot : 0.0f;
1730 }
1731 
1732 #if 0
1733 
1734 static bool sculpt_brush_test_cyl(SculptBrushTest *test,
1735  float co[3],
1736  float location[3],
1737  const float area_no[3])
1738 {
1739  if (sculpt_brush_test_sphere_fast(test, co)) {
1740  float t1[3], t2[3], t3[3], dist;
1741 
1742  sub_v3_v3v3(t1, location, co);
1743  sub_v3_v3v3(t2, x2, location);
1744 
1745  cross_v3_v3v3(t3, area_no, t1);
1746 
1747  dist = len_v3(t3) / len_v3(t2);
1748 
1749  test->dist = dist;
1750 
1751  return true;
1752  }
1753 
1754  return false;
1755 }
1756 
1757 #endif
1758 
1759 /* ===== Sculpting =====
1760  */
1761 
1762 static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle)
1763 {
1764  float mirror[3];
1765  float distsq;
1766 
1767  flip_v3_v3(mirror, cache->true_location, symm);
1768 
1769  if (axis != 0) {
1770  float mat[3][3];
1771  axis_angle_to_mat3_single(mat, axis, angle);
1772  mul_m3_v3(mat, mirror);
1773  }
1774 
1775  distsq = len_squared_v3v3(mirror, cache->true_location);
1776 
1777  if (distsq <= 4.0f * (cache->radius_squared)) {
1778  return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache->radius));
1779  }
1780  return 0.0f;
1781 }
1782 
1784  StrokeCache *cache,
1785  const char symm,
1786  const char axis)
1787 {
1788  float overlap = 0.0f;
1789 
1790  for (int i = 1; i < sd->radial_symm[axis - 'X']; i++) {
1791  const float angle = 2.0f * M_PI * i / sd->radial_symm[axis - 'X'];
1792  overlap += calc_overlap(cache, symm, axis, angle);
1793  }
1794 
1795  return overlap;
1796 }
1797 
1798 static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
1799 {
1801  return 1.0f;
1802  }
1803  float overlap;
1804  const int symm = cache->symmetry;
1805 
1806  overlap = 0.0f;
1807  for (int i = 0; i <= symm; i++) {
1808  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
1809  continue;
1810  }
1811 
1812  overlap += calc_overlap(cache, i, 0, 0);
1813 
1814  overlap += calc_radial_symmetry_feather(sd, cache, i, 'X');
1815  overlap += calc_radial_symmetry_feather(sd, cache, i, 'Y');
1816  overlap += calc_radial_symmetry_feather(sd, cache, i, 'Z');
1817  }
1818  return 1.0f / overlap;
1819 }
1820 
1823 /* -------------------------------------------------------------------- */
1837 typedef struct AreaNormalCenterTLSData {
1838  /* 0 = towards view, 1 = flipped */
1839  float area_cos[2][3];
1840  float area_nos[2][3];
1841  int count_no[2];
1842  int count_co[2];
1844 
1845 static void calc_area_normal_and_center_task_cb(void *__restrict userdata,
1846  const int n,
1847  const TaskParallelTLS *__restrict tls)
1848 {
1849  SculptThreadedTaskData *data = userdata;
1850  SculptSession *ss = data->ob->sculpt;
1851  AreaNormalCenterTLSData *anctd = tls->userdata_chunk;
1852  const bool use_area_nos = data->use_area_nos;
1853  const bool use_area_cos = data->use_area_cos;
1854 
1855  PBVHVertexIter vd;
1856  SculptUndoNode *unode = NULL;
1857 
1858  bool use_original = false;
1859  bool normal_test_r, area_test_r;
1860 
1861  if (ss->cache && ss->cache->original) {
1862  unode = SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS);
1863  use_original = (unode->co || unode->bm_entry);
1864  }
1865 
1866  SculptBrushTest normal_test;
1867  SculptBrushTestFn sculpt_brush_normal_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
1868  ss, &normal_test, data->brush->falloff_shape);
1869 
1870  /* Update the test radius to sample the normal using the normal radius of the brush. */
1871  if (data->brush->ob_mode == OB_MODE_SCULPT) {
1872  float test_radius = sqrtf(normal_test.radius_squared);
1873  test_radius *= data->brush->normal_radius_factor;
1874  normal_test.radius = test_radius;
1875  normal_test.radius_squared = test_radius * test_radius;
1876  }
1877 
1878  SculptBrushTest area_test;
1879  SculptBrushTestFn sculpt_brush_area_test_sq_fn = SCULPT_brush_test_init_with_falloff_shape(
1880  ss, &area_test, data->brush->falloff_shape);
1881 
1882  if (data->brush->ob_mode == OB_MODE_SCULPT) {
1883  float test_radius = sqrtf(area_test.radius_squared);
1884  /* Layer brush produces artifacts with normal and area radius */
1885  /* Enable area radius control only on Scrape for now */
1886  if (ELEM(data->brush->sculpt_tool, SCULPT_TOOL_SCRAPE, SCULPT_TOOL_FILL) &&
1887  data->brush->area_radius_factor > 0.0f) {
1888  test_radius *= data->brush->area_radius_factor;
1889  if (ss->cache && data->brush->flag2 & BRUSH_AREA_RADIUS_PRESSURE) {
1890  test_radius *= ss->cache->pressure;
1891  }
1892  }
1893  else {
1894  test_radius *= data->brush->normal_radius_factor;
1895  }
1896  area_test.radius = test_radius;
1897  area_test.radius_squared = test_radius * test_radius;
1898  }
1899 
1900  /* When the mesh is edited we can't rely on original coords
1901  * (original mesh may not even have verts in brush radius). */
1902  if (use_original && data->has_bm_orco) {
1903  float(*orco_coords)[3];
1904  int(*orco_tris)[3];
1905  int orco_tris_num;
1906 
1907  BKE_pbvh_node_get_bm_orco_data(data->nodes[n], &orco_tris, &orco_tris_num, &orco_coords);
1908 
1909  for (int i = 0; i < orco_tris_num; i++) {
1910  const float *co_tri[3] = {
1911  orco_coords[orco_tris[i][0]],
1912  orco_coords[orco_tris[i][1]],
1913  orco_coords[orco_tris[i][2]],
1914  };
1915  float co[3];
1916 
1917  closest_on_tri_to_point_v3(co, normal_test.location, UNPACK3(co_tri));
1918 
1919  normal_test_r = sculpt_brush_normal_test_sq_fn(&normal_test, co);
1920  area_test_r = sculpt_brush_area_test_sq_fn(&area_test, co);
1921 
1922  if (!normal_test_r && !area_test_r) {
1923  continue;
1924  }
1925 
1926  float no[3];
1927  int flip_index;
1928 
1929  normal_tri_v3(no, UNPACK3(co_tri));
1930 
1931  flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f);
1932  if (use_area_cos && area_test_r) {
1933  /* Weight the coordinates towards the center. */
1934  float p = 1.0f - (sqrtf(area_test.dist) / area_test.radius);
1935  const float afactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
1936 
1937  float disp[3];
1938  sub_v3_v3v3(disp, co, area_test.location);
1939  mul_v3_fl(disp, 1.0f - afactor);
1940  add_v3_v3v3(co, area_test.location, disp);
1941  add_v3_v3(anctd->area_cos[flip_index], co);
1942 
1943  anctd->count_co[flip_index] += 1;
1944  }
1945  if (use_area_nos && normal_test_r) {
1946  /* Weight the normals towards the center. */
1947  float p = 1.0f - (sqrtf(normal_test.dist) / normal_test.radius);
1948  const float nfactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
1949  mul_v3_fl(no, nfactor);
1950 
1951  add_v3_v3(anctd->area_nos[flip_index], no);
1952  anctd->count_no[flip_index] += 1;
1953  }
1954  }
1955  }
1956  else {
1957  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
1958  float co[3];
1959 
1960  /* For bm_vert only. */
1961  float no_s[3];
1962 
1963  if (use_original) {
1964  if (unode->bm_entry) {
1965  const float *temp_co;
1966  const float *temp_no_s;
1967  BM_log_original_vert_data(ss->bm_log, vd.bm_vert, &temp_co, &temp_no_s);
1968  copy_v3_v3(co, temp_co);
1969  copy_v3_v3(no_s, temp_no_s);
1970  }
1971  else {
1972  copy_v3_v3(co, unode->co[vd.i]);
1973  copy_v3_v3(no_s, unode->no[vd.i]);
1974  }
1975  }
1976  else {
1977  copy_v3_v3(co, vd.co);
1978  }
1979 
1980  normal_test_r = sculpt_brush_normal_test_sq_fn(&normal_test, co);
1981  area_test_r = sculpt_brush_area_test_sq_fn(&area_test, co);
1982 
1983  if (!normal_test_r && !area_test_r) {
1984  continue;
1985  }
1986 
1987  float no[3];
1988  int flip_index;
1989 
1990  data->any_vertex_sampled = true;
1991 
1992  if (use_original) {
1993  copy_v3_v3(no, no_s);
1994  }
1995  else {
1996  if (vd.no) {
1997  copy_v3_v3(no, vd.no);
1998  }
1999  else {
2000  copy_v3_v3(no, vd.fno);
2001  }
2002  }
2003 
2004  flip_index = (dot_v3v3(ss->cache ? ss->cache->view_normal : ss->cursor_view_normal, no) <=
2005  0.0f);
2006 
2007  if (use_area_cos && area_test_r) {
2008  /* Weight the coordinates towards the center. */
2009  float p = 1.0f - (sqrtf(area_test.dist) / area_test.radius);
2010  const float afactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
2011 
2012  float disp[3];
2013  sub_v3_v3v3(disp, co, area_test.location);
2014  mul_v3_fl(disp, 1.0f - afactor);
2015  add_v3_v3v3(co, area_test.location, disp);
2016 
2017  add_v3_v3(anctd->area_cos[flip_index], co);
2018  anctd->count_co[flip_index] += 1;
2019  }
2020  if (use_area_nos && normal_test_r) {
2021  /* Weight the normals towards the center. */
2022  float p = 1.0f - (sqrtf(normal_test.dist) / normal_test.radius);
2023  const float nfactor = clamp_f(3.0f * p * p - 2.0f * p * p * p, 0.0f, 1.0f);
2024  mul_v3_fl(no, nfactor);
2025 
2026  add_v3_v3(anctd->area_nos[flip_index], no);
2027  anctd->count_no[flip_index] += 1;
2028  }
2029  }
2031  }
2032 }
2033 
2034 static void calc_area_normal_and_center_reduce(const void *__restrict UNUSED(userdata),
2035  void *__restrict chunk_join,
2036  void *__restrict chunk)
2037 {
2038  AreaNormalCenterTLSData *join = chunk_join;
2039  AreaNormalCenterTLSData *anctd = chunk;
2040 
2041  /* For flatten center. */
2042  add_v3_v3(join->area_cos[0], anctd->area_cos[0]);
2043  add_v3_v3(join->area_cos[1], anctd->area_cos[1]);
2044 
2045  /* For area normal. */
2046  add_v3_v3(join->area_nos[0], anctd->area_nos[0]);
2047  add_v3_v3(join->area_nos[1], anctd->area_nos[1]);
2048 
2049  /* Weights. */
2050  add_v2_v2_int(join->count_no, anctd->count_no);
2051  add_v2_v2_int(join->count_co, anctd->count_co);
2052 }
2053 
2055  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3])
2056 {
2057  const Brush *brush = BKE_paint_brush(&sd->paint);
2058  SculptSession *ss = ob->sculpt;
2059  const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
2060  int n;
2061 
2062  /* Intentionally set 'sd' to NULL since we share logic with vertex paint. */
2064  .sd = NULL,
2065  .ob = ob,
2066  .brush = brush,
2067  .nodes = nodes,
2068  .totnode = totnode,
2069  .has_bm_orco = has_bm_orco,
2070  .use_area_cos = true,
2071  };
2072 
2073  AreaNormalCenterTLSData anctd = {{{0}}};
2074 
2075  TaskParallelSettings settings;
2076  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
2078  settings.userdata_chunk = &anctd;
2079  settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
2081 
2082  /* For flatten center. */
2083  for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) {
2084  if (anctd.count_co[n] == 0) {
2085  continue;
2086  }
2087 
2088  mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]);
2089  break;
2090  }
2091 
2092  if (n == 2) {
2093  zero_v3(r_area_co);
2094  }
2095 
2096  if (anctd.count_co[0] == 0 && anctd.count_co[1] == 0) {
2097  if (ss->cache) {
2098  copy_v3_v3(r_area_co, ss->cache->location);
2099  }
2100  }
2101 }
2102 
2104  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
2105 {
2106  const Brush *brush = BKE_paint_brush(&sd->paint);
2107  SCULPT_pbvh_calc_area_normal(brush, ob, nodes, totnode, true, r_area_no);
2108 }
2109 
2111  Object *ob,
2112  PBVHNode **nodes,
2113  int totnode,
2114  bool use_threading,
2115  float r_area_no[3])
2116 {
2117  SculptSession *ss = ob->sculpt;
2118  const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
2119 
2120  /* Intentionally set 'sd' to NULL since this is used for vertex paint too. */
2122  .sd = NULL,
2123  .ob = ob,
2124  .brush = brush,
2125  .nodes = nodes,
2126  .totnode = totnode,
2127  .has_bm_orco = has_bm_orco,
2128  .use_area_nos = true,
2129  .any_vertex_sampled = false,
2130  };
2131 
2132  AreaNormalCenterTLSData anctd = {{{0}}};
2133 
2134  TaskParallelSettings settings;
2135  BKE_pbvh_parallel_range_settings(&settings, use_threading, totnode);
2137  settings.userdata_chunk = &anctd;
2138  settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
2140 
2141  /* For area normal. */
2142  for (int i = 0; i < ARRAY_SIZE(anctd.area_nos); i++) {
2143  if (normalize_v3_v3(r_area_no, anctd.area_nos[i]) != 0.0f) {
2144  break;
2145  }
2146  }
2147 
2148  return data.any_vertex_sampled;
2149 }
2150 
2152  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
2153 {
2154  const Brush *brush = BKE_paint_brush(&sd->paint);
2155  SculptSession *ss = ob->sculpt;
2156  const bool has_bm_orco = ss->bm && SCULPT_stroke_is_dynamic_topology(ss, brush);
2157  int n;
2158 
2159  /* Intentionally set 'sd' to NULL since this is used for vertex paint too. */
2161  .sd = NULL,
2162  .ob = ob,
2163  .brush = brush,
2164  .nodes = nodes,
2165  .totnode = totnode,
2166  .has_bm_orco = has_bm_orco,
2167  .use_area_cos = true,
2168  .use_area_nos = true,
2169  };
2170 
2171  AreaNormalCenterTLSData anctd = {{{0}}};
2172 
2173  TaskParallelSettings settings;
2174  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
2176  settings.userdata_chunk = &anctd;
2177  settings.userdata_chunk_size = sizeof(AreaNormalCenterTLSData);
2179 
2180  /* For flatten center. */
2181  for (n = 0; n < ARRAY_SIZE(anctd.area_cos); n++) {
2182  if (anctd.count_co[n] == 0) {
2183  continue;
2184  }
2185 
2186  mul_v3_v3fl(r_area_co, anctd.area_cos[n], 1.0f / anctd.count_co[n]);
2187  break;
2188  }
2189 
2190  if (n == 2) {
2191  zero_v3(r_area_co);
2192  }
2193 
2194  if (anctd.count_co[0] == 0 && anctd.count_co[1] == 0) {
2195  if (ss->cache) {
2196  copy_v3_v3(r_area_co, ss->cache->location);
2197  }
2198  }
2199 
2200  /* For area normal. */
2201  for (n = 0; n < ARRAY_SIZE(anctd.area_nos); n++) {
2202  if (normalize_v3_v3(r_area_no, anctd.area_nos[n]) != 0.0f) {
2203  break;
2204  }
2205  }
2206 }
2207 
2210 /* -------------------------------------------------------------------- */
2219 static float brush_strength(const Sculpt *sd,
2220  const StrokeCache *cache,
2221  const float feather,
2222  const UnifiedPaintSettings *ups,
2223  const PaintModeSettings *UNUSED(paint_mode_settings))
2224 {
2225  const Scene *scene = cache->vc->scene;
2226  const Brush *brush = BKE_paint_brush((Paint *)&sd->paint);
2227 
2228  /* Primary strength input; square it to make lower values more sensitive. */
2229  const float root_alpha = BKE_brush_alpha_get(scene, brush);
2230  const float alpha = root_alpha * root_alpha;
2231  const float dir = (brush->flag & BRUSH_DIR_IN) ? -1.0f : 1.0f;
2232  const float pressure = BKE_brush_use_alpha_pressure(brush) ? cache->pressure : 1.0f;
2233  const float pen_flip = cache->pen_flip ? -1.0f : 1.0f;
2234  const float invert = cache->invert ? -1.0f : 1.0f;
2235  float overlap = ups->overlap_factor;
2236  /* Spacing is integer percentage of radius, divide by 50 to get
2237  * normalized diameter. */
2238 
2239  float flip = dir * invert * pen_flip;
2240  if (brush->flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
2241  flip = 1.0f;
2242  }
2243 
2244  /* Pressure final value after being tweaked depending on the brush. */
2245  float final_pressure;
2246 
2247  switch (brush->sculpt_tool) {
2248  case SCULPT_TOOL_CLAY:
2249  final_pressure = pow4f(pressure);
2250  overlap = (1.0f + overlap) / 2.0f;
2251  return 0.25f * alpha * flip * final_pressure * overlap * feather;
2252  case SCULPT_TOOL_DRAW:
2254  case SCULPT_TOOL_LAYER:
2255  return alpha * flip * pressure * overlap * feather;
2257  return alpha * pressure * overlap * feather;
2258  case SCULPT_TOOL_CLOTH:
2260  /* Grab deform uses the same falloff as a regular grab brush. */
2261  return root_alpha * feather;
2262  }
2263  else if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_SNAKE_HOOK) {
2264  return root_alpha * feather * pressure * overlap;
2265  }
2266  else if (brush->cloth_deform_type == BRUSH_CLOTH_DEFORM_EXPAND) {
2267  /* Expand is more sensible to strength as it keeps expanding the cloth when sculpting over
2268  * the same vertices. */
2269  return 0.1f * alpha * flip * pressure * overlap * feather;
2270  }
2271  else {
2272  /* Multiply by 10 by default to get a larger range of strength depending on the size of the
2273  * brush and object. */
2274  return 10.0f * alpha * flip * pressure * overlap * feather;
2275  }
2277  return alpha * pressure * overlap * feather;
2279  return alpha * pressure * overlap * feather * 2.0f;
2280  case SCULPT_TOOL_PAINT:
2281  final_pressure = pressure * pressure;
2282  return final_pressure * overlap * feather;
2283  case SCULPT_TOOL_SMEAR:
2285  return alpha * pressure * overlap * feather;
2287  /* Clay Strips needs less strength to compensate the curve. */
2288  final_pressure = powf(pressure, 1.5f);
2289  return alpha * flip * final_pressure * overlap * feather * 0.3f;
2291  final_pressure = pressure * pressure;
2292  return alpha * flip * final_pressure * overlap * feather * 1.3f;
2293 
2294  case SCULPT_TOOL_MASK:
2295  overlap = (1.0f + overlap) / 2.0f;
2296  switch ((BrushMaskTool)brush->mask_tool) {
2297  case BRUSH_MASK_DRAW:
2298  return alpha * flip * pressure * overlap * feather;
2299  case BRUSH_MASK_SMOOTH:
2300  return alpha * pressure * feather;
2301  }
2302  BLI_assert_msg(0, "Not supposed to happen");
2303  return 0.0f;
2304 
2305  case SCULPT_TOOL_CREASE:
2306  case SCULPT_TOOL_BLOB:
2307  return alpha * flip * pressure * overlap * feather;
2308 
2309  case SCULPT_TOOL_INFLATE:
2310  if (flip > 0.0f) {
2311  return 0.250f * alpha * flip * pressure * overlap * feather;
2312  }
2313  else {
2314  return 0.125f * alpha * flip * pressure * overlap * feather;
2315  }
2316 
2318  overlap = (1.0f + overlap) / 2.0f;
2319  return alpha * flip * pressure * overlap * feather;
2320 
2321  case SCULPT_TOOL_FILL:
2322  case SCULPT_TOOL_SCRAPE:
2323  case SCULPT_TOOL_FLATTEN:
2324  if (flip > 0.0f) {
2325  overlap = (1.0f + overlap) / 2.0f;
2326  return alpha * flip * pressure * overlap * feather;
2327  }
2328  else {
2329  /* Reduce strength for DEEPEN, PEAKS, and CONTRAST. */
2330  return 0.5f * alpha * flip * pressure * overlap * feather;
2331  }
2332 
2333  case SCULPT_TOOL_SMOOTH:
2334  return flip * alpha * pressure * feather;
2335 
2336  case SCULPT_TOOL_PINCH:
2337  if (flip > 0.0f) {
2338  return alpha * flip * pressure * overlap * feather;
2339  }
2340  else {
2341  return 0.25f * alpha * flip * pressure * overlap * feather;
2342  }
2343 
2344  case SCULPT_TOOL_NUDGE:
2345  overlap = (1.0f + overlap) / 2.0f;
2346  return alpha * pressure * overlap * feather;
2347 
2348  case SCULPT_TOOL_THUMB:
2349  return alpha * pressure * feather;
2350 
2352  return root_alpha * feather;
2353 
2354  case SCULPT_TOOL_GRAB:
2355  return root_alpha * feather;
2356 
2357  case SCULPT_TOOL_ROTATE:
2358  return alpha * pressure * feather;
2359 
2361  case SCULPT_TOOL_POSE:
2362  case SCULPT_TOOL_BOUNDARY:
2363  return root_alpha * feather;
2364 
2365  default:
2366  return 0.0f;
2367  }
2368 }
2369 
2371  const Brush *br,
2372  const float brush_point[3],
2373  const float len,
2374  const float vno[3],
2375  const float fno[3],
2376  const float mask,
2377  const int vertex_index,
2378  const int thread_id)
2379 {
2380  StrokeCache *cache = ss->cache;
2381  const Scene *scene = cache->vc->scene;
2382  const MTex *mtex = &br->mtex;
2383  float avg = 1.0f;
2384  float rgba[4];
2385  float point[3];
2386 
2387  sub_v3_v3v3(point, brush_point, cache->plane_offset);
2388 
2389  if (!mtex->tex) {
2390  avg = 1.0f;
2391  }
2392  else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) {
2393  /* Get strength by feeding the vertex location directly into a texture. */
2394  avg = BKE_brush_sample_tex_3d(scene, br, point, rgba, 0, ss->tex_pool);
2395  }
2396  else {
2397  float symm_point[3], point_2d[2];
2398  /* Quite warnings. */
2399  float x = 0.0f, y = 0.0f;
2400 
2401  /* If the active area is being applied for symmetry, flip it
2402  * across the symmetry axis and rotate it back to the original
2403  * position in order to project it. This insures that the
2404  * brush texture will be oriented correctly. */
2405  if (cache->radial_symmetry_pass) {
2406  mul_m4_v3(cache->symm_rot_mat_inv, point);
2407  }
2408  flip_v3_v3(symm_point, point, cache->mirror_symmetry_pass);
2409 
2410  ED_view3d_project_float_v2_m4(cache->vc->region, symm_point, point_2d, cache->projection_mat);
2411 
2412  /* Still no symmetry supported for other paint modes.
2413  * Sculpt does it DIY. */
2414  if (mtex->brush_map_mode == MTEX_MAP_MODE_AREA) {
2415  /* Similar to fixed mode, but projects from brush angle
2416  * rather than view direction. */
2417 
2418  mul_m4_v3(cache->brush_local_mat, symm_point);
2419 
2420  x = symm_point[0];
2421  y = symm_point[1];
2422 
2423  x *= br->mtex.size[0];
2424  y *= br->mtex.size[1];
2425 
2426  x += br->mtex.ofs[0];
2427  y += br->mtex.ofs[1];
2428 
2429  avg = paint_get_tex_pixel(&br->mtex, x, y, ss->tex_pool, thread_id);
2430 
2431  avg += br->texture_sample_bias;
2432  }
2433  else {
2434  const float point_3d[3] = {point_2d[0], point_2d[1], 0.0f};
2435  avg = BKE_brush_sample_tex_3d(scene, br, point_3d, rgba, 0, ss->tex_pool);
2436  }
2437  }
2438 
2439  /* Hardness. */
2440  float final_len = len;
2441  const float hardness = cache->paint_brush.hardness;
2442  float p = len / cache->radius;
2443  if (p < hardness) {
2444  final_len = 0.0f;
2445  }
2446  else if (hardness == 1.0f) {
2447  final_len = cache->radius;
2448  }
2449  else {
2450  p = (p - hardness) / (1.0f - hardness);
2451  final_len = p * cache->radius;
2452  }
2453 
2454  /* Falloff curve. */
2455  avg *= BKE_brush_curve_strength(br, final_len, cache->radius);
2456  avg *= frontface(br, cache->view_normal, vno, fno);
2457 
2458  /* Paint mask. */
2459  avg *= 1.0f - mask;
2460 
2461  /* Auto-masking. */
2462  avg *= SCULPT_automasking_factor_get(cache->automasking, ss, vertex_index);
2463 
2464  return avg;
2465 }
2466 
2468 {
2469  SculptSearchSphereData *data = data_v;
2470  const float *center;
2471  float nearest[3];
2472  if (data->center) {
2473  center = data->center;
2474  }
2475  else {
2476  center = data->ss->cache ? data->ss->cache->location : data->ss->cursor_location;
2477  }
2478  float t[3], bb_min[3], bb_max[3];
2479 
2480  if (data->ignore_fully_ineffective) {
2482  return false;
2483  }
2485  return false;
2486  }
2487  }
2488 
2489  if (data->original) {
2490  BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
2491  }
2492  else {
2493  BKE_pbvh_node_get_BB(node, bb_min, bb_max);
2494  }
2495 
2496  for (int i = 0; i < 3; i++) {
2497  if (bb_min[i] > center[i]) {
2498  nearest[i] = bb_min[i];
2499  }
2500  else if (bb_max[i] < center[i]) {
2501  nearest[i] = bb_max[i];
2502  }
2503  else {
2504  nearest[i] = center[i];
2505  }
2506  }
2507 
2508  sub_v3_v3v3(t, center, nearest);
2509 
2510  return len_squared_v3(t) < data->radius_squared;
2511 }
2512 
2514 {
2515  SculptSearchCircleData *data = data_v;
2516  float bb_min[3], bb_max[3];
2517 
2518  if (data->ignore_fully_ineffective) {
2520  return false;
2521  }
2522  }
2523 
2524  if (data->original) {
2525  BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
2526  }
2527  else {
2528  BKE_pbvh_node_get_BB(node, bb_min, bb_min);
2529  }
2530 
2531  float dummy_co[3], dummy_depth;
2532  const float dist_sq = dist_squared_ray_to_aabb_v3(
2533  data->dist_ray_to_aabb_precalc, bb_min, bb_max, dummy_co, &dummy_depth);
2534 
2535  /* Seems like debug code.
2536  * Maybe this function can just return true if the node is not fully masked. */
2537  return dist_sq < data->radius_squared || true;
2538 }
2539 
2540 void SCULPT_clip(Sculpt *sd, SculptSession *ss, float co[3], const float val[3])
2541 {
2542  for (int i = 0; i < 3; i++) {
2543  if (sd->flags & (SCULPT_LOCK_X << i)) {
2544  continue;
2545  }
2546 
2547  bool do_clip = false;
2548  float co_clip[3];
2549  if (ss->cache && (ss->cache->flag & (CLIP_X << i))) {
2550  /* Take possible mirror object into account. */
2551  mul_v3_m4v3(co_clip, ss->cache->clip_mirror_mtx, co);
2552 
2553  if (fabsf(co_clip[i]) <= ss->cache->clip_tolerance[i]) {
2554  co_clip[i] = 0.0f;
2555  float imtx[4][4];
2556  invert_m4_m4(imtx, ss->cache->clip_mirror_mtx);
2557  mul_m4_v3(imtx, co_clip);
2558  do_clip = true;
2559  }
2560  }
2561 
2562  if (do_clip) {
2563  co[i] = co_clip[i];
2564  }
2565  else {
2566  co[i] = val[i];
2567  }
2568  }
2569 }
2570 
2572  Sculpt *sd,
2573  bool use_original,
2574  int *r_totnode)
2575 {
2576  SculptSession *ss = ob->sculpt;
2577  PBVHNode **nodes = NULL;
2579  .ss = ss,
2580  .sd = sd,
2581  .radius_squared = ss->cursor_radius,
2582  .original = use_original,
2583  .ignore_fully_ineffective = false,
2584  .center = NULL,
2585  };
2586  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
2587  return nodes;
2588 }
2589 
2591  Sculpt *sd,
2592  const Brush *brush,
2593  bool use_original,
2594  float radius_scale,
2595  int *r_totnode)
2596 {
2597  SculptSession *ss = ob->sculpt;
2598  PBVHNode **nodes = NULL;
2599 
2600  /* Build a list of all nodes that are potentially within the cursor or brush's area of influence.
2601  */
2602  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
2604  .ss = ss,
2605  .sd = sd,
2606  .radius_squared = square_f(ss->cache->radius * radius_scale),
2607  .original = use_original,
2608  .ignore_fully_ineffective = brush->sculpt_tool != SCULPT_TOOL_MASK,
2609  .center = NULL,
2610  };
2611  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, r_totnode);
2612  }
2613  else {
2614  struct DistRayAABB_Precalc dist_ray_to_aabb_precalc;
2616  &dist_ray_to_aabb_precalc, ss->cache->location, ss->cache->view_normal);
2618  .ss = ss,
2619  .sd = sd,
2620  .radius_squared = ss->cache ? square_f(ss->cache->radius * radius_scale) :
2621  ss->cursor_radius,
2622  .original = use_original,
2623  .dist_ray_to_aabb_precalc = &dist_ray_to_aabb_precalc,
2624  .ignore_fully_ineffective = brush->sculpt_tool != SCULPT_TOOL_MASK,
2625  };
2626  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_circle_cb, &data, &nodes, r_totnode);
2627  }
2628  return nodes;
2629 }
2630 
2631 /* Calculate primary direction of movement for many brushes. */
2633  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
2634 {
2635  const Brush *brush = BKE_paint_brush(&sd->paint);
2636  const SculptSession *ss = ob->sculpt;
2637 
2638  switch (brush->sculpt_plane) {
2639  case SCULPT_DISP_DIR_VIEW:
2640  copy_v3_v3(r_area_no, ss->cache->true_view_normal);
2641  break;
2642 
2643  case SCULPT_DISP_DIR_X:
2644  ARRAY_SET_ITEMS(r_area_no, 1.0f, 0.0f, 0.0f);
2645  break;
2646 
2647  case SCULPT_DISP_DIR_Y:
2648  ARRAY_SET_ITEMS(r_area_no, 0.0f, 1.0f, 0.0f);
2649  break;
2650 
2651  case SCULPT_DISP_DIR_Z:
2652  ARRAY_SET_ITEMS(r_area_no, 0.0f, 0.0f, 1.0f);
2653  break;
2654 
2655  case SCULPT_DISP_DIR_AREA:
2656  SCULPT_calc_area_normal(sd, ob, nodes, totnode, r_area_no);
2657  break;
2658 
2659  default:
2660  break;
2661  }
2662 }
2663 
2664 static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
2665 {
2666  const Brush *brush = BKE_paint_brush(&sd->paint);
2667  StrokeCache *cache = ob->sculpt->cache;
2668  /* Grab brush does not update the sculpt normal during a stroke. */
2669  const bool update_normal =
2670  !(brush->flag & BRUSH_ORIGINAL_NORMAL) && !(brush->sculpt_tool == SCULPT_TOOL_GRAB) &&
2671  !(brush->sculpt_tool == SCULPT_TOOL_THUMB && !(brush->flag & BRUSH_ANCHORED)) &&
2672  !(brush->sculpt_tool == SCULPT_TOOL_ELASTIC_DEFORM) &&
2673  !(brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK && cache->normal_weight > 0.0f);
2674 
2675  if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0 &&
2676  (SCULPT_stroke_is_first_brush_step_of_symmetry_pass(cache) || update_normal)) {
2677  calc_sculpt_normal(sd, ob, nodes, totnode, cache->sculpt_normal);
2678  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
2680  normalize_v3(cache->sculpt_normal);
2681  }
2683  }
2684  else {
2687  mul_m4_v3(cache->symm_rot_mat, cache->sculpt_normal_symm);
2688  }
2689 }
2690 
2691 static void calc_local_y(ViewContext *vc, const float center[3], float y[3])
2692 {
2693  Object *ob = vc->obact;
2694  float loc[3];
2695  const float xy_delta[2] = {0.0f, 1.0f};
2696 
2697  mul_v3_m4v3(loc, ob->imat, center);
2698  const float zfac = ED_view3d_calc_zfac(vc->rv3d, loc);
2699 
2700  ED_view3d_win_to_delta(vc->region, xy_delta, zfac, y);
2701  normalize_v3(y);
2702 
2703  add_v3_v3(y, ob->loc);
2704  mul_m4_v3(ob->imat, y);
2705 }
2706 
2707 static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat[4][4])
2708 {
2709  const StrokeCache *cache = ob->sculpt->cache;
2710  float tmat[4][4];
2711  float mat[4][4];
2712  float scale[4][4];
2713  float angle, v[3];
2714  float up[3];
2715 
2716  /* Ensure `ob->imat` is up to date. */
2717  invert_m4_m4(ob->imat, ob->obmat);
2718 
2719  /* Initialize last column of matrix. */
2720  mat[0][3] = 0.0f;
2721  mat[1][3] = 0.0f;
2722  mat[2][3] = 0.0f;
2723  mat[3][3] = 1.0f;
2724 
2725  /* Get view's up vector in object-space. */
2726  calc_local_y(cache->vc, cache->location, up);
2727 
2728  /* Calculate the X axis of the local matrix. */
2729  cross_v3_v3v3(v, up, cache->sculpt_normal);
2730  /* Apply rotation (user angle, rake, etc.) to X axis. */
2731  angle = brush->mtex.rot - cache->special_rotation;
2732  rotate_v3_v3v3fl(mat[0], v, cache->sculpt_normal, angle);
2733 
2734  /* Get other axes. */
2735  cross_v3_v3v3(mat[1], cache->sculpt_normal, mat[0]);
2736  copy_v3_v3(mat[2], cache->sculpt_normal);
2737 
2738  /* Set location. */
2739  copy_v3_v3(mat[3], cache->location);
2740 
2741  /* Scale by brush radius. */
2742  normalize_m4(mat);
2743  scale_m4_fl(scale, cache->radius);
2744  mul_m4_m4m4(tmat, mat, scale);
2745 
2746  /* Return inverse (for converting from model-space coords to local area coords). */
2747  invert_m4_m4(local_mat, tmat);
2748 }
2749 
2750 #define SCULPT_TILT_SENSITIVITY 0.7f
2751 void SCULPT_tilt_apply_to_normal(float r_normal[3], StrokeCache *cache, const float tilt_strength)
2752 {
2753  if (!U.experimental.use_sculpt_tools_tilt) {
2754  return;
2755  }
2756  const float rot_max = M_PI_2 * tilt_strength * SCULPT_TILT_SENSITIVITY;
2757  mul_v3_mat3_m4v3(r_normal, cache->vc->obact->obmat, r_normal);
2758  float normal_tilt_y[3];
2759  rotate_v3_v3v3fl(normal_tilt_y, r_normal, cache->vc->rv3d->viewinv[0], cache->y_tilt * rot_max);
2760  float normal_tilt_xy[3];
2762  normal_tilt_xy, normal_tilt_y, cache->vc->rv3d->viewinv[1], cache->x_tilt * rot_max);
2763  mul_v3_mat3_m4v3(r_normal, cache->vc->obact->imat, normal_tilt_xy);
2764  normalize_v3(r_normal);
2765 }
2766 
2767 void SCULPT_tilt_effective_normal_get(const SculptSession *ss, const Brush *brush, float r_no[3])
2768 {
2769  copy_v3_v3(r_no, ss->cache->sculpt_normal_symm);
2771 }
2772 
2773 static void update_brush_local_mat(Sculpt *sd, Object *ob)
2774 {
2775  StrokeCache *cache = ob->sculpt->cache;
2776 
2777  if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0) {
2779  }
2780 }
2781 
2784 /* -------------------------------------------------------------------- */
2788 static bool sculpt_needs_pbvh_pixels(PaintModeSettings *paint_mode_settings,
2789  const Brush *brush,
2790  Object *ob)
2791 {
2792  if (brush->sculpt_tool == SCULPT_TOOL_PAINT && U.experimental.use_sculpt_texture_paint) {
2793  Image *image;
2794  ImageUser *image_user;
2795  return SCULPT_paint_image_canvas_get(paint_mode_settings, ob, &image, &image_user);
2796  }
2797 
2798  return false;
2799 }
2800 
2801 static void sculpt_pbvh_update_pixels(PaintModeSettings *paint_mode_settings,
2802  SculptSession *ss,
2803  Object *ob)
2804 {
2805  BLI_assert(ob->type == OB_MESH);
2806  Mesh *mesh = (Mesh *)ob->data;
2807 
2808  Image *image;
2809  ImageUser *image_user;
2810  if (!SCULPT_paint_image_canvas_get(paint_mode_settings, ob, &image, &image_user)) {
2811  return;
2812  }
2813 
2814  BKE_pbvh_build_pixels(ss->pbvh, mesh, image, image_user);
2815 }
2816 
2819 /* -------------------------------------------------------------------- */
2823 typedef struct {
2825  const float *ray_start;
2826  const float *ray_normal;
2827  bool hit;
2828  float depth;
2829  bool original;
2830 
2832  float *face_normal;
2833 
2835 
2836  struct IsectRayPrecalc isect_precalc;
2838 
2839 typedef struct {
2841  const float *ray_start, *ray_normal;
2842  bool hit;
2843  float depth;
2845  bool original;
2847 
2849 {
2851  if (co[0] < 0.0f) {
2852  symm_area |= PAINT_SYMM_AREA_X;
2853  }
2854  if (co[1] < 0.0f) {
2855  symm_area |= PAINT_SYMM_AREA_Y;
2856  }
2857  if (co[2] < 0.0f) {
2858  symm_area |= PAINT_SYMM_AREA_Z;
2859  }
2860  return symm_area;
2861 }
2862 
2864  const ePaintSymmetryFlags symm,
2865  const ePaintSymmetryAreas symmarea,
2866  const float pivot[3])
2867 {
2868  for (int i = 0; i < 3; i++) {
2869  ePaintSymmetryFlags symm_it = 1 << i;
2870  if (!(symm & symm_it)) {
2871  continue;
2872  }
2873  if (symmarea & symm_it) {
2874  flip_v3(v, symm_it);
2875  }
2876  if (pivot[i] < 0.0f) {
2877  flip_v3(v, symm_it);
2878  }
2879  }
2880 }
2881 
2883  const ePaintSymmetryFlags symm,
2884  const ePaintSymmetryAreas symmarea,
2885  const float pivot[3])
2886 {
2887  for (int i = 0; i < 3; i++) {
2888  ePaintSymmetryFlags symm_it = 1 << i;
2889  if (!(symm & symm_it)) {
2890  continue;
2891  }
2892  if (symmarea & symm_it) {
2893  flip_qt(quat, symm_it);
2894  }
2895  if (pivot[i] < 0.0f) {
2896  flip_qt(quat, symm_it);
2897  }
2898  }
2899 }
2900 
2902  Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3])
2903 {
2904  SculptSession *ss = ob->sculpt;
2905  Brush *brush = BKE_paint_brush(&sd->paint);
2906 
2907  zero_v3(r_area_co);
2908  zero_v3(r_area_no);
2909 
2912  !(brush->flag & BRUSH_ORIGINAL_PLANE) || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) {
2913  switch (brush->sculpt_plane) {
2914  case SCULPT_DISP_DIR_VIEW:
2915  copy_v3_v3(r_area_no, ss->cache->true_view_normal);
2916  break;
2917 
2918  case SCULPT_DISP_DIR_X:
2919  ARRAY_SET_ITEMS(r_area_no, 1.0f, 0.0f, 0.0f);
2920  break;
2921 
2922  case SCULPT_DISP_DIR_Y:
2923  ARRAY_SET_ITEMS(r_area_no, 0.0f, 1.0f, 0.0f);
2924  break;
2925 
2926  case SCULPT_DISP_DIR_Z:
2927  ARRAY_SET_ITEMS(r_area_no, 0.0f, 0.0f, 1.0f);
2928  break;
2929 
2930  case SCULPT_DISP_DIR_AREA:
2931  SCULPT_calc_area_normal_and_center(sd, ob, nodes, totnode, r_area_no, r_area_co);
2932  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
2933  project_plane_v3_v3v3(r_area_no, r_area_no, ss->cache->view_normal);
2934  normalize_v3(r_area_no);
2935  }
2936  break;
2937 
2938  default:
2939  break;
2940  }
2941 
2942  /* For flatten center. */
2943  /* Flatten center has not been calculated yet if we are not using the area normal. */
2944  if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) {
2945  SCULPT_calc_area_center(sd, ob, nodes, totnode, r_area_co);
2946  }
2947 
2948  /* For area normal. */
2950  (brush->flag & BRUSH_ORIGINAL_NORMAL)) {
2951  copy_v3_v3(r_area_no, ss->cache->sculpt_normal);
2952  }
2953  else {
2954  copy_v3_v3(ss->cache->sculpt_normal, r_area_no);
2955  }
2956 
2957  /* For flatten center. */
2959  (brush->flag & BRUSH_ORIGINAL_PLANE)) {
2960  copy_v3_v3(r_area_co, ss->cache->last_center);
2961  }
2962  else {
2963  copy_v3_v3(ss->cache->last_center, r_area_co);
2964  }
2965  }
2966  else {
2967  /* For area normal. */
2968  copy_v3_v3(r_area_no, ss->cache->sculpt_normal);
2969 
2970  /* For flatten center. */
2971  copy_v3_v3(r_area_co, ss->cache->last_center);
2972 
2973  /* For area normal. */
2974  flip_v3(r_area_no, ss->cache->mirror_symmetry_pass);
2975 
2976  /* For flatten center. */
2977  flip_v3(r_area_co, ss->cache->mirror_symmetry_pass);
2978 
2979  /* For area normal. */
2980  mul_m4_v3(ss->cache->symm_rot_mat, r_area_no);
2981 
2982  /* For flatten center. */
2983  mul_m4_v3(ss->cache->symm_rot_mat, r_area_co);
2984 
2985  /* Shift the plane for the current tile. */
2986  add_v3_v3(r_area_co, ss->cache->plane_offset);
2987  }
2988 }
2989 
2990 int SCULPT_plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3])
2991 {
2992  return (!(brush->flag & BRUSH_PLANE_TRIM) ||
2993  ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared)));
2994 }
2995 
2996 int SCULPT_plane_point_side(const float co[3], const float plane[4])
2997 {
2998  float d = plane_point_side_v3(plane, co);
2999  return d <= 0.0f;
3000 }
3001 
3003 {
3004  Brush *brush = BKE_paint_brush(&sd->paint);
3005 
3006  float rv = brush->plane_offset;
3007 
3008  if (brush->flag & BRUSH_OFFSET_PRESSURE) {
3009  rv *= ss->cache->pressure;
3010  }
3011 
3012  return rv;
3013 }
3014 
3017 /* -------------------------------------------------------------------- */
3021 static void do_gravity_task_cb_ex(void *__restrict userdata,
3022  const int n,
3023  const TaskParallelTLS *__restrict tls)
3024 {
3025  SculptThreadedTaskData *data = userdata;
3026  SculptSession *ss = data->ob->sculpt;
3027  const Brush *brush = data->brush;
3028  float *offset = data->offset;
3029 
3030  PBVHVertexIter vd;
3031  float(*proxy)[3];
3032 
3033  proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co;
3034 
3035  SculptBrushTest test;
3037  ss, &test, data->brush->falloff_shape);
3038  const int thread_id = BLI_task_parallel_thread_id(tls);
3039 
3040  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3041  if (!sculpt_brush_test_sq_fn(&test, vd.co)) {
3042  continue;
3043  }
3044  const float fade = SCULPT_brush_strength_factor(ss,
3045  brush,
3046  vd.co,
3047  sqrtf(test.dist),
3048  vd.no,
3049  vd.fno,
3050  vd.mask ? *vd.mask : 0.0f,
3051  vd.index,
3052  thread_id);
3053 
3054  mul_v3_v3fl(proxy[vd.i], offset, fade);
3055 
3056  if (vd.mvert) {
3058  }
3059  }
3061 }
3062 
3063 static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength)
3064 {
3065  SculptSession *ss = ob->sculpt;
3066  Brush *brush = BKE_paint_brush(&sd->paint);
3067 
3068  float offset[3];
3069  float gravity_vector[3];
3070 
3071  mul_v3_v3fl(gravity_vector, ss->cache->gravity_direction, -ss->cache->radius_squared);
3072 
3073  /* Offset with as much as possible factored in already. */
3074  mul_v3_v3v3(offset, gravity_vector, ss->cache->scale);
3075  mul_v3_fl(offset, bstrength);
3076 
3077  /* Threaded loop over nodes. */
3079  .sd = sd,
3080  .ob = ob,
3081  .brush = brush,
3082  .nodes = nodes,
3083  .offset = offset,
3084  };
3085 
3086  TaskParallelSettings settings;
3087  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3088  BLI_task_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings);
3089 }
3090 
3093 /* -------------------------------------------------------------------- */
3097 void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float (*vertCos)[3])
3098 {
3099  Mesh *me = (Mesh *)ob->data;
3100  float(*ofs)[3] = NULL;
3101  int a;
3102  const int kb_act_idx = ob->shapenr - 1;
3103  KeyBlock *currkey;
3104 
3105  /* For relative keys editing of base should update other keys. */
3106  if (BKE_keyblock_is_basis(me->key, kb_act_idx)) {
3107  ofs = BKE_keyblock_convert_to_vertcos(ob, kb);
3108 
3109  /* Calculate key coord offsets (from previous location). */
3110  for (a = 0; a < me->totvert; a++) {
3111  sub_v3_v3v3(ofs[a], vertCos[a], ofs[a]);
3112  }
3113 
3114  /* Apply offsets on other keys. */
3115  for (currkey = me->key->block.first; currkey; currkey = currkey->next) {
3116  if ((currkey != kb) && (currkey->relative == kb_act_idx)) {
3117  BKE_keyblock_update_from_offset(ob, currkey, ofs);
3118  }
3119  }
3120 
3121  MEM_freeN(ofs);
3122  }
3123 
3124  /* Modifying of basis key should update mesh. */
3125  if (kb == me->key->refkey) {
3126  MVert *mvert = me->mvert;
3127 
3128  for (a = 0; a < me->totvert; a++, mvert++) {
3129  copy_v3_v3(mvert->co, vertCos[a]);
3130  }
3132  }
3133 
3134  /* Apply new coords on active key block, no need to re-allocate kb->data here! */
3135  BKE_keyblock_update_from_vertcos(ob, kb, vertCos);
3136 }
3137 
3138 /* NOTE: we do the topology update before any brush actions to avoid
3139  * issues with the proxies. The size of the proxy can't change, so
3140  * topology must be updated first. */
3142  Object *ob,
3143  Brush *brush,
3145  PaintModeSettings *UNUSED(paint_mode_settings))
3146 {
3147  SculptSession *ss = ob->sculpt;
3148 
3149  int n, totnode;
3150  /* Build a list of all nodes that are potentially within the brush's area of influence. */
3151  const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
3152  ss->cache->original;
3153  const float radius_scale = 1.25f;
3155  ob, sd, brush, use_original, radius_scale, &totnode);
3156 
3157  /* Only act if some verts are inside the brush area. */
3158  if (totnode == 0) {
3159  return;
3160  }
3161 
3162  /* Free index based vertex info as it will become invalid after modifying the topology during the
3163  * stroke. */
3166 
3167  PBVHTopologyUpdateMode mode = 0;
3168  float location[3];
3169 
3170  if (!(sd->flags & SCULPT_DYNTOPO_DETAIL_MANUAL)) {
3171  if (sd->flags & SCULPT_DYNTOPO_SUBDIVIDE) {
3172  mode |= PBVH_Subdivide;
3173  }
3174 
3175  if ((sd->flags & SCULPT_DYNTOPO_COLLAPSE) || (brush->sculpt_tool == SCULPT_TOOL_SIMPLIFY)) {
3176  mode |= PBVH_Collapse;
3177  }
3178  }
3179 
3180  for (n = 0; n < totnode; n++) {
3182  nodes[n],
3185  BKE_pbvh_node_mark_update(nodes[n]);
3186 
3187  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
3189  BKE_pbvh_bmesh_node_save_orig(ss->bm, nodes[n]);
3190  }
3191  }
3192 
3193  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
3195  mode,
3196  ss->cache->location,
3197  ss->cache->view_normal,
3198  ss->cache->radius,
3199  (brush->flag & BRUSH_FRONTFACE) != 0,
3201  }
3202 
3203  MEM_SAFE_FREE(nodes);
3204 
3205  /* Update average stroke position. */
3206  copy_v3_v3(location, ss->cache->true_location);
3207  mul_m4_v3(ob->obmat, location);
3208 }
3209 
3210 static void do_brush_action_task_cb(void *__restrict userdata,
3211  const int n,
3212  const TaskParallelTLS *__restrict UNUSED(tls))
3213 {
3214  SculptThreadedTaskData *data = userdata;
3215  SculptSession *ss = data->ob->sculpt;
3216 
3217  bool need_coords = ss->cache->supports_gravity;
3218 
3219  /* Face Sets modifications do a single undo push */
3220  if (data->brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS) {
3221  BKE_pbvh_node_mark_redraw(data->nodes[n]);
3222  /* Draw face sets in smooth mode moves the vertices. */
3223  if (ss->cache->alt_smooth) {
3224  need_coords = true;
3225  }
3226  }
3227  else if (data->brush->sculpt_tool == SCULPT_TOOL_MASK) {
3230  }
3231  else if (SCULPT_tool_is_paint(data->brush->sculpt_tool)) {
3234  }
3235  else {
3236  need_coords = true;
3237  }
3238 
3239  if (need_coords) {
3241  BKE_pbvh_node_mark_update(data->nodes[n]);
3242  }
3243 }
3244 
3245 static void do_brush_action(Sculpt *sd,
3246  Object *ob,
3247  Brush *brush,
3248  UnifiedPaintSettings *ups,
3249  PaintModeSettings *paint_mode_settings)
3250 {
3251  SculptSession *ss = ob->sculpt;
3252  int totnode;
3253  PBVHNode **nodes;
3254 
3255  /* Check for unsupported features. */
3257 
3259  if (type != PBVH_FACES) {
3260  return;
3261  }
3262 
3264  }
3265 
3266  /* Build a list of all nodes that are potentially within the brush's area of influence */
3267 
3268  if (SCULPT_tool_needs_all_pbvh_nodes(brush)) {
3269  /* These brushes need to update all nodes as they are not constrained by the brush radius */
3270  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
3271  }
3272  else if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
3273  nodes = SCULPT_cloth_brush_affected_nodes_gather(ss, brush, &totnode);
3274  }
3275  else {
3276  const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true :
3277  ss->cache->original;
3278  float radius_scale = 1.0f;
3279 
3280  /* Corners of square brushes can go outside the brush radius. */
3281  if (sculpt_tool_has_cube_tip(brush->sculpt_tool)) {
3282  radius_scale = M_SQRT2;
3283  }
3284 
3285  /* With these options enabled not all required nodes are inside the original brush radius, so
3286  * the brush can produce artifacts in some situations. */
3287  if (brush->sculpt_tool == SCULPT_TOOL_DRAW && brush->flag & BRUSH_ORIGINAL_NORMAL) {
3288  radius_scale = 2.0f;
3289  }
3290  nodes = sculpt_pbvh_gather_generic(ob, sd, brush, use_original, radius_scale, &totnode);
3291  }
3292  const bool use_pixels = sculpt_needs_pbvh_pixels(paint_mode_settings, brush, ob);
3293  if (use_pixels) {
3294  sculpt_pbvh_update_pixels(paint_mode_settings, ss, ob);
3295  }
3296 
3297  /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode deforms the
3298  * vertices and uses regular coords undo. */
3299  /* It also assigns the paint_face_set here as it needs to be done regardless of the stroke type
3300  * and the number of nodes under the brush influence. */
3301  if (brush->sculpt_tool == SCULPT_TOOL_DRAW_FACE_SETS &&
3303 
3304  /* Dynamic-topology does not support Face Sets data, so it can't store/restore it from undo. */
3305  /* TODO(pablodp606): This check should be done in the undo code and not here, but the rest of
3306  * the sculpt code is not checking for unsupported undo types that may return a null node. */
3307  if (BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {
3309  }
3310 
3311  if (ss->cache->invert) {
3312  /* When inverting the brush, pick the paint face mask ID from the mesh. */
3314  }
3315  else {
3316  /* By default create a new Face Sets. */
3318  }
3319  }
3320 
3321  /* For anchored brushes with spherical falloff, we start off with zero radius, thus we have no
3322  * PBVH nodes on the first brush step. */
3323  if (totnode ||
3324  ((brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) && (brush->flag & BRUSH_ANCHORED))) {
3326  /* Initialize auto-masking cache. */
3327  if (SCULPT_is_automasking_enabled(sd, ss, brush)) {
3328  ss->cache->automasking = SCULPT_automasking_cache_init(sd, brush, ob);
3329  }
3330  /* Initialize surface smooth cache. */
3331  if ((brush->sculpt_tool == SCULPT_TOOL_SMOOTH) &&
3335  sizeof(float[3]) * SCULPT_vertex_count_get(ss), "HC smooth laplacian b");
3336  }
3337  }
3338  }
3339 
3340  /* Only act if some verts are inside the brush area. */
3341  if (totnode == 0) {
3342  return;
3343  }
3344  float location[3];
3345 
3346  if (!use_pixels) {
3347  SculptThreadedTaskData task_data = {
3348  .sd = sd,
3349  .ob = ob,
3350  .brush = brush,
3351  .nodes = nodes,
3352  };
3353 
3354  TaskParallelSettings settings;
3355  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3356  BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings);
3357  }
3358 
3359  if (sculpt_brush_needs_normal(ss, brush)) {
3360  update_sculpt_normal(sd, ob, nodes, totnode);
3361  }
3362 
3363  if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) {
3364  update_brush_local_mat(sd, ob);
3365  }
3366 
3368  SCULPT_pose_brush_init(sd, ob, ss, brush);
3369  }
3370 
3372  if (!ss->cache->cloth_sim) {
3374  ob, 1.0f, 0.0f, 0.0f, false, true);
3376  }
3379  sd, ob, nodes, totnode, ss->cache->cloth_sim, ss->cache->location, FLT_MAX);
3380  }
3381 
3382  bool invert = ss->cache->pen_flip || ss->cache->invert || brush->flag & BRUSH_DIR_IN;
3383 
3384  /* Apply one type of brush action. */
3385  switch (brush->sculpt_tool) {
3386  case SCULPT_TOOL_DRAW:
3387  SCULPT_do_draw_brush(sd, ob, nodes, totnode);
3388  break;
3389  case SCULPT_TOOL_SMOOTH:
3391  SCULPT_do_smooth_brush(sd, ob, nodes, totnode);
3392  }
3393  else if (brush->smooth_deform_type == BRUSH_SMOOTH_DEFORM_SURFACE) {
3394  SCULPT_do_surface_smooth_brush(sd, ob, nodes, totnode);
3395  }
3396  break;
3397  case SCULPT_TOOL_CREASE:
3398  SCULPT_do_crease_brush(sd, ob, nodes, totnode);
3399  break;
3400  case SCULPT_TOOL_BLOB:
3401  SCULPT_do_crease_brush(sd, ob, nodes, totnode);
3402  break;
3403  case SCULPT_TOOL_PINCH:
3404  SCULPT_do_pinch_brush(sd, ob, nodes, totnode);
3405  break;
3406  case SCULPT_TOOL_INFLATE:
3407  SCULPT_do_inflate_brush(sd, ob, nodes, totnode);
3408  break;
3409  case SCULPT_TOOL_GRAB:
3410  SCULPT_do_grab_brush(sd, ob, nodes, totnode);
3411  break;
3412  case SCULPT_TOOL_ROTATE:
3413  SCULPT_do_rotate_brush(sd, ob, nodes, totnode);
3414  break;
3416  SCULPT_do_snake_hook_brush(sd, ob, nodes, totnode);
3417  break;
3418  case SCULPT_TOOL_NUDGE:
3419  SCULPT_do_nudge_brush(sd, ob, nodes, totnode);
3420  break;
3421  case SCULPT_TOOL_THUMB:
3422  SCULPT_do_thumb_brush(sd, ob, nodes, totnode);
3423  break;
3424  case SCULPT_TOOL_LAYER:
3425  SCULPT_do_layer_brush(sd, ob, nodes, totnode);
3426  break;
3427  case SCULPT_TOOL_FLATTEN:
3428  SCULPT_do_flatten_brush(sd, ob, nodes, totnode);
3429  break;
3430  case SCULPT_TOOL_CLAY:
3431  SCULPT_do_clay_brush(sd, ob, nodes, totnode);
3432  break;
3434  SCULPT_do_clay_strips_brush(sd, ob, nodes, totnode);
3435  break;
3437  SCULPT_do_multiplane_scrape_brush(sd, ob, nodes, totnode);
3438  break;
3440  SCULPT_do_clay_thumb_brush(sd, ob, nodes, totnode);
3441  break;
3442  case SCULPT_TOOL_FILL:
3443  if (invert && brush->flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
3444  SCULPT_do_scrape_brush(sd, ob, nodes, totnode);
3445  }
3446  else {
3447  SCULPT_do_fill_brush(sd, ob, nodes, totnode);
3448  }
3449  break;
3450  case SCULPT_TOOL_SCRAPE:
3451  if (invert && brush->flag & BRUSH_INVERT_TO_SCRAPE_FILL) {
3452  SCULPT_do_fill_brush(sd, ob, nodes, totnode);
3453  }
3454  else {
3455  SCULPT_do_scrape_brush(sd, ob, nodes, totnode);
3456  }
3457  break;
3458  case SCULPT_TOOL_MASK:
3459  SCULPT_do_mask_brush(sd, ob, nodes, totnode);
3460  break;
3461  case SCULPT_TOOL_POSE:
3462  SCULPT_do_pose_brush(sd, ob, nodes, totnode);
3463  break;
3465  SCULPT_do_draw_sharp_brush(sd, ob, nodes, totnode);
3466  break;
3468  SCULPT_do_elastic_deform_brush(sd, ob, nodes, totnode);
3469  break;
3471  SCULPT_do_slide_relax_brush(sd, ob, nodes, totnode);
3472  break;
3473  case SCULPT_TOOL_BOUNDARY:
3474  SCULPT_do_boundary_brush(sd, ob, nodes, totnode);
3475  break;
3476  case SCULPT_TOOL_CLOTH:
3477  SCULPT_do_cloth_brush(sd, ob, nodes, totnode);
3478  break;
3480  SCULPT_do_draw_face_sets_brush(sd, ob, nodes, totnode);
3481  break;
3483  SCULPT_do_displacement_eraser_brush(sd, ob, nodes, totnode);
3484  break;
3486  SCULPT_do_displacement_smear_brush(sd, ob, nodes, totnode);
3487  break;
3488  case SCULPT_TOOL_PAINT:
3489  SCULPT_do_paint_brush(paint_mode_settings, sd, ob, nodes, totnode);
3490  break;
3491  case SCULPT_TOOL_SMEAR:
3492  SCULPT_do_smear_brush(sd, ob, nodes, totnode);
3493  break;
3494  }
3495 
3497  brush->autosmooth_factor > 0) {
3498  if (brush->flag & BRUSH_INVERSE_SMOOTH_PRESSURE) {
3499  SCULPT_smooth(
3500  sd, ob, nodes, totnode, brush->autosmooth_factor * (1.0f - ss->cache->pressure), false);
3501  }
3502  else {
3503  SCULPT_smooth(sd, ob, nodes, totnode, brush->autosmooth_factor, false);
3504  }
3505  }
3506 
3507  if (sculpt_brush_use_topology_rake(ss, brush)) {
3508  SCULPT_bmesh_topology_rake(sd, ob, nodes, totnode, brush->topology_rake_factor);
3509  }
3510 
3511  /* The cloth brush adds the gravity as a regular force and it is processed in the solver. */
3512  if (ss->cache->supports_gravity && !ELEM(brush->sculpt_tool,
3516  do_gravity(sd, ob, nodes, totnode, sd->gravity_factor);
3517  }
3518 
3521  SCULPT_cloth_sim_activate_nodes(ss->cache->cloth_sim, nodes, totnode);
3522  SCULPT_cloth_brush_do_simulation_step(sd, ob, ss->cache->cloth_sim, nodes, totnode);
3523  }
3524  }
3525 
3526  MEM_SAFE_FREE(nodes);
3527 
3528  /* Update average stroke position. */
3529  copy_v3_v3(location, ss->cache->true_location);
3530  mul_m4_v3(ob->obmat, location);
3531 
3532  add_v3_v3(ups->average_stroke_accum, location);
3533  ups->average_stroke_counter++;
3534  /* Update last stroke position. */
3535  ups->last_stroke_valid = true;
3536 }
3537 
3538 /* Flush displacement from deformed PBVH vertex to original mesh. */
3540 {
3541  SculptSession *ss = ob->sculpt;
3542  Mesh *me = ob->data;
3543  float disp[3], newco[3];
3544  int index = vd->vert_indices[vd->i];
3545 
3546  sub_v3_v3v3(disp, vd->co, ss->deform_cos[index]);
3547  mul_m3_v3(ss->deform_imats[index], disp);
3548  add_v3_v3v3(newco, disp, ss->orig_cos[index]);
3549 
3550  copy_v3_v3(ss->deform_cos[index], vd->co);
3551  copy_v3_v3(ss->orig_cos[index], newco);
3552 
3553  if (!ss->shapekey_active) {
3554  copy_v3_v3(me->mvert[index].co, newco);
3555  }
3556 }
3557 
3558 static void sculpt_combine_proxies_task_cb(void *__restrict userdata,
3559  const int n,
3560  const TaskParallelTLS *__restrict UNUSED(tls))
3561 {
3562  SculptThreadedTaskData *data = userdata;
3563  SculptSession *ss = data->ob->sculpt;
3564  Sculpt *sd = data->sd;
3565  Object *ob = data->ob;
3566  const bool use_orco = data->use_proxies_orco;
3567 
3568  PBVHVertexIter vd;
3569  PBVHProxyNode *proxies;
3570  int proxy_count;
3571  float(*orco)[3] = NULL;
3572 
3573  if (use_orco && !ss->bm) {
3574  orco = SCULPT_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS)->co;
3575  }
3576 
3577  BKE_pbvh_node_get_proxies(data->nodes[n], &proxies, &proxy_count);
3578 
3579  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3580  float val[3];
3581 
3582  if (use_orco) {
3583  if (ss->bm) {
3585  }
3586  else {
3587  copy_v3_v3(val, orco[vd.i]);
3588  }
3589  }
3590  else {
3591  copy_v3_v3(val, vd.co);
3592  }
3593 
3594  for (int p = 0; p < proxy_count; p++) {
3595  add_v3_v3(val, proxies[p].co[vd.i]);
3596  }
3597 
3598  SCULPT_clip(sd, ss, vd.co, val);
3599 
3600  if (ss->deform_modifiers_active) {
3602  }
3603  }
3605 
3606  BKE_pbvh_node_free_proxies(data->nodes[n]);
3607 }
3608 
3609 static void sculpt_combine_proxies(Sculpt *sd, Object *ob)
3610 {
3611  SculptSession *ss = ob->sculpt;
3612  Brush *brush = BKE_paint_brush(&sd->paint);
3613  PBVHNode **nodes;
3614  int totnode;
3615 
3617  /* First line is tools that don't support proxies. */
3618  return;
3619  }
3620 
3621  /* First line is tools that don't support proxies. */
3622  const bool use_orco = ELEM(brush->sculpt_tool,
3629 
3630  BKE_pbvh_gather_proxies(ss->pbvh, &nodes, &totnode);
3631 
3633  .sd = sd,
3634  .ob = ob,
3635  .brush = brush,
3636  .nodes = nodes,
3637  .use_proxies_orco = use_orco,
3638  };
3639 
3640  TaskParallelSettings settings;
3641  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3643  MEM_SAFE_FREE(nodes);
3644 }
3645 
3647 {
3648  SculptSession *ss = ob->sculpt;
3649  PBVHNode **nodes;
3650  int totnode;
3651 
3652  BKE_pbvh_gather_proxies(ss->pbvh, &nodes, &totnode);
3654  .sd = sd,
3655  .ob = ob,
3656  .nodes = nodes,
3657  .use_proxies_orco = false,
3658  };
3659 
3660  TaskParallelSettings settings;
3661  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3663 
3664  MEM_SAFE_FREE(nodes);
3665 }
3666 
3671 {
3672  SculptSession *ss = ob->sculpt;
3673  float(*vertCos)[3];
3674 
3675  /* Key-block update happens after handling deformation caused by modifiers,
3676  * so ss->orig_cos would be updated with new stroke. */
3677  if (ss->orig_cos) {
3678  vertCos = ss->orig_cos;
3679  }
3680  else {
3681  vertCos = BKE_pbvh_vert_coords_alloc(ss->pbvh);
3682  }
3683 
3684  if (!vertCos) {
3685  return;
3686  }
3687 
3688  SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos);
3689 
3690  if (vertCos != ss->orig_cos) {
3691  MEM_freeN(vertCos);
3692  }
3693 }
3694 
3695 static void SCULPT_flush_stroke_deform_task_cb(void *__restrict userdata,
3696  const int n,
3697  const TaskParallelTLS *__restrict UNUSED(tls))
3698 {
3699  SculptThreadedTaskData *data = userdata;
3700  SculptSession *ss = data->ob->sculpt;
3701  Object *ob = data->ob;
3702  float(*vertCos)[3] = data->vertCos;
3703 
3704  PBVHVertexIter vd;
3705 
3706  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
3708 
3709  if (!vertCos) {
3710  continue;
3711  }
3712 
3713  int index = vd.vert_indices[vd.i];
3714  copy_v3_v3(vertCos[index], ss->orig_cos[index]);
3715  }
3717 }
3718 
3719 void SCULPT_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_used)
3720 {
3721  SculptSession *ss = ob->sculpt;
3722  Brush *brush = BKE_paint_brush(&sd->paint);
3723 
3724  if (is_proxy_used && ss->deform_modifiers_active) {
3725  /* This brushes aren't using proxies, so sculpt_combine_proxies() wouldn't propagate needed
3726  * deformation to original base. */
3727 
3728  int totnode;
3729  Mesh *me = (Mesh *)ob->data;
3730  PBVHNode **nodes;
3731  float(*vertCos)[3] = NULL;
3732 
3733  if (ss->shapekey_active) {
3734  vertCos = MEM_mallocN(sizeof(*vertCos) * me->totvert, "flushStrokeDeofrm keyVerts");
3735 
3736  /* Mesh could have isolated verts which wouldn't be in BVH, to deal with this we copy old
3737  * coordinates over new ones and then update coordinates for all vertices from BVH. */
3738  memcpy(vertCos, ss->orig_cos, sizeof(*vertCos) * me->totvert);
3739  }
3740 
3741  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
3742 
3744  .sd = sd,
3745  .ob = ob,
3746  .brush = brush,
3747  .nodes = nodes,
3748  .vertCos = vertCos,
3749  };
3750 
3751  TaskParallelSettings settings;
3752  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
3754 
3755  if (vertCos) {
3756  SCULPT_vertcos_to_key(ob, ss->shapekey_active, vertCos);
3757  MEM_freeN(vertCos);
3758  }
3759 
3760  MEM_SAFE_FREE(nodes);
3761  }
3762  else if (ss->shapekey_active) {
3764  }
3765 }
3766 
3768  const char symm,
3769  const char axis,
3770  const float angle)
3771 {
3772  flip_v3_v3(cache->location, cache->true_location, symm);
3773  flip_v3_v3(cache->last_location, cache->true_last_location, symm);
3774  flip_v3_v3(cache->grab_delta_symmetry, cache->grab_delta, symm);
3775  flip_v3_v3(cache->view_normal, cache->true_view_normal, symm);
3776 
3777  flip_v3_v3(cache->initial_location, cache->true_initial_location, symm);
3778  flip_v3_v3(cache->initial_normal, cache->true_initial_normal, symm);
3779 
3780  /* XXX This reduces the length of the grab delta if it approaches the line of symmetry
3781  * XXX However, a different approach appears to be needed. */
3782 #if 0
3784  float frac = 1.0f / max_overlap_count(sd);
3785  float reduce = (feather - frac) / (1.0f - frac);
3786 
3787  printf("feather: %f frac: %f reduce: %f\n", feather, frac, reduce);
3788 
3789  if (frac < 1.0f) {
3790  mul_v3_fl(cache->grab_delta_symmetry, reduce);
3791  }
3792  }
3793 #endif
3794 
3795  unit_m4(cache->symm_rot_mat);
3796  unit_m4(cache->symm_rot_mat_inv);
3797  zero_v3(cache->plane_offset);
3798 
3799  /* Expects XYZ. */
3800  if (axis) {
3801  rotate_m4(cache->symm_rot_mat, axis, angle);
3802  rotate_m4(cache->symm_rot_mat_inv, axis, -angle);
3803  }
3804 
3805  mul_m4_v3(cache->symm_rot_mat, cache->location);
3806  mul_m4_v3(cache->symm_rot_mat, cache->grab_delta_symmetry);
3807 
3808  if (cache->supports_gravity) {
3809  flip_v3_v3(cache->gravity_direction, cache->true_gravity_direction, symm);
3810  mul_m4_v3(cache->symm_rot_mat, cache->gravity_direction);
3811  }
3812 
3813  if (cache->is_rake_rotation_valid) {
3814  flip_qt_qt(cache->rake_rotation_symmetry, cache->rake_rotation, symm);
3815  }
3816 }
3817 
3818 typedef void (*BrushActionFunc)(Sculpt *sd,
3819  Object *ob,
3820  Brush *brush,
3821  UnifiedPaintSettings *ups,
3822  PaintModeSettings *paint_mode_settings);
3823 
3824 static void do_tiled(Sculpt *sd,
3825  Object *ob,
3826  Brush *brush,
3827  UnifiedPaintSettings *ups,
3828  PaintModeSettings *paint_mode_settings,
3829  BrushActionFunc action)
3830 {
3831  SculptSession *ss = ob->sculpt;
3832  StrokeCache *cache = ss->cache;
3833  const float radius = cache->radius;
3834  const BoundBox *bb = BKE_object_boundbox_get(ob);
3835  const float *bbMin = bb->vec[0];
3836  const float *bbMax = bb->vec[6];
3837  const float *step = sd->paint.tile_offset;
3838 
3839  /* These are integer locations, for real location: multiply with step and add orgLoc.
3840  * So 0,0,0 is at orgLoc. */
3841  int start[3];
3842  int end[3];
3843  int cur[3];
3844 
3845  /* Position of the "prototype" stroke for tiling. */
3846  float orgLoc[3];
3847  float original_initial_location[3];
3848  copy_v3_v3(orgLoc, cache->location);
3849  copy_v3_v3(original_initial_location, cache->initial_location);
3850 
3851  for (int dim = 0; dim < 3; dim++) {
3852  if ((sd->paint.symmetry_flags & (PAINT_TILE_X << dim)) && step[dim] > 0) {
3853  start[dim] = (bbMin[dim] - orgLoc[dim] - radius) / step[dim];
3854  end[dim] = (bbMax[dim] - orgLoc[dim] + radius) / step[dim];
3855  }
3856  else {
3857  start[dim] = end[dim] = 0;
3858  }
3859  }
3860 
3861  /* First do the "un-tiled" position to initialize the stroke for this location. */
3862  cache->tile_pass = 0;
3863  action(sd, ob, brush, ups, paint_mode_settings);
3864 
3865  /* Now do it for all the tiles. */
3866  copy_v3_v3_int(cur, start);
3867  for (cur[0] = start[0]; cur[0] <= end[0]; cur[0]++) {
3868  for (cur[1] = start[1]; cur[1] <= end[1]; cur[1]++) {
3869  for (cur[2] = start[2]; cur[2] <= end[2]; cur[2]++) {
3870  if (!cur[0] && !cur[1] && !cur[2]) {
3871  /* Skip tile at orgLoc, this was already handled before all others. */
3872  continue;
3873  }
3874 
3875  ++cache->tile_pass;
3876 
3877  for (int dim = 0; dim < 3; dim++) {
3878  cache->location[dim] = cur[dim] * step[dim] + orgLoc[dim];
3879  cache->plane_offset[dim] = cur[dim] * step[dim];
3880  cache->initial_location[dim] = cur[dim] * step[dim] + original_initial_location[dim];
3881  }
3882  action(sd, ob, brush, ups, paint_mode_settings);
3883  }
3884  }
3885  }
3886 }
3887 
3888 static void do_radial_symmetry(Sculpt *sd,
3889  Object *ob,
3890  Brush *brush,
3891  UnifiedPaintSettings *ups,
3892  PaintModeSettings *paint_mode_settings,
3893  BrushActionFunc action,
3894  const char symm,
3895  const int axis,
3896  const float UNUSED(feather))
3897 {
3898  SculptSession *ss = ob->sculpt;
3899 
3900  for (int i = 1; i < sd->radial_symm[axis - 'X']; i++) {
3901  const float angle = 2.0f * M_PI * i / sd->radial_symm[axis - 'X'];
3902  ss->cache->radial_symmetry_pass = i;
3903  SCULPT_cache_calc_brushdata_symm(ss->cache, symm, axis, angle);
3904  do_tiled(sd, ob, brush, ups, paint_mode_settings, action);
3905  }
3906 }
3907 
3912 static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
3913 {
3914  SculptSession *ss = ob->sculpt;
3915  Brush *brush = BKE_paint_brush(&sd->paint);
3916  MTex *mtex = &brush->mtex;
3917 
3918  if (ss->multires.active && mtex->tex && mtex->tex->type == TEX_NOISE) {
3920  }
3921 }
3922 
3924  Object *ob,
3925  BrushActionFunc action,
3926  UnifiedPaintSettings *ups,
3927  PaintModeSettings *paint_mode_settings)
3928 {
3929  Brush *brush = BKE_paint_brush(&sd->paint);
3930  SculptSession *ss = ob->sculpt;
3931  StrokeCache *cache = ss->cache;
3932  const char symm = SCULPT_mesh_symmetry_xyz_get(ob);
3933 
3934  float feather = calc_symmetry_feather(sd, ss->cache);
3935 
3936  cache->bstrength = brush_strength(sd, cache, feather, ups, paint_mode_settings);
3937  cache->symmetry = symm;
3938 
3939  /* `symm` is a bit combination of XYZ -
3940  * 1 is mirror X; 2 is Y; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ; 7 is XYZ */
3941  for (int i = 0; i <= symm; i++) {
3942  if (!SCULPT_is_symmetry_iteration_valid(i, symm)) {
3943  continue;
3944  }
3945  cache->mirror_symmetry_pass = i;
3946  cache->radial_symmetry_pass = 0;
3947 
3948  SCULPT_cache_calc_brushdata_symm(cache, i, 0, 0);
3949  do_tiled(sd, ob, brush, ups, paint_mode_settings, action);
3950 
3951  do_radial_symmetry(sd, ob, brush, ups, paint_mode_settings, action, i, 'X', feather);
3952  do_radial_symmetry(sd, ob, brush, ups, paint_mode_settings, action, i, 'Y', feather);
3953  do_radial_symmetry(sd, ob, brush, ups, paint_mode_settings, action, i, 'Z', feather);
3954  }
3955 }
3956 
3958 {
3960  return ob && ob->mode & OB_MODE_SCULPT;
3961 }
3962 
3964 {
3965  return (SCULPT_mode_poll(C) && CTX_wm_region_view3d(C));
3966 }
3967 
3969 {
3970  return (SCULPT_poll(C) && CTX_wm_region_view3d(C));
3971 }
3972 
3974 {
3976 }
3977 
3978 static const char *sculpt_tool_name(Sculpt *sd)
3979 {
3980  Brush *brush = BKE_paint_brush(&sd->paint);
3981 
3982  switch ((eBrushSculptTool)brush->sculpt_tool) {
3983  case SCULPT_TOOL_DRAW:
3984  return "Draw Brush";
3985  case SCULPT_TOOL_SMOOTH:
3986  return "Smooth Brush";
3987  case SCULPT_TOOL_CREASE:
3988  return "Crease Brush";
3989  case SCULPT_TOOL_BLOB:
3990  return "Blob Brush";
3991  case SCULPT_TOOL_PINCH:
3992  return "Pinch Brush";
3993  case SCULPT_TOOL_INFLATE:
3994  return "Inflate Brush";
3995  case SCULPT_TOOL_GRAB:
3996  return "Grab Brush";
3997  case SCULPT_TOOL_NUDGE:
3998  return "Nudge Brush";
3999  case SCULPT_TOOL_THUMB:
4000  return "Thumb Brush";
4001  case SCULPT_TOOL_LAYER:
4002  return "Layer Brush";
4003  case SCULPT_TOOL_FLATTEN:
4004  return "Flatten Brush";
4005  case SCULPT_TOOL_CLAY:
4006  return "Clay Brush";
4008  return "Clay Strips Brush";
4010  return "Clay Thumb Brush";
4011  case SCULPT_TOOL_FILL:
4012  return "Fill Brush";
4013  case SCULPT_TOOL_SCRAPE:
4014  return "Scrape Brush";
4016  return "Snake Hook Brush";
4017  case SCULPT_TOOL_ROTATE:
4018  return "Rotate Brush";
4019  case SCULPT_TOOL_MASK:
4020  return "Mask Brush";
4021  case SCULPT_TOOL_SIMPLIFY:
4022  return "Simplify Brush";
4024  return "Draw Sharp Brush";
4026  return "Elastic Deform Brush";
4027  case SCULPT_TOOL_POSE:
4028  return "Pose Brush";
4030  return "Multi-plane Scrape Brush";
4032  return "Slide/Relax Brush";
4033  case SCULPT_TOOL_BOUNDARY:
4034  return "Boundary Brush";
4035  case SCULPT_TOOL_CLOTH:
4036  return "Cloth Brush";
4038  return "Draw Face Sets";
4040  return "Multires Displacement Eraser";
4042  return "Multires Displacement Smear";
4043  case SCULPT_TOOL_PAINT:
4044  return "Paint Brush";
4045  case SCULPT_TOOL_SMEAR:
4046  return "Smear Brush";
4047  }
4048 
4049  return "Sculpting";
4050 }
4051 
4052 /* Operator for applying a stroke (various attributes including mouse path)
4053  * using the current brush. */
4054 
4056 {
4057  MEM_SAFE_FREE(cache->dial);
4060  MEM_SAFE_FREE(cache->prev_colors);
4065 
4066  if (cache->pose_ik_chain) {
4068  }
4069 
4070  for (int i = 0; i < PAINT_SYMM_AREAS; i++) {
4071  if (cache->boundaries[i]) {
4073  }
4074  }
4075 
4076  if (cache->cloth_sim) {
4078  }
4079 
4080  MEM_freeN(cache);
4081 }
4082 
4083 /* Initialize mirror modifier clipping. */
4085 {
4086  ModifierData *md;
4087 
4089 
4090  for (md = ob->modifiers.first; md; md = md->next) {
4091  if (!(md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime))) {
4092  continue;
4093  }
4095 
4096  if (!(mmd->flag & MOD_MIR_CLIPPING)) {
4097  continue;
4098  }
4099  /* Check each axis for mirroring. */
4100  for (int i = 0; i < 3; i++) {
4101  if (!(mmd->flag & (MOD_MIR_AXIS_X << i))) {
4102  continue;
4103  }
4104  /* Enable sculpt clipping. */
4105  ss->cache->flag |= CLIP_X << i;
4106 
4107  /* Update the clip tolerance. */
4108  if (mmd->tolerance > ss->cache->clip_tolerance[i]) {
4109  ss->cache->clip_tolerance[i] = mmd->tolerance;
4110  }
4111 
4112  /* Store matrix for mirror object clipping. */
4113  if (mmd->mirror_ob) {
4114  float imtx_mirror_ob[4][4];
4115  invert_m4_m4(imtx_mirror_ob, mmd->mirror_ob->obmat);
4116  mul_m4_m4m4(ss->cache->clip_mirror_mtx, imtx_mirror_ob, ob->obmat);
4117  }
4118  }
4119  }
4120 }
4121 
4122 static void smooth_brush_toggle_on(const bContext *C, Paint *paint, StrokeCache *cache)
4123 {
4125  Brush *brush = paint->brush;
4126 
4127  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
4128  cache->saved_mask_brush_tool = brush->mask_tool;
4129  brush->mask_tool = BRUSH_MASK_SMOOTH;
4130  }
4131  else if (ELEM(brush->sculpt_tool,
4135  SCULPT_TOOL_SMEAR)) {
4136  /* Do nothing, this tool has its own smooth mode. */
4137  }
4138  else {
4139  int cur_brush_size = BKE_brush_size_get(scene, brush);
4140 
4142  brush->id.name + 2,
4143  sizeof(cache->saved_active_brush_name));
4144 
4145  /* Switch to the smooth brush. */
4147  if (brush) {
4148  BKE_paint_brush_set(paint, brush);
4149  cache->saved_smooth_size = BKE_brush_size_get(scene, brush);
4150  BKE_brush_size_set(scene, brush, cur_brush_size);
4151  BKE_curvemapping_init(brush->curve);
4152  }
4153  }
4154 }
4155 
4156 static void smooth_brush_toggle_off(const bContext *C, Paint *paint, StrokeCache *cache)
4157 {
4158  Main *bmain = CTX_data_main(C);
4160  Brush *brush = BKE_paint_brush(paint);
4161 
4162  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
4163  brush->mask_tool = cache->saved_mask_brush_tool;
4164  }
4165  else if (ELEM(brush->sculpt_tool,
4169  SCULPT_TOOL_SMEAR)) {
4170  /* Do nothing. */
4171  }
4172  else {
4173  /* Try to switch back to the saved/previous brush. */
4174  BKE_brush_size_set(scene, brush, cache->saved_smooth_size);
4175  brush = (Brush *)BKE_libblock_find_name(bmain, ID_BR, cache->saved_active_brush_name);
4176  if (brush) {
4177  BKE_paint_brush_set(paint, brush);
4178  }
4179  }
4180 }
4181 
4182 /* Initialize the stroke cache invariants from operator properties. */
4184  bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mval[2])
4185 {
4186  StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache");
4188  Brush *brush = BKE_paint_brush(&sd->paint);
4191  float mat[3][3];
4192  float viewDir[3] = {0.0f, 0.0f, 1.0f};
4193  float max_scale;
4194  int mode;
4195 
4196  ss->cache = cache;
4197 
4198  /* Set scaling adjustment. */
4199  max_scale = 0.0f;
4200  for (int i = 0; i < 3; i++) {
4201  max_scale = max_ff(max_scale, fabsf(ob->scale[i]));
4202  }
4203  cache->scale[0] = max_scale / ob->scale[0];
4204  cache->scale[1] = max_scale / ob->scale[1];
4205  cache->scale[2] = max_scale / ob->scale[2];
4206 
4207  cache->plane_trim_squared = brush->plane_trim * brush->plane_trim;
4208 
4209  cache->flag = 0;
4210 
4212 
4213  /* Initial mouse location. */
4214  if (mval) {
4215  copy_v2_v2(cache->initial_mouse, mval);
4216  }
4217  else {
4218  zero_v2(cache->initial_mouse);
4219  }
4220 
4223 
4226 
4227  mode = RNA_enum_get(op->ptr, "mode");
4228  cache->invert = mode == BRUSH_STROKE_INVERT;
4229  cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH;
4230  cache->normal_weight = brush->normal_weight;
4231 
4232  /* Interpret invert as following normal, for grab brushes. */
4234  if (cache->invert) {
4235  cache->invert = false;
4236  cache->normal_weight = (cache->normal_weight == 0.0f);
4237  }
4238  }
4239 
4240  /* Not very nice, but with current events system implementation
4241  * we can't handle brush appearance inversion hotkey separately (sergey). */
4242  if (cache->invert) {
4243  ups->draw_inverted = true;
4244  }
4245  else {
4246  ups->draw_inverted = false;
4247  }
4248 
4249  /* Alt-Smooth. */
4250  if (cache->alt_smooth) {
4251  smooth_brush_toggle_on(C, &sd->paint, cache);
4252  /* Refresh the brush pointer in case we switched brush in the toggle function. */
4253  brush = BKE_paint_brush(&sd->paint);
4254  }
4255 
4256  copy_v2_v2(cache->mouse, cache->initial_mouse);
4257  copy_v2_v2(cache->mouse_event, cache->initial_mouse);
4258  copy_v2_v2(ups->tex_mouse, cache->initial_mouse);
4259 
4260  /* Truly temporary data that isn't stored in properties. */
4261  cache->vc = vc;
4262  cache->brush = brush;
4263 
4264  /* Cache projection matrix. */
4265  ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat);
4266 
4267  invert_m4_m4(ob->imat, ob->obmat);
4268  copy_m3_m4(mat, cache->vc->rv3d->viewinv);
4269  mul_m3_v3(mat, viewDir);
4270  copy_m3_m4(mat, ob->imat);
4271  mul_m3_v3(mat, viewDir);
4272  normalize_v3_v3(cache->true_view_normal, viewDir);
4273 
4274  cache->supports_gravity = (!ELEM(brush->sculpt_tool,
4280  (sd->gravity_factor > 0.0f));
4281  /* Get gravity vector in world space. */
4282  if (cache->supports_gravity) {
4283  if (sd->gravity_object) {
4284  Object *gravity_object = sd->gravity_object;
4285 
4286  copy_v3_v3(cache->true_gravity_direction, gravity_object->obmat[2]);
4287  }
4288  else {
4289  cache->true_gravity_direction[0] = cache->true_gravity_direction[1] = 0.0f;
4290  cache->true_gravity_direction[2] = 1.0f;
4291  }
4292 
4293  /* Transform to sculpted object space. */
4294  mul_m3_v3(mat, cache->true_gravity_direction);
4296  }
4297 
4298  /* Make copies of the mesh vertex locations and normals for some tools. */
4299  if (brush->flag & BRUSH_ANCHORED) {
4300  cache->original = true;
4301  }
4302 
4303  /* Draw sharp does not need the original coordinates to produce the accumulate effect, so it
4304  * should work the opposite way. */
4305  if (brush->sculpt_tool == SCULPT_TOOL_DRAW_SHARP) {
4306  cache->original = true;
4307  }
4308 
4310  if (!(brush->flag & BRUSH_ACCUMULATE)) {
4311  cache->original = true;
4312  if (brush->sculpt_tool == SCULPT_TOOL_DRAW_SHARP) {
4313  cache->original = false;
4314  }
4315  }
4316  }
4317 
4318  cache->first_time = true;
4319 
4320 #define PIXEL_INPUT_THRESHHOLD 5
4321  if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) {
4323  }
4324 
4325 #undef PIXEL_INPUT_THRESHHOLD
4326 }
4327 
4328 static float sculpt_brush_dynamic_size_get(Brush *brush, StrokeCache *cache, float initial_size)
4329 {
4330  switch (brush->sculpt_tool) {
4331  case SCULPT_TOOL_CLAY:
4332  return max_ff(initial_size * 0.20f, initial_size * pow3f(cache->pressure));
4334  return max_ff(initial_size * 0.30f, initial_size * powf(cache->pressure, 1.5f));
4335  case SCULPT_TOOL_CLAY_THUMB: {
4336  float clay_stabilized_pressure = SCULPT_clay_thumb_get_stabilized_pressure(cache);
4337  return initial_size * clay_stabilized_pressure;
4338  }
4339  default:
4340  return initial_size * cache->pressure;
4341  }
4342 }
4343 
4344 /* In these brushes the grab delta is calculated always from the initial stroke location, which is
4345  * generally used to create grab deformations. */
4347 {
4348  if (brush->sculpt_tool == SCULPT_TOOL_SMEAR && (brush->flag & BRUSH_ANCHORED)) {
4349  return true;
4350  }
4351 
4352  if (ELEM(brush->sculpt_tool,
4358  return true;
4359  }
4360  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH &&
4362  return true;
4363  }
4364  return false;
4365 }
4366 
4367 /* In these brushes the grab delta is calculated from the previous stroke location, which is used
4368  * to calculate to orientate the brush tip and deformation towards the stroke direction. */
4370 {
4371  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
4372  return brush->cloth_deform_type != BRUSH_CLOTH_DEFORM_GRAB;
4373  }
4374  return ELEM(brush->sculpt_tool,
4381 }
4382 
4384 {
4385  SculptSession *ss = ob->sculpt;
4386  StrokeCache *cache = ss->cache;
4387  const float mval[2] = {
4388  cache->mouse_event[0],
4389  cache->mouse_event[1],
4390  };
4391  int tool = brush->sculpt_tool;
4392 
4393  if (!ELEM(tool,
4407  SCULPT_TOOL_THUMB) &&
4408  !sculpt_brush_use_topology_rake(ss, brush)) {
4409  return;
4410  }
4411  float grab_location[3], imat[4][4], delta[3], loc[3];
4412 
4414  if (tool == SCULPT_TOOL_GRAB && brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) {
4417  }
4418  else {
4420  }
4421  }
4422  else if (tool == SCULPT_TOOL_SNAKE_HOOK ||
4423  (tool == SCULPT_TOOL_CLOTH &&
4425  add_v3_v3(cache->true_location, cache->grab_delta);
4426  }
4427 
4428  /* Compute 3d coordinate at same z from original location + mval. */
4429  mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location);
4430  ED_view3d_win_to_3d(cache->vc->v3d, cache->vc->region, loc, mval, grab_location);
4431 
4432  /* Compute delta to move verts by. */
4435  sub_v3_v3v3(delta, grab_location, cache->old_grab_location);
4436  invert_m4_m4(imat, ob->obmat);
4437  mul_mat3_m4_v3(imat, delta);
4438  add_v3_v3(cache->grab_delta, delta);
4439  }
4440  else if (sculpt_needs_delta_for_tip_orientation(brush)) {
4441  if (brush->flag & BRUSH_ANCHORED) {
4442  float orig[3];
4443  mul_v3_m4v3(orig, ob->obmat, cache->orig_grab_location);
4444  sub_v3_v3v3(cache->grab_delta, grab_location, orig);
4445  }
4446  else {
4447  sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location);
4448  }
4449  invert_m4_m4(imat, ob->obmat);
4450  mul_mat3_m4_v3(imat, cache->grab_delta);
4451  }
4452  else {
4453  /* Use for 'Brush.topology_rake_factor'. */
4454  sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location);
4455  }
4456  }
4457  else {
4458  zero_v3(cache->grab_delta);
4459  }
4460 
4461  if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
4463  }
4464 
4465  copy_v3_v3(cache->old_grab_location, grab_location);
4466 
4467  if (tool == SCULPT_TOOL_GRAB) {
4468  if (brush->flag & BRUSH_GRAB_ACTIVE_VERTEX) {
4470  }
4471  else {
4472  copy_v3_v3(cache->anchored_location, cache->true_location);
4473  }
4474  }
4475  else if (tool == SCULPT_TOOL_ELASTIC_DEFORM || SCULPT_is_cloth_deform_brush(brush)) {
4476  copy_v3_v3(cache->anchored_location, cache->true_location);
4477  }
4478  else if (tool == SCULPT_TOOL_THUMB) {
4480  }
4481 
4483  /* Location stays the same for finding vertices in brush radius. */
4485 
4486  ups->draw_anchored = true;
4488  ups->anchored_size = ups->pixel_radius;
4489  }
4490 
4491  /* Handle 'rake' */
4492  cache->is_rake_rotation_valid = false;
4493 
4494  invert_m4_m4(imat, ob->obmat);
4495  mul_mat3_m4_v3(imat, grab_location);
4496 
4498  copy_v3_v3(cache->rake_data.follow_co, grab_location);
4499  }
4500 
4501  if (!sculpt_brush_needs_rake_rotation(brush)) {
4502  return;
4503  }
4505 
4506  if (!is_zero_v3(cache->grab_delta)) {
4507  const float eps = 0.00001f;
4508 
4509  float v1[3], v2[3];
4510 
4511  copy_v3_v3(v1, cache->rake_data.follow_co);
4512  copy_v3_v3(v2, cache->rake_data.follow_co);
4513  sub_v3_v3(v2, cache->grab_delta);
4514 
4515  sub_v3_v3(v1, grab_location);
4516  sub_v3_v3(v2, grab_location);
4517 
4518  if ((normalize_v3(v2) > eps) && (normalize_v3(v1) > eps) && (len_squared_v3v3(v1, v2) > eps)) {
4519  const float rake_dist_sq = len_squared_v3v3(cache->rake_data.follow_co, grab_location);
4520  const float rake_fade = (rake_dist_sq > square_f(cache->rake_data.follow_dist)) ?
4521  1.0f :
4522  sqrtf(rake_dist_sq) / cache->rake_data.follow_dist;
4523 
4524  float axis[3], angle;
4525  float tquat[4];
4526 
4528 
4529  /* Use axis-angle to scale rotation since the factor may be above 1. */
4530  quat_to_axis_angle(axis, &angle, tquat);
4531  normalize_v3(axis);
4532 
4533  angle *= brush->rake_factor * rake_fade;
4535  cache->is_rake_rotation_valid = true;
4536  }
4537  }
4538  sculpt_rake_data_update(&cache->rake_data, grab_location);
4539 }
4540 
4541 static void sculpt_update_cache_paint_variants(StrokeCache *cache, const Brush *brush)
4542 {
4543  cache->paint_brush.hardness = brush->hardness;
4546  1.0f - cache->pressure :
4547  cache->pressure;
4548  }
4549 
4550  cache->paint_brush.flow = brush->flow;
4551  if (brush->paint_flags & BRUSH_PAINT_FLOW_PRESSURE) {
4553  1.0f - cache->pressure :
4554  cache->pressure;
4555  }
4556 
4557  cache->paint_brush.wet_mix = brush->wet_mix;
4560  1.0f - cache->pressure :
4561  cache->pressure;
4562 
4563  /* This makes wet mix more sensible in higher values, which allows to create brushes that have
4564  * a wider pressure range were they only blend colors without applying too much of the brush
4565  * color. */
4566  cache->paint_brush.wet_mix = 1.0f - pow2f(1.0f - cache->paint_brush.wet_mix);
4567  }
4568 
4571  cache->paint_brush.wet_persistence = brush->paint_flags &
4573  1.0f - cache->pressure :
4574  cache->pressure;
4575  }
4576 
4577  cache->paint_brush.density = brush->density;
4580  1.0f - cache->pressure :
4581  cache->pressure;
4582  }
4583 }
4584 
4585 /* Initialize the stroke cache variants from operator properties. */
4587 {
4590  SculptSession *ss = ob->sculpt;
4591  StrokeCache *cache = ss->cache;
4592  Brush *brush = BKE_paint_brush(&sd->paint);
4593 
4595  !((brush->flag & BRUSH_ANCHORED) || (brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK) ||
4597  RNA_float_get_array(ptr, "location", cache->true_location);
4598  }
4599 
4600  cache->pen_flip = RNA_boolean_get(ptr, "pen_flip");
4601  RNA_float_get_array(ptr, "mouse", cache->mouse);
4602  RNA_float_get_array(ptr, "mouse_event", cache->mouse_event);
4603 
4604  /* XXX: Use pressure value from first brush step for brushes which don't support strokes (grab,
4605  * thumb). They depends on initial state and brush coord/pressure/etc.
4606  * It's more an events design issue, which doesn't split coordinate/pressure/angle changing
4607  * events. We should avoid this after events system re-design. */
4609  cache->pressure = RNA_float_get(ptr, "pressure");
4610  }
4611 
4612  cache->x_tilt = RNA_float_get(ptr, "x_tilt");
4613  cache->y_tilt = RNA_float_get(ptr, "y_tilt");
4614 
4615  /* Truly temporary data that isn't stored in properties. */
4617  if (!BKE_brush_use_locked_size(scene, brush)) {
4619  cache->vc, cache->true_location, BKE_brush_size_get(scene, brush));
4621  }
4622  else {
4624  }
4625  }
4626 
4627  /* Clay stabilized pressure. */
4628  if (brush->sculpt_tool == SCULPT_TOOL_CLAY_THUMB) {
4630  for (int i = 0; i < SCULPT_CLAY_STABILIZER_LEN; i++) {
4631  ss->cache->clay_pressure_stabilizer[i] = 0.0f;
4632  }
4634  }
4635  else {
4637  cache->clay_pressure_stabilizer_index += 1;
4639  cache->clay_pressure_stabilizer_index = 0;
4640  }
4641  }
4642  }
4643 
4644  if (BKE_brush_use_size_pressure(brush) &&
4646  cache->radius = sculpt_brush_dynamic_size_get(brush, cache, cache->initial_radius);
4648  brush, cache, ups->initial_pixel_radius);
4649  }
4650  else {
4651  cache->radius = cache->initial_radius;
4653  }
4654 
4655  sculpt_update_cache_paint_variants(cache, brush);
4656 
4657  cache->radius_squared = cache->radius * cache->radius;
4658 
4659  if (brush->flag & BRUSH_ANCHORED) {
4660  /* True location has been calculated as part of the stroke system already here. */
4661  if (brush->flag & BRUSH_EDGE_TO_EDGE) {
4662  RNA_float_get_array(ptr, "location", cache->true_location);
4663  }
4664 
4666  cache->vc, cache->true_location, ups->pixel_radius);
4667  cache->radius_squared = cache->radius * cache->radius;
4668 
4669  copy_v3_v3(cache->anchored_location, cache->true_location);
4670  }
4671 
4672  sculpt_update_brush_delta(ups, ob, brush);
4673 
4674  if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) {
4675  cache->vertex_rotation = -BLI_dial_angle(cache->dial, cache->mouse) * cache->bstrength;
4676 
4677  ups->draw_anchored = true;
4679  copy_v3_v3(cache->anchored_location, cache->true_location);
4680  ups->anchored_size = ups->pixel_radius;
4681  }
4682 
4683  cache->special_rotation = ups->brush_rotation;
4684 
4685  cache->iteration_count++;
4686 }
4687 
4688 /* Returns true if any of the smoothing modes are active (currently
4689  * one of smooth brush, autosmooth, mask smooth, or shift-key
4690  * smooth). */
4692  const Brush *brush,
4693  SculptSession *ss,
4694  int stroke_mode)
4695 {
4696  if (ss && ss->pbvh && SCULPT_is_automasking_enabled(sd, ss, brush)) {
4697  return true;
4698  }
4699  return ((stroke_mode == BRUSH_STROKE_SMOOTH) || (ss && ss->cache && ss->cache->alt_smooth) ||
4700  (brush->sculpt_tool == SCULPT_TOOL_SMOOTH) || (brush->autosmooth_factor > 0) ||
4701  ((brush->sculpt_tool == SCULPT_TOOL_MASK) && (brush->mask_tool == BRUSH_MASK_SMOOTH)) ||
4702  (brush->sculpt_tool == SCULPT_TOOL_POSE) ||
4703  (brush->sculpt_tool == SCULPT_TOOL_BOUNDARY) ||
4704  (brush->sculpt_tool == SCULPT_TOOL_SLIDE_RELAX) ||
4706  (brush->sculpt_tool == SCULPT_TOOL_SMEAR) ||
4709  (brush->sculpt_tool == SCULPT_TOOL_PAINT));
4710 }
4711 
4712 void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush)
4713 {
4714  SculptSession *ss = ob->sculpt;
4717 
4718  bool need_pmap = sculpt_needs_connectivity_info(sd, brush, ss, 0);
4719  if (ss->shapekey_active || ss->deform_modifiers_active ||
4720  (!BKE_sculptsession_use_pbvh_draw(ob, rv3d) && need_pmap)) {
4723  depsgraph, ob, need_pmap, false, SCULPT_tool_is_paint(brush->sculpt_tool));
4724  }
4725 }
4726 
4727 static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
4728 {
4729  if (BKE_pbvh_node_get_tmin(node) >= *tmin) {
4730  return;
4731  }
4732  SculptRaycastData *srd = data_v;
4733  float(*origco)[3] = NULL;
4734  bool use_origco = false;
4735 
4736  if (srd->original && srd->ss->cache) {
4737  if (BKE_pbvh_type(srd->ss->pbvh) == PBVH_BMESH) {
4738  use_origco = true;
4739  }
4740  else {
4741  /* Intersect with coordinates from before we started stroke. */
4743  origco = (unode) ? unode->co : NULL;
4744  use_origco = origco ? true : false;
4745  }
4746  }
4747 
4748  if (BKE_pbvh_node_raycast(srd->ss->pbvh,
4749  node,
4750  origco,
4751  use_origco,
4752  srd->ray_start,
4753  srd->ray_normal,
4754  &srd->isect_precalc,
4755  &srd->depth,
4756  &srd->active_vertex_index,
4757  &srd->active_face_grid_index,
4758  srd->face_normal)) {
4759  srd->hit = true;
4760  *tmin = srd->depth;
4761  }
4762 }
4763 
4764 static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *tmin)
4765 {
4766  if (BKE_pbvh_node_get_tmin(node) >= *tmin) {
4767  return;
4768  }
4769  SculptFindNearestToRayData *srd = data_v;
4770  float(*origco)[3] = NULL;
4771  bool use_origco = false;
4772 
4773  if (srd->original && srd->ss->cache) {
4774  if (BKE_pbvh_type(srd->ss->pbvh) == PBVH_BMESH) {
4775  use_origco = true;
4776  }
4777  else {
4778  /* Intersect with coordinates from before we started stroke. */
4780  origco = (unode) ? unode->co : NULL;
4781  use_origco = origco ? true : false;
4782  }
4783  }
4784 
4786  node,
4787  origco,
4788  use_origco,
4789  srd->ray_start,
4790  srd->ray_normal,
4791  &srd->depth,
4792  &srd->dist_sq_to_ray)) {
4793  srd->hit = true;
4794  *tmin = srd->dist_sq_to_ray;
4795  }
4796 }
4797 
4799  const float mval[2],
4800  float ray_start[3],
4801  float ray_end[3],
4802  float ray_normal[3],
4803  bool original)
4804 {
4805  float obimat[4][4];
4806  float dist;
4807  Object *ob = vc->obact;
4808  RegionView3D *rv3d = vc->region->regiondata;
4809  View3D *v3d = vc->v3d;
4810 
4811  /* TODO: what if the segment is totally clipped? (return == 0). */
4813  vc->depsgraph, vc->region, vc->v3d, mval, ray_start, ray_end, true);
4814 
4815  invert_m4_m4(obimat, ob->obmat);
4816  mul_m4_v3(obimat, ray_start);
4817  mul_m4_v3(obimat, ray_end);
4818 
4819  sub_v3_v3v3(ray_normal, ray_end, ray_start);
4820  dist = normalize_v3(ray_normal);
4821 
4822  if ((rv3d->is_persp == false) &&
4823  /* If the ray is clipped, don't adjust its start/end. */
4824  !RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
4825  BKE_pbvh_raycast_project_ray_root(ob->sculpt->pbvh, original, ray_start, ray_end, ray_normal);
4826 
4827  /* rRecalculate the normal. */
4828  sub_v3_v3v3(ray_normal, ray_end, ray_start);
4829  dist = normalize_v3(ray_normal);
4830  }
4831 
4832  return dist;
4833 }
4834 
4837  const float mval[2],
4838  bool use_sampled_normal)
4839 {
4842  Sculpt *sd = scene->toolsettings->sculpt;
4843  Object *ob;
4844  SculptSession *ss;
4845  ViewContext vc;
4847  float ray_start[3], ray_end[3], ray_normal[3], depth, face_normal[3], sampled_normal[3],
4848  mat[3][3];
4849  float viewDir[3] = {0.0f, 0.0f, 1.0f};
4850  int totnode;
4851  bool original = false;
4852 
4854 
4855  ob = vc.obact;
4856  ss = ob->sculpt;
4857 
4858  if (!ss->pbvh) {
4859  zero_v3(out->location);
4860  zero_v3(out->normal);
4861  zero_v3(out->active_vertex_co);
4862  return false;
4863  }
4864 
4865  /* PBVH raycast to get active vertex and face normal. */
4866  depth = SCULPT_raycast_init(&vc, mval, ray_start, ray_end, ray_normal, original);
4867  SCULPT_stroke_modifiers_check(C, ob, brush);
4868 
4869  SculptRaycastData srd = {
4870  .original = original,
4871  .ss = ob->sculpt,
4872  .hit = false,
4873  .ray_start = ray_start,
4874  .ray_normal = ray_normal,
4875  .depth = depth,
4876  .face_normal = face_normal,
4877  };
4879  BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, ray_start, ray_normal, srd.original);
4880 
4881  /* Cursor is not over the mesh, return default values. */
4882  if (!srd.hit) {
4883  zero_v3(out->location);
4884  zero_v3(out->normal);
4885  zero_v3(out->active_vertex_co);
4886  return false;
4887  }
4888 
4889  /* Update the active vertex of the SculptSession. */
4892  copy_v3_v3(out->active_vertex_co, SCULPT_active_vertex_co_get(ss));
4893 
4894  switch (BKE_pbvh_type(ss->pbvh)) {
4895  case PBVH_FACES:
4897  ss->active_grid_index = 0;
4898  break;
4899  case PBVH_GRIDS:
4900  ss->active_face_index = 0;
4902  break;
4903  case PBVH_BMESH:
4904  ss->active_face_index = 0;
4905  ss->active_grid_index = 0;
4906  break;
4907  }
4908 
4909  copy_v3_v3(out->location, ray_normal);
4910  mul_v3_fl(out->location, srd.depth);
4911  add_v3_v3(out->location, ray_start);
4912 
4913  /* Option to return the face normal directly for performance o accuracy reasons. */
4914  if (!use_sampled_normal) {
4915  copy_v3_v3(out->normal, srd.face_normal);
4916  return srd.hit;
4917  }
4918 
4919  /* Sampled normal calculation. */
4920  float radius;
4921 
4922  /* Update cursor data in SculptSession. */
4923  invert_m4_m4(ob->imat, ob->obmat);
4924  copy_m3_m4(mat, vc.rv3d->viewinv);
4925  mul_m3_v3(mat, viewDir);
4926  copy_m3_m4(mat, ob->imat);
4927  mul_m3_v3(mat, viewDir);
4928  normalize_v3_v3(ss->cursor_view_normal, viewDir);
4930  copy_v3_v3(ss->cursor_location, out->location);
4931  ss->rv3d = vc.rv3d;
4932  ss->v3d = vc.v3d;
4933 
4934  if (!BKE_brush_use_locked_size(scene, brush)) {
4935  radius = paint_calc_object_space_radius(&vc, out->location, BKE_brush_size_get(scene, brush));
4936  }
4937  else {
4938  radius = BKE_brush_unprojected_radius_get(scene, brush);
4939  }
4940  ss->cursor_radius = radius;
4941 
4942  PBVHNode **nodes = sculpt_pbvh_gather_cursor_update(ob, sd, original, &totnode);
4943 
4944  /* In case there are no nodes under the cursor, return the face normal. */
4945  if (!totnode) {
4946  MEM_SAFE_FREE(nodes);
4947  copy_v3_v3(out->normal, srd.face_normal);
4948  return true;
4949  }
4950 
4951  /* Calculate the sampled normal. */
4952  if (SCULPT_pbvh_calc_area_normal(brush, ob, nodes, totnode, true, sampled_normal)) {
4953  copy_v3_v3(out->normal, sampled_normal);
4954  copy_v3_v3(ss->cursor_sampled_normal, sampled_normal);
4955  }
4956  else {
4957  /* Use face normal when there are no vertices to sample inside the cursor radius. */
4958  copy_v3_v3(out->normal, srd.face_normal);
4959  }
4960  MEM_SAFE_FREE(nodes);
4961  return true;
4962 }
4963 
4965  float out[3],
4966  const float mval[2],
4967  bool force_original)
4968 {
4970  Object *ob;
4971  SculptSession *ss;
4972  StrokeCache *cache;
4973  float ray_start[3], ray_end[3], ray_normal[3], depth, face_normal[3];
4974  bool original;
4975  ViewContext vc;
4976 
4978 
4979  ob = vc.obact;
4980 
4981  ss = ob->sculpt;
4982  cache = ss->cache;
4983  original = force_original || ((cache) ? cache->original : false);
4984 
4986 
4987  SCULPT_stroke_modifiers_check(C, ob, brush);
4988 
4989  depth = SCULPT_raycast_init(&vc, mval, ray_start, ray_end, ray_normal, original);
4990 
4991  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
4994  }
4995 
4996  bool hit = false;
4997  {
4998  SculptRaycastData srd;
4999  srd.ss = ob->sculpt;
5000  srd.ray_start = ray_start;
5001  srd.ray_normal = ray_normal;
5002  srd.hit = false;
5003  srd.depth = depth;
5004  srd.original = original;
5005  srd.face_normal = face_normal;
5007 
5008  BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, ray_start, ray_normal, srd.original);
5009  if (srd.hit) {
5010  hit = true;
5011  copy_v3_v3(out, ray_normal);
5012  mul_v3_fl(out, srd.depth);
5013  add_v3_v3(out, ray_start);
5014  }
5015  }
5016 
5017  if (hit) {
5018  return hit;
5019  }
5020 
5022  return hit;
5023  }
5024 
5026  .original = original,
5027  .ss = ob->sculpt,
5028  .hit = false,
5029  .ray_start = ray_start,
5030  .ray_normal = ray_normal,
5031  .depth = FLT_MAX,
5032  .dist_sq_to_ray = FLT_MAX,
5033  };
5035  ss->pbvh, sculpt_find_nearest_to_ray_cb, &srd, ray_start, ray_normal, srd.original);
5036  if (srd.hit) {
5037  hit = true;
5038  copy_v3_v3(out, ray_normal);
5039  mul_v3_fl(out, srd.depth);
5040  add_v3_v3(out, ray_start);
5041  }
5042 
5043  return hit;
5044 }
5045 
5047 {
5048  Brush *brush = BKE_paint_brush(&sd->paint);
5049  MTex *mtex = &brush->mtex;
5050 
5051  /* Init mtex nodes. */
5052  if (mtex->tex && mtex->tex->nodetree) {
5053  /* Has internal flag to detect it only does it once. */
5055  }
5056 
5057  if (ss->tex_pool == NULL) {
5058  ss->tex_pool = BKE_image_pool_new();
5059  }
5060 }
5061 
5063 {
5065  ToolSettings *tool_settings = CTX_data_tool_settings(C);
5066  Sculpt *sd = tool_settings->sculpt;
5068  Brush *brush = BKE_paint_brush(&sd->paint);
5069  int mode = RNA_enum_get(op->ptr, "mode");
5070  bool need_pmap, needs_colors;
5071  bool need_mask = false;
5072 
5073  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
5074  need_mask = true;
5075  }
5076 
5077  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH ||
5079  need_mask = true;
5080  }
5081 
5083  sculpt_brush_init_tex(sd, ss);
5084 
5085  need_pmap = sculpt_needs_connectivity_info(sd, brush, ss, mode);
5086  needs_colors = SCULPT_tool_is_paint(brush->sculpt_tool) &&
5087  !SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob);
5088 
5089  if (needs_colors) {
5091  }
5092 
5093  /* CTX_data_ensure_evaluated_depsgraph should be used at the end to include the updates of
5094  * earlier steps modifying the data. */
5097  depsgraph, ob, need_pmap, need_mask, SCULPT_tool_is_paint(brush->sculpt_tool));
5098 
5100 }
5101 
5102 static void sculpt_restore_mesh(Sculpt *sd, Object *ob)
5103 {
5104  SculptSession *ss = ob->sculpt;
5105  Brush *brush = BKE_paint_brush(&sd->paint);
5106 
5107  /* For the cloth brush it makes more sense to not restore the mesh state to keep running the
5108  * simulation from the previous state. */
5109  if (brush->sculpt_tool == SCULPT_TOOL_CLOTH) {
5110  return;
5111  }
5112 
5113  /* Restore the mesh before continuing with anchored stroke. */
5114  if ((brush->flag & BRUSH_ANCHORED) ||
5116  BKE_brush_use_size_pressure(brush)) ||
5117  (brush->flag & BRUSH_DRAG_DOT)) {
5118 
5120  if (unode && unode->type == SCULPT_UNDO_FACE_SETS) {
5121  for (int i = 0; i < ss->totfaces; i++) {
5122  ss->face_sets[i] = unode->face_sets[i];
5123  }
5124  }
5125 
5126  paint_mesh_restore_co(sd, ob);
5127 
5128  if (ss->cache) {
5130  }
5131  }
5132 }
5133 
5135 {
5136  if (ob->runtime.bb) {
5137  float bb_min[3], bb_max[3];
5138 
5139  BKE_pbvh_bounding_box(ob->sculpt->pbvh, bb_min, bb_max);
5140  BKE_boundbox_init_from_minmax(ob->runtime.bb, bb_min, bb_max);
5141  }
5142 }
5143 
5145 {
5148  SculptSession *ss = ob->sculpt;
5149  ARegion *region = CTX_wm_region(C);
5152 
5153  if (rv3d) {
5154  /* Mark for faster 3D viewport redraws. */
5155  rv3d->rflag |= RV3D_PAINTING;
5156  }
5157 
5158  if (mmd != NULL) {
5160  }
5161 
5162  if ((update_flags & SCULPT_UPDATE_IMAGE) != 0) {
5163  ED_region_tag_redraw(region);
5164  if (update_flags == SCULPT_UPDATE_IMAGE) {
5165  /* Early exit when only need to update the images. We don't want to tag any geometry updates
5166  * that would rebuilt the PBVH. */
5167  return;
5168  }
5169  }
5170 
5172 
5173  /* Only current viewport matters, slower update for all viewports will
5174  * be done in sculpt_flush_update_done. */
5175  if (!BKE_sculptsession_use_pbvh_draw(ob, rv3d)) {
5176  /* Slow update with full dependency graph update and all that comes with it.
5177  * Needed when there are modifiers or full shading in the 3D viewport. */
5179  ED_region_tag_redraw(region);
5180  }
5181  else {
5182  /* Fast path where we just update the BVH nodes that changed, and redraw
5183  * only the part of the 3D viewport where changes happened. */
5184  rcti r;
5185 
5186  if (update_flags & SCULPT_UPDATE_COORDS) {
5188  /* Update the object's bounding box too so that the object
5189  * doesn't get incorrectly clipped during drawing in
5190  * draw_mesh_object(). T33790. */
5192  }
5193 
5194  if (SCULPT_get_redraw_rect(region, CTX_wm_region_view3d(C), ob, &r)) {
5195  if (ss->cache) {
5196  ss->cache->current_r = r;
5197  }
5198 
5199  /* previous is not set in the current cache else
5200  * the partial rect will always grow */
5202 
5203  r.xmin += region->winrct.xmin - 2;
5204  r.xmax += region->winrct.xmin + 2;
5205  r.ymin += region->winrct.ymin - 2;
5206  r.ymax += region->winrct.ymin + 2;
5207  ED_region_tag_redraw_partial(region, &r, true);
5208  }
5209  }
5210 }
5211 
5213 {
5214  /* After we are done drawing the stroke, check if we need to do a more
5215  * expensive depsgraph tag to update geometry. */
5217  RegionView3D *current_rv3d = CTX_wm_region_view3d(C);
5218  SculptSession *ss = ob->sculpt;
5219  Mesh *mesh = ob->data;
5220 
5221  /* Always needed for linked duplicates. */
5222  bool need_tag = (ID_REAL_USERS(&mesh->id) > 1);
5223 
5224  if (current_rv3d) {
5225  current_rv3d->rflag &= ~RV3D_PAINTING;
5226  }
5227 
5228  LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
5229  bScreen *screen = WM_window_get_active_screen(win);
5230  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
5231  SpaceLink *sl = area->spacedata.first;
5232  if (sl->spacetype != SPACE_VIEW3D) {
5233  continue;
5234  }
5235 
5236  /* Tag all 3D viewports for redraw now that we are done. Others
5237  * viewports did not get a full redraw, and anti-aliasing for the
5238  * current viewport was deactivated. */
5239  LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
5240  if (region->regiontype == RGN_TYPE_WINDOW) {
5241  RegionView3D *rv3d = region->regiondata;
5242  if (rv3d != current_rv3d) {
5243  need_tag |= !BKE_sculptsession_use_pbvh_draw(ob, rv3d);
5244  }
5245 
5246  ED_region_tag_redraw(region);
5247  }
5248  }
5249  }
5250 
5251  if (update_flags & SCULPT_UPDATE_IMAGE) {
5252  LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
5253  SpaceLink *sl = area->spacedata.first;
5254  if (sl->spacetype != SPACE_IMAGE) {
5255  continue;
5256  }
5258  }
5259  }
5260  }
5261 
5262  if (update_flags & SCULPT_UPDATE_COORDS) {
5264 
5265  /* Coordinates were modified, so fake neighbors are not longer valid. */
5267  }
5268 
5269  if (update_flags & SCULPT_UPDATE_MASK) {
5271  }
5272 
5273  if (update_flags & SCULPT_UPDATE_COLOR) {
5275  }
5276 
5277  if (update_flags & SCULPT_UPDATE_COORDS) {
5278  if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) {
5280  }
5281 
5282  /* Optimization: if there is locked key and active modifiers present in */
5283  /* the stack, keyblock is updating at each step. otherwise we could update */
5284  /* keyblock only when stroke is finished. */
5285  if (ss->shapekey_active && !ss->deform_modifiers_active) {
5287  }
5288  }
5289 
5290  if (need_tag) {
5292  }
5293 }
5294 
5295 /* Returns whether the mouse/stylus is over the mesh (1)
5296  * or over the background (0). */
5297 static bool over_mesh(bContext *C, struct wmOperator *UNUSED(op), const float mval[2])
5298 {
5299  float co_dummy[3];
5300  return SCULPT_stroke_get_location(C, co_dummy, mval, false);
5301 }
5302 
5304 {
5305  switch (BKE_pbvh_type(ss->pbvh)) {
5306  case PBVH_FACES:
5307  return true;
5308  case PBVH_BMESH:
5309  BKE_report(reports, RPT_ERROR, "Not supported in dynamic topology mode");
5310  return false;
5311  case PBVH_GRIDS:
5312  BKE_report(reports, RPT_ERROR, "Not supported in multiresolution mode");
5313  return false;
5314  }
5315 
5316  BLI_assert_msg(0, "PBVH corruption, type was invalid.");
5317 
5318  return false;
5319 }
5320 
5321 static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const float mval[2])
5322 {
5323  /* Don't start the stroke until `mval` goes over the mesh.
5324  * NOTE: `mval` will only be null when re-executing the saved stroke.
5325  * We have exception for 'exec' strokes since they may not set `mval`,
5326  * only 'location', see: T52195. */
5327  if (((op->flag & OP_IS_INVOKE) == 0) || (mval == NULL) || over_mesh(C, op, mval)) {
5329  SculptSession *ss = ob->sculpt;
5331  Brush *brush = BKE_paint_brush(&sd->paint);
5332  ToolSettings *tool_settings = CTX_data_tool_settings(C);
5333 
5334  /* NOTE: This should be removed when paint mode is available. Paint mode can force based on the
5335  * canvas it is painting on. (ref. use_sculpt_texture_paint). */
5336  if (brush && SCULPT_tool_is_paint(brush->sculpt_tool) &&
5337  !SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob)) {
5338  View3D *v3d = CTX_wm_view3d(C);
5339  if (v3d->shading.type == OB_SOLID) {
5341  }
5342  }
5343 
5345 
5346  sculpt_update_cache_invariants(C, sd, ss, op, mval);
5347 
5349  SCULPT_cursor_geometry_info_update(C, &sgi, mval, false);
5350 
5351  /* Setup the correct undo system. Image painting and sculpting are mutual exclusive.
5352  * Color attributes are part of the sculpting undo system. */
5353  if (brush && brush->sculpt_tool == SCULPT_TOOL_PAINT &&
5354  SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob)) {
5356  }
5357  else {
5359  }
5360 
5361  return true;
5362  }
5363  return false;
5364 }
5365 
5367  wmOperator *UNUSED(op),
5368  struct PaintStroke *stroke,
5369  PointerRNA *itemptr)
5370 {
5374  SculptSession *ss = ob->sculpt;
5375  const Brush *brush = BKE_paint_brush(&sd->paint);
5376  ToolSettings *tool_settings = CTX_data_tool_settings(C);
5377  StrokeCache *cache = ss->cache;
5378  cache->stroke_distance = paint_stroke_distance_get(stroke);
5379 
5380  SCULPT_stroke_modifiers_check(C, ob, brush);
5381  sculpt_update_cache_variants(C, sd, ob, itemptr);
5382  sculpt_restore_mesh(sd, ob);
5383 
5385  float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat));
5386  BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail);
5387  }
5388  else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) {
5390  }
5391  else {
5393  (ss->cache->radius / ss->cache->dyntopo_pixel_radius) *
5394  (sd->detail_size * U.pixelsize) / 0.4f);
5395  }
5396 
5397  if (SCULPT_stroke_is_dynamic_topology(ss, brush)) {
5398  do_symmetrical_brush_actions(sd, ob, sculpt_topology_update, ups, &tool_settings->paint_mode);
5399  }
5400 
5401  do_symmetrical_brush_actions(sd, ob, do_brush_action, ups, &tool_settings->paint_mode);
5402  sculpt_combine_proxies(sd, ob);
5403 
5404  /* Hack to fix noise texture tearing mesh. */
5405  sculpt_fix_noise_tear(sd, ob);
5406 
5407  /* TODO(sergey): This is not really needed for the solid shading,
5408  * which does use pBVH drawing anyway, but texture and wireframe
5409  * requires this.
5410  *
5411  * Could be optimized later, but currently don't think it's so
5412  * much common scenario.
5413  *
5414  * Same applies to the DEG_id_tag_update() invoked from
5415  * sculpt_flush_update_step().
5416  */
5417  if (ss->deform_modifiers_active) {
5419  }
5420  else if (ss->shapekey_active) {
5422  }
5423 
5424  ss->cache->first_time = false;
5426 
5427  /* Cleanup. */
5428  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
5430  }
5431  else if (SCULPT_tool_is_paint(brush->sculpt_tool)) {
5432  if (SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob)) {
5434  }
5435  else {
5437  }
5438  }
5439  else {
5441  }
5442 }
5443 
5445 {
5446  Brush *brush = BKE_paint_brush(&sd->paint);
5447  MTex *mtex = &brush->mtex;
5448 
5449  if (mtex->tex && mtex->tex->nodetree) {
5451  }
5452 }
5453 
5454 static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke))
5455 {
5457  SculptSession *ss = ob->sculpt;
5459  ToolSettings *tool_settings = CTX_data_tool_settings(C);
5460 
5461  /* Finished. */
5462  if (!ss->cache) {
5464  return;
5465  }
5467  Brush *brush = BKE_paint_brush(&sd->paint);
5468  BLI_assert(brush == ss->cache->brush); /* const, so we shouldn't change. */
5469  ups->draw_inverted = false;
5470 
5471  SCULPT_stroke_modifiers_check(C, ob, brush);
5472 
5473  /* Alt-Smooth. */
5474  if (ss->cache->alt_smooth) {
5475  smooth_brush_toggle_off(C, &sd->paint, ss->cache);
5476  /* Refresh the brush pointer in case we switched brush in the toggle function. */
5477  brush = BKE_paint_brush(&sd->paint);
5478  }
5479 
5480  if (SCULPT_is_automasking_enabled(sd, ss, brush)) {
5482  }
5483 
5485  SCULPT_cache_free(ss->cache);
5486  ss->cache = NULL;
5487 
5488  if (brush && brush->sculpt_tool == SCULPT_TOOL_PAINT &&
5489  SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob)) {
5491  }
5492  else {
5494  }
5495 
5496  if (brush->sculpt_tool == SCULPT_TOOL_MASK) {
5498  }
5499  else if (brush->sculpt_tool == SCULPT_TOOL_PAINT) {
5500  if (SCULPT_use_image_paint_brush(&tool_settings->paint_mode, ob)) {
5502  }
5503  else {
5505  }
5506  }
5507  else {
5509  }
5510 
5513 }
5514 
5515 static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
5516 {
5517  struct PaintStroke *stroke;
5518  int ignore_background_click;
5519  int retval;
5521 
5522  /* Test that ob is visible; otherwise we won't be able to get evaluated data
5523  * from the depsgraph. We do this here instead of SCULPT_mode_poll
5524  * to avoid falling through to the translate operator in the
5525  * global view3d keymap.
5526  *
5527  * Note: BKE_object_is_visible_in_viewport is not working here (it returns false
5528  * if the object is in local view); instead, test for OB_HIDE_VIEWPORT directly.
5529  */
5530 
5531  if (ob->visibility_flag & OB_HIDE_VIEWPORT) {
5532  return OPERATOR_CANCELLED;
5533  }
5534 
5536 
5538  Brush *brush = BKE_paint_brush(&sd->paint);
5539 
5542  return OPERATOR_CANCELLED;
5543  }
5544 
5545  stroke = paint_stroke_new(C,
5546  op,
5550  NULL,
5552  event->type);
5553 
5554  op->customdata = stroke;
5555 
5556  /* For tablet rotation. */
5557  ignore_background_click = RNA_boolean_get(op->ptr, "ignore_background_click");
5558 
5559  if (ignore_background_click && !over_mesh(C, op, (const float[2]){UNPACK2(event->mval)})) {
5560  paint_stroke_free(C, op, op->customdata);
5561  return OPERATOR_PASS_THROUGH;
5562  }
5563 
5564  if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
5565  paint_stroke_free(C, op, op->customdata);
5566  return OPERATOR_FINISHED;
5567  }
5568  /* Add modal handler. */
5570 
5571  OPERATOR_RETVAL_CHECK(retval);
5573 
5574  return OPERATOR_RUNNING_MODAL;
5575 }
5576 
5578 {
5580 
5582  op,
5586  NULL,
5588  0);
5589 
5590  /* Frees op->customdata. */
5591  paint_stroke_exec(C, op, op->customdata);
5592 
5593  return OPERATOR_FINISHED;
5594 }
5595 
5597 {
5599  SculptSession *ss = ob->sculpt;
5601  const Brush *brush = BKE_paint_brush(&sd->paint);
5602 
5603  /* XXX Canceling strokes that way does not work with dynamic topology,
5604  * user will have to do real undo for now. See T46456. */
5605  if (ss->cache && !SCULPT_stroke_is_dynamic_topology(ss, brush)) {
5606  paint_mesh_restore_co(sd, ob);
5607  }
5608 
5609  paint_stroke_cancel(C, op, op->customdata);
5610 
5611  if (ss->cache) {
5612  SCULPT_cache_free(ss->cache);
5613  ss->cache = NULL;
5614  }
5615 
5617 }
5618 
5619 static int sculpt_brush_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
5620 {
5621  return paint_stroke_modal(C, op, event, (struct PaintStroke **)&op->customdata);
5622 }
5623 
5625 {
5626  /* Identifiers. */
5627  ot->name = "Sculpt";
5628  ot->idname = "SCULPT_OT_brush_stroke";
5629  ot->description = "Sculpt a stroke into the geometry";
5630 
5631  /* API callbacks. */
5635  ot->poll = SCULPT_poll;
5637 
5638  /* Flags (sculpt does own undo? (ton)). */
5639  ot->flag = OPTYPE_BLOCKING;
5640 
5641  /* Properties. */
5642 
5644 
5646  "ignore_background_click",
5647  0,
5648  "Ignore Background Click",
5649  "Clicks on the background do not start the stroke");
5650 }
5651 
5652 /* Fake Neighbors. */
5653 /* This allows the sculpt tools to work on meshes with multiple connected components as they had
5654  * only one connected component. When initialized and enabled, the sculpt API will return extra
5655  * connectivity neighbors that are not in the real mesh. These neighbors are calculated for each
5656  * vertex using the minimum distance to a vertex that is in a different connected component. */
5657 
5658 /* The fake neighbors first need to be ensured to be initialized.
5659  * After that tools which needs fake neighbors functionality need to
5660  * temporarily enable it:
5661  *
5662  * void my_awesome_sculpt_tool() {
5663  * SCULPT_fake_neighbors_ensure(sd, object, brush->disconnected_distance_max);
5664  * SCULPT_fake_neighbors_enable(ob);
5665  *
5666  * ... Logic of the tool ...
5667  * SCULPT_fake_neighbors_disable(ob);
5668  * }
5669  *
5670  * Such approach allows to keep all the connectivity information ready for reuse
5671  * (without having lag prior to every stroke), but also makes it so the affect
5672  * is localized to a specific brushes and tools only. */
5673 
5674 enum {
5677 };
5678 
5680 {
5681  if (ss->vertex_info.connected_component) {
5682  return ss->vertex_info.connected_component[index];
5683  }
5685 }
5686 
5687 static void SCULPT_fake_neighbor_init(SculptSession *ss, const float max_dist)
5688 {
5689  const int totvert = SCULPT_vertex_count_get(ss);
5691  totvert, sizeof(int), "fake neighbor");
5692  for (int i = 0; i < totvert; i++) {
5694  }
5695 
5696  ss->fake_neighbors.current_max_distance = max_dist;
5697 }
5698 
5699 static void SCULPT_fake_neighbor_add(SculptSession *ss, int v_index_a, int v_index_b)
5700 {
5701  if (ss->fake_neighbors.fake_neighbor_index[v_index_a] == FAKE_NEIGHBOR_NONE) {
5702  ss->fake_neighbors.fake_neighbor_index[v_index_a] = v_index_b;
5703  ss->fake_neighbors.fake_neighbor_index[v_index_b] = v_index_a;
5704  }
5705 }
5706 
5708 {
5710 }
5711 
5717 
5718 static void do_fake_neighbor_search_task_cb(void *__restrict userdata,
5719  const int n,
5720  const TaskParallelTLS *__restrict tls)
5721 {
5722  SculptThreadedTaskData *data = userdata;
5723  SculptSession *ss = data->ob->sculpt;
5724  NearestVertexFakeNeighborTLSData *nvtd = tls->userdata_chunk;
5725  PBVHVertexIter vd;
5726 
5727  BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
5728  int vd_topology_id = SCULPT_vertex_get_connected_component(ss, vd.index);
5729  if (vd_topology_id != nvtd->current_topology_id &&
5731  float distance_squared = len_squared_v3v3(vd.co, data->nearest_vertex_search_co);
5732  if (distance_squared < nvtd->nearest_vertex_distance_squared &&
5733  distance_squared < data->max_distance_squared) {
5734  nvtd->nearest_vertex_index = vd.index;
5736  }
5737  }
5738  }
5740 }
5741 
5742 static void fake_neighbor_search_reduce(const void *__restrict UNUSED(userdata),
5743  void *__restrict chunk_join,
5744  void *__restrict chunk)
5745 {
5746  NearestVertexFakeNeighborTLSData *join = chunk_join;
5747  NearestVertexFakeNeighborTLSData *nvtd = chunk;
5748  if (join->nearest_vertex_index == -1) {
5751  }
5755  }
5756 }
5757 
5758 static int SCULPT_fake_neighbor_search(Sculpt *sd, Object *ob, const int index, float max_distance)
5759 {
5760  SculptSession *ss = ob->sculpt;
5761  PBVHNode **nodes = NULL;
5762  int totnode;
5764  .ss = ss,
5765  .sd = sd,
5766  .radius_squared = max_distance * max_distance,
5767  .original = false,
5768  .center = SCULPT_vertex_co_get(ss, index),
5769  };
5770  BKE_pbvh_search_gather(ss->pbvh, SCULPT_search_sphere_cb, &data, &nodes, &totnode);
5771 
5772  if (totnode == 0) {
5773  return -1;
5774  }
5775 
5776  SculptThreadedTaskData task_data = {
5777  .sd = sd,
5778  .ob = ob,
5779  .nodes = nodes,
5780  .max_distance_squared = max_distance * max_distance,
5781  };
5782 
5784 
5786  nvtd.nearest_vertex_index = -1;
5787  nvtd.nearest_vertex_distance_squared = FLT_MAX;
5789 
5790  TaskParallelSettings settings;
5791  BKE_pbvh_parallel_range_settings(&settings, true, totnode);
5793  settings.userdata_chunk = &nvtd;
5795  BLI_task_parallel_range(0, totnode, &task_data, do_fake_neighbor_search_task_cb, &settings);
5796 
5797  MEM_SAFE_FREE(nodes);
5798 
5799  return nvtd.nearest_vertex_index;
5800 }
5801 
5803  int next_id;
5805 
5807  SculptSession *ss, int from_v, int to_v, bool UNUSED(is_duplicate), void *userdata)
5808 {
5809  SculptTopologyIDFloodFillData *data = userdata;
5810  ss->vertex_info.connected_component[from_v] = data->next_id;
5811  ss->vertex_info.connected_component[to_v] = data->next_id;
5812  return true;
5813 }
5814 
5816 {
5817  SculptSession *ss = ob->sculpt;
5818 
5819  /* Topology IDs already initialized. They only need to be recalculated when the PBVH is
5820  * rebuild.
5821  */
5822  if (ss->vertex_info.connected_component) {
5823  return;
5824  }
5825 
5826  const int totvert = SCULPT_vertex_count_get(ss);
5827  ss->vertex_info.connected_component = MEM_malloc_arrayN(totvert, sizeof(int), "topology ID");
5828 
5829  for (int i = 0; i < totvert; i++) {
5831  }
5832 
5833  int next_id = 0;
5834  for (int i = 0; i < totvert; i++) {
5836  SculptFloodFill flood;
5837  SCULPT_floodfill_init(ss, &flood);
5838  SCULPT_floodfill_add_initial(&flood, i);
5840  data.next_id = next_id;
5842  SCULPT_floodfill_free(&flood);
5843  next_id++;
5844  }
5845  }
5846 }
5847 
5849 {
5850  SculptSession *ss = object->sculpt;
5851  if (ss->vertex_info.boundary) {
5852  return;
5853  }
5854 
5855  Mesh *base_mesh = BKE_mesh_from_object(object);
5856  ss->vertex_info.boundary = BLI_BITMAP_NEW(base_mesh->totvert, "Boundary info");
5857  int *adjacent_faces_edge_count = MEM_calloc_arrayN(
5858  base_mesh->totedge, sizeof(int), "Adjacent face edge count");
5859 
5860  for (int p = 0; p < base_mesh->totpoly; p++) {
5861  MPoly *poly = &base_mesh->mpoly[p];
5862  for (int l = 0; l < poly->totloop; l++) {
5863  MLoop *loop = &base_mesh->mloop[l + poly->loopstart];
5864  adjacent_faces_edge_count[loop->e]++;
5865  }
5866  }
5867 
5868  for (int e = 0; e < base_mesh->totedge; e++) {
5869  if (adjacent_faces_edge_count[e] < 2) {
5870  MEdge *edge = &base_mesh->medge[e];
5871  BLI_BITMAP_SET(ss->vertex_info.boundary, edge->v1, true);
5872  BLI_BITMAP_SET(ss->vertex_info.boundary, edge->v2, true);
5873  }
5874  }
5875 
5876  MEM_freeN(adjacent_faces_edge_count);
5877 }
5878 
5879 void SCULPT_fake_neighbors_ensure(Sculpt *sd, Object *ob, const float max_dist)
5880 {
5881  SculptSession *ss = ob->sculpt;
5882  const int totvert = SCULPT_vertex_count_get(ss);
5883 
5884  /* Fake neighbors were already initialized with the same distance, so no need to be
5885  * recalculated.
5886  */
5888  ss->fake_neighbors.current_max_distance == max_dist) {
5889  return;
5890  }
5891 
5893  SCULPT_fake_neighbor_init(ss, max_dist);
5894 
5895  for (int i = 0; i < totvert; i++) {
5896  const int from_v = i;
5897 
5898  /* This vertex does not have a fake neighbor yet, search one for it. */
5900  const int to_v = SCULPT_fake_neighbor_search(sd, ob, from_v, max_dist);
5901  if (to_v != -1) {
5902  /* Add the fake neighbor if available. */
5903  SCULPT_fake_neighbor_add(ss, from_v, to_v);
5904  }
5905  }
5906  }
5907 }
5908 
5910 {
5911  SculptSession *ss = ob->sculpt;
5914 }
5915 
5917 {
5918  SculptSession *ss = ob->sculpt;
5920  ss->fake_neighbors.use_fake_neighbors = false;
5921 }
5922 
5924 {
5925  SculptSession *ss = ob->sculpt;
5927 }
5928 
typedef float(TangentPoint)[2]
Generic geometry attributes built on CustomData.
@ ATTR_DOMAIN_CORNER
Definition: BKE_attribute.h:30
struct CustomDataLayer * BKE_id_attributes_active_color_get(const struct ID *id)
eAttrDomain BKE_id_attribute_domain(const struct ID *id, const struct CustomDataLayer *layer)
void BKE_brush_size_set(struct Scene *scene, struct Brush *brush, int size)
Definition: brush.cc:2234
float BKE_brush_curve_strength(const struct Brush *br, float p, float len)
float BKE_brush_sample_tex_3d(const struct Scene *scene, const struct Brush *br, const float point[3], float rgba[4], int thread, struct ImagePool *pool)
bool BKE_brush_use_size_pressure(const struct Brush *brush)
float BKE_brush_alpha_get(const struct Scene *scene, const struct Brush *brush)
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.cc:2294
bool BKE_brush_use_locked_size(const struct Scene *scene, const struct Brush *brush)
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:97
BLI_INLINE CCGElem * CCG_elem_offset(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:103
BLI_INLINE float * CCG_elem_no(const CCGKey *key, CCGElem *elem)
Definition: BKE_ccg.h:91
struct CCGElem CCGElem
Definition: BKE_ccg.h:30
BLI_INLINE float * CCG_elem_co(const CCGKey *key, CCGElem *elem)
void BKE_curvemapping_init(struct CurveMapping *cumap)
Definition: colortools.c:1235
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
struct Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Definition: context.c:1505
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
Definition: context.c:1282
struct RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:793
int CustomData_get_offset(const struct CustomData *data, int type)
struct ImagePool * BKE_image_pool_new(void)
void BKE_keyblock_update_from_offset(const struct Object *ob, struct KeyBlock *kb, const float(*ofs)[3])
void BKE_keyblock_update_from_vertcos(const struct Object *ob, struct KeyBlock *kb, const float(*vertCos)[3])
bool BKE_keyblock_is_basis(const struct Key *key, int index)
float(* BKE_keyblock_convert_to_vertcos(const struct Object *ob, const struct KeyBlock *kb))[3]
struct ID * BKE_libblock_find_name(struct Main *bmain, short type, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: lib_id.c:1297
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.cc:1365
void BKE_mesh_tag_coords_changed(struct Mesh *mesh)
void multires_stitch_grids(struct Object *)
Definition: multires.c:1178
void multires_mark_as_modified(struct Depsgraph *depsgraph, struct Object *object, enum MultiresModifiedFlags flags)
Definition: multires.c:387
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3])
Definition: object.cc:3645
struct Mesh * BKE_object_get_original_mesh(const struct Object *object)
const struct BoundBox * BKE_object_boundbox_get(struct Object *ob)
Definition: object.cc:3684
#define PAINT_SYMM_AREAS
Definition: BKE_paint.h:118
void BKE_paint_brush_set(struct Paint *paint, struct Brush *br)
Definition: paint.c:617
#define PAINT_SYMM_AREA_DEFAULT
Definition: BKE_paint.h:110
void BKE_sculpt_sync_face_sets_visibility_to_base_mesh(struct Mesh *mesh)
Definition: paint.c:2091
void BKE_sculpt_sync_face_sets_visibility_to_grids(struct Mesh *mesh, struct SubdivCCG *subdiv_ccg)
Definition: paint.c:2106
ePaintSymmetryAreas
Definition: BKE_paint.h:112
@ PAINT_SYMM_AREA_Z
Definition: BKE_paint.h:115
@ PAINT_SYMM_AREA_X
Definition: BKE_paint.h:113
@ PAINT_SYMM_AREA_Y
Definition: BKE_paint.h:114
void BKE_sculpt_update_object_for_edit(struct Depsgraph *depsgraph, struct Object *ob_orig, bool need_pmap, bool need_mask, bool is_paint_tool)
Definition: paint.c:1914
struct Brush * BKE_paint_toolslots_brush_get(struct Paint *paint, int slot_index)
struct Brush * BKE_paint_brush(struct Paint *paint)
Definition: paint.c:607
#define SCULPT_FACE_SET_NONE
Definition: BKE_paint.h:267
struct Paint * BKE_paint_get_active_from_context(const struct bContext *C)
bool BKE_sculptsession_use_pbvh_draw(const struct Object *ob, const struct RegionView3D *rv3d)
@ PAINT_MODE_SCULPT
Definition: BKE_paint.h:68
void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
Definition: paint.c:1880
A BVH for high poly meshes.
bool BKE_pbvh_node_fully_masked_get(PBVHNode *node)
Definition: pbvh.c:1945
void BKE_pbvh_node_free_proxies(PBVHNode *node)
Definition: pbvh.c:3037
void BKE_pbvh_node_mark_update(PBVHNode *node)
Definition: pbvh.c:1869
BLI_bitmap ** BKE_pbvh_get_grid_visibility(const PBVH *pbvh)
Definition: pbvh.c:1843
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:2116
#define BKE_pbvh_vertex_iter_begin(pbvh, node, vi, mode)
Definition: BKE_pbvh.h:439
void BKE_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
Definition: pbvh.c:2090
struct CCGElem ** BKE_pbvh_get_grids(const PBVH *pbvh)
Definition: pbvh.c:1837
void BKE_pbvh_node_mark_update_color(PBVHNode *node)
Definition: pbvh.c:1880
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:2516
void BKE_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
Definition: pbvh.c:3050
void BKE_pbvh_redraw_BB(PBVH *pbvh, float bb_min[3], float bb_max[3])
Definition: pbvh.c:1729
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:2593
void BKE_pbvh_bmesh_node_save_orig(struct BMesh *bm, PBVHNode *node)
Definition: pbvh_bmesh.c:2020
float(* BKE_pbvh_vert_coords_alloc(struct PBVH *pbvh))[3]
Definition: pbvh.c:2948
void BKE_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
Definition: pbvh.c:2084
void BKE_pbvh_node_color_buffer_free(PBVH *pbvh)
Definition: pbvh.c:3088
PBVHType BKE_pbvh_type(const PBVH *pbvh)
Definition: pbvh.c:1798
float BKE_pbvh_node_get_tmin(PBVHNode *node)
Definition: pbvh.c:949
bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh, PBVHTopologyUpdateMode mode, const float center[3], const float view_normal[3], float radius, bool use_frontface, bool use_projected)
Definition: pbvh_bmesh.c:1943
struct BMesh * BKE_pbvh_get_bmesh(PBVH *pbvh)
Definition: pbvh.c:1861
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:2457
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:2169
#define BKE_pbvh_vertex_iter_end
Definition: BKE_pbvh.h:509
void BKE_pbvh_vert_tag_update_normal(PBVH *pbvh, int index)
Definition: pbvh.c:1967
const float(* BKE_pbvh_get_vert_normals(const PBVH *pbvh))[3]
Definition: pbvh.c:3225
#define PBVH_ITER_UNIQUE
Definition: BKE_pbvh.h:391
int BKE_pbvh_get_grid_num_vertices(const PBVH *pbvh)
Definition: pbvh.c:1849
PBVHTopologyUpdateMode
Definition: BKE_pbvh.h:278
@ PBVH_Collapse
Definition: BKE_pbvh.h:280
@ PBVH_Subdivide
Definition: BKE_pbvh.h:279
const struct CCGKey * BKE_pbvh_get_grid_key(const PBVH *pbvh)
Definition: pbvh.c:1831
void BKE_pbvh_build_pixels(PBVH *pbvh, struct Mesh *mesh, struct Image *image, struct ImageUser *image_user)
Definition: pbvh_pixels.cc:383
PBVHType
Definition: BKE_pbvh.h:233
@ PBVH_GRIDS
Definition: BKE_pbvh.h:235
@ PBVH_BMESH
Definition: BKE_pbvh.h:236
@ PBVH_FACES
Definition: BKE_pbvh.h:234
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:2717
void BKE_pbvh_ensure_node_loops(PBVH *pbvh)
Definition: pbvh.c:3280
PBVHProxyNode * BKE_pbvh_node_add_proxy(PBVH *pbvh, PBVHNode *node)
Definition: pbvh.c:3016
void BKE_pbvh_vertex_color_set(PBVH *pbvh, int vertex, const float color[4])
Definition: pbvh.cc:155
bool BKE_pbvh_node_fully_hidden_get(PBVHNode *node)
Definition: pbvh.c:1928
void BKE_pbvh_parallel_range_settings(struct TaskParallelSettings *settings, bool use_threading, int totnode)
Definition: pbvh.c:3211
struct MVert * BKE_pbvh_get_verts(const PBVH *pbvh)
Definition: pbvh.c:3219
void BKE_pbvh_update_vertex_data(PBVH *pbvh, int flags)
Definition: pbvh.c:1567
void BKE_pbvh_bmesh_after_stroke(PBVH *pbvh)
Definition: pbvh_bmesh.c:2077
void BKE_pbvh_vertex_color_get(const PBVH *pbvh, int vertex, float r_color[4])
Definition: pbvh.cc:147
void BKE_pbvh_node_mark_update_mask(PBVHNode *node)
Definition: pbvh.c:1875
void BKE_pbvh_update_bounds(PBVH *pbvh, int flags)
Definition: pbvh.c:1545
void BKE_pbvh_bounding_box(const PBVH *pbvh, float min[3], float max[3])
Definition: pbvh.c:1812
void BKE_pbvh_node_mark_redraw(PBVHNode *node)
Definition: pbvh.c:1906
void BKE_pbvh_bmesh_detail_size_set(PBVH *pbvh, float detail_size)
Definition: pbvh_bmesh.c:2092
void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *proxy_count)
Definition: pbvh.c:2096
void BKE_pbvh_node_mark_topology_update(PBVHNode *node)
Definition: pbvh_bmesh.c:2098
void BKE_pbvh_search_gather(PBVH *pbvh, BKE_pbvh_SearchCallback scb, void *search_data, PBVHNode ***array, int *tot)
Definition: pbvh.c:838
@ 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, eReportType type, const char *message)
Definition: report.c:83
void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg, const SubdivCCGCoord *coord, bool include_duplicates, SubdivCCGNeighbors *r_neighbors)
Definition: subdiv_ccg.c:1911
void BKE_subdiv_ccg_eval_limit_point(const SubdivCCG *subdiv_ccg, const SubdivCCGCoord *coord, float r_point[3])
Definition: subdiv_ccg.c:2078
SubdivCCGAdjacencyType BKE_subdiv_ccg_coarse_mesh_adjacency_info_get(const SubdivCCG *subdiv_ccg, const SubdivCCGCoord *coord, const struct MLoop *mloop, const struct MPoly *mpoly, int *r_v1, int *r_v2)
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, int grid_index)
Definition: subdiv_ccg.c:1940
@ MULTIRES_COORDS_MODIFIED
Definition: BKE_subsurf.h:67
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
#define BLI_BITMAP_NEW(_num, _alloc_string)
Definition: BLI_bitmap.h:40
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:64
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition: BLI_bitmap.h:81
#define BLI_BITMAP_SET(_bitmap, _index, _set)
Definition: BLI_bitmap.h:102
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
#define BLI_INLINE
Dial * BLI_dial_init(const float start_position[2], float threshold)
Definition: BLI_dial_2d.c:34
float BLI_dial_angle(Dial *dial, const float current_position[2])
Definition: BLI_dial_2d.c:44
void BLI_gsqueue_free(GSQueue *queue)
Definition: gsqueue.c:90
GSQueue * BLI_gsqueue_new(size_t elem_size)
Definition: gsqueue.c:69
void BLI_gsqueue_push(GSQueue *queue, const void *item)
Definition: gsqueue.c:97
void BLI_gsqueue_pop(GSQueue *queue, void *r_item)
Definition: gsqueue.c:131
bool BLI_gsqueue_is_empty(const GSQueue *queue)
Definition: gsqueue.c:159
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
MINLINE float max_ff(float a, float b)
#define M_SQRT2
Definition: BLI_math_base.h:29
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:23
MINLINE float square_f(float a)
MINLINE float pow3f(float x)
#define M_PI
Definition: BLI_math_base.h:20
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:209
void isect_ray_tri_watertight_v3_precalc(struct IsectRayPrecalc *isect_precalc, const float ray_direction[3])
Definition: math_geom.c:1784
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:408
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:651
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:980
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:665
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition: math_geom.c:33
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:926
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:87
void unit_m4(float m[4][4])
Definition: rct.c:1090
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:790
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:729
void scale_m4_fl(float R[4][4], float scale)
Definition: math_matrix.c:2297
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
float mat4_to_scale(const float M[4][4])
Definition: math_matrix.c:2185
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
void rotate_m4(float mat[4][4], char axis, float angle)
Definition: math_matrix.c:2325
void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:800
void normalize_m4(float R[4][4]) ATTR_NONNULL()
Definition: math_matrix.c:1945
void axis_angle_to_mat3_single(float R[3][3], char axis, float angle)
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
void axis_angle_normalized_to_quat(float r[4], const float axis[3], float angle)
void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
void rotate_v3_v3v3fl(float r[3], const float p[3], const float axis[3], float angle)
Definition: math_vector.c:800
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 mul_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3(float r[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 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:638
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
Definition: math_vector.c:29
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])
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 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 *rct_a, const struct rcti *rct_b)
bool BLI_rcti_is_empty(const struct rcti *rect)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
unsigned int uint
Definition: BLI_sys_types.h:67
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
Definition: task_range.cc:94
int BLI_task_parallel_thread_id(const TaskParallelTLS *tls)
#define UNPACK2(a)
#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(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_SHADING
Definition: DNA_ID.h:811
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:553
@ ID_BR
Definition: DNA_ID_enums.h:69
#define SCULPT_TOOL_HAS_DYNTOPO(t)
#define SCULPT_TOOL_HAS_ACCUMULATE(t)
@ BRUSH_DEFORM_TARGET_CLOTH_SIM
@ BRUSH_DEFORM_TARGET_GEOMETRY
@ SCULPT_DISP_DIR_VIEW
@ SCULPT_DISP_DIR_X
@ SCULPT_DISP_DIR_Z
@ SCULPT_DISP_DIR_Y
@ SCULPT_DISP_DIR_AREA
#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_INVERT_TO_SCRAPE_FILL
@ BRUSH_CLOTH_DEFORM_EXPAND
@ BRUSH_CLOTH_DEFORM_GRAB
@ BRUSH_CLOTH_DEFORM_SNAKE_HOOK
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
@ PAINT_FALLOFF_SHAPE_SPHERE
@ PAINT_FALLOFF_SHAPE_TUBE
@ 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
@ BRUSH_AREA_RADIUS_PRESSURE
BrushMaskTool
@ BRUSH_MASK_DRAW
@ BRUSH_MASK_SMOOTH
#define SCULPT_TOOL_HAS_NORMAL_WEIGHT(t)
#define SCULPT_TOOL_HAS_RAKE(t)
@ CD_PAINT_MASK
@ ME_HIDE
@ eModifierMode_Realtime
@ eModifierType_Mirror
@ MOD_MIR_CLIPPING
@ MOD_MIR_AXIS_X
@ OB_SOLID
@ OB_MODE_SCULPT
Object is a sort of wrapper for general info.
@ OB_HIDE_VIEWPORT
@ OB_MESH
@ SCULPT_DYNTOPO_SUBDIVIDE
@ SCULPT_DYNTOPO_DETAIL_MANUAL
@ SCULPT_LOCK_X
@ SCULPT_DYNTOPO_DETAIL_CONSTANT
@ SCULPT_DYNTOPO_COLLAPSE
@ SCULPT_DYNTOPO_DETAIL_BRUSH
ePaintSymmetryFlags
@ PAINT_SYMMETRY_FEATHER
@ PAINT_TILE_X
@ RGN_TYPE_WINDOW
@ SPACE_IMAGE
@ SPACE_VIEW3D
#define MTEX_MAP_MODE_3D
#define MTEX_MAP_MODE_AREA
@ V3D_SHADING_VERTEX_COLOR
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
#define RV3D_PAINTING
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
@ OPERATOR_PASS_THROUGH
#define OPERATOR_RETVAL_CHECK(ret)
void ED_paint_tool_update_sticky_shading_color(struct bContext *C, struct Object *ob)
void ED_image_undo_push_begin(const char *name, int paint_mode)
Definition: image_undo.cc:1095
void ED_image_undo_push_end(void)
Definition: image_undo.cc:1133
void ED_region_tag_redraw_partial(struct ARegion *region, const struct rcti *rct, bool rebuild)
void ED_area_tag_redraw_regiontype(ScrArea *area, int type)
Definition: area.c:747
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:655
bool ED_view3d_win_to_segment_clipped(const struct Depsgraph *depsgraph, const struct ARegion *region, const struct View3D *v3d, const float mval[2], float r_ray_start[3], float r_ray_end[3], bool do_clip_planes)
void ED_view3d_win_to_delta(const struct ARegion *region, const float xy_delta[2], float zfac, float r_out[3])
void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc, struct Depsgraph *depsgraph)
void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, const struct Object *ob, float r_pmat[4][4])
bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, const float co[3], bool is_local)
void ED_view3d_project_float_v2_m4(const struct ARegion *region, const float co[3], float r_co[2], const float mat[4][4])
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3])
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)
void ED_view3d_init_mats_rv3d(const struct Object *ob, struct RegionView3D *rv3d)
Definition: space_view3d.c:166
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 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 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 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
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture TEX_NOISE
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
void ntreeTexEndExecTree(struct bNodeTreeExec *exec)
struct bNodeTreeExec * ntreeTexBeginExecTree(struct bNodeTree *ntree)
Platform independent time functions.
#define C
Definition: RandGen.cpp:25
@ OPTYPE_BLOCKING
Definition: WM_types.h:150
#define ND_DRAW
Definition: WM_types.h:410
#define NC_OBJECT
Definition: WM_types.h:329
@ BM_VERT
Definition: bmesh_class.h:383
@ BM_ELEM_HIDDEN
Definition: bmesh_class.h:472
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:541
#define BM_elem_index_get(ele)
Definition: bmesh_inline.h:110
#define BM_elem_flag_set(ele, hflag, val)
Definition: bmesh_inline.h:16
#define BM_elem_flag_test(ele, hflag)
Definition: bmesh_inline.h:12
#define BM_ITER_ELEM(ele, iter, data, itype)
@ BM_LOOPS_OF_VERT
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const float **r_no)
Definition: bmesh_log.c:960
float BM_log_original_mask(BMLog *log, BMVert *v)
Definition: bmesh_log.c:945
const float * BM_log_original_vert_co(BMLog *log, BMVert *v)
Definition: bmesh_log.c:915
int BM_mesh_elem_count(BMesh *bm, const char htype)
Definition: bmesh_mesh.cc:708
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
Definition: bmesh_mesh.cc:558
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
Definition: bmesh_mesh.cc:446
BLI_INLINE BMVert * BM_vert_at_index(BMesh *bm, const int index)
Definition: bmesh_mesh.h:103
bool BM_vert_is_boundary(const BMVert *v)
Definition: bmesh_query.c:916
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
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
#define powf(x, y)
Definition: cuda/compat.h:103
OperationNode * node
Scene scene
const Depsgraph * depsgraph
SyclQueue void void size_t num_bytes void
int len
Definition: draw_manager.c:108
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
IconTextureDrawCall normal
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: invert.h:8
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:34
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:32
void *(* MEM_reallocN_id)(void *vmemh, size_t len, const char *str)
Definition: mallocn.c:29
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
ccl_device_inline float frac(float x, int *ix)
static unsigned a[3]
Definition: RandGen.cpp:78
static void area(int d1, int d2, int e1, int e2, float weights[2])
T distance_squared(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T abs(const T &a)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken rgba("rgba", pxr::TfToken::Immortal)
CCL_NAMESPACE_BEGIN ccl_device float fade(float t)
Definition: noise.h:15
void paint_stroke_cancel(struct bContext *C, struct wmOperator *op, struct PaintStroke *stroke)
int paint_stroke_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event, struct PaintStroke **stroke_p)
int paint_stroke_exec(struct bContext *C, struct wmOperator *op, struct PaintStroke *stroke)
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:874
@ BRUSH_STROKE_SMOOTH
Definition: paint_intern.h:451
@ BRUSH_STROKE_INVERT
Definition: paint_intern.h:450
BLI_INLINE void flip_v3(float v[3], const ePaintSymmetryFlags symm)
Definition: paint_intern.h:437
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)
float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius)
Definition: paint_utils.c:130
void paint_stroke_free(struct bContext *C, struct wmOperator *op, struct PaintStroke *stroke)
BLI_INLINE void flip_qt(float quat[4], const ePaintSymmetryFlags symm)
Definition: paint_intern.h:442
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)
BLI_INLINE void flip_qt_qt(float out[4], const float in[4], const ePaintSymmetryFlags symm)
Definition: paint_intern.h:414
float paint_get_tex_pixel(const struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread)
struct ViewContext * paint_stroke_view_context(struct PaintStroke *stroke)
bool PAINT_brush_tool_poll(struct bContext *C)
void paint_stroke_operator_properties(struct wmOperatorType *ot)
Definition: paint_utils.c:188
BLI_INLINE void flip_v3_v3(float out[3], const float in[3], const ePaintSymmetryFlags symm)
Definition: paint_intern.h:392
float paint_stroke_distance_get(struct PaintStroke *stroke)
const btScalar eps
Definition: poly34.cpp:11
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:4980
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3493
static const char * sculpt_tool_name(Sculpt *sd)
Definition: sculpt.c:3978
const float * SCULPT_vertex_co_get(SculptSession *ss, int index)
Definition: sculpt.c:125
bool SCULPT_brush_test_sphere(SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1583
int SCULPT_vertex_count_get(SculptSession *ss)
Definition: sculpt.c:111
static void sculpt_pbvh_update_pixels(PaintModeSettings *paint_mode_settings, SculptSession *ss, Object *ob)
Definition: sculpt.c:2801
void SCULPT_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter *iter)
Definition: sculpt.c:1300
void SCULPT_floodfill_add_and_skip_initial(SculptFloodFill *flood, int index)
Definition: sculpt.c:1086
void SCULPT_OT_brush_stroke(wmOperatorType *ot)
Definition: sculpt.c:5624
void SCULPT_floodfill_add_initial_with_symmetry(Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, int index, float radius)
Definition: sculpt.c:1092
void SCULPT_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node, SculptUndoType type)
Definition: sculpt.c:1290
void SCULPT_boundary_info_ensure(Object *object)
Definition: sculpt.c:5848
static bool sculpt_needs_pbvh_pixels(PaintModeSettings *paint_mode_settings, const Brush *brush, Object *ob)
Definition: sculpt.c:2788
void SCULPT_vertcos_to_key(Object *ob, KeyBlock *kb, const float(*vertCos)[3])
Definition: sculpt.c:3097
void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *region, Object *ob)
Definition: sculpt.c:1508
static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect)
Definition: sculpt.c:1468
int SCULPT_active_vertex_get(SculptSession *ss)
Definition: sculpt.c:271
bool SCULPT_cursor_geometry_info_update(bContext *C, SculptCursorGeometryInfo *out, const float mval[2], bool use_sampled_normal)
Definition: sculpt.c:4835
int SCULPT_nearest_vertex_get(Sculpt *sd, Object *ob, const float co[3], float max_distance, bool use_original)
Definition: sculpt.c:983
static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength)
Definition: sculpt.c:3063
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:2110
void SCULPT_floodfill_init(SculptSession *ss, SculptFloodFill *flood)
Definition: sculpt.c:1072
int SCULPT_plane_point_side(const float co[3], const float plane[4])
Definition: sculpt.c:2996
void SCULPT_face_set_visibility_set(SculptSession *ss, int face_set, bool visible)
Definition: sculpt.c:376
static int SCULPT_fake_neighbor_search(Sculpt *sd, Object *ob, const int index, float max_distance)
Definition: sculpt.c:5758
void SCULPT_fake_neighbors_ensure(Sculpt *sd, Object *ob, const float max_dist)
Definition: sculpt.c:5879
static void fake_neighbor_search_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:5742
bool SCULPT_vertex_has_face_set(SculptSession *ss, int index, int face_set)
Definition: sculpt.c:533
void SCULPT_vertex_persistent_normal_get(SculptSession *ss, int index, float no[3])
Definition: sculpt.c:239
static void calc_area_normal_and_center_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:2034
static int SCULPT_vertex_get_connected_component(SculptSession *ss, int index)
Definition: sculpt.c:5679
bool SCULPT_stroke_get_location(bContext *C, float out[3], const float mval[2], bool force_original)
Definition: sculpt.c:4964
struct NearestVertexTLSData NearestVertexTLSData
static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush *brush)
Definition: sculpt.c:1224
static void sculpt_combine_proxies(Sculpt *sd, Object *ob)
Definition: sculpt.c:3609
static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush)
Definition: sculpt.c:1233
bool SCULPT_vertex_has_unique_face_set(SculptSession *ss, int index)
Definition: sculpt.c:662
static int sculpt_brush_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition: sculpt.c:5619
void SCULPT_cache_calc_brushdata_symm(StrokeCache *cache, const char symm, const char axis, const float angle)
Definition: sculpt.c:3767
const float * SCULPT_brush_frontface_normal_from_falloff_shape(SculptSession *ss, char falloff_shape)
Definition: sculpt.c:1703
static void do_nearest_vertex_get_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:947
SculptBrushTestFn SCULPT_brush_test_init_with_falloff_shape(SculptSession *ss, SculptBrushTest *test, char falloff_shape)
Definition: sculpt.c:1686
void SCULPT_tilt_effective_normal_get(const SculptSession *ss, const Brush *brush, float r_no[3])
Definition: sculpt.c:2767
struct NearestVertexFakeNeighborTLSData NearestVertexFakeNeighborTLSData
static void do_brush_action_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:3210
void SCULPT_fake_neighbors_free(Object *ob)
Definition: sculpt.c:5923
bool SCULPT_vertex_any_face_set_visible_get(SculptSession *ss, int index)
Definition: sculpt.c:439
const float * SCULPT_vertex_co_for_grab_active_get(SculptSession *ss, int index)
Definition: sculpt.c:201
BLI_INLINE bool sculpt_brush_test_clipping(const SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1569
static void sculpt_vertex_neighbor_add(SculptVertexNeighborIter *iter, int neighbor_index)
Definition: sculpt.c:717
void SCULPT_vertex_face_set_set(SculptSession *ss, int index, int face_set)
Definition: sculpt.c:483
bool SCULPT_brush_test_circle_sq(SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1621
void SCULPT_floodfill_add_initial(SculptFloodFill *flood, int index)
Definition: sculpt.c:1081
void SCULPT_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:2151
bool SCULPT_is_symmetry_iteration_valid(char i, char symm)
Definition: sculpt.c:1025
static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd)
Definition: sculpt.c:3539
float SCULPT_brush_strength_factor(SculptSession *ss, const Brush *br, const float brush_point[3], const float len, const float vno[3], const float fno[3], const float mask, const int vertex_index, const int thread_id)
Definition: sculpt.c:2370
void SCULPT_connected_components_ensure(Object *ob)
Definition: sculpt.c:5815
const float * SCULPT_active_vertex_co_get(SculptSession *ss)
Definition: sculpt.c:279
static void calc_area_normal_and_center_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:1845
void SCULPT_vertex_random_access_ensure(SculptSession *ss)
Definition: sculpt.c:103
static void do_symmetrical_brush_actions(Sculpt *sd, Object *ob, BrushActionFunc action, UnifiedPaintSettings *ups, PaintModeSettings *paint_mode_settings)
Definition: sculpt.c:3923
void SCULPT_flush_update_done(const bContext *C, Object *ob, SculptUpdateType update_flags)
Definition: sculpt.c:5212
static void do_tiled(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, PaintModeSettings *paint_mode_settings, BrushActionFunc action)
Definition: sculpt.c:3824
static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op)
Definition: sculpt.c:5577
bool SCULPT_brush_test_cube(SculptBrushTest *test, const float co[3], const float local[4][4], const float roundness)
Definition: sculpt.c:1639
bool SCULPT_search_sphere_cb(PBVHNode *node, void *data_v)
Definition: sculpt.c:2467
static void sculpt_combine_proxies_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:3558
void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush)
Definition: sculpt.c:4712
void SCULPT_vertex_visible_set(SculptSession *ss, int index, bool visible)
Definition: sculpt.c:341
static void sculpt_vertex_neighbors_get_grids(SculptSession *ss, const int index, const bool include_duplicates, SculptVertexNeighborIter *iter)
Definition: sculpt.c:799
bool SCULPT_vertex_visible_get(SculptSession *ss, int index)
Definition: sculpt.c:356
static void SCULPT_flush_stroke_deform_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:3695
void SCULPT_vertex_color_set(SculptSession *ss, int index, const float color[4])
Definition: sculpt.c:166
static void UNUSED_FUNCTION() sculpt_visibility_sync_vertex_to_face_sets(SculptSession *ss, int index)
Definition: sculpt.c:576
void SCULPT_combine_transform_proxies(Sculpt *sd, Object *ob)
Definition: sculpt.c:3646
void SCULPT_face_sets_visibility_all_set(SculptSession *ss, bool visible)
Definition: sculpt.c:412
static void paint_mesh_restore_co_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: sculpt.c:1357
float * SCULPT_brush_deform_target_vertex_co_get(SculptSession *ss, const int deform_target, PBVHVertexIter *iter)
Definition: sculpt.c:304
static bool sculpt_check_unique_face_set_for_edge_in_base_mesh(SculptSession *ss, int v1, int v2)
Definition: sculpt.c:634
static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
Definition: sculpt.c:4727
void SCULPT_face_sets_visibility_invert(SculptSession *ss)
Definition: sculpt.c:398
static void sculpt_restore_mesh(Sculpt *sd, Object *ob)
Definition: sculpt.c:5102
static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, PointerRNA *ptr)
Definition: sculpt.c:4586
void SCULPT_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, SculptUndoNode *unode)
Definition: sculpt.c:1271
static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition: sculpt.c:5515
StrokeFlags
Definition: sculpt.c:1265
@ CLIP_Z
Definition: sculpt.c:1268
@ CLIP_Y
Definition: sculpt.c:1267
@ CLIP_X
Definition: sculpt.c:1266
void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags)
Definition: sculpt.c:5144
void SCULPT_vertex_color_get(const SculptSession *ss, int index, float r_color[4])
Definition: sculpt.c:161
void SCULPT_vertex_normal_get(SculptSession *ss, int index, float no[3])
Definition: sculpt.c:171
static void sculpt_update_keyblock(Object *ob)
Definition: sculpt.c:3670
void(* BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, PaintModeSettings *paint_mode_settings)
Definition: sculpt.c:3818
void SCULPT_vertex_limit_surface_get(SculptSession *ss, int index, float r_co[3])
Definition: sculpt.c:218
static PBVHNode ** sculpt_pbvh_gather_cursor_update(Object *ob, Sculpt *sd, bool use_original, int *r_totnode)
Definition: sculpt.c:2571
float SCULPT_raycast_init(ViewContext *vc, const float mval[2], float ray_start[3], float ray_end[3], float ray_normal[3], bool original)
Definition: sculpt.c:4798
struct SculptTopologyIDFloodFillData SculptTopologyIDFloodFillData
static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const float mval[2])
Definition: sculpt.c:5321
bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *brush)
Definition: sculpt.c:1338
bool SCULPT_vertex_is_boundary(const SculptSession *ss, const int index)
Definition: sculpt.c:865
static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob)
Definition: sculpt.c:3912
void SCULPT_flip_v3_by_symm_area(float v[3], const ePaintSymmetryFlags symm, const ePaintSymmetryAreas symmarea, const float pivot[3])
Definition: sculpt.c:2863
static void smooth_brush_toggle_off(const bContext *C, Paint *paint, StrokeCache *cache)
Definition: sculpt.c:4156
static bool sculpt_tool_is_proxy_used(const char sculpt_tool)
Definition: sculpt.c:1210
static void sculpt_brush_stroke_cancel(bContext *C, wmOperator *op)
Definition: sculpt.c:5596
bool SCULPT_mode_poll_view3d(bContext *C)
Definition: sculpt.c:3963
float SCULPT_brush_plane_offset_get(Sculpt *sd, SculptSession *ss)
Definition: sculpt.c:3002
void SCULPT_floodfill_free(SculptFloodFill *flood)
Definition: sculpt.c:1174
static float calc_radial_symmetry_feather(Sculpt *sd, StrokeCache *cache, const char symm, const char axis)
Definition: sculpt.c:1783
bool SCULPT_mode_poll(bContext *C)
Definition: sculpt.c:3957
void SCULPT_fake_neighbors_enable(Object *ob)
Definition: sculpt.c:5909
bool SCULPT_stroke_is_main_symmetry_pass(StrokeCache *cache)
Definition: sculpt.c:906
static void sculpt_update_cache_paint_variants(StrokeCache *cache, const Brush *brush)
Definition: sculpt.c:4541
#define SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY
Definition: sculpt.c:715
void SCULPT_active_vertex_normal_get(SculptSession *ss, float normal[3])
Definition: sculpt.c:284
static bool sculpt_needs_delta_from_anchored_origin(Brush *brush)
Definition: sculpt.c:4346
static void SCULPT_fake_neighbor_add(SculptSession *ss, int v_index_a, int v_index_b)
Definition: sculpt.c:5699
bool SCULPT_vertex_all_face_sets_visible_get(const SculptSession *ss, int index)
Definition: sculpt.c:459
#define SCULPT_TILT_SENSITIVITY
Definition: sculpt.c:2750
static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat[4][4])
Definition: sculpt.c:2707
static bool sculpt_needs_connectivity_info(const Sculpt *sd, const Brush *brush, SculptSession *ss, int stroke_mode)
Definition: sculpt.c:4691
void SCULPT_brush_test_init(SculptSession *ss, SculptBrushTest *test)
Definition: sculpt.c:1532
bool SCULPT_brush_test_sphere_sq(SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1599
void SCULPT_tilt_apply_to_normal(float r_normal[3], StrokeCache *cache, const float tilt_strength)
Definition: sculpt.c:2751
int SCULPT_vertex_face_set_get(SculptSession *ss, int index)
Definition: sculpt.c:508
static void calc_local_y(ViewContext *vc, const float center[3], float y[3])
Definition: sculpt.c:2691
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:2590
static void paint_mesh_restore_co(Sculpt *sd, Object *ob)
Definition: sculpt.c:1435
bool SCULPT_has_loop_colors(const Object *ob)
Definition: sculpt.c:148
static void sculpt_stroke_update_step(bContext *C, wmOperator *UNUSED(op), struct PaintStroke *stroke, PointerRNA *itemptr)
Definition: sculpt.c:5366
static bool sculpt_needs_delta_for_tip_orientation(Brush *brush)
Definition: sculpt.c:4369
static void smooth_brush_toggle_on(const bContext *C, Paint *paint, StrokeCache *cache)
Definition: sculpt.c:4122
static void sculpt_pose_fake_neighbors_free(SculptSession *ss)
Definition: sculpt.c:5707
void SCULPT_visibility_sync_all_vertex_to_face_sets(SculptSession *ss)
Definition: sculpt.c:591
bool SCULPT_stroke_is_first_brush_step_of_symmetry_pass(StrokeCache *cache)
Definition: sculpt.c:918
static void sculpt_rake_data_update(struct SculptRakeData *srd, const float co[3])
Definition: sculpt.c:1324
static void sculpt_vertex_neighbors_get_bmesh(SculptSession *ss, int index, SculptVertexNeighborIter *iter)
Definition: sculpt.c:742
float SCULPT_vertex_mask_get(SculptSession *ss, int index)
Definition: sculpt.c:248
static void update_brush_local_mat(Sculpt *sd, Object *ob)
Definition: sculpt.c:2773
static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Brush *brush)
Definition: sculpt.c:4383
static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache)
Definition: sculpt.c:1798
void SCULPT_fake_neighbors_disable(Object *ob)
Definition: sculpt.c:5916
@ SCULPT_TOPOLOGY_ID_DEFAULT
Definition: sculpt.c:5676
@ SCULPT_TOPOLOGY_ID_NONE
Definition: sculpt.c:5675
bool SCULPT_handles_colors_report(SculptSession *ss, ReportList *reports)
Definition: sculpt.c:5303
static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *tmin)
Definition: sculpt.c:4764
static void sculpt_topology_update(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *UNUSED(ups), PaintModeSettings *UNUSED(paint_mode_settings))
Definition: sculpt.c:3141
int SCULPT_face_set_next_available_get(SculptSession *ss)
Definition: sculpt.c:693
static bool sculpt_check_unique_face_set_in_base_mesh(SculptSession *ss, int index)
Definition: sculpt.c:613
static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, PaintModeSettings *paint_mode_settings)
Definition: sculpt.c:3245
static void SCULPT_fake_neighbor_init(SculptSession *ss, const float max_dist)
Definition: sculpt.c:5687
static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss)
Definition: sculpt.c:4084
int SCULPT_plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3])
Definition: sculpt.c:2990
static void sculpt_brush_exit_tex(Sculpt *sd)
Definition: sculpt.c:5444
static bool sculpt_tool_has_cube_tip(const char sculpt_tool)
Definition: sculpt.c:1183
char SCULPT_mesh_symmetry_xyz_get(Object *object)
Definition: sculpt.c:317
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:2901
static bool sculpt_tool_needs_original(const char sculpt_tool)
Definition: sculpt.c:1196
bool SCULPT_is_vertex_inside_brush_radius_symm(const float vertex[3], const float br_co[3], float radius, char symm)
Definition: sculpt.c:1030
void SCULPT_vertex_neighbors_get(SculptSession *ss, const int index, const bool include_duplicates, SculptVertexNeighborIter *iter)
Definition: sculpt.c:841
bool SCULPT_search_circle_cb(PBVHNode *node, void *data_v)
Definition: sculpt.c:2513
void SCULPT_update_object_bounding_box(Object *ob)
Definition: sculpt.c:5134
static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, PaintModeSettings *paint_mode_settings, BrushActionFunc action, const char symm, const int axis, const float UNUSED(feather))
Definition: sculpt.c:3888
bool SCULPT_check_vertex_pivot_symmetry(const float vco[3], const float pco[3], const char symm)
Definition: sculpt.c:923
static void do_fake_neighbor_search_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:5718
static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
Definition: sculpt.c:2664
void SCULPT_cache_free(StrokeCache *cache)
Definition: sculpt.c:4055
void SCULPT_floodfill_add_active(Sculpt *sd, Object *ob, SculptSession *ss, SculptFloodFill *flood, float radius)
Definition: sculpt.c:1118
void SCULPT_flush_stroke_deform(Sculpt *sd, Object *ob, bool is_proxy_used)
Definition: sculpt.c:3719
static float sculpt_brush_dynamic_size_get(Brush *brush, StrokeCache *cache, float initial_size)
Definition: sculpt.c:4328
void SCULPT_calc_area_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
Definition: sculpt.c:2103
bool SCULPT_stroke_is_first_brush_step(StrokeCache *cache)
Definition: sculpt.c:912
static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mval[2])
Definition: sculpt.c:4183
const float * SCULPT_vertex_persistent_co_get(SculptSession *ss, int index)
Definition: sculpt.c:193
bool SCULPT_get_redraw_rect(ARegion *region, RegionView3D *rv3d, Object *ob, rcti *rect)
Definition: sculpt.c:1489
MVert * SCULPT_mesh_deformed_mverts_get(SculptSession *ss)
Definition: sculpt.c:289
static void nearest_vertex_get_reduce(const void *__restrict UNUSED(userdata), void *__restrict chunk_join, void *__restrict chunk)
Definition: sculpt.c:967
bool SCULPT_poll_view3d(bContext *C)
Definition: sculpt.c:3968
static bool sculpt_brush_needs_rake_rotation(const Brush *brush)
Definition: sculpt.c:1254
bool SCULPT_poll(bContext *C)
Definition: sculpt.c:3973
ePaintSymmetryAreas SCULPT_get_vertex_symm_area(const float co[3])
Definition: sculpt.c:2848
static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle)
Definition: sculpt.c:1762
static void do_gravity_task_cb_ex(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict tls)
Definition: sculpt.c:3021
static bool over_mesh(bContext *C, struct wmOperator *UNUSED(op), const float mval[2])
Definition: sculpt.c:5297
int SCULPT_active_face_set_get(SculptSession *ss)
Definition: sculpt.c:325
static bool SCULPT_connected_components_floodfill_cb(SculptSession *ss, int from_v, int to_v, bool UNUSED(is_duplicate), void *userdata)
Definition: sculpt.c:5806
static void sculpt_brush_init_tex(Sculpt *sd, SculptSession *ss)
Definition: sculpt.c:5046
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:1143
static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke))
Definition: sculpt.c:5454
void SCULPT_flip_quat_by_symm_area(float quat[4], const ePaintSymmetryFlags symm, const ePaintSymmetryAreas symmarea, const float pivot[3])
Definition: sculpt.c:2882
void SCULPT_clip(Sculpt *sd, SculptSession *ss, float co[3], const float val[3])
Definition: sculpt.c:2540
static bool sculpt_check_boundary_vertex_in_base_mesh(const SculptSession *ss, const int index)
Definition: sculpt.c:859
void SCULPT_visibility_sync_all_face_sets_to_vertices(Object *ob)
Definition: sculpt.c:557
bool SCULPT_has_colors(const SculptSession *ss)
Definition: sculpt.c:156
static void sculpt_brush_stroke_init(bContext *C, wmOperator *op)
Definition: sculpt.c:5062
static float brush_strength(const Sculpt *sd, const StrokeCache *cache, const float feather, const UnifiedPaintSettings *ups, const PaintModeSettings *UNUSED(paint_mode_settings))
Definition: sculpt.c:2219
void SCULPT_calc_area_center(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3])
Definition: sculpt.c:2054
static void calc_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3])
Definition: sculpt.c:2632
struct AreaNormalCenterTLSData AreaNormalCenterTLSData
#define PIXEL_INPUT_THRESHHOLD
void SCULPT_tag_update_overlays(bContext *C)
Definition: sculpt.c:1048
bool SCULPT_brush_test_sphere_fast(const SculptBrushTest *test, const float co[3])
Definition: sculpt.c:1613
static float frontface(const Brush *br, const float sculpt_normal[3], const float no[3], const float fno[3])
Definition: sculpt.c:1713
static void sculpt_vertex_neighbors_get_faces(SculptSession *ss, int index, SculptVertexNeighborIter *iter)
Definition: sculpt.c:765
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_do_clay_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_displacement_eraser_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_displacement_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_slide_relax_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_elastic_deform_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_draw_sharp_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_bmesh_topology_rake(Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength)
float SCULPT_clay_thumb_get_stabilized_pressure(StrokeCache *cache)
void SCULPT_do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_do_fill_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:106
void SCULPT_cloth_sim_activate_nodes(SculptClothSimulation *cloth_sim, PBVHNode **nodes, int totnode)
SculptClothSimulation * SCULPT_cloth_brush_simulation_create(Object *ob, 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:908
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_do_draw_face_sets_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
void SCULPT_undo_push_begin(struct Object *ob, const char *name)
Definition: sculpt_undo.c:1545
#define SCULPT_RAKE_BRUSH_FACTOR
BLI_INLINE bool SCULPT_tool_is_paint(int tool)
void SCULPT_undo_push_end(struct Object *ob)
Definition: sculpt_undo.c:1575
#define FAKE_NEIGHBOR_NONE
void SCULPT_do_smear_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
bool SCULPT_use_image_paint_brush(struct PaintModeSettings *settings, Object *ob) ATTR_NONNULL()
void SCULPT_pose_brush_init(struct Sculpt *sd, struct Object *ob, struct SculptSession *ss, struct Brush *br)
Definition: sculpt_pose.c:957
void SCULPT_do_paint_brush(struct PaintModeSettings *paint_mode_settings, Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) ATTR_NONNULL()
BLI_INLINE bool SCULPT_is_cloth_deform_brush(const Brush *brush)
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_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:1037
#define SCULPT_CLAY_STABILIZER_LEN
SculptUpdateType
Definition: sculpt_intern.h:44
@ SCULPT_UPDATE_COLOR
Definition: sculpt_intern.h:48
@ SCULPT_UPDATE_IMAGE
Definition: sculpt_intern.h:49
@ SCULPT_UPDATE_MASK
Definition: sculpt_intern.h:46
@ SCULPT_UPDATE_COORDS
Definition: sculpt_intern.h:45
#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:1112
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:1419
SculptUndoNode * SCULPT_undo_get_node(PBVHNode *node, SculptUndoType type)
Definition: sculpt_undo.c:1020
#define SCULPT_VERTEX_DUPLICATES_AND_NEIGHBORS_ITER_BEGIN(ss, v_index, neighbor_iterator)
void SCULPT_smooth(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength, bool smooth_mask)
void SCULPT_pose_ik_chain_free(struct SculptPoseIKChain *ik_chain)
Definition: sculpt_pose.c:1209
SculptUndoType
@ SCULPT_UNDO_FACE_SETS
@ SCULPT_UNDO_COORDS
@ SCULPT_UNDO_COLOR
@ SCULPT_UNDO_MASK
bool SCULPT_paint_image_canvas_get(struct PaintModeSettings *paint_mode_settings, struct Object *ob, struct Image **r_image, struct ImageUser **r_image_user) ATTR_NONNULL()
Get the image canvas for painting on the given object.
void * regiondata
float area_nos[2][3]
Definition: sculpt.c:1840
float area_cos[2][3]
Definition: sculpt.c:1839
struct BMVert * v
Definition: bmesh_class.h:153
struct BMLoop * prev
Definition: bmesh_class.h:233
struct BMLoop * next
Definition: bmesh_class.h:233
float co[3]
Definition: bmesh_class.h:87
float no[3]
Definition: bmesh_class.h:88
CustomData vdata
Definition: bmesh_class.h:337
float vec[8][3]
float topology_rake_factor
int sculpt_plane
int cloth_deform_type
float density
struct MTex mtex
float normal_weight
float rake_factor
struct CurveMapping * curve
float texture_sample_bias
float plane_trim
char falloff_shape
float tilt_strength_factor
float hardness
float flow
char mask_tool
char sculpt_tool
int smooth_deform_type
float wet_mix
float wet_persistence
int deform_target
float plane_offset
float autosmooth_factor
int paint_flags
Definition: BKE_ccg.h:32
int grid_size
Definition: BKE_ccg.h:40
int grid_area
Definition: BKE_ccg.h:42
char name[66]
Definition: DNA_ID.h:378
struct KeyBlock * next
Definition: DNA_key_types.h:25
short relative
Definition: DNA_key_types.h:41
ListBase block
Definition: DNA_key_types.h:84
KeyBlock * refkey
Definition: DNA_key_types.h:72
void * first
Definition: DNA_listBase.h:31
unsigned int e
unsigned int v
char brush_map_mode
float rot
float ofs[3]
float size[3]
struct Tex * tex
float co[3]
Definition: BKE_main.h:121
struct MEdge * medge
char symmetry
struct MVert * mvert
int totedge
int totvert
struct MLoop * mloop
int totpoly
struct Key * key
struct MPoly * mpoly
struct Object * mirror_ob
struct ModifierData * next
float nearest_vertex_distance_squared
Definition: sculpt.c:944
int nearest_vertex_index
Definition: sculpt.c:943
struct BoundBox * bb
ListBase modifiers
float loc[3]
float scale[3]
float imat[4][4]
short shapenr
Object_Runtime runtime
short visibility_flag
float obmat[4][4]
struct SculptSession * sculpt
void * data
float(* co)[3]
Definition: BKE_pbvh.h:47
struct MVert * mvert
Definition: BKE_pbvh.h:428
float * co
Definition: BKE_pbvh.h:430
float * fno
Definition: BKE_pbvh.h:432
float * no
Definition: BKE_pbvh.h:431
struct BMVert * bm_vert
Definition: BKE_pbvh.h:429
float * mask
Definition: BKE_pbvh.h:433
const int * vert_indices
Definition: BKE_pbvh.h:417
Brush * brush
Definition: paint_stroke.c:67
float tile_offset[3]
int symmetry_flags
struct Brush * brush
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:362
int * fake_neighbor_index
Definition: BKE_paint.h:480
float current_max_distance
Definition: BKE_paint.h:477
const float * ray_normal
Definition: sculpt.c:2841
SculptSession * ss
Definition: sculpt.c:2840
const float * ray_start
Definition: sculpt.c:2841
GSQueue * queue
Definition: sculpt_intern.h:95
BLI_bitmap * visited_vertices
Definition: sculpt_intern.h:96
const float * co
Definition: sculpt_intern.h:87
struct SculptUndoNode * unode
Definition: sculpt_intern.h:80
float(* normals)[3]
Definition: sculpt_intern.h:82
struct BMLog * bm_log
Definition: sculpt_intern.h:78
const float * vmasks
Definition: sculpt_intern.h:83
const float * col
Definition: sculpt_intern.h:90
float(* colors)[4]
Definition: sculpt_intern.h:84
const float * no
Definition: sculpt_intern.h:88
float(* coords)[3]
Definition: sculpt_intern.h:81
float follow_co[3]
int active_face_grid_index
Definition: sculpt.c:2834
const float * ray_normal
Definition: sculpt.c:2826
float * face_normal
Definition: sculpt.c:2832
int active_vertex_index
Definition: sculpt.c:2831
const float * ray_start
Definition: sculpt.c:2825
struct IsectRayPrecalc isect_precalc
Definition: sculpt.c:2836
SculptSession * ss
Definition: sculpt.c:2824
float cursor_normal[3]
Definition: BKE_paint.h:578
struct SubdivCCG * subdiv_ccg
Definition: BKE_paint.h:547
struct ImagePool * tex_pool
Definition: BKE_paint.h:561
float cursor_view_normal[3]
Definition: BKE_paint.h:580
SculptVertexInfo vertex_info
Definition: BKE_paint.h:608
float cursor_location[3]
Definition: BKE_paint.h:577
struct RegionView3D * rv3d
Definition: BKE_paint.h:589
float(* orig_cos)[3]
Definition: BKE_paint.h:556
int * face_sets
Definition: BKE_paint.h:536
float cursor_radius
Definition: BKE_paint.h:576
struct MVert * mvert
Definition: BKE_paint.h:498
struct MPropCol * vcol
Definition: BKE_paint.h:506
struct KeyBlock * shapekey_active
Definition: BKE_paint.h:505
struct BMesh * bm
Definition: BKE_paint.h:539
int active_face_index
Definition: BKE_paint.h:570
struct BMLog * bm_log
Definition: BKE_paint.h:544
int active_vertex_index
Definition: BKE_paint.h:568
float * vmask
Definition: BKE_paint.h:512
struct MeshElemMap * pmap
Definition: BKE_paint.h:516
struct MLoop * mloop
Definition: BKE_paint.h:500
struct SculptSession::@52 multires
struct MPoly * mpoly
Definition: BKE_paint.h:499
struct MultiresModifierData * modifier
Definition: BKE_paint.h:490
float(* deform_imats)[3][3]
Definition: BKE_paint.h:558
float cursor_sampled_normal[3]
Definition: BKE_paint.h:579
struct StrokeCache * cache
Definition: BKE_paint.h:563
struct View3D * v3d
Definition: BKE_paint.h:590
float(* deform_cos)[3]
Definition: BKE_paint.h:557
struct MLoopCol * mcol
Definition: BKE_paint.h:507
int active_grid_index
Definition: BKE_paint.h:571
SculptFakeNeighbors fake_neighbors
Definition: BKE_paint.h:609
SculptPersistentBase * persistent_base
Definition: BKE_paint.h:606
struct PBVH * pbvh
Definition: BKE_paint.h:550
bool deform_modifiers_active
Definition: BKE_paint.h:555
struct Sculpt * sd
float nearest_vertex_search_co[3]
struct BMLogEntry * bm_entry
float(* no)[3]
float(* co)[3]
SculptUndoType type
int * connected_component
Definition: BKE_paint.h:392
BLI_bitmap * boundary
Definition: BKE_paint.h:395
int neighbors_fixed[SCULPT_VERTEX_NEIGHBOR_FIXED_CAPACITY]
Definition: sculpt_intern.h:65
struct Object * gravity_object
float detail_percent
Paint paint
int radial_symm[3]
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]
void * prev_colors_vpaint
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
struct StrokeCache::@514 paint_brush
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 Dial * dial
float(* prev_displacement)[3]
int saved_smooth_size
bool is_rake_rotation_valid
float gravity_direction[3]
float plane_trim_squared
float stroke_distance
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
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:181
size_t userdata_chunk_size
Definition: BLI_task.h:169
short type
struct bNodeTree * nodetree
struct PaintModeSettings paint_mode
struct UnifiedPaintSettings unified_paint_settings
View3DShading shading
struct Depsgraph * depsgraph
Definition: ED_view3d.h:64
struct Scene * scene
Definition: ED_view3d.h:65
struct ARegion * region
Definition: ED_view3d.h:69
struct Object * obact
Definition: ED_view3d.h:67
struct View3D * v3d
Definition: ED_view3d.h:70
struct RegionView3D * rv3d
Definition: ED_view3d.h:72
struct bNodeTreeExec * execdata
ListBase areabase
int ymin
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int mval[2]
Definition: WM_types.h:684
short type
Definition: WM_types.h:678
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:919
const char * name
Definition: WM_types.h:888
int(* modal)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:935
const char * idname
Definition: WM_types.h:890
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:943
void(* cancel)(struct bContext *, struct wmOperator *)
Definition: WM_types.h:927
struct StructRNA * srna
Definition: WM_types.h:969
const char * description
Definition: WM_types.h:893
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:903
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
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:3480
wmOperatorType * ot
Definition: wm_files.c:3479
bScreen * WM_window_get_active_screen(const wmWindow *win)
Definition: wm_window.c:2300