Multires: Remove simple subdivision type

The simple subdivision as a type only causes issues like no-continuous
normals across edges, inability to reliably switch the type and things
like this.

The new subdivision operators supports wider variety of how to add
details to the model, which are more powerful than a single one-time
decision on the subdivision type.

The versioning code is adjusting topology converter to specify all
edges as infinitely sharp. The reason for this (instead of using
settings.is_simple) is because in a longer term the simple subdivision
will be removed from Subsurf modifier as well, and will be replaced
with more efficient bmesh-based modifier.

This is finished up version of D8436.

Differential Revision: https://developer.blender.org/D9350
This commit is contained in:
Sergey Sharybin 2020-10-26 12:32:22 +01:00
parent 09139e41ed
commit 17381c7b90
17 changed files with 182 additions and 65 deletions

View File

@ -39,7 +39,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 0
#define BLENDER_FILE_SUBVERSION 1
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -218,6 +218,13 @@ BLI_INLINE void BKE_multires_construct_tangent_matrix(float tangent_matrix[3][3]
const float dPdv[3],
const int corner);
/* Versioning. */
/* Convert displacement which is stored for simply-subdivided mesh to a Catmull-Clark
* subdivided mesh. */
void multires_do_versions_simple_to_catmull_clark(struct Object *object,
struct MultiresModifierData *mmd);
#ifdef __cplusplus
}
#endif

View File

