Blender V4.5
paint.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 by Nicholas Bishop. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11#include <optional>
12
13#include "MEM_guardedalloc.h"
14
15#include "DNA_asset_types.h"
16#include "DNA_brush_types.h"
17#include "DNA_defaults.h"
18#include "DNA_key_types.h"
19#include "DNA_mesh_types.h"
20#include "DNA_meshdata_types.h"
21#include "DNA_modifier_types.h"
22#include "DNA_object_enums.h"
23#include "DNA_object_types.h"
24#include "DNA_scene_types.h"
25#include "DNA_space_types.h"
26#include "DNA_userdef_types.h"
27#include "DNA_view3d_types.h"
28#include "DNA_workspace_types.h"
29
30#include "BLI_hash.h"
31#include "BLI_listbase.h"
32#include "BLI_math_color.h"
33#include "BLI_math_matrix.hh"
34#include "BLI_math_vector.h"
35#include "BLI_noise.hh"
36#include "BLI_string.h"
37#include "BLI_utildefines.h"
38#include "BLI_vector.hh"
39
40#include "BLT_translation.hh"
41
42#include "BKE_asset.hh"
43#include "BKE_asset_edit.hh"
44#include "BKE_attribute.hh"
45#include "BKE_brush.hh"
46#include "BKE_ccg.hh"
47#include "BKE_colortools.hh"
48#include "BKE_context.hh"
49#include "BKE_crazyspace.hh"
50#include "BKE_deform.hh"
51#include "BKE_gpencil_legacy.h"
52#include "BKE_idtype.hh"
53#include "BKE_image.hh"
54#include "BKE_key.hh"
55#include "BKE_layer.hh"
56#include "BKE_lib_id.hh"
57#include "BKE_main.hh"
58#include "BKE_material.hh"
59#include "BKE_mesh.hh"
60#include "BKE_mesh_runtime.hh"
61#include "BKE_modifier.hh"
62#include "BKE_multires.hh"
63#include "BKE_object.hh"
64#include "BKE_paint.hh"
65#include "BKE_paint_bvh.hh"
66#include "BKE_scene.hh"
67#include "BKE_subdiv_ccg.hh"
68#include "BKE_subsurf.hh"
69
70#include "DEG_depsgraph.hh"
72
73#include "RNA_enum_types.hh"
74
75#include "BLO_read_write.hh"
76
77#include "bmesh.hh"
78
79using blender::float3;
81using blender::Span;
82using blender::Vector;
84
85static void palette_init_data(ID *id)
86{
87 Palette *palette = (Palette *)id;
88
90
91 /* Enable fake user by default. */
92 id_fake_user_set(&palette->id);
93}
94
95static void palette_copy_data(Main * /*bmain*/,
96 std::optional<Library *> /*owner_library*/,
97 ID *id_dst,
98 const ID *id_src,
99 const int /*flag*/)
100{
101 Palette *palette_dst = (Palette *)id_dst;
102 const Palette *palette_src = (const Palette *)id_src;
103
104 BLI_duplicatelist(&palette_dst->colors, &palette_src->colors);
105}
106
107static void palette_free_data(ID *id)
108{
109 Palette *palette = (Palette *)id;
110
111 BLI_freelistN(&palette->colors);
112}
113
114static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
115{
116 Palette *palette = (Palette *)id;
117
118 BLO_write_id_struct(writer, Palette, id_address, &palette->id);
119 BKE_id_blend_write(writer, &palette->id);
120
121 BLO_write_struct_list(writer, PaletteColor, &palette->colors);
122}
123
125{
126 Palette *palette = (Palette *)id;
127 BLO_read_struct_list(reader, PaletteColor, &palette->colors);
128}
129
130static void palette_undo_preserve(BlendLibReader * /*reader*/, ID *id_new, ID *id_old)
131{
132 /* Whole Palette is preserved across undo-steps, and it has no extra pointer, simple. */
133 /* NOTE: We do not care about potential internal references to self here, Palette has none. */
134 /* NOTE: We do not swap IDProperties, as dealing with potential ID pointers in those would be
135 * fairly delicate. */
136 BKE_lib_id_swap(nullptr, id_new, id_old, false, 0);
137 std::swap(id_new->properties, id_old->properties);
138 std::swap(id_new->system_properties, id_old->system_properties);
139}
140
142 /*id_code*/ Palette::id_type,
143 /*id_filter*/ FILTER_ID_PAL,
144 /*dependencies_id_types*/ 0,
145 /*main_listbase_index*/ INDEX_ID_PAL,
146 /*struct_size*/ sizeof(Palette),
147 /*name*/ "Palette",
148 /*name_plural*/ N_("palettes"),
149 /*translation_context*/ BLT_I18NCONTEXT_ID_PALETTE,
150 /*flags*/ IDTYPE_FLAGS_NO_ANIMDATA,
151 /*asset_type_info*/ nullptr,
152
153 /*init_data*/ palette_init_data,
154 /*copy_data*/ palette_copy_data,
155 /*free_data*/ palette_free_data,
156 /*make_local*/ nullptr,
157 /*foreach_id*/ nullptr,
158 /*foreach_cache*/ nullptr,
159 /*foreach_path*/ nullptr,
160 /*owner_pointer_get*/ nullptr,
161
162 /*blend_write*/ palette_blend_write,
163 /*blend_read_data*/ palette_blend_read_data,
164 /*blend_read_after_liblink*/ nullptr,
165
166 /*blend_read_undo_preserve*/ palette_undo_preserve,
167
168 /*lib_override_apply_post*/ nullptr,
169};
170
171static void paint_curve_copy_data(Main * /*bmain*/,
172 std::optional<Library *> /*owner_library*/,
173 ID *id_dst,
174 const ID *id_src,
175 const int /*flag*/)
176{
177 PaintCurve *paint_curve_dst = (PaintCurve *)id_dst;
178 const PaintCurve *paint_curve_src = (const PaintCurve *)id_src;
179
180 if (paint_curve_src->tot_points != 0) {
181 paint_curve_dst->points = static_cast<PaintCurvePoint *>(
182 MEM_dupallocN(paint_curve_src->points));
183 }
184}
185
186static void paint_curve_free_data(ID *id)
187{
188 PaintCurve *paint_curve = (PaintCurve *)id;
189
190 MEM_SAFE_FREE(paint_curve->points);
191 paint_curve->tot_points = 0;
192}
193
194static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
195{
196 PaintCurve *pc = (PaintCurve *)id;
197
198 BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
199 BKE_id_blend_write(writer, &pc->id);
200
202}
203
205{
206 PaintCurve *pc = (PaintCurve *)id;
208}
209
211 /*id_code*/ PaintCurve::id_type,
212 /*id_filter*/ FILTER_ID_PC,
213 /*dependencies_id_types*/ 0,
214 /*main_listbase_index*/ INDEX_ID_PC,
215 /*struct_size*/ sizeof(PaintCurve),
216 /*name*/ "PaintCurve",
217 /*name_plural*/ N_("paint_curves"),
218 /*translation_context*/ BLT_I18NCONTEXT_ID_PAINTCURVE,
219 /*flags*/ IDTYPE_FLAGS_NO_ANIMDATA,
220 /*asset_type_info*/ nullptr,
221
222 /*init_data*/ nullptr,
223 /*copy_data*/ paint_curve_copy_data,
224 /*free_data*/ paint_curve_free_data,
225 /*make_local*/ nullptr,
226 /*foreach_id*/ nullptr,
227 /*foreach_cache*/ nullptr,
228 /*foreach_path*/ nullptr,
229 /*owner_pointer_get*/ nullptr,
230
231 /*blend_write*/ paint_curve_blend_write,
232 /*blend_read_data*/ paint_curve_blend_read_data,
233 /*blend_read_after_liblink*/ nullptr,
234
235 /*blend_read_undo_preserve*/ nullptr,
236
237 /*lib_override_apply_post*/ nullptr,
238};
239
240const uchar PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
241const uchar PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
242const uchar PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
243const uchar PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
244const uchar PAINT_CURSOR_SCULPT_CURVES[3] = {255, 100, 100};
245const uchar PAINT_CURSOR_PAINT_GREASE_PENCIL[3] = {255, 100, 100};
246const uchar PAINT_CURSOR_SCULPT_GREASE_PENCIL[3] = {255, 100, 100};
247
249
250void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex)
251{
252 Paint *paint = BKE_paint_get_active(scene, view_layer);
253 if (!paint) {
254 return;
255 }
256
257 Brush *br = BKE_paint_brush(paint);
258 if (!br) {
259 return;
260 }
261
262 if (br->mtex.tex == tex) {
264 }
265 if (br->mask_mtex.tex == tex) {
267 }
268}
269
271{
272 Paint *paint = BKE_paint_get_active(scene, view_layer);
273 if (paint == nullptr) {
274 return;
275 }
276
277 Brush *br = BKE_paint_brush(paint);
278 if (br && br->curve == curve) {
280 }
281}
282
288
293
311
316
318{
319 ToolSettings *ts = sce->toolsettings;
320 Paint **paint_ptr = nullptr;
321 /* Some paint modes don't store paint settings as pointer, for these this can be set and
322 * referenced by paint_ptr. */
323 Paint *paint_tmp = nullptr;
324
325 switch (mode) {
327 paint_ptr = (Paint **)&ts->sculpt;
328 break;
330 paint_ptr = (Paint **)&ts->vpaint;
331 break;
333 paint_ptr = (Paint **)&ts->wpaint;
334 break;
337 paint_tmp = (Paint *)&ts->imapaint;
338 paint_ptr = &paint_tmp;
339 break;
341 paint_ptr = (Paint **)&ts->gp_paint;
342 break;
344 paint_ptr = (Paint **)&ts->gp_vertexpaint;
345 break;
347 paint_ptr = (Paint **)&ts->gp_sculptpaint;
348 break;
350 paint_ptr = (Paint **)&ts->gp_weightpaint;
351 break;
353 paint_ptr = (Paint **)&ts->curves_sculpt;
354 break;
356 break;
357 }
358 if (paint_ptr) {
359 BKE_paint_ensure(ts, paint_ptr);
360 return true;
361 }
362 return false;
363}
364
366{
367 if (sce) {
368 ToolSettings *ts = sce->toolsettings;
369
370 switch (mode) {
372 return &ts->sculpt->paint;
374 return &ts->vpaint->paint;
376 return &ts->wpaint->paint;
379 return &ts->imapaint.paint;
381 return &ts->gp_paint->paint;
383 return &ts->gp_vertexpaint->paint;
385 return &ts->gp_sculptpaint->paint;
387 return &ts->gp_weightpaint->paint;
389 return &ts->curves_sculpt->paint;
391 return nullptr;
392 default:
393 return &ts->imapaint.paint;
394 }
395 }
396
397 return nullptr;
398}
399
427
429{
430 if (sce && view_layer) {
431 ToolSettings *ts = sce->toolsettings;
432 BKE_view_layer_synced_ensure(sce, view_layer);
433 Object *actob = BKE_view_layer_active_object_get(view_layer);
434
435 if (actob) {
436 switch (actob->mode) {
437 case OB_MODE_SCULPT:
438 return &ts->sculpt->paint;
440 return &ts->vpaint->paint;
442 return &ts->wpaint->paint;
444 return &ts->imapaint.paint;
446 return &ts->gp_paint->paint;
448 return &ts->gp_vertexpaint->paint;
450 return &ts->gp_sculptpaint->paint;
452 return &ts->gp_weightpaint->paint;
454 return &ts->curves_sculpt->paint;
455 default:
456 break;
457 }
458 }
459
460 /* default to image paint */
461 return &ts->imapaint.paint;
462 }
463
464 return nullptr;
465}
466
468{
469 Scene *sce = CTX_data_scene(C);
470 ViewLayer *view_layer = CTX_data_view_layer(C);
471
472 if (sce && view_layer) {
473 ToolSettings *ts = sce->toolsettings;
474 BKE_view_layer_synced_ensure(sce, view_layer);
475 Object *obact = BKE_view_layer_active_object_get(view_layer);
476
478 if (sima != nullptr) {
479 if (obact && obact->mode == OB_MODE_EDIT) {
480 if (sima->mode == SI_MODE_PAINT) {
481 return &ts->imapaint.paint;
482 }
483 }
484 else {
485 return &ts->imapaint.paint;
486 }
487 }
488 else {
489 return BKE_paint_get_active(sce, view_layer);
490 }
491 }
492
493 return nullptr;
494}
495
497{
498 Scene *sce = CTX_data_scene(C);
499 ViewLayer *view_layer = CTX_data_view_layer(C);
500
501 if (sce && view_layer) {
502 BKE_view_layer_synced_ensure(sce, view_layer);
503 Object *obact = BKE_view_layer_active_object_get(view_layer);
504
506 if (sima != nullptr) {
507 if (obact && obact->mode == OB_MODE_EDIT) {
508 if (sima->mode == SI_MODE_PAINT) {
510 }
511 }
512 else {
514 }
515 }
516 else if (obact) {
517 switch (obact->mode) {
518 case OB_MODE_SCULPT:
519 return PaintMode::Sculpt;
521 if (obact->type == OB_GREASE_PENCIL) {
523 }
524 return PaintMode::Invalid;
526 return PaintMode::GPencil;
532 return PaintMode::Vertex;
534 return PaintMode::Weight;
539 default:
541 }
542 }
543 else {
544 /* default to image paint */
546 }
547 }
548
549 return PaintMode::Invalid;
550}
551
591
592bool BKE_paint_use_unified_color(const ToolSettings *tool_settings, const Paint *paint)
593{
594 /* Grease pencil draw mode never uses unified paint. */
596 return false;
597 }
598
599 return tool_settings->unified_paint_settings.flag & UNIFIED_PAINT_COLOR;
600}
601
607{
608 /* Don't resolve this during file read, it will be done after. */
609 if (bmain->is_locked_for_linking) {
610 return false;
611 }
612 /* Attempt to restore a valid active brush from brush asset information. */
613 if (paint->brush != nullptr) {
614 return false;
615 }
616 if (paint->brush_asset_reference == nullptr) {
617 return false;
618 }
619
621 *bmain, ID_BR, *paint->brush_asset_reference));
622 BLI_assert(brush == nullptr || blender::bke::asset_edit_id_is_editable(brush->id));
623
624 /* Ensure we have a brush with appropriate mode to assign.
625 * Could happen if contents of asset blend was manually changed. */
626 if (brush == nullptr || (paint->runtime.ob_mode & brush->ob_mode) == 0) {
627 MEM_delete(paint->brush_asset_reference);
628 paint->brush_asset_reference = nullptr;
629 return false;
630 }
631
632 paint->brush = brush;
633 return true;
634}
635
637{
638 return paint ? paint->brush : nullptr;
639}
640
642{
643 return paint ? paint->brush : nullptr;
644}
645
646bool BKE_paint_brush_poll(const Paint *paint, const Brush *brush)
647{
648 if (paint == nullptr) {
649 return false;
650 }
651 return !brush || (paint->runtime.ob_mode & brush->ob_mode) != 0;
652}
653
655{
656 if (std::optional<AssetWeakReference> weak_ref = blender::bke::asset_edit_weak_reference_from_id(
657 brush->id))
658 {
659 return MEM_new<AssetWeakReference>(__func__, *weak_ref);
660 }
661
662 return nullptr;
663}
664
666 Paint *paint,
667 const AssetWeakReference *brush_asset_reference)
668{
669 /* Don't resolve this during file read, it will be done after. */
670 if (bmain->is_locked_for_linking) {
671 return false;
672 }
673
674 Brush *brush = reinterpret_cast<Brush *>(
675 blender::bke::asset_edit_id_from_weak_reference(*bmain, ID_BR, *brush_asset_reference));
676 BLI_assert(brush == nullptr || !ID_IS_LINKED(brush) ||
678
679 /* Ensure we have a brush with appropriate mode to assign.
680 * Could happen if contents of asset blend were manually changed. */
681 if (!BKE_paint_brush_poll(paint, brush)) {
682 return false;
683 }
684
685 /* Update the brush itself. */
686 paint->brush = brush;
687 /* Update the brush asset reference. */
688 {
689 MEM_delete(paint->brush_asset_reference);
690 paint->brush_asset_reference = nullptr;
691 if (brush != nullptr) {
693 *brush_asset_reference);
694 paint->brush_asset_reference = MEM_new<AssetWeakReference>(__func__, *brush_asset_reference);
695 }
696 }
697
698 return true;
699}
700
701bool BKE_paint_brush_set(Paint *paint, Brush *brush)
702{
703 if (!BKE_paint_brush_poll(paint, brush)) {
704 return false;
705 }
706
707 paint->brush = brush;
708
709 MEM_delete(paint->brush_asset_reference);
710 paint->brush_asset_reference = nullptr;
711 if (brush != nullptr) {
713 }
714
715 return true;
716}
717
719{
720 switch (ob_mode) {
721 case OB_MODE_SCULPT:
722 return "essentials_brushes-mesh_sculpt.blend";
724 return "essentials_brushes-mesh_vertex.blend";
726 return "essentials_brushes-mesh_weight.blend";
728 return "essentials_brushes-mesh_texture.blend";
730 return "essentials_brushes-gp_draw.blend";
732 return "essentials_brushes-gp_sculpt.blend";
734 return "essentials_brushes-gp_weight.blend";
736 return "essentials_brushes-gp_vertex.blend";
738 return "essentials_brushes-curve_sculpt.blend";
739 default:
740 return nullptr;
741 }
742}
743
745 const char *name, const eObjectMode ob_mode)
746{
747 const char *essentials_file_name = paint_brush_essentials_asset_file_name_from_obmode(ob_mode);
748 if (!essentials_file_name) {
749 return nullptr;
750 }
751
752 AssetWeakReference *weak_ref = MEM_new<AssetWeakReference>(__func__);
753 weak_ref->asset_library_type = eAssetLibraryType::ASSET_LIBRARY_ESSENTIALS;
754 weak_ref->asset_library_identifier = nullptr;
756 "brushes/%s/Brush/%s", essentials_file_name, name);
757 return weak_ref;
758}
759
760static std::optional<AssetWeakReference> paint_brush_asset_reference_from_essentials(
761 const char *name, const eObjectMode ob_mode)
762{
763 const char *essentials_file_name = paint_brush_essentials_asset_file_name_from_obmode(ob_mode);
764 if (!essentials_file_name) {
765 return {};
766 }
767
768 AssetWeakReference weak_ref;
769 weak_ref.asset_library_type = eAssetLibraryType::ASSET_LIBRARY_ESSENTIALS;
770 weak_ref.asset_library_identifier = nullptr;
772 "brushes/%s/Brush/%s", essentials_file_name, name);
773 return weak_ref;
774}
775
776Brush *BKE_paint_brush_from_essentials(Main *bmain, const eObjectMode ob_mode, const char *name)
777{
778 std::optional<AssetWeakReference> weak_ref = paint_brush_asset_reference_from_essentials(
779 name, ob_mode);
780 if (!weak_ref) {
781 return nullptr;
782 }
783
784 return reinterpret_cast<Brush *>(
786}
787
788static void paint_brush_set_essentials_reference(Paint *paint, const char *name)
789{
790 /* Set brush asset reference to a named brush in the essentials asset library. */
791 MEM_delete(paint->brush_asset_reference);
792
795 name, eObjectMode(paint->runtime.ob_mode));
796 paint->brush = nullptr;
797}
798
799static void paint_eraser_brush_set_essentials_reference(Paint *paint, const char *name)
800{
801 /* Set brush asset reference to a named brush in the essentials asset library. */
802 MEM_delete(paint->eraser_brush_asset_reference);
803
806 name, eObjectMode(paint->runtime.ob_mode));
807 paint->eraser_brush = nullptr;
808}
809
811 eObjectMode ob_mode,
812 std::optional<int> brush_type,
814 blender::StringRefNull *r_eraser_name = nullptr)
815{
816 const char *name = "";
817 const char *eraser_name = "";
818
819 switch (ob_mode) {
820 case OB_MODE_SCULPT:
821 name = "Draw";
822 if (brush_type) {
823 switch (eBrushSculptType(*brush_type)) {
825 name = "Mask";
826 break;
828 name = "Face Set Paint";
829 break;
831 name = "Paint Hard";
832 break;
834 name = "Density";
835 break;
837 name = "Erase Multires Displacement";
838 break;
840 name = "Smear Multires Displacement";
841 break;
842 default:
843 break;
844 }
845 }
846 break;
848 name = "Paint Hard";
849 if (brush_type) {
850 switch (eBrushVertexPaintType(*brush_type)) {
852 name = "Blur";
853 break;
855 name = "Average";
856 break;
858 name = "Smear";
859 break;
861 /* Use default, don't override. */
862 break;
863 }
864 }
865 break;
867 name = "Paint";
868 if (brush_type) {
869 switch (eBrushWeightPaintType(*brush_type)) {
871 name = "Blur";
872 break;
874 name = "Average";
875 break;
877 name = "Smear";
878 break;
880 /* Use default, don't override. */
881 break;
882 }
883 }
884 break;
886 name = "Paint Hard";
887 if (brush_type) {
888 switch (eBrushImagePaintType(*brush_type)) {
890 name = "Blur";
891 break;
893 name = "Smear";
894 break;
896 name = "Fill";
897 break;
899 name = "Mask";
900 break;
902 name = "Clone";
903 break;
905 break;
906 }
907 }
908 break;
910 name = "Comb";
911 if (brush_type) {
912 switch (eBrushCurvesSculptType(*brush_type)) {
914 name = "Add";
915 break;
917 name = "Delete";
918 break;
920 name = "Density";
921 break;
923 name = "Select";
924 break;
925 default:
926 break;
927 }
928 }
929 break;
931 name = "Pencil";
932 /* Different default brush for some brush types. */
933 if (brush_type) {
934 switch (eBrushGPaintType(*brush_type)) {
936 name = "Eraser Hard";
937 break;
939 name = "Fill";
940 break;
943 /* Use default, don't override. */
944 break;
945 }
946 }
947 eraser_name = "Eraser Soft";
948 break;
950 name = "Paint";
951 if (brush_type) {
952 switch (eBrushGPVertexType(*brush_type)) {
954 name = "Blur";
955 break;
957 name = "Average";
958 break;
960 name = "Smear";
961 break;
963 name = "Replace";
964 break;
966 /* Use default, don't override. */
967 break;
969 /* Unused brush type. */
971 break;
972 }
973 }
974 break;
976 name = "Smooth";
977 if (brush_type) {
978 switch (eBrushGPSculptType(*brush_type)) {
980 name = "Clone";
981 break;
982 default:
983 break;
984 }
985 }
986 break;
988 name = "Paint";
989 if (brush_type) {
990 switch (eBrushGPWeightType(*brush_type)) {
992 name = "Blur";
993 break;
995 name = "Average";
996 break;
998 name = "Smear";
999 break;
1001 /* Use default, don't override. */
1002 break;
1003 }
1004 }
1005 break;
1006 default:
1008 break;
1009 }
1010
1011 *r_name = name;
1012 if (r_eraser_name) {
1013 *r_eraser_name = eraser_name;
1014 }
1015}
1016
1017std::optional<AssetWeakReference> BKE_paint_brush_type_default_reference(
1018 eObjectMode ob_mode, std::optional<int> brush_type)
1019{
1021
1022 paint_brush_default_essentials_name_get(ob_mode, brush_type, &name, nullptr);
1023 if (name.is_empty()) {
1024 return {};
1025 }
1026
1027 return paint_brush_asset_reference_from_essentials(name.c_str(), ob_mode);
1028}
1029
1031 const bool do_regular = true,
1032 const bool do_eraser = true)
1033{
1034 if (!paint->runtime.initialized) {
1035 /* Can happen when loading old file where toolsettings are created in versioning, without
1036 * calling #paint_runtime_init(). Will be done later when necessary. */
1037 return;
1038 }
1039
1041 blender::StringRefNull eraser_name;
1042
1044 eObjectMode(paint->runtime.ob_mode), std::nullopt, &name, &eraser_name);
1045
1046 if (do_regular && !name.is_empty()) {
1048 }
1049 if (do_eraser && !eraser_name.is_empty()) {
1051 }
1052}
1053
1082
1084{
1085 paint_brush_set_default_reference(paint, true, false);
1086 return paint_brush_update_from_asset_reference(bmain, paint);
1087}
1088
1089bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
1090{
1092 return paint_brush_update_from_asset_reference(bmain, paint);
1093}
1094
1096 AssetWeakReference &&asset_weak_reference)
1097{
1099 paint->runtime.previous_active_brush_reference = MEM_new<AssetWeakReference>(__func__);
1100 }
1101 *paint->runtime.previous_active_brush_reference = asset_weak_reference;
1102}
1103
1105{
1106 MEM_SAFE_DELETE(paint->runtime.previous_active_brush_reference);
1107}
1108
1110{
1111 /* Clear brush with invalid mode. Unclear if this can still happen,
1112 * but kept from old paint tool-slots code. */
1113 Brush *brush = BKE_paint_brush(paint);
1114 if (brush && (paint->runtime.ob_mode & brush->ob_mode) == 0) {
1115 BKE_paint_brush_set(paint, nullptr);
1116 BKE_paint_brush_set_default(bmain, paint);
1117 }
1118
1119 Brush *eraser_brush = BKE_paint_eraser_brush(paint);
1120 if (eraser_brush && (paint->runtime.ob_mode & eraser_brush->ob_mode) == 0) {
1121 BKE_paint_eraser_brush_set(paint, nullptr);
1123 }
1124}
1125
1127{
1128 /* Don't resolve this during file read, it will be done after. */
1129 if (bmain->is_locked_for_linking) {
1130 return false;
1131 }
1132 /* Attempt to restore a valid active brush from brush asset information. */
1133 if (paint->eraser_brush != nullptr) {
1134 return false;
1135 }
1136 if (paint->eraser_brush_asset_reference == nullptr) {
1137 return false;
1138 }
1139
1140 Brush *brush = reinterpret_cast<Brush *>(blender::bke::asset_edit_id_from_weak_reference(
1141 *bmain, ID_BR, *paint->eraser_brush_asset_reference));
1142 BLI_assert(brush == nullptr || blender::bke::asset_edit_id_is_editable(brush->id));
1143
1144 /* Ensure we have a brush with appropriate mode to assign.
1145 * Could happen if contents of asset blend was manually changed. */
1146 if (brush == nullptr || (paint->runtime.ob_mode & brush->ob_mode) == 0) {
1147 MEM_delete(paint->eraser_brush_asset_reference);
1148 paint->eraser_brush_asset_reference = nullptr;
1149 return false;
1150 }
1151
1152 paint->eraser_brush = brush;
1153 return true;
1154}
1155
1157{
1158 return paint ? paint->eraser_brush : nullptr;
1159}
1160
1162{
1163 return paint ? paint->eraser_brush : nullptr;
1164}
1165
1167{
1168 if (paint == nullptr || paint->eraser_brush == brush) {
1169 return false;
1170 }
1171 if (brush && (paint->runtime.ob_mode & brush->ob_mode) == 0) {
1172 return false;
1173 }
1174
1175 paint->eraser_brush = brush;
1176
1177 MEM_delete(paint->eraser_brush_asset_reference);
1178 paint->eraser_brush_asset_reference = nullptr;
1179
1180 if (brush != nullptr) {
1181 std::optional<AssetWeakReference> weak_ref = blender::bke::asset_edit_weak_reference_from_id(
1182 brush->id);
1183 if (weak_ref.has_value()) {
1184 paint->eraser_brush_asset_reference = MEM_new<AssetWeakReference>(__func__, *weak_ref);
1185 }
1186 }
1187
1188 return true;
1189}
1190
1192{
1193 std::optional<AssetWeakReference> weak_ref = paint_brush_asset_reference_from_essentials(
1194 name, ob_mode);
1195 if (!weak_ref) {
1196 return {};
1197 }
1198
1199 return reinterpret_cast<Brush *>(
1201}
1202
1204{
1205 paint_brush_set_default_reference(paint, false, true);
1207}
1208
1209bool BKE_paint_eraser_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
1210{
1213}
1214
1215static void paint_runtime_init(const ToolSettings *ts, Paint *paint)
1216{
1217 if (paint == &ts->imapaint.paint) {
1219 }
1220 else if (ts->sculpt && paint == &ts->sculpt->paint) {
1222 }
1223 else if (ts->vpaint && paint == &ts->vpaint->paint) {
1225 }
1226 else if (ts->wpaint && paint == &ts->wpaint->paint) {
1228 }
1229 else if (ts->gp_paint && paint == &ts->gp_paint->paint) {
1231 }
1232 else if (ts->gp_vertexpaint && paint == &ts->gp_vertexpaint->paint) {
1234 }
1235 else if (ts->gp_sculptpaint && paint == &ts->gp_sculptpaint->paint) {
1237 }
1238 else if (ts->gp_weightpaint && paint == &ts->gp_weightpaint->paint) {
1240 }
1241 else if (ts->curves_sculpt && paint == &ts->curves_sculpt->paint) {
1243 }
1244 else {
1246 }
1247
1248 paint->runtime.initialized = true;
1250}
1251
1253{
1254 switch (mode) {
1257 return offsetof(Brush, image_brush_type);
1258 case PaintMode::Sculpt:
1259 return offsetof(Brush, sculpt_brush_type);
1260 case PaintMode::Vertex:
1261 return offsetof(Brush, vertex_brush_type);
1262 case PaintMode::Weight:
1263 return offsetof(Brush, weight_brush_type);
1264 case PaintMode::GPencil:
1265 return offsetof(Brush, gpencil_brush_type);
1267 return offsetof(Brush, gpencil_vertex_brush_type);
1269 return offsetof(Brush, gpencil_sculpt_brush_type);
1271 return offsetof(Brush, gpencil_weight_brush_type);
1273 return offsetof(Brush, curves_sculpt_brush_type);
1274 case PaintMode::Invalid:
1275 break; /* We don't use these yet. */
1276 }
1277 return 0;
1278}
1279
1280std::optional<int> BKE_paint_get_brush_type_from_obmode(const Brush *brush,
1281 const eObjectMode ob_mode)
1282{
1283 switch (ob_mode) {
1285 case OB_MODE_EDIT:
1286 return brush->image_brush_type;
1287 case OB_MODE_SCULPT:
1288 return brush->sculpt_brush_type;
1290 return brush->vertex_brush_type;
1292 return brush->weight_brush_type;
1294 return brush->gpencil_brush_type;
1296 return brush->gpencil_vertex_brush_type;
1298 return brush->gpencil_sculpt_brush_type;
1300 return brush->gpencil_weight_brush_type;
1302 return brush->curves_sculpt_brush_type;
1303 default:
1304 return {};
1305 }
1306}
1307
1308std::optional<int> BKE_paint_get_brush_type_from_paintmode(const Brush *brush,
1309 const PaintMode mode)
1310{
1311 switch (mode) {
1314 return brush->image_brush_type;
1315 case PaintMode::Sculpt:
1316 return brush->sculpt_brush_type;
1317 case PaintMode::Vertex:
1318 return brush->vertex_brush_type;
1319 case PaintMode::Weight:
1320 return brush->weight_brush_type;
1321 case PaintMode::GPencil:
1322 return brush->gpencil_brush_type;
1324 return brush->gpencil_vertex_brush_type;
1326 return brush->gpencil_sculpt_brush_type;
1328 return brush->gpencil_weight_brush_type;
1330 return brush->curves_sculpt_brush_type;
1331 case PaintMode::Invalid:
1332 default:
1333 return {};
1334 }
1335}
1336
1337PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
1338{
1339 PaintCurve *pc = BKE_id_new<PaintCurve>(bmain, name);
1340 return pc;
1341}
1342
1344{
1345 return paint ? paint->palette : nullptr;
1346}
1347
1349{
1350 if (paint) {
1351 id_us_min((ID *)paint->palette);
1352 paint->palette = palette;
1353 id_us_plus((ID *)paint->palette);
1354 }
1355}
1356
1358{
1359 pc->add_index = (add_index || pc->tot_points == 1) ? (add_index + 1) : 0;
1360}
1361
1363{
1364 if (BLI_listbase_count_at_most(&palette->colors, palette->active_color) == palette->active_color)
1365 {
1366 palette->active_color--;
1367 }
1368
1369 BLI_remlink(&palette->colors, color);
1370
1371 if (palette->active_color < 0 && !BLI_listbase_is_empty(&palette->colors)) {
1372 palette->active_color = 0;
1373 }
1374
1375 MEM_freeN(color);
1376}
1377
1379{
1380 BLI_freelistN(&palette->colors);
1381 palette->active_color = 0;
1382}
1383
1384Palette *BKE_palette_add(Main *bmain, const char *name)
1385{
1386 Palette *palette = BKE_id_new<Palette>(bmain, name);
1387 return palette;
1388}
1389
1391{
1392 PaletteColor *color = MEM_callocN<PaletteColor>(__func__);
1393 BLI_addtail(&palette->colors, color);
1394 return color;
1395}
1396
1397bool BKE_palette_is_empty(const Palette *palette)
1398{
1399 return BLI_listbase_is_empty(&palette->colors);
1400}
1401
1402static int palettecolor_compare_hsv(const void *a1, const void *a2)
1403{
1404 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1405 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1406
1407 /* Hue */
1408 if (ps1->h > ps2->h) {
1409 return 1;
1410 }
1411 if (ps1->h < ps2->h) {
1412 return -1;
1413 }
1414
1415 /* Saturation. */
1416 if (ps1->s > ps2->s) {
1417 return 1;
1418 }
1419 if (ps1->s < ps2->s) {
1420 return -1;
1421 }
1422
1423 /* Value. */
1424 if (1.0f - ps1->v > 1.0f - ps2->v) {
1425 return 1;
1426 }
1427 if (1.0f - ps1->v < 1.0f - ps2->v) {
1428 return -1;
1429 }
1430
1431 return 0;
1432}
1433
1434void BKE_palette_sort_hsv(tPaletteColorHSV *color_array, const int totcol)
1435{
1436 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_hsv);
1437}
1438
1439static int palettecolor_compare_svh(const void *a1, const void *a2)
1440{
1441 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1442 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1443
1444 /* Saturation. */
1445 if (ps1->s > ps2->s) {
1446 return 1;
1447 }
1448 if (ps1->s < ps2->s) {
1449 return -1;
1450 }
1451
1452 /* Value. */
1453 if (1.0f - ps1->v > 1.0f - ps2->v) {
1454 return 1;
1455 }
1456 if (1.0f - ps1->v < 1.0f - ps2->v) {
1457 return -1;
1458 }
1459
1460 /* Hue */
1461 if (ps1->h > ps2->h) {
1462 return 1;
1463 }
1464 if (ps1->h < ps2->h) {
1465 return -1;
1466 }
1467
1468 return 0;
1469}
1470
1471void BKE_palette_sort_svh(tPaletteColorHSV *color_array, const int totcol)
1472{
1473 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_svh);
1474}
1475
1476static int palettecolor_compare_vhs(const void *a1, const void *a2)
1477{
1478 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1479 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1480
1481 /* Value. */
1482 if (1.0f - ps1->v > 1.0f - ps2->v) {
1483 return 1;
1484 }
1485 if (1.0f - ps1->v < 1.0f - ps2->v) {
1486 return -1;
1487 }
1488
1489 /* Hue */
1490 if (ps1->h > ps2->h) {
1491 return 1;
1492 }
1493 if (ps1->h < ps2->h) {
1494 return -1;
1495 }
1496
1497 /* Saturation. */
1498 if (ps1->s > ps2->s) {
1499 return 1;
1500 }
1501 if (ps1->s < ps2->s) {
1502 return -1;
1503 }
1504
1505 return 0;
1506}
1507
1508void BKE_palette_sort_vhs(tPaletteColorHSV *color_array, const int totcol)
1509{
1510 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_vhs);
1511}
1512
1513static int palettecolor_compare_luminance(const void *a1, const void *a2)
1514{
1515 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1516 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1517
1518 float lumi1 = (ps1->rgb[0] + ps1->rgb[1] + ps1->rgb[2]) / 3.0f;
1519 float lumi2 = (ps2->rgb[0] + ps2->rgb[1] + ps2->rgb[2]) / 3.0f;
1520
1521 if (lumi1 > lumi2) {
1522 return -1;
1523 }
1524 if (lumi1 < lumi2) {
1525 return 1;
1526 }
1527
1528 return 0;
1529}
1530
1531void BKE_palette_sort_luminance(tPaletteColorHSV *color_array, const int totcol)
1532{
1533 /* Sort by Luminance (calculated with the average, enough for sorting). */
1534 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_luminance);
1535}
1536
1537bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name, const bool linear)
1538{
1539 tPaletteColorHSV *color_array = nullptr;
1540 tPaletteColorHSV *col_elm = nullptr;
1541 bool done = false;
1542
1543 const int totpal = BLI_ghash_len(color_table);
1544
1545 if (totpal > 0) {
1546 color_array = MEM_calloc_arrayN<tPaletteColorHSV>(totpal, __func__);
1547 /* Put all colors in an array. */
1548 GHashIterator gh_iter;
1549 int t = 0;
1550 GHASH_ITER (gh_iter, color_table) {
1552 float r, g, b;
1553 float h, s, v;
1554 cpack_to_rgb(col, &r, &g, &b);
1555 rgb_to_hsv(r, g, b, &h, &s, &v);
1556
1557 col_elm = &color_array[t];
1558 col_elm->rgb[0] = r;
1559 col_elm->rgb[1] = g;
1560 col_elm->rgb[2] = b;
1561 col_elm->h = h;
1562 col_elm->s = s;
1563 col_elm->v = v;
1564 t++;
1565 }
1566 }
1567
1568 /* Create the Palette. */
1569 if (totpal > 0) {
1570 /* Sort by Hue and saturation. */
1571 BKE_palette_sort_hsv(color_array, totpal);
1572
1573 Palette *palette = BKE_palette_add(bmain, name);
1574 if (palette) {
1575 for (int i = 0; i < totpal; i++) {
1576 col_elm = &color_array[i];
1577 PaletteColor *palcol = BKE_palette_color_add(palette);
1578 if (palcol) {
1579 copy_v3_v3(palcol->rgb, col_elm->rgb);
1580 if (linear) {
1581 linearrgb_to_srgb_v3_v3(palcol->rgb, palcol->rgb);
1582 }
1583 }
1584 }
1585 done = true;
1586 }
1587 }
1588 else {
1589 done = false;
1590 }
1591
1592 if (totpal > 0) {
1593 MEM_SAFE_FREE(color_array);
1594 }
1595
1596 return done;
1597}
1598
1600{
1601 return ((ob != nullptr) && (ob->type == OB_MESH) && (ob->data != nullptr) &&
1602 (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_FACE_SEL) &&
1604}
1605
1607{
1608 return ((ob != nullptr) && (ob->type == OB_MESH) && (ob->data != nullptr) &&
1609 (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_VERT_SEL) &&
1611}
1612
1614{
1615 if (ob == nullptr || ob->data == nullptr) {
1616 return false;
1617 }
1618 if (ob->type == OB_GREASE_PENCIL) {
1620 }
1621 return false;
1622}
1623
1629
1631{
1632 return ((ob != nullptr) && (ob->type == OB_MESH) && (ob->data != nullptr) &&
1634}
1635
1636void BKE_paint_cavity_curve_preset(Paint *paint, int preset)
1637{
1638 CurveMapping *cumap = nullptr;
1639 CurveMap *cuma = nullptr;
1640
1641 if (!paint->cavity_curve) {
1642 paint->cavity_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
1643 }
1644 cumap = paint->cavity_curve;
1646 cumap->preset = preset;
1647
1648 cuma = cumap->cm;
1650 BKE_curvemapping_changed(cumap, false);
1651}
1652
1654{
1655 switch (mode) {
1656 case PaintMode::Sculpt:
1657 return OB_MODE_SCULPT;
1658 case PaintMode::Vertex:
1659 return OB_MODE_VERTEX_PAINT;
1660 case PaintMode::Weight:
1661 return OB_MODE_WEIGHT_PAINT;
1664 return OB_MODE_TEXTURE_PAINT;
1666 return OB_MODE_SCULPT_CURVES;
1667 case PaintMode::GPencil:
1669 case PaintMode::Invalid:
1670 default:
1671 return OB_MODE_OBJECT;
1672 }
1673}
1674
1676{
1677 Paint *paint = nullptr;
1678 if (*r_paint) {
1679 if (!(*r_paint)->runtime.initialized) {
1680 /* Currently only image painting is initialized this way, others have to be allocated. */
1681 BLI_assert(ELEM(*r_paint, (Paint *)&ts->imapaint));
1682
1683 paint_runtime_init(ts, *r_paint);
1684 }
1685 else {
1686 BLI_assert(ELEM(*r_paint,
1687 /* Cast is annoying, but prevent nullptr-pointer access. */
1688 (Paint *)ts->gp_paint,
1689 (Paint *)ts->gp_vertexpaint,
1690 (Paint *)ts->gp_sculptpaint,
1691 (Paint *)ts->gp_weightpaint,
1692 (Paint *)ts->sculpt,
1693 (Paint *)ts->vpaint,
1694 (Paint *)ts->wpaint,
1695 (Paint *)ts->curves_sculpt,
1696 (Paint *)&ts->imapaint));
1697#ifndef NDEBUG
1698 Paint paint_test = **r_paint;
1699 paint_runtime_init(ts, *r_paint);
1700 /* Swap so debug doesn't hide errors when release fails. */
1701 std::swap(**r_paint, paint_test);
1702 BLI_assert(paint_test.runtime.ob_mode == (*r_paint)->runtime.ob_mode);
1703#endif
1704 }
1705 return true;
1706 }
1707
1708 if (((VPaint **)r_paint == &ts->vpaint) || ((VPaint **)r_paint == &ts->wpaint)) {
1709 VPaint *data = MEM_callocN<VPaint>(__func__);
1710 paint = &data->paint;
1711 }
1712 else if ((Sculpt **)r_paint == &ts->sculpt) {
1713 Sculpt *data = MEM_callocN<Sculpt>(__func__);
1714
1716
1717 paint = &data->paint;
1718 }
1719 else if ((GpPaint **)r_paint == &ts->gp_paint) {
1720 GpPaint *data = MEM_callocN<GpPaint>(__func__);
1721 paint = &data->paint;
1722 }
1723 else if ((GpVertexPaint **)r_paint == &ts->gp_vertexpaint) {
1725 paint = &data->paint;
1726 }
1727 else if ((GpSculptPaint **)r_paint == &ts->gp_sculptpaint) {
1729 paint = &data->paint;
1730 }
1731 else if ((GpWeightPaint **)r_paint == &ts->gp_weightpaint) {
1733 paint = &data->paint;
1734 }
1735 else if ((CurvesSculpt **)r_paint == &ts->curves_sculpt) {
1737 paint = &data->paint;
1738 }
1739 else if (*r_paint == &ts->imapaint.paint) {
1740 paint = &ts->imapaint.paint;
1741 }
1742
1743 paint->flags |= PAINT_SHOW_BRUSH;
1744
1745 *r_paint = paint;
1746
1747 paint_runtime_init(ts, paint);
1748
1749 return false;
1750}
1751
1753{
1754 if (paint->brush_asset_reference) {
1756 }
1757 if (paint->eraser_brush_asset_reference) {
1759 }
1760
1761 if (!paint->brush) {
1762 BKE_paint_brush_set_default(bmain, paint);
1763 }
1764 if (!paint->eraser_brush) {
1766 }
1767}
1768
1770 Main *bmain, Scene *sce, PaintMode mode, const uchar col[3], const bool ensure_brushes)
1771{
1773
1775 Paint *paint = BKE_paint_get_active_from_paintmode(sce, mode);
1776
1777 if (ensure_brushes) {
1778 BKE_paint_brushes_ensure(bmain, paint);
1779 }
1780
1782 paint->paint_cursor_col[3] = 128;
1783 ups->last_stroke_valid = false;
1785 ups->average_stroke_counter = 0;
1786 if (!paint->cavity_curve) {
1788 }
1789}
1790
1792{
1794 MEM_delete(paint->brush_asset_reference);
1796 MEM_delete(paint->eraser_brush_asset_reference);
1797
1799 brush_ref,
1801 {
1802 MEM_delete(brush_ref->name);
1803 MEM_delete(brush_ref->brush_asset_reference);
1804 MEM_delete(brush_ref);
1805 }
1806 MEM_delete(paint->runtime.previous_active_brush_reference);
1807}
1808
1809void BKE_paint_copy(const Paint *src, Paint *dst, const int flag)
1810{
1811 dst->brush = src->brush;
1813
1814 if (src->brush_asset_reference) {
1815 dst->brush_asset_reference = MEM_new<AssetWeakReference>(__func__,
1816 *src->brush_asset_reference);
1817 }
1819 dst->tool_brush_bindings.main_brush_asset_reference = MEM_new<AssetWeakReference>(
1821 }
1823 dst->eraser_brush_asset_reference = MEM_new<AssetWeakReference>(
1824 __func__, *src->eraser_brush_asset_reference);
1825 }
1830 {
1831 brush_ref->name = BLI_strdup(brush_ref->name);
1832 brush_ref->brush_asset_reference = MEM_new<AssetWeakReference>(
1833 __func__, *brush_ref->brush_asset_reference);
1834 }
1835
1836 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
1837 id_us_plus((ID *)dst->palette);
1838 }
1839}
1840
1841void BKE_paint_stroke_get_average(const Scene *scene, const Object *ob, float stroke[3])
1842{
1844 if (ups->last_stroke_valid && ups->average_stroke_counter > 0) {
1845 float fac = 1.0f / ups->average_stroke_counter;
1846 mul_v3_v3fl(stroke, ups->average_stroke_accum, fac);
1847 }
1848 else {
1849 copy_v3_v3(stroke, ob->object_to_world().location());
1850 }
1851}
1852
1854 const blender::float3 &initial_hsv_jitter,
1855 const float distance,
1856 const float pressure,
1857 const blender::float3 &color)
1858{
1859 constexpr float noise_scale = 1 / 20.0f;
1860
1861 const float random_hue = (color_jitter.flag & BRUSH_COLOR_JITTER_USE_HUE_AT_STROKE) ?
1862 initial_hsv_jitter[0] :
1864 distance * noise_scale, initial_hsv_jitter[0] * 100));
1865
1866 const float random_sat = (color_jitter.flag & BRUSH_COLOR_JITTER_USE_SAT_AT_STROKE) ?
1867 initial_hsv_jitter[1] :
1869 distance * noise_scale, initial_hsv_jitter[1] * 100));
1870
1871 const float random_val = (color_jitter.flag & BRUSH_COLOR_JITTER_USE_VAL_AT_STROKE) ?
1872 initial_hsv_jitter[2] :
1874 distance * noise_scale, initial_hsv_jitter[2] * 100));
1875
1876 float hue_jitter_scale = color_jitter.hue;
1877 if ((color_jitter.flag & BRUSH_COLOR_JITTER_USE_HUE_RAND_PRESS)) {
1878 hue_jitter_scale *= BKE_curvemapping_evaluateF(color_jitter.curve_hue_jitter, 0, pressure);
1879 }
1880 float sat_jitter_scale = color_jitter.saturation;
1881 if ((color_jitter.flag & BRUSH_COLOR_JITTER_USE_SAT_RAND_PRESS)) {
1882 sat_jitter_scale *= BKE_curvemapping_evaluateF(color_jitter.curve_sat_jitter, 0, pressure);
1883 }
1884 float val_jitter_scale = color_jitter.value;
1885 if ((color_jitter.flag & BRUSH_COLOR_JITTER_USE_VAL_RAND_PRESS)) {
1886 val_jitter_scale *= BKE_curvemapping_evaluateF(color_jitter.curve_val_jitter, 0, pressure);
1887 }
1888
1889 blender::float3 hsv;
1890 rgb_to_hsv_v(color, hsv);
1891
1892 hsv[0] += blender::math::interpolate(0.5f, random_hue, hue_jitter_scale) - 0.5f;
1893 /* Wrap hue. */
1894 if (hsv[0] > 1.0f) {
1895 hsv[0] -= 1.0f;
1896 }
1897 else if (hsv[0] < 0.0f) {
1898 hsv[0] += 1.0f;
1899 }
1900
1901 hsv[1] *= blender::math::interpolate(1.0f, random_sat * 2.0f, sat_jitter_scale);
1902 hsv[2] *= blender::math::interpolate(1.0f, random_val * 2.0f, val_jitter_scale);
1903
1904 blender::float3 random_color;
1905 hsv_to_rgb_v(hsv, random_color);
1906 return random_color;
1907}
1908
1910{
1911 if (paint->cavity_curve) {
1913 }
1914 if (paint->brush_asset_reference) {
1916 }
1917 if (paint->eraser_brush_asset_reference) {
1919 }
1920
1921 {
1922 /* Write tool system bindings. */
1923 ToolSystemBrushBindings &tool_brush_bindings = paint->tool_brush_bindings;
1924
1925 if (tool_brush_bindings.main_brush_asset_reference) {
1927 }
1929 writer, NamedBrushAssetReference, &tool_brush_bindings.active_brush_per_brush_type);
1931 NamedBrushAssetReference *, brush_ref, &tool_brush_bindings.active_brush_per_brush_type)
1932 {
1933 BLO_write_string(writer, brush_ref->name);
1934 if (brush_ref->brush_asset_reference) {
1935 BKE_asset_weak_reference_write(writer, brush_ref->brush_asset_reference);
1936 }
1937 }
1938 }
1939}
1940
1941void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint)
1942{
1943 BLO_read_struct(reader, CurveMapping, &paint->cavity_curve);
1944 if (paint->cavity_curve) {
1946 }
1947 else {
1949 }
1950
1952 if (paint->brush_asset_reference) {
1954 }
1956 if (paint->eraser_brush_asset_reference) {
1958 }
1959
1960 {
1961 /* Read tool system bindings. */
1962 ToolSystemBrushBindings &tool_brush_bindings = paint->tool_brush_bindings;
1963
1964 BLO_read_struct(reader, AssetWeakReference, &tool_brush_bindings.main_brush_asset_reference);
1965 if (tool_brush_bindings.main_brush_asset_reference) {
1966 BKE_asset_weak_reference_read(reader, tool_brush_bindings.main_brush_asset_reference);
1967 }
1968
1970 reader, NamedBrushAssetReference, &tool_brush_bindings.active_brush_per_brush_type);
1972 NamedBrushAssetReference *, brush_ref, &tool_brush_bindings.active_brush_per_brush_type)
1973 {
1974 BLO_read_string(reader, &brush_ref->name);
1975
1976 BLO_read_struct(reader, AssetWeakReference, &brush_ref->brush_asset_reference);
1977 if (brush_ref->brush_asset_reference) {
1978 BKE_asset_weak_reference_read(reader, brush_ref->brush_asset_reference);
1979 }
1980 }
1981 }
1982
1983 paint->paint_cursor = nullptr;
1984 paint_runtime_init(scene->toolsettings, paint);
1985}
1986
1988 const int gridsize,
1989 const int x,
1990 const int y)
1991{
1992 return grid_hidden[CCG_grid_xy_to_index(gridsize, x, y)] ||
1993 grid_hidden[CCG_grid_xy_to_index(gridsize, x + 1, y)] ||
1994 grid_hidden[CCG_grid_xy_to_index(gridsize, x + 1, y + 1)] ||
1995 grid_hidden[CCG_grid_xy_to_index(gridsize, x, y + 1)];
1996}
1997
1999{
2000 BMLoop *l_iter;
2001 BMLoop *l_first;
2002
2003 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2004 do {
2005 if (BM_elem_flag_test(l_iter->v, BM_ELEM_HIDDEN)) {
2006 return true;
2007 }
2008 } while ((l_iter = l_iter->next) != l_first);
2009
2010 return false;
2011}
2012
2014{
2015 int factor = BKE_ccg_factor(level, gpm->level);
2016 int gridsize = BKE_ccg_gridsize(gpm->level);
2017
2018 return gpm->data[(y * factor) * gridsize + (x * factor)];
2019}
2020
2021/* Threshold to move before updating the brush rotation, reduces jitter. */
2022static float paint_rake_rotation_spacing(const UnifiedPaintSettings & /*ups*/, const Brush &brush)
2023{
2024 return brush.sculpt_brush_type == SCULPT_BRUSH_TYPE_CLAY_STRIPS ? 1.0f : 20.0f;
2025}
2026
2028 const Brush &brush,
2029 float rotation)
2030{
2031 ups.brush_rotation = rotation;
2032
2034 ups.brush_rotation_sec = rotation;
2035 }
2036 else {
2037 ups.brush_rotation_sec = 0.0f;
2038 }
2039}
2040
2041static bool paint_rake_rotation_active(const MTex &mtex)
2042{
2043 return mtex.tex && mtex.brush_angle_mode & MTEX_ANGLE_RAKE;
2044}
2045
2046static bool paint_rake_rotation_active(const Brush &brush, PaintMode paint_mode)
2047{
2049 BKE_brush_has_cube_tip(&brush, paint_mode);
2050}
2051
2053 const Brush &brush,
2054 const float mouse_pos[2],
2055 const PaintMode paint_mode,
2056 bool stroke_has_started)
2057{
2058 bool ok = false;
2059 if (paint_rake_rotation_active(brush, paint_mode)) {
2060 float r = paint_rake_rotation_spacing(ups, brush);
2061 float rotation;
2062
2063 /* Use a smaller limit if the stroke hasn't started to prevent excessive pre-roll. */
2064 if (!stroke_has_started) {
2065 r = min_ff(r, 4.0f);
2066 }
2067
2068 float dpos[2];
2069 sub_v2_v2v2(dpos, mouse_pos, ups.last_rake);
2070
2071 /* Limit how often we update the angle to prevent jitter. */
2072 if (len_squared_v2(dpos) >= r * r) {
2073 rotation = atan2f(dpos[1], dpos[0]) + float(0.5f * M_PI);
2074
2075 copy_v2_v2(ups.last_rake, mouse_pos);
2076
2077 ups.last_rake_angle = rotation;
2078
2079 paint_update_brush_rake_rotation(ups, brush, rotation);
2080 ok = true;
2081 }
2082 /* Make sure we reset here to the last rotation to avoid accumulating
2083 * values in case a random rotation is also added. */
2084 else {
2086 ok = false;
2087 }
2088 }
2089 else {
2090 ups.brush_rotation = ups.brush_rotation_sec = 0.0f;
2091 ok = true;
2092 }
2093 return ok;
2094}
2095
2097{
2098 ss->deform_cos = {};
2099 ss->deform_imats = {};
2100 ss->vert_normals_deform = {};
2101 ss->face_normals_deform = {};
2102}
2103
2115
2120{
2121 SculptSession &ss = *ob->sculpt;
2122
2123 if (ss.bm) {
2124 if (ob->data) {
2125 if (reorder) {
2127 }
2129 params.calc_object_remap = false;
2130 BM_mesh_bm_to_me(nullptr, ss.bm, static_cast<Mesh *>(ob->data), &params);
2131 }
2132 }
2133}
2134
2135void BKE_sculptsession_bm_to_me(Object *ob, bool reorder)
2136{
2137 if (ob && ob->sculpt) {
2139
2140 /* Ensure the objects evaluated mesh doesn't hold onto arrays
2141 * now realloc'd in the mesh #34473. */
2143 }
2144}
2145
2147{
2148 SculptSession *ss = object.sculpt;
2149 if (!ss) {
2150 return;
2151 }
2152
2153 ss->pbvh.reset();
2154 ss->edge_to_face_offsets = {};
2155 ss->edge_to_face_indices = {};
2156 ss->edge_to_face_map = {};
2157 ss->vert_to_edge_offsets = {};
2158 ss->vert_to_edge_indices = {};
2159 ss->vert_to_edge_map = {};
2160
2161 ss->preview_verts = {};
2162
2165 ss->topology_island_cache.reset();
2166
2167 ss->clear_active_elements(false);
2168}
2169
2171{
2172 if (object && object->sculpt) {
2173 if (object->sculpt->bm) {
2174 /* Ensure no points to old arrays are stored in DM
2175 *
2176 * Apparently, we could not use DEG_id_tag_update
2177 * here because this will lead to the while object
2178 * surface to disappear, so we'll release DM in place.
2179 */
2181
2183
2184 /* In contrast with sculptsession_bm_to_me no need in
2185 * DAG tag update here - derived mesh was freed and
2186 * old pointers are nowhere stored.
2187 */
2188 }
2189 }
2190}
2191
2193{
2194 if (ob && ob->sculpt) {
2195 SculptSession *ss = ob->sculpt;
2196
2197 if (ss->bm) {
2199 BM_mesh_free(ss->bm);
2200 }
2201
2203
2204 MEM_delete(ss);
2205
2206 ob->sculpt = nullptr;
2207 }
2208}
2209
2211
2213{
2214 if (this->bm_log) {
2215 BM_log_free(this->bm_log);
2216 }
2217
2218 if (this->tex_pool) {
2220 }
2221
2223
2225}
2226
2228{
2229 return active_vert_;
2230}
2231
2233{
2234 return last_active_vert_;
2235}
2236
2238{
2239 if (std::holds_alternative<int>(active_vert_)) {
2240 return std::get<int>(active_vert_);
2241 }
2242 if (std::holds_alternative<BMVert *>(active_vert_)) {
2243 BMVert *bm_vert = std::get<BMVert *>(active_vert_);
2244 return BM_elem_index_get(bm_vert);
2245 }
2246
2247 return -1;
2248}
2249
2251{
2252 if (std::holds_alternative<int>(last_active_vert_)) {
2253 return std::get<int>(last_active_vert_);
2254 }
2255 if (std::holds_alternative<BMVert *>(last_active_vert_)) {
2256 BMVert *bm_vert = std::get<BMVert *>(last_active_vert_);
2257 return BM_elem_index_get(bm_vert);
2258 }
2259
2260 return -1;
2261}
2262
2264 const Object &object) const
2265{
2266 if (std::holds_alternative<int>(active_vert_)) {
2267 if (this->subdiv_ccg) {
2268 return this->subdiv_ccg->positions[std::get<int>(active_vert_)];
2269 }
2271 return positions[std::get<int>(active_vert_)];
2272 }
2273 if (std::holds_alternative<BMVert *>(active_vert_)) {
2274 BMVert *bm_vert = std::get<BMVert *>(active_vert_);
2275 return bm_vert->co;
2276 }
2277
2279 return float3(std::numeric_limits<float>::infinity());
2280}
2281
2282void SculptSession::clear_active_elements(bool persist_last_active)
2283{
2284 if (persist_last_active) {
2285 if (!std::holds_alternative<std::monostate>(active_vert_)) {
2286 last_active_vert_ = active_vert_;
2287 }
2288 }
2289 else {
2290 last_active_vert_ = {};
2291 }
2292 active_vert_ = {};
2293 active_grid_index.reset();
2294 active_face_index.reset();
2295}
2296
2298{
2299 active_vert_ = vert;
2300}
2301
2302std::optional<PersistentMultiresData> SculptSession::persistent_multires_data()
2303{
2305 if (persistent.grids_num == -1 || persistent.grid_size == -1) {
2306 return std::nullopt;
2307 }
2308
2309 if (this->subdiv_ccg->grids_num != persistent.grids_num ||
2310 this->subdiv_ccg->grid_size != persistent.grid_size)
2311 {
2312 return std::nullopt;
2313 }
2314
2315 return PersistentMultiresData{persistent.sculpt_persistent_co,
2316 persistent.sculpt_persistent_no,
2317 persistent.sculpt_persistent_disp};
2318}
2319
2321 Object *ob,
2322 const bool auto_create_mdisps)
2323{
2324 Mesh &mesh = *static_cast<Mesh *>(ob->data);
2325
2326 if (ob->sculpt && ob->sculpt->bm) {
2327 /* Can't combine multires and dynamic topology. */
2328 return nullptr;
2329 }
2330
2331 bool need_mdisps = false;
2332
2334 if (!auto_create_mdisps) {
2335 /* Multires can't work without displacement layer. */
2336 return nullptr;
2337 }
2338 need_mdisps = true;
2339 }
2340
2341 /* Weight paint operates on original vertices, and needs to treat multires as regular modifier
2342 * to make it so that pbvh::Tree vertices are at the multires surface. */
2343 if ((ob->mode & OB_MODE_SCULPT) == 0) {
2344 return nullptr;
2345 }
2346
2347 VirtualModifierData virtual_modifier_data;
2348 for (ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data); md;
2349 md = md->next)
2350 {
2351 if (md->type == eModifierType_Multires) {
2352 MultiresModifierData *mmd = reinterpret_cast<MultiresModifierData *>(md);
2353
2355 continue;
2356 }
2357
2358 if (mmd->sculptlvl > 0 && !(mmd->flags & eMultiresModifierFlag_UseSculptBaseMesh)) {
2359 if (need_mdisps) {
2361 }
2362
2363 return mmd;
2364 }
2365
2366 return nullptr;
2367 }
2368 }
2369
2370 return nullptr;
2371}
2372
2374{
2375 return sculpt_multires_modifier_get(scene, ob, false);
2376}
2377
2378/* Checks if there are any supported deformation modifiers active */
2379static bool sculpt_modifiers_active(const Scene *scene, const Sculpt *sd, Object *ob)
2380{
2381 const Mesh &mesh = *static_cast<Mesh *>(ob->data);
2382
2383 if (ob->sculpt->bm || BKE_sculpt_multires_active(scene, ob)) {
2384 return false;
2385 }
2386
2387 /* Non-locked shape keys could be handled in the same way as deformed mesh. */
2388 if ((ob->shapeflag & OB_SHAPE_LOCK) == 0 && mesh.key && ob->shapenr) {
2389 return true;
2390 }
2391
2392 VirtualModifierData virtual_modifier_data;
2393 for (ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data); md;
2394 md = md->next)
2395 {
2396 const ModifierTypeInfo *mti = BKE_modifier_get_info(static_cast<ModifierType>(md->type));
2398 continue;
2399 }
2400 if (md->type == eModifierType_Multires && (ob->mode & OB_MODE_SCULPT)) {
2401 MultiresModifierData *mmd = reinterpret_cast<MultiresModifierData *>(md);
2403 continue;
2404 }
2405 }
2406 /* Exception for shape keys because we can edit those. */
2407 if (md->type == eModifierType_ShapeKey) {
2408 continue;
2409 }
2410
2411 if (mti->type == ModifierTypeType::OnlyDeform) {
2412 return true;
2413 }
2414 if ((sd->flags & SCULPT_ONLY_DEFORM) == 0) {
2415 return true;
2416 }
2417 }
2418
2419 return false;
2420}
2421
2422static void sculpt_update_object(Depsgraph *depsgraph,
2423 Object *ob,
2424 Object *ob_eval,
2425 bool is_paint_tool)
2426{
2427 using namespace blender;
2428 using namespace blender::bke;
2430 Sculpt *sd = scene->toolsettings->sculpt;
2431 SculptSession &ss = *ob->sculpt;
2432 Mesh *mesh_orig = BKE_object_get_original_mesh(ob);
2433 /* Use the "unchecked" function, because this code also runs as part of the depsgraph node that
2434 * evaluates the object's geometry. So from perspective of the depsgraph, the mesh is not fully
2435 * evaluated yet. */
2436 Mesh *mesh_eval = BKE_object_get_evaluated_mesh_unchecked(ob_eval);
2437 MultiresModifierData *mmd = sculpt_multires_modifier_get(scene, ob, true);
2438
2439 BLI_assert(mesh_eval != nullptr);
2440
2441 /* This is for handling a newly opened file with no object visible,
2442 * causing `mesh_eval == nullptr`. */
2443 if (mesh_eval == nullptr) {
2444 return;
2445 }
2446
2448
2449 ss.building_vp_handle = false;
2450
2451 ss.shapekey_active = (mmd == nullptr) ? BKE_keyblock_from_object(ob) : nullptr;
2452
2453 /* NOTE: Weight pPaint require mesh info for loop lookup, but it never uses multires code path,
2454 * so no extra checks is needed here. */
2455 if (mmd) {
2456 ss.multires.active = true;
2457 ss.multires.modifier = mmd;
2458 ss.multires.level = mmd->sculptlvl;
2459 }
2460 else {
2461 ss.multires.active = false;
2462 ss.multires.modifier = nullptr;
2463 ss.multires.level = 0;
2464 }
2465
2466 ss.subdiv_ccg = mesh_eval->runtime->subdiv_ccg.get();
2467
2469
2470 if (ss.deform_modifiers_active) {
2471 /* Painting doesn't need crazyspace, use already evaluated mesh coordinates if possible. */
2472 bool used_me_eval = false;
2473
2475 const Mesh *me_eval_deform = BKE_object_get_mesh_deform_eval(ob_eval);
2476
2477 /* If the fully evaluated mesh has the same topology as the deform-only version, use it.
2478 * This matters because crazyspace evaluation is very restrictive and excludes even modifiers
2479 * that simply recompute vertex weights (which can even include Geometry Nodes). */
2480 if (me_eval_deform->faces_num == mesh_eval->faces_num &&
2481 me_eval_deform->corners_num == mesh_eval->corners_num &&
2482 me_eval_deform->verts_num == mesh_eval->verts_num)
2483 {
2485
2486 BLI_assert(me_eval_deform->verts_num == mesh_orig->verts_num);
2487
2488 ss.deform_cos = mesh_eval->vert_positions();
2490
2491 used_me_eval = true;
2492 }
2493 }
2494
2495 /* We depend on the deform coordinates not being updated in the middle of a stroke. This array
2496 * eventually gets cleared inside BKE_sculpt_update_object_before_eval.
2497 * See #126713 for more information. */
2498 if (ss.deform_cos.is_empty() && !used_me_eval) {
2500
2503
2504 for (blender::float3x3 &matrix : ss.deform_imats) {
2505 matrix = blender::math::invert(matrix);
2506 }
2507 }
2508 }
2509 else {
2511 }
2512
2513 if (ss.shapekey_active != nullptr && ss.deform_cos.is_empty()) {
2514 ss.deform_cos = Span(static_cast<const float3 *>(ss.shapekey_active->data),
2515 mesh_orig->verts_num);
2516 }
2517
2518 /* if pbvh is deformed, key block is already applied to it */
2519 if (ss.shapekey_active) {
2520 if (ss.deform_cos.is_empty()) {
2521 const Span key_data(static_cast<const float3 *>(ss.shapekey_active->data),
2522 mesh_orig->verts_num);
2523
2524 if (key_data.data() != nullptr) {
2526 if (ss.deform_cos.is_empty()) {
2527 ss.deform_cos = key_data;
2528 }
2529 }
2530 }
2531 }
2532
2533 if (is_paint_tool) {
2534 /* We should rebuild the PBVH_pixels when painting canvas changes.
2535 *
2536 * The relevant changes are stored/encoded in the paint canvas key.
2537 * These include the active uv map, and resolutions. */
2538 if (USER_EXPERIMENTAL_TEST(&U, use_sculpt_texture_paint)) {
2539 char *paint_canvas_key = BKE_paint_canvas_key_get(&scene->toolsettings->paint_mode, ob);
2540 if (ss.last_paint_canvas_key == nullptr ||
2541 !STREQ(paint_canvas_key, ss.last_paint_canvas_key))
2542 {
2544 ss.last_paint_canvas_key = paint_canvas_key;
2546 }
2547 else {
2548 MEM_freeN(paint_canvas_key);
2549 }
2550 }
2551
2552 /* We could be more precise when we have access to the active tool. */
2553 const bool use_paint_slots = (ob->mode & OB_MODE_SCULPT) != 0;
2554 if (use_paint_slots) {
2556 }
2557 }
2558
2559 /* This solves a crash when running a sculpt brush in background mode, because there is no redraw
2560 * after entering sculpt mode to make sure normals are allocated. Recalculating normals with
2561 * every brush step is too expensive currently. */
2563}
2564
2566{
2567 using namespace blender;
2568 /* Update before mesh evaluation in the dependency graph. */
2569 Object *ob_orig = DEG_get_original(ob_eval);
2570 SculptSession *ss = ob_orig->sculpt;
2571 if (!ss) {
2572 return;
2573 }
2574 if (ss->building_vp_handle) {
2575 return;
2576 }
2577
2579
2580 if (!ss->cache && !ss->filter_cache && !ss->expand_cache) {
2581 /* Avoid performing the following normal update for Multires, as it causes race conditions
2582 * and other intermittent crashes with shared meshes.
2583 * See !125268 and #125157 for more information. */
2584 if (pbvh && pbvh->type() != blender::bke::pbvh::Type::Grids) {
2585 /* pbvh::Tree nodes may contain dirty normal tags. To avoid losing that information when
2586 * the pbvh::Tree is deleted, make sure all tagged geometry normals are up to date.
2587 * See #122947 for more information. */
2589 }
2590 /* We free pbvh on changes, except in the middle of drawing a stroke
2591 * since it can't deal with changing PVBH node organization, we hope
2592 * topology does not change in the meantime .. weak. */
2594
2596
2597 /* In vertex/weight paint, force maps to be rebuilt. */
2599 }
2600 else if (pbvh) {
2601 IndexMaskMemory memory;
2602 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(*pbvh, memory);
2603 pbvh->tag_positions_changed(node_mask);
2604 switch (pbvh->type()) {
2605 case bke::pbvh::Type::Mesh: {
2607 node_mask.foreach_index([&](const int i) { BKE_pbvh_node_mark_update(nodes[i]); });
2608 break;
2609 }
2612 node_mask.foreach_index([&](const int i) { BKE_pbvh_node_mark_update(nodes[i]); });
2613 break;
2614 }
2617 node_mask.foreach_index([&](const int i) { BKE_pbvh_node_mark_update(nodes[i]); });
2618 break;
2619 }
2620 }
2621 }
2622}
2623
2625{
2626 /* Update after mesh evaluation in the dependency graph, to rebuild pbvh::Tree or
2627 * other data when modifiers change the mesh. */
2628 Object *ob_orig = DEG_get_original(ob_eval);
2629
2630 sculpt_update_object(depsgraph, ob_orig, ob_eval, false);
2631}
2632
2634{
2635 using namespace blender;
2636 using namespace blender::bke;
2637 Mesh *orig_me = BKE_object_get_original_mesh(object);
2638
2639 if (BKE_color_attribute_supported(*orig_me, orig_me->active_color_attribute)) {
2640 return;
2641 }
2642
2643 AttributeOwner owner = AttributeOwner::from_id(&orig_me->id);
2644 const std::string unique_name = BKE_attribute_calc_unique_name(owner, "Color");
2645 if (!orig_me->attributes_for_write().add(
2647 {
2648 return;
2649 }
2650
2654 BKE_mesh_tessface_clear(orig_me);
2655}
2656
2657void BKE_sculpt_update_object_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
2658{
2659 BLI_assert(ob_orig == DEG_get_original(ob_orig));
2660
2661 Object *ob_eval = DEG_get_evaluated(depsgraph, ob_orig);
2662
2663 sculpt_update_object(depsgraph, ob_orig, ob_eval, is_paint_tool);
2664}
2665
2667 Main *bmain,
2668 Object *ob,
2670{
2671 using namespace blender;
2672 using namespace blender::bke;
2673 Mesh *mesh = static_cast<Mesh *>(ob->data);
2674 const OffsetIndices faces = mesh->faces();
2675 const Span<int> corner_verts = mesh->corner_verts();
2676 MutableAttributeAccessor attributes = mesh->attributes_for_write();
2677
2678 /* if multires is active, create a grid paint mask layer if there
2679 * isn't one already */
2680 if (mmd && !CustomData_has_layer(&mesh->corner_data, CD_GRID_PAINT_MASK)) {
2681 int level = max_ii(1, mmd->sculptlvl);
2682 int gridsize = BKE_ccg_gridsize(level);
2683 int gridarea = gridsize * gridsize;
2684
2685 GridPaintMask *gmask = static_cast<GridPaintMask *>(CustomData_add_layer(
2686 &mesh->corner_data, CD_GRID_PAINT_MASK, CD_SET_DEFAULT, mesh->corners_num));
2687
2688 for (int i = 0; i < mesh->corners_num; i++) {
2689 GridPaintMask *gpm = &gmask[i];
2690
2691 gpm->level = level;
2692 gpm->data = MEM_calloc_arrayN<float>(gridarea, "GridPaintMask.data");
2693 }
2694
2695 /* If vertices already have mask, copy into multires data. */
2696 if (const VArray<float> mask = *attributes.lookup<float>(".sculpt_mask", AttrDomain::Point)) {
2697 const VArraySpan<float> mask_span(mask);
2698 for (const int i : faces.index_range()) {
2699 const IndexRange face = faces[i];
2700
2701 /* Mask center. */
2702 float avg = 0.0f;
2703 for (const int vert : corner_verts.slice(face)) {
2704 avg += mask_span[vert];
2705 }
2706 avg /= float(face.size());
2707
2708 /* Fill in multires mask corner. */
2709 for (const int corner : face) {
2710 GridPaintMask *gpm = &gmask[corner];
2711 const int vert = corner_verts[corner];
2712 const int prev = corner_verts[mesh::face_corner_prev(face, corner)];
2713 const int next = corner_verts[mesh::face_corner_next(face, corner)];
2714
2715 gpm->data[0] = avg;
2716 gpm->data[1] = (mask_span[vert] + mask_span[next]) * 0.5f;
2717 gpm->data[2] = (mask_span[vert] + mask_span[prev]) * 0.5f;
2718 gpm->data[3] = mask_span[vert];
2719 }
2720 }
2721 }
2722 /* The evaluated multires CCG must be updated to contain the new data. */
2724 if (depsgraph) {
2726 }
2727 }
2728 else {
2729 attributes.add<float>(".sculpt_mask", AttrDomain::Point, AttributeInitDefaultValue());
2730 }
2731}
2732
2743
2745{
2748
2749 Sculpt *sd = scene->toolsettings->sculpt;
2750
2751 const Sculpt *defaults = DNA_struct_default_get(Sculpt);
2752
2753 /* We have file versioning code here for historical
2754 * reasons. Don't add more checks here, do it properly
2755 * in blenloader.
2756 */
2757 if (sd->automasking_start_normal_limit == 0.0f) {
2760
2763 }
2764
2765 if (sd->detail_percent == 0.0f) {
2766 sd->detail_percent = defaults->detail_percent;
2767 }
2768 if (sd->constant_detail == 0.0f) {
2769 sd->constant_detail = defaults->constant_detail;
2770 }
2771 if (sd->detail_size == 0.0f) {
2772 sd->detail_size = defaults->detail_size;
2773 }
2774
2775 /* Set sane default tiling offsets. */
2776 if (!sd->paint.tile_offset[0]) {
2777 sd->paint.tile_offset[0] = 1.0f;
2778 }
2779 if (!sd->paint.tile_offset[1]) {
2780 sd->paint.tile_offset[1] = 1.0f;
2781 }
2782 if (!sd->paint.tile_offset[2]) {
2783 sd->paint.tile_offset[2] = 1.0f;
2784 }
2785
2788 }
2789}
2790
2791static bool check_sculpt_object_deformed(Object *object, const bool for_construction)
2792{
2793 bool deformed = false;
2794
2795 /* Active modifiers means extra deformation, which can't be handled correct
2796 * on birth of pbvh::Tree and sculpt "layer" levels, so use pbvh::Tree only for internal brush
2797 * stuff and show final evaluated mesh so user would see actual object shape. */
2798 deformed |= object->sculpt->deform_modifiers_active;
2799
2800 if (for_construction) {
2801 deformed |= object->sculpt->shapekey_active != nullptr;
2802 }
2803 else {
2804 /* As in case with modifiers, we can't synchronize deformation made against
2805 * pbvh::Tree and non-locked keyblock, so also use pbvh::Tree only for brushes and
2806 * final DM to give final result to user. */
2807 deformed |= object->sculpt->shapekey_active && (object->shapeflag & OB_SHAPE_LOCK) == 0;
2808 }
2809
2810 return deformed;
2811}
2812
2814{
2815 using namespace blender;
2816 using namespace blender::bke;
2817
2818 const AttributeAccessor attributes = mesh.attributes();
2819 const VArray<bool> hide_poly = *attributes.lookup_or_default<bool>(
2820 ".hide_poly", AttrDomain::Face, false);
2821 if (hide_poly.is_single() && !hide_poly.get_internal_single()) {
2823 return;
2824 }
2825
2826 const OffsetIndices<int> faces = mesh.faces();
2827
2828 const VArraySpan<bool> hide_poly_span(hide_poly);
2829 BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(subdiv_ccg);
2830 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
2831 for (const int i : range) {
2832 const bool face_hidden = hide_poly_span[i];
2833 for (const int corner : faces[i]) {
2834 grid_hidden[corner].set_all(face_hidden);
2835 }
2836 }
2837 });
2838}
2839
2840namespace blender::bke {
2841
2842static std::unique_ptr<pbvh::Tree> build_pbvh_for_dynamic_topology(Object *ob)
2843{
2844 BMesh &bm = *ob->sculpt->bm;
2845 BM_data_layer_ensure_named(&bm, &bm.vdata, CD_PROP_INT32, ".sculpt_dyntopo_node_id_vertex");
2846 BM_data_layer_ensure_named(&bm, &bm.pdata, CD_PROP_INT32, ".sculpt_dyntopo_node_id_face");
2847
2848 return std::make_unique<pbvh::Tree>(pbvh::Tree::from_bmesh(bm));
2849}
2850
2851static std::unique_ptr<pbvh::Tree> build_pbvh_from_regular_mesh(Object *ob,
2852 const Mesh *me_eval_deform)
2853{
2855 std::unique_ptr<pbvh::Tree> pbvh = std::make_unique<pbvh::Tree>(pbvh::Tree::from_mesh(mesh));
2856
2857 const bool is_deformed = check_sculpt_object_deformed(ob, true);
2858 if (is_deformed && me_eval_deform != nullptr) {
2859 BKE_pbvh_vert_coords_apply(*pbvh, me_eval_deform->vert_positions());
2860 }
2861
2862 return pbvh;
2863}
2864
2865static std::unique_ptr<pbvh::Tree> build_pbvh_from_ccg(Object *ob, SubdivCCG &subdiv_ccg)
2866{
2867 const Mesh &base_mesh = *BKE_mesh_from_object(ob);
2868 BKE_sculpt_sync_face_visibility_to_grids(base_mesh, subdiv_ccg);
2869
2870 return std::make_unique<pbvh::Tree>(pbvh::Tree::from_grids(base_mesh, subdiv_ccg));
2871}
2872
2873} // namespace blender::bke
2874
2875namespace blender::bke::object {
2876
2878{
2879 if (pbvh::Tree *pbvh = pbvh_get(object)) {
2880 return *pbvh;
2881 }
2882 BLI_assert(object.sculpt != nullptr);
2883 SculptSession &ss = *object.sculpt;
2884
2885 if (ss.bm != nullptr) {
2886 /* Sculpting on a BMesh (dynamic-topology) gets a special pbvh::Tree. */
2888 }
2889 else {
2890 Object *object_eval = DEG_get_evaluated(&depsgraph, &object);
2891 Mesh *mesh_eval = static_cast<Mesh *>(object_eval->data);
2892 if (mesh_eval->runtime->subdiv_ccg != nullptr) {
2893 ss.pbvh = build_pbvh_from_ccg(&object, *mesh_eval->runtime->subdiv_ccg);
2894 }
2895 else {
2896 const Mesh *me_eval_deform = BKE_object_get_mesh_deform_eval(object_eval);
2897 ss.pbvh = build_pbvh_from_regular_mesh(&object, me_eval_deform);
2898 }
2899 }
2900
2901 return *object::pbvh_get(object);
2902}
2903
2904const pbvh::Tree *pbvh_get(const Object &object)
2905{
2906 if (!object.sculpt) {
2907 return nullptr;
2908 }
2909 return object.sculpt->pbvh.get();
2910}
2911
2913{
2914 BLI_assert(object.type == OB_MESH);
2915 if (!object.sculpt) {
2916 return nullptr;
2917 }
2918 return object.sculpt->pbvh.get();
2919}
2920
2921} // namespace blender::bke::object
2922
2924{
2925 return object->sculpt && object->sculpt->bm;
2926}
2927
2929{
2930 SculptSession *ss = ob->sculpt;
2931 if (ss == nullptr || ss->mode_type != OB_MODE_SCULPT) {
2932 return false;
2933 }
2935 if (!pbvh) {
2936 return false;
2937 }
2938
2939 if (pbvh->type() == blender::bke::pbvh::Type::Mesh) {
2940 /* Regular mesh only draws from pbvh::Tree without modifiers and shape keys, or for
2941 * external engines that do not have access to the pbvh::Tree like Eevee does. */
2942 const bool external_engine = rv3d && rv3d->view_render != nullptr;
2943 return !(ss->shapekey_active || ss->deform_modifiers_active || external_engine);
2944 }
2945
2946 /* Multires and dyntopo always draw directly from the pbvh::Tree. */
2947 return true;
2948}
2949
2950/* Returns the Face Set random color for rendering in the overlay given its ID and a color seed. */
2951#define GOLDEN_RATIO_CONJUGATE 0.618033988749895f
2952void BKE_paint_face_set_overlay_color_get(const int face_set, const int seed, uchar r_color[4])
2953{
2954 float rgba[4];
2955 float random_mod_hue = GOLDEN_RATIO_CONJUGATE * (face_set + (seed % 10));
2956 random_mod_hue = random_mod_hue - floorf(random_mod_hue);
2957 const float random_mod_sat = BLI_hash_int_01(face_set + seed + 1);
2958 const float random_mod_val = BLI_hash_int_01(face_set + seed + 2);
2959 hsv_to_rgb(random_mod_hue,
2960 0.6f + (random_mod_sat * 0.25f),
2961 1.0f - (random_mod_val * 0.35f),
2962 &rgba[0],
2963 &rgba[1],
2964 &rgba[2]);
2965 rgba_float_to_uchar(r_color, rgba);
2966}
void BKE_asset_weak_reference_read(BlendDataReader *reader, AssetWeakReference *weak_ref)
void BKE_asset_weak_reference_write(BlendWriter *writer, const AssetWeakReference *weak_ref)
void BKE_id_attributes_default_color_set(struct ID *id, std::optional< blender::StringRef > name)
std::string BKE_attribute_calc_unique_name(const AttributeOwner &owner, blender::StringRef name)
Definition attribute.cc:383
bool BKE_color_attribute_supported(const struct Mesh &mesh, blender::StringRef name)
void BKE_id_attributes_active_color_set(struct ID *id, std::optional< blender::StringRef > name)
Definition attribute.cc:986
bool BKE_brush_has_cube_tip(const Brush *brush, PaintMode paint_mode)
Definition brush.cc:1636
int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
Definition BKE_ccg.hh:77
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap)
@ CURVEMAP_SLOPE_POSITIVE
CurveMapping * BKE_curvemapping_copy(const CurveMapping *cumap)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:89
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, int slope)
void BKE_curvemapping_free(CurveMapping *cumap)
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
void BKE_curvemapping_blend_write(BlendWriter *writer, const CurveMapping *cumap)
SpaceImage * CTX_wm_space_image(const bContext *C)
@ CTX_MODE_VERTEX_GPENCIL_LEGACY
@ CTX_MODE_WEIGHT_GPENCIL_LEGACY
@ CTX_MODE_SCULPT_GPENCIL_LEGACY
@ CTX_MODE_PAINT_GREASE_PENCIL
@ CTX_MODE_PAINT_GPENCIL_LEGACY
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_SCULPT_GREASE_PENCIL
@ CTX_MODE_SCULPT
@ CTX_MODE_SCULPT_CURVES
@ CTX_MODE_WEIGHT_GREASE_PENCIL
@ CTX_MODE_VERTEX_GREASE_PENCIL
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_PAINT_WEIGHT
Scene * CTX_data_scene(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_crazyspace_build_sculpt(Depsgraph *depsgraph, Scene *scene, Object *ob, blender::Array< blender::float3x3, 0 > &deformmats, blender::Array< blender::float3, 0 > &deformcos)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
@ CD_SET_DEFAULT
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
support for deformation groups and hooks.
void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert)
Definition deform.cc:1045
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition BKE_idtype.hh:46
IDTypeInfo IDType_ID_PAL
Definition paint.cc:141
IDTypeInfo IDType_ID_PC
Definition paint.cc:210
void BKE_image_pool_free(ImagePool *pool)
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1922
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void id_us_plus(ID *id)
Definition lib_id.cc:353
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void id_fake_user_set(ID *id)
Definition lib_id.cc:391
void BKE_lib_id_swap(Main *bmain, ID *id_a, ID *id_b, const bool do_self_remap, const int self_remap_flags)
Definition lib_id.cc:1046
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1495
void id_us_min(ID *id)
Definition lib_id.cc:361
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2611
General operations, lookup, etc. for materials.
void BKE_texpaint_slots_refresh_object(Scene *scene, Object *ob)
void BKE_mesh_tessface_clear(Mesh *mesh)
Mesh * BKE_mesh_from_object(Object *ob)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
General operations, lookup, etc. for blender objects.
const Mesh * BKE_object_get_mesh_deform_eval(const Object *object)
Mesh * BKE_object_get_evaluated_mesh_unchecked(const Object *object)
Mesh * BKE_object_get_original_mesh(const Object *object)
void BKE_object_free_derived_caches(Object *ob)
const uchar PAINT_CURSOR_SCULPT_GREASE_PENCIL[3]
Definition paint.cc:246
std::variant< std::monostate, int, BMVert * > ActiveVert
Definition BKE_paint.hh:380
void BKE_sculpt_sync_face_visibility_to_grids(const Mesh &mesh, SubdivCCG &subdiv_ccg)
Definition paint.cc:2813
PaintMode
Definition BKE_paint.hh:93
const uchar PAINT_CURSOR_PAINT_GREASE_PENCIL[3]
Definition paint.cc:245
const uchar PAINT_CURSOR_WEIGHT_PAINT[3]
Definition paint.cc:242
void BKE_sculptsession_free_vwpaint_data(SculptSession *ss)
Definition paint.cc:2104
ePaintOverlayControlFlags
Definition BKE_paint.hh:115
@ PAINT_OVERLAY_INVALID_CURVE
Definition BKE_paint.hh:118
@ PAINT_OVERLAY_INVALID_TEXTURE_SECONDARY
Definition BKE_paint.hh:117
@ PAINT_OVERLAY_OVERRIDE_CURSOR
Definition BKE_paint.hh:119
@ PAINT_OVERLAY_INVALID_TEXTURE_PRIMARY
Definition BKE_paint.hh:116
@ PAINT_OVERLAY_OVERRIDE_SECONDARY
Definition BKE_paint.hh:121
@ PAINT_OVERLAY_OVERRIDE_PRIMARY
Definition BKE_paint.hh:120
CurveMapping * BKE_sculpt_default_cavity_curve()
Definition scene.cc:125
#define PAINT_OVERRIDE_MASK
Definition BKE_paint.hh:125
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
Definition paint.cc:2373
const uchar PAINT_CURSOR_SCULPT[3]
Definition paint.cc:240
const uchar PAINT_CURSOR_TEXTURE_PAINT[3]
Definition paint.cc:243
const uchar PAINT_CURSOR_SCULPT_CURVES[3]
Definition paint.cc:244
const uchar PAINT_CURSOR_VERTEX_PAINT[3]
Definition paint.cc:241
char * BKE_paint_canvas_key_get(PaintModeSettings *settings, Object *ob)
A BVH for high poly meshes.
void BKE_pbvh_mark_rebuild_pixels(blender::bke::pbvh::Tree &pbvh)
Definition pbvh.cc:1514
void BKE_pbvh_node_mark_update(blender::bke::pbvh::Node &node)
Definition pbvh.cc:1509
void BKE_pbvh_vert_coords_apply(blender::bke::pbvh::Tree &pbvh, blender::Span< blender::float3 > vert_positions)
Definition pbvh.cc:2348
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2623
blender::BitGroupVector & BKE_subdiv_ccg_grid_hidden_ensure(SubdivCCG &subdiv_ccg)
void BKE_subdiv_ccg_grid_hidden_free(SubdivCCG &subdiv_ccg)
int BKE_ccg_gridsize(int level)
Definition CCGSubSurf.cc:24
int BKE_ccg_factor(int low_level, int high_level)
Definition CCGSubSurf.cc:29
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.h:299
#define GHASH_ITER(gh_iter_, ghash_)
Definition BLI_ghash.h:318
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:702
BLI_INLINE float BLI_hash_int_01(unsigned int k)
Definition BLI_hash.h:92
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
int BLI_listbase_count_at_most(const ListBase *listbase, int count_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:511
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:57
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
void cpack_to_rgb(unsigned int col, float *r_r, float *r_g, float *r_b)
#define M_PI
MINLINE float len_squared_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3_uchar(unsigned char r[3], const unsigned char a[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
unsigned char uchar
unsigned int uint
#define POINTER_AS_INT(i)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define STREQ(a, b)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:5351
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
#define BLO_write_struct_array(writer, struct_name, array_size, data_ptr)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct_array(reader, struct_name, array_size, ptr_p)
#define BLO_write_struct_list(writer, struct_name, list_ptr)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define BLT_I18NCONTEXT_ID_PALETTE
#define BLT_I18NCONTEXT_ID_PAINTCURVE
void DEG_id_tag_update(ID *id, unsigned int flags)
T * DEG_get_original(T *id)
Scene * DEG_get_input_scene(const Depsgraph *graph)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ ID_RECALC_GEOMETRY_ALL_MODES
Definition DNA_ID.h:1089
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ INDEX_ID_PC
Definition DNA_ID.h:1254
@ INDEX_ID_PAL
Definition DNA_ID.h:1253
@ ID_BR
eBrushGPVertexType
@ GPVERTEX_BRUSH_TYPE_BLUR
@ GPVERTEX_BRUSH_TYPE_DRAW
@ GPVERTEX_BRUSH_TYPE_TINT
@ GPVERTEX_BRUSH_TYPE_REPLACE
@ GPVERTEX_BRUSH_TYPE_AVERAGE
@ GPVERTEX_BRUSH_TYPE_SMEAR
eBrushGPaintType
@ GPAINT_BRUSH_TYPE_TINT
@ GPAINT_BRUSH_TYPE_FILL
@ GPAINT_BRUSH_TYPE_DRAW
@ GPAINT_BRUSH_TYPE_ERASE
eBrushWeightPaintType
@ WPAINT_BRUSH_TYPE_BLUR
@ WPAINT_BRUSH_TYPE_AVERAGE
@ WPAINT_BRUSH_TYPE_DRAW
@ WPAINT_BRUSH_TYPE_SMEAR
eBrushSculptType
@ SCULPT_BRUSH_TYPE_DISPLACEMENT_SMEAR
@ SCULPT_BRUSH_TYPE_MASK
@ SCULPT_BRUSH_TYPE_DRAW_FACE_SETS
@ SCULPT_BRUSH_TYPE_SIMPLIFY
@ SCULPT_BRUSH_TYPE_PAINT
@ SCULPT_BRUSH_TYPE_DISPLACEMENT_ERASER
@ SCULPT_BRUSH_TYPE_CLAY_STRIPS
eBrushImagePaintType
@ IMAGE_PAINT_BRUSH_TYPE_MASK
@ IMAGE_PAINT_BRUSH_TYPE_FILL
@ IMAGE_PAINT_BRUSH_TYPE_DRAW
@ IMAGE_PAINT_BRUSH_TYPE_CLONE
@ IMAGE_PAINT_BRUSH_TYPE_SOFTEN
@ IMAGE_PAINT_BRUSH_TYPE_SMEAR
@ BRUSH_COLOR_JITTER_USE_VAL_AT_STROKE
@ BRUSH_COLOR_JITTER_USE_HUE_AT_STROKE
@ BRUSH_COLOR_JITTER_USE_SAT_AT_STROKE
@ BRUSH_COLOR_JITTER_USE_SAT_RAND_PRESS
@ BRUSH_COLOR_JITTER_USE_VAL_RAND_PRESS
@ BRUSH_COLOR_JITTER_USE_HUE_RAND_PRESS
eBrushVertexPaintType
@ VPAINT_BRUSH_TYPE_AVERAGE
@ VPAINT_BRUSH_TYPE_DRAW
@ VPAINT_BRUSH_TYPE_SMEAR
@ VPAINT_BRUSH_TYPE_BLUR
eOverlayFlags
@ BRUSH_OVERLAY_SECONDARY_OVERRIDE_ON_STROKE
@ BRUSH_OVERLAY_PRIMARY_OVERRIDE_ON_STROKE
@ BRUSH_OVERLAY_CURSOR_OVERRIDE_ON_STROKE
#define BRUSH_OVERLAY_OVERRIDE_MASK
eBrushGPWeightType
@ GPWEIGHT_BRUSH_TYPE_AVERAGE
@ GPWEIGHT_BRUSH_TYPE_DRAW
@ GPWEIGHT_BRUSH_TYPE_SMEAR
@ GPWEIGHT_BRUSH_TYPE_BLUR
eBrushGPSculptType
@ GPSCULPT_BRUSH_TYPE_CLONE
eBrushCurvesSculptType
@ CURVES_SCULPT_BRUSH_TYPE_ADD
@ CURVES_SCULPT_BRUSH_TYPE_DENSITY
@ CURVES_SCULPT_BRUSH_TYPE_DELETE
@ CURVES_SCULPT_BRUSH_TYPE_SELECTION_PAINT
@ CUMA_EXTEND_EXTRAPOLATE
@ CURVE_PRESET_LINE
@ CD_PROP_COLOR
@ CD_PROP_INT32
@ CD_GRID_PAINT_MASK
#define DNA_struct_default_get(struct_name)
@ ME_EDIT_PAINT_VERT_SEL
@ ME_EDIT_PAINT_FACE_SEL
@ eMultiresModifierFlag_UseSculptBaseMesh
@ eModifierMode_Realtime
@ eModifierType_ShapeKey
@ eModifierType_Multires
eObjectMode
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_SCULPT
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_SHAPE_LOCK
@ OB_GREASE_PENCIL
@ OB_MESH
@ UNIFIED_PAINT_COLOR
@ SCULPT_ONLY_DEFORM
@ PAINT_SHOW_BRUSH
@ SPACE_IMAGE
@ SPACE_VIEW3D
@ SI_MODE_PAINT
@ MTEX_ANGLE_RAKE
#define USER_EXPERIMENTAL_TEST(userdef, member)
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
#define U
#define BM_FACE_FIRST_LOOP(p)
@ BM_ELEM_HIDDEN
#define BM_elem_index_get(ele)
#define BM_elem_flag_test(ele, hflag)
void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const StringRef name)
BMesh const char void * data
BMesh * bm
void BM_log_free(BMLog *log)
Definition bmesh_log.cc:524
void BM_log_mesh_elems_reorder(BMesh *bm, BMLog *log)
Definition bmesh_log.cc:539
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
ATTR_WARN_UNUSED_RESULT const BMVert * v
BPy_StructRNA * depsgraph
static unsigned long seed
Definition btSoftBody.h:39
int64_t size() const
Definition BLI_array.hh:245
const T * data() const
Definition BLI_array.hh:301
bool is_empty() const
Definition BLI_array.hh:253
static AttributeOwner from_id(ID *id)
Definition attribute.cc:43
void foreach_index(Fn &&fn) const
constexpr int64_t size() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:137
constexpr const T * data() const
Definition BLI_span.hh:215
constexpr bool is_empty() const
constexpr const char * c_str() const
GAttributeReader lookup(const StringRef attribute_id) const
GAttributeReader lookup_or_default(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const void *default_value=nullptr) const
bool add(const StringRef attribute_id, const AttrDomain domain, const eCustomDataType data_type, const AttributeInit &initializer)
static Tree from_bmesh(BMesh &bm)
static Tree from_grids(const Mesh &base_mesh, const SubdivCCG &subdiv_ccg)
Definition pbvh.cc:395
static Tree from_mesh(const Mesh &mesh)
Definition pbvh.cc:233
#define atan2f(x, y)
#define floorf(x)
#define offsetof(t, d)
uint col
#define this
float distance(VecOp< float, D >, VecOp< float, D >) RET
#define MEM_SAFE_FREE(v)
#define ID_IS_LINKED(_id)
#define FILTER_ID_PC
#define FILTER_ID_PAL
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static ulong * next
static char faces[256]
int face_corner_prev(const IndexRange face, const int corner)
Definition BKE_mesh.hh:290
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:299
pbvh::Tree & pbvh_ensure(Depsgraph &depsgraph, Object &object)
Definition paint.cc:2877
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:2912
void update_normals(const Depsgraph &depsgraph, Object &object_orig, Tree &pbvh)
Definition pbvh.cc:1073
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
Definition pbvh.cc:2544
void update_normals_from_eval(Object &object_eval, Tree &pbvh)
Definition pbvh.cc:1080
Span< float3 > vert_positions_eval(const Depsgraph &depsgraph, const Object &object_orig)
Definition pbvh.cc:2416
ID * asset_edit_id_from_weak_reference(Main &global_main, ID_Type id_type, const AssetWeakReference &weak_ref)
static std::unique_ptr< pbvh::Tree > build_pbvh_from_regular_mesh(Object *ob, const Mesh *me_eval_deform)
Definition paint.cc:2851
std::optional< AssetWeakReference > asset_edit_weak_reference_from_id(const ID &id)
static std::unique_ptr< pbvh::Tree > build_pbvh_from_ccg(Object *ob, SubdivCCG &subdiv_ccg)
Definition paint.cc:2865
static std::unique_ptr< pbvh::Tree > build_pbvh_for_dynamic_topology(Object *ob)
Definition paint.cc:2842
bool asset_edit_id_is_editable(const ID &id)
CartesianBasis invert(const CartesianBasis &basis)
T interpolate(const T &a, const T &b, const FactorT &t)
float perlin(float position)
Definition noise.cc:567
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
VecBase< float, 2 > float2
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
static void unique_name(bNode *node)
void BKE_palette_sort_vhs(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1508
Brush * BKE_paint_brush_from_essentials(Main *bmain, const eObjectMode ob_mode, const char *name)
Definition paint.cc:776
void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)
Definition paint.cc:2624
PaletteColor * BKE_palette_color_add(Palette *palette)
Definition paint.cc:1390
bool BKE_paint_eraser_brush_set_default(Main *bmain, Paint *paint)
Definition paint.cc:1203
bool BKE_paint_select_grease_pencil_test(const Object *ob)
Definition paint.cc:1613
void BKE_paint_cavity_curve_preset(Paint *paint, int preset)
Definition paint.cc:1636
void BKE_paint_set_overlay_override(eOverlayFlags flags)
Definition paint.cc:294
Brush * BKE_paint_eraser_brush(Paint *paint)
Definition paint.cc:1156
const EnumPropertyItem * BKE_paint_get_tool_enum_from_paintmode(const PaintMode mode)
Definition paint.cc:400
static bool paint_brush_update_from_asset_reference(Main *bmain, Paint *paint)
Definition paint.cc:606
void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, CurveMapping *curve)
Definition paint.cc:270
float paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y)
Definition paint.cc:2013
bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
Definition paint.cc:1089
void BKE_sculpt_sync_face_visibility_to_grids(const Mesh &mesh, SubdivCCG &subdiv_ccg)
Definition paint.cc:2813
void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex)
Definition paint.cc:250
static void sculptsession_bm_to_me_update_data_only(Object *ob, bool reorder)
Definition paint.cc:2119
void BKE_paint_copy(const Paint *src, Paint *dst, const int flag)
Definition paint.cc:1809
blender::float3 BKE_paint_randomize_color(const BrushColorJitterSettings &color_jitter, const blender::float3 &initial_hsv_jitter, const float distance, const float pressure, const blender::float3 &color)
Definition paint.cc:1853
static bool paint_rake_rotation_active(const MTex &mtex)
Definition paint.cc:2041
static bool sculpt_modifiers_active(const Scene *scene, const Sculpt *sd, Object *ob)
Definition paint.cc:2379
void BKE_sculptsession_bm_to_me(Object *ob, bool reorder)
Definition paint.cc:2135
bool paint_calculate_rake_rotation(UnifiedPaintSettings &ups, const Brush &brush, const float mouse_pos[2], const PaintMode paint_mode, bool stroke_has_started)
Definition paint.cc:2052
static MultiresModifierData * sculpt_multires_modifier_get(const Scene *scene, Object *ob, const bool auto_create_mdisps)
Definition paint.cc:2320
bool BKE_paint_always_hide_test(const Object *ob)
Definition paint.cc:1630
PaintCurve * BKE_paint_curve_add(Main *bmain, const char *name)
Definition paint.cc:1337
std::optional< int > BKE_paint_get_brush_type_from_obmode(const Brush *brush, const eObjectMode ob_mode)
Definition paint.cc:1280
static bool check_sculpt_object_deformed(Object *object, const bool for_construction)
Definition paint.cc:2791
bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name, const bool linear)
Definition paint.cc:1537
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:2928
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Definition paint.cc:1752
static AssetWeakReference * asset_reference_create_from_brush(Brush *brush)
Definition paint.cc:654
static int palettecolor_compare_luminance(const void *a1, const void *a2)
Definition paint.cc:1513
void BKE_sculptsession_free(Object *ob)
Definition paint.cc:2192
bool BKE_paint_use_unified_color(const ToolSettings *tool_settings, const Paint *paint)
Definition paint.cc:592
bool BKE_paint_brush_set(Main *bmain, Paint *paint, const AssetWeakReference *brush_asset_reference)
Definition paint.cc:665
static void paint_brush_default_essentials_name_get(eObjectMode ob_mode, std::optional< int > brush_type, blender::StringRefNull *r_name, blender::StringRefNull *r_eraser_name=nullptr)
Definition paint.cc:810
static void palette_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
Definition paint.cc:95
void BKE_sculptsession_free_deformMats(SculptSession *ss)
Definition paint.cc:2096
bool BKE_paint_select_elem_test(const Object *ob)
Definition paint.cc:1624
Paint * BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
Definition paint.cc:428
ePaintOverlayControlFlags BKE_paint_get_overlay_flags()
Definition paint.cc:289
static bool paint_eraser_brush_set_from_asset_reference(Main *bmain, Paint *paint)
Definition paint.cc:1126
bool BKE_paint_select_vert_test(const Object *ob)
Definition paint.cc:1606
static float paint_rake_rotation_spacing(const UnifiedPaintSettings &, const Brush &brush)
Definition paint.cc:2022
void BKE_palette_color_remove(Palette *palette, PaletteColor *color)
Definition paint.cc:1362
void BKE_sculptsession_free_vwpaint_data(SculptSession *ss)
Definition paint.cc:2104
void BKE_paint_previous_asset_reference_set(Paint *paint, AssetWeakReference &&asset_weak_reference)
Definition paint.cc:1095
bool paint_is_grid_face_hidden(const blender::BoundedBitSpan grid_hidden, const int gridsize, const int x, const int y)
Definition paint.cc:1987
static const char * paint_brush_essentials_asset_file_name_from_obmode(const eObjectMode ob_mode)
Definition paint.cc:718
uint BKE_paint_get_brush_type_offset_from_paintmode(const PaintMode mode)
Definition paint.cc:1252
void BKE_paint_stroke_get_average(const Scene *scene, const Object *ob, float stroke[3])
Definition paint.cc:1841
const Brush * BKE_paint_eraser_brush_for_read(const Paint *paint)
Definition paint.cc:1161
void BKE_sculpt_update_object_before_eval(Object *ob_eval)
Definition paint.cc:2565
void BKE_palette_sort_hsv(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1434
static int palettecolor_compare_svh(const void *a1, const void *a2)
Definition paint.cc:1439
void BKE_paint_reset_overlay_invalid(ePaintOverlayControlFlags flag)
Definition paint.cc:312
void BKE_palette_sort_svh(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1471
static void paint_curve_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
Definition paint.cc:171
static void paint_runtime_init(const ToolSettings *ts, Paint *paint)
Definition paint.cc:1215
void BKE_paint_free(Paint *paint)
Definition paint.cc:1791
void paint_update_brush_rake_rotation(UnifiedPaintSettings &ups, const Brush &brush, float rotation)
Definition paint.cc:2027
static AssetWeakReference * paint_brush_asset_reference_ptr_from_essentials(const char *name, const eObjectMode ob_mode)
Definition paint.cc:744
void BKE_palette_sort_luminance(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1531
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:641
bool BKE_paint_eraser_brush_set(Paint *paint, Brush *brush)
Definition paint.cc:1166
static void palette_free_data(ID *id)
Definition paint.cc:107
static void palette_undo_preserve(BlendLibReader *, ID *id_new, ID *id_old)
Definition paint.cc:130
static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition paint.cc:194
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:365
void BKE_paint_previous_asset_reference_clear(Paint *paint)
Definition paint.cc:1104
eObjectMode BKE_paint_object_mode_from_paintmode(const PaintMode mode)
Definition paint.cc:1653
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
Definition paint.cc:2373
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3], const bool ensure_brushes)
Definition paint.cc:1769
static void paint_curve_free_data(ID *id)
Definition paint.cc:186
Brush * BKE_paint_eraser_brush_from_essentials(Main *bmain, eObjectMode ob_mode, const char *name)
Definition paint.cc:1191
void BKE_sculpt_update_object_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
Definition paint.cc:2657
#define GOLDEN_RATIO_CONJUGATE
Definition paint.cc:2951
void BKE_sculpt_color_layer_create_if_needed(Object *object)
Definition paint.cc:2633
void BKE_palette_clear(Palette *palette)
Definition paint.cc:1378
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:467
bool paint_is_bmesh_face_hidden(const BMFace *f)
Definition paint.cc:1998
void BKE_sculptsession_bm_to_me_for_render(Object *object)
Definition paint.cc:2170
static std::optional< AssetWeakReference > paint_brush_asset_reference_from_essentials(const char *name, const eObjectMode ob_mode)
Definition paint.cc:760
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
Definition paint.cc:1675
static ePaintOverlayControlFlags overlay_flags
Definition paint.cc:248
std::optional< AssetWeakReference > BKE_paint_brush_type_default_reference(eObjectMode ob_mode, std::optional< int > brush_type)
Definition paint.cc:1017
bool BKE_paint_brush_set_default(Main *bmain, Paint *paint)
Definition paint.cc:1083
Palette * BKE_palette_add(Main *bmain, const char *name)
Definition paint.cc:1384
static void sculpt_update_object(Depsgraph *depsgraph, Object *ob, Object *ob_eval, bool is_paint_tool)
Definition paint.cc:2422
static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition paint.cc:114
bool BKE_paint_eraser_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
Definition paint.cc:1209
static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id)
Definition paint.cc:204
void BKE_sculptsession_free_pbvh(Object &object)
Definition paint.cc:2146
static int palettecolor_compare_vhs(const void *a1, const void *a2)
Definition paint.cc:1476
static void palette_init_data(ID *id)
Definition paint.cc:85
static int palettecolor_compare_hsv(const void *a1, const void *a2)
Definition paint.cc:1402
static void paint_eraser_brush_set_essentials_reference(Paint *paint, const char *name)
Definition paint.cc:799
void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint)
Definition paint.cc:1941
static void paint_brush_set_default_reference(Paint *paint, const bool do_regular=true, const bool do_eraser=true)
Definition paint.cc:1030
void BKE_paint_face_set_overlay_color_get(const int face_set, const int seed, uchar r_color[4])
Definition paint.cc:2952
static void paint_brush_set_essentials_reference(Paint *paint, const char *name)
Definition paint.cc:788
std::optional< int > BKE_paint_get_brush_type_from_paintmode(const Brush *brush, const PaintMode mode)
Definition paint.cc:1308
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:636
void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene)
Definition paint.cc:2744
Palette * BKE_paint_palette(Paint *paint)
Definition paint.cc:1343
void BKE_paint_palette_set(Paint *paint, Palette *palette)
Definition paint.cc:1348
void BKE_paint_curve_clamp_endpoint_add_index(PaintCurve *pc, const int add_index)
Definition paint.cc:1357
bool BKE_palette_is_empty(const Palette *palette)
Definition paint.cc:1397
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
Definition paint.cc:496
static void palette_blend_read_data(BlendDataReader *reader, ID *id)
Definition paint.cc:124
void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, Main *bmain, Object *ob, MultiresModifierData *mmd)
Definition paint.cc:2666
bool BKE_paint_brush_poll(const Paint *paint, const Brush *brush)
Definition paint.cc:646
bool BKE_object_sculpt_use_dyntopo(const Object *object)
Definition paint.cc:2923
void BKE_paint_brushes_set_default_references(ToolSettings *ts)
Definition paint.cc:1054
bool BKE_paint_select_face_test(const Object *ob)
Definition paint.cc:1599
PaintMode BKE_paintmode_get_from_tool(const bToolRef *tref)
Definition paint.cc:552
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
Definition paint.cc:1109
void BKE_paint_invalidate_overlay_all()
Definition paint.cc:283
void BKE_paint_blend_write(BlendWriter *writer, Paint *paint)
Definition paint.cc:1909
void BKE_sculpt_cavity_curves_ensure(Sculpt *sd)
Definition paint.cc:2733
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:317
const EnumPropertyItem rna_enum_brush_weight_brush_type_items[]
Definition rna_brush.cc:202
const EnumPropertyItem rna_enum_brush_gpencil_sculpt_types_items[]
Definition rna_brush.cc:265
const EnumPropertyItem rna_enum_brush_image_brush_type_items[]
Definition rna_brush.cc:210
const EnumPropertyItem rna_enum_brush_sculpt_brush_type_items[]
Definition rna_brush.cc:149
const EnumPropertyItem rna_enum_brush_gpencil_vertex_types_items[]
Definition rna_brush.cc:240
const EnumPropertyItem rna_enum_brush_gpencil_weight_types_items[]
Definition rna_brush.cc:301
const EnumPropertyItem rna_enum_brush_vertex_brush_type_items[]
Definition rna_brush.cc:194
const EnumPropertyItem rna_enum_brush_gpencil_types_items[]
Definition rna_brush.cc:220
const EnumPropertyItem rna_enum_brush_curves_sculpt_brush_type_items[]
Definition rna_brush.cc:313
const char * relative_asset_identifier
const char * asset_library_identifier
struct BMVert * v
struct BMLoop * next
float co[3]
CurveMapping * curve_sat_jitter
Definition BKE_brush.hh:178
CurveMapping * curve_val_jitter
Definition BKE_brush.hh:179
CurveMapping * curve_hue_jitter
Definition BKE_brush.hh:177
char sculpt_brush_type
struct MTex mtex
char gpencil_sculpt_brush_type
short ob_mode
char image_brush_type
struct CurveMapping * curve
char gpencil_weight_brush_type
char gpencil_vertex_brush_type
char curves_sculpt_brush_type
struct MTex mask_mtex
char gpencil_brush_type
char weight_brush_type
char vertex_brush_type
CurveMap cm[4]
Definition DNA_ID.h:404
IDProperty * system_properties
Definition DNA_ID.h:454
IDProperty * properties
Definition DNA_ID.h:446
void * data
char brush_angle_mode
struct Tex * tex
bool is_locked_for_linking
Definition BKE_main.hh:196
int corners_num
MeshRuntimeHandle * runtime
CustomData corner_data
struct Key * key
int faces_num
int verts_num
char * active_color_attribute
struct ModifierData * next
ModifierTypeType type
struct SculptSession * sculpt
PaintCurvePoint * points
unsigned int initialized
unsigned short ob_mode
struct AssetWeakReference * previous_active_brush_reference
struct Paint_Runtime runtime
float tile_offset[3]
struct Brush * eraser_brush
void * paint_cursor
unsigned char paint_cursor_col[4]
struct CurveMapping * cavity_curve
struct AssetWeakReference * eraser_brush_asset_reference
struct Palette * palette
struct AssetWeakReference * brush_asset_reference
struct Brush * brush
ToolSystemBrushBindings tool_brush_bindings
ListBase colors
struct ViewRender * view_render
struct ToolSettings * toolsettings
blender::Array< int > fake_neighbor_index
Definition BKE_paint.hh:369
blender::ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:437
BMLog * bm_log
Definition BKE_paint.hh:412
struct SculptSession::@334041245165342176141020054324004000173214370340 persistent
std::optional< int > active_grid_index
Definition BKE_paint.hh:443
blender::ed::sculpt_paint::filter::Cache * filter_cache
Definition BKE_paint.hh:438
std::optional< int > active_face_index
Definition BKE_paint.hh:442
KeyBlock * shapekey_active
Definition BKE_paint.hh:397
blender::Array< int > vert_to_edge_indices
Definition BKE_paint.hh:406
SculptVertexInfo vertex_info
Definition BKE_paint.hh:482
blender::SharedCache< blender::Vector< blender::float3 > > face_normals_deform
Definition BKE_paint.hh:432
blender::GroupedSpan< int > vert_to_edge_map
Definition BKE_paint.hh:407
SubdivCCG * subdiv_ccg
Definition BKE_paint.hh:415
blender::Array< MDeformVert > dvert_prev
Definition BKE_paint.hh:505
blender::Array< int > preview_verts
Definition BKE_paint.hh:460
ActiveVert active_vert() const
Definition paint.cc:2227
blender::Array< int > edge_to_face_offsets
Definition BKE_paint.hh:400
struct SculptSession::@160233021176123211313176342066311124252220006052 multires
blender::Array< blender::float3, 0 > deform_cos
Definition BKE_paint.hh:423
blender::float3 active_vert_position(const Depsgraph &depsgraph, const Object &object) const
Definition paint.cc:2263
int last_active_vert_index() const
Definition paint.cc:2250
struct SculptSession::@277147341176372332050050347244236340077143206264 mode
float * alpha_weight
Definition BKE_paint.hh:501
ImagePool * tex_pool
Definition BKE_paint.hh:435
std::unique_ptr< blender::bke::pbvh::Tree > pbvh
Definition BKE_paint.hh:418
std::unique_ptr< SculptTopologyIslandCache > topology_island_cache
Definition BKE_paint.hh:537
char * last_paint_canvas_key
Definition BKE_paint.hh:534
blender::Array< int > vert_to_edge_offsets
Definition BKE_paint.hh:405
blender::GroupedSpan< int > edge_to_face_map
Definition BKE_paint.hh:402
blender::SharedCache< blender::Vector< blender::float3 > > vert_normals_deform
Definition BKE_paint.hh:431
blender::ed::sculpt_paint::expand::Cache * expand_cache
Definition BKE_paint.hh:439
int active_vert_index() const
Definition paint.cc:2237
eObjectMode mode_type
Definition BKE_paint.hh:511
ActiveVert last_active_vert() const
Definition paint.cc:2232
std::optional< PersistentMultiresData > persistent_multires_data()
Definition paint.cc:2302
blender::Array< int > edge_to_face_indices
Definition BKE_paint.hh:401
struct SculptSession::@277147341176372332050050347244236340077143206264::@267002172247257132177045334232116313020165177372 wpaint
blender::Array< blender::float3x3, 0 > deform_imats
Definition BKE_paint.hh:425
MultiresModifierData * modifier
Definition BKE_paint.hh:393
SculptFakeNeighbors fake_neighbors
Definition BKE_paint.hh:483
bool building_vp_handle
Definition BKE_paint.hh:515
bool deform_modifiers_active
Definition BKE_paint.hh:421
void set_active_vert(ActiveVert vert)
Definition paint.cc:2297
void clear_active_elements(bool persist_last_active)
Definition paint.cc:2282
blender::BitVector boundary
Definition BKE_paint.hh:354
float automasking_start_normal_falloff
float detail_percent
float automasking_view_normal_limit
float detail_size
struct CurveMapping * automasking_cavity_curve_op
float automasking_start_normal_limit
struct CurveMapping * automasking_cavity_curve
float constant_detail
float automasking_view_normal_falloff
GpWeightPaint * gp_weightpaint
struct ImagePaintSettings imapaint
GpSculptPaint * gp_sculptpaint
struct PaintModeSettings paint_mode
struct UnifiedPaintSettings unified_paint_settings
CurvesSculpt * curves_sculpt
GpVertexPaint * gp_vertexpaint
struct AssetWeakReference * main_brush_asset_reference
i
Definition text_draw.cc:230
#define N_(msgid)
uint8_t flag
Definition wm_window.cc:139