diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-06-22 18:54:18 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-06-22 18:55:48 +0300 |
commit | 122e0105e29be18931731223522171bd2fc6ecbc (patch) | |
tree | 4da2dec3a4159542f08aed448868811c1f09fa0d /source/blender/blenkernel | |
parent | 8286cc8cd4d0ebeb142a471751f59a6c41cca60b (diff) |
Port DM_debug stuf to BKE_mesh_runtime.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh_runtime.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_runtime.c | 148 |
2 files changed, 155 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h index 34b9440b5c4..455ca088d20 100644 --- a/source/blender/blenkernel/BKE_mesh_runtime.h +++ b/source/blender/blenkernel/BKE_mesh_runtime.h @@ -35,6 +35,7 @@ #include "BKE_customdata.h" /* for CustomDataMask */ +struct CustomData; struct Depsgraph; struct KeyBlock; struct Mesh; @@ -85,5 +86,11 @@ struct Mesh *mesh_get_eval_deform( void BKE_mesh_runtime_eval_to_meshkey(struct Mesh *me_deformed, struct Mesh *me, struct KeyBlock *kb); +#ifndef NDEBUG +char *BKE_mesh_runtime_debug_info(struct Mesh *me_eval); +void BKE_mesh_runtime_debug_print(struct Mesh *me_eval); +void BKE_mesh_runtime_debug_print_cdlayers(struct CustomData *data); +bool BKE_mesh_runtime_is_valid(struct Mesh *me_eval); +#endif /* NDEBUG */ #endif /* __BKE_MESH_RUNTIME_H__ */ diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.c index cd9db408d19..657cd3b6c52 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.c +++ b/source/blender/blenkernel/intern/mesh_runtime.c @@ -226,3 +226,151 @@ void BKE_mesh_batch_cache_free(Mesh *me) } /** \} */ + +/** \name Mesh runtime debug helpers. + * \{ */ +/* evaluated mesh info printing function, + * to help track down differences output */ + +#ifndef NDEBUG +#include "BLI_dynstr.h" + +static void mesh_runtime_debug_info_layers( + DynStr *dynstr, CustomData *cd) +{ + int type; + + for (type = 0; type < CD_NUMTYPES; type++) { + if (CustomData_has_layer(cd, type)) { + /* note: doesnt account for multiple layers */ + const char *name = CustomData_layertype_name(type); + const int size = CustomData_sizeof(type); + const void *pt = CustomData_get_layer(cd, type); + const int pt_size = pt ? (int)(MEM_allocN_len(pt) / size) : 0; + const char *structname; + int structnum; + CustomData_file_write_info(type, &structname, &structnum); + BLI_dynstr_appendf(dynstr, + " dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n", + name, structname, type, (const void *)pt, size, pt_size); + } + } +} + +char *BKE_mesh_runtime_debug_info(Mesh *me_eval) +{ + DynStr *dynstr = BLI_dynstr_new(); + char *ret; + + BLI_dynstr_appendf(dynstr, "{\n"); + BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)me_eval); +#if 0 + const char *tstr; + switch (me_eval->type) { + case DM_TYPE_CDDM: tstr = "DM_TYPE_CDDM"; break; + case DM_TYPE_EDITBMESH: tstr = "DM_TYPE_EDITMESH"; break; + case DM_TYPE_CCGDM: tstr = "DM_TYPE_CCGDM"; break; + default: tstr = "UNKNOWN"; break; + } + BLI_dynstr_appendf(dynstr, " 'type': '%s',\n", tstr); +#endif + BLI_dynstr_appendf(dynstr, " 'totvert': %d,\n", me_eval->totvert); + BLI_dynstr_appendf(dynstr, " 'totedge': %d,\n", me_eval->totedge); + BLI_dynstr_appendf(dynstr, " 'totface': %d,\n", me_eval->totface); + BLI_dynstr_appendf(dynstr, " 'totpoly': %d,\n", me_eval->totpoly); + BLI_dynstr_appendf(dynstr, " 'deformed_only': %d,\n", me_eval->runtime.deformed_only); + + BLI_dynstr_appendf(dynstr, " 'vertexLayers': (\n"); + mesh_runtime_debug_info_layers(dynstr, &me_eval->vdata); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, " 'edgeLayers': (\n"); + mesh_runtime_debug_info_layers(dynstr, &me_eval->edata); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, " 'loopLayers': (\n"); + mesh_runtime_debug_info_layers(dynstr, &me_eval->ldata); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, " 'polyLayers': (\n"); + mesh_runtime_debug_info_layers(dynstr, &me_eval->pdata); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, " 'tessFaceLayers': (\n"); + mesh_runtime_debug_info_layers(dynstr, &me_eval->fdata); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, "}\n"); + + ret = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + return ret; +} + +void BKE_mesh_runtime_debug_print(Mesh *me_eval) +{ + char *str = BKE_mesh_runtime_debug_info(me_eval); + puts(str); + fflush(stdout); + MEM_freeN(str); +} + +/* XXX Should go in customdata file? */ +void BKE_mesh_runtime_debug_print_cdlayers(CustomData *data) +{ + int i; + const CustomDataLayer *layer; + + printf("{\n"); + + for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) { + + const char *name = CustomData_layertype_name(layer->type); + const int size = CustomData_sizeof(layer->type); + const char *structname; + int structnum; + CustomData_file_write_info(layer->type, &structname, &structnum); + printf(" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n", + name, structname, layer->type, (const void *)layer->data, size, (int)(MEM_allocN_len(layer->data) / size)); + } + + printf("}\n"); +} + +bool BKE_mesh_runtime_is_valid(Mesh *me_eval) +{ + const bool do_verbose = true; + const bool do_fixes = false; + + bool is_valid = true; + bool changed = true; + + if (do_verbose) { + printf("MESH: %s\n", me_eval->id.name + 2); + } + + is_valid &= BKE_mesh_validate_all_customdata( + &me_eval->vdata, &me_eval->edata, &me_eval->ldata, &me_eval->pdata, + false, /* setting mask here isn't useful, gives false positives */ + do_verbose, do_fixes, + &changed); + + is_valid &= BKE_mesh_validate_arrays( + me_eval, + me_eval->mvert, me_eval->totvert, + me_eval->medge, me_eval->totedge, + me_eval->mface, me_eval->totface, + me_eval->mloop, me_eval->totloop, + me_eval->mpoly, me_eval->totpoly, + me_eval->dvert, + do_verbose, do_fixes, + &changed); + + BLI_assert(changed == false); + + return is_valid; +} + +#endif /* NDEBUG */ + +/** \} */ |