Revert "Freestyle: Built-in SVG exporter."
[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_brush_types.h"
38 #include "DNA_cloth_types.h"
39 #include "DNA_constraint_types.h"
40 #include "DNA_sdna_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_screen_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_mesh_types.h"
45 #include "DNA_modifier_types.h"
46 #include "DNA_particle_types.h"
47 #include "DNA_linestyle_types.h"
48 #include "DNA_actuator_types.h"
49
50 #include "DNA_genfile.h"
51
52 #include "BLI_blenlib.h"
53 #include "BLI_math.h"
54
55 #include "BKE_main.h"
56 #include "BKE_node.h"
57
58 #include "BLI_math.h"
59 #include "BLI_string.h"
60
61 #include "BLO_readfile.h"
62
63 #include "readfile.h"
64
65
66 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
67 {
68         bConstraint *con;
69
70         for (con = lb->first; con; con = con->next) {
71                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
72                         bTransformConstraint *data = (bTransformConstraint *)con->data;
73                         const float deg_to_rad_f = DEG2RADF(1.0f);
74
75                         if (data->from == TRANS_ROTATION) {
76                                 mul_v3_fl(data->from_min, deg_to_rad_f);
77                                 mul_v3_fl(data->from_max, deg_to_rad_f);
78                         }
79
80                         if (data->to == TRANS_ROTATION) {
81                                 mul_v3_fl(data->to_min, deg_to_rad_f);
82                                 mul_v3_fl(data->to_max, deg_to_rad_f);
83                         }
84                 }
85         }
86 }
87
88 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
89 {
90         bConstraint *con;
91
92         for (con = lb->first; con; con = con->next) {
93                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
94                         bTransformConstraint *data = (bTransformConstraint *)con->data;
95
96                         if (data->from == TRANS_ROTATION) {
97                                 copy_v3_v3(data->from_min_rot, data->from_min);
98                                 copy_v3_v3(data->from_max_rot, data->from_max);
99                         }
100                         else if (data->from == TRANS_SCALE) {
101                                 copy_v3_v3(data->from_min_scale, data->from_min);
102                                 copy_v3_v3(data->from_max_scale, data->from_max);
103                         }
104
105                         if (data->to == TRANS_ROTATION) {
106                                 copy_v3_v3(data->to_min_rot, data->to_min);
107                                 copy_v3_v3(data->to_max_rot, data->to_max);
108                         }
109                         else if (data->to == TRANS_SCALE) {
110                                 copy_v3_v3(data->to_min_scale, data->to_min);
111                                 copy_v3_v3(data->to_max_scale, data->to_max);
112                         }
113                 }
114         }
115 }
116
117 static void do_version_constraints_stretch_to_limits(ListBase *lb)
118 {
119         bConstraint *con;
120
121         for (con = lb->first; con; con = con->next) {
122                 if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
123                         bStretchToConstraint *data = (bStretchToConstraint *)con->data;
124                         data->bulge_min = 1.0f;
125                         data->bulge_max = 1.0f;
126                 }
127         }
128 }
129
130 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
131 {
132         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
133
134                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
135                         Object *ob;
136
137                         for (ob = main->object.first; ob; ob = ob->id.next) {
138                                 ModifierData *md;
139                                 for (md = ob->modifiers.first; md; md = md->next) {
140                                         if (md->type == eModifierType_Bevel) {
141                                                 BevelModifierData *bmd = (BevelModifierData *)md;
142                                                 bmd->profile = 0.5f;
143                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
144                                         }
145                                 }
146                         }
147                 }
148
149                 /* nodes don't use fixed node->id any more, clean up */
150                 FOREACH_NODETREE(main, ntree, id) {
151                         if (ntree->type == NTREE_COMPOSIT) {
152                                 bNode *node;
153                                 for (node = ntree->nodes.first; node; node = node->next) {
154                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
155                                                 node->id = NULL;
156                                         }
157                                 }
158                         }
159                 } FOREACH_NODETREE_END
160
161                 {
162                         bScreen *screen;
163
164                         for (screen = main->screen.first; screen; screen = screen->id.next) {
165                                 ScrArea *area;
166                                 for (area = screen->areabase.first; area; area = area->next) {
167                                         SpaceLink *space_link;
168                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
169                                                 if (space_link->spacetype == SPACE_CLIP) {
170                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
171                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
172                                                                 space_clip->mode = SC_MODE_TRACKING;
173                                                         }
174                                                 }
175                                         }
176                                 }
177                         }
178                 }
179
180                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
181                         MovieClip *clip;
182                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
183                                 clip->tracking.settings.default_weight = 1.0f;
184                         }
185                 }
186         }
187
188         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
189                 Scene *sce;
190                 Object *ob;
191
192                 /* Update Transform constraint (another deg -> rad stuff). */
193                 for (ob = main->object.first; ob; ob = ob->id.next) {
194                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
195
196                         if (ob->pose) {
197                                 /* Bones constraints! */
198                                 bPoseChannel *pchan;
199                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
200                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
201                                 }
202                         }
203                 }
204
205                 for (sce = main->scene.first; sce; sce = sce->id.next) {
206                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
207                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
208                         }
209                 }
210         }
211
212         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
213                 Mesh *me;
214
215                 /* Mesh smoothresh deg->rad. */
216                 for (me = main->mesh.first; me; me = me->id.next) {
217                         me->smoothresh = DEG2RADF(me->smoothresh);
218                 }
219         }
220
221         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
222                 FreestyleLineStyle *linestyle;
223
224                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
225                         linestyle->flag |= LS_NO_SORTING;
226                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
227                         linestyle->integration_type = LS_INTEGRATION_MEAN;
228                 }
229         }
230
231         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
232                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
233                  * This will always reset situation to a valid state.
234                  */
235                 bScreen *sc;
236
237                 for (sc = main->screen.first; sc; sc = sc->id.next) {
238                         ScrArea *sa;
239                         for (sa = sc->areabase.first; sa; sa = sa->next) {
240                                 SpaceLink *sl;
241
242                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
243                                         ARegion *ar;
244                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
245
246                                         for (ar = lb->first; ar; ar = ar->next) {
247                                                 BLI_listbase_clear(&ar->ui_previews);
248                                         }
249                                 }
250                         }
251                 }
252         }
253
254         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
255                 Object *ob;
256
257                 /* Update Transform constraint (again :|). */
258                 for (ob = main->object.first; ob; ob = ob->id.next) {
259                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
260
261                         if (ob->pose) {
262                                 /* Bones constraints! */
263                                 bPoseChannel *pchan;
264                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
265                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
266                                 }
267                         }
268                 }
269         }
270
271         if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
272                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
273                         Material *ma;
274
275                         for (ma = main->mat.first; ma; ma = ma->id.next)
276                                 ma->mode2 = MA_CASTSHADOW;
277                 }
278
279                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
280                         Scene *sce;
281
282                         for (sce = main->scene.first; sce; sce = sce->id.next) {
283                                 sce->r.bake.flag = R_BAKE_CLEAR;
284                                 sce->r.bake.width = 512;
285                                 sce->r.bake.height = 512;
286                                 sce->r.bake.margin = 16;
287                                 sce->r.bake.normal_space = R_BAKE_SPACE_TANGENT;
288                                 sce->r.bake.normal_swizzle[0] = R_BAKE_POSX;
289                                 sce->r.bake.normal_swizzle[1] = R_BAKE_POSY;
290                                 sce->r.bake.normal_swizzle[2] = R_BAKE_POSZ;
291                                 BLI_strncpy(sce->r.bake.filepath, U.renderdir, sizeof(sce->r.bake.filepath));
292
293                                 sce->r.bake.im_format.planes = R_IMF_PLANES_RGBA;
294                                 sce->r.bake.im_format.imtype = R_IMF_IMTYPE_PNG;
295                                 sce->r.bake.im_format.depth = R_IMF_CHAN_DEPTH_8;
296                                 sce->r.bake.im_format.quality = 90;
297                                 sce->r.bake.im_format.compress = 15;
298                         }
299                 }
300
301                 if (!DNA_struct_elem_find(fd->filesdna, "FreestyleLineStyle", "float", "texstep")) {
302                         FreestyleLineStyle *linestyle;
303
304                         for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
305                                 linestyle->flag |= LS_TEXTURE;
306                                 linestyle->texstep = 1.0;
307                         }
308                 }
309
310                 {
311                         Scene *scene;
312                         for (scene = main->scene.first; scene; scene = scene->id.next) {
313                                 int num_layers = BLI_countlist(&scene->r.layers);
314                                 scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
315                         }
316                 }
317         }
318
319         if (!MAIN_VERSION_ATLEAST(main, 271, 1)) {
320                 if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "line_col[4]")) {
321                         Material *mat;
322
323                         for (mat = main->mat.first; mat; mat = mat->id.next) {
324                                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
325                                 mat->line_col[3] = mat->alpha;
326                         }
327                 }
328
329                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
330                         Scene *scene;
331                         for (scene = main->scene.first; scene; scene = scene->id.next) {
332                                 scene->r.preview_start_resolution = 64;
333                         }
334                 }
335         }
336
337         if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
338                 /* init up & track axis property of trackto actuators */
339                 Object *ob;
340
341                 for (ob = main->object.first; ob; ob = ob->id.next) {
342                         bActuator *act;
343                         for (act = ob->actuators.first; act; act = act->next) {
344                                 if (act->type == ACT_EDIT_OBJECT) {
345                                         bEditObjectActuator *eoact = act->data;
346                                         eoact->trackflag = ob->trackflag;
347                                         /* if trackflag is pointing +-Z axis then upflag should point Y axis.
348                                          * Rest of trackflag cases, upflag should be point z axis */
349                                         if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
350                                                 eoact->upflag = 1;
351                                         }
352                                         else {
353                                                 eoact->upflag = 2;
354                                         }
355                                 }
356                         }
357                 }
358         }
359
360         if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
361                 Brush *br;
362
363                 for (br = main->brush.first; br; br = br->id.next) {
364                         br->fill_threshold = 0.2f;
365                 }
366
367                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "int", "mat")) {
368                         Object *ob;
369                         for (ob = main->object.first; ob; ob = ob->id.next) {
370                                 ModifierData *md;
371
372                                 for (md = ob->modifiers.first; md; md = md->next) {
373                                         if (md->type == eModifierType_Bevel) {
374                                                 BevelModifierData *bmd = (BevelModifierData *)md;
375                                                 bmd->mat = -1;
376                                         }
377                                 }
378                         }
379                 }
380         }
381
382         if (!MAIN_VERSION_ATLEAST(main, 271, 6)) {
383                 Object *ob;
384                 for (ob = main->object.first; ob; ob = ob->id.next) {
385                         ModifierData *md;
386
387                         for (md = ob->modifiers.first; md; md = md->next) {
388                                 if (md->type == eModifierType_ParticleSystem) {
389                                         ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
390                                         if (pmd->psys && pmd->psys->clmd) {
391                                                 pmd->psys->clmd->sim_parms->vel_damping = 1.0f;
392                                         }
393                                 }
394                         }
395                 }
396         }
397
398         if (!MAIN_VERSION_ATLEAST(main, 272, 0)) {
399                 if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "int", "preview_start_resolution")) {
400                         Scene *scene;
401                         for (scene = main->scene.first; scene; scene = scene->id.next) {
402                                 scene->r.preview_start_resolution = 64;
403                         }
404                 }
405         }
406         
407         if (!MAIN_VERSION_ATLEAST(main, 272, 1)) {
408                 Brush *br;
409                 for (br = main->brush.first; br; br = br->id.next) {
410                         if ((br->ob_mode & OB_MODE_SCULPT) && ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK))
411                                 br->alpha = 1.0f;
412                 }
413         }
414
415         if (!DNA_struct_elem_find(fd->filesdna, "Image", "float", "gen_color")) {
416                 Image *image;
417                 for (image = main->image.first; image != NULL; image = image->id.next) {
418                         image->gen_color[3] = 1.0f;
419                 }
420         }
421
422         if (!DNA_struct_elem_find(fd->filesdna, "bStretchToConstraint", "float", "bulge_min")) {
423                 Object *ob;
424
425                 /* Update Transform constraint (again :|). */
426                 for (ob = main->object.first; ob; ob = ob->id.next) {
427                         do_version_constraints_stretch_to_limits(&ob->constraints);
428
429                         if (ob->pose) {
430                                 /* Bones constraints! */
431                                 bPoseChannel *pchan;
432                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
433                                         do_version_constraints_stretch_to_limits(&pchan->constraints);
434                                 }
435                         }
436                 }
437         }
438 }