Welcome to mirror list, hosted at ThFree Co, Russian Federation.

brush_engine_presets.c « intern « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d46e13ef8f1d525f19a75cb67b4f3298f448f60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
#include "MEM_guardedalloc.h"

#include "BLI_alloca.h"
#include "BLI_array.h"
#include "BLI_bitmap.h"
#include "BLI_compiler_attrs.h"
#include "BLI_compiler_compat.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
#include "BLI_rect.h"
#include "BLI_task.h"
#include "BLI_threads.h"

#include "DNA_brush_enums.h"
#include "DNA_brush_types.h"
#include "DNA_color_types.h"
#include "DNA_curveprofile_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_sculpt_brush_types.h"

#include "BKE_brush.h"
#include "BKE_colorband.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_node.h"
#include "BKE_paint.h"

#include "BKE_brush_engine.h"

static bool check_builtin_init();

#if 1
#  define namestack_push(name)
#  define namestack_pop()
#else
void namestack_push(const char *name);
void namestack_pop();
#  define namestack_head_name strdup(namestack[namestack_i].tag)
#endif

/*
Instructions to add a built-in channel:

1. Add to brush_builtin_channels
2. Add to BKE_brush_builtin_patch to insert it in old brushes (without converting data)

To enable converting to/from old data:
3. If not a boolean mapping to a bitflag: Add to brush_settings_map
4. If a boolean mapping to a bitflag: Add to brush_flags_map_len.
*/
#define ICON_NONE "NONE"

/* clang-format off */
#define MAKE_FLOAT_EX_OPEN(idname1, name1, tooltip1, value1, min1, max1, smin1, smax1) \
  {.name = name1, \
   .idname = idname1, \
   .fvalue = value1,\
   .tooltip = tooltip1, \
   .min = min1,\
   .max = max1,\
   .soft_min = smin1,\
   .soft_max = smax1,\
   .type = BRUSH_CHANNEL_FLOAT

#define MAKE_FLOAT_EX(idname, name, tooltip, value, min, max, smin, smax) \
  MAKE_FLOAT_EX_OPEN(idname, name, tooltip, value, min, max, smin, smax) }

#define MAKE_FLOAT(idname, name, tooltip, value, min, max) MAKE_FLOAT_EX(idname, name, tooltip, value, min, max, min, max)

#define MAKE_COLOR3(idname1, name1, tooltip1, r, g, b){\
  .idname = idname1, \
  .name = name1, \
  .tooltip = tooltip1, \
  .type = BRUSH_CHANNEL_VEC3,\
  .vector = {r, g, b, 1.0f},\
  .min = 0.0f, .max = 5.0f,\
  .soft_min = 0.0f, .soft_max = 1.0f,\
  .flag = BRUSH_CHANNEL_COLOR,\
}

#define MAKE_COLOR4(idname1, name1, tooltip1, r, g, b, a){\
  .idname = idname1, \
  .name = name1, \
  .tooltip = tooltip1, \
  .type = BRUSH_CHANNEL_VEC4,\
  .vector = {r, g, b, a},\
  .min = 0.0f, .max = 5.0f,\
  .soft_min = 0.0f, .soft_max = 1.0f,\
  .flag = BRUSH_CHANNEL_COLOR,\
}


#define MAKE_INT_EX_OPEN(idname1, name1, tooltip1, value1, min1, max1, smin1, smax1) \
  {.name = name1, \
   .idname = idname1, \
   .tooltip = tooltip1, \
   .min = min1,\
   .max = max1,\
   .ivalue = value1,\
   .soft_min = smin1,\
   .soft_max = smax1,\
   .type = BRUSH_CHANNEL_INT

#define MAKE_INT_EX(idname, name, tooltip, value, min, max, smin, smax) \
  MAKE_INT_EX_OPEN(idname, name, tooltip, value, min, max, smin, smax) }

#define MAKE_INT(idname, name, tooltip, value, min, max) MAKE_INT_EX(idname, name, tooltip, value, min, max, min, max)

#define MAKE_BOOL_EX_OPEN(idname1, name1, tooltip1, value1)\
  {.name = name1, \
   .idname = idname1, \
   .tooltip = tooltip1, \
   .ivalue = value1,\
   .type = BRUSH_CHANNEL_BOOL

#define MAKE_BOOL(idname, name, tooltip, value)\
  MAKE_BOOL_EX_OPEN(idname, name, tooltip, value) }


/*
This is where all the builtin brush channels are defined.
That includes per-brush enums and bitflags!
*/

