Subdivision Surfaces: add boundary smooth option to modifiers

This adds the option to either smooth the entire boundary, or to keep
corners sharp, for the Subdivision Surface and Multiresolution modifiers.

This mainly helps with compatibility with other software. The default
behavior remains to smooth the entire boundary.

Differential Revision: https://developer.blender.org/D8485
This commit is contained in:
Piotr Ostrowski 2020-09-30 15:56:37 +02:00 committed by Brecht Van Lommel
parent 53f20b940a
commit 6070f92ab9
7 changed files with 49 additions and 4 deletions

View File

@ -204,6 +204,9 @@ void BKE_subdiv_exit(void);
/* NOTE: uv_smooth is eSubsurfUVSmooth. */
eSubdivFVarLinearInterpolation BKE_subdiv_fvar_interpolation_from_uv_smooth(int uv_smooth);
eSubdivVtxBoundaryInterpolation BKE_subdiv_vtx_boundary_interpolation_from_subsurf(
int boundary_smooth);
/* =============================== STATISTICS =============================== */
void BKE_subdiv_stats_init(SubdivStats *stats);

View File

@ -40,7 +40,8 @@ void BKE_multires_subdiv_settings_init(SubdivSettings *settings, const MultiresM
settings->is_adaptive = true;
settings->level = settings->is_simple ? 1 : mmd->quality;
settings->use_creases = (mmd->flags & eMultiresModifierFlag_UseCrease);
settings->vtx_boundary_interpolation = SUBDIV_VTX_BOUNDARY_EDGE_ONLY;
settings->vtx_boundary_interpolation = BKE_subdiv_vtx_boundary_interpolation_from_subsurf(
mmd->boundary_smooth);
settings->fvar_linear_interpolation = BKE_subdiv_fvar_interpolation_from_uv_smooth(
mmd->uv_smooth);
}

View File

@ -72,6 +72,19 @@ eSubdivFVarLinearInterpolation BKE_subdiv_fvar_interpolation_from_uv_smooth(int
return SUBDIV_FVAR_LINEAR_INTERPOLATION_ALL;
}
eSubdivVtxBoundaryInterpolation BKE_subdiv_vtx_boundary_interpolation_from_subsurf(
int boundary_smooth)
{
switch (boundary_smooth) {
case SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS:
return SUBDIV_VTX_BOUNDARY_EDGE_AND_CORNER;
case SUBSURF_BOUNDARY_SMOOTH_ALL:
return SUBDIV_VTX_BOUNDARY_EDGE_ONLY;
}
BLI_assert(!"Unknown boundary smooth flag");
return SUBDIV_VTX_BOUNDARY_EDGE_ONLY;
}
/* ================================ SETTINGS ================================ */
static bool check_mesh_has_non_quad(const Mesh *mesh)

View File

@ -179,13 +179,19 @@ typedef enum {
SUBSURF_UV_SMOOTH_ALL = 5,
} eSubsurfUVSmooth;
typedef enum {
SUBSURF_BOUNDARY_SMOOTH_ALL = 0,
SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS = 1,
} eSubsurfBoundarySmooth;
typedef struct SubsurfModifierData {
ModifierData modifier;
short subdivType, levels, renderLevels, flags;
short uv_smooth;
short quality;
char _pad[4];
short boundary_smooth;
char _pad[2];
/* TODO(sergey): Get rid of those with the old CCG subdivision code. */
void *emCache, *mCache;
@ -1042,7 +1048,8 @@ typedef struct MultiresModifierData {
char simple, flags, _pad[2];
short quality;
short uv_smooth;
char _pad2[4];
short boundary_smooth;
char _pad2[2];
} MultiresModifierData;
typedef enum {

View File

@ -1686,6 +1686,16 @@ static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const c
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem prop_boundary_smooth_items[] = {
{SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS,
"PRESERVE_CORNERS",
0,
"Keep Corners",
"Smooth boundaries, but corners are kept sharp"},
{SUBSURF_BOUNDARY_SMOOTH_ALL, "ALL", 0, "All", "Smooth boundaries, including corners"},
{0, NULL, 0, NULL, NULL},
};
PropertyRNA *prop;
RNA_define_lib_overridable(true);
@ -1704,6 +1714,12 @@ static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const c
prop, "Quality", "Accuracy of vertex positions, lower value is faster but less precise");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "boundary_smooth", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "boundary_smooth");
RNA_def_property_enum_items(prop, prop_boundary_smooth_items);
RNA_def_property_ui_text(prop, "Boundary Smooth", "Controls how open boundaries are smoothed");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "subdivision_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, type);
RNA_def_property_enum_items(prop, prop_subdivision_type_items);

View File

@ -73,6 +73,7 @@ static void initData(ModifierData *md)
mmd->renderlvl = 0;
mmd->totlvl = 0;
mmd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
mmd->boundary_smooth = SUBSURF_BOUNDARY_SMOOTH_ALL;
mmd->quality = 4;
mmd->flags |= (eMultiresModifierFlag_UseCrease | eMultiresModifierFlag_ControlEdges);
@ -489,6 +490,7 @@ static void advanced_panel_draw(const bContext *UNUSED(C), Panel *panel)
col = uiLayoutColumn(layout, false);
uiLayoutSetEnabled(col, true);
uiItemR(col, ptr, "uv_smooth", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "boundary_smooth", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_creases", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_custom_normals", 0, NULL, ICON_NONE);

View File

@ -74,6 +74,7 @@ static void initData(ModifierData *md)
smd->levels = 1;
smd->renderLevels = 2;
smd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
smd->boundary_smooth = SUBSURF_BOUNDARY_SMOOTH_ALL;
smd->quality = 3;
smd->flags |= (eSubsurfModifierFlag_UseCrease | eSubsurfModifierFlag_ControlEdges);
}
@ -167,7 +168,8 @@ static void subdiv_settings_init(SubdivSettings *settings,
1 :
(settings->is_adaptive ? smd->quality : requested_levels);
settings->use_creases = (smd->flags & eSubsurfModifierFlag_UseCrease);
settings->vtx_boundary_interpolation = SUBDIV_VTX_BOUNDARY_EDGE_ONLY;
settings->vtx_boundary_interpolation = BKE_subdiv_vtx_boundary_interpolation_from_subsurf(
smd->boundary_smooth);
settings->fvar_linear_interpolation = BKE_subdiv_fvar_interpolation_from_uv_smooth(
smd->uv_smooth);
}
@ -471,6 +473,7 @@ static void advanced_panel_draw(const bContext *C, Panel *panel)
uiItemR(col, ptr, "quality", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "uv_smooth", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "boundary_smooth", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_creases", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "use_custom_normals", 0, NULL, ICON_NONE);
}