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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/modifiers/intern/MOD_subsurf.c')
-rw-r--r--source/blender/modifiers/intern/MOD_subsurf.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index e66b3fdbafb..1899faa3583 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -1,6 +1,4 @@
/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
* 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
@@ -17,30 +15,21 @@
*
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
* All rights reserved.
- *
- * Contributor(s): Daniel Dunbar
- * Ton Roosendaal,
- * Ben Batt,
- * Brecht Van Lommel,
- * Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- *
*/
-/** \file blender/modifiers/intern/MOD_subsurf.c
- * \ingroup modifiers
+/** \file
+ * \ingroup modifiers
*/
#include <stddef.h>
+#include "BLI_utildefines.h"
+
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_mesh_types.h"
-#include "BLI_utildefines.h"
-
#include "BKE_cdderivedmesh.h"
#include "BKE_scene.h"
#include "BKE_subdiv.h"
@@ -75,6 +64,7 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
modifier_copyData_generic(md, target, flag);
tsmd->emCache = tsmd->mCache = NULL;
+ tsmd->subdiv = NULL;
}
static void freeData(ModifierData *md)
@@ -89,6 +79,9 @@ static void freeData(ModifierData *md)
ccgSubSurf_free(smd->emCache);
smd->emCache = NULL;
}
+ if (smd->subdiv != NULL) {
+ BKE_subdiv_free(smd->subdiv);
+ }
}
static bool isDisabled(const Scene *scene, ModifierData *md, bool useRenderParams)
@@ -122,6 +115,18 @@ static void subdiv_settings_init(SubdivSettings *settings,
BKE_subdiv_fvar_interpolation_from_uv_smooth(smd->uv_smooth);
}
+/* Main goal of this function is to give usable subdivision surface descriptor
+ * which matches settings and topology. */
+static Subdiv *subdiv_descriptor_ensure(SubsurfModifierData *smd,
+ const SubdivSettings *subdiv_settings,
+ const Mesh *mesh)
+{
+ Subdiv *subdiv = BKE_subdiv_update_from_mesh(
+ smd->subdiv, subdiv_settings, mesh);
+ smd->subdiv = subdiv;
+ return subdiv;
+}
+
/* Subdivide into fully qualified mesh. */
static void subdiv_mesh_settings_init(SubdivToMeshSettings *settings,
@@ -189,24 +194,24 @@ static Mesh *applyModifier(ModifierData *md,
if (subdiv_settings.level == 0) {
return result;
}
- /* TODO(sergey): Try to re-use subdiv when possible. */
- Subdiv *subdiv = BKE_subdiv_new_from_mesh(&subdiv_settings, mesh);
+ BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh);
+ Subdiv *subdiv = subdiv_descriptor_ensure(smd, &subdiv_settings, mesh);
if (subdiv == NULL) {
- /* Happens on bad topology, ut also on empty input mesh. */
+ /* Happens on bad topology, but also on empty input mesh. */
return result;
}
/* TODO(sergey): Decide whether we ever want to use CCG for subsurf,
- * maybe when it is a last modifier in the stack?
- */
+ * maybe when it is a last modifier in the stack? */
if (true) {
result = subdiv_as_mesh(smd, ctx, mesh, subdiv);
}
else {
result = subdiv_as_ccg(smd, ctx, mesh, subdiv);
}
- /* TODO(sergey): Cache subdiv somehow. */
// BKE_subdiv_stats_print(&subdiv->stats);
- BKE_subdiv_free(subdiv);
+ if (subdiv != smd->subdiv) {
+ BKE_subdiv_free(subdiv);
+ }
return result;
}