[Bf-blender-cvs] [ef0e0af3325] soc-2021-porting-modifiers-to-nodes-remesh-blocks: - Renamed Remesh to Remesh Block. - Moved Dualcon Remesh to BKE - Used new BKE_mesh_remesh_blocks in modifier and node.

Fabian Schempp noreply at git.blender.org
Tue Jul 13 22:00:55 CEST 2021


Commit: ef0e0af33258167b9cd2db0d9566ef90efc56f65
Author: Fabian Schempp
Date:   Mon Jul 12 23:55:33 2021 +0200
Branches: soc-2021-porting-modifiers-to-nodes-remesh-blocks
https://developer.blender.org/rBef0e0af33258167b9cd2db0d9566ef90efc56f65

- Renamed Remesh to Remesh Block.
- Moved Dualcon Remesh to BKE
- Used new BKE_mesh_remesh_blocks in modifier and node.

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_mesh.h
A	source/blender/blenkernel/BKE_mesh_remesh_blocks.h
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/mesh_remesh_blocks.c
M	source/blender/blenkernel/intern/node.cc
M	source/blender/modifiers/intern/MOD_remesh.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
R050	source/blender/nodes/geometry/nodes/node_geo_remesh.cc	source/blender/nodes/geometry/nodes/node_geo_remesh_blocks.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index b539a9bbef5..346ece0a315 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -548,7 +548,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeEdgeSplit"),
         NodeItem("GeometryNodeSubdivisionSurface"),
         NodeItem("GeometryNodeMeshSubdivide"),
