[Bf-blender-cvs] [5075082b590] temp-trimesh-sculpt: add these files

Joseph Eagar noreply at git.blender.org
Wed Oct 14 04:05:44 CEST 2020


Commit: 5075082b5909ff0528bb06d1e6a7300a8e7e54d1
Author: Joseph Eagar
Date:   Wed Sep 30 04:36:45 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rB5075082b5909ff0528bb06d1e6a7300a8e7e54d1

add these files

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

A	source/blender/trimesh/CMakeLists.txt
A	source/blender/trimesh/intern/trimesh_conv.c
A	source/blender/trimesh/intern/trimesh_log.c
A	source/blender/trimesh/intern/trimesh_private.h
A	source/blender/trimesh/intern/trimesh_thread.c

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

diff --git a/source/blender/trimesh/CMakeLists.txt b/source/blender/trimesh/CMakeLists.txt
new file mode 100644
index 00000000000..6588bbad260
--- /dev/null
+++ b/source/blender/trimesh/CMakeLists.txt
@@ -0,0 +1,74 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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) 2006, Blender Foundation
+# All rights reserved.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+  .
+  ./intern
+  ../blenkernel
+  ../blenlib
+  ../bmesh
+  ../blentranslation
+  ../makesdna
+  ../../../intern/atomic
+  ../../../intern/eigen
+  ../../../intern/guardedalloc
+  ../../../extern/rangetree
+)
+
+set(INC_SYS
+
+)
+
+set(SRC
+  intern/trimesh.c
+  intern/trimesh_log.c
+  intern/trimesh_thread.c
+  intern/trimesh_conv.c
+  intern/trimesh_private.h
+  trimesh.h
+)
+
+set(LIB
+  bf_blenkernel
+  bf_blenlib
+  extern_rangetree
+)
+
+if(WITH_BULLET)
+  list(APPEND INC_SYS
+    ${BULLET_INCLUDE_DIRS}
+  )
+  list(APPEND LIB
+    extern_bullet
+
+    ${BULLET_LIBRARIES}
+  )
+  add_definitions(-DWITH_BULLET)
+endif()
+
+if(WITH_INTERNATIONAL)
+  add_definitions(-DWITH_INTERNATIONAL)
+endif()
+
+if(WITH_FREESTYLE)
+  add_definitions(-DWITH_FREESTYLE)
+endif()
+
+blender_add_lib(bf_trimesh "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/trimesh/intern/trimesh_conv.c b/source/blender/trimesh/intern/trimesh_conv.c
new file mode 100644
index 00000000000..0e628157739
--- /dev/null
+++ b/source/blender/trimesh/intern/trimesh_conv.c
@@ -0,0 +1,460 @@
+/*
+* 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) 2008 by Blender Foundation.
+* All rights reserved.
+*/
+
+/** \file
+* \ingroup trimesh
+*
+* optimized thread-safe triangle mesh library with topological info
+*
+*/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "BLI_listbase.h"
+
+#include "BLI_math.h"
+#include "BLI_threadsafe_mempool.h"
+#include "BLI_array.h"
+#include "BLI_alloca.h"
+
+#include "DNA_key_types.h"
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+
+#include "atomic_ops.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
+#include "BKE_customdata.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
+#include "BKE_multires.h"
+
+#include "BKE_key.h"
+#include "BKE_main.h"
+
+#include "MEM_guardedalloc.h"
+#ifdef WITH_MEM_VALGRIND
+#  include "valgrind/memcheck.h"
+#endif
+
+#include "trimesh_private.h"
+#include "trimesh.h"
+#include "bmesh.h"
+
+/* ME -> BM */
+char TM_vert_flag_from_mflag(const char meflag)
+{
+  return (((meflag & SELECT) ? SELECT : 0) | ((meflag & ME_HIDE) ? TRIMESH_HIDE : 0));
+}
+char TM_edge_flag_from_mflag(const short meflag)
+{
+  return (((meflag & SELECT) ? SELECT : 0) | ((meflag & ME_SEAM) ? TRIMESH_SEAM : 0) |
+    ((meflag & ME_EDGEDRAW) ? TRIMESH_EDGEDRAW : 0) |
+    ((meflag & ME_SHARP) == 0 ? TRIMESH_SHARP : 0) | /* invert */
+    ((meflag & ME_HIDE) ? TRIMESH_HIDE : 0));
+}
+char TM_face_flag_from_mflag(const char meflag)
+{
+  return (((meflag & ME_FACE_SEL) ? SELECT : 0) |
+    ((meflag & ME_SMOOTH) ? TRIMESH_SMOOTH : 0) | ((meflag & ME_HIDE) ? TRIMESH_HIDE : 0));
+}
+
+static void update_data_blocks(TM_TriMesh *tm, CustomData *olddata, CustomData *data)
+{
+  TM_TriMeshIter iter;
+  BLI_ThreadSafePool *oldpool = olddata->tpool;
+  void *block;
+
+  if (data == &tm->vdata) {
+    TMVert *eve;
+
+    CustomData_trimesh_init_pool(tm, data, tm->totvert, TM_VERTEX);
+
+    TM_ITER_MESH (eve, &iter, tm, TM_VERTS_OF_MESH) {
+      block = NULL;
+      CustomData_bmesh_set_default(data, &block);
+      CustomData_bmesh_copy_data(olddata, data, eve->customdata, &block);
+      CustomData_bmesh_free_block(olddata, &eve->customdata);
+      eve->customdata = block;
+    }
+  }
+  else if (data == &tm->edata) {
+    TMEdge *eed;
+
+    CustomData_trimesh_init_pool(tm, data, tm->totedge, TM_EDGE);
+
+    TM_ITER_MESH (eed, &iter, tm, TM_EDGES_OF_MESH) {
+      block = NULL;
+      CustomData_bmesh_set_default(data, &block);
+      CustomData_bmesh_copy_data(olddata, data, eed->customdata, &block);
+      CustomData_bmesh_free_block(olddata, &eed->customdata);
+      eed->customdata = block;
+    }
+  }
+  else if (data == &tm->ldata) {
+    TMFace *efa;
+
+    CustomData_trimesh_init_pool(tm, data, tm->tottri*3, TM_LOOP);
+    TM_ITER_MESH (efa, &iter, tm, TM_TRIS_OF_MESH) {
+      for (int i=0; i<3; i++) {
+        TMLoopData *l = TM_GET_TRI_LOOP(efa, i);
+        block = NULL;
+        CustomData_bmesh_set_default(data, &block);
+        CustomData_bmesh_copy_data(olddata, data, l->customdata, &block);
+        CustomData_bmesh_free_block(olddata, &l->customdata);
+        l->customdata = block;
+      }
+    }
+  }
+  else if (data == &tm->tdata) {
+    TMFace *efa;
+
+    CustomData_trimesh_init_pool(tm, data, tm->tottri, TM_TRI);
+
+    TM_ITER_MESH (efa, &iter, tm, TM_TRIS_OF_MESH) {
+      block = NULL;
+      CustomData_bmesh_set_default(data, &block);
+      CustomData_bmesh_copy_data(olddata, data, efa->customdata, &block);
+      CustomData_bmesh_free_block(olddata, &efa->customdata);
+      efa->customdata = block;
+    }
+  }
+  else {
+    /* should never reach this! */
+    BLI_assert(0);
+  }
+
+  if (oldpool) {
+    /* this should never happen but can when dissolve fails - [#28960] */
+    BLI_assert(data->tpool != oldpool);
+
+    BLI_safepool_destroy(oldpool);
+  }
+}
+
+void TM_data_layer_add(TM_TriMesh *tm, CustomData *data, int type)
+{
+  CustomData olddata;
+
+  olddata = *data;
+  olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
+
+  /* the pool is now owned by olddata and must not be shared */
+  data->tpool = NULL;
+
+  CustomData_add_layer(data, type, CD_DEFAULT, NULL, 0);
+
+  update_data_blocks(tm, &olddata, data);
+  if (olddata.layers) {
+    MEM_freeN(olddata.layers);
+  }
+}
+
+
+void TM_data_layer_free(TM_TriMesh *tm, CustomData *data, int type)
+{
+  CustomData olddata;
+  bool has_layer;
+
+  olddata = *data;
+  olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL;
+
+  /* the pool is now owned by olddata and must not be shared */
+  data->tpool = NULL;
+
+  has_layer = CustomData_free_layer_active(data, type, 0);
+  /* assert because its expensive to realloc - better not do if layer isnt present */
+  BLI_assert(has_layer != false);
+  UNUSED_VARS_NDEBUG(has_layer);
+
+  update_data_blocks(tm, &olddata, data);
+  if (olddata.layers) {
+    MEM_freeN(olddata.layers);
+  }
+}
+
+void TM_mesh_cd_flag_apply(TM_TriMesh *bm, const char cd_flag)
+{
+  /* CustomData_bmesh_init_pool() must run first */
+  BLI_assert(bm->vdata.totlayer == 0 || bm->vdata.tpool != NULL);
+  BLI_assert(bm->edata.totlayer == 0 || bm->edata.tpool != NULL);
+  BLI_assert(bm->tdata.totlayer == 0 || bm->tdata.tpool != NULL);
+
+  if (cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
+    if (!CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) {
+      TM_data_layer_add(bm, &bm->vdata, CD_BWEIGHT);
+    }
+  }
+  else {
+    if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) {
+      TM_data_layer_free(bm, &bm->vdata, CD_BWEIGHT);
+    }
+  }
+
+  if (cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
+    if (!CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
+      TM_data_layer_add(bm, &bm->edata, CD_BWEIGHT);
+    }
+  }
+  else {
+    if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
+      TM_data_layer_free(bm, &bm->edata, CD_BWEIGHT);
+    }
+  }
+
+  if (cd_flag & ME_CDFLAG_EDGE_CREASE) {
+    if (!CustomData_has_layer(&bm->edata, CD_CREASE)) {
+      TM_data_layer_add(bm, &bm->edata, CD_CREASE);
+    }
+  }
+  else {
+    if (CustomData_has_layer(&bm->edata, CD_CREASE)) {
+      TM_data_layer_free(bm, &bm->edata, CD_CREASE);
+    }
+  }
+}
+
+void TM_mesh_tm_from_me(TM_TriMesh *bm, const Mesh *me, const struct TriMeshFromMeshParams *params) {
+  const bool is_new = !(bm->totvert || (bm->vdata.totlayer || bm->edata.totlayer ||
+    bm->tdata.totlayer || bm->ldata.totlayer));
+  MVert *mvert;
+  MEdge *medge;
+  MLoop *mloop;
+  MPoly *mp;
+  KeyBlock *actkey, *block;
+  TMVert *v, **vtable = NULL;
+  TMEdge *e, **etable = NULL;
+  TMFace *f, **ftable = NULL;
+  float(*keyco)[3] = NULL;
+  int totloops, i;
+  CustomData_MeshMasks mask = CD_MASK_BMESH;
+  CustomData_MeshMasks_update(&mask, &params->cd_mask_extra);
+
+  if (!me || !me->totvert) {
+    if (me && is_new) { /* No verts? still copy custom-data layout. */
+      CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_ASSIGN, 0);
+      CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_ASSIGN, 0);
+      CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_ASSIGN, 0);
+      CustomData_copy(&me->pdata, &bm->tdata, mask.pmask, CD_ASSIGN, 0);
+
+      CustomData_trimesh_init_pool(bm, &bm->vdata, 0, TM_VERTEX);
+      Custom

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list