diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-19 04:18:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-19 04:18:25 +0400 |
commit | b748d4f0cf34e956bed1f411c45bb259f166883d (patch) | |
tree | aff5407e6a525333a59e5cb294bd5792e7cf71fd /source/blender | |
parent | c69abe0965b8a2680070f8a5489161611acb243e (diff) |
debug function DM_debug_info / DM_debug_print, with access from python
through Object.dm_info('SOURCE/DEFORM/FINAL')
this is to help tracking down issues with modifiers where loosing data
layers between modifiers can cause bugs, also to helo with comparing
bmesh/trunk's modifier stack.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 75 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object_api.c | 62 |
3 files changed, 142 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 5f451ce7821..0c47c833cb3 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -584,5 +584,10 @@ void DM_calc_auto_bump_scale(DerivedMesh *dm); /* Set object's bounding box based on DerivedMesh min/max data */ void DM_set_object_boundbox(struct Object *ob, DerivedMesh *dm); +/* debug only */ +#ifndef NDEBUG +char *DM_debug_info(DerivedMesh *dm); +void DM_debug_print(DerivedMesh *dm); #endif +#endif diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 0ff46045f78..344fc485d1a 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -2313,3 +2313,78 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm) #endif /* WITH_GAMEENGINE */ /* --- NAVMESH (end) --- */ + + +/* derivedmesh info printing function, + * to help track down differences DM output */ + +#ifndef NDEBUG +#include "BLI_dynstr.h" + +static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, void *(*getElemDataArray)(DerivedMesh *, int)) +{ + int type; + + for (type = 0; type < CD_NUMTYPES; type++) { + /* note: doesnt account for multiple layers */ + void *pt = getElemDataArray(dm, type); + if (pt) { + const char *name = CustomData_layertype_name(type); + const int size = CustomData_sizeof(type); + 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, (void *)pt, size, (int)(MEM_allocN_len(pt) / size)); + } + } +} + +char *DM_debug_info(DerivedMesh *dm) +{ + DynStr *dynstr= BLI_dynstr_new(); + char *ret; + const char *tstr; + + BLI_dynstr_appendf(dynstr, "{\n"); + BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)dm); + switch (dm->type) { + case DM_TYPE_CDDM: tstr = "DM_TYPE_CDDM"; break; + case DM_TYPE_EDITMESH: 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); + BLI_dynstr_appendf(dynstr, " 'numVertData': %d,\n", dm->numVertData); + BLI_dynstr_appendf(dynstr, " 'numEdgeData': %d,\n", dm->numEdgeData); + BLI_dynstr_appendf(dynstr, " 'numFaceData': %d,\n", dm->numFaceData); + BLI_dynstr_appendf(dynstr, " 'deformedOnly': %d,\n", dm->deformedOnly); + + BLI_dynstr_appendf(dynstr, " 'vertexLayers': (\n"); + dm_debug_info_layers(dynstr, dm, dm->getVertDataArray); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, " 'edgeLayers': (\n"); + dm_debug_info_layers(dynstr, dm, dm->getEdgeDataArray); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, " 'faceLayers': (\n"); + dm_debug_info_layers(dynstr, dm, dm->getFaceDataArray); + BLI_dynstr_appendf(dynstr, " ),\n"); + + BLI_dynstr_appendf(dynstr, "}\n"); + + ret = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + return ret; +} + +void DM_debug_print(DerivedMesh *dm) +{ + char *str = DM_debug_info(dm); + printf(str); + fflush(stdout); +} + +#endif /* NDEBUG */ diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 877da130357..53203717c85 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -63,6 +63,7 @@ #include "BKE_font.h" #include "BKE_mball.h" #include "BKE_modifier.h" +#include "BKE_cdderivedmesh.h" #include "DNA_mesh_types.h" #include "DNA_scene_types.h" @@ -470,6 +471,44 @@ int rna_Object_is_modified(Object *ob, Scene *scene, int settings) return object_is_modified(scene, ob) & settings; } +#ifndef NDEBUG +void rna_Object_dm_info(struct Object *ob, int type, char *result) +{ + DerivedMesh *dm = NULL; + int dm_release = FALSE; + char *ret = NULL; + + result[0] = '\0'; + + switch(type) { + case 0: + if (ob->type == OB_MESH) { + dm = CDDM_from_mesh(ob->data, ob); + ret = DM_debug_info(dm); + dm_release = TRUE; + } + break; + case 1: + dm = ob->derivedDeform; + break; + case 2: + dm = ob->derivedFinal; + break; + } + + if (dm) { + ret = DM_debug_info(dm); + if (dm_release) { + dm->release(dm); + } + if (ret) { + strcpy(result, ret); + MEM_freeN(ret); + } + } +} +#endif /* NDEBUG */ + #else void RNA_api_object(StructRNA *srna) @@ -483,6 +522,15 @@ void RNA_api_object(StructRNA *srna) {0, NULL, 0, NULL, NULL} }; +#ifndef NDEBUG + static EnumPropertyItem mesh_dm_info_items[] = { + {0, "SOURCE", 0, "Source", "Source mesh"}, + {1, "DEFORM", 0, "Deform", "Objects deform mesh"}, + {2, "FINAL", 0, "Final", "Objects final mesh"}, + {0, NULL, 0, NULL, NULL} + }; +#endif + /* mesh */ func= RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh"); RNA_def_function_ui_description(func, "Create a Mesh datablock with modifiers applied"); @@ -585,6 +633,20 @@ void RNA_api_object(StructRNA *srna) RNA_def_property_flag(parm, PROP_REQUIRED); parm= RNA_def_boolean(func, "result", 0, "", "Object visibility"); RNA_def_function_return(func, parm); + + +#ifndef NDEBUG + /* mesh */ + func= RNA_def_function(srna, "dm_info", "rna_Object_dm_info"); + RNA_def_function_ui_description(func, "Returns a string for derived mesh data"); + + parm= RNA_def_enum(func, "type", mesh_dm_info_items, 0, "", "Modifier settings to apply"); + RNA_def_property_flag(parm, PROP_REQUIRED); + /* weak!, no way to return dynamic string type */ + parm= RNA_def_string(func, "result", "result", 1024, "result", ""); + RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */ + RNA_def_function_output(func, parm); +#endif /* NDEBUG */ } |