Revision: 53338
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53338
Author:   campbellbarton
Date:     2012-12-27 03:51:45 +0000 (Thu, 27 Dec 2012)
Log Message:
-----------
display the number of tri's in object mode status, often requested feature from 
users who model for realtime/game-engine output,
the total number of faces wasn't so useful and could be especially misleading 
with ngons.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_displist.h
    trunk/blender/source/blender/blenkernel/intern/displist.c
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom_inline.c
    trunk/blender/source/blender/editors/space_info/info_stats.c

Modified: trunk/blender/source/blender/blenkernel/BKE_displist.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_displist.h      2012-12-27 
03:14:11 UTC (rev 53337)
+++ trunk/blender/source/blender/blenkernel/BKE_displist.h      2012-12-27 
03:51:45 UTC (rev 53338)
@@ -83,7 +83,7 @@
 DispList *BKE_displist_find_or_create(struct ListBase *lb, int type);
 DispList *BKE_displist_find(struct ListBase *lb, int type);
 void BKE_displist_normals_add(struct ListBase *lb);
-void BKE_displist_count(struct ListBase *lb, int *totvert, int *totface);
+void BKE_displist_count(struct ListBase *lb, int *totvert, int *totface, int 
*tottri);
 void BKE_displist_free(struct ListBase *lb);
 int BKE_displist_has_faces(struct ListBase *lb);
 

Modified: trunk/blender/source/blender/blenkernel/intern/displist.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/displist.c   2012-12-27 
03:14:11 UTC (rev 53337)
+++ trunk/blender/source/blender/blenkernel/intern/displist.c   2012-12-27 
03:51:45 UTC (rev 53338)
@@ -225,29 +225,48 @@
        }
 }
 
-void BKE_displist_count(ListBase *lb, int *totvert, int *totface)
+void BKE_displist_count(ListBase *lb, int *totvert, int *totface, int *tottri)
 {
        DispList *dl;
 
-       dl = lb->first;
-       while (dl) {
+       for (dl = lb->first; dl; dl = dl->next) {
+               int vert_tot = 0;
+               int face_tot = 0;
+               int tri_tot = 0;
+
                switch (dl->type) {
                        case DL_SURF:
-                               *totvert += dl->nr * dl->parts;
-                               *totface += (dl->nr - 1) * (dl->parts - 1);
+                       {
+                               vert_tot = dl->nr * dl->parts;
+                               face_tot = (dl->nr - 1) * (dl->parts - 1);
+                               tri_tot  = face_tot * 2;
                                break;
+                       }
                        case DL_INDEX3:
+                       {
+                               vert_tot = dl->nr;
+                               face_tot = dl->parts;
+                               tri_tot  = face_tot;
+                               break;
+                       }
                        case DL_INDEX4:
-                               *totvert += dl->nr;
-                               *totface += dl->parts;
+                       {
+                               vert_tot = dl->nr;
+                               face_tot = dl->parts;
+                               tri_tot  = face_tot * 2;
                                break;
+                       }
                        case DL_POLY:
                        case DL_SEGM:
-                               *totvert += dl->nr * dl->parts;
+                       {
+                               vert_tot = dl->nr * dl->parts;
                                break;
+                       }
                }
 
-               dl = dl->next;
+               *totvert += vert_tot;
+               *totface += face_tot;
+               *tottri  += tri_tot;
        }
 }
 

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h        2012-12-27 
03:14:11 UTC (rev 53337)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h        2012-12-27 
03:51:45 UTC (rev 53338)
@@ -262,6 +262,8 @@
 MINLINE int max_axis_v3(const float vec[3]);
 MINLINE int min_axis_v3(const float vec[3]);
 
+MINLINE int poly_to_tri_count(const int poly_count, const int corner_count);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/source/blender/blenlib/intern/math_geom_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom_inline.c      
2012-12-27 03:14:11 UTC (rev 53337)
+++ trunk/blender/source/blender/blenlib/intern/math_geom_inline.c      
2012-12-27 03:51:45 UTC (rev 53338)
@@ -158,4 +158,24 @@
               ((y < z) ? 1 : 2));
 }
 
