Blender  V3.3
sculpt_detail.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 #include "BLI_blenlib.h"
11 #include "BLI_math.h"
12 
13 #include "BLT_translation.h"
14 
15 #include "DNA_mesh_types.h"
16 
17 #include "BKE_context.h"
18 #include "BKE_paint.h"
19 #include "BKE_pbvh.h"
20 #include "BKE_screen.h"
21 
22 #include "DEG_depsgraph.h"
23 
24 #include "GPU_immediate.h"
25 #include "GPU_immediate_util.h"
26 #include "GPU_matrix.h"
27 #include "GPU_state.h"
28 
29 #include "WM_api.h"
30 #include "WM_types.h"
31 
32 #include "ED_screen.h"
33 #include "ED_sculpt.h"
34 #include "ED_space_api.h"
35 #include "ED_view3d.h"
36 #include "sculpt_intern.h"
37 
38 #include "RNA_access.h"
39 #include "RNA_define.h"
40 
41 #include <math.h>
42 #include <stdlib.h>
43 
44 /* -------------------------------------------------------------------- */
48 typedef struct {
49  const float *ray_start;
50  bool hit;
51  float depth;
52  float edge_length;
53 
54  struct IsectRayPrecalc isect_precalc;
56 
58 {
61 
62  return SCULPT_mode_poll(C) && ob->sculpt->bm &&
64 }
65 
67 {
69 
70  return SCULPT_mode_poll(C) && ob->sculpt->bm;
71 }
72 
75 /* -------------------------------------------------------------------- */
80 {
83  SculptSession *ss = ob->sculpt;
84  float size;
85  float bb_min[3], bb_max[3], center[3], dim[3];
86  int totnodes;
87  PBVHNode **nodes;
88 
89  BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnodes);
90 
91  if (!totnodes) {
92  return OPERATOR_CANCELLED;
93  }
94 
95  for (int i = 0; i < totnodes; i++) {
97  }
98  /* Get the bounding box, its center and size. */
99  BKE_pbvh_bounding_box(ob->sculpt->pbvh, bb_min, bb_max);
100  add_v3_v3v3(center, bb_min, bb_max);
101  mul_v3_fl(center, 0.5f);
102  sub_v3_v3v3(dim, bb_max, bb_min);
103  size = max_fff(dim[0], dim[1], dim[2]);
104 
105  /* Update topology size. */
106  float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat));
107  BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail);
108 
109  SCULPT_undo_push_begin(ob, "Dynamic topology flood fill");
111 
113  ss->pbvh, PBVH_Collapse | PBVH_Subdivide, center, NULL, size, false, false)) {
114  for (int i = 0; i < totnodes; i++) {
116  }
117  }
118 
119  MEM_SAFE_FREE(nodes);
121 
122  /* Force rebuild of PBVH for better BB placement. */
123  SCULPT_pbvh_clear(ob);
124  /* Redraw. */
126 
127  return OPERATOR_FINISHED;
128 }
129 
131 {
132  /* Identifiers. */
133  ot->name = "Detail Flood Fill";
134  ot->idname = "SCULPT_OT_detail_flood_fill";
135  ot->description = "Flood fill the mesh with the selected detail setting";
136 
137  /* API callbacks. */
140 
142 }
143 
146 /* -------------------------------------------------------------------- */
154 
156  {SAMPLE_DETAIL_DYNTOPO, "DYNTOPO", 0, "Dyntopo", "Sample dyntopo detail"},
157  {SAMPLE_DETAIL_VOXEL, "VOXEL", 0, "Voxel", "Sample mesh voxel size"},
158  {0, NULL, 0, NULL, NULL},
159 };
160 
161 static void sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2])
162 {
164  Object *ob = vc->obact;
165  Mesh *mesh = ob->data;
166 
167  SculptSession *ss = ob->sculpt;
170 
171  /* Update the active vertex. */
172  const float mval_fl[2] = {UNPACK2(mval)};
173  SCULPT_cursor_geometry_info_update(C, &sgi, mval_fl, false);
174  BKE_sculpt_update_object_for_edit(depsgraph, ob, true, false, false);
175 
176  /* Average the edge length of the connected edges to the active vertex. */
177  int active_vertex = SCULPT_active_vertex_get(ss);
178  const float *active_vertex_co = SCULPT_active_vertex_co_get(ss);
179  float edge_length = 0.0f;
180  int tot = 0;
182  SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, active_vertex, ni) {
183  edge_length += len_v3v3(active_vertex_co, SCULPT_vertex_co_get(ss, ni.index));
184  tot += 1;
185  }
187  if (tot > 0) {
188  mesh->remesh_voxel_size = edge_length / (float)tot;
189  }
190 }
191 
192 static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin)
193 {
194  if (BKE_pbvh_node_get_tmin(node) < *tmin) {
195  SculptDetailRaycastData *srd = data_v;
197  node, srd->ray_start, &srd->isect_precalc, &srd->depth, &srd->edge_length)) {
198  srd->hit = true;
199  *tmin = srd->depth;
200  }
201  }
202 }
203 
204 static void sample_detail_dyntopo(bContext *C, ViewContext *vc, const int mval[2])
205 {
207  Object *ob = vc->obact;
208  Brush *brush = BKE_paint_brush(&sd->paint);
209 
210  SCULPT_stroke_modifiers_check(C, ob, brush);
211 
212  const float mval_fl[2] = {UNPACK2(mval)};
213  float ray_start[3], ray_end[3], ray_normal[3];
214  float depth = SCULPT_raycast_init(vc, mval_fl, ray_start, ray_end, ray_normal, false);
215 
217  srd.hit = 0;
218  srd.ray_start = ray_start;
219  srd.depth = depth;
220  srd.edge_length = 0.0f;
222 
223  BKE_pbvh_raycast(ob->sculpt->pbvh, sculpt_raycast_detail_cb, &srd, ray_start, ray_normal, false);
224 
225  if (srd.hit && srd.edge_length > 0.0f) {
226  /* Convert edge length to world space detail resolution. */
227  sd->constant_detail = 1 / (srd.edge_length * mat4_to_scale(ob->obmat));
228  }
229 }
230 
231 static int sample_detail(bContext *C, const int event_xy[2], int mode)
232 {
233  /* Find 3D view to pick from. */
234  bScreen *screen = CTX_wm_screen(C);
235  ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_VIEW3D, event_xy);
236  ARegion *region = (area) ? BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, event_xy) : NULL;
237  if (region == NULL) {
238  return OPERATOR_CANCELLED;
239  }
240 
241  /* Set context to 3D view. */
242  ScrArea *prev_area = CTX_wm_area(C);
243  ARegion *prev_region = CTX_wm_region(C);
245  CTX_wm_region_set(C, region);
246 
248  ViewContext vc;
250 
251  Object *ob = vc.obact;
252  if (ob == NULL) {
253  return OPERATOR_CANCELLED;
254  }
255 
256  SculptSession *ss = ob->sculpt;
257  if (!ss->pbvh) {
258  return OPERATOR_CANCELLED;
259  }
260 
261  const int mval[2] = {
262  event_xy[0] - region->winrct.xmin,
263  event_xy[1] - region->winrct.ymin,
264  };
265 
266  /* Pick sample detail. */
267  switch (mode) {
269  if (BKE_pbvh_type(ss->pbvh) != PBVH_BMESH) {
270  CTX_wm_area_set(C, prev_area);
271  CTX_wm_region_set(C, prev_region);
272  return OPERATOR_CANCELLED;
273  }
274  sample_detail_dyntopo(C, &vc, mval);
275  break;
276  case SAMPLE_DETAIL_VOXEL:
277  if (BKE_pbvh_type(ss->pbvh) != PBVH_FACES) {
278  CTX_wm_area_set(C, prev_area);
279  CTX_wm_region_set(C, prev_region);
280  return OPERATOR_CANCELLED;
281  }
282  sample_detail_voxel(C, &vc, mval);
283  break;
284  }
285 
286  /* Restore context. */
287  CTX_wm_area_set(C, prev_area);
288  CTX_wm_region_set(C, prev_region);
289 
290  return OPERATOR_FINISHED;
291 }
292 
294 {
295  int ss_co[2];
296  RNA_int_get_array(op->ptr, "location", ss_co);
297  int mode = RNA_enum_get(op->ptr, "mode");
298  return sample_detail(C, ss_co, mode);
299 }
300 
302 {
303  ED_workspace_status_text(C, TIP_("Click on the mesh to set the detail"));
306  return OPERATOR_RUNNING_MODAL;
307 }
308 
310 {
311  switch (event->type) {
312  case LEFTMOUSE:
313  if (event->val == KM_PRESS) {
314  int mode = RNA_enum_get(op->ptr, "mode");
315  sample_detail(C, event->xy, mode);
316 
317  RNA_int_set_array(op->ptr, "location", event->xy);
321 
322  return OPERATOR_FINISHED;
323  }
324  break;
325  case EVT_ESCKEY:
326  case RIGHTMOUSE: {
329 
330  return OPERATOR_CANCELLED;
331  }
332  }
333 
334  return OPERATOR_RUNNING_MODAL;
335 }
336 
338 {
339  /* Identifiers. */
340  ot->name = "Sample Detail Size";
341  ot->idname = "SCULPT_OT_sample_detail_size";
342  ot->description = "Sample the mesh detail on clicked point";
343 
344  /* API callbacks. */
349 
351 
353  "location",
354  2,
355  NULL,
356  0,
357  SHRT_MAX,
358  "Location",
359  "Screen coordinates of sampling",
360  0,
361  SHRT_MAX);
363  "mode",
366  "Detail Mode",
367  "Target sculpting workflow that is going to use the sampled size");
368 }
369 
372 /* -------------------------------------------------------------------- */
382 static void set_brush_rc_props(PointerRNA *ptr, const char *prop)
383 {
384  char *path = BLI_sprintfN("tool_settings.sculpt.brush.%s", prop);
385  RNA_string_set(ptr, "data_path_primary", path);
386  MEM_freeN(path);
387 }
388 
390 {
392 
393  PointerRNA props_ptr;
394  wmOperatorType *ot = WM_operatortype_find("WM_OT_radial_control", true);
395 
397 
399  set_brush_rc_props(&props_ptr, "constant_detail_resolution");
401  &props_ptr, "data_path_primary", "tool_settings.sculpt.constant_detail_resolution");
402  }
403  else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) {
404  set_brush_rc_props(&props_ptr, "constant_detail_resolution");
405  RNA_string_set(&props_ptr, "data_path_primary", "tool_settings.sculpt.detail_percent");
406  }
407  else {
408  set_brush_rc_props(&props_ptr, "detail_size");
409  RNA_string_set(&props_ptr, "data_path_primary", "tool_settings.sculpt.detail_size");
410  }
411 
413 
414  WM_operator_properties_free(&props_ptr);
415 }
416 
418 {
420 
421  return OPERATOR_FINISHED;
422 }
423 
425 {
426  /* Identifiers. */
427  ot->name = "Set Detail Size";
428  ot->idname = "SCULPT_OT_set_detail_size";
429  ot->description =
430  "Set the mesh detail (either relative or constant one, depending on current dyntopo mode)";
431 
432  /* API callbacks. */
435 
437 }
438 
441 /* -------------------------------------------------------------------- */
445 /* Defines how much the mouse movement will modify the detail size value. */
446 #define DETAIL_SIZE_DELTA_SPEED 0.08f
447 #define DETAIL_SIZE_DELTA_ACCURATE_SPEED 0.004f
448 
450  void *draw_handle;
452 
453  float init_mval[2];
454  float accurate_mval[2];
455 
456  float outline_col[4];
457 
460 
463  float detail_size;
464  float radius;
465 
466  float preview_tri[3][3];
467  float gizmo_mat[4][4];
469 
472  const float start_co[3],
473  const float end_co[3],
474  bool flip,
475  const float angle)
476 {
477  float object_space_constant_detail = 1.0f /
479 
480  /* The constant detail represents the maximum edge length allowed before subdividing it. If the
481  * triangle grid preview is created with this value it will represent an ideal mesh density where
482  * all edges have the exact maximum length, which never happens in practice. As the minimum edge
483  * length for dyntopo is 0.4 * max_edge_length, this adjust the detail size to the average
484  * between max and min edge length so the preview is more accurate. */
485  object_space_constant_detail *= 0.7f;
486 
487  const float total_len = len_v3v3(cd->preview_tri[0], cd->preview_tri[1]);
488  const int tot_lines = (int)(total_len / object_space_constant_detail) + 1;
489  const float tot_lines_fl = total_len / object_space_constant_detail;
490  float spacing_disp[3];
491  sub_v3_v3v3(spacing_disp, end_co, start_co);
492  normalize_v3(spacing_disp);
493 
494  float line_disp[3];
495  rotate_v2_v2fl(line_disp, spacing_disp, DEG2RAD(angle));
496  mul_v3_fl(spacing_disp, total_len / tot_lines_fl);
497 
498  immBegin(GPU_PRIM_LINES, (uint)tot_lines * 2);
499  for (int i = 0; i < tot_lines; i++) {
500  float line_length;
501  if (flip) {
502  line_length = total_len * ((float)i / (float)tot_lines_fl);
503  }
504  else {
505  line_length = total_len * (1.0f - ((float)i / (float)tot_lines_fl));
506  }
507  float line_start[3];
508  copy_v3_v3(line_start, start_co);
509  madd_v3_v3v3fl(line_start, line_start, spacing_disp, i);
510  float line_end[3];
511  madd_v3_v3v3fl(line_end, line_start, line_disp, line_length);
512  immVertex3fv(pos3d, line_start);
513  immVertex3fv(pos3d, line_end);
514  }
515  immEnd();
516 }
517 
519  ARegion *UNUSED(ar),
520  void *arg)
521 {
524  GPU_line_smooth(true);
525 
528  GPU_matrix_push();
530 
531  /* Draw Cursor */
533  GPU_line_width(3.0f);
534 
535  imm_draw_circle_wire_3d(pos3d, 0, 0, cd->radius, 80);
536 
537  /* Draw Triangle. */
538  immUniformColor4f(0.9f, 0.9f, 0.9f, 0.8f);
540  immVertex3fv(pos3d, cd->preview_tri[0]);
541  immVertex3fv(pos3d, cd->preview_tri[1]);
542 
543  immVertex3fv(pos3d, cd->preview_tri[1]);
544  immVertex3fv(pos3d, cd->preview_tri[2]);
545 
546  immVertex3fv(pos3d, cd->preview_tri[2]);
547  immVertex3fv(pos3d, cd->preview_tri[0]);
548  immEnd();
549 
550  /* Draw Grid */
551  GPU_line_width(1.0f);
553  pos3d, cd, cd->preview_tri[0], cd->preview_tri[1], false, 60.0f);
555  pos3d, cd, cd->preview_tri[0], cd->preview_tri[1], true, 120.0f);
557  pos3d, cd, cd->preview_tri[0], cd->preview_tri[2], false, -60.0f);
558 
560  GPU_matrix_pop();
562  GPU_line_smooth(false);
563 }
564 
566 {
567  Object *active_object = CTX_data_active_object(C);
568  SculptSession *ss = active_object->sculpt;
569  ARegion *region = CTX_wm_region(C);
572  ss->draw_faded_cursor = false;
573  MEM_freeN(op->customdata);
575 }
576 
579 {
580  SculptSession *ss = ob->sculpt;
581  const int active_vertex = SCULPT_active_vertex_get(ss);
582 
583  float len_accum = 0;
584  int num_neighbors = 0;
586  SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN (ss, active_vertex, ni) {
587  len_accum += len_v3v3(SCULPT_vertex_co_get(ss, active_vertex),
588  SCULPT_vertex_co_get(ss, ni.index));
589  num_neighbors++;
590  }
592 
593  if (num_neighbors > 0) {
594  const float avg_edge_len = len_accum / num_neighbors;
595  /* Use 0.7 as the average of min and max dyntopo edge length. */
596  const float detail_size = 0.7f / (avg_edge_len * mat4_to_scale(cd->active_object->obmat));
597  cd->detail_size = clamp_f(detail_size, 1.0f, 500.0f);
598  }
599 }
600 
602  const wmEvent *event)
603 {
604  const float mval[2] = {event->mval[0], event->mval[1]};
605 
606  float detail_size_delta;
607  if (cd->accurate_mode) {
608  detail_size_delta = mval[0] - cd->accurate_mval[0];
610  detail_size_delta * DETAIL_SIZE_DELTA_ACCURATE_SPEED;
611  }
612  else {
613  detail_size_delta = mval[0] - cd->init_mval[0];
614  cd->detail_size = cd->init_detail_size + detail_size_delta * DETAIL_SIZE_DELTA_SPEED;
615  }
616 
617  if (event->type == EVT_LEFTSHIFTKEY && event->val == KM_PRESS) {
618  cd->accurate_mode = true;
619  copy_v2_v2(cd->accurate_mval, mval);
621  }
622  if (event->type == EVT_LEFTSHIFTKEY && event->val == KM_RELEASE) {
623  cd->accurate_mode = false;
624  cd->accurate_detail_size = 0.0f;
625  }
626 
627  cd->detail_size = clamp_f(cd->detail_size, 1.0f, 500.0f);
628 }
629 
631 {
632  Object *active_object = CTX_data_active_object(C);
633  SculptSession *ss = active_object->sculpt;
634  ARegion *region = CTX_wm_region(C);
637 
638  /* Cancel modal operator */
639  if ((event->type == EVT_ESCKEY && event->val == KM_PRESS) ||
640  (event->type == RIGHTMOUSE && event->val == KM_PRESS)) {
642  ED_region_tag_redraw(region);
643  return OPERATOR_FINISHED;
644  }
645 
646  /* Finish modal operator */
647  if ((event->type == LEFTMOUSE && event->val == KM_RELEASE) ||
648  (event->type == EVT_RETKEY && event->val == KM_PRESS) ||
649  (event->type == EVT_PADENTER && event->val == KM_PRESS)) {
651  sd->constant_detail = cd->detail_size;
652  ss->draw_faded_cursor = false;
653  MEM_freeN(op->customdata);
654  ED_region_tag_redraw(region);
656  return OPERATOR_FINISHED;
657  }
658 
659  ED_region_tag_redraw(region);
660 
661  if (ELEM(event->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY)) {
662  if (event->val == KM_PRESS) {
663  cd->sample_mode = true;
664  }
665  else if (event->val == KM_RELEASE) {
666  cd->sample_mode = false;
667  }
668  }
669 
670  /* Sample mode sets the detail size sampling the average edge length under the surface. */
671  if (cd->sample_mode) {
672  dyntopo_detail_size_sample_from_surface(active_object, cd);
673  return OPERATOR_RUNNING_MODAL;
674  }
675  /* Regular mode, changes the detail size by moving the cursor. */
677 
678  return OPERATOR_RUNNING_MODAL;
679 }
680 
682 {
684 
685  /* Fallback to radial control for modes other than SCULPT_DYNTOPO_DETAIL_CONSTANT [same as in
686  * SCULPT_OT_set_detail_size]. */
689 
690  return OPERATOR_FINISHED;
691  }
692 
693  /* Special method for SCULPT_DYNTOPO_DETAIL_CONSTANT. */
694  ARegion *region = CTX_wm_region(C);
695  Object *active_object = CTX_data_active_object(C);
696  Brush *brush = BKE_paint_brush(&sd->paint);
697 
699  "Dyntopo Detail Size Edit OP Custom Data");
700 
701  /* Initial operator Custom Data setup. */
704  cd->active_object = active_object;
705  cd->init_mval[0] = event->mval[0];
706  cd->init_mval[1] = event->mval[1];
707  cd->detail_size = sd->constant_detail;
709  copy_v4_v4(cd->outline_col, brush->add_col);
710  op->customdata = cd;
711 
712  SculptSession *ss = active_object->sculpt;
713  cd->radius = ss->cursor_radius;
714 
715  /* Generates the matrix to position the gizmo in the surface of the mesh using the same location
716  * and orientation as the brush cursor. */
717  float cursor_trans[4][4], cursor_rot[4][4];
718  const float z_axis[4] = {0.0f, 0.0f, 1.0f, 0.0f};
719  float quat[4];
720  copy_m4_m4(cursor_trans, active_object->obmat);
721  translate_m4(
722  cursor_trans, ss->cursor_location[0], ss->cursor_location[1], ss->cursor_location[2]);
723 
724  float cursor_normal[3];
725  if (!is_zero_v3(ss->cursor_sampled_normal)) {
726  copy_v3_v3(cursor_normal, ss->cursor_sampled_normal);
727  }
728  else {
729  copy_v3_v3(cursor_normal, ss->cursor_normal);
730  }
731 
732  rotation_between_vecs_to_quat(quat, z_axis, cursor_normal);
733  quat_to_mat4(cursor_rot, quat);
734  copy_m4_m4(cd->gizmo_mat, cursor_trans);
735  mul_m4_m4_post(cd->gizmo_mat, cursor_rot);
736 
737  /* Initialize the position of the triangle vertices. */
738  const float y_axis[3] = {0.0f, cd->radius, 0.0f};
739  for (int i = 0; i < 3; i++) {
740  zero_v3(cd->preview_tri[i]);
741  rotate_v2_v2fl(cd->preview_tri[i], y_axis, DEG2RAD(120.0f * i));
742  }
743 
745 
747  ED_region_tag_redraw(region);
748 
749  ss->draw_faded_cursor = true;
750 
751  const char *status_str = TIP_(
752  "Move the mouse to change the dyntopo detail size. LMB: confirm size, ESC/RMB: cancel");
753  ED_workspace_status_text(C, status_str);
754 
755  return OPERATOR_RUNNING_MODAL;
756 }
757 
759 {
760  /* identifiers */
761  ot->name = "Edit Dyntopo Detail Size";
762  ot->description = "Modify the detail size of dyntopo interactively";
763  ot->idname = "SCULPT_OT_dyntopo_detail_size_edit";
764 
765  /* api callbacks */
770 
772 }
773 
typedef float(TangentPoint)[2]
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
void CTX_wm_region_set(bContext *C, struct ARegion *region)
Definition: context.c:1009
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 bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:733
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
void CTX_wm_area_set(bContext *C, struct ScrArea *area)
Definition: context.c:997
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
Definition: context.c:1282
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
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_brush(struct Paint *paint)
Definition: paint.c:607
A BVH for high poly meshes.
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
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
bool BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3], struct IsectRayPrecalc *isect_precalc, float *depth, float *r_edge_length)
Definition: pbvh_bmesh.c:1560
@ PBVH_Collapse
Definition: BKE_pbvh.h:280
@ PBVH_Subdivide
Definition: BKE_pbvh.h:279
@ PBVH_BMESH
Definition: BKE_pbvh.h:236
@ PBVH_FACES
Definition: BKE_pbvh.h:234
void BKE_pbvh_bounding_box(const PBVH *pbvh, float min[3], float max[3])
Definition: pbvh.c:1812
void BKE_pbvh_bmesh_detail_size_set(PBVH *pbvh, float detail_size)
Definition: pbvh_bmesh.c:2092
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
struct ScrArea struct ScrArea * BKE_screen_find_area_xy(struct bScreen *screen, int spacetype, const int xy[2]) ATTR_NONNULL(1
struct ARegion * BKE_area_find_region_xy(struct ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
Definition: screen.c:898
MINLINE float max_fff(float a, float b, float c)
MINLINE float clamp_f(float value, float min, float max)
void isect_ray_tri_watertight_v3_precalc(struct IsectRayPrecalc *isect_precalc, const float ray_direction[3])
Definition: math_geom.c:1784
void translate_m4(float mat[4][4], float tx, float ty, float tz)
Definition: math_matrix.c:2318
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_m4_m4_post(float R[4][4], const float B[4][4])
Definition: math_matrix.c:380
void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3])
#define DEG2RAD(_deg)
void quat_to_mat4(float mat[4][4], const float q[4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3(float r[3])
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 add_v3_v3v3(float r[3], const float a[3], const float b[3])
void rotate_v2_v2fl(float r[2], const float p[2], float angle)
Definition: math_vector.c:765
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void zero_v3(float r[3])
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
unsigned int uint
Definition: BLI_sys_types.h:67
#define UNPACK2(a)
#define UNUSED(x)
#define ELEM(...)
#define TIP_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
@ SCULPT_DYNTOPO_DETAIL_MANUAL
@ SCULPT_DYNTOPO_DETAIL_CONSTANT
@ SCULPT_DYNTOPO_DETAIL_BRUSH
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:655
void ED_workspace_status_text(struct bContext *C, const char *str)
Definition: area.c:816
#define REGION_DRAW_POST_VIEW
Definition: ED_space_api.h:62
void * ED_region_draw_cb_activate(struct ARegionType *art, void(*draw)(const struct bContext *, struct ARegion *, void *), void *customdata, int type)
Definition: spacetypes.c:226
bool ED_region_draw_cb_exit(struct ARegionType *art, void *handle)
Definition: spacetypes.c:241
void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc, struct Depsgraph *depsgraph)
NSNotificationCenter * center
void immUniformColor4f(float r, float g, float b, float a)
void immUnbindProgram(void)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immUniformColor4fv(const float rgba[4])
GPUVertFormat * immVertexFormat(void)
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments)
void GPU_matrix_pop(void)
Definition: gpu_matrix.cc:126
#define GPU_matrix_mul(x)
Definition: GPU_matrix.h:224
void GPU_matrix_push(void)
Definition: gpu_matrix.cc:119
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:20
@ GPU_SHADER_3D_UNIFORM_COLOR
Definition: GPU_shader.h:230
@ GPU_BLEND_NONE
Definition: GPU_state.h:60
@ GPU_BLEND_ALPHA
Definition: GPU_state.h:62
void GPU_blend(eGPUBlend blend)
Definition: gpu_state.cc:39
void GPU_line_width(float width)
Definition: gpu_state.cc:158
void GPU_line_smooth(bool enable)
Definition: gpu_state.cc:75
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
#define C
Definition: RandGen.cpp:25
@ KM_PRESS
Definition: WM_types.h:267
@ KM_RELEASE
Definition: WM_types.h:268
@ OPTYPE_UNDO
Definition: WM_types.h:148
@ OPTYPE_REGISTER
Definition: WM_types.h:146
#define ND_DRAW
Definition: WM_types.h:410
#define NC_SCENE
Definition: WM_types.h:328
#define ND_TOOLSETTINGS
Definition: WM_types.h:397
@ WM_OP_INVOKE_DEFAULT
Definition: WM_types.h:201
#define NC_OBJECT
Definition: WM_types.h:329
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
OperationNode * node
const Depsgraph * depsgraph
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static void area(int d1, int d2, int e1, int e2, float weights[2])
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
Definition: rna_access.c:4945
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Definition: rna_access.c:4933
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:5155
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
Definition: rna_define.c:3655
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3783
const float * SCULPT_vertex_co_get(SculptSession *ss, int index)
Definition: sculpt.c:125
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
const float * SCULPT_active_vertex_co_get(SculptSession *ss)
Definition: sculpt.c:279
void SCULPT_vertex_random_access_ensure(SculptSession *ss)
Definition: sculpt.c:103
void SCULPT_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush)
Definition: sculpt.c:4712
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
bool SCULPT_mode_poll(bContext *C)
Definition: sculpt.c:3957
static int sculpt_sample_detail_size_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e))
void SCULPT_OT_sample_detail_size(wmOperatorType *ot)
static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin)
static bool sculpt_and_constant_or_manual_detail_poll(bContext *C)
Definition: sculpt_detail.c:57
static void dyntopo_detail_size_edit_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
static int dyntopo_detail_size_edit_modal(bContext *C, wmOperator *op, const wmEvent *event)
void SCULPT_OT_detail_flood_fill(wmOperatorType *ot)
static int sculpt_sample_detail_size_exec(bContext *C, wmOperator *op)
static void dyntopo_detail_size_parallel_lines_draw(uint pos3d, DyntopoDetailSizeEditCustomData *cd, const float start_co[3], const float end_co[3], bool flip, const float angle)
void SCULPT_OT_set_detail_size(wmOperatorType *ot)
static void dyntopo_detail_size_sample_from_surface(Object *ob, DyntopoDetailSizeEditCustomData *cd)
static int sculpt_sample_detail_size_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int sample_detail(bContext *C, const int event_xy[2], int mode)
static void dyntopo_detail_size_update_from_mouse_delta(DyntopoDetailSizeEditCustomData *cd, const wmEvent *event)
static bool sculpt_and_dynamic_topology_poll(bContext *C)
Definition: sculpt_detail.c:66
static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op))
Definition: sculpt_detail.c:79
#define DETAIL_SIZE_DELTA_ACCURATE_SPEED
static void dyntopo_detail_size_edit_cancel(bContext *C, wmOperator *op)
static void sculpt_detail_size_set_radial_control(bContext *C)
struct DyntopoDetailSizeEditCustomData DyntopoDetailSizeEditCustomData
static EnumPropertyItem prop_sculpt_sample_detail_mode_types[]
void SCULPT_OT_dyntopo_detail_size_edit(wmOperatorType *ot)
static void sample_detail_dyntopo(bContext *C, ViewContext *vc, const int mval[2])
eSculptSampleDetailModeTypes
@ SAMPLE_DETAIL_DYNTOPO
@ SAMPLE_DETAIL_VOXEL
static void sample_detail_voxel(bContext *C, ViewContext *vc, const int mval[2])
#define DETAIL_SIZE_DELTA_SPEED
static int sculpt_set_detail_size_exec(bContext *C, wmOperator *UNUSED(op))
static void set_brush_rc_props(PointerRNA *ptr, const char *prop)
static int dyntopo_detail_size_edit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void SCULPT_pbvh_clear(Object *ob)
void SCULPT_undo_push_begin(struct Object *ob, const char *name)
Definition: sculpt_undo.c:1545
void SCULPT_undo_push_end(struct Object *ob)
Definition: sculpt_undo.c:1575
#define SCULPT_VERTEX_NEIGHBORS_ITER_BEGIN(ss, v_index, neighbor_iterator)
#define SCULPT_VERTEX_NEIGHBORS_ITER_END(neighbor_iterator)
SculptUndoNode * SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType type)
Definition: sculpt_undo.c:1419
@ SCULPT_UNDO_COORDS
struct ARegionType * type
float add_col[4]
float remesh_voxel_size
float obmat[4][4]
struct SculptSession * sculpt
void * data
struct IsectRayPrecalc isect_precalc
Definition: sculpt_detail.c:54
const float * ray_start
Definition: sculpt_detail.c:49
float cursor_normal[3]
Definition: BKE_paint.h:578
float cursor_location[3]
Definition: BKE_paint.h:577
bool draw_faded_cursor
Definition: BKE_paint.h:575
float cursor_radius
Definition: BKE_paint.h:576
struct BMesh * bm
Definition: BKE_paint.h:539
float cursor_sampled_normal[3]
Definition: BKE_paint.h:579
struct PBVH * pbvh
Definition: BKE_paint.h:550
Paint paint
float constant_detail
struct Object * obact
Definition: ED_view3d.h:67
int ymin
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
short val
Definition: WM_types.h:680
int xy[2]
Definition: WM_types.h:682
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 PointerRNA * ptr
void WM_cursor_modal_set(wmWindow *win, int val)
Definition: wm_cursors.c:191
void WM_cursor_modal_restore(wmWindow *win)
Definition: wm_cursors.c:200
@ WM_CURSOR_EYEDROPPER
Definition: wm_cursors.h:35
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_main_add_notifier(unsigned int type, void *reference)
int WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ RIGHTMOUSE
@ EVT_RIGHTCTRLKEY
@ EVT_LEFTCTRLKEY
@ EVT_PADENTER
@ LEFTMOUSE
@ EVT_ESCKEY
@ EVT_LEFTSHIFTKEY
@ EVT_RETKEY
PointerRNA * ptr
Definition: wm_files.c:3480
wmOperatorType * ot
Definition: wm_files.c:3479
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
Definition: wm_operators.c:661
void WM_operator_properties_free(PointerRNA *ptr)
Definition: wm_operators.c:783