diff options
author | Campbell Barton <campbell@blender.org> | 2022-01-19 07:09:48 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-01-19 09:16:00 +0300 |
commit | eb63646605ddce336da7a8779ab86336133786b1 (patch) | |
tree | 0de363cc98ee3d738eeb735c7b58a95a759d3e01 /source/blender/bmesh | |
parent | 71879d665d69bd1e96dab0dc089785a43d1d42fd (diff) |
BMesh: add mesh debug information printing
- Add BM_mesh_debug_print & BM_mesh_debug_info.
- Report flags in Mesh.cd_flag in BKE_mesh_debug_print
- Move custom data printing into customdata.cc (noted as a TODO).
Note that the term "runtime" has been removed from
`BKE_mesh_runtime_debug_print` since these are useful for debugging any
kind of mesh data.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/bmesh/bmesh.h | 1 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_debug.c | 86 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_debug.h | 30 |
4 files changed, 119 insertions, 0 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index 7bf80939980..f57d4da4d26 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -100,6 +100,8 @@ set(SRC intern/bmesh_mesh.h intern/bmesh_mesh_convert.c intern/bmesh_mesh_convert.h + intern/bmesh_mesh_debug.c + intern/bmesh_mesh_debug.h intern/bmesh_mesh_duplicate.c intern/bmesh_mesh_duplicate.h intern/bmesh_mesh_normals.c diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 40db423ba2f..fc97c55091a 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -214,6 +214,7 @@ extern "C" { #include "intern/bmesh_marking.h" #include "intern/bmesh_mesh.h" #include "intern/bmesh_mesh_convert.h" +#include "intern/bmesh_mesh_debug.h" #include "intern/bmesh_mesh_duplicate.h" #include "intern/bmesh_mesh_normals.h" #include "intern/bmesh_mesh_partial_update.h" diff --git a/source/blender/bmesh/intern/bmesh_mesh_debug.c b/source/blender/bmesh/intern/bmesh_mesh_debug.c new file mode 100644 index 00000000000..81a11df13f2 --- /dev/null +++ b/source/blender/bmesh/intern/bmesh_mesh_debug.c @@ -0,0 +1,86 @@ +/* + * 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 bke + * + * Evaluated mesh info printing function, to help track down differences output. + * + * Output from these functions can be evaluated as Python literals. + * See `mesh_debug.cc` for the equivalent #Mesh functionality. + */ + +#ifndef NDEBUG + +# include <stdio.h> + +# include "MEM_guardedalloc.h" + +# include "BLI_utildefines.h" + +# include "BKE_customdata.h" + +# include "bmesh.h" + +# include "bmesh_mesh_debug.h" + +# include "BLI_dynstr.h" + +char *BM_mesh_debug_info(BMesh *bm) +{ + DynStr *dynstr = BLI_dynstr_new(); + char *ret; + + const char *indent8 = " "; + + BLI_dynstr_append(dynstr, "{\n"); + BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)bm); + BLI_dynstr_appendf(dynstr, " 'totvert': %d,\n", bm->totvert); + BLI_dynstr_appendf(dynstr, " 'totedge': %d,\n", bm->totedge); + BLI_dynstr_appendf(dynstr, " 'totface': %d,\n", bm->totface); + + BLI_dynstr_append(dynstr, " 'vert_layers': (\n"); + CustomData_debug_info_from_layers(&bm->vdata, indent8, dynstr); + BLI_dynstr_append(dynstr, " ),\n"); + + BLI_dynstr_append(dynstr, " 'edge_layers': (\n"); + CustomData_debug_info_from_layers(&bm->edata, indent8, dynstr); + BLI_dynstr_append(dynstr, " ),\n"); + + BLI_dynstr_append(dynstr, " 'loop_layers': (\n"); + CustomData_debug_info_from_layers(&bm->ldata, indent8, dynstr); + BLI_dynstr_append(dynstr, " ),\n"); + + BLI_dynstr_append(dynstr, " 'poly_layers': (\n"); + CustomData_debug_info_from_layers(&bm->pdata, indent8, dynstr); + BLI_dynstr_append(dynstr, " ),\n"); + + BLI_dynstr_append(dynstr, "}\n"); + + ret = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + return ret; +} + +void BM_mesh_debug_print(BMesh *bm) +{ + char *str = BM_mesh_debug_info(bm); + puts(str); + fflush(stdout); + MEM_freeN(str); +} + +#endif /* NDEBUG */ diff --git a/source/blender/bmesh/intern/bmesh_mesh_debug.h b/source/blender/bmesh/intern/bmesh_mesh_debug.h new file mode 100644 index 00000000000..e903b627419 --- /dev/null +++ b/source/blender/bmesh/intern/bmesh_mesh_debug.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#pragma once + +/** \file + * \ingroup bmesh + */ + +#include "BLI_compiler_attrs.h" + +#include "bmesh.h" + +#ifndef NDEBUG +char *BM_mesh_debug_info(BMesh *bm) ATTR_NONNULL(1) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; +void BM_mesh_debug_print(BMesh *bm) ATTR_NONNULL(1); +#endif /* NDEBUG */ |