[Bf-blender-cvs] [97aab4245ef] gsoc-2021-porting-modifiers-to-nodes-solidify: - re-added the one important file that I deleted by accident.

Fabian Schempp noreply at git.blender.org
Tue Jun 22 10:49:56 CEST 2021


Commit: 97aab4245ef17c478b7b1c6afde5187b86a10c65
Author: Fabian Schempp
Date:   Tue Jun 22 10:43:29 2021 +0200
Branches: gsoc-2021-porting-modifiers-to-nodes-solidify
https://developer.blender.org/rB97aab4245ef17c478b7b1c6afde5187b86a10c65

- re-added the one important file that I deleted by accident.

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

A	source/blender/blenkernel/intern/solidify_nonmanifold.c
M	source/blender/nodes/geometry/nodes/node_geo_solidifiy.cc

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

diff --git a/source/blender/blenkernel/intern/solidify_nonmanifold.c b/source/blender/blenkernel/intern/solidify_nonmanifold.c
new file mode 100644
index 00000000000..b381403babd
--- /dev/null
+++ b/source/blender/blenkernel/intern/solidify_nonmanifold.c
@@ -0,0 +1,2520 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup modifiers
+ */
+
+#include "BLI_utildefines.h"
+#include <BKE_customdata.h>
+#include <DNA_modifier_types.h>
+
+#include "BLI_math.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_deform.h"
+#include "BKE_lattice.h"
+#include "BKE_mesh.h"
+#include "BKE_solidifiy.h"
+
+#ifdef __GNUC__
+#  pragma GCC diagnostic error "-Wsign-conversion"
+#endif
+
+/* -------------------------------------------------------------------- */
+/** \name Local Utilities
+ * \{ */
+
+/**
+ * Similar to #project_v3_v3v3_normalized that returns the dot-product.
+ */
+static float project_v3_v3(float r[3], const float a[3])
+{
+  float d = dot_v3v3(r, a);
+  r[0] -= a[0] * d;
+  r[1] -= a[1] * d;
+  r[2] -= a[2] * d;
+  return d;
+}
+
+static float angle_signed_on_axis_normalized_v3v3_v3(const float n[3],
+                                                     const float ref_n[3],
+                                                     const float axis[3])
+{
+  float d = dot_v3v3(n, ref_n);
+  CLAMP(d, -1, 1);
+  float angle = acosf(d);
+  float cross[3];
+  cross_v3_v3v3(cross, n, ref_n);
+  if (dot_v3v3(cross, axis) >= 0) {
+    angle = 2 * M_PI - angle;
+  }
+  return angle;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Main Solidify Function
+ * \{ */
+
+/* Data structures for manifold solidify. */
+
+typedef struct NewFaceRef {
+  MPoly *face;
+  uint index;
+  bool reversed;
+  struct NewEdgeRef **link_edges;
+} NewFaceRef;
+
+typedef struct OldEdgeFaceRef {
+  uint *faces;
+  uint faces_len;
+  bool *faces_reversed;
+  uint used;
+} OldEdgeFaceRef;
+
+typedef struct OldVertEdgeRef {
+  uint *edges;
+  uint edges_len;
+} OldVertEdgeRef;
+
+typedef struct NewEdgeRef {
+  uint old_edge;
+  NewFaceRef *faces[2];
+  struct EdgeGroup *link_edge_groups[2];
+  float angle;
+  uint new_edge;
+} NewEdgeRef;
+
+typedef struct EdgeGroup {
+  bool valid;
+  NewEdgeRef **edges;
+  uint edges_len;
+  uint open_face_edge;
+  bool is_orig_closed;
+  bool is_even_split;
+  uint split;
+  bool is_singularity;
+  uint topo_group;
+  float co[3];
+  float no[3];
+  uint new_vert;
+} EdgeGroup;
+
+typedef struct FaceKeyPair {
+  float angle;
+  NewFaceRef *face;
+} FaceKeyPair;
+
+static int comp_float_int_pair(const void *a, const void *b)
+{
+  FaceKeyPair *x = (FaceKeyPair *)a;
+  FaceKeyPair *y = (FaceKeyPair *)b;
+  return (int)(x->angle > y->angle) - (int)(x->angle < y->angle);
+}
+
+/* NOLINTNEXTLINE: readability-function-size */
+Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
+                           Mesh *mesh,
+                           bool **r_shell_verts,
+                           bool **r_rim_verts,
+                           bool **r_shell_faces,
+                           bool **r_rim_faces)
+{
+  Mesh *result;
+
+  MVert *mv, *mvert, *orig_mvert;
+  MEdge *ed, *medge, *orig_medge;
+  MLoop *ml, *mloop, *orig_mloop;
+  MPoly *mp, *mpoly, *orig_mpoly;
+  const uint numVerts = (uint)mesh->totvert;
+  const uint numEdges = (uint)mesh->totedge;
+  const uint numPolys = (uint)mesh->totpoly;
+  const uint numLoops = (uint)mesh->totloop;
+
+  if (numPolys == 0 && numVerts != 0) {
+    return mesh;
+  }
+
+  float(*poly_nors)[3] = NULL;
+
+  const float ofs_front = (solidify_data->offset_fac + 1.0f) * 0.5f * solidify_data->offset;
+  const float ofs_back = ofs_front - solidify_data->offset * solidify_data->offset_fac;
+  const float ofs_front_clamped = max_ff(1e-5f,
+                                         fabsf(solidify_data->offset > 0 ? ofs_front : ofs_back));
+  const float ofs_back_clamped = max_ff(1e-5f,
+                                        fabsf(solidify_data->offset > 0 ? ofs_back : ofs_front));
+  const float offset_fac_vg = solidify_data->offset_fac_vg;
+  const float offset_fac_vg_inv = 1.0f - solidify_data->offset_fac_vg;
+  const float offset = fabsf(solidify_data->offset) * solidify_data->offset_clamp;
+  const bool do_angle_clamp = solidify_data->flag & MOD_SOLIDIFY_OFFSET_ANGLE_CLAMP;
+  const bool do_flip = (solidify_data->flag & MOD_SOLIDIFY_FLIP) != 0;
+  const bool do_rim = solidify_data->flag & MOD_SOLIDIFY_RIM;
+  const bool do_shell = solidify_data->flag & MOD_SOLIDIFY_SHELL;
+  const bool do_clamp = (solidify_data->offset_clamp != 0.0f);
+
+  const float bevel_convex = solidify_data->bevel_convex;
+
+  const bool do_flat_faces = solidify_data->flag & MOD_SOLIDIFY_NONMANIFOLD_FLAT_FACES;
+
+  orig_mvert = mesh->mvert;
+  orig_medge = mesh->medge;
+  orig_mloop = mesh->mloop;
+  orig_mpoly = mesh->mpoly;
+
+  uint numNewVerts = 0;
+  uint numNewEdges = 0;
+  uint numNewLoops = 0;
+  uint numNewPolys = 0;
+
+#define MOD_SOLIDIFY_EMPTY_TAG ((uint)-1)
+
+  /* Calculate only face normals. */
+  poly_nors = MEM_malloc_arrayN(numPolys, sizeof(*poly_nors), __func__);
+  BKE_mesh_calc_normals_poly(orig_mvert,
+                             NULL,
+                             (int)numVerts,
+                             orig_mloop,
+                             orig_mpoly,
+                             (int)numLoops,
+                             (int)numPolys,
+                             poly_nors,
+                             true);
+
+  NewFaceRef *face_sides_arr = MEM_malloc_arrayN(
+      numPolys * 2, sizeof(*face_sides_arr), "face_sides_arr in solidify");
+  bool *null_faces = (solidify_data->nonmanifold_offset_mode ==
+                      MOD_SOLIDIFY_NONMANIFOLD_OFFSET_MODE_CONSTRAINTS) ?
+                         MEM_calloc_arrayN(
+                             numPolys, sizeof(*null_faces), "null_faces in solidify") :
+                         NULL;
+  uint largest_ngon = 3;
+  /* Calculate face to #NewFaceRef map. */
+  {
+    mp = orig_mpoly;
+    for (uint i = 0; i < numPolys; i++, mp++) {
+      /* Make normals for faces without area (should really be avoided though). */
+      if (len_squared_v3(poly_nors[i]) < 0.5f) {
+        MEdge *e = orig_medge + orig_mloop[mp->loopstart].e;
+        float edgedir[3];
+        sub_v3_v3v3(edgedir, orig_mvert[e->v2].co, orig_mvert[e->v1].co);
+        if (fabsf(edgedir[2]) < fabsf(edgedir[1])) {
+          poly_nors[i][2] = 1.0f;
+        }
+        else {
+          poly_nors[i][1] = 1.0f;
+        }
+        if (null_faces) {
+          null_faces[i] = true;
+        }
+      }
+
+      NewEdgeRef **link_edges = MEM_calloc_arrayN(
+          (uint)mp->totloop, sizeof(*link_edges), "NewFaceRef::link_edges in solidify");
+      face_sides_arr[i * 2] = (NewFaceRef){
+          .face = mp, .index = i, .reversed = false, .link_edges = link_edges};
+      link_edges = MEM_calloc_arrayN(
+          (uint)mp->totloop, sizeof(*link_edges), "NewFaceRef::link_edges in solidify");
+      face_sides_arr[i * 2 + 1] = (NewFaceRef){
+          .face = mp, .index = i, .reversed = true, .link_edges = link_edges};
+      if (mp->totloop > largest_ngon) {
+        largest_ngon = (uint)mp->totloop;
+      }
+      /* add to final mesh face count */
+      if (do_shell) {
+        numNewPolys += 2;
+        numNewLoops += (uint)mp->totloop * 2;
+      }
+    }
+  }
+
+  uint *edge_adj_faces_len = MEM_calloc_arrayN(
+      numEdges, sizeof(*edge_adj_faces_len), "edge_adj_faces_len in solidify");
+  /* Count for each edge how many faces it has adjacent. */
+  {
+    mp = orig_mpoly;
+    for (uint i = 0; i < numPolys; i++, mp++) {
+      ml = orig_mloop + mp->loopstart;
+      for (uint j = 0; j < mp->totloop; j++, ml++) {
+        edge_adj_faces_len[ml->e]++;
+      }
+    }
+  }
+
+  /* Original edge to #NewEdgeRef map. */
+  NewEdgeRef ***orig_edge_data_arr = MEM_calloc_arrayN(
+      numEdges, sizeof(*orig_edge_data_arr), "orig_edge_data_arr in solidify");
+  /* Original edge length cache. */
+  float *orig_edge_lengths = MEM_calloc_arrayN(
+      numEdges, sizeof(*orig_edge_lengths), "orig_edge_lengths in solidify");
+  /* Edge groups for every original vert. */
+  EdgeGroup **orig_vert_groups_arr = MEM_calloc_arrayN(
+      numVerts, sizeof(*orig_vert_groups_arr), "orig_vert_groups_arr in solidify");
+  /* vertex map used to map duplicates. */
+  uint *vm = MEM_malloc_arrayN(numVerts, sizeof(*vm), "orig_vert_map in solidify");
+  for (uint i = 0; i < numVerts; i++) {
+    vm[i] = i;
+  }
+
+  uint edge_index = 0;
+  uint loop_index = 0;
+  uint poly_index = 0;
+
+  bool has_singularities = false;
+
+  /* Vert edge adjacent map. */
+  OldVertEdgeRef **vert_adj_edges = MEM_calloc_arrayN(
+      numVerts, sizeof(*vert_adj_edges), "vert_adj_edges in solidify");
+  /* Original vertex positions (changed for degenerated geometry). */
+  float(*orig_mvert_co)[3] = MEM_malloc_arrayN(
+      numVerts, sizeof(*orig_mvert_co), "orig_mvert_co in solidify");
+  /* Fill in the original vertex positions. */
+  for (uint i = 0; i < numVerts; i++) {
+    orig_mvert_co[i][0] = orig_mvert[i].co[0];
+    orig_mvert_co[i][1] = orig_mvert[i].co[1];
+    orig_mvert_co[i][2] = orig_mvert[i].co[2];
+  }
+
+  /* Create edge to #NewEdgeRef map. */
+  {
+    OldEdgeFaceRef **edge_adj_faces = MEM_calloc_arrayN(
+        numEdges, sizeof(*edge_adj_faces), "edge_adj_faces in solidify");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list