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