Saturday morning first cup of coffee hack (yeah, its a late
[blender.git] / source / blender / blenkernel / intern / displist.c
index 077060b7890807773fb6504665a4e42eeffd32ea..d18c205d82560e12e01ce7ca5a84a28a2cc25e83 100644 (file)
@@ -66,6 +66,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 #include "BLI_editVert.h"
+#include "BLI_edgehash.h"
 
 #include "BKE_bad_level_calls.h"
 #include "BKE_utildefines.h"
@@ -2049,3 +2050,43 @@ static void boundbox_displist(Object *ob)
        }
 }
 
+void displistmesh_add_edges(DispListMesh *dlm)
+{
+       EdgeHash *eh = BLI_edgehash_new();
+       EdgeHashIterator *ehi;
+       int i;
+
+       for (i=0; i<dlm->totface; i++) {
+               MFace *mf = &dlm->mface[i];
+
+               if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2))
+                       BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL);
+               if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3))
+                       BLI_edgehash_insert(eh, mf->v2, mf->v3, NULL);
+               
+               if (mf->v4) {
+                       if (!BLI_edgehash_haskey(eh, mf->v3, mf->v4))
+                               BLI_edgehash_insert(eh, mf->v3, mf->v4, NULL);
+                       if (!BLI_edgehash_haskey(eh, mf->v4, mf->v1))
+                               BLI_edgehash_insert(eh, mf->v4, mf->v1, NULL);
+               } else {
+                       if (!BLI_edgehash_haskey(eh, mf->v3, mf->v1))
+                               BLI_edgehash_insert(eh, mf->v3, mf->v1, NULL);
+               }
+       }
+
+       dlm->totedge = BLI_edgehash_size(eh);
+       dlm->medge = MEM_callocN(dlm->totedge*sizeof(*dlm->medge), "medge");
+
+       ehi = BLI_edgehashIterator_new(eh);
+       for (i=0; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) {
+               MEdge *med = &dlm->medge[i++];
+
+               BLI_edgehashIterator_getKey(ehi, &med->v1, &med->v2);
+
+               med->flag = ME_EDGEDRAW|ME_EDGERENDER;
+       }
+       BLI_edgehashIterator_free(ehi);
+
+       BLI_edgehash_free(eh, NULL);
+}