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@blender.org>2020-10-26 14:32:22 +0300
committerSergey Sharybin <sergey@blender.org>2020-10-27 12:31:48 +0300
commit17381c7b90eb3acde53eca013ae5a5a55699f17d (patch)
tree403a988cb4a5698c4ebcfdb0e34e45e0c799987e /source/blender/blenkernel/intern/multires_versioning.c
parent09139e41ed4eaf4d9b8943e92b8604d979dbbc92 (diff)
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
Diffstat (limited to 'source/blender/blenkernel/intern/multires_versioning.c')
-rw-r--r--source/blender/blenkernel/intern/multires_versioning.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/multires_versioning.c b/source/blender/blenkernel/intern/multires_versioning.c
new file mode 100644
index 00000000000..4c0d7165cd0
--- /dev/null
+++ b/source/blender/blenkernel/intern/multires_versioning.c
@@ -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);
+ }
+}