Blender V5.3
mesh/sculpt_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 by Nicholas Bishop. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#include "MEM_guardedalloc.h"
11
13#include "BLI_math_matrix.hh"
14#include "BLI_math_vector.hh"
15
16#include "BLT_translation.hh"
17
18#include "DNA_brush_types.h"
19#include "DNA_listBase.h"
20#include "DNA_node_types.h"
21#include "DNA_object_types.h"
22#include "DNA_scene_types.h"
23
24#include "BKE_attribute.hh"
25#include "BKE_brush.hh"
26#include "BKE_ccg.hh"
27#include "BKE_context.hh"
28#include "BKE_layer.hh"
29#include "BKE_main.hh"
30#include "BKE_material.hh"
31#include "BKE_mesh.hh"
32#include "BKE_mesh_mirror.hh"
33#include "BKE_multires.hh"
34#include "BKE_object.hh"
35#include "BKE_object_types.hh"
36#include "BKE_paint.hh"
37#include "BKE_paint_bvh.hh"
38#include "BKE_paint_types.hh"
39#include "BKE_report.hh"
40#include "BKE_scene.hh"
41#include "BKE_subdiv_ccg.hh"
42
43#include "DEG_depsgraph.hh"
44
46
47#include "WM_api.hh"
48#include "WM_message.hh"
49#include "WM_toolsystem.hh"
50#include "WM_types.hh"
51
52#include "ED_image.hh"
53#include "ED_object.hh"
54#include "ED_paint.hh"
55#include "ED_screen.hh"
56#include "ED_sculpt.hh"
57
58#include "../paint_intern.hh"
59#include "mesh_brush_common.hh"
60#include "mesh_paint.hh"
61#include "paint_mask.hh"
62#include "sculpt_automask.hh"
63#include "sculpt_color.hh"
64#include "sculpt_dyntopo.hh"
65#include "sculpt_flood_fill.hh"
66#include "sculpt_intern.hh"
67#include "sculpt_undo.hh"
68
69#include "RNA_access.hh"
70#include "RNA_define.hh"
71
72#include "UI_interface.hh"
74#include "UI_resources.hh"
75
76#include "bmesh.hh"
77
78#include <cmath>
79#include <cstring>
80
82
83/* -------------------------------------------------------------------- */
86
88{
89 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
92
93 const View3D *v3d = CTX_wm_view3d(C);
94 const Base *base = CTX_data_active_base(C);
95 if (!BKE_base_is_visible(v3d, base)) {
96 return OPERATOR_CANCELLED;
97 }
98
99 if (!ss) {
100 return OPERATOR_CANCELLED;
101 }
102
103 BKE_sculptsession_update_for_edit(depsgraph, &ob, false);
104
105 switch (bke::object::pbvh_get(ob)->type()) {
107 Mesh &mesh = *id_cast<Mesh *>(ob.data);
108 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
109 attributes.remove(".sculpt_persistent_co");
110 attributes.remove(".sculpt_persistent_no");
111 attributes.remove(".sculpt_persistent_disp");
112
113 const bke::AttributeReader positions = attributes.lookup<float3>("position");
114 if (positions.sharing_info && positions.varray.is_span()) {
115 attributes.add<float3>(
116 ".sculpt_persistent_co",
118 bke::AttributeInitShared(positions.varray.get_internal_span().data(),
119 *positions.sharing_info));
120 }
121 else {
122 attributes.add<float3>(".sculpt_persistent_co",
125 }
126
127 const Span<float3> vert_normals = bke::pbvh::vert_normals_eval(*depsgraph, ob);
128 attributes.add<float3>(".sculpt_persistent_no",
131 break;
132 }
134 const SubdivCCG &subdiv_ccg = *ss->subdiv_ccg;
135 ss->persistent.sculpt_persistent_co = subdiv_ccg.positions;
136 ss->persistent.sculpt_persistent_no = subdiv_ccg.normals;
137 ss->persistent.sculpt_persistent_disp = Array<float>(subdiv_ccg.positions.size(), 0.0f);
138 ss->persistent.grid_size = subdiv_ccg.grid_size;
139 ss->persistent.grids_num = subdiv_ccg.grids_num;
140 break;
141 }
143 return OPERATOR_CANCELLED;
144 }
145 }
146
147 return OPERATOR_FINISHED;
148}
149
151{
152 ot->name = "Set Persistent Base";
153 ot->idname = "SCULPT_OT_set_persistent_base";
154 ot->description = "Reset the copy of the mesh that is being sculpted on";
155
158
160}
161
163
164/* -------------------------------------------------------------------- */
167
179
180/* The BVH gets less optimal more quickly with dynamic topology than
181 * regular sculpting. There is no doubt more clever stuff we can do to
182 * optimize it on the fly, but for now this gives the user a nicer way
183 * to recalculate it than toggling modes. */
185{
186 ot->name = "Rebuild BVH";
187 ot->idname = "SCULPT_OT_optimize";
188 ot->description = "Recalculate the sculpt BVH to improve performance";
189
190 ot->exec = optimize_exec;
192
193 ot->flag = OPTYPE_REGISTER;
194}
195
197
198/* -------------------------------------------------------------------- */
201
203{
205 if (!ob) {
206 return false;
207 }
208 if (ob->type != OB_MESH) {
209 return false;
210 }
212 if (sculpt_mode_poll(C) && ob->runtime->sculpt_session && pbvh) {
213 return pbvh->type() != bke::pbvh::Type::Grids;
214 }
215 return false;
216}
217
219{
220 Main *bmain = CTX_data_main(C);
221 const Scene &scene = *CTX_data_scene(C);
222 const Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C);
224 const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
227 const float dist = RNA_float_get(op->ptr, "merge_tolerance");
228
229 if (!pbvh) {
230 return OPERATOR_CANCELLED;
231 }
232
233 const View3D *v3d = CTX_wm_view3d(C);
234 const Base *base = CTX_data_active_base(C);
235 if (!BKE_base_is_visible(v3d, base)) {
236 return OPERATOR_CANCELLED;
237 }
238
239 switch (pbvh->type()) {
241 /* Dyntopo Symmetrize. */
242
243 /* To simplify undo for symmetrize, all BMesh elements are logged
244 * as deleted, then after symmetrize operation all BMesh elements
245 * are logged as added (as opposed to attempting to store just the
246 * parts that symmetrize modifies). */
247 undo::push_begin(scene, ob, op);
248 undo::push_node(depsgraph, ob, nullptr, undo::Type::Geometry);
250
251 BM_mesh_toolflags_set(ss.bm, true);
252
253 /* Symmetrize and re-triangulate. */
254 BMO_op_callf(ss.bm,
256 "symmetrize input=%avef direction=%i dist=%f use_shapekey=%b",
258 dist,
259 true);
261
262 /* Bisect operator flags edges (keep tags clean for edge queue). */
264
265 BM_mesh_toolflags_set(ss.bm, false);
266
267 /* Finish undo. */
268 BM_log_all_added(ss.bm, ss.bm_log);
269 undo::push_end(ob);
270
271 break;
272 }
274 /* Mesh Symmetrize. */
275 undo::geometry_begin(scene, ob, op);
276 Mesh *mesh = id_cast<Mesh *>(ob.data);
277
279
282
283 break;
284 }
286 return OPERATOR_CANCELLED;
287 }
288
292
293 return OPERATOR_FINISHED;
294}
295
297{
298 ot->name = "Symmetrize";
299 ot->idname = "SCULPT_OT_symmetrize";
300 ot->description = "Symmetrize the topology modifications";
301
302 ot->exec = symmetrize_exec;
304
305 PropertyRNA *prop = RNA_def_float(ot->srna,
306 "merge_tolerance",
307 0.0005f,
308 0.0f,
309 std::numeric_limits<float>::max(),
310 "Merge Distance",
311 "Distance within which symmetrical vertices are merged",
312 0.0f,
313 1.0f);
314
315 RNA_def_property_ui_range(prop, 0.0, std::numeric_limits<float>::max(), 0.001, 5);
316}
317
319
320/* -------------------------------------------------------------------- */
323
325 Depsgraph &depsgraph,
326 Scene &scene,
327 Object &ob,
328 const bool force_dyntopo,
329 ReportList *reports)
330{
332
333 /* Re-triangulating the mesh for position changes in sculpt mode isn't worth the performance
334 * impact, so delay triangulation updates until the user exits sculpt mode. */
335 mesh->runtime->corner_tris_cache.freeze();
336
337 if (!(fabsf(ob.scale[0] - ob.scale[1]) < 1e-4f && fabsf(ob.scale[1] - ob.scale[2]) < 1e-4f)) {
339 reports, RPT_WARNING, "Object has non-uniform scale, sculpting may be unpredictable");
340 }
341 else if (is_negative_m4(ob.object_to_world().ptr())) {
342 BKE_report(reports, RPT_WARNING, "Object has negative scale, sculpting may be unpredictable");
343 }
344
345 ed::sculpt_paint::mode_enter_generic(bmain, depsgraph, scene, ob, OB_MODE_SCULPT);
346
347 if (mesh->attributes().contains(".sculpt_face_set")) {
348 /* Here we can detect geometry that was just added to Sculpt Mode as it has the
349 * face_set_none assigned, so we can create a new face set for it. */
350 /* In sculpt mode all geometry that is assigned to face_set_none is considered as not
351 * initialized, which is used is some operators that modify the mesh topology to perform
352 * certain actions in the new faces. After these operations are finished, all faces should have
353 * a valid face set ID assigned (different from face_set_none) to manage their
354 * visibility correctly. */
355 /* TODO(pablodp606): Based on this we can improve the UX in future tools for creating new
356 * objects, like moving the transform pivot position to the new area or masking existing
357 * geometry. */
358 const int new_face_set = face_set::find_next_available_id(ob);
359 face_set::initialize_none_to_id(id_cast<Mesh *>(ob.data), new_face_set);
360 }
361
362 /* Check dynamic-topology flag; re-enter dynamic-topology mode when changing modes,
363 * As long as no data was added that is not supported. */
364 if (mesh->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) {
366
367 const char *message_unsupported = nullptr;
368 if (mesh->corners_num != mesh->faces_num * 3) {
369 message_unsupported = RPT_("non-triangle face");
370 }
371 else if (mmd != nullptr) {
372 message_unsupported = RPT_("multi-res modifier");
373 }
374 else {
376 if (flag == 0) {
377 /* pass */
378 }
379 else if (flag & dyntopo::ATTRIBUTES) {
380 BKE_report(reports,
382 "Dyntopo will not preserve face sets, colors, UVs, or other attributes");
383 }
384 else if (flag & dyntopo::MODIFIER) {
385 message_unsupported = RPT_("constructive modifier");
386 }
387 else {
389 }
390 }
391
392 if ((message_unsupported == nullptr) || force_dyntopo) {
393 /* Needed because we may be entering this mode before the undo system loads. */
394 wmWindowManager *wm = bmain.wm.first();
395 const bool has_undo = wm->runtime->undo_stack != nullptr;
396 /* Undo push is needed to prevent memory leak. */
397 if (has_undo) {
398 undo::push_begin_ex(scene, ob, "Dynamic topology enable");
399 }
400 dyntopo::enable_ex(bmain, depsgraph, ob);
401 if (has_undo) {
402 undo::push_node(depsgraph, ob, nullptr, undo::Type::DyntopoBegin);
403 undo::push_end(ob);
404 }
405 }
406 else {
408 reports, RPT_WARNING, "Dynamic Topology found: %s, disabled", message_unsupported);
410 }
411 }
412
413 /* Flush object mode. */
415}
416
417void object_sculpt_mode_enter(bContext *C, Depsgraph &depsgraph, ReportList *reports)
418{
419 Main &bmain = *CTX_data_main(C);
420 Scene &scene = *CTX_data_scene(C);
421 ViewLayer &view_layer = *CTX_data_view_layer(C);
422 BKE_view_layer_synced_ensure(bmain, &scene, &view_layer);
423 Object &ob = *BKE_view_layer_active_object_get(&view_layer);
424 object_sculpt_mode_enter(bmain, depsgraph, scene, ob, false, reports);
425}
426
427void object_sculpt_mode_exit(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob)
428{
430
431 mesh->runtime->corner_tris_cache.unfreeze();
432
434
435 if (mesh->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) {
436 /* Dynamic topology must be disabled before exiting sculpt
437 * mode to ensure the undo stack stays in a consistent
438 * state. */
439 dyntopo::disable_with_undo(bmain, depsgraph, scene, ob);
440
441 /* Store so we know to re-enable when entering sculpt mode. */
443 }
444
447}
448
449void object_sculpt_mode_exit(bContext *C, Depsgraph &depsgraph)
450{
451 Main &bmain = *CTX_data_main(C);
452 Scene &scene = *CTX_data_scene(C);
453 ViewLayer &view_layer = *CTX_data_view_layer(C);
454 BKE_view_layer_synced_ensure(bmain, &scene, &view_layer);
455 Object &ob = *BKE_view_layer_active_object_get(&view_layer);
456 object_sculpt_mode_exit(bmain, depsgraph, scene, ob);
457}
458
460{
462 Main &bmain = *CTX_data_main(C);
463 Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
464 Scene &scene = *CTX_data_scene(C);
465 ViewLayer &view_layer = *CTX_data_view_layer(C);
466 BKE_view_layer_synced_ensure(bmain, &scene, &view_layer);
467 Object &ob = *BKE_view_layer_active_object_get(&view_layer);
468 const eObjectMode mode_flag = OB_MODE_SCULPT;
469 const bool is_mode_set = (ob.mode & mode_flag) != 0;
470
471 if (!is_mode_set) {
472 if (!object::mode_compat_set(C, &ob, eObjectMode(mode_flag), op->reports)) {
473 return OPERATOR_CANCELLED;
474 }
475 }
476
477 if (is_mode_set) {
478 object_sculpt_mode_exit(bmain, *depsgraph, scene, ob);
479 }
480 else {
481 if (depsgraph) {
483 }
484 object_sculpt_mode_enter(bmain, *depsgraph, scene, ob, false, op->reports);
485
486 if (ob.mode & mode_flag) {
487 Mesh *mesh = id_cast<Mesh *>(ob.data);
488 /* Dyntopo adds its own undo step. */
489 if ((mesh->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) == 0) {
490 /* Without this the memfile undo step is used,
491 * while it works it causes lag when undoing the first undo step, see #71564. */
493 if (wm->op_undo_depth <= 1) {
494 undo::push_enter_sculpt_mode(scene, ob, op);
495 undo::push_end(ob);
496 }
497 }
498 }
499 }
500
502
503 WM_msg_publish_rna_prop(mbus, &ob.id, &ob, Object, mode);
504
506
507 return OPERATOR_FINISHED;
508}
509
511{
512 ot->name = "Sculpt Mode";
513 ot->idname = "SCULPT_OT_sculptmode_toggle";
514 ot->description = "Toggle sculpt mode in 3D view";
515
518
520}
521
523
524namespace mask {
525
526/* -------------------------------------------------------------------- */
529
539#define MASK_BY_COLOR_SLOPE 0.25f
540
541static float color_delta_get(const float3 &color_a,
542 const float3 &color_b,
543 const float threshold,
544 const bool invert)
545{
546 float len = math::distance(color_a, color_b);
547 /* Normalize len to the (0, 1) range. */
548 len = len / std::numbers::sqrt3_v<float>;
549
550 if (len < threshold - MASK_BY_COLOR_SLOPE) {
551 len = 1.0f;
552 }
553 else if (len >= threshold) {
554 len = 0.0f;
555 }
556 else {
557 len = (-len + threshold) / MASK_BY_COLOR_SLOPE;
558 }
559
560 if (invert) {
561 return 1.0f - len;
562 }
563 return len;
564}
565
566static float final_mask_get(const float current_mask,
567 const float new_mask,
568 const bool invert,
569 const bool preserve_mask)
570{
571 if (preserve_mask) {
572 if (invert) {
573 return std::min(current_mask, new_mask);
574 }
575 return std::max(current_mask, new_mask);
576 }
577 return new_mask;
578}
579
580static void mask_by_color_contiguous_mesh(const Depsgraph &depsgraph,
581 Object &object,
582 const int vert,
583 const float threshold,
584 const bool invert,
585 const bool preserve_mask)
586{
588 const Mesh &mesh = *id_cast<const Mesh *>(object.data);
589 const GroupedSpan<int> vert_to_face_map = mesh.vert_to_face_map();
590 const bke::AttributeAccessor attributes = mesh.attributes();
591 const VArraySpan colors = *attributes.lookup_or_default<ColorGeometry4f>(
592 mesh.active_color_attribute, bke::AttrDomain::Point, {});
593 const float4 active_color = float4(colors[vert]);
594
595 Array<float> new_mask(mesh.verts_num, invert ? 1.0f : 0.0f);
596
597 flood_fill::FillDataMesh flood(mesh.verts_num);
598 flood.add_initial(vert);
599
600 flood.execute(object, vert_to_face_map, [&](int /*from_v*/, int to_v) {
601 const float4 current_color = float4(colors[to_v]);
602
603 float new_vertex_mask = color_delta_get(
604 current_color.xyz(), active_color.xyz(), threshold, invert);
605 new_mask[to_v] = new_vertex_mask;
606
607 float len = math::distance(current_color.xyz(), active_color.xyz());
608 len = len / std::numbers::sqrt3_v<float>;
609 return len <= threshold;
610 });
611
612 IndexMaskMemory memory;
613 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
614
616 depsgraph, object, node_mask, [&](MutableSpan<float> node_masks, const Span<int> verts) {
617 for (const int i : verts.index_range()) {
618 node_masks[i] = final_mask_get(node_masks[i], new_mask[verts[i]], invert, preserve_mask);
619 }
620 });
621}
622
623static void mask_by_color_full_mesh(const Depsgraph &depsgraph,
624 Object &object,
625 const int vert,
626 const float threshold,
627 const bool invert,
628 const bool preserve_mask)
629{
631 const Mesh &mesh = *id_cast<const Mesh *>(object.data);
632 const bke::AttributeAccessor attributes = mesh.attributes();
633 const VArraySpan colors = *attributes.lookup_or_default<ColorGeometry4f>(
634 mesh.active_color_attribute, bke::AttrDomain::Point, {});
635 const float4 active_color = float4(colors[vert]);
636
637 IndexMaskMemory memory;
638 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
639
641 depsgraph, object, node_mask, [&](MutableSpan<float> node_masks, const Span<int> verts) {
642 for (const int i : verts.index_range()) {
643 const float4 current_color = float4(colors[verts[i]]);
644 const float current_mask = node_masks[i];
645 const float new_mask = color_delta_get(
646 active_color.xyz(), current_color.xyz(), threshold, invert);
647 node_masks[i] = final_mask_get(current_mask, new_mask, invert, preserve_mask);
648 }
649 });
650}
651
652static wmOperatorStatus mask_by_color(bContext *C, wmOperator *op, const float2 region_location)
653{
654 const Scene &scene = *CTX_data_scene(C);
655 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
658 View3D *v3d = CTX_wm_view3d(C);
659
660 {
661 if (v3d && v3d->shading.type == OB_SOLID) {
663 }
664 }
665
666 const Base *base = CTX_data_active_base(C);
667 if (!BKE_base_is_visible(v3d, base)) {
668 return OPERATOR_CANCELLED;
669 }
670
672
673 /* Color data is not available in multi-resolution or dynamic topology. */
674 if (!color_supported_check(scene, ob, op->reports)) {
675 return OPERATOR_CANCELLED;
676 }
677
678 BKE_sculptsession_update_for_edit(depsgraph, &ob, false);
679
680 /* Tools that are not brushes do not have the brush gizmo to update the vertex as the mouse move,
681 * so it needs to be updated here. */
682 cursor_geometry_info_update(C, region_location, false);
683
684 if (std::holds_alternative<std::monostate>(ss.active_vert())) {
685 return OPERATOR_CANCELLED;
686 }
687
688 undo::push_begin(scene, ob, op);
690
691 const float threshold = RNA_float_get(op->ptr, "threshold");
692 const bool invert = RNA_boolean_get(op->ptr, "invert");
693 const bool preserve_mask = RNA_boolean_get(op->ptr, "preserve_previous_mask");
694
695 const int active_vert = std::get<int>(ss.active_vert());
696 if (RNA_boolean_get(op->ptr, "contiguous")) {
697 mask_by_color_contiguous_mesh(*depsgraph, ob, active_vert, threshold, invert, preserve_mask);
698 }
699 else {
700 mask_by_color_full_mesh(*depsgraph, ob, active_vert, threshold, invert, preserve_mask);
701 }
702
703 undo::push_end(ob);
704
707
708 return OPERATOR_FINISHED;
709}
710
712{
713 int2 mval;
714 RNA_int_get_array(op->ptr, "location", mval);
715 return mask_by_color(C, op, float2(mval[0], mval[1]));
716}
717
719{
720 RNA_int_set_array(op->ptr, "location", event->mval);
721 return mask_by_color(C, op, float2(event->mval[0], event->mval[1]));
722}
723
725{
726 ot->name = "Mask by Color";
727 ot->idname = "SCULPT_OT_mask_by_color";
728 ot->description = "Creates a mask based on the active color attribute";
729
733
735
736 ot->prop = RNA_def_boolean(
737 ot->srna, "contiguous", false, "Contiguous", "Mask only contiguous color areas");
738
739 ot->prop = RNA_def_boolean(ot->srna, "invert", false, "Invert", "Invert the generated mask");
740 ot->prop = RNA_def_boolean(
741 ot->srna,
742 "preserve_previous_mask",
743 false,
744 "Preserve Previous Mask",
745 "Preserve the previous mask and add or subtract the new one generated by the colors");
746
748 "threshold",
749 0.35f,
750 0.0f,
751 1.0f,
752 "Threshold",
753 "How much changes in color affect the mask generation",
754 0.0f,
755 1.0f);
756
757 ot->prop = RNA_def_int_array(ot->srna,
758 "location",
759 2,
760 nullptr,
761 0,
762 SHRT_MAX,
763 "Location",
764 "Region coordinates of sampling",
765 0,
766 SHRT_MAX);
768}
769
771
772/* -------------------------------------------------------------------- */
775
776enum class ApplyMaskMode : int8_t {
780 Add,
781 Subtract,
782};
783
785 {int(ApplyMaskMode::Mix), "MIX", ICON_NONE, "Mix", ""},
786 {int(ApplyMaskMode::Multiply), "MULTIPLY", ICON_NONE, "Multiply", ""},
787 {int(ApplyMaskMode::Divide), "DIVIDE", ICON_NONE, "Divide", ""},
788 {int(ApplyMaskMode::Add), "ADD", ICON_NONE, "Add", ""},
789 {int(ApplyMaskMode::Subtract), "SUBTRACT", ICON_NONE, "Subtract", ""},
790 {0, nullptr, 0, nullptr, nullptr},
791};
792
794
797 "OPERATOR",
798 ICON_NONE,
799 "Operator",
800 "Use settings from operator properties"},
801 {int(MaskSettingsSource::Brush), "BRUSH", ICON_NONE, "Brush", "Use settings from brush"},
802 {int(MaskSettingsSource::Scene), "SCENE", ICON_NONE, "Scene", "Use settings from scene"},
803 {0, nullptr, 0, nullptr, nullptr}};
804
810
811static void calc_new_masks(const ApplyMaskMode mode,
812 const Span<float> node_mask,
813 const MutableSpan<float> new_mask)
814{
815 switch (mode) {
817 break;
819 for (const int i : node_mask.index_range()) {
820 new_mask[i] = node_mask[i] * new_mask[i];
821 }
822 break;
824 for (const int i : node_mask.index_range()) {
825 new_mask[i] = new_mask[i] > 0.00001f ? node_mask[i] / new_mask[i] : 0.0f;
826 }
827 break;
829 for (const int i : node_mask.index_range()) {
830 new_mask[i] = node_mask[i] + new_mask[i];
831 }
832 break;
834 for (const int i : node_mask.index_range()) {
835 new_mask[i] = node_mask[i] - new_mask[i];
836 }
837 break;
838 }
839 mask::clamp_mask(new_mask);
840}
841
842static void apply_mask_mesh(const Depsgraph &depsgraph,
843 const Object &object,
844 const Span<bool> hide_vert,
845 const auto_mask::Cache &automasking,
846 const ApplyMaskMode mode,
847 const float factor,
849 LocalData &tls,
851{
852 const Span<int> verts = node.verts();
853
854 tls.factors.resize(verts.size());
855 const MutableSpan<float> factors = tls.factors;
856 fill_factor_from_hide(hide_vert, verts, factors);
857 scale_factors(factors, factor);
858
859 tls.new_mask.resize(verts.size());
860 const MutableSpan<float> new_mask = tls.new_mask;
861 new_mask.fill(1.0f);
862 auto_mask::calc_vert_factors(depsgraph, object, automasking, node, verts, new_mask);
863
864 mask::invert_mask(new_mask);
865
866 tls.mask.resize(verts.size());
867 const MutableSpan<float> node_mask = tls.mask;
868 gather_data_mesh(mask.as_span(), verts, node_mask);
869
870 calc_new_masks(mode, node_mask, new_mask);
871 mix_new_masks(new_mask, factors, node_mask);
872
873 scatter_data_mesh(node_mask.as_span(), verts, mask);
874}
875
876static void apply_mask_grids(const Depsgraph &depsgraph,
877 Object &object,
878 const auto_mask::Cache &automasking,
879 const ApplyMaskMode mode,
880 const float factor,
882 LocalData &tls)
883{
884 SculptSession &ss = *object.runtime->sculpt_session;
885 SubdivCCG &subdiv_ccg = *ss.subdiv_ccg;
886 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
887
888 const Span<int> grids = node.grids();
889 const int grid_verts_num = grids.size() * key.grid_area;
890
891 tls.factors.resize(grid_verts_num);
892 const MutableSpan<float> factors = tls.factors;
893 fill_factor_from_hide(subdiv_ccg, grids, factors);
894 scale_factors(factors, factor);
895
896 tls.new_mask.resize(grid_verts_num);
897 const MutableSpan<float> new_mask = tls.new_mask;
898 new_mask.fill(1.0f);
899 auto_mask::calc_grids_factors(depsgraph, object, automasking, node, grids, new_mask);
900
901 mask::invert_mask(new_mask);
902
903 tls.mask.resize(grid_verts_num);
904 const MutableSpan<float> node_mask = tls.mask;
905 gather_mask_grids(subdiv_ccg, grids, node_mask);
906
907 calc_new_masks(mode, node_mask, new_mask);
908 mix_new_masks(new_mask, factors, node_mask);
909
910 scatter_mask_grids(node_mask.as_span(), subdiv_ccg, grids);
911}
912
913static void apply_mask_bmesh(const Depsgraph &depsgraph,
914 Object &object,
915 const auto_mask::Cache &automasking,
916 const ApplyMaskMode mode,
917 const float factor,
919 LocalData &tls)
920{
921 const SculptSession &ss = *object.runtime->sculpt_session;
923
924 tls.factors.resize(verts.size());
925 const MutableSpan<float> factors = tls.factors;
926 fill_factor_from_hide(verts, factors);
927 scale_factors(factors, factor);
928
929 tls.new_mask.resize(verts.size());
930 const MutableSpan<float> new_mask = tls.new_mask;
931 new_mask.fill(1.0f);
932 auto_mask::calc_vert_factors(depsgraph, object, automasking, node, verts, new_mask);
933
934 mask::invert_mask(new_mask);
935
936 tls.mask.resize(verts.size());
937 const MutableSpan<float> node_mask = tls.mask;
938 gather_mask_bmesh(*ss.bm, verts, node_mask);
939
940 calc_new_masks(mode, node_mask, new_mask);
941 mix_new_masks(new_mask, factors, node_mask);
942
943 scatter_mask_bmesh(node_mask.as_span(), *ss.bm, verts);
944}
945
946static void apply_mask_from_settings(const Depsgraph &depsgraph,
947 Object &object,
949 const IndexMask &node_mask,
950 const auto_mask::Cache &automasking,
951 const ApplyMaskMode mode,
952 const float factor)
953{
955 switch (pbvh.type()) {
957 Mesh &mesh = *id_cast<Mesh *>(object.data);
958 bke::MutableAttributeAccessor attributes = mesh.attributes_for_write();
960 ".sculpt_mask", bke::AttrDomain::Point);
961 const VArraySpan hide_vert = *attributes.lookup<bool>(".hide_vert", bke::AttrDomain::Point);
963 node_mask.foreach_index(
964 [&](const int i) {
965 LocalData &tls = all_tls.local();
967 depsgraph, object, hide_vert, automasking, mode, factor, nodes[i], tls, mask.span);
969 },
971 mask.finish();
972 break;
973 }
975 SubdivCCG &subdiv_ccg = *object.runtime->sculpt_session->subdiv_ccg;
976 const CCGKey key = BKE_subdiv_ccg_key_top_level(subdiv_ccg);
977 MutableSpan<float> masks = subdiv_ccg.masks;
979 node_mask.foreach_index(
980 [&](const int i) {
981 LocalData &tls = all_tls.local();
982 apply_mask_grids(depsgraph, object, automasking, mode, factor, nodes[i], tls);
984 },
986 break;
987 }
989 const int mask_offset = CustomData_get_offset_named(
990 &object.runtime->sculpt_session->bm->vdata, CD_PROP_FLOAT, ".sculpt_mask");
992 node_mask.foreach_index(
993 [&](const int i) {
994 LocalData &tls = all_tls.local();
995 apply_mask_bmesh(depsgraph, object, automasking, mode, factor, nodes[i], tls);
997 },
999 break;
1000 }
1001 }
1002}
1003
1005{
1006 const Scene &scene = *CTX_data_scene(C);
1007 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
1009 const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
1010 const Paint &paint = sd.paint;
1012
1013 const View3D *v3d = CTX_wm_view3d(C);
1014 const Base *base = CTX_data_active_base(C);
1015 if (!BKE_base_is_visible(v3d, base)) {
1016 return OPERATOR_CANCELLED;
1017 }
1018
1020 BKE_sculpt_mask_layers_ensure(depsgraph, CTX_data_main(C), &ob, mmd);
1021
1023
1024 BKE_sculptsession_update_for_edit(depsgraph, &ob, false);
1026
1027 const ApplyMaskMode mode = ApplyMaskMode(RNA_enum_get(op->ptr, "mix_mode"));
1028 const float factor = RNA_float_get(op->ptr, "mix_factor");
1029
1031
1032 IndexMaskMemory memory;
1033 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
1034
1035 /* Set up automasking settings. */
1036 Paint scene_copy = dna::shallow_copy(sd.paint);
1037 /* We don't do a deep copy of the automasking settings, we simply need a new one so that the
1038 * canonical pointer isn't overwritten. */
1039 MeshAutomaskingSettings automasking_settings;
1040 scene_copy.mesh_automasking_settings = &automasking_settings;
1041
1042 /* TODO: This pattern of recreating the scene / brush and using them as the "settings" is weak
1043 * and can cause hard to find bugs due to modifying actual data. This should be refactored to
1044 * take in a options struct */
1045 MaskSettingsSource src = MaskSettingsSource(RNA_enum_get(op->ptr, "settings_source"));
1046 switch (src) {
1048 if (RNA_boolean_get(op->ptr, "invert")) {
1050 }
1051 else {
1053 }
1054
1055 if (RNA_boolean_get(op->ptr, "use_curve")) {
1057 }
1058
1059 scene_copy.mesh_automasking_settings->cavity_blur_steps = RNA_int_get(op->ptr, "blur_steps");
1060 scene_copy.mesh_automasking_settings->cavity_factor = RNA_float_get(op->ptr, "factor");
1061
1063 paint.mesh_automasking_settings->cavity_curve_op;
1064 break;
1066 if (brush) {
1067 scene_copy.mesh_automasking_settings->flags = brush->mesh_automasking_settings->flags;
1069 brush->mesh_automasking_settings->cavity_factor;
1071 brush->mesh_automasking_settings->cavity_curve;
1073 brush->mesh_automasking_settings->cavity_blur_steps;
1074
1075 /* Ensure only cavity masking is enabled. */
1078 }
1079 else {
1081 BKE_report(op->reports, RPT_WARNING, "No active brush");
1082
1083 return OPERATOR_CANCELLED;
1084 }
1085
1086 break;
1095 /* Ensure only cavity masking is enabled. */
1098 break;
1099 }
1100
1101 /* Ensure cavity mask is actually enabled. */
1104 }
1105
1106 /* Create copy of brush with cleared automasking settings. */
1107 Brush brush_copy = dna::shallow_copy(*brush);
1108 MeshAutomaskingSettings brush_settings;
1109 brush_settings.flags = eAutomasking_flag(0);
1110 brush_settings.boundary_edges_propagation_steps = 1;
1111 brush_settings.cavity_curve = scene_copy.mesh_automasking_settings->cavity_curve;
1112
1113 brush_copy.mesh_automasking_settings = &brush_settings;
1114 /* Set a brush type that doesn't change topology so automasking isn't "disabled". */
1116
1117 std::unique_ptr<auto_mask::Cache> automasking = auto_mask::cache_init(
1118 *depsgraph, scene_copy, &brush_copy, ob);
1119
1120 if (!automasking) {
1121 return OPERATOR_CANCELLED;
1122 }
1123
1124 undo::push_begin(scene, ob, op);
1125 undo::push_nodes(*depsgraph, ob, node_mask, undo::Type::Mask);
1126
1127 automasking->calc_cavity_factor(*depsgraph, ob, node_mask);
1128 apply_mask_from_settings(*depsgraph, ob, pbvh, node_mask, *automasking, mode, factor);
1129
1130 undo::push_end(ob);
1131
1132 pbvh.tag_masks_changed(node_mask);
1135
1136 return OPERATOR_FINISHED;
1137}
1138
1140{
1141 ui::Layout &layout = *op->layout;
1142 Scene *scene = CTX_data_scene(C);
1143 Sculpt *sd = scene->toolsettings ? scene->toolsettings->sculpt : nullptr;
1144
1145 layout.use_property_split_set(true);
1146 layout.use_property_decorate_set(false);
1147 MaskSettingsSource source = MaskSettingsSource(RNA_enum_get(op->ptr, "settings_source"));
1148
1149 if (!sd) {
1151 }
1152
1153 switch (source) {
1155 layout.prop(op->ptr, "mix_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1156 layout.prop(op->ptr, "mix_factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1157 layout.prop(op->ptr, "factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1158 layout.prop(op->ptr, "blur_steps", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1159 layout.prop(op->ptr, "invert", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1160 layout.prop(op->ptr, "use_curve", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1161
1162 if (sd && RNA_boolean_get(op->ptr, "use_curve")) {
1163 PointerRNA sculpt_ptr = RNA_pointer_create_discrete(&scene->id, RNA_Sculpt, sd);
1164 template_curve_mapping(&layout,
1165 &sculpt_ptr,
1166 "automasking_cavity_curve_op",
1167 'v',
1168 false,
1169 false,
1170 false,
1171 false,
1172 false);
1173 }
1174 break;
1175 }
1178 layout.prop(op->ptr, "mix_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1179 layout.prop(op->ptr, "mix_factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1180
1181 break;
1182 }
1183}
1184
1186{
1187 ot->name = "Mask From Cavity";
1188 ot->idname = "SCULPT_OT_mask_from_cavity";
1189 ot->description = "Creates a mask based on the curvature of the surface";
1190
1191 ot->ui = mask_from_cavity_ui;
1193 ot->poll = sculpt_mode_poll;
1194
1196
1197 RNA_def_enum(ot->srna, "mix_mode", mix_modes, int(ApplyMaskMode::Mix), "Mode", "Mix mode");
1198 RNA_def_float(ot->srna, "mix_factor", 1.0f, 0.0f, 5.0f, "Mix Factor", "", 0.0f, 1.0f);
1199 RNA_def_enum(ot->srna,
1200 "settings_source",
1203 "Settings",
1204 "Use settings from here");
1205 RNA_def_float(ot->srna,
1206 "factor",
1207 0.5f,
1208 0.0f,
1209 5.0f,
1210 "Factor",
1211 "The contrast of the cavity mask",
1212 0.0f,
1213 1.0f);
1214 RNA_def_int(ot->srna,
1215 "blur_steps",
1216 2,
1217 0,
1218 25,
1219 "Blur",
1220 "The number of times the cavity mask is blurred",
1221 0,
1222 25);
1223 RNA_def_boolean(ot->srna, "use_curve", false, "Custom Curve", "");
1224 RNA_def_boolean(ot->srna, "invert", false, "Cavity (Inverted)", "");
1225}
1226
1227enum class MaskBoundaryMode : int8_t { Mesh, FaceSets };
1228
1230{
1231 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
1233 const Sculpt &sd = *CTX_data_tool_settings(C)->sculpt;
1234 const Scene &scene = *CTX_data_scene(C);
1236
1237 const View3D *v3d = CTX_wm_view3d(C);
1238 const Base *base = CTX_data_active_base(C);
1239 if (!BKE_base_is_visible(v3d, base)) {
1240 return OPERATOR_CANCELLED;
1241 }
1242
1244 BKE_sculpt_mask_layers_ensure(depsgraph, CTX_data_main(C), &ob, mmd);
1245
1247
1248 BKE_sculptsession_update_for_edit(depsgraph, &ob, false);
1250
1251 const ApplyMaskMode mode = ApplyMaskMode(RNA_enum_get(op->ptr, "mix_mode"));
1252 const float factor = RNA_float_get(op->ptr, "mix_factor");
1253
1255
1256 IndexMaskMemory memory;
1257 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(pbvh, memory);
1258
1259 /* Set up automasking settings. */
1260 Paint scene_copy = dna::shallow_copy(sd.paint);
1261 /* We don't do a deep copy of the automasking settings, we simply need a new one so that the
1262 * canonical pointer isn't overwritten. */
1263 MeshAutomaskingSettings automasking_settings;
1264 scene_copy.mesh_automasking_settings = &automasking_settings;
1265
1266 MaskSettingsSource src = MaskSettingsSource(RNA_enum_get(op->ptr, "settings_source"));
1267 switch (src) {
1269 const MaskBoundaryMode boundary_mode = MaskBoundaryMode(
1270 RNA_enum_get(op->ptr, "boundary_mode"));
1271 switch (boundary_mode) {
1274 break;
1277 break;
1278 }
1280 op->ptr, "propagation_steps");
1281 break;
1282 }
1284 if (brush) {
1285 scene_copy.mesh_automasking_settings->flags = brush->mesh_automasking_settings->flags;
1287 brush->mesh_automasking_settings->boundary_edges_propagation_steps;
1288
1291 }
1292 else {
1294 BKE_report(op->reports, RPT_WARNING, "No active brush");
1295
1296 return OPERATOR_CANCELLED;
1297 }
1298
1299 break;
1304
1307 break;
1308 }
1309
1310 /* Create copy of brush with cleared automasking settings. */
1311 Brush brush_copy = dna::shallow_copy(*brush);
1312 MeshAutomaskingSettings brush_settings;
1313 brush_settings.flags = eAutomasking_flag(0);
1314 brush_settings.boundary_edges_propagation_steps = 1;
1315 /* Set a brush type that doesn't change topology so automasking isn't "disabled". */
1316 brush_copy.mesh_automasking_settings = &brush_settings;
1318
1319 std::unique_ptr<auto_mask::Cache> automasking = auto_mask::cache_init(
1320 *depsgraph, scene_copy, &brush_copy, ob);
1321
1322 if (!automasking) {
1323 return OPERATOR_CANCELLED;
1324 }
1325
1326 undo::push_begin(scene, ob, op);
1327 undo::push_nodes(*depsgraph, ob, node_mask, undo::Type::Mask);
1328
1329 apply_mask_from_settings(*depsgraph, ob, pbvh, node_mask, *automasking, mode, factor);
1330
1331 undo::push_end(ob);
1332
1333 pbvh.tag_masks_changed(node_mask);
1336
1337 return OPERATOR_FINISHED;
1338}
1339
1341{
1342 ui::Layout &layout = *op->layout;
1343 Scene *scene = CTX_data_scene(C);
1344 Sculpt *sd = scene->toolsettings ? scene->toolsettings->sculpt : nullptr;
1345
1346 layout.use_property_split_set(true);
1347 layout.use_property_decorate_set(false);
1348 MaskSettingsSource source = MaskSettingsSource(RNA_enum_get(op->ptr, "settings_source"));
1349
1350 if (!sd) {
1352 }
1353
1354 switch (source) {
1356 layout.prop(op->ptr, "mix_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1357 layout.prop(op->ptr, "mix_factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1358 layout.prop(op->ptr, "boundary_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1359 layout.prop(op->ptr, "propagation_steps", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1360 break;
1361 }
1364 layout.prop(op->ptr, "mix_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1365 layout.prop(op->ptr, "mix_factor", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1366 break;
1367 }
1368}
1369
1371{
1372 ot->name = "Mask From Boundary";
1373 ot->idname = "SCULPT_OT_mask_from_boundary";
1374 ot->description = "Creates a mask based on the boundaries of the surface";
1375
1378 ot->poll = sculpt_mode_poll;
1379
1381
1382 RNA_def_enum(ot->srna, "mix_mode", mix_modes, int(ApplyMaskMode::Mix), "Mode", "Mix mode");
1383 RNA_def_float(ot->srna, "mix_factor", 1.0f, 0.0f, 5.0f, "Mix Factor", "", 0.0f, 1.0f);
1384 RNA_def_enum(ot->srna,
1385 "settings_source",
1388 "Settings",
1389 "Use settings from here");
1390
1391 static EnumPropertyItem mask_boundary_modes[] = {
1393 "MESH",
1394 ICON_NONE,
1395 "Mesh",
1396 "Calculate the boundary mask based on disconnected mesh topology islands"},
1398 "FACE_SETS",
1399 ICON_NONE,
1400 "Face Sets",
1401 "Calculate the boundary mask between face sets"},
1402 {0, nullptr, 0, nullptr, nullptr}};
1403
1404 RNA_def_enum(ot->srna,
1405 "boundary_mode",
1406 mask_boundary_modes,
1408 "Mode",
1409 "Boundary type to mask");
1410 RNA_def_int(ot->srna, "propagation_steps", 1, 1, 20, "Propagation Steps", "", 1, 20);
1411}
1412
1414
1415} // namespace mask
1416
1418{
1445
1450
1457}
1458
1460{
1461 filter::modal_keymap(keyconf);
1462}
1463
1464} // namespace blender::ed::sculpt_paint
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
A BVH for high poly meshes.
#define RPT_(msgid)
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define ND_DRAW
Definition WM_types.hh:502
#define ND_MODE
Definition WM_types.hh:464
#define NC_SCENE
Definition WM_types.hh:391
#define NC_OBJECT
Definition WM_types.hh:392
#define BLI_assert_unreachable()
#define BMO_FLAG_DEFAULTS
int64_t size() const
Definition BLI_array.hh:267
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
constexpr Span< T > as_span() const
Definition BLI_span.hh:667
int64_t size() const
Definition BLI_set.hh:606
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
static VArray from_span(Span< T > values)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GAttributeReader lookup(const StringRef name) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
#define SHRT_MAX
float2x2 invert(float2x2 mat)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
#define MASK_BY_COLOR_SLOPE
pbvh::Tree * pbvh_get(Object &object)
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
Definition pbvh.cc:2522
void node_update_mask_bmesh(int mask_offset, BMeshNode &node)
Definition pbvh.cc:1404
void node_update_mask_mesh(Span< float > mask, MeshNode &node)
Definition pbvh.cc:1345
void node_update_mask_grids(const CCGKey &key, Span< float > masks, GridsNode &node)
Definition pbvh.cc:1373
Span< float3 > vert_normals_eval(const Depsgraph &depsgraph, const Object &object_orig)
Definition pbvh.cc:952
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
bool mode_compat_set(bContext *C, Object *ob, eObjectMode mode, ReportList *reports)
std::unique_ptr< Cache > cache_init(const Depsgraph &depsgraph, const Paint &paint, const Brush *brush, Object &ob)
void calc_vert_factors(const Depsgraph &depsgraph, const Object &object, const Cache &automasking, const bke::pbvh::MeshNode &node, Span< int > verts, MutableSpan< float > factors)
void calc_grids_factors(const Depsgraph &depsgraph, const Object &object, const Cache &automasking, const bke::pbvh::GridsNode &node, Span< int > grids, MutableSpan< float > factors)
void SCULPT_OT_cloth_filter(wmOperatorType *ot)
void SCULPT_OT_color_filter(wmOperatorType *ot)
void enable_ex(Main &bmain, Depsgraph &depsgraph, Object &ob)
void SCULPT_OT_detail_flood_fill(wmOperatorType *ot)
void disable_with_undo(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob)
void SCULPT_OT_sample_detail_size(wmOperatorType *ot)
WarnFlag check_attribute_warning(Scene &scene, Object &ob)
void SCULPT_OT_dynamic_topology_toggle(wmOperatorType *ot)
void SCULPT_OT_dyntopo_detail_size_edit(wmOperatorType *ot)
void SCULPT_OT_expand(wmOperatorType *ot)
void SCULPT_OT_face_set_lasso_gesture(wmOperatorType *ot)
void initialize_none_to_id(Mesh *mesh, int new_id)
void SCULPT_OT_face_set_line_gesture(wmOperatorType *ot)
void SCULPT_OT_face_set_polyline_gesture(wmOperatorType *ot)
void SCULPT_OT_face_sets_init(wmOperatorType *ot)
void SCULPT_OT_face_sets_create(wmOperatorType *ot)
void SCULPT_OT_face_set_change_visibility(wmOperatorType *ot)
void SCULPT_OT_face_sets_randomize_colors(wmOperatorType *ot)
void SCULPT_OT_face_sets_edit(wmOperatorType *ot)
void SCULPT_OT_face_set_box_gesture(wmOperatorType *ot)
int find_next_available_id(const Mesh &mesh)
void SCULPT_OT_mesh_filter(wmOperatorType *ot)
wmKeyMap * modal_keymap(wmKeyConfig *keyconf)
static float color_delta_get(const float3 &color_a, const float3 &color_b, const float threshold, const bool invert)
static wmOperatorStatus mask_from_boundary_exec(bContext *C, wmOperator *op)
void SCULPT_OT_mask_filter(wmOperatorType *ot)
void scatter_mask_grids(const Span< float > mask, SubdivCCG &subdiv_ccg, const Span< int > grids)
static wmOperatorStatus mask_by_color_exec(bContext *C, wmOperator *op)
static wmOperatorStatus mask_by_color(bContext *C, wmOperator *op, const float2 region_location)
static EnumPropertyItem mix_modes[]
static void mask_from_cavity_ui(bContext *C, wmOperator *op)
void update_mask_mesh(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, FunctionRef< void(MutableSpan< float >, Span< int >)> update_fn)
static void apply_mask_from_settings(const Depsgraph &depsgraph, Object &object, bke::pbvh::Tree &pbvh, const IndexMask &node_mask, const auto_mask::Cache &automasking, const ApplyMaskMode mode, const float factor)
void SCULPT_OT_mask_init(wmOperatorType *ot)
static void SCULPT_OT_mask_by_color(wmOperatorType *ot)
void scatter_mask_bmesh(const Span< float > mask, const BMesh &bm, const Set< BMVert *, 0 > &verts)
void gather_mask_bmesh(const BMesh &bm, const Set< BMVert *, 0 > &verts, const MutableSpan< float > r_mask)
void mix_new_masks(const Span< float > new_masks, const float factor, const MutableSpan< float > masks)
Definition paint_mask.cc:96
static void mask_by_color_full_mesh(const Depsgraph &depsgraph, Object &object, const int vert, const float threshold, const bool invert, const bool preserve_mask)
static void calc_new_masks(const ApplyMaskMode mode, const Span< float > node_mask, const MutableSpan< float > new_mask)
static wmOperatorStatus mask_by_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus mask_from_cavity_exec(bContext *C, wmOperator *op)
static void mask_from_boundary_ui(bContext *C, wmOperator *op)
static void mask_by_color_contiguous_mesh(const Depsgraph &depsgraph, Object &object, const int vert, const float threshold, const bool invert, const bool preserve_mask)
void invert_mask(const MutableSpan< float > masks)
void gather_mask_grids(const SubdivCCG &subdiv_ccg, const Span< int > grids, const MutableSpan< float > r_mask)
static void apply_mask_mesh(const Depsgraph &depsgraph, const Object &object, const Span< bool > hide_vert, const auto_mask::Cache &automasking, const ApplyMaskMode mode, const float factor, const bke::pbvh::MeshNode &node, LocalData &tls, const MutableSpan< float > mask)
static void apply_mask_bmesh(const Depsgraph &depsgraph, Object &object, const auto_mask::Cache &automasking, const ApplyMaskMode mode, const float factor, bke::pbvh::BMeshNode &node, LocalData &tls)
static void SCULPT_OT_mask_from_cavity(wmOperatorType *ot)
static EnumPropertyItem settings_sources[]
static void apply_mask_grids(const Depsgraph &depsgraph, Object &object, const auto_mask::Cache &automasking, const ApplyMaskMode mode, const float factor, const bke::pbvh::GridsNode &node, LocalData &tls)
static void SCULPT_OT_mask_from_boundary(wmOperatorType *ot)
static float final_mask_get(const float current_mask, const float new_mask, const bool invert, const bool preserve_mask)
void clamp_mask(const MutableSpan< float > masks)
void SCULPT_OT_project_line_gesture(wmOperatorType *ot)
void SCULPT_OT_trim_lasso_gesture(wmOperatorType *ot)
void SCULPT_OT_trim_box_gesture(wmOperatorType *ot)
void SCULPT_OT_trim_line_gesture(wmOperatorType *ot)
void SCULPT_OT_trim_polyline_gesture(wmOperatorType *ot)
void push_nodes(const Depsgraph &depsgraph, Object &object, const IndexMask &node_mask, const Type type)
void push_begin_ex(const Scene &, Object &ob, const char *name)
void push_enter_sculpt_mode(const Scene &, Object &ob, const wmOperator *op)
void geometry_begin(const Scene &scene, Object &ob, const wmOperator *op)
void push_node(const Depsgraph &depsgraph, const Object &object, const bke::pbvh::Node *node, const Type type)
void push_begin(const Scene &scene, Object &ob, const wmOperator *op)
void object_sculpt_mode_enter(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob, bool force_dyntopo, ReportList *reports)
void SCULPT_OT_paint_mask_slice(wmOperatorType *ot)
void mode_exit_generic(Scene &scene, Object &ob, const eObjectMode mode_flag)
static bool no_multires_poll(bContext *C)
void mode_enter_generic(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob, const eObjectMode mode_flag)
Definition mesh_paint.cc:76
static wmOperatorStatus set_persistent_base_exec(bContext *C, wmOperator *)
void vert_random_access_ensure(Object &object)
Definition sculpt.cc:154
static void SCULPT_OT_symmetrize(wmOperatorType *ot)
static wmOperatorStatus optimize_exec(bContext *C, wmOperator *)
void keymap_sculpt(wmKeyConfig *keyconf)
static void SCULPT_OT_sculptmode_toggle(wmOperatorType *ot)
bool sculpt_mode_poll(bContext *C)
Definition sculpt.cc:3800
bool color_supported_check(const Scene &scene, Object &object, ReportList *reports)
Definition sculpt.cc:5432
static wmOperatorStatus sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
void scale_factors(MutableSpan< float > factors, float strength)
Definition sculpt.cc:7856
void object_sculpt_mode_exit(Main &bmain, Depsgraph &depsgraph, Scene &scene, Object &ob)
static void SCULPT_OT_set_persistent_base(wmOperatorType *ot)
static void SCULPT_OT_optimize(wmOperatorType *ot)
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void SCULPT_OT_brush_stroke(wmOperatorType *ot)
Definition sculpt.cc:5926
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void flush_update_done(bContext *C, Object &ob, const UpdateType update_type)
Definition sculpt.cc:5131
std::optional< CursorGeometryInfo > cursor_geometry_info_update(bContext *C, const float2 &mval, const bool use_sampled_normal)
Definition sculpt.cc:4584
static wmOperatorStatus symmetrize_exec(bContext *C, wmOperator *op)
void fill_factor_from_hide(Span< bool > hide_vert, Span< int > verts, MutableSpan< float > r_factors)
Definition sculpt.cc:7077
void SCULPT_OT_paint_mask_extract(wmOperatorType *ot)
void mask_overlay_check(bContext &C, wmOperator &op)
Definition sculpt.cc:8298
void SCULPT_OT_face_set_extract(wmOperatorType *ot)
void SCULPT_OT_set_pivot_position(wmOperatorType *ot)
void tag_update_overlays(bContext *C)
Definition sculpt.cc:895
constexpr ParallelGrainSize grain_size(int grain_size)
T distance(const T &a, const T &b)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
int RNA_enum_get(PointerRNA *ptr, const char *name)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
@ RPT_WARNING
Definition BKE_report.hh:40
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
bool BKE_base_is_visible(const View3D *v3d, const Base *base)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool is_negative_m4(const float mat[4][4])
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
void BM_log_all_added(BMesh *bm, BMLog *log)
Definition bmesh_log.cc:741
Base * CTX_data_active_base(const bContext *C)
void BKE_sculptsession_free_pbvh(Object &object)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, Main *bmain, Object *ob, MultiresModifierData *mmd)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
@ SCULPT_BRUSH_TYPE_SMOOTH
void multires_flush_sculpt_updates(Object *object)
Definition multires.cc:277
VecBase< float, 4 > float4
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void BM_log_before_all_removed(BMesh *bm, BMLog *log)
Definition bmesh_log.cc:769
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Mesh * BKE_mesh_from_object(Object *ob)
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
void WM_toolsystem_update_from_context_view3d(bContext *C)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool BMO_op_callf(BMesh *bm, int flag, const char *fmt,...)
ToolSettings * CTX_data_tool_settings(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
@ V3D_SHADING_VERTEX_COLOR
@ ME_SCULPT_DYNAMIC_TOPOLOGY
void BM_mesh_toolflags_set(BMesh *bm, bool use_toolflags)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BKE_sculpt_color_layer_create_if_needed(Object *object)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
@ BRUSH_AUTOMASKING_CAVITY_USE_CURVE
@ BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS
@ BRUSH_AUTOMASKING_BOUNDARY_EDGES
@ BRUSH_AUTOMASKING_CAVITY_ALL
@ BRUSH_AUTOMASKING_CAVITY_NORMAL
@ BRUSH_AUTOMASKING_CAVITY_INVERTED
const Brush * BKE_paint_brush_for_read(const Paint *paint)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void BKE_mesh_mirror_apply_mirror_on_axis(Main *bmain, Mesh *mesh, int axis, float dist)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
Depsgraph * CTX_data_depsgraph_on_load(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
Main * CTX_data_main(const bContext *C)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_sculptsession_update_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
Scene * CTX_data_scene(const bContext *C)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool ED_operator_object_active_editable_mesh_from_view_layer(bContext *C)
@ BKE_MESH_BATCH_DIRTY_ALL
Definition BKE_mesh.h:48
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
const Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(bke::pbvh::BMeshNode *node)
float RNA_float_get(PointerRNA *ptr, const char *name)
View3D * CTX_wm_view3d(const bContext *C)
signed char int8_t
Definition BKE_text.h:76
@ Multiply
Definition types.hh:145
@ Divide
Definition types.hh:70
#define fabsf
eBrushSculptType sculpt_brush_type
struct MeshAutomaskingSettings * mesh_automasking_settings
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
bke::ObjectRuntime * runtime
struct MeshAutomaskingSettings * mesh_automasking_settings
struct ToolSettings * toolsettings
struct blender::SculptSession::@037313230252170341305206315164127110104334247060 persistent
Array< float3 > positions
Array< float3 > normals
Array< float > masks
eV3DShadingColorType color_type
View3DShading shading
const ImplicitSharingInfo * sharing_info
void execute(Object &object, GroupedSpan< int > vert_to_face_map, FunctionRef< bool(int from_v, int to_v)> func)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
void resize(int new_size)
Definition vector.hh:94
#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_)