Followup to rB8714ae09f894: better not have several RNA properties affect a single...
[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_blenlib.h"
50 #include "BLI_math.h"
51
52 #include "BKE_main.h"
53 #include "BKE_node.h"
54
55 #include "BLO_readfile.h"
56
57 #include "readfile.h"
58
59
60 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
61 {
62         bConstraint *con;
63
64         for (con = lb->first; con; con = con->next) {
65                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
66                         bTransformConstraint *data = (bTransformConstraint *)con->data;
67                         const float deg_to_rad_f = DEG2RADF(1.0f);
68
69                         if (data->from == TRANS_ROTATION) {
70                                 mul_v3_fl(data->from_min, deg_to_rad_f);
71                                 mul_v3_fl(data->from_max, deg_to_rad_f);
72                         }
73
74                         if (data->to == TRANS_ROTATION) {
75                                 mul_v3_fl(data->to_min, deg_to_rad_f);
76                                 mul_v3_fl(data->to_max, deg_to_rad_f);
77                         }
78                 }
79         }
80 }
81
82 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
83 {
84         bConstraint *con;
85
86         for (con = lb->first; con; con = con->next) {
87                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
88                         bTransformConstraint *data = (bTransformConstraint *)con->data;
89
90                         if (data->from == TRANS_ROTATION) {
91                                 copy_v3_v3(data->from_min_rot, data->from_min);
92                                 copy_v3_v3(data->from_max_rot, data->from_max);
93                         }
94                         else if (data->from == TRANS_SCALE) {
95                                 copy_v3_v3(data->from_min_scale, data->from_min);
96                                 copy_v3_v3(data->from_max_scale, data->from_max);
97                         }
98
99                         if (data->to == TRANS_ROTATION) {
100                                 copy_v3_v3(data->to_min_rot, data->to_min);
101                                 copy_v3_v3(data->to_max_rot, data->to_max);
102                         }
103                         else if (data->to == TRANS_SCALE) {
104                                 copy_v3_v3(data->to_min_scale, data->to_min);
105                                 copy_v3_v3(data->to_max_scale, data->to_max);
106                         }
107                 }
108         }
109 }
110
111 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
112 {
113         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
114
115                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
116                         Object *ob;
117
118                         for (ob = main->object.first; ob; ob = ob->id.next) {
119                                 ModifierData *md;
120                                 for (md = ob->modifiers.first; md; md = md->next) {
121                                         if (md->type == eModifierType_Bevel) {
122                                                 BevelModifierData *bmd = (BevelModifierData *)md;
123                                                 bmd->profile = 0.5f;
124                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
125                                         }
126                                 }
127                         }
128                 }
129
130                 /* nodes don't use fixed node->id any more, clean up */
131                 FOREACH_NODETREE(main, ntree, id) {
132                         if (ntree->type == NTREE_COMPOSIT) {
133                                 bNode *node;
134                                 for (node = ntree->nodes.first; node; node = node->next) {
135                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
136                                                 node->id = NULL;
137                                         }
138                                 }
139                         }
140                 } FOREACH_NODETREE_END
141
142                 {
143                         bScreen *screen;
144
145                         for (screen = main->screen.first; screen; screen = screen->id.next) {
146                                 ScrArea *area;
147                                 for (area = screen->areabase.first; area; area = area->next) {
148                                         SpaceLink *space_link;
149                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
150                                                 if (space_link->spacetype == SPACE_CLIP) {
151                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
152                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
153                                                                 space_clip->mode = SC_MODE_TRACKING;
154                                                         }
155                                                 }
156                                         }
157                                 }
158                         }
159                 }
160
161                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
162                         MovieClip *clip;
163                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
164                                 clip->tracking.settings.default_weight = 1.0f;
165                         }
166                 }
167         }
168
169         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
170                 Scene *sce;
171                 Object *ob;
172
173                 /* Update Transform constraint (another deg -> rad stuff). */
174                 for (ob = main->object.first; ob; ob = ob->id.next) {
175                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
176
177                         if (ob->pose) {
178                                 /* Bones constraints! */
179                                 bPoseChannel *pchan;
180                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
181                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
182                                 }
183                         }
184                 }
185
186                 for (sce = main->scene.first; sce; sce = sce->id.next) {
187                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
188                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
189                         }
190                 }
191         }
192
193         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
194                 Mesh *me;
195
196                 /* Mesh smoothresh deg->rad. */
197                 for (me = main->mesh.first; me; me = me->id.next) {
198                         me->smoothresh = DEG2RADF(me->smoothresh);
199                 }
200         }
201
202         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
203                 FreestyleLineStyle *linestyle;
204
205                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
206                         linestyle->flag |= LS_NO_SORTING;
207                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
208                         linestyle->integration_type = LS_INTEGRATION_MEAN;
209                 }
210         }
211
212         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
213                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
214                  * This will always reset situation to a valid state.
215                  */
216                 bScreen *sc;
217
218                 for (sc = main->screen.first; sc; sc = sc->id.next) {
219                         ScrArea *sa;
220                         for (sa = sc->areabase.first; sa; sa = sa->next) {
221                                 SpaceLink *sl;
222
223                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
224                                         ARegion *ar;
225                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
226
227                                         for (ar = lb->first; ar; ar = ar->next) {
228                                                 BLI_listbase_clear(&ar->ui_previews);
229                                         }
230                                 }
231                         }
232                 }
233         }
234
235         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
236                 Object *ob;
237
238                 /* Update Transform constraint (again :|). */
239                 for (ob = main->object.first; ob; ob = ob->id.next) {
240                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
241
242                         if (ob->pose) {
243                                 /* Bones constraints! */
244                                 bPoseChannel *pchan;
245                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
246                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
247                                 }
248                         }
249                 }
250         }
251
252         if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) { /* will be replaced with version check when other new flag is added to mode2 */
253                 Material *ma;
254
255                 for (ma = main->mat.first; ma; ma = ma->id.next)
256                         ma->mode2 = MA_CASTSHADOW;
257         }
258 }