@ -189,6 +189,7 @@ set(SRC
intern/multires_reshape_vertcos.c
intern/multires_subdiv.c
intern/multires_unsubdivide.c
intern/multires_versioning.c
intern/nla.c
intern/node.c
intern/object.c

View File

@ -747,7 +747,6 @@ static DerivedMesh *multires_dm_create_local(Scene *scene,
DerivedMesh *dm,
int lvl,
int totlvl,
int simple,
bool alloc_paint_mask,
int flags)
{
@ -757,7 +756,6 @@ static DerivedMesh *multires_dm_create_local(Scene *scene,
mmd.sculptlvl = lvl;
mmd.renderlvl = lvl;
mmd.totlvl = totlvl;
mmd.simple = simple;
flags |= MULTIRES_USE_LOCAL_MMD;
if (alloc_paint_mask) {
@ -1081,7 +1079,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene)
ob,
cddm,
totlvl,
mmd->simple,
false,
0,
mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE,
has_mask,
@ -1091,7 +1089,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene)
/* create multires DM from original mesh and displacements */
lowdm = multires_dm_create_local(
scene, ob, cddm, lvl, totlvl, mmd->simple, has_mask, MULTIRES_IGNORE_SIMPLIFY);
scene, ob, cddm, lvl, totlvl, has_mask, MULTIRES_IGNORE_SIMPLIFY);
cddm->release(cddm);
/* gather grid data */
@ -1156,7 +1154,7 @@ void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene)
ob,
cddm,
mmd->totlvl,
mmd->simple,
false,
0,
mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE,
has_mask,
@ -1254,7 +1252,7 @@ DerivedMesh *multires_make_derived_from_derived(
ob,
dm,
lvl,
mmd->simple,
false,
mmd->flags & eMultiresModifierFlag_ControlEdges,
mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE,
flags & MULTIRES_ALLOC_PAINT_MASK,
@ -1368,14 +1366,8 @@ void multiresModifier_sync_levels_ex(Object *ob_dst,
}
if (mmd_src->totlvl > mmd_dst->totlvl) {
if (mmd_dst->simple) {
multiresModifier_subdivide_to_level(
ob_dst, mmd_dst, mmd_src->totlvl, MULTIRES_SUBDIVIDE_SIMPLE);
}
else {
multiresModifier_subdivide_to_level(
ob_dst, mmd_dst, mmd_src->totlvl, MULTIRES_SUBDIVIDE_CATMULL_CLARK);
}
multiresModifier_subdivide_to_level(
ob_dst, mmd_dst, mmd_src->totlvl, MULTIRES_SUBDIVIDE_CATMULL_CLARK);
}
else {
multires_del_higher(mmd_dst, ob_dst, mmd_src->totlvl);

View File

@ -172,6 +172,12 @@ bool multires_reshape_context_create_from_modifier(MultiresReshapeContext *resha
struct MultiresModifierData *mmd,
int top_level);
bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape_context,
struct Object *object,
struct MultiresModifierData *mmd,
struct Subdiv *subdiv,
int top_level);
void multires_reshape_free_original_grids(MultiresReshapeContext *reshape_context);
void multires_reshape_context_free(MultiresReshapeContext *reshape_context);

View File

@ -81,11 +81,6 @@ static float v3_dist_from_plane(const float v[3], const float center[3], const f
void multires_reshape_apply_base_refit_base_mesh(MultiresReshapeContext *reshape_context)
{
if (reshape_context->mmd->simple) {
/* Simple subdivisions does not move base mesh verticies, so no refitting is needed. */
return;
}
Mesh *base_mesh = reshape_context->base_mesh;
MeshElemMap *pmap;

View File

@ -246,6 +246,22 @@ bool multires_reshape_context_create_from_modifier(MultiresReshapeContext *resha
struct Object *object,
struct MultiresModifierData *mmd,
int top_level)
{
Subdiv *subdiv = multires_reshape_create_subdiv(NULL, object, mmd);
const bool result = multires_reshape_context_create_from_subdiv(
reshape_context, object, mmd, subdiv, top_level);
reshape_context->need_free_subdiv = true;
return result;
}
bool multires_reshape_context_create_from_subdiv(MultiresReshapeContext *reshape_context,
struct Object *object,
struct MultiresModifierData *mmd,
struct Subdiv *subdiv,
int top_level)
{
context_zero(reshape_context);
@ -254,8 +270,8 @@ bool multires_reshape_context_create_from_modifier(MultiresReshapeContext *resha
reshape_context->mmd = mmd;
reshape_context->base_mesh = base_mesh;
reshape_context->subdiv = multires_reshape_create_subdiv(NULL, object, mmd);
reshape_context->need_free_subdiv = true;
reshape_context->subdiv = subdiv;
reshape_context->need_free_subdiv = false;
reshape_context->reshape.level = mmd->totlvl;
reshape_context->reshape.grid_size = BKE_subdiv_grid_size_from_level(

View File

@ -36,7 +36,7 @@
void BKE_multires_subdiv_settings_init(SubdivSettings *settings, const MultiresModifierData *mmd)
{
settings->is_simple = (mmd->simple != 0);
settings->is_simple = false;
settings->is_adaptive = true;
settings->level = settings->is_simple ? 1 : mmd->quality;
settings->use_creases = (mmd->flags & eMultiresModifierFlag_UseCrease);

View File

@ -0,0 +1,106 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2020 by Blender Foundation.
* All rights reserved.
*/
/** \file
* \ingroup bke
*/
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "BKE_subdiv.h"
#include "BKE_subdiv_eval.h"
#include "multires_reshape.h"
#include "opensubdiv_converter_capi.h"
#include "subdiv_converter.h"
static float simple_to_catmull_clark_get_edge_sharpness(
const OpenSubdiv_Converter *UNUSED(converter), int UNUSED(manifold_edge_index))
{
return 10.0f;
}
static bool simple_to_catmull_clark_is_infinite_sharp_vertex(
const OpenSubdiv_Converter *UNUSED(converter), int UNUSED(manifold_vertex_index))
{
return true;
}
static Subdiv *subdiv_for_simple_to_catmull_clark(Object *object, MultiresModifierData *mmd)
{
SubdivSettings subdiv_settings;
BKE_multires_subdiv_settings_init(&subdiv_settings, mmd);
Mesh *base_mesh = object->data;
OpenSubdiv_Converter converter;
BKE_subdiv_converter_init_for_mesh(&converter, &subdiv_settings, base_mesh);
converter.getEdgeSharpness = simple_to_catmull_clark_get_edge_sharpness;
converter.isInfiniteSharpVertex = simple_to_catmull_clark_is_infinite_sharp_vertex;
Subdiv *subdiv = BKE_subdiv_new_from_converter(&subdiv_settings, &converter);
BKE_subdiv_converter_free(&converter);
if (!BKE_subdiv_eval_begin_from_mesh(subdiv, base_mesh, NULL)) {
BKE_subdiv_free(subdiv);
return NULL;
}
return subdiv;
}
void multires_do_versions_simple_to_catmull_clark(Object *object, MultiresModifierData *mmd)
{
const Mesh *base_mesh = object->data;
if (base_mesh->totloop == 0) {
return;
}
/* Store the grids displacement in object space against the simple limit surface. */
{
Subdiv *subdiv = subdiv_for_simple_to_catmull_clark(object, mmd);
MultiresReshapeContext reshape_context;
if (!multires_reshape_context_create_from_subdiv(
&reshape_context, object, mmd, subdiv, mmd->totlvl)) {
BKE_subdiv_free(subdiv);
return;
}
multires_reshape_store_original_grids(&reshape_context);
multires_reshape_assign_final_coords_from_mdisps(&reshape_context);
multires_reshape_context_free(&reshape_context);
BKE_subdiv_free(subdiv);
}
/* Calculate the new tangent displacement against the new Catmull-Clark limit surface. */
{
MultiresReshapeContext reshape_context;
if (!multires_reshape_context_create_from_modifier(
&reshape_context, object, mmd, mmd->totlvl)) {
return;
}
multires_reshape_object_grids_to_tangent_displacement(&reshape_context);
multires_reshape_context_free(&reshape_context);
}
}

View File

@ -53,6 +53,7 @@
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_multires.h"
#include "BKE_node.h"
#include "MEM_guardedalloc.h"
@ -275,6 +276,21 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports))
}
}
/* Convert all Multires displacement to Catmull-Clark subdivision limit surface. */
if (!MAIN_VERSION_ATLEAST(bmain, 292, 1)) {
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
ModifierData *md;
for (md = ob->modifiers.first; md; md = md->next) {
if (md->type == eModifierType_Multires) {
MultiresModifierData *mmd = (MultiresModifierData *)md;
if (mmd->simple) {
multires_do_versions_simple_to_catmull_clark(ob, mmd);
}
}
}
}
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -97,7 +97,6 @@ typedef struct MultiresBakerJobData {
int len;
} ob_image;
DerivedMesh *lores_dm, *hires_dm;
bool simple;
int lvl, tot_lvl;
ListBase images;
} MultiresBakerJobData;
@ -247,7 +246,7 @@ static DerivedMesh *multiresbake_create_loresdm(Scene *scene, Object *ob, int *l
return dm;
}
static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *lvl, bool *simple)
static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *lvl)
{
Mesh *me = (Mesh *)ob->data;
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
@ -264,7 +263,6 @@ static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *l
CustomData_set_only_copy(&cddm->polyData, CD_MASK_BAREMESH.pmask);
*lvl = mmd->totlvl;
*simple = mmd->simple != 0;
tmp_mmd.lvl = mmd->totlvl;
tmp_mmd.sculptlvl = mmd->totlvl;
@ -386,7 +384,7 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
bkr.ob_image.array = bake_object_image_get_array(ob);
bkr.ob_image.len = ob->totcol;
bkr.hires_dm = multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl, &bkr.simple);
bkr.hires_dm = multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl);
bkr.lores_dm = multiresbake_create_loresdm(scene, ob, &bkr.lvl);
RE_multires_bake_images(&bkr);
@ -441,7 +439,7 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
data->ob_image.len = ob->totcol;
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
data->hires_dm = multiresbake_create_hiresdm(scene, ob, &data->tot_lvl, &data->simple);
data->hires_dm = multiresbake_create_hiresdm(scene, ob, &data->tot_lvl);
data->lores_dm = multiresbake_create_loresdm(scene, ob, &lvl);
data->lvl = lvl;
@ -491,7 +489,6 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
bkr.hires_dm = data->hires_dm;
bkr.tot_lvl = data->tot_lvl;
bkr.lvl = data->lvl;
bkr.simple = data->simple;
/* needed for proper progress bar */
bkr.tot_obj = tot_obj;

