Cycles: add location/rotate/scale and XYZ mapping options for all texture nodes,
[blender.git] / source / blender / blenloader / intern / readfile.c
index 7a8bacf1ec6f1063bfe7e6860223e6366c3648fc..1c96cd2e05af59619dc0e6915c95c2d3306ab0ec 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -3224,7 +3222,7 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache)
                                pm->data[i] = newdataadr(fd, pm->data[i]);
                                
                                /* the cache saves non-struct data without DNA */
-                               if(pm->data[i] && strcmp(ptcache_data_struct[i], "")==0 && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) {
+                               if(pm->data[i] && ptcache_data_struct[i][0]=='\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) {
                                        int j, tot= (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */
                                        int *poin= pm->data[i];
                                        
@@ -3540,6 +3538,9 @@ static void lib_link_mtface(FileData *fd, Mesh *me, MTFace *mtface, int totface)
        MTFace *tf= mtface;
        int i;
 
+       /* Add pseudo-references (not fake users!) to images used by texface. A
+          little bogus; it would be better if each mesh consistently added one ref
+          to each image it used. - z0r */
        for (i=0; i<totface; i++, tf++) {
                tf->tpage= newlibadr(fd, me->id.lib, tf->tpage);
                if(tf->tpage && tf->tpage->id.us==0)
@@ -5038,15 +5039,6 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                sfile->folders_prev= NULL;
                                                sfile->folders_next= NULL;
                                        }
-                                       else if(sl->spacetype==SPACE_IMASEL) {
-                                               SpaceImaSel *simasel= (SpaceImaSel *)sl;
-
-                                               simasel->files = NULL;                                          
-                                               simasel->returnfunc= NULL;
-                                               simasel->menup= NULL;
-                                               simasel->pupmenu= NULL;
-                                               simasel->img= NULL;
-                                       }
                                        else if(sl->spacetype==SPACE_ACTION) {
                                                SpaceAction *saction= (SpaceAction *)sl;
                                                bDopeSheet *ads= &saction->ads;
@@ -5110,11 +5102,6 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                        }
                                                }
                                        }
-                                       else if(sl->spacetype==SPACE_SOUND) {
-                                               SpaceSound *ssound= (SpaceSound *)sl;
-
-                                               ssound->sound= newlibadr_us(fd, sc->id.lib, ssound->sound);
-                                       }
                                        else if(sl->spacetype==SPACE_NODE) {
                                                SpaceNode *snode= (SpaceNode *)sl;
                                                
@@ -5285,12 +5272,6 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        SpaceFile *sfile= (SpaceFile *)sl;
                                        sfile->op= NULL;
                                }
-                               else if(sl->spacetype==SPACE_IMASEL) {
-                                       SpaceImaSel *simasel= (SpaceImaSel *)sl;
-                                       if (simasel->files) {
-                                               //XXX BIF_filelist_freelib(simasel->files);
-                                       }
-                               }
                                else if(sl->spacetype==SPACE_ACTION) {
                                        SpaceAction *saction= (SpaceAction *)sl;
                                        
@@ -5357,11 +5338,6 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                                }
                                        }
                                }
-                               else if(sl->spacetype==SPACE_SOUND) {
-                                       SpaceSound *ssound= (SpaceSound *)sl;
-
-                                       ssound->sound= restore_pointer_by_name(newmain, (ID *)ssound->sound, 1);
-                               }
                                else if(sl->spacetype==SPACE_NODE) {
                                        SpaceNode *snode= (SpaceNode *)sl;
                                        
@@ -5445,8 +5421,8 @@ static void view3d_split_250(View3D *v3d, ListBase *regions)
                        rv3d->persp= v3d->persp;
                        rv3d->view= v3d->view;
                        rv3d->dist= v3d->dist;
-                       VECCOPY(rv3d->ofs, v3d->ofs);
-                       QUATCOPY(rv3d->viewquat, v3d->viewquat);
+                       copy_v3_v3(rv3d->ofs, v3d->ofs);
+                       copy_qt_qt(rv3d->viewquat, v3d->viewquat);
                }
        }
 
