Fix T63283: Second subdivision modifier does not ignore crease

This is something where there is no single correct behavior,
sometimes it's needed to ignore the crease to make mesh more
smooth. But sometimes crease is to be considered after first
subdivision surface: for example, when adding extra subdivisions
for render-time displacement.

Made it an option whether modifier needs to take crease into
account or not.

Existing files should be openable in the 2.7 compatible way,
to re-create an old behavior the options is to be manually
disabled in the modifier settings.

Reviewers: brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D4652
This commit is contained in:
Sergey Sharybin 2019-04-05 14:13:05 +02:00
parent 6de0da70de
commit d220a87b47
Notes: blender-bot 2023-02-14 03:07:34 +01:00
Referenced by issue #63283, Second subdivision modifier does not ignore crease anymore
10 changed files with 56 additions and 2 deletions

View File

@ -658,6 +658,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.operator("object.multires_base_apply", text="Apply Base")
col.prop(md, "uv_smooth", text="")
col.prop(md, "show_only_control_edges")
col.prop(md, "use_creases")
layout.separator()
@ -1035,6 +1036,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
sub.prop(md, "uv_smooth", text="")
col.prop(md, "show_only_control_edges")
col.prop(md, "use_creases")
if show_adaptive_options and ob.cycles.use_adaptive_subdivision:
col = layout.column(align=True)

View File

@ -24,7 +24,7 @@
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 280
#define BLENDER_SUBVERSION 53
#define BLENDER_SUBVERSION 54
/* Several breakages with 280, e.g. collections vs layers */
#define BLENDER_MINVERSION 280
#define BLENDER_MINSUBVERSION 0

View File

@ -58,6 +58,7 @@ typedef struct SubdivSettings {
bool is_simple;
bool is_adaptive;
int level;
bool use_creases;
eSubdivVtxBoundaryInterpolation vtx_boundary_interpolation;
eSubdivFVarLinearInterpolation fvar_linear_interpolation;
} SubdivSettings;

View File

@ -41,6 +41,7 @@ void BKE_multires_subdiv_settings_init(
settings->is_simple = (mmd->simple != 0);
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->fvar_linear_interpolation =
BKE_subdiv_fvar_interpolation_from_uv_smooth(mmd->uv_smooth);

View File

@ -168,6 +168,9 @@ static float get_edge_sharpness(const OpenSubdiv_Converter *converter,
return 10.0f;
}
#endif
if (!storage->settings.use_creases) {
return 0.0f;
}
const int edge_index =
storage->manifold_edge_index_reverse[manifold_edge_index];
const MEdge *medge = storage->mesh->medge;
@ -190,9 +193,13 @@ static bool is_infinite_sharp_vertex(const OpenSubdiv_Converter *converter,
vertex_index);
}
static float get_vertex_sharpness(const OpenSubdiv_Converter *UNUSED(converter),
static float get_vertex_sharpness(const OpenSubdiv_Converter *converter,
int UNUSED(manifold_vertex_index))
{
ConverterStorage *storage = converter->user_data;
if (!storage->settings.use_creases) {
return 0.0f;
}
return 0.0f;
}

View File

@ -2967,6 +2967,34 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 280, 54)) {
for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
bool is_first_subdiv = true;
for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
if (md->type == eModifierType_Subsurf) {
SubsurfModifierData *smd = (SubsurfModifierData *)md;
if (is_first_subdiv) {
smd->flags |= eSubsurfModifierFlag_UseCrease;
}
else {
smd->flags &= ~eSubsurfModifierFlag_UseCrease;
}
is_first_subdiv = false;
}
else if (md->type == eModifierType_Multires) {
MultiresModifierData *mmd = (MultiresModifierData *)md;
if (is_first_subdiv) {
mmd->flags |= eMultiresModifierFlag_UseCrease;
}
else {
mmd->flags &= ~eMultiresModifierFlag_UseCrease;
}
is_first_subdiv = false;
}
}
}
}
{
/* Versioning code until next subversion bump goes here. */

View File

@ -144,6 +144,7 @@ typedef enum {
eSubsurfModifierFlag_ControlEdges = (1 << 2),
/* DEPRECATED, ONLY USED FOR DO-VERSIONS */
eSubsurfModifierFlag_SubsurfUv_DEPRECATED = (1 << 3),
eSubsurfModifierFlag_UseCrease = (1 << 4),
} SubsurfModifierFlag;
typedef enum {
@ -960,6 +961,7 @@ typedef enum {
eMultiresModifierFlag_ControlEdges = (1 << 0),
/* DEPRECATED, only used for versioning. */
eMultiresModifierFlag_PlainUv_DEPRECATED = (1 << 1),
eMultiresModifierFlag_UseCrease = (1 << 2),
} MultiresModifierFlag;
typedef struct FluidsimModifierData {

View File

@ -1278,6 +1278,11 @@ static void rna_def_modifier_subsurf(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flags", eSubsurfModifierFlag_ControlEdges);
RNA_def_property_ui_text(prop, "Optimal Display", "Skip drawing/rendering of interior subdivided edges");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "use_creases", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", eSubsurfModifierFlag_UseCrease);
RNA_def_property_ui_text(prop, "Use Creases", "Use mesh edge crease information to sharpen edges");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_generic_map_info(StructRNA *srna)
@ -1423,6 +1428,11 @@ static void rna_def_modifier_multires(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flags", eMultiresModifierFlag_ControlEdges);
RNA_def_property_ui_text(prop, "Optimal Display", "Skip drawing/rendering of interior subdivided edges");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "use_creases", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", eMultiresModifierFlag_UseCrease);
RNA_def_property_ui_text(prop, "Use Creases", "Use mesh edge crease information to sharpen edges");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_lattice(BlenderRNA *brna)

View File

@ -61,6 +61,7 @@ static void initData(ModifierData *md)
mmd->totlvl = 0;
mmd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
mmd->quality = 3;
mmd->flags |= eMultiresModifierFlag_UseCrease;
}
static void copyData(const ModifierData *md_src, ModifierData *md_dst, const int flag)

View File

@ -59,6 +59,7 @@ static void initData(ModifierData *md)
smd->renderLevels = 2;
smd->uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
smd->quality = 3;
smd->flags |= eSubsurfModifierFlag_UseCrease;
}
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
@ -126,6 +127,7 @@ static void subdiv_settings_init(SubdivSettings *settings,
settings->is_simple = (smd->subdivType == SUBSURF_TYPE_SIMPLE);
settings->is_adaptive = true;
settings->level = settings->is_simple ? 1 : smd->quality;
settings->use_creases = (smd->flags & eSubsurfModifierFlag_UseCrease);
settings->vtx_boundary_interpolation = SUBDIV_VTX_BOUNDARY_EDGE_ONLY;
settings->fvar_linear_interpolation =
BKE_subdiv_fvar_interpolation_from_uv_smooth(smd->uv_smooth);