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:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-01-16 12:58:35 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-01-16 13:00:43 +0300
commit1579dc8c3b3974e98c513cffb2e407c11c32d11c (patch)
treed199f0264eb777eb4e5b7f5ff8d251f8b55621df /source/blender/modifiers/intern/MOD_multires.c
parent6ae72d2d41a30bf96e425656bbca166287a5f359 (diff)
Multires: Prepare for cached topology
Note that the actual caching is still disabled, since more tests is needed with more production-looking files.
Diffstat (limited to 'source/blender/modifiers/intern/MOD_multires.c')
-rw-r--r--source/blender/modifiers/intern/MOD_multires.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c
index fc8a376d2d7..9775a536e99 100644
--- a/source/blender/modifiers/intern/MOD_multires.c
+++ b/source/blender/modifiers/intern/MOD_multires.c
@@ -67,6 +67,28 @@ static void initData(ModifierData *md)
mmd->quality = 3;
}
+static void freeData(ModifierData *md)
+{
+ MultiresModifierData *mmd = (MultiresModifierData *) md;
+ if (mmd->subdiv != NULL) {
+ BKE_subdiv_free(mmd->subdiv);
+ }
+}
+
+/* Main goal of this function is to give usable subdivision surface descriptor
+ * which matches settings and topology. */
+static Subdiv *subdiv_descriptor_ensure(MultiresModifierData *mmd,
+ const SubdivSettings *subdiv_settings,
+ const Mesh *mesh)
+{
+ Subdiv *subdiv = BKE_subdiv_update_from_mesh(
+ mmd->subdiv, subdiv_settings, mesh);
+ if (false) {
+ mmd->subdiv = subdiv;
+ }
+ return subdiv;
+}
+
/* Subdivide into fully qualified mesh. */
static Mesh *multires_as_mesh(MultiresModifierData *mmd,
@@ -137,16 +159,14 @@ 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);
+ Subdiv *subdiv = subdiv_descriptor_ensure(mmd, &subdiv_settings, mesh);
if (subdiv == NULL) {
/* Happens on bad topology, ut also on empty input mesh. */
return result;
}
/* NOTE: Orco needs final coordinates on CPU side, which are expected to be
* accessible via MVert. For this reason we do not evaluate multires to
- * grids when orco is requested.
- */
+ * grids when orco is requested. */
const bool for_orco = (ctx->flag & MOD_APPLY_ORCO) != 0;
if ((ctx->object->mode & OB_MODE_SCULPT) && !for_orco) {
/* NOTE: CCG takes ownership over Subdiv. */
@@ -156,9 +176,10 @@ static Mesh *applyModifier(ModifierData *md,
}
else {
result = multires_as_mesh(mmd, ctx, mesh, subdiv);
- /* TODO(sergey): Cache subdiv somehow. */
// BKE_subdiv_stats_print(&subdiv->stats);
- BKE_subdiv_free(subdiv);
+ if (subdiv != mmd->subdiv) {
+ BKE_subdiv_free(subdiv);
+ }
}
return result;
}
@@ -188,7 +209,7 @@ ModifierTypeInfo modifierType_Multires = {
/* initData */ initData,
/* requiredDataMask */ NULL,
- /* freeData */ NULL,
+ /* freeData */ freeData,
/* isDisabled */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,