@@ -6755,16 +6731,6 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                //ar->v2d.flag |= V2D_IS_INITIALISED;
                                break;
                        }
-                       case SPACE_SOUND:
-                       {
-                               SpaceSound *ssound= (SpaceSound *)sl;
-                               memcpy(&ar->v2d, &ssound->v2d, sizeof(View2D));
-                               
-                               ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
-                               ar->v2d.scroll |= (V2D_SCROLL_LEFT);
-                               //ar->v2d.flag |= V2D_IS_INITIALISED;
-                               break;
-                       }
                        case SPACE_NLA:
                        {
                                SpaceNla *snla= (SpaceNla *)sl;
@@ -6880,11 +6846,17 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
                
                area_add_window_regions(sa, sa->spacedata.first, &sa->regionbase);
                
-               /* space imageselect is depricated */
+               /* space imageselect is deprecated */
                for(sl= sa->spacedata.first; sl; sl= sl->next) {
                        if(sl->spacetype==SPACE_IMASEL)
-                               sl->spacetype= SPACE_INFO;      /* spacedata then matches */
-               }               
+                               sl->spacetype= SPACE_EMPTY;     /* spacedata then matches */
+               }
+               
+               /* space sound is deprecated */
+               for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                       if(sl->spacetype==SPACE_SOUND)
+                               sl->spacetype= SPACE_EMPTY;     /* spacedata then matches */
+               }
                
                /* it seems to be possible in 2.5 to have this saved, filewindow probably */
                sa->butspacetype= sa->spacetype;
@@ -7240,6 +7212,40 @@ static void do_versions_nodetree_image_default_alpha_output(bNodeTree *ntree)
        }
 }
 
