Freestyle: New options for sorting to arrange the stacking order of lines.
[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_sdna_types.h"
46 #include "DNA_linestyle_types.h"
47
48 #include "DNA_genfile.h"
49
50 #include "BLI_math.h"
51
52 #include "BKE_main.h"
53 #include "BKE_node.h"
54
55 #include "BLI_math.h"
56
57 #include "BLO_readfile.h"
58
59 #include "readfile.h"
60
61
62 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
63 {
64         bConstraint *con;
65
66         for (con = lb->first; con; con = con->next) {
67                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
68                         bTransformConstraint *data = (bTransformConstraint *)con->data;
69                         const float deg_to_rad_f = DEG2RADF(1.0f);
70
71                         if (data->from == TRANS_ROTATION) {
72                                 mul_v3_fl(data->from_min, deg_to_rad_f);
73                                 mul_v3_fl(data->from_max, deg_to_rad_f);
74                         }
75
76                         if (data->to == TRANS_ROTATION) {
77                                 mul_v3_fl(data->to_min, deg_to_rad_f);
78                                 mul_v3_fl(data->to_max, deg_to_rad_f);
79                         }
80                 }
81         }
82 }
83
84
85 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
86 {
87         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
88
89                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
90                         Object *ob;
91
92                         for (ob = main->object.first; ob; ob = ob->id.next) {
93                                 ModifierData *md;
94                                 for (md = ob->modifiers.first; md; md = md->next) {
95                                         if (md->type == eModifierType_Bevel) {
96                                                 BevelModifierData *bmd = (BevelModifierData *)md;
97                                                 bmd->profile = 0.5f;
98                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
99                                         }
100                                 }
101                         }
102                 }
103
104                 /* nodes don't use fixed node->id any more, clean up */
105                 FOREACH_NODETREE(main, ntree, id) {
106                         if (ntree->type == NTREE_COMPOSIT) {
107                                 bNode *node;
108                                 for (node = ntree->nodes.first; node; node = node->next) {
109                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
110                                                 node->id = NULL;
111                                         }
112                                 }
113                         }
114                 } FOREACH_NODETREE_END
115
116                 {
117                         bScreen *screen;
118
119                         for (screen = main->screen.first; screen; screen = screen->id.next) {
120                                 ScrArea *area;
121                                 for (area = screen->areabase.first; area; area = area->next) {
122                                         SpaceLink *space_link;
123                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
124                                                 if (space_link->spacetype == SPACE_CLIP) {
125                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
126                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
127                                                                 space_clip->mode = SC_MODE_TRACKING;
128                                                         }
129                                                 }
130                                         }
131                                 }
132                         }
133                 }
134
135                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
136                         MovieClip *clip;
137                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
138                                 clip->tracking.settings.default_weight = 1.0f;
139                         }
140                 }
141         }
142
143         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
144                 Scene *sce;
145                 Object *ob;
146
147                 /* Update Transform constraint (another deg -> rad stuff). */
148                 for (ob = main->object.first; ob; ob = ob->id.next) {
149                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
150
151                         if (ob->pose) {
152                                 /* Bones constraints! */
153                                 bPoseChannel *pchan;
154                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
155                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
156                                 }
157                         }
158                 }
159
160                 for (sce = main->scene.first; sce; sce = sce->id.next) {
161                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
162                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
163                         }
164                 }
165         }
166
167         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
168                 Mesh *me;
169
170                 /* Mesh smoothresh deg->rad. */
171                 for (me = main->mesh.first; me; me = me->id.next) {
172                         me->smoothresh = DEG2RADF(me->smoothresh);
173                 }
174         }
175
176         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
177                 FreestyleLineStyle *linestyle;
178
179                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
180                         linestyle->flag |= LS_NO_SORTING;
181                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
182                         linestyle->integration_type = LS_INTEGRATION_MEAN;
183                 }
184         }
185 }