2.5 Paint:
authorNicholas Bishop <nicholasbishop@gmail.com>
Mon, 17 Aug 2009 00:39:00 +0000 (00:39 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Mon, 17 Aug 2009 00:39:00 +0000 (00:39 +0000)
* Refactored the file write/read code for the new Paint type. Just used for sculpt for now, but this'll make it easier when the other paint modes are converted.

source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c

index 279dca5e0a58724c2d1f9741c0d8a57c6e142e88..91596cf884330385640d00ba41fd05e702631576 100644 (file)
@@ -4011,6 +4011,14 @@ static void composite_patch(bNodeTree *ntree, Scene *scene)
                        node->id= &scene->id;
 }
 
+static void link_paint(FileData *fd, Scene *sce, Paint *p)
+{
+       if(p && p->brushes) {
+               int i;
+               for(i = 0; i < p->brush_count; ++i)
+                       p->brushes[i]= newlibadr_us(fd, sce->id.lib, p->brushes[i]);
+       }
+}
 
 static void lib_link_scene(FileData *fd, Main *main)
 {
@@ -4036,12 +4044,9 @@ static void lib_link_scene(FileData *fd, Main *main)
                        
                        sce->toolsettings->imapaint.brush=
                                newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.brush);
-                       if(sce->toolsettings->sculpt && sce->toolsettings->sculpt->paint.brushes) {
-                               int i;
-                               for(i = 0; i < sce->toolsettings->sculpt->paint.brush_count; ++i)
-                                       sce->toolsettings->sculpt->paint.brushes[i]=
-                                               newlibadr_us(fd, sce->id.lib, sce->toolsettings->sculpt->paint.brushes[i]);
-                       }
+
+                       link_paint(fd, sce, &sce->toolsettings->sculpt->paint);
+
                        if(sce->toolsettings->vpaint)
                                sce->toolsettings->vpaint->brush=
                                        newlibadr_us(fd, sce->id.lib, sce->toolsettings->vpaint->brush);
@@ -4121,6 +4126,13 @@ static void link_recurs_seq(FileData *fd, ListBase *lb)
                        link_recurs_seq(fd, &seq->seqbase);
 }
 
+static void direct_link_paint(FileData *fd, Paint **paint)
+{
+       (*paint)= newdataadr(fd, (*paint));
+       if(*paint)
+               (*paint)->brushes= newdataadr(fd, (*paint)->brushes);
+}
+
 static void direct_link_scene(FileData *fd, Scene *sce)
 {
        Editing *ed;
@@ -4150,9 +4162,8 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        if(sce->toolsettings) {
                sce->toolsettings->vpaint= newdataadr(fd, sce->toolsettings->vpaint);
                sce->toolsettings->wpaint= newdataadr(fd, sce->toolsettings->wpaint);
-               sce->toolsettings->sculpt= newdataadr(fd, sce->toolsettings->sculpt);
-               if(sce->toolsettings->sculpt)
-                       sce->toolsettings->sculpt->paint.brushes= newdataadr(fd, sce->toolsettings->sculpt->paint.brushes);
+               direct_link_paint(fd, (Paint**)&sce->toolsettings->sculpt);
+
                sce->toolsettings->imapaint.paintcursor= NULL;
                sce->toolsettings->particle.paintcursor= NULL;
        }
index 366480f3c82fe4fc6c93af7b07b89b7dc6fd6bcb..6822305e75f5b4ec24189cdeb8332b4c92485486 100644 (file)
@@ -1676,6 +1676,11 @@ static void write_lamps(WriteData *wd, ListBase *idbase)
        }
 }
 
+static void write_paint(WriteData *wd, Paint *p)
+{
+       if(p && p->brushes)
+               writedata(wd, DATA, p->brush_count * sizeof(Brush*), p->brushes);
+}
 
 static void write_scenes(WriteData *wd, ListBase *scebase)
 {
@@ -1688,6 +1693,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
        TimeMarker *marker;
        TransformOrientation *ts;
        SceneRenderLayer *srl;
+       ToolSettings *tos;
        
        sce= scebase->first;
        while(sce) {
@@ -1705,17 +1711,15 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                        base= base->next;
                }
                
-               writestruct(wd, DATA, "ToolSettings", 1, sce->toolsettings);
-               if(sce->toolsettings->vpaint)
-                       writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->vpaint);
-               if(sce->toolsettings->wpaint)
-                       writestruct(wd, DATA, "VPaint", 1, sce->toolsettings->wpaint);
-               if(sce->toolsettings->sculpt) {
-                       writestruct(wd, DATA, "Sculpt", 1, sce->toolsettings->sculpt);
-                       if(sce->toolsettings->sculpt->paint.brushes) {
-                               Paint *p = &sce->toolsettings->sculpt->paint;
-                               writedata(wd, DATA, p->brush_count * sizeof(Brush*), p->brushes);
-                       }
+               tos = sce->toolsettings;
+               writestruct(wd, DATA, "ToolSettings", 1, tos);
+               if(tos->vpaint)
+                       writestruct(wd, DATA, "VPaint", 1, tos->vpaint);
+               if(tos->wpaint)
+                       writestruct(wd, DATA, "VPaint", 1, tos->wpaint);
+               if(tos->sculpt) {
+                       writestruct(wd, DATA, "Sculpt", 1, tos->sculpt);
+                       write_paint(wd, &tos->sculpt->paint);
                }
 
                ed= sce->ed;