+static void do_version_ntree_tex_mapping_260(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree)
+{
+       bNode *node;
+
+       for(node=ntree->nodes.first; node; node=node->next) {
+               TexMapping *tex_mapping= NULL;
+               ColorMapping *color_mapping= NULL;
+
+               if(node->type == SH_NODE_MAPPING) {
+                       tex_mapping= node->storage;
+                       tex_mapping->projx= PROJ_X;
+                       tex_mapping->projy= PROJ_Y;
+                       tex_mapping->projz= PROJ_Z;
+               }
+               else if(ELEM7(node->type, SH_NODE_TEX_IMAGE, SH_NODE_TEX_NOISE, SH_NODE_TEX_SKY,
+                       SH_NODE_TEX_BLEND, SH_NODE_TEX_VORONOI, SH_NODE_TEX_MAGIC, SH_NODE_TEX_MARBLE) ||
+                       ELEM6(node->type, SH_NODE_TEX_CLOUDS, SH_NODE_TEX_WOOD, SH_NODE_TEX_MUSGRAVE,
+                       SH_NODE_TEX_STUCCI, SH_NODE_TEX_DISTNOISE, SH_NODE_TEX_ENVIRONMENT)) {
+                       NodeTexBase *base= node->storage;
+
+                       if(node->type == SH_NODE_TEX_NOISE)
+                               node->storage= MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise");
+
+                       tex_mapping= &base->tex_mapping;
+                       color_mapping= &base->color_mapping;
+
+                       if(is_zero_v3(tex_mapping->size)) {
+                               default_tex_mapping(tex_mapping);
+                               default_color_mapping(color_mapping);
+                       }
+               }
+       }
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -8820,7 +8826,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                
                for (wo = main->world.first; wo; wo= wo->id.next) {
                        /* Migrate to Bullet for games, except for the NaN versions */
-                       /* People can still explicitely choose for Sumo (after 2.42 is out) */
+                       /* People can still explicitly choose for Sumo (after 2.42 is out) */
                        if(main->versionfile > 225)
                                wo->physicsEngine = WOPHY_BULLET;
                        if(WO_AODIST == wo->aomode)
@@ -9311,7 +9317,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        }
        if(main->versionfile <= 245) {
                Scene *sce;
-               bScreen *sc;
                Object *ob;
                Image *ima;
                Lamp *la;
@@ -9401,49 +9406,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        for(ima= main->image.first; ima; ima= ima->id.next) {
                                ima->preview = NULL;
                        }
-                       
-                       /* repair imasel space - completely reworked */
-                       for(sc= main->screen.first; sc; sc= sc->id.next) {
-                               ScrArea *sa;
-                               sa= sc->areabase.first;
-                               while(sa) {
-                                       SpaceLink *sl;
-                                       
-                                       for (sl= sa->spacedata.first; sl; sl= sl->next) {
-                                               if(sl->spacetype==SPACE_IMASEL) {
-                                                       SpaceImaSel *simasel= (SpaceImaSel*) sl;
-                                                       simasel->blockscale= 0.7f;
-                                                       /* view 2D */
-                                                       simasel->v2d.tot.xmin=  -10.0f;
-                                                       simasel->v2d.tot.ymin=  -10.0f;
-                                                       simasel->v2d.tot.xmax= (float)sa->winx + 10.0f;
-                                                       simasel->v2d.tot.ymax= (float)sa->winy + 10.0f;                                         
-                                                       simasel->v2d.cur.xmin=  0.0f;
-                                                       simasel->v2d.cur.ymin=  0.0f;
-                                                       simasel->v2d.cur.xmax= (float)sa->winx;
-                                                       simasel->v2d.cur.ymax= (float)sa->winy;                                         
-                                                       simasel->v2d.min[0]= 1.0;
-                                                       simasel->v2d.min[1]= 1.0;                                               
-                                                       simasel->v2d.max[0]= 32000.0f;
-                                                       simasel->v2d.max[1]= 32000.0f;                                          
-                                                       simasel->v2d.minzoom= 0.5f;
-                                                       simasel->v2d.maxzoom= 1.21f;                                            
-                                                       simasel->v2d.scroll= 0;
-                                                       simasel->v2d.keepzoom= V2D_LIMITZOOM|V2D_KEEPASPECT;
-                                                       simasel->v2d.keeptot= 0;
-                                                       simasel->prv_h = 96;
-                                                       simasel->prv_w = 96;
-                                                       simasel->flag = 7; /* ??? elubie */
-                                                       BLI_strncpy (simasel->dir,  U.textudir, sizeof(simasel->dir)); /* TON */
-                                                       simasel->file[0]= '\0';
-                                                       
-                                                       simasel->returnfunc     =  NULL;
-                                                       simasel->title[0]       =  0;
-                                               }
-                                       }
-                                       sa = sa->next;
-                               }
-                       }
                }
 
                /* add point caches */
@@ -12358,8 +12320,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                ntree_tmp_cycles_emission_version_patch(fd, lib, ma->nodetree);
        }
 
-       /* put compatibility code here until next subversion bump */
-       {
+       if (main->versionfile < 260){
                {
                        /* set default alpha value of Image outputs in image and render layer nodes to 0 */
                        Scene *sce;
@@ -12392,6 +12353,38 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
+
+       }
+
+       if (main->versionfile < 260 || (main->versionfile == 260 && main->subversionfile < 1)){
+               Object *ob;
+
+               for (ob= main->object.first; ob; ob= ob->id.next) {
+                       ob->collision_boundtype= ob->boundtype;
+               }
+
+               {
+                       Camera *cam;
+                       for(cam= main->camera.first; cam; cam= cam->id.next) {
+                               if (cam->sensor_x < 0.01)
+                                       cam->sensor_x = DEFAULT_SENSOR_WIDTH;
+
+                               if (cam->sensor_y < 0.01)
+                                       cam->sensor_y = DEFAULT_SENSOR_HEIGHT;
+                       }
+               }
+
+               {
+                       bNodeTreeType *ntreetype= ntreeGetType(NTREE_SHADER);
+
+                       if(ntreetype && ntreetype->foreach_nodetree)
+                               ntreetype->foreach_nodetree(main, NULL, do_version_ntree_tex_mapping_260);
+               }
+       }
+
+       /* put compatibility code here until next subversion bump */
+       {
+               
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */