debug function DM_debug_info / DM_debug_print, with access from python
authorCampbell Barton <ideasman42@gmail.com>
Thu, 19 Jan 2012 00:18:25 +0000 (00:18 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 19 Jan 2012 00:18:25 +0000 (00:18 +0000)
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.

source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/makesrna/intern/rna_object_api.c

index 5f451ce78217dc7df8331290d5a1e9a6a82cc2ce..0c47c833cb31789cf2325d3bf3f4b23a0ba8467c 100644 (file)
@@ -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
index 0ff46045f78e356a0ff9a84641001c4fa02d7571..344fc485d1a1ddd76a0221dc803a1e0870fc1f50 100644 (file)
@@ -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 */
index 877da130357b2d7c48db7147da5685e9eea92adf..53203717c850aadbc998b1aa8169f4a45261d632 100644 (file)
@@ -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 */
 }