[Bf-blender-cvs] [e5c9bf3aa28] master: Quadriflow: Symmetry support

Pablo Dobarro noreply at git.blender.org
Thu Sep 26 16:43:06 CEST 2019


Commit: e5c9bf3aa28af3d1edddecb909b5a95fe029e18e
Author: Pablo Dobarro
Date:   Wed Sep 25 14:54:34 2019 +0200
Branches: master
https://developer.blender.org/rBe5c9bf3aa28af3d1edddecb909b5a95fe029e18e

Quadriflow: Symmetry support

This patch adds paint symmetry support to Quadriflow. It bisects and mirrors the input and the output from the remesher to build the final mesh using the preserve boundary option.
This is also an important performance improvement in Quadriflow because it only needs to process half of the mesh with half the resolution.

Reviewed By: jbakker

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

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

A	source/blender/blenkernel/BKE_mirror.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/mirror.c
M	source/blender/editors/object/object_remesh.c
M	source/blender/modifiers/intern/MOD_mirror.c

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

diff --git a/source/blender/blenkernel/BKE_mirror.h b/source/blender/blenkernel/BKE_mirror.h
new file mode 100644
index 00000000000..20eb8a920fc
--- /dev/null
+++ b/source/blender/blenkernel/BKE_mirror.h
@@ -0,0 +1,45 @@
+/*
+ * 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) 2019 Blender Foundation.
+ * All rights reserved.
+ */
+
+#ifndef __BKE_MIRROR_H__
+#define __BKE_MIRROR_H__
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BLI_utildefines.h"
+
+struct MirrorModifierData;
+struct ModifierEvalContext;
+struct Object;
+
+struct Mesh *BKE_mirror_bisect_on_mirror_plane(struct MirrorModifierData *mmd,
+                                               const struct Mesh *mesh,
+                                               int axis,
+                                               const float plane_co[3],
+                                               float plane_no[3]);
+
+struct Mesh *BKE_mirror_apply_mirror_on_axis(struct MirrorModifierData *mmd,
+                                             const struct ModifierEvalContext *UNUSED(ctx),
+                                             struct Object *ob,
+                                             const struct Mesh *mesh,
+                                             int axis);
+
+#endif /* __BKE_MIRROR_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 834f4dd1b9e..f598a81ff5e 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -159,6 +159,7 @@ set(SRC
   intern/mesh_runtime.c
   intern/mesh_tangent.c
   intern/mesh_validate.c
+  intern/mirror.c
   intern/modifier.c
   intern/movieclip.c
   intern/multires.c
@@ -312,6 +313,7 @@ set(SRC
   BKE_mesh_remesh_voxel.h
   BKE_mesh_runtime.h
   BKE_mesh_tangent.h
+  BKE_mirror.h
   BKE_modifier.h
   BKE_movieclip.h
   BKE_multires.h
diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/blenkernel/intern/mirror.c
similarity index 78%
copy from source/blender/modifiers/intern/MOD_mirror.c
copy to source/blender/blenkernel/intern/mirror.c
index c91f5d41c5e..f7677d7441a 100644
--- a/source/blender/modifiers/intern/MOD_mirror.c
+++ b/source/blender/blenkernel/intern/mirror.c
@@ -10,15 +10,15 @@
  * 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,
+ * 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) 2005 by the Blender Foundation.
+ * The Original Code is Copyright (C) Blender Foundation.
  * All rights reserved.
  */
 
 /** \file
- * \ingroup modifiers
+ * \ingroup bke
  */
 
 #include "BLI_math.h"
@@ -38,41 +38,14 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "DEG_depsgraph_build.h"
-#include "DEG_depsgraph_query.h"
-
 #include "MOD_modifiertypes.h"
 
