Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mesh_debug.cc « intern « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 017f96c2eceefd23c4c1f3dc9daf7885daaa61c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * 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 `bmesh_debug.c` for the equivalent #BMesh functionality.
 */

#ifndef NDEBUG

#  include <stdio.h>

#  include "MEM_guardedalloc.h"

#  include "DNA_mesh_types.h"
#  include "DNA_meshdata_types.h"
#  include "DNA_object_types.h"

#  include "BLI_utildefines.h"

#  include "BKE_customdata.h"

#  include "BKE_mesh.h"

#  include "BLI_dynstr.h"

static void mesh_debug_info_from_cd_flag(const Mesh *me, DynStr *dynstr)
{
  BLI_dynstr_append(dynstr, "'cd_flag': {");
  if (me->cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
    BLI_dynstr_append(dynstr, "'VERT_BWEIGHT', ");
  }
  if (me->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
    BLI_dynstr_append(dynstr, "'EDGE_BWEIGHT', ");
  }
  if (me->cd_flag & ME_CDFLAG_EDGE_CREASE) {
    BLI_dynstr_append(dynstr, "'EDGE_CREASE', ");
  }
  BLI_dynstr_append(dynstr, "},\n");
}

char *BKE_mesh_debug_info(const Mesh *me)
{
  DynStr *dynstr = BLI_dynstr_new();
  char *ret;

  const char *indent4 = "    ";
  const char *indent8 = "        ";

  BLI_dynstr_append(dynstr, "{\n");
  BLI_dynstr_appendf(dynstr, "    'ptr': '%p',\n", (void *)me);
  BLI_dynstr_appendf(dynstr, "    'totvert': %d,\n", me->totvert);
  BLI_dynstr_appendf(dynstr, "    'totedge': %d,\n", me->totedge);
  BLI_dynstr_appendf(dynstr, "    'totface': %d,\n", me->totface);
  BLI_dynstr_appendf(dynstr, "    'totpoly': %d,\n", me->totpoly);

  BLI_dynstr_appendf(dynstr, "    'runtime.deformed_only': %d,\n", me->runtime.deformed_only);
  BLI_dynstr_appendf(dynstr, "    'runtime.is_original': %d,\n", me->runtime.is_original);

  BLI_dynstr_append(dynstr, "    'vert_layers': (\n");
  CustomData_debug_info_from_layers(&me->vdata, indent8, dynstr);
  BLI_dynstr_append(dynstr, "    ),\n");

  BLI_dynstr_append(dynstr, "    'edge_layers': (\n");
  CustomData_debug_info_from_layers(&me->edata, indent8, dynstr);
  BLI_dynstr_append(dynstr, "    ),\n");

  BLI_dynstr_append(dynstr, "    'loop_layers': (\n");
  CustomData_debug_info_from_layers(&me->ldata, indent8, dynstr);
  BLI_dynstr_append(dynstr, "    ),\n");

  BLI_dynstr_append(dynstr, "    'poly_layers': (\n");
  CustomData_debug_info_from_layers(&me->pdata, indent8, dynstr);
  BLI_dynstr_append(dynstr, "    ),\n");

  BLI_dynstr_append(dynstr, "    'tessface_layers': (\n");
  CustomData_debug_info_from_layers(&me->fdata, indent8, dynstr);
  BLI_dynstr_append(dynstr, "    ),\n");

  BLI_dynstr_append(dynstr, indent4);
  mesh_debug_info_from_cd_flag(me, dynstr);

  BLI_dynstr_append(dynstr, "}\n");

  ret = BLI_dynstr_get_cstring(dynstr);
  BLI_dynstr_free(dynstr);
  return ret;
}

void BKE_mesh_debug_print(const Mesh *me)
{
  char *str = BKE_mesh_debug_info(me);
  puts(str);
  fflush(stdout);
  MEM_freeN(str);
}

#endif /* NDEBUG */