Add MDisps.hidden bitmap.
authorNicholas Bishop <nicholasbishop@gmail.com>
Wed, 14 Mar 2012 06:31:38 +0000 (06:31 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Wed, 14 Mar 2012 06:31:38 +0000 (06:31 +0000)
Updates SDNA, customdata functions, and file read/write. Also adds
accessor functions to BKE paint.

source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/paint.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_meshdata_types.h

index 045e11c18b829767a746eff2ecb3e883f47c9d04..ff3e3c81724c06db4d58523cc651144fe4c60361 100644 (file)
@@ -33,6 +33,7 @@
  */
 
 struct Brush;
+struct MDisps;
 struct MFace;
 struct MultireModifierData;
 struct MVert;
@@ -61,6 +62,11 @@ void paint_brush_set(struct Paint *paint, struct Brush *br);
 int paint_facesel_test(struct Object *ob);
 int paint_vertsel_test(struct Object *ob);
 
+/* partial visibility */
+int paint_is_face_hidden(const struct MFace *f, const struct MVert *mvert);
+int paint_is_grid_face_hidden(const unsigned int *grid_hidden,
+                                                         int gridsize, int x, int y);
+
 /* Session data (mode-specific) */
 
 typedef struct SculptSession {
index 2520c9b666e26ab25dc760ffcefafacdbda084c4..e7af73c5e0f00132d089186ebe6174f7e73dc0f5 100644 (file)
@@ -484,6 +484,7 @@ static void layerCopy_mdisps(const void *source, void *dest, int count)
        for(i = 0; i < count; ++i) {
                if(s[i].disps) {
                        d[i].disps = MEM_dupallocN(s[i].disps);
+                       d[i].hidden = MEM_dupallocN(s[i].hidden);
                        d[i].totdisp = s[i].totdisp;
                        d[i].level = s[i].level;
                }
@@ -504,7 +505,10 @@ static void layerFree_mdisps(void *data, int count, int UNUSED(size))
        for(i = 0; i < count; ++i) {
                if(d[i].disps)
                        MEM_freeN(d[i].disps);
+               if(d[i].hidden)
+                       MEM_freeN(d[i].hidden);
                d[i].disps = NULL;
+               d[i].hidden = NULL;
                d[i].totdisp = 0;
                d[i].level = 0;
        }
index 2b3f792f7775e2d090daf734868470c879ea1b86..fe4fdb589519ee32d65beaf282cb1756ad8e051a 100644 (file)
 
 #include "DNA_object_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_brush_types.h"
 
+#include "BLI_bitmap.h"
 #include "BLI_utildefines.h"
 
-
 #include "BKE_brush.h"
 #include "BKE_library.h"
 #include "BKE_paint.h"
+#include "BKE_subsurf.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -147,3 +149,26 @@ void copy_paint(Paint *src, Paint *tar)
        tar->brush= src->brush;
        id_us_plus((ID *)tar->brush);
 }
+
+/* returns non-zero if any of the face's vertices
+   are hidden, zero otherwise */
+int paint_is_face_hidden(const MFace *f, const MVert *mvert)
+{
+       return ((mvert[f->v1].flag & ME_HIDE) ||
+                       (mvert[f->v2].flag & ME_HIDE) ||
+                       (mvert[f->v3].flag & ME_HIDE) ||
+                       (f->v4 && (mvert[f->v4].flag & ME_HIDE)));
+}
+
+/* returns non-zero if any of the corners of the grid
+   face whose inner corner is at (x,y) are hidden,
+   zero otherwise */
+int paint_is_grid_face_hidden(const unsigned int *grid_hidden,
+                                                         int gridsize, int x, int y)
+{
+       /* skip face if any of its corners are hidden */
+       return (BLI_BITMAP_GET(grid_hidden, y * gridsize + x) ||
+                       BLI_BITMAP_GET(grid_hidden, y * gridsize + x+1) ||
+                       BLI_BITMAP_GET(grid_hidden, (y+1) * gridsize + x+1) ||
+                       BLI_BITMAP_GET(grid_hidden, (y+1) * gridsize + x));
+}
index 2cbb8a300ed99e0565c7d5cfdd0d34431c954713..0ba4c7a63d021ed96da2dfbadab4ae46c5ae9140 100644 (file)
@@ -3750,6 +3750,7 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte
 
                for(i = 0; i < count; ++i) {
                        mdisps[i].disps = newdataadr(fd, mdisps[i].disps);
+                       mdisps[i].hidden = newdataadr(fd, mdisps[i].hidden);
 
                        if (mdisps[i].totdisp && !mdisps[i].level) {
                                /* this calculation is only correct for loop mdisps;
index 42c0ed1e55db573b35e1bab5f3adf34e48c962b7..37e2308a0c1edb2f80b76eb0d7457f3a0b46a3f1 100644 (file)
@@ -135,6 +135,7 @@ Any case: direct data is ALWAYS after the lib block
 #include "DNA_movieclip_types.h"
 
 #include "MEM_guardedalloc.h" // MEM_freeN
+#include "BLI_bitmap.h"
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
 #include "BLI_bpath.h"
@@ -1638,11 +1639,15 @@ static void write_mdisps(WriteData *wd, int count, MDisps *mdlist, int external)
                int i;
                
                writestruct(wd, DATA, "MDisps", count, mdlist);
-               if(!external) {
-                       for(i = 0; i < count; ++i) {
-                               if(mdlist[i].disps)
-                                       writedata(wd, DATA, sizeof(float)*3*mdlist[i].totdisp, mdlist[i].disps);
+               for(i = 0; i < count; ++i) {
+                       MDisps *md = &mdlist[i];
+                       if(md->disps) {
+                               if(!external)
+                                       writedata(wd, DATA, sizeof(float)*3*md->totdisp, md->disps);
                        }
+                       
+                       if(md->hidden)
+                               writedata(wd, DATA, BLI_BITMAP_SIZE(md->totdisp), md->hidden);
                }
        }
 }
index f5a8a185556ca26cb45515f09f0f1b16cd575d42..6b526c6463e5fd292ab804d78b00135c69144323 100644 (file)
@@ -166,6 +166,12 @@ typedef struct MDisps {
        int totdisp;
        int level;
        float (*disps)[3];
+       
+       /* Used for hiding parts of a multires mesh. Essentially the multires
+          equivalent of MVert.flag's ME_HIDE bit.
+       
+          This is a bitmap, keep in sync with type used in BLI_bitmap.h */
+       unsigned int *hidden;
 } MDisps;
 
 /** Multires structs kept for compatibility with old files **/