[Bf-blender-cvs] [134619fabbc] master: Multires: Subdivide Simple and Subdivide Linear

Pablo Dobarro noreply at git.blender.org
Thu Apr 30 17:00:13 CEST 2020


Commit: 134619fabbc550afb275260b17c9c7910e7a1c53
Author: Pablo Dobarro
Date:   Thu Apr 30 15:15:19 2020 +0200
Branches: master
https://developer.blender.org/rB134619fabbc550afb275260b17c9c7910e7a1c53

Multires: Subdivide Simple and Subdivide Linear

This introduces two alternative subdivision modes that generates
displacement on the grids that look as Simple subdivisions but while
using the Catmull-Clark subdivision type in the modifier. This way,
Simple and Catmull-Clark subdivision can be combined when creating new
levels if needed, for example, to sculpt hard surface objects.

Subdivide simple smooths the sculpted data when creating a new
subdivision level. Subdivide linear also preserves the sharpness
in the sculpted data.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D7415

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_multires.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/multires.c
M	source/blender/blenkernel/intern/multires_reshape.c
M	source/blender/blenkernel/intern/multires_reshape.h
M	source/blender/blenkernel/intern/multires_reshape_smooth.c
A	source/blender/blenkernel/intern/multires_reshape_subdivide.c
M	source/blender/editors/object/object_modifier.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 9a034dfe378..6e6bcd81cdc 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -696,7 +696,15 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col = split.column()
 
         col.enabled = ob.mode != 'EDIT'
-        col.operator("object.multires_subdivide", text="Subdivide")
+        op = col.operator("object.multires_subdivide", text="Subdivide")
+        op.mode = 'CATMULL_CLARK'
+
+        op = col.operator("object.multires_subdivide", text="Subdivide Simple")
+        op.mode = 'SIMPLE'
+
+        op = col.operator("object.multires_subdivide", text="Subdivide Linear")
+        op.mode = 'LINEAR'
+
         col.operator("object.multires_higher_levels_delete", text="Delete Higher")
         col.operator("object.multires_unsubdivide", text="Unsubdivide")
         col.operator("object.multires_reshape", text="Reshape")
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h
index 62366f7952b..927aad287a6 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -180,13 +180,25 @@ bool multiresModifier_reshapeFromCCG(const int tot_level,
                                      struct SubdivCCG *subdiv_ccg);
 
 /* Subdivide multires displacement once. */
