Blender V5.0
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/* ALlow using deprecated color for sync legacy. */
10#define DNA_DEPRECATED_ALLOW
11
12#include <cstdlib>
13#include <cstring>
14#include <optional>
15
16#include "MEM_guardedalloc.h"
17
18#include "DNA_asset_types.h"
19#include "DNA_brush_types.h"
20#include "DNA_defaults.h"
21#include "DNA_key_types.h"
22#include "DNA_mesh_types.h"
23#include "DNA_meshdata_types.h"
24#include "DNA_modifier_types.h"
25#include "DNA_object_enums.h"
26#include "DNA_object_types.h"
27#include "DNA_scene_types.h"
28#include "DNA_space_types.h"
29#include "DNA_userdef_types.h"
30#include "DNA_view3d_types.h"
31#include "DNA_workspace_types.h"
32
33#include "BLI_hash.h"
34#include "BLI_listbase.h"
35#include "BLI_math_color.h"
36#include "BLI_math_matrix.hh"
37#include "BLI_math_vector.h"
38#include "BLI_noise.hh"
39#include "BLI_string.h"
40#include "BLI_utildefines.h"
41#include "BLI_vector.hh"
42
43#include "BLT_translation.hh"
44
45#include "BKE_asset.hh"
46#include "BKE_asset_edit.hh"
47#include "BKE_attribute.hh"
48#include "BKE_brush.hh"
49#include "BKE_ccg.hh"
50#include "BKE_colortools.hh"
51#include "BKE_context.hh"
52#include "BKE_crazyspace.hh"
53#include "BKE_deform.hh"
54#include "BKE_idtype.hh"
55#include "BKE_image.hh"
56#include "BKE_key.hh"
57#include "BKE_layer.hh"
58#include "BKE_lib_id.hh"
59#include "BKE_main.hh"
60#include "BKE_material.hh"
61#include "BKE_mesh.hh"
62#include "BKE_mesh_runtime.hh"
63#include "BKE_modifier.hh"
64#include "BKE_multires.hh"
65#include "BKE_object.hh"
66#include "BKE_paint.hh"
67#include "BKE_paint_bvh.hh"
68#include "BKE_paint_types.hh"
69#include "BKE_scene.hh"
70#include "BKE_subdiv_ccg.hh"
71
72#include "DEG_depsgraph.hh"
74
75#include "RNA_enum_types.hh"
76
77#include "BLO_read_write.hh"
78
80
81#include "bmesh.hh"
82
83using blender::float3;
85using blender::Span;
86using blender::Vector;
88
89static void palette_init_data(ID *id)
90{
91 Palette *palette = (Palette *)id;
92
94
95 /* Enable fake user by default. */
96 id_fake_user_set(&palette->id);
97}
98
99static void palette_copy_data(Main * /*bmain*/,
100 std::optional<Library *> /*owner_library*/,
101 ID *id_dst,
102 const ID *id_src,
103 const int /*flag*/)
104{
105 Palette *palette_dst = (Palette *)id_dst;
106 const Palette *palette_src = (const Palette *)id_src;
107
108 BLI_duplicatelist(&palette_dst->colors, &palette_src->colors);
109}
110
111static void palette_free_data(ID *id)
112{
113 Palette *palette = (Palette *)id;
114
115 BLI_freelistN(&palette->colors);
116}
117
120{
121 Palette *palette = (Palette *)id;
122
123 LISTBASE_FOREACH (PaletteColor *, color, &palette->colors) {
124 fn.single(color->color);
126 }
127}
128
129static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
130{
131 Palette *palette = (Palette *)id;
132
133 BLO_write_id_struct(writer, Palette, id_address, &palette->id);
134 BKE_id_blend_write(writer, &palette->id);
135
136 BLO_write_struct_list(writer, PaletteColor, &palette->colors);
137}
138
140{
141 Palette *palette = (Palette *)id;
142 BLO_read_struct_list(reader, PaletteColor, &palette->colors);
143}
144
145static void palette_undo_preserve(BlendLibReader * /*reader*/, ID *id_new, ID *id_old)
146{
147 /* Whole Palette is preserved across undo-steps, and it has no extra pointer, simple. */
148 /* NOTE: We do not care about potential internal references to self here, Palette has none. */
149 /* NOTE: We do not swap IDProperties, as dealing with potential ID pointers in those would be
150 * fairly delicate. */
151 BKE_lib_id_swap(nullptr, id_new, id_old, false, 0);
152 std::swap(id_new->properties, id_old->properties);
153 std::swap(id_new->system_properties, id_old->system_properties);
154}
155
157 /*id_code*/ Palette::id_type,
158 /*id_filter*/ FILTER_ID_PAL,
159 /*dependencies_id_types*/ 0,
160 /*main_listbase_index*/ INDEX_ID_PAL,
161 /*struct_size*/ sizeof(Palette),
162 /*name*/ "Palette",
163 /*name_plural*/ N_("palettes"),
164 /*translation_context*/ BLT_I18NCONTEXT_ID_PALETTE,
165 /*flags*/ IDTYPE_FLAGS_NO_ANIMDATA,
166 /*asset_type_info*/ nullptr,
167
168 /*init_data*/ palette_init_data,
169 /*copy_data*/ palette_copy_data,
170 /*free_data*/ palette_free_data,
171 /*make_local*/ nullptr,
172 /*foreach_id*/ nullptr,
173 /*foreach_cache*/ nullptr,
174 /*foreach_path*/ nullptr,
175 /*foreach_working_space_color*/ palette_foreach_working_space_color,
176 /*owner_pointer_get*/ nullptr,
177
178 /*blend_write*/ palette_blend_write,
179 /*blend_read_data*/ palette_blend_read_data,
180 /*blend_read_after_liblink*/ nullptr,
181
182 /*blend_read_undo_preserve*/ palette_undo_preserve,
183
184 /*lib_override_apply_post*/ nullptr,
185};
186
187static void paint_curve_copy_data(Main * /*bmain*/,
188 std::optional<Library *> /*owner_library*/,
189 ID *id_dst,
190 const ID *id_src,
191 const int /*flag*/)
192{
193 PaintCurve *paint_curve_dst = (PaintCurve *)id_dst;
194 const PaintCurve *paint_curve_src = (const PaintCurve *)id_src;
195
196 if (paint_curve_src->tot_points != 0) {
197 paint_curve_dst->points = static_cast<PaintCurvePoint *>(
198 MEM_dupallocN(paint_curve_src->points));
199 }
200}
201
202static void paint_curve_free_data(ID *id)
203{
204 PaintCurve *paint_curve = (PaintCurve *)id;
205
206 MEM_SAFE_FREE(paint_curve->points);
207 paint_curve->tot_points = 0;
208}
209
210static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
211{
212 PaintCurve *pc = (PaintCurve *)id;
213
214 BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
215 BKE_id_blend_write(writer, &pc->id);
216
218}
219
221{
222 PaintCurve *pc = (PaintCurve *)id;
224}
225
227 /*id_code*/ PaintCurve::id_type,
228 /*id_filter*/ FILTER_ID_PC,
229 /*dependencies_id_types*/ 0,
230 /*main_listbase_index*/ INDEX_ID_PC,
231 /*struct_size*/ sizeof(PaintCurve),
232 /*name*/ "PaintCurve",
233 /*name_plural*/ N_("paint_curves"),
234 /*translation_context*/ BLT_I18NCONTEXT_ID_PAINTCURVE,
235 /*flags*/ IDTYPE_FLAGS_NO_ANIMDATA,
236 /*asset_type_info*/ nullptr,
237
238 /*init_data*/ nullptr,
239 /*copy_data*/ paint_curve_copy_data,
240 /*free_data*/ paint_curve_free_data,
241 /*make_local*/ nullptr,
242 /*foreach_id*/ nullptr,
243 /*foreach_cache*/ nullptr,
244 /*foreach_path*/ nullptr,
245 /*foreach_working_space_color*/ nullptr,
246 /*owner_pointer_get*/ nullptr,
247
248 /*blend_write*/ paint_curve_blend_write,
249 /*blend_read_data*/ paint_curve_blend_read_data,
250 /*blend_read_after_liblink*/ nullptr,
251
252 /*blend_read_undo_preserve*/ nullptr,
253
254 /*lib_override_apply_post*/ nullptr,
255};
256
258
259void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex)
260{
261 Paint *paint = BKE_paint_get_active(scene, view_layer);
262 if (!paint) {
263 return;
264 }
265
266 Brush *br = BKE_paint_brush(paint);
267 if (!br) {
268 return;
269 }
270
271 if (br->mtex.tex == tex) {
273 }
274 if (br->mask_mtex.tex == tex) {
276 }
277}
278
280{
281 Paint *paint = BKE_paint_get_active(scene, view_layer);
282 if (paint == nullptr) {
283 return;
284 }
285
286 Brush *br = BKE_paint_brush(paint);
287 if (br && br->curve_distance_falloff == curve) {
289 }
290}
291
297
302
320
325
327{
328 ToolSettings *ts = sce->toolsettings;
329 Paint **paint_ptr = nullptr;
330 /* Some paint modes don't store paint settings as pointer, for these this can be set and
331 * referenced by paint_ptr. */
332 Paint *paint_tmp = nullptr;
333
334 switch (mode) {
336 paint_ptr = (Paint **)&ts->sculpt;
337 break;
339 paint_ptr = (Paint **)&ts->vpaint;
340 break;
342 paint_ptr = (Paint **)&ts->wpaint;
343 break;
346 paint_tmp = (Paint *)&ts->imapaint;
347 paint_ptr = &paint_tmp;
348 break;
350 paint_ptr = (Paint **)&ts->gp_paint;
351 break;
353 paint_ptr = (Paint **)&ts->gp_vertexpaint;
354 break;
356 paint_ptr = (Paint **)&ts->gp_sculptpaint;
357 break;
359 paint_ptr = (Paint **)&ts->gp_weightpaint;
360 break;
362 paint_ptr = (Paint **)&ts->curves_sculpt;
363 break;
365 break;
366 }
367 if (paint_ptr) {
368 BKE_paint_ensure(ts, paint_ptr);
369 return true;
370 }
371 return false;
372}
373
375{
376 if (sce) {
377 ToolSettings *ts = sce->toolsettings;
378
379 switch (mode) {
381 return &ts->sculpt->paint;
383 return &ts->vpaint->paint;
385 return &ts->wpaint->paint;
388 return &ts->imapaint.paint;
390 return &ts->gp_paint->paint;
392 return &ts->gp_vertexpaint->paint;
394 return &ts->gp_sculptpaint->paint;
396 return &ts->gp_weightpaint->paint;
398 return &ts->curves_sculpt->paint;
400 return nullptr;
401 default:
402 return &ts->imapaint.paint;
403 }
404 }
405
406 return nullptr;
407}
408
436
438{
439 if (sce && view_layer) {
440 ToolSettings *ts = sce->toolsettings;
441 BKE_view_layer_synced_ensure(sce, view_layer);
442 Object *actob = BKE_view_layer_active_object_get(view_layer);
443
444 if (actob) {
445 switch (actob->mode) {
446 case OB_MODE_SCULPT:
447 return &ts->sculpt->paint;
449 return &ts->vpaint->paint;
451 return &ts->wpaint->paint;
453 return &ts->imapaint.paint;
455 return &ts->gp_paint->paint;
457 return &ts->gp_vertexpaint->paint;
459 return &ts->gp_sculptpaint->paint;
461 return &ts->gp_weightpaint->paint;
463 return &ts->curves_sculpt->paint;
464 default:
465 break;
466 }
467 }
468
469 /* default to image paint */
470 return &ts->imapaint.paint;
471 }
472
473 return nullptr;
474}
475
477{
478 Scene *sce = CTX_data_scene(C);
479 ViewLayer *view_layer = CTX_data_view_layer(C);
480
481 if (sce && view_layer) {
482 ToolSettings *ts = sce->toolsettings;
483 BKE_view_layer_synced_ensure(sce, view_layer);
484 Object *obact = BKE_view_layer_active_object_get(view_layer);
485
487 if (sima != nullptr) {
488 if (obact && obact->mode == OB_MODE_EDIT) {
489 if (sima->mode == SI_MODE_PAINT) {
490 return &ts->imapaint.paint;
491 }
492 }
493 else {
494 return &ts->imapaint.paint;
495 }
496 }
497 else {
498 return BKE_paint_get_active(sce, view_layer);
499 }
500 }
501
502 return nullptr;
503}
504
506{
507 Scene *sce = CTX_data_scene(C);
508 ViewLayer *view_layer = CTX_data_view_layer(C);
509
510 if (sce && view_layer) {
511 BKE_view_layer_synced_ensure(sce, view_layer);
512 Object *obact = BKE_view_layer_active_object_get(view_layer);
513
515 if (sima != nullptr) {
516 if (obact && obact->mode == OB_MODE_EDIT) {
517 if (sima->mode == SI_MODE_PAINT) {
519 }
520 }
521 else {
523 }
524 }
525 else if (obact) {
526 switch (obact->mode) {
527 case OB_MODE_SCULPT:
528 return PaintMode::Sculpt;
530 if (obact->type == OB_GREASE_PENCIL) {
532 }
533 return PaintMode::Invalid;
535 return PaintMode::GPencil;
541 return PaintMode::Vertex;
543 return PaintMode::Weight;
548 default:
550 }
551 }
552 else {
553 /* default to image paint */
555 }
556 }
557
558 return PaintMode::Invalid;
559}
560
600
602{
603 /* Grease pencil draw mode never uses unified paint. */
604 if (paint->runtime->ob_mode == OB_MODE_PAINT_GREASE_PENCIL) {
605 return false;
606 }
607
609}
610
616{
617 /* Don't resolve this during file read, it will be done after. */
618 if (bmain->is_locked_for_linking) {
619 return false;
620 }
621 /* Attempt to restore a valid active brush from brush asset information. */
622 if (paint->brush != nullptr) {
623 return false;
624 }
625 if (paint->brush_asset_reference == nullptr) {
626 return false;
627 }
628
630 *bmain, ID_BR, *paint->brush_asset_reference));
631 BLI_assert(brush == nullptr || blender::bke::asset_edit_id_is_editable(brush->id));
632
633 /* Ensure we have a brush with appropriate mode to assign.
634 * Could happen if contents of asset blend was manually changed. */
635 if (brush == nullptr || (paint->runtime->ob_mode & brush->ob_mode) == 0) {
636 MEM_delete(paint->brush_asset_reference);
637 paint->brush_asset_reference = nullptr;
638 return false;
639 }
640
641 paint->brush = brush;
642 return true;
643}
644
646{
647 return paint ? paint->brush : nullptr;
648}
649
651{
652 return paint ? paint->brush : nullptr;
653}
654
655bool BKE_paint_can_use_brush(const Paint *paint, const Brush *brush)
656{
657 if (paint == nullptr) {
658 return false;
659 }
660 return !brush || (paint->runtime->ob_mode & brush->ob_mode) != 0;
661}
662
664{
665 if (std::optional<AssetWeakReference> weak_ref = blender::bke::asset_edit_weak_reference_from_id(
666 brush->id))
667 {
668 return MEM_new<AssetWeakReference>(__func__, *weak_ref);
669 }
670
671 return nullptr;
672}
673
675 Paint *paint,
676 const AssetWeakReference &brush_asset_reference)
677{
678 /* Don't resolve this during file read, it will be done after. */
679 if (bmain->is_locked_for_linking) {
680 return false;
681 }
682
683 Brush *brush = reinterpret_cast<Brush *>(
684 blender::bke::asset_edit_id_from_weak_reference(*bmain, ID_BR, brush_asset_reference));
685 BLI_assert(brush == nullptr || !ID_IS_LINKED(brush) ||
687
688 /* Ensure we have a brush with appropriate mode to assign.
689 * Could happen if contents of asset blend were manually changed. */
690 if (brush == nullptr || !BKE_paint_can_use_brush(paint, brush)) {
691 return false;
692 }
693
694 /* Update the brush itself. */
695 paint->brush = brush;
696 /* Update the brush asset reference. */
697 {
698 MEM_delete(paint->brush_asset_reference);
699 paint->brush_asset_reference = nullptr;
700 if (brush != nullptr) {
702 brush_asset_reference);
703 paint->brush_asset_reference = MEM_new<AssetWeakReference>(__func__, brush_asset_reference);
704 }
705 }
706
707 return true;
708}
709
710bool BKE_paint_brush_set(Paint *paint, Brush *brush)
711{
712 if (!BKE_paint_can_use_brush(paint, brush)) {
713 return false;
714 }
715
716 paint->brush = brush;
717
718 MEM_delete(paint->brush_asset_reference);
719 paint->brush_asset_reference = nullptr;
720 if (brush != nullptr) {
722 }
723
725
726 return true;
727}
728
730 const PaintMode paint_mode)
731{
732 switch (paint_mode) {
734 return "essentials_brushes-mesh_sculpt.blend";
736 return "essentials_brushes-mesh_vertex.blend";
738 return "essentials_brushes-mesh_weight.blend";
741 return "essentials_brushes-mesh_texture.blend";
743 return "essentials_brushes-gp_draw.blend";
745 return "essentials_brushes-gp_sculpt.blend";
747 return "essentials_brushes-gp_weight.blend";
749 return "essentials_brushes-gp_vertex.blend";
751 return "essentials_brushes-curve_sculpt.blend";
752 default:
753 return nullptr;
754 }
755}
756
758 const char *name, const PaintMode paint_mode)
759{
760 const char *essentials_file_name = paint_brush_essentials_asset_file_name_from_paint_mode(
761 paint_mode);
762 if (!essentials_file_name) {
763 return nullptr;
764 }
765
766 AssetWeakReference *weak_ref = MEM_new<AssetWeakReference>(__func__);
767 weak_ref->asset_library_type = eAssetLibraryType::ASSET_LIBRARY_ESSENTIALS;
768 weak_ref->asset_library_identifier = nullptr;
770 "brushes/%s/Brush/%s", essentials_file_name, name);
771 return weak_ref;
772}
773
774static std::optional<AssetWeakReference> paint_brush_asset_reference_from_essentials(
775 const char *name, const PaintMode paint_mode)
776{
777 const char *essentials_file_name = paint_brush_essentials_asset_file_name_from_paint_mode(
778 paint_mode);
779 if (!essentials_file_name) {
780 return {};
781 }
782
783 AssetWeakReference weak_ref;
784 weak_ref.asset_library_type = eAssetLibraryType::ASSET_LIBRARY_ESSENTIALS;
785 weak_ref.asset_library_identifier = nullptr;
787 "brushes/%s/Brush/%s", essentials_file_name, name);
788 return weak_ref;
789}
790
791Brush *BKE_paint_brush_from_essentials(Main *bmain, const PaintMode paint_mode, const char *name)
792{
793 std::optional<AssetWeakReference> weak_ref = paint_brush_asset_reference_from_essentials(
794 name, paint_mode);
795 if (!weak_ref) {
796 return nullptr;
797 }
798
799 return reinterpret_cast<Brush *>(
801}
802
803static void paint_brush_set_essentials_reference(Paint *paint, const char *name)
804{
805 /* Set brush asset reference to a named brush in the essentials asset library. */
806 MEM_delete(paint->brush_asset_reference);
807
808 BLI_assert(paint->runtime->initialized);
810 name, paint->runtime->paint_mode);
811 paint->brush = nullptr;
812}
813
815{
816 /* Set brush asset reference to a named brush in the essentials asset library. */
817 MEM_delete(paint->eraser_brush_asset_reference);
818
819 BLI_assert(paint->runtime->initialized);
821 name, paint->runtime->paint_mode);
822 paint->eraser_brush = nullptr;
823}
824
826 const PaintMode paint_mode,
827 std::optional<int> brush_type,
829 blender::StringRefNull *r_eraser_name = nullptr)
830{
831 const char *name = "";
832 const char *eraser_name = "";
833
834 switch (paint_mode) {
836 name = "Draw";
837 if (brush_type) {
838 switch (eBrushSculptType(*brush_type)) {
840 name = "Mask";
841 break;
843 name = "Face Set Paint";
844 break;
846 name = "Paint Hard";
847 break;
849 name = "Density";
850 break;
852 name = "Erase Multires Displacement";
853 break;
855 name = "Smear Multires Displacement";
856 break;
857 default:
858 break;
859 }
860 }
861 break;
863 name = "Paint Hard";
864 if (brush_type) {
865 switch (eBrushVertexPaintType(*brush_type)) {
867 name = "Blur";
868 break;
870 name = "Average";
871 break;
873 name = "Smear";
874 break;
876 /* Use default, don't override. */
877 break;
878 }
879 }
880 break;
882 name = "Paint";
883 if (brush_type) {
884 switch (eBrushWeightPaintType(*brush_type)) {
886 name = "Blur";
887 break;
889 name = "Average";
890 break;
892 name = "Smear";
893 break;
895 /* Use default, don't override. */
896 break;
897 }
898 }
899 break;
902 name = "Paint Hard";
903 if (brush_type) {
904 switch (eBrushImagePaintType(*brush_type)) {
906 name = "Blur";
907 break;
909 name = "Smear";
910 break;
912 name = "Fill";
913 break;
915 name = "Mask";
916 break;
918 name = "Clone";
919 break;
921 break;
922 }
923 }
924 break;
926 name = "Comb";
927 if (brush_type) {
928 switch (eBrushCurvesSculptType(*brush_type)) {
930 name = "Add";
931 break;
933 name = "Delete";
934 break;
936 name = "Density";
937 break;
939 name = "Select";
940 break;
941 default:
942 break;
943 }
944 }
945 break;
947 name = "Pencil";
948 /* Different default brush for some brush types. */
949 if (brush_type) {
950 switch (eBrushGPaintType(*brush_type)) {
952 name = "Eraser Hard";
953 break;
955 name = "Fill";
956 break;
959 /* Use default, don't override. */
960 break;
961 }
962 }
963 eraser_name = "Eraser Soft";
964 break;
966 name = "Paint";
967 if (brush_type) {
968 switch (eBrushGPVertexType(*brush_type)) {
970 name = "Blur";
971 break;
973 name = "Average";
974 break;
976 name = "Smear";
977 break;
979 name = "Replace";
980 break;
982 /* Use default, don't override. */
983 break;
985 /* Unused brush type. */
987 break;
988 }
989 }
990 break;
992 name = "Smooth";
993 if (brush_type) {
994 switch (eBrushGPSculptType(*brush_type)) {
996 name = "Clone";
997 break;
998 default:
999 break;
1000 }
1001 }
1002 break;
1004 name = "Paint";
1005 if (brush_type) {
1006 switch (eBrushGPWeightType(*brush_type)) {
1008 name = "Blur";
1009 break;
1011 name = "Average";
1012 break;
1014 name = "Smear";
1015 break;
1017 /* Use default, don't override. */
1018 break;
1019 }
1020 }
1021 break;
1022 default:
1024 break;
1025 }
1026
1027 *r_name = name;
1028 if (r_eraser_name) {
1029 *r_eraser_name = eraser_name;
1030 }
1031}
1032
1033std::optional<AssetWeakReference> BKE_paint_brush_type_default_reference(
1034 const PaintMode paint_mode, std::optional<int> brush_type)
1035{
1037
1038 paint_brush_default_essentials_name_get(paint_mode, brush_type, &name, nullptr);
1039 if (name.is_empty()) {
1040 return {};
1041 }
1042
1043 return paint_brush_asset_reference_from_essentials(name.c_str(), paint_mode);
1044}
1045
1047 const bool do_regular = true,
1048 const bool do_eraser = true)
1049{
1050 if (!paint->runtime || !paint->runtime->initialized) {
1051 /* Can happen when loading old file where toolsettings are created in versioning, without
1052 * calling #paint_runtime_init(). Will be done later when necessary. */
1053 return;
1054 }
1055
1057 blender::StringRefNull eraser_name;
1058
1060 paint->runtime->paint_mode, std::nullopt, &name, &eraser_name);
1061
1062 if (do_regular && !name.is_empty()) {
1064 }
1065 if (do_eraser && !eraser_name.is_empty()) {
1067 }
1068}
1069
1098
1100{
1101 paint_brush_set_default_reference(paint, true, false);
1102 return paint_brush_update_from_asset_reference(bmain, paint);
1103}
1104
1105bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
1106{
1108 return paint_brush_update_from_asset_reference(bmain, paint);
1109}
1110
1112 AssetWeakReference &&asset_weak_reference)
1113{
1114 if (!paint->runtime->previous_active_brush_reference) {
1115 paint->runtime->previous_active_brush_reference = MEM_new<AssetWeakReference>(__func__);
1116 }
1117 *paint->runtime->previous_active_brush_reference = asset_weak_reference;
1118}
1119
1121{
1122 MEM_SAFE_DELETE(paint->runtime->previous_active_brush_reference);
1123}
1124
1126{
1127 /* Clear brush with invalid mode. Unclear if this can still happen,
1128 * but kept from old paint tool-slots code. */
1129 Brush *brush = BKE_paint_brush(paint);
1130 if (brush && (paint->runtime->ob_mode & brush->ob_mode) == 0) {
1131 BKE_paint_brush_set(paint, nullptr);
1132 BKE_paint_brush_set_default(bmain, paint);
1133 }
1134
1135 Brush *eraser_brush = BKE_paint_eraser_brush(paint);
1136 if (eraser_brush && (paint->runtime->ob_mode & eraser_brush->ob_mode) == 0) {
1137 BKE_paint_eraser_brush_set(paint, nullptr);
1139 }
1140}
1141
1143{
1144 /* Don't resolve this during file read, it will be done after. */
1145 if (bmain->is_locked_for_linking) {
1146 return false;
1147 }
1148 /* Attempt to restore a valid active brush from brush asset information. */
1149 if (paint->eraser_brush != nullptr) {
1150 return false;
1151 }
1152 if (paint->eraser_brush_asset_reference == nullptr) {
1153 return false;
1154 }
1155
1156 Brush *brush = reinterpret_cast<Brush *>(blender::bke::asset_edit_id_from_weak_reference(
1157 *bmain, ID_BR, *paint->eraser_brush_asset_reference));
1158 BLI_assert(brush == nullptr || blender::bke::asset_edit_id_is_editable(brush->id));
1159
1160 /* Ensure we have a brush with appropriate mode to assign.
1161 * Could happen if contents of asset blend was manually changed. */
1162 if (brush == nullptr || (paint->runtime->ob_mode & brush->ob_mode) == 0) {
1163 MEM_delete(paint->eraser_brush_asset_reference);
1164 paint->eraser_brush_asset_reference = nullptr;
1165 return false;
1166 }
1167
1168 paint->eraser_brush = brush;
1169 return true;
1170}
1171
1173{
1174 return paint ? paint->eraser_brush : nullptr;
1175}
1176
1178{
1179 return paint ? paint->eraser_brush : nullptr;
1180}
1181
1183{
1184 if (paint == nullptr || paint->eraser_brush == brush) {
1185 return false;
1186 }
1187 if (brush && (paint->runtime->ob_mode & brush->ob_mode) == 0) {
1188 return false;
1189 }
1190
1191 paint->eraser_brush = brush;
1192
1193 MEM_delete(paint->eraser_brush_asset_reference);
1194 paint->eraser_brush_asset_reference = nullptr;
1195
1196 if (brush != nullptr) {
1197 std::optional<AssetWeakReference> weak_ref = blender::bke::asset_edit_weak_reference_from_id(
1198 brush->id);
1199 if (weak_ref.has_value()) {
1200 paint->eraser_brush_asset_reference = MEM_new<AssetWeakReference>(__func__, *weak_ref);
1201 }
1202 }
1203
1204 return true;
1205}
1206
1208 const PaintMode paint_mode,
1209 const char *name)
1210{
1211 std::optional<AssetWeakReference> weak_ref = paint_brush_asset_reference_from_essentials(
1212 name, paint_mode);
1213 if (!weak_ref) {
1214 return {};
1215 }
1216
1217 return reinterpret_cast<Brush *>(
1219}
1220
1222{
1223 paint_brush_set_default_reference(paint, false, true);
1225}
1226
1232
1233static void paint_runtime_init(const ToolSettings *ts, Paint *paint)
1234{
1235 if (!paint->runtime) {
1236 paint->runtime = MEM_new<blender::bke::PaintRuntime>(__func__);
1237 }
1238
1239 if (paint == &ts->imapaint.paint) {
1240 paint->runtime->ob_mode = OB_MODE_TEXTURE_PAINT;
1241 /* Note: This is an odd case where 3D Texture paint and Image Paint share the same struct.
1242 * It would be equally valid to assign PaintMode::Texture2D to this. */
1243 paint->runtime->paint_mode = PaintMode::Texture3D;
1244 }
1245 else if (ts->sculpt && paint == &ts->sculpt->paint) {
1246 paint->runtime->ob_mode = OB_MODE_SCULPT;
1247 paint->runtime->paint_mode = PaintMode::Sculpt;
1248 }
1249 else if (ts->vpaint && paint == &ts->vpaint->paint) {
1250 paint->runtime->ob_mode = OB_MODE_VERTEX_PAINT;
1251 paint->runtime->paint_mode = PaintMode::Vertex;
1252 }
1253 else if (ts->wpaint && paint == &ts->wpaint->paint) {
1254 paint->runtime->ob_mode = OB_MODE_WEIGHT_PAINT;
1255 paint->runtime->paint_mode = PaintMode::Weight;
1256 }
1257 else if (ts->gp_paint && paint == &ts->gp_paint->paint) {
1258 paint->runtime->ob_mode = OB_MODE_PAINT_GREASE_PENCIL;
1259 paint->runtime->paint_mode = PaintMode::GPencil;
1260 }
1261 else if (ts->gp_vertexpaint && paint == &ts->gp_vertexpaint->paint) {
1262 paint->runtime->ob_mode = OB_MODE_VERTEX_GREASE_PENCIL;
1263 paint->runtime->paint_mode = PaintMode::VertexGPencil;
1264 }
1265 else if (ts->gp_sculptpaint && paint == &ts->gp_sculptpaint->paint) {
1266 paint->runtime->ob_mode = OB_MODE_SCULPT_GREASE_PENCIL;
1267 paint->runtime->paint_mode = PaintMode::SculptGPencil;
1268 }
1269 else if (ts->gp_weightpaint && paint == &ts->gp_weightpaint->paint) {
1270 paint->runtime->ob_mode = OB_MODE_WEIGHT_GREASE_PENCIL;
1271 paint->runtime->paint_mode = PaintMode::WeightGPencil;
1272 }
1273 else if (ts->curves_sculpt && paint == &ts->curves_sculpt->paint) {
1274 paint->runtime->ob_mode = OB_MODE_SCULPT_CURVES;
1275 paint->runtime->paint_mode = PaintMode::SculptCurves;
1276 }
1277 else {
1279 }
1280
1281 paint->runtime->initialized = true;
1282}
1283
1285{
1286 switch (mode) {
1289 return offsetof(Brush, image_brush_type);
1290 case PaintMode::Sculpt:
1291 return offsetof(Brush, sculpt_brush_type);
1292 case PaintMode::Vertex:
1293 return offsetof(Brush, vertex_brush_type);
1294 case PaintMode::Weight:
1295 return offsetof(Brush, weight_brush_type);
1296 case PaintMode::GPencil:
1297 return offsetof(Brush, gpencil_brush_type);
1299 return offsetof(Brush, gpencil_vertex_brush_type);
1301 return offsetof(Brush, gpencil_sculpt_brush_type);
1303 return offsetof(Brush, gpencil_weight_brush_type);
1305 return offsetof(Brush, curves_sculpt_brush_type);
1306 case PaintMode::Invalid:
1307 break; /* We don't use these yet. */
1308 }
1309 return 0;
1310}
1311
1312std::optional<int> BKE_paint_get_brush_type_from_obmode(const Brush *brush,
1313 const eObjectMode ob_mode)
1314{
1315 switch (ob_mode) {
1317 case OB_MODE_EDIT:
1318 return brush->image_brush_type;
1319 case OB_MODE_SCULPT:
1320 return brush->sculpt_brush_type;
1322 return brush->vertex_brush_type;
1324 return brush->weight_brush_type;
1326 return brush->gpencil_brush_type;
1328 return brush->gpencil_vertex_brush_type;
1330 return brush->gpencil_sculpt_brush_type;
1332 return brush->gpencil_weight_brush_type;
1334 return brush->curves_sculpt_brush_type;
1335 default:
1336 return {};
1337 }
1338}
1339
1340std::optional<int> BKE_paint_get_brush_type_from_paintmode(const Brush *brush,
1341 const PaintMode mode)
1342{
1343 switch (mode) {
1346 return brush->image_brush_type;
1347 case PaintMode::Sculpt:
1348 return brush->sculpt_brush_type;
1349 case PaintMode::Vertex:
1350 return brush->vertex_brush_type;
1351 case PaintMode::Weight:
1352 return brush->weight_brush_type;
1353 case PaintMode::GPencil:
1354 return brush->gpencil_brush_type;
1356 return brush->gpencil_vertex_brush_type;
1358 return brush->gpencil_sculpt_brush_type;
1360 return brush->gpencil_weight_brush_type;
1362 return brush->curves_sculpt_brush_type;
1363 case PaintMode::Invalid:
1364 default:
1365 return {};
1366 }
1367}
1368
1370{
1372 return pc;
1373}
1374
1376{
1377 return paint ? paint->palette : nullptr;
1378}
1379
1381{
1382 if (paint) {
1383 id_us_min((ID *)paint->palette);
1384 paint->palette = palette;
1385 id_us_plus((ID *)paint->palette);
1386 }
1387}
1388
1390{
1391 pc->add_index = (add_index || pc->tot_points == 1) ? (add_index + 1) : 0;
1392}
1393
1395{
1396 if (BLI_listbase_count_at_most(&palette->colors, palette->active_color) == palette->active_color)
1397 {
1398 palette->active_color--;
1399 }
1400
1401 BLI_remlink(&palette->colors, color);
1402
1403 if (palette->active_color < 0 && !BLI_listbase_is_empty(&palette->colors)) {
1404 palette->active_color = 0;
1405 }
1406
1407 MEM_freeN(color);
1408}
1409
1411{
1412 BLI_freelistN(&palette->colors);
1413 palette->active_color = 0;
1414}
1415
1416void BKE_palette_color_set(PaletteColor *color, const float rgb[3])
1417{
1418 copy_v3_v3(color->color, rgb);
1420}
1421
1423{
1424 linearrgb_to_srgb_v3_v3(color->rgb, color->color);
1425}
1426
1427Palette *BKE_palette_add(Main *bmain, const char *name)
1428{
1429 Palette *palette = BKE_id_new<Palette>(bmain, name);
1430 return palette;
1431}
1432
1434{
1435 PaletteColor *color = MEM_callocN<PaletteColor>(__func__);
1436 BLI_addtail(&palette->colors, color);
1437 return color;
1438}
1439
1440bool BKE_palette_is_empty(const Palette *palette)
1441{
1442 return BLI_listbase_is_empty(&palette->colors);
1443}
1444
1445static int palettecolor_compare_hsv(const void *a1, const void *a2)
1446{
1447 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1448 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1449
1450 /* Hue */
1451 if (ps1->h > ps2->h) {
1452 return 1;
1453 }
1454 if (ps1->h < ps2->h) {
1455 return -1;
1456 }
1457
1458 /* Saturation. */
1459 if (ps1->s > ps2->s) {
1460 return 1;
1461 }
1462 if (ps1->s < ps2->s) {
1463 return -1;
1464 }
1465
1466 /* Value. */
1467 if (1.0f - ps1->v > 1.0f - ps2->v) {
1468 return 1;
1469 }
1470 if (1.0f - ps1->v < 1.0f - ps2->v) {
1471 return -1;
1472 }
1473
1474 return 0;
1475}
1476
1477void BKE_palette_sort_hsv(tPaletteColorHSV *color_array, const int totcol)
1478{
1479 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_hsv);
1480}
1481
1482static int palettecolor_compare_svh(const void *a1, const void *a2)
1483{
1484 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1485 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1486
1487 /* Saturation. */
1488 if (ps1->s > ps2->s) {
1489 return 1;
1490 }
1491 if (ps1->s < ps2->s) {
1492 return -1;
1493 }
1494
1495 /* Value. */
1496 if (1.0f - ps1->v > 1.0f - ps2->v) {
1497 return 1;
1498 }
1499 if (1.0f - ps1->v < 1.0f - ps2->v) {
1500 return -1;
1501 }
1502
1503 /* Hue */
1504 if (ps1->h > ps2->h) {
1505 return 1;
1506 }
1507 if (ps1->h < ps2->h) {
1508 return -1;
1509 }
1510
1511 return 0;
1512}
1513
1514void BKE_palette_sort_svh(tPaletteColorHSV *color_array, const int totcol)
1515{
1516 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_svh);
1517}
1518
1519static int palettecolor_compare_vhs(const void *a1, const void *a2)
1520{
1521 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1522 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1523
1524 /* Value. */
1525 if (1.0f - ps1->v > 1.0f - ps2->v) {
1526 return 1;
1527 }
1528 if (1.0f - ps1->v < 1.0f - ps2->v) {
1529 return -1;
1530 }
1531
1532 /* Hue */
1533 if (ps1->h > ps2->h) {
1534 return 1;
1535 }
1536 if (ps1->h < ps2->h) {
1537 return -1;
1538 }
1539
1540 /* Saturation. */
1541 if (ps1->s > ps2->s) {
1542 return 1;
1543 }
1544 if (ps1->s < ps2->s) {
1545 return -1;
1546 }
1547
1548 return 0;
1549}
1550
1551void BKE_palette_sort_vhs(tPaletteColorHSV *color_array, const int totcol)
1552{
1553 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_vhs);
1554}
1555
1556static int palettecolor_compare_luminance(const void *a1, const void *a2)
1557{
1558 const tPaletteColorHSV *ps1 = static_cast<const tPaletteColorHSV *>(a1);
1559 const tPaletteColorHSV *ps2 = static_cast<const tPaletteColorHSV *>(a2);
1560
1561 float lumi1 = (ps1->rgb[0] + ps1->rgb[1] + ps1->rgb[2]) / 3.0f;
1562 float lumi2 = (ps2->rgb[0] + ps2->rgb[1] + ps2->rgb[2]) / 3.0f;
1563
1564 if (lumi1 > lumi2) {
1565 return -1;
1566 }
1567 if (lumi1 < lumi2) {
1568 return 1;
1569 }
1570
1571 return 0;
1572}
1573
1574void BKE_palette_sort_luminance(tPaletteColorHSV *color_array, const int totcol)
1575{
1576 /* Sort by Luminance (calculated with the average, enough for sorting). */
1577 qsort(color_array, totcol, sizeof(tPaletteColorHSV), palettecolor_compare_luminance);
1578}
1579
1580bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name)
1581{
1582 tPaletteColorHSV *color_array = nullptr;
1583 tPaletteColorHSV *col_elm = nullptr;
1584 bool done = false;
1585
1586 const int totpal = BLI_ghash_len(color_table);
1587
1588 if (totpal > 0) {
1589 color_array = MEM_calloc_arrayN<tPaletteColorHSV>(totpal, __func__);
1590 /* Put all colors in an array. */
1591 GHashIterator gh_iter;
1592 int t = 0;
1593 GHASH_ITER (gh_iter, color_table) {
1595 float r, g, b;
1596 float h, s, v;
1597 cpack_to_rgb(col, &r, &g, &b);
1598 rgb_to_hsv(r, g, b, &h, &s, &v);
1599
1600 col_elm = &color_array[t];
1601 col_elm->rgb[0] = r;
1602 col_elm->rgb[1] = g;
1603 col_elm->rgb[2] = b;
1604 col_elm->h = h;
1605 col_elm->s = s;
1606 col_elm->v = v;
1607 t++;
1608 }
1609 }
1610
1611 /* Create the Palette. */
1612 if (totpal > 0) {
1613 /* Sort by Hue and saturation. */
1614 BKE_palette_sort_hsv(color_array, totpal);
1615
1616 Palette *palette = BKE_palette_add(bmain, name);
1617 if (palette) {
1618 for (int i = 0; i < totpal; i++) {
1619 col_elm = &color_array[i];
1620 PaletteColor *palcol = BKE_palette_color_add(palette);
1621 if (palcol) {
1622 /* Hex was stored as sRGB. */
1624 }
1625 }
1626 done = true;
1627 }
1628 }
1629 else {
1630 done = false;
1631 }
1632
1633 if (totpal > 0) {
1634 MEM_SAFE_FREE(color_array);
1635 }
1636
1637 return done;
1638}
1639
1641{
1642 return ((ob != nullptr) && (ob->type == OB_MESH) && (ob->data != nullptr) &&
1643 (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_FACE_SEL) &&
1645}
1646
1648{
1649 return ((ob != nullptr) && (ob->type == OB_MESH) && (ob->data != nullptr) &&
1650 (((Mesh *)ob->data)->editflag & ME_EDIT_PAINT_VERT_SEL) &&
1652}
1653
1655{
1656 if (ob == nullptr || ob->data == nullptr) {
1657 return false;
1658 }
1659 if (ob->type == OB_GREASE_PENCIL) {
1661 }
1662 return false;
1663}
1664
1670
1672{
1673 return ((ob != nullptr) && (ob->type == OB_MESH) && (ob->data != nullptr) &&
1675}
1676
1677void BKE_paint_cavity_curve_preset(Paint *paint, int preset)
1678{
1679 CurveMapping *cumap = nullptr;
1680 CurveMap *cuma = nullptr;
1681
1682 if (!paint->cavity_curve) {
1683 paint->cavity_curve = BKE_curvemapping_add(1, 0, 0, 1, 1);
1684 }
1685 cumap = paint->cavity_curve;
1687 cumap->preset = preset;
1688
1689 cuma = cumap->cm;
1691 BKE_curvemapping_changed(cumap, false);
1692}
1693
1695{
1696 switch (mode) {
1697 case PaintMode::Sculpt:
1698 return OB_MODE_SCULPT;
1699 case PaintMode::Vertex:
1700 return OB_MODE_VERTEX_PAINT;
1701 case PaintMode::Weight:
1702 return OB_MODE_WEIGHT_PAINT;
1705 return OB_MODE_TEXTURE_PAINT;
1707 return OB_MODE_SCULPT_CURVES;
1708 case PaintMode::GPencil:
1710 case PaintMode::Invalid:
1711 default:
1712 return OB_MODE_OBJECT;
1713 }
1714}
1715
1737
1739{
1740 Paint *paint = nullptr;
1741 if (*r_paint) {
1742 if (!(*r_paint)->runtime) {
1743 (*r_paint)->runtime = MEM_new<blender::bke::PaintRuntime>(__func__);
1744 }
1745 if (!(*r_paint)->runtime->initialized && *r_paint == (Paint *)&ts->imapaint) {
1746 paint_runtime_init(ts, *r_paint);
1747 }
1748 else {
1749 BLI_assert(ELEM(*r_paint,
1750 /* Cast is annoying, but prevent nullptr-pointer access. */
1751 (Paint *)ts->gp_paint,
1752 (Paint *)ts->gp_vertexpaint,
1753 (Paint *)ts->gp_sculptpaint,
1754 (Paint *)ts->gp_weightpaint,
1755 (Paint *)ts->sculpt,
1756 (Paint *)ts->vpaint,
1757 (Paint *)ts->wpaint,
1758 (Paint *)ts->curves_sculpt,
1759 (Paint *)&ts->imapaint));
1760#ifndef NDEBUG
1761 Paint paint_test = blender::dna::shallow_copy(**r_paint);
1762 paint_runtime_init(ts, *r_paint);
1763 /* Swap so debug doesn't hide errors when release fails. */
1764 blender::dna::shallow_swap(**r_paint, paint_test);
1765 BLI_assert(paint_test.runtime->ob_mode == (*r_paint)->runtime->ob_mode);
1766#endif
1767 }
1768 return true;
1769 }
1770
1771 if (((VPaint **)r_paint == &ts->vpaint) || ((VPaint **)r_paint == &ts->wpaint)) {
1772 VPaint *data = MEM_callocN<VPaint>(__func__);
1773 paint = &data->paint;
1774 paint_init_data(*paint);
1775 }
1776 else if ((Sculpt **)r_paint == &ts->sculpt) {
1777 Sculpt *data = MEM_callocN<Sculpt>(__func__);
1778
1779 *data = blender::dna::shallow_copy(*DNA_struct_default_get(Sculpt));
1780
1781 paint = &data->paint;
1782 paint_init_data(*paint);
1783 }
1784 else if ((GpPaint **)r_paint == &ts->gp_paint) {
1785 GpPaint *data = MEM_callocN<GpPaint>(__func__);
1786 paint = &data->paint;
1787 paint_init_data(*paint);
1788 }
1789 else if ((GpVertexPaint **)r_paint == &ts->gp_vertexpaint) {
1791 paint = &data->paint;
1792 paint_init_data(*paint);
1793 }
1794 else if ((GpSculptPaint **)r_paint == &ts->gp_sculptpaint) {
1796 paint = &data->paint;
1797 paint_init_data(*paint);
1798 }
1799 else if ((GpWeightPaint **)r_paint == &ts->gp_weightpaint) {
1801 paint = &data->paint;
1802 paint_init_data(*paint);
1803 }
1804 else if ((CurvesSculpt **)r_paint == &ts->curves_sculpt) {
1806 paint = &data->paint;
1807 paint_init_data(*paint);
1808 }
1809 else if (*r_paint == &ts->imapaint.paint) {
1810 paint = &ts->imapaint.paint;
1811 paint_init_data(*paint);
1812 }
1813
1814 paint->flags |= PAINT_SHOW_BRUSH;
1815
1816 *r_paint = paint;
1817
1818 paint_runtime_init(ts, paint);
1819
1820 return false;
1821}
1822
1824{
1825 if (paint->brush_asset_reference) {
1827 }
1828 if (paint->eraser_brush_asset_reference) {
1830 }
1831
1832 if (!paint->brush) {
1833 BKE_paint_brush_set_default(bmain, paint);
1834 }
1835 if (!paint->eraser_brush) {
1837 }
1838}
1839
1840void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const bool ensure_brushes)
1841{
1842
1844 Paint *paint = BKE_paint_get_active_from_paintmode(sce, mode);
1845
1846 if (ensure_brushes) {
1847 BKE_paint_brushes_ensure(bmain, paint);
1848 }
1849
1850 if (!paint->cavity_curve) {
1852 }
1853}
1854
1856{
1858 MEM_delete(paint->brush_asset_reference);
1860 MEM_delete(paint->eraser_brush_asset_reference);
1861
1863 brush_ref,
1865 {
1866 MEM_delete(brush_ref->name);
1867 MEM_delete(brush_ref->brush_asset_reference);
1868 MEM_delete(brush_ref);
1869 }
1870
1874 MEM_SAFE_DELETE(paint->runtime);
1875}
1876
1877void BKE_paint_copy(const Paint *src, Paint *dst, const int flag)
1878{
1879 dst->brush = src->brush;
1881
1882 if (src->brush_asset_reference) {
1883 dst->brush_asset_reference = MEM_new<AssetWeakReference>(__func__,
1884 *src->brush_asset_reference);
1885 }
1887 dst->tool_brush_bindings.main_brush_asset_reference = MEM_new<AssetWeakReference>(
1889 }
1891 dst->eraser_brush_asset_reference = MEM_new<AssetWeakReference>(
1892 __func__, *src->eraser_brush_asset_reference);
1893 }
1898 {
1899 brush_ref->name = BLI_strdup(brush_ref->name);
1900 brush_ref->brush_asset_reference = MEM_new<AssetWeakReference>(
1901 __func__, *brush_ref->brush_asset_reference);
1902 }
1903
1910
1911 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
1912 id_us_plus((ID *)dst->palette);
1913 }
1914
1915 dst->runtime = MEM_new<blender::bke::PaintRuntime>(__func__);
1916 if (src->runtime) {
1917 dst->runtime->paint_mode = src->runtime->paint_mode;
1918 dst->runtime->ob_mode = src->runtime->ob_mode;
1919 dst->runtime->initialized = true;
1920 }
1921}
1922
1924{
1925 if (ts->vpaint) {
1926 fn(reinterpret_cast<Paint *>(ts->vpaint));
1927 }
1928 if (ts->wpaint) {
1929 fn(reinterpret_cast<Paint *>(ts->wpaint));
1930 }
1931 if (ts->sculpt) {
1932 fn(reinterpret_cast<Paint *>(ts->sculpt));
1933 }
1934 if (ts->gp_paint) {
1935 fn(reinterpret_cast<Paint *>(ts->gp_paint));
1936 }
1937 if (ts->gp_vertexpaint) {
1938 fn(reinterpret_cast<Paint *>(ts->gp_vertexpaint));
1939 }
1940 if (ts->gp_sculptpaint) {
1941 fn(reinterpret_cast<Paint *>(ts->gp_sculptpaint));
1942 }
1943 if (ts->gp_weightpaint) {
1944 fn(reinterpret_cast<Paint *>(ts->gp_weightpaint));
1945 }
1946 if (ts->curves_sculpt) {
1947 fn(reinterpret_cast<Paint *>(ts->curves_sculpt));
1948 }
1949 fn(reinterpret_cast<Paint *>(&ts->imapaint));
1950}
1951
1952void BKE_paint_stroke_get_average(const Paint *paint, const Object *ob, float stroke[3])
1953{
1954 const blender::bke::PaintRuntime &paint_runtime = *paint->runtime;
1955 if (paint_runtime.last_stroke_valid && paint_runtime.average_stroke_counter > 0) {
1956 float fac = 1.0f / paint_runtime.average_stroke_counter;
1957 mul_v3_v3fl(stroke, paint_runtime.average_stroke_accum, fac);
1958 }
1959 else {
1960 copy_v3_v3(stroke, ob->object_to_world().location());
1961 }
1962}
1963
1965 const blender::float3 &initial_hsv_jitter,
1966 const float distance,
1967 const float pressure,
1968 const blender::float3 &color)
1969{
1970 constexpr float noise_scale = 1 / 20.0f;
1971
1972 const float random_hue = (color_jitter.flag & BRUSH_COLOR_JITTER_USE_HUE_AT_STROKE) ?
1973 initial_hsv_jitter[0] :
1975 distance * noise_scale, initial_hsv_jitter[0] * 100));
1976
1977 const float random_sat = (color_jitter.flag & BRUSH_COLOR_JITTER_USE_SAT_AT_STROKE) ?
1978 initial_hsv_jitter[1] :
1980 distance * noise_scale, initial_hsv_jitter[1] * 100));
1981
1982 const float random_val = (color_jitter.flag & BRUSH_COLOR_JITTER_USE_VAL_AT_STROKE) ?
1983 initial_hsv_jitter[2] :
1985 distance * noise_scale, initial_hsv_jitter[2] * 100));
1986
1987 float hue_jitter_scale = color_jitter.hue;
1988 if (color_jitter.flag & BRUSH_COLOR_JITTER_USE_HUE_RAND_PRESS) {
1989 hue_jitter_scale *= BKE_curvemapping_evaluateF(color_jitter.curve_hue_jitter, 0, pressure);
1990 }
1991 float sat_jitter_scale = color_jitter.saturation;
1992 if (color_jitter.flag & BRUSH_COLOR_JITTER_USE_SAT_RAND_PRESS) {
1993 sat_jitter_scale *= BKE_curvemapping_evaluateF(color_jitter.curve_sat_jitter, 0, pressure);
1994 }
1995 float val_jitter_scale = color_jitter.value;
1996 if (color_jitter.flag & BRUSH_COLOR_JITTER_USE_VAL_RAND_PRESS) {
1997 val_jitter_scale *= BKE_curvemapping_evaluateF(color_jitter.curve_val_jitter, 0, pressure);
1998 }
1999
2000 blender::float3 hsv;
2001 rgb_to_hsv_v(color, hsv);
2002
2003 hsv[0] += blender::math::interpolate(0.5f, random_hue, hue_jitter_scale) - 0.5f;
2004 /* Wrap hue. */
2005 if (hsv[0] > 1.0f) {
2006 hsv[0] -= 1.0f;
2007 }
2008 else if (hsv[0] < 0.0f) {
2009 hsv[0] += 1.0f;
2010 }
2011
2012 hsv[1] *= blender::math::interpolate(1.0f, random_sat * 2.0f, sat_jitter_scale);
2013 hsv[2] *= blender::math::interpolate(1.0f, random_val * 2.0f, val_jitter_scale);
2014
2015 blender::float3 random_color;
2016 hsv_to_rgb_v(hsv, random_color);
2017 return random_color;
2018}
2019
2021{
2022 if (paint->cavity_curve) {
2024 }
2025 if (paint->brush_asset_reference) {
2027 }
2028 if (paint->eraser_brush_asset_reference) {
2030 }
2031
2032 {
2033 /* Write tool system bindings. */
2034 ToolSystemBrushBindings &tool_brush_bindings = paint->tool_brush_bindings;
2035
2036 if (tool_brush_bindings.main_brush_asset_reference) {
2038 }
2040 writer, NamedBrushAssetReference, &tool_brush_bindings.active_brush_per_brush_type);
2042 NamedBrushAssetReference *, brush_ref, &tool_brush_bindings.active_brush_per_brush_type)
2043 {
2044 BLO_write_string(writer, brush_ref->name);
2045 if (brush_ref->brush_asset_reference) {
2046 BKE_asset_weak_reference_write(writer, brush_ref->brush_asset_reference);
2047 }
2048 }
2049 }
2050
2053 }
2054
2057 }
2058
2061 }
2062}
2063
2064void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint)
2065{
2066 BLO_read_struct(reader, CurveMapping, &paint->cavity_curve);
2067 if (paint->cavity_curve) {
2069 }
2070 else {
2072 }
2073
2075 if (paint->brush_asset_reference) {
2077 }
2079 if (paint->eraser_brush_asset_reference) {
2081 }
2082
2083 {
2084 /* Read tool system bindings. */
2085 ToolSystemBrushBindings &tool_brush_bindings = paint->tool_brush_bindings;
2086
2087 BLO_read_struct(reader, AssetWeakReference, &tool_brush_bindings.main_brush_asset_reference);
2088 if (tool_brush_bindings.main_brush_asset_reference) {
2089 BKE_asset_weak_reference_read(reader, tool_brush_bindings.main_brush_asset_reference);
2090 }
2091
2093 reader, NamedBrushAssetReference, &tool_brush_bindings.active_brush_per_brush_type);
2095 NamedBrushAssetReference *, brush_ref, &tool_brush_bindings.active_brush_per_brush_type)
2096 {
2097 BLO_read_string(reader, &brush_ref->name);
2098
2099 BLO_read_struct(reader, AssetWeakReference, &brush_ref->brush_asset_reference);
2100 if (brush_ref->brush_asset_reference) {
2101 BKE_asset_weak_reference_read(reader, brush_ref->brush_asset_reference);
2102 }
2103 }
2104 }
2107 if (ups->curve_rand_hue) {
2110 }
2111
2113 if (ups->curve_rand_saturation) {
2116 }
2117
2119 if (ups->curve_rand_value) {
2122 }
2123
2124 paint->runtime = MEM_new<blender::bke::PaintRuntime>(__func__);
2125
2126 paint_runtime_init(scene->toolsettings, paint);
2127}
2128
2130 const int gridsize,
2131 const int x,
2132 const int y)
2133{
2134 return grid_hidden[CCG_grid_xy_to_index(gridsize, x, y)] ||
2135 grid_hidden[CCG_grid_xy_to_index(gridsize, x + 1, y)] ||
2136 grid_hidden[CCG_grid_xy_to_index(gridsize, x + 1, y + 1)] ||
2137 grid_hidden[CCG_grid_xy_to_index(gridsize, x, y + 1)];
2138}
2139
2141{
2142 BMLoop *l_iter;
2143 BMLoop *l_first;
2144
2145 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
2146 do {
2147 if (BM_elem_flag_test(l_iter->v, BM_ELEM_HIDDEN)) {
2148 return true;
2149 }
2150 } while ((l_iter = l_iter->next) != l_first);
2151
2152 return false;
2153}
2154
2156{
2157 int factor = CCG_grid_factor(level, gpm->level);
2158 int gridsize = CCG_grid_size(gpm->level);
2159
2160 return gpm->data[(y * factor) * gridsize + (x * factor)];
2161}
2162
2163/* Threshold to move before updating the brush rotation, reduces jitter. */
2164static float paint_rake_rotation_spacing(const Paint & /*ups*/, const Brush &brush)
2165{
2166 return brush.sculpt_brush_type == SCULPT_BRUSH_TYPE_CLAY_STRIPS ? 1.0f : 20.0f;
2167}
2168
2169void paint_update_brush_rake_rotation(Paint &paint, const Brush &brush, float rotation)
2170{
2171 blender::bke::PaintRuntime &paint_runtime = *paint.runtime;
2172 paint_runtime.brush_rotation = rotation;
2173
2175 paint_runtime.brush_rotation_sec = rotation;
2176 }
2177 else {
2178 paint_runtime.brush_rotation_sec = 0.0f;
2179 }
2180}
2181
2182static bool paint_rake_rotation_active(const MTex &mtex)
2183{
2184 return mtex.tex && mtex.brush_angle_mode & MTEX_ANGLE_RAKE;
2185}
2186
2187static bool paint_rake_rotation_active(const Brush &brush, PaintMode paint_mode)
2188{
2190 BKE_brush_has_cube_tip(&brush, paint_mode);
2191}
2192
2194 const Brush &brush,
2195 const float mouse_pos[2],
2196 const PaintMode paint_mode,
2197 bool stroke_has_started)
2198{
2199 blender::bke::PaintRuntime &paint_runtime = *paint.runtime;
2200
2201 bool ok = false;
2202 if (paint_rake_rotation_active(brush, paint_mode)) {
2203 float r = paint_rake_rotation_spacing(paint, brush);
2204 float rotation;
2205
2206 /* Use a smaller limit if the stroke hasn't started to prevent excessive pre-roll. */
2207 if (!stroke_has_started) {
2208 r = min_ff(r, 4.0f);
2209 }
2210
2211 float dpos[2];
2212 sub_v2_v2v2(dpos, mouse_pos, paint_runtime.last_rake);
2213
2214 /* Limit how often we update the angle to prevent jitter. */
2215 if (len_squared_v2(dpos) >= r * r) {
2216 rotation = atan2f(dpos[1], dpos[0]) + float(0.5f * M_PI);
2217
2218 copy_v2_v2(paint_runtime.last_rake, mouse_pos);
2219
2220 paint_runtime.last_rake_angle = rotation;
2221
2222 paint_update_brush_rake_rotation(paint, brush, rotation);
2223 ok = true;
2224 }
2225 /* Make sure we reset here to the last rotation to avoid accumulating
2226 * values in case a random rotation is also added. */
2227 else {
2228 paint_update_brush_rake_rotation(paint, brush, paint_runtime.last_rake_angle);
2229 ok = false;
2230 }
2231 }
2232 else {
2233 paint_runtime.brush_rotation = paint_runtime.brush_rotation_sec = 0.0f;
2234 ok = true;
2235 }
2236 return ok;
2237}
2238
2240{
2241 ss->deform_cos = {};
2242 ss->deform_imats = {};
2243 ss->vert_normals_deform = {};
2244 ss->face_normals_deform = {};
2245}
2246
2258
2263{
2264 SculptSession &ss = *ob->sculpt;
2265
2266 if (ss.bm) {
2267 if (ob->data) {
2269 params.calc_object_remap = false;
2270 BM_mesh_bm_to_me(nullptr, ss.bm, static_cast<Mesh *>(ob->data), &params);
2271 }
2272 }
2273}
2274
2276{
2277 if (ob && ob->sculpt) {
2279
2280 /* Ensure the objects evaluated mesh doesn't hold onto arrays
2281 * now realloc'd in the mesh #34473. */
2283 }
2284}
2285
2287{
2288 SculptSession *ss = object.sculpt;
2289 if (!ss) {
2290 return;
2291 }
2292
2293 ss->pbvh.reset();
2294 ss->edge_to_face_offsets = {};
2295 ss->edge_to_face_indices = {};
2296 ss->edge_to_face_map = {};
2297 ss->vert_to_edge_offsets = {};
2298 ss->vert_to_edge_indices = {};
2299 ss->vert_to_edge_map = {};
2300
2301 ss->preview_verts = {};
2302
2305 ss->topology_island_cache.reset();
2306
2307 ss->clear_active_elements(false);
2308}
2309
2311{
2312 if (object && object->sculpt) {
2313 if (object->sculpt->bm) {
2314 /* Ensure no points to old arrays are stored in DM
2315 *
2316 * Apparently, we could not use DEG_id_tag_update
2317 * here because this will lead to the while object
2318 * surface to disappear, so we'll release DM in place.
2319 */
2321
2323
2324 /* In contrast with sculptsession_bm_to_me no need in
2325 * DAG tag update here - derived mesh was freed and
2326 * old pointers are nowhere stored.
2327 */
2328 }
2329 }
2330}
2331
2333{
2334 if (ob && ob->sculpt) {
2335 SculptSession *ss = ob->sculpt;
2336
2337 if (ss->bm) {
2339 BM_mesh_free(ss->bm);
2340 }
2341
2343
2344 MEM_delete(ss);
2345
2346 ob->sculpt = nullptr;
2347 }
2348}
2349
2351
2353{
2354 if (this->bm_log) {
2355 BM_log_free(this->bm_log);
2356 }
2357
2358 if (this->tex_pool) {
2360 }
2361
2363
2365}
2366
2368{
2369 return active_vert_;
2370}
2371
2373{
2374 return last_active_vert_;
2375}
2376
2378{
2379 if (std::holds_alternative<int>(active_vert_)) {
2380 return std::get<int>(active_vert_);
2381 }
2382 if (std::holds_alternative<BMVert *>(active_vert_)) {
2383 BMVert *bm_vert = std::get<BMVert *>(active_vert_);
2384 return BM_elem_index_get(bm_vert);
2385 }
2386
2387 return -1;
2388}
2389
2391{
2392 if (std::holds_alternative<int>(last_active_vert_)) {
2393 return std::get<int>(last_active_vert_);
2394 }
2395 if (std::holds_alternative<BMVert *>(last_active_vert_)) {
2396 BMVert *bm_vert = std::get<BMVert *>(last_active_vert_);
2397 return BM_elem_index_get(bm_vert);
2398 }
2399
2400 return -1;
2401}
2402
2404 const Object &object) const
2405{
2406 if (std::holds_alternative<int>(active_vert_)) {
2407 if (this->subdiv_ccg) {
2408 return this->subdiv_ccg->positions[std::get<int>(active_vert_)];
2409 }
2411 return positions[std::get<int>(active_vert_)];
2412 }
2413 if (std::holds_alternative<BMVert *>(active_vert_)) {
2414 BMVert *bm_vert = std::get<BMVert *>(active_vert_);
2415 return bm_vert->co;
2416 }
2417
2419 return float3(std::numeric_limits<float>::infinity());
2420}
2421
2422void SculptSession::clear_active_elements(bool persist_last_active)
2423{
2424 if (persist_last_active) {
2425 if (!std::holds_alternative<std::monostate>(active_vert_)) {
2426 last_active_vert_ = active_vert_;
2427 }
2428 }
2429 else {
2430 last_active_vert_ = {};
2431 }
2432 active_vert_ = {};
2433 active_grid_index.reset();
2434 active_face_index.reset();
2435}
2436
2438{
2439 active_vert_ = vert;
2440}
2441
2442std::optional<PersistentMultiresData> SculptSession::persistent_multires_data()
2443{
2445 if (persistent.grids_num == -1 || persistent.grid_size == -1) {
2446 return std::nullopt;
2447 }
2448
2449 if (this->subdiv_ccg->grids_num != persistent.grids_num ||
2450 this->subdiv_ccg->grid_size != persistent.grid_size)
2451 {
2452 return std::nullopt;
2453 }
2454
2455 return PersistentMultiresData{persistent.sculpt_persistent_co,
2456 persistent.sculpt_persistent_no,
2457 persistent.sculpt_persistent_disp};
2458}
2459
2461 Object *ob,
2462 const bool auto_create_mdisps)
2463{
2464 Mesh &mesh = *static_cast<Mesh *>(ob->data);
2465
2466 if (ob->sculpt && ob->sculpt->bm) {
2467 /* Can't combine multires and dynamic topology. */
2468 return nullptr;
2469 }
2470
2471 bool need_mdisps = false;
2472
2474 if (!auto_create_mdisps) {
2475 /* Multires can't work without displacement layer. */
2476 return nullptr;
2477 }
2478 need_mdisps = true;
2479 }
2480
2481 /* Weight paint operates on original vertices, and needs to treat multires as regular modifier
2482 * to make it so that pbvh::Tree vertices are at the multires surface. */
2483 if ((ob->mode & OB_MODE_SCULPT) == 0) {
2484 return nullptr;
2485 }
2486
2487 VirtualModifierData virtual_modifier_data;
2488 for (ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data); md;
2489 md = md->next)
2490 {
2491 if (md->type == eModifierType_Multires) {
2492 MultiresModifierData *mmd = reinterpret_cast<MultiresModifierData *>(md);
2493
2495 continue;
2496 }
2497
2498 if (mmd->sculptlvl > 0 && !(mmd->flags & eMultiresModifierFlag_UseSculptBaseMesh)) {
2499 if (need_mdisps) {
2501 }
2502
2503 return mmd;
2504 }
2505
2506 return nullptr;
2507 }
2508 }
2509
2510 return nullptr;
2511}
2512
2514{
2515 return sculpt_multires_modifier_get(scene, ob, false);
2516}
2517
2518/* Checks if there are any supported deformation modifiers active */
2519static bool sculpt_modifiers_active(const Scene *scene, const Sculpt *sd, Object *ob)
2520{
2521 const Mesh &mesh = *static_cast<Mesh *>(ob->data);
2522
2523 if (ob->sculpt->bm || BKE_sculpt_multires_active(scene, ob)) {
2524 return false;
2525 }
2526
2527 /* Non-locked shape keys could be handled in the same way as deformed mesh. */
2528 if ((ob->shapeflag & OB_SHAPE_LOCK) == 0 && mesh.key && ob->shapenr) {
2529 return true;
2530 }
2531
2532 VirtualModifierData virtual_modifier_data;
2533 for (ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtual_modifier_data); md;
2534 md = md->next)
2535 {
2536 const ModifierTypeInfo *mti = BKE_modifier_get_info(static_cast<ModifierType>(md->type));
2538 continue;
2539 }
2540 if (md->type == eModifierType_Multires && (ob->mode & OB_MODE_SCULPT)) {
2541 MultiresModifierData *mmd = reinterpret_cast<MultiresModifierData *>(md);
2543 continue;
2544 }
2545 }
2546 /* Exception for shape keys because we can edit those. */
2547 if (md->type == eModifierType_ShapeKey) {
2548 continue;
2549 }
2550
2551 if (mti->type == ModifierTypeType::OnlyDeform) {
2552 return true;
2553 }
2554 if ((sd->flags & SCULPT_ONLY_DEFORM) == 0) {
2555 return true;
2556 }
2557 }
2558
2559 return false;
2560}
2561
2562static void sculpt_update_object(Depsgraph *depsgraph,
2563 Object *ob,
2564 Object *ob_eval,
2565 bool is_paint_tool)
2566{
2567 using namespace blender;
2568 using namespace blender::bke;
2570 Sculpt *sd = scene->toolsettings->sculpt;
2571 SculptSession &ss = *ob->sculpt;
2572 Mesh *mesh_orig = BKE_object_get_original_mesh(ob);
2573 /* Use the "unchecked" function, because this code also runs as part of the depsgraph node that
2574 * evaluates the object's geometry. So from perspective of the depsgraph, the mesh is not fully
2575 * evaluated yet. */
2576 Mesh *mesh_eval = BKE_object_get_evaluated_mesh_unchecked(ob_eval);
2577 MultiresModifierData *mmd = sculpt_multires_modifier_get(scene, ob, true);
2578
2579 BLI_assert(mesh_eval != nullptr);
2580
2581 /* This is for handling a newly opened file with no object visible,
2582 * causing `mesh_eval == nullptr`. */
2583 if (mesh_eval == nullptr) {
2584 return;
2585 }
2586
2588
2589 ss.building_vp_handle = false;
2590
2591 ss.shapekey_active = (mmd == nullptr) ? BKE_keyblock_from_object(ob) : nullptr;
2592
2593 /* NOTE: Weight pPaint require mesh info for loop lookup, but it never uses multires code path,
2594 * so no extra checks is needed here. */
2595 if (mmd) {
2596 ss.multires.active = true;
2597 ss.multires.modifier = mmd;
2598 ss.multires.level = mmd->sculptlvl;
2599 }
2600 else {
2601 ss.multires.active = false;
2602 ss.multires.modifier = nullptr;
2603 ss.multires.level = 0;
2604 }
2605
2606 ss.subdiv_ccg = mesh_eval->runtime->subdiv_ccg.get();
2607
2609
2610 if (ss.deform_modifiers_active) {
2611 /* Painting doesn't need crazyspace, use already evaluated mesh coordinates if possible. */
2612 bool used_me_eval = false;
2613
2615 const Mesh *me_eval_deform = BKE_object_get_mesh_deform_eval(ob_eval);
2616
2617 /* If the fully evaluated mesh has the same topology as the deform-only version, use it.
2618 * This matters because crazyspace evaluation is very restrictive and excludes even modifiers
2619 * that simply recompute vertex weights (which can even include Geometry Nodes). */
2620 if (me_eval_deform->faces_num == mesh_eval->faces_num &&
2621 me_eval_deform->corners_num == mesh_eval->corners_num &&
2622 me_eval_deform->verts_num == mesh_eval->verts_num)
2623 {
2625
2626 BLI_assert(me_eval_deform->verts_num == mesh_orig->verts_num);
2627
2628 ss.deform_cos = mesh_eval->vert_positions();
2630
2631 used_me_eval = true;
2632 }
2633 }
2634
2635 /* We depend on the deform coordinates not being updated in the middle of a stroke. This array
2636 * eventually gets cleared inside BKE_sculpt_update_object_before_eval.
2637 * See #126713 for more information. */
2638 if (ss.deform_cos.is_empty() && !used_me_eval) {
2640
2643
2644 for (blender::float3x3 &matrix : ss.deform_imats) {
2645 matrix = blender::math::invert(matrix);
2646 }
2647 }
2648 }
2649 else {
2651 }
2652
2653 if (ss.shapekey_active != nullptr && ss.deform_cos.is_empty()) {
2654 ss.deform_cos = Span(static_cast<const float3 *>(ss.shapekey_active->data),
2655 mesh_orig->verts_num);
2656 }
2657
2658 /* if pbvh is deformed, key block is already applied to it */
2659 if (ss.shapekey_active) {
2660 if (ss.deform_cos.is_empty()) {
2661 const Span key_data(static_cast<const float3 *>(ss.shapekey_active->data),
2662 mesh_orig->verts_num);
2663
2664 if (key_data.data() != nullptr) {
2666 if (ss.deform_cos.is_empty()) {
2667 ss.deform_cos = key_data;
2668 }
2669 }
2670 }
2671 }
2672
2673 if (is_paint_tool) {
2674 /* We should rebuild the PBVH_pixels when painting canvas changes.
2675 *
2676 * The relevant changes are stored/encoded in the paint canvas key.
2677 * These include the active uv map, and resolutions. */
2678 if (USER_EXPERIMENTAL_TEST(&U, use_sculpt_texture_paint)) {
2679 char *paint_canvas_key = BKE_paint_canvas_key_get(&scene->toolsettings->paint_mode, ob);
2680 if (ss.last_paint_canvas_key == nullptr ||
2681 !STREQ(paint_canvas_key, ss.last_paint_canvas_key))
2682 {
2684 ss.last_paint_canvas_key = paint_canvas_key;
2686 }
2687 else {
2688 MEM_freeN(paint_canvas_key);
2689 }
2690 }
2691
2692 /* We could be more precise when we have access to the active tool. */
2693 const bool use_paint_slots = (ob->mode & OB_MODE_SCULPT) != 0;
2694 if (use_paint_slots) {
2696 }
2697 }
2698
2699 /* This solves a crash when running a sculpt brush in background mode, because there is no redraw
2700 * after entering sculpt mode to make sure normals are allocated. Recalculating normals with
2701 * every brush step is too expensive currently. */
2703}
2704
2706{
2707 using namespace blender;
2708 /* Update before mesh evaluation in the dependency graph. */
2709 Object *ob_orig = DEG_get_original(ob_eval);
2710 SculptSession *ss = ob_orig->sculpt;
2711 if (!ss) {
2712 return;
2713 }
2714 if (ss->building_vp_handle) {
2715 return;
2716 }
2717
2719
2720 if (!ss->cache && !ss->filter_cache && !ss->expand_cache) {
2721 /* Avoid performing the following normal update for Multires, as it causes race conditions
2722 * and other intermittent crashes with shared meshes.
2723 * See !125268 and #125157 for more information. */
2724 if (pbvh && pbvh->type() != blender::bke::pbvh::Type::Grids) {
2725 /* pbvh::Tree nodes may contain dirty normal tags. To avoid losing that information when
2726 * the pbvh::Tree is deleted, make sure all tagged geometry normals are up to date.
2727 * See #122947 for more information. */
2729 }
2730 /* We free pbvh on changes, except in the middle of drawing a stroke
2731 * since it can't deal with changing PVBH node organization, we hope
2732 * topology does not change in the meantime .. weak. */
2734
2736
2737 /* In vertex/weight paint, force maps to be rebuilt. */
2739 }
2740 else if (pbvh) {
2741 IndexMaskMemory memory;
2742 const IndexMask node_mask = bke::pbvh::all_leaf_nodes(*pbvh, memory);
2743 pbvh->tag_positions_changed(node_mask);
2744 switch (pbvh->type()) {
2745 case bke::pbvh::Type::Mesh: {
2747 node_mask.foreach_index([&](const int i) { BKE_pbvh_node_mark_update(nodes[i]); });
2748 break;
2749 }
2752 node_mask.foreach_index([&](const int i) { BKE_pbvh_node_mark_update(nodes[i]); });
2753 break;
2754 }
2757 node_mask.foreach_index([&](const int i) { BKE_pbvh_node_mark_update(nodes[i]); });
2758 break;
2759 }
2760 }
2761 }
2762}
2763
2765{
2766 /* Update after mesh evaluation in the dependency graph, to rebuild pbvh::Tree or
2767 * other data when modifiers change the mesh. */
2768 Object *ob_orig = DEG_get_original(ob_eval);
2769
2770 sculpt_update_object(depsgraph, ob_orig, ob_eval, false);
2771}
2772
2774{
2775 using namespace blender;
2776 using namespace blender::bke;
2777 Mesh *orig_me = BKE_object_get_original_mesh(object);
2778
2779 if (BKE_color_attribute_supported(*orig_me, orig_me->active_color_attribute)) {
2780 return;
2781 }
2782
2783 AttributeOwner owner = AttributeOwner::from_id(&orig_me->id);
2784 const std::string unique_name = BKE_attribute_calc_unique_name(owner, "Color");
2785 if (!orig_me->attributes_for_write().add(
2787 {
2788 return;
2789 }
2790
2794 BKE_mesh_tessface_clear(orig_me);
2795}
2796
2797void BKE_sculpt_update_object_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
2798{
2799 BLI_assert(ob_orig == DEG_get_original(ob_orig));
2800
2801 Object *ob_eval = DEG_get_evaluated(depsgraph, ob_orig);
2802
2803 sculpt_update_object(depsgraph, ob_orig, ob_eval, is_paint_tool);
2804}
2805
2807 Main *bmain,
2808 Object *ob,
2810{
2811 using namespace blender;
2812 using namespace blender::bke;
2813 Mesh *mesh = static_cast<Mesh *>(ob->data);
2814 const OffsetIndices faces = mesh->faces();
2815 const Span<int> corner_verts = mesh->corner_verts();
2816 MutableAttributeAccessor attributes = mesh->attributes_for_write();
2817
2818 /* if multires is active, create a grid paint mask layer if there
2819 * isn't one already */
2820 if (mmd && !CustomData_has_layer(&mesh->corner_data, CD_GRID_PAINT_MASK)) {
2821 int level = max_ii(1, mmd->sculptlvl);
2822 int gridsize = CCG_grid_size(level);
2823 int gridarea = gridsize * gridsize;
2824
2825 GridPaintMask *gmask = static_cast<GridPaintMask *>(CustomData_add_layer(
2826 &mesh->corner_data, CD_GRID_PAINT_MASK, CD_SET_DEFAULT, mesh->corners_num));
2827
2828 for (int i = 0; i < mesh->corners_num; i++) {
2829 GridPaintMask *gpm = &gmask[i];
2830
2831 gpm->level = level;
2832 gpm->data = MEM_calloc_arrayN<float>(gridarea, "GridPaintMask.data");
2833 }
2834
2835 /* If vertices already have mask, copy into multires data. */
2836 if (const VArray<float> mask = *attributes.lookup<float>(".sculpt_mask", AttrDomain::Point)) {
2837 const VArraySpan<float> mask_span(mask);
2838 for (const int i : faces.index_range()) {
2839 const IndexRange face = faces[i];
2840
2841 /* Mask center. */
2842 float avg = 0.0f;
2843 for (const int vert : corner_verts.slice(face)) {
2844 avg += mask_span[vert];
2845 }
2846 avg /= float(face.size());
2847
2848 /* Fill in multires mask corner. */
2849 for (const int corner : face) {
2850 GridPaintMask *gpm = &gmask[corner];
2851 const int vert = corner_verts[corner];
2852 const int prev = corner_verts[mesh::face_corner_prev(face, corner)];
2853 const int next = corner_verts[mesh::face_corner_next(face, corner)];
2854
2855 gpm->data[0] = avg;
2856 gpm->data[1] = (mask_span[vert] + mask_span[next]) * 0.5f;
2857 gpm->data[2] = (mask_span[vert] + mask_span[prev]) * 0.5f;
2858 gpm->data[3] = mask_span[vert];
2859 }
2860 }
2861 }
2862 /* The evaluated multires CCG must be updated to contain the new data. */
2864 if (depsgraph) {
2866 }
2867 }
2868 else {
2869 attributes.add<float>(".sculpt_mask", AttrDomain::Point, AttributeInitDefaultValue());
2870 }
2871}
2872
2883
2885{
2888
2889 Sculpt *sd = scene->toolsettings->sculpt;
2890
2891 const Sculpt *defaults = DNA_struct_default_get(Sculpt);
2892
2893 /* We have file versioning code here for historical
2894 * reasons. Don't add more checks here, do it properly
2895 * in blenloader.
2896 */
2897 if (sd->automasking_start_normal_limit == 0.0f) {
2900
2903 }
2904
2905 if (sd->detail_percent == 0.0f) {
2906 sd->detail_percent = defaults->detail_percent;
2907 }
2908 if (sd->constant_detail == 0.0f) {
2909 sd->constant_detail = defaults->constant_detail;
2910 }
2911 if (sd->detail_size == 0.0f) {
2912 sd->detail_size = defaults->detail_size;
2913 }
2914
2915 /* Set sane default tiling offsets. */
2916 if (!sd->paint.tile_offset[0]) {
2917 sd->paint.tile_offset[0] = 1.0f;
2918 }
2919 if (!sd->paint.tile_offset[1]) {
2920 sd->paint.tile_offset[1] = 1.0f;
2921 }
2922 if (!sd->paint.tile_offset[2]) {
2923 sd->paint.tile_offset[2] = 1.0f;
2924 }
2925
2928 }
2929}
2930
2931static bool check_sculpt_object_deformed(Object *object, const bool for_construction)
2932{
2933 bool deformed = false;
2934
2935 /* Active modifiers means extra deformation, which can't be handled correct
2936 * on birth of pbvh::Tree and sculpt "layer" levels, so use pbvh::Tree only for internal brush
2937 * stuff and show final evaluated mesh so user would see actual object shape. */
2938 deformed |= object->sculpt->deform_modifiers_active;
2939
2940 if (for_construction) {
2941 deformed |= object->sculpt->shapekey_active != nullptr;
2942 }
2943 else {
2944 /* As in case with modifiers, we can't synchronize deformation made against
2945 * pbvh::Tree and non-locked keyblock, so also use pbvh::Tree only for brushes and
2946 * final DM to give final result to user. */
2947 deformed |= object->sculpt->shapekey_active && (object->shapeflag & OB_SHAPE_LOCK) == 0;
2948 }
2949
2950 return deformed;
2951}
2952
2954{
2955 using namespace blender;
2956 using namespace blender::bke;
2957
2958 const AttributeAccessor attributes = mesh.attributes();
2959 const VArray<bool> hide_poly = *attributes.lookup_or_default<bool>(
2960 ".hide_poly", AttrDomain::Face, false);
2961 if (hide_poly.is_single() && !hide_poly.get_internal_single()) {
2963 return;
2964 }
2965
2966 const OffsetIndices<int> faces = mesh.faces();
2967
2968 const VArraySpan<bool> hide_poly_span(hide_poly);
2969 BitGroupVector<> &grid_hidden = BKE_subdiv_ccg_grid_hidden_ensure(subdiv_ccg);
2970 threading::parallel_for(faces.index_range(), 1024, [&](const IndexRange range) {
2971 for (const int i : range) {
2972 const bool face_hidden = hide_poly_span[i];
2973 for (const int corner : faces[i]) {
2974 grid_hidden[corner].set_all(face_hidden);
2975 }
2976 }
2977 });
2978}
2979
2980namespace blender::bke {
2981
2982static std::unique_ptr<pbvh::Tree> build_pbvh_for_dynamic_topology(Object *ob)
2983{
2984 BMesh &bm = *ob->sculpt->bm;
2985 BM_data_layer_ensure_named(&bm, &bm.vdata, CD_PROP_INT32, ".sculpt_dyntopo_node_id_vertex");
2986 BM_data_layer_ensure_named(&bm, &bm.pdata, CD_PROP_INT32, ".sculpt_dyntopo_node_id_face");
2987
2988 return std::make_unique<pbvh::Tree>(pbvh::Tree::from_bmesh(bm));
2989}
2990
2991static std::unique_ptr<pbvh::Tree> build_pbvh_from_regular_mesh(Object *ob,
2992 const Mesh *me_eval_deform)
2993{
2995 std::unique_ptr<pbvh::Tree> pbvh = std::make_unique<pbvh::Tree>(pbvh::Tree::from_mesh(mesh));
2996
2997 const bool is_deformed = check_sculpt_object_deformed(ob, true);
2998 if (is_deformed && me_eval_deform != nullptr) {
2999 BKE_pbvh_vert_coords_apply(*pbvh, me_eval_deform->vert_positions());
3000 }
3001
3002 return pbvh;
3003}
3004
3005static std::unique_ptr<pbvh::Tree> build_pbvh_from_ccg(Object *ob, SubdivCCG &subdiv_ccg)
3006{
3007 const Mesh &base_mesh = *BKE_mesh_from_object(ob);
3008 BKE_sculpt_sync_face_visibility_to_grids(base_mesh, subdiv_ccg);
3009
3010 return std::make_unique<pbvh::Tree>(pbvh::Tree::from_grids(base_mesh, subdiv_ccg));
3011}
3012
3013} // namespace blender::bke
3014
3015namespace blender::bke::object {
3016
3018{
3019 if (pbvh::Tree *pbvh = pbvh_get(object)) {
3020 return *pbvh;
3021 }
3022 BLI_assert(object.sculpt != nullptr);
3023 SculptSession &ss = *object.sculpt;
3024
3025 if (ss.bm != nullptr) {
3026 /* Sculpting on a BMesh (dynamic-topology) gets a special pbvh::Tree. */
3028 }
3029 else {
3030 Object *object_eval = DEG_get_evaluated(&depsgraph, &object);
3031 Mesh *mesh_eval = static_cast<Mesh *>(object_eval->data);
3032 if (mesh_eval->runtime->subdiv_ccg != nullptr) {
3033 ss.pbvh = build_pbvh_from_ccg(&object, *mesh_eval->runtime->subdiv_ccg);
3034 }
3035 else {
3036 const Mesh *me_eval_deform = BKE_object_get_mesh_deform_eval(object_eval);
3037 ss.pbvh = build_pbvh_from_regular_mesh(&object, me_eval_deform);
3038 }
3039 }
3040
3041 return *object::pbvh_get(object);
3042}
3043
3044const pbvh::Tree *pbvh_get(const Object &object)
3045{
3046 if (!object.sculpt) {
3047 return nullptr;
3048 }
3049 return object.sculpt->pbvh.get();
3050}
3051
3053{
3054 BLI_assert(object.type == OB_MESH);
3055 if (!object.sculpt) {
3056 return nullptr;
3057 }
3058 return object.sculpt->pbvh.get();
3059}
3060
3061} // namespace blender::bke::object
3062
3064{
3065 return object->sculpt && object->sculpt->bm;
3066}
3067
3069{
3070 SculptSession *ss = ob->sculpt;
3071 if (ss == nullptr || ss->mode_type != OB_MODE_SCULPT) {
3072 return false;
3073 }
3075 if (!pbvh) {
3076 return false;
3077 }
3078
3079 if (pbvh->type() == blender::bke::pbvh::Type::Mesh) {
3080 /* Regular mesh only draws from pbvh::Tree without modifiers and shape keys, or for
3081 * external engines that do not have access to the pbvh::Tree like Eevee does. */
3082 const bool external_engine = rv3d && rv3d->view_render != nullptr;
3083 return !(ss->shapekey_active || ss->deform_modifiers_active || external_engine);
3084 }
3085
3086 /* Multires and dyntopo always draw directly from the pbvh::Tree. */
3087 return true;
3088}
3089
3090/* Returns the Face Set random color for rendering in the overlay given its ID and a color seed. */
3091#define GOLDEN_RATIO_CONJUGATE 0.618033988749895f
3092void BKE_paint_face_set_overlay_color_get(const int face_set, const int seed, uchar r_color[4])
3093{
3094 float rgba[4];
3095 float random_mod_hue = GOLDEN_RATIO_CONJUGATE * (face_set + (seed % 10));
3096 random_mod_hue = random_mod_hue - floorf(random_mod_hue);
3097 const float random_mod_sat = BLI_hash_int_01(face_set + seed + 1);
3098 const float random_mod_val = BLI_hash_int_01(face_set + seed + 2);
3099 hsv_to_rgb(random_mod_hue,
3100 0.6f + (random_mod_sat * 0.25f),
3101 1.0f - (random_mod_val * 0.35f),
3102 &rgba[0],
3103 &rgba[1],
3104 &rgba[2]);
3105 rgba_float_to_uchar(r_color, rgba);
3106}
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:370
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:985
bool BKE_brush_has_cube_tip(const Brush *brush, PaintMode paint_mode)
Definition brush.cc:1707
int CCG_grid_factor(int low_level, int high_level)
Definition BKE_ccg.hh:110
int CCG_grid_xy_to_index(const int grid_size, const int x, const int y)
Definition BKE_ccg.hh:73
int CCG_grid_size(const int level)
Definition BKE_ccg.hh:104
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, CurveMapSlopeType slope)
float BKE_curvemapping_evaluateF(const CurveMapping *cumap, int cur, float value)
void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap)
CurveMapping * BKE_curvemapping_copy(const CurveMapping *cumap)
void BKE_curvemapping_init(CurveMapping *cumap)
CurveMapping * BKE_curvemapping_add(int tot, float minx, float miny, float maxx, float maxy)
Definition colortools.cc:89
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:1056
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition BKE_idtype.hh:49
IDTypeInfo IDType_ID_PAL
Definition paint.cc:156
IDTypeInfo IDType_ID_PC
Definition paint.cc:226
void BKE_image_pool_free(ImagePool *pool)
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1889
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:358
void id_fake_user_set(ID *id)
Definition lib_id.cc:396
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:1056
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1514
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void id_us_min(ID *id)
Definition lib_id.cc:366
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2631
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)
std::variant< std::monostate, int, BMVert * > ActiveVert
Definition BKE_paint.hh:360
void BKE_sculpt_sync_face_visibility_to_grids(const Mesh &mesh, SubdivCCG &subdiv_ccg)
Definition paint.cc:2953
void BKE_sculptsession_free_vwpaint_data(SculptSession *ss)
Definition paint.cc:2247
ePaintOverlayControlFlags
Definition BKE_paint.hh:87
@ PAINT_OVERLAY_INVALID_CURVE
Definition BKE_paint.hh:90
@ PAINT_OVERLAY_INVALID_TEXTURE_SECONDARY
Definition BKE_paint.hh:89
@ PAINT_OVERLAY_OVERRIDE_CURSOR
Definition BKE_paint.hh:91
@ PAINT_OVERLAY_INVALID_TEXTURE_PRIMARY
Definition BKE_paint.hh:88
@ PAINT_OVERLAY_OVERRIDE_SECONDARY
Definition BKE_paint.hh:93
@ PAINT_OVERLAY_OVERRIDE_PRIMARY
Definition BKE_paint.hh:92
CurveMapping * BKE_sculpt_default_cavity_curve()
Definition scene.cc:131
CurveMapping * BKE_paint_default_curve()
Definition scene.cc:146
#define PAINT_OVERRIDE_MASK
Definition BKE_paint.hh:97
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
Definition paint.cc:2513
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:1698
void BKE_pbvh_node_mark_update(blender::bke::pbvh::Node &node)
Definition pbvh.cc:1693
void BKE_pbvh_vert_coords_apply(blender::bke::pbvh::Tree &pbvh, blender::Span< blender::float3 > vert_positions)
Definition pbvh.cc:2532
PaintMode
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2626
blender::BitGroupVector & BKE_subdiv_ccg_grid_hidden_ensure(SubdivCCG &subdiv_ccg)
void BKE_subdiv_ccg_grid_hidden_free(SubdivCCG &subdiv_ccg)
#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
MINLINE 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_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 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:5828
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:1181
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:694
@ INDEX_ID_PC
Definition DNA_ID.h:1345
@ INDEX_ID_PAL
Definition DNA_ID.h:1344
#define FILTER_ID_PC
Definition DNA_ID.h:1216
#define FILTER_ID_PAL
Definition DNA_ID.h:1215
@ 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_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)
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
#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:497
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:256
const T * data() const
Definition BLI_array.hh:312
bool is_empty() const
Definition BLI_array.hh:264
static AttributeOwner from_id(ID *id)
Definition attribute.cc:44
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_or_default(StringRef attribute_id, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GAttributeReader lookup(const StringRef attribute_id) const
bool add(const StringRef attribute_id, const AttrDomain domain, const AttrType 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:471
static Tree from_mesh(const Mesh &mesh)
Definition pbvh.cc:306
nullptr float
#define offsetof(t, d)
uint col
float distance(VecOp< float, D >, VecOp< float, D >) RET
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:306
int face_corner_next(const IndexRange face, const int corner)
Definition BKE_mesh.hh:315
pbvh::Tree & pbvh_ensure(Depsgraph &depsgraph, Object &object)
Definition paint.cc:3017
pbvh::Tree * pbvh_get(Object &object)
Definition paint.cc:3052
void update_normals(const Depsgraph &depsgraph, Object &object_orig, Tree &pbvh)
Definition pbvh.cc:1257
IndexMask all_leaf_nodes(const Tree &pbvh, IndexMaskMemory &memory)
Definition pbvh.cc:2628
void update_normals_from_eval(Object &object_eval, Tree &pbvh)
Definition pbvh.cc:1264
Span< float3 > vert_positions_eval(const Depsgraph &depsgraph, const Object &object_orig)
Definition pbvh.cc:1040
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:2991
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:3005
static std::unique_ptr< pbvh::Tree > build_pbvh_for_dynamic_topology(Object *ob)
Definition paint.cc:2982
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:665
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:1551
void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)
Definition paint.cc:2764
PaletteColor * BKE_palette_color_add(Palette *palette)
Definition paint.cc:1433
bool BKE_paint_eraser_brush_set_default(Main *bmain, Paint *paint)
Definition paint.cc:1221
bool BKE_paint_select_grease_pencil_test(const Object *ob)
Definition paint.cc:1654
void BKE_paint_cavity_curve_preset(Paint *paint, int preset)
Definition paint.cc:1677
void BKE_paint_set_overlay_override(eOverlayFlags flags)
Definition paint.cc:303
static float paint_rake_rotation_spacing(const Paint &, const Brush &brush)
Definition paint.cc:2164
void BKE_paint_stroke_get_average(const Paint *paint, const Object *ob, float stroke[3])
Definition paint.cc:1952
Brush * BKE_paint_eraser_brush(Paint *paint)
Definition paint.cc:1172
const EnumPropertyItem * BKE_paint_get_tool_enum_from_paintmode(const PaintMode mode)
Definition paint.cc:409
static bool paint_brush_update_from_asset_reference(Main *bmain, Paint *paint)
Definition paint.cc:615
void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, CurveMapping *curve)
Definition paint.cc:279
float paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y)
Definition paint.cc:2155
static void palette_foreach_working_space_color(ID *id, const IDTypeForeachColorFunctionCallback &fn)
Definition paint.cc:118
bool BKE_paint_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
Definition paint.cc:1105
void BKE_sculpt_sync_face_visibility_to_grids(const Mesh &mesh, SubdivCCG &subdiv_ccg)
Definition paint.cc:2953
void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex)
Definition paint.cc:259
void BKE_paint_copy(const Paint *src, Paint *dst, const int flag)
Definition paint.cc:1877
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:1964
void paint_update_brush_rake_rotation(Paint &paint, const Brush &brush, float rotation)
Definition paint.cc:2169
static AssetWeakReference * paint_brush_asset_reference_ptr_from_essentials(const char *name, const PaintMode paint_mode)
Definition paint.cc:757
static bool paint_rake_rotation_active(const MTex &mtex)
Definition paint.cc:2182
static bool sculpt_modifiers_active(const Scene *scene, const Sculpt *sd, Object *ob)
Definition paint.cc:2519
bool paint_calculate_rake_rotation(Paint &paint, const Brush &brush, const float mouse_pos[2], const PaintMode paint_mode, bool stroke_has_started)
Definition paint.cc:2193
static MultiresModifierData * sculpt_multires_modifier_get(const Scene *scene, Object *ob, const bool auto_create_mdisps)
Definition paint.cc:2460
bool BKE_paint_always_hide_test(const Object *ob)
Definition paint.cc:1671
PaintCurve * BKE_paint_curve_add(Main *bmain, const char *name)
Definition paint.cc:1369
void BKE_sculptsession_bm_to_me(Object *ob)
Definition paint.cc:2275
std::optional< int > BKE_paint_get_brush_type_from_obmode(const Brush *brush, const eObjectMode ob_mode)
Definition paint.cc:1312
static bool check_sculpt_object_deformed(Object *object, const bool for_construction)
Definition paint.cc:2931
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:3068
void BKE_paint_brushes_ensure(Main *bmain, Paint *paint)
Definition paint.cc:1823
static AssetWeakReference * asset_reference_create_from_brush(Brush *brush)
Definition paint.cc:663
static int palettecolor_compare_luminance(const void *a1, const void *a2)
Definition paint.cc:1556
void BKE_sculptsession_free(Object *ob)
Definition paint.cc:2332
void BKE_paint_settings_foreach_mode(ToolSettings *ts, blender::FunctionRef< void(Paint *paint)> fn)
Definition paint.cc:1923
static void palette_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
Definition paint.cc:99
void BKE_sculptsession_free_deformMats(SculptSession *ss)
Definition paint.cc:2239
bool BKE_paint_select_elem_test(const Object *ob)
Definition paint.cc:1665
Paint * BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
Definition paint.cc:437
ePaintOverlayControlFlags BKE_paint_get_overlay_flags()
Definition paint.cc:298
static bool paint_eraser_brush_set_from_asset_reference(Main *bmain, Paint *paint)
Definition paint.cc:1142
bool BKE_paint_select_vert_test(const Object *ob)
Definition paint.cc:1647
void BKE_palette_color_remove(Palette *palette, PaletteColor *color)
Definition paint.cc:1394
std::optional< AssetWeakReference > BKE_paint_brush_type_default_reference(const PaintMode paint_mode, std::optional< int > brush_type)
Definition paint.cc:1033
void BKE_sculptsession_free_vwpaint_data(SculptSession *ss)
Definition paint.cc:2247
void BKE_paint_previous_asset_reference_set(Paint *paint, AssetWeakReference &&asset_weak_reference)
Definition paint.cc:1111
bool paint_is_grid_face_hidden(const blender::BoundedBitSpan grid_hidden, const int gridsize, const int x, const int y)
Definition paint.cc:2129
uint BKE_paint_get_brush_type_offset_from_paintmode(const PaintMode mode)
Definition paint.cc:1284
const Brush * BKE_paint_eraser_brush_for_read(const Paint *paint)
Definition paint.cc:1177
void BKE_sculpt_update_object_before_eval(Object *ob_eval)
Definition paint.cc:2705
void BKE_palette_sort_hsv(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1477
static int palettecolor_compare_svh(const void *a1, const void *a2)
Definition paint.cc:1482
void BKE_paint_reset_overlay_invalid(ePaintOverlayControlFlags flag)
Definition paint.cc:321
void BKE_palette_sort_svh(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1514
static void paint_curve_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
Definition paint.cc:187
static void paint_runtime_init(const ToolSettings *ts, Paint *paint)
Definition paint.cc:1233
void BKE_paint_free(Paint *paint)
Definition paint.cc:1855
Brush * BKE_paint_brush_from_essentials(Main *bmain, const PaintMode paint_mode, const char *name)
Definition paint.cc:791
void BKE_palette_sort_luminance(tPaletteColorHSV *color_array, const int totcol)
Definition paint.cc:1574
const Brush * BKE_paint_brush_for_read(const Paint *paint)
Definition paint.cc:650
bool BKE_paint_eraser_brush_set(Paint *paint, Brush *brush)
Definition paint.cc:1182
static void palette_free_data(ID *id)
Definition paint.cc:111
static void palette_undo_preserve(BlendLibReader *, ID *id_new, ID *id_old)
Definition paint.cc:145
static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition paint.cc:210
Paint * BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:374
void BKE_paint_previous_asset_reference_clear(Paint *paint)
Definition paint.cc:1120
bool BKE_paint_use_unified_color(const Paint *paint)
Definition paint.cc:601
eObjectMode BKE_paint_object_mode_from_paintmode(const PaintMode mode)
Definition paint.cc:1694
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
Definition paint.cc:2513
static void paint_brush_default_essentials_name_get(const PaintMode paint_mode, std::optional< int > brush_type, blender::StringRefNull *r_name, blender::StringRefNull *r_eraser_name=nullptr)
Definition paint.cc:825
Brush * BKE_paint_eraser_brush_from_essentials(Main *bmain, const PaintMode paint_mode, const char *name)
Definition paint.cc:1207
static void paint_curve_free_data(ID *id)
Definition paint.cc:202
void BKE_sculpt_update_object_for_edit(Depsgraph *depsgraph, Object *ob_orig, bool is_paint_tool)
Definition paint.cc:2797
#define GOLDEN_RATIO_CONJUGATE
Definition paint.cc:3091
void BKE_sculpt_color_layer_create_if_needed(Object *object)
Definition paint.cc:2773
void BKE_palette_clear(Palette *palette)
Definition paint.cc:1410
Paint * BKE_paint_get_active_from_context(const bContext *C)
Definition paint.cc:476
bool paint_is_bmesh_face_hidden(const BMFace *f)
Definition paint.cc:2140
void BKE_sculptsession_bm_to_me_for_render(Object *object)
Definition paint.cc:2310
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
Definition paint.cc:1738
static ePaintOverlayControlFlags overlay_flags
Definition paint.cc:257
bool BKE_paint_brush_set_default(Main *bmain, Paint *paint)
Definition paint.cc:1099
Palette * BKE_palette_add(Main *bmain, const char *name)
Definition paint.cc:1427
static std::optional< AssetWeakReference > paint_brush_asset_reference_from_essentials(const char *name, const PaintMode paint_mode)
Definition paint.cc:774
static void sculpt_update_object(Depsgraph *depsgraph, Object *ob, Object *ob_eval, bool is_paint_tool)
Definition paint.cc:2562
static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition paint.cc:129
bool BKE_palette_from_hash(Main *bmain, GHash *color_table, const char *name)
Definition paint.cc:1580
bool BKE_paint_eraser_brush_set_essentials(Main *bmain, Paint *paint, const char *name)
Definition paint.cc:1227
bool BKE_paint_can_use_brush(const Paint *paint, const Brush *brush)
Definition paint.cc:655
static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id)
Definition paint.cc:220
void BKE_sculptsession_free_pbvh(Object &object)
Definition paint.cc:2286
bool BKE_paint_brush_set(Main *bmain, Paint *paint, const AssetWeakReference &brush_asset_reference)
Definition paint.cc:674
static int palettecolor_compare_vhs(const void *a1, const void *a2)
Definition paint.cc:1519
static void palette_init_data(ID *id)
Definition paint.cc:89
static int palettecolor_compare_hsv(const void *a1, const void *a2)
Definition paint.cc:1445
static void paint_eraser_brush_set_essentials_reference(Paint *paint, const char *name)
Definition paint.cc:814
void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *paint)
Definition paint.cc:2064
static void sculptsession_bm_to_me_update_data_only(Object *ob)
Definition paint.cc:2262
static void paint_brush_set_default_reference(Paint *paint, const bool do_regular=true, const bool do_eraser=true)
Definition paint.cc:1046
void BKE_paint_face_set_overlay_color_get(const int face_set, const int seed, uchar r_color[4])
Definition paint.cc:3092
static void paint_brush_set_essentials_reference(Paint *paint, const char *name)
Definition paint.cc:803
std::optional< int > BKE_paint_get_brush_type_from_paintmode(const Brush *brush, const PaintMode mode)
Definition paint.cc:1340
Brush * BKE_paint_brush(Paint *paint)
Definition paint.cc:645
void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene)
Definition paint.cc:2884
void BKE_palette_color_set(PaletteColor *color, const float rgb[3])
Definition paint.cc:1416
Palette * BKE_paint_palette(Paint *paint)
Definition paint.cc:1375
void BKE_paint_palette_set(Paint *paint, Palette *palette)
Definition paint.cc:1380
void BKE_paint_curve_clamp_endpoint_add_index(PaintCurve *pc, const int add_index)
Definition paint.cc:1389
static const char * paint_brush_essentials_asset_file_name_from_paint_mode(const PaintMode paint_mode)
Definition paint.cc:729
bool BKE_palette_is_empty(const Palette *palette)
Definition paint.cc:1440
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
Definition paint.cc:505
static void paint_init_data(Paint &paint)
Definition paint.cc:1716
static void palette_blend_read_data(BlendDataReader *reader, ID *id)
Definition paint.cc:139
void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, Main *bmain, Object *ob, MultiresModifierData *mmd)
Definition paint.cc:2806
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const bool ensure_brushes)
Definition paint.cc:1840
bool BKE_object_sculpt_use_dyntopo(const Object *object)
Definition paint.cc:3063
void BKE_paint_brushes_set_default_references(ToolSettings *ts)
Definition paint.cc:1070
void BKE_palette_color_sync_legacy(PaletteColor *color)
Definition paint.cc:1422
bool BKE_paint_select_face_test(const Object *ob)
Definition paint.cc:1640
PaintMode BKE_paintmode_get_from_tool(const bToolRef *tref)
Definition paint.cc:561
void BKE_paint_brushes_validate(Main *bmain, Paint *paint)
Definition paint.cc:1125
void BKE_paint_invalidate_overlay_all()
Definition paint.cc:292
void BKE_paint_blend_write(BlendWriter *writer, Paint *paint)
Definition paint.cc:2020
void BKE_sculpt_cavity_curves_ensure(Sculpt *sd)
Definition paint.cc:2873
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
Definition paint.cc:326
const char * name
#define floorf
#define atan2f
const EnumPropertyItem rna_enum_brush_weight_brush_type_items[]
Definition rna_brush.cc:187
const EnumPropertyItem rna_enum_brush_gpencil_sculpt_types_items[]
Definition rna_brush.cc:250
const EnumPropertyItem rna_enum_brush_image_brush_type_items[]
Definition rna_brush.cc:195
const EnumPropertyItem rna_enum_brush_sculpt_brush_type_items[]
Definition rna_brush.cc:134
const EnumPropertyItem rna_enum_brush_gpencil_vertex_types_items[]
Definition rna_brush.cc:225
const EnumPropertyItem rna_enum_brush_gpencil_weight_types_items[]
Definition rna_brush.cc:286
const EnumPropertyItem rna_enum_brush_vertex_brush_type_items[]
Definition rna_brush.cc:179
const EnumPropertyItem rna_enum_brush_gpencil_types_items[]
Definition rna_brush.cc:205
const EnumPropertyItem rna_enum_brush_curves_sculpt_brush_type_items[]
Definition rna_brush.cc:298
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_distance_falloff
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]
const blender::FunctionRef< void(float rgb[3])> single
Definition DNA_ID.h:414
IDProperty * system_properties
Definition DNA_ID.h:489
IDProperty * properties
Definition DNA_ID.h:480
void * data
char brush_angle_mode
struct Tex * tex
bool is_locked_for_linking
Definition BKE_main.hh:224
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
float tile_offset[3]
struct Brush * eraser_brush
struct UnifiedPaintSettings unified_paint_settings
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
PaintRuntimeHandle * runtime
ListBase colors
struct ViewRender * view_render
struct ToolSettings * toolsettings
blender::Array< int > fake_neighbor_index
Definition BKE_paint.hh:349
blender::ed::sculpt_paint::StrokeCache * cache
Definition BKE_paint.hh:417
BMLog * bm_log
Definition BKE_paint.hh:392
struct SculptSession::@345375365225333342236070250113232025260070150165 persistent
std::optional< int > active_grid_index
Definition BKE_paint.hh:423
blender::ed::sculpt_paint::filter::Cache * filter_cache
Definition BKE_paint.hh:418
std::optional< int > active_face_index
Definition BKE_paint.hh:422
KeyBlock * shapekey_active
Definition BKE_paint.hh:377
blender::Array< int > vert_to_edge_indices
Definition BKE_paint.hh:386
SculptVertexInfo vertex_info
Definition BKE_paint.hh:462
blender::SharedCache< blender::Vector< blender::float3 > > face_normals_deform
Definition BKE_paint.hh:412
blender::GroupedSpan< int > vert_to_edge_map
Definition BKE_paint.hh:387
SubdivCCG * subdiv_ccg
Definition BKE_paint.hh:395
blender::Array< MDeformVert > dvert_prev
Definition BKE_paint.hh:485
blender::Array< int > preview_verts
Definition BKE_paint.hh:440
ActiveVert active_vert() const
Definition paint.cc:2367
blender::Array< int > edge_to_face_offsets
Definition BKE_paint.hh:380
blender::Array< blender::float3, 0 > deform_cos
Definition BKE_paint.hh:403
blender::float3 active_vert_position(const Depsgraph &depsgraph, const Object &object) const
Definition paint.cc:2403
int last_active_vert_index() const
Definition paint.cc:2390
float * alpha_weight
Definition BKE_paint.hh:481
ImagePool * tex_pool
Definition BKE_paint.hh:415
struct SculptSession::@300305335361021334214041350300054316061376210174 multires
std::unique_ptr< blender::bke::pbvh::Tree > pbvh
Definition BKE_paint.hh:398
std::unique_ptr< SculptTopologyIslandCache > topology_island_cache
Definition BKE_paint.hh:517
char * last_paint_canvas_key
Definition BKE_paint.hh:514
blender::Array< int > vert_to_edge_offsets
Definition BKE_paint.hh:385
blender::GroupedSpan< int > edge_to_face_map
Definition BKE_paint.hh:382
blender::SharedCache< blender::Vector< blender::float3 > > vert_normals_deform
Definition BKE_paint.hh:411
struct SculptSession::@362240011116215270333121305340144315201335267314::@377352350121204263020240366015362210376116055117 wpaint
blender::ed::sculpt_paint::expand::Cache * expand_cache
Definition BKE_paint.hh:419
int active_vert_index() const
Definition paint.cc:2377
eObjectMode mode_type
Definition BKE_paint.hh:491
ActiveVert last_active_vert() const
Definition paint.cc:2372
std::optional< PersistentMultiresData > persistent_multires_data()
Definition paint.cc:2442
blender::Array< int > edge_to_face_indices
Definition BKE_paint.hh:381
blender::Array< blender::float3x3, 0 > deform_imats
Definition BKE_paint.hh:405
MultiresModifierData * modifier
Definition BKE_paint.hh:373
SculptFakeNeighbors fake_neighbors
Definition BKE_paint.hh:463
struct SculptSession::@362240011116215270333121305340144315201335267314 mode
bool building_vp_handle
Definition BKE_paint.hh:495
bool deform_modifiers_active
Definition BKE_paint.hh:401
void set_active_vert(ActiveVert vert)
Definition paint.cc:2437
void clear_active_elements(bool persist_last_active)
Definition paint.cc:2422
blender::BitVector boundary
Definition BKE_paint.hh:334
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
CurvesSculpt * curves_sculpt
GpVertexPaint * gp_vertexpaint
struct AssetWeakReference * main_brush_asset_reference
struct CurveMapping * curve_rand_value
struct CurveMapping * curve_rand_saturation
struct CurveMapping * curve_rand_hue
blender::float3 average_stroke_accum
i
Definition text_draw.cc:230
#define N_(msgid)
uint8_t flag
Definition wm_window.cc:145