View File

@ -438,7 +438,6 @@
.sculptlvl = 0, \
.renderlvl = 0, \
.totlvl = 0, \
.simple = 0, \
.flags = eMultiresModifierFlag_UseCrease | eMultiresModifierFlag_ControlEdges, \
.uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS, \
.quality = 4, \

View File

@ -1049,7 +1049,8 @@ typedef struct MultiresModifierData {
ModifierData modifier;
char lvl, sculptlvl, renderlvl, totlvl;
char simple, flags, _pad[2];
char simple DNA_DEPRECATED;
char flags, _pad[2];
short quality;
short uv_smooth;
short boundary_smooth;

View File

@ -969,15 +969,6 @@ static void rna_fluid_set_type(Main *bmain, Scene *scene, PointerRNA *ptr)
rna_Modifier_dependency_update(bmain, scene, ptr);
}
static void rna_MultiresModifier_type_set(PointerRNA *ptr, int value)
{
Object *ob = (Object *)ptr->owner_id;
MultiresModifierData *mmd = (MultiresModifierData *)ptr->data;
multires_force_sculpt_rebuild(ob);
mmd->simple = value;
}
static void rna_MultiresModifier_level_range(
PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
{
@ -1604,15 +1595,8 @@ static int rna_MeshSequenceCacheModifier_read_velocity_get(PointerRNA *ptr)
#else
/* NOTE: *MUST* return subdivision_type property. */
static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const char type[])
static void rna_def_property_subdivision_common(StructRNA *srna)
{
static const EnumPropertyItem prop_subdivision_type_items[] = {
{SUBSURF_TYPE_CATMULL_CLARK, "CATMULL_CLARK", 0, "Catmull-Clark", ""},
{SUBSURF_TYPE_SIMPLE, "SIMPLE", 0, "Simple", ""},
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem prop_uv_smooth_items[] = {
{SUBSURF_UV_SMOOTH_NONE, "NONE", 0, "None", "UVs are not smoothed, boundaries are kept sharp"},
{SUBSURF_UV_SMOOTH_PRESERVE_CORNERS,
@ -1677,19 +1661,17 @@ static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const c
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);
RNA_def_property_ui_text(prop, "Subdivision Type", "Select type of subdivision algorithm");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
RNA_define_lib_overridable(false);
return prop;
}
static void rna_def_modifier_subsurf(BlenderRNA *brna)
{
static const EnumPropertyItem prop_subdivision_type_items[] = {
{SUBSURF_TYPE_CATMULL_CLARK, "CATMULL_CLARK", 0, "Catmull-Clark", ""},
{SUBSURF_TYPE_SIMPLE, "SIMPLE", 0, "Simple", ""},
{0, NULL, 0, NULL, NULL},
};
StructRNA *srna;
PropertyRNA *prop;
@ -1698,10 +1680,16 @@ static void rna_def_modifier_subsurf(BlenderRNA *brna)
RNA_def_struct_sdna(srna, "SubsurfModifierData");
RNA_def_struct_ui_icon(srna, ICON_MOD_SUBSURF);
rna_def_property_subdivision_common(srna, "subdivType");
rna_def_property_subdivision_common(srna);
RNA_define_lib_overridable(true);
prop = RNA_def_property(srna, "subdivision_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "subdivType");
RNA_def_property_enum_items(prop, prop_subdivision_type_items);
RNA_def_property_ui_text(prop, "Subdivision Type", "Select type of subdivision algorithm");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
/* see CCGSUBSURF_LEVEL_MAX for max limit */
prop = RNA_def_property(srna, "levels", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "levels");
@ -1893,8 +1881,7 @@ static void rna_def_modifier_multires(BlenderRNA *brna)
RNA_define_lib_overridable(true);
prop = rna_def_property_subdivision_common(srna, "simple");
RNA_def_property_enum_funcs(prop, NULL, "rna_MultiresModifier_type_set", NULL);
rna_def_property_subdivision_common(srna);
prop = RNA_def_property(srna, "levels", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "lvl");

View File

@ -478,7 +478,6 @@ static void advanced_panel_draw(const bContext *UNUSED(C), Panel *panel)
uiLayoutSetActive(layout, !has_displacement);
uiItemR(layout, ptr, "subdivision_type", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "quality", 0, NULL, ICON_NONE);
col = uiLayoutColumn(layout, false);

View File

@ -33,7 +33,6 @@ extern "C" {
typedef struct MultiresBakeRender {
Scene *scene;
DerivedMesh *lores_dm, *hires_dm;
bool simple;
int bake_filter; /* Bake-filter, aka margin */
int lvl, tot_lvl;
short mode;

View File

@ -766,10 +766,6 @@ static void *init_heights_data(MultiresBakeRender *bkr, Image *ima)
smd.uv_smooth = SUBSURF_UV_SMOOTH_PRESERVE_CORNERS;
smd.quality = 3;
if (bkr->simple) {
smd.subdivType = ME_SIMPLE_SUBSURF;
}
height_data->ssdm = subsurf_make_derived_from_derived(
bkr->lores_dm, &smd, bkr->scene, NULL, 0);
init_ccgdm_arrays(height_data->ssdm);