/* clang-format off */
BrushChannelType brush_builtin_channels[] = {
  {
    .name = "Radius",
    .idname = "radius",
    .min = 0.001f,
    .type = BRUSH_CHANNEL_FLOAT,
    .max = 2048.0f,
    .fvalue = 50.0f,
    .soft_min = 0.1f,
    .soft_max = 1024.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0f, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },

    {
    .name = "Strength",
    .idname = "strength",
    .min = -1.0f,
    .type = BRUSH_CHANNEL_FLOAT,
    .max = 4.0f,
    .fvalue = 0.5f,
    .soft_min = 0.0f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0f, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
   {
    .name = "Alpha",
    .idname = "alpha",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0f,
    .max = 1.0f,
    .fvalue = 1.0f,
    .soft_min = 0.0f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0f, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
   },
   {
    .name = "Spacing",
    .idname = "spacing",
    .min = 1.0f,
    .type = BRUSH_CHANNEL_INT,
    .max = 500.0f,
    .fvalue = 10.0f,
    .soft_min = 1.0f,
    .soft_max = 500.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
    {
    .name = "Autosmooth",
    .idname = "autosmooth",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = -1.0f,
    .max = 4.0f,
    .soft_min = 0.0f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false, .inv = true},
    }
  },
    {
    .name = "Topology Rake",
    .idname = "topology_rake",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = -1.0f,
    .max = 4.0f,
    .soft_min = 0.0f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
  {
    .name = "Autosmooth Radius Scale",
    .idname = "autosmooth_radius_scale",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 25.0f,
    .fvalue = 1.0f,
    .soft_min = 0.1f,
    .soft_max = 4.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
  {
    .name = "Rake Radius Scale",
    .idname = "topology_rake_radius_scale",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 25.0f,
    .fvalue = 1.0f,
    .soft_min = 0.1f,
    .soft_max = 4.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
  {
    .name = "Face Set Slide",
    .idname = "fset_slide",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .fvalue = 1.0f,
    .soft_min = 0.0f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
  {
    .name = "Boundary Smooth",
    .idname = "boundary_smooth",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .soft_min = 0.1f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
   {
    .name = "Projection",
    .idname = "projection",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .soft_min = 0.1f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
   {
     .name = "Use Spacing",
     .idname = "topology_rake_use_spacing",
     .type = BRUSH_CHANNEL_BOOL,
     .ivalue = 0
   },
   {
     .name = "Use Spacing",
     .idname = "autosmooth_use_spacing",
     .type = BRUSH_CHANNEL_BOOL,
     .ivalue = 0
   },
   {
    .name = "Projection",
    .idname = "autosmooth_projection",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .soft_min = 0.1f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
  {
    .name = "Projection",
    .idname = "topology_rake_projection",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .fvalue = 0.975f,
    .soft_min = 0.1f,
    .soft_max = 1.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
    {
    .name = "Spacing",
    .idname = "topology_rake_spacing",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .fvalue = 13.0f,
    .soft_min = 0.1f,
    .soft_max = 100.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
    {
    .name = "Spacing",
    .idname = "autosmooth_spacing",
    .type = BRUSH_CHANNEL_FLOAT,
    .min = 0.0001f,
    .max = 1.0f,
    .fvalue = 13.0f,
    .soft_min = 0.1f,
    .soft_max = 100.0f,
    .mappings = {
        .pressure = {.curve = CURVE_PRESET_LINE, .factor = 1.0, .min = 0.0f, .max = 1.0f, .enabled = false},
    }
  },
  
  {
    .name = "Topology Rake Mode",
    .idname = "topology_rake_mode",
    .type = BRUSH_CHANNEL_ENUM,
    .enumdef = {
      {0, "BRUSH_DIRECTION", ICON_NONE, "Stroke", "Stroke Direction"},
      {1, "CURVATURE", ICON_NONE, "Curvature", "Follow mesh curvature"},
      {-1}
    }
  },
   {
     .name = "Automasking",
     .idname = "automasking",
     .flag = BRUSH_CHANNEL_INHERIT_IF_UNSET,
     .type = BRUSH_CHANNEL_BITMASK,
     .enumdef = {
         {BRUSH_AUTOMASKING_BOUNDARY_EDGES, "BOUNDARY_EDGE", ICON_NONE, "Boundary Edges", ""},
         {BRUSH_AUTOMASKING_BOUNDARY_FACE_SETS, "BOUNDARY_FACE_SETS", ICON_NONE, "Boundary Face Sets", ""},
         {BRUSH_AUTOMASKING_CONCAVITY, "CONCAVITY", ICON_NONE, "Concave", ""},
         {BRUSH_AUTOMASKING_INVERT_CONCAVITY, "INVERT_CONCAVITY", ICON_NONE, "Invert Concave", "Invert Concave Map"},
         {BRUSH_AUTOMASKING_FACE_SETS, "FACE_SETS", ICON_NONE, "Face Sets", ""},
         {BRUSH_AUTOMASKING_TOPOLOGY, "TOPOLOGY", ICON_NONE, "Topology", ""},
         {-1}
      }
   },
   {
     .name = "Disable Dyntopo",
     .idname = "dyntopo_disabled",
     .type = BRUSH_CHANNEL_BOOL,
     .flag = BRUSH_CHANNEL_NO_MAPPINGS,
     .ivalue = 0
   },
    {
      .name = "Operations",
      .idname = "dyntopo_mode",
      .type = BRUSH_CHANNEL_BITMASK,
      .flag = BRUSH_CHANNEL_INHERIT,
      .ivalue = DYNTOPO_COLLAPSE | DYNTOPO_CLEANUP | DYNTOPO_SUBDIVIDE,
      .enumdef = {
        {DYNTOPO_COLLAPSE, "COLLAPSE", ICON_NONE, "Collapse", ""},
        {DYNTOPO_SUBDIVIDE, "SUBDIVIDE", ICON_NONE, "Subdivide", ""},
        {DYNTOPO_CLEANUP, "CLEANUP", ICON_NONE, "Cleanup", ""},
        {DYNTOPO_LOCAL_COLLAPSE, "LOCAL_COLLAPSE", ICON_NONE, "Local Collapse", ""},
        {DYNTOPO_LOCAL_SUBDIVIDE, "LOCAL_SUBDIVIDE", ICON_NONE, "Local Subdivide", ""},
        {-1}
      }
    },
   {
     .name = "Slide Deform Type",
     .idname = "slide_deform_type",
     .ivalue = BRUSH_SLIDE_DEFORM_DRAG,
     .type = BRUSH_CHANNEL_ENUM,
     .enumdef = {
       {BRUSH_SLIDE_DEFORM_DRAG, "DRAG", ICON_NONE, "Drag", ""},
       {BRUSH_SLIDE_DEFORM_PINCH, "PINCH", ICON_NONE, "Pinch", ""},
       {BRUSH_SLIDE_DEFORM_EXPAND, "EXPAND", ICON_NONE, "Expand", ""},
       {-1}
      }
   },
   {
      .name = "Normal Radius",
      .idname = "normal_radius_factor",
      .tooltip = "Ratio between the brush radius and the radius that is going to be "
                            "used to sample the normal",
      .type = BRUSH_CHANNEL_FLOAT,
      .min = 0.0f,
      .max = 2.0f,
      .soft_min = 0.0f,
      .soft_max = 2.0f,
   },
   {
      .name = "Hardness",
      .idname = "hardness",
      .tooltip = "Brush hardness",
      .type = BRUSH_CHANNEL_FLOAT,
      .fvalue = 0.0f,
      .min = 0.0f,
      .max = 1.0f,
      .soft_min = 0.0f,
      .soft_max = 1.0f
   },
      {
      .name = "Tip Roundness",
      .idname = "tip_roundness",
      .tooltip = "",
      .type = BRUSH_CHANNEL_FLOAT,
      .fvalue = 0.0f,
      .min = 0.0f,
      .max = 1.0f,
      .soft_min = 0.0f,
      .soft_max = 1.0f
   },
   {
      .name = "Accumulate",
      .idname = "accumulate",
      .type = BRUSH_CHANNEL_BOOL,
      .ivalue = 0
   },
   { /*this one is weird, it's an enum pretending to be a bool,
     that was how it was in in original rna too*/

     .name = "Direction",
     .idname = "direction",
     .ivalue = 0,
     .type = BRUSH_CHANNEL_ENUM,
     .enumdef = {
        {0, "ADD", "ADD", "Add", "Add effect of brush"},
        {1, "SUBTRACT", "REMOVE", "Subtract", "Subtract effect of brush"},
        {-1}
     }
   },
    MAKE_FLOAT("normal_weight", "Normal Weight", "", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT("rake_factor", "Rake Factor",  "How much grab will follow cursor rotation", 0.0f, 0.0f, 10.0f),
    MAKE_FLOAT("weight", "Weight", "", 0.5f, 0.0f, 1.0f),
    MAKE_FLOAT("jitter", "Jitter",  "Jitter the position of the brush while painting", 0.0f, 0.0f, 1.0f),
    MAKE_INT("jitter_absolute", "Absolute Jitter", "", 0, 0.0f, 1000.0f),
    MAKE_FLOAT("smooth_stroke_radius", "Smooth Stroke Radius", "Minimum distance from last point before stroke continues", 10.0f, 10.0f, 200.0f),
    MAKE_FLOAT("smooth_stroke_factor", "Smooth Stroke Factor", "", 0.5f, 0.5f, 0.99f),
    MAKE_FLOAT_EX("rate", "Rate", "", 0.5, 0.0001f, 10000.0f, 0.01f, 1.0f),
    MAKE_FLOAT("flow", "Flow", "Amount of paint that is applied per stroke sample", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT("wet_mix", "Wet Mix", "Amount of paint that is picked from the surface into the brush color", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT("wet_persistence", "Wet Persistence", "Amount of wet paint that stays in the brush after applying paint to the surface", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT("density", "Density", "Amount of random elements that are going to be affected by the brush", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT("tip_scale_x", "Tip Scale X", "Scale of the brush tip in the X axis", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT("dash_ratio", "Dash Ratio", "Ratio of samples in a cycle that the brush is enabled", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT_EX("plane_offset", "Plane Offset", "Adjust plane on which the brush acts towards or away from the object surface", 0.0f, -2.0f, 2.0f, -0.5f, 0.5f),
    MAKE_BOOL("original_normal", "Original Normal", "When locked keep using normal of surface where stroke was initiated", false),
    MAKE_BOOL("original_plane", "Original Plane", "When locked keep using the plane origin of surface where stroke was initiated", false),
    MAKE_BOOL("use_weighted_smooth", "Weight By Area", "Weight by face area to get a smoother result", true),
    MAKE_BOOL("preserve_faceset_boundary", "Keep FSet Boundary", "Preserve face set boundaries", true),
    MAKE_BOOL("hard_edge_mode", "Hard Edge Mode", "Forces all brushes into hard edge face set mode (sets face set slide to 0)", false),
    MAKE_BOOL("grab_silhouette", "Grab Silhouette", "Grabs trying to automask the silhouette of the object", false),
    MAKE_FLOAT("dyntopo_detail_percent", "Detail Percent", "Detail Percent", 25.0f, 0.0f, 1000.0f),
    MAKE_FLOAT("dyntopo_detail_range", "Detail Range", "Detail Range", 0.45f, 0.01f, 0.99f),
    MAKE_FLOAT_EX("dyntopo_detail_size", "Detail Size", "Detail Size", 8.0f, 0.1f, 100.0f, 0.001f, 500.0f),
    MAKE_FLOAT_EX("dyntopo_constant_detail", "Constaint Detail", "", 3.0f, 0.001f, 1000.0f, 0.0001, FLT_MAX),
    MAKE_FLOAT_EX("dyntopo_spacing", "Spacing", "Dyntopo Spacing", 35.0f, 0.01f, 300.0f, 0.001f, 50000.0f),
    MAKE_FLOAT_EX("dyntopo_radius_scale", "Radius Scale", "Scale brush radius for dyntopo radius", 1.0f, 0.001f, 3.0f, 0.0001f, 100.0f),
    MAKE_FLOAT("concave_mask_factor", "Cavity Factor", "", 0.35f, 0.0f, 1.0f),
    MAKE_INT_EX("automasking_boundary_edges_propagation_steps", "Propagation Steps",
      "Distance where boundary edge automasking is going to protect vertices "
                           "from the fully masked edge", 1, 1, 20, 1, 3),
    MAKE_COLOR4("cursor_color_add", "Add Color", "Color of cursor when adding", 1.0f, 0.39f, 0.39f, 1.0f),
    MAKE_COLOR4("cursor_color_sub", "Subtract Color", "Color of cursor when subtracting", 0.39f, 0.39f, 1.0f, 1.0f),
    MAKE_COLOR3("color", "Color", "", 1.0f, 1.0f, 1.0f),
    MAKE_COLOR3("secondary_color", "Secondary Color", "", 0.0f, 0.0f, 0.0f),
    MAKE_FLOAT("vcol_boundary_factor", "Boundary Hardening", "Automatically align edges on color boundaries"
                           "to generate sharper features. ", 0.0f, 0.0f, 1.0f),
    MAKE_FLOAT_EX("vcol_boundary_exponent", "Exponent", "Hardening exponent (smaller values make smoother edges)",
                   1.0, 0.001f, 6.0f, 0.001, 3.0f),
    MAKE_FLOAT_EX("vcol_boundary_radius_scale", "Radius Scale",
      "Scale brush radius for vcol boundary hardening",
      1.0f, 0.0001f, 100.0f, 0.001f, 3.0f),
    MAKE_FLOAT_EX("vcol_boundary_spacing", "Spacing", "Spacing for vcol boundary hardening", 15, 0.25, 5000, 0.5, 300),
     MAKE_BOOL("invert_to_scrape_fill","Invert to Scrape or Fill",
                           "Use Scrape or Fill tool when inverting this brush instead of "
                           "inverting its displacement direction", true),
     MAKE_FLOAT("area_radius_factor", "Area Radius", "Ratio between the brush radius and the radius that is going to be "
                           "used to sample the area center", 0.5f, 0.0f, 2.0f),
    MAKE_BOOL("use_multiplane_scrape_dynamic", "Dynamic Mode",  "The angle between the planes changes during the stroke to fit the "
                           "surface under the cursor", true),
    MAKE_BOOL("show_multiplane_scrape_planes_preview", "Show Cursor Preview", "Preview the scrape planes in the cursor during the stroke", true),
    MAKE_FLOAT("multiplane_scrape_angle", "Plane Angle", "Angle between the planes of the crease", 60.0f, 0.0f, 160.0f),
};
//BRUSH_INVERT_TO_SCRAPE_FILL
/* clang-format on */
const int brush_builtin_channel_len = ARRAY_SIZE(brush_builtin_channels);

static bool do_builtin_init = true;
ATTR_NO_OPT static bool check_builtin_init()
{
  if (!do_builtin_init || !BLI_thread_is_main()) {
    return false;
  }

  do_builtin_init = false;

  // can't do this here, since we can't lookup icon ids in blenkernel
  // for (int i = 0; i < brush_builtin_channel_len; i++) {
  // BKE_brush_channeltype_rna_check(brush_builtin_channels + i);
  //}

  return true;
}

#ifdef FLOAT
#  undef FLOAT
#endif
#ifdef INT
#  undef INT
#endif
#ifdef BOOL
#  undef BOOL
#endif

#define FLOAT BRUSH_CHANNEL_FLOAT
#define INT BRUSH_CHANNEL_INT
#define BOOL BRUSH_CHANNEL_BOOL
#define FLOAT3 BRUSH_CHANNEL_VEC3
#define FLOAT4 BRUSH_CHANNEL_VEC4

#ifdef ADDCH
#  undef ADDCH
#endif
#ifdef GETCH
#  undef GETCH
#endif

#define ADDCH(name) \
  (BKE_brush_channelset_ensure_builtin(chset, name), BKE_brush_channelset_lookup(chset, name))
#define GETCH(name) BKE_brush_channelset_lookup(chset, name)

/* clang-format off */
#define DEF(brush_member, channel_name, btype, ctype) \
  {offsetof(Brush, brush_member), #channel_name, btype, ctype, sizeof(((Brush){0}).brush_member)},
/* clang-format on */

typedef struct BrushSettingsMap {
  int brush_offset;
  const char *channel_name;
  int brush_type;
  int channel_type;
  int member_size;
} BrushSettingsMap;

/* clang-format off */

/* This lookup table is used convert data to/from brush channels
   and the old settings fields in Brush*/
static BrushSettingsMap brush_settings_map[] = {
  DEF(size, radius, INT, FLOAT)
  DEF(alpha, strength, FLOAT, FLOAT)
  DEF(autosmooth_factor, autosmooth, FLOAT, FLOAT)
  DEF(area_radius_factor, area_radius_factor, FLOAT, FLOAT)
  DEF(autosmooth_projection, SMOOTH_PROJECTION, FLOAT, FLOAT)
  DEF(topology_rake_projection, topology_rake_projection, FLOAT, FLOAT)
  DEF(topology_rake_radius_factor, topology_rake_radius_scale, FLOAT, FLOAT)
  DEF(topology_rake_spacing, topology_rake_spacing, INT, FLOAT)
  DEF(topology_rake_factor, topology_rake, FLOAT, FLOAT)
  DEF(autosmooth_fset_slide, fset_slide, FLOAT, FLOAT)
  DEF(boundary_smooth_factor, boundary_smooth, FLOAT, FLOAT)
  DEF(autosmooth_radius_factor, autosmooth_radius_scale, FLOAT, FLOAT)
  DEF(normal_weight, normal_weight, FLOAT, FLOAT)
  DEF(rake_factor, rake_factor, FLOAT, FLOAT)
  DEF(weight, weight, FLOAT, FLOAT)
  DEF(multiplane_scrape_angle, multiplane_scrape_angle, FLOAT, FLOAT)
  DEF(jitter, jitter, FLOAT, FLOAT)
  DEF(jitter_absolute, JITTER_ABSOLITE, INT, INT)
  DEF(smooth_stroke_radius, smooth_stroke_radius, INT, FLOAT)
  DEF(smooth_stroke_factor, smooth_stroke_factor, FLOAT, FLOAT)
  DEF(rate, rate, FLOAT, FLOAT)
  DEF(flow, flow, FLOAT, FLOAT)
  DEF(wet_mix, wet_mix, FLOAT, FLOAT)
  DEF(wet_persistence, wet_persistence, FLOAT, FLOAT)
  DEF(density, density, FLOAT, FLOAT)
  DEF(tip_scale_x, tip_scale_x, FLOAT, FLOAT)
  DEF(concave_mask_factor, concave_mask_factor, FLOAT, FLOAT)
  DEF(automasking_boundary_edges_propagation_steps, automasking_boundary_edges_propagation_steps, INT, INT)
  DEF(add_col, cursor_color_add, FLOAT4, FLOAT4)
  DEF(sub_col, cursor_color_sub, FLOAT4, FLOAT4)
  DEF(rgb, color, FLOAT3, FLOAT3)
  DEF(secondary_rgb, secondary_color, FLOAT3, FLOAT3)
  DEF(vcol_boundary_factor, vcol_boundary_factor, FLOAT, FLOAT)
  DEF(vcol_boundary_exponent, vcol_boundary_exponent, FLOAT, FLOAT)
};

static const int brush_settings_map_len = ARRAY_SIZE(brush_settings_map);

#undef DEF
#define DEF(brush_member, channel_name, btype, ctype) \
  {offsetof(DynTopoSettings, brush_member), \
   #channel_name, \
   btype, \
   ctype, \
   sizeof(((DynTopoSettings){0}).brush_member)},

static BrushSettingsMap dyntopo_settings_map[] = {
  DEF(detail_range, dyntopo_detail_range, FLOAT, FLOAT)
  DEF(detail_percent, dyntopo_detail_percent, FLOAT, FLOAT)
  DEF(detail_size, dyntopo_detail_size, FLOAT, FLOAT)
  DEF(constant_detail, dyntopo_constant_detail, FLOAT, FLOAT)
  DEF(spacing, dyntopo_spacing, INT, FLOAT)
  DEF(radius_scale, dyntopo_radius_scale, FLOAT, FLOAT)
};
static const int dyntopo_settings_map_len = ARRAY_SIZE(dyntopo_settings_map);

/* clang-format on */

typedef struct BrushFlagMap {
  int member_offset;
  char *channel_name;
  int flag;
  int member_size;
} BrushFlagMap;

/* clang-format off */
#ifdef DEF
#undef DEF
#endif

#define DEF(member, channel, flag)\
  {offsetof(Brush, member), #channel, flag, sizeof(((Brush){0}).member)},

/* This lookup table is like brush_settings_map except it converts
   individual bitflags instead of whole struct members.*/
BrushFlagMap brush_flags_map[] =  {
  DEF(flag, direction, BRUSH_DIR_IN)
  DEF(flag, original_normal, BRUSH_ORIGINAL_NORMAL)
  DEF(flag, original_plane, BRUSH_ORIGINAL_PLANE)
  DEF(flag, accumulate, BRUSH_ACCUMULATE)
  DEF(flag2, use_weighted_smooth, BRUSH_SMOOTH_USE_AREA_WEIGHT)
  DEF(flag2, preserve_faceset_boundary, BRUSH_SMOOTH_PRESERVE_FACE_SETS)
  DEF(flag2, hard_edge_mode, BRUSH_HARD_EDGE_MODE)
  DEF(flag2, grab_silhouette, BRUSH_GRAB_SILHOUETTE)
  DEF(flag, invert_to_scrape_fill, BRUSH_INVERT_TO_SCRAPE_FILL)
  DEF(flag2, use_multiplane_scrape_dynamic, BRUSH_MULTIPLANE_SCRAPE_DYNAMIC)
  DEF(flag2, show_multiplane_scrape_planes_preview, BRUSH_MULTIPLANE_SCRAPE_PLANES_PREVIEW)
};

int brush_flags_map_len = ARRAY_SIZE(brush_flags_map);

/* clang-format on */

static ATTR_NO_OPT void do_coerce(
    int type1, void *ptr1, int size1, int type2, void *ptr2, int size2)
{
  double val = 0;
  float vec[4];

  switch (type1) {
    case BRUSH_CHANNEL_FLOAT:
      val = *(float *)ptr1;
      break;
    case BRUSH_CHANNEL_INT:
    case BRUSH_CHANNEL_ENUM:
    case BRUSH_CHANNEL_BITMASK:
    case BRUSH_CHANNEL_BOOL:
      switch (size1) {
        case 1:
          val = (double)*(char *)ptr1;
          break;
        case 2:
          val = (double)*(unsigned short *)ptr1;
          break;
        case 4:
          val = (double)*(int *)ptr1;
          break;
        case 8:
          val = (double)*(int64_t *)ptr1;
          break;
      }
      break;
    case BRUSH_CHANNEL_VEC3:
      copy_v3_v3(vec, (float *)ptr1);
      break;
    case BRUSH_CHANNEL_VEC4:
      copy_v4_v4(vec, (float *)ptr1);
      break;
  }

  switch (type2) {
    case BRUSH_CHANNEL_FLOAT:
      *(float *)ptr2 = (float)val;
      break;
    case BRUSH_CHANNEL_INT:
    case BRUSH_CHANNEL_ENUM:
    case BRUSH_CHANNEL_BITMASK:
    case BRUSH_CHANNEL_BOOL: {
      switch (size2) {
        case 1:
          *(char *)ptr2 = (char)val;
          break;
        case 2:
          *(unsigned short *)ptr2 = (unsigned short)val;
          break;
        case 4:
          *(int *)ptr2 = (int)val;
          break;
        case 8:
          *(int64_t *)ptr2 = (int64_t)val;
          break;
      }
      break;
    }
    case BRUSH_CHANNEL_VEC3:
      copy_v3_v3((float *)ptr2, vec);
      break;
    case BRUSH_CHANNEL_VEC4:
      copy_v4_v4((float *)ptr2, vec);
      break;
  }
}

void *get_channel_value_pointer(BrushChannel *ch, int *r_data_size)
{
  *r_data_size = 4;

  switch (ch->type) {
    case BRUSH_CHANNEL_FLOAT:
      return &ch->fvalue;
    case BRUSH_CHANNEL_INT:
    case BRUSH_CHANNEL_ENUM:
    case BRUSH_CHANNEL_BITMASK:
    case BRUSH_CHANNEL_BOOL:
      return &ch->ivalue;
    case BRUSH_CHANNEL_VEC3:
      *r_data_size = sizeof(float) * 3;
      return ch->vector;
    case BRUSH_CHANNEL_VEC4:
      *r_data_size = sizeof(float) * 4;
      return ch->vector;
  }

  return NULL;
}

ATTR_NO_OPT static void brush_flags_from_channels(BrushChannelSet *chset, Brush *brush)
{
  for (int i = 0; i < brush_flags_map_len; i++) {
    BrushFlagMap *mf = brush_flags_map + i;
    BrushChannel *ch = BKE_brush_channelset_lookup(chset, mf->channel_name);

    if (!ch) {
      continue;
    }

    char *ptr = (char *)brush;
    ptr += mf->member_offset;

    switch (mf->member_size) {
      case 1: {
        char *f = (char *)ptr;
        if (ch->ivalue) {
          *f |= mf->flag;
        }
        else {
          *f &= ~mf->flag;
        }
        break;
      }
      case 2: {
        ushort *f = (ushort *)ptr;
        if (ch->ivalue) {
          *f |= mf->flag;
        }
        else {
          *f &= ~mf->flag;
        }
        break;
      }
      case 4: {
        uint *f = (uint *)ptr;
        if (ch->ivalue) {
          *f |= mf->flag;
        }
        else {
          *f &= ~mf->flag;
        }
        break;
      }
      case 8: {
        uint64_t *f = (uint64_t *)ptr;
        if (ch->ivalue) {
          *f |= mf->flag;
        }
        else {
          *f &= ~mf->flag;
        }
        break;
      }
    }
  }
}

ATTR_NO_OPT static void brush_flags_to_channels(BrushChannelSet *chset, Brush *brush)
{
  for (int i = 0; i < brush_flags_map_len; i++) {
    BrushFlagMap *mf = brush_flags_map + i;
    BrushChannel *ch = BKE_brush_channelset_lookup(chset, mf->channel_name);

    if (!ch) {
      continue;
    }

    char *ptr = (char *)brush;
    ptr += mf->member_offset;

    switch (mf->member_size) {
      case 1: {
        char *f = (char *)ptr;
        ch->ivalue = (*f & mf->flag) ? 1 : 0;
        break;
      }
      case 2: {
        ushort *f = (ushort *)ptr;
        ch->ivalue = (*f & mf->flag) ? 1 : 0;
        break;
      }
      case 4: {
        uint *f = (uint *)ptr;
        ch->ivalue = (*f & mf->flag) ? 1 : 0;
        break;
      }
      case 8: {
        uint64_t *f = (uint64_t *)ptr;
        ch->ivalue = (*f & mf->flag) ? 1 : 0;
        break;
      }
    }
  }
}

ATTR_NO_OPT void BKE_brush_channelset_compat_load_intern(BrushChannelSet *chset,
                                                         void *data,
                                                         bool brush_to_channels,
                                                         BrushSettingsMap *settings_map,
                                                         int settings_map_len)
{

  for (int i = 0; i < settings_map_len; i++) {
    BrushSettingsMap *mp = settings_map + i;
    BrushChannel *ch = BKE_brush_channelset_lookup(chset, mp->channel_name);

    if (!ch) {
      continue;
    }

    char *bptr = (char *)data;
    bptr += mp->brush_offset;

    int csize;
    void *cptr = get_channel_value_pointer(ch, &csize);

    if (brush_to_channels) {
      do_coerce(mp->brush_type, bptr, mp->member_size, ch->type, cptr, csize);
    }
    else {
      do_coerce(ch->type, cptr, csize, mp->brush_type, bptr, mp->member_size);
    }
  }
}

ATTR_NO_OPT void BKE_brush_channelset_compat_load(BrushChannelSet *chset,
                                                  Brush *brush,
                                                  bool brush_to_channels)
{
  if (brush_to_channels) {
    brush_flags_to_channels(chset, brush);
  }
  else {
    brush_flags_from_channels(chset, brush);
  }

  BKE_brush_channelset_compat_load_intern(
      chset, (void *)brush, brush_to_channels, brush_settings_map, brush_settings_map_len);
  BKE_brush_channelset_compat_load_intern(chset,
                                          (void *)&brush->dyntopo,
                                          brush_to_channels,
                                          dyntopo_settings_map,
                                          dyntopo_settings_map_len);

  // now handle dyntopo mode
  if (!brush_to_channels) {
    int flag = BKE_brush_channelset_get_int(chset, "dyntopo_mode", NULL);

    if (BKE_brush_channelset_get_int(chset, "dyntopo_disabled", NULL)) {
      flag |= DYNTOPO_DISABLED;
    }

    brush->dyntopo.flag = flag;
  }
  else {
    const int mask = DYNTOPO_COLLAPSE | DYNTOPO_SUBDIVIDE | DYNTOPO_CLEANUP |
                     DYNTOPO_LOCAL_COLLAPSE | DYNTOPO_LOCAL_SUBDIVIDE;

#ifdef SETCH
#  undef SETCH
#endif

    BKE_brush_channelset_set_int(chset, "dyntopo_mode", brush->dyntopo.flag & mask);
    BKE_brush_channelset_set_int(
        chset, "dyntopo_mode", brush->dyntopo.flag & DYNTOPO_DISABLED ? 1 : 0);

#define SETCH(key, val) BKE_brush_channelset_set_float(chset, #key, val)
    SETCH(dyntopo_detail_range, brush->dyntopo.detail_range);
    SETCH(dyntopo_detail_percent, brush->dyntopo.detail_percent);
    SETCH(dyntopo_detail_size, brush->dyntopo.detail_size);
    SETCH(dyntopo_constant_detail, brush->dyntopo.constant_detail);
    SETCH(dyntopo_spacing, brush->dyntopo.spacing);
  }
}
#undef SETCH

// adds any missing channels to brushes
void BKE_brush_builtin_patch(Brush *brush, int tool)
{
  check_builtin_init();

  namestack_push(__func__);

  if (!brush->channels) {
    brush->channels = BKE_brush_channelset_create();
  }

  BrushChannelSet *chset = brush->channels;

  ADDCH("radius");
  ADDCH("spacing");
  ADDCH("strength");

  ADDCH("autosmooth");
  ADDCH("autosmooth_radius_scale");
  ADDCH("autosmooth_spacing");
  ADDCH("autosmooth_use_spacing");
  ADDCH("autosmooth_projection");

  ADDCH("vcol_boundary_exponent");
  ADDCH("vcol_boundary_factor");
  ADDCH("vcol_boundary_radius_scale");
  ADDCH("vcol_boundary_spacing");

  ADDCH("topology_rake");
  ADDCH("topology_rake_mode");
  ADDCH("topology_rake_radius_scale");
  ADDCH("topology_rake_use_spacing");
  ADDCH("topology_rake_spacing");
  ADDCH("topology_rake_projection");

  ADDCH("hardness");
  ADDCH("tip_roundness");
  ADDCH("normal_radius_factor");

  ADDCH("automasking");
  ADDCH("automasking_boundary_edges_propagation_steps");
  ADDCH("concave_mask_factor");
  ADDCH("dyntopo_disabled");
  ADDCH("dyntopo_mode")->flag |= BRUSH_CHANNEL_INHERIT;
  ADDCH("dyntopo_detail_range")->flag |= BRUSH_CHANNEL_INHERIT;
  ADDCH("dyntopo_detail_percent")->flag |= BRUSH_CHANNEL_INHERIT;
  ADDCH("dyntopo_detail_size")->flag |= BRUSH_CHANNEL_INHERIT;
  ADDCH("dyntopo_constant_detail")->flag |= BRUSH_CHANNEL_INHERIT;
  ADDCH("dyntopo_spacing")->flag |= BRUSH_CHANNEL_INHERIT;
  ADDCH("dyntopo_radius_scale")->flag |= BRUSH_CHANNEL_INHERIT;

  ADDCH("accumulate");
  ADDCH("original_normal");
  ADDCH("original_plane");
  ADDCH("jitter");
  ADDCH("jitter_absolute");
  ADDCH("use_weighted_smooth");
  ADDCH("preserve_faceset_boundary");
  ADDCH("hard_edge_mode");
  ADDCH("grab_silhouette");

  ADDCH("projection");
  ADDCH("boundary_smooth");
  ADDCH("fset_slide");

  ADDCH("direction");

  switch (tool) {
    case SCULPT_TOOL_DRAW: {
      break;
    }

    case SCULPT_TOOL_PAINT: {
      ADDCH("color");
      ADDCH("secondary_color");
      break;
    }
    case SCULPT_TOOL_SLIDE_RELAX:
      ADDCH("slide_deform_type");
      break;
  }

  namestack_pop();
}

ATTR_NO_OPT void BKE_brush_builtin_create(Brush *brush, int tool)
{
  namestack_push(__func__);

  if (!brush->channels) {
    brush->channels = BKE_brush_channelset_create();
  }

  BrushChannelSet *chset = brush->channels;

  BKE_brush_builtin_patch(brush, tool);

  GETCH("strength")->flag |= BRUSH_CHANNEL_INHERIT;
  GETCH("radius")->flag |= BRUSH_CHANNEL_INHERIT;

  ADDCH("area_radius_factor");

  switch (tool) {
    case SCULPT_TOOL_DRAW: {
      break;
    }
    case SCULPT_TOOL_SIMPLIFY:
      GETCH("strength")->mappings[BRUSH_MAPPING_PRESSURE].flag &= ~BRUSH_MAPPING_ENABLED;
      GETCH("radius")->mappings[BRUSH_MAPPING_PRESSURE].flag &= ~BRUSH_MAPPING_ENABLED;
      GETCH("strength")->fvalue = 0.5;
      GETCH("autosmooth")->fvalue = 0.05;
      GETCH("topology_rake_mode")->ivalue = 1;  // curvature mode
      GETCH("topology_rake")->fvalue = 0.35;
      break;
    case SCULPT_TOOL_DRAW_SHARP:
      GETCH("spacing")->ivalue = 5;
      GETCH("radius")->mappings[BRUSH_MAPPING_PRESSURE].flag |= BRUSH_MAPPING_ENABLED;
      GETCH("strength")->mappings[BRUSH_MAPPING_PRESSURE].flag &= ~BRUSH_MAPPING_ENABLED;
      break;
    case SCULPT_TOOL_DISPLACEMENT_ERASER:
    case SCULPT_TOOL_FAIRING:
    case SCULPT_TOOL_SCENE_PROJECT:
      GETCH("spacing")->ivalue = 10;
      GETCH("strength")->fvalue = 1.0f;
      GETCH("dyntopo_disabled")->ivalue = 1;
      break;
    case SCULPT_TOOL_SLIDE_RELAX:
      GETCH("spacing")->ivalue = 10;
      GETCH("strength")->fvalue = 1.0f;
      GETCH("dyntopo_disabled")->ivalue = 1;
      GETCH("slide_deform_type")->ivalue = BRUSH_SLIDE_DEFORM_DRAG;
      break;
    case SCULPT_TOOL_CLAY:
      GETCH("radius")->mappings[BRUSH_MAPPING_PRESSURE].flag |= BRUSH_MAPPING_ENABLED;
      GETCH("spacing")->ivalue = 3;
      GETCH("autosmooth")->fvalue = 0.25f;
      GETCH("normal_radius_factor")->fvalue = 0.75f;
      GETCH("hardness")->fvalue = 0.65;
      break;
    case SCULPT_TOOL_TWIST:
      GETCH("strength")->fvalue = 0.5f;
      GETCH("normal_radius_factor")->fvalue = 1.0f;
      GETCH("spacing")->ivalue = 6;
      GETCH("hardness")->fvalue = 0.5;
      break;
    case SCULPT_TOOL_CLAY_STRIPS: {
      GETCH("radius")->mappings[BRUSH_MAPPING_PRESSURE].flag |= BRUSH_MAPPING_ENABLED;
      GETCH("tip_roundness")->fvalue = 0.18f;
      GETCH("normal_radius_factor")->fvalue = 1.35f;
      GETCH("strength")->fvalue = 0.8f;
      GETCH("accumulate")->ivalue = 1;

      BKE_brush_mapping_ensure_write(&GETCH("radius")->mappings[BRUSH_MAPPING_PRESSURE]);

      CurveMapping *curve = GETCH("radius")->mappings[BRUSH_MAPPING_PRESSURE].curve;

      CurveMap *cuma = curve->cm;

      cuma->curve[0].x = 0.0f;
      cuma->curve[0].y = 0.55f;
      BKE_curvemap_insert(cuma, 0.5f, 0.7f);
      cuma->curve[2].x = 1.0f;
      cuma->curve[2].y = 1.0f;
      BKE_curvemapping_changed(curve, true);

      cuma = curve->cm;
      BKE_curvemap_insert(cuma, 0.6f, 0.25f);
      BKE_curvemapping_changed(curve, true);

      break;
    }
    case SCULPT_TOOL_MULTIPLANE_SCRAPE:
      ADDCH("use_multiplane_scrape_dynamic");
      ADDCH("show_multiplane_scrape_planes_preview");
      GETCH("strength")->fvalue = 0.7f;
      GETCH("normal_radius_factor")->fvalue = 0.7f;
      ADDCH("multiplane_scrape_angle");
      GETCH("spacing")->fvalue = 5.0f;
      break;
    case SCULPT_TOOL_CREASE:
      GETCH("direction")->ivalue = true;
      GETCH("strength")->fvalue = 0.25;
      break;
    case SCULPT_TOOL_SCRAPE:
    case SCULPT_TOOL_FILL:
      GETCH("strength")->fvalue = 0.7f;
      GETCH("area_radius_factor")->fvalue = 0.5f;
      GETCH("spacing")->fvalue = 7;
      ADDCH("invert_to_scrape_fill");
      GETCH("invert_to_scrape_fill")->ivalue = true;
      GETCH("accumulate")->ivalue = true;
      break;
    case SCULPT_TOOL_ROTATE:
      GETCH("strength")->fvalue = 1.0;
      GETCH("dyntopo_disabled")->ivalue = true;
      break;
    default: {
      // implement me!
      // BKE_brush_channelset_free(chset);
      // brush->channels = NULL;
      break;
    }
  }

  namestack_pop();
}

void BKE_brush_init_toolsettings(Sculpt *sd)
{
  namestack_push(__func__);

  if (sd->channels) {
    BKE_brush_channelset_free(sd->channels);
  }

  BKE_brush_check_toolsettings(sd);

  namestack_pop();
}

void BKE_brush_check_toolsettings(Sculpt *sd)
{
  namestack_push(__func__);

  BrushChannelSet *chset = sd->channels;

  ADDCH("radius");
  ADDCH("strength");
  ADDCH("automasking_boundary_edges_propagation_steps");
  ADDCH("concave_mask_factor");
  ADDCH("automasking");
  ADDCH("topology_rake_mode");

  ADDCH("vcol_boundary_exponent");
  ADDCH("vcol_boundary_factor");
  ADDCH("vcol_boundary_radius_scale");
  ADDCH("vcol_boundary_spacing");

  ADDCH("area_radius_factor");

  ADDCH("color");
  ADDCH("secondary_color");

  ADDCH("dyntopo_disabled");
  ADDCH("dyntopo_mode");
  ADDCH("dyntopo_detail_range");
  ADDCH("dyntopo_detail_percent");
  ADDCH("dyntopo_detail_size");
  ADDCH("dyntopo_constant_detail");
  ADDCH("dyntopo_spacing");
  ADDCH("dyntopo_radius_scale");

  namestack_pop();
}