-        NodeItem("GeometryNodeRemesh"),
+        NodeItem("GeometryNodeRemeshBlocks"),
     ]),
     GeometryNodeCategory("GEO_PRIMITIVES_MESH", "Mesh Primitives", items=[
         NodeItem("GeometryNodeMeshCircle"),
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 12560ebed7b..7c61c33e6c1 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -24,6 +24,7 @@
 
 #include "BKE_mesh_types.h"
 #include "BLI_utildefines.h"
+#include "DNA_customdata_types.h"
 
 struct BLI_Stack;
 struct BMesh;
diff --git a/source/blender/blenkernel/BKE_mesh_remesh_blocks.h b/source/blender/blenkernel/BKE_mesh_remesh_blocks.h
new file mode 100644
index 00000000000..9078413e471
--- /dev/null
+++ b/source/blender/blenkernel/BKE_mesh_remesh_blocks.h
@@ -0,0 +1,52 @@
+/*
+ * 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 by Blender Foundation
+ * All rights reserved.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bke
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Mesh;
+
+typedef enum eRemeshBlocksMode {
+  /* blocky */
+  REMESH_BLOCKS_CENTROID = 0,
+  /* smooth */
+  REMESH_BLOCKS_MASS_POINT = 1,
+  /* keeps sharp edges */
+  REMESH_BLOCKS_SHARP_FEATURES = 2,
+} eRemeshBlocksMode;
+
+
+struct Mesh *BKE_mesh_remesh_blocks_to_mesh_nomain(struct Mesh *mesh,
+                                            const char remesh_flag,
+                                            const char remesh_mode,
+                                            const float threshold,
+                                            const int hermite_num,
+                                            const float scale,
+                                            const int depth);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 9b705e8ff45..14ce314af75 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1458,7 +1458,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_VIEWER 1067
 #define GEO_NODE_CURVE_PRIMITIVE_LINE 1068
 #define GEO_NODE_CURVE_ENDPOINTS 1069
-#define GEO_NODE_REMESH 1070
+#define GEO_NODE_REMESH_BLOCKS 1070
 
 /** \} */
 
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 2c25b940578..3bd79628743 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -193,6 +193,7 @@ set(SRC
   intern/mesh_normals.cc
   intern/mesh_remap.c
   intern/mesh_remesh_voxel.c
+  intern/mesh_remesh_blocks.c
   intern/mesh_runtime.c
   intern/mesh_sample.cc
   intern/mesh_tangent.c
@@ -386,6 +387,7 @@ set(SRC
   BKE_mesh_mapping.h
   BKE_mesh_mirror.h
   BKE_mesh_remap.h
+  BKE_mesh_remesh_blocks.h
   BKE_mesh_remesh_voxel.h
   BKE_mesh_runtime.h
   BKE_mesh_sample.hh
@@ -487,6 +489,16 @@ set(LIB
   bf_simulation
 )
 
+if(WITH_MOD_REMESH)
+  list(APPEND INC
+          ../../../intern/dualcon
+          )
+  list(APPEND LIB
+          bf_intern_dualcon
+          )
+  add_definitions(-DWITH_MOD_REMESH)
+endif()
+
 if(WITH_BINRELOC)
   list(APPEND INC_SYS
     ${BINRELOC_INCLUDE_DIRS}
diff --git a/source/blender/blenkernel/intern/mesh_remesh_blocks.c b/source/blender/blenkernel/intern/mesh_remesh_blocks.c
new file mode 100644
index 00000000000..0915d641303
--- /dev/null
+++ b/source/blender/blenkernel/intern/mesh_remesh_blocks.c
@@ -0,0 +1,165 @@
+/*
+ * 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 by Blender Foundation
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_remesh_blocks.h" /* own include */
+#include "BKE_mesh_runtime.h"
+
+#include "BLI_math_vector.h"
+#include "BLI_threads.h"
+
+#include "DNA_modifier_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "dualcon.h"
+
+static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
+{
+  memset(input, 0, sizeof(DualConInput));
+
+  input->co = (void *)mesh->mvert;
+  input->co_stride = sizeof(MVert);
+  input->totco = mesh->totvert;
+
+  input->mloop = (void *)mesh->mloop;
+  input->loop_stride = sizeof(MLoop);
+
+  BKE_mesh_runtime_looptri_ensure(mesh);
+  input->looptri = (void *)mesh->runtime.looptris.array;
+  input->tri_stride = sizeof(MLoopTri);
+  input->tottri = mesh->runtime.looptris.len;
+
+  INIT_MINMAX(input->min, input->max);
+  BKE_mesh_minmax(mesh, input->min, input->max);
+}
+
+/* simple structure to hold the output: a CDDM and two counters to
+ * keep track of the current elements */
+typedef struct {
+  Mesh *mesh;
+  int curvert, curface;
+} DualConOutput;
+
+/* allocate and initialize a DualConOutput */
+static void *dualcon_alloc_output(int totvert, int totquad)
+{
+  DualConOutput *output;
+
+  if (!(output = MEM_callocN(sizeof(DualConOutput), "DualConOutput"))) {
+    return NULL;
+  }
+
+  output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad);
+  return output;
+}
+
+static void dualcon_add_vert(void *output_v, const float co[3])
+{
+  DualConOutput *output = output_v;
+  Mesh *mesh = output->mesh;
+
+  BLI_assert(output->curvert < mesh->totvert);
+
+  copy_v3_v3(mesh->mvert[output->curvert].co, co);
+  output->curvert++;
+}
+
+static void dualcon_add_quad(void *output_v, const int vert_indices[4])
+{
+  DualConOutput *output = output_v;
+  Mesh *mesh = output->mesh;
+  MLoop *mloop;
+  MPoly *cur_poly;
+  int i;
+
+  BLI_assert(output->curface < mesh->totpoly);
+
+  mloop = mesh->mloop;
+  cur_poly = &mesh->mpoly[output->curface];
+
+  cur_poly->loopstart = output->curface * 4;
+  cur_poly->totloop = 4;
+  for (i = 0; i < 4; i++) {
+    mloop[output->curface * 4 + i].v = vert_indices[i];
+  }
+
+  output->curface++;
+}
+
+Mesh *BKE_mesh_remesh_blocks_to_mesh_nomain(Mesh *mesh,
+                                            const char remesh_flag,
+                                            const char remesh_mode,
+                                            const float threshold,
+                                            const int hermite_num,
+                                            const float scale,
+                                            const int depth)
+{
+  DualConOutput *output;
+  DualConInput input;
+  Mesh *result;
+  DualConFlags flags = 0;
+  DualConMode mode = 0;
+
+  /* Dualcon modes. */
+  init_dualcon_mesh(&input, mesh);
+
+  if (remesh_flag & MOD_REMESH_FLOOD_FILL) {
+    flags |= DUALCON_FLOOD_FILL;
+  }
+
+  switch (remesh_mode) {
+    case REMESH_BLOCKS_CENTROID:
+      mode = DUALCON_CENTROID;
+      break;
+    case REMESH_BLOCKS_MASS_POINT:
+      mode = DUALCON_MASS_POINT;
+      break;
+    case REMESH_BLOCKS_SHARP_FEATURES:
+      mode = DUALCON_SHARP_FEATURES;
+      break;
+  }
+  /* TODO(jbakker): Dualcon crashes when run in parallel. Could be related to incorrect
+   * input data or that the library isn't thread safe.
+   * This was identified when changing the task isolation's during T76553. */
+  static ThreadMutex dualcon_mutex = BLI_MUTEX_INITIALIZER;
+  BLI_mutex_lock(&dualcon_mutex);
+  output = dualcon(&input,
+                   dualcon_alloc_output,
+                   dualcon_add_vert,
+                   dualcon_add_quad,
+                   flags,
+                   mode,
+                   threshold,
+                   hermite_num,
+                   scale,
+                   depth);
+  BLI_mutex_unlock(&dualcon_mutex);
+
+  result = output->mesh;
+  MEM_freeN(output);
+
+  return result;
+}
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index f88ff7a12da..d7d662447ac 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5150,7 +5150,7 @@ static void registerGeometryNodes()
   register_node_type_geo_separate_components();
   register_node_type_geo_subdivision_surface();
   register_node_type_geo_switch();
-  register_node_type_geo_remesh();
+  register_node_type_geo_remesh_blocks();
   register_node_type_geo_transform();
   register_node_type_geo_triangulate();
   register_node_type_geo_viewer();
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index 4677a9bc253..f79303138c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list