Blender Internal: Add material property "Cast" which can disable both ray and buffer...
[blender.git] / source / blender / blenloader / intern / versioning_270.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_270.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_compiler_attrs.h"
30
31 /* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
32 #include <stddef.h>
33
34 /* allow readfile to use deprecated functionality */
35 #define DNA_DEPRECATED_ALLOW
36
37 #include "DNA_constraint_types.h"
38 #include "DNA_curve_types.h"
39 #include "DNA_sdna_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_modifier_types.h"
45 #include "DNA_linestyle_types.h"
46
47 #include "DNA_genfile.h"
48
49 #include "BLI_math.h"
50
51 #include "BKE_main.h"
52 #include "BKE_node.h"
53
54 #include "BLO_readfile.h"
55
56 #include "readfile.h"
57
58
59 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
60 {
61         bConstraint *con;
62
63         for (con = lb->first; con; con = con->next) {
64                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
65                         bTransformConstraint *data = (bTransformConstraint *)con->data;
66                         const float deg_to_rad_f = DEG2RADF(1.0f);
67
68                         if (data->from == TRANS_ROTATION) {
69                                 mul_v3_fl(data->from_min, deg_to_rad_f);
70                                 mul_v3_fl(data->from_max, deg_to_rad_f);
71                         }
72
73                         if (data->to == TRANS_ROTATION) {
74                                 mul_v3_fl(data->to_min, deg_to_rad_f);
75                                 mul_v3_fl(data->to_max, deg_to_rad_f);
76                         }
77                 }
78         }
79 }
80
81
82 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
83 {
84         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
85
86                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
87                         Object *ob;
88
89                         for (ob = main->object.first; ob; ob = ob->id.next) {
90                                 ModifierData *md;
91                                 for (md = ob->modifiers.first; md; md = md->next) {
92                                         if (md->type == eModifierType_Bevel) {
93                                                 BevelModifierData *bmd = (BevelModifierData *)md;
94                                                 bmd->profile = 0.5f;
95                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
96                                         }
97                                 }
98                         }
99                 }
100
101                 /* nodes don't use fixed node->id any more, clean up */
102                 FOREACH_NODETREE(main, ntree, id) {
103                         if (ntree->type == NTREE_COMPOSIT) {
104                                 bNode *node;
105                                 for (node = ntree->nodes.first; node; node = node->next) {
106                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
107                                                 node->id = NULL;
108                                         }
109                                 }
110                         }
111                 } FOREACH_NODETREE_END
112
113                 {
114                         bScreen *screen;
115
116                         for (screen = main->screen.first; screen; screen = screen->id.next) {
117                                 ScrArea *area;
118                                 for (area = screen->areabase.first; area; area = area->next) {
119                                         SpaceLink *space_link;
120                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
121                                                 if (space_link->spacetype == SPACE_CLIP) {
122                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
123                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
124                                                                 space_clip->mode = SC_MODE_TRACKING;
125                                                         }
126                                                 }
127                                         }
128                                 }
129                         }
130                 }
131
132                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
133                         MovieClip *clip;
134                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
135                                 clip->tracking.settings.default_weight = 1.0f;
136                         }
137                 }
138         }
139
140         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
141                 Scene *sce;
142                 Object *ob;
143
144                 /* Update Transform constraint (another deg -> rad stuff). */
145                 for (ob = main->object.first; ob; ob = ob->id.next) {
146                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
147
148                         if (ob->pose) {
149                                 /* Bones constraints! */
150                                 bPoseChannel *pchan;
151                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
152                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
153                                 }
154                         }
155                 }
156
157                 for (sce = main->scene.first; sce; sce = sce->id.next) {
158                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
159                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
160                         }
161                 }
162         }
163
164         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
165                 Mesh *me;
166
167                 /* Mesh smoothresh deg->rad. */
168                 for (me = main->mesh.first; me; me = me->id.next) {
169                         me->smoothresh = DEG2RADF(me->smoothresh);
170                 }
171         }
172
173         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
174                 FreestyleLineStyle *linestyle;
175
176                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
177                         linestyle->flag |= LS_NO_SORTING;
178                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
179                         linestyle->integration_type = LS_INTEGRATION_MEAN;
180                 }
181         }
182
183         if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) { /* will be replaced with version check when other new flag is added to mode2 */
184                 Material *ma;
185
186                 for (ma = main->mat.first; ma; ma = ma->id.next)
187                         ma->mode2 = MA_CASTSHADOW;
188         }
189 }