-void multiresModifier_subdivide(struct Object *object, struct MultiresModifierData *mmd);
+
+typedef enum eMultiresSubdivideModeType {
+  MULTIRES_SUBDIVIDE_CATMULL_CLARK,
+  MULTIRES_SUBDIVIDE_SIMPLE,
+  MULTIRES_SUBDIVIDE_LINEAR,
+} eMultiresSubdivideModeType;
+
+void multiresModifier_subdivide(struct Object *object,
+                                struct MultiresModifierData *mmd,
+                                const eMultiresSubdivideModeType mode);
+void multires_subdivide_create_tangent_displacement_linear_grids(struct Object *object,
+                                                                 struct MultiresModifierData *mmd);
 
 /* Subdivide displacement to the given level.
  * If level is lower than the current top level nothing happens. */
 void multiresModifier_subdivide_to_level(struct Object *object,
                                          struct MultiresModifierData *mmd,
-                                         const int top_level);
+                                         const int top_level,
+                                         const eMultiresSubdivideModeType mode);
 
 /* Subdivision integration, defined in multires_subdiv.c */
 
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 688e71da8da..57d173d9f56 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -175,6 +175,7 @@ set(SRC
   intern/multires_reshape_apply_base.c
   intern/multires_reshape_ccg.c
   intern/multires_reshape_smooth.c
+  intern/multires_reshape_subdivide.c
   intern/multires_reshape_util.c
   intern/multires_reshape_vertcos.c
   intern/multires_subdiv.c
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 317c59182ed..d79dbbb7d32 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -2234,7 +2234,14 @@ void multiresModifier_sync_levels_ex(Object *ob_dst,
   }
 
   if (mmd_src->totlvl > mmd_dst->totlvl) {
-    multiresModifier_subdivide_to_level(ob_dst, mmd_dst, mmd_src->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);
+    }
   }
   else {
     multires_del_higher(mmd_dst, ob_dst, mmd_src->totlvl);
diff --git a/source/blender/blenkernel/intern/multires_reshape.c b/source/blender/blenkernel/intern/multires_reshape.c
index 9b3242ba73a..480a1d0b2a0 100644
--- a/source/blender/blenkernel/intern/multires_reshape.c
+++ b/source/blender/blenkernel/intern/multires_reshape.c
@@ -28,8 +28,6 @@
 #include "DNA_modifier_types.h"
 #include "DNA_scene_types.h"
 
-#include "BLI_math_vector.h"
-
 #include "BKE_customdata.h"
 #include "BKE_lib_id.h"
 #include "BKE_mesh.h"
@@ -37,6 +35,8 @@
 #include "BKE_modifier.h"
 #include "BKE_multires.h"
 #include "BKE_subdiv.h"
+#include "BKE_subsurf.h"
+#include "BLI_math_vector.h"
 
 #include "DEG_depsgraph_query.h"
 
@@ -171,15 +171,18 @@ bool multiresModifier_reshapeFromCCG(const int tot_level,
 /** \name Subdivision
  * \{ */
 
-void multiresModifier_subdivide(Object *object, MultiresModifierData *mmd)
+void multiresModifier_subdivide(Object *object,
+                                MultiresModifierData *mmd,
+                                const eMultiresSubdivideModeType mode)
 {
   const int top_level = mmd->totlvl + 1;
-  multiresModifier_subdivide_to_level(object, mmd, top_level);
+  multiresModifier_subdivide_to_level(object, mmd, top_level, mode);
 }
 
 void multiresModifier_subdivide_to_level(struct Object *object,
                                          struct MultiresModifierData *mmd,
-                                         const int top_level)
+                                         const int top_level,
+                                         const eMultiresSubdivideModeType mode)
 {
   if (top_level <= mmd->totlvl) {
     return;
@@ -196,7 +199,12 @@ void multiresModifier_subdivide_to_level(struct Object *object,
   }
   if (!has_mdisps || top_level == 1) {
     multires_reshape_ensure_grids(coarse_mesh, top_level);
-    multires_set_tot_level(object, mmd, top_level);
+    if (ELEM(mode, MULTIRES_SUBDIVIDE_LINEAR, MULTIRES_SUBDIVIDE_SIMPLE)) {
+      multires_subdivide_create_tangent_displacement_linear_grids(object, mmd);
+    }
+    else {
+      multires_set_tot_level(object, mmd, top_level);
+    }
     return;
   }
 
@@ -205,16 +213,22 @@ void multiresModifier_subdivide_to_level(struct Object *object,
   if (!multires_reshape_context_create_from_subdivide(&reshape_context, object, mmd, top_level)) {
     return;
   }
+
   multires_reshape_store_original_grids(&reshape_context);
   multires_reshape_ensure_grids(coarse_mesh, reshape_context.top.level);
   multires_reshape_assign_final_coords_from_orig_mdisps(&reshape_context);
 
-  /* Free original grids which makes it so smoothing with details thinks all the details were
-   * added against base mesh's limit surface. This is similar behavior to as if we've done all
-   * displacement in sculpt mode at the old top level and then propagated to the new top level. */
-  multires_reshape_free_original_grids(&reshape_context);
+  if (ELEM(mode, MULTIRES_SUBDIVIDE_LINEAR, MULTIRES_SUBDIVIDE_SIMPLE)) {
+    multires_reshape_smooth_object_grids(&reshape_context, mode);
+  }
+  else {
+    /* Free original grids which makes it so smoothing with details thinks all the details were
+     * added against base mesh's limit surface. This is similar behavior to as if we've done all
+     * displacement in sculpt mode at the old top level and then propagated to the new top level.*/
+    multires_reshape_free_original_grids(&reshape_context);
 
-  multires_reshape_smooth_object_grids_with_details(&reshape_context);
+    multires_reshape_smooth_object_grids_with_details(&reshape_context);
+  }
   multires_reshape_object_grids_to_tangent_displacement(&reshape_context);
   multires_reshape_context_free(&reshape_context);
 
diff --git a/source/blender/blenkernel/intern/multires_reshape.h b/source/blender/blenkernel/intern/multires_reshape.h
index 3b06e126f15..e3127885aa3 100644
--- a/source/blender/blenkernel/intern/multires_reshape.h
+++ b/source/blender/blenkernel/intern/multires_reshape.h
@@ -25,6 +25,7 @@
 #define __BKE_INTERN_MULTIRES_RESHAPE_H__
 
 #include "BLI_sys_types.h"
+#include "BKE_multires.h"
 
 struct Depsgraph;
 struct GridPaintMask;
@@ -289,7 +290,8 @@ void multires_reshape_smooth_object_grids_with_details(
  *
  * Makes it so surface on top level looks smooth. Details are not preserved
  */
-void multires_reshape_smooth_object_grids(const MultiresReshapeContext *reshape_context);
+void multires_reshape_smooth_object_grids(const MultiresReshapeContext *reshape_context,
+                                          const enum eMultiresSubdivideModeType mode);
 
 /* --------------------------------------------------------------------
  * Displacement, space conversion.
@@ -324,5 +326,4 @@ void multires_reshape_apply_base_refine_from_base(MultiresReshapeContext *reshap
  *
  * NOTE: Will re-evaluate all leading modifiers, so it's not cheap. */
 void multires_reshape_apply_base_refine_from_deform(MultiresReshapeContext *reshape_context);
-
 #endif /* __BKE_INTERN_MULTIRES_RESHAPE_H__ */
diff --git a/source/blender/blenkernel/intern/multires_reshape_smooth.c b/source/blender/blenkernel/intern/multires_reshape_smooth.c
index 22864143f80..3ddd20720d5 100644
--- a/source/blender/blenkernel/intern/multires_reshape_smooth.c
+++ b/source/blender/blenkernel/intern/multires_reshape_smooth.c
@@ -119,6 +119,14 @@ typedef struct MultiresReshapeSmoothContext {
   Subdiv *reshape_subdiv;
 
   SurfaceGrid *base_surface_grids;
+
+  /* Defines how displacement is interpolated on the higher levels (for example, whether
+   * displacement is smoothed in Catmull-Clark mode or interpolated linearly preserving sharp edges
+   * of the current sculpt level).
+   *
+   * NOTE: Uses same enumerator type as Subdivide operator, since the values are the same and
+   * decoupling type just adds extra headache to convert one enumerator to another. */
+  eMultiresSubdivideModeType smoothing_type;
 } MultiresReshapeSmoothContext;
 
 /** \} */
@@ -412,15 +420,17 @@ static int get_reshape_level_resolution(const MultiresReshapeContext *reshape_co
 static char get_effective_edge_crease_char(
     const MultiresReshapeSmoothContext *reshape_smooth_context, const MEdge *base_edge)
 {
-  const MultiresReshapeContext *reshape_context = reshape_smooth_context->reshape_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list