Blender  V3.3
mesh_debug.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
12 #ifndef NDEBUG
13 
14 # include <cstdio>
15 
16 # include "MEM_guardedalloc.h"
17 
18 # include "DNA_mesh_types.h"
19 # include "DNA_meshdata_types.h"
20 # include "DNA_object_types.h"
21 
22 # include "BLI_utildefines.h"
23 
24 # include "BKE_customdata.h"
25 
26 # include "BKE_mesh.h"
27 
28 # include "BLI_dynstr.h"
29 
30 static void mesh_debug_info_from_cd_flag(const Mesh *me, DynStr *dynstr)
31 {
32  BLI_dynstr_append(dynstr, "'cd_flag': {");
33  if (me->cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
34  BLI_dynstr_append(dynstr, "'VERT_BWEIGHT', ");
35  }
36  if (me->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
37  BLI_dynstr_append(dynstr, "'EDGE_BWEIGHT', ");
38  }
39  if (me->cd_flag & ME_CDFLAG_EDGE_CREASE) {
40  BLI_dynstr_append(dynstr, "'EDGE_CREASE', ");
41  }
42  BLI_dynstr_append(dynstr, "},\n");
43 }
44 
45 char *BKE_mesh_debug_info(const Mesh *me)
46 {
47  DynStr *dynstr = BLI_dynstr_new();
48  char *ret;
49 
50  const char *indent4 = " ";
51  const char *indent8 = " ";
52 
53  BLI_dynstr_append(dynstr, "{\n");
54  BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)me);
55  BLI_dynstr_appendf(dynstr, " 'totvert': %d,\n", me->totvert);
56  BLI_dynstr_appendf(dynstr, " 'totedge': %d,\n", me->totedge);
57  BLI_dynstr_appendf(dynstr, " 'totface': %d,\n", me->totface);
58  BLI_dynstr_appendf(dynstr, " 'totpoly': %d,\n", me->totpoly);
59 
60  BLI_dynstr_appendf(dynstr, " 'runtime.deformed_only': %d,\n", me->runtime.deformed_only);
61  BLI_dynstr_appendf(dynstr, " 'runtime.is_original': %d,\n", me->runtime.is_original);
62 
63  BLI_dynstr_append(dynstr, " 'vert_layers': (\n");
64  CustomData_debug_info_from_layers(&me->vdata, indent8, dynstr);
65  BLI_dynstr_append(dynstr, " ),\n");
66 
67  BLI_dynstr_append(dynstr, " 'edge_layers': (\n");
68  CustomData_debug_info_from_layers(&me->edata, indent8, dynstr);
69  BLI_dynstr_append(dynstr, " ),\n");
70 
71  BLI_dynstr_append(dynstr, " 'loop_layers': (\n");
72  CustomData_debug_info_from_layers(&me->ldata, indent8, dynstr);
73  BLI_dynstr_append(dynstr, " ),\n");
74 
75  BLI_dynstr_append(dynstr, " 'poly_layers': (\n");
76  CustomData_debug_info_from_layers(&me->pdata, indent8, dynstr);
77  BLI_dynstr_append(dynstr, " ),\n");
78 
79  BLI_dynstr_append(dynstr, " 'tessface_layers': (\n");
80  CustomData_debug_info_from_layers(&me->fdata, indent8, dynstr);
81  BLI_dynstr_append(dynstr, " ),\n");
82 
83  BLI_dynstr_append(dynstr, indent4);
84  mesh_debug_info_from_cd_flag(me, dynstr);
85 
86  BLI_dynstr_append(dynstr, "}\n");
87 
88  ret = BLI_dynstr_get_cstring(dynstr);
89  BLI_dynstr_free(dynstr);
90  return ret;
91 }
92 
93 void BKE_mesh_debug_print(const Mesh *me)
94 {
95  char *str = BKE_mesh_debug_info(me);
96  puts(str);
97  fflush(stdout);
98  MEM_freeN(str);
99 }
100 
101 #endif /* NDEBUG */
CustomData interface, see also DNA_customdata_types.h.
void CustomData_debug_info_from_layers(const struct CustomData *data, const char *indent, struct DynStr *dynstr)
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:50
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:256
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:281
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:75
@ ME_CDFLAG_EDGE_CREASE
@ ME_CDFLAG_VERT_BWEIGHT
@ ME_CDFLAG_EDGE_BWEIGHT
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define str(s)
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void BKE_mesh_debug_print(const Mesh *me)
Definition: mesh_debug.cc:93
char * BKE_mesh_debug_info(const Mesh *me)
Definition: mesh_debug.cc:45
static void mesh_debug_info_from_cd_flag(const Mesh *me, DynStr *dynstr)
Definition: mesh_debug.cc:30
return ret
CustomData vdata
int totedge
char cd_flag
int totvert
int totface
Mesh_Runtime runtime
CustomData pdata
CustomData fdata
int totpoly
CustomData edata
CustomData ldata