sculpt-dev: Fix tip_roundness versioning bug

This commit is contained in:
Joseph Eagar 2022-06-01 19:34:22 -07:00
parent 4c3d11c233
commit d7d6ad76d7
3 changed files with 44 additions and 22 deletions

View File

@ -52,12 +52,6 @@
extern struct CurveMappingCache *brush_curve_cache;
#if 1
struct {
char t1[32], t2[32], t3[32], t4[32];
} test[1] = {{1, 1, 1, 1}};
#endif
static bool check_builtin_init();
#if 1
@ -439,13 +433,19 @@ static bool check_builtin_init()
/* TODO: Destroy these macros.*/
#define ADDCH_EX(idname, category, visflag) \
do { \
BKE_brush_channelset_ensure_builtin(chset, BRUSH_BUILTIN_##idname); \
BrushChannel *ch = BKE_brush_channelset_lookup(chset, BRUSH_BUILTIN_##idname); \
SETCAT(idname, category); \
ch->flag |= visflag; \
} while (0);
static void _ensure_channel(BrushChannelSet *chset,
const char *idname,
const char *category,
int visflag)
{
BKE_brush_channelset_ensure_builtin(chset, idname);
BrushChannel *ch = BKE_brush_channelset_lookup(chset, idname);
BLI_strncpy(_get_def(idname)->category, category, sizeof(_get_def(idname)->category));
ch->flag |= visflag;
}
#define ensure_channel(chset, idname, category, visflag) \
_ensure_channel(chset, BRUSH_BUILTIN_##idname, category, visflag)
/* TODO: replace these two macros with equivalent BRUSHSET_XXX ones */
#define ADDCH(name) \
@ -1104,7 +1104,7 @@ void reset_clay_mappings(BrushChannelSet *chset, bool strips)
}
// adds any missing channels to brushes
void BKE_brush_builtin_patch(Brush *brush, int tool)
ATTR_NO_OPT void BKE_brush_builtin_patch(Brush *brush, int tool)
{
check_builtin_init();
@ -1280,16 +1280,23 @@ void BKE_brush_builtin_patch(Brush *brush, int tool)
/* Patch olds files. */
if (!BRUSHSET_LOOKUP(chset, tip_scale_x)) {
ADDCH_EX(tip_scale_x,
"Basic",
BRUSH_CHANNEL_SHOW_IN_WORKSPACE | BRUSH_CHANNEL_SHOW_IN_CONTEXT_MENU);
ADDCH_EX(tip_roundness,
"Basic",
BRUSH_CHANNEL_SHOW_IN_WORKSPACE | BRUSH_CHANNEL_SHOW_IN_CONTEXT_MENU);
ensure_channel(chset,
tip_scale_x,
"Basic",
BRUSH_CHANNEL_SHOW_IN_WORKSPACE | BRUSH_CHANNEL_SHOW_IN_CONTEXT_MENU);
ensure_channel(chset,
tip_roundness,
"Basic",
BRUSH_CHANNEL_SHOW_IN_WORKSPACE | BRUSH_CHANNEL_SHOW_IN_CONTEXT_MENU);
if (tool == SCULPT_TOOL_CLAY_STRIPS) {
BRUSHSET_SET_FLOAT(chset, tip_roundness, 0.18f);
}
else {
BRUSHSET_SET_FLOAT(chset, tip_roundness, 1.0f);
}
BRUSHSET_SET_FLOAT(chset, tip_scale_x, 1.0f);
}
/* stuff for deform_target cloth mode*/
ADDCH(cloth_use_collision);

View File

@ -2471,6 +2471,9 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
BKE_brush_builtin_create(brush, brush->sculpt_tool);
BKE_brush_channelset_compat_load(brush->channels, brush, true);
BRUSHSET_SET_FLOAT(brush->channels, tip_roundness, 1.0f);
BRUSHSET_SET_FLOAT(brush->channels, tip_scale_x, 1.0f);
}
}
@ -2885,6 +2888,9 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
BKE_brush_builtin_patch(brush, brush->sculpt_tool);
BKE_brush_channelset_compat_load(brush->channels, brush, true);
BRUSHSET_SET_FLOAT(brush->channels, tip_roundness, 1.0f);
BRUSHSET_SET_FLOAT(brush->channels, tip_scale_x, 1.0f);
Brush temp = *brush;
temp.channels = NULL;

View File

@ -3058,6 +3058,10 @@ bool SCULPT_brush_test_cube_sq(SculptBrushTest *test, const float co[3])
if (SCULPT_brush_test_cube(test, co, test->cube_matrix, test->tip_roundness, true)) {
test->dist *= test->dist * test->radius_squared;
if (test->dist > test->radius_squared) {
return false;
}
return true;
}
@ -3067,7 +3071,7 @@ bool SCULPT_brush_test_cube_sq(SculptBrushTest *test, const float co[3])
bool SCULPT_brush_test_thru_cube_sq(SculptBrushTest *test, const float co[3])
{
if (SCULPT_brush_test_cube(test, co, test->cube_matrix, test->tip_roundness, false)) {
test->dist *= test->dist * test->radius_squared;
test->dist *= test->radius;
return true;
}
@ -3237,7 +3241,12 @@ SculptBrushTestFn SCULPT_brush_test_init_ex(const SculptSession *ss,
mat[1][3] = 0;
copy_v3_v3(mat[2], ss->cache->cached_area_normal);
mat[2][3] = 0;
copy_v3_v3(mat[3], ss->cache->location);
float loc[3];
copy_v3_v3(loc, ss->cache->location);
madd_v3_v3fl(loc, ss->cache->sculpt_normal_symm, -ss->cache->radius * 0.5f);
copy_v3_v3(mat[3], loc);
mat[3][3] = 1;
normalize_m4(mat);