+/**
+ * Simple method to find how many tri's we need when we already know the 
corner+poly count.
+ *
+ * Formula is:
+ *
+ *   tri = ((corner_count / poly_count) - 2) * poly_count;
+ *
+ * Use doubles since this is used for allocating and we
+ * don't want float precision to give incorrect results.
+ *
+ * \param poly_count The number of ngon's/tris (1-2 sided faces will give 
incorrect results)
+ * \param corner_count - also known as loops in BMesh/DNA
+ */
+MINLINE int poly_to_tri_count(const int poly_count, const int corner_count)
+{
+       const double poly_count_d   = (double)poly_count;
+       const double corner_count_d = (double)corner_count;
+       return (int)((((corner_count_d / poly_count_d) - 2.0) * poly_count_d) + 
0.5);
+}
+
 #endif /* __MATH_GEOM_INLINE_C__ */

Modified: trunk/blender/source/blender/editors/space_info/info_stats.c
===================================================================
--- trunk/blender/source/blender/editors/space_info/info_stats.c        
2012-12-27 03:14:11 UTC (rev 53337)
+++ trunk/blender/source/blender/editors/space_info/info_stats.c        
2012-12-27 03:51:45 UTC (rev 53338)
@@ -39,6 +39,7 @@
 #include "DNA_scene_types.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_math.h"
 
 #include "BKE_anim.h"
 #include "BKE_blender.h"
@@ -62,7 +63,7 @@
        int totbone, totbonesel;
        int totobj,  totobjsel;
        int totlamp, totlampsel; 
-       int tottri, totmesh, totcurve;
+       int tottri, totmesh;
 
        char infostr[512];
 } SceneStats;
@@ -74,7 +75,7 @@
                {
                        /* we assume derivedmesh is already built, this 
strictly does stats now. */
                        DerivedMesh *dm = ob->derivedFinal;
-                       int totvert, totedge, totface;
+                       int totvert, totedge, totface, totloop;
 
                        stats->totmesh += totob;
 
@@ -82,10 +83,12 @@
                                totvert = dm->getNumVerts(dm);
                                totedge = dm->getNumEdges(dm);
                                totface = dm->getNumPolys(dm);
+                               totloop = dm->getNumLoops(dm);
 
                                stats->totvert += totvert * totob;
                                stats->totedge += totedge * totob;
                                stats->totface += totface * totob;
+                               stats->tottri  += poly_to_tri_count(totface, 
totloop) * totob;
 
                                if (sel) {
                                        stats->totvertsel += totvert;
@@ -103,44 +106,27 @@
                case OB_SURF:
                case OB_CURVE:
                case OB_FONT:
+               case OB_MBALL:
                {
-                       int tot = 0, totf = 0;
+                       int totv = 0, totf = 0, tottri = 0;
 
-                       stats->totcurve += totob;
-
                        if (ob->disp.first)
-                               BKE_displist_count(&ob->disp, &tot, &totf);
+                               BKE_displist_count(&ob->disp, &totv, &totf, 
&tottri);
 
-                       tot *= totob;
-                       totf *= totob;
+                       totv   *= totob;
+                       totf   *= totob;
+                       tottri *= totob;
 
-                       stats->totvert += tot;
+                       stats->totvert += totv;
                        stats->totface += totf;
+                       stats->tottri  += tottri;
 
                        if (sel) {
-                               stats->totvertsel += tot;
+                               stats->totvertsel += totv;
                                stats->totfacesel += totf;
                        }
                        break;
                }
-               case OB_MBALL:
-               {
-                       int tot = 0, totf = 0;
-
-                       BKE_displist_count(&ob->disp, &tot, &totf);
-
-                       tot *= totob;
-                       totf *= totob;
-
-                       stats->totvert += tot;
-                       stats->totface += totf;
-
-                       if (sel) {
-                               stats->totvertsel += tot;
-                               stats->totfacesel += totf;
-                       }
-                       break;
-               }
        }
 }
 
@@ -389,8 +375,8 @@
                             stats->totbonesel, stats->totbone, memstr);
        }
        else {
-               s += sprintf(s, "Verts:%d | Faces:%d | Objects:%d/%d | 
Lamps:%d/%d%s",
-                            stats->totvert, stats->totface, stats->totobjsel, 
stats->totobj, stats->totlampsel, stats->totlamp, memstr);
+               s += sprintf(s, "Verts:%d | Faces:%d| Tris:%d | Objects:%d/%d | 
Lamps:%d/%d%s",
+                            stats->totvert, stats->totface, stats->tottri, 
stats->totobjsel, stats->totobj, stats->totlampsel, stats->totlamp, memstr);
        }
 
        if (ob)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to