-static void initData(ModifierData *md)
-{
-  MirrorModifierData *mmd = (MirrorModifierData *)md;
 
-  mmd->flag |= (MOD_MIR_AXIS_X | MOD_MIR_VGROUP);
-  mmd->tolerance = 0.001;
-  mmd->mirror_ob = NULL;
-}
-
-static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
-{
-  MirrorModifierData *mmd = (MirrorModifierData *)md;
-
-  walk(userData, ob, &mmd->mirror_ob, IDWALK_CB_NOP);
-}
-
-static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
-  MirrorModifierData *mmd = (MirrorModifierData *)md;
-  if (mmd->mirror_ob != NULL) {
-    DEG_add_object_relation(ctx->node, mmd->mirror_ob, DEG_OB_COMP_TRANSFORM, "Mirror Modifier");
-    DEG_add_modifier_to_transform_relation(ctx->node, "Mirror Modifier");
-  }
-}
-
-static Mesh *doBiscetOnMirrorPlane(MirrorModifierData *mmd,
-                                   const Mesh *mesh,
-                                   int axis,
-                                   const float plane_co[3],
-                                   float plane_no[3])
+Mesh *BKE_mirror_bisect_on_mirror_plane(MirrorModifierData *mmd,
+                                        const Mesh *mesh,
+                                        int axis,
+                                        const float plane_co[3],
+                                        float plane_no[3])
 {
   bool do_bisect_flip_axis = ((axis == 0 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_X) ||
                               (axis == 1 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_Y) ||
@@ -124,11 +97,11 @@ static Mesh *doBiscetOnMirrorPlane(MirrorModifierData *mmd,
   return result;
 }
 
-static Mesh *doMirrorOnAxis(MirrorModifierData *mmd,
-                            const ModifierEvalContext *UNUSED(ctx),
-                            Object *ob,
-                            const Mesh *mesh,
-                            int axis)
+Mesh *BKE_mirror_apply_mirror_on_axis(MirrorModifierData *mmd,
+                                      const ModifierEvalContext *UNUSED(ctx),
+                                      Object *ob,
+                                      const Mesh *mesh,
+                                      int axis)
 {
   const float tolerance_sq = mmd->tolerance * mmd->tolerance;
   const bool do_vtargetmap = (mmd->flag & MOD_MIR_NO_MERGE) == 0;
@@ -184,7 +157,7 @@ static Mesh *doMirrorOnAxis(MirrorModifierData *mmd,
 
   Mesh *mesh_bisect = NULL;
   if (do_bisect) {
-    mesh_bisect = doBiscetOnMirrorPlane(mmd, mesh, axis, plane_co, plane_no);
+    mesh_bisect = BKE_mirror_bisect_on_mirror_plane(mmd, mesh, axis, plane_co, plane_no);
     mesh = mesh_bisect;
   }
 
@@ -438,79 +411,3 @@ static Mesh *doMirrorOnAxis(MirrorModifierData *mmd,
 
   return result;
 }
-
-static Mesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
-                                      const ModifierEvalContext *ctx,
-                                      Object *ob,
-                                      Mesh *mesh)
-{
-  Mesh *result = mesh;
-
-  /* check which axes have been toggled and mirror accordingly */
-  if (mmd->flag & MOD_MIR_AXIS_X) {
-    result = doMirrorOnAxis(mmd, ctx, ob, result, 0);
-  }
-  if (mmd->flag & MOD_MIR_AXIS_Y) {
-    Mesh *tmp = result;
-    result = doMirrorOnAxis(mmd, ctx, ob, result, 1);
-    if (tmp != mesh) {
-      /* free intermediate results */
-      BKE_id_free(NULL, tmp);
-    }
-  }
-  if (mmd->flag & MOD_MIR_AXIS_Z) {
-    Mesh *tmp = result;
-    result = doMirrorOnAxis(mmd, ctx, ob, result, 2);
-    if (tmp != mesh) {
-      /* free intermediate results */
-      BKE_id_free(NULL, tmp);
-    }
-  }
-
-  return result;
-}
-
-static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
-{
-  Mesh *result;
-  MirrorModifierData *mmd = (MirrorModifierData *)md;
-
-  result = mirrorModifier__doMirror(mmd, ctx, ctx->object, mesh);
-
-  if (result != mesh) {
-    result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
-  }
-  return result;
-}
-
-ModifierTypeInfo modifierType_Mirror = {
-    /* name */ "Mirror",
-    /* structName */ "MirrorModifierData",
-    /* structSize */ sizeof(MirrorModifierData),
-    /* type */ eModifierTypeType_Constructive,
-    /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
-        eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode |
-        eModifierTypeFlag_AcceptsCVs |
-        /* this is only the case when 'MOD_MIR_VGROUP' is used */
-        eModifierTypeFlag_UsesPreview,
-
-    /* copyData */ modifier_copyData_generic,
-
-    /* deformVerts */ NULL,
-    /* deformMatrices */ NULL,
-    /* deformVertsEM */ NULL,
-    /* deformMatricesEM */ NULL,
-    /* applyModifier */ applyModifier,
-
-    /* initData */ initData,
-    /* requiredDataMask */ NULL,
-    /* freeData */ NULL,
-    /* isDisabled */ NULL,
-    /* updateDepsgraph */ updateDepsgraph,
-    /* dependsOnTime */ NULL,
-    /* dependsOnNormals */ NULL,
-    /* foreachObjectLink */ foreachObjectLink,
-    /* foreachIDLink */ NULL,
-    /* foreachTexLink */ NULL,
-    /* freeRuntimeData */ NULL,
-};
diff --git a/source/blender/editors/object/object_remesh.c b/source/blender/editors/object/object_remesh.c
index 6075867b552..f8ca3b268cc 100644
--- a/source/blender/editors/object/object_remesh.c
+++ b/source/blender/editors/object/object_remesh.c
@@ -40,10 +40,12 @@
 
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_runtime.h"
-#include "BKE_library.h"
+#include "BKE_mirror.h"
+#include "BKE_modifier.h"
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
@@ -170,14 +172,26 @@ enum {
 
 /****************** quadriflow remesh operator *********************/
 
+#define QUADRIFLOW_MIRROR_BISECT_TOLERANCE 0.005f
+
+typedef enum eSymmetryAxes {
+  SYMMETRY_AXES_X = (1 << 0),
+  SYMMETRY_AXES_Y = (1 << 1),
+  SYMMETRY_AXES_Z = (1 << 2),
+} eSymmetryAxes;
+
 typedef struct QuadriFlowJob {
   /* from wmJob */
   struct Object *owner;
+  struct Main *bmain;
   short *stop, *do_update;
   float *progress;
 
   int target_faces;
   int seed;
+  bool use_paint_symmetry;
+  eSymmetryAxes symmetry_axes;
+
   bool use_preserve_sharp;
   bool use_preserve_boundary;
   bool use_mesh_curvature;
@@ -228,6 +242,66 @@ static void quadriflow_update_job(void *customdata, float progress, int *cancel)
   *(qj->progress) = progress;
 }
 
+static Mesh *remesh_symmetry_bisect(Mai

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list