Merging r46495 through r46557 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 8b8b4f65c44a5d5c65c6ee7a5cefc88775a1335a..1e61aa937d6a2f72a0f1e24c1bc54e356d6f3126 100644 (file)
@@ -3829,6 +3829,19 @@ static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int exte
        }
 }
 
+static void direct_link_grid_paint_mask(FileData *fd, int count, GridPaintMask *grid_paint_mask)
+{
+       if(grid_paint_mask) {
+               int i;
+
+               for(i = 0; i < count; ++i) {
+                       GridPaintMask *gpm = &grid_paint_mask[i];
+                       if(gpm->data)
+                               gpm->data = newdataadr(fd, gpm->data);
+               }
+       }
+}
+
 /*this isn't really a public api function, so prototyped here*/
 static void direct_link_customdata(FileData *fd, CustomData *data, int count)
 {
@@ -3855,6 +3868,8 @@ static void direct_link_customdata(FileData *fd, CustomData *data, int count)
                        layer->data = newdataadr(fd, layer->data);
                        if (layer->type == CD_MDISPS)
                                direct_link_mdisps(fd, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
+                       else if(layer->type == CD_GRID_PAINT_MASK)
+                               direct_link_grid_paint_mask(fd, count, layer->data);
                        i++;
                }
        }
@@ -6915,6 +6930,52 @@ static void do_versions_nodetree_multi_file_output_path_2_64_0(bNodeTree *ntree)
        }
 }
 
+static void do_versions_nodetree_file_output_layers_2_64_5(bNodeTree *ntree)
+{
+       bNode *node;
+       
+       for (node=ntree->nodes.first; node; node=node->next) {
+               if (node->type==CMP_NODE_OUTPUT_FILE) {
+                       bNodeSocket *sock;
+                       for (sock=node->inputs.first; sock; sock=sock->next) {
+                               NodeImageMultiFileSocket *input = sock->storage;
+                               
+                               /* multilayer names are stored as separate strings now,
+                                * used the path string before, so copy it over.
+                                */
+                               BLI_strncpy(input->layer, input->path, sizeof(input->layer));
+                               
+                               /* paths/layer names also have to be unique now, initial check */
+                               ntreeCompositOutputFileUniquePath(&node->inputs, sock, input->path, '_');
+                               ntreeCompositOutputFileUniqueLayer(&node->inputs, sock, input->layer, '_');
+                       }
+               }
+       }
+}
+
+static void do_versions_nodetree_image_layer_2_64_5(bNodeTree *ntree)
+{
+       bNode *node;
+       
+       for (node=ntree->nodes.first; node; node=node->next) {
+               if (node->type==CMP_NODE_IMAGE) {
+                       ImageUser *iuser= (ImageUser *)node->storage;
+                       bNodeSocket *sock;
+                       for (sock=node->outputs.first; sock; sock=sock->next) {
+                               NodeImageLayer *output = MEM_callocN(sizeof(NodeImageLayer), "node image layer");
+                               
+                               /* take layer index from image user (this is ignored from now on) */
+                               output->layer_index = iuser->layer;
+                               /* take pass index both from current storage ptr (actually an int) */
+                               output->pass_index = GET_INT_FROM_POINTER(sock->storage);
+                               
+                               /* replace socket data pointer */
+                               sock->storage = output;
+                       }
+               }
+       }
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -7531,6 +7592,26 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
+       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 5))
+       {
+               {
+                       /* file output node paths are now stored in the file info struct instead socket name */
+                       Scene *sce;
+                       bNodeTree *ntree;
+                       
+                       for (sce = main->scene.first; sce; sce=sce->id.next) {
+                               if (sce->nodetree) {
+                                       do_versions_nodetree_file_output_layers_2_64_5(sce->nodetree);
+                                       do_versions_nodetree_image_layer_2_64_5(sce->nodetree);
+                               }
+                       }
+                       for (ntree = main->nodetree.first; ntree; ntree=ntree->id.next) {
+                               do_versions_nodetree_file_output_layers_2_64_5(ntree);
+                               do_versions_nodetree_image_layer_2_64_5(ntree);
+                       }
+